/** * A constrained matrix type. Allows for matrix/vector operations that won't fail due to * incompatible shapes * * @since 1.0.0 */ import * as Apl from 'fp-ts/Applicative'; import * as Fun from 'fp-ts/Functor'; import * as FunI from 'fp-ts/FunctorWithIndex'; import * as Fl from 'fp-ts/Foldable'; import * as FlI from 'fp-ts/FoldableWithIndex'; import * as IO from 'fp-ts/IO'; import { Kind, Kind2, Kind3, Kind4, URIS, URIS2, URIS3, URIS4 } from 'fp-ts/HKT'; import * as Mn from 'fp-ts/Monoid'; import * as O from 'fp-ts/Option'; import * as Rng from 'fp-ts/Ring'; import * as TC from './typeclasses'; import * as V from './Vector'; /** * @since 1.0.0 * @category Model */ export interface Mat extends V.Vec> { _rows: M; _cols: N; } /** * @since 1.0.0 * @category Constructors */ export declare const from2dVectors: (ks: V.Vec>) => Mat; /** * @since 1.0.0 * @category Constructors */ export declare const fromNestedTuples: { (t: []): Mat<0, 0, A>; (t: [[A]]): Mat<1, 1, A>; (t: [[A, A]]): Mat<1, 2, A>; (t: [[A], [A]]): Mat<2, 1, A>; (t: [[A, A], [A, A]]): Mat<2, 2, A>; (t: [[A, A, A]]): Mat<1, 3, A>; (t: [[A], [A], [A]]): Mat<3, 1, A>; (t: [[A, A, A], [A, A, A]]): Mat<2, 3, A>; (t: [[A, A], [A, A], [A, A]]): Mat<3, 2, A>; (t: [[A, A, A], [A, A, A], [A, A, A]]): Mat<3, 3, A>; (t: [[A, A, A, A]]): Mat<1, 4, A>; (t: [[A], [A], [A], [A]]): Mat<4, 1, A>; (t: [[A, A, A, A], [A, A, A, A]]): Mat<2, 4, A>; (t: [[A, A], [A, A], [A, A], [A, A]]): Mat<4, 2, A>; (t: [[A, A, A, A], [A, A, A, A], [A, A, A, A]]): Mat<3, 4, A>; (t: [[A, A, A], [A, A, A], [A, A, A], [A, A, A]]): Mat<4, 3, A>; (t: [[A, A, A, A], [A, A, A, A], [A, A, A, A], [A, A, A, A]]): Mat<4, 4, A>; (t: [[A, A, A, A, A]]): Mat<1, 5, A>; (t: [[A], [A], [A], [A], [A]]): Mat<5, 1, A>; (t: [[A, A, A, A, A], [A, A, A, A, A]]): Mat<2, 5, A>; (t: [[A, A], [A, A], [A, A], [A, A], [A, A]]): Mat<5, 2, A>; (t: [[A, A, A, A, A], [A, A, A, A, A], [A, A, A, A, A]]): Mat<3, 5, A>; (t: [[A, A, A], [A, A, A], [A, A, A], [A, A, A], [A, A, A]]): Mat<5, 3, A>; (t: [[A, A, A, A, A], [A, A, A, A, A], [A, A, A, A, A], [A, A, A, A, A]]): Mat<4, 5, A>; (t: [[A, A, A, A], [A, A, A, A], [A, A, A, A], [A, A, A, A], [A, A, A, A]]): Mat<5, 4, A>; (t: [ [ A, A, A, A, A ], [ A, A, A, A, A ], [ A, A, A, A, A ], [ A, A, A, A, A ], [ A, A, A, A, A ] ]): Mat<5, 5, A>; (t: [[A, A, A, A, A, A]]): Mat<1, 6, A>; (t: [[A], [A], [A], [A], [A], [A]]): Mat<6, 1, A>; (t: [[A, A, A, A, A, A], [A, A, A, A, A, A]]): Mat<2, 6, A>; (t: [[A, A], [A, A], [A, A], [A, A], [A, A], [A, A]]): Mat<6, 2, A>; (t: [[A, A, A, A, A, A], [A, A, A, A, A, A], [A, A, A, A, A, A]]): Mat<3, 6, A>; (t: [[A, A, A], [A, A, A], [A, A, A], [A, A, A], [A, A, A], [A, A, A]]): Mat<6, 3, A>; (t: [[A, A, A, A, A, A], [A, A, A, A, A, A], [A, A, A, A, A, A], [A, A, A, A, A, A]]): Mat<4, 6, A>; (t: [ [ A, A, A, A ], [ A, A, A, A ], [ A, A, A, A ], [ A, A, A, A ], [ A, A, A, A ], [ A, A, A, A ] ]): Mat<6, 4, A>; (t: [ [ A, A, A, A, A, A ], [ A, A, A, A, A, A ], [ A, A, A, A, A, A ], [ A, A, A, A, A, A ], [ A, A, A, A, A, A ] ]): Mat<5, 6, A>; (t: [ [ A, A, A, A, A ], [ A, A, A, A, A ], [ A, A, A, A, A ], [ A, A, A, A, A ], [ A, A, A, A, A ], [ A, A, A, A, A ] ]): Mat<6, 5, A>; (t: [ [ A, A, A, A, A, A ], [ A, A, A, A, A, A ], [ A, A, A, A, A, A ], [ A, A, A, A, A, A ], [ A, A, A, A, A, A ], [ A, A, A, A, A, A ] ]): Mat<6, 6, A>; }; /** * @since 1.0.0 * @category Constructors */ export declare const fromNestedReadonlyArrays: (m: M, n: N) => (as: ReadonlyArray>) => O.Option>; /** * @since 1.0.0 * @category Constructors */ export declare const fromVectorAsRow: (v: V.Vec) => Mat<1, N, A>; /** * @since 1.0.0 * @category Constructors */ export declare const fromVectorAsColumn: (v: V.Vec) => Mat; /** * @since 1.0.0 * @category Constructors */ export declare const makeBy: (m: M, n: N, f: (a: [number, number]) => A) => Mat; /** * Constructs the identity matrix * * @since 1.0.0 * @category Constructors */ export declare const identity: (R: Rng.Ring) => (m: M) => Mat; /** * @since 1.0.0 * @category Constructors */ export declare const repeat: (a: A) => (m: M, n: N) => Mat; /** * @since 1.0.0 * @category Constructors */ export declare const randMatrix: (m: M, n: N, make: IO.IO) => IO.IO>; /** * @since 1.0.0 * @category Constructors */ export declare const outerProduct: (R: Rng.Ring) => (v1: V.Vec, v2: V.Vec) => Mat; /** * Constructs a Vandermonde matrix from a vector. Note: Terms is inclusive of the first * column of ones. So a quadratic Vandermonde matrix has 3 terms. * * @since 1.1.0 * @category Constructors */ export declare const vand: (terms: N) => (t: V.Vec) => Mat; /** * @since 1.0.0 * @category Instances */ export declare const URI = "Mat"; /** * @since 1.0.0 * @category Instances */ export declare type URI = typeof URI; declare module 'fp-ts/HKT' { interface URItoKind3 { readonly [URI]: Mat; } interface URItoKind2 { readonly [URI]: Mat; } } /** * @since 1.1.0 * @category Instances */ export declare const getSquareMonoidProduct: (R: Rng.Ring) => (m: M) => Mn.Monoid>; /** * @since 1.0.0 * @category Instances */ export declare const getAdditiveAbelianGroup: (R: Rng.Ring) => (m: M, n: N) => TC.AbelianGroup>; /** * @since 1.0.0 * @category Instances */ export declare const getBimodule: (R: Rng.Ring) => (m: M, n: N) => TC.Bimodule, A>; /** * @since 1.0.0 * @category Instance Operations */ export declare const map: (f: (a: A) => B) => (v: Mat) => Mat; /** * @since 1.0.0 * @category Instances */ export declare const Functor: Fun.Functor3; /** * @since 1.0.0 * @category Instance Operations */ export declare const mapWithIndex: (f: (ij: [number, number], a: A) => B) => (v: Mat) => Mat; /** * @since 1.0.0 * @category Instances */ export declare const FunctorWithIndex: FunI.FunctorWithIndex3; /** * @since 1.0.0 * @category Instance Operations */ export declare const reduce: (b: B, f: (b: B, a: A) => B) => (fa: Mat) => B; /** * @since 1.0.0 * @category Instance Operations */ export declare const foldMap: (M: Mn.Monoid) => (f: (a: A) => M) => (fa: Mat) => M; /** * @since 1.0.0 * @category Instance Operations */ export declare const reduceRight: (b: A, f: (b: B, a: A) => A) => (fa: Mat) => A; /** * @since 1.0.0 * @category Instances */ export declare const Foldable: Fl.Foldable3; /** * @since 1.0.0 * @category Instance Operations */ export declare const reduceWithIndex: (b: B, f: (i: [number, number], b: B, a: A) => B) => (fa: Mat) => B; /** * @since 1.0.0 * @category Instance Operations */ export declare const foldMapWithIndex: (M: Mn.Monoid) => (f: (i: [number, number], a: A) => M) => (fa: Mat) => M; /** * @since 1.0.0 * @category Instance Operations */ export declare const reduceRightWithIndex: (b: A, f: (i: [number, number], b: B, a: A) => A) => (fa: Mat) => A; /** * @since 1.0.0 * @category Instances */ export declare const FoldableWithIndex: FlI.FoldableWithIndex3; /** * @since 1.0.0 * @category Instance Operations */ export declare function sequence(F: Apl.Applicative4): (ta: Mat>) => Kind4>; export declare function sequence(F: Apl.Applicative3): (ta: Mat>) => Kind3>; export declare function sequence(F: Apl.Applicative2): (ta: Mat>) => Kind2>; export declare function sequence(F: Apl.Applicative1): (ta: Mat>) => Kind>; /** * @since 1.0.0 * @category Instance Operations */ export declare function traverse(F: Apl.Applicative4): (f: (a: A) => Kind4) => (ta: Mat) => Kind4>; export declare function traverse(F: Apl.Applicative3): (f: (a: A) => Kind3) => (ta: Mat) => Kind3>; export declare function traverse(F: Apl.Applicative2): (f: (a: A) => Kind2) => (ta: Mat) => Kind2>; export declare function traverse(F: Apl.Applicative1): (f: (a: A) => Kind) => (ta: Mat) => Kind>; /** * @since 1.0.0 * @category Instance Operations */ export declare function traverseWithIndex(F: Apl.Applicative4): (f: (i: [number, number], a: A) => Kind4) => (ta: Mat) => Kind4>; export declare function traverseWithIndex(F: Apl.Applicative3): (f: (i: [number, number], a: A) => Kind3) => (ta: Mat) => Kind3>; export declare function traverseWithIndex(F: Apl.Applicative2): (f: (i: [number, number], a: A) => Kind2) => (ta: Mat) => Kind2>; export declare function traverseWithIndex(F: Apl.Applicative1): (f: (i: [number, number], a: A) => Kind) => (ta: Mat) => Kind>; /** * @since 1.0.0 * @category Destructors */ export declare const toNestedReadonlyArrays: (m: Mat) => ReadonlyArray>; /** * @since 1.0.0 * @category Destructors */ export declare const toNestedArrays: (m: Mat) => Array>; /** * @since 1.0.0 * @category Destructors */ export declare const shape: (m: Mat) => [M, N]; /** * Map a particular row of a matrix * * @since 1.1.0 * @category Sub-Matrix */ export declare const mapRow: (rowIndex: number, f: (a: A) => A) => (m: Mat) => O.Option>; /** * Reduce the rows of a matrix to a vector of opposite length * * @since 1.1.0 * @category Sub-Matrix */ export declare const reduceByRow: (f: (a: V.Vec) => B) => (m: Mat) => V.Vec; /** * Map a particular column of a matrix * * @since 1.1.0 * @category Sub-Matrix */ export declare const mapColumn: (columnIndex: number, f: (a: A) => A) => (m: Mat) => O.Option>; /** * Reduce the columns of a matrix to a vector of opposite length * * @since 1.1.0 * @category Sub-Matrix */ export declare const reduceByColumn: (f: (a: V.Vec) => B) => (A: Mat) => V.Vec; /** * Used to extract a sub-column from a matrix, and returns a new generic `P` that * represents the length of the sub-column. * * Note: `fromIncl` is the **inclusive** column start-index, and `toExcl` is the * **exclusive** column end-index. If `toExcl` is omitted, then the extracted sub-column * will span to the last row of the matrix. * * Note: In order to preserve type safety, P cannot be inferred, and must be passed * directly as a type argument. * * If `P` is unknown, it can be declared in the parent function as an arbitrary generic * that has a numeric constraint. * * See: Decomposition > QR as an example declaring an unknown length constraint * * @since 1.1.0 * @category Sub-Matrix */ export declare const getSubColumn: (col: number, fromIncl: number, toExcl?: number) =>

(m: Mat) => O.Option>; /** * Used to replace a sub-column of a matrix along with a generic `P` that is the length of * the sub-column. If `P` is incompatible with matrix length `N`, or provided indices will * result in an overflow, `O.none` is returned. * * Note: `fromRowIncl` is the **inclusive** row start-index * * @since 1.1.0 * @category Sub-Matrix */ export declare const updateSubColumn:

(col: number, fromRowIncl: number, repl: V.Vec) => (m: Mat) => O.Option>; /** * Used to extract a portion of a matrix, and returns new generics `P` and `Q` that * represents the the rows / columns of the extracted sub-matrix. * * Note: `rowFromIncl` and `colFromIncl` are the **inclusive** row / column start-indices, * and `rowToExcl` and `colToExcl` are the **exclusive** row / column end-indices. If * `rowToExcl` or `colToExcl` are omitted, the extracted sub-matrix will span to the final * row / column. * * Note: In order to preserve type safety, `P` and `Q` cannot be inferred, and must be * passed directly as type arguments. * * If `P` and `Q` are unknown, they can be declared in the parent function as arbitrary * generics that have a numeric constraint. * * See: Decomposition > QR as an example declaring unknown length constraints * * @since 1.1.0 * @category Sub-Matrix */ export declare const getSubMatrix:

(rowFromIncl: number, colFromIncl: number, rowToExcl?: number, colToExcl?: number) => (m: Mat) => O.Option>; /** * Used to replace a portion of a matrix with generics `P` and `Q` that are the rows / * columns of the replacement sub-matrix. If `P` is incompatible with matrix rows `M`, `Q` * is incompatible with matrix columns `N`, or if provided indices will result in an * overflow, `O.none` is returned. * * Note: `rowFromIncl` and `colFromIncl` are the **inclusive** row / column start-indices * * @since 1.1.0 * @category Sub-Matrix */ export declare const updateSubMatrix:

(rowFromIncl: number, colFromIncl: number, repl: Mat) => (m: Mat) => O.Option>; /** * Add a column at the beginning of a matrix. Due to the limitations of the typesystem, * the length parameter must be passed explicitly, and will be the number of columns of * the returned matrix. * * @since 1.1.0 * @category Sub-Matrix */ export declare const prependColumn: (c0: V.Vec) =>

(m: Mat) => Mat; /** * Add a column at the end of a matrix. Due to the limitations of the typesystem, the * length parameter must be passed explicitly, and will be the number of columns of the * returned matrix. * * @since 1.1.0 * @category Sub-Matrix */ export declare const appendColumn: (c0: V.Vec) =>

(m: Mat) => Mat; /** * Crops a matrix to be square by removing excess rows. Returns O.none if there are more * columns than rows. * * @since 1.1.0 * @category Sub-Matrix */ export declare const cropRows: (m: Mat) => O.Option>; /** * Crops a matrix to be square by removing excess columns. Returns O.none if there are * more columns than rows. * * @since 1.1.0 * @category Sub-Matrix */ export declare const cropColumns: (m: Mat) => O.Option>; /** * @since 1.0.0 * @category Sub-Matrix */ export declare const switchRows: (i: number, j: number) => (vs: Mat) => O.Option>; /** * @since 1.1.0 * @category Sub-Matrix */ export declare const switchColumns: (i: number, j: number) => (vs: Mat) => O.Option>; /** * Multiply two matricies with matching inner dimensions * * ```math * (A ∈ R_mn) (B ∈ R_np) = C ∈ R_mp * ``` * * Efficiency: `2mpn` flops (for numeric Ring) * * @since 1.0.0 * @category Matrix Operations */ export declare const mul: (R: Rng.Ring) => (x: Mat, y: Mat) => Mat; /** * Transform a vector `x` into vector `b` by matrix `A` * * ```math * Ax = b * ``` * * Efficiency: `2mn` flops (for numeric Ring) * * @since 1.0.0 * @category Matrix Operations */ export declare const linMap: (R: Rng.Ring) => (A: Mat, x: V.Vec) => V.Vec; /** * Transform a row-vector `x` into vector `b` by matrix `A` * * ```math * xA = b * ``` * * Efficiency: `2mn` flops (for numeric Ring) * * @since 1.1.0 * @category Matrix Operations */ export declare const linMapR: (R: Rng.Ring) => (x: V.Vec, A: Mat) => V.Vec; /** * The sum of the diagonal elements * * Efficiency: `m` flops (for numeric Ring) * * @since 1.0.0 * @category Matrix Operations */ export declare const trace: (R: Rng.Ring) => (fa: Mat) => A; /** * @since 1.0.0 * @category Matrix Operations */ export declare const transpose: (v: Mat) => Mat; /** * @since 1.0.0 * @category Matrix Operations */ export declare const get: (i: number, j: number) => (m: Mat) => O.Option; /** * @since 1.1.0 * @category Matrix Operations */ export declare const updateAt: (i: number, j: number, a: A) => (A: Mat) => O.Option>; /** * @since 1.0.0 * @category Matrix Operations */ export declare const lift2: (f: (x: A, y: A) => B) => (x: Mat, y: Mat) => Mat; //# sourceMappingURL=Matrix.d.ts.map