1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
use super::{Float, Matrix};
use crate::{ColumnVector, RowVector, VectorImpl};
use core::ops;
impl<T: Float, const ROWS: usize, const COLS: usize> ops::Add<&VectorImpl<T, ROWS, COLS>>
for VectorImpl<T, ROWS, COLS>
{
type Output = Option<VectorImpl<T, ROWS, COLS>>;
fn add(self, other: &VectorImpl<T, ROWS, COLS>) -> Self::Output {
self.add_to(other)
}
}
impl<T: Float, const ROWS: usize, const COLS: usize> ops::Sub<&VectorImpl<T, ROWS, COLS>>
for VectorImpl<T, ROWS, COLS>
{
type Output = Option<VectorImpl<T, ROWS, COLS>>;
fn sub(self, other: &VectorImpl<T, ROWS, COLS>) -> Self::Output {
self.subtract(other)
}
}
impl<T: Float, const ROWS: usize, const COLS: usize> ops::Mul<T> for VectorImpl<T, ROWS, COLS> {
type Output = VectorImpl<T, ROWS, COLS>;
fn mul(self, scalar: T) -> Self::Output {
self.scale(scalar)
}
}
impl<T: Float, const ROWS: usize, const COLS: usize> ops::Div<T> for VectorImpl<T, ROWS, COLS> {
type Output = VectorImpl<T, ROWS, COLS>;
fn div(self, scalar: T) -> Self::Output {
self.scale(T::one() / scalar)
}
}
impl<T: Float, const ROWS: usize, const COLS: usize> ops::AddAssign<VectorImpl<T, ROWS, COLS>>
for VectorImpl<T, ROWS, COLS>
{
fn add_assign(&mut self, other: VectorImpl<T, ROWS, COLS>) {
if let Some(result) = self.add_to(&other) {
*self = result;
}
}
}
impl<T: Float, const ROWS: usize, const COLS: usize> ops::SubAssign<VectorImpl<T, ROWS, COLS>>
for VectorImpl<T, ROWS, COLS>
{
fn sub_assign(&mut self, other: VectorImpl<T, ROWS, COLS>) {
if let Some(result) = self.subtract(&other) {
*self = result;
}
}
}
impl<T: Float, const ROWS: usize, const COLS: usize> ops::MulAssign<T>
for VectorImpl<T, ROWS, COLS>
{
fn mul_assign(&mut self, scalar: T) {
*self = self.scale(scalar);
}
}
impl<T: Float, const ROWS: usize, const COLS: usize> ops::DivAssign<T>
for VectorImpl<T, ROWS, COLS>
{
fn div_assign(&mut self, scalar: T) {
*self = self.scale(T::one() / scalar);
}
}
impl<T: Float> ops::Mul<&Matrix<T>> for RowVector<T> {
type Output = Option<RowVector<T>>;
fn mul(self, matrix: &Matrix<T>) -> Self::Output {
self.mul_matrix(matrix)
}
}
impl<T: Float> ops::Mul<&Matrix<T>> for ColumnVector<T> {
type Output = Option<ColumnVector<T>>;
fn mul(self, matrix: &Matrix<T>) -> Self::Output {
self.mul_matrix(matrix)
}
}
impl<T: Float> ops::MulAssign<&Matrix<T>> for RowVector<T> {
fn mul_assign(&mut self, matrix: &Matrix<T>) {
if let Some(result) = self.mul_matrix(matrix) {
*self = result;
}
}
}
impl<T: Float> ops::MulAssign<&Matrix<T>> for ColumnVector<T> {
fn mul_assign(&mut self, matrix: &Matrix<T>) {
if let Some(result) = self.mul_matrix(matrix) {
*self = result;
}
}
}
|