Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The integer dtype used in array constructors need not be restricted to intp #2758

Closed
stuartarchibald opened this issue Feb 16, 2018 · 1 comment
Labels

Comments

@stuartarchibald
Copy link
Contributor

This:

import numpy as np
from numba import njit

def foo():
    sz = np.int8(2)
    return np.zeros((sz, sz))

print(foo())
print(njit(foo)())

gives:

array([[ 0.,  0.],
       [ 0.,  0.]])
<traceback omitted>
LoweringError: Failed at nopython (nopython mode backend)
Operands must be the same type, got (i64, i8)

the root cause is a type mismatch in builder.mul as the arrlen const is fixed to types.intp:

# compute array length
arrlen = context.get_constant(types.intp, 1)
for s in shapes:
arrlen = builder.mul(arrlen, s)

and is probably fixable by obtaining the type(s) in the shape tuple here,

def _parse_shape(context, builder, ty, val):
and returning it as part of:
def _parse_empty_args(context, builder, sig, args):
"""
Parse the arguments of a np.empty(), np.zeros() or np.ones() call.
"""
arrshapetype = sig.args[0]
arrshape = args[0]
arrtype = sig.return_type
return arrtype, _parse_shape(context, builder, arrshapetype, arrshape)

and doing an appropriate cast to types.intp in the loop above that accumulates arrlen.

@stuartarchibald
Copy link
Contributor Author

Closing, fixed by #4729

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant