You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to write some functions to do some financial math using this combination of ndarray and this other crate moneta1.
Divisions turn out to be a bit of a problem. As I understand it, impl_binary_ops forces Output to be of the same type as Rhs.2 However, this is not really true for monetary values (or any quantity really).3
The first test works and shows the common case dividing 2 monetary values, which returns a ratio, a plain amount with no currency. Dividing a money value by an amount would instead return another monetary value.4
The second fails to compile with error:
error[E0277]: cannot divide `&ArrayBase<OwnedRepr<Money>, Dim<[usize; 1]>>` by `&ArrayBase<OwnedRepr<Money>, Dim<[usize; 1]>>`
--> tests/test_ndarray.rs:27:23
|
27 | assert_eq!(&a / &b, array![Dec!(10), Dec!(32), Dec!(0.25)]);
| ^ no implementation for `&ArrayBase<OwnedRepr<Money>, Dim<[usize; 1]>> / &ArrayBase<OwnedRepr<Money>, Dim<[usize; 1]>>`
|
= help: the trait `Div<&ArrayBase<OwnedRepr<Money>, Dim<[usize; 1]>>>` is not implemented for `&ArrayBase<OwnedRepr<Money>, Dim<[usize; 1]>>`
= help: the following other types implement trait `Div<Rhs>`:
`&'a ArrayBase<S, D>` implements `Div<&'a ArrayBase<S2, E>>`
`&'a ArrayBase<S, D>` implements `Div<ArrayBase<S2, E>>`
`&'a ArrayBase<S, D>` implements `Div<B>`
`ArrayBase<S, D>` implements `Div<&'a ArrayBase<S2, E>>`
`ArrayBase<S, D>` implements `Div<ArrayBase<S2, E>>`
`ArrayBase<S, D>` implements `Div<B>`
Am I just missing something obvious here? Or is this unreasonable to do with ndarray?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
I'm trying to write some functions to do some financial math using this combination of
ndarray
and this other cratemoneta
1.Divisions turn out to be a bit of a problem. As I understand it,
impl_binary_ops
forcesOutput
to be of the same type asRhs
.2 However, this is not really true for monetary values (or any quantity really).3The first test works and shows the common case dividing 2 monetary values, which returns a ratio, a plain amount with no currency. Dividing a money value by an amount would instead return another monetary value.4
The second fails to compile with error:
Am I just missing something obvious here? Or is this unreasonable to do with ndarray?
Footnotes
https://crates.io/crates/moneta ↩
https://github.com/rust-ndarray/ndarray/blob/fce60345ddbf576d6e5cd8c4b0c8104d00c9e326/src/impl_ops.rs#L74 ↩
https://github.com/mamrhein/money.rs/blob/34e804222fed1030453e0e9935c2a33997169438/src/lib.rs#L539-L561 ↩
https://github.com/mamrhein/money.rs/blob/34e804222fed1030453e0e9935c2a33997169438/src/lib.rs#L636-L649 ↩
Beta Was this translation helpful? Give feedback.
All reactions