Restore most of @oleglite Row/Col implementations lost during the last merge.

This commit is contained in:
Sébastien Crozet 2016-01-10 16:10:14 +01:00
parent bfd97beffe
commit d15211737a
1 changed files with 23 additions and 25 deletions

View File

@ -454,28 +454,23 @@ macro_rules! dmat_impl(
} }
#[inline] #[inline]
fn set_col(&mut self, col_id: usize, v: $dvec<N>) { fn set_col(&mut self, col_id: usize, col: $dvec<N>) {
assert!(col_id < self.ncols); assert!(col_id < self.ncols);
assert!(self.nrows == v.len()); assert!(col.len() == self.nrows);
for (i, e) in v[..].iter().enumerate() { for row_id in 0 .. self.nrows {
unsafe { unsafe {
self.unsafe_set((i, col_id), *e); self.unsafe_set((row_id, col_id), col.unsafe_at(row_id));
} }
} }
} }
#[inline]
fn col(&self, col_id: usize) -> $dvec<N> { fn col(&self, col_id: usize) -> $dvec<N> {
let mut res: $dvec<N> = unsafe { assert!(col_id < self.ncols);
$dvec::new_uninitialized(self.nrows)
};
for (row_id, e) in res[..].iter_mut().enumerate() { let start = self.offset(0, col_id);
*e = unsafe { self.unsafe_at((row_id, col_id)) }; let stop = self.offset(self.nrows, col_id);
} $dvec::from_slice(self.nrows, &self.mij[start .. stop])
res
} }
} }
@ -501,28 +496,31 @@ macro_rules! dmat_impl(
} }
#[inline] #[inline]
fn set_row(&mut self, row_id: usize, v: $dvec<N>) { fn set_row(&mut self, row_id: usize, row: $dvec<N>) {
assert!(row_id < self.nrows); assert!(row_id < self.nrows);
assert!(self.ncols == v.len()); assert!(row.len() == self.ncols);
for (i, e) in v[..].iter().enumerate() { for col_id in 0 .. self.ncols {
unsafe { unsafe {
self.unsafe_set((row_id, i), *e); self.unsafe_set((row_id, col_id), row.unsafe_at(col_id));
} }
} }
} }
#[inline] #[inline]
fn row(&self, row_id: usize) -> $dvec<N> { fn row(&self, row_id: usize) -> $dvec<N> {
let mut res: $dvec<N> = unsafe { assert!(row_id < self.nrows);
let mut slice : $dvec<N> = unsafe {
$dvec::new_uninitialized(self.ncols) $dvec::new_uninitialized(self.ncols)
}; };
for (col_id, e) in res[..].iter_mut().enumerate() { for col_id in 0 .. self.ncols {
*e = unsafe { self.unsafe_at((row_id, col_id)) }; unsafe {
slice.unsafe_set(col_id, self.unsafe_at((row_id, col_id)));
} }
}
res slice
} }
} }