Comments (3)
Are you referring to the Scalar
trait from nalgebra there? If so, it is automatically implemented for any type that already implements Copy + PartialEq + Debug + Any
.
from alga.
Yes, I am referring to that Scalar
trait.
Allow me to get to the details. I'd like to be able to multiply vectors of Dual<T: Scalar+Num>
, but I currently cannot seem to be able to do this (note that the following code requires the latest master
from dual_num which isn't published on crates.io yet):
let x = Vector2::new(Dual::from(1.0f64), Dual::from(-2.0f64));
println!("{}", Dual::from(2.0f64) * x);
Which leads to the following error:
Compiling dual_num v0.2.0 (file:///home/chris/Workspace/rust/dual_num)
error[E0277]: cannot multiply `na::Matrix<dual_num::Dual<f64>, na::U2, na::U1, na::MatrixArray<dual_num::Dual<f64>, na::U2, na::U1>>` to `dual_num::Dual<f64>`
--> tests/lib.rs:247:39
|
247 | println!("{}", Dual::from(2.0f64) * x);
| ^ no implementation for `dual_num::Dual<f64> * na::Matrix<dual_num::Dual<f64>, na::U2, na::U1, na::MatrixArray<dual_num::Dual<f64>, na::U2, na::U1>>`
|
= help: the trait `std::ops::Mul<na::Matrix<dual_num::Dual<f64>, na::U2, na::U1, na::MatrixArray<dual_num::Dual<f64>, na::U2, na::U1>>>` is not implemented for `dual_num::Dual<f64>`
error: aborting due to previous error
So I assumed, perhaps incorrectly, that the Scalar
trait wasn't implemented because from the following code, I think that PartialEq, Debug and Copy are all implemented.
Note that the Dual
struct is defined as follows:
#[derive(Clone, Copy)]
pub struct Dual<T: Scalar>(na::Vector2<T>);
/// ...
impl<T: Scalar + PartialEq> PartialEq<Self> for Dual<T> {
fn eq(&self, rhs: &Self) -> bool {
self.0 == rhs.0
}
}
// ...
impl<T: Scalar + PartialEq> PartialEq<T> for Dual<T> {
fn eq(&self, rhs: &T) -> bool {
*self.real_ref() == *rhs
}
}
/// ...
impl<T: Scalar> Debug for Dual<T> {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
f.debug_tuple("Dual").field(self.real_ref()).field(self.dual_ref()).finish()
}
}
Any hint is appreciated, thanks
from alga.
For the record:
The solution was trivial (as pointed out by sebcrozet on IRC). The scalar multiplication of a vector must be as vector * x
due to the limitations of the compilers (which prevents implementing traits on structs defined by other traits).
Thanks for the support!
from alga.
Related Issues (20)
- Deriving a Ring trait requires a two-sided multiplicative inverse HOT 2
- Add a README.
- Use Rust 2021 edition
- Is the Real trait is too broad? (or too specialized) HOT 9
- Standard implementation for the trivial group?
- `alga_derive` generates quickcheck tests against the `approx` properties
- Instructions incomplete/incorrect on how to define an additive group HOT 3
- quickcheck 0.8 HOT 1
- RealField/ComplexField traits HOT 3
- Update syn dependency HOT 1
- Implement traits for i128 and u128 HOT 2
- Consider softening the demands on ComplexField HOT 1
- FiniteDimVectorSpace forces every type of vectors to have the same rank HOT 2
- Are the real numbers a normed space? HOT 7
- Consider adding bounded lattice
- Polynomial ring over a finite field HOT 2
- Publish new version of `alga_derive` HOT 1
- Considering NaN, do floating point values form a lattice?
- InnerSpace Angle Implementation Bug
- FiniteDimVectorField should be implemented for `f64`and `f32`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alga.