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

View File

@ -11,7 +11,7 @@ macro_rules! bench_mul_dmat(
let a: 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!
b = a.clone() * b;
}
@ -53,7 +53,7 @@ macro_rules! bench_mul_dmat_dvec(
let m : DMat<f64> = DMat::new_random($nrows, $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!
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(unused_qualifications)]
#![deny(unused_results)]
#![allow(unstable)]
#![warn(missing_docs)]
#![feature(old_orphan_check)]
#![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.
#[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)
}
@ -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
#[inline(always)]
pub fn new_identity<M: Eye>(dim: uint) -> M {
pub fn new_identity<M: Eye>(dim: usize) -> M {
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.
#[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)
}
@ -902,7 +903,7 @@ pub fn diag<M: Diag<V>, V>(m: &M) -> V {
///
/// Same as `Dim::dim::(None::<V>)`.
#[inline(always)]
pub fn dim<V: Dim>() -> uint {
pub fn dim<V: Dim>() -> usize {
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
/// * `start` - the starting dimension of the subspace of the reflexion
/// * `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,
M: Eye + Indexable<(uint, uint), N>,
V: Indexable<uint, N> {
M: Eye + Indexable<(usize, usize), N>,
V: Indexable<usize, N> {
let mut qk : M = Eye::new_identity(dim);
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);
for j in range(start, stop) {
for i in range(start, stop) {
for j in (start .. stop) {
for i in (start .. stop) {
unsafe {
let vv = vec.unsafe_at(i - start) * vec.unsafe_at(j - start);
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
pub fn qr<N, V, M>(m: &M) -> (M, M)
where N: BaseFloat,
V: Indexable<uint, N> + Norm<N>,
M: Copy + Eye + ColSlice<V> + Transpose + Indexable<(uint, uint), N> +
V: Indexable<usize, N> + Norm<N>,
M: Copy + Eye + ColSlice<V> + Transpose + Indexable<(usize, usize), N> +
Mul<M, Output = M> {
let (rows, cols) = m.shape();
assert!(rows >= cols);
@ -50,7 +50,7 @@ pub fn qr<N, V, M>(m: &M) -> (M, M)
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 alpha =
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.
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,
VS: Indexable<uint, N> + Norm<N>,
M: Indexable<(uint, uint), N> + SquareMat<N, V> + Add<M, Output = M> +
VS: Indexable<usize, N> + Norm<N>,
M: Indexable<(usize, usize), N> + SquareMat<N, V> + Add<M, Output = M> +
Sub<M, Output = M> + ColSlice<VS> +
ApproxEq<N> + Copy {
let mut eigenvectors: M = ::one::<M>();
let mut eigenvalues = *m;
// let mut shifter: M = Eye::new_identity(rows);
let mut iter = 0u;
for _ in range(0, niter) {
let mut iter = 0us;
for _ in (0 .. niter) {
let mut stop = true;
for j in range(0, ::dim::<M>()) {
for i in range(0, j) {
for j in (0 .. ::dim::<M>()) {
for i in (0 .. j) {
if unsafe { eigenvalues.unsafe_at((i, j)) }.abs() >= *eps {
stop = false;
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 {
stop = false;
break;

View File

@ -18,15 +18,15 @@ use std::fmt::{Show, Formatter, Result, String};
/// Matrix with dimensions unknown at compile-time.
#[derive(Eq, PartialEq, Clone)]
pub struct DMat<N> {
nrows: uint,
ncols: uint,
nrows: usize,
ncols: usize,
mij: Vec<N>
}
impl<N> DMat<N> {
/// Creates an uninitialized matrix.
#[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);
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`
/// components.
#[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())
}
@ -66,7 +66,7 @@ impl<N: Zero + Clone + Copy> DMat<N> {
impl<N: Rand> DMat<N> {
/// Builds a matrix filled with random values.
#[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())
}
}
@ -74,7 +74,7 @@ impl<N: Rand> DMat<N> {
impl<N: One + Clone + Copy> DMat<N> {
/// Builds a matrix filled with a given constant.
#[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())
}
}
@ -82,7 +82,7 @@ impl<N: One + Clone + Copy> DMat<N> {
impl<N: Clone + Copy> DMat<N> {
/// Builds a matrix filled with a given constant.
#[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 {
nrows: nrows,
ncols: ncols,
@ -97,7 +97,7 @@ impl<N: Clone + Copy> DMat<N> {
///
/// The vector must have at least `nrows * ncols` elements.
#[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);
// 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.
#[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());
DMat {
@ -127,27 +127,27 @@ impl<N: Clone + Copy> DMat<N> {
impl<N> DMat<N> {
/// Builds a matrix filled with a given constant.
#[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 {
nrows: nrows,
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.
#[inline]
pub fn nrows(&self) -> uint {
pub fn nrows(&self) -> usize {
self.nrows
}
/// The number of columns on the matrix.
#[inline]
pub fn ncols(&self) -> uint {
pub fn ncols(&self) -> usize {
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.
#[inline]
pub fn to_vec(self) -> Vec<N> {
@ -157,14 +157,14 @@ impl<N> DMat<N> {
/// Gets a reference to this matrix data.
/// The returned vector contains the matrix data in column-major order.
#[inline]
pub fn as_vec<'r>(&'r self) -> &'r [N] {
self.mij.as_slice()
pub fn as_vec(&self) -> &[N] {
&self.mij[]
}
/// Gets a mutable reference to this matrix data.
/// The returned vector contains the matrix data in column-major order.
#[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()
}
}
@ -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`
/// components.
#[inline]
fn new_identity(dim: uint) -> DMat<N> {
fn new_identity(dim: usize) -> DMat<N> {
let mut res = DMat::new_zeros(dim, dim);
for i in range(0u, dim) {
for i in (0us .. dim) {
let _1: N = ::one();
res[(i, i)] = _1;
}
@ -192,19 +192,19 @@ impl<N: One + Zero + Clone + Copy> Eye for DMat<N> {
impl<N> DMat<N> {
#[inline(always)]
fn offset(&self, i: uint, j: uint) -> uint {
fn offset(&self, i: usize, j: usize) -> usize {
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.
///
/// # Arguments
/// * `rowcol` - 0-based tuple (row, col) to be changed
#[inline]
fn set(&mut self, rowcol: (uint, uint), val: N) {
fn set(&mut self, rowcol: (usize, usize), val: N) {
let (row, col) = rowcol;
assert!(row < self.nrows);
assert!(col < self.ncols);
@ -215,7 +215,7 @@ impl<N: Copy> Indexable<(uint, uint), N> for DMat<N> {
/// Just like `set` without bounds checking.
#[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 offset = self.offset(row, col);
*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
/// * `rowcol` - 0-based tuple (row, col) to be read
#[inline]
fn at(&self, rowcol: (uint, uint)) -> N {
fn at(&self, rowcol: (usize, usize)) -> N {
let (row, col) = rowcol;
assert!(row < self.nrows);
assert!(col < self.ncols);
@ -235,14 +235,14 @@ impl<N: Copy> Indexable<(uint, uint), N> for DMat<N> {
/// Just like `at` without bounds checking.
#[inline]
unsafe fn unsafe_at(&self, rowcol: (uint, uint)) -> N {
unsafe fn unsafe_at(&self, rowcol: (usize, usize)) -> N {
let (row, col) = rowcol;
*self.mij.as_slice().get_unchecked(self.offset(row, col))
*self.mij[].get_unchecked(self.offset(row, col))
}
#[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 (row2, col2) = rowcol2;
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]
fn shape(&self) -> (uint, uint) {
fn shape(&self) -> (usize, usize) {
(self.nrows, self.ncols)
}
}
impl<N> Index<(uint, uint)> for DMat<N> {
impl<N> Index<(usize, usize)> for DMat<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!(j < self.ncols);
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;
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!(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) };
for i in range(0u, self.nrows) {
for j in range(0u, right.ncols) {
for i in (0us .. self.nrows) {
for j in (0us .. right.ncols) {
let mut acc: N = ::zero();
unsafe {
for k in range(0u, self.ncols) {
for k in (0us .. self.ncols) {
acc = acc
+ 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) };
for i in range(0u, self.nrows) {
for i in (0us .. self.nrows) {
let mut acc: N = ::zero();
for j in range(0u, self.ncols) {
for j in (0us .. self.ncols) {
unsafe {
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) };
for i in range(0u, right.ncols) {
for i in (0us .. right.ncols) {
let mut acc: N = ::zero();
for j in range(0u, right.nrows) {
for j in (0us .. right.nrows) {
unsafe {
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);
// 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
// FIXME: would it be worth it to spend some more time searching for the
// max instead?
@ -406,7 +406,7 @@ impl<N: BaseNum + Clone> Inv for DMat<N> {
// swap pivot line
if n0 != k {
for j in range(0u, dim) {
for j in (0us .. dim) {
let off_n0_j = self.offset(n0, j);
let off_k_j = self.offset(k, j);
@ -418,26 +418,26 @@ impl<N: BaseNum + Clone> Inv for DMat<N> {
unsafe {
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;
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;
res.unsafe_set((k, j), resval);
}
for l in range(0u, dim) {
for l in (0us .. dim) {
if 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;
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;
res.unsafe_set((l, j), resval);
}
@ -465,8 +465,8 @@ impl<N: Clone + Copy> Transpose for DMat<N> {
else {
let mut res = unsafe { DMat::new_uninitialized(self.ncols, self.nrows) };
for i in range(0u, self.nrows) {
for j in range(0u, self.ncols) {
for i in (0us .. self.nrows) {
for j in (0us .. self.ncols) {
unsafe {
res.unsafe_set((j, i), self.unsafe_at((i, j)))
}
@ -480,8 +480,8 @@ impl<N: Clone + Copy> Transpose for DMat<N> {
#[inline]
fn transpose(&mut self) {
if self.nrows == self.ncols {
for i in range(1u, self.nrows) {
for j in range(0u, self.ncols - 1) {
for i in (1us .. self.nrows) {
for j in (0us .. self.ncols - 1) {
let off_i_j = self.offset(i, j);
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 normalizer: N = Cast::from(1.0f64 / Cast::from(self.nrows));
for i in range(0u, self.nrows) {
for j in range(0u, self.ncols) {
for i in (0us .. self.nrows) {
for j in (0us .. self.ncols) {
unsafe {
let acc = res.unsafe_at(j) + self.unsafe_at((i, j)) * normalizer;
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();
// FIXME: use the rows iterator when available
for i in range(0u, self.nrows) {
for j in range(0u, self.ncols) {
for i in (0us .. self.nrows) {
for j in (0us .. self.ncols) {
unsafe {
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> {
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!(row_start < row_end);
assert!(row_end <= self.nrows);
// we can init from slice thanks to the matrix being column major
let start= self.offset(row_start, col_id);
let stop = self.offset(row_end, col_id);
let slice = DVec::from_slice(
row_end - row_start, self.mij.slice(start, stop));
let slice = DVec::from_slice(row_end - row_start, &self.mij[start .. stop]);
slice
}
}
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!(col_start < col_end);
assert!(col_end <= self.ncols);
let mut slice : DVec<N> = unsafe {
DVec::new_uninitialized(self.nrows)
};
let mut slice_idx = 0u;
for col_id in range(col_start, col_end) {
let mut slice_idx = 0us;
for col_id in (col_start .. col_end) {
unsafe {
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);
for i in range(0, smallest_dim) {
for i in (0 .. smallest_dim) {
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);
for i in range(0, smallest_dim) {
for i in (0 .. smallest_dim) {
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> {
fn fmt(&self, form:&mut Formatter) -> Result {
for i in range(0u, self.nrows()) {
for j in range(0u, self.ncols()) {
for i in (0us .. self.nrows()) {
for j in (0us .. self.ncols()) {
let _ = write!(form, "{} ", self[(i, j)]);
}
let _ = write!(form, "\n");

View File

@ -22,7 +22,7 @@ pub struct DVec<N> {
impl<N> DVec<N> {
/// Creates an uninitialized vec.
#[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);
vec.set_len(dim);
@ -35,7 +35,7 @@ impl<N> DVec<N> {
impl<N: Clone> DVec<N> {
/// Builds a vector filled with a constant.
#[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() }
}
@ -43,11 +43,11 @@ impl<N: Clone> DVec<N> {
///
/// The vector must have at least `dim` elements.
#[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());
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> {
/// Builds a vector filled with the result of a function.
#[inline(always)]
pub fn from_fn<F: FnMut(uint) -> N>(dim: uint, mut f: F) -> DVec<N> {
DVec { at: range(0, dim).map(|i| f(i)).collect() }
pub fn from_fn<F: FnMut(usize) -> N>(dim: usize, mut f: F) -> DVec<N> {
DVec { at: (0 .. dim).map(|i| f(i)).collect() }
}
#[inline]
pub fn len(&self) -> uint {
pub fn len(&self) -> usize {
self.at.len()
}
}
@ -84,7 +84,7 @@ dvec_impl!(DVec);
/// Stack-allocated, dynamically sized vector with a maximum size of 1.
pub struct DVec1<N> {
at: [N; 1],
dim: uint
dim: usize
}
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.
pub struct DVec2<N> {
at: [N; 2],
dim: uint
dim: usize
}
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.
pub struct DVec3<N> {
at: [N; 3],
dim: uint
dim: usize
}
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.
pub struct DVec4<N> {
at: [N; 4],
dim: uint
dim: usize
}
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.
pub struct DVec5<N> {
at: [N; 5],
dim: uint
dim: usize
}
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.
pub struct DVec6<N> {
at: [N; 6],
dim: uint
dim: usize
}
small_dvec_impl!(DVec6, 6, 0, 1, 2, 3, 4, 5);

View File

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

View File

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

View File

@ -60,13 +60,13 @@ macro_rules! at_fast_impl(
($t: ident, $dim: expr) => (
impl<N: Copy> $t<N> {
#[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)
.get_unchecked(i + j * $dim))
}
#[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)
.get_unchecked_mut(i + j * $dim)) = val
}
@ -154,7 +154,7 @@ macro_rules! mat_add_scalar_impl(
macro_rules! eye_impl(
($t: ident, $dim: expr, $($comp_diagN: ident),+) => (
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);
let mut eye: $t<N> = ::zero();
$(eye.$comp_diagN = ::one();)+
@ -247,7 +247,7 @@ macro_rules! dim_impl(
($t: ident, $dim: expr) => (
impl<N> Dim for $t<N> {
#[inline]
fn dim(_: Option<$t<N>>) -> uint {
fn dim(_: Option<$t<N>>) -> usize {
$dim
}
}
@ -256,30 +256,30 @@ macro_rules! dim_impl(
macro_rules! indexable_impl(
($t: ident, $dim: expr) => (
impl<N> Shape<(uint, uint)> for $t<N> {
impl<N> Shape<(usize, usize)> for $t<N> {
#[inline]
fn shape(&self) -> (uint, uint) {
fn shape(&self) -> (usize, usize) {
($dim, $dim)
}
}
impl<N: Copy> Indexable<(uint, uint), N> for $t<N> {
impl<N: Copy> Indexable<(usize, usize), N> for $t<N> {
#[inline]
fn at(&self, (i, j): (uint, uint)) -> N {
fn at(&self, (i, j): (usize, usize)) -> N {
unsafe {
mem::transmute::<&$t<N>, &[N; $dim * $dim]>(self)[i + j * $dim]
}
}
#[inline]
fn set(&mut self, (i, j): (uint, uint), val: N) {
fn set(&mut self, (i, j): (usize, usize), val: N) {
unsafe {
mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self)[i + j * $dim] = val
}
}
#[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 {
mem::transmute::<&mut $t<N>, &mut [N; $dim * $dim]>(self)
.swap(i1 + j1 * $dim, i2 + j2 * $dim)
@ -287,12 +287,12 @@ macro_rules! indexable_impl(
}
#[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))
}
#[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
}
}
@ -301,20 +301,20 @@ macro_rules! indexable_impl(
macro_rules! index_impl(
($t: ident, $dim: expr) => (
impl<N> Index<(uint, uint)> for $t<N> {
impl<N> Index<(usize, usize)> for $t<N> {
type Output = N;
fn index(&self, &(i, j): &(uint, uint)) -> &N {
fn index(&self, &(i, j): &(usize, usize)) -> &N {
unsafe {
&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;
fn index_mut(&mut self, &(i, j): &(uint, uint)) -> &mut N {
fn index_mut(&mut self, &(i, j): &(usize, usize)) -> &mut N {
unsafe {
&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(
($t: ident, $tv: ident, $slice: ident, $dim: expr) => (
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);
$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) => (
impl<N: Copy + Zero> Row<$tv<N>> for $t<N> {
#[inline]
fn nrows(&self) -> uint {
fn nrows(&self) -> usize {
Dim::dim(None::<$t<N>>)
}
#[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() {
self.set((row, i), *e);
}
}
#[inline]
fn row(&self, row: uint) -> $tv<N> {
fn row(&self, row: usize) -> $tv<N> {
let mut res: $tv<N> = ::zero();
for (i, e) in res.iter_mut().enumerate() {
@ -367,7 +367,7 @@ macro_rules! row_impl(
macro_rules! row_slice_impl(
($t: ident, $tv: ident, $slice: ident, $dim: expr) => (
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);
$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) => (
impl<N: Copy + Zero> Col<$tv<N>> for $t<N> {
#[inline]
fn ncols(&self) -> uint {
fn ncols(&self) -> usize {
Dim::dim(None::<$t<N>>)
}
#[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() {
self.set((i, col), *e);
}
}
#[inline]
fn col(&self, col: uint) -> $tv<N> {
fn col(&self, col: usize) -> $tv<N> {
let mut res: $tv<N> = ::zero();
for (i, e) in res.iter_mut().enumerate() {
@ -419,7 +419,7 @@ macro_rules! diag_impl(
#[inline]
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)) }
}
}
@ -428,7 +428,7 @@ macro_rules! diag_impl(
fn diag(&self) -> $tv<N> {
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))) }
}
@ -447,12 +447,12 @@ macro_rules! mat_mul_mat_impl(
// careful! we need to comute other * self here (self is the rhs).
let mut res: $t<N> = ::zero();
for i in range(0u, $dim) {
for j in range(0u, $dim) {
for i in (0us .. $dim) {
for j in (0us .. $dim) {
let mut acc: N = ::zero();
unsafe {
for k in range(0u, $dim) {
for k in (0us .. $dim) {
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> {
let mut res : $v<N> = $zero();
for i in range(0u, $dim) {
for j in range(0u, $dim) {
for i in (0us .. $dim) {
for j in (0us .. $dim) {
unsafe {
let val = res.at_fast(i) + self.at_fast(j) * right.at_fast((j, i));
res.set_fast(i, val)
@ -500,8 +500,8 @@ macro_rules! mat_mul_vec_impl(
fn mul(self, right: $v<N>) -> $v<N> {
let mut res : $v<N> = $zero();
for i in range(0u, $dim) {
for j in range(0u, $dim) {
for i in (0us .. $dim) {
for j in (0us .. $dim) {
unsafe {
let val = res.at_fast(i) + self.at_fast((i, j)) * right.at_fast(j);
res.set_fast(i, val)
@ -546,7 +546,7 @@ macro_rules! inv_impl(
let mut res: $t<N> = ::one();
// 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
// FIXME: would it be worth it to spend some more time searching for the
// max instead?
@ -567,7 +567,7 @@ macro_rules! inv_impl(
// swap pivot line
if n0 != k {
for j in range(0u, $dim) {
for j in (0us .. $dim) {
self.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));
for j in range(k, $dim) {
for j in (k .. $dim) {
let selfval = self.at((k, j)) / pivot;
self.set((k, j), selfval);
}
for j in range(0u, $dim) {
for j in (0us .. $dim) {
let resval = res.at((k, j)) / pivot;
res.set((k, j), resval);
}
for l in range(0u, $dim) {
for l in (0us .. $dim) {
if 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;
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;
res.set((l, j), resval);
}
@ -623,8 +623,8 @@ macro_rules! transpose_impl(
#[inline]
fn transpose(&mut self) {
for i in range(1u, $dim) {
for j in range(0u, i) {
for i in (1us .. $dim) {
for j in (0us .. i) {
self.swap((i, j), (j, i))
}
}
@ -668,8 +668,8 @@ macro_rules! to_homogeneous_impl(
fn to_homogeneous(&self) -> $t2<N> {
let mut res: $t2<N> = ::one();
for i in range(0u, $dim) {
for j in range(0u, $dim) {
for i in (0us .. $dim) {
for j in (0us .. $dim) {
res.set((i, j), self.at((i, j)))
}
}
@ -687,8 +687,8 @@ macro_rules! from_homogeneous_impl(
fn from(m: &$t2<N>) -> $t<N> {
let mut res: $t<N> = ::one();
for i in range(0u, $dim2) {
for j in range(0u, $dim2) {
for i in (0us .. $dim2) {
for j in (0us .. $dim2) {
res.set((i, j), m.at((i, j)))
}
}
@ -708,8 +708,8 @@ macro_rules! outer_impl(
#[inline]
fn outer(&self, other: &$t<N>) -> $m<N> {
let mut res: $m<N> = ::zero();
for i in range(0u, Dim::dim(None::<$t<N>>)) {
for j in range(0u, Dim::dim(None::<$t<N>>)) {
for i in (0us .. Dim::dim(None::<$t<N>>)) {
for j in (0us .. Dim::dim(None::<$t<N>>)) {
res.set((i, j), self.at(i) * other.at(j))
}
}
@ -723,7 +723,7 @@ macro_rules! eigen_qr_impl(
($t: ident, $v: ident) => (
impl<N> EigenQR<N, $v<N>> for $t<N>
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)
}
}

View File

@ -41,7 +41,7 @@ pub struct Pnt1<N> {
new_impl!(Pnt1, x);
orig_impl!(Pnt1, x);
ord_impl!(Pnt1, x);
ord_impl!(Pnt1, x,);
scalar_mul_impl!(Pnt1, x);
scalar_div_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>
Rand for Rot3<N> {
impl<N: Clone + Rand + BaseFloat> Rand for Rot3<N> {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> Rot3<N> {
Rot3::new(rng.gen())

View File

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

View File

@ -132,12 +132,12 @@ impl<N: BaseNum> Det<N> for Mat3<N> {
impl<N: Copy> Row<Vec3<N>> for Mat3<N> {
#[inline]
fn nrows(&self) -> uint {
fn nrows(&self) -> usize {
3
}
#[inline]
fn row(&self, i: uint) -> Vec3<N> {
fn row(&self, i: usize) -> Vec3<N> {
match i {
0 => Vec3::new(self.m11, self.m12, self.m13),
1 => Vec3::new(self.m21, self.m22, self.m23),
@ -147,7 +147,7 @@ impl<N: Copy> Row<Vec3<N>> for Mat3<N> {
}
#[inline]
fn set_row(&mut self, i: uint, r: Vec3<N>) {
fn set_row(&mut self, i: usize, r: Vec3<N>) {
match i {
0 => {
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> {
#[inline]
fn ncols(&self) -> uint {
fn ncols(&self) -> usize {
3
}
#[inline]
fn col(&self, i: uint) -> Vec3<N> {
fn col(&self, i: usize) -> Vec3<N> {
match i {
0 => Vec3::new(self.m11, self.m21, self.m31),
1 => Vec3::new(self.m12, self.m22, self.m32),
@ -187,7 +187,7 @@ impl<N: Copy> Col<Vec3<N>> for Mat3<N> {
}
#[inline]
fn set_col(&mut self, i: uint, r: Vec3<N>) {
fn set_col(&mut self, i: usize, r: Vec3<N>) {
match i {
0 => {
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!(u16, u16Cast);
primitive_double_dispatch_cast_decl_trait!(u8, u8Cast);
primitive_double_dispatch_cast_decl_trait!(int, intCast);
primitive_double_dispatch_cast_decl_trait!(uint, uintCast);
primitive_double_dispatch_cast_decl_trait!(isize, isizeCast);
primitive_double_dispatch_cast_decl_trait!(usize, usizeCast);
primitive_cast_redispatch_impl!(f64, f64Cast);
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!(u16, u16Cast);
primitive_cast_redispatch_impl!(u8, u8Cast);
primitive_cast_redispatch_impl!(int, intCast);
primitive_cast_redispatch_impl!(uint, uintCast);
primitive_cast_redispatch_impl!(isize, isizeCast);
primitive_cast_redispatch_impl!(usize, usizeCast);
primitive_double_dispatch_cast_impl!(f64, f64, 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, u16, f64Cast);
primitive_double_dispatch_cast_impl!(f64, u8, f64Cast);
primitive_double_dispatch_cast_impl!(f64, int, f64Cast);
primitive_double_dispatch_cast_impl!(f64, uint, f64Cast);
primitive_double_dispatch_cast_impl!(f64, isize, f64Cast);
primitive_double_dispatch_cast_impl!(f64, usize, f64Cast);
primitive_double_dispatch_cast_impl!(f32, f64, 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, u16, f32Cast);
primitive_double_dispatch_cast_impl!(f32, u8, f32Cast);
primitive_double_dispatch_cast_impl!(f32, int, f32Cast);
primitive_double_dispatch_cast_impl!(f32, uint, f32Cast);
primitive_double_dispatch_cast_impl!(f32, isize, f32Cast);
primitive_double_dispatch_cast_impl!(f32, usize, f32Cast);
primitive_double_dispatch_cast_impl!(i64, f64, 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, u16, i64Cast);
primitive_double_dispatch_cast_impl!(i64, u8, i64Cast);
primitive_double_dispatch_cast_impl!(i64, int, i64Cast);
primitive_double_dispatch_cast_impl!(i64, uint, i64Cast);
primitive_double_dispatch_cast_impl!(i64, isize, i64Cast);
primitive_double_dispatch_cast_impl!(i64, usize, i64Cast);
primitive_double_dispatch_cast_impl!(i32, f64, 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, u16, i32Cast);
primitive_double_dispatch_cast_impl!(i32, u8, i32Cast);
primitive_double_dispatch_cast_impl!(i32, int, i32Cast);
primitive_double_dispatch_cast_impl!(i32, uint, i32Cast);
primitive_double_dispatch_cast_impl!(i32, isize, i32Cast);
primitive_double_dispatch_cast_impl!(i32, usize, i32Cast);
primitive_double_dispatch_cast_impl!(i16, f64, 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, u16, i16Cast);
primitive_double_dispatch_cast_impl!(i16, u8, i16Cast);
primitive_double_dispatch_cast_impl!(i16, int, i16Cast);
primitive_double_dispatch_cast_impl!(i16, uint, i16Cast);
primitive_double_dispatch_cast_impl!(i16, isize, i16Cast);
primitive_double_dispatch_cast_impl!(i16, usize, i16Cast);
primitive_double_dispatch_cast_impl!(i8, f64, 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, u16, i8Cast);
primitive_double_dispatch_cast_impl!(i8, u8, i8Cast);
primitive_double_dispatch_cast_impl!(i8, int, i8Cast);
primitive_double_dispatch_cast_impl!(i8, uint, i8Cast);
primitive_double_dispatch_cast_impl!(i8, isize, i8Cast);
primitive_double_dispatch_cast_impl!(i8, usize, i8Cast);
primitive_double_dispatch_cast_impl!(u64, f64, 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, u16, u64Cast);
primitive_double_dispatch_cast_impl!(u64, u8, u64Cast);
primitive_double_dispatch_cast_impl!(u64, int, u64Cast);
primitive_double_dispatch_cast_impl!(u64, uint, u64Cast);
primitive_double_dispatch_cast_impl!(u64, isize, u64Cast);
primitive_double_dispatch_cast_impl!(u64, usize, u64Cast);
primitive_double_dispatch_cast_impl!(u32, f64, 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, u16, u32Cast);
primitive_double_dispatch_cast_impl!(u32, u8, u32Cast);
primitive_double_dispatch_cast_impl!(u32, int, u32Cast);
primitive_double_dispatch_cast_impl!(u32, uint, u32Cast);
primitive_double_dispatch_cast_impl!(u32, isize, u32Cast);
primitive_double_dispatch_cast_impl!(u32, usize, u32Cast);
primitive_double_dispatch_cast_impl!(u16, f64, 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, u16, u16Cast);
primitive_double_dispatch_cast_impl!(u16, u8, u16Cast);
primitive_double_dispatch_cast_impl!(u16, int, u16Cast);
primitive_double_dispatch_cast_impl!(u16, uint, u16Cast);
primitive_double_dispatch_cast_impl!(u16, isize, u16Cast);
primitive_double_dispatch_cast_impl!(u16, usize, u16Cast);
primitive_double_dispatch_cast_impl!(u8, f64, 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, u16, u8Cast);
primitive_double_dispatch_cast_impl!(u8, u8, u8Cast);
primitive_double_dispatch_cast_impl!(u8, int, u8Cast);
primitive_double_dispatch_cast_impl!(u8, uint, u8Cast);
primitive_double_dispatch_cast_impl!(u8, isize, u8Cast);
primitive_double_dispatch_cast_impl!(u8, usize, u8Cast);
primitive_double_dispatch_cast_impl!(uint, f64, uintCast);
primitive_double_dispatch_cast_impl!(uint, f32, uintCast);
primitive_double_dispatch_cast_impl!(uint, i64, uintCast);
primitive_double_dispatch_cast_impl!(uint, i32, uintCast);
primitive_double_dispatch_cast_impl!(uint, i16, uintCast);
primitive_double_dispatch_cast_impl!(uint, i8, uintCast);
primitive_double_dispatch_cast_impl!(uint, u64, uintCast);
primitive_double_dispatch_cast_impl!(uint, u32, uintCast);
primitive_double_dispatch_cast_impl!(uint, u16, uintCast);
primitive_double_dispatch_cast_impl!(uint, u8, uintCast);
primitive_double_dispatch_cast_impl!(uint, int, uintCast);
primitive_double_dispatch_cast_impl!(uint, uint, uintCast);
primitive_double_dispatch_cast_impl!(usize, f64, usizeCast);
primitive_double_dispatch_cast_impl!(usize, f32, usizeCast);
primitive_double_dispatch_cast_impl!(usize, i64, usizeCast);
primitive_double_dispatch_cast_impl!(usize, i32, usizeCast);
primitive_double_dispatch_cast_impl!(usize, i16, usizeCast);
primitive_double_dispatch_cast_impl!(usize, i8, usizeCast);
primitive_double_dispatch_cast_impl!(usize, u64, usizeCast);
primitive_double_dispatch_cast_impl!(usize, u32, usizeCast);
primitive_double_dispatch_cast_impl!(usize, u16, usizeCast);
primitive_double_dispatch_cast_impl!(usize, u8, usizeCast);
primitive_double_dispatch_cast_impl!(usize, isize, usizeCast);
primitive_double_dispatch_cast_impl!(usize, usize, usizeCast);
primitive_double_dispatch_cast_impl!(int, f64, intCast);
primitive_double_dispatch_cast_impl!(int, f32, intCast);
primitive_double_dispatch_cast_impl!(int, i64, intCast);
primitive_double_dispatch_cast_impl!(int, i32, intCast);
primitive_double_dispatch_cast_impl!(int, i16, intCast);
primitive_double_dispatch_cast_impl!(int, i8, intCast);
primitive_double_dispatch_cast_impl!(int, u64, intCast);
primitive_double_dispatch_cast_impl!(int, u32, intCast);
primitive_double_dispatch_cast_impl!(int, u16, intCast);
primitive_double_dispatch_cast_impl!(int, u8, intCast);
primitive_double_dispatch_cast_impl!(int, int, intCast);
primitive_double_dispatch_cast_impl!(int, uint, intCast);
primitive_double_dispatch_cast_impl!(isize, f64, isizeCast);
primitive_double_dispatch_cast_impl!(isize, f32, isizeCast);
primitive_double_dispatch_cast_impl!(isize, i64, isizeCast);
primitive_double_dispatch_cast_impl!(isize, i32, isizeCast);
primitive_double_dispatch_cast_impl!(isize, i16, isizeCast);
primitive_double_dispatch_cast_impl!(isize, i8, isizeCast);
primitive_double_dispatch_cast_impl!(isize, u64, isizeCast);
primitive_double_dispatch_cast_impl!(isize, u32, isizeCast);
primitive_double_dispatch_cast_impl!(isize, u16, isizeCast);
primitive_double_dispatch_cast_impl!(isize, u8, isizeCast);
primitive_double_dispatch_cast_impl!(isize, isize, isizeCast);
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
impl<N: Copy> Row<Vec1<N>> for Vec2<N> {
#[inline]
fn nrows(&self) -> uint {
fn nrows(&self) -> usize {
2
}
#[inline]
fn row(&self, i: uint) -> Vec1<N> {
fn row(&self, i: usize) -> Vec1<N> {
match i {
0 => Vec1::new(self.x),
1 => Vec1::new(self.y),
@ -62,7 +62,7 @@ impl<N: Copy> Row<Vec1<N>> for Vec2<N> {
}
#[inline]
fn set_row(&mut self, i: uint, r: Vec1<N>) {
fn set_row(&mut self, i: usize, r: Vec1<N>) {
match i {
0 => self.x = 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) { }
#[inline]
fn canonical_basis_element(i: uint) -> Option<Vec1<N>> {
fn canonical_basis_element(i: usize) -> Option<Vec1<N>> {
if i == 0 {
Some(Vec1::new(::one()))
}
@ -105,7 +105,7 @@ impl<N: Copy + One + Zero + Neg<Output = N>> Basis for Vec2<N> {
}
#[inline]
fn canonical_basis_element(i: uint) -> Option<Vec2<N>> {
fn canonical_basis_element(i: usize) -> Option<Vec2<N>> {
if i == 0 {
Some(Vec2::new(::one(), ::zero()))
}
@ -141,7 +141,7 @@ impl<N: BaseFloat> Basis for Vec3<N> {
}
#[inline]
fn canonical_basis_element(i: uint) -> Option<Vec3<N>> {
fn canonical_basis_element(i: usize) -> Option<Vec3<N>> {
if i == 0 {
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;
#[inline]
fn index(&self, _: &uint) -> &N {
fn index(&self, _: &usize) -> &N {
panic!("Canot index a Vec0.")
}
}
impl<N> IndexMut<uint> for vec::Vec0<N> {
impl<N> IndexMut<usize> for vec::Vec0<N> {
type Output = N;
#[inline]
fn index_mut(&mut self, _: &uint) -> &mut N {
fn index_mut(&mut self, _: &usize) -> &mut N {
panic!("Canot index a Vec0.")
}
}
impl<N> Shape<uint> for vec::Vec0<N> {
impl<N> Shape<usize> for vec::Vec0<N> {
#[inline]
fn shape(&self) -> uint {
fn shape(&self) -> usize {
0
}
}
impl<N> Indexable<uint, N> for vec::Vec0<N> {
impl<N> Indexable<usize, N> for vec::Vec0<N> {
#[inline]
fn at(&self, _: uint) -> N {
fn at(&self, _: usize) -> N {
panic!("Cannot index a Vec0.")
}
#[inline]
fn set(&mut self, _: uint, _: N) {
fn set(&mut self, _: usize, _: N) {
}
#[inline]
fn swap(&mut self, _: uint, _: uint) {
fn swap(&mut self, _: usize, _: usize) {
}
#[inline]
unsafe fn unsafe_at(&self, _: uint) -> N {
unsafe fn unsafe_at(&self, _: usize) -> N {
panic!("Cannot index a Vec0.")
}
#[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> {
#[inline]
fn dim(_: Option<vec::Vec0<N>>) -> uint {
fn dim(_: Option<vec::Vec0<N>>) -> usize {
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) { }
#[inline(always)]
fn canonical_basis_element(_: uint) -> Option<vec::Vec0<N>> {
fn canonical_basis_element(_: usize) -> Option<vec::Vec0<N>> {
None
}
}

View File

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

View File

@ -62,13 +62,13 @@ macro_rules! at_fast_impl(
impl<N: Copy> $t<N> {
/// Unsafe read access to a vector element by index.
#[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))
}
/// Unsafe write access to a vector element by index.
#[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
}
}
@ -78,74 +78,73 @@ macro_rules! at_fast_impl(
// FIXME: N should be bounded by Ord instead of BaseFloat…
// However, f32/f64 does not implement Ord…
macro_rules! ord_impl(
($t: ident, $($compN: ident),+) => (
($t: ident, $comp0: ident, $($compN: ident),*) => (
impl<N: BaseFloat + Copy> POrd for $t<N> {
#[inline]
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]
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]
#[allow(unused_mut)] // otherwise there will be a warning for is_eq or Vec1.
fn partial_cmp(&self, other: &$t<N>) -> POrdering {
let mut first = true;
let mut is_lt = false;
let mut is_eq = false;
let is_lt = self.$comp0 < other.$comp0;
let mut is_eq = self.$comp0 == other.$comp0;
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 {
return POrdering::NotComparable
}
)*
POrdering::PartialLess
}
else { // >=
$(
if self.$compN < other.$compN {
return POrdering::NotComparable
}
else if self.$compN > other.$compN {
is_eq = false;
}
}
)+
if is_lt {
POrdering::PartialLess
}
else if is_eq {
)*
if is_eq {
POrdering::PartialEqual
}
else {
POrdering::PartialGreater
}
}
}
#[inline]
fn partial_lt(&self, other: &$t<N>) -> bool {
$(self.$compN < other.$compN)&&+
self.$comp0 < other.$comp0 $(&& self.$compN < other.$compN)*
}
#[inline]
fn partial_le(&self, other: &$t<N>) -> bool {
$(self.$compN <= other.$compN)&&+
self.$comp0 <= other.$comp0 $(&& self.$compN <= other.$compN)*
}
#[inline]
fn partial_gt(&self, other: &$t<N>) -> bool {
$(self.$compN > other.$compN)&&+
self.$comp0 > other.$comp0 $(&& self.$compN > other.$compN)*
}
#[inline]
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(
($t: ident, $dim: expr) => (
impl<N> Shape<uint> for $t<N> {
impl<N> Shape<usize> for $t<N> {
#[inline]
fn shape(&self) -> uint {
fn shape(&self) -> usize {
$dim
}
}
impl<N: Copy> Indexable<uint, N> for $t<N> {
impl<N: Copy> Indexable<usize, N> for $t<N> {
#[inline]
fn at(&self, i: uint) -> N {
fn at(&self, i: usize) -> N {
unsafe {
mem::transmute::<&$t<N>, &[N; $dim]>(self)[i]
}
}
#[inline]
fn set(&mut self, i: uint, val: N) {
fn set(&mut self, i: usize, val: N) {
unsafe {
mem::transmute::<&mut $t<N>, &mut [N; $dim]>(self)[i] = val
}
}
#[inline]
fn swap(&mut self, i1: uint, i2: uint) {
fn swap(&mut self, i1: usize, i2: usize) {
unsafe {
mem::transmute::<&mut $t<N>, &mut [N; $dim]>(self).swap(i1, i2)
}
}
#[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))
}
#[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
}
}
@ -226,18 +225,18 @@ macro_rules! indexable_impl(
macro_rules! index_impl(
($t: ident) => (
impl<N> Index<uint> for $t<N> {
impl<N> Index<usize> for $t<N> {
type Output = N;
fn index(&self, i: &uint) -> &N {
fn index(&self, i: &usize) -> &N {
&self.as_array()[*i]
}
}
impl<N> IndexMut<uint> for $t<N> {
impl<N> IndexMut<usize> for $t<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]
}
}
@ -288,7 +287,7 @@ macro_rules! dim_impl(
($t: ident, $dim: expr) => (
impl<N> Dim for $t<N> {
#[inline]
fn dim(_: Option<$t<N>>) -> uint {
fn dim(_: Option<$t<N>>) -> usize {
$dim
}
}
@ -299,7 +298,7 @@ macro_rules! container_impl(
($t: ident) => (
impl<N> $t<N> {
#[inline]
pub fn len(&self) -> uint {
pub fn len(&self) -> usize {
Dim::dim(None::<$t<N>>)
}
}
@ -311,7 +310,7 @@ macro_rules! basis_impl(
impl<N: Copy + BaseFloat + ApproxEq<N>> Basis for $t<N> {
#[inline]
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 }
}
}
@ -322,7 +321,7 @@ macro_rules! basis_impl(
// orthogonalization algorithm
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();
unsafe {
@ -352,7 +351,7 @@ macro_rules! basis_impl(
}
#[inline]
fn canonical_basis_element(i: uint) -> Option<$t<N>> {
fn canonical_basis_element(i: usize) -> Option<$t<N>> {
if i < $dim {
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
if self.signum() != other.signum() { return false; }
// IEEE754 floats are in the same order as 2s complement ints
// so this trick (subtracting the ints) works.
// IEEE754 floats are in the same order as 2s complement isizes
// so this trick (subtracting the isizes) works.
let iself: i32 = unsafe { ::std::mem::transmute(*self) };
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.
pub trait EigenQR<N, V>: SquareMat<N, V> {
/// 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
@ -404,12 +404,12 @@ impl_absolute!(i8);
impl_absolute!(i16);
impl_absolute!(i32);
impl_absolute!(i64);
impl_absolute!(int);
impl_absolute!(isize);
impl_absolute_id!(u8);
impl_absolute_id!(u16);
impl_absolute_id!(u32);
impl_absolute_id!(u64);
impl_absolute_id!(uint);
impl_absolute_id!(usize);
macro_rules! impl_axpy(
($n: ty) => {
@ -428,9 +428,9 @@ impl_axpy!(i8);
impl_axpy!(i16);
impl_axpy!(i32);
impl_axpy!(i64);
impl_axpy!(int);
impl_axpy!(isize);
impl_axpy!(u8);
impl_axpy!(u16);
impl_axpy!(u32);
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::geometry::{Dot, Norm, Orig};
/// Basic integral numeric trait.
/// Basic isizeegral numeric trait.
pub trait BaseNum: Copy + Zero + One +
Add<Self, Output = Self> + Sub<Self, Output = Self> +
Mul<Self, Output = Self> + Div<Self, Output = Self> +
@ -60,10 +60,10 @@ pub trait Cast<T> {
/// Trait of matrices.
///
/// 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
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.
@ -78,7 +78,7 @@ impl<N, V, M> SquareMat<N, V> for M
/// Trait for constructing the identity matrix
pub trait Eye {
/// Return the identity matrix of specified dimension
fn new_identity(dim: uint) -> Self;
fn new_identity(dim: usize) -> Self;
}
/// Additive identity.
@ -115,17 +115,17 @@ pub trait Basis {
fn orthonormal_subspace_basis<F: FnMut(Self) -> bool>(&Self, F);
/// 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.
pub trait Row<R> {
/// The number of column of `self`.
fn nrows(&self) -> uint;
fn nrows(&self) -> usize;
/// 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`.
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
// a lot of operations.
@ -134,13 +134,13 @@ pub trait Row<R> {
/// Trait to access columns of a matrix or vector.
pub trait Col<C> {
/// The number of column of this matrix or vector.
fn ncols(&self) -> uint;
fn ncols(&self) -> usize;
/// 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`.
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
// a lot of operations.
@ -149,19 +149,19 @@ pub trait Col<C> {
/// Trait to access part of a column of a matrix
pub trait ColSlice<C> {
/// 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
pub trait RowSlice<R> {
/// 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.
pub trait Dim {
/// 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.
@ -241,7 +241,7 @@ pub trait NumVec<N>: Dim +
Sub<Self, Output = Self> + Add<Self, Output = Self> +
Mul<N, Output = Self> + Div<N, Output = Self> +
Neg<Output = Self> +
Index<uint, Output = N> +
Index<usize, Output = N> +
Zero + PartialEq + Dot<N> + Axpy<N> {
}
@ -281,7 +281,7 @@ pub trait NumPnt<N, V>:
Mul<N, Output = Self> +
Div<N, 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.
@ -338,12 +338,12 @@ impl_zero_one!(i8, 0, 1);
impl_zero_one!(i16, 0, 1);
impl_zero_one!(i32, 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!(u16, 0, 1);
impl_zero_one!(u32, 0, 1);
impl_zero_one!(u64, 0, 1);
impl_zero_one!(uint, 0, 1);
impl_zero_one!(usize, 0, 1);
// 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!(i32, 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!(u16, 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!(uint, Int::min_value(), Int::max_value());
impl_bounded!(usize, Int::min_value(), Int::max_value());
// 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(
($t: ty) => (
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let randmat : $t = random();
match na::inv(&randmat) {
@ -19,7 +19,7 @@ macro_rules! test_inv_mat_impl(
macro_rules! test_transpose_mat_impl(
($t: ty) => (
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let randmat : $t = random();
assert!(na::transpose(&na::transpose(&randmat)) == randmat);
@ -29,7 +29,7 @@ macro_rules! test_transpose_mat_impl(
macro_rules! test_qr_impl(
($t: ty) => (
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let randmat : $t = random();
let (q, r) = na::qr(&randmat);
@ -43,7 +43,7 @@ macro_rules! test_qr_impl(
// NOTE: deactivated untile we get a better convergence rate.
// macro_rules! test_eigen_qr_impl(
// ($t: ty) => {
// for _ in range(0u, 10000) {
// for _ in (0us .. 10000) {
// let randmat : $t = random();
// // Make it symetric so that we can recompose the matrix to test at the end.
// let randmat = na::transpose(&randmat) * randmat;
@ -125,7 +125,7 @@ fn test_inv_mat6() {
#[test]
fn test_rotation2() {
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let randmat: na::Rot2<f64> = na::one();
let ang = Vec1::new(na::abs(&random::<f64>()) % BaseFloat::pi());
@ -142,7 +142,7 @@ fn test_index_mat2() {
#[test]
fn test_inv_rotation3() {
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let randmat: Rot3<f64> = na::one();
let dir: Vec3<f64> = random();
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.
#[test]
fn test_qr() {
for _ in range(0u, 10) {
let dim1: uint = random();
let dim2: uint = random();
for _ in (0us .. 10) {
let dim1: usize = random();
let dim2: usize = random();
let rows = min(40, max(dim1, dim2));
let cols = min(40, min(dim1, dim2));
let randmat: DMat<f64> = DMat::new_random(rows, cols);
@ -327,8 +327,8 @@ fn test_qr_mat6() {
#[test]
fn test_from_fn() {
let actual: DMat<uint> = DMat::from_fn(3, 4, |i, j| 10 * i + j);
let expected: DMat<uint> = DMat::from_row_vec(3, 4,
let actual: DMat<usize> = DMat::from_fn(3, 4, |i, j| 10 * i + j);
let expected: DMat<usize> = DMat::from_row_vec(3, 4,
&[ 0_0, 0_1, 0_2, 0_3,
1_0, 1_1, 1_2, 1_3,
2_0, 2_1, 2_2, 2_3 ]);

View File

@ -5,7 +5,7 @@ use std::rand::random;
#[test]
fn test_quat_as_mat() {
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let axis_angle: Vec3<f64> = random();
assert!(na::approx_eq(&UnitQuat::new(axis_angle).to_rot(), &Rot3::new(axis_angle)))
@ -14,7 +14,7 @@ fn test_quat_as_mat() {
#[test]
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 vec: Vec3<f64> = random();
let pnt: Pnt3<f64> = random();
@ -31,7 +31,7 @@ fn test_quat_mul_vec_or_pnt_as_mat() {
#[test]
fn test_quat_div_quat() {
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let axis_angle1: Vec3<f64> = random();
let axis_angle2: Vec3<f64> = random();
@ -47,7 +47,7 @@ fn test_quat_div_quat() {
#[test]
fn test_quat_to_axis_angle() {
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let axis_angle: Vec3<f64> = random();
let q = UnitQuat::new(axis_angle);
@ -59,7 +59,7 @@ fn test_quat_to_axis_angle() {
#[test]
fn test_quat_euler_angles() {
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let angles: Vec3<f64> = random();
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(
($t: ty, $n: ty) => (
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let v: $t = random();
let mut mv: $t = v.clone();
let n: $n = random();
@ -23,7 +23,7 @@ macro_rules! test_iterator_impl(
macro_rules! test_commut_dot_impl(
($t: ty) => (
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let v1 : $t = random();
let v2 : $t = random();
@ -34,7 +34,7 @@ macro_rules! test_commut_dot_impl(
macro_rules! test_scalar_op_impl(
($t: ty, $n: ty) => (
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let v1 : $t = random();
let n : $n = random();
@ -57,7 +57,7 @@ macro_rules! test_scalar_op_impl(
macro_rules! test_basis_impl(
($t: ty) => (
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
na::canonical_basis(|e1: $t| {
na::canonical_basis(|e2: $t| {
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(
($t: ty) => (
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let v : $t = random();
let v1 = na::normalize(&v);
@ -99,7 +99,7 @@ macro_rules! test_subspace_basis_impl(
#[test]
fn test_cross_vec3() {
for _ in range(0u, 10000) {
for _ in (0us .. 10000) {
let v1 : Vec3<f64> = random();
let v2 : Vec3<f64> = random();
let v3 : Vec3<f64> = na::cross(&v1, &v2);