From 0b8058e88ff20c9e43e67675e1407699c3976cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sat, 1 Jun 2013 20:50:00 +0200 Subject: [PATCH] Adapted for the compiler 'incomming' branch. --- src/adaptors/rotmat.rs | 6 +++--- src/adaptors/transform.rs | 6 +++--- src/dim1/mat1.rs | 6 +++--- src/dim1/vec1.rs | 6 +++--- src/dim2/mat2.rs | 8 ++++---- src/dim2/vec2.rs | 6 +++--- src/dim3/mat3.rs | 8 ++++---- src/dim3/vec3.rs | 6 +++--- src/ndim/dmat.rs | 41 +++++++++++++++++++------------------- src/ndim/dvec.rs | 25 ++++++++++++----------- src/ndim/nmat.rs | 25 ++++++++++++----------- src/ndim/nvec.rs | 11 +++++----- src/tests/mat.rs | 13 ++++++------ src/tests/vec.rs | 16 +++++++-------- src/traits/ring.rs | 2 +- src/traits/vector_space.rs | 2 +- 16 files changed, 96 insertions(+), 91 deletions(-) diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index d79d634e..246a1607 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -1,6 +1,6 @@ -use core::num::{One, Zero}; -use core::rand::{Rand, Rng, RngUtil}; -use core::cmp::ApproxEq; +use std::num::{One, Zero}; +use std::rand::{Rand, Rng, RngUtil}; +use std::cmp::ApproxEq; use traits::workarounds::rlmul::{RMul, LMul}; use traits::dim::Dim; use traits::inv::Inv; diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index cb31216a..3acb06cb 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -1,6 +1,6 @@ -use core::num::{One, Zero}; -use core::rand::{Rand, Rng, RngUtil}; -use core::cmp::ApproxEq; +use std::num::{One, Zero}; +use std::rand::{Rand, Rng, RngUtil}; +use std::cmp::ApproxEq; use traits::dim::Dim; use traits::inv::Inv; use traits::rotation::Rotation; diff --git a/src/dim1/mat1.rs b/src/dim1/mat1.rs index 12780120..5d5cee66 100644 --- a/src/dim1/mat1.rs +++ b/src/dim1/mat1.rs @@ -1,6 +1,6 @@ -use core::num::{One, Zero}; -use core::rand::{Rand, Rng, RngUtil}; -use core::cmp::ApproxEq; +use std::num::{One, Zero}; +use std::rand::{Rand, Rng, RngUtil}; +use std::cmp::ApproxEq; use traits::dim::Dim; use traits::inv::Inv; use traits::transpose::Transpose; diff --git a/src/dim1/vec1.rs b/src/dim1/vec1.rs index 3b33d0fc..9de405ed 100644 --- a/src/dim1/vec1.rs +++ b/src/dim1/vec1.rs @@ -1,6 +1,6 @@ -use core::num::{Zero, One, Algebraic}; -use core::rand::{Rand, Rng, RngUtil}; -use core::cmp::ApproxEq; +use std::num::{Zero, One, Algebraic}; +use std::rand::{Rand, Rng, RngUtil}; +use std::cmp::ApproxEq; use traits::basis::Basis; use traits::dim::Dim; use traits::dot::Dot; diff --git a/src/dim2/mat2.rs b/src/dim2/mat2.rs index 505700d0..e3b47af0 100644 --- a/src/dim2/mat2.rs +++ b/src/dim2/mat2.rs @@ -1,7 +1,7 @@ -use core::num::{One, Zero}; -use core::rand::{Rand, Rng, RngUtil}; -use core::cmp::ApproxEq; -use core::util::swap; +use std::num::{One, Zero}; +use std::rand::{Rand, Rng, RngUtil}; +use std::cmp::ApproxEq; +use std::util::swap; use traits::dim::Dim; use traits::inv::Inv; use traits::transpose::Transpose; diff --git a/src/dim2/vec2.rs b/src/dim2/vec2.rs index 0da1f880..6f1ec62e 100644 --- a/src/dim2/vec2.rs +++ b/src/dim2/vec2.rs @@ -1,7 +1,7 @@ -use core::num::{Zero, One, Algebraic}; -use core::rand::{Rand, Rng, RngUtil}; +use std::num::{Zero, One, Algebraic}; +use std::rand::{Rand, Rng, RngUtil}; use dim1::vec1::{Vec1, vec1}; -use core::cmp::ApproxEq; +use std::cmp::ApproxEq; use traits::basis::Basis; use traits::cross::Cross; use traits::dim::Dim; diff --git a/src/dim3/mat3.rs b/src/dim3/mat3.rs index 9e8f56bc..2f22b848 100644 --- a/src/dim3/mat3.rs +++ b/src/dim3/mat3.rs @@ -1,7 +1,7 @@ -use core::num::{One, Zero}; -use core::rand::{Rand, Rng, RngUtil}; -use core::cmp::ApproxEq; -use core::util::swap; +use std::num::{One, Zero}; +use std::rand::{Rand, Rng, RngUtil}; +use std::cmp::ApproxEq; +use std::util::swap; use traits::dim::Dim; use traits::inv::Inv; use traits::transpose::Transpose; diff --git a/src/dim3/vec3.rs b/src/dim3/vec3.rs index 8cf59713..eca742be 100644 --- a/src/dim3/vec3.rs +++ b/src/dim3/vec3.rs @@ -1,6 +1,6 @@ -use core::num::{Zero, One, Algebraic, abs}; -use core::rand::{Rand, Rng, RngUtil}; -use core::cmp::ApproxEq; +use std::num::{Zero, One, Algebraic, abs}; +use std::rand::{Rand, Rng, RngUtil}; +use std::cmp::ApproxEq; use traits::basis::Basis; use traits::cross::Cross; use traits::dim::Dim; diff --git a/src/ndim/dmat.rs b/src/ndim/dmat.rs index c5083bbc..af06bbeb 100644 --- a/src/ndim/dmat.rs +++ b/src/ndim/dmat.rs @@ -1,6 +1,7 @@ -use core::num::{One, Zero}; -use core::vec::{from_elem, swap, all, all2, len}; -use core::cmp::ApproxEq; +use std::uint::iterate; +use std::num::{One, Zero}; +use std::vec::{from_elem, swap, all, all2, len}; +use std::cmp::ApproxEq; use traits::inv::Inv; use traits::division_ring::DivisionRing; use traits::transpose::Transpose; @@ -25,7 +26,7 @@ pub fn one_mat_with_dim(dim: uint) -> DMat let mut res = zero_mat_with_dim(dim); let _1 = One::one::(); - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { res.set(i, i, &_1); } res @@ -67,13 +68,13 @@ Mul, DMat> for DMat let dim = self.dim; let mut res = zero_mat_with_dim(dim); - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { - for uint::range(0u, dim) |j| + for iterate(0u, dim) |j| { let mut acc = Zero::zero::(); - for uint::range(0u, dim) |k| + for iterate(0u, dim) |k| { acc += self.at(i, k) * other.at(k, j); } res.set(i, j, &acc); @@ -94,9 +95,9 @@ RMul> for DMat let dim = self.dim; let mut res : DVec = zero_vec_with_dim(dim); - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { - for uint::range(0u, dim) |j| + for iterate(0u, dim) |j| { res.at[i] = res.at[i] + other.at[j] * self.at(i, j); } } @@ -114,9 +115,9 @@ LMul> for DMat let dim = self.dim; let mut res : DVec = zero_vec_with_dim(dim); - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { - for uint::range(0u, dim) |j| + for iterate(0u, dim) |j| { res.at[i] = res.at[i] + other.at[j] * self.at(j, i); } } @@ -143,7 +144,7 @@ Inv for DMat let _0T = Zero::zero::(); // inversion using Gauss-Jordan elimination - for uint::range(0u, dim) |k| + for iterate(0u, dim) |k| { // search a non-zero value on the k-th column // FIXME: would it be worth it to spend some more time searching for the @@ -164,7 +165,7 @@ Inv for DMat // swap pivot line if (n0 != k) { - for uint::range(0u, dim) |j| + for iterate(0u, dim) |j| { let off_n0_j = self.offset(n0, j); let off_k_j = self.offset(k, j); @@ -176,31 +177,31 @@ Inv for DMat let pivot = self.at(k, k); - for uint::range(k, dim) |j| + for iterate(k, dim) |j| { let selfval = &(self.at(k, j) / pivot); self.set(k, j, selfval); } - for uint::range(0u, dim) |j| + for iterate(0u, dim) |j| { let resval = &(res.at(k, j) / pivot); res.set(k, j, resval); } - for uint::range(0u, dim) |l| + for iterate(0u, dim) |l| { if (l != k) { let normalizer = self.at(l, k); - for uint::range(k, dim) |j| + for iterate(k, dim) |j| { let selfval = &(self.at(l, j) - self.at(k, j) * normalizer); self.set(l, j, selfval); } - for uint::range(0u, dim) |j| + for iterate(0u, dim) |j| { let resval = &(res.at(l, j) - res.at(k, j) * normalizer); res.set(l, j, resval); @@ -228,9 +229,9 @@ impl Transpose for DMat { let dim = self.dim; - for uint::range(1u, dim) |i| + for iterate(1u, dim) |i| { - for uint::range(0u, dim - 1) |j| + for iterate(0u, dim - 1) |j| { let off_i_j = self.offset(i, j); let off_j_i = self.offset(j, i); diff --git a/src/ndim/dvec.rs b/src/ndim/dvec.rs index 9fc8e236..26ff815a 100644 --- a/src/ndim/dvec.rs +++ b/src/ndim/dvec.rs @@ -1,6 +1,7 @@ -use core::num::{Zero, One, Algebraic}; -use core::vec::{map_zip, map, all2, len, from_elem, all}; -use core::cmp::ApproxEq; +use std::uint::iterate; +use std::num::{Zero, One, Algebraic}; +use std::vec::{map_zip, map, all2, len, from_elem, all}; +use std::cmp::ApproxEq; use traits::ring::Ring; use traits::division_ring::DivisionRing; use traits::dot::Dot; @@ -28,7 +29,7 @@ impl> DVec { let mut res : ~[DVec] = ~[]; - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { let mut basis_element : DVec = zero_vec_with_dim(dim); @@ -47,7 +48,7 @@ impl> DVec let dim = len(self.at); let mut res : ~[DVec] = ~[]; - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { let mut basis_element : DVec = zero_vec_with_dim(len(self.at)); @@ -106,7 +107,7 @@ Dot for DVec let mut res = Zero::zero::(); - for uint::range(0u, len(self.at)) |i| + for iterate(0u, len(self.at)) |i| { res += self.at[i] * other.at[i]; } res @@ -119,7 +120,7 @@ impl SubDot for DVec { let mut res = Zero::zero::(); - for uint::range(0u, len(self.at)) |i| + for iterate(0u, len(self.at)) |i| { res += (self.at[i] - a.at[i]) * b.at[i]; } res @@ -134,7 +135,7 @@ ScalarMul for DVec fn scalar_mul_inplace(&mut self, s: &T) { - for uint::range(0u, len(self.at)) |i| + for iterate(0u, len(self.at)) |i| { self.at[i] *= *s; } } } @@ -148,7 +149,7 @@ ScalarDiv for DVec fn scalar_div_inplace(&mut self, s: &T) { - for uint::range(0u, len(self.at)) |i| + for iterate(0u, len(self.at)) |i| { self.at[i] /= *s; } } } @@ -161,7 +162,7 @@ ScalarAdd for DVec fn scalar_add_inplace(&mut self, s: &T) { - for uint::range(0u, len(self.at)) |i| + for iterate(0u, len(self.at)) |i| { self.at[i] += *s; } } } @@ -174,7 +175,7 @@ ScalarSub for DVec fn scalar_sub_inplace(&mut self, s: &T) { - for uint::range(0u, len(self.at)) |i| + for iterate(0u, len(self.at)) |i| { self.at[i] -= *s; } } } @@ -213,7 +214,7 @@ Norm for DVec { let l = self.norm(); - for uint::range(0u, len(self.at)) |i| + for iterate(0u, len(self.at)) |i| { self.at[i] /= l; } l diff --git a/src/ndim/nmat.rs b/src/ndim/nmat.rs index 083e73bf..c16b12cb 100644 --- a/src/ndim/nmat.rs +++ b/src/ndim/nmat.rs @@ -1,6 +1,7 @@ -use core::num::{One, Zero}; -use core::rand::{Rand, Rng, RngUtil}; -use core::cmp::ApproxEq; +use std::uint::iterate; +use std::num::{One, Zero}; +use std::rand::{Rand, Rng, RngUtil}; +use std::cmp::ApproxEq; use traits::dim::Dim; use traits::inv::Inv; use traits::division_ring::DivisionRing; @@ -61,13 +62,13 @@ Mul, NMat> for NMat let dim = Dim::dim::(); let mut res = Zero::zero::>(); - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { - for uint::range(0u, dim) |j| + for iterate(0u, dim) |j| { let mut acc: T = Zero::zero(); - for uint::range(0u, dim) |k| + for iterate(0u, dim) |k| { acc += self[(i, k)] * other[(k, j)]; } res.set(i, j, &acc); @@ -86,9 +87,9 @@ RMul> for NMat let dim = Dim::dim::(); let mut res : NVec = Zero::zero(); - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { - for uint::range(0u, dim) |j| + for iterate(0u, dim) |j| { res.at.at[i] = res.at.at[i] + other.at.at[j] * self[(i, j)]; } } @@ -104,9 +105,9 @@ LMul> for NMat let dim = Dim::dim::(); let mut res : NVec = Zero::zero(); - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { - for uint::range(0u, dim) |j| + for iterate(0u, dim) |j| { res.at.at[i] = res.at.at[i] + other.at.at[j] * self[(j, i)]; } } @@ -158,9 +159,9 @@ impl Rand for NMat let dim = Dim::dim::(); let mut res : NMat = Zero::zero(); - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { - for uint::range(0u, dim) |j| + for iterate(0u, dim) |j| { res.set(i, j, &rng.gen()); } } diff --git a/src/ndim/nvec.rs b/src/ndim/nvec.rs index a18f6d3f..adeb37f9 100644 --- a/src/ndim/nvec.rs +++ b/src/ndim/nvec.rs @@ -1,7 +1,8 @@ -use core::num::{Zero, Algebraic}; -use core::rand::{Rand, Rng, RngUtil}; -use core::vec::{map}; -use core::cmp::ApproxEq; +use std::uint::iterate; +use std::num::{Zero, Algebraic}; +use std::rand::{Rand, Rng, RngUtil}; +use std::vec::{map}; +use std::cmp::ApproxEq; use ndim::dvec::{DVec, zero_vec_with_dim, is_zero_vec}; use traits::basis::Basis; use traits::ring::Ring; @@ -189,7 +190,7 @@ impl Rand for NVec let dim = Dim::dim::(); let mut res : NVec = Zero::zero(); - for uint::range(0u, dim) |i| + for iterate(0u, dim) |i| { res.at.at[i] = rng.gen() } res diff --git a/src/tests/mat.rs b/src/tests/mat.rs index 1e4fc21f..0763fcd6 100644 --- a/src/tests/mat.rs +++ b/src/tests/mat.rs @@ -1,9 +1,9 @@ #[test] -use core::num::{One, abs}; +use std::num::{Real, One, abs}; #[test] -use core::rand::{random}; +use std::rand::{random}; #[test] -use core::cmp::ApproxEq; +use std::cmp::ApproxEq; #[test] use traits::inv::Inv; #[test] @@ -25,7 +25,7 @@ use adaptors::rotmat::Rotmat; macro_rules! test_inv_mat_impl( ($t:ty) => ( - for uint::range(0u, 10000u) |_| + for 10000.times { let randmat : $t = random(); @@ -46,6 +46,7 @@ fn test_inv_mat2() fn test_inv_mat3() { test_inv_mat_impl!(Mat3); } +// FIXME: ICE // #[test] // fn test_inv_nmat() // { test_inv_mat_impl!(NMat); } @@ -53,10 +54,10 @@ fn test_inv_mat3() #[test] fn test_rotation2() { - for uint::range(0u, 10000u) |_| + for 10000.times { let randmat = One::one::>>(); - let ang = &vec1(abs::(random()) % f64::consts::pi); + let ang = &vec1(abs::(random()) % Real::pi()); assert!(randmat.rotated(ang).rotation().approx_eq(ang)); } diff --git a/src/tests/vec.rs b/src/tests/vec.rs index a4201e85..75f06131 100644 --- a/src/tests/vec.rs +++ b/src/tests/vec.rs @@ -1,11 +1,11 @@ #[test] -use core::num::{Zero, One}; +use std::num::{Zero, One}; #[test] -use core::rand::{random}; +use std::rand::{random}; #[test] -use core::vec::{all, all2}; +use std::vec::{all, all2}; #[test] -use core::cmp::ApproxEq; +use std::cmp::ApproxEq; #[test] use dim3::vec3::Vec3; #[test] @@ -27,7 +27,7 @@ use traits::norm::Norm; macro_rules! test_commut_dot_impl( ($t:ty) => ( - for uint::range(0u, 10000u) |_| + for 10000.times { let v1 : $t = random(); let v2 : $t = random(); @@ -39,7 +39,7 @@ macro_rules! test_commut_dot_impl( macro_rules! test_basis_impl( ($t:ty) => ( - for uint::range(0u, 10000u) |_| + for 10000.times { let basis = Basis::canonical_basis::<$t>(); @@ -53,7 +53,7 @@ macro_rules! test_basis_impl( macro_rules! test_subspace_basis_impl( ($t:ty) => ( - for uint::range(0u, 10000u) |_| + for 10000.times { let v : Vec3 = random(); let v1 = v.normalized(); @@ -72,7 +72,7 @@ macro_rules! test_subspace_basis_impl( #[test] fn test_cross_vec3() { - for uint::range(0u, 10000u) |_| + for 10000.times { let v1 : Vec3 = random(); let v2 : Vec3 = random(); diff --git a/src/traits/ring.rs b/src/traits/ring.rs index d09661d0..7f77afea 100644 --- a/src/traits/ring.rs +++ b/src/traits/ring.rs @@ -1,4 +1,4 @@ -use core::num::{One, Zero}; +use std::num::{One, Zero}; /** * Trait of elements of a ring. A rings is an algebraic structure, the diff --git a/src/traits/vector_space.rs b/src/traits/vector_space.rs index 4dd5acc8..6221edec 100644 --- a/src/traits/vector_space.rs +++ b/src/traits/vector_space.rs @@ -1,4 +1,4 @@ -use core::num::Zero; +use std::num::Zero; use traits::division_ring::DivisionRing; use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv};