Skip to content

Commit 0c09946

Browse files
committed
Add document for Matrix format
1 parent 4e0ef6f commit 0c09946

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/layout.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
1-
//! Memory layout of matrices
1+
//! Convert ndarray into LAPACK-compatible matrix format
2+
//!
3+
//! Different from ndarray format which consists of shape and strides,
4+
//! matrix format in LAPACK consists of row or column size and leading dimension.
5+
//!
6+
//! ndarray format and stride
7+
//! --------------------------
8+
//!
9+
//! Let us consider 3-dimensional array for explaining ndarray structure.
10+
//! The address of `(x,y,z)`-element in ndarray satisfies following relation:
11+
//!
12+
//! ```
13+
//! shape = [Nx, Ny, Nz]
14+
//! where Nx > 0, Ny > 0, Nz > 0
15+
//! stride = [Sx, Sy, Sz]
16+
//!
17+
//! &data[(x, y, z)] = &data[(0, 0, 0)] + Sx*x + Sy*y + Sz*z
18+
//! for x < Nx, y < Ny, z < Nz
19+
//! ```
20+
//!
21+
//! The array is called
22+
//!
23+
//! - C-continuous if `[Sx, Sy, Sz] = [Nz*Ny, Nz, 1]`
24+
//! - F(Fortran)-continuous if `[Sx, Sy, Sz] = [1, Nx, Nx*Ny]`
25+
//!
26+
//! Strides of ndarray `[Sx, Sy, Sz]` take arbitrary value,
27+
//! e.g. it can be non-ordered `Sy > Sx > Sz`, or can be negative `Sx < 0`.
28+
//! If the minimum of `[Sx, Sy, Sz]` equals to `1`,
29+
//! the value of elements fills `data` memory region and called "continuous".
30+
//! Non-continuous ndarray is useful to get sub-array without copying data.
31+
//!
32+
//! Matrix layout for LAPACK
33+
//! -------------------------
34+
//!
35+
//! LAPACK interface focuses on the linear algebra operations for F-continuous 2-dimensional array.
36+
//! Under this restriction, stride becomes far simpler; we only have to consider the case `[1, S]`
37+
//! This `S` for a matrix `A` is called "leading dimension of the array A" in LAPACK document, and denoted by `lda`.
38+
//!
239
340
use ndarray::*;
441

0 commit comments

Comments
 (0)