Skip to content

Commit ffdc77f

Browse files
authored
feat: Implement multiplying chains of matrices using dynamic programming (#141)
1 parent aef543b commit ffdc77f

13 files changed

+1453
-2469
lines changed

docs/VECTOR.api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ export function center<S>(A: Matrix<S>): Matrix<S>;
9898
// @public
9999
export function centralDifferenceMatrix(binCount: number): NumberMatrix;
100100

101+
// @public
102+
export function chainProduct<S>(...matrices: Matrix<S>[]): Matrix<S>;
103+
101104
// @public
102105
export interface CholeskyDecomposition<S> {
103106
// (undocumented)
@@ -373,7 +376,7 @@ export function isOrthonormal<S>(matrix: Matrix<S>): boolean;
373376
export function isSparse<S>(vector: Vector<S>): vector is SparseVector<S>;
374377

375378
// @public
376-
export function isSquare(matrix: Matrix<any>): boolean;
379+
export function isSquare<S>(matrix: Matrix<S>): boolean;
377380

378381
// @public
379382
export function isSymmetric<S>(matrix: Matrix<S>): boolean;

docs/api/vector.chainproduct.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@josh-brown/vector](./vector.md) &gt; [chainProduct](./vector.chainproduct.md)
4+
5+
## chainProduct() function
6+
7+
Returns the product of the given array of matrices.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export declare function chainProduct<S>(...matrices: Matrix<S>[]): Matrix<S>;
13+
```
14+
15+
## Parameters
16+
17+
| Parameter | Type | Description |
18+
| --- | --- | --- |
19+
| matrices | [Matrix](./vector.matrix.md)<!-- -->&lt;S&gt;\[\] | The array of matrices to multiply |
20+
21+
<b>Returns:</b>
22+
23+
[Matrix](./vector.matrix.md)<!-- -->&lt;S&gt;
24+
25+
## Remarks
26+
27+
Uses dynamic programming to determine the order of multiplication that minimizes the total number of scalar multiplications.
28+

docs/api/vector.issquare.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ Tests if a matrix is square.
99
<b>Signature:</b>
1010

1111
```typescript
12-
export declare function isSquare(matrix: Matrix<any>): boolean;
12+
export declare function isSquare<S>(matrix: Matrix<S>): boolean;
1313
```
1414

1515
## Parameters
1616

1717
| Parameter | Type | Description |
1818
| --- | --- | --- |
19-
| matrix | [Matrix](./vector.matrix.md)<!-- -->&lt;any&gt; | The matrix to check |
19+
| matrix | [Matrix](./vector.matrix.md)<!-- -->&lt;S&gt; | The matrix to check |
2020

2121
<b>Returns:</b>
2222

docs/api/vector.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
| [center(x)](./vector.center.md) | Returns the vector <code>x</code>, shifted so that its mean is at 0 |
5353
| [center(A)](./vector.center_1.md) | Returns the matrix <code>A</code> with each column shifted so that its mean is at 0 |
5454
| [centralDifferenceMatrix(binCount)](./vector.centraldifferencematrix.md) | Builds a matrix that transforms a vector to a vector of central differences |
55+
| [chainProduct(matrices)](./vector.chainproduct.md) | Returns the product of the given array of matrices. |
5556
| [columnSumSupremumNorm(A)](./vector.columnsumsupremumnorm.md) | Calculates the 1-Norm of a matrix <code>A</code> |
5657
| [correlation(first, second)](./vector.correlation.md) | Calculates the correlation coefficient r of two vectors |
5758
| [correlation(A)](./vector.correlation_1.md) | Calculates the correlation matrix of a matrix <code>A</code> |

0 commit comments

Comments
 (0)