@justinelliottcobb/amari-wasm 0.8.7 → 0.9.1
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/README.md +81 -17
- package/amari_wasm.d.ts +67 -67
- package/amari_wasm.js +127 -127
- package/amari_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
|
-
# @justinelliottcobb/amari-wasm v0.
|
|
1
|
+
# @justinelliottcobb/amari-wasm v0.9.0
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Unified Mathematical Computing Library with High-Precision WebAssembly Support**
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@justinelliottcobb/amari-wasm)
|
|
6
6
|
[](https://github.com/justinelliottcobb/Amari/actions/workflows/ci.yml)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
|
|
9
|
-
Amari is a comprehensive mathematical computing library that brings
|
|
9
|
+
Amari is a comprehensive mathematical computing library that brings advanced algebraic systems to JavaScript/TypeScript through WebAssembly, now with full high-precision arithmetic support for spacecraft orbital mechanics and relativistic physics calculations. Features pure Rust implementation with no native dependencies for universal deployment.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Features
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
- **📦 TypeScript Support**: Full TypeScript definitions included
|
|
13
|
+
### New in v0.9.0: High-Precision WebAssembly
|
|
14
|
+
- **Spacecraft Orbital Mechanics**: Full-precision trajectory calculations now available in browsers
|
|
15
|
+
- **Relativistic Physics**: Spacetime algebra (Cl(1,3)) with WebAssembly-compatible precision
|
|
16
|
+
- **Pure Rust Backend**: dashu-powered arithmetic with no native dependencies
|
|
17
|
+
- **Universal Deployment**: Same precision guarantees across desktop, web, and edge environments
|
|
18
|
+
- **WebAssembly 3.0 Ready**: Leverages latest WASM features for enhanced mathematical computing
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
### Core Mathematical Systems
|
|
21
|
+
- **Geometric Algebra (Clifford Algebra)**: Multivectors, rotors, and geometric products for 3D rotations and spatial transformations
|
|
22
|
+
- **Tropical Algebra**: Max-plus semiring operations for optimization and neural network applications
|
|
23
|
+
- **Automatic Differentiation**: Forward-mode AD with dual numbers for exact derivatives
|
|
24
|
+
- **Cellular Automata**: Geometric cellular automata with multivector states
|
|
25
|
+
- **WebGPU Acceleration**: Optional GPU acceleration for large-scale operations
|
|
26
|
+
- **Pure Rust Implementation**: Memory-safe, high-performance core with WASM bindings
|
|
27
|
+
- **TypeScript Support**: Full TypeScript definitions included
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
22
30
|
|
|
23
31
|
```bash
|
|
24
32
|
npm install @amari/core
|
|
@@ -30,7 +38,7 @@ Or with yarn:
|
|
|
30
38
|
yarn add @amari/core
|
|
31
39
|
```
|
|
32
40
|
|
|
33
|
-
##
|
|
41
|
+
## Quick Start
|
|
34
42
|
|
|
35
43
|
```typescript
|
|
36
44
|
import init, { WasmMultivector, WasmRotor } from '@amari/core';
|
|
@@ -71,7 +79,63 @@ async function main() {
|
|
|
71
79
|
main();
|
|
72
80
|
```
|
|
73
81
|
|
|
74
|
-
##
|
|
82
|
+
## High-Precision Orbital Mechanics (New in v0.9.0)
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import init, {
|
|
86
|
+
WasmSpacetimeVector,
|
|
87
|
+
WasmFourVelocity,
|
|
88
|
+
WasmRelativisticParticle,
|
|
89
|
+
WasmSchwarzschildMetric
|
|
90
|
+
} from '@amari/core';
|
|
91
|
+
|
|
92
|
+
async function spacecraftSimulation() {
|
|
93
|
+
await init();
|
|
94
|
+
|
|
95
|
+
// Create Earth's gravitational field
|
|
96
|
+
const earth = WasmSchwarzschildMetric.earth();
|
|
97
|
+
|
|
98
|
+
// Spacecraft at 400km altitude (ISS orbit)
|
|
99
|
+
const altitude = 400e3; // 400 km
|
|
100
|
+
const earthRadius = 6.371e6; // Earth radius in meters
|
|
101
|
+
const position = new Float64Array([earthRadius + altitude, 0.0, 0.0]);
|
|
102
|
+
const velocity = new Float64Array([0.0, 7.67e3, 0.0]); // ~7.67 km/s orbital velocity
|
|
103
|
+
|
|
104
|
+
// Create spacecraft with high-precision arithmetic
|
|
105
|
+
const spacecraft = WasmRelativisticParticle.new(
|
|
106
|
+
position,
|
|
107
|
+
velocity,
|
|
108
|
+
0.0, // No charge
|
|
109
|
+
1000.0, // 1000 kg spacecraft
|
|
110
|
+
0.0 // No magnetic charge
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// Propagate orbit for one complete period with high precision
|
|
114
|
+
const orbitalPeriod = 5580.0; // ~93 minutes
|
|
115
|
+
const timeStep = 60.0; // 1-minute time steps
|
|
116
|
+
|
|
117
|
+
// High-precision geodesic integration using dashu backend
|
|
118
|
+
const trajectory = spacecraft.propagate_trajectory(
|
|
119
|
+
earth,
|
|
120
|
+
orbitalPeriod,
|
|
121
|
+
timeStep
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
console.log(`Orbital trajectory computed with ${trajectory.length} points`);
|
|
125
|
+
console.log(`Final position deviation: ${spacecraft.position_error()} meters`);
|
|
126
|
+
|
|
127
|
+
// WebAssembly precision matches native accuracy!
|
|
128
|
+
|
|
129
|
+
// Clean up WASM memory
|
|
130
|
+
earth.free();
|
|
131
|
+
spacecraft.free();
|
|
132
|
+
trajectory.forEach(point => point.free());
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
spacecraftSimulation();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Core Concepts
|
|
75
139
|
|
|
76
140
|
### Geometric Algebra
|
|
77
141
|
|
|
@@ -119,7 +183,7 @@ for (let i = 0; i < 100; i++) {
|
|
|
119
183
|
console.log(`Generation: ${ca.generation()}`);
|
|
120
184
|
```
|
|
121
185
|
|
|
122
|
-
##
|
|
186
|
+
## Use Cases
|
|
123
187
|
|
|
124
188
|
- **Computer Graphics**: 3D rotations and transformations using rotors
|
|
125
189
|
- **Physics Simulations**: Geometric algebra for electromagnetic fields
|
|
@@ -128,7 +192,7 @@ console.log(`Generation: ${ca.generation()}`);
|
|
|
128
192
|
- **Scientific Computing**: High-performance mathematical operations
|
|
129
193
|
- **Game Development**: Efficient spatial transformations and physics
|
|
130
194
|
|
|
131
|
-
##
|
|
195
|
+
## API Reference
|
|
132
196
|
|
|
133
197
|
### Multivector Operations
|
|
134
198
|
|
|
@@ -199,4 +263,4 @@ MIT License - see [LICENSE](https://github.com/justinelliottcobb/Amari/blob/mast
|
|
|
199
263
|
|
|
200
264
|
---
|
|
201
265
|
|
|
202
|
-
**Made with
|
|
266
|
+
**Made with Rust by the Amari team**
|
package/amari_wasm.d.ts
CHANGED
|
@@ -29,21 +29,21 @@ export class PerformanceOperations {
|
|
|
29
29
|
free(): void;
|
|
30
30
|
[Symbol.dispose](): void;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
static fastGeometricProduct(lhs: Float64Array, rhs: Float64Array): Float64Array;
|
|
35
|
-
/**
|
|
36
|
-
* Optimized vector operations for 3D space
|
|
32
|
+
* Batch normalize vectors for efficiency
|
|
37
33
|
*/
|
|
38
|
-
static
|
|
34
|
+
static batchNormalize(vectors: Float64Array, vector_size: number): Float64Array;
|
|
39
35
|
/**
|
|
40
36
|
* Optimized vector dot product
|
|
41
37
|
*/
|
|
42
38
|
static vectorDotProduct(v1: Float64Array, v2: Float64Array): number;
|
|
43
39
|
/**
|
|
44
|
-
*
|
|
40
|
+
* Optimized vector operations for 3D space
|
|
45
41
|
*/
|
|
46
|
-
static
|
|
42
|
+
static vectorCrossProduct(v1: Float64Array, v2: Float64Array): Float64Array;
|
|
43
|
+
/**
|
|
44
|
+
* Fast geometric product for hot paths with memory pooling
|
|
45
|
+
*/
|
|
46
|
+
static fastGeometricProduct(lhs: Float64Array, rhs: Float64Array): Float64Array;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* WASM wrapper for Multivector with TypedArray support
|
|
@@ -52,25 +52,21 @@ export class WasmMultivector {
|
|
|
52
52
|
free(): void;
|
|
53
53
|
[Symbol.dispose](): void;
|
|
54
54
|
/**
|
|
55
|
-
* Create a
|
|
56
|
-
*/
|
|
57
|
-
constructor();
|
|
58
|
-
/**
|
|
59
|
-
* Create from a Float64Array of coefficients
|
|
55
|
+
* Create a basis vector (0-indexed)
|
|
60
56
|
*/
|
|
61
|
-
static
|
|
57
|
+
static basisVector(index: number): WasmMultivector;
|
|
62
58
|
/**
|
|
63
|
-
*
|
|
59
|
+
* Inner product (dot product for vectors)
|
|
64
60
|
*/
|
|
65
|
-
|
|
61
|
+
innerProduct(other: WasmMultivector): WasmMultivector;
|
|
66
62
|
/**
|
|
67
|
-
*
|
|
63
|
+
* Outer product (wedge product)
|
|
68
64
|
*/
|
|
69
|
-
|
|
65
|
+
outerProduct(other: WasmMultivector): WasmMultivector;
|
|
70
66
|
/**
|
|
71
|
-
*
|
|
67
|
+
* Scalar product
|
|
72
68
|
*/
|
|
73
|
-
|
|
69
|
+
scalarProduct(other: WasmMultivector): number;
|
|
74
70
|
/**
|
|
75
71
|
* Get a specific coefficient
|
|
76
72
|
*/
|
|
@@ -80,61 +76,65 @@ export class WasmMultivector {
|
|
|
80
76
|
*/
|
|
81
77
|
setCoefficient(index: number, value: number): void;
|
|
82
78
|
/**
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
|
-
geometricProduct(other: WasmMultivector): WasmMultivector;
|
|
86
|
-
/**
|
|
87
|
-
* Inner product (dot product for vectors)
|
|
79
|
+
* Get coefficients as a Float64Array
|
|
88
80
|
*/
|
|
89
|
-
|
|
81
|
+
getCoefficients(): Float64Array;
|
|
90
82
|
/**
|
|
91
|
-
*
|
|
83
|
+
* Grade projection
|
|
92
84
|
*/
|
|
93
|
-
|
|
85
|
+
gradeProjection(grade: number): WasmMultivector;
|
|
94
86
|
/**
|
|
95
|
-
*
|
|
87
|
+
* Create from a Float64Array of coefficients
|
|
96
88
|
*/
|
|
97
|
-
|
|
89
|
+
static fromCoefficients(coefficients: Float64Array): WasmMultivector;
|
|
98
90
|
/**
|
|
99
|
-
*
|
|
91
|
+
* Geometric product
|
|
100
92
|
*/
|
|
101
|
-
|
|
93
|
+
geometricProduct(other: WasmMultivector): WasmMultivector;
|
|
102
94
|
/**
|
|
103
|
-
*
|
|
95
|
+
* Add two multivectors
|
|
104
96
|
*/
|
|
105
|
-
|
|
97
|
+
add(other: WasmMultivector): WasmMultivector;
|
|
106
98
|
/**
|
|
107
99
|
* Exponential (for bivectors to create rotors)
|
|
108
100
|
*/
|
|
109
101
|
exp(): WasmMultivector;
|
|
110
102
|
/**
|
|
111
|
-
*
|
|
103
|
+
* Create a new zero multivector
|
|
112
104
|
*/
|
|
113
|
-
|
|
105
|
+
constructor();
|
|
106
|
+
/**
|
|
107
|
+
* Subtract two multivectors
|
|
108
|
+
*/
|
|
109
|
+
sub(other: WasmMultivector): WasmMultivector;
|
|
114
110
|
/**
|
|
115
111
|
* Compute norm (alias for magnitude, maintained for compatibility)
|
|
116
112
|
*/
|
|
117
113
|
norm(): number;
|
|
118
114
|
/**
|
|
119
|
-
*
|
|
115
|
+
* Scale by a scalar
|
|
120
116
|
*/
|
|
121
|
-
|
|
117
|
+
scale(scalar: number): WasmMultivector;
|
|
118
|
+
/**
|
|
119
|
+
* Create a scalar multivector
|
|
120
|
+
*/
|
|
121
|
+
static scalar(value: number): WasmMultivector;
|
|
122
122
|
/**
|
|
123
123
|
* Compute inverse
|
|
124
124
|
*/
|
|
125
125
|
inverse(): WasmMultivector;
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
127
|
+
* Reverse
|
|
128
128
|
*/
|
|
129
|
-
|
|
129
|
+
reverse(): WasmMultivector;
|
|
130
130
|
/**
|
|
131
|
-
*
|
|
131
|
+
* Compute magnitude
|
|
132
132
|
*/
|
|
133
|
-
|
|
133
|
+
magnitude(): number;
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
135
|
+
* Normalize
|
|
136
136
|
*/
|
|
137
|
-
|
|
137
|
+
normalize(): WasmMultivector;
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* Rotor operations for WASM
|
|
@@ -165,38 +165,38 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
165
165
|
|
|
166
166
|
export interface InitOutput {
|
|
167
167
|
readonly memory: WebAssembly.Memory;
|
|
168
|
+
readonly __wbg_batchoperations_free: (a: number, b: number) => void;
|
|
168
169
|
readonly __wbg_wasmmultivector_free: (a: number, b: number) => void;
|
|
169
|
-
readonly
|
|
170
|
-
readonly
|
|
171
|
-
readonly
|
|
170
|
+
readonly batchoperations_batchAdd: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
171
|
+
readonly batchoperations_batchGeometricProduct: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
172
|
+
readonly init: () => void;
|
|
173
|
+
readonly performanceoperations_batchNormalize: (a: number, b: number, c: number) => [number, number];
|
|
174
|
+
readonly performanceoperations_fastGeometricProduct: (a: number, b: number, c: number, d: number) => [number, number];
|
|
175
|
+
readonly performanceoperations_vectorCrossProduct: (a: number, b: number, c: number, d: number) => [number, number];
|
|
176
|
+
readonly performanceoperations_vectorDotProduct: (a: number, b: number, c: number, d: number) => number;
|
|
177
|
+
readonly wasmmultivector_add: (a: number, b: number) => number;
|
|
172
178
|
readonly wasmmultivector_basisVector: (a: number) => [number, number, number];
|
|
173
|
-
readonly
|
|
174
|
-
readonly
|
|
175
|
-
readonly wasmmultivector_setCoefficient: (a: number, b: number, c: number) => void;
|
|
179
|
+
readonly wasmmultivector_exp: (a: number) => number;
|
|
180
|
+
readonly wasmmultivector_fromCoefficients: (a: number, b: number) => [number, number, number];
|
|
176
181
|
readonly wasmmultivector_geometricProduct: (a: number, b: number) => number;
|
|
177
|
-
readonly
|
|
178
|
-
readonly
|
|
179
|
-
readonly wasmmultivector_scalarProduct: (a: number, b: number) => number;
|
|
180
|
-
readonly wasmmultivector_reverse: (a: number) => number;
|
|
182
|
+
readonly wasmmultivector_getCoefficient: (a: number, b: number) => number;
|
|
183
|
+
readonly wasmmultivector_getCoefficients: (a: number) => [number, number];
|
|
181
184
|
readonly wasmmultivector_gradeProjection: (a: number, b: number) => number;
|
|
182
|
-
readonly
|
|
185
|
+
readonly wasmmultivector_innerProduct: (a: number, b: number) => number;
|
|
186
|
+
readonly wasmmultivector_inverse: (a: number) => [number, number, number];
|
|
183
187
|
readonly wasmmultivector_magnitude: (a: number) => number;
|
|
188
|
+
readonly wasmmultivector_new: () => number;
|
|
184
189
|
readonly wasmmultivector_normalize: (a: number) => [number, number, number];
|
|
185
|
-
readonly
|
|
186
|
-
readonly
|
|
187
|
-
readonly
|
|
190
|
+
readonly wasmmultivector_outerProduct: (a: number, b: number) => number;
|
|
191
|
+
readonly wasmmultivector_reverse: (a: number) => number;
|
|
192
|
+
readonly wasmmultivector_scalar: (a: number) => number;
|
|
193
|
+
readonly wasmmultivector_scalarProduct: (a: number, b: number) => number;
|
|
188
194
|
readonly wasmmultivector_scale: (a: number, b: number) => number;
|
|
189
|
-
readonly
|
|
190
|
-
readonly
|
|
191
|
-
readonly batchoperations_batchAdd: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
192
|
-
readonly wasmrotor_fromBivector: (a: number, b: number) => number;
|
|
195
|
+
readonly wasmmultivector_setCoefficient: (a: number, b: number, c: number) => void;
|
|
196
|
+
readonly wasmmultivector_sub: (a: number, b: number) => number;
|
|
193
197
|
readonly wasmrotor_apply: (a: number, b: number) => number;
|
|
194
198
|
readonly wasmrotor_compose: (a: number, b: number) => number;
|
|
195
|
-
readonly
|
|
196
|
-
readonly performanceoperations_vectorCrossProduct: (a: number, b: number, c: number, d: number) => [number, number];
|
|
197
|
-
readonly performanceoperations_vectorDotProduct: (a: number, b: number, c: number, d: number) => number;
|
|
198
|
-
readonly performanceoperations_batchNormalize: (a: number, b: number, c: number) => [number, number];
|
|
199
|
-
readonly init: () => void;
|
|
199
|
+
readonly wasmrotor_fromBivector: (a: number, b: number) => number;
|
|
200
200
|
readonly wasmmultivector_norm: (a: number) => number;
|
|
201
201
|
readonly __wbg_performanceoperations_free: (a: number, b: number) => void;
|
|
202
202
|
readonly wasmrotor_inverse: (a: number) => number;
|
package/amari_wasm.js
CHANGED
|
@@ -152,64 +152,64 @@ export class PerformanceOperations {
|
|
|
152
152
|
wasm.__wbg_performanceoperations_free(ptr, 0);
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
|
-
*
|
|
156
|
-
* @param {Float64Array}
|
|
157
|
-
* @param {
|
|
155
|
+
* Batch normalize vectors for efficiency
|
|
156
|
+
* @param {Float64Array} vectors
|
|
157
|
+
* @param {number} vector_size
|
|
158
158
|
* @returns {Float64Array}
|
|
159
159
|
*/
|
|
160
|
-
static
|
|
161
|
-
const ptr0 = passArrayF64ToWasm0(
|
|
160
|
+
static batchNormalize(vectors, vector_size) {
|
|
161
|
+
const ptr0 = passArrayF64ToWasm0(vectors, wasm.__wbindgen_malloc);
|
|
162
162
|
const len0 = WASM_VECTOR_LEN;
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
const ret = wasm.performanceoperations_fastGeometricProduct(ptr0, len0, ptr1, len1);
|
|
166
|
-
var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
163
|
+
const ret = wasm.performanceoperations_batchNormalize(ptr0, len0, vector_size);
|
|
164
|
+
var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
167
165
|
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
168
|
-
return
|
|
166
|
+
return v2;
|
|
169
167
|
}
|
|
170
168
|
/**
|
|
171
|
-
* Optimized vector
|
|
169
|
+
* Optimized vector dot product
|
|
172
170
|
* @param {Float64Array} v1
|
|
173
171
|
* @param {Float64Array} v2
|
|
174
|
-
* @returns {
|
|
172
|
+
* @returns {number}
|
|
175
173
|
*/
|
|
176
|
-
static
|
|
174
|
+
static vectorDotProduct(v1, v2) {
|
|
177
175
|
const ptr0 = passArrayF64ToWasm0(v1, wasm.__wbindgen_malloc);
|
|
178
176
|
const len0 = WASM_VECTOR_LEN;
|
|
179
177
|
const ptr1 = passArrayF64ToWasm0(v2, wasm.__wbindgen_malloc);
|
|
180
178
|
const len1 = WASM_VECTOR_LEN;
|
|
181
|
-
const ret = wasm.
|
|
182
|
-
|
|
183
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
184
|
-
return v3;
|
|
179
|
+
const ret = wasm.performanceoperations_vectorDotProduct(ptr0, len0, ptr1, len1);
|
|
180
|
+
return ret;
|
|
185
181
|
}
|
|
186
182
|
/**
|
|
187
|
-
* Optimized vector
|
|
183
|
+
* Optimized vector operations for 3D space
|
|
188
184
|
* @param {Float64Array} v1
|
|
189
185
|
* @param {Float64Array} v2
|
|
190
|
-
* @returns {
|
|
186
|
+
* @returns {Float64Array}
|
|
191
187
|
*/
|
|
192
|
-
static
|
|
188
|
+
static vectorCrossProduct(v1, v2) {
|
|
193
189
|
const ptr0 = passArrayF64ToWasm0(v1, wasm.__wbindgen_malloc);
|
|
194
190
|
const len0 = WASM_VECTOR_LEN;
|
|
195
191
|
const ptr1 = passArrayF64ToWasm0(v2, wasm.__wbindgen_malloc);
|
|
196
192
|
const len1 = WASM_VECTOR_LEN;
|
|
197
|
-
const ret = wasm.
|
|
198
|
-
|
|
193
|
+
const ret = wasm.performanceoperations_vectorCrossProduct(ptr0, len0, ptr1, len1);
|
|
194
|
+
var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
195
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
196
|
+
return v3;
|
|
199
197
|
}
|
|
200
198
|
/**
|
|
201
|
-
*
|
|
202
|
-
* @param {Float64Array}
|
|
203
|
-
* @param {
|
|
199
|
+
* Fast geometric product for hot paths with memory pooling
|
|
200
|
+
* @param {Float64Array} lhs
|
|
201
|
+
* @param {Float64Array} rhs
|
|
204
202
|
* @returns {Float64Array}
|
|
205
203
|
*/
|
|
206
|
-
static
|
|
207
|
-
const ptr0 = passArrayF64ToWasm0(
|
|
204
|
+
static fastGeometricProduct(lhs, rhs) {
|
|
205
|
+
const ptr0 = passArrayF64ToWasm0(lhs, wasm.__wbindgen_malloc);
|
|
208
206
|
const len0 = WASM_VECTOR_LEN;
|
|
209
|
-
const
|
|
210
|
-
|
|
207
|
+
const ptr1 = passArrayF64ToWasm0(rhs, wasm.__wbindgen_malloc);
|
|
208
|
+
const len1 = WASM_VECTOR_LEN;
|
|
209
|
+
const ret = wasm.performanceoperations_fastGeometricProduct(ptr0, len0, ptr1, len1);
|
|
210
|
+
var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
211
211
|
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
212
|
-
return
|
|
212
|
+
return v3;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
if (Symbol.dispose) PerformanceOperations.prototype[Symbol.dispose] = PerformanceOperations.prototype.free;
|
|
@@ -242,58 +242,46 @@ export class WasmMultivector {
|
|
|
242
242
|
wasm.__wbg_wasmmultivector_free(ptr, 0);
|
|
243
243
|
}
|
|
244
244
|
/**
|
|
245
|
-
* Create a
|
|
246
|
-
|
|
247
|
-
constructor() {
|
|
248
|
-
const ret = wasm.wasmmultivector_new();
|
|
249
|
-
this.__wbg_ptr = ret >>> 0;
|
|
250
|
-
WasmMultivectorFinalization.register(this, this.__wbg_ptr, this);
|
|
251
|
-
return this;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Create from a Float64Array of coefficients
|
|
255
|
-
* @param {Float64Array} coefficients
|
|
245
|
+
* Create a basis vector (0-indexed)
|
|
246
|
+
* @param {number} index
|
|
256
247
|
* @returns {WasmMultivector}
|
|
257
248
|
*/
|
|
258
|
-
static
|
|
259
|
-
const
|
|
260
|
-
const len0 = WASM_VECTOR_LEN;
|
|
261
|
-
const ret = wasm.wasmmultivector_fromCoefficients(ptr0, len0);
|
|
249
|
+
static basisVector(index) {
|
|
250
|
+
const ret = wasm.wasmmultivector_basisVector(index);
|
|
262
251
|
if (ret[2]) {
|
|
263
252
|
throw takeFromExternrefTable0(ret[1]);
|
|
264
253
|
}
|
|
265
254
|
return WasmMultivector.__wrap(ret[0]);
|
|
266
255
|
}
|
|
267
256
|
/**
|
|
268
|
-
*
|
|
269
|
-
* @param {
|
|
257
|
+
* Inner product (dot product for vectors)
|
|
258
|
+
* @param {WasmMultivector} other
|
|
270
259
|
* @returns {WasmMultivector}
|
|
271
260
|
*/
|
|
272
|
-
|
|
273
|
-
|
|
261
|
+
innerProduct(other) {
|
|
262
|
+
_assertClass(other, WasmMultivector);
|
|
263
|
+
const ret = wasm.wasmmultivector_innerProduct(this.__wbg_ptr, other.__wbg_ptr);
|
|
274
264
|
return WasmMultivector.__wrap(ret);
|
|
275
265
|
}
|
|
276
266
|
/**
|
|
277
|
-
*
|
|
278
|
-
* @param {
|
|
267
|
+
* Outer product (wedge product)
|
|
268
|
+
* @param {WasmMultivector} other
|
|
279
269
|
* @returns {WasmMultivector}
|
|
280
270
|
*/
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
return WasmMultivector.__wrap(ret[0]);
|
|
271
|
+
outerProduct(other) {
|
|
272
|
+
_assertClass(other, WasmMultivector);
|
|
273
|
+
const ret = wasm.wasmmultivector_outerProduct(this.__wbg_ptr, other.__wbg_ptr);
|
|
274
|
+
return WasmMultivector.__wrap(ret);
|
|
287
275
|
}
|
|
288
276
|
/**
|
|
289
|
-
*
|
|
290
|
-
* @
|
|
277
|
+
* Scalar product
|
|
278
|
+
* @param {WasmMultivector} other
|
|
279
|
+
* @returns {number}
|
|
291
280
|
*/
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return v1;
|
|
281
|
+
scalarProduct(other) {
|
|
282
|
+
_assertClass(other, WasmMultivector);
|
|
283
|
+
const ret = wasm.wasmmultivector_scalarProduct(this.__wbg_ptr, other.__wbg_ptr);
|
|
284
|
+
return ret;
|
|
297
285
|
}
|
|
298
286
|
/**
|
|
299
287
|
* Get a specific coefficient
|
|
@@ -313,96 +301,110 @@ export class WasmMultivector {
|
|
|
313
301
|
wasm.wasmmultivector_setCoefficient(this.__wbg_ptr, index, value);
|
|
314
302
|
}
|
|
315
303
|
/**
|
|
316
|
-
*
|
|
317
|
-
* @
|
|
304
|
+
* Get coefficients as a Float64Array
|
|
305
|
+
* @returns {Float64Array}
|
|
306
|
+
*/
|
|
307
|
+
getCoefficients() {
|
|
308
|
+
const ret = wasm.wasmmultivector_getCoefficients(this.__wbg_ptr);
|
|
309
|
+
var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
310
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
311
|
+
return v1;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Grade projection
|
|
315
|
+
* @param {number} grade
|
|
318
316
|
* @returns {WasmMultivector}
|
|
319
317
|
*/
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const ret = wasm.wasmmultivector_geometricProduct(this.__wbg_ptr, other.__wbg_ptr);
|
|
318
|
+
gradeProjection(grade) {
|
|
319
|
+
const ret = wasm.wasmmultivector_gradeProjection(this.__wbg_ptr, grade);
|
|
323
320
|
return WasmMultivector.__wrap(ret);
|
|
324
321
|
}
|
|
325
322
|
/**
|
|
326
|
-
*
|
|
327
|
-
* @param {
|
|
323
|
+
* Create from a Float64Array of coefficients
|
|
324
|
+
* @param {Float64Array} coefficients
|
|
328
325
|
* @returns {WasmMultivector}
|
|
329
326
|
*/
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
|
|
327
|
+
static fromCoefficients(coefficients) {
|
|
328
|
+
const ptr0 = passArrayF64ToWasm0(coefficients, wasm.__wbindgen_malloc);
|
|
329
|
+
const len0 = WASM_VECTOR_LEN;
|
|
330
|
+
const ret = wasm.wasmmultivector_fromCoefficients(ptr0, len0);
|
|
331
|
+
if (ret[2]) {
|
|
332
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
333
|
+
}
|
|
334
|
+
return WasmMultivector.__wrap(ret[0]);
|
|
334
335
|
}
|
|
335
336
|
/**
|
|
336
|
-
*
|
|
337
|
+
* Geometric product
|
|
337
338
|
* @param {WasmMultivector} other
|
|
338
339
|
* @returns {WasmMultivector}
|
|
339
340
|
*/
|
|
340
|
-
|
|
341
|
+
geometricProduct(other) {
|
|
341
342
|
_assertClass(other, WasmMultivector);
|
|
342
|
-
const ret = wasm.
|
|
343
|
+
const ret = wasm.wasmmultivector_geometricProduct(this.__wbg_ptr, other.__wbg_ptr);
|
|
343
344
|
return WasmMultivector.__wrap(ret);
|
|
344
345
|
}
|
|
345
346
|
/**
|
|
346
|
-
*
|
|
347
|
+
* Add two multivectors
|
|
347
348
|
* @param {WasmMultivector} other
|
|
348
|
-
* @returns {
|
|
349
|
+
* @returns {WasmMultivector}
|
|
349
350
|
*/
|
|
350
|
-
|
|
351
|
+
add(other) {
|
|
351
352
|
_assertClass(other, WasmMultivector);
|
|
352
|
-
const ret = wasm.
|
|
353
|
-
return ret;
|
|
353
|
+
const ret = wasm.wasmmultivector_add(this.__wbg_ptr, other.__wbg_ptr);
|
|
354
|
+
return WasmMultivector.__wrap(ret);
|
|
354
355
|
}
|
|
355
356
|
/**
|
|
356
|
-
*
|
|
357
|
+
* Exponential (for bivectors to create rotors)
|
|
357
358
|
* @returns {WasmMultivector}
|
|
358
359
|
*/
|
|
359
|
-
|
|
360
|
-
const ret = wasm.
|
|
360
|
+
exp() {
|
|
361
|
+
const ret = wasm.wasmmultivector_exp(this.__wbg_ptr);
|
|
361
362
|
return WasmMultivector.__wrap(ret);
|
|
362
363
|
}
|
|
363
364
|
/**
|
|
364
|
-
*
|
|
365
|
-
* @param {number} grade
|
|
366
|
-
* @returns {WasmMultivector}
|
|
365
|
+
* Create a new zero multivector
|
|
367
366
|
*/
|
|
368
|
-
|
|
369
|
-
const ret = wasm.
|
|
370
|
-
|
|
367
|
+
constructor() {
|
|
368
|
+
const ret = wasm.wasmmultivector_new();
|
|
369
|
+
this.__wbg_ptr = ret >>> 0;
|
|
370
|
+
WasmMultivectorFinalization.register(this, this.__wbg_ptr, this);
|
|
371
|
+
return this;
|
|
371
372
|
}
|
|
372
373
|
/**
|
|
373
|
-
*
|
|
374
|
+
* Subtract two multivectors
|
|
375
|
+
* @param {WasmMultivector} other
|
|
374
376
|
* @returns {WasmMultivector}
|
|
375
377
|
*/
|
|
376
|
-
|
|
377
|
-
|
|
378
|
+
sub(other) {
|
|
379
|
+
_assertClass(other, WasmMultivector);
|
|
380
|
+
const ret = wasm.wasmmultivector_sub(this.__wbg_ptr, other.__wbg_ptr);
|
|
378
381
|
return WasmMultivector.__wrap(ret);
|
|
379
382
|
}
|
|
380
383
|
/**
|
|
381
|
-
* Compute magnitude
|
|
384
|
+
* Compute norm (alias for magnitude, maintained for compatibility)
|
|
382
385
|
* @returns {number}
|
|
383
386
|
*/
|
|
384
|
-
|
|
387
|
+
norm() {
|
|
385
388
|
const ret = wasm.wasmmultivector_magnitude(this.__wbg_ptr);
|
|
386
389
|
return ret;
|
|
387
390
|
}
|
|
388
391
|
/**
|
|
389
|
-
*
|
|
390
|
-
* @
|
|
392
|
+
* Scale by a scalar
|
|
393
|
+
* @param {number} scalar
|
|
394
|
+
* @returns {WasmMultivector}
|
|
391
395
|
*/
|
|
392
|
-
|
|
393
|
-
const ret = wasm.
|
|
394
|
-
return ret;
|
|
396
|
+
scale(scalar) {
|
|
397
|
+
const ret = wasm.wasmmultivector_scale(this.__wbg_ptr, scalar);
|
|
398
|
+
return WasmMultivector.__wrap(ret);
|
|
395
399
|
}
|
|
396
400
|
/**
|
|
397
|
-
*
|
|
401
|
+
* Create a scalar multivector
|
|
402
|
+
* @param {number} value
|
|
398
403
|
* @returns {WasmMultivector}
|
|
399
404
|
*/
|
|
400
|
-
|
|
401
|
-
const ret = wasm.
|
|
402
|
-
|
|
403
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
404
|
-
}
|
|
405
|
-
return WasmMultivector.__wrap(ret[0]);
|
|
405
|
+
static scalar(value) {
|
|
406
|
+
const ret = wasm.wasmmultivector_scalar(value);
|
|
407
|
+
return WasmMultivector.__wrap(ret);
|
|
406
408
|
}
|
|
407
409
|
/**
|
|
408
410
|
* Compute inverse
|
|
@@ -416,33 +418,31 @@ export class WasmMultivector {
|
|
|
416
418
|
return WasmMultivector.__wrap(ret[0]);
|
|
417
419
|
}
|
|
418
420
|
/**
|
|
419
|
-
*
|
|
420
|
-
* @param {WasmMultivector} other
|
|
421
|
+
* Reverse
|
|
421
422
|
* @returns {WasmMultivector}
|
|
422
423
|
*/
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
const ret = wasm.wasmmultivector_add(this.__wbg_ptr, other.__wbg_ptr);
|
|
424
|
+
reverse() {
|
|
425
|
+
const ret = wasm.wasmmultivector_reverse(this.__wbg_ptr);
|
|
426
426
|
return WasmMultivector.__wrap(ret);
|
|
427
427
|
}
|
|
428
428
|
/**
|
|
429
|
-
*
|
|
430
|
-
* @
|
|
431
|
-
* @returns {WasmMultivector}
|
|
429
|
+
* Compute magnitude
|
|
430
|
+
* @returns {number}
|
|
432
431
|
*/
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
return WasmMultivector.__wrap(ret);
|
|
432
|
+
magnitude() {
|
|
433
|
+
const ret = wasm.wasmmultivector_magnitude(this.__wbg_ptr);
|
|
434
|
+
return ret;
|
|
437
435
|
}
|
|
438
436
|
/**
|
|
439
|
-
*
|
|
440
|
-
* @param {number} scalar
|
|
437
|
+
* Normalize
|
|
441
438
|
* @returns {WasmMultivector}
|
|
442
439
|
*/
|
|
443
|
-
|
|
444
|
-
const ret = wasm.
|
|
445
|
-
|
|
440
|
+
normalize() {
|
|
441
|
+
const ret = wasm.wasmmultivector_normalize(this.__wbg_ptr);
|
|
442
|
+
if (ret[2]) {
|
|
443
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
444
|
+
}
|
|
445
|
+
return WasmMultivector.__wrap(ret[0]);
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
448
|
if (Symbol.dispose) WasmMultivector.prototype[Symbol.dispose] = WasmMultivector.prototype.free;
|
|
@@ -554,7 +554,7 @@ async function __wbg_load(module, imports) {
|
|
|
554
554
|
function __wbg_get_imports() {
|
|
555
555
|
const imports = {};
|
|
556
556
|
imports.wbg = {};
|
|
557
|
-
imports.wbg.
|
|
557
|
+
imports.wbg.__wbg_log_fb67a0d730fc146e = function(arg0, arg1) {
|
|
558
558
|
console.log(getStringFromWasm0(arg0, arg1));
|
|
559
559
|
};
|
|
560
560
|
imports.wbg.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
|
package/amari_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"Amari Contributors"
|
|
6
6
|
],
|
|
7
7
|
"description": "WebAssembly bindings for Amari mathematical computing library - geometric algebra, tropical algebra, automatic differentiation, fusion systems, and information geometry",
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.9.1",
|
|
9
9
|
"license": "MIT OR Apache-2.0",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|