<commit_before># coding: utf-8

# TODO remove sympify, Symbol
import numpy
from sympy.core.function import Function
from sympy.core import Symbol, Tuple
from sympy import sympify
from sympy.core.basic import Basic
from sympy.utilities.iterables import iterable
from sympy.logic.boolalg import Boolean, BooleanTrue, BooleanFalse

from .core import Variable, IndexedElement, IndexedVariable,List
from .core import DataType, datatype
from .core import (NativeInteger, NativeFloat, NativeDouble, NativeComplex,
                   NativeBool, String)


class Array(Function):
    """Represents a call to  numpy.array for code generation.

    ls : list ,tuple ,Tuple,List
    """
    def __new__(cls, ls, dtype=None):
        if not isinstance(ls,(list,tuple,Tuple,List) ):
            raise TypeError("Uknown type of  %s." % type(ls))
        if isinstance(dtype, str):
            dtype = datatype('ndarray'+dtype)

        return Basic.__new__(cls, ls, dtype)

    def _sympystr(self, printer):
        sstr = printer.doprint
        return self.ls
     
    
    @property
    def ls(self):
        return self._args[0]
    
    @property
    def dtype(self):
        return self._args[1]
    
    @property
    def shape(self):
        return Tuple(*numpy.shape(self._args[0]))

    @property
    def rank(self):
        return len(self.shape) 
    
    def fprint(self, printer, lhs):
        """Fortran print."""
        if isinstance(self.shape, (Tuple,tuple)):
        # this is a correction. problem on LRZ
            shape_code = ', '.join('0:' + printer(i-1) for i in self.shape)
        else:
            shape_code = '0:' + printer(self.shape-1)
        lhs_code = printer(lhs)

        code_alloc = "allocate({0}({1}))".format(lhs_code, shape_code)
        init_value = printer(self.ls)
        code_init = "{0} = {1}".format(lhs_code, init_value)
        code = "{0}\n{1}".format(code_alloc, code_init)

        return code


class Shape(Array):
    """Represents a call to  numpy.shape for code generation.

    ls : list ,tuple ,Tuple,List, Variable
    """
    def __new__(cls, ls):
        if not isinstance(ls,(list,tuple,Tuple,List,Array, Variable) ):
            raise TypeError("Uknown type of  %s." % type(ls))
        return Basic.__new__(cls, ls)

    @property
    def ls(self):
        return self._args[0]
    
    @property
    def dtype(self):
        return 'ndarrayint'
    
    @property
    def shape(self):
        return Tuple(self.ls.rank,)

    @property
    def rank(self):
        return 1 
  
    def fprint(self, printer, lhs):
        """Fortran print."""
 
        lhs_code = printer(lhs)
        if isinstance(self.ls, Array):
           init_value = printer(self.ls.ls)
        else:
           init_value = printer(self.ls)
        code_init = "{0} = shape({1})".format(lhs_code, init_value)
        
        return code_init


class Int(Function):
    """Represents a call to  numpy.int for code generation.

    arg : Variable,Float,Integer
    """
    def __new__(cls, arg):
        if not isinstance(arg,(Variable,NativeInteger, NativeFloat, NativeDouble, NativeComplex)):
            raise TypeError("Uknown type of  %s." % type(ls))
        return Basic.__new__(cls, arg)

    @property
    def arg(self):
        return self._args[0]
    
    @property
    def dtype(self):
        return 'int'
    
    @property
    def shape(self):
        return None

    @property
    def rank(self):
        return 0 
    
    def fprint(self, printer, lhs):
        """Fortran print."""
        lhs_code = printer(lhs)
        init_value = printer(self.arg)
        code = "{0} = Int({1})".format(lhs_code, init_value)
        return code



class Zeros(Function):
    """Represents a call to numpy.zeros for code generation.

    shape : int, list, tuple
        int or list of integers

    dtype: str, DataType
        datatype for the constructed array

    Examples

    """
    # TODO improve
    def __new__(cls, shape, dtype=None):

        if isinstance(shape, list):
            # this is a correction. otherwise it is not working on LRZ
            if isinstance(shape[0], list):
                shape = Tuple(*(sympify(i) for i in shape[0]))
            else:
                shape = Tuple(*(sympify(i) for i in shape))
        elif isinstance(shape, int):
            shape = Tuple(sympify(shape))
        else:
            shape = shape

        if dtype is None:
            dtype = 'double'

        if isinstance(dtype, String):
            dtype = datatype('ndarray'+dtype.arg.replace('\'', ''))
        elif not isinstance(dtype, DataType):
            raise TypeError("datatype must be an instance of DataType.")

        return Basic.__new__(cls, shape, dtype)
<commit_msg>fix bug shape in numpy<commit_after># coding: utf-8

# TODO remove sympify, Symbol
import numpy
from sympy.core.function import Function
from sympy.core import Symbol, Tuple
from sympy import sympify
from sympy.core.basic import Basic
from sympy.utilities.iterables import iterable
from sympy.logic.boolalg import Boolean, BooleanTrue, BooleanFalse

from .core import Variable, IndexedElement, IndexedVariable,List
from .core import DataType, datatype
from .core import (NativeInteger, NativeFloat, NativeDouble, NativeComplex,
                   NativeBool, String)


class Array(Function):
    """Represents a call to  numpy.array for code generation.

    ls : list ,tuple ,Tuple,List
    """
    def __new__(cls, ls, dtype=None):
        if not isinstance(ls,(list,tuple,Tuple,List) ):
            raise TypeError("Uknown type of  %s." % type(ls))
        if isinstance(dtype, str):
            dtype = datatype('ndarray'+dtype)

        return Basic.__new__(cls, ls, dtype)

    def _sympystr(self, printer):
        sstr = printer.doprint
        return self.ls
     
    
    @property
    def ls(self):
        return self._args[0]
    
    @property
    def dtype(self):
        return self._args[1]
    
    @property
    def shape(self):
        return Tuple(*numpy.shape(self._args[0]))

    @property
    def rank(self):
        return len(self.shape) 
    
    def fprint(self, printer, lhs):
        """Fortran print."""
        if isinstance(self.shape, (Tuple,tuple)):
        # this is a correction. problem on LRZ
            shape_code = ', '.join('0:' + printer(i-1) for i in self.shape)
        else:
            shape_code = '0:' + printer(self.shape-1)
        lhs_code = printer(lhs)

        code_alloc = "allocate({0}({1}))".format(lhs_code, shape_code)
        init_value = printer(self.ls)
        code_init = "{0} = {1}".format(lhs_code, init_value)
        code = "{0}\n{1}".format(code_alloc, code_init)

        return code


class Shape(Array):
    """Represents a call to  numpy.shape for code generation.

    ls : list ,tuple ,Tuple,List, Variable
    """
    def __new__(cls, ls):
        if not isinstance(ls,(list,tuple,Tuple,List,Array, Variable) ):
            raise TypeError("Uknown type of  %s." % type(ls))
        return Basic.__new__(cls, ls)

    @property
    def ls(self):
        return self._args[0]
    
    @property
    def dtype(self):
        return 'ndarrayint'
    
    @property
    def shape(self):
        return Tuple(self.ls.rank,)

    @property
    def rank(self):
        return 1 
  
    def fprint(self, printer, lhs):
        """Fortran print."""
 
        lhs_code = printer(lhs)
        if isinstance(self.ls, Array):
           init_value = printer(self.ls.ls)
        else:
           init_value = printer(self.ls)
        code_init = "{0} = shape({1})".format(lhs_code, init_value)
        
        return code_init


class Int(Function):
    """Represents a call to  numpy.int for code generation.

    arg : Variable,Float,Integer
    """
    def __new__(cls, arg):
        if not isinstance(arg,(Variable,NativeInteger, NativeFloat, NativeDouble, NativeComplex)):
            raise TypeError("Uknown type of  %s." % type(ls))
        return Basic.__new__(cls, arg)

    @property
    def arg(self):
        return self._args[0]
    
    @property
    def dtype(self):
        return 'int'
    
    @property
    def shape(self):
        return None

    @property
    def rank(self):
        return 0 
    
    def fprint(self, printer, lhs):
        """Fortran print."""
        lhs_code = printer(lhs)
        init_value = printer(self.arg)
        code = "{0} = Int({1})".format(lhs_code, init_value)
        return code



class Zeros(Function):
    """Represents a call to numpy.zeros for code generation.

    shape : int, list, tuple
        int or list of integers

    dtype: str, DataType
        datatype for the constructed array

    Examples

    """
    # TODO improve
    def __new__(cls, shape, dtype=None):

        if isinstance(shape, list):
            # this is a correction. otherwise it is not working on LRZ
            if isinstance(shape[0], list):
                shape = Tuple(*(sympify(i) for i in shape[0]))
            else:
                shape = Tuple(*(sympify(i) for i in shape))
        elif isinstance(shape, int):
            shape = Tuple(sympify(shape))
        else:
            shape = shape

        if dtype is None:
            dtype = String('double')

        if isinstance(dtype, String):
            dtype = datatype('ndarray'+dtype.arg.replace('\'', ''))
        elif not isinstance(dtype, DataType):
            raise TypeError("datatype must be an instance of DataType.")

        return Basic.__new__(cls, shape, dtype)

{'fraction_non_alphanumeric': 0.11294910968285744, 'fraction_numerical': 0.005057422821620482, 'mean_word_length': 2.258496395468589, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1035404', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2829, 'n_words': 804}