Issues with array creation functions
See original GitHub issueSome issues I noticed in the array creation functions from adding tests to the test suite:
arange
- stop and step should not be keyword-only (this was also mentioned at https://github.com/data-apis/array-api/issues/85)
- Does not specify the behavior if stop or start are out of range for the dtype
- Says “If
dtype
isNone
, the output array data type must be the default floating-point data type.” I think the default for arange should be int if all the arguments are integers. step
cannot be 0.- The function is only defined for numeric dtypes (https://github.com/data-apis/array-api/issues/98)
- “The length of the output array must be
ceil((stop-start)/step)
” should be caveated (stop and step provided, stop >= start for step > 0 and stop <= start for step < 0)
eye
- May be worth explicitly saying elements with index i, j should be 1 if j - i = k and 0 otherwise.
- The function is only defined for numeric dtypes (https://github.com/data-apis/array-api/issues/98)
full (and full_like)
- Says “If
dtype
isNone
, the output array data type must be the default floating-point data type.” I think the default should be a corresponding dtype to the input value (we don’t have a notion of a “default” integer dtype).
linspace
- It’s a bit ambiguous whether it actually says this right now, but I think the stop value should not be required to be included (when endpoint=True). Consider
>>> np.linspace(0, 9288674231451855, 2, dtype=np.int64)
array([ 0, 9288674231451856])
The stop value is different from what is given because of floating point loss of precision when computing the linspace.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Array Creation - Problem Solving with Python
NumPy arrays are created with the np.array() function. The arguments provided to np.array() needs to be a list or iterable. An example is...
Read more >Array creation and __array_function__ · Issue #4883 ... - GitHub
One of the issues that arise when introducing __array_function__ in a NumPy-like library, such as Dask, is array creation. Many functions ...
Read more >Numpy Array creation problems in class method
To generate the vx matrix, I have tried a variety of different things in numpy such as np.asarray, np.vstack, np.array with and without ......
Read more >7.7. Arrays And Functions
C++ programmers can create multi-dimensional arrays the way that Java programs always do: by creating arrays of arrays with the new operator. The...
Read more >NumPy Array Creation - Scaler Topics
Make use of different operations and functions to structure the different NumPy arrays according to our needs, like reshaping and flattening.
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 FreeTop 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
Top GitHub Comments
A few other suggestions:
shape
arguments to be passed as keyword arguments, too? This is a pretty unambiguous name, and code can be clearer when it uses names.num
be allowed as a keyword forlinespace
andfill_value
be allowed as a keyword forfull
/full_like
?empty
andempty_like
may not necessarily make sense for libraries that do not support mutation (e.g., JAX, Dask, TensorFlow) It might be worth calling this out.That looks like a clear bug, not even a subtle one. The integer start point and step size calculation should just not use floats.