question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with array creation functions

See original GitHub issue

Some 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 is None, 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

full (and full_like)

  • Says “If dtype is None, 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:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
shoyercommented, Jan 30, 2021

A few other suggestions:

  • To resurface concerns from https://github.com/data-apis/array-api/issues/85:
    • Why allow shape arguments to be passed as keyword arguments, too? This is a pretty unambiguous name, and code can be clearer when it uses names.
    • Likewise, could num be allowed as a keyword for linespace and fill_value be allowed as a keyword for full/full_like?
  • empty and empty_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.
0reactions
rgommerscommented, May 1, 2021

That looks like a clear bug, not even a subtle one. The integer start point and step size calculation should just not use floats.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found