You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if that is a bug or a feature, but passing a 2D array that is both Fortran and C contiguous will fail if the signature expected a Fortran-aligned array:
fromnumbaimportjitclass, uint8importnumpyasnp@jitclass([ ('X', uint8[::1, :]), # fortran aligned array])classClass:
def__init__(self, X):
self.X=X# F contiguous, not C contiguousX=np.arange(10).reshape(2, 5).astype(np.uint8)
X=np.asfortranarray(X)
assertnotX.flags['C_CONTIGUOUS']
assertX.flags['F_CONTIGUOUS']
Class(X) # OKX=np.arange(10).reshape(10, 1).astype(np.uint8)
assertX.flags['C_CONTIGUOUS']
assertX.flags['F_CONTIGUOUS']
Class(X) # fails
Traceback (most recent call last):
File "numba_lol.py", line 21, in <module>
Class(X) # fails
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/jitclass/base.py", line 123, in __call__
return cls._ctor(*args, **kwargs)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/dispatcher.py", line 348, in _compile_for_args
error_rewrite(e, 'typing')
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/dispatcher.py", line 315, in error_rewrite
reraise(type(e), e, None)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/six.py", line 658, in reraise
raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.typeinfer.CallConstraint object at 0x7fe5fa702160>:
--%<----------------------------------------------------------------------------
Traceback (most recent call last):
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/errors.py", line 599, in new_error_context
yield
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/lowering.py", line 254, in lower_block
self.lower_inst(inst)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/lowering.py", line 393, in lower_inst
signature.args[1])
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/targets/base.py", line 677, in cast
return impl(self, builder, fromty, toty, val)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/targets/arrayobj.py", line 4673, in array_to_array
assert fromty.mutable != toty.mutable or toty.layout == 'A'
AssertionError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/typeinfer.py", line 142, in propagate
constraint(typeinfer)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/typeinfer.py", line 423, in __call__
self.resolve(typeinfer, typevars, fnty)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/typeinfer.py", line 450, in resolve
literals=literals)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/typeinfer.py", line 1173, in resolve_call
literals=literals)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/typing/context.py", line 211, in resolve_function_type
return func.get_call_type_with_literals(self, args, kws, literals)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/types/abstract.py", line 268, in get_call_type_with_literals
return self.get_call_type(context, args, kws)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/types/misc.py", line 375, in get_call_type
return self.ctor_template(context).apply(args, kws)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/typing/templates.py", line 207, in apply
sig = generic(args, kws)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/jitclass/base.py", line 240, in generic
sig = disp_type.get_call_type(self.context, boundargs, kws)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/types/functions.py", line 258, in get_call_type
template, pysig, args, kws = self.dispatcher.get_call_template(args, kws)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/dispatcher.py", line 272, in get_call_template
self.compile(tuple(args))
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/dispatcher.py", line 655, in compile
cres = self._compiler.compile(args, return_type)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/dispatcher.py", line 82, in compile
pipeline_class=self.pipeline_class)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler.py", line 904, in compile_extra
return pipeline.compile_extra(func)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler.py", line 367, in compile_extra
return self._compile_bytecode()
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler.py", line 835, in _compile_bytecode
return self._compile_core()
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler.py", line 822, in _compile_core
res = pm.run(self.status)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler.py", line 253, in run
raise patched_exception
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler.py", line 244, in run
stage()
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler.py", line 696, in stage_nopython_backend
self._backend(lowerfn, objectmode=False)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler.py", line 646, in _backend
lowered = lowerfn()
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler.py", line 633, in backend_nopython_mode
self.flags)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/compiler.py", line 1023, in native_lowering_stage
lower.lower()
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/lowering.py", line 173, in lower
self.lower_normal_function(self.fndesc)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/lowering.py", line 214, in lower_normal_function
entry_block_tail = self.lower_function_body()
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/lowering.py", line 239, in lower_function_body
self.lower_block(block)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/lowering.py", line 254, in lower_block
self.lower_inst(inst)
File "/usr/lib64/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/errors.py", line 607, in new_error_context
six.reraise(type(newerr), newerr, tb)
File "/home/nico/.virtualenvs/pygbm/lib/python3.7/site-packages/numba/six.py", line 659, in reraise
raise value
numba.errors.LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
File "numba_lol.py", line 9:
def __init__(self, X):
self.X = X
^
[1] During: lowering "(self).X = X" at numba_lol.py (9)
[2] During: resolving callee type: jitclass.Class#55644369be18<X:array(uint8, 2d, F)>
[3] During: typing of call at <string> (3)
--%<----------------------------------------------------------------------------
The text was updated successfully, but these errors were encountered:
I think this is a bug (or a limitation of the type system). As the example shows, being C-contiguous or F-contiguous is not exclusive for numpy arrays.
Thanks for the report. I think this is a limitation, the typing mech at present requires types inheriting from buffer protocol to have a single layout, one of LAYOUTS = frozenset(['C', 'F', 'CS', 'FS', 'A']), with preference given to C based layouts.
Reproducer with no jitclass:
fromnumbaimportnjit, float64, typeofimportnumpyasnp@njit([float64(float64[::1, :]),])deffoo(x):
returnx[0, 0]
# F contiguous, not C contiguousX=np.arange(10.).reshape(2, 5)
X=np.asfortranarray(X)
print(typeof(X))
assertnotX.flags['C_CONTIGUOUS']
assertX.flags['F_CONTIGUOUS']
foo(X) # OKX=np.arange(10.).reshape(10, 1)
print(typeof(X))
assertX.flags['C_CONTIGUOUS']
assertX.flags['F_CONTIGUOUS']
foo(X) # fails
Reporting a bug
the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).
I'm not sure if that is a bug or a feature, but passing a 2D array that is both Fortran and C contiguous will fail if the signature expected a Fortran-aligned array:
The text was updated successfully, but these errors were encountered: