* Compute RREF and return the pivot columns.
( matrix: number[][], tolerance = 1e-10 )
| 2345 | |
| 2346 | // Each side is read as either a list of points or a single point. A side |
| 2347 | // that is neither — a vector, a matrix, a symbolic point — leaves the |
| 2348 | // product to the routes below. |
| 2349 | const sides: Array<ReadonlyArray<Expression> | undefined> = []; |
| 2350 | for (let i = 0; i < 2; i++) { |
| 2351 | if (isList[i]) { |
| 2352 | const points = pointListPoints(ops[i]); |
| 2353 | if (points === undefined) return undefined; |
| 2354 | sides.push(points); |
| 2355 | } else { |
| 2356 | if (pointComponents(ops[i]) === undefined) return undefined; |
| 2357 | sides.push(undefined); |
| 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | const counts = sides.map((s) => s?.length); |
| 2362 | if ( |
| 2363 | counts[0] !== undefined && |
| 2364 | counts[1] !== undefined && |
| 2365 | counts[0] !== counts[1] |
| 2366 | ) |
| 2367 | return ce.error('incompatible-dimensions', `${counts[0]} vs ${counts[1]}`); |
| 2368 | const n = counts[0] ?? counts[1]!; |
| 2369 | |
| 2370 | const results: Expression[] = []; |
| 2371 | for (let i = 0; i < n; i++) { |
| 2372 | const as = pointComponents(sides[0]?.[i] ?? ops[0]); |
| 2373 | const bs = pointComponents(sides[1]?.[i] ?? ops[1]); |
| 2374 | if (as === undefined || bs === undefined) return undefined; |
| 2375 | if (as.length !== bs.length) |
| 2376 | return ce.error( |
| 2377 | 'incompatible-dimensions', |
| 2378 | `${as.length} vs ${bs.length}` |
| 2379 | ); |
| 2380 | // An absent coordinate (`Missing`) makes this point's product |
| 2381 | // `Missing`, as it makes the product of two points `Missing` (see the |
| 2382 | // `Dot` evaluate handler). |
| 2383 | if ([...as, ...bs].some((c) => isAbsentSymbol(c))) { |
| 2384 | results.push(ce.Missing); |
| 2385 | continue; |
| 2386 | } |
| 2387 | if (![...as, ...bs].every((c) => isNumber(c))) return undefined; |
| 2388 | results.push( |
| 2389 | ce |
| 2390 | .function( |
| 2391 | 'Add', |
| 2392 | as.map((a, k) => ce.function('Multiply', [a, bs[k]])) |
| 2393 | ) |
| 2394 | .evaluate({ numericApproximation }) |
| 2395 | ); |
| 2396 | } |
| 2397 | return ce.function('List', results); |
| 2398 | } |
| 2399 | |
| 2400 | /** |
| 2401 | * The inner product when an operand is a list of points that holds |
| 2402 | * restricted or absent points, or `undefined` when no operand is. |
| 2403 | * |
| 2404 | * A restricted point or a restricted list of points whose condition is not |
no test coverage detected