Merge pull request #62 from bfops/master
Update for last rustc of 2014!
This commit is contained in:
commit
445cd08eff
|
@ -83,7 +83,7 @@ macro_rules! bench_unop_self(
|
||||||
i = (i + 1) & (LEN - 1);
|
i = (i + 1) & (LEN - 1);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
test::black_box(elems.unsafe_mut(i).$unop())
|
test::black_box(elems.get_unchecked_mut(i).$unop())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#![allow(missing_docs)] // we hide doc to not have to document the $trhs double dispatch trait.
|
#![allow(missing_docs)] // we hide doc to not have to document the $trhs double dispatch trait.
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::iter::repeat;
|
||||||
use std::rand::Rand;
|
use std::rand::Rand;
|
||||||
use std::rand;
|
use std::rand;
|
||||||
use traits::operations::ApproxEq;
|
use traits::operations::ApproxEq;
|
||||||
|
@ -84,7 +85,7 @@ impl<N: Clone + Copy> DMat<N> {
|
||||||
DMat {
|
DMat {
|
||||||
nrows: nrows,
|
nrows: nrows,
|
||||||
ncols: ncols,
|
ncols: ncols,
|
||||||
mij: Vec::from_elem(nrows * ncols, val)
|
mij: repeat(val).take(nrows * ncols).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ impl<N> DMat<N> {
|
||||||
DMat {
|
DMat {
|
||||||
nrows: nrows,
|
nrows: nrows,
|
||||||
ncols: ncols,
|
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<N: Copy> Indexable<(uint, uint), N> for DMat<N> {
|
||||||
unsafe fn unsafe_set(&mut self, rowcol: (uint, uint), val: N) {
|
unsafe fn unsafe_set(&mut self, rowcol: (uint, uint), val: N) {
|
||||||
let (row, col) = rowcol;
|
let (row, col) = rowcol;
|
||||||
let offset = self.offset(row, col);
|
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.
|
/// Reads the value of a component of the matrix.
|
||||||
|
@ -236,7 +237,7 @@ impl<N: Copy> Indexable<(uint, uint), N> for DMat<N> {
|
||||||
unsafe fn unsafe_at(&self, rowcol: (uint, uint)) -> N {
|
unsafe fn unsafe_at(&self, rowcol: (uint, uint)) -> N {
|
||||||
let (row, col) = rowcol;
|
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]
|
#[inline]
|
||||||
|
@ -266,7 +267,7 @@ impl<N> Index<(uint, uint), N> for DMat<N> {
|
||||||
assert!(j < self.ncols);
|
assert!(j < self.ncols);
|
||||||
|
|
||||||
unsafe {
|
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<N> IndexMut<(uint, uint), N> for DMat<N> {
|
||||||
let offset = self.offset(i, j);
|
let offset = self.offset(i, j);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
self.mij.as_mut_slice().unsafe_mut(offset)
|
self.mij.as_mut_slice().get_unchecked_mut(offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use std::rand::Rand;
|
||||||
use std::rand;
|
use std::rand;
|
||||||
use std::slice::{Iter, IterMut};
|
use std::slice::{Iter, IterMut};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
|
use std::iter::repeat;
|
||||||
use traits::operations::{ApproxEq, Axpy};
|
use traits::operations::{ApproxEq, Axpy};
|
||||||
use traits::geometry::{Dot, Norm};
|
use traits::geometry::{Dot, Norm};
|
||||||
use traits::structure::{Iterable, IterableMut, Indexable, Shape, BaseFloat, BaseNum, Zero, One};
|
use traits::structure::{Iterable, IterableMut, Indexable, Shape, BaseFloat, BaseNum, Zero, One};
|
||||||
|
@ -34,7 +35,7 @@ impl<N: Clone> DVec<N> {
|
||||||
/// Builds a vector filled with a constant.
|
/// Builds a vector filled with a constant.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_elem(dim: uint, elem: N) -> DVec<N> {
|
pub fn from_elem(dim: uint, elem: N) -> DVec<N> {
|
||||||
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.
|
/// Builds a vector filled with the components provided by a vector.
|
||||||
|
@ -54,7 +55,7 @@ impl<N> DVec<N> {
|
||||||
/// Builds a vector filled with the result of a function.
|
/// Builds a vector filled with the result of a function.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_fn(dim: uint, f: |uint| -> N) -> DVec<N> {
|
pub fn from_fn(dim: uint, f: |uint| -> N) -> DVec<N> {
|
||||||
DVec { at: Vec::from_fn(dim, |i| f(i)) }
|
DVec { at: range(0, dim).map(|i| f(i)).collect() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -72,7 +72,7 @@ macro_rules! dvec_impl(
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn unsafe_set(&mut self, i: uint, val: N) {
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ macro_rules! at_fast_impl(
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn set_fast(&mut self, (i, j): (uint, uint), val: N) {
|
pub unsafe fn set_fast(&mut self, (i, j): (uint, uint), val: N) {
|
||||||
(*mem::transmute::<&mut $t<N>, &mut [N, ..$dim * $dim]>(self)
|
(*mem::transmute::<&mut $t<N>, &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]
|
#[inline]
|
||||||
unsafe fn unsafe_set(&mut self, (i, j): (uint, uint), val: N) {
|
unsafe fn unsafe_set(&mut self, (i, j): (uint, uint), val: N) {
|
||||||
(*mem::transmute::<&mut $t<N>, &mut [N, ..$dim * $dim]>(self).unsafe_mut(i + j * $dim)) = val
|
(*mem::transmute::<&mut $t<N>, &mut [N, ..$dim * $dim]>(self).get_unchecked_mut(i + j * $dim)) = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -70,7 +70,7 @@ macro_rules! at_fast_impl(
|
||||||
/// Unsafe write access to a vector element by index.
|
/// Unsafe write access to a vector element by index.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn set_fast(&mut self, i: uint, val: N) {
|
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]
|
#[inline]
|
||||||
unsafe fn unsafe_set(&mut self, i: uint, val: N) {
|
unsafe fn unsafe_set(&mut self, i: uint, val: N) {
|
||||||
(*mem::transmute::<&mut $t<N>, &mut [N, ..$dim]>(self).unsafe_mut(i)) = val
|
(*mem::transmute::<&mut $t<N>, &mut [N, ..$dim]>(self).get_unchecked_mut(i)) = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue