From b701ca3b58fe6526b7206d837fad5c3dbd7a169f Mon Sep 17 00:00:00 2001 From: Ben Foppa Date: Thu, 1 Jan 2015 17:23:35 -0500 Subject: [PATCH] Update for last rustc of 2014! --- benches/common/macros.rs | 2 +- src/structs/dmat.rs | 13 +++++++------ src/structs/dvec.rs | 5 +++-- src/structs/dvec_macros.rs | 2 +- src/structs/mat_macros.rs | 4 ++-- src/structs/vec_macros.rs | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/benches/common/macros.rs b/benches/common/macros.rs index 57492c47..66b3897d 100644 --- a/benches/common/macros.rs +++ b/benches/common/macros.rs @@ -83,7 +83,7 @@ macro_rules! bench_unop_self( i = (i + 1) & (LEN - 1); unsafe { - test::black_box(elems.unsafe_mut(i).$unop()) + test::black_box(elems.get_unchecked_mut(i).$unop()) } }) } diff --git a/src/structs/dmat.rs b/src/structs/dmat.rs index 757770a6..fbd04268 100644 --- a/src/structs/dmat.rs +++ b/src/structs/dmat.rs @@ -3,6 +3,7 @@ #![allow(missing_docs)] // we hide doc to not have to document the $trhs double dispatch trait. use std::cmp; +use std::iter::repeat; use std::rand::Rand; use std::rand; use traits::operations::ApproxEq; @@ -84,7 +85,7 @@ impl DMat { DMat { nrows: nrows, ncols: ncols, - mij: Vec::from_elem(nrows * ncols, val) + mij: repeat(val).take(nrows * ncols).collect() } } @@ -129,7 +130,7 @@ impl DMat { DMat { nrows: nrows, ncols: ncols, - mij: Vec::from_fn(nrows * ncols, |i| { let m = i / nrows; f(i - m * nrows, m) }) + mij: range(0, nrows * ncols).map(|i| { let m = i / nrows; f(i - m * nrows, m) }).collect() } } @@ -216,7 +217,7 @@ impl Indexable<(uint, uint), N> for DMat { unsafe fn unsafe_set(&mut self, rowcol: (uint, uint), val: N) { let (row, col) = rowcol; let offset = self.offset(row, col); - *self.mij.as_mut_slice().unsafe_mut(offset) = val + *self.mij.as_mut_slice().get_unchecked_mut(offset) = val } /// Reads the value of a component of the matrix. @@ -236,7 +237,7 @@ impl Indexable<(uint, uint), N> for DMat { unsafe fn unsafe_at(&self, rowcol: (uint, uint)) -> N { let (row, col) = rowcol; - *self.mij.as_slice().unsafe_get(self.offset(row, col)) + *self.mij.as_slice().get_unchecked(self.offset(row, col)) } #[inline] @@ -266,7 +267,7 @@ impl Index<(uint, uint), N> for DMat { assert!(j < self.ncols); unsafe { - self.mij.as_slice().unsafe_get(self.offset(i, j)) + self.mij.as_slice().get_unchecked(self.offset(i, j)) } } } @@ -279,7 +280,7 @@ impl IndexMut<(uint, uint), N> for DMat { let offset = self.offset(i, j); unsafe { - self.mij.as_mut_slice().unsafe_mut(offset) + self.mij.as_mut_slice().get_unchecked_mut(offset) } } } diff --git a/src/structs/dvec.rs b/src/structs/dvec.rs index e99b1524..57d71723 100644 --- a/src/structs/dvec.rs +++ b/src/structs/dvec.rs @@ -6,6 +6,7 @@ use std::rand::Rand; use std::rand; use std::slice::{Iter, IterMut}; use std::iter::FromIterator; +use std::iter::repeat; use traits::operations::{ApproxEq, Axpy}; use traits::geometry::{Dot, Norm}; use traits::structure::{Iterable, IterableMut, Indexable, Shape, BaseFloat, BaseNum, Zero, One}; @@ -34,7 +35,7 @@ impl DVec { /// Builds a vector filled with a constant. #[inline] pub fn from_elem(dim: uint, elem: N) -> DVec { - DVec { at: Vec::from_elem(dim, elem) } + DVec { at: repeat(elem).take(dim).collect() } } /// Builds a vector filled with the components provided by a vector. @@ -54,7 +55,7 @@ impl DVec { /// Builds a vector filled with the result of a function. #[inline(always)] pub fn from_fn(dim: uint, f: |uint| -> N) -> DVec { - DVec { at: Vec::from_fn(dim, |i| f(i)) } + DVec { at: range(0, dim).map(|i| f(i)).collect() } } #[inline] diff --git a/src/structs/dvec_macros.rs b/src/structs/dvec_macros.rs index 8ee1f762..5f3c4922 100644 --- a/src/structs/dvec_macros.rs +++ b/src/structs/dvec_macros.rs @@ -72,7 +72,7 @@ macro_rules! dvec_impl( #[inline] unsafe fn unsafe_set(&mut self, i: uint, val: N) { - *self.at.as_mut_slice().unsafe_mut(i) = val + *self.at.as_mut_slice().get_unchecked_mut(i) = val } } diff --git a/src/structs/mat_macros.rs b/src/structs/mat_macros.rs index 9d91d5e5..82168b5e 100644 --- a/src/structs/mat_macros.rs +++ b/src/structs/mat_macros.rs @@ -69,7 +69,7 @@ macro_rules! at_fast_impl( #[inline] pub unsafe fn set_fast(&mut self, (i, j): (uint, uint), val: N) { (*mem::transmute::<&mut $t, &mut [N, ..$dim * $dim]>(self) - .unsafe_mut(i + j * $dim)) = val + .get_unchecked_mut(i + j * $dim)) = val } } ) @@ -283,7 +283,7 @@ macro_rules! indexable_impl( #[inline] unsafe fn unsafe_set(&mut self, (i, j): (uint, uint), val: N) { - (*mem::transmute::<&mut $t, &mut [N, ..$dim * $dim]>(self).unsafe_mut(i + j * $dim)) = val + (*mem::transmute::<&mut $t, &mut [N, ..$dim * $dim]>(self).get_unchecked_mut(i + j * $dim)) = val } } ) diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index f33e0644..c9788cd4 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -70,7 +70,7 @@ macro_rules! at_fast_impl( /// Unsafe write access to a vector element by index. #[inline] pub unsafe fn set_fast(&mut self, i: uint, val: N) { - (*self.as_array_mut().unsafe_mut(i)) = val + (*self.as_array_mut().get_unchecked_mut(i)) = val } } ) @@ -228,7 +228,7 @@ macro_rules! indexable_impl( #[inline] unsafe fn unsafe_set(&mut self, i: uint, val: N) { - (*mem::transmute::<&mut $t, &mut [N, ..$dim]>(self).unsafe_mut(i)) = val + (*mem::transmute::<&mut $t, &mut [N, ..$dim]>(self).get_unchecked_mut(i)) = val } } )