added test comments

This commit is contained in:
Marc Haubenstock 2019-07-28 14:22:42 +02:00
parent 9467494ece
commit e589dc0dae
2 changed files with 14 additions and 49 deletions

View File

@ -162,10 +162,9 @@ impl<N: RealField> DMatrix<N> {
//TODO: rest ?
}
impl<N: RealField, R1: Dim +DimName, C1: Dim +DimName> MatrixMN<N, R1, C1> where DefaultAllocator: Allocator<N, R1, C1> {
impl<N: RealField, R1: Dim + DimName, C1: Dim + DimName> MatrixMN<N, R1, C1> where DefaultAllocator: Allocator<N, R1, C1> {
/// Returns the convolution of the target vector and a kernel.
///
/// # Arguments
@ -184,8 +183,6 @@ impl<N: RealField, R1: Dim +DimName, C1: Dim +DimName> MatrixMN<N, R1, C1> where
C2: Dim,
S2: Storage<N, R2, C2>
{
let mat_rows = self.nrows() as i32;
let mat_cols = self.ncols() as i32;
@ -193,13 +190,11 @@ impl<N: RealField, R1: Dim +DimName, C1: Dim +DimName> MatrixMN<N, R1, C1> where
convolve(&self, &kernel,&mut conv,mat_rows,mat_cols);
conv
}
//TODO: rest ?
}
@ -213,7 +208,6 @@ fn convolve<N, R1, C1, R2, C2, S2>(mat: &MatrixMN<N,R1,C1>, kernel: &Matrix<N, R
S2: Storage<N, R2, C2>,
DefaultAllocator: Allocator<N, R1, C1>
{
let ker_rows = kernel.data.shape().0.value() as i32;
let ker_cols = kernel.data.shape().1.value() as i32;
@ -225,7 +219,6 @@ fn convolve<N, R1, C1, R2, C2, S2>(mat: &MatrixMN<N,R1,C1>, kernel: &Matrix<N, R
mat_rows, ker_rows, mat_cols, ker_cols);
}
let kernel_size = ker_rows;
let kernel_min = kernel_size/2;
let zero = zero::<N>();

View File

@ -118,50 +118,22 @@ fn convolve_valid_check(){
}
//// >>> convolve([1,2,3,4],[1,2],"same")
//// array([ 1, 4, 7, 10])
//#[test]
//fn convolve_same_integers_check(){
// // Static Tests
// let actual_s = Vector4::new(1, 4, 7, 10);
// let expected_s = Vector4::new(1, 2, 3, 4).convolve_same(Vector2::new(1, 2));
//
// assert!(relative_eq!(actual_s, expected_s, epsilon = 1.0e-7));
// mat([ 1, 1, 1, 1, 1,
// 1, 1, 1, 1, 1,
// 1, 1, 1, 1, 1,
// 1, 1, 1, 1, 1,
// 1, 1, 1, 1, 1])
//
// // Dynamic Tests
// let actual_d = DVector::from_vec(vec![1, 4, 7, 10]);
// let expected_d = DVector::from_vec(vec![1, 2, 3, 4]).convolve_same(DVector::from_vec(vec![1, 2]));
// kernel([ 0, 1, 0,
// 1, 1, 1,
// 0, 1, 0,])
//
// assert!(relative_eq!(actual_d, expected_d, epsilon = 1.0e-7));
//
// // Panic Tests
// // These really only apply to dynamic sized vectors
// assert!(
// panic::catch_unwind(|| {
// DVector::from_vec(vec![1, 2]).convolve_same(DVector::from_vec(vec![1, 2, 3, 4]));
// }).is_err()
// );
//
// assert!(
// panic::catch_unwind(|| {
// DVector::<usize>::from_vec(vec![]).convolve_same(DVector::from_vec(vec![1, 2, 3, 4]));
// }).is_err()
// );
//
// assert!(
// panic::catch_unwind(|| {
// DVector::from_vec(vec![1, 2, 3, 4]).convolve_same(DVector::<usize>::from_vec(vec![]));
// }).is_err()
// );
//}
//
// Should mimic calculations in Python's scipy library
// >>>from scipy.signal import convolve
//
// >>> convolve([1,2,3,4],[1,2],"same")
// array([ 1, 4, 7, 10])
// res([ 3, 4, 4, 4, 3,
// 4, 5, 5, 5, 4,
// 4, 5, 5, 5, 4,
// 4, 5, 5, 5, 4,
// 3, 4, 4, 4, 3])
#[test]
fn convolve_same_mat_check(){
let actual_s = Matrix5::from_vec( vec![3.0,4.0,4.0,4.0,3.0,4.0,5.0,5.0,5.0,4.0,4.0,5.0,5.0,5.0,4.0,4.0,5.0,5.0,5.0,4.0,3.0,4.0,4.0,4.0,3.0]);