MCPcopy Create free account
hub / github.com/Axect/Peroxide / row_ptr

Method row_ptr

src/traits/pointer.rs:299–320  ·  view source on GitHub ↗

Row pointer # Examples ``` #[macro_use] extern crate peroxide; use peroxide::fuga::*; fn main() { let a = ml_matrix("1 2;3 4"); unsafe { let b = a.row_ptr(1); let b_vec = ptr_to_vec(&b); assert_eq!(b_vec, vec![3f64, 4f64]); } } ```

(&self, idx: usize)

Source from the content-addressed store, hash-verified

297 /// }
298 /// ```
299 unsafe fn row_ptr(&self, idx: usize) -> Vec<*const f64> {
300 assert!(idx < self.col, "Index out of range");
301 match self.shape {
302 Shape::Row => {
303 let mut v: Vec<*const f64> = vec![&0f64; self.col];
304 let start_idx = idx * self.col;
305 let p = self.ptr();
306 for (i, j) in (start_idx..start_idx + v.len()).enumerate() {
307 v[i] = p.add(j);
308 }
309 v
310 }
311 Shape::Col => {
312 let mut v: Vec<*const f64> = vec![&0f64; self.col];
313 let p = self.ptr();
314 for (i, elem) in v.iter_mut().enumerate() {
315 *elem = p.add(idx + i * self.row);
316 }
317 v
318 }
319 }
320 }
321
322 unsafe fn col_ptr(&self, idx: usize) -> Vec<*const f64> {
323 assert!(idx < self.col, "Index out of range");

Callers

nothing calls this directly

Calls 3

ptrMethod · 0.45
lenMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected