Skip to content

Commit

Permalink
Update to ndarray v0.15.* and fixes related to that
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarson3 committed May 2, 2021
1 parent d6902b2 commit 5e4bfd6
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 76 deletions.
2 changes: 1 addition & 1 deletion mori/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exclude = [
]

[dependencies]
ndarray = {version = "0.13.0", features=["approx"]}
ndarray = {version = "0.15.1", features=["approx"]}
[features]
parallel = ["ndarray/rayon"]
[dev-dependencies]
Expand Down
8 changes: 4 additions & 4 deletions mori/src/orientations/ang_axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,14 +850,14 @@ impl RotVector for AngAxis{
par_azip!((mut vec in vec.axis_iter_mut(Axis(1)), ref ang_axis in self.ori.axis_iter(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
ang_axis_rot_vec(&ang_axis, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});

#[cfg(not(feature = "parallel"))]
azip!((mut vec in vec.axis_iter_mut(Axis(1)), ref ang_axis in self.ori.axis_iter(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
ang_axis_rot_vec(&ang_axis, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});
} else{
//We just have one Axis-angle representation so perform pretty much the above to get all of our values
Expand All @@ -867,14 +867,14 @@ impl RotVector for AngAxis{
par_azip!((mut vec in vec.axis_iter_mut(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
ang_axis_rot_vec(&ang_axis, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});

#[cfg(not(feature = "parallel"))]
azip!((mut vec in vec.axis_iter_mut(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
ang_axis_rot_vec(&ang_axis, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});
}//End of if-else
}//End of rot_vector_inplace
Expand Down
8 changes: 4 additions & 4 deletions mori/src/orientations/quat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,14 +1034,14 @@ impl RotVector for Quat{
par_azip!((mut vec in vec.axis_iter_mut(Axis(1)), ref quat in self.ori.axis_iter(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
quat_rot_vec(&quat, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});

#[cfg(not(feature = "parallel"))]
azip!((mut vec in vec.axis_iter_mut(Axis(1)), ref quat in self.ori.axis_iter(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
quat_rot_vec(&quat, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});
} else{
//We just have one Quaternion so perform pretty much the above to get all of our values
Expand All @@ -1051,14 +1051,14 @@ impl RotVector for Quat{
par_azip!((mut vec in vec.axis_iter_mut(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
quat_rot_vec(&quat, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});

#[cfg(not(feature = "parallel"))]
azip!((mut vec in vec.axis_iter_mut(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
quat_rot_vec(&quat, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});
}//End of if-else
}//End of rot_vector_inplace
Expand Down
36 changes: 18 additions & 18 deletions mori/src/orientations/rmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,12 @@ impl RotVector for RMat{
//rvec values all at once.
//The subview is necessary because we represent RMat as an Array3 and we need an Array1 or Array2
//to use the dot function
rvec.assign({&self.ori.index_axis(Axis(2), 0).dot(&vec)});
rvec.assign(&self.ori.index_axis(Axis(2), 0).dot(&vec));
}else{
//We now need to look at the case where we only have one vector to rotate but several rotation matrices
let vec = vec.index_axis(Axis(1), 0);
let f = |mut rvec: ArrayViewMut1::<f64>, ref rmat: ArrayView2::<f64>| {
rvec.assign({&rmat.dot(&vec)});
rvec.assign(&rmat.dot(&vec));
};

#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -821,12 +821,12 @@ impl RotVector for RMat{
//rvec values all at once.
//The subview is necessary because we represent RMat as an Array3 and we need an Array1 or Array2
//to use the dot function
rvec.assign({&self.ori.index_axis(Axis(2), 0).dot(&vec)});
rvec.assign(&self.ori.index_axis(Axis(2), 0).dot(&vec));
}else{
//We now need to look at the case where we only have one vector to rotate but several rotation matrices
let vec = vec.index_axis(Axis(1), 0);
let f = |mut rvec: ArrayViewMut1::<f64>, ref rmat: ArrayView2::<f64>| {
rvec.assign({&rmat.dot(&vec)});
rvec.assign(&rmat.dot(&vec));
};

#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -867,8 +867,8 @@ impl RotVector for RMat{
let f = |mut vec: ArrayViewMut1::<f64>, ref rmat: ArrayView2::<f64>| {
//A cleaner way needs to exists to perform this operation.
let mut rvec = Array1::<f64>::zeros((3).f());
rvec.assign({&rmat.dot(&vec)});
vec.assign({&rvec});
rvec.assign(&rmat.dot(&vec));
vec.assign(&rvec);
};

#[cfg(feature = "parallel")]
Expand All @@ -889,8 +889,8 @@ impl RotVector for RMat{
let f = |mut vec: ArrayViewMut1::<f64>| {
//A cleaner way needs to exists to perform this operation.
let mut rvec = Array1::<f64>::zeros((3).f());
rvec.assign({&self.ori.index_axis(Axis(2), 0).dot(&vec)});
vec.assign({&rvec});
rvec.assign(&self.ori.index_axis(Axis(2), 0).dot(&vec));
vec.assign(&rvec);
};

#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -940,7 +940,7 @@ impl RotTensor for RMat{
//and assigning R*T*R^T to the rotated tensor.

let f = |mut rtensor: ArrayViewMut2::<f64>, ref tensor: ArrayView2::<f64>, ref rmat: ArrayView2::<f64>| {
rtensor.assign({&rmat.dot(&tensor.dot(&rmat.t()))});
rtensor.assign(&rmat.dot(&tensor.dot(&rmat.t())));
};

#[cfg(feature = "parallel")]
Expand All @@ -960,9 +960,9 @@ impl RotTensor for RMat{
//to use the dot function

let f = |mut rtensor: ArrayViewMut2::<f64>, ref tensor: ArrayView2::<f64>| {
rtensor.assign({
rtensor.assign(
&self.ori.index_axis(Axis(2), 0).dot(&tensor.dot(&self.ori.index_axis(Axis(2), 0).t()))
});
);
};

#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -1016,7 +1016,7 @@ impl RotTensor for RMat{
//Here we're iterating through each tensor, rotation matrix, and rotated tensor value
//and assigning R*T*R^T to the rotated tensor.
let f = |mut rtensor: ArrayViewMut2::<f64>, ref tensor: ArrayView2::<f64>, ref rmat: ArrayView2::<f64>| {
rtensor.assign({&rmat.dot(&tensor.dot(&rmat.t()))});
rtensor.assign(&rmat.dot(&tensor.dot(&rmat.t())));
};

#[cfg(feature = "parallel")]
Expand All @@ -1035,9 +1035,9 @@ impl RotTensor for RMat{
//The subview is necessary because we represent RMat as an Array3 and we need an Array1 or Array2
//to use the dot function
let f = |mut rtensor: ArrayViewMut2::<f64>, ref tensor: ArrayView2::<f64>| {
rtensor.assign({
rtensor.assign(
&self.ori.index_axis(Axis(2), 0).dot(&tensor.dot(&self.ori.index_axis(Axis(2), 0).t()))
});
);
};

#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -1081,8 +1081,8 @@ impl RotTensor for RMat{
let f = |mut tensor: ArrayViewMut2::<f64>, ref rmat: ArrayView2::<f64>| {
//A cleaner way needs to exists to perform this operation.
let mut rtensor = Array2::<f64>::zeros((3, 3).f());
rtensor.assign({&rmat.dot(&tensor.dot(&rmat.t()))});
tensor.assign({&rtensor});
rtensor.assign(&rmat.dot(&tensor.dot(&rmat.t())));
tensor.assign(&rtensor);
};

#[cfg(feature = "parallel")]
Expand All @@ -1101,8 +1101,8 @@ impl RotTensor for RMat{
let f = |mut tensor: ArrayViewMut2::<f64>| {
//A cleaner way needs to exists to perform this operation.
let mut rtensor = Array2::<f64>::zeros((3, 3).f());
rtensor.assign({&self.ori.index_axis(Axis(2), 0).dot(&tensor.dot(&self.ori.index_axis(Axis(2), 0).t()))});
tensor.assign({&rtensor});
rtensor.assign(&self.ori.index_axis(Axis(2), 0).dot(&tensor.dot(&self.ori.index_axis(Axis(2), 0).t())));
tensor.assign(&rtensor);
};

#[cfg(feature = "parallel")]
Expand Down
8 changes: 4 additions & 4 deletions mori/src/orientations/rod_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,14 +691,14 @@ impl RotVector for RodVec{
par_azip!((mut vec in vec.axis_iter_mut(Axis(1)), ref rod_vec in self.ori.axis_iter(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
rod_vec_rot_vec(&rod_vec, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});

#[cfg(not(feature = "parallel"))]
azip!((mut vec in vec.axis_iter_mut(Axis(1)), ref rod_vec in self.ori.axis_iter(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
rod_vec_rot_vec(&rod_vec, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});
} else{
//We just have one Rodrigues vector so perform pretty much the above to get all of our values
Expand All @@ -708,14 +708,14 @@ impl RotVector for RodVec{
par_azip!((mut vec in vec.axis_iter_mut(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
rod_vec_rot_vec(&rod_vec, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});

#[cfg(not(feature = "parallel"))]
azip!((mut vec in vec.axis_iter_mut(Axis(1))) {
let mut rvec = Array1::<f64>::zeros((3).f());
rod_vec_rot_vec(&rod_vec, &vec.view(), rvec.view_mut());
vec.assign({&rvec});
vec.assign(&rvec);
});
}//End if-else
}//End of rot_vector_inplace
Expand Down
29 changes: 14 additions & 15 deletions mori/tests/ori_conv_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ extern crate csv;
use mori::orientations::*;
use csv::ReaderBuilder;
use ndarray::prelude::*;
use approx::assert_abs_diff_eq;

//All of the below tests use a set of Rodrigues Vector data pulled from a Fundamental
//Region of cubic crystals located at the origin. It therefore provides a comprehensive
Expand All @@ -23,7 +22,7 @@ fn rod2rodcomp(){

let rod_comp_ori2 = rod_comp.ori_view();

assert_abs_diff_eq!(rod_comp_ori, rod_comp_ori2, epsilon = 1e-14);
assert!(rod_comp_ori.abs_diff_eq(&rod_comp_ori2, 1e-14));
}

#[test]
Expand Down Expand Up @@ -63,7 +62,7 @@ fn rod2angaxis2rod(){
let rod2 = ang_axis.to_rod_vec();
let rod_ori2 = rod2.ori_view();

assert_abs_diff_eq!(rod_ori, rod_ori2, epsilon = 1e-14);
assert!(rod_ori.abs_diff_eq(&rod_ori2, 1e-14));
}

#[test]
Expand All @@ -77,7 +76,7 @@ fn rod2angaxiscomp2rod(){
let rod2 = ang_axis_comp.to_rod_vec();
let rod_ori2 = rod2.ori_view();

assert_abs_diff_eq!(rod_ori, rod_ori2, epsilon = 1e-14);
assert!(rod_ori.abs_diff_eq(&rod_ori2, 1e-14));
}


Expand All @@ -92,7 +91,7 @@ fn rod2rmat2rod(){
let rod2 = rmat.to_rod_vec();
let rod_ori2 = rod2.ori_view();

assert_abs_diff_eq!(rod_ori, rod_ori2, epsilon = 1e-14);
assert!(rod_ori.abs_diff_eq(&rod_ori2, 1e-14));
}

#[test]
Expand All @@ -106,7 +105,7 @@ fn rod2bunge2rod(){
let rod2 = bunge.to_rod_vec();
let rod_ori2 = rod2.ori_view();

assert_abs_diff_eq!(rod_ori, rod_ori2, epsilon = 1e-14);
assert!(rod_ori.abs_diff_eq(&rod_ori2, 1e-14));
}


Expand All @@ -125,7 +124,7 @@ fn rod2bunge2rod_inplace(){

let rod_ori2 = rod2.ori_view();

assert_abs_diff_eq!(rod_ori, rod_ori2, epsilon = 1e-14);
assert!(rod_ori.abs_diff_eq(&rod_ori2, 1e-14));
}

#[test]
Expand All @@ -139,7 +138,7 @@ fn rod2quat2rod(){
let rod2 = quat.to_rod_vec();
let rod_ori2 = rod2.ori_view();

assert_abs_diff_eq!(rod_ori, rod_ori2, epsilon = 1e-14);
assert!(rod_ori.abs_diff_eq(&rod_ori2, 1e-14));
}

#[test]
Expand All @@ -156,7 +155,7 @@ fn rmat2bunge2rmat(){
let rmat_ori = rmat.ori_view();
let rmat_ori2 = rmat2.ori_view();

assert_abs_diff_eq!(rmat_ori, rmat_ori2, epsilon = 1e-14);
assert!(rmat_ori.abs_diff_eq(&rmat_ori2, 1e-14));
}

#[test]
Expand All @@ -173,7 +172,7 @@ fn rmat2angaxis2rmat(){
let rmat_ori = rmat.ori_view();
let rmat_ori2 = rmat2.ori_view();

assert_abs_diff_eq!(rmat_ori, rmat_ori2, epsilon = 1e-14);
assert!(rmat_ori.abs_diff_eq(&rmat_ori2, 1e-14));
}

#[test]
Expand All @@ -190,7 +189,7 @@ fn rmat2angaxiscomp2rmat(){
let rmat_ori = rmat.ori_view();
let rmat_ori2 = rmat2.ori_view();

assert_abs_diff_eq!(rmat_ori, rmat_ori2, epsilon = 1e-14);
assert!(rmat_ori.abs_diff_eq(&rmat_ori2, 1e-14));
}

#[test]
Expand All @@ -207,7 +206,7 @@ fn quat2bunge2quat(){
let quat_ori = quat.ori_view();
let quat_ori2 = quat2.ori_view();

assert_abs_diff_eq!(quat_ori, quat_ori2, epsilon = 1e-14);
assert!(quat_ori.abs_diff_eq(&quat_ori2, 1e-14));
}

#[test]
Expand All @@ -224,7 +223,7 @@ fn quat2rmat2quat(){
let quat_ori = quat.ori_view();
let quat_ori2 = quat2.ori_view();

assert_abs_diff_eq!(quat_ori, quat_ori2, epsilon = 1e-14);
assert!(quat_ori.abs_diff_eq(&quat_ori2, 1e-14));
}

#[test]
Expand All @@ -241,7 +240,7 @@ fn quat2angaxiscomp2quat(){
let quat_ori = quat.ori_view();
let quat_ori2 = quat2.ori_view();

assert_abs_diff_eq!(quat_ori, quat_ori2, epsilon = 1e-14);
assert!(quat_ori.abs_diff_eq(&quat_ori2, 1e-14));
}

#[test]
Expand All @@ -258,7 +257,7 @@ fn angaxis2bunge2angaxis(){
let angaxis_ori = ang_axis.ori_view();
let angaxis_ori2 = ang_axis2.ori_view();

assert_abs_diff_eq!(angaxis_ori, angaxis_ori2, epsilon = 1e-14);
assert!(angaxis_ori.abs_diff_eq(&angaxis_ori2, 1e-14));
}

fn read_rod_file() -> Array2<f64>{
Expand Down
Loading

0 comments on commit 5e4bfd6

Please sign in to comment.