Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Raising scipy.spatial.transform.Rotation to power of 0 adds dimension to underlying numpy.array #20188

Closed
allanerlang opened this issue Mar 5, 2024 · 3 comments · Fixed by #20191
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.spatial
Milestone

Comments

@allanerlang
Copy link

Describe your issue.

If I define a scipy.spatial.transform.Rotation and return it as e.g. a quaternion, I get it as a numpy.array of shape (4,). But if I raise it to the zeroth power and return as a quaternion again, I now receive a numpy.array of shape (1,4). The same thing happens for all as_*() member functions.
Is this intended, and if so, why?

Reproducing Code Example

r = Rotation.from_quat([0, 0, 0, 1])
r.as_quat().shape
(4,)
(r**0).as_quat().shape
(1,4)

Error message

Not any

SciPy/NumPy/Python version and system information

1.12.0 1.26.2 sys.version_info(major=3, minor=12, micro=0, releaselevel='final', serial=0)
Build Dependencies:
  blas:
    detection method: pkgconfig
    found: true
    include directory: /usr/local/include
    lib directory: /usr/local/lib
    name: openblas
    openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
      NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= HASWELL MAX_THREADS=2
    pc file directory: /usr/local/lib/pkgconfig
    version: 0.3.21.dev
  lapack:
    detection method: pkgconfig
    found: true
    include directory: /usr/local/include
    lib directory: /usr/local/lib
    name: openblas
    openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
      NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= HASWELL MAX_THREADS=2
    pc file directory: /usr/local/lib/pkgconfig
    version: 0.3.21.dev
  pybind11:
    detection method: config-tool
    include directory: unknown
    name: pybind11
    version: 2.11.1
Compilers:
  c:
    commands: cc
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  c++:
    commands: c++
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  cython:
    commands: cython
    linker: cython
    name: cython
    version: 3.0.8
  fortran:
    commands: gfortran
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  pythran:
    include directory: ../../tmp/pip-build-env-tfqmvy7q/overlay/lib/python3.12/site-packages/pythran
    version: 0.15.0
Machine Information:
  build:
    cpu: x86_64
    endian: little
    family: x86_64
    system: linux
  cross-compiled: false
  host:
    cpu: x86_64
    endian: little
    family: x86_64
    system: linux
Python Information:
  path: /opt/python/cp312-cp312/bin/python
  version: '3.12'
@allanerlang allanerlang added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label Mar 5, 2024
@j-bowhay
Copy link
Member

j-bowhay commented Mar 5, 2024

@scottshambaugh would you be interested in having a look at this?

@allanerlang
Copy link
Author

allanerlang commented Mar 5, 2024

It seems to be this line that causes the change in dimension:
if n == 0: return Rotation.identity(len(self._quat))
Changing the code to something along the lines of
if n == 0: return Rotation.identity(0 if self._single else len(self._quat))
should do the trick, but there is probably a better solution.

@scottshambaugh
Copy link
Contributor

Hey @allanerlang good catch! And your solution is pretty much perfect, except that None is the arg to pass in instead of 0 to get a single identity rotation. PR is open to fix this and test this category of error.

@j-bowhay j-bowhay added this to the 1.13.0 milestone Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.spatial
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants