7.2 Types, Predicates and Accessors

► |  | Math Library

1 | Constants and Elementary Functions
2 | Flonums
3 | Special Functions
4 | Number Theory
5 | Arbitrary-Precision Floating-Point Numbers (Bigfloats)
6 | Arrays
7 | Matrices and Linear Algebra
8 | Statistics Functions
9 | Probability Distributions
10 | Stuff That Doesn’t Belong Anywhere Else

▼ | 7 | Matrices and Linear Algebra

7.1 | Introduction
7.2 | Types, Predicates and Accessors
7.3 | Construction
7.4 | Conversion
7.5 | Entrywise Operations and Arithmetic
7.6 | Polymorphic Operations
7.7 | Basic Operations
7.8 | Inner Product Space Operations
7.9 | Solving Systems of Equations
7.10 | Row-Based Algorithms
7.11 | Orthogonal Algorithms
7.12 | Operator Norms and Comparing Matrices

On this page:

Matrix
matrix?
row-matrix?
col-matrix?
square-matrix?
matrix-shape
matrix-num-rows
matrix-num-cols
square-matrix-size

top ← prev up next →

#### 7.2`` Types, Predicates and Accessors

> syntax (Matrix A)

Equivalent to (Array A), but used for values M for which (matrix? M) is #t.

> procedure (matrix? arr) → Boolean
> arr : (Array A)

Returns #t when arr is a matrix: a nonempty array with exactly two axes.

Examples:
> > (matrix? (array 10))
> - : Boolean
> #f
> > (matrix? (array #[1 2 3]))
> - : Boolean
> #f
> > (matrix? (make-array #(5 0) 0))
> - : Boolean
> #f
> > (matrix? (array #[#[1 0] #[0 1]]))
> - : Boolean
> #t

> procedure (row-matrix? arr) → Boolean
> arr : (Array A)

Returns #t when arr is a row matrix: a matrix with exactly one row.

> procedure (col-matrix? arr) → Boolean
> arr : (Array A)

Returns #t when arr is a column matrix: a matrix with exactly one column.

> procedure (square-matrix? arr) → Boolean
> arr : (Array A)

Returns #t when arr is a matrix with the same number of rows and columns.

> procedure (matrix-shape M) → (Values Index Index)
> M : (Matrix A)

Returns M’s row and column count, respectively. Raises an error if (matrix? M) is #f.

Examples:
> > (matrix-shape (row-matrix [1 2 3]))
> - : (Values Integer Integer) [generalized from (Values Index Index)]
> 1
> 3
> > (matrix-shape (col-matrix [1 2 3]))
> - : (Values Integer Integer) [generalized from (Values Index Index)]
> 3
> 1
> > (matrix-shape (identity-matrix 3))
> - : (Values Integer Integer) [generalized from (Values Index Index)]
> 3
> 3

> procedure (matrix-num-rows M) → Index
> M : (Matrix A)

Returns the number of rows in M, or the first value of (matrix-shape M).

> procedure (matrix-num-cols M) → Index
> M : (Matrix A)

Returns the number of columns in M, or the second value of (matrix-shape M).

> procedure (square-matrix-size M) → Index
> M : (Matrix A)

Returns the number of rows/columns in M. Raises an error if (square-matrix? M) is #f.

Examples:
> > (square-matrix-size (identity-matrix 3))
> - : Integer [generalized from Index]
> 3
> > (square-matrix-size (row-matrix [1 2 3]))
> square-matrix-size: contract violation
> expected: square-matrix?
> given: (array #[#[1 2 3]])

top ← prev up next →