Skip to content

BUG: Ensure non-array logspace base does not influence dtype of output.#25919

Merged
rgommers merged 1 commit intonumpy:mainfrom
mhvk:logspace-broadcast-only-arrays
Mar 4, 2024
Merged

BUG: Ensure non-array logspace base does not influence dtype of output.#25919
rgommers merged 1 commit intonumpy:mainfrom
mhvk:logspace-broadcast-only-arrays

Conversation

@mhvk
Copy link
Contributor

@mhvk mhvk commented Mar 3, 2024

Fixes gh-24957

@mhvk mhvk added this to the 2.0.0 release milestone Mar 3, 2024
@mhvk mhvk requested a review from seberg March 3, 2024 16:21
@tylerjereddy tylerjereddy changed the title BUG: Ensuse non-array logspace base does not influence dtype of output. BUG: Ensure non-array logspace base does not influence dtype of output. Mar 3, 2024
@rgommers
Copy link
Member

rgommers commented Mar 3, 2024

Thanks @mhvk!

The CircleCI failure is related:

numpy.logspace
--------------

File "venv/lib/python3.11/site-packages/numpy/__init__.py", line ?, in logspace
Failed example:
    np.logspace(2.0, 3.0, num=4, base=[2.0, 3.0], axis=-1)
Exception raised:
    Traceback (most recent call last):
      File "/home/circleci/.pyenv/versions/3.11.4/lib/python3.11/doctest.py", line 1351, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest logspace[5]>", line 1, in <module>
        np.logspace(2.0, 3.0, num=4, base=[2.0, 3.0], axis=-1)
      File "/home/circleci/repo/venv/lib/python3.11/site-packages/numpy/_core/function_base.py", line 312, in logspace
        return _nx.power(base, y)
               ^^^^^^^^^^^^^^^^^^
    ValueError: operands could not be broadcast together with shapes (2,) (4,)

@mhvk mhvk force-pushed the logspace-broadcast-only-arrays branch from 9d99f6e to 136b9ed Compare March 3, 2024 19:02
@mhvk
Copy link
Contributor Author

mhvk commented Mar 3, 2024

OK, hopefully fixed now...

@mhvk
Copy link
Contributor Author

mhvk commented Mar 3, 2024

The freebsd failure is unrelated, so this should be all OK now.

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix @mhvk!

@rgommers rgommers merged commit 9d69a62 into numpy:main Mar 4, 2024
@seberg
Copy link
Member

seberg commented Mar 4, 2024

Thanks, it's not actually quite right, because we are not dealing with the other arguments being scalars. But at least it fixes the bigger problem.

@mhvk
Copy link
Contributor Author

mhvk commented Mar 4, 2024

@seberg - ah, yes, I thought about doing it after the linspace call, but then one has to deal with the fact that axis gets applied differently... Probably would have been better to use your array_converter or so, and use that to calculate the dtype first.

@mhvk mhvk deleted the logspace-broadcast-only-arrays branch March 4, 2024 13:03
@seberg
Copy link
Member

seberg commented Mar 4, 2024

Yeah, array-converter should help a bit, but it simply is tedious. The reason is that base can be the only array in which case you need to broadcast the linspace result manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: incorrect promotion of scalars in logspace

3 participants