Merge pull request #73 from sebcrozet/rustup_warn

Rustup warn
This commit is contained in:
Sébastien Crozet 2015-01-09 23:07:09 +01:00
commit dc7a85ccde
24 changed files with 373 additions and 375 deletions

View File

@ -4,12 +4,12 @@ macro_rules! bench_binop(
($name: ident, $t1: ty, $t2: ty, $binop: ident) => { ($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
#[bench] #[bench]
fn $name(bh: &mut Bencher) { fn $name(bh: &mut Bencher) {
const LEN: uint = 1 << 13; const LEN: usize = 1 << 13;
let mut rng = IsaacRng::new_unseeded(); let mut rng = IsaacRng::new_unseeded();
let elems1 = Vec::from_fn(LEN, |_| rng.gen::<$t1>()); let elems1: Vec<$t1> = (0us .. LEN).map(|_| rng.gen::<$t1>()).collect();
let elems2 = Vec::from_fn(LEN, |_| rng.gen::<$t2>()); let elems2: Vec<$t2> = (0us .. LEN).map(|_| rng.gen::<$t2>()).collect();
let mut i = 0; let mut i = 0;
bh.iter(|| { bh.iter(|| {
@ -27,12 +27,12 @@ macro_rules! bench_binop_na(
($name: ident, $t1: ty, $t2: ty, $binop: ident) => { ($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
#[bench] #[bench]
fn $name(bh: &mut Bencher) { fn $name(bh: &mut Bencher) {
const LEN: uint = 1 << 13; const LEN: usize = 1 << 13;
let mut rng = IsaacRng::new_unseeded(); let mut rng = IsaacRng::new_unseeded();
let elems1 = Vec::from_fn(LEN, |_| rng.gen::<$t1>()); let elems1: Vec<$t1> = (0us .. LEN).map(|_| rng.gen::<$t1>()).collect();
let elems2 = Vec::from_fn(LEN, |_| rng.gen::<$t2>()); let elems2: Vec<$t2> = (0us .. LEN).map(|_| rng.gen::<$t2>()).collect();
let mut i = 0; let mut i = 0;
bh.iter(|| { bh.iter(|| {
@ -50,11 +50,11 @@ macro_rules! bench_unop(
($name: ident, $t: ty, $unop: ident) => { ($name: ident, $t: ty, $unop: ident) => {
#[bench] #[bench]
fn $name(bh: &mut Bencher) { fn $name(bh: &mut Bencher) {
const LEN: uint = 1 << 13; const LEN: usize = 1 << 13;
let mut rng = IsaacRng::new_unseeded(); let mut rng = IsaacRng::new_unseeded();
let elems = Vec::from_fn(LEN, |_| rng.gen::<$t>()); let elems: Vec<$t> = (0us .. LEN).map(|_| rng.gen::<$t>()).collect();
let mut i = 0; let mut i = 0;
bh.iter(|| { bh.iter(|| {
@ -72,11 +72,11 @@ macro_rules! bench_unop_self(
($name: ident, $t: ty, $unop: ident) => { ($name: ident, $t: ty, $unop: ident) => {
#[bench] #[bench]
fn $name(bh: &mut Bencher) { fn $name(bh: &mut Bencher) {
const LEN: uint = 1 << 13; const LEN: usize = 1 << 13;
let mut rng = IsaacRng::new_unseeded(); let mut rng = IsaacRng::new_unseeded();
let mut elems = Vec::from_fn(LEN, |_| rng.gen::<$t>()); let mut elems: Vec<$t> = (0us .. LEN).map(|_| rng.gen::<$t>()).collect();
let mut i = 0; let mut i = 0;
bh.iter(|| { bh.iter(|| {
@ -91,14 +91,14 @@ macro_rules! bench_unop_self(
); );
macro_rules! bench_construction( macro_rules! bench_construction(
($name: ident, $constructor: path $(, $args: ident: $types: ty)*) => { ($name: ident, $constructor: path, $( $args: ident: $types: ty),*) => {
#[bench] #[bench]
fn $name(bh: &mut Bencher) { fn $name(bh: &mut Bencher) {
const LEN: uint = 1 << 13; const LEN: usize = 1 << 13;
let mut rng = IsaacRng::new_unseeded(); let mut rng = IsaacRng::new_unseeded();
$(let $args = Vec::from_fn(LEN, |_| rng.gen::<$types>());)* $(let $args: Vec<$types> = (0us .. LEN).map(|_| rng.gen::<$types>()).collect();)*
let mut i = 0; let mut i = 0;
bh.iter(|| { bh.iter(|| {

View File

@ -11,7 +11,7 @@ macro_rules! bench_mul_dmat(
let a: DMat<f64> = DMat::new_random($nrows, $ncols); let a: DMat<f64> = DMat::new_random($nrows, $ncols);
let mut b: DMat<f64> = DMat::new_random($nrows, $ncols); let mut b: DMat<f64> = DMat::new_random($nrows, $ncols);
for _ in range(0u, 1000) { for _ in (0us .. 1000) {
// XXX: the clone here is highly undesirable! // XXX: the clone here is highly undesirable!
b = a.clone() * b; b = a.clone() * b;
} }
@ -53,7 +53,7 @@ macro_rules! bench_mul_dmat_dvec(
let m : DMat<f64> = DMat::new_random($nrows, $ncols); let m : DMat<f64> = DMat::new_random($nrows, $ncols);
let mut v : DVec<f64> = DVec::new_random($ncols); let mut v : DVec<f64> = DVec::new_random($ncols);
for _ in range(0u, 1000) { for _ in (0us .. 1000) {
// XXX: the clone here is highly undesirable! // XXX: the clone here is highly undesirable!
v = m.clone() * v v = m.clone() * v
} }

View File

@ -81,6 +81,7 @@ Feel free to add your project to this list if you happen to use **nalgebra**!
#![deny(non_upper_case_globals)] #![deny(non_upper_case_globals)]
#![deny(unused_qualifications)] #![deny(unused_qualifications)]
#![deny(unused_results)] #![deny(unused_results)]
#![allow(unstable)]
#![warn(missing_docs)] #![warn(missing_docs)]
#![feature(old_orphan_check)] #![feature(old_orphan_check)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
@ -837,7 +838,7 @@ pub fn mean<N, M: Mean<N>>(observations: &M) -> N {
*/ */
/// Computes the eigenvalues and eigenvectors of a square matrix usin the QR algorithm. /// Computes the eigenvalues and eigenvectors of a square matrix usin the QR algorithm.
#[inline(always)] #[inline(always)]
pub fn eigen_qr<N, V, M: EigenQR<N, V>>(m: &M, eps: &N, niter: uint) -> (M, V) { pub fn eigen_qr<N, V, M: EigenQR<N, V>>(m: &M, eps: &N, niter: usize) -> (M, V) {
EigenQR::eigen_qr(m, eps, niter) EigenQR::eigen_qr(m, eps, niter)
} }
@ -852,7 +853,7 @@ pub fn eigen_qr<N, V, M: EigenQR<N, V>>(m: &M, eps: &N, niter: uint) -> (M, V) {
*/ */
/// Construct the identity matrix for a given dimension /// Construct the identity matrix for a given dimension
#[inline(always)] #[inline(always)]
pub fn new_identity<M: Eye>(dim: uint) -> M { pub fn new_identity<M: Eye>(dim: usize) -> M {
Eye::new_identity(dim) Eye::new_identity(dim)
} }
@ -874,7 +875,7 @@ pub fn orthonormal_subspace_basis<V: Basis, F: FnMut(V) -> bool>(v: &V, f: F) {
/// Gets the (0-based) i-th element of the canonical basis of V. /// Gets the (0-based) i-th element of the canonical basis of V.
#[inline] #[inline]
pub fn canonical_basis_element<V: Basis>(i: uint) -> Option<V> { pub fn canonical_basis_element<V: Basis>(i: usize) -> Option<V> {
Basis::canonical_basis_element(i) Basis::canonical_basis_element(i)
} }
@ -902,7 +903,7 @@ pub fn diag<M: Diag<V>, V>(m: &M) -> V {
/// ///
/// Same as `Dim::dim::(None::<V>)`. /// Same as `Dim::dim::(None::<V>)`.
#[inline(always)] #[inline(always)]
pub fn dim<V: Dim>() -> uint { pub fn dim<V: Dim>() -> usize {
Dim::dim(None::<V>) Dim::dim(None::<V>)
} }

View File

@ -11,10 +11,10 @@ use std::ops::{Mul, Add, Sub};
/// * `dim` - the dimension of the space the resulting matrix operates in /// * `dim` - the dimension of the space the resulting matrix operates in
/// * `start` - the starting dimension of the subspace of the reflexion /// * `start` - the starting dimension of the subspace of the reflexion
/// * `vec` - the vector defining the reflection. /// * `vec` - the vector defining the reflection.
pub fn householder_matrix<N, V, M>(dim: uint, start: uint, vec: V) -> M pub fn householder_matrix<N, V, M>(dim: usize, start: usize, vec: V) -> M
where N: BaseFloat, where N: BaseFloat,
M: Eye + Indexable<(uint, uint), N>, M: Eye + Indexable<(usize, usize), N>,
V: Indexable<uint, N> { V: Indexable<usize, N> {
let mut qk : M = Eye::new_identity(dim); let mut qk : M = Eye::new_identity(dim);
let subdim = vec.shape(); let subdim = vec.shape();
@ -22,8 +22,8 @@ pub fn householder_matrix<N, V, M>(dim: uint, start: uint, vec: V) -> M
assert!(dim >= stop); assert!(dim >= stop);
for j in range(start, stop) { for j in (start .. stop) {
for i in range(start, stop) { for i in (start .. stop) {
unsafe { unsafe {
let vv = vec.unsafe_at(i - start) * vec.unsafe_at(j - start); let vv = vec.unsafe_at(i - start) * vec.unsafe_at(j - start);
let qkij = qk.unsafe_at((i, j)); let qkij = qk.unsafe_at((i, j));
@ -40,8 +40,8 @@ pub fn householder_matrix<N, V, M>(dim: uint, start: uint, vec: V) -> M
/// * `m` - matrix to decompose /// * `m` - matrix to decompose
pub fn qr<N, V, M>(m: &M) -> (M, M) pub fn qr<N, V, M>(m: &M) -> (M, M)
where N: BaseFloat, where N: BaseFloat,
V: Indexable<uint, N> + Norm<N>, V: Indexable<usize, N> + Norm<N>,
M: Copy + Eye + ColSlice<V> + Transpose + Indexable<(uint, uint), N> + M: Copy + Eye + ColSlice<V> + Transpose + Indexable<(usize, usize), N> +
Mul<M, Output = M> { Mul<M, Output = M> {
let (rows, cols) = m.shape(); let (rows, cols) = m.shape();
assert!(rows >= cols); assert!(rows >= cols);
@ -50,7 +50,7 @@ pub fn qr<N, V, M>(m: &M) -> (M, M)
let iterations = min(rows - 1, cols); let iterations = min(rows - 1, cols);
for ite in range(0u, iterations) { for ite in (0us .. iterations) {
let mut v = r.col_slice(ite, ite, rows); let mut v = r.col_slice(ite, ite, rows);
let alpha = let alpha =
if unsafe { v.unsafe_at(ite) } >= ::zero() { if unsafe { v.unsafe_at(ite) } >= ::zero() {
@ -74,29 +74,29 @@ pub fn qr<N, V, M>(m: &M) -> (M, M)
} }
/// Eigendecomposition of a square matrix using the qr algorithm. /// Eigendecomposition of a square matrix using the qr algorithm.
pub fn eigen_qr<N, V, VS, M>(m: &M, eps: &N, niter: uint) -> (M, V) pub fn eigen_qr<N, V, VS, M>(m: &M, eps: &N, niter: usize) -> (M, V)
where N: BaseFloat, where N: BaseFloat,
VS: Indexable<uint, N> + Norm<N>, VS: Indexable<usize, N> + Norm<N>,
M: Indexable<(uint, uint), N> + SquareMat<N, V> + Add<M, Output = M> + M: Indexable<(usize, usize), N> + SquareMat<N, V> + Add<M, Output = M> +
Sub<M, Output = M> + ColSlice<VS> + Sub<M, Output = M> + ColSlice<VS> +
ApproxEq<N> + Copy { ApproxEq<N> + Copy {
let mut eigenvectors: M = ::one::<M>(); let mut eigenvectors: M = ::one::<M>();
let mut eigenvalues = *m; let mut eigenvalues = *m;
// let mut shifter: M = Eye::new_identity(rows); // let mut shifter: M = Eye::new_identity(rows);
let mut iter = 0u; let mut iter = 0us;
for _ in range(0, niter) { for _ in (0 .. niter) {
let mut stop = true; let mut stop = true;
for j in range(0, ::dim::<M>()) { for j in (0 .. ::dim::<M>()) {
for i in range(0, j) { for i in (0 .. j) {
if unsafe { eigenvalues.unsafe_at((i, j)) }.abs() >= *eps { if unsafe { eigenvalues.unsafe_at((i, j)) }.abs() >= *eps {
stop = false; stop = false;
break; break;
} }
} }
for i in range(j + 1, ::dim::<M>()) { for i in (j + 1 .. ::dim::<M>()) {
if unsafe { eigenvalues.unsafe_at((i, j)) }.abs() >= *eps { if unsafe { eigenvalues.unsafe_at((i, j)) }.abs() >= *eps {
stop = false; stop = false;
break; break;

View File

@ -18,15 +18,15 @@ use std::fmt::{Show, Formatter, Result, String};
/// Matrix with dimensions unknown at compile-time. /// Matrix with dimensions unknown at compile-time.
#[derive(Eq, PartialEq, Clone)] #[derive(Eq, PartialEq, Clone)]
pub struct DMat<N> { pub struct DMat<N> {
nrows: uint, nrows: usize,
ncols: uint, ncols: usize,
mij: Vec<N> mij: Vec<N>
} }
impl<N> DMat<N> { impl<N> DMat<N> {
/// Creates an uninitialized matrix. /// Creates an uninitialized matrix.
#[inline] #[inline]
pub unsafe fn new_uninitialized(nrows: uint, ncols: uint) -> DMat<N> { pub unsafe fn new_uninitialized(nrows: usize, ncols: usize) -> DMat<N> {
let mut vec = Vec::with_capacity(nrows * ncols); let mut vec = Vec::with_capacity(nrows * ncols);
vec.set_len(nrows * ncols); vec.set_len(nrows * ncols);
@ -45,7 +45,7 @@ impl<N: Zero + Clone + Copy> DMat<N> {
/// * `dim` - The dimension of the matrix. A `dim`-dimensional matrix contains `dim * dim` /// * `dim` - The dimension of the matrix. A `dim`-dimensional matrix contains `dim * dim`
/// components. /// components.
#[inline] #[inline]
pub fn new_zeros(nrows: uint, ncols: uint) -> DMat<N> { pub fn new_zeros(nrows: usize, ncols: usize) -> DMat<N> {
DMat::from_elem(nrows, ncols, ::zero()) DMat::from_elem(nrows, ncols, ::zero())
} }
@ -66,7 +66,7 @@ impl<N: Zero + Clone + Copy> DMat<N> {
impl<N: Rand> DMat<N> { impl<N: Rand> DMat<N> {
/// Builds a matrix filled with random values. /// Builds a matrix filled with random values.
#[inline] #[inline]
pub fn new_random(nrows: uint, ncols: uint) -> DMat<N> { pub fn new_random(nrows: usize, ncols: usize) -> DMat<N> {
DMat::from_fn(nrows, ncols, |_, _| rand::random()) DMat::from_fn(nrows, ncols, |_, _| rand::random())
} }
} }
@ -74,7 +74,7 @@ impl<N: Rand> DMat<N> {
impl<N: One + Clone + Copy> DMat<N> { impl<N: One + Clone + Copy> DMat<N> {
/// Builds a matrix filled with a given constant. /// Builds a matrix filled with a given constant.
#[inline] #[inline]
pub fn new_ones(nrows: uint, ncols: uint) -> DMat<N> { pub fn new_ones(nrows: usize, ncols: usize) -> DMat<N> {
DMat::from_elem(nrows, ncols, ::one()) DMat::from_elem(nrows, ncols, ::one())
} }
} }
@ -82,7 +82,7 @@ impl<N: One + Clone + Copy> DMat<N> {
impl<N: Clone + Copy> DMat<N> { impl<N: Clone + Copy> DMat<N> {
/// Builds a matrix filled with a given constant. /// Builds a matrix filled with a given constant.
#[inline] #[inline]
pub fn from_elem(nrows: uint, ncols: uint, val: N) -> DMat<N> { pub fn from_elem(nrows: usize, ncols: usize, val: N) -> DMat<N> {
DMat { DMat {
nrows: nrows, nrows: nrows,
ncols: ncols, ncols: ncols,
@ -97,7 +97,7 @@ impl<N: Clone + Copy> DMat<N> {
/// ///
/// The vector must have at least `nrows * ncols` elements. /// The vector must have at least `nrows * ncols` elements.
#[inline] #[inline]
pub fn from_row_vec(nrows: uint, ncols: uint, vec: &[N]) -> DMat<N> { pub fn from_row_vec(nrows: usize, ncols: usize, vec: &[N]) -> DMat<N> {
let mut res = DMat::from_col_vec(ncols, nrows, vec); let mut res = DMat::from_col_vec(ncols, nrows, vec);
// we transpose because the buffer is row_major // we transpose because the buffer is row_major
@ -113,7 +113,7 @@ impl<N: Clone + Copy> DMat<N> {
/// ///
/// The vector must have at least `nrows * ncols` elements. /// The vector must have at least `nrows * ncols` elements.
#[inline] #[inline]
pub fn from_col_vec(nrows: uint, ncols: uint, vec: &[N]) -> DMat<N> { pub fn from_col_vec(nrows: usize, ncols: usize, vec: &[N]) -> DMat<N> {
assert!(nrows * ncols == vec.len()); assert!(nrows * ncols == vec.len());
DMat { DMat {
@ -127,27 +127,27 @@ impl<N: Clone + Copy> DMat<N> {
impl<N> DMat<N> { impl<N> DMat<N> {
/// Builds a matrix filled with a given constant. /// Builds a matrix filled with a given constant.
#[inline(always)] #[inline(always)]
pub fn from_fn<F: FnMut(uint, uint) -> N>(nrows: uint, ncols: uint, mut f: F) -> DMat<N> { pub fn from_fn<F: FnMut(usize, usize) -> N>(nrows: usize, ncols: usize, mut f: F) -> DMat<N> {
DMat { DMat {
nrows: nrows, nrows: nrows,
ncols: ncols, ncols: ncols,
mij: range(0, nrows * ncols).map(|i| { let m = i / nrows; f(i - m * nrows, m) }).collect() mij: (0 .. nrows * ncols).map(|i| { let m = i / nrows; f(i - m * nrows, m) }).collect()
} }
} }
/// The number of row on the matrix. /// The number of row on the matrix.
#[inline] #[inline]
pub fn nrows(&self) -> uint { pub fn nrows(&self) -> usize {
self.nrows self.nrows
} }
/// The number of columns on the matrix. /// The number of columns on the matrix.
#[inline] #[inline]
pub fn ncols(&self) -> uint { pub fn ncols(&self) -> usize {
self.ncols self.ncols
} }
/// Transforms this matrix into an array. This consumes the matrix and is O(1). /// Transforms this matrix isizeo an array. This consumes the matrix and is O(1).
/// The returned vector contains the matrix data in column-major order. /// The returned vector contains the matrix data in column-major order.
#[inline] #[inline]
pub fn to_vec(self) -> Vec<N> { pub fn to_vec(self) -> Vec<N> {
@ -157,14 +157,14 @@ impl<N> DMat<N> {
/// Gets a reference to this matrix data. /// Gets a reference to this matrix data.
/// The returned vector contains the matrix data in column-major order. /// The returned vector contains the matrix data in column-major order.
#[inline] #[inline]
pub fn as_vec<'r>(&'r self) -> &'r [N] { pub fn as_vec(&self) -> &[N] {
self.mij.as_slice() &self.mij[]
} }
/// Gets a mutable reference to this matrix data. /// Gets a mutable reference to this matrix data.
/// The returned vector contains the matrix data in column-major order. /// The returned vector contains the matrix data in column-major order.
#[inline] #[inline]
pub fn as_mut_vec<'r>(&'r mut self) -> &'r mut [N] { pub fn as_mut_vec(&mut self) -> &mut [N] {
self.mij.as_mut_slice() self.mij.as_mut_slice()
} }
} }
@ -178,10 +178,10 @@ impl<N: One + Zero + Clone + Copy> Eye for DMat<N> {
/// * `dim` - The dimension of the matrix. A `dim`-dimensional matrix contains `dim * dim` /// * `dim` - The dimension of the matrix. A `dim`-dimensional matrix contains `dim * dim`
/// components. /// components.
#[inline] #[inline]
fn new_identity(dim: uint) -> DMat<N> { fn new_identity(dim: usize) -> DMat<N> {
let mut res = DMat::new_zeros(dim, dim); let mut res = DMat::new_zeros(dim, dim);
for i in range(0u, dim) { for i in (0us .. dim) {
let _1: N = ::one(); let _1: N = ::one();
res[(i, i)] = _1; res[(i, i)] = _1;
} }
@ -192,19 +192,19 @@ impl<N: One + Zero + Clone + Copy> Eye for DMat<N> {
impl<N> DMat<N> { impl<N> DMat<N> {
#[inline(always)] #[inline(always)]
fn offset(&self, i: uint, j: uint) -> uint { fn offset(&self, i: usize, j: usize) -> usize {
i + j * self.nrows i + j * self.nrows
} }
} }
impl<N: Copy> Indexable<(uint, uint), N> for DMat<N> { impl<N: Copy> Indexable<(usize, usize), N> for DMat<N> {
/// Changes the value of a component of the matrix. /// Changes the value of a component of the matrix.
/// ///
/// # Arguments /// # Arguments
/// * `rowcol` - 0-based tuple (row, col) to be changed /// * `rowcol` - 0-based tuple (row, col) to be changed
#[inline] #[inline]
fn set(&mut self, rowcol: (uint, uint), val: N) { fn set(&mut self, rowcol: (usize, usize), val: N) {
let (row, col) = rowcol; let (row, col) = rowcol;
assert!(row < self.nrows); assert!(row < self.nrows);
assert!(col < self.ncols); assert!(col < self.ncols);
@ -215,7 +215,7 @@ impl<N: Copy> Indexable<(uint, uint), N> for DMat<N> {
/// Just like `set` without bounds checking. /// Just like `set` without bounds checking.
#[inline] #[inline]
unsafe fn unsafe_set(&mut self, rowcol: (uint, uint), val: N) { unsafe fn unsafe_set(&mut self, rowcol: (usize, usize), 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().get_unchecked_mut(offset) = val *self.mij.as_mut_slice().get_unchecked_mut(offset) = val
@ -226,7 +226,7 @@ impl<N: Copy> Indexable<(uint, uint), N> for DMat<N> {
/// # Arguments /// # Arguments
/// * `rowcol` - 0-based tuple (row, col) to be read /// * `rowcol` - 0-based tuple (row, col) to be read
#[inline] #[inline]
fn at(&self, rowcol: (uint, uint)) -> N { fn at(&self, rowcol: (usize, usize)) -> N {
let (row, col) = rowcol; let (row, col) = rowcol;
assert!(row < self.nrows); assert!(row < self.nrows);
assert!(col < self.ncols); assert!(col < self.ncols);
@ -235,14 +235,14 @@ impl<N: Copy> Indexable<(uint, uint), N> for DMat<N> {
/// Just like `at` without bounds checking. /// Just like `at` without bounds checking.
#[inline] #[inline]
unsafe fn unsafe_at(&self, rowcol: (uint, uint)) -> N { unsafe fn unsafe_at(&self, rowcol: (usize, usize)) -> N {
let (row, col) = rowcol; let (row, col) = rowcol;
*self.mij.as_slice().get_unchecked(self.offset(row, col)) *self.mij[].get_unchecked(self.offset(row, col))
} }
#[inline] #[inline]
fn swap(&mut self, rowcol1: (uint, uint), rowcol2: (uint, uint)) { fn swap(&mut self, rowcol1: (usize, usize), rowcol2: (usize, usize)) {
let (row1, col1) = rowcol1; let (row1, col1) = rowcol1;
let (row2, col2) = rowcol2; let (row2, col2) = rowcol2;
let offset1 = self.offset(row1, col1); let offset1 = self.offset(row1, col1);
@ -255,30 +255,30 @@ impl<N: Copy> Indexable<(uint, uint), N> for DMat<N> {
} }
impl<N> Shape<(uint, uint)> for DMat<N> { impl<N> Shape<(usize, usize)> for DMat<N> {
#[inline] #[inline]
fn shape(&self) -> (uint, uint) { fn shape(&self) -> (usize, usize) {
(self.nrows, self.ncols) (self.nrows, self.ncols)
} }
} }
impl<N> Index<(uint, uint)> for DMat<N> { impl<N> Index<(usize, usize)> for DMat<N> {
type Output = N; type Output = N;
fn index(&self, &(i, j): &(uint, uint)) -> &N { fn index(&self, &(i, j): &(usize, usize)) -> &N {
assert!(i < self.nrows); assert!(i < self.nrows);
assert!(j < self.ncols); assert!(j < self.ncols);
unsafe { unsafe {
self.mij.as_slice().get_unchecked(self.offset(i, j)) self.mij[].get_unchecked(self.offset(i, j))
} }
} }
} }
impl<N> IndexMut<(uint, uint)> for DMat<N> { impl<N> IndexMut<(usize, usize)> for DMat<N> {
type Output = N; type Output = N;
fn index_mut(&mut self, &(i, j): &(uint, uint)) -> &mut N { fn index_mut(&mut self, &(i, j): &(usize, usize)) -> &mut N {
assert!(i < self.nrows); assert!(i < self.nrows);
assert!(j < self.ncols); assert!(j < self.ncols);
@ -298,12 +298,12 @@ impl<N: Copy + Mul<N, Output = N> + Add<N, Output = N> + Zero> Mul<DMat<N>> for
let mut res = unsafe { DMat::new_uninitialized(self.nrows, right.ncols) }; let mut res = unsafe { DMat::new_uninitialized(self.nrows, right.ncols) };
for i in range(0u, self.nrows) { for i in (0us .. self.nrows) {
for j in range(0u, right.ncols) { for j in (0us .. right.ncols) {
let mut acc: N = ::zero(); let mut acc: N = ::zero();
unsafe { unsafe {
for k in range(0u, self.ncols) { for k in (0us .. self.ncols) {
acc = acc acc = acc
+ self.unsafe_at((i, k)) * right.unsafe_at((k, j)); + self.unsafe_at((i, k)) * right.unsafe_at((k, j));
} }
@ -325,10 +325,10 @@ impl<N: Copy + Add<N, Output = N> + Mul<N, Output = N> + Zero> Mul<DVec<N>> for
let mut res : DVec<N> = unsafe { DVec::new_uninitialized(self.nrows) }; let mut res : DVec<N> = unsafe { DVec::new_uninitialized(self.nrows) };
for i in range(0u, self.nrows) { for i in (0us .. self.nrows) {
let mut acc: N = ::zero(); let mut acc: N = ::zero();
for j in range(0u, self.ncols) { for j in (0us .. self.ncols) {
unsafe { unsafe {
acc = acc + self.unsafe_at((i, j)) * right.unsafe_at(j); acc = acc + self.unsafe_at((i, j)) * right.unsafe_at(j);
} }
@ -350,10 +350,10 @@ impl<N: Copy + Add<N, Output = N> + Mul<N, Output = N> + Zero> Mul<DMat<N>> for
let mut res : DVec<N> = unsafe { DVec::new_uninitialized(right.ncols) }; let mut res : DVec<N> = unsafe { DVec::new_uninitialized(right.ncols) };
for i in range(0u, right.ncols) { for i in (0us .. right.ncols) {
let mut acc: N = ::zero(); let mut acc: N = ::zero();
for j in range(0u, right.nrows) { for j in (0us .. right.nrows) {
unsafe { unsafe {
acc = acc + self.unsafe_at(j) * right.unsafe_at((j, i)); acc = acc + self.unsafe_at(j) * right.unsafe_at((j, i));
} }
@ -385,7 +385,7 @@ impl<N: BaseNum + Clone> Inv for DMat<N> {
let mut res: DMat<N> = Eye::new_identity(dim); let mut res: DMat<N> = Eye::new_identity(dim);
// inversion using Gauss-Jordan elimination // inversion using Gauss-Jordan elimination
for k in range(0u, dim) { for k in (0us .. dim) {
// search a non-zero value on the k-th column // search a non-zero value on the k-th column
// FIXME: would it be worth it to spend some more time searching for the // FIXME: would it be worth it to spend some more time searching for the
// max instead? // max instead?
@ -406,7 +406,7 @@ impl<N: BaseNum + Clone> Inv for DMat<N> {
// swap pivot line // swap pivot line
if n0 != k { if n0 != k {
for j in range(0u, dim) { for j in (0us .. dim) {
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);
@ -418,26 +418,26 @@ impl<N: BaseNum + Clone> Inv for DMat<N> {
unsafe { unsafe {
let pivot = self.unsafe_at((k, k)); let pivot = self.unsafe_at((k, k));
for j in range(k, dim) { for j in (k .. dim) {
let selfval = self.unsafe_at((k, j)) / pivot; let selfval = self.unsafe_at((k, j)) / pivot;
self.unsafe_set((k, j), selfval); self.unsafe_set((k, j), selfval);
} }
for j in range(0u, dim) { for j in (0us .. dim) {
let resval = res.unsafe_at((k, j)) / pivot; let resval = res.unsafe_at((k, j)) / pivot;
res.unsafe_set((k, j), resval); res.unsafe_set((k, j), resval);
} }
for l in range(0u, dim) { for l in (0us .. dim) {
if l != k { if l != k {
let normalizer = self.unsafe_at((l, k)); let normalizer = self.unsafe_at((l, k));
for j in range(k, dim) { for j in (k .. dim) {
let selfval = self.unsafe_at((l, j)) - self.unsafe_at((k, j)) * normalizer; let selfval = self.unsafe_at((l, j)) - self.unsafe_at((k, j)) * normalizer;
self.unsafe_set((l, j), selfval); self.unsafe_set((l, j), selfval);
} }
for j in range(0u, dim) { for j in (0us .. dim) {
let resval = res.unsafe_at((l, j)) - res.unsafe_at((k, j)) * normalizer; let resval = res.unsafe_at((l, j)) - res.unsafe_at((k, j)) * normalizer;
res.unsafe_set((l, j), resval); res.unsafe_set((l, j), resval);
} }
@ -465,8 +465,8 @@ impl<N: Clone + Copy> Transpose for DMat<N> {
else { else {
let mut res = unsafe { DMat::new_uninitialized(self.ncols, self.nrows) }; let mut res = unsafe { DMat::new_uninitialized(self.ncols, self.nrows) };
for i in range(0u, self.nrows) { for i in (0us .. self.nrows) {
for j in range(0u, self.ncols) { for j in (0us .. self.ncols) {
unsafe { unsafe {
res.unsafe_set((j, i), self.unsafe_at((i, j))) res.unsafe_set((j, i), self.unsafe_at((i, j)))
} }
@ -480,8 +480,8 @@ impl<N: Clone + Copy> Transpose for DMat<N> {
#[inline] #[inline]
fn transpose(&mut self) { fn transpose(&mut self) {
if self.nrows == self.ncols { if self.nrows == self.ncols {
for i in range(1u, self.nrows) { for i in (1us .. self.nrows) {
for j in range(0u, self.ncols - 1) { for j in (0us .. self.ncols - 1) {
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);
@ -503,8 +503,8 @@ impl<N: BaseNum + Cast<f64> + Clone> Mean<DVec<N>> for DMat<N> {
let mut res: DVec<N> = DVec::new_zeros(self.ncols); let mut res: DVec<N> = DVec::new_zeros(self.ncols);
let normalizer: N = Cast::from(1.0f64 / Cast::from(self.nrows)); let normalizer: N = Cast::from(1.0f64 / Cast::from(self.nrows));
for i in range(0u, self.nrows) { for i in (0us .. self.nrows) {
for j in range(0u, self.ncols) { for j in (0us .. self.ncols) {
unsafe { unsafe {
let acc = res.unsafe_at(j) + self.unsafe_at((i, j)) * normalizer; let acc = res.unsafe_at(j) + self.unsafe_at((i, j)) * normalizer;
res.unsafe_set(j, acc); res.unsafe_set(j, acc);
@ -525,8 +525,8 @@ impl<N: BaseNum + Cast<f64> + Clone> Cov<DMat<N>> for DMat<N> {
let mean = self.mean(); let mean = self.mean();
// FIXME: use the rows iterator when available // FIXME: use the rows iterator when available
for i in range(0u, self.nrows) { for i in (0us .. self.nrows) {
for j in range(0u, self.ncols) { for j in (0us .. self.ncols) {
unsafe { unsafe {
centered.unsafe_set((i, j), self.unsafe_at((i, j)) - mean.unsafe_at(j)); centered.unsafe_set((i, j), self.unsafe_at((i, j)) - mean.unsafe_at(j));
} }
@ -542,29 +542,28 @@ impl<N: BaseNum + Cast<f64> + Clone> Cov<DMat<N>> for DMat<N> {
} }
impl<N: Copy + Clone> ColSlice<DVec<N>> for DMat<N> { impl<N: Copy + Clone> ColSlice<DVec<N>> for DMat<N> {
fn col_slice(&self, col_id :uint, row_start: uint, row_end: uint) -> DVec<N> { fn col_slice(&self, col_id :usize, row_start: usize, row_end: usize) -> DVec<N> {
assert!(col_id < self.ncols); assert!(col_id < self.ncols);
assert!(row_start < row_end); assert!(row_start < row_end);
assert!(row_end <= self.nrows); assert!(row_end <= self.nrows);
// we can init from slice thanks to the matrix being column major // we can init from slice thanks to the matrix being column major
let start= self.offset(row_start, col_id); let start= self.offset(row_start, col_id);
let stop = self.offset(row_end, col_id); let stop = self.offset(row_end, col_id);
let slice = DVec::from_slice( let slice = DVec::from_slice(row_end - row_start, &self.mij[start .. stop]);
row_end - row_start, self.mij.slice(start, stop));
slice slice
} }
} }
impl<N: Copy> RowSlice<DVec<N>> for DMat<N> { impl<N: Copy> RowSlice<DVec<N>> for DMat<N> {
fn row_slice(&self, row_id :uint, col_start: uint, col_end: uint) -> DVec<N> { fn row_slice(&self, row_id :usize, col_start: usize, col_end: usize) -> DVec<N> {
assert!(row_id < self.nrows); assert!(row_id < self.nrows);
assert!(col_start < col_end); assert!(col_start < col_end);
assert!(col_end <= self.ncols); assert!(col_end <= self.ncols);
let mut slice : DVec<N> = unsafe { let mut slice : DVec<N> = unsafe {
DVec::new_uninitialized(self.nrows) DVec::new_uninitialized(self.nrows)
}; };
let mut slice_idx = 0u; let mut slice_idx = 0us;
for col_id in range(col_start, col_end) { for col_id in (col_start .. col_end) {
unsafe { unsafe {
slice.unsafe_set(slice_idx, self.unsafe_at((row_id, col_id))); slice.unsafe_set(slice_idx, self.unsafe_at((row_id, col_id)));
} }
@ -590,7 +589,7 @@ impl<N: Copy + Clone + Zero> Diag<DVec<N>> for DMat<N> {
assert!(diag.len() == smallest_dim); assert!(diag.len() == smallest_dim);
for i in range(0, smallest_dim) { for i in (0 .. smallest_dim) {
unsafe { self.unsafe_set((i, i), diag.unsafe_at(i)) } unsafe { self.unsafe_set((i, i), diag.unsafe_at(i)) }
} }
} }
@ -601,7 +600,7 @@ impl<N: Copy + Clone + Zero> Diag<DVec<N>> for DMat<N> {
let mut diag: DVec<N> = DVec::new_zeros(smallest_dim); let mut diag: DVec<N> = DVec::new_zeros(smallest_dim);
for i in range(0, smallest_dim) { for i in (0 .. smallest_dim) {
unsafe { diag.unsafe_set(i, self.unsafe_at((i, i))) } unsafe { diag.unsafe_set(i, self.unsafe_at((i, i))) }
} }
@ -635,8 +634,8 @@ impl<N: ApproxEq<N>> ApproxEq<N> for DMat<N> {
impl<N: Show + Copy + String> Show for DMat<N> { impl<N: Show + Copy + String> Show for DMat<N> {
fn fmt(&self, form:&mut Formatter) -> Result { fn fmt(&self, form:&mut Formatter) -> Result {
for i in range(0u, self.nrows()) { for i in (0us .. self.nrows()) {
for j in range(0u, self.ncols()) { for j in (0us .. self.ncols()) {
let _ = write!(form, "{} ", self[(i, j)]); let _ = write!(form, "{} ", self[(i, j)]);
} }
let _ = write!(form, "\n"); let _ = write!(form, "\n");

View File

@ -22,7 +22,7 @@ pub struct DVec<N> {
impl<N> DVec<N> { impl<N> DVec<N> {
/// Creates an uninitialized vec. /// Creates an uninitialized vec.
#[inline] #[inline]
pub unsafe fn new_uninitialized(dim: uint) -> DVec<N> { pub unsafe fn new_uninitialized(dim: usize) -> DVec<N> {
let mut vec = Vec::with_capacity(dim); let mut vec = Vec::with_capacity(dim);
vec.set_len(dim); vec.set_len(dim);
@ -35,7 +35,7 @@ impl<N> DVec<N> {
impl<N: Clone> DVec<N> { 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: usize, elem: N) -> DVec<N> {
DVec { at: repeat(elem).take(dim).collect() } DVec { at: repeat(elem).take(dim).collect() }
} }
@ -43,11 +43,11 @@ impl<N: Clone> DVec<N> {
/// ///
/// The vector must have at least `dim` elements. /// The vector must have at least `dim` elements.
#[inline] #[inline]
pub fn from_slice(dim: uint, vec: &[N]) -> DVec<N> { pub fn from_slice(dim: usize, vec: &[N]) -> DVec<N> {
assert!(dim <= vec.len()); assert!(dim <= vec.len());
DVec { DVec {
at: vec.slice_to(dim).to_vec() at: vec[.. dim].to_vec()
} }
} }
} }
@ -55,12 +55,12 @@ impl<N: Clone> DVec<N> {
impl<N> DVec<N> { 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<F: FnMut(uint) -> N>(dim: uint, mut f: F) -> DVec<N> { pub fn from_fn<F: FnMut(usize) -> N>(dim: usize, mut f: F) -> DVec<N> {
DVec { at: range(0, dim).map(|i| f(i)).collect() } DVec { at: (0 .. dim).map(|i| f(i)).collect() }
} }
#[inline] #[inline]
pub fn len(&self) -> uint { pub fn len(&self) -> usize {
self.at.len() self.at.len()
} }
} }
@ -84,7 +84,7 @@ dvec_impl!(DVec);
/// Stack-allocated, dynamically sized vector with a maximum size of 1. /// Stack-allocated, dynamically sized vector with a maximum size of 1.
pub struct DVec1<N> { pub struct DVec1<N> {
at: [N; 1], at: [N; 1],
dim: uint dim: usize
} }
small_dvec_impl!(DVec1, 1, 0); small_dvec_impl!(DVec1, 1, 0);
@ -94,7 +94,7 @@ small_dvec_from_impl!(DVec1, 1, ::zero());
/// Stack-allocated, dynamically sized vector with a maximum size of 2. /// Stack-allocated, dynamically sized vector with a maximum size of 2.
pub struct DVec2<N> { pub struct DVec2<N> {
at: [N; 2], at: [N; 2],
dim: uint dim: usize
} }
small_dvec_impl!(DVec2, 2, 0, 1); small_dvec_impl!(DVec2, 2, 0, 1);
@ -104,7 +104,7 @@ small_dvec_from_impl!(DVec2, 2, ::zero(), ::zero());
/// Stack-allocated, dynamically sized vector with a maximum size of 3. /// Stack-allocated, dynamically sized vector with a maximum size of 3.
pub struct DVec3<N> { pub struct DVec3<N> {
at: [N; 3], at: [N; 3],
dim: uint dim: usize
} }
small_dvec_impl!(DVec3, 3, 0, 1, 2); small_dvec_impl!(DVec3, 3, 0, 1, 2);
@ -114,7 +114,7 @@ small_dvec_from_impl!(DVec3, 3, ::zero(), ::zero(), ::zero());
/// Stack-allocated, dynamically sized vector with a maximum size of 4. /// Stack-allocated, dynamically sized vector with a maximum size of 4.
pub struct DVec4<N> { pub struct DVec4<N> {
at: [N; 4], at: [N; 4],
dim: uint dim: usize
} }
small_dvec_impl!(DVec4, 4, 0, 1, 2, 3); small_dvec_impl!(DVec4, 4, 0, 1, 2, 3);
@ -124,7 +124,7 @@ small_dvec_from_impl!(DVec4, 4, ::zero(), ::zero(), ::zero(), ::zero());
/// Stack-allocated, dynamically sized vector with a maximum size of 5. /// Stack-allocated, dynamically sized vector with a maximum size of 5.
pub struct DVec5<N> { pub struct DVec5<N> {
at: [N; 5], at: [N; 5],
dim: uint dim: usize
} }
small_dvec_impl!(DVec5, 5, 0, 1, 2, 3, 4); small_dvec_impl!(DVec5, 5, 0, 1, 2, 3, 4);
@ -134,7 +134,7 @@ small_dvec_from_impl!(DVec5, 5, ::zero(), ::zero(), ::zero(), ::zero(), ::zero()
/// Stack-allocated, dynamically sized vector with a maximum size of 6. /// Stack-allocated, dynamically sized vector with a maximum size of 6.
pub struct DVec6<N> { pub struct DVec6<N> {
at: [N; 6], at: [N; 6],
dim: uint dim: usize
} }
small_dvec_impl!(DVec6, 6, 0, 1, 2, 3, 4, 5); small_dvec_impl!(DVec6, 6, 0, 1, 2, 3, 4, 5);

View File

@ -8,7 +8,7 @@ macro_rules! dvec_impl(
/// # Arguments /// # Arguments
/// * `dim` - The dimension of the vector. /// * `dim` - The dimension of the vector.
#[inline] #[inline]
pub fn new_zeros(dim: uint) -> $dvec<N> { pub fn new_zeros(dim: usize) -> $dvec<N> {
$dvec::from_elem(dim, ::zero()) $dvec::from_elem(dim, ::zero())
} }
@ -34,16 +34,16 @@ macro_rules! dvec_impl(
} }
} }
impl<N> Shape<uint> for $dvec<N> { impl<N> Shape<usize> for $dvec<N> {
#[inline] #[inline]
fn shape(&self) -> uint { fn shape(&self) -> usize {
self.len() self.len()
} }
} }
impl<N: Copy> Indexable<uint, N> for $dvec<N> { impl<N: Copy> Indexable<usize, N> for $dvec<N> {
#[inline] #[inline]
fn at(&self, i: uint) -> N { fn at(&self, i: usize) -> N {
assert!(i < self.len()); assert!(i < self.len());
unsafe { unsafe {
self.unsafe_at(i) self.unsafe_at(i)
@ -51,7 +51,7 @@ macro_rules! dvec_impl(
} }
#[inline] #[inline]
fn set(&mut self, i: uint, val: N) { fn set(&mut self, i: usize, val: N) {
assert!(i < self.len()); assert!(i < self.len());
unsafe { unsafe {
self.unsafe_set(i, val); self.unsafe_set(i, val);
@ -59,36 +59,36 @@ macro_rules! dvec_impl(
} }
#[inline] #[inline]
fn swap(&mut self, i: uint, j: uint) { fn swap(&mut self, i: usize, j: usize) {
assert!(i < self.len()); assert!(i < self.len());
assert!(j < self.len()); assert!(j < self.len());
self.as_mut_slice().swap(i, j); self.as_mut_slice().swap(i, j);
} }
#[inline] #[inline]
unsafe fn unsafe_at(&self, i: uint) -> N { unsafe fn unsafe_at(&self, i: usize) -> N {
*self.at.as_slice().get_unchecked(i) *self.at.as_slice().get_unchecked(i)
} }
#[inline] #[inline]
unsafe fn unsafe_set(&mut self, i: uint, val: N) { unsafe fn unsafe_set(&mut self, i: usize, val: N) {
*self.at.as_mut_slice().get_unchecked_mut(i) = val *self.at.as_mut_slice().get_unchecked_mut(i) = val
} }
} }
impl<N> Index<uint> for $dvec<N> { impl<N> Index<usize> for $dvec<N> {
type Output = N; type Output = N;
fn index(&self, i: &uint) -> &N { fn index(&self, i: &usize) -> &N {
&self.as_slice()[*i] &self.as_slice()[*i]
} }
} }
impl<N> IndexMut<uint> for $dvec<N> { impl<N> IndexMut<usize> for $dvec<N> {
type Output = N; type Output = N;
fn index_mut(&mut self, i: &uint) -> &mut N { fn index_mut(&mut self, i: &usize) -> &mut N {
&mut self.as_mut_slice()[*i] &mut self.as_mut_slice()[*i]
} }
} }
@ -99,7 +99,7 @@ macro_rules! dvec_impl(
/// # Arguments /// # Arguments
/// * `dim` - The dimension of the vector. /// * `dim` - The dimension of the vector.
#[inline] #[inline]
pub fn new_ones(dim: uint) -> $dvec<N> { pub fn new_ones(dim: usize) -> $dvec<N> {
$dvec::from_elem(dim, ::one()) $dvec::from_elem(dim, ::one())
} }
} }
@ -107,7 +107,7 @@ macro_rules! dvec_impl(
impl<N: Rand + Zero> $dvec<N> { impl<N: Rand + Zero> $dvec<N> {
/// Builds a vector filled with random values. /// Builds a vector filled with random values.
#[inline] #[inline]
pub fn new_random(dim: uint) -> $dvec<N> { pub fn new_random(dim: usize) -> $dvec<N> {
$dvec::from_fn(dim, |&: _| rand::random()) $dvec::from_fn(dim, |&: _| rand::random())
} }
} }
@ -130,7 +130,7 @@ macro_rules! dvec_impl(
fn axpy(&mut self, a: &N, x: &$dvec<N>) { fn axpy(&mut self, a: &N, x: &$dvec<N>) {
assert!(self.len() == x.len()); assert!(self.len() == x.len());
for i in range(0, x.len()) { for i in (0 .. x.len()) {
unsafe { unsafe {
let self_i = self.unsafe_at(i); let self_i = self.unsafe_at(i);
self.unsafe_set(i, self_i + *a * x.unsafe_at(i)) self.unsafe_set(i, self_i + *a * x.unsafe_at(i))
@ -143,10 +143,10 @@ macro_rules! dvec_impl(
/// Computes the canonical basis for the given dimension. A canonical basis is a set of /// Computes the canonical basis for the given dimension. A canonical basis is a set of
/// vectors, mutually orthogonal, with all its component equal to 0.0 except one which is equal /// vectors, mutually orthogonal, with all its component equal to 0.0 except one which is equal
/// to 1.0. /// to 1.0.
pub fn canonical_basis_with_dim(dim: uint) -> Vec<$dvec<N>> { pub fn canonical_basis_with_dim(dim: usize) -> Vec<$dvec<N>> {
let mut res : Vec<$dvec<N>> = Vec::new(); let mut res : Vec<$dvec<N>> = Vec::new();
for i in range(0u, dim) { for i in (0us .. dim) {
let mut basis_element : $dvec<N> = $dvec::new_zeros(dim); let mut basis_element : $dvec<N> = $dvec::new_zeros(dim);
basis_element.set(i, ::one()); basis_element.set(i, ::one());
@ -165,7 +165,7 @@ macro_rules! dvec_impl(
let dim = self.len(); let dim = self.len();
let mut res : Vec<$dvec<N>> = Vec::new(); let mut res : Vec<$dvec<N>> = Vec::new();
for i in range(0u, dim) { for i in (0us .. dim) {
let mut basis_element : $dvec<N> = $dvec::new_zeros(self.len()); let mut basis_element : $dvec<N> = $dvec::new_zeros(self.len());
basis_element.set(i, ::one()); basis_element.set(i, ::one());
@ -276,7 +276,7 @@ macro_rules! dvec_impl(
fn dot(&self, other: &$dvec<N>) -> N { fn dot(&self, other: &$dvec<N>) -> N {
assert!(self.len() == other.len()); assert!(self.len() == other.len());
let mut res: N = ::zero(); let mut res: N = ::zero();
for i in range(0u, self.len()) { for i in (0us .. self.len()) {
res = res + unsafe { self.unsafe_at(i) * other.unsafe_at(i) }; res = res + unsafe { self.unsafe_at(i) * other.unsafe_at(i) };
} }
res res
@ -398,7 +398,7 @@ macro_rules! small_dvec_impl (
($dvec: ident, $dim: expr, $($idx: expr),*) => ( ($dvec: ident, $dim: expr, $($idx: expr),*) => (
impl<N> $dvec<N> { impl<N> $dvec<N> {
#[inline] #[inline]
pub fn len(&self) -> uint { pub fn len(&self) -> usize {
self.dim self.dim
} }
} }
@ -440,7 +440,7 @@ macro_rules! small_dvec_from_impl (
impl<N: Copy + Zero> $dvec<N> { impl<N: Copy + Zero> $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: usize, elem: N) -> $dvec<N> {
assert!(dim <= $dim); assert!(dim <= $dim);
let mut at: [N; $dim] = [ $( $zeros, )* ]; let mut at: [N; $dim] = [ $( $zeros, )* ];
@ -461,7 +461,7 @@ macro_rules! small_dvec_from_impl (
/// ///
/// The vector must have at least `dim` elements. /// The vector must have at least `dim` elements.
#[inline] #[inline]
pub fn from_slice(dim: uint, vec: &[N]) -> $dvec<N> { pub fn from_slice(dim: usize, vec: &[N]) -> $dvec<N> {
assert!(dim <= vec.len() && dim <= $dim); assert!(dim <= vec.len() && dim <= $dim);
// FIXME: not safe. // FIXME: not safe.
@ -481,12 +481,12 @@ macro_rules! small_dvec_from_impl (
impl<N: Zero> $dvec<N> { impl<N: Zero> $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<F: FnMut(uint) -> N>(dim: uint, mut f: F) -> $dvec<N> { pub fn from_fn<F: FnMut(usize) -> N>(dim: usize, mut f: F) -> $dvec<N> {
assert!(dim <= $dim); assert!(dim <= $dim);
let mut at: [N; $dim] = [ $( $zeros, )* ]; let mut at: [N; $dim] = [ $( $zeros, )* ];
for i in range(0, dim) { for i in (0 .. dim) {
at[i] = f(i); at[i] = f(i);
} }

View File

@ -43,7 +43,7 @@ macro_rules! dim_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> Dim for $t<N> { impl<N> Dim for $t<N> {
#[inline] #[inline]
fn dim(_: Option<$t<N>>) -> uint { fn dim(_: Option<$t<N>>) -> usize {
$dim $dim
} }
} }

View File

@ -60,13 +60,13 @@ macro_rules! at_fast_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N: Copy> $t<N> { impl<N: Copy> $t<N> {
#[inline] #[inline]
pub unsafe fn at_fast(&self, (i, j): (uint, uint)) -> N { pub unsafe fn at_fast(&self, (i, j): (usize, usize)) -> N {
(*mem::transmute::<&$t<N>, &[N; $dim * $dim]>(self) (*mem::transmute::<&$t<N>, &[N; $dim * $dim]>(self)
.get_unchecked(i + j * $dim)) .get_unchecked(i + j * $dim))
} }
#[inline] #[inline]
pub unsafe fn set_fast(&mut self, (i, j): (uint, uint), val: N) { pub unsafe fn set_fast(&mut self, (i, j): (usize, usize), val: N) {
(*mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self) (*mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self)
.get_unchecked_mut(i + j * $dim)) = val .get_unchecked_mut(i + j * $dim)) = val
} }
@ -154,7 +154,7 @@ macro_rules! mat_add_scalar_impl(
macro_rules! eye_impl( macro_rules! eye_impl(
($t: ident, $dim: expr, $($comp_diagN: ident),+) => ( ($t: ident, $dim: expr, $($comp_diagN: ident),+) => (
impl<N: Zero + One> Eye for $t<N> { impl<N: Zero + One> Eye for $t<N> {
fn new_identity(dim: uint) -> $t<N> { fn new_identity(dim: usize) -> $t<N> {
assert!(dim == $dim); assert!(dim == $dim);
let mut eye: $t<N> = ::zero(); let mut eye: $t<N> = ::zero();
$(eye.$comp_diagN = ::one();)+ $(eye.$comp_diagN = ::one();)+
@ -247,7 +247,7 @@ macro_rules! dim_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> Dim for $t<N> { impl<N> Dim for $t<N> {
#[inline] #[inline]
fn dim(_: Option<$t<N>>) -> uint { fn dim(_: Option<$t<N>>) -> usize {
$dim $dim
} }
} }
@ -256,30 +256,30 @@ macro_rules! dim_impl(
macro_rules! indexable_impl( macro_rules! indexable_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> Shape<(uint, uint)> for $t<N> { impl<N> Shape<(usize, usize)> for $t<N> {
#[inline] #[inline]
fn shape(&self) -> (uint, uint) { fn shape(&self) -> (usize, usize) {
($dim, $dim) ($dim, $dim)
} }
} }
impl<N: Copy> Indexable<(uint, uint), N> for $t<N> { impl<N: Copy> Indexable<(usize, usize), N> for $t<N> {
#[inline] #[inline]
fn at(&self, (i, j): (uint, uint)) -> N { fn at(&self, (i, j): (usize, usize)) -> N {
unsafe { unsafe {
mem::transmute::<&$t<N>, &[N; $dim * $dim]>(self)[i + j * $dim] mem::transmute::<&$t<N>, &[N; $dim * $dim]>(self)[i + j * $dim]
} }
} }
#[inline] #[inline]
fn set(&mut self, (i, j): (uint, uint), val: N) { fn set(&mut self, (i, j): (usize, usize), val: N) {
unsafe { unsafe {
mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self)[i + j * $dim] = val mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self)[i + j * $dim] = val
} }
} }
#[inline] #[inline]
fn swap(&mut self, (i1, j1): (uint, uint), (i2, j2): (uint, uint)) { fn swap(&mut self, (i1, j1): (usize, usize), (i2, j2): (usize, usize)) {
unsafe { unsafe {
mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self) mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self)
.swap(i1 + j1 * $dim, i2 + j2 * $dim) .swap(i1 + j1 * $dim, i2 + j2 * $dim)
@ -287,12 +287,12 @@ macro_rules! indexable_impl(
} }
#[inline] #[inline]
unsafe fn unsafe_at(&self, (i, j): (uint, uint)) -> N { unsafe fn unsafe_at(&self, (i, j): (usize, usize)) -> N {
(*mem::transmute::<&$t<N>, &[N; $dim * $dim]>(self).get_unchecked(i + j * $dim)) (*mem::transmute::<&$t<N>, &[N; $dim * $dim]>(self).get_unchecked(i + j * $dim))
} }
#[inline] #[inline]
unsafe fn unsafe_set(&mut self, (i, j): (uint, uint), val: N) { unsafe fn unsafe_set(&mut self, (i, j): (usize, usize), val: N) {
(*mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self).get_unchecked_mut(i + j * $dim)) = val (*mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self).get_unchecked_mut(i + j * $dim)) = val
} }
} }
@ -301,20 +301,20 @@ macro_rules! indexable_impl(
macro_rules! index_impl( macro_rules! index_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> Index<(uint, uint)> for $t<N> { impl<N> Index<(usize, usize)> for $t<N> {
type Output = N; type Output = N;
fn index(&self, &(i, j): &(uint, uint)) -> &N { fn index(&self, &(i, j): &(usize, usize)) -> &N {
unsafe { unsafe {
&mem::transmute::<&$t<N>, &mut [N; $dim * $dim]>(self)[i + j * $dim] &mem::transmute::<&$t<N>, &mut [N; $dim * $dim]>(self)[i + j * $dim]
} }
} }
} }
impl<N> IndexMut<(uint, uint)> for $t<N> { impl<N> IndexMut<(usize, usize)> for $t<N> {
type Output = N; type Output = N;
fn index_mut(&mut self, &(i, j): &(uint, uint)) -> &mut N { fn index_mut(&mut self, &(i, j): &(usize, usize)) -> &mut N {
unsafe { unsafe {
&mut mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self)[i + j * $dim] &mut mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self)[i + j * $dim]
} }
@ -326,7 +326,7 @@ macro_rules! index_impl(
macro_rules! col_slice_impl( macro_rules! col_slice_impl(
($t: ident, $tv: ident, $slice: ident, $dim: expr) => ( ($t: ident, $tv: ident, $slice: ident, $dim: expr) => (
impl<N: Clone + Copy + Zero> ColSlice<$slice<N>> for $t<N> { impl<N: Clone + Copy + Zero> ColSlice<$slice<N>> for $t<N> {
fn col_slice(&self, cid: uint, rstart: uint, rend: uint) -> $slice<N> { fn col_slice(&self, cid: usize, rstart: usize, rend: usize) -> $slice<N> {
let col = self.col(cid); let col = self.col(cid);
$slice::from_slice(rend - rstart, col.as_array().slice(rstart, rend)) $slice::from_slice(rend - rstart, col.as_array().slice(rstart, rend))
@ -339,19 +339,19 @@ macro_rules! row_impl(
($t: ident, $tv: ident, $dim: expr) => ( ($t: ident, $tv: ident, $dim: expr) => (
impl<N: Copy + Zero> Row<$tv<N>> for $t<N> { impl<N: Copy + Zero> Row<$tv<N>> for $t<N> {
#[inline] #[inline]
fn nrows(&self) -> uint { fn nrows(&self) -> usize {
Dim::dim(None::<$t<N>>) Dim::dim(None::<$t<N>>)
} }
#[inline] #[inline]
fn set_row(&mut self, row: uint, v: $tv<N>) { fn set_row(&mut self, row: usize, v: $tv<N>) {
for (i, e) in v.iter().enumerate() { for (i, e) in v.iter().enumerate() {
self.set((row, i), *e); self.set((row, i), *e);
} }
} }
#[inline] #[inline]
fn row(&self, row: uint) -> $tv<N> { fn row(&self, row: usize) -> $tv<N> {
let mut res: $tv<N> = ::zero(); let mut res: $tv<N> = ::zero();
for (i, e) in res.iter_mut().enumerate() { for (i, e) in res.iter_mut().enumerate() {
@ -367,7 +367,7 @@ macro_rules! row_impl(
macro_rules! row_slice_impl( macro_rules! row_slice_impl(
($t: ident, $tv: ident, $slice: ident, $dim: expr) => ( ($t: ident, $tv: ident, $slice: ident, $dim: expr) => (
impl<N: Clone + Copy + Zero> RowSlice<$slice<N>> for $t<N> { impl<N: Clone + Copy + Zero> RowSlice<$slice<N>> for $t<N> {
fn row_slice(&self, rid: uint, cstart: uint, cend: uint) -> $slice<N> { fn row_slice(&self, rid: usize, cstart: usize, cend: usize) -> $slice<N> {
let row = self.row(rid); let row = self.row(rid);
$slice::from_slice(cend - cstart, row.as_array().slice(cstart, cend)) $slice::from_slice(cend - cstart, row.as_array().slice(cstart, cend))
@ -380,19 +380,19 @@ macro_rules! col_impl(
($t: ident, $tv: ident, $dim: expr) => ( ($t: ident, $tv: ident, $dim: expr) => (
impl<N: Copy + Zero> Col<$tv<N>> for $t<N> { impl<N: Copy + Zero> Col<$tv<N>> for $t<N> {
#[inline] #[inline]
fn ncols(&self) -> uint { fn ncols(&self) -> usize {
Dim::dim(None::<$t<N>>) Dim::dim(None::<$t<N>>)
} }
#[inline] #[inline]
fn set_col(&mut self, col: uint, v: $tv<N>) { fn set_col(&mut self, col: usize, v: $tv<N>) {
for (i, e) in v.iter().enumerate() { for (i, e) in v.iter().enumerate() {
self.set((i, col), *e); self.set((i, col), *e);
} }
} }
#[inline] #[inline]
fn col(&self, col: uint) -> $tv<N> { fn col(&self, col: usize) -> $tv<N> {
let mut res: $tv<N> = ::zero(); let mut res: $tv<N> = ::zero();
for (i, e) in res.iter_mut().enumerate() { for (i, e) in res.iter_mut().enumerate() {
@ -419,7 +419,7 @@ macro_rules! diag_impl(
#[inline] #[inline]
fn set_diag(&mut self, diag: &$tv<N>) { fn set_diag(&mut self, diag: &$tv<N>) {
for i in range(0, $dim) { for i in (0 .. $dim) {
unsafe { self.unsafe_set((i, i), diag.unsafe_at(i)) } unsafe { self.unsafe_set((i, i), diag.unsafe_at(i)) }
} }
} }
@ -428,7 +428,7 @@ macro_rules! diag_impl(
fn diag(&self) -> $tv<N> { fn diag(&self) -> $tv<N> {
let mut diag: $tv<N> = ::zero(); let mut diag: $tv<N> = ::zero();
for i in range(0, $dim) { for i in (0 .. $dim) {
unsafe { diag.unsafe_set(i, self.unsafe_at((i, i))) } unsafe { diag.unsafe_set(i, self.unsafe_at((i, i))) }
} }
@ -447,12 +447,12 @@ macro_rules! mat_mul_mat_impl(
// careful! we need to comute other * self here (self is the rhs). // careful! we need to comute other * self here (self is the rhs).
let mut res: $t<N> = ::zero(); let mut res: $t<N> = ::zero();
for i in range(0u, $dim) { for i in (0us .. $dim) {
for j in range(0u, $dim) { for j in (0us .. $dim) {
let mut acc: N = ::zero(); let mut acc: N = ::zero();
unsafe { unsafe {
for k in range(0u, $dim) { for k in (0us .. $dim) {
acc = acc + self.at_fast((i, k)) * right.at_fast((k, j)); acc = acc + self.at_fast((i, k)) * right.at_fast((k, j));
} }
@ -476,8 +476,8 @@ macro_rules! vec_mul_mat_impl(
fn mul(self, right: $t<N>) -> $v<N> { fn mul(self, right: $t<N>) -> $v<N> {
let mut res : $v<N> = $zero(); let mut res : $v<N> = $zero();
for i in range(0u, $dim) { for i in (0us .. $dim) {
for j in range(0u, $dim) { for j in (0us .. $dim) {
unsafe { unsafe {
let val = res.at_fast(i) + self.at_fast(j) * right.at_fast((j, i)); let val = res.at_fast(i) + self.at_fast(j) * right.at_fast((j, i));
res.set_fast(i, val) res.set_fast(i, val)
@ -500,8 +500,8 @@ macro_rules! mat_mul_vec_impl(
fn mul(self, right: $v<N>) -> $v<N> { fn mul(self, right: $v<N>) -> $v<N> {
let mut res : $v<N> = $zero(); let mut res : $v<N> = $zero();
for i in range(0u, $dim) { for i in (0us .. $dim) {
for j in range(0u, $dim) { for j in (0us .. $dim) {
unsafe { unsafe {
let val = res.at_fast(i) + self.at_fast((i, j)) * right.at_fast(j); let val = res.at_fast(i) + self.at_fast((i, j)) * right.at_fast(j);
res.set_fast(i, val) res.set_fast(i, val)
@ -546,7 +546,7 @@ macro_rules! inv_impl(
let mut res: $t<N> = ::one(); let mut res: $t<N> = ::one();
// inversion using Gauss-Jordan elimination // inversion using Gauss-Jordan elimination
for k in range(0u, $dim) { for k in (0us .. $dim) {
// search a non-zero value on the k-th column // search a non-zero value on the k-th column
// FIXME: would it be worth it to spend some more time searching for the // FIXME: would it be worth it to spend some more time searching for the
// max instead? // max instead?
@ -567,7 +567,7 @@ macro_rules! inv_impl(
// swap pivot line // swap pivot line
if n0 != k { if n0 != k {
for j in range(0u, $dim) { for j in (0us .. $dim) {
self.swap((n0, j), (k, j)); self.swap((n0, j), (k, j));
res.swap((n0, j), (k, j)); res.swap((n0, j), (k, j));
} }
@ -575,26 +575,26 @@ macro_rules! inv_impl(
let pivot = self.at((k, k)); let pivot = self.at((k, k));
for j in range(k, $dim) { for j in (k .. $dim) {
let selfval = self.at((k, j)) / pivot; let selfval = self.at((k, j)) / pivot;
self.set((k, j), selfval); self.set((k, j), selfval);
} }
for j in range(0u, $dim) { for j in (0us .. $dim) {
let resval = res.at((k, j)) / pivot; let resval = res.at((k, j)) / pivot;
res.set((k, j), resval); res.set((k, j), resval);
} }
for l in range(0u, $dim) { for l in (0us .. $dim) {
if l != k { if l != k {
let normalizer = self.at((l, k)); let normalizer = self.at((l, k));
for j in range(k, $dim) { for j in (k .. $dim) {
let selfval = self.at((l, j)) - self.at((k, j)) * normalizer; let selfval = self.at((l, j)) - self.at((k, j)) * normalizer;
self.set((l, j), selfval); self.set((l, j), selfval);
} }
for j in range(0u, $dim) { for j in (0us .. $dim) {
let resval = res.at((l, j)) - res.at((k, j)) * normalizer; let resval = res.at((l, j)) - res.at((k, j)) * normalizer;
res.set((l, j), resval); res.set((l, j), resval);
} }
@ -623,8 +623,8 @@ macro_rules! transpose_impl(
#[inline] #[inline]
fn transpose(&mut self) { fn transpose(&mut self) {
for i in range(1u, $dim) { for i in (1us .. $dim) {
for j in range(0u, i) { for j in (0us .. i) {
self.swap((i, j), (j, i)) self.swap((i, j), (j, i))
} }
} }
@ -668,8 +668,8 @@ macro_rules! to_homogeneous_impl(
fn to_homogeneous(&self) -> $t2<N> { fn to_homogeneous(&self) -> $t2<N> {
let mut res: $t2<N> = ::one(); let mut res: $t2<N> = ::one();
for i in range(0u, $dim) { for i in (0us .. $dim) {
for j in range(0u, $dim) { for j in (0us .. $dim) {
res.set((i, j), self.at((i, j))) res.set((i, j), self.at((i, j)))
} }
} }
@ -687,8 +687,8 @@ macro_rules! from_homogeneous_impl(
fn from(m: &$t2<N>) -> $t<N> { fn from(m: &$t2<N>) -> $t<N> {
let mut res: $t<N> = ::one(); let mut res: $t<N> = ::one();
for i in range(0u, $dim2) { for i in (0us .. $dim2) {
for j in range(0u, $dim2) { for j in (0us .. $dim2) {
res.set((i, j), m.at((i, j))) res.set((i, j), m.at((i, j)))
} }
} }
@ -708,8 +708,8 @@ macro_rules! outer_impl(
#[inline] #[inline]
fn outer(&self, other: &$t<N>) -> $m<N> { fn outer(&self, other: &$t<N>) -> $m<N> {
let mut res: $m<N> = ::zero(); let mut res: $m<N> = ::zero();
for i in range(0u, Dim::dim(None::<$t<N>>)) { for i in (0us .. Dim::dim(None::<$t<N>>)) {
for j in range(0u, Dim::dim(None::<$t<N>>)) { for j in (0us .. Dim::dim(None::<$t<N>>)) {
res.set((i, j), self.at(i) * other.at(j)) res.set((i, j), self.at(i) * other.at(j))
} }
} }
@ -723,7 +723,7 @@ macro_rules! eigen_qr_impl(
($t: ident, $v: ident) => ( ($t: ident, $v: ident) => (
impl<N> EigenQR<N, $v<N>> for $t<N> impl<N> EigenQR<N, $v<N>> for $t<N>
where N: BaseFloat + ApproxEq<N> + Clone { where N: BaseFloat + ApproxEq<N> + Clone {
fn eigen_qr(&self, eps: &N, niter: uint) -> ($t<N>, $v<N>) { fn eigen_qr(&self, eps: &N, niter: usize) -> ($t<N>, $v<N>) {
linalg::eigen_qr(self, eps, niter) linalg::eigen_qr(self, eps, niter)
} }
} }

View File

@ -41,7 +41,7 @@ pub struct Pnt1<N> {
new_impl!(Pnt1, x); new_impl!(Pnt1, x);
orig_impl!(Pnt1, x); orig_impl!(Pnt1, x);
ord_impl!(Pnt1, x); ord_impl!(Pnt1, x,);
scalar_mul_impl!(Pnt1, x); scalar_mul_impl!(Pnt1, x);
scalar_div_impl!(Pnt1, x); scalar_div_impl!(Pnt1, x);
scalar_add_impl!(Pnt1, x); scalar_add_impl!(Pnt1, x);

View File

@ -270,8 +270,7 @@ Rotation<Vec3<N>> for Rot3<N> {
} }
} }
impl<N: Clone + Rand + BaseFloat> impl<N: Clone + Rand + BaseFloat> Rand for Rot3<N> {
Rand for Rot3<N> {
#[inline] #[inline]
fn rand<R: Rng>(rng: &mut R) -> Rot3<N> { fn rand<R: Rng>(rng: &mut R) -> Rot3<N> {
Rot3::new(rng.gen()) Rot3::new(rng.gen())

View File

@ -71,7 +71,7 @@ macro_rules! dim_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> Dim for $t<N> { impl<N> Dim for $t<N> {
#[inline] #[inline]
fn dim(_: Option<$t<N>>) -> uint { fn dim(_: Option<$t<N>>) -> usize {
$dim $dim
} }
} }
@ -193,16 +193,16 @@ macro_rules! row_impl(
($t: ident, $tv: ident) => ( ($t: ident, $tv: ident) => (
impl<N: Copy + Zero> Row<$tv<N>> for $t<N> { impl<N: Copy + Zero> Row<$tv<N>> for $t<N> {
#[inline] #[inline]
fn nrows(&self) -> uint { fn nrows(&self) -> usize {
self.submat.nrows() self.submat.nrows()
} }
#[inline] #[inline]
fn row(&self, i: uint) -> $tv<N> { fn row(&self, i: usize) -> $tv<N> {
self.submat.row(i) self.submat.row(i)
} }
#[inline] #[inline]
fn set_row(&mut self, i: uint, row: $tv<N>) { fn set_row(&mut self, i: usize, row: $tv<N>) {
self.submat.set_row(i, row); self.submat.set_row(i, row);
} }
} }
@ -213,16 +213,16 @@ macro_rules! col_impl(
($t: ident, $tv: ident) => ( ($t: ident, $tv: ident) => (
impl<N: Copy + Zero> Col<$tv<N>> for $t<N> { impl<N: Copy + Zero> Col<$tv<N>> for $t<N> {
#[inline] #[inline]
fn ncols(&self) -> uint { fn ncols(&self) -> usize {
self.submat.ncols() self.submat.ncols()
} }
#[inline] #[inline]
fn col(&self, i: uint) -> $tv<N> { fn col(&self, i: usize) -> $tv<N> {
self.submat.col(i) self.submat.col(i)
} }
#[inline] #[inline]
fn set_col(&mut self, i: uint, col: $tv<N>) { fn set_col(&mut self, i: usize, col: $tv<N>) {
self.submat.set_col(i, col); self.submat.set_col(i, col);
} }
} }
@ -231,10 +231,10 @@ macro_rules! col_impl(
macro_rules! index_impl( macro_rules! index_impl(
($t: ident) => ( ($t: ident) => (
impl<N> Index<(uint, uint)> for $t<N> { impl<N> Index<(usize, usize)> for $t<N> {
type Output = N; type Output = N;
fn index(&self, i: &(uint, uint)) -> &N { fn index(&self, i: &(usize, usize)) -> &N {
&self.submat[*i] &self.submat[*i]
} }
} }

View File

@ -45,7 +45,7 @@ impl<N: Clone + BaseNum + BaseNumCast + Zero> Inv for Cmplx<N> {
impl<N> Dim for Cmplx<N> { impl<N> Dim for Cmplx<N> {
#[inline] #[inline]
fn dim(unsused_self: Option<Cmplx<N>>) -> uint { fn dim(unsused_self: Option<Cmplx<N>>) -> usize {
2 2
} }
} }

View File

@ -132,12 +132,12 @@ impl<N: BaseNum> Det<N> for Mat3<N> {
impl<N: Copy> Row<Vec3<N>> for Mat3<N> { impl<N: Copy> Row<Vec3<N>> for Mat3<N> {
#[inline] #[inline]
fn nrows(&self) -> uint { fn nrows(&self) -> usize {
3 3
} }
#[inline] #[inline]
fn row(&self, i: uint) -> Vec3<N> { fn row(&self, i: usize) -> Vec3<N> {
match i { match i {
0 => Vec3::new(self.m11, self.m12, self.m13), 0 => Vec3::new(self.m11, self.m12, self.m13),
1 => Vec3::new(self.m21, self.m22, self.m23), 1 => Vec3::new(self.m21, self.m22, self.m23),
@ -147,7 +147,7 @@ impl<N: Copy> Row<Vec3<N>> for Mat3<N> {
} }
#[inline] #[inline]
fn set_row(&mut self, i: uint, r: Vec3<N>) { fn set_row(&mut self, i: usize, r: Vec3<N>) {
match i { match i {
0 => { 0 => {
self.m11 = r.x; self.m11 = r.x;
@ -172,12 +172,12 @@ impl<N: Copy> Row<Vec3<N>> for Mat3<N> {
impl<N: Copy> Col<Vec3<N>> for Mat3<N> { impl<N: Copy> Col<Vec3<N>> for Mat3<N> {
#[inline] #[inline]
fn ncols(&self) -> uint { fn ncols(&self) -> usize {
3 3
} }
#[inline] #[inline]
fn col(&self, i: uint) -> Vec3<N> { fn col(&self, i: usize) -> Vec3<N> {
match i { match i {
0 => Vec3::new(self.m11, self.m21, self.m31), 0 => Vec3::new(self.m11, self.m21, self.m31),
1 => Vec3::new(self.m12, self.m22, self.m32), 1 => Vec3::new(self.m12, self.m22, self.m32),
@ -187,7 +187,7 @@ impl<N: Copy> Col<Vec3<N>> for Mat3<N> {
} }
#[inline] #[inline]
fn set_col(&mut self, i: uint, r: Vec3<N>) { fn set_col(&mut self, i: usize, r: Vec3<N>) {
match i { match i {
0 => { 0 => {
self.m11 = r.x; self.m11 = r.x;

View File

@ -46,8 +46,8 @@ primitive_double_dispatch_cast_decl_trait!(u64, u64Cast);
primitive_double_dispatch_cast_decl_trait!(u32, u32Cast); primitive_double_dispatch_cast_decl_trait!(u32, u32Cast);
primitive_double_dispatch_cast_decl_trait!(u16, u16Cast); primitive_double_dispatch_cast_decl_trait!(u16, u16Cast);
primitive_double_dispatch_cast_decl_trait!(u8, u8Cast); primitive_double_dispatch_cast_decl_trait!(u8, u8Cast);
primitive_double_dispatch_cast_decl_trait!(int, intCast); primitive_double_dispatch_cast_decl_trait!(isize, isizeCast);
primitive_double_dispatch_cast_decl_trait!(uint, uintCast); primitive_double_dispatch_cast_decl_trait!(usize, usizeCast);
primitive_cast_redispatch_impl!(f64, f64Cast); primitive_cast_redispatch_impl!(f64, f64Cast);
primitive_cast_redispatch_impl!(f32, f32Cast); primitive_cast_redispatch_impl!(f32, f32Cast);
@ -59,8 +59,8 @@ primitive_cast_redispatch_impl!(u64, u64Cast);
primitive_cast_redispatch_impl!(u32, u32Cast); primitive_cast_redispatch_impl!(u32, u32Cast);
primitive_cast_redispatch_impl!(u16, u16Cast); primitive_cast_redispatch_impl!(u16, u16Cast);
primitive_cast_redispatch_impl!(u8, u8Cast); primitive_cast_redispatch_impl!(u8, u8Cast);
primitive_cast_redispatch_impl!(int, intCast); primitive_cast_redispatch_impl!(isize, isizeCast);
primitive_cast_redispatch_impl!(uint, uintCast); primitive_cast_redispatch_impl!(usize, usizeCast);
primitive_double_dispatch_cast_impl!(f64, f64, f64Cast); primitive_double_dispatch_cast_impl!(f64, f64, f64Cast);
primitive_double_dispatch_cast_impl!(f64, f32, f64Cast); primitive_double_dispatch_cast_impl!(f64, f32, f64Cast);
@ -72,8 +72,8 @@ primitive_double_dispatch_cast_impl!(f64, u64, f64Cast);
primitive_double_dispatch_cast_impl!(f64, u32, f64Cast); primitive_double_dispatch_cast_impl!(f64, u32, f64Cast);
primitive_double_dispatch_cast_impl!(f64, u16, f64Cast); primitive_double_dispatch_cast_impl!(f64, u16, f64Cast);
primitive_double_dispatch_cast_impl!(f64, u8, f64Cast); primitive_double_dispatch_cast_impl!(f64, u8, f64Cast);
primitive_double_dispatch_cast_impl!(f64, int, f64Cast); primitive_double_dispatch_cast_impl!(f64, isize, f64Cast);
primitive_double_dispatch_cast_impl!(f64, uint, f64Cast); primitive_double_dispatch_cast_impl!(f64, usize, f64Cast);
primitive_double_dispatch_cast_impl!(f32, f64, f32Cast); primitive_double_dispatch_cast_impl!(f32, f64, f32Cast);
primitive_double_dispatch_cast_impl!(f32, f32, f32Cast); primitive_double_dispatch_cast_impl!(f32, f32, f32Cast);
@ -85,8 +85,8 @@ primitive_double_dispatch_cast_impl!(f32, u64, f32Cast);
primitive_double_dispatch_cast_impl!(f32, u32, f32Cast); primitive_double_dispatch_cast_impl!(f32, u32, f32Cast);
primitive_double_dispatch_cast_impl!(f32, u16, f32Cast); primitive_double_dispatch_cast_impl!(f32, u16, f32Cast);
primitive_double_dispatch_cast_impl!(f32, u8, f32Cast); primitive_double_dispatch_cast_impl!(f32, u8, f32Cast);
primitive_double_dispatch_cast_impl!(f32, int, f32Cast); primitive_double_dispatch_cast_impl!(f32, isize, f32Cast);
primitive_double_dispatch_cast_impl!(f32, uint, f32Cast); primitive_double_dispatch_cast_impl!(f32, usize, f32Cast);
primitive_double_dispatch_cast_impl!(i64, f64, i64Cast); primitive_double_dispatch_cast_impl!(i64, f64, i64Cast);
primitive_double_dispatch_cast_impl!(i64, f32, i64Cast); primitive_double_dispatch_cast_impl!(i64, f32, i64Cast);
@ -98,8 +98,8 @@ primitive_double_dispatch_cast_impl!(i64, u64, i64Cast);
primitive_double_dispatch_cast_impl!(i64, u32, i64Cast); primitive_double_dispatch_cast_impl!(i64, u32, i64Cast);
primitive_double_dispatch_cast_impl!(i64, u16, i64Cast); primitive_double_dispatch_cast_impl!(i64, u16, i64Cast);
primitive_double_dispatch_cast_impl!(i64, u8, i64Cast); primitive_double_dispatch_cast_impl!(i64, u8, i64Cast);
primitive_double_dispatch_cast_impl!(i64, int, i64Cast); primitive_double_dispatch_cast_impl!(i64, isize, i64Cast);
primitive_double_dispatch_cast_impl!(i64, uint, i64Cast); primitive_double_dispatch_cast_impl!(i64, usize, i64Cast);
primitive_double_dispatch_cast_impl!(i32, f64, i32Cast); primitive_double_dispatch_cast_impl!(i32, f64, i32Cast);
primitive_double_dispatch_cast_impl!(i32, f32, i32Cast); primitive_double_dispatch_cast_impl!(i32, f32, i32Cast);
@ -111,8 +111,8 @@ primitive_double_dispatch_cast_impl!(i32, u64, i32Cast);
primitive_double_dispatch_cast_impl!(i32, u32, i32Cast); primitive_double_dispatch_cast_impl!(i32, u32, i32Cast);
primitive_double_dispatch_cast_impl!(i32, u16, i32Cast); primitive_double_dispatch_cast_impl!(i32, u16, i32Cast);
primitive_double_dispatch_cast_impl!(i32, u8, i32Cast); primitive_double_dispatch_cast_impl!(i32, u8, i32Cast);
primitive_double_dispatch_cast_impl!(i32, int, i32Cast); primitive_double_dispatch_cast_impl!(i32, isize, i32Cast);
primitive_double_dispatch_cast_impl!(i32, uint, i32Cast); primitive_double_dispatch_cast_impl!(i32, usize, i32Cast);
primitive_double_dispatch_cast_impl!(i16, f64, i16Cast); primitive_double_dispatch_cast_impl!(i16, f64, i16Cast);
primitive_double_dispatch_cast_impl!(i16, f32, i16Cast); primitive_double_dispatch_cast_impl!(i16, f32, i16Cast);
@ -124,8 +124,8 @@ primitive_double_dispatch_cast_impl!(i16, u64, i16Cast);
primitive_double_dispatch_cast_impl!(i16, u32, i16Cast); primitive_double_dispatch_cast_impl!(i16, u32, i16Cast);
primitive_double_dispatch_cast_impl!(i16, u16, i16Cast); primitive_double_dispatch_cast_impl!(i16, u16, i16Cast);
primitive_double_dispatch_cast_impl!(i16, u8, i16Cast); primitive_double_dispatch_cast_impl!(i16, u8, i16Cast);
primitive_double_dispatch_cast_impl!(i16, int, i16Cast); primitive_double_dispatch_cast_impl!(i16, isize, i16Cast);
primitive_double_dispatch_cast_impl!(i16, uint, i16Cast); primitive_double_dispatch_cast_impl!(i16, usize, i16Cast);
primitive_double_dispatch_cast_impl!(i8, f64, i8Cast); primitive_double_dispatch_cast_impl!(i8, f64, i8Cast);
primitive_double_dispatch_cast_impl!(i8, f32, i8Cast); primitive_double_dispatch_cast_impl!(i8, f32, i8Cast);
@ -137,8 +137,8 @@ primitive_double_dispatch_cast_impl!(i8, u64, i8Cast);
primitive_double_dispatch_cast_impl!(i8, u32, i8Cast); primitive_double_dispatch_cast_impl!(i8, u32, i8Cast);
primitive_double_dispatch_cast_impl!(i8, u16, i8Cast); primitive_double_dispatch_cast_impl!(i8, u16, i8Cast);
primitive_double_dispatch_cast_impl!(i8, u8, i8Cast); primitive_double_dispatch_cast_impl!(i8, u8, i8Cast);
primitive_double_dispatch_cast_impl!(i8, int, i8Cast); primitive_double_dispatch_cast_impl!(i8, isize, i8Cast);
primitive_double_dispatch_cast_impl!(i8, uint, i8Cast); primitive_double_dispatch_cast_impl!(i8, usize, i8Cast);
primitive_double_dispatch_cast_impl!(u64, f64, u64Cast); primitive_double_dispatch_cast_impl!(u64, f64, u64Cast);
primitive_double_dispatch_cast_impl!(u64, f32, u64Cast); primitive_double_dispatch_cast_impl!(u64, f32, u64Cast);
@ -150,8 +150,8 @@ primitive_double_dispatch_cast_impl!(u64, u64, u64Cast);
primitive_double_dispatch_cast_impl!(u64, u32, u64Cast); primitive_double_dispatch_cast_impl!(u64, u32, u64Cast);
primitive_double_dispatch_cast_impl!(u64, u16, u64Cast); primitive_double_dispatch_cast_impl!(u64, u16, u64Cast);
primitive_double_dispatch_cast_impl!(u64, u8, u64Cast); primitive_double_dispatch_cast_impl!(u64, u8, u64Cast);
primitive_double_dispatch_cast_impl!(u64, int, u64Cast); primitive_double_dispatch_cast_impl!(u64, isize, u64Cast);
primitive_double_dispatch_cast_impl!(u64, uint, u64Cast); primitive_double_dispatch_cast_impl!(u64, usize, u64Cast);
primitive_double_dispatch_cast_impl!(u32, f64, u32Cast); primitive_double_dispatch_cast_impl!(u32, f64, u32Cast);
primitive_double_dispatch_cast_impl!(u32, f32, u32Cast); primitive_double_dispatch_cast_impl!(u32, f32, u32Cast);
@ -163,8 +163,8 @@ primitive_double_dispatch_cast_impl!(u32, u64, u32Cast);
primitive_double_dispatch_cast_impl!(u32, u32, u32Cast); primitive_double_dispatch_cast_impl!(u32, u32, u32Cast);
primitive_double_dispatch_cast_impl!(u32, u16, u32Cast); primitive_double_dispatch_cast_impl!(u32, u16, u32Cast);
primitive_double_dispatch_cast_impl!(u32, u8, u32Cast); primitive_double_dispatch_cast_impl!(u32, u8, u32Cast);
primitive_double_dispatch_cast_impl!(u32, int, u32Cast); primitive_double_dispatch_cast_impl!(u32, isize, u32Cast);
primitive_double_dispatch_cast_impl!(u32, uint, u32Cast); primitive_double_dispatch_cast_impl!(u32, usize, u32Cast);
primitive_double_dispatch_cast_impl!(u16, f64, u16Cast); primitive_double_dispatch_cast_impl!(u16, f64, u16Cast);
primitive_double_dispatch_cast_impl!(u16, f32, u16Cast); primitive_double_dispatch_cast_impl!(u16, f32, u16Cast);
@ -176,8 +176,8 @@ primitive_double_dispatch_cast_impl!(u16, u64, u16Cast);
primitive_double_dispatch_cast_impl!(u16, u32, u16Cast); primitive_double_dispatch_cast_impl!(u16, u32, u16Cast);
primitive_double_dispatch_cast_impl!(u16, u16, u16Cast); primitive_double_dispatch_cast_impl!(u16, u16, u16Cast);
primitive_double_dispatch_cast_impl!(u16, u8, u16Cast); primitive_double_dispatch_cast_impl!(u16, u8, u16Cast);
primitive_double_dispatch_cast_impl!(u16, int, u16Cast); primitive_double_dispatch_cast_impl!(u16, isize, u16Cast);
primitive_double_dispatch_cast_impl!(u16, uint, u16Cast); primitive_double_dispatch_cast_impl!(u16, usize, u16Cast);
primitive_double_dispatch_cast_impl!(u8, f64, u8Cast); primitive_double_dispatch_cast_impl!(u8, f64, u8Cast);
primitive_double_dispatch_cast_impl!(u8, f32, u8Cast); primitive_double_dispatch_cast_impl!(u8, f32, u8Cast);
@ -189,31 +189,31 @@ primitive_double_dispatch_cast_impl!(u8, u64, u8Cast);
primitive_double_dispatch_cast_impl!(u8, u32, u8Cast); primitive_double_dispatch_cast_impl!(u8, u32, u8Cast);
primitive_double_dispatch_cast_impl!(u8, u16, u8Cast); primitive_double_dispatch_cast_impl!(u8, u16, u8Cast);
primitive_double_dispatch_cast_impl!(u8, u8, u8Cast); primitive_double_dispatch_cast_impl!(u8, u8, u8Cast);
primitive_double_dispatch_cast_impl!(u8, int, u8Cast); primitive_double_dispatch_cast_impl!(u8, isize, u8Cast);
primitive_double_dispatch_cast_impl!(u8, uint, u8Cast); primitive_double_dispatch_cast_impl!(u8, usize, u8Cast);
primitive_double_dispatch_cast_impl!(uint, f64, uintCast); primitive_double_dispatch_cast_impl!(usize, f64, usizeCast);
primitive_double_dispatch_cast_impl!(uint, f32, uintCast); primitive_double_dispatch_cast_impl!(usize, f32, usizeCast);
primitive_double_dispatch_cast_impl!(uint, i64, uintCast); primitive_double_dispatch_cast_impl!(usize, i64, usizeCast);
primitive_double_dispatch_cast_impl!(uint, i32, uintCast); primitive_double_dispatch_cast_impl!(usize, i32, usizeCast);
primitive_double_dispatch_cast_impl!(uint, i16, uintCast); primitive_double_dispatch_cast_impl!(usize, i16, usizeCast);
primitive_double_dispatch_cast_impl!(uint, i8, uintCast); primitive_double_dispatch_cast_impl!(usize, i8, usizeCast);
primitive_double_dispatch_cast_impl!(uint, u64, uintCast); primitive_double_dispatch_cast_impl!(usize, u64, usizeCast);
primitive_double_dispatch_cast_impl!(uint, u32, uintCast); primitive_double_dispatch_cast_impl!(usize, u32, usizeCast);
primitive_double_dispatch_cast_impl!(uint, u16, uintCast); primitive_double_dispatch_cast_impl!(usize, u16, usizeCast);
primitive_double_dispatch_cast_impl!(uint, u8, uintCast); primitive_double_dispatch_cast_impl!(usize, u8, usizeCast);
primitive_double_dispatch_cast_impl!(uint, int, uintCast); primitive_double_dispatch_cast_impl!(usize, isize, usizeCast);
primitive_double_dispatch_cast_impl!(uint, uint, uintCast); primitive_double_dispatch_cast_impl!(usize, usize, usizeCast);
primitive_double_dispatch_cast_impl!(int, f64, intCast); primitive_double_dispatch_cast_impl!(isize, f64, isizeCast);
primitive_double_dispatch_cast_impl!(int, f32, intCast); primitive_double_dispatch_cast_impl!(isize, f32, isizeCast);
primitive_double_dispatch_cast_impl!(int, i64, intCast); primitive_double_dispatch_cast_impl!(isize, i64, isizeCast);
primitive_double_dispatch_cast_impl!(int, i32, intCast); primitive_double_dispatch_cast_impl!(isize, i32, isizeCast);
primitive_double_dispatch_cast_impl!(int, i16, intCast); primitive_double_dispatch_cast_impl!(isize, i16, isizeCast);
primitive_double_dispatch_cast_impl!(int, i8, intCast); primitive_double_dispatch_cast_impl!(isize, i8, isizeCast);
primitive_double_dispatch_cast_impl!(int, u64, intCast); primitive_double_dispatch_cast_impl!(isize, u64, isizeCast);
primitive_double_dispatch_cast_impl!(int, u32, intCast); primitive_double_dispatch_cast_impl!(isize, u32, isizeCast);
primitive_double_dispatch_cast_impl!(int, u16, intCast); primitive_double_dispatch_cast_impl!(isize, u16, isizeCast);
primitive_double_dispatch_cast_impl!(int, u8, intCast); primitive_double_dispatch_cast_impl!(isize, u8, isizeCast);
primitive_double_dispatch_cast_impl!(int, int, intCast); primitive_double_dispatch_cast_impl!(isize, isize, isizeCast);
primitive_double_dispatch_cast_impl!(int, uint, intCast); primitive_double_dispatch_cast_impl!(isize, usize, isizeCast);

View File

@ -48,12 +48,12 @@ impl<N: Neg<Output = N> + Zero + Copy> CrossMatrix<Mat3<N>> for Vec3<N> {
// FIXME: implement this for all other vectors // FIXME: implement this for all other vectors
impl<N: Copy> Row<Vec1<N>> for Vec2<N> { impl<N: Copy> Row<Vec1<N>> for Vec2<N> {
#[inline] #[inline]
fn nrows(&self) -> uint { fn nrows(&self) -> usize {
2 2
} }
#[inline] #[inline]
fn row(&self, i: uint) -> Vec1<N> { fn row(&self, i: usize) -> Vec1<N> {
match i { match i {
0 => Vec1::new(self.x), 0 => Vec1::new(self.x),
1 => Vec1::new(self.y), 1 => Vec1::new(self.y),
@ -62,7 +62,7 @@ impl<N: Copy> Row<Vec1<N>> for Vec2<N> {
} }
#[inline] #[inline]
fn set_row(&mut self, i: uint, r: Vec1<N>) { fn set_row(&mut self, i: usize, r: Vec1<N>) {
match i { match i {
0 => self.x = r.x, 0 => self.x = r.x,
1 => self.y = r.x, 1 => self.y = r.x,
@ -82,7 +82,7 @@ impl<N: One> Basis for Vec1<N> {
fn orthonormal_subspace_basis<F: FnMut(Vec1<N>) -> bool>(_: &Vec1<N>, _: F) { } fn orthonormal_subspace_basis<F: FnMut(Vec1<N>) -> bool>(_: &Vec1<N>, _: F) { }
#[inline] #[inline]
fn canonical_basis_element(i: uint) -> Option<Vec1<N>> { fn canonical_basis_element(i: usize) -> Option<Vec1<N>> {
if i == 0 { if i == 0 {
Some(Vec1::new(::one())) Some(Vec1::new(::one()))
} }
@ -105,7 +105,7 @@ impl<N: Copy + One + Zero + Neg<Output = N>> Basis for Vec2<N> {
} }
#[inline] #[inline]
fn canonical_basis_element(i: uint) -> Option<Vec2<N>> { fn canonical_basis_element(i: usize) -> Option<Vec2<N>> {
if i == 0 { if i == 0 {
Some(Vec2::new(::one(), ::zero())) Some(Vec2::new(::one(), ::zero()))
} }
@ -141,7 +141,7 @@ impl<N: BaseFloat> Basis for Vec3<N> {
} }
#[inline] #[inline]
fn canonical_basis_element(i: uint) -> Option<Vec3<N>> { fn canonical_basis_element(i: usize) -> Option<Vec3<N>> {
if i == 0 { if i == 0 {
Some(Vec3::new(::one(), ::zero(), ::zero())) Some(Vec3::new(::one(), ::zero(), ::zero()))
} }

View File

@ -20,52 +20,52 @@ impl<N> Zero for vec::Vec0<N> {
} }
} }
impl<N> Index<uint> for vec::Vec0<N> { impl<N> Index<usize> for vec::Vec0<N> {
type Output = N; type Output = N;
#[inline] #[inline]
fn index(&self, _: &uint) -> &N { fn index(&self, _: &usize) -> &N {
panic!("Canot index a Vec0.") panic!("Canot index a Vec0.")
} }
} }
impl<N> IndexMut<uint> for vec::Vec0<N> { impl<N> IndexMut<usize> for vec::Vec0<N> {
type Output = N; type Output = N;
#[inline] #[inline]
fn index_mut(&mut self, _: &uint) -> &mut N { fn index_mut(&mut self, _: &usize) -> &mut N {
panic!("Canot index a Vec0.") panic!("Canot index a Vec0.")
} }
} }
impl<N> Shape<uint> for vec::Vec0<N> { impl<N> Shape<usize> for vec::Vec0<N> {
#[inline] #[inline]
fn shape(&self) -> uint { fn shape(&self) -> usize {
0 0
} }
} }
impl<N> Indexable<uint, N> for vec::Vec0<N> { impl<N> Indexable<usize, N> for vec::Vec0<N> {
#[inline] #[inline]
fn at(&self, _: uint) -> N { fn at(&self, _: usize) -> N {
panic!("Cannot index a Vec0.") panic!("Cannot index a Vec0.")
} }
#[inline] #[inline]
fn set(&mut self, _: uint, _: N) { fn set(&mut self, _: usize, _: N) {
} }
#[inline] #[inline]
fn swap(&mut self, _: uint, _: uint) { fn swap(&mut self, _: usize, _: usize) {
} }
#[inline] #[inline]
unsafe fn unsafe_at(&self, _: uint) -> N { unsafe fn unsafe_at(&self, _: usize) -> N {
panic!("Cannot index a Vec0.") panic!("Cannot index a Vec0.")
} }
#[inline] #[inline]
unsafe fn unsafe_set(&mut self, _: uint, _: N) { unsafe fn unsafe_set(&mut self, _: usize, _: N) {
} }
} }
@ -85,7 +85,7 @@ impl<N: 'static> IterableMut<N> for vec::Vec0<N> {
impl<N> Dim for vec::Vec0<N> { impl<N> Dim for vec::Vec0<N> {
#[inline] #[inline]
fn dim(_: Option<vec::Vec0<N>>) -> uint { fn dim(_: Option<vec::Vec0<N>>) -> usize {
0 0
} }
} }
@ -98,7 +98,7 @@ impl<N> Basis for vec::Vec0<N> {
fn orthonormal_subspace_basis<F: FnMut(vec::Vec0<N>) -> bool>(_: &vec::Vec0<N>, _: F) { } fn orthonormal_subspace_basis<F: FnMut(vec::Vec0<N>) -> bool>(_: &vec::Vec0<N>, _: F) { }
#[inline(always)] #[inline(always)]
fn canonical_basis_element(_: uint) -> Option<vec::Vec0<N>> { fn canonical_basis_element(_: usize) -> Option<vec::Vec0<N>> {
None None
} }
} }

View File

@ -41,7 +41,7 @@ pub struct Vec1<N> {
} }
new_impl!(Vec1, x); new_impl!(Vec1, x);
ord_impl!(Vec1, x); ord_impl!(Vec1, x,);
vec_axis_impl!(Vec1, x); vec_axis_impl!(Vec1, x);
vec_cast_impl!(Vec1, x); vec_cast_impl!(Vec1, x);
as_array_impl!(Vec1, 1); as_array_impl!(Vec1, 1);

View File

@ -62,13 +62,13 @@ macro_rules! at_fast_impl(
impl<N: Copy> $t<N> { impl<N: Copy> $t<N> {
/// Unsafe read access to a vector element by index. /// Unsafe read access to a vector element by index.
#[inline] #[inline]
pub unsafe fn at_fast(&self, i: uint) -> N { pub unsafe fn at_fast(&self, i: usize) -> N {
(*self.as_array().get_unchecked(i)) (*self.as_array().get_unchecked(i))
} }
/// 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: usize, val: N) {
(*self.as_array_mut().get_unchecked_mut(i)) = val (*self.as_array_mut().get_unchecked_mut(i)) = val
} }
} }
@ -78,74 +78,73 @@ macro_rules! at_fast_impl(
// FIXME: N should be bounded by Ord instead of BaseFloat… // FIXME: N should be bounded by Ord instead of BaseFloat…
// However, f32/f64 does not implement Ord… // However, f32/f64 does not implement Ord…
macro_rules! ord_impl( macro_rules! ord_impl(
($t: ident, $($compN: ident),+) => ( ($t: ident, $comp0: ident, $($compN: ident),*) => (
impl<N: BaseFloat + Copy> POrd for $t<N> { impl<N: BaseFloat + Copy> POrd for $t<N> {
#[inline] #[inline]
fn inf(&self, other: &$t<N>) -> $t<N> { fn inf(&self, other: &$t<N>) -> $t<N> {
$t::new($(self.$compN.min(other.$compN)),+) $t::new(self.$comp0.min(other.$comp0)
$(, self.$compN.min(other.$compN))*)
} }
#[inline] #[inline]
fn sup(&self, other: &$t<N>) -> $t<N> { fn sup(&self, other: &$t<N>) -> $t<N> {
$t::new($(self.$compN.max(other.$compN)),+) $t::new(self.$comp0.max(other.$comp0)
$(, self.$compN.max(other.$compN))*)
} }
#[inline] #[inline]
#[allow(unused_mut)] // otherwise there will be a warning for is_eq or Vec1. #[allow(unused_mut)] // otherwise there will be a warning for is_eq or Vec1.
fn partial_cmp(&self, other: &$t<N>) -> POrdering { fn partial_cmp(&self, other: &$t<N>) -> POrdering {
let mut first = true; let is_lt = self.$comp0 < other.$comp0;
let mut is_lt = false; let mut is_eq = self.$comp0 == other.$comp0;
let mut is_eq = false;
$( if is_lt { // <
if first { $(
is_lt = self.$compN < other.$compN;
is_eq = self.$compN == other.$compN;
first = false;
}
else if is_lt { // <
if self.$compN > other.$compN { if self.$compN > other.$compN {
return POrdering::NotComparable return POrdering::NotComparable
} }
} )*
else { // >=
POrdering::PartialLess
}
else { // >=
$(
if self.$compN < other.$compN { if self.$compN < other.$compN {
return POrdering::NotComparable return POrdering::NotComparable
} }
else if self.$compN > other.$compN { else if self.$compN > other.$compN {
is_eq = false; is_eq = false;
} }
}
)+
if is_lt { )*
POrdering::PartialLess
} if is_eq {
else if is_eq { POrdering::PartialEqual
POrdering::PartialEqual }
} else {
else { POrdering::PartialGreater
POrdering::PartialGreater }
} }
} }
#[inline] #[inline]
fn partial_lt(&self, other: &$t<N>) -> bool { fn partial_lt(&self, other: &$t<N>) -> bool {
$(self.$compN < other.$compN)&&+ self.$comp0 < other.$comp0 $(&& self.$compN < other.$compN)*
} }
#[inline] #[inline]
fn partial_le(&self, other: &$t<N>) -> bool { fn partial_le(&self, other: &$t<N>) -> bool {
$(self.$compN <= other.$compN)&&+ self.$comp0 <= other.$comp0 $(&& self.$compN <= other.$compN)*
} }
#[inline] #[inline]
fn partial_gt(&self, other: &$t<N>) -> bool { fn partial_gt(&self, other: &$t<N>) -> bool {
$(self.$compN > other.$compN)&&+ self.$comp0 > other.$comp0 $(&& self.$compN > other.$compN)*
} }
#[inline] #[inline]
fn partial_ge(&self, other: &$t<N>) -> bool { fn partial_ge(&self, other: &$t<N>) -> bool {
$(self.$compN >= other.$compN)&&+ self.$comp0 >= other.$comp0 $(&& self.$compN >= other.$compN)*
} }
} }
) )
@ -182,42 +181,42 @@ macro_rules! vec_cast_impl(
macro_rules! indexable_impl( macro_rules! indexable_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> Shape<uint> for $t<N> { impl<N> Shape<usize> for $t<N> {
#[inline] #[inline]
fn shape(&self) -> uint { fn shape(&self) -> usize {
$dim $dim
} }
} }
impl<N: Copy> Indexable<uint, N> for $t<N> { impl<N: Copy> Indexable<usize, N> for $t<N> {
#[inline] #[inline]
fn at(&self, i: uint) -> N { fn at(&self, i: usize) -> N {
unsafe { unsafe {
mem::transmute::<&$t<N>, &[N; $dim]>(self)[i] mem::transmute::<&$t<N>, &[N; $dim]>(self)[i]
} }
} }
#[inline] #[inline]
fn set(&mut self, i: uint, val: N) { fn set(&mut self, i: usize, val: N) {
unsafe { unsafe {
mem::transmute::<&mut $t<N>, &mut [N; $dim]>(self)[i] = val mem::transmute::<&mut $t<N>, &mut [N; $dim]>(self)[i] = val
} }
} }
#[inline] #[inline]
fn swap(&mut self, i1: uint, i2: uint) { fn swap(&mut self, i1: usize, i2: usize) {
unsafe { unsafe {
mem::transmute::<&mut $t<N>, &mut [N; $dim]>(self).swap(i1, i2) mem::transmute::<&mut $t<N>, &mut [N; $dim]>(self).swap(i1, i2)
} }
} }
#[inline] #[inline]
unsafe fn unsafe_at(&self, i: uint) -> N { unsafe fn unsafe_at(&self, i: usize) -> N {
(*mem::transmute::<&$t<N>, &[N; $dim]>(self).get_unchecked(i)) (*mem::transmute::<&$t<N>, &[N; $dim]>(self).get_unchecked(i))
} }
#[inline] #[inline]
unsafe fn unsafe_set(&mut self, i: uint, val: N) { unsafe fn unsafe_set(&mut self, i: usize, val: N) {
(*mem::transmute::<&mut $t<N>, &mut [N; $dim]>(self).get_unchecked_mut(i)) = val (*mem::transmute::<&mut $t<N>, &mut [N; $dim]>(self).get_unchecked_mut(i)) = val
} }
} }
@ -226,18 +225,18 @@ macro_rules! indexable_impl(
macro_rules! index_impl( macro_rules! index_impl(
($t: ident) => ( ($t: ident) => (
impl<N> Index<uint> for $t<N> { impl<N> Index<usize> for $t<N> {
type Output = N; type Output = N;
fn index(&self, i: &uint) -> &N { fn index(&self, i: &usize) -> &N {
&self.as_array()[*i] &self.as_array()[*i]
} }
} }
impl<N> IndexMut<uint> for $t<N> { impl<N> IndexMut<usize> for $t<N> {
type Output = N; type Output = N;
fn index_mut(&mut self, i: &uint) -> &mut N { fn index_mut(&mut self, i: &usize) -> &mut N {
&mut self.as_array_mut()[*i] &mut self.as_array_mut()[*i]
} }
} }
@ -288,7 +287,7 @@ macro_rules! dim_impl(
($t: ident, $dim: expr) => ( ($t: ident, $dim: expr) => (
impl<N> Dim for $t<N> { impl<N> Dim for $t<N> {
#[inline] #[inline]
fn dim(_: Option<$t<N>>) -> uint { fn dim(_: Option<$t<N>>) -> usize {
$dim $dim
} }
} }
@ -299,7 +298,7 @@ macro_rules! container_impl(
($t: ident) => ( ($t: ident) => (
impl<N> $t<N> { impl<N> $t<N> {
#[inline] #[inline]
pub fn len(&self) -> uint { pub fn len(&self) -> usize {
Dim::dim(None::<$t<N>>) Dim::dim(None::<$t<N>>)
} }
} }
@ -311,7 +310,7 @@ macro_rules! basis_impl(
impl<N: Copy + BaseFloat + ApproxEq<N>> Basis for $t<N> { impl<N: Copy + BaseFloat + ApproxEq<N>> Basis for $t<N> {
#[inline] #[inline]
fn canonical_basis<F: FnMut($t<N>) -> bool>(mut f: F) { fn canonical_basis<F: FnMut($t<N>) -> bool>(mut f: F) {
for i in range(0u, $dim) { for i in (0us .. $dim) {
if !f(Basis::canonical_basis_element(i).unwrap()) { return } if !f(Basis::canonical_basis_element(i).unwrap()) { return }
} }
} }
@ -322,7 +321,7 @@ macro_rules! basis_impl(
// orthogonalization algorithm // orthogonalization algorithm
let mut basis: Vec<$t<N>> = Vec::new(); let mut basis: Vec<$t<N>> = Vec::new();
for i in range(0u, $dim) { for i in (0us .. $dim) {
let mut basis_element : $t<N> = ::zero(); let mut basis_element : $t<N> = ::zero();
unsafe { unsafe {
@ -352,7 +351,7 @@ macro_rules! basis_impl(
} }
#[inline] #[inline]
fn canonical_basis_element(i: uint) -> Option<$t<N>> { fn canonical_basis_element(i: usize) -> Option<$t<N>> {
if i < $dim { if i < $dim {
let mut basis_element : $t<N> = ::zero(); let mut basis_element : $t<N> = ::zero();

View File

@ -193,8 +193,8 @@ impl ApproxEq<f32> for f32 {
// Otherwise, differing signs should be not-equal, even if within ulps // Otherwise, differing signs should be not-equal, even if within ulps
if self.signum() != other.signum() { return false; } if self.signum() != other.signum() { return false; }
// IEEE754 floats are in the same order as 2s complement ints // IEEE754 floats are in the same order as 2s complement isizes
// so this trick (subtracting the ints) works. // so this trick (subtracting the isizes) works.
let iself: i32 = unsafe { ::std::mem::transmute(*self) }; let iself: i32 = unsafe { ::std::mem::transmute(*self) };
let iother: i32 = unsafe { ::std::mem::transmute(*other) }; let iother: i32 = unsafe { ::std::mem::transmute(*other) };
@ -298,7 +298,7 @@ pub trait Mean<N> {
/// Trait for computing the eigenvector and eigenvalues of a square matrix usin the QR algorithm. /// Trait for computing the eigenvector and eigenvalues of a square matrix usin the QR algorithm.
pub trait EigenQR<N, V>: SquareMat<N, V> { pub trait EigenQR<N, V>: SquareMat<N, V> {
/// Computes the eigenvectors and eigenvalues of this matrix. /// Computes the eigenvectors and eigenvalues of this matrix.
fn eigen_qr(&self, eps: &N, niter: uint) -> (Self, V); fn eigen_qr(&self, eps: &N, niter: usize) -> (Self, V);
} }
// XXX: those two traits should not exist since there is generalized operator overloading of Add // XXX: those two traits should not exist since there is generalized operator overloading of Add
@ -404,12 +404,12 @@ impl_absolute!(i8);
impl_absolute!(i16); impl_absolute!(i16);
impl_absolute!(i32); impl_absolute!(i32);
impl_absolute!(i64); impl_absolute!(i64);
impl_absolute!(int); impl_absolute!(isize);
impl_absolute_id!(u8); impl_absolute_id!(u8);
impl_absolute_id!(u16); impl_absolute_id!(u16);
impl_absolute_id!(u32); impl_absolute_id!(u32);
impl_absolute_id!(u64); impl_absolute_id!(u64);
impl_absolute_id!(uint); impl_absolute_id!(usize);
macro_rules! impl_axpy( macro_rules! impl_axpy(
($n: ty) => { ($n: ty) => {
@ -428,9 +428,9 @@ impl_axpy!(i8);
impl_axpy!(i16); impl_axpy!(i16);
impl_axpy!(i32); impl_axpy!(i32);
impl_axpy!(i64); impl_axpy!(i64);
impl_axpy!(int); impl_axpy!(isize);
impl_axpy!(u8); impl_axpy!(u8);
impl_axpy!(u16); impl_axpy!(u16);
impl_axpy!(u32); impl_axpy!(u32);
impl_axpy!(u64); impl_axpy!(u64);
impl_axpy!(uint); impl_axpy!(usize);

View File

@ -8,7 +8,7 @@ use std::ops::{Add, Sub, Mul, Div, Neg, Rem, Index, IndexMut};
use traits::operations::{RMul, LMul, Axpy, Transpose, Inv, Absolute}; use traits::operations::{RMul, LMul, Axpy, Transpose, Inv, Absolute};
use traits::geometry::{Dot, Norm, Orig}; use traits::geometry::{Dot, Norm, Orig};
/// Basic integral numeric trait. /// Basic isizeegral numeric trait.
pub trait BaseNum: Copy + Zero + One + pub trait BaseNum: Copy + Zero + One +
Add<Self, Output = Self> + Sub<Self, Output = Self> + Add<Self, Output = Self> + Sub<Self, Output = Self> +
Mul<Self, Output = Self> + Div<Self, Output = Self> + Mul<Self, Output = Self> + Div<Self, Output = Self> +
@ -60,10 +60,10 @@ pub trait Cast<T> {
/// Trait of matrices. /// Trait of matrices.
/// ///
/// A matrix has rows and columns and are able to multiply them. /// A matrix has rows and columns and are able to multiply them.
pub trait Mat<N, R, C>: Row<R> + Col<C> + RMul<R> + LMul<C> + Index<(uint, uint), Output = N> { } pub trait Mat<N, R, C>: Row<R> + Col<C> + RMul<R> + LMul<C> + Index<(usize, usize), Output = N> { }
impl<N, M, R, C> Mat<N, R, C> for M impl<N, M, R, C> Mat<N, R, C> for M
where M: Row<R> + Col<C> + RMul<R> + LMul<C> + Index<(uint, uint), Output = N> { where M: Row<R> + Col<C> + RMul<R> + LMul<C> + Index<(usize, usize), Output = N> {
} }
/// Trait implemented by square matrices. /// Trait implemented by square matrices.
@ -78,7 +78,7 @@ impl<N, V, M> SquareMat<N, V> for M
/// Trait for constructing the identity matrix /// Trait for constructing the identity matrix
pub trait Eye { pub trait Eye {
/// Return the identity matrix of specified dimension /// Return the identity matrix of specified dimension
fn new_identity(dim: uint) -> Self; fn new_identity(dim: usize) -> Self;
} }
/// Additive identity. /// Additive identity.
@ -115,17 +115,17 @@ pub trait Basis {
fn orthonormal_subspace_basis<F: FnMut(Self) -> bool>(&Self, F); fn orthonormal_subspace_basis<F: FnMut(Self) -> bool>(&Self, F);
/// Gets the ith element of the canonical basis. /// Gets the ith element of the canonical basis.
fn canonical_basis_element(i: uint) -> Option<Self>; fn canonical_basis_element(i: usize) -> Option<Self>;
} }
/// Trait to access rows of a matrix or a vector. /// Trait to access rows of a matrix or a vector.
pub trait Row<R> { pub trait Row<R> {
/// The number of column of `self`. /// The number of column of `self`.
fn nrows(&self) -> uint; fn nrows(&self) -> usize;
/// Reads the `i`-th row of `self`. /// Reads the `i`-th row of `self`.
fn row(&self, i: uint) -> R; fn row(&self, i: usize) -> R;
/// Writes the `i`-th row of `self`. /// Writes the `i`-th row of `self`.
fn set_row(&mut self, i: uint, R); fn set_row(&mut self, i: usize, R);
// FIXME: add iterators on rows: this could be a very good way to generalize _and_ optimize // FIXME: add iterators on rows: this could be a very good way to generalize _and_ optimize
// a lot of operations. // a lot of operations.
@ -134,13 +134,13 @@ pub trait Row<R> {
/// Trait to access columns of a matrix or vector. /// Trait to access columns of a matrix or vector.
pub trait Col<C> { pub trait Col<C> {
/// The number of column of this matrix or vector. /// The number of column of this matrix or vector.
fn ncols(&self) -> uint; fn ncols(&self) -> usize;
/// Reads the `i`-th column of `self`. /// Reads the `i`-th column of `self`.
fn col(&self, i: uint) -> C; fn col(&self, i: usize) -> C;
/// Writes the `i`-th column of `self`. /// Writes the `i`-th column of `self`.
fn set_col(&mut self, i: uint, C); fn set_col(&mut self, i: usize, C);
// FIXME: add iterators on columns: this could be a very good way to generalize _and_ optimize // FIXME: add iterators on columns: this could be a very good way to generalize _and_ optimize
// a lot of operations. // a lot of operations.
@ -149,19 +149,19 @@ pub trait Col<C> {
/// Trait to access part of a column of a matrix /// Trait to access part of a column of a matrix
pub trait ColSlice<C> { pub trait ColSlice<C> {
/// Returns a view to a slice of a column of a matrix. /// Returns a view to a slice of a column of a matrix.
fn col_slice(&self, col_id: uint, row_start: uint, row_end: uint) -> C; fn col_slice(&self, col_id: usize, row_start: usize, row_end: usize) -> C;
} }
/// Trait to access part of a row of a matrix /// Trait to access part of a row of a matrix
pub trait RowSlice<R> { pub trait RowSlice<R> {
/// Returns a view to a slice of a row of a matrix. /// Returns a view to a slice of a row of a matrix.
fn row_slice(&self, row_id: uint, col_start: uint, col_end: uint) -> R; fn row_slice(&self, row_id: usize, col_start: usize, col_end: usize) -> R;
} }
/// Trait of objects having a spacial dimension known at compile time. /// Trait of objects having a spacial dimension known at compile time.
pub trait Dim { pub trait Dim {
/// The dimension of the object. /// The dimension of the object.
fn dim(unused_self: Option<Self>) -> uint; fn dim(unused_self: Option<Self>) -> usize;
} }
/// Trait to get the diagonal of square matrices. /// Trait to get the diagonal of square matrices.
@ -241,7 +241,7 @@ pub trait NumVec<N>: Dim +
Sub<Self, Output = Self> + Add<Self, Output = Self> + Sub<Self, Output = Self> + Add<Self, Output = Self> +
Mul<N, Output = Self> + Div<N, Output = Self> + Mul<N, Output = Self> + Div<N, Output = Self> +
Neg<Output = Self> + Neg<Output = Self> +
Index<uint, Output = N> + Index<usize, Output = N> +
Zero + PartialEq + Dot<N> + Axpy<N> { Zero + PartialEq + Dot<N> + Axpy<N> {
} }
@ -281,7 +281,7 @@ pub trait NumPnt<N, V>:
Mul<N, Output = Self> + Mul<N, Output = Self> +
Div<N, Output = Self> + Div<N, Output = Self> +
Add<V, Output = Self> + Add<V, Output = Self> +
Index<uint, Output = N> { // FIXME: + Sub<V, Self> Index<usize, Output = N> { // FIXME: + Sub<V, Self>
} }
/// Trait of points with components implementing the `BaseFloat` trait. /// Trait of points with components implementing the `BaseFloat` trait.
@ -338,12 +338,12 @@ impl_zero_one!(i8, 0, 1);
impl_zero_one!(i16, 0, 1); impl_zero_one!(i16, 0, 1);
impl_zero_one!(i32, 0, 1); impl_zero_one!(i32, 0, 1);
impl_zero_one!(i64, 0, 1); impl_zero_one!(i64, 0, 1);
impl_zero_one!(int, 0, 1); impl_zero_one!(isize, 0, 1);
impl_zero_one!(u8, 0, 1); impl_zero_one!(u8, 0, 1);
impl_zero_one!(u16, 0, 1); impl_zero_one!(u16, 0, 1);
impl_zero_one!(u32, 0, 1); impl_zero_one!(u32, 0, 1);
impl_zero_one!(u64, 0, 1); impl_zero_one!(u64, 0, 1);
impl_zero_one!(uint, 0, 1); impl_zero_one!(usize, 0, 1);
// Bounded // Bounded
@ -369,12 +369,12 @@ impl_bounded!(i8, Int::min_value(), Int::max_value());
impl_bounded!(i16, Int::min_value(), Int::max_value()); impl_bounded!(i16, Int::min_value(), Int::max_value());
impl_bounded!(i32, Int::min_value(), Int::max_value()); impl_bounded!(i32, Int::min_value(), Int::max_value());
impl_bounded!(i64, Int::min_value(), Int::max_value()); impl_bounded!(i64, Int::min_value(), Int::max_value());
impl_bounded!(int, Int::min_value(), Int::max_value()); impl_bounded!(isize, Int::min_value(), Int::max_value());
impl_bounded!(u8, Int::min_value(), Int::max_value()); impl_bounded!(u8, Int::min_value(), Int::max_value());
impl_bounded!(u16, Int::min_value(), Int::max_value()); impl_bounded!(u16, Int::min_value(), Int::max_value());
impl_bounded!(u32, Int::min_value(), Int::max_value()); impl_bounded!(u32, Int::min_value(), Int::max_value());
impl_bounded!(u64, Int::min_value(), Int::max_value()); impl_bounded!(u64, Int::min_value(), Int::max_value());
impl_bounded!(uint, Int::min_value(), Int::max_value()); impl_bounded!(usize, Int::min_value(), Int::max_value());
// BaseFloat // BaseFloat

View File

@ -6,7 +6,7 @@ use na::{Vec1, Vec3, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot3, Persp3, PerspMat3
macro_rules! test_inv_mat_impl( macro_rules! test_inv_mat_impl(
($t: ty) => ( ($t: ty) => (
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let randmat : $t = random(); let randmat : $t = random();
match na::inv(&randmat) { match na::inv(&randmat) {
@ -19,7 +19,7 @@ macro_rules! test_inv_mat_impl(
macro_rules! test_transpose_mat_impl( macro_rules! test_transpose_mat_impl(
($t: ty) => ( ($t: ty) => (
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let randmat : $t = random(); let randmat : $t = random();
assert!(na::transpose(&na::transpose(&randmat)) == randmat); assert!(na::transpose(&na::transpose(&randmat)) == randmat);
@ -29,7 +29,7 @@ macro_rules! test_transpose_mat_impl(
macro_rules! test_qr_impl( macro_rules! test_qr_impl(
($t: ty) => ( ($t: ty) => (
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let randmat : $t = random(); let randmat : $t = random();
let (q, r) = na::qr(&randmat); let (q, r) = na::qr(&randmat);
@ -43,7 +43,7 @@ macro_rules! test_qr_impl(
// NOTE: deactivated untile we get a better convergence rate. // NOTE: deactivated untile we get a better convergence rate.
// macro_rules! test_eigen_qr_impl( // macro_rules! test_eigen_qr_impl(
// ($t: ty) => { // ($t: ty) => {
// for _ in range(0u, 10000) { // for _ in (0us .. 10000) {
// let randmat : $t = random(); // let randmat : $t = random();
// // Make it symetric so that we can recompose the matrix to test at the end. // // Make it symetric so that we can recompose the matrix to test at the end.
// let randmat = na::transpose(&randmat) * randmat; // let randmat = na::transpose(&randmat) * randmat;
@ -125,7 +125,7 @@ fn test_inv_mat6() {
#[test] #[test]
fn test_rotation2() { fn test_rotation2() {
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let randmat: na::Rot2<f64> = na::one(); let randmat: na::Rot2<f64> = na::one();
let ang = Vec1::new(na::abs(&random::<f64>()) % BaseFloat::pi()); let ang = Vec1::new(na::abs(&random::<f64>()) % BaseFloat::pi());
@ -142,7 +142,7 @@ fn test_index_mat2() {
#[test] #[test]
fn test_inv_rotation3() { fn test_inv_rotation3() {
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let randmat: Rot3<f64> = na::one(); let randmat: Rot3<f64> = na::one();
let dir: Vec3<f64> = random(); let dir: Vec3<f64> = random();
let ang = na::normalize(&dir) * (na::abs(&random::<f64>()) % BaseFloat::pi()); let ang = na::normalize(&dir) * (na::abs(&random::<f64>()) % BaseFloat::pi());
@ -250,9 +250,9 @@ fn test_dmat_from_vec() {
/* FIXME: review qr decomposition to make it work with DMat. /* FIXME: review qr decomposition to make it work with DMat.
#[test] #[test]
fn test_qr() { fn test_qr() {
for _ in range(0u, 10) { for _ in (0us .. 10) {
let dim1: uint = random(); let dim1: usize = random();
let dim2: uint = random(); let dim2: usize = random();
let rows = min(40, max(dim1, dim2)); let rows = min(40, max(dim1, dim2));
let cols = min(40, min(dim1, dim2)); let cols = min(40, min(dim1, dim2));
let randmat: DMat<f64> = DMat::new_random(rows, cols); let randmat: DMat<f64> = DMat::new_random(rows, cols);
@ -327,8 +327,8 @@ fn test_qr_mat6() {
#[test] #[test]
fn test_from_fn() { fn test_from_fn() {
let actual: DMat<uint> = DMat::from_fn(3, 4, |i, j| 10 * i + j); let actual: DMat<usize> = DMat::from_fn(3, 4, |i, j| 10 * i + j);
let expected: DMat<uint> = DMat::from_row_vec(3, 4, let expected: DMat<usize> = DMat::from_row_vec(3, 4,
&[ 0_0, 0_1, 0_2, 0_3, &[ 0_0, 0_1, 0_2, 0_3,
1_0, 1_1, 1_2, 1_3, 1_0, 1_1, 1_2, 1_3,
2_0, 2_1, 2_2, 2_3 ]); 2_0, 2_1, 2_2, 2_3 ]);

View File

@ -5,7 +5,7 @@ use std::rand::random;
#[test] #[test]
fn test_quat_as_mat() { fn test_quat_as_mat() {
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let axis_angle: Vec3<f64> = random(); let axis_angle: Vec3<f64> = random();
assert!(na::approx_eq(&UnitQuat::new(axis_angle).to_rot(), &Rot3::new(axis_angle))) assert!(na::approx_eq(&UnitQuat::new(axis_angle).to_rot(), &Rot3::new(axis_angle)))
@ -14,7 +14,7 @@ fn test_quat_as_mat() {
#[test] #[test]
fn test_quat_mul_vec_or_pnt_as_mat() { fn test_quat_mul_vec_or_pnt_as_mat() {
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let axis_angle: Vec3<f64> = random(); let axis_angle: Vec3<f64> = random();
let vec: Vec3<f64> = random(); let vec: Vec3<f64> = random();
let pnt: Pnt3<f64> = random(); let pnt: Pnt3<f64> = random();
@ -31,7 +31,7 @@ fn test_quat_mul_vec_or_pnt_as_mat() {
#[test] #[test]
fn test_quat_div_quat() { fn test_quat_div_quat() {
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let axis_angle1: Vec3<f64> = random(); let axis_angle1: Vec3<f64> = random();
let axis_angle2: Vec3<f64> = random(); let axis_angle2: Vec3<f64> = random();
@ -47,7 +47,7 @@ fn test_quat_div_quat() {
#[test] #[test]
fn test_quat_to_axis_angle() { fn test_quat_to_axis_angle() {
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let axis_angle: Vec3<f64> = random(); let axis_angle: Vec3<f64> = random();
let q = UnitQuat::new(axis_angle); let q = UnitQuat::new(axis_angle);
@ -59,7 +59,7 @@ fn test_quat_to_axis_angle() {
#[test] #[test]
fn test_quat_euler_angles() { fn test_quat_euler_angles() {
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let angles: Vec3<f64> = random(); let angles: Vec3<f64> = random();
let q = UnitQuat::new_with_euler_angles(angles.x, angles.y, angles.z); let q = UnitQuat::new_with_euler_angles(angles.x, angles.y, angles.z);

View File

@ -5,7 +5,7 @@ use na::{Vec0, Vec1, Vec2, Vec3, Vec4, Vec5, Vec6, Mat3, Iterable, IterableMut};
macro_rules! test_iterator_impl( macro_rules! test_iterator_impl(
($t: ty, $n: ty) => ( ($t: ty, $n: ty) => (
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let v: $t = random(); let v: $t = random();
let mut mv: $t = v.clone(); let mut mv: $t = v.clone();
let n: $n = random(); let n: $n = random();
@ -23,7 +23,7 @@ macro_rules! test_iterator_impl(
macro_rules! test_commut_dot_impl( macro_rules! test_commut_dot_impl(
($t: ty) => ( ($t: ty) => (
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let v1 : $t = random(); let v1 : $t = random();
let v2 : $t = random(); let v2 : $t = random();
@ -34,7 +34,7 @@ macro_rules! test_commut_dot_impl(
macro_rules! test_scalar_op_impl( macro_rules! test_scalar_op_impl(
($t: ty, $n: ty) => ( ($t: ty, $n: ty) => (
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let v1 : $t = random(); let v1 : $t = random();
let n : $n = random(); let n : $n = random();
@ -57,7 +57,7 @@ macro_rules! test_scalar_op_impl(
macro_rules! test_basis_impl( macro_rules! test_basis_impl(
($t: ty) => ( ($t: ty) => (
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
na::canonical_basis(|e1: $t| { na::canonical_basis(|e1: $t| {
na::canonical_basis(|e2: $t| { na::canonical_basis(|e2: $t| {
assert!(e1 == e2 || na::approx_eq(&na::dot(&e1, &e2), &na::zero())); assert!(e1 == e2 || na::approx_eq(&na::dot(&e1, &e2), &na::zero()));
@ -75,7 +75,7 @@ macro_rules! test_basis_impl(
macro_rules! test_subspace_basis_impl( macro_rules! test_subspace_basis_impl(
($t: ty) => ( ($t: ty) => (
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let v : $t = random(); let v : $t = random();
let v1 = na::normalize(&v); let v1 = na::normalize(&v);
@ -99,7 +99,7 @@ macro_rules! test_subspace_basis_impl(
#[test] #[test]
fn test_cross_vec3() { fn test_cross_vec3() {
for _ in range(0u, 10000) { for _ in (0us .. 10000) {
let v1 : Vec3<f64> = random(); let v1 : Vec3<f64> = random();
let v2 : Vec3<f64> = random(); let v2 : Vec3<f64> = random();
let v3 : Vec3<f64> = na::cross(&v1, &v2); let v3 : Vec3<f64> = na::cross(&v1, &v2);