|
1 | 1 | //! Memory layout of matrices
|
2 | 2 |
|
3 |
| -use ndarray::*; |
4 |
| - |
5 | 3 | use super::error::*;
|
| 4 | +use ndarray::*; |
6 | 5 |
|
7 |
| -pub type LDA = i32; |
8 |
| -pub type LEN = i32; |
9 |
| -pub type Col = i32; |
10 |
| -pub type Row = i32; |
11 |
| - |
12 |
| -#[derive(Debug, Clone, Copy, PartialEq)] |
13 |
| -pub enum MatrixLayout { |
14 |
| - C((Row, LDA)), |
15 |
| - F((Col, LDA)), |
16 |
| -} |
17 |
| - |
18 |
| -impl MatrixLayout { |
19 |
| - pub fn size(&self) -> (Row, Col) { |
20 |
| - match *self { |
21 |
| - MatrixLayout::C((row, lda)) => (row, lda), |
22 |
| - MatrixLayout::F((col, lda)) => (lda, col), |
23 |
| - } |
24 |
| - } |
25 |
| - |
26 |
| - pub fn resized(&self, row: Row, col: Col) -> MatrixLayout { |
27 |
| - match *self { |
28 |
| - MatrixLayout::C(_) => MatrixLayout::C((row, col)), |
29 |
| - MatrixLayout::F(_) => MatrixLayout::F((col, row)), |
30 |
| - } |
31 |
| - } |
32 |
| - |
33 |
| - pub fn lda(&self) -> LDA { |
34 |
| - std::cmp::max( |
35 |
| - 1, |
36 |
| - match *self { |
37 |
| - MatrixLayout::C((_, lda)) | MatrixLayout::F((_, lda)) => lda, |
38 |
| - }, |
39 |
| - ) |
40 |
| - } |
41 |
| - |
42 |
| - pub fn len(&self) -> LEN { |
43 |
| - match *self { |
44 |
| - MatrixLayout::C((row, _)) => row, |
45 |
| - MatrixLayout::F((col, _)) => col, |
46 |
| - } |
47 |
| - } |
48 |
| - |
49 |
| - pub fn is_empty(&self) -> bool { |
50 |
| - self.len() == 0 |
51 |
| - } |
52 |
| - |
53 |
| - pub fn lapacke_layout(&self) -> lapacke::Layout { |
54 |
| - match *self { |
55 |
| - MatrixLayout::C(_) => lapacke::Layout::RowMajor, |
56 |
| - MatrixLayout::F(_) => lapacke::Layout::ColumnMajor, |
57 |
| - } |
58 |
| - } |
59 |
| - |
60 |
| - pub fn same_order(&self, other: &MatrixLayout) -> bool { |
61 |
| - self.lapacke_layout() == other.lapacke_layout() |
62 |
| - } |
63 |
| - |
64 |
| - pub fn as_shape(&self) -> Shape<Ix2> { |
65 |
| - match *self { |
66 |
| - MatrixLayout::C((row, col)) => (row as usize, col as usize).into_shape(), |
67 |
| - MatrixLayout::F((col, row)) => (row as usize, col as usize).f().into_shape(), |
68 |
| - } |
69 |
| - } |
70 |
| - |
71 |
| - pub fn toggle_order(&self) -> Self { |
72 |
| - match *self { |
73 |
| - MatrixLayout::C((row, col)) => MatrixLayout::F((col, row)), |
74 |
| - MatrixLayout::F((col, row)) => MatrixLayout::C((row, col)), |
75 |
| - } |
76 |
| - } |
77 |
| -} |
| 6 | +pub use lapack::layout::MatrixLayout; |
78 | 7 |
|
79 | 8 | pub trait AllocatedArray {
|
80 | 9 | type Elem;
|
|
0 commit comments