Change implementation of to_row_vector for nalgebra (#34)

* Add failing test

* Change implementation of to_row_vector for nalgebra
This commit is contained in:
morenol
2020-11-25 14:39:02 -04:00
committed by GitHub
parent 9db993939e
commit 89a5136191
4 changed files with 23 additions and 4 deletions
+6
View File
@@ -1064,6 +1064,12 @@ mod tests {
);
}
#[test]
fn col_matrix_to_row_vector() {
let m: DenseMatrix<f64> = BaseMatrix::zeros(10, 1);
assert_eq!(m.to_row_vector().len(), 10)
}
#[test]
fn iter() {
let vec = vec![1., 2., 3., 4., 5., 6.];
+9 -2
View File
@@ -185,14 +185,15 @@ impl<T: RealNumber + 'static> BaseVector<T> for MatrixMN<T, U1, Dynamic> {
impl<T: RealNumber + Scalar + AddAssign + SubAssign + MulAssign + DivAssign + Sum + 'static>
BaseMatrix<T> for Matrix<T, Dynamic, Dynamic, VecStorage<T, Dynamic, Dynamic>>
{
type RowVector = MatrixMN<T, U1, Dynamic>;
type RowVector = RowDVector<T>;
fn from_row_vector(vec: Self::RowVector) -> Self {
Matrix::from_rows(&[vec])
}
fn to_row_vector(self) -> Self::RowVector {
self.row(0).into_owned()
let (nrows, ncols) = self.shape();
self.reshape_generic(U1, Dynamic::new(nrows * ncols))
}
fn get(&self, row: usize, col: usize) -> T {
@@ -697,6 +698,12 @@ mod tests {
assert_eq!(m.to_row_vector(), expected);
}
#[test]
fn col_matrix_to_row_vector() {
let m: DMatrix<f64> = BaseMatrix::zeros(10, 1);
assert_eq!(m.to_row_vector().len(), 10)
}
#[test]
fn get_row_col_as_vec() {
let m = DMatrix::from_row_slice(3, 3, &[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]);
+6
View File
@@ -563,6 +563,12 @@ mod tests {
);
}
#[test]
fn col_matrix_to_row_vector() {
let m: Array2<f64> = BaseMatrix::zeros(10, 1);
assert_eq!(m.to_row_vector().len(), 10)
}
#[test]
fn add_mut() {
let mut a1 = arr2(&[[1., 2., 3.], [4., 5., 6.]]);