Skip to content

Commit fec0c74

Browse files
committed
Merge pull request dimforge#55 from sebcrozet/rustup
Update to the last rust-nightly.
2 parents 6c431ff + a92c681 commit fec0c74

20 files changed

+479
-416
lines changed

benches/common/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ macro_rules! bench_binop(
1616
i = (i + 1) & (LEN - 1);
1717

1818
unsafe {
19-
test::black_box(elems1.unsafe_get(i).$binop(elems2.unsafe_get(i)))
19+
test::black_box(elems1.unsafe_get(i).$binop(*elems2.unsafe_get(i)))
2020
}
2121
})
2222
}

benches/dmat.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ use na::{DVec, DMat};
99
macro_rules! bench_mul_dmat(
1010
($bh: expr, $nrows: expr, $ncols: expr) => {
1111
{
12-
let a: DMat<f64> = DMat::new_random($nrows, $ncols);
13-
let mut b: DMat<f64> = DMat::new_random($nrows, $ncols);
14-
1512
$bh.iter(|| {
13+
let a: DMat<f64> = DMat::new_random($nrows, $ncols);
14+
let mut b: DMat<f64> = DMat::new_random($nrows, $ncols);
15+
1616
for _ in range(0u, 1000) {
17-
b = a * b;
17+
// XXX: the clone here is highly undesirable!
18+
b = a.clone() * b;
1819
}
1920
})
2021
}
@@ -49,12 +50,14 @@ fn bench_mul_dmat6(bh: &mut Bencher) {
4950
macro_rules! bench_mul_dmat_dvec(
5051
($bh: expr, $nrows: expr, $ncols: expr) => {
5152
{
52-
let m : DMat<f64> = DMat::new_random($nrows, $ncols);
53-
let mut v : DVec<f64> = DVec::new_random($ncols);
5453

5554
$bh.iter(|| {
55+
let m : DMat<f64> = DMat::new_random($nrows, $ncols);
56+
let mut v : DVec<f64> = DVec::new_random($ncols);
57+
5658
for _ in range(0u, 1000) {
57-
v = m * v
59+
// XXX: the clone here is highly undesirable!
60+
v = m.clone() * v
5861
}
5962
})
6063
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub fn orig<P: Orig>() -> P {
315315

316316
/// Returns the center of two points.
317317
#[inline]
318-
pub fn center<N: BaseFloat, P: FloatPnt<N, V>, V>(a: &P, b: &P) -> P {
318+
pub fn center<N: BaseFloat, P: FloatPnt<N, V>, V: Copy>(a: &P, b: &P) -> P {
319319
let _2 = one::<N>() + one();
320320
(*a + *b.as_vec()) / _2
321321
}

src/linalg/decompositions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ pub fn householder_matrix<N, V, M>(dim: uint, start: uint, vec: V) -> M
4040
pub fn qr<N, V, M>(m: &M) -> (M, M)
4141
where N: BaseFloat,
4242
V: Indexable<uint, N> + Norm<N>,
43-
M: Clone + Eye + ColSlice<V> + Transpose + Indexable<(uint, uint), N> + Mul<M, M> {
43+
M: Copy + Eye + ColSlice<V> + Transpose + Indexable<(uint, uint), N> + Mul<M, M> {
4444
let (rows, cols) = m.shape();
4545
assert!(rows >= cols);
4646
let mut q : M = Eye::new_identity(rows);
47-
let mut r = m.clone();
47+
let mut r = *m;
4848

4949
let iterations = min(rows - 1, cols);
5050

@@ -76,9 +76,9 @@ pub fn eigen_qr<N, V, VS, M>(m: &M, eps: &N, niter: uint) -> (M, V)
7676
where N: BaseFloat,
7777
VS: Indexable<uint, N> + Norm<N>,
7878
M: Indexable<(uint, uint), N> + SquareMat<N, V> + Add<M, M> + Sub<M, M> + ColSlice<VS> +
79-
ApproxEq<N> + Clone {
79+
ApproxEq<N> + Copy {
8080
let mut eigenvectors: M = ::one::<M>();
81-
let mut eigenvalues = m.clone();
81+
let mut eigenvalues = *m;
8282
// let mut shifter: M = Eye::new_identity(rows);
8383

8484
let mut iter = 0u;

src/structs/dmat.rs

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<N> DMat<N> {
3636
}
3737
}
3838

39-
impl<N: Zero + Clone> DMat<N> {
39+
impl<N: Zero + Clone + Copy> DMat<N> {
4040
/// Builds a matrix filled with zeros.
4141
///
4242
/// # Arguments
@@ -69,15 +69,15 @@ impl<N: Rand> DMat<N> {
6969
}
7070
}
7171

72-
impl<N: One + Clone> DMat<N> {
72+
impl<N: One + Clone + Copy> DMat<N> {
7373
/// Builds a matrix filled with a given constant.
7474
#[inline]
7575
pub fn new_ones(nrows: uint, ncols: uint) -> DMat<N> {
7676
DMat::from_elem(nrows, ncols, ::one())
7777
}
7878
}
7979

80-
impl<N: Clone> DMat<N> {
80+
impl<N: Clone + Copy> DMat<N> {
8181
/// Builds a matrix filled with a given constant.
8282
#[inline]
8383
pub fn from_elem(nrows: uint, ncols: uint, val: N) -> DMat<N> {
@@ -169,7 +169,7 @@ impl<N> DMat<N> {
169169

170170
// FIXME: add a function to modify the dimension (to avoid useless allocations)?
171171

172-
impl<N: One + Zero + Clone> Eye for DMat<N> {
172+
impl<N: One + Zero + Clone + Copy> Eye for DMat<N> {
173173
/// Builds an identity matrix.
174174
///
175175
/// # Arguments
@@ -196,7 +196,7 @@ impl<N> DMat<N> {
196196

197197
}
198198

199-
impl<N: Clone> Indexable<(uint, uint), N> for DMat<N> {
199+
impl<N: Copy> Indexable<(uint, uint), N> for DMat<N> {
200200
/// Changes the value of a component of the matrix.
201201
///
202202
/// # Arguments
@@ -235,7 +235,8 @@ impl<N: Clone> Indexable<(uint, uint), N> for DMat<N> {
235235
#[inline]
236236
unsafe fn unsafe_at(&self, rowcol: (uint, uint)) -> N {
237237
let (row, col) = rowcol;
238-
(*self.mij.as_slice().unsafe_get(self.offset(row, col))).clone()
238+
239+
*self.mij.as_slice().unsafe_get(self.offset(row, col))
239240
}
240241

241242
#[inline]
@@ -283,8 +284,8 @@ impl<N> IndexMut<(uint, uint), N> for DMat<N> {
283284
}
284285
}
285286

286-
impl<N: Clone + Mul<N, N> + Add<N, N> + Zero> Mul<DMat<N>, DMat<N>> for DMat<N> {
287-
fn mul(&self, right: &DMat<N>) -> DMat<N> {
287+
impl<N: Copy + Mul<N, N> + Add<N, N> + Zero> Mul<DMat<N>, DMat<N>> for DMat<N> {
288+
fn mul(self, right: DMat<N>) -> DMat<N> {
288289
assert!(self.ncols == right.nrows);
289290

290291
let mut res = unsafe { DMat::new_uninitialized(self.nrows, right.ncols) };
@@ -308,8 +309,8 @@ impl<N: Clone + Mul<N, N> + Add<N, N> + Zero> Mul<DMat<N>, DMat<N>> for DMat<N>
308309
}
309310
}
310311

311-
impl<N: Clone + Add<N, N> + Mul<N, N> + Zero> Mul<DVec<N>, DVec<N>> for DMat<N> {
312-
fn mul(&self, right: &DVec<N>) -> DVec<N> {
312+
impl<N: Copy + Add<N, N> + Mul<N, N> + Zero> Mul<DVec<N>, DVec<N>> for DMat<N> {
313+
fn mul(self, right: DVec<N>) -> DVec<N> {
313314
assert!(self.ncols == right.at.len());
314315

315316
let mut res : DVec<N> = unsafe { DVec::new_uninitialized(self.nrows) };
@@ -331,8 +332,8 @@ impl<N: Clone + Add<N, N> + Mul<N, N> + Zero> Mul<DVec<N>, DVec<N>> for DMat<N>
331332
}
332333

333334

334-
impl<N: Clone + Add<N, N> + Mul<N, N> + Zero> Mul<DMat<N>, DVec<N>> for DVec<N> {
335-
fn mul(&self, right: &DMat<N>) -> DVec<N> {
335+
impl<N: Copy + Add<N, N> + Mul<N, N> + Zero> Mul<DMat<N>, DVec<N>> for DVec<N> {
336+
fn mul(self, right: DMat<N>) -> DVec<N> {
336337
assert!(right.nrows == self.at.len());
337338

338339
let mut res : DVec<N> = unsafe { DVec::new_uninitialized(right.ncols) };
@@ -353,7 +354,7 @@ impl<N: Clone + Add<N, N> + Mul<N, N> + Zero> Mul<DMat<N>, DVec<N>> for DVec<N>
353354
}
354355
}
355356

356-
impl<N: Clone + BaseNum + Zero + One> Inv for DMat<N> {
357+
impl<N: BaseNum + Clone> Inv for DMat<N> {
357358
#[inline]
358359
fn inv_cpy(&self) -> Option<DMat<N>> {
359360
let mut res: DMat<N> = self.clone();
@@ -439,7 +440,7 @@ impl<N: Clone + BaseNum + Zero + One> Inv for DMat<N> {
439440
}
440441
}
441442

442-
impl<N: Clone> Transpose for DMat<N> {
443+
impl<N: Clone + Copy> Transpose for DMat<N> {
443444
#[inline]
444445
fn transpose_cpy(&self) -> DMat<N> {
445446
if self.nrows == self.ncols {
@@ -485,7 +486,7 @@ impl<N: Clone> Transpose for DMat<N> {
485486
}
486487
}
487488

488-
impl<N: BaseNum + Cast<f64> + Zero + Clone> Mean<DVec<N>> for DMat<N> {
489+
impl<N: BaseNum + Cast<f64> + Clone> Mean<DVec<N>> for DMat<N> {
489490
fn mean(&self) -> DVec<N> {
490491
let mut res: DVec<N> = DVec::new_zeros(self.ncols);
491492
let normalizer: N = Cast::from(1.0f64 / Cast::from(self.nrows));
@@ -503,7 +504,7 @@ impl<N: BaseNum + Cast<f64> + Zero + Clone> Mean<DVec<N>> for DMat<N> {
503504
}
504505
}
505506

506-
impl<N: Clone + BaseNum + Cast<f64> + Div<N, N>> Cov<DMat<N>> for DMat<N> {
507+
impl<N: BaseNum + Cast<f64> + Clone> Cov<DMat<N>> for DMat<N> {
507508
// FIXME: this could be heavily optimized, removing all temporaries by merging loops.
508509
fn cov(&self) -> DMat<N> {
509510
assert!(self.nrows > 1);
@@ -528,7 +529,7 @@ impl<N: Clone + BaseNum + Cast<f64> + Div<N, N>> Cov<DMat<N>> for DMat<N> {
528529
}
529530
}
530531

531-
impl<N: Clone> ColSlice<DVec<N>> for DMat<N> {
532+
impl<N: Copy + Clone> ColSlice<DVec<N>> for DMat<N> {
532533
fn col_slice(&self, col_id :uint, row_start: uint, row_end: uint) -> DVec<N> {
533534
assert!(col_id < self.ncols);
534535
assert!(row_start < row_end);
@@ -542,7 +543,7 @@ impl<N: Clone> ColSlice<DVec<N>> for DMat<N> {
542543
}
543544
}
544545

545-
impl<N: Clone> RowSlice<DVec<N>> for DMat<N> {
546+
impl<N: Copy> RowSlice<DVec<N>> for DMat<N> {
546547
fn row_slice(&self, row_id :uint, col_start: uint, col_end: uint) -> DVec<N> {
547548
assert!(row_id < self.nrows);
548549
assert!(col_start < col_end);
@@ -561,7 +562,7 @@ impl<N: Clone> RowSlice<DVec<N>> for DMat<N> {
561562
}
562563
}
563564

564-
impl<N: Clone + Zero> Diag<DVec<N>> for DMat<N> {
565+
impl<N: Copy + Clone + Zero> Diag<DVec<N>> for DMat<N> {
565566
#[inline]
566567
fn from_diag(diag: &DVec<N>) -> DMat<N> {
567568
let mut res = DMat::new_zeros(diag.len(), diag.len());
@@ -609,7 +610,7 @@ impl<N: ApproxEq<N>> ApproxEq<N> for DMat<N> {
609610
}
610611
}
611612

612-
impl<N: Show + Clone> Show for DMat<N> {
613+
impl<N: Show + Copy> Show for DMat<N> {
613614
fn fmt(&self, form:&mut Formatter) -> Result {
614615
for i in range(0u, self.nrows()) {
615616
for j in range(0u, self.ncols()) {
@@ -621,46 +622,54 @@ impl<N: Show + Clone> Show for DMat<N> {
621622
}
622623
}
623624

624-
impl<N: Mul<N, N>> Mul<N, DMat<N>> for DMat<N> {
625+
impl<N: Copy + Mul<N, N>> Mul<N, DMat<N>> for DMat<N> {
625626
#[inline]
626-
fn mul(&self, right: &N) -> DMat<N> {
627-
DMat {
628-
nrows: self.nrows,
629-
ncols: self.ncols,
630-
mij: self.mij.iter().map(|a| *a * *right).collect()
627+
fn mul(self, right: N) -> DMat<N> {
628+
let mut res = self;
629+
630+
for mij in res.mij.iter_mut() {
631+
*mij = *mij * right;
631632
}
633+
634+
res
632635
}
633636
}
634637

635-
impl<N: Div<N, N>> Div<N, DMat<N>> for DMat<N> {
638+
impl<N: Copy + Div<N, N>> Div<N, DMat<N>> for DMat<N> {
636639
#[inline]
637-
fn div(&self, right: &N) -> DMat<N> {
638-
DMat {
639-
nrows: self.nrows,
640-
ncols: self.ncols,
641-
mij: self.mij.iter().map(|a| *a / *right).collect()
640+
fn div(self, right: N) -> DMat<N> {
641+
let mut res = self;
642+
643+
for mij in res.mij.iter_mut() {
644+
*mij = *mij / right;
642645
}
646+
647+
res
643648
}
644649
}
645650

646-
impl<N: Add<N, N>> Add<N, DMat<N>> for DMat<N> {
651+
impl<N: Copy + Add<N, N>> Add<N, DMat<N>> for DMat<N> {
647652
#[inline]
648-
fn add(&self, right: &N) -> DMat<N> {
649-
DMat {
650-
nrows: self.nrows,
651-
ncols: self.ncols,
652-
mij: self.mij.iter().map(|a| *a + *right).collect()
653+
fn add(self, right: N) -> DMat<N> {
654+
let mut res = self;
655+
656+
for mij in res.mij.iter_mut() {
657+
*mij = *mij + right;
653658
}
659+
660+
res
654661
}
655662
}
656663

657-
impl<N: Sub<N, N>> Sub<N, DMat<N>> for DMat<N> {
664+
impl<N: Copy + Sub<N, N>> Sub<N, DMat<N>> for DMat<N> {
658665
#[inline]
659-
fn sub(&self, right: &N) -> DMat<N> {
660-
DMat {
661-
nrows: self.nrows,
662-
ncols: self.ncols,
663-
mij: self.mij.iter().map(|a| *a - *right).collect()
666+
fn sub(self, right: N) -> DMat<N> {
667+
let mut res = self;
668+
669+
for mij in res.mij.iter_mut() {
670+
*mij = *mij - right;
664671
}
672+
673+
res
665674
}
666675
}

src/structs/dvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use std::rand::Rand;
66
use std::rand;
77
use std::slice::{Items, MutItems};
8-
use traits::operations::ApproxEq;
98
use std::iter::FromIterator;
9+
use traits::operations::{ApproxEq, Axpy};
1010
use traits::geometry::{Dot, Norm};
1111
use traits::structure::{Iterable, IterableMut, Indexable, Shape, BaseFloat, BaseNum, Zero, One};
1212

0 commit comments

Comments
 (0)