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

unable to compute vector norms using custom numeric type #521

Closed
ofloveandhate opened this issue Dec 18, 2024 · 3 comments
Closed

unable to compute vector norms using custom numeric type #521

ofloveandhate opened this issue Dec 18, 2024 · 3 comments

Comments

@ofloveandhate
Copy link

For the custom numeric type (mpfr complex, mpfr reals) I've implement in my pull request for the example #370 , I am unable to easily compute norms of vectors or matrices.


np.array( np.zeros( (3)).astype(np.int64),dtype=dtype)
np.norm(A)

fails with error message

TypeError: Cannot cast array data from dtype(MpfrComplex) to dtype('float64') according to the rule 'unsafe'

This sounds un-solvable, since I cannot convert my multiprecision complex numbers to float64.


As an alternative to using np.norm, I switched to

np.sqrt(np.sum((A)**2)

This fails with error message

 TypeError: ufunc 'square' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

That is, EigenPy doesn't provide the square ufunc, but it should.

(I still need to push the changes in my custom numeric type example, and I've added pytest unit tests for the example which help probe failing functionality)

ofloveandhate added a commit to ofloveandhate/eigenpy that referenced this issue Dec 18, 2024
much of the functions I added were me trying to get Python to crash in a specific way.  I failed, which is a good thing, because it means that EigenPy doesn't have the bug I thought it does.

BUT.  EigenPy *does* have two issues exercised in the unit tests for the custom type, issues stack-of-tasks#519  and stack-of-tasks#520 .  Additionally, this code exercises issue stack-of-tasks#521 , where I try to compute vector norms in two different ways and fail.

Additionally, I bumped the C++ standard to C++14, since Boost 1.87 didn't work correctly with only C++11, and 1.87 is now distributed by homebrew (I develop on a Mac)
@jcarpent
Copy link
Contributor

jcarpent commented Jan 9, 2025

I've solved the issue in #525

@jcarpent
Copy link
Contributor

jcarpent commented Jan 9, 2025

np.array( np.zeros( (3)).astype(np.int64),dtype=dtype)
np.norm(A)

fails with error message

TypeError: Cannot cast array data from dtype(MpfrComplex) to dtype('float64') according to the rule 'unsafe'

This sounds un-solvable, since I cannot convert my multiprecision complex numbers to float64.

For this part of the issue, the error is coming from NumPy directly. Their strategy does not apply for custom types.

@jcarpent
Copy link
Contributor

Solved via #525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants