Functions

The following functions are available globally.

One-line creators for matrices

  • Create a matrix of zeros.

    Declaration

    Swift

    public func zeros(_ rows: Int, _ cols: Int) -> Matrix

    Parameters

    rows

    number of rows

    cols

    number of columns

    Return Value

    zeros matrix of specified size

  • Create a matrix of zeros.

    Declaration

    Swift

    public func zeros(like m: Matrix) -> Matrix

    Parameters

    m

    Matrix

    Return Value

    matrix of zeros with same size as input

  • Create a matrix of ones.

    Declaration

    Swift

    public func ones(_ rows: Int, _ cols: Int) -> Matrix

    Parameters

    rows

    number of rows

    cols

    number of columns

    Return Value

    ones matrix of specified size

  • Create a matrix of ones.

    Declaration

    Swift

    public func ones(like m: Matrix) -> Matrix

    Parameters

    m

    Matrix

    Return Value

    matrix of ones with same size as input

  • Create a matrix of uniformly distributed on [0, 1) interval random values.

    Declaration

    Swift

    public func rand(_ rows: Int, _ cols: Int) -> Matrix

    Parameters

    rows

    number of rows

    cols

    number of columns

    Return Value

    random values matrix of specified size

  • Create a matrix of normally distibuted random values.

    Declaration

    Swift

    public func randn(_ rows: Int, _ cols: Int) -> Matrix

    Parameters

    rows

    number of rows

    cols

    number of columns

    Return Value

    random values matrix of specified size

  • Create a matrix with ones on the main diagonal and zeros elsewhere.

    Declaration

    Swift

    public func eye(_ rows: Int, _ cols: Int) -> Matrix

    Parameters

    rows

    number of rows

    cols

    number of columns

    Return Value

    identity matrix of specified size

  • Create a square matrix with specified values on the main diagonal and zeros elsewhere.

    Declaration

    Swift

    public func diag(_ v: Matrix) -> Matrix

    Parameters

    v

    matrix of values with one column

    Return Value

    square diagonal matrix with specified values

  • Create a square matrix with specified values on the main diagonal and zeros elsewhere.

    Declaration

    Swift

    public func diag(_ v: Vector) -> Matrix

    Parameters

    v

    vector of values

    Return Value

    square diagonal matrix with specified values

  • Create a matrix with specified values on the main diagonal and zeros elsewhere.

    Declaration

    Swift

    public func diag(_ rows: Int, _ cols: Int, _ v: Matrix) -> Matrix

    Parameters

    rows

    number of rows

    cols

    number of columns

    v

    matrix of values with one column

    Return Value

    diagonal matrix with specified values and size

  • Create a matrix with specified values on the main diagonal and zeros elsewhere.

    Declaration

    Swift

    public func diag(_ rows: Int, _ cols: Int, _ v: Vector) -> Matrix

    Parameters

    rows

    number of rows

    cols

    number of columns

    v

    vector of values

    Return Value

    diagonal matrix with specified values and size

Matrix manipulation

  • Vertically stack (top-to-bottom) rows in matrices.

    Precondition: All matrices need the same number of columns.

    Declaration

    Swift

    public func vstack(_ ma: [Matrix]) -> Matrix

    Parameters

    ma

    Return Value

    new matrix by vertically stacking rows of input matrices

  • Horizontally stack (left-to-right) columns in matrices.

    Precondition: All matrices need the same number of rows.

    Declaration

    Swift

    public func hstack(_ ma: [Matrix]) -> Matrix

    Parameters

    ma

    Return Value

    new matrix by horizontally stacking columns of input matrices

  • Insert row to matrix at specified position.

    Declaration

    Swift

    public func insert(_ m: Matrix, row: Vector, at index: Int) -> Matrix

    Parameters

    m

    matrix

    row

    row values to insert

    at

    index to insert row to

    Return Value

    new matrix with inserted row

  • Insert rows to matrix at specified position.

    Declaration

    Swift

    public func insert(_ m: Matrix, rows: Matrix, at index: Int) -> Matrix

    Parameters

    m

    matrix

    rows

    rows values to insert represented as matrix

    at

    index to insert rows to

    Return Value

    new matrix with inserted rows

  • Append row to matrix.

    Declaration

    Swift

    public func append(_ m: Matrix, row: Matrix) -> Matrix

    Parameters

    m

    matrix

    row

    row values to append represented as row matrix

    Return Value

    new matrix with appended row

  • Append row to matrix.

    Alternatively, append(m, row: row) can be executed with m === row.

    Declaration

    Swift

    public func append(_ m: Matrix, row: Vector) -> Matrix

    Parameters

    m

    matrix

    row

    row values to append

    Return Value

    new matrix with appended row

  • Append row to matrix constructed from scalar value.

    Alternatively, append(m, row: row) can be executed with m === row.

    Declaration

    Swift

    public func append(_ m: Matrix, row: Double) -> Matrix

    Parameters

    m

    matrix

    row

    row value to append

    Return Value

    new matrix with appended row

  • Append rows to matrix.

    Alternatively, append(m, rows: rows) can be executed with m === rows.

    Declaration

    Swift

    public func append(_ m: Matrix, rows: Matrix) -> Matrix

    Parameters

    m

    matrix

    rows

    rows values to append represented as matrix

    Return Value

    new matrix with appended rows

  • Append rows to matrix.

    Declaration

    Swift

    public func append(_ m: Matrix, rows: [Vector]) -> Matrix

    Parameters

    m

    matrix

    rows

    rows values to append represented as array of vectors

    Return Value

    new matrix with appended rows

  • Append row to matrix constructed from scalar value.

    Alternatively, m === row can be executed with append(m, row: row).

    Declaration

    Swift

    public func === (m: Matrix, row: Double) -> Matrix

    Parameters

    m

    matrix

    row

    row value to append

    Return Value

    new matrix with appended row

  • Append row to matrix.

    Alternatively, m === row can be executed with append(m, row: row).

    Declaration

    Swift

    public func === (m: Matrix, row: Vector) -> Matrix

    Parameters

    m

    matrix

    row

    row values to append

    Return Value

    new matrix with appended row

  • Prepend row to matrix.

    Declaration

    Swift

    public func prepend(_ m: Matrix, row: Matrix) -> Matrix

    Parameters

    m

    matrix

    row

    row values to prepend represented as row matrix

    Return Value

    new matrix with prepended row

  • Prepend row to matrix.

    Alternatively, prepend(m, row: row) can be executed with row === m.

    Declaration

    Swift

    public func prepend(_ m: Matrix, row: Vector) -> Matrix

    Parameters

    m

    matrix

    row

    row values to prepend

    Return Value

    new matrix with prepended row

  • Prepend row to matrix constructed from scalar value.

    Alternatively, prepend(m, row: row) can be executed with row === m.

    Declaration

    Swift

    public func prepend(_ m: Matrix, row: Double) -> Matrix

    Parameters

    m

    matrix

    row

    row value to prepend

    Return Value

    new matrix with prepended row

  • Prepend rows to matrix.

    Alternatively, prepend(m, rows: rows) can be executed with rows === m.

    Declaration

    Swift

    public func prepend(_ m: Matrix, rows: Matrix) -> Matrix

    Parameters

    m

    matrix

    rows

    rows values to prepend represented as matrix

    Return Value

    new matrix with prepended rows

  • Prepend rows to matrix.

    Declaration

    Swift

    public func prepend(_ m: Matrix, rows: [Vector]) -> Matrix

    Parameters

    m

    matrix

    rows

    rows values to prepended represented as array of vectors

    Return Value

    new matrix with prepended rows

  • Prepend row to matrix constructed from scalar value.

    Alternatively, row === m can be executed with prepend(m, row: row).

    Declaration

    Swift

    public func === (row: Double, m: Matrix) -> Matrix

    Parameters

    row

    row value to prepend

    m

    matrix

    Return Value

    new matrix with prepended row

  • Prepend row to matrix.

    Alternatively, row === m can be executed with prepend(m, row: row).

    Declaration

    Swift

    public func === (row: Vector, m: Matrix) -> Matrix

    Parameters

    row

    row values to prepend

    m

    matrix

    Return Value

    new matrix with prepended row

  • Horizontally concatenate two matrices. It is similar to appending rhs as rows to lhs

    Alternatively, lhs === rhs can be executed with append(lhs, rows: rhs).

    Declaration

    Swift

    public func === (lhs: Matrix, rhs: Matrix) -> Matrix
  • Insert column to matrix at specified position.

    Declaration

    Swift

    public func insert(_ m: Matrix, col: Vector, at index: Int) -> Matrix

    Parameters

    m

    matrix

    cols

    column values to insert

    at

    index to insert column to

    Return Value

    new matrix with inserted column

  • Insert columns to matrix at specified position.

    Declaration

    Swift

    public func insert(_ m: Matrix, cols: Matrix, at index: Int) -> Matrix

    Parameters

    m

    matrix

    cols

    columns values to insert represented as matrix

    at

    index to insert columns to

    Return Value

    new matrix with inserted columns

  • Append column to matrix.

    Declaration

    Swift

    public func append(_ m: Matrix, col: Matrix) -> Matrix

    Parameters

    m

    matrix

    col

    column values to append represented as column matrix

    Return Value

    new matrix with appended column

  • Append column to matrix.

    Alternatively, append(m, col: col) can be executed with m ||| col.

    Declaration

    Swift

    public func append(_ m: Matrix, col: Vector) -> Matrix

    Parameters

    m

    matrix

    col

    column values to append

    Return Value

    new matrix with appended column

  • Append column to matrix constructed from scalar value.

    Alternatively, append(m, col: col) can be executed with m ||| col.

    Declaration

    Swift

    public func append(_ m: Matrix, col: Double) -> Matrix

    Parameters

    m

    matrix

    col

    column value to append

    Return Value

    new matrix with appended column

  • Append columns to matrix.

    Alternatively, append(m, cols: cols) can be executed with m ||| cols.

    Declaration

    Swift

    public func append(_ m: Matrix, cols: Matrix) -> Matrix

    Parameters

    m

    matrix

    cols

    columns values to append represented as matrix

    Return Value

    new matrix with appended columns

  • Append columns to matrix.

    Declaration

    Swift

    public func append(_ m: Matrix, cols: [Vector]) -> Matrix

    Parameters

    m

    matrix

    cols

    columns values to append represented as array of vectors

    Return Value

    new matrix with appended columns

  • Append column to matrix constructed from scalar value.

    Alternatively, m ||| col can be executed with append(m, col: col).

    Declaration

    Swift

    public func ||| (m: Matrix, col: Double) -> Matrix

    Parameters

    m

    matrix

    col

    column value to append

    Return Value

    new matrix with appended column

  • Append column to matrix.

    Alternatively, m ||| col can be executed with append(m, col: col).

    Declaration

    Swift

    public func ||| (m: Matrix, col: Vector) -> Matrix

    Parameters

    m

    matrix

    col

    column values to append

    Return Value

    new matrix with appended column

  • Prepend column to matrix.

    Declaration

    Swift

    public func prepend(_ m: Matrix, col: Matrix) -> Matrix

    Parameters

    m

    matrix

    col

    column values to prepend represented as column matrix

    Return Value

    new matrix with prepended column

  • Prepend column to matrix.

    Alternatively, prepend(m, col: col) can be executed with col ||| m.

    Declaration

    Swift

    public func prepend(_ m: Matrix, col: Vector) -> Matrix

    Parameters

    m

    matrix

    col

    column values to prepend

    Return Value

    new matrix with prepended column

  • Prepend column to matrix constructed from scalar value.

    Alternatively, prepend(m, col: col) can be executed with col ||| m.

    Declaration

    Swift

    public func prepend(_ m: Matrix, col: Double) -> Matrix

    Parameters

    m

    matrix

    col

    column value to prepend

    Return Value

    new matrix with prepended column

  • Prepend columns to matrix.

    Alternatively, prepend(m, cols: cols) can be executed with cols ||| m.

    Declaration

    Swift

    public func prepend(_ m: Matrix, cols: Matrix) -> Matrix

    Parameters

    m

    matrix

    cols

    columns values to prepend represented as matrix

    Return Value

    new matrix with prepended columns

  • Prepend columns to matrix.

    Declaration

    Swift

    public func prepend(_ m: Matrix, cols: [Vector]) -> Matrix

    Parameters

    m

    matrix

    cols

    columns values to prepended represented as array of vectors

    Return Value

    new matrix with prepended columns

  • Prepend column to matrix constructed from scalar value.

    Alternatively, col ||| m can be executed with prepend(m, col: col).

    Declaration

    Swift

    public func ||| (col: Double, m: Matrix) -> Matrix

    Parameters

    col

    column value to prepend

    m

    matrix

    Return Value

    new matrix with prepended column

  • Prepend column to matrix.

    Alternatively, col ||| m can be executed with prepend(m, col: col).

    Declaration

    Swift

    public func ||| (col: Vector, m: Matrix) -> Matrix

    Parameters

    col

    column values to prepend

    m

    matrix

    Return Value

    new matrix with prepended column

  • Vertically concatenate two matrices. It is similar to appending rhs as columns to lhs

    Alternatively, lhs ||| rhs can be executed with append(lhs, cols: rhs).

    Declaration

    Swift

    public func ||| (lhs: Matrix, rhs: Matrix) -> Matrix

Slicing

  • Construct new matrix from source using specified extractor

    Alternatively, slice(m, e) can be executed with m ?? e or m[e].

    Declaration

    Swift

    public func slice(_ m: Matrix, _ e: (er: Extractor, ec: Extractor)) -> Matrix

    Return Value

    extracted matrix

  • Construct new matrix from source using specified extractor.

    Alternatively, m ?? e can be executed with slice(m, e) or m[e].

    Declaration

    Swift

    public func ?? (m: Matrix, e: (er: Extractor, ec: Extractor)) -> Matrix

    Return Value

    extracted matrix

Map-reduce

  • Map all elements of source matrix to new matrix using specified function.

    Declaration

    Swift

    public func map(_ A: Matrix, _ f: ((Double) -> Double)) -> Matrix

    Return Value

    mapped matrix

  • Map all elements of source matrix to new matrix using specified function which operates on vectors.

    Declaration

    Swift

    public func map(_ A: Matrix, _ f: ((Vector) -> Vector)) -> Matrix

    Return Value

    mapped matrix

  • Perform reduce operation on a matrix using specified function within the specified dimension.

    Declaration

    Swift

    public func reduce(_ A: Matrix, _ f: ((Vector) -> Double), _ d: Dim = .Row) -> Vector

    Return Value

    vector of reduced values

Matrix comparison

  • Check if two matrices are equal using Double value approximate comparison

    Declaration

    Swift

    public func == (lhs: Matrix, rhs: Matrix) -> Bool
  • Check if two matrices are not equal using Double value approximate comparison

    Declaration

    Swift

    public func != (lhs: Matrix, rhs: Matrix) -> Bool
  • Check if one matrix is greater than another using Double value approximate comparison

    Declaration

    Swift

    public func > (lhs: Matrix, rhs: Matrix) -> Bool
  • Check if one matrix is less than another using Double value approximate comparison

    Declaration

    Swift

    public func < (lhs: Matrix, rhs: Matrix) -> Bool
  • Check if one matrix is greater than or equal to another using Double value approximate comparison

    Declaration

    Swift

    public func >= (lhs: Matrix, rhs: Matrix) -> Bool
  • Check if one matrix is less than or equal to another using Double value approximate comparison

    Declaration

    Swift

    public func <= (lhs: Matrix, rhs: Matrix) -> Bool

Linear algebra operations on matrices

  • Compute the trace of a matrix.

    Declaration

    Swift

    public func trace(_ A: Matrix) -> Double

    Parameters

    A

    matrix to compute trace of

    Return Value

    sum of the elements on the main diagonal

  • Transpose matrix.

    Alternatively, transpose(A) can be executed with A′.

    Declaration

    Swift

    public func transpose(_ A: Matrix) -> Matrix

    Return Value

    transposed matrix

  • Transpose matrix.

    Alternatively, A′ can be executed with transpose(A).

    Declaration

    Swift

    public postfix func  (a: Matrix) -> Matrix

    Return Value

    transposed matrix

  • Perform matrix multiplication.

    Alternatively, mtimes(A, B) can be executed with A * B.

    Declaration

    Swift

    public func mtimes(_ A: Matrix, _ B: Matrix) -> Matrix

    Return Value

    matrix product of A and B

  • Perform matrix multiplication.

    Alternatively, A * B can be executed with mtimes(A, B).

    Declaration

    Swift

    public func * (A: Matrix, B: Matrix) -> Matrix

    Return Value

    matrix product of A and B

  • Raise matrix to specified power (integer value).

    If power is 1, source matrix is returned If power is -1, inverted matrix is returned If power is > 1, continuous matrix product result is returned (eg mpower(A, 2) = mtimes(A, A)) If power is < -1, continuous matrix product of inverted matrix result is returned All other values are invalid

    Alternatively, mpower(A, p) can be executed with A ^ p.

    Declaration

    Swift

    public func mpower(_ A: Matrix, _ p: Int) -> Matrix

    Return Value

    matrix A raised to power p

  • Raise matrix to specified power (integer value).

    If power is 1, source matrix is returned If power is -1, inverted matrix is returned If power is > 1, continuous matrix product result is returned (eg A ^ 2 = mtimes(A, A)) If power is < -1, continuous matrix product of inverted matrix result is returned All other values are invalid

    Alternatively, A ^ p can be executed with mpower(A, p).

    Declaration

    Swift

    public func ^ (a: Matrix, p: Int) -> Matrix

    Return Value

    matrix A raised to power p

  • Compute the inverse of a given square matrix.

    A precondition error is thrown if the given matrix is singular or algorithm fails to converge.

    Declaration

    Swift

    public func inv(_ A: Matrix) -> Matrix

    Parameters

    A

    square matrix to invert

    Return Value

    inverse of A matrix

  • Compute eigen values and vectors of a given square matrix.

    A precondition error is thrown if the algorithm fails to converge.

    Declaration

    Swift

    public func eig(_ A: Matrix) -> (V: Matrix, D: Matrix)

    Parameters

    A

    square matrix to calculate eigen values and vectors of

    Return Value

    eigenvectors matrix (by rows) and diagonal matrix with eigenvalues on the main diagonal

  • Perform a singular value decomposition of a given matrix.

    Declaration

    Swift

    public func svd(_ A: Matrix) -> (U: Matrix, S: Matrix, V: Matrix)

    Parameters

    A

    matrix to find singular values of

    Return Value

    matrices U, S, and V such that A = U * S * transpose(V)

  • Perform a generalized singular value decomposition of 2 given matrices.

    Declaration

    Swift

    public func gsvd(_ A: Matrix, _ B: Matrix) -> (U: Matrix, V: Matrix, Q: Matrix, alpha: Vector, beta: Vector, success: Bool)

    Parameters

    A

    first matrix

    B

    second matrix

    Return Value

    matrices U, V, and Q, plus vectors alpha and beta

  • Compute the Cholesky factorization of a real symmetric positive definite matrix.

    A precondition error is thrown if the algorithm fails to converge.

    Declaration

    Swift

    public func chol(_ A: Matrix, _ t: Triangle = .Upper) -> Matrix

    Parameters

    A

    square matrix to compute Cholesky factorization of

    t

    Triangle value (.Upper, .Lower)

    Return Value

    upper triangular matrix U so that A = U' * U or lower triangular matrix L so that A = L * L'

  • Return the upper/lower triangular part of a given matrix.

    Declaration

    Swift

    public func tri(_ A: Matrix, _ t: Triangle) -> Matrix

    Parameters

    A

    matrix

    t

    Triangle value (.Upper, .Lower)

    Return Value

    upper/lower triangular part

  • Compute the determinant of a given square matrix.

    A precondition error is thrown if the given matrix is singular or algorithm fails to converge.

    Declaration

    Swift

    public func det(_ A: Matrix) -> Double

    Parameters

    A

    square matrix=

    Return Value

    determinant of A matrix

  • Return the result of convolving the given matrix with the provided kernel.

    Declaration

    Swift

    @available(iOS 13.0, macOS 10.15, tvOS 13.0, *)
    public func convolve(_ A: Matrix, _ K: Matrix) -> Matrix

    Parameters

    A

    Matrix

    K

    Matrix (Needs to be smaller in dimension than A)

    Return Value

    Matrix result of the convolution

Matrix-Matrix arithmetics

  • Perform matrix addition.

    Alternatively, plus(A, B) can be executed with A + B.

    Declaration

    Swift

    public func plus(_ A: Matrix, _ B: Matrix) -> Matrix

    Return Value

    elementwise matrix sum of A and B

  • Perform matrix addition.

    Alternatively, A + B can be executed with plus(A, B).

    Declaration

    Swift

    public func + (A: Matrix, B: Matrix) -> Matrix

    Return Value

    elementwise matrix sum of A and B

  • Perform matrix substraction.

    Alternatively, minus(A, B) can be executed with A - B.

    Declaration

    Swift

    public func minus(_ A: Matrix, _ B: Matrix) -> Matrix

    Return Value

    elementwise matrix difference of A and B

  • Perform matrix substraction.

    Alternatively, A - B can be executed with minus(A, B).

    Declaration

    Swift

    public func - (A: Matrix, B: Matrix) -> Matrix

    Return Value

    elementwise matrix difference of A and B

  • Perform matrix multiplication.

    Alternatively, times(A, B) can be executed with A .* B.

    Declaration

    Swift

    public func times(_ A: Matrix, _ B: Matrix) -> Matrix

    Return Value

    elementwise matrix product of A and B

  • Perform matrix multiplication.

    Alternatively, A .* B can be executed with times(A, B).

    Declaration

    Swift

    public func .* (A: Matrix, B: Matrix) -> Matrix

    Return Value

    elementwise matrix product of A and B

  • Perform matrix right division.

    Alternatively, rdivide(A, B) can be executed with A ./ B.

    Declaration

    Swift

    public func rdivide(_ A: Matrix, _ B: Matrix) -> Matrix

    Return Value

    result of elementwise division of A by B

  • Perform matrix right division.

    Alternatively, A ./ B can be executed with rdivide(A, B).

    Declaration

    Swift

    public func ./ (A: Matrix, B: Matrix) -> Matrix

    Return Value

    result of elementwise division of A by B

  • Perform matrix left division.

    Alternatively, ldivide(A, B) can be executed with A ./. B.

    Declaration

    Swift

    public func ldivide(_ A: Matrix, _ B: Matrix) -> Matrix

    Return Value

    result of elementwise division of B by A

  • Perform matrix left division.

    Alternatively, A ./. B can be executed with ldivide(A, B).

Matrix-Scalar arithmetics

  • Perform matrix and scalar addition.

    Scalar value expands to matrix dimensions and elementwise matrix addition is performed.

    Alternatively, plus(A, b) can be executed with A + b.

    Declaration

    Swift

    public func plus(_ A: Matrix, _ b: Double) -> Matrix

    Return Value

    elementwise sum of matrix A and scalar b

  • Perform matrix and scalar addition.

    Scalar value expands to matrix dimensions and elementwise matrix addition is performed.

    Alternatively, A + b can be executed with plus(A, b).

    Declaration

    Swift

    public func + (A: Matrix, b: Double) -> Matrix

    Return Value

    elementwise sum of matrix A and scalar b

  • Perform scalar and matrix addition.

    Scalar value expands to matrix dimensions and elementwise matrix addition is performed.

    Alternatively, plus(a, B) can be executed with a + B.

    Declaration

    Swift

    public func plus(_ a: Double, _ B: Matrix) -> Matrix

    Return Value

    elementwise sum of scalar a and matrix B

  • Perform scalar and matrix addition.

    Scalar value expands to matrix dimensions and elementwise matrix addition is performed.

    Alternatively, a + B can be executed with plus(a, B).

    Declaration

    Swift

    public func + (a: Double, B: Matrix) -> Matrix

    Return Value

    elementwise sum of scalar a and matrix B

  • Perform matrix and scalar substraction.

    Scalar value expands to matrix dimensions and elementwise matrix substraction is performed.

    Alternatively, minus(A, b) can be executed with A - b.

    Declaration

    Swift

    public func minus(_ A: Matrix, _ b: Double) -> Matrix

    Return Value

    elementwise difference of matrix A and scalar b

  • Perform matrix and scalar substraction.

    Scalar value expands to matrix dimensions and elementwise matrix substraction is performed.

    Alternatively, A - b can be executed with minus(A, b).

    Declaration

    Swift

    public func - (A: Matrix, b: Double) -> Matrix

    Return Value

    elementwise difference of matrix A and scalar b

  • Perform scalar and matrix substraction.

    Scalar value expands to matrix dimensions and elementwise matrix addition is performed.

    Alternatively, minus(a, B) can be executed with a - B.

    Declaration

    Swift

    public func minus(_ a: Double, _ B: Matrix) -> Matrix

    Return Value

    elementwise difference of scalar a and matrix B

  • Perform scalar and matrix substraction.

    Scalar value expands to matrix dimensions and elementwise matrix addition is performed.

    Alternatively, a - B can be executed with minus(a, B).

    Declaration

    Swift

    public func - (a: Double, B: Matrix) -> Matrix

    Return Value

    elementwise difference of scalar a and matrix B

  • Perform matrix and scalar multiplication.

    Scalar value expands to matrix dimensions and elementwise matrix multiplication is performed.

    Alternatively, times(A, b) can be executed with A .* b.

    Declaration

    Swift

    public func times(_ A: Matrix, _ b: Double) -> Matrix

    Return Value

    elementwise product of matrix A and scalar b

  • Perform matrix and scalar multiplication.

    Scalar value expands to matrix dimensions and elementwise matrix multiplication is performed.

    Alternatively, A .* b can be executed with times(A, b).

    Declaration

    Swift

    public func .* (A: Matrix, b: Double) -> Matrix

    Return Value

    elementwise product of matrix A and scalar b

  • Perform scalar and matrix multiplication.

    Scalar value expands to matrix dimensions and elementwise matrix multiplication is performed.

    Alternatively, times(a, B) can be executed with a .* B.

    Declaration

    Swift

    public func times(_ a: Double, _ B: Matrix) -> Matrix

    Return Value

    elementwise product of scalar a and matrix B

  • Perform scalar and matrix multiplication.

    Scalar value expands to matrix dimensions and elementwise matrix multiplication is performed.

    Alternatively, a .* B can be executed with times(a, B).

    Declaration

    Swift

    public func .* (a: Double, B: Matrix) -> Matrix

    Return Value

    elementwise product of scalar a and matrix B

  • Perform matrix and scalar right division.

    Scalar value expands to matrix dimensions and elementwise matrix right division is performed.

    Alternatively, rdivide(A, b) can be executed with A ./ b.

    Declaration

    Swift

    public func rdivide(_ A: Matrix, _ b: Double) -> Matrix

    Return Value

    result of elementwise division of matrix A by scalar b

  • Perform matrix and scalar right division.

    Scalar value expands to matrix dimensions and elementwise matrix right division is performed.

    Alternatively, A ./ b can be executed with rdivide(A, b).

    Declaration

    Swift

    public func ./ (A: Matrix, b: Double) -> Matrix

    Return Value

    result of elementwise division of matrix A by scalar b

  • Perform scalar and matrix right division.

    Scalar value expands to matrix dimensions and elementwise matrix right division is performed.

    Alternatively, rdivide(a, B) can be executed with a ./ B.

    Declaration

    Swift

    public func rdivide(_ a: Double, _ B: Matrix) -> Matrix

    Return Value

    result of elementwise division of scalar a by matrix B

  • Perform scalar and matrix right division.

    Scalar value expands to matrix dimension and elementwise matrix right division is performed.

    Alternatively, a ./ B can be executed with rdivide(a, B).

    Declaration

    Swift

    public func ./ (a: Double, B: Matrix) -> Matrix

    Return Value

    result of elementwise division of scalar a by matrix B

  • Perform matrix and scalar left division.

    Scalar value expands to matrix dimensions and elementwise matrix left division is performed.

    Alternatively, ldivide(A, b) can be executed with A ./. b.

    Declaration

    Swift

    public func ldivide(_ A: Matrix, _ b: Double) -> Matrix

    Return Value

    result of elementwise division of scalar b by matrix A

  • Perform scalar and matrix left division.

    Scalar value expands to matrix dimensions and elementwise matrix left division is performed.

    Alternatively, ldivide(a, B) can be executed with a ./. B.

    Declaration

    Swift

    public func ldivide(_ a: Double, _ B: Matrix) -> Matrix

    Return Value

    result of elementwise division of matrix B by scalar a

Matrix-Vector arithmetics

  • Perform matrix and vector addition.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, plus(A, b) can be executed with A + b.

    Declaration

    Swift

    public func plus(_ A: Matrix, _ b: Vector) -> Matrix

    Return Value

    elementwise sum of matrix A and vector b

  • Perform matrix and vector addition.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, A + b can be executed with plus(A, b).

    Declaration

    Swift

    public func + (A: Matrix, b: Vector) -> Matrix

    Return Value

    elementwise sum of matrix A and vector b

  • Perform vector and matrix addition.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, plus(a, B) can be executed with a + B.

    Declaration

    Swift

    public func plus(_ a: Vector, _ B: Matrix) -> Matrix

    Return Value

    elementwise sum of vector a and matrix B

  • Perform vector and matrix addition.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, a + B can be executed with plus(a, B).

    Declaration

    Swift

    public func + (a: Vector, B: Matrix) -> Matrix

    Return Value

    elementwise sum of vector a and matrix B

  • Perform matrix and vector substraction.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, minus(A, b) can be executed with A - b.

    Declaration

    Swift

    public func minus(_ A: Matrix, _ b: Vector) -> Matrix

    Return Value

    elementwise difference of matrix A and vector b

  • Perform matrix and vector substraction.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, A - b can be executed with minus(A, b).

    Declaration

    Swift

    public func - (A: Matrix, b: Vector) -> Matrix

    Return Value

    elementwise difference of matrix A and vector b

  • Perform vector and matrix substraction.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, minus(a, B) can be executed with a - B.

    Declaration

    Swift

    public func minus(_ a: Vector, _ B: Matrix) -> Matrix

    Return Value

    elementwise difference of vector a and matrix B

  • Perform vector and matrix substraction.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, a - B can be executed with minus(a, B).

    Declaration

    Swift

    public func - (a: Vector, B: Matrix) -> Matrix

    Return Value

    elementwise difference of vector a and matrix B

  • Perform matrix and vector multiplication.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, times(A, b) can be executed with A .* b.

    Declaration

    Swift

    public func times(_ A: Matrix, _ b: Vector) -> Matrix

    Return Value

    elementwise product of matrix A and vector b

  • Perform matrix and vector multiplication.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, A .* b can be executed with times(A, b).

    Declaration

    Swift

    public func .* (A: Matrix, b: Vector) -> Matrix

    Return Value

    elementwise product of matrix A and vector b

  • Perform vector and matrix multiplication.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, times(a, B) can be executed with a .* B.

    Declaration

    Swift

    public func times(_ a: Vector, _ B: Matrix) -> Matrix

    Return Value

    elementwise product of vector a and matrix B

  • Perform vector and matrix multiplication.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, a .* B can be executed with times(a, B).

    Declaration

    Swift

    public func .* (a: Vector, B: Matrix) -> Matrix

    Return Value

    elementwise product of vector a and matrix B

  • Perform matrix and vector right division.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, rdivide(A, b) can be executed with A ./ b.

    Declaration

    Swift

    public func rdivide(_ A: Matrix, _ b: Vector) -> Matrix

    Return Value

    result of elementwise division of matrix A by vector b

  • Perform matrix and vector right division.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, A ./ b can be executed with rdivide(A, b).

    Declaration

    Swift

    public func ./ (A: Matrix, b: Vector) -> Matrix

    Return Value

    result of elementwise division of matrix A by vector b

  • Perform vector and matrix right division.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, rdivide(a, B) can be executed with a ./ B.

    Declaration

    Swift

    public func rdivide(_ a: Vector, _ B: Matrix) -> Matrix

    Return Value

    result of elementwise division of vector a by matrix B

  • Perform vector and matrix right division.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, a ./ B can be executed with rdivide(a, B).

    Declaration

    Swift

    public func ./ (a: Vector, B: Matrix) -> Matrix

    Return Value

    result of elementwise division of vector a by matrix B

  • Perform matrix and vector left division.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, ldivide(A, b) can be executed with A ./. b.

    Declaration

    Swift

    public func ldivide(_ A: Matrix, _ b: Vector) -> Matrix

    Return Value

    result of elementwise division of vector b by matrix A

  • Perform vector and matrix left division.

    Vector value expands to matrix dimensions (by rows) and elementwise matrix addition is performed.

    Alternatively, ldivide(a, B) can be executed with a ./. B.

    Declaration

    Swift

    public func ldivide(_ a: Vector, _ B: Matrix) -> Matrix

    Return Value

    result of elementwise division of matrix B by vector a

Sign operations on matrix

  • Absolute value of matrix.

    Declaration

    Swift

    public func abs(_ A: Matrix) -> Matrix

    Return Value

    matrix of absolute values of elements of matrix A

  • Negation of matrix.

    Alternatively, uminus(A) can be executed with -A.

    Declaration

    Swift

    public func uminus(_ A: Matrix) -> Matrix

    Return Value

    matrix of negated values of elements of matrix A

  • Negation of matrix.

    Alternatively, -A can be executed with uminus(A).

    Declaration

    Swift

    public prefix func - (A: Matrix) -> Matrix

    Return Value

    matrix of negated values of elements of matrix A

  • Threshold function on matrix.

    Declaration

    Swift

    public func thr(_ A: Matrix, _ t: Double) -> Matrix

    Return Value

    matrix with values less than certain value set to 0 and keeps the value otherwise

Power and exponential functions

  • Exponentiation function, returning matrix raised to power.

    Alternatively, power(A, p) can be executed with A .^ p.

    Mathematically, power would return a complex number when base is negative and power is not an integral value. power can’t do that, so instead it signals domain error (returns ±NaN).

    Declaration

    Swift

    public func power(_ A: Matrix, _ b: Double) -> Matrix

    Return Value

    elementwise matrix power of a raised to p

  • Exponentiation function, returning matrix raised to power.

    Alternatively, A .^ p can be executed with power(A, p).

    Mathematically, power would return a complex number when base is negative and power is not an integral value. power can’t do that, so instead it signals domain error (returns ±NaN).

    Declaration

    Swift

    public func .^ (A: Matrix, p: Double) -> Matrix

    Return Value

    elementwise matrix power of a raised to p

  • Exponentiation function, returning matrix raised to power of 2.

    Declaration

    Swift

    public func square(_ A: Matrix) -> Matrix

    Return Value

    elementwise vector power of a matrix to power of 2

  • Exponentiation function, returning square root of matrix.

    Mathematically, sqrt would return a complex number when base is negative. sqrt can’t do that, so instead it signals domain error (returns ±NaN).

    Declaration

    Swift

    public func sqrt(_ A: Matrix) -> Matrix

    Return Value

    elementwise square root of matrix A

  • Compute e (the base of natural logarithms) raised to the power A.

    If the magnitude of the result is too large to be representable, exp signals overflow (returns Inf).

    Declaration

    Swift

    public func exp(_ A: Matrix) -> Matrix

    Return Value

    elementwise e raised to the power of matrix A

  • Compute the natural logarithm of A where exp(log(A)) equals A, exactly in mathematics and approximately in C.

    If x is negative, log signals a domain error (returns NaN). If x is zero, it returns negative infinity (-Inf); if x is too close to zero, it may signal overflow.

    Declaration

    Swift

    public func log(_ A: Matrix) -> Matrix

    Return Value

    elementwise natural logarithm of matrix A

  • Return the base-2 logarithm of A, where log2(A) = log(A)/log(2).

    Declaration

    Swift

    public func log2(_ A: Matrix) -> Matrix

    Return Value

    elementwise base-2 logarithm of matrix A

  • Return the base-10 logarithm of A, where log10(A) = log(A)/log(10).

    Declaration

    Swift

    public func log10(_ A: Matrix) -> Matrix

    Return Value

    elementwise base-10 logarithm of matrix A

  • Compute the least squares solution to the overdetermined linear system A*X = B with full rank matrix A.

    A precondition errors throw for mismatched matrix dimensions or if algorithm fails.

    Requires M (rows of A) >= N (cols of A).

    Declaration

    Swift

    public func lstsqr(_ A: Matrix, _ B: Matrix) -> (X: Matrix, R: Matrix)

    Parameters

    A

    MxN matrix

    B

    MxK matrix

    Return Value

    • X: NxK solution matrix
    • R: 1xK residuals

Statistic functions on matrix

  • Return vector of largest elements of matrix in a specified dimension.

    Declaration

    Swift

    public func max(_ A: Matrix, _ d: Dim = .Row) -> Vector
  • Return vector of indices of largest elements of matrix in a specified dimension.

    Declaration

    Swift

    public func maxi(_ A: Matrix, _ d: Dim = .Row) -> [Int]
  • Return vector of smallest elements of matrix in a specified dimension.

    Declaration

    Swift

    public func min(_ A: Matrix, _ d: Dim = .Row) -> Vector
  • Return vector of indices of smallest elements of matrix in a specified dimension.

    Declaration

    Swift

    public func mini(_ A: Matrix, _ d: Dim = .Row) -> [Int]
  • Return vector of mean values of matrix in a specified dimension.

    Declaration

    Swift

    public func mean(_ A: Matrix, _ d: Dim = .Row) -> Vector
  • Return vector of standard deviation values of matrix in a specified dimension.

    Declaration

    Swift

    public func std(_ A: Matrix, _ d: Dim = .Row) -> Vector
  • Return normalized matrix (substract mean value and divide by standard deviation) in dpecified dimension.

    Declaration

    Swift

    public func normalize(_ A: Matrix, _ d: Dim = .Row) -> Matrix

    Return Value

    normalized matrix A

  • Return vector of sums of values of matrix in a specified dimension.

    Declaration

    Swift

    public func sum(_ A: Matrix, _ d: Dim = .Row) -> Vector
  • Return vector of sums of squared values of matrix in a specified dimension.

    Declaration

    Swift

    public func sumsq(_ A: Matrix, _ d: Dim = .Row) -> Vector

Trigonometric functions on matrix

  • Return the sine of A, where A is given in radians and the return value is in the range -1 to 1.

    Declaration

    Swift

    public func sin(_ A: Matrix) -> Matrix

    Return Value

    sine of a matrix values

  • Return the cosine of A, where A is given in radians and the return value is in the range -1 to 1.

    Declaration

    Swift

    public func cos(_ A: Matrix) -> Matrix

    Return Value

    cosine of a matrix values

  • Return the tangent of A, where A is given in radians.

    Mathematically, the tangent function has singularities at odd multiples of pi/2. If the argument x is too close to one of these singularities, tan will return extremely large value.

    Declaration

    Swift

    public func tan(_ A: Matrix) -> Matrix

    Return Value

    tangent of a matrix values

  • Return the arcsine of A, where return value is in the range -pi/2 to pi/2.

    Declaration

    Swift

    public func asin(_ A: Matrix) -> Matrix

    Return Value

    arcsine of a matrix values

  • Return the arccosine of A, where return value is in the range 0 to pi.

    Declaration

    Swift

    public func acos(_ A: Matrix) -> Matrix

    Return Value

    arccosine of a matrix values

  • Return the arctangent of a.

    Declaration

    Swift

    public func atan(_ A: Matrix) -> Matrix

    Return Value

    arctangent of a matrix values

One-line creators for vectors

  • Create a vector of zeros.

    Declaration

    Swift

    public func zeros(_ count: Int) -> Vector

    Parameters

    count

    number of elements

    Return Value

    zeros vector of specified size

  • Create a vector of ones.

    Declaration

    Swift

    public func ones(_ count: Int) -> Vector

    Parameters

    count

    number of elements

    Return Value

    ones vector of specified size

  • Create a vector of uniformly distributed on [0, 1) interval random values.

    Declaration

    Swift

    public func rand(_ count: Int) -> Vector

    Parameters

    count

    number of elements

    Return Value

    random values vector of specified size

  • Create a vector of normally distributed random values.

    Declaration

    Swift

    public func randn(_ count: Int) -> Vector

    Parameters

    count

    number of elements

    Return Value

    random values vector of specified size

Vector comparison

  • Check if two vectors are equal using Double value approximate comparison

    Declaration

    Swift

    public func == (lhs: Vector, rhs: Vector) -> Bool
  • Check if two vectors are not equal using Double value approximate comparison

    Declaration

    Swift

    public func != (lhs: Vector, rhs: Vector) -> Bool
  • Check if one vector is greater than another using Double value approximate comparison

    Declaration

    Swift

    public func > (lhs: Vector, rhs: Vector) -> Bool
  • Check if one vector is less than another using Double value approximate comparison

    Declaration

    Swift

    public func < (lhs: Vector, rhs: Vector) -> Bool
  • Check if one vector is greater than or equal to another using Double value approximate comparison

    Declaration

    Swift

    public func >= (lhs: Vector, rhs: Vector) -> Bool
  • Check if one vector is less than or equal to another using Double value approximate comparison

    Declaration

    Swift

    public func <= (lhs: Vector, rhs: Vector) -> Bool

Arithmetic operations on two vectors

  • Perform vector addition.

    Alternatively, plus(a, b) can be executed with a + b.

    Declaration

    Swift

    public func plus(_ a: Vector, _ b: Vector) -> Vector

    Return Value

    elementwise vector sum of a and b

  • Perform vector addition.

    Alternatively, a + b can be executed with plus(a, b).

    Declaration

    Swift

    public func + (a: Vector, b: Vector) -> Vector

    Return Value

    elementwise vector sum of a and b

  • Perform vector substraction.

    Alternatively, minus(a, b) can be executed with a - b.

    Declaration

    Swift

    public func minus(_ a: Vector, _ b: Vector) -> Vector

    Return Value

    elementwise vector difference of a and b

  • Perform vector substraction.

    Alternatively, a - b can be executed with minus(a, b).

    Declaration

    Swift

    public func - (a: Vector, b: Vector) -> Vector

    Return Value

    elementwise vector difference of a and b

  • Perform vector multiplication.

    Alternatively, times(a, b) can be executed with a .* b.

    Declaration

    Swift

    public func times(_ a: Vector, _ b: Vector) -> Vector

    Return Value

    elementwise vector product of a and b

  • Perform vector multiplication.

    Alternatively, a .* b can be executed with times(a, b).

    Declaration

    Swift

    public func .* (a: Vector, b: Vector) -> Vector

    Return Value

    elementwise vector product of a and b

  • Perform vector right division.

    Alternatively, rdivide(a, b) can be executed with a ./ b.

    Declaration

    Swift

    public func rdivide(_ a: Vector, _ b: Vector) -> Vector

    Return Value

    result of elementwise division of a by b

  • Perform vector right division.

    Alternatively, a ./ b can be executed with rdivide(a, b).

    Declaration

    Swift

    public func ./ (a: Vector, b: Vector) -> Vector

    Return Value

    result of elementwise division of a by b

  • Perform vector left division.

    Alternatively, ldivide(a, b) can be executed with a ./. b.

    Declaration

    Swift

    public func ldivide(_ a: Vector, _ b: Vector) -> Vector

    Return Value

    result of elementwise division of b by a

Dot product operations on two vectors

  • Perform vector dot product operation.

    Alternatively, dot(a, b) can be executed with a * b.

    Declaration

    Swift

    public func dot(_ a: Vector, _ b: Vector) -> Double

    Return Value

    dot product of a and b

  • Perform vector dot product operation.

    Alternatively, a * b can be executed with dot(a, b).

    Declaration

    Swift

    public func * (a: Vector, b: Vector) -> Double

    Return Value

    dot product of a and b

Arithmetic operations on vector and scalar

  • Perform vector and scalar addition.

    Scalar value expands to vector dimension and elementwise vector addition is performed.

    Alternatively, plus(a, b) can be executed with a + b.

    Declaration

    Swift

    public func plus(_ a: Vector, _ b: Double) -> Vector

    Return Value

    elementwise sum of vector a and scalar b

  • Perform vector and scalar addition.

    Scalar value expands to vector dimension and elementwise vector addition is performed.

    Alternatively, a + b can be executed with plus(a, b).

    Declaration

    Swift

    public func + (a: Vector, b: Double) -> Vector

    Return Value

    elementwise sum of vector a and scalar b

  • Perform scalar and vector addition.

    Scalar value expands to vector dimension and elementwise vector addition is performed.

    Alternatively, plus(a, b) can be executed with a + b.

    Declaration

    Swift

    public func plus(_ a: Double, _ b: Vector) -> Vector

    Return Value

    elementwise sum of scalar a and vector b

  • Perform scalar and vector addition.

    Scalar value expands to vector dimension and elementwise vector addition is performed.

    Alternatively, a + b can be executed with plus(a, b).

    Declaration

    Swift

    public func + (a: Double, b: Vector) -> Vector

    Return Value

    elementwise sum of scalar a and vector b

  • Perform vector and scalar substraction.

    Scalar value expands to vector dimension and elementwise vector substraction is performed.

    Alternatively, minus(a, b) can be executed with a - b.

    Declaration

    Swift

    public func minus(_ a: Vector, _ b: Double) -> Vector

    Return Value

    elementwise difference of vector a and scalar b

  • Perform vector and scalar substraction.

    Scalar value expands to vector dimension and elementwise vector substraction is performed.

    Alternatively, a - b can be executed with minus(a, b).

    Declaration

    Swift

    public func - (a: Vector, b: Double) -> Vector

    Return Value

    elementwise difference of vector a and scalar b

  • Perform scalar and vector substraction.

    Scalar value expands to vector dimension and elementwise vector addition is performed.

    Alternatively, minus(a, b) can be executed with a - b.

    Declaration

    Swift

    public func minus(_ a: Double, _ b: Vector) -> Vector

    Return Value

    elementwise difference of scalar a and vector b

  • Perform scalar and vector substraction.

    Scalar value expands to vector dimension and elementwise vector addition is performed.

    Alternatively, a - b can be executed with minus(a, b).

    Declaration

    Swift

    public func - (a: Double, b: Vector) -> Vector

    Return Value

    elementwise difference of scalar a and vector b

  • Perform vector and scalar multiplication.

    Scalar value expands to vector dimension and elementwise vector multiplication is performed.

    Alternatively, times(a, b) can be executed with a .* b.

    Declaration

    Swift

    public func times(_ a: Vector, _ b: Double) -> Vector

    Return Value

    elementwise product of vector a and scalar b

  • Perform vector and scalar multiplication.

    Scalar value expands to vector dimension and elementwise vector multiplication is performed.

    Alternatively, a .* b can be executed with times(a, b).

    Declaration

    Swift

    public func .* (a: Vector, b: Double) -> Vector

    Return Value

    elementwise product of vector a and scalar b

  • Perform scalar and vector multiplication.

    Scalar value expands to vector dimension and elementwise vector multiplication is performed.

    Alternatively, times(a, b) can be executed with a .* b.

    Declaration

    Swift

    public func times(_ a: Double, _ b: Vector) -> Vector

    Return Value

    elementwise product of scalar a and vector b

  • Perform scalar and vector multiplication.

    Scalar value expands to vector dimension and elementwise vector multiplication is performed.

    Alternatively, a .* b can be executed with times(a, b).

    Declaration

    Swift

    public func .* (a: Double, b: Vector) -> Vector

    Return Value

    elementwise product of scalar a and vector b

  • Perform vector and scalar right division.

    Scalar value expands to vector dimension and elementwise vector right division is performed.

    Alternatively, rdivide(a, b) can be executed with a ./ b.

    Declaration

    Swift

    public func rdivide(_ a: Vector, _ b: Double) -> Vector

    Return Value

    result of elementwise division of vector a by scalar b

  • Perform vector and scalar right division.

    Scalar value expands to vector dimension and elementwise vector right division is performed.

    Alternatively, a ./ b can be executed with rdivide(a, b).

    Declaration

    Swift

    public func ./ (a: Vector, b: Double) -> Vector

    Return Value

    result of elementwise division of vector a by scalar b

  • Perform scalar and vector right division.

    Scalar value expands to vector dimension and elementwise vector right division is performed.

    Alternatively, rdivide(a, b) can be executed with a ./ b.

    Declaration

    Swift

    public func rdivide(_ a: Double, _ b: Vector) -> Vector

    Return Value

    result of elementwise division of scalar a by vector b

  • Perform scalar and vector right division.

    Scalar value expands to vector dimension and elementwise vector right division is performed.

    Alternatively, a ./ b can be executed with rdivide(a, b).

    Declaration

    Swift

    public func ./ (a: Double, b: Vector) -> Vector

    Return Value

    result of elementwise division of scalar a by vector b

  • Perform vector and scalar left division.

    Scalar value expands to vector dimension and elementwise vector left division is performed.

    Alternatively, ldivide(a, b) can be executed with a ./. b.

    Declaration

    Swift

    public func ldivide(_ a: Vector, _ b: Double) -> Vector

    Return Value

    result of elementwise division of scalar b by vector a

  • Perform scalar and vector left division.

    Scalar value expands to vector dimension and elementwise vector left division is performed.

    Alternatively, ldivide(a, b) can be executed with a ./. b.

    Declaration

    Swift

    public func ldivide(_ a: Double, _ b: Vector) -> Vector

    Return Value

    result of elementwise division of vector b by scalar a

Sign operations on vector

  • Absolute value of vector.

    Declaration

    Swift

    public func abs(_ a: Vector) -> Vector

    Return Value

    vector of absolute values of elements of vector a

  • Negation of vector.

    Alternatively, uminus(a) can be executed with -a.

    Declaration

    Swift

    public func uminus(_ a: Vector) -> Vector

    Return Value

    vector of negated values of elements of vector a

  • Negation of vector.

    Alternatively, -a can be executed with uminus(a).

    Declaration

    Swift

    public prefix func - (a: Vector) -> Vector

    Return Value

    vector of negated values of elements of vector a

  • Threshold function on vector.

    Declaration

    Swift

    public func thr(_ a: Vector, _ t: Double) -> Vector

    Return Value

    vector with values less than certain value set to 0 and keeps the value otherwise

Power and exponential operations on vector

  • Exponentiation function, returning vector raised to power.

    Alternatively, power(a, p) can be executed with a .^ p.

    Mathematically, power would return a complex number when base is negative and power is not an integral value. power can’t do that, so instead it signals domain error (returns ±NaN).

    Declaration

    Swift

    public func power(_ a: Vector, _ p: Double) -> Vector

    Return Value

    elementwise vector power of a raised to p

  • Exponentiation function, returning vector raised to power.

    Alternatively, a .^ p can be executed with power(a, p).

    Mathematically, power would return a complex number when base is negative and power is not an integral value. power can’t do that, so instead it signals domain error (returns ±NaN).

    Declaration

    Swift

    public func .^ (a: Vector, p: Double) -> Vector

    Return Value

    elementwise vector power of a raised to p

  • Exponentiation function, returning vector raised to power of 2.

    Declaration

    Swift

    public func square(_ a: Vector) -> Vector

    Return Value

    elementwise vector power of a raised to power of 2

  • Exponentiation function, returning square root of vector.

    Mathematically, sqrt would return a complex number when base is negative. sqrt can’t do that, so instead it signals domain error (returns ±NaN).

    Declaration

    Swift

    public func sqrt(_ a: Vector) -> Vector

    Return Value

    elementwise square root of vector a

  • Compute e (the base of natural logarithms) raised to the power a.

    If the magnitude of the result is too large to be representable, exp signals overflow (returns Inf).

    Declaration

    Swift

    public func exp(_ a: Vector) -> Vector

    Return Value

    elementwise e raised to the power of vector a

  • Compute the natural logarithm of a where exp(log(a)) equals a, exactly in mathematics and approximately in C.

    If x is negative, log signals a domain error (returns NaN). If x is zero, it returns negative infinity (-Inf); if x is too close to zero, it may signal overflow.

    Declaration

    Swift

    public func log(_ a: Vector) -> Vector

    Return Value

    elementwise natural logarithm of vector a

  • Return the base-2 logarithm of a, where log2(a) = log(a)/log(2).

    Declaration

    Swift

    public func log2(_ a: Vector) -> Vector

    Return Value

    elementwise base-2 logarithm of vector a

  • Return the base-10 logarithm of a, where log10(a) = log(a)/log(10).

    Declaration

    Swift

    public func log10(_ a: Vector) -> Vector

    Return Value

    elementwise base-10 logarithm of vector a

Statistical operations on vector

  • Return the largest element of vector.

    Declaration

    Swift

    public func max(_ a: Vector) -> Double

    Return Value

    largest element of vector a

  • Return the index of largest element of vector.

    Declaration

    Swift

    public func maxi(_ a: Vector) -> Int

    Return Value

    index of largest element of vector a

  • Return the smallest element of vector.

    Declaration

    Swift

    public func min(_ a: Vector) -> Double

    Return Value

    smallest element of vector a

  • Return the index of smallest element of vector.

    Declaration

    Swift

    public func mini(_ a: Vector) -> Int

    Return Value

    index of smallest element of vector a

  • Return mean (statistically average) value of vector.

    Declaration

    Swift

    public func mean(_ a: Vector) -> Double

    Return Value

    mean value of vector a

  • Return standard deviation value of vector.

    Declaration

    Swift

    public func std(_ a: Vector) -> Double

    Return Value

    standard deviation value of vector a

  • Return normalized vector (substract mean value and divide by standard deviation).

    Declaration

    Swift

    public func normalize(_ a: Vector) -> Vector

    Return Value

    normalized vector a

  • Return sum of vector’s elements.

    Declaration

    Swift

    public func sum(_ a: Vector) -> Double

    Return Value

    sum of elements of vector a

  • Return sum of vector’s squared elements.

    Declaration

    Swift

    public func sumsq(_ a: Vector) -> Double

    Return Value

    sum of squared elements of vector a

Trigonometric operations on vector

  • Return the sine of a, where a is given in radians and the return value is in the range -1 to 1.

    Declaration

    Swift

    public func sin(_ a: Vector) -> Vector

    Return Value

    sine of a vector values

  • Return the cosine of a, where a is given in radians and the return value is in the range -1 to 1.

    Declaration

    Swift

    public func cos(_ a: Vector) -> Vector

    Return Value

    cosine of a vector values

  • Return the tangent of a, where a is given in radians.

    Mathematically, the tangent function has singularities at odd multiples of pi/2. If the argument x is too close to one of these singularities, tan will return extremely large value.

    Declaration

    Swift

    public func tan(_ a: Vector) -> Vector

    Return Value

    tangent of a vector values

  • Return the arcsine of a, where return value is in the range -pi/2 to pi/2.

    Declaration

    Swift

    public func asin(_ a: Vector) -> Vector

    Return Value

    arcsine of a vector values

  • Return the arccosine of a, where return value is in the range 0 to pi.

    Declaration

    Swift

    public func acos(_ a: Vector) -> Vector

    Return Value

    arccosine of a vector values

  • Return the arctangent of a.

    Declaration

    Swift

    public func atan(_ a: Vector) -> Vector

    Return Value

    arctangent of a vector values