Skip to content

Commit 35330b6

Browse files
committed
Add document for Matrix format
Move doc
1 parent 81f08e3 commit 35330b6

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lax/src/layout.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
//! Memory layout of matrices
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+
//! ```text
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
pub type LDA = i32;
441
pub type LEN = i32;

ndarray-linalg/src/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Memory layout of matrices
1+
//! Convert ndarray into LAPACK-compatible matrix format
22
33
use super::error::*;
44
use ndarray::*;

0 commit comments

Comments
 (0)