From 50b34ca7651156b5701cbea1fb7263a1e157680e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sat, 3 Aug 2013 12:21:56 +0200 Subject: [PATCH] Fix `for` loops (again) + `iterate` becomes `range`. --- src/dmat.rs | 35 +++++++++++++++++------------------ src/dvec.rs | 23 +++++++++++------------ src/mat.rs | 1 - src/mat_macros.rs | 44 ++++++++++++++++++++++---------------------- src/tests/vec.rs | 2 +- src/vec.rs | 1 - src/vec_macros.rs | 6 +++--- src/vec_spec.rs | 4 ++-- 8 files changed, 56 insertions(+), 60 deletions(-) diff --git a/src/dmat.rs b/src/dmat.rs index 7a7f69d5..d9091453 100644 --- a/src/dmat.rs +++ b/src/dmat.rs @@ -1,4 +1,3 @@ -use std::uint::iterate; use std::num::{One, Zero}; use std::vec::from_elem; use std::cmp::ApproxEq; @@ -42,7 +41,7 @@ pub fn one_mat_with_dim(dim: uint) -> DMat let mut res = zero_mat_with_dim(dim); let _1 = One::one::(); - for iterate(0u, dim) |i| + for i in range(0u, dim) { res.set(i, i, &_1); } res @@ -98,13 +97,13 @@ Mul, DMat> for DMat let dim = self.dim; let mut res = zero_mat_with_dim(dim); - for iterate(0u, dim) |i| + for i in range(0u, dim) { - for iterate(0u, dim) |j| + for j in range(0u, dim) { let mut acc = Zero::zero::(); - for iterate(0u, dim) |k| + for k in range(0u, dim) { acc = acc + self.at(i, k) * other.at(k, j); } res.set(i, j, &acc); @@ -125,9 +124,9 @@ RMul> for DMat let dim = self.dim; let mut res : DVec = zero_vec_with_dim(dim); - for iterate(0u, dim) |i| + for i in range(0u, dim) { - for iterate(0u, dim) |j| + for j in range(0u, dim) { res.at[i] = res.at[i] + other.at[j] * self.at(i, j); } } @@ -145,9 +144,9 @@ LMul> for DMat let dim = self.dim; let mut res : DVec = zero_vec_with_dim(dim); - for iterate(0u, dim) |i| + for i in range(0u, dim) { - for iterate(0u, dim) |j| + for j in range(0u, dim) { res.at[i] = res.at[i] + other.at[j] * self.at(j, i); } } @@ -176,7 +175,7 @@ Inv for DMat let _0T = Zero::zero::(); // inversion using Gauss-Jordan elimination - for iterate(0u, dim) |k| + for k in range(0u, dim) { // search a non-zero value on the k-th column // FIXME: would it be worth it to spend some more time searching for the @@ -198,7 +197,7 @@ Inv for DMat // swap pivot line if n0 != k { - for iterate(0u, dim) |j| + for j in range(0u, dim) { let off_n0_j = self.offset(n0, j); let off_k_j = self.offset(k, j); @@ -210,31 +209,31 @@ Inv for DMat let pivot = self.at(k, k); - for iterate(k, dim) |j| + for j in range(k, dim) { let selfval = &(self.at(k, j) / pivot); self.set(k, j, selfval); } - for iterate(0u, dim) |j| + for j in range(0u, dim) { let resval = &(res.at(k, j) / pivot); res.set(k, j, resval); } - for iterate(0u, dim) |l| + for l in range(0u, dim) { if l != k { let normalizer = self.at(l, k); - for iterate(k, dim) |j| + for j in range(k, dim) { let selfval = &(self.at(l, j) - self.at(k, j) * normalizer); self.set(l, j, selfval); } - for iterate(0u, dim) |j| + for j in range(0u, dim) { let resval = &(res.at(l, j) - res.at(k, j) * normalizer); res.set(l, j, resval); @@ -265,9 +264,9 @@ impl Transpose for DMat { let dim = self.dim; - for iterate(1u, dim) |i| + for i in range(1u, dim) { - for iterate(0u, dim - 1) |j| + for j in range(0u, dim - 1) { let off_i_j = self.offset(i, j); let off_j_i = self.offset(j, i); diff --git a/src/dvec.rs b/src/dvec.rs index 24a14676..1a8329c5 100644 --- a/src/dvec.rs +++ b/src/dvec.rs @@ -1,4 +1,3 @@ -use std::uint::iterate; use std::num::{Zero, One, Algebraic}; use std::vec::{VecIterator, VecMutIterator}; use std::vec::from_elem; @@ -52,7 +51,7 @@ impl> FromIterator for DVec { let mut res = DVec { at: ~[] }; - foreach e in param + for e in param { res.at.push(e) } res @@ -68,7 +67,7 @@ impl> DVec { let mut res : ~[DVec] = ~[]; - for iterate(0u, dim) |i| + for i in range(0u, dim) { let mut basis_element : DVec = zero_vec_with_dim(dim); @@ -89,7 +88,7 @@ impl> DVec let dim = self.at.len(); let mut res : ~[DVec] = ~[]; - for iterate(0u, dim) |i| + for i in range(0u, dim) { let mut basis_element : DVec = zero_vec_with_dim(self.at.len()); @@ -102,7 +101,7 @@ impl> DVec elt = elt - self.scalar_mul(&basis_element.dot(self)); - foreach v in res.iter() + for v in res.iter() { elt = elt - v.scalar_mul(&elt.dot(v)) }; if !elt.sqnorm().approx_eq(&Zero::zero()) @@ -156,7 +155,7 @@ Dot for DVec let mut res = Zero::zero::(); - for iterate(0u, self.at.len()) |i| + for i in range(0u, self.at.len()) { res = res + self.at[i] * other.at[i]; } res @@ -170,7 +169,7 @@ impl SubDot for DVec { let mut res = Zero::zero::(); - for iterate(0u, self.at.len()) |i| + for i in range(0u, self.at.len()) { res = res + (self.at[i] - a.at[i]) * b.at[i]; } res @@ -187,7 +186,7 @@ ScalarMul for DVec #[inline] fn scalar_mul_inplace(&mut self, s: &N) { - for iterate(0u, self.at.len()) |i| + for i in range(0u, self.at.len()) { self.at[i] = self.at[i] * *s; } } } @@ -203,7 +202,7 @@ ScalarDiv for DVec #[inline] fn scalar_div_inplace(&mut self, s: &N) { - for iterate(0u, self.at.len()) |i| + for i in range(0u, self.at.len()) { self.at[i] = self.at[i] / *s; } } } @@ -218,7 +217,7 @@ ScalarAdd for DVec #[inline] fn scalar_add_inplace(&mut self, s: &N) { - for iterate(0u, self.at.len()) |i| + for i in range(0u, self.at.len()) { self.at[i] = self.at[i] + *s; } } } @@ -233,7 +232,7 @@ ScalarSub for DVec #[inline] fn scalar_sub_inplace(&mut self, s: &N) { - for iterate(0u, self.at.len()) |i| + for i in range(0u, self.at.len()) { self.at[i] = self.at[i] - *s; } } } @@ -286,7 +285,7 @@ Norm for DVec { let l = self.norm(); - for iterate(0u, self.at.len()) |i| + for i in range(0u, self.at.len()) { self.at[i] = self.at[i] / l; } l diff --git a/src/mat.rs b/src/mat.rs index 99cafd53..75efe48a 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -1,7 +1,6 @@ #[allow(missing_doc)]; // we allow missing to avoid having to document the mij components. use std::cast; -use std::uint::iterate; use std::num::{One, Zero}; use std::cmp::ApproxEq; use std::iterator::IteratorUtil; diff --git a/src/mat_macros.rs b/src/mat_macros.rs index d358b417..a8f49f9c 100644 --- a/src/mat_macros.rs +++ b/src/mat_macros.rs @@ -102,7 +102,7 @@ macro_rules! column_impl( { fn set_column(&mut self, col: uint, v: V) { - foreach (i, e) in v.iter().enumerate() + for (i, e) in v.iter().enumerate() { if i == Dim::dim::<$t>() { break } @@ -115,7 +115,7 @@ macro_rules! column_impl( { let mut res = Zero::zero::(); - foreach (i, e) in res.mut_iter().enumerate() + for (i, e) in res.mut_iter().enumerate() { if i >= Dim::dim::<$t>() { break } @@ -138,13 +138,13 @@ macro_rules! mul_impl( { let mut res: $t = Zero::zero(); - for iterate(0u, $dim) |i| + for i in range(0u, $dim) { - for iterate(0u, $dim) |j| + for j in range(0u, $dim) { let mut acc = Zero::zero::(); - for iterate(0u, $dim) |k| + for k in range(0u, $dim) { acc = acc + self.at((i, k)) * other.at((k, j)); } res.set((i, j), acc); @@ -166,9 +166,9 @@ macro_rules! rmul_impl( { let mut res : $v = Zero::zero(); - for iterate(0u, $dim) |i| + for i in range(0u, $dim) { - for iterate(0u, $dim) |j| + for j in range(0u, $dim) { let val = res.at(i) + other.at(j) * self.at((i, j)); res.set(i, val) @@ -191,9 +191,9 @@ macro_rules! lmul_impl( let mut res : $v = Zero::zero(); - for iterate(0u, $dim) |i| + for i in range(0u, $dim) { - for iterate(0u, $dim) |j| + for j in range(0u, $dim) { let val = res.at(i) + other.at(j) * self.at((j, i)); res.set(i, val) @@ -250,7 +250,7 @@ macro_rules! inv_impl( let _0N: N = Zero::zero(); // inversion using Gauss-Jordan elimination - for iterate(0u, $dim) |k| + for k in range(0u, $dim) { // search a non-zero value on the k-th column // FIXME: would it be worth it to spend some more time searching for the @@ -272,7 +272,7 @@ macro_rules! inv_impl( // swap pivot line if n0 != k { - for iterate(0u, $dim) |j| + for j in range(0u, $dim) { self.swap((n0, j), (k, j)); res.swap((n0, j), (k, j)); @@ -281,31 +281,31 @@ macro_rules! inv_impl( let pivot = self.at((k, k)); - for iterate(k, $dim) |j| + for j in range(k, $dim) { let selfval = self.at((k, j)) / pivot; self.set((k, j), selfval); } - for iterate(0u, $dim) |j| + for j in range(0u, $dim) { let resval = res.at((k, j)) / pivot; res.set((k, j), resval); } - for iterate(0u, $dim) |l| + for l in range(0u, $dim) { if l != k { let normalizer = self.at((l, k)); - for iterate(k, $dim) |j| + for j in range(k, $dim) { let selfval = self.at((l, j)) - self.at((k, j)) * normalizer; self.set((l, j), selfval); } - for iterate(0u, $dim) |j| + for j in range(0u, $dim) { let resval = res.at((l, j)) - res.at((k, j)) * normalizer; res.set((l, j), resval); @@ -338,9 +338,9 @@ macro_rules! transpose_impl( fn transpose(&mut self) { - for iterate(1u, $dim) |i| + for i in range(1u, $dim) { - for iterate(0u, i) |j| + for j in range(0u, i) { self.swap((i, j), (j, i)) } } } @@ -383,9 +383,9 @@ macro_rules! to_homogeneous_impl( { let mut res: $t2 = One::one(); - for iterate(0, $dim) |i| + for i in range(0u, $dim) { - for iterate(0, $dim) |j| + for j in range(0u, $dim) { res.set((i, j), self.at((i, j))) } } @@ -403,9 +403,9 @@ macro_rules! from_homogeneous_impl( { let mut res: $t = One::one(); - for iterate(0, $dim2) |i| + for i in range(0u, $dim2) { - for iterate(0, $dim2) |j| + for j in range(0u, $dim2) { res.set((i, j), m.at((i, j))) } } diff --git a/src/tests/vec.rs b/src/tests/vec.rs index cd064a03..19a1750d 100644 --- a/src/tests/vec.rs +++ b/src/tests/vec.rs @@ -31,7 +31,7 @@ macro_rules! test_iterator_impl( let nv: $t = v.iter().transform(|e| e * n).collect(); - foreach e in mv.mut_iter() + for e in mv.mut_iter() { *e = *e * n } assert!(nv == mv && nv == v.scalar_mul(&n)); diff --git a/src/vec.rs b/src/vec.rs index 1cb3336c..0d0bd050 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -4,7 +4,6 @@ use std::rand::Rng; use std::vec::{VecIterator, VecMutIterator}; use std::iterator::{Iterator, FromIterator}; use std::cmp::ApproxEq; -use std::uint::iterate; use traits::basis::Basis; use traits::dim::Dim; use traits::translation::{Translation, Translatable}; diff --git a/src/vec_macros.rs b/src/vec_macros.rs index 23bd2116..b9b314ca 100644 --- a/src/vec_macros.rs +++ b/src/vec_macros.rs @@ -132,7 +132,7 @@ macro_rules! basis_impl( { pub fn canonical_basis(f: &fn($t)) { - for iterate(0u, $dim) |i| + for i in range(0u, $dim) { let mut basis_element : $t = Zero::zero(); @@ -148,7 +148,7 @@ macro_rules! basis_impl( // orthogonalization algorithm let mut basis: ~[$t] = ~[]; - for iterate(0u, $dim) |i| + for i in range(0u, $dim) { let mut basis_element : $t = Zero::zero(); @@ -161,7 +161,7 @@ macro_rules! basis_impl( elt = elt - self.scalar_mul(&basis_element.dot(self)); - foreach v in basis.iter() + for v in basis.iter() { elt = elt - v.scalar_mul(&elt.dot(v)) }; if !elt.sqnorm().approx_eq(&Zero::zero()) diff --git a/src/vec_spec.rs b/src/vec_spec.rs index e5b093f3..e4453b0e 100644 --- a/src/vec_spec.rs +++ b/src/vec_spec.rs @@ -150,7 +150,7 @@ impl UniformSphereSample for Vec2 { pub fn sample(f: &fn(&'static Vec2)) { - foreach sample in SAMPLES_2_F64.iter() + for sample in SAMPLES_2_F64.iter() { f(sample) } } } @@ -159,7 +159,7 @@ impl UniformSphereSample for Vec3 { pub fn sample(f: &fn(&'static Vec3)) { - foreach sample in SAMPLES_3_F64.iter() + for sample in SAMPLES_3_F64.iter() { f(sample) } } }