Dense, fully-reduced matrix value: a row-major Array[Double], not n² _Number nodes.
The concrete counterpart of the symbolic matrix node (matrix._Matrix), exactly as _Number is the concrete counterpart of a scalar expression. Lives in core so Environment can bind matrix values without core depending on any domain.
Immutability: the public factory (_MatrixValue$.apply) takes a defensive copy and the storage is private — kernels build results on arrays they own, skipping the copy.
multiply parallelises over independent row blocks above a work-volume threshold; writes are disjoint and require no locking.
Value parameters
- cols
-
number of columns; must be positive
- rows
-
number of rows; must be positive
Attributes
- Companion
- object
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
Element-wise matrix addition.
Element-wise matrix addition.
Value parameters
- that
-
matrix to add; must have the same
rowsandcols
Attributes
Returns the element at row i, column j (zero-based).
Returns the element at row i, column j (zero-based).
Attributes
Sub-expressions subject to recursive structural traversal. Binder positions (e.g. the differentiation variable) are excluded.
Sub-expressions subject to recursive structural traversal. Binder positions (e.g. the differentiation variable) are excluded.
Attributes
- Definition Classes
Cholesky factorisation of a symmetric positive-definite matrix: the lower-triangular L with a positive diagonal and A = L·Lᵀ (F_0054).
Cholesky factorisation of a symmetric positive-definite matrix: the lower-triangular L with a positive diagonal and A = L·Lᵀ (F_0054).
The refusals are the point: its failure is the cheapest convexity test there is, which is what the quadratic-programming tier (F_0053) relies on. A non-square matrix, an asymmetric one — never factored from one triangle, which would answer for a different matrix — and one with a non-positive pivot (indefinite, negative definite, or singular semidefinite) give None. Both tests are relative to the largest entry, at CholeskyTolerance, so rescaling the matrix never moves the verdict.
Attributes
- Returns
-
Some(L)for a symmetric positive-definite matrix,Noneotherwise
Determinant via LU decomposition with partial pivoting, O(n³). None when the matrix is non-square; Some(0.0) when singular (zero pivot). Operates on a defensive clone — the value's storage is untouched.
Determinant via LU decomposition with partial pivoting, O(n³). None when the matrix is non-square; Some(0.0) when singular (zero pivot). Operates on a defensive clone — the value's storage is untouched.
Attributes
- Returns
-
Some(det)for square matrices,Nonefor non-square
Renders this matrix at precision decimal places for REPL display; mirrors _Number.round behaviour.
Renders this matrix at precision decimal places for REPL display; mirrors _Number.round behaviour.
Value parameters
- precision
-
number of decimal places to show
Attributes
Eigenvalues by the Francis double-shift QR iteration: the matrix is balanced, reduced to upper Hessenberg form, and iterated with implicit double shifts (EISPACK balanc, elmhes, hqr). Returns the n eigenvalues as _Number (real) or _Complex (a conjugate pair, +im first).
Eigenvalues by the Francis double-shift QR iteration: the matrix is balanced, reduced to upper Hessenberg form, and iterated with implicit double shifts (EISPACK balanc, elmhes, hqr). Returns the n eigenvalues as _Number (real) or _Complex (a conjugate pair, +im first).
It was a full-matrix QR iteration with a single real shift until F_0100, and declined most random dense matrices from n = 3: it deflated only a trailing 1×1, tested one sub-diagonal entry of a matrix it never reduced to Hessenberg form (so the test did not say the last row was split off), and shifted a trailing complex pair by its real part, which cannot split it. The double shift splits the pair in real arithmetic, and a deflation may happen at any sub-diagonal entry. Every test is relative to the entries it compares, so k·A gives k times the spectrum (the F_0091 rule).
Attributes
- Returns
-
Some(eigenvalues)in deflation order, bottom up;Nonefor a non-square or non-finite matrix, or no convergence within 60 iterations for one eigenvalue
Compares the receiver object (this) with the argument object (that) for equivalence.
Compares the receiver object (this) with the argument object (that) for equivalence.
Any implementation of this method should be an equivalence relation:
- It is reflexive: for any instance
xof typeAny,x.equals(x)should returntrue. - It is symmetric: for any instances
xandyof typeAny,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any instances
x,y, andzof typeAnyifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue.
If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).
Value parameters
- that
-
the object to compare against this object for equality.
Attributes
- Returns
-
trueif the receiver object is equivalent to the argument;falseotherwise. - Definition Classes
-
Any
Returns Right(this) — a concrete matrix needs no further reduction.
Returns Right(this) — a concrete matrix needs no further reduction.
Attributes
- Definition Classes
Matrix exponential e^A = sum(k >= 0) A^k / k!, by scaling and squaring with a degree-13 Padé approximant.
Matrix exponential e^A = sum(k >= 0) A^k / k!, by scaling and squaring with a degree-13 Padé approximant.
Not the eigen route. V·diag(e^λ)·V⁻¹ is tempting because spectralDecompose already exists, but it needs an eigenbasis and a defective matrix has none — and a defective matrix is ordinary in the problems that want this, since a repeated pole produces one. A Jordan block (λ 1; 0 λ) would come back wrong rather than refused. Scaling and squaring is uniform over both cases, which is why it is the standard method.
The identity e^A = (e^(A/2^s))^(2^s) is what makes it work: A is scaled until its norm is inside the Padé approximant's accurate radius, the approximant is evaluated there, and the result is squared back s times.
Note this is matrix Padé — a fixed rational approximant with tabulated coefficients — and is unrelated to the scalar scalar.padeApproximant, which fits a series.
Exactness follows the decomposition precedent rather than matrix/Exact.scala: the exponential is transcendental, so an exact operand demotes to Double exactly as lu/qr/eigen do — "demote an exact operand rather than lose the operation".
Attributes
- Returns
-
Some(e^A)for a square matrix,Nonewhen non-square or non-finite
Lifts this matrix into an Either for use in eval: Right(this) when all elements are finite; Left(orElse) otherwise (non-finite is a domain error — stays symbolic like x / 0). Shared by scalar and matrix packages without requiring cross-imports.
Lifts this matrix into an Either for use in eval: Right(this) when all elements are finite; Left(orElse) otherwise (non-finite is a domain error — stays symbolic like x / 0). Shared by scalar and matrix packages without requiring cross-imports.
Value parameters
- orElse
-
the symbolic fallback expression
Attributes
Inverse via Gauss–Jordan elimination with partial pivoting, O(n³). None when the matrix is non-square or singular — the caller stays symbolic, the same "domain error stays symbolic" contract as x / 0 in scalar.Ratio.
Inverse via Gauss–Jordan elimination with partial pivoting, O(n³). None when the matrix is non-square or singular — the caller stays symbolic, the same "domain error stays symbolic" contract as x / 0 in scalar.Ratio.
Attributes
- Returns
-
Some(A⁻¹)for invertible square matrices,Noneotherwise
Returns true when every element is finite (not NaN, not infinite).
Returns true when every element is finite (not NaN, not infinite).
Attributes
Kronecker product this ⊗ that: the (rows·that.rows) × (cols·that.cols) block matrix whose (i, j) block is this(i, j) · that. The kernel behind the vectorized matrix-equation tier: vec(A·X·B) = (Bᵀ ⊗ A) · vec(X).
Kronecker product this ⊗ that: the (rows·that.rows) × (cols·that.cols) block matrix whose (i, j) block is this(i, j) · that. The kernel behind the vectorized matrix-equation tier: vec(A·X·B) = (Bᵀ ⊗ A) · vec(X).
Value parameters
- that
-
the right factor
Attributes
LU decomposition with partial pivoting: P·A = L·U, where L is unit lower triangular, U is upper triangular, and P is the permutation matrix. None when the matrix is non-square or singular (zero pivot encountered).
LU decomposition with partial pivoting: P·A = L·U, where L is unit lower triangular, U is upper triangular, and P is the permutation matrix. None when the matrix is non-square or singular (zero pivot encountered).
Attributes
- Returns
-
Some((L, U, P))for square non-singular matrices,Noneotherwise
Matrix multiplication this × that (this.cols must equal that.rows).
Matrix multiplication this × that (this.cols must equal that.rows).
Block-tiled i-k-j loop: Tile × Tile blocks keep the hot tile of that (and out) cache-resident across a whole row block. Within each output cell, k-accumulation is ascending, so results are bit-identical to the untiled kernel. Row blocks write disjoint slices of out and parallelise with no locking above the work-volume threshold.
Value parameters
- that
-
right factor;
that.rowsmust equalthis.cols
Attributes
QR decomposition via modified Gram-Schmidt: A = Q·R (m ≥ n). Q is m × n with orthonormal columns; R is n × n upper triangular. None when rows < cols or the matrix is rank-deficient: a column whose orthogonalised norm is at most QrDependenceFactor·max(m, n)·ε times the largest original column norm — relative, so the verdict for k·A is the verdict for A (F_0091).
QR decomposition via modified Gram-Schmidt: A = Q·R (m ≥ n). Q is m × n with orthonormal columns; R is n × n upper triangular. None when rows < cols or the matrix is rank-deficient: a column whose orthogonalised norm is at most QrDependenceFactor·max(m, n)·ε times the largest original column norm — relative, so the verdict for k·A is the verdict for A (F_0091).
Attributes
- Returns
-
Some((Q, R))orNone
Reconstructs the same node shape with replacement sub-expressions.
Reconstructs the same node shape with replacement sub-expressions.
Value parameters
- newChildren
-
replacements in the same order and count as
children
Attributes
- Definition Classes
Multiplies every element by scalar k.
Multiplies every element by scalar k.
Value parameters
- k
-
the scalar factor
Attributes
Spectral decomposition: eigenvalues and right eigenvectors. Returns (columns of V, eigenvalues) where eigenvector column j corresponds to eigenvalue j. Complex conjugate pairs (α ± βi) occupy consecutive positions. An eigenvalue met for the k-th time (within 1e-8 of the largest entry) takes the null vector of the k-th free column, so a repeated eigenvalue with a full eigenspace gets independent eigenvectors; a defective one runs out of free columns. Real eigenvalues since F_0174, complex pairs since F_0175 (counted by their +im member). None when non-square, QR iteration fails, or an eigenvector cannot be extracted (numerically degenerate or defective matrix).
Spectral decomposition: eigenvalues and right eigenvectors. Returns (columns of V, eigenvalues) where eigenvector column j corresponds to eigenvalue j. Complex conjugate pairs (α ± βi) occupy consecutive positions. An eigenvalue met for the k-th time (within 1e-8 of the largest entry) takes the null vector of the k-th free column, so a repeated eigenvalue with a full eigenspace gets independent eigenvectors; a defective one runs out of free columns. Real eigenvalues since F_0174, complex pairs since F_0175 (counted by their +im member). None when non-square, QR iteration fails, or an eigenvector cannot be extracted (numerically degenerate or defective matrix).
Attributes
- Returns
-
Some((V, eigenvalues))orNone
The singular value decomposition A = U·diag(σ)·Vᵀ, economy size (F_0061).
The singular value decomposition A = U·diag(σ)·Vᵀ, economy size (F_0061).
U is m×k and V is n×k with orthonormal columns, k = min(m, n), and σ holds the k singular values in descending order. One-sided Jacobi (Hestenes): column pairs are rotated until every pair is orthogonal, so the singular values come from column norms and small ones keep their relative accuracy — and AᵀA is never formed, which would square the condition number (the 2.11 rule). A wide matrix is decomposed through its transpose. A column whose singular value is numerically zero has no direction of its own, so U is completed there by Gram–Schmidt against the standard basis.
Certified (X-02): the answer is returned only if ‖U·Σ·Vᵀ − A‖ and the departure of U and V from orthonormality are below _MatrixValue.SvdCertificate, relative to ‖A‖.
Attributes
- Returns
-
Some((U, σ, V)), orNonefor a non-finite entry, non-convergence within _MatrixValue.SvdMaxSweeps sweeps, a failed certificate, or work past the default Limit.MaxSvdWork
svd under limits (F_0124): the work max(m, n)·min(m, n)² may be at most Limit.MaxSvdWork. An overload rather than a defaulted parameter, which would be a binary break.
Renders this matrix at Environment.DefaultPrecision decimal places.
Renders this matrix at Environment.DefaultPrecision decimal places.
Attributes
- Definition Classes
-
Any
Read-only view of the dense storage in row-major order.
Read-only view of the dense storage in row-major order.
Attributes
Returns the transpose of this matrix (cols × rows).
Returns the transpose of this matrix (cols × rows).
Attributes
Column-stacking vectorisation: returns the (rows·cols) × 1 column vector where vec[j·rows + i] = this(i, j). Paired with _MatrixValue$.unvec.
Column-stacking vectorisation: returns the (rows·cols) × 1 column vector where vec[j·rows + i] = this(i, j). Paired with _MatrixValue$.unvec.
Attributes
Inherited fields
Cached set of free variable names; O(1) after the first access.
Cached set of free variable names; O(1) after the first access.
Attributes
- Inherited from:
- _Expression