pub trait DotProduct<V> {
type Output;
// Required method
fn dot(self, other: V) -> Self::Output;
}Expand description
Trait for the dot product operation.
The dot product is the sum of the element-wise products of two vectors.
The dot method is only defined for Vector and RowVector.
However, the dot method accepts as an argument a Matrix or any of its views,
as long it represents a column or row vector respectively. That is, to dot with a Vector
of length n, the rhs must be a Matrix of shape (n, 1).
Similarly for RowVector.
§Example
This example shows some of the possible dot product combinations.
use ferrix::DotProduct;
use ferrix::{Vector, RowVector, Matrix};
// Dot product of two vectors
let a = Vector::from([1, 2, 3]);
let b = Vector::from([4, 5, 6]);
assert_eq!(a.dot(b), 32);
// Alternatively
let a = Vector::from([1, 2, 3]);
let b = Matrix::from([[4], [5], [6]]);
assert_eq!(a.dot(b), 32);
// Dot product of two row vectors
let a = RowVector::from([1, 2, 3]);
let b = RowVector::from([4, 5, 6]);
assert_eq!(a.dot(b), 32);
// Similarly
let a = RowVector::from([1, 2, 3]);
let b = Matrix::from([[4, 5, 6]]);
assert_eq!(a.dot(b), 32);