map -> iter().transform

This commit is contained in:
Sébastien Crozet 2013-07-02 10:00:55 +00:00
parent 68d601a642
commit 51fd2bc744
4 changed files with 19 additions and 16 deletions

View File

@ -1,6 +1,6 @@
use std::uint::iterate; use std::uint::iterate;
use std::num::{One, Zero}; use std::num::{One, Zero};
use std::vec::{from_elem, swap}; use std::vec::from_elem;
use std::cmp::ApproxEq; use std::cmp::ApproxEq;
use std::iterator::IteratorUtil; use std::iterator::IteratorUtil;
use traits::inv::Inv; use traits::inv::Inv;
@ -179,8 +179,8 @@ Inv for DMat<N>
let off_n0_j = self.offset(n0, j); let off_n0_j = self.offset(n0, j);
let off_k_j = self.offset(k, j); let off_k_j = self.offset(k, j);
swap(self.mij, off_n0_j, off_k_j); self.mij.swap(off_n0_j, off_k_j);
swap(res.mij, off_n0_j, off_k_j); res.mij.swap(off_n0_j, off_k_j);
} }
} }
@ -246,7 +246,7 @@ impl<N:Copy> Transpose for DMat<N>
let off_i_j = self.offset(i, j); let off_i_j = self.offset(i, j);
let off_j_i = self.offset(j, i); let off_j_i = self.offset(j, i);
swap(self.mij, off_i_j, off_j_i); self.mij.swap(off_i_j, off_j_i);
} }
} }
} }

View File

@ -1,7 +1,7 @@
use std::uint::iterate; use std::uint::iterate;
use std::num::{Zero, One, Algebraic}; use std::num::{Zero, One, Algebraic};
use std::vec::{VecIterator, VecMutIterator}; use std::vec::{VecIterator, VecMutIterator};
use std::vec::{map_zip, map, from_elem}; use std::vec::from_elem;
use std::cmp::ApproxEq; use std::cmp::ApproxEq;
use std::iterator::{FromIterator, IteratorUtil}; use std::iterator::{FromIterator, IteratorUtil};
use traits::iterable::{Iterable, IterableMut}; use traits::iterable::{Iterable, IterableMut};
@ -110,7 +110,9 @@ impl<N: Copy + Add<N,N>> Add<DVec<N>, DVec<N>> for DVec<N>
fn add(&self, other: &DVec<N>) -> DVec<N> fn add(&self, other: &DVec<N>) -> DVec<N>
{ {
assert!(self.at.len() == other.at.len()); assert!(self.at.len() == other.at.len());
DVec { at: map_zip(self.at, other.at, | a, b | { *a + *b }) } DVec {
at: self.at.iter().zip(other.at.iter()).transform(|(a, b)| *a + *b).collect()
}
} }
} }
@ -120,7 +122,9 @@ impl<N: Copy + Sub<N,N>> Sub<DVec<N>, DVec<N>> for DVec<N>
fn sub(&self, other: &DVec<N>) -> DVec<N> fn sub(&self, other: &DVec<N>) -> DVec<N>
{ {
assert!(self.at.len() == other.at.len()); assert!(self.at.len() == other.at.len());
DVec { at: map_zip(self.at, other.at, | a, b | *a - *b) } DVec {
at: self.at.iter().zip(other.at.iter()).transform(|(a, b)| *a - *b).collect()
}
} }
} }
@ -128,7 +132,7 @@ impl<N: Neg<N>> Neg<DVec<N>> for DVec<N>
{ {
#[inline] #[inline]
fn neg(&self) -> DVec<N> fn neg(&self) -> DVec<N>
{ DVec { at: map(self.at, |a| -a) } } { DVec { at: self.at.iter().transform(|a| -a).collect() } }
} }
impl<N: Ring> impl<N: Ring>
@ -167,7 +171,7 @@ ScalarMul<N> for DVec<N>
{ {
#[inline] #[inline]
fn scalar_mul(&self, s: &N) -> DVec<N> fn scalar_mul(&self, s: &N) -> DVec<N>
{ DVec { at: map(self.at, |a| a * *s) } } { DVec { at: self.at.iter().transform(|a| a * *s).collect() } }
#[inline] #[inline]
fn scalar_mul_inplace(&mut self, s: &N) fn scalar_mul_inplace(&mut self, s: &N)
@ -183,7 +187,7 @@ ScalarDiv<N> for DVec<N>
{ {
#[inline] #[inline]
fn scalar_div(&self, s: &N) -> DVec<N> fn scalar_div(&self, s: &N) -> DVec<N>
{ DVec { at: map(self.at, |a| a / *s) } } { DVec { at: self.at.iter().transform(|a| a / *s).collect() } }
#[inline] #[inline]
fn scalar_div_inplace(&mut self, s: &N) fn scalar_div_inplace(&mut self, s: &N)
@ -198,7 +202,7 @@ ScalarAdd<N> for DVec<N>
{ {
#[inline] #[inline]
fn scalar_add(&self, s: &N) -> DVec<N> fn scalar_add(&self, s: &N) -> DVec<N>
{ DVec { at: map(self.at, |a| a + *s) } } { DVec { at: self.at.iter().transform(|a| a + *s).collect() } }
#[inline] #[inline]
fn scalar_add_inplace(&mut self, s: &N) fn scalar_add_inplace(&mut self, s: &N)
@ -213,7 +217,7 @@ ScalarSub<N> for DVec<N>
{ {
#[inline] #[inline]
fn scalar_sub(&self, s: &N) -> DVec<N> fn scalar_sub(&self, s: &N) -> DVec<N>
{ DVec { at: map(self.at, |a| a - *s) } } { DVec { at: self.at.iter().transform(|a| a - *s).collect() } }
#[inline] #[inline]
fn scalar_sub_inplace(&mut self, s: &N) fn scalar_sub_inplace(&mut self, s: &N)

View File

@ -1,6 +1,5 @@
use std::uint::iterate; use std::uint::iterate;
use std::num::{One, Zero}; use std::num::{One, Zero};
use std::vec::swap;
use std::cmp::ApproxEq; use std::cmp::ApproxEq;
use std::rand::{Rand, Rng, RngUtil}; use std::rand::{Rand, Rng, RngUtil};
use std::iterator::IteratorUtil; use std::iterator::IteratorUtil;

View File

@ -238,8 +238,8 @@ macro_rules! inv_impl(
let off_n0_j = self.offset(n0, j); let off_n0_j = self.offset(n0, j);
let off_k_j = self.offset(k, j); let off_k_j = self.offset(k, j);
swap(self.mij, off_n0_j, off_k_j); self.mij.swap(off_n0_j, off_k_j);
swap(res.mij, off_n0_j, off_k_j); res.mij.swap(off_n0_j, off_k_j);
} }
} }
@ -307,7 +307,7 @@ macro_rules! transpose_impl(
let off_i_j = self.offset(i, j); let off_i_j = self.offset(i, j);
let off_j_i = self.offset(j, i); let off_j_i = self.offset(j, i);
swap(self.mij, off_i_j, off_j_i); self.mij.swap(off_i_j, off_j_i);
} }
} }
} }