Fix `for` loops (again) + `iterate` becomes `range`.

This commit is contained in:
Sébastien Crozet 2013-08-03 12:21:56 +02:00
parent 7b2dbb244e
commit 50b34ca765
8 changed files with 56 additions and 60 deletions

View File

@ -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<N: Clone + One + Zero>(dim: uint) -> DMat<N>
let mut res = zero_mat_with_dim(dim);
let _1 = One::one::<N>();
for iterate(0u, dim) |i|
for i in range(0u, dim)
{ res.set(i, i, &_1); }
res
@ -98,13 +97,13 @@ Mul<DMat<N>, DMat<N>> for DMat<N>
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::<N>();
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<DVec<N>> for DMat<N>
let dim = self.dim;
let mut res : DVec<N> = 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<DVec<N>> for DMat<N>
let dim = self.dim;
let mut res : DVec<N> = 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<N>
let _0T = Zero::zero::<N>();
// 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<N>
// 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<N>
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<N: Clone> Transpose for DMat<N>
{
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);

View File

@ -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<N, Iter: Iterator<N>> FromIterator<N, Iter> for DVec<N>
{
let mut res = DVec { at: ~[] };
foreach e in param
for e in param
{ res.at.push(e) }
res
@ -68,7 +67,7 @@ impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> DVec<N>
{
let mut res : ~[DVec<N>] = ~[];
for iterate(0u, dim) |i|
for i in range(0u, dim)
{
let mut basis_element : DVec<N> = zero_vec_with_dim(dim);
@ -89,7 +88,7 @@ impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> DVec<N>
let dim = self.at.len();
let mut res : ~[DVec<N>] = ~[];
for iterate(0u, dim) |i|
for i in range(0u, dim)
{
let mut basis_element : DVec<N> = zero_vec_with_dim(self.at.len());
@ -102,7 +101,7 @@ impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> DVec<N>
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<N> for DVec<N>
let mut res = Zero::zero::<N>();
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<N: Ring> SubDot<N> for DVec<N>
{
let mut res = Zero::zero::<N>();
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<N> for DVec<N>
#[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<N> for DVec<N>
#[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<N> for DVec<N>
#[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<N> for DVec<N>
#[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<N> for DVec<N>
{
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

View File

@ -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;

View File

@ -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<N>>()
{ break }
@ -115,7 +115,7 @@ macro_rules! column_impl(
{
let mut res = Zero::zero::<V>();
foreach (i, e) in res.mut_iter().enumerate()
for (i, e) in res.mut_iter().enumerate()
{
if i >= Dim::dim::<$t<N>>()
{ break }
@ -138,13 +138,13 @@ macro_rules! mul_impl(
{
let mut res: $t<N> = 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::<N>();
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<N> = 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<N> = 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<N> = 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<N> = 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))) }
}

View File

@ -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));

View File

@ -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};

View File

@ -132,7 +132,7 @@ macro_rules! basis_impl(
{
pub fn canonical_basis(f: &fn($t<N>))
{
for iterate(0u, $dim) |i|
for i in range(0u, $dim)
{
let mut basis_element : $t<N> = Zero::zero();
@ -148,7 +148,7 @@ macro_rules! basis_impl(
// orthogonalization algorithm
let mut basis: ~[$t<N>] = ~[];
for iterate(0u, $dim) |i|
for i in range(0u, $dim)
{
let mut basis_element : $t<N> = 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())

View File

@ -150,7 +150,7 @@ impl UniformSphereSample for Vec2<f64>
{
pub fn sample(f: &fn(&'static Vec2<f64>))
{
foreach sample in SAMPLES_2_F64.iter()
for sample in SAMPLES_2_F64.iter()
{ f(sample) }
}
}
@ -159,7 +159,7 @@ impl UniformSphereSample for Vec3<f64>
{
pub fn sample(f: &fn(&'static Vec3<f64>))
{
foreach sample in SAMPLES_3_F64.iter()
for sample in SAMPLES_3_F64.iter()
{ f(sample) }
}
}