@siteimprove/alfa-math 0.108.2 → 0.110.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/matrix.d.ts +2 -1
- package/dist/matrix.js +10 -3
- package/dist/real.d.ts +2 -1
- package/dist/real.js +2 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @siteimprove/alfa-math
|
|
2
2
|
|
|
3
|
+
## 0.110.0
|
|
4
|
+
|
|
5
|
+
## 0.109.0
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- **Added:** `Matrix.multiply` now accepts vectors as the left/right operand, which is turned into a single row/column matrix. ([#1944](https://github.com/Siteimprove/alfa/pull/1944))
|
|
10
|
+
|
|
3
11
|
## 0.108.2
|
|
4
12
|
|
|
5
13
|
## 0.108.1
|
package/dist/matrix.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Vector } from "./vector.js";
|
|
1
2
|
/**
|
|
2
3
|
* {@link https://en.wikipedia.org/wiki/Matrix_(mathematics)}
|
|
3
4
|
*
|
|
@@ -23,7 +24,7 @@ export declare namespace Matrix {
|
|
|
23
24
|
/**
|
|
24
25
|
* {@link https://en.wikipedia.org/wiki/Matrix_multiplication}
|
|
25
26
|
*/
|
|
26
|
-
function multiply(m: Matrix, n: number | Matrix): Matrix;
|
|
27
|
+
function multiply(m: Matrix | Vector, n: number | Matrix | Vector): Matrix;
|
|
27
28
|
/**
|
|
28
29
|
* Compute the transpose of a matrix.
|
|
29
30
|
*
|
package/dist/matrix.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Real } from "./real.js";
|
|
2
|
+
import { Vector } from "./vector.js";
|
|
2
3
|
/**
|
|
3
4
|
* @public
|
|
4
5
|
*/
|
|
@@ -63,9 +64,15 @@ export var Matrix;
|
|
|
63
64
|
* {@link https://en.wikipedia.org/wiki/Matrix_multiplication}
|
|
64
65
|
*/
|
|
65
66
|
function multiply(m, n) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
// If m is a vector, treat it as a single row matrix.
|
|
68
|
+
// [a, b, c] => [[a, b, c]]
|
|
69
|
+
const left = Vector.isVector(m) ? [m] : m;
|
|
70
|
+
// If n is a vector, treat it as a single column matrix.
|
|
71
|
+
// [a, b, c] => [[a], [b], [c]]
|
|
72
|
+
const right = Vector.isVector(n) ? n.map((x) => [x]) : n;
|
|
73
|
+
return typeof right === "number"
|
|
74
|
+
? left.map((r) => r.map((v) => v * right))
|
|
75
|
+
: left.map((r, i) => right[0].map((_, j) => r.reduce((s, _, k) => s + left[i][k] * right?.[k]?.[j], 0)));
|
|
69
76
|
}
|
|
70
77
|
Matrix.multiply = multiply;
|
|
71
78
|
/**
|
package/dist/real.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ export declare namespace Real {
|
|
|
17
17
|
*
|
|
18
18
|
* @remarks
|
|
19
19
|
* The modulo operation is different from the remainder operation supported
|
|
20
|
-
* natively in JavaScript through the
|
|
20
|
+
* natively in JavaScript through the `%` operator. The modulo operation
|
|
21
|
+
* always returns a result with the same sign as the divisor.
|
|
21
22
|
*/
|
|
22
23
|
function modulo(p: number, d: number): number;
|
|
23
24
|
/**
|
package/dist/real.js
CHANGED
|
@@ -33,7 +33,8 @@ export var Real;
|
|
|
33
33
|
*
|
|
34
34
|
* @remarks
|
|
35
35
|
* The modulo operation is different from the remainder operation supported
|
|
36
|
-
* natively in JavaScript through the
|
|
36
|
+
* natively in JavaScript through the `%` operator. The modulo operation
|
|
37
|
+
* always returns a result with the same sign as the divisor.
|
|
37
38
|
*/
|
|
38
39
|
function modulo(p, d) {
|
|
39
40
|
return ((p % d) + d) % d;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "http://json.schemastore.org/package",
|
|
3
3
|
"name": "@siteimprove/alfa-math",
|
|
4
4
|
"homepage": "https://alfa.siteimprove.com",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.110.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Functionality for working with numbers and mathematical structures, such as vectors and matrices",
|
|
8
8
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist/**/*.d.ts"
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@siteimprove/alfa-test": "^0.
|
|
25
|
+
"@siteimprove/alfa-test": "^0.110.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public",
|