MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / canonicalMatrix

Function canonicalMatrix

src/compute-engine/library/linear-algebra.ts:2574–2594  ·  view source on GitHub ↗
(
  ops: ReadonlyArray<Expression>,
  { engine: ce }: { engine: ComputeEngine }
)

Source from the content-addressed store, hash-verified

2572 for (let k = 0; k < j; k++) {
2573 sum += L[j][k] * L[j][k];
2574 }
2575 const val = A[j][j] - sum;
2576 if (val < 0) {
2577 // Matrix is not positive definite
2578 return ce.error('expected-positive-definite-matrix', M.toString());
2579 }
2580 L[j][j] = Math.sqrt(val);
2581 } else {
2582 // Off-diagonal element
2583 for (let k = 0; k < j; k++) {
2584 sum += L[i][k] * L[j][k];
2585 }
2586 if (Math.abs(L[j][j]) < 1e-10) {
2587 return ce.error('expected-positive-definite-matrix', M.toString());
2588 }
2589 L[i][j] = (A[i][j] - sum) / L[j][j];
2590 }
2591 }
2592 }
2593
2594 // Build result matrix
2595 return ce.expr([
2596 'List',
2597 ...L.map((row) => ce.expr(['List', ...row.map((x) => ce.number(x))])),

Callers

nothing calls this directly

Calls 3

isFunctionFunction · 0.90
checkArityFunction · 0.90
_fnMethod · 0.65

Tested by

no test coverage detected