Skip to content

[BUG] np.average with weights fails #106

Description

@dlakaplan
import numpy_quaddtype
x=numpy_quaddtype.QuadPrecision([1,2,3])
y=numpy_quaddtype.QuadPrecision([2,2.5,2.3])
np.average(x,weights=1/y)

fails:

File ~/miniforge3/envs/pintdev_arm/lib/python3.14/site-packages/numpy/lib/_function_base_impl.py:587, in average(a, axis, weights, returned, keepdims)
    584 else:
    585     result_dtype = np.result_type(a.dtype, wgt.dtype)
--> 587 scl = wgt.sum(axis=axis, dtype=result_dtype, **keepdims_kw)
    588 if np.any(scl == 0.0):
    589     raise ZeroDivisionError(
    590         "Weights sum to zero, can't be normalized")

File ~/miniforge3/envs/pintdev_arm/lib/python3.14/site-packages/numpy/_core/_methods.py:49, in _sum(a, axis, dtype, out, keepdims, initial, where)
     47 def _sum(a, axis=None, dtype=None, out=None, keepdims=False,
     48          initial=_NoValue, where=True):
---> 49     return umr_sum(a, axis, dtype, out, keepdims, initial, where)

TypeError: Cannot pass a new user DType instance to the `dtype` or `signature` arguments of ufuncs. Pass the DType class instead.

Without the weights argument this works OK.

Activity

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

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