Skip to content

BUG: branch choices for geomspace on complex arguments #25644

@mcabbott

Description

@mcabbott

Describe the issue:

The docs for np.geomspace state:

If the inputs or dtype are complex, the output will follow a logarithmic spiral in the complex plane. (There are an infinite number of spirals passing through two points; the output will follow the shortest such path.)

But the function does not appear to obey this rule. I'm not sure how it is in fact choosing branch cuts.

Searching a bit, this may be altered by #25441 but I believe that is not in any released version yet.

Reproduce the code example:

import numpy as np

np.geomspace(-1j, 0.001 + 1j, 5)   # semicircle to the right, via +1
np.geomspace(-1j, -0.001 + 1j, 5)  # semicircle to the left, via -1, as documented

x = 1.2 + 3.4j  # also x = 1+1j
delta = 0.01j
np.geomspace(x, -x + delta, 5)  # crosses real line near 3.5, middle point 3.4-1.2j
np.geomspace(x, -x - delta, 5)  # goes the same way!

Error message:

No error message. Numerical result is:

>>> x = 1.2 + 3.4j  # also x = 1+1j
>>> delta = 0.01j
>>> np.geomspace(x, -x + delta, 5)  # crosses real line near 3.5, middle point 3.4-1.2j
array([ 1.2       +3.4j       ,  3.2509223 +1.5538648j ,
        3.39499673-1.20000116j,  1.55032927-3.24738677j,
       -1.2       -3.39j      ])
>>> np.geomspace(x, -x - delta, 5)  # goes the same way!
array([ 1.2       +3.4j       ,  3.25445784+1.55740034j,
        3.40499673-1.20000115j,  1.56093588-3.25799337j,
       -1.2       -3.41j      ])

Python and NumPy Versions:

1.26.3
3.11.7 (main, Jan 16 2024, 14:42:22) [Clang 14.0.0 (clang-1400.0.29.202)]

Runtime Environment:

[{'numpy_version': '1.26.3',
  'python': '3.11.7 (main, Jan 16 2024, 14:42:22) [Clang 14.0.0 '
            '(clang-1400.0.29.202)]',
  'uname': uname_result(system='Darwin', node='ArmBook.local', release='21.6.0', version='Darwin Kernel Version 21.6.0: Sun Nov  6 23:29:57 PST 2022; root:xnu-8020.240.14~1/RELEASE_ARM64_T8101', machine='arm64')},
 {'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
                      'found': ['ASIMDHP'],
                      'not_found': ['ASIMDFHM']}},
 {'architecture': 'armv8',
  'filepath': '/opt/homebrew/lib/python3.11/site-packages/numpy/.dylibs/libopenblas64_.0.dylib',
  'internal_api': 'openblas',
  'num_threads': 8,
  'prefix': 'libopenblas',
  'threading_layer': 'pthreads',
  'user_api': 'blas',
  'version': '0.3.23.dev'}]
None

Context for the issue:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions