Skip to content

user_type scalars have array-like functionality, and it's weird #520

Open
@ofloveandhate

Description

@ofloveandhate

In the EigenPy user_type that's compiled and tested as part of eigenpy, the scalar types end up having numpy-array-like functions, which is weird.

For example,

import user_type
a = user_type.CustomDouble(1) # makes a scalar.  

dir(a) # reveals a ton of functionality that I wouldn't expect for a scalar

For example, we get .flatten, .prod and .cumsum. This seems weird to me. Like, I don't think a Scalar should have these properties. Furthermore, many of these functions produce errors when called.

a.std() # error!

produces the following error message:

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
Cell In[12], line 1
----> 1 a.std()

File ~/env/b2/lib/python3.12/site-packages/numpy/_core/_methods.py:227, in _std(a, axis, dtype, out, ddof, keepdims, where, mean)
    225 def _std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *,
    226          where=True, mean=None):
--> 227     ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
    228                keepdims=keepdims, where=where, mean=mean)
    230     if isinstance(ret, mu.ndarray):
    231         ret = um.sqrt(ret, out=ret)

File ~/env/b2/lib/python3.12/site-packages/numpy/_core/_methods.py:173, in _var(a, axis, dtype, out, ddof, keepdims, where, mean)
    168     arrmean = mean
    169 else:
    170     # Compute the mean.
    171     # Note that if dtype is not of inexact type then arraymean will
    172     # not be either.
--> 173     arrmean = umr_sum(arr, axis, dtype, keepdims=True, where=where)
    174     # The shape of rcount has to match arrmean to not change the shape of
    175     # out in broadcasting. Otherwise, it cannot be stored back to arrmean.
    176     if rcount.ndim == 0:
    177         # fast-path for default case when where is True

SystemError: <built-in method reduce of numpy.ufunc object at 0x10768ac40> returned NULL without setting an exception

What am I not understanding? Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions