Implement np.shape for nestedarray
See original GitHub issueFeature request
numba currently (0.54.1) doesn’t implement np.shape for nestedarrays from numpy record types. Support for this would simplify some generic code a little bit.
import numba
import numpy as np
dtype = np.dtype([
("a", np.float64, (10,))
])
data = np.zeros((), dtype=dtype)[()]
@numba.njit
def foo(data):
#return data.a.shape # this works
return np.shape(data.a)
foo(data) # Throws a TypeError
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function shape at 0x7fb0b028e430>) found for signature:
>>> shape(nestedarray(float64, (10,)))
There are 2 candidate implementations:
- Of which 2 did not match due to:
Overload in function 'np_shape': File: numba/np/arrayobj.py: Line 1981.
With argument(s): '(nestedarray(float64, (10,)))':
Rejected as the implementation raised a specific error:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function asarray at 0x7fb0b026a040>) found for signature:
>>> asarray(nestedarray(float64, (10,)))
There are 2 candidate implementations:
- Of which 2 did not match due to:
Overload in function 'np_asarray': File: numba/np/arraymath.py: Line 4196.
With argument(s): '(nestedarray(float64, (10,)))':
Rejected as the implementation raised a specific error:
LoweringError: Failed in nopython mode pipeline (step: native lowering)
Can only insert double at [0] in [10 x double]: got i8*
File "../../../miniconda3/envs/aesara-numba/lib/python3.9/site-packages/numba/np/arraymath.py", line 4208:
def impl(a, dtype=None):
return a
^
During: lowering "return $4return_value.1" at /home/anna/miniconda3/envs/aesara-numba/lib/python3.9/site-packages/numba/np/arraymath.py (4208)
raised from /home/anna/miniconda3/envs/aesara-numba/lib/python3.9/site-packages/numba/core/errors.py:786
During: resolving callee type: Function(<function asarray at 0x7fb0b026a040>)
During: typing of call at /home/anna/miniconda3/envs/aesara-numba/lib/python3.9/site-packages/numba/np/arrayobj.py (1987)
File "../../../miniconda3/envs/aesara-numba/lib/python3.9/site-packages/numba/np/arrayobj.py", line 1987:
def impl(a):
return np.asarray(a).shape
^
raised from /home/anna/miniconda3/envs/aesara-numba/lib/python3.9/site-packages/numba/core/typeinfer.py:1074
During: resolving callee type: Function(<function shape at 0x7fb0b028e430>)
During: typing of call at /tmp/ipykernel_17638/1962980170.py (14)
File "../../../../../tmp/ipykernel_17638/1962980170.py", line 14:
<source missing, REPL/exec in use?>
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to Get NumPy Array Shape? - Spark by {Examples}
To get the shape of a Python NumPy array use numpy.ndarray.shape property. The array shape can be defined as the number of elements...
Read more >How to Convert From Numpy Array to List - Sharp Sight
This tutorial will show you how to convert from Numpy array to list. It shows the syntax of the .tolist() function, and clear...
Read more >NumPy Array Shape - GeeksforGeeks
In NumPy we will use an attribute called shape which returns a tuple, the elements of the tuple give the lengths of the...
Read more >Array model - APL Wiki
An array's shape is then a vector whose elements are axis lengths, ... In nested array theory the elements can only be arrays, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

With #7359, the following:
prints
So I think this will be resolved by #7359.
That sounds great, thanks for testing! I wanted to test it for a while but did not actually get around to do so.
I will try with my use cases and get back to you.