numpy-ts 0.1.0 → 0.3.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/README.md +63 -138
- package/dist/numpy-ts.browser.js +99 -1067
- package/dist/numpy-ts.esm.js +99 -1067
- package/dist/numpy-ts.node.cjs +125 -1078
- package/dist/types/core/broadcasting.d.ts +16 -13
- package/dist/types/core/ndarray.d.ts +213 -52
- package/dist/types/core/storage.d.ts +25 -18
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal/compute.d.ts +18 -0
- package/dist/types/ops/arithmetic.d.ts +59 -0
- package/dist/types/ops/exponential.d.ts +28 -0
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -5,28 +5,23 @@ Complete NumPy implementation for TypeScript and JavaScript
|
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|

|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
> This project is under construction and is currently unstable. Expect breaking changes.
|
|
8
|
+
**⚠️ WARNING: Under active development. API may change.**
|
|
10
9
|
|
|
11
10
|
---
|
|
12
11
|
|
|
13
12
|
## What is numpy-ts?
|
|
14
13
|
|
|
15
|
-
A complete
|
|
14
|
+
A complete NumPy 2.0+ implementation for TypeScript/JavaScript, validated against Python NumPy.
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
**Goals:**
|
|
17
|
+
- **100% API Coverage** - All NumPy functions and operations
|
|
18
|
+
- **Type Safety** - Full TypeScript support with inference
|
|
19
|
+
- **Correctness** - Cross-validated against Python NumPy
|
|
20
|
+
- **Cross-Platform** - Node.js and browsers
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
- ✅ **File Compatibility** - Read/write .npy and .npz files
|
|
23
|
-
- ✅ **Correctness First** - Validated against Python NumPy
|
|
24
|
-
|
|
25
|
-
### Not Goals
|
|
26
|
-
|
|
27
|
-
- ❌ Matching Python NumPy's exact performance (initially)
|
|
28
|
-
- ❌ C API compatibility
|
|
29
|
-
- ❌ Legacy NumPy 1.x deprecated functions
|
|
22
|
+
**Non-Goals:**
|
|
23
|
+
- Matching NumPy's C-optimized performance (initially)
|
|
24
|
+
- C API compatibility
|
|
30
25
|
|
|
31
26
|
---
|
|
32
27
|
|
|
@@ -109,6 +104,8 @@ const loaded = np.load('matrix.npy');
|
|
|
109
104
|
|
|
110
105
|
## Architecture
|
|
111
106
|
|
|
107
|
+
Pure TypeScript implementation with three layers:
|
|
108
|
+
|
|
112
109
|
```
|
|
113
110
|
┌────────────────────────────────┐
|
|
114
111
|
│ NumPy-Compatible API │
|
|
@@ -120,23 +117,21 @@ const loaded = np.load('matrix.npy');
|
|
|
120
117
|
└────────────┬───────────────────┘
|
|
121
118
|
│
|
|
122
119
|
┌────────────┴───────────────────┐
|
|
123
|
-
│
|
|
124
|
-
│
|
|
120
|
+
│ TypeScript/JavaScript Core │
|
|
121
|
+
│ Computational Engine │
|
|
125
122
|
└────────────────────────────────┘
|
|
126
123
|
```
|
|
127
124
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
**We use**: @stdlib for proven numerical computations
|
|
125
|
+
Built from scratch for correctness and NumPy compatibility.
|
|
131
126
|
|
|
132
127
|
---
|
|
133
128
|
|
|
134
129
|
## Key Features
|
|
135
130
|
|
|
136
131
|
### Comprehensive NumPy API
|
|
137
|
-
- **Array creation**: `zeros`, `ones`, `arange`, `linspace` (all support dtype parameter)
|
|
132
|
+
- **Array creation**: `zeros`, `ones`, `arange`, `linspace`, `eye` (all support dtype parameter)
|
|
138
133
|
- **Arithmetic operations**: `add`, `subtract`, `multiply`, `divide` with broadcasting
|
|
139
|
-
- **Linear algebra**: `matmul`
|
|
134
|
+
- **Linear algebra**: `matmul`, `dot`, `transpose`
|
|
140
135
|
- **Reductions**: `sum`, `mean`, `std`, `min`, `max` with axis support
|
|
141
136
|
- **DTypes**: 11 types supported (float32/64, int8/16/32/64, uint8/16/32/64, bool)
|
|
142
137
|
- Full dtype preservation across operations
|
|
@@ -188,98 +183,27 @@ const c = a.add(b); // (3, 4) + (4,) → (3, 4)
|
|
|
188
183
|
|
|
189
184
|
---
|
|
190
185
|
|
|
191
|
-
## Installation
|
|
186
|
+
## Installation
|
|
192
187
|
|
|
193
188
|
```bash
|
|
194
189
|
npm install numpy-ts
|
|
195
190
|
```
|
|
196
191
|
|
|
197
|
-
### Node.js
|
|
198
192
|
```typescript
|
|
199
|
-
import * as np from 'numpy-ts
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### Browser
|
|
203
|
-
```typescript
|
|
204
|
-
import * as np from 'numpy-ts/browser';
|
|
193
|
+
import * as np from 'numpy-ts';
|
|
205
194
|
```
|
|
206
195
|
|
|
207
196
|
---
|
|
208
197
|
|
|
209
|
-
## Development Status
|
|
210
|
-
|
|
211
|
-
### Phase 0: Project Setup ✅ COMPLETE
|
|
212
|
-
- [x] Package configuration
|
|
213
|
-
- [x] TypeScript setup
|
|
214
|
-
- [x] Build system (esbuild)
|
|
215
|
-
- [x] Test framework (Vitest)
|
|
216
|
-
- [x] Documentation consolidated
|
|
217
|
-
- [x] Linting (ESLint + Prettier)
|
|
218
|
-
- [x] @stdlib investigation and integration
|
|
219
|
-
- [x] First working implementation
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
### Phase 1: Core Foundation ✅ **COMPLETE**
|
|
223
|
-
- [x] NDArray wrapper class (using @stdlib/ndarray)
|
|
224
|
-
- [x] Array creation: `zeros()`, `ones()`, `array()`, `arange()`, `linspace()`, `eye()`
|
|
225
|
-
- [x] Matrix operations: `matmul()` using optimized BLAS
|
|
226
|
-
- [x] Properties: `shape`, `ndim`, `size`, `dtype`, `data`, `strides`
|
|
227
|
-
- [x] View tracking: `base` attribute, `flags` property
|
|
228
|
-
- [x] Memory flags: `C_CONTIGUOUS`, `F_CONTIGUOUS`, `OWNDATA`
|
|
229
|
-
- [x] Basic arithmetic: `add()`, `subtract()`, `multiply()`, `divide()` with dtype preservation
|
|
230
|
-
- [x] Broadcasting ✅ **COMPLETE** (fully integrated into all operations)
|
|
231
|
-
- [x] String-based slicing ✅ **COMPLETE** (`arr.slice('0:5', ':')`, `row()`, `col()`, etc.)
|
|
232
|
-
- [x] Reductions with axis support ✅ **COMPLETE** (`sum(axis, keepdims)`, `mean()`, `max()`, `min()`)
|
|
233
|
-
- [x] Comparison operations ✅ **COMPLETE** (`greater()`, `less()`, `equal()`, `isclose()`, `allclose()`)
|
|
234
|
-
- [x] Reshape operations ✅ **COMPLETE** (`reshape()`, `flatten()`, `ravel()`, `transpose()`, `squeeze()`, `expand_dims()`)
|
|
235
|
-
- [x] DType system ✅ **COMPLETE** (11 types: float32/64, int8/16/32/64, uint8/16/32/64, bool)
|
|
236
|
-
- Full dtype preservation
|
|
237
|
-
- NumPy-compatible promotion rules
|
|
238
|
-
- BigInt support for int64/uint64
|
|
239
|
-
- [x] Testing ✅ **748/750 tests passing (99.7%)**
|
|
240
|
-
- Unit tests for all operations
|
|
241
|
-
- NumPy validation tests (cross-checked against Python NumPy 2.3.3)
|
|
242
|
-
- Edge case validation (overflow, underflow, special values)
|
|
243
|
-
|
|
244
|
-
### Phase 2: Benchmarks & CI/CD
|
|
245
|
-
- [X] CI/CD (GitHub Actions)
|
|
246
|
-
- [X] PR workflow
|
|
247
|
-
- [X] Publish workflow
|
|
248
|
-
- [ ] Implement benchmarks
|
|
249
|
-
- [ ] Regression (vs. previous runs)
|
|
250
|
-
- [X] Comparison against Python NumPy
|
|
251
|
-
- [ ] Automated in CI/CD
|
|
252
|
-
|
|
253
|
-
### Phase 3: Essential Operations
|
|
254
|
-
- [ ] Matrix operations (using @stdlib BLAS)
|
|
255
|
-
- [ ] Linear algebra (using @stdlib LAPACK)
|
|
256
|
-
- [ ] Reductions with axis support
|
|
257
|
-
- [ ] Mathematical functions
|
|
258
|
-
- [ ] Comparison operations
|
|
259
|
-
- [ ] dtype consistency testing
|
|
260
|
-
|
|
261
|
-
### Phase 4: Extended Features
|
|
262
|
-
- [ ] Random number generation
|
|
263
|
-
- [ ] FFT operations (using fft.js)
|
|
264
|
-
- [ ] I/O operations (.npy/.npz)
|
|
265
|
-
- [ ] Advanced indexing
|
|
266
|
-
- [ ] Complex numbers, datetime
|
|
267
|
-
- [ ] Optional WASM mode
|
|
268
|
-
|
|
269
|
-
See [API-REFERENCE.md](./docs/API-REFERENCE.md) for complete function checklist.
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
198
|
## Documentation
|
|
274
199
|
|
|
275
200
|
### User Documentation
|
|
276
|
-
- [API-REFERENCE.md](
|
|
201
|
+
- [API-REFERENCE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/API-REFERENCE.md) - Complete API checklist
|
|
277
202
|
|
|
278
203
|
### Developer Documentation
|
|
279
|
-
- [ARCHITECTURE.md](
|
|
280
|
-
- [TESTING-GUIDE.md](
|
|
281
|
-
- [
|
|
282
|
-
- [benchmarks/README.md](./benchmarks/README.md) - Performance benchmarking guide
|
|
204
|
+
- [ARCHITECTURE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/ARCHITECTURE.md) - Design and implementation details
|
|
205
|
+
- [TESTING-GUIDE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/TESTING-GUIDE.md) - How to add tests (unit, validation, benchmarks)
|
|
206
|
+
- [benchmarks/README.md](https://github.com/dupontcyborg/numpy-ts/blob/main/benchmarks/README.md) - Performance benchmarking guide
|
|
283
207
|
|
|
284
208
|
---
|
|
285
209
|
|
|
@@ -325,25 +249,28 @@ it('int8 overflow wraps like NumPy', () => {
|
|
|
325
249
|
|
|
326
250
|
## Design Decisions
|
|
327
251
|
|
|
328
|
-
|
|
329
|
-
|
|
252
|
+
**Pure TypeScript Implementation**
|
|
253
|
+
- Built from scratch without heavy dependencies
|
|
254
|
+
- Focus on correctness and NumPy compatibility
|
|
330
255
|
|
|
331
|
-
|
|
332
|
-
|
|
256
|
+
**BigInt for int64/uint64**
|
|
257
|
+
- Exact representation over convenience
|
|
258
|
+
- No precision loss (different type but fully accurate)
|
|
333
259
|
|
|
334
|
-
|
|
335
|
-
`arr.slice('0:5', ':')` instead of `arr[0:5, :]`
|
|
260
|
+
**String-Based Slicing**
|
|
261
|
+
- `arr.slice('0:5', ':')` instead of `arr[0:5, :]`
|
|
262
|
+
- TypeScript limitation, Pythonic compromise
|
|
336
263
|
|
|
337
|
-
|
|
338
|
-
Track base array
|
|
264
|
+
**View Tracking**
|
|
265
|
+
- Track base array with `base` attribute
|
|
266
|
+
- Zero-copy optimizations where possible
|
|
267
|
+
- Matches NumPy semantics
|
|
339
268
|
|
|
340
|
-
|
|
341
|
-
|
|
269
|
+
**Correctness First**
|
|
270
|
+
- Validate against Python NumPy before optimizing
|
|
271
|
+
- Performance improvements (WASM/SIMD) come later
|
|
342
272
|
|
|
343
|
-
|
|
344
|
-
Validate everything against Python NumPy before optimizing. WASM/SIMD later.
|
|
345
|
-
|
|
346
|
-
See [ARCHITECTURE.md](./docs/ARCHITECTURE.md) for full rationale.
|
|
273
|
+
See [ARCHITECTURE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/ARCHITECTURE.md) for detailed design rationale.
|
|
347
274
|
|
|
348
275
|
---
|
|
349
276
|
|
|
@@ -362,8 +289,8 @@ npm test
|
|
|
362
289
|
|
|
363
290
|
### Adding New Features
|
|
364
291
|
|
|
365
|
-
1. Pick a function from [API-REFERENCE.md](
|
|
366
|
-
2. Follow the [TESTING-GUIDE.md](
|
|
292
|
+
1. Pick a function from [API-REFERENCE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/API-REFERENCE.md)
|
|
293
|
+
2. Follow the [TESTING-GUIDE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/TESTING-GUIDE.md) to add:
|
|
367
294
|
- Implementation in `src/`
|
|
368
295
|
- Unit tests in `tests/unit/`
|
|
369
296
|
- NumPy validation tests in `tests/validation/`
|
|
@@ -372,7 +299,7 @@ npm test
|
|
|
372
299
|
4. Run benchmarks: `npm run bench:quick`
|
|
373
300
|
5. Submit a pull request
|
|
374
301
|
|
|
375
|
-
See [TESTING-GUIDE.md](
|
|
302
|
+
See [TESTING-GUIDE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/TESTING-GUIDE.md) for detailed instructions on adding tests.
|
|
376
303
|
|
|
377
304
|
---
|
|
378
305
|
|
|
@@ -390,58 +317,56 @@ See [TESTING-GUIDE.md](./docs/TESTING-GUIDE.md) for detailed instructions on add
|
|
|
390
317
|
|
|
391
318
|
## Benchmarking
|
|
392
319
|
|
|
393
|
-
Compare numpy-ts performance against Python NumPy:
|
|
320
|
+
Compare numpy-ts performance against Python NumPy with auto-calibrated benchmarks:
|
|
394
321
|
|
|
395
322
|
```bash
|
|
396
|
-
#
|
|
397
|
-
npm run bench:quick
|
|
398
|
-
|
|
399
|
-
# Run standard benchmarks (~5-10 min)
|
|
400
|
-
npm run bench
|
|
323
|
+
# Quick benchmarks (~2-3 min) - 1 sample, 50ms/sample
|
|
324
|
+
source ~/.zshrc && conda activate py313 && npm run bench:quick
|
|
401
325
|
|
|
402
|
-
#
|
|
403
|
-
npm run bench
|
|
326
|
+
# Standard benchmarks (~5-10 min) - 5 samples, 100ms/sample (default)
|
|
327
|
+
source ~/.zshrc && conda activate py313 && npm run bench
|
|
404
328
|
|
|
405
|
-
# View interactive HTML report
|
|
329
|
+
# View interactive HTML report with ops/sec comparison
|
|
406
330
|
npm run bench:view
|
|
407
331
|
```
|
|
408
332
|
|
|
333
|
+
**Both modes use the same array sizes** - only sampling strategy differs (quick for speed, standard for accuracy).
|
|
334
|
+
|
|
409
335
|
### Performance Overview
|
|
410
336
|
|
|
411
|
-

|
|
412
338
|
|
|
413
|
-
See [benchmarks/README.md](
|
|
339
|
+
See [benchmarks/README.md](https://github.com/dupontcyborg/numpy-ts/blob/main/benchmarks/README.md) for detailed benchmarking guide.
|
|
414
340
|
|
|
415
341
|
---
|
|
416
342
|
|
|
417
343
|
## Performance Expectations
|
|
418
344
|
|
|
419
|
-
**v1.0**
|
|
420
|
-
- 10-100x slower than NumPy
|
|
421
|
-
|
|
422
|
-
**v2.0** (Selective WASM):
|
|
423
|
-
- 2-20x slower - optimized bottlenecks only
|
|
345
|
+
**Current (v1.0)** - Pure TypeScript:
|
|
346
|
+
- 10-100x slower than NumPy
|
|
347
|
+
- Focus on correctness and API completeness
|
|
424
348
|
|
|
425
|
-
**
|
|
426
|
-
-
|
|
349
|
+
**Future (v2.0+)** - Optimizations:
|
|
350
|
+
- WASM for compute-intensive operations
|
|
351
|
+
- SIMD for vectorized operations
|
|
352
|
+
- Target: 2-20x slower than NumPy
|
|
427
353
|
|
|
428
|
-
|
|
354
|
+
Correctness and completeness first, then performance.
|
|
429
355
|
|
|
430
356
|
---
|
|
431
357
|
|
|
432
358
|
## License
|
|
433
359
|
|
|
434
|
-
[MIT License](
|
|
360
|
+
[MIT License](https://github.com/dupontcyborg/numpy-ts/blob/main/LICENSE) - Copyright (c) 2025 Nicolas Dupont
|
|
435
361
|
|
|
436
362
|
---
|
|
437
363
|
|
|
438
364
|
## Links
|
|
439
365
|
|
|
440
|
-
- **Documentation**: [`docs/`](./docs)
|
|
441
366
|
- **NumPy**: https://numpy.org/
|
|
442
367
|
- **@stdlib**: https://stdlib.io/
|
|
443
368
|
- **Issues**: https://github.com/dupontcyborg/numpy-ts/issues
|
|
444
369
|
|
|
445
370
|
---
|
|
446
371
|
|
|
447
|
-
**Ready to bring NumPy to JavaScript!** ⭐
|
|
372
|
+
**Ready to bring NumPy to TypeScript + JavaScript!** ⭐
|