pyccel
pyccel copied to clipboard
np.array chooses wrong dtype
Describe the bug np.array chooses wrong dtype from its arguments
To Reproduce Provide code to reproduce the behavior:
@types('int8', 'int8')
def return_array(a, b):
from numpy import array
x = array([a,b])
return x[0]
The return type is int64
, but it should be int8
Workaround
@types('int8', 'int8')
def return_array(a, b):
from numpy import array
x = array([a,b], dtype=type(a))
return x[0]
Beware when debugging. int8
has precision=1
, int64
has precision=8
Sorry if I interpreted it wrong I am a beginner in python. ( I don't know why @types is giving errors( i am attaching screenshots))
The code below is giving correct output
import numpy as np
x=np.int8(3)
y=np.int8(4)
def return_array(a, b):
from numpy import array
x = array([a,b], dtype=type(a))
return x[0]
print(type(return_array(x,y)))
Output is : <class 'numpy.int8'>
Code output ss:-
Error ss : -
You have an error because you haven't imported the types
decorator:
from pyccel.decorators import types
Pyccel doesn't care about this as we haven't found a simple way to follow python conventions and still be able to use epyccel on a function