diff --git a/benches/common/macros.rs b/benches/common/macros.rs index 2918f428..39eb7118 100644 --- a/benches/common/macros.rs +++ b/benches/common/macros.rs @@ -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(|| { diff --git a/benches/dmat.rs b/benches/dmat.rs index bd1468f8..96b07324 100644 --- a/benches/dmat.rs +++ b/benches/dmat.rs @@ -11,7 +11,7 @@ macro_rules! bench_mul_dmat( let a: DMat = DMat::new_random($nrows, $ncols); let mut b: DMat = 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 = DMat::new_random($nrows, $ncols); let mut v : DVec = DVec::new_random($ncols); - for _ in range(0u, 1000) { + for _ in (0us .. 1000) { // XXX: the clone here is highly undesirable! v = m.clone() * v } diff --git a/src/lib.rs b/src/lib.rs index 20a51261..fb1af57b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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>(observations: &M) -> N { */ /// Computes the eigenvalues and eigenvectors of a square matrix usin the QR algorithm. #[inline(always)] -pub fn eigen_qr>(m: &M, eps: &N, niter: uint) -> (M, V) { +pub fn eigen_qr>(m: &M, eps: &N, niter: usize) -> (M, V) { EigenQR::eigen_qr(m, eps, niter) } @@ -852,7 +853,7 @@ pub fn eigen_qr>(m: &M, eps: &N, niter: uint) -> (M, V) { */ /// Construct the identity matrix for a given dimension #[inline(always)] -pub fn new_identity(dim: uint) -> M { +pub fn new_identity(dim: usize) -> M { Eye::new_identity(dim) } @@ -874,7 +875,7 @@ pub fn orthonormal_subspace_basis bool>(v: &V, f: F) { /// Gets the (0-based) i-th element of the canonical basis of V. #[inline] -pub fn canonical_basis_element(i: uint) -> Option { +pub fn canonical_basis_element(i: usize) -> Option { Basis::canonical_basis_element(i) } @@ -902,7 +903,7 @@ pub fn diag, V>(m: &M) -> V { /// /// Same as `Dim::dim::(None::)`. #[inline(always)] -pub fn dim() -> uint { +pub fn dim() -> usize { Dim::dim(None::) } diff --git a/src/linalg/decompositions.rs b/src/linalg/decompositions.rs index 3b60d436..b4379ee0 100644 --- a/src/linalg/decompositions.rs +++ b/src/linalg/decompositions.rs @@ -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(dim: uint, start: uint, vec: V) -> M +pub fn householder_matrix(dim: usize, start: usize, vec: V) -> M where N: BaseFloat, - M: Eye + Indexable<(uint, uint), N>, - V: Indexable { + M: Eye + Indexable<(usize, usize), N>, + V: Indexable { let mut qk : M = Eye::new_identity(dim); let subdim = vec.shape(); @@ -22,8 +22,8 @@ pub fn householder_matrix(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(dim: uint, start: uint, vec: V) -> M /// * `m` - matrix to decompose pub fn qr(m: &M) -> (M, M) where N: BaseFloat, - V: Indexable + Norm, - M: Copy + Eye + ColSlice + Transpose + Indexable<(uint, uint), N> + + V: Indexable + Norm, + M: Copy + Eye + ColSlice + Transpose + Indexable<(usize, usize), N> + Mul { let (rows, cols) = m.shape(); assert!(rows >= cols); @@ -50,7 +50,7 @@ pub fn qr(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(m: &M) -> (M, M) } /// Eigendecomposition of a square matrix using the qr algorithm. -pub fn eigen_qr(m: &M, eps: &N, niter: uint) -> (M, V) +pub fn eigen_qr(m: &M, eps: &N, niter: usize) -> (M, V) where N: BaseFloat, - VS: Indexable + Norm, - M: Indexable<(uint, uint), N> + SquareMat + Add + + VS: Indexable + Norm, + M: Indexable<(usize, usize), N> + SquareMat + Add + Sub + ColSlice + ApproxEq + Copy { let mut eigenvectors: M = ::one::(); 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::()) { - for i in range(0, j) { + for j in (0 .. ::dim::()) { + for i in (0 .. j) { if unsafe { eigenvalues.unsafe_at((i, j)) }.abs() >= *eps { stop = false; break; } } - for i in range(j + 1, ::dim::()) { + for i in (j + 1 .. ::dim::()) { if unsafe { eigenvalues.unsafe_at((i, j)) }.abs() >= *eps { stop = false; break; diff --git a/src/structs/dmat.rs b/src/structs/dmat.rs index 9b7cb5c0..44d7dd2d 100644 --- a/src/structs/dmat.rs +++ b/src/structs/dmat.rs @@ -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 { - nrows: uint, - ncols: uint, + nrows: usize, + ncols: usize, mij: Vec } impl DMat { /// Creates an uninitialized matrix. #[inline] - pub unsafe fn new_uninitialized(nrows: uint, ncols: uint) -> DMat { + pub unsafe fn new_uninitialized(nrows: usize, ncols: usize) -> DMat { let mut vec = Vec::with_capacity(nrows * ncols); vec.set_len(nrows * ncols); @@ -45,7 +45,7 @@ impl DMat { /// * `dim` - The dimension of the matrix. A `dim`-dimensional matrix contains `dim * dim` /// components. #[inline] - pub fn new_zeros(nrows: uint, ncols: uint) -> DMat { + pub fn new_zeros(nrows: usize, ncols: usize) -> DMat { DMat::from_elem(nrows, ncols, ::zero()) } @@ -66,7 +66,7 @@ impl DMat { impl DMat { /// Builds a matrix filled with random values. #[inline] - pub fn new_random(nrows: uint, ncols: uint) -> DMat { + pub fn new_random(nrows: usize, ncols: usize) -> DMat { DMat::from_fn(nrows, ncols, |_, _| rand::random()) } } @@ -74,7 +74,7 @@ impl DMat { impl DMat { /// Builds a matrix filled with a given constant. #[inline] - pub fn new_ones(nrows: uint, ncols: uint) -> DMat { + pub fn new_ones(nrows: usize, ncols: usize) -> DMat { DMat::from_elem(nrows, ncols, ::one()) } } @@ -82,7 +82,7 @@ impl DMat { impl DMat { /// Builds a matrix filled with a given constant. #[inline] - pub fn from_elem(nrows: uint, ncols: uint, val: N) -> DMat { + pub fn from_elem(nrows: usize, ncols: usize, val: N) -> DMat { DMat { nrows: nrows, ncols: ncols, @@ -97,7 +97,7 @@ impl DMat { /// /// The vector must have at least `nrows * ncols` elements. #[inline] - pub fn from_row_vec(nrows: uint, ncols: uint, vec: &[N]) -> DMat { + pub fn from_row_vec(nrows: usize, ncols: usize, vec: &[N]) -> DMat { let mut res = DMat::from_col_vec(ncols, nrows, vec); // we transpose because the buffer is row_major @@ -113,7 +113,7 @@ impl DMat { /// /// The vector must have at least `nrows * ncols` elements. #[inline] - pub fn from_col_vec(nrows: uint, ncols: uint, vec: &[N]) -> DMat { + pub fn from_col_vec(nrows: usize, ncols: usize, vec: &[N]) -> DMat { assert!(nrows * ncols == vec.len()); DMat { @@ -127,27 +127,27 @@ impl DMat { impl DMat { /// Builds a matrix filled with a given constant. #[inline(always)] - pub fn from_fn N>(nrows: uint, ncols: uint, mut f: F) -> DMat { + pub fn from_fn N>(nrows: usize, ncols: usize, mut f: F) -> DMat { 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 { @@ -157,14 +157,14 @@ impl DMat { /// 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 Eye for DMat { /// * `dim` - The dimension of the matrix. A `dim`-dimensional matrix contains `dim * dim` /// components. #[inline] - fn new_identity(dim: uint) -> DMat { + fn new_identity(dim: usize) -> DMat { 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 Eye for DMat { impl DMat { #[inline(always)] - fn offset(&self, i: uint, j: uint) -> uint { + fn offset(&self, i: usize, j: usize) -> usize { i + j * self.nrows } } -impl Indexable<(uint, uint), N> for DMat { +impl Indexable<(usize, usize), N> for DMat { /// 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 Indexable<(uint, uint), N> for DMat { /// 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 Indexable<(uint, uint), N> for DMat { /// # 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 Indexable<(uint, uint), N> for DMat { /// 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 Indexable<(uint, uint), N> for DMat { } -impl Shape<(uint, uint)> for DMat { +impl Shape<(usize, usize)> for DMat { #[inline] - fn shape(&self) -> (uint, uint) { + fn shape(&self) -> (usize, usize) { (self.nrows, self.ncols) } } -impl Index<(uint, uint)> for DMat { +impl Index<(usize, usize)> for DMat { 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 IndexMut<(uint, uint)> for DMat { +impl IndexMut<(usize, usize)> for DMat { 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 + Add + Zero> Mul> 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 + Mul + Zero> Mul> for let mut res : DVec = 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 + Mul + Zero> Mul> for let mut res : DVec = 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 Inv for DMat { let mut res: DMat = 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 Inv for DMat { // 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 Inv for DMat { 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 Transpose for DMat { 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 Transpose for DMat { #[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 + Clone> Mean> for DMat { let mut res: DVec = 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 + Clone> Cov> for DMat { 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 + Clone> Cov> for DMat { } impl ColSlice> for DMat { - fn col_slice(&self, col_id :uint, row_start: uint, row_end: uint) -> DVec { + fn col_slice(&self, col_id :usize, row_start: usize, row_end: usize) -> DVec { 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 RowSlice> for DMat { - fn row_slice(&self, row_id :uint, col_start: uint, col_end: uint) -> DVec { + fn row_slice(&self, row_id :usize, col_start: usize, col_end: usize) -> DVec { assert!(row_id < self.nrows); assert!(col_start < col_end); assert!(col_end <= self.ncols); let mut slice : DVec = 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 Diag> for DMat { 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 Diag> for DMat { let mut diag: DVec = 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> ApproxEq for DMat { impl Show for DMat { 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"); diff --git a/src/structs/dvec.rs b/src/structs/dvec.rs index a8e8a5d8..36b78317 100644 --- a/src/structs/dvec.rs +++ b/src/structs/dvec.rs @@ -22,7 +22,7 @@ pub struct DVec { impl DVec { /// Creates an uninitialized vec. #[inline] - pub unsafe fn new_uninitialized(dim: uint) -> DVec { + pub unsafe fn new_uninitialized(dim: usize) -> DVec { let mut vec = Vec::with_capacity(dim); vec.set_len(dim); @@ -35,7 +35,7 @@ impl DVec { impl DVec { /// Builds a vector filled with a constant. #[inline] - pub fn from_elem(dim: uint, elem: N) -> DVec { + pub fn from_elem(dim: usize, elem: N) -> DVec { DVec { at: repeat(elem).take(dim).collect() } } @@ -43,11 +43,11 @@ impl DVec { /// /// The vector must have at least `dim` elements. #[inline] - pub fn from_slice(dim: uint, vec: &[N]) -> DVec { + pub fn from_slice(dim: usize, vec: &[N]) -> DVec { assert!(dim <= vec.len()); DVec { - at: vec.slice_to(dim).to_vec() + at: vec[.. dim].to_vec() } } } @@ -55,12 +55,12 @@ impl DVec { impl DVec { /// Builds a vector filled with the result of a function. #[inline(always)] - pub fn from_fn N>(dim: uint, mut f: F) -> DVec { - DVec { at: range(0, dim).map(|i| f(i)).collect() } + pub fn from_fn N>(dim: usize, mut f: F) -> DVec { + 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 { 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 { 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 { 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 { 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 { 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 { at: [N; 6], - dim: uint + dim: usize } small_dvec_impl!(DVec6, 6, 0, 1, 2, 3, 4, 5); diff --git a/src/structs/dvec_macros.rs b/src/structs/dvec_macros.rs index 3a5587c4..c64a8c4c 100644 --- a/src/structs/dvec_macros.rs +++ b/src/structs/dvec_macros.rs @@ -8,7 +8,7 @@ macro_rules! dvec_impl( /// # Arguments /// * `dim` - The dimension of the vector. #[inline] - pub fn new_zeros(dim: uint) -> $dvec { + pub fn new_zeros(dim: usize) -> $dvec { $dvec::from_elem(dim, ::zero()) } @@ -34,16 +34,16 @@ macro_rules! dvec_impl( } } - impl Shape for $dvec { + impl Shape for $dvec { #[inline] - fn shape(&self) -> uint { + fn shape(&self) -> usize { self.len() } } - impl Indexable for $dvec { + impl Indexable for $dvec { #[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 Index for $dvec { + impl Index for $dvec { type Output = N; - fn index(&self, i: &uint) -> &N { + fn index(&self, i: &usize) -> &N { &self.as_slice()[*i] } } - impl IndexMut for $dvec { + impl IndexMut for $dvec { 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 { + pub fn new_ones(dim: usize) -> $dvec { $dvec::from_elem(dim, ::one()) } } @@ -107,7 +107,7 @@ macro_rules! dvec_impl( impl $dvec { /// Builds a vector filled with random values. #[inline] - pub fn new_random(dim: uint) -> $dvec { + pub fn new_random(dim: usize) -> $dvec { $dvec::from_fn(dim, |&: _| rand::random()) } } @@ -130,7 +130,7 @@ macro_rules! dvec_impl( fn axpy(&mut self, a: &N, x: &$dvec) { 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> { + pub fn canonical_basis_with_dim(dim: usize) -> Vec<$dvec> { let mut res : Vec<$dvec> = Vec::new(); - for i in range(0u, dim) { + for i in (0us .. dim) { let mut basis_element : $dvec = $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> = Vec::new(); - for i in range(0u, dim) { + for i in (0us .. dim) { let mut basis_element : $dvec = $dvec::new_zeros(self.len()); basis_element.set(i, ::one()); @@ -276,7 +276,7 @@ macro_rules! dvec_impl( fn dot(&self, other: &$dvec) -> 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 $dvec { #[inline] - pub fn len(&self) -> uint { + pub fn len(&self) -> usize { self.dim } } @@ -440,7 +440,7 @@ macro_rules! small_dvec_from_impl ( impl $dvec { /// Builds a vector filled with a constant. #[inline] - pub fn from_elem(dim: uint, elem: N) -> $dvec { + pub fn from_elem(dim: usize, elem: N) -> $dvec { 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 { + pub fn from_slice(dim: usize, vec: &[N]) -> $dvec { assert!(dim <= vec.len() && dim <= $dim); // FIXME: not safe. @@ -481,12 +481,12 @@ macro_rules! small_dvec_from_impl ( impl $dvec { /// Builds a vector filled with the result of a function. #[inline(always)] - pub fn from_fn N>(dim: uint, mut f: F) -> $dvec { + pub fn from_fn N>(dim: usize, mut f: F) -> $dvec { assert!(dim <= $dim); let mut at: [N; $dim] = [ $( $zeros, )* ]; - for i in range(0, dim) { + for i in (0 .. dim) { at[i] = f(i); } diff --git a/src/structs/iso_macros.rs b/src/structs/iso_macros.rs index 89b64eb5..0bdfd74e 100644 --- a/src/structs/iso_macros.rs +++ b/src/structs/iso_macros.rs @@ -43,7 +43,7 @@ macro_rules! dim_impl( ($t: ident, $dim: expr) => ( impl Dim for $t { #[inline] - fn dim(_: Option<$t>) -> uint { + fn dim(_: Option<$t>) -> usize { $dim } } diff --git a/src/structs/mat_macros.rs b/src/structs/mat_macros.rs index a80fff78..6bf7386d 100644 --- a/src/structs/mat_macros.rs +++ b/src/structs/mat_macros.rs @@ -60,13 +60,13 @@ macro_rules! at_fast_impl( ($t: ident, $dim: expr) => ( impl $t { #[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; $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, &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 Eye for $t { - fn new_identity(dim: uint) -> $t { + fn new_identity(dim: usize) -> $t { assert!(dim == $dim); let mut eye: $t = ::zero(); $(eye.$comp_diagN = ::one();)+ @@ -247,7 +247,7 @@ macro_rules! dim_impl( ($t: ident, $dim: expr) => ( impl Dim for $t { #[inline] - fn dim(_: Option<$t>) -> uint { + fn dim(_: Option<$t>) -> usize { $dim } } @@ -256,30 +256,30 @@ macro_rules! dim_impl( macro_rules! indexable_impl( ($t: ident, $dim: expr) => ( - impl Shape<(uint, uint)> for $t { + impl Shape<(usize, usize)> for $t { #[inline] - fn shape(&self) -> (uint, uint) { + fn shape(&self) -> (usize, usize) { ($dim, $dim) } } - impl Indexable<(uint, uint), N> for $t { + impl Indexable<(usize, usize), N> for $t { #[inline] - fn at(&self, (i, j): (uint, uint)) -> N { + fn at(&self, (i, j): (usize, usize)) -> N { unsafe { mem::transmute::<&$t, &[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, &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, &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; $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, &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 Index<(uint, uint)> for $t { + impl Index<(usize, usize)> for $t { type Output = N; - fn index(&self, &(i, j): &(uint, uint)) -> &N { + fn index(&self, &(i, j): &(usize, usize)) -> &N { unsafe { &mem::transmute::<&$t, &mut [N; $dim * $dim]>(self)[i + j * $dim] } } } - impl IndexMut<(uint, uint)> for $t { + impl IndexMut<(usize, usize)> for $t { 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, &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 ColSlice<$slice> for $t { - fn col_slice(&self, cid: uint, rstart: uint, rend: uint) -> $slice { + fn col_slice(&self, cid: usize, rstart: usize, rend: usize) -> $slice { 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 Row<$tv> for $t { #[inline] - fn nrows(&self) -> uint { + fn nrows(&self) -> usize { Dim::dim(None::<$t>) } #[inline] - fn set_row(&mut self, row: uint, v: $tv) { + fn set_row(&mut self, row: usize, v: $tv) { for (i, e) in v.iter().enumerate() { self.set((row, i), *e); } } #[inline] - fn row(&self, row: uint) -> $tv { + fn row(&self, row: usize) -> $tv { let mut res: $tv = ::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 RowSlice<$slice> for $t { - fn row_slice(&self, rid: uint, cstart: uint, cend: uint) -> $slice { + fn row_slice(&self, rid: usize, cstart: usize, cend: usize) -> $slice { 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 Col<$tv> for $t { #[inline] - fn ncols(&self) -> uint { + fn ncols(&self) -> usize { Dim::dim(None::<$t>) } #[inline] - fn set_col(&mut self, col: uint, v: $tv) { + fn set_col(&mut self, col: usize, v: $tv) { for (i, e) in v.iter().enumerate() { self.set((i, col), *e); } } #[inline] - fn col(&self, col: uint) -> $tv { + fn col(&self, col: usize) -> $tv { let mut res: $tv = ::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) { - 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 { let mut diag: $tv = ::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 = ::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) -> $v { let mut res : $v = $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) -> $v { let mut res : $v = $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 = ::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 { let mut res: $t2 = ::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) -> $t { let mut res: $t = ::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) -> $m { let mut res: $m = ::zero(); - for i in range(0u, Dim::dim(None::<$t>)) { - for j in range(0u, Dim::dim(None::<$t>)) { + for i in (0us .. Dim::dim(None::<$t>)) { + for j in (0us .. Dim::dim(None::<$t>)) { res.set((i, j), self.at(i) * other.at(j)) } } @@ -723,7 +723,7 @@ macro_rules! eigen_qr_impl( ($t: ident, $v: ident) => ( impl EigenQR> for $t where N: BaseFloat + ApproxEq + Clone { - fn eigen_qr(&self, eps: &N, niter: uint) -> ($t, $v) { + fn eigen_qr(&self, eps: &N, niter: usize) -> ($t, $v) { linalg::eigen_qr(self, eps, niter) } } diff --git a/src/structs/pnt.rs b/src/structs/pnt.rs index 4995c954..cf9f2aee 100644 --- a/src/structs/pnt.rs +++ b/src/structs/pnt.rs @@ -41,7 +41,7 @@ pub struct Pnt1 { 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); diff --git a/src/structs/rot.rs b/src/structs/rot.rs index 7c507e2a..a87ce47c 100644 --- a/src/structs/rot.rs +++ b/src/structs/rot.rs @@ -270,8 +270,7 @@ Rotation> for Rot3 { } } -impl -Rand for Rot3 { +impl Rand for Rot3 { #[inline] fn rand(rng: &mut R) -> Rot3 { Rot3::new(rng.gen()) diff --git a/src/structs/rot_macros.rs b/src/structs/rot_macros.rs index c49c8ac2..8c2077af 100644 --- a/src/structs/rot_macros.rs +++ b/src/structs/rot_macros.rs @@ -71,7 +71,7 @@ macro_rules! dim_impl( ($t: ident, $dim: expr) => ( impl Dim for $t { #[inline] - fn dim(_: Option<$t>) -> uint { + fn dim(_: Option<$t>) -> usize { $dim } } @@ -193,16 +193,16 @@ macro_rules! row_impl( ($t: ident, $tv: ident) => ( impl Row<$tv> for $t { #[inline] - fn nrows(&self) -> uint { + fn nrows(&self) -> usize { self.submat.nrows() } #[inline] - fn row(&self, i: uint) -> $tv { + fn row(&self, i: usize) -> $tv { self.submat.row(i) } #[inline] - fn set_row(&mut self, i: uint, row: $tv) { + fn set_row(&mut self, i: usize, row: $tv) { self.submat.set_row(i, row); } } @@ -213,16 +213,16 @@ macro_rules! col_impl( ($t: ident, $tv: ident) => ( impl Col<$tv> for $t { #[inline] - fn ncols(&self) -> uint { + fn ncols(&self) -> usize { self.submat.ncols() } #[inline] - fn col(&self, i: uint) -> $tv { + fn col(&self, i: usize) -> $tv { self.submat.col(i) } #[inline] - fn set_col(&mut self, i: uint, col: $tv) { + fn set_col(&mut self, i: usize, col: $tv) { self.submat.set_col(i, col); } } @@ -231,10 +231,10 @@ macro_rules! col_impl( macro_rules! index_impl( ($t: ident) => ( - impl Index<(uint, uint)> for $t { + impl Index<(usize, usize)> for $t { type Output = N; - fn index(&self, i: &(uint, uint)) -> &N { + fn index(&self, i: &(usize, usize)) -> &N { &self.submat[*i] } } diff --git a/src/structs/spec/complex.rs b/src/structs/spec/complex.rs index 7a06d180..2855ab7e 100644 --- a/src/structs/spec/complex.rs +++ b/src/structs/spec/complex.rs @@ -45,7 +45,7 @@ impl Inv for Cmplx { impl Dim for Cmplx { #[inline] - fn dim(unsused_self: Option>) -> uint { + fn dim(unsused_self: Option>) -> usize { 2 } } diff --git a/src/structs/spec/mat.rs b/src/structs/spec/mat.rs index 96635906..000b2ba9 100644 --- a/src/structs/spec/mat.rs +++ b/src/structs/spec/mat.rs @@ -132,12 +132,12 @@ impl Det for Mat3 { impl Row> for Mat3 { #[inline] - fn nrows(&self) -> uint { + fn nrows(&self) -> usize { 3 } #[inline] - fn row(&self, i: uint) -> Vec3 { + fn row(&self, i: usize) -> Vec3 { 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 Row> for Mat3 { } #[inline] - fn set_row(&mut self, i: uint, r: Vec3) { + fn set_row(&mut self, i: usize, r: Vec3) { match i { 0 => { self.m11 = r.x; @@ -172,12 +172,12 @@ impl Row> for Mat3 { impl Col> for Mat3 { #[inline] - fn ncols(&self) -> uint { + fn ncols(&self) -> usize { 3 } #[inline] - fn col(&self, i: uint) -> Vec3 { + fn col(&self, i: usize) -> Vec3 { 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 Col> for Mat3 { } #[inline] - fn set_col(&mut self, i: uint, r: Vec3) { + fn set_col(&mut self, i: usize, r: Vec3) { match i { 0 => { self.m11 = r.x; diff --git a/src/structs/spec/primitives.rs b/src/structs/spec/primitives.rs index e32fb15c..de9e6195 100644 --- a/src/structs/spec/primitives.rs +++ b/src/structs/spec/primitives.rs @@ -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); diff --git a/src/structs/spec/vec.rs b/src/structs/spec/vec.rs index c1485536..adc04f6a 100644 --- a/src/structs/spec/vec.rs +++ b/src/structs/spec/vec.rs @@ -48,12 +48,12 @@ impl + Zero + Copy> CrossMatrix> for Vec3 { // FIXME: implement this for all other vectors impl Row> for Vec2 { #[inline] - fn nrows(&self) -> uint { + fn nrows(&self) -> usize { 2 } #[inline] - fn row(&self, i: uint) -> Vec1 { + fn row(&self, i: usize) -> Vec1 { match i { 0 => Vec1::new(self.x), 1 => Vec1::new(self.y), @@ -62,7 +62,7 @@ impl Row> for Vec2 { } #[inline] - fn set_row(&mut self, i: uint, r: Vec1) { + fn set_row(&mut self, i: usize, r: Vec1) { match i { 0 => self.x = r.x, 1 => self.y = r.x, @@ -82,7 +82,7 @@ impl Basis for Vec1 { fn orthonormal_subspace_basis) -> bool>(_: &Vec1, _: F) { } #[inline] - fn canonical_basis_element(i: uint) -> Option> { + fn canonical_basis_element(i: usize) -> Option> { if i == 0 { Some(Vec1::new(::one())) } @@ -105,7 +105,7 @@ impl> Basis for Vec2 { } #[inline] - fn canonical_basis_element(i: uint) -> Option> { + fn canonical_basis_element(i: usize) -> Option> { if i == 0 { Some(Vec2::new(::one(), ::zero())) } @@ -141,7 +141,7 @@ impl Basis for Vec3 { } #[inline] - fn canonical_basis_element(i: uint) -> Option> { + fn canonical_basis_element(i: usize) -> Option> { if i == 0 { Some(Vec3::new(::one(), ::zero(), ::zero())) } diff --git a/src/structs/spec/vec0.rs b/src/structs/spec/vec0.rs index 713c874e..90d4b3d9 100644 --- a/src/structs/spec/vec0.rs +++ b/src/structs/spec/vec0.rs @@ -20,52 +20,52 @@ impl Zero for vec::Vec0 { } } -impl Index for vec::Vec0 { +impl Index for vec::Vec0 { type Output = N; #[inline] - fn index(&self, _: &uint) -> &N { + fn index(&self, _: &usize) -> &N { panic!("Canot index a Vec0.") } } -impl IndexMut for vec::Vec0 { +impl IndexMut for vec::Vec0 { 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 Shape for vec::Vec0 { +impl Shape for vec::Vec0 { #[inline] - fn shape(&self) -> uint { + fn shape(&self) -> usize { 0 } } -impl Indexable for vec::Vec0 { +impl Indexable for vec::Vec0 { #[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 IterableMut for vec::Vec0 { impl Dim for vec::Vec0 { #[inline] - fn dim(_: Option>) -> uint { + fn dim(_: Option>) -> usize { 0 } } @@ -98,7 +98,7 @@ impl Basis for vec::Vec0 { fn orthonormal_subspace_basis) -> bool>(_: &vec::Vec0, _: F) { } #[inline(always)] - fn canonical_basis_element(_: uint) -> Option> { + fn canonical_basis_element(_: usize) -> Option> { None } } diff --git a/src/structs/vec.rs b/src/structs/vec.rs index 927799da..92181472 100644 --- a/src/structs/vec.rs +++ b/src/structs/vec.rs @@ -41,7 +41,7 @@ pub struct Vec1 { } 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); diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index 8c781e74..4f083b5b 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -62,13 +62,13 @@ macro_rules! at_fast_impl( impl $t { /// 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 POrd for $t { #[inline] fn inf(&self, other: &$t) -> $t { - $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) -> $t { - $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) -> POrdering { - let mut first = true; - let mut is_lt = false; - let mut is_eq = false; - $( - if first { - is_lt = self.$compN < other.$compN; - is_eq = self.$compN == other.$compN; - first = false; - } - else if is_lt { // < + fn partial_cmp(&self, other: &$t) -> POrdering { + let is_lt = self.$comp0 < other.$comp0; + let mut is_eq = self.$comp0 == other.$comp0; + + if is_lt { // < + $( if self.$compN > other.$compN { return POrdering::NotComparable } - } - else { // >= + )* + + POrdering::PartialLess + } + else { // >= + $( if self.$compN < other.$compN { return POrdering::NotComparable } else if self.$compN > other.$compN { is_eq = false; } + + )* + + if is_eq { + POrdering::PartialEqual + } + else { + POrdering::PartialGreater } - )+ - - if is_lt { - POrdering::PartialLess - } - else if is_eq { - POrdering::PartialEqual - } - else { - POrdering::PartialGreater } } #[inline] fn partial_lt(&self, other: &$t) -> bool { - $(self.$compN < other.$compN)&&+ + self.$comp0 < other.$comp0 $(&& self.$compN < other.$compN)* } #[inline] fn partial_le(&self, other: &$t) -> bool { - $(self.$compN <= other.$compN)&&+ + self.$comp0 <= other.$comp0 $(&& self.$compN <= other.$compN)* } #[inline] fn partial_gt(&self, other: &$t) -> bool { - $(self.$compN > other.$compN)&&+ + self.$comp0 > other.$comp0 $(&& self.$compN > other.$compN)* } #[inline] fn partial_ge(&self, other: &$t) -> 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 Shape for $t { + impl Shape for $t { #[inline] - fn shape(&self) -> uint { + fn shape(&self) -> usize { $dim } } - impl Indexable for $t { + impl Indexable for $t { #[inline] - fn at(&self, i: uint) -> N { + fn at(&self, i: usize) -> N { unsafe { mem::transmute::<&$t, &[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, &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, &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; $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, &mut [N; $dim]>(self).get_unchecked_mut(i)) = val } } @@ -226,18 +225,18 @@ macro_rules! indexable_impl( macro_rules! index_impl( ($t: ident) => ( - impl Index for $t { + impl Index for $t { type Output = N; - fn index(&self, i: &uint) -> &N { + fn index(&self, i: &usize) -> &N { &self.as_array()[*i] } } - impl IndexMut for $t { + impl IndexMut for $t { 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 Dim for $t { #[inline] - fn dim(_: Option<$t>) -> uint { + fn dim(_: Option<$t>) -> usize { $dim } } @@ -299,7 +298,7 @@ macro_rules! container_impl( ($t: ident) => ( impl $t { #[inline] - pub fn len(&self) -> uint { + pub fn len(&self) -> usize { Dim::dim(None::<$t>) } } @@ -311,7 +310,7 @@ macro_rules! basis_impl( impl> Basis for $t { #[inline] fn canonical_basis) -> 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> = Vec::new(); - for i in range(0u, $dim) { + for i in (0us .. $dim) { let mut basis_element : $t = ::zero(); unsafe { @@ -352,7 +351,7 @@ macro_rules! basis_impl( } #[inline] - fn canonical_basis_element(i: uint) -> Option<$t> { + fn canonical_basis_element(i: usize) -> Option<$t> { if i < $dim { let mut basis_element : $t = ::zero(); diff --git a/src/traits/operations.rs b/src/traits/operations.rs index 75281e71..14e0845f 100644 --- a/src/traits/operations.rs +++ b/src/traits/operations.rs @@ -193,8 +193,8 @@ impl ApproxEq 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 { /// Trait for computing the eigenvector and eigenvalues of a square matrix usin the QR algorithm. pub trait EigenQR: SquareMat { /// 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); diff --git a/src/traits/structure.rs b/src/traits/structure.rs index 3aeaa7dd..b84e5e2d 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -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 + Sub + Mul + Div + @@ -60,10 +60,10 @@ pub trait Cast { /// Trait of matrices. /// /// A matrix has rows and columns and are able to multiply them. -pub trait Mat: Row + Col + RMul + LMul + Index<(uint, uint), Output = N> { } +pub trait Mat: Row + Col + RMul + LMul + Index<(usize, usize), Output = N> { } impl Mat for M - where M: Row + Col + RMul + LMul + Index<(uint, uint), Output = N> { + where M: Row + Col + RMul + LMul + Index<(usize, usize), Output = N> { } /// Trait implemented by square matrices. @@ -78,7 +78,7 @@ impl SquareMat 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 bool>(&Self, F); /// Gets the ith element of the canonical basis. - fn canonical_basis_element(i: uint) -> Option; + fn canonical_basis_element(i: usize) -> Option; } /// Trait to access rows of a matrix or a vector. pub trait Row { /// 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 { /// Trait to access columns of a matrix or vector. pub trait Col { /// 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 { /// Trait to access part of a column of a matrix pub trait ColSlice { /// 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 { /// 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) -> uint; + fn dim(unused_self: Option) -> usize; } /// Trait to get the diagonal of square matrices. @@ -241,7 +241,7 @@ pub trait NumVec: Dim + Sub + Add + Mul + Div + Neg + - Index + + Index + Zero + PartialEq + Dot + Axpy { } @@ -281,7 +281,7 @@ pub trait NumPnt: Mul + Div + Add + - Index { // FIXME: + Sub + Index { // FIXME: + Sub } /// 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 diff --git a/tests/mat.rs b/tests/mat.rs index 5755b394..a38adf7c 100644 --- a/tests/mat.rs +++ b/tests/mat.rs @@ -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 = na::one(); let ang = Vec1::new(na::abs(&random::()) % 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 = na::one(); let dir: Vec3 = random(); let ang = na::normalize(&dir) * (na::abs(&random::()) % 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 = DMat::new_random(rows, cols); @@ -327,8 +327,8 @@ fn test_qr_mat6() { #[test] fn test_from_fn() { - let actual: DMat = DMat::from_fn(3, 4, |i, j| 10 * i + j); - let expected: DMat = DMat::from_row_vec(3, 4, + let actual: DMat = DMat::from_fn(3, 4, |i, j| 10 * i + j); + let expected: DMat = 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 ]); diff --git a/tests/quat.rs b/tests/quat.rs index 11ec293f..2b1d9532 100644 --- a/tests/quat.rs +++ b/tests/quat.rs @@ -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 = 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 = random(); let vec: Vec3 = random(); let pnt: Pnt3 = 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 = random(); let axis_angle2: Vec3 = 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 = 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 = random(); let q = UnitQuat::new_with_euler_angles(angles.x, angles.y, angles.z); diff --git a/tests/vec.rs b/tests/vec.rs index 8af66537..dab3e9a4 100644 --- a/tests/vec.rs +++ b/tests/vec.rs @@ -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 = random(); let v2 : Vec3 = random(); let v3 : Vec3 = na::cross(&v1, &v2);