Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions numba/core/typing/npydecl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,50 +1139,3 @@ def generic(self, args, kws):
return None

return signature(retty, *args)

# -----------------------------------------------------------------------------
# Numba helpers

@glue_typing(carray)
class NumbaCArray(CallableTemplate):
layout = 'C'

def generic(self):
func_name = self.key.__name__

def typer(ptr, shape, dtype=None):
if ptr is types.voidptr:
ptr_dtype = None
elif isinstance(ptr, types.CPointer):
ptr_dtype = ptr.dtype
else:
raise NumbaTypeError("%s(): pointer argument expected, got '%s'"
% (func_name, ptr))

if dtype is None:
if ptr_dtype is None:
raise NumbaTypeError("%s(): explicit dtype required for void* argument"
% (func_name,))
dtype = ptr_dtype
elif isinstance(dtype, types.DTypeSpec):
dtype = dtype.dtype
if ptr_dtype is not None and dtype != ptr_dtype:
raise NumbaTypeError("%s(): mismatching dtype '%s' for pointer type '%s'"
% (func_name, dtype, ptr))
else:
raise NumbaTypeError("%s(): invalid dtype spec '%s'"
% (func_name, dtype))

ndim = parse_shape(shape)
if ndim is None:
raise NumbaTypeError("%s(): invalid shape '%s'"
% (func_name, shape))

return types.Array(dtype, ndim, self.layout)

return typer


@glue_typing(farray)
class NumbaFArray(NumbaCArray):
layout = 'F'
75 changes: 70 additions & 5 deletions numba/np/arrayobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -3967,7 +3967,8 @@ def _empty_nd_impl(context, builder, arrtype, shapes):

@overload_classmethod(types.Array, "_allocate")
def _ol_array_allocate(cls, allocsize, align):
"""Implements a Numba-only default target (cpu) classmethod on the array type.
"""Implements a Numba-only default target (cpu) classmethod on the array
type.
"""
def impl(cls, allocsize, align):
return intrin_alloc(allocsize, align)
Expand Down Expand Up @@ -4805,10 +4806,74 @@ def np_frombuffer(context, builder, sig, args):
return impl_ret_borrowed(context, builder, sig.return_type, res)


@glue_lowering(carray, types.Any, types.Any)
@glue_lowering(carray, types.Any, types.Any, types.DTypeSpec)
@glue_lowering(farray, types.Any, types.Any)
@glue_lowering(farray, types.Any, types.Any, types.DTypeSpec)
@overload(carray)
def impl_carray(ptr, shape, dtype=None):
if is_nonelike(dtype):
intrinsic_cfarray = get_cfarray_intrinsic('C', None)

def impl(ptr, shape, dtype=None):
return intrinsic_cfarray(ptr, shape)
return impl
elif isinstance(dtype, types.DTypeSpec):
intrinsic_cfarray = get_cfarray_intrinsic('C', dtype)

def impl(ptr, shape, dtype=None):
return intrinsic_cfarray(ptr, shape)
return impl


@overload(farray)
def impl_farray(ptr, shape, dtype=None):
if is_nonelike(dtype):
intrinsic_cfarray = get_cfarray_intrinsic('F', None)

def impl(ptr, shape, dtype=None):
return intrinsic_cfarray(ptr, shape)
return impl
elif isinstance(dtype, types.DTypeSpec):
intrinsic_cfarray = get_cfarray_intrinsic('F', dtype)

def impl(ptr, shape, dtype=None):
return intrinsic_cfarray(ptr, shape)
return impl


def get_cfarray_intrinsic(layout, dtype_):
@intrinsic
def intrinsic_cfarray(typingctx, ptr, shape):
if ptr is types.voidptr:
ptr_dtype = None
elif isinstance(ptr, types.CPointer):
ptr_dtype = ptr.dtype
else:
msg = f"pointer argument expected, got '{ptr}'"
raise errors.NumbaTypeError(msg)

if dtype_ is None:
if ptr_dtype is None:
msg = "explicit dtype required for void* argument"
raise errors.NumbaTypeError(msg)
dtype = ptr_dtype
elif isinstance(dtype_, types.DTypeSpec):
dtype = dtype_.dtype
if ptr_dtype is not None and dtype != ptr_dtype:
msg = f"mismatching dtype '{dtype}' for pointer type '{ptr}'"
raise errors.NumbaTypeError(msg)
else:
msg = f"invalid dtype spec '{dtype_}'"
raise errors.NumbaTypeError(msg)

ndim = ty_parse_shape(shape)
if ndim is None:
msg = f"invalid shape '{shape}'"
raise errors.NumbaTypeError(msg)

retty = types.Array(dtype, ndim, layout)
sig = signature(retty, ptr, shape)
return sig, np_cfarray
return intrinsic_cfarray


def np_cfarray(context, builder, sig, args):
"""
numba.numpy_support.carray(...) and
Expand Down