From 51fd2bc744c09d077e571f4b43fd32bb397972c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 2 Jul 2013 10:00:55 +0000 Subject: [PATCH] map -> iter().transform --- src/dmat.rs | 8 ++++---- src/dvec.rs | 20 ++++++++++++-------- src/mat.rs | 1 - src/mat_impl.rs | 6 +++--- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/dmat.rs b/src/dmat.rs index 87f7cb7e..db5d11a1 100644 --- a/src/dmat.rs +++ b/src/dmat.rs @@ -1,6 +1,6 @@ use std::uint::iterate; use std::num::{One, Zero}; -use std::vec::{from_elem, swap}; +use std::vec::from_elem; use std::cmp::ApproxEq; use std::iterator::IteratorUtil; use traits::inv::Inv; @@ -179,8 +179,8 @@ Inv for DMat let off_n0_j = self.offset(n0, j); let off_k_j = self.offset(k, j); - swap(self.mij, off_n0_j, off_k_j); - swap(res.mij, off_n0_j, off_k_j); + self.mij.swap(off_n0_j, off_k_j); + res.mij.swap(off_n0_j, off_k_j); } } @@ -246,7 +246,7 @@ impl Transpose for DMat let off_i_j = self.offset(i, j); 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); } } } diff --git a/src/dvec.rs b/src/dvec.rs index 8673cce7..4d9f5a35 100644 --- a/src/dvec.rs +++ b/src/dvec.rs @@ -1,7 +1,7 @@ use std::uint::iterate; use std::num::{Zero, One, Algebraic}; use std::vec::{VecIterator, VecMutIterator}; -use std::vec::{map_zip, map, from_elem}; +use std::vec::from_elem; use std::cmp::ApproxEq; use std::iterator::{FromIterator, IteratorUtil}; use traits::iterable::{Iterable, IterableMut}; @@ -110,7 +110,9 @@ impl> Add, DVec> for DVec fn add(&self, other: &DVec) -> DVec { 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> Sub, DVec> for DVec fn sub(&self, other: &DVec) -> DVec { 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> Neg> for DVec { #[inline] fn neg(&self) -> DVec - { DVec { at: map(self.at, |a| -a) } } + { DVec { at: self.at.iter().transform(|a| -a).collect() } } } impl @@ -167,7 +171,7 @@ ScalarMul for DVec { #[inline] fn scalar_mul(&self, s: &N) -> DVec - { DVec { at: map(self.at, |a| a * *s) } } + { DVec { at: self.at.iter().transform(|a| a * *s).collect() } } #[inline] fn scalar_mul_inplace(&mut self, s: &N) @@ -183,7 +187,7 @@ ScalarDiv for DVec { #[inline] fn scalar_div(&self, s: &N) -> DVec - { DVec { at: map(self.at, |a| a / *s) } } + { DVec { at: self.at.iter().transform(|a| a / *s).collect() } } #[inline] fn scalar_div_inplace(&mut self, s: &N) @@ -198,7 +202,7 @@ ScalarAdd for DVec { #[inline] fn scalar_add(&self, s: &N) -> DVec - { DVec { at: map(self.at, |a| a + *s) } } + { DVec { at: self.at.iter().transform(|a| a + *s).collect() } } #[inline] fn scalar_add_inplace(&mut self, s: &N) @@ -213,7 +217,7 @@ ScalarSub for DVec { #[inline] fn scalar_sub(&self, s: &N) -> DVec - { DVec { at: map(self.at, |a| a - *s) } } + { DVec { at: self.at.iter().transform(|a| a - *s).collect() } } #[inline] fn scalar_sub_inplace(&mut self, s: &N) diff --git a/src/mat.rs b/src/mat.rs index d8d2a025..4fe5ef7d 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -1,6 +1,5 @@ use std::uint::iterate; use std::num::{One, Zero}; -use std::vec::swap; use std::cmp::ApproxEq; use std::rand::{Rand, Rng, RngUtil}; use std::iterator::IteratorUtil; diff --git a/src/mat_impl.rs b/src/mat_impl.rs index 37bc221c..0b7ed0d6 100644 --- a/src/mat_impl.rs +++ b/src/mat_impl.rs @@ -238,8 +238,8 @@ macro_rules! inv_impl( let off_n0_j = self.offset(n0, j); let off_k_j = self.offset(k, j); - swap(self.mij, off_n0_j, off_k_j); - swap(res.mij, off_n0_j, off_k_j); + self.mij.swap(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_j_i = self.offset(j, i); - swap(self.mij, off_i_j, off_j_i); + self.mij.swap(off_i_j, off_j_i); } } }