numpy-ts 0.2.0 → 0.4.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 +50 -126
- package/dist/numpy-ts.browser.js +1 -1364
- package/dist/numpy-ts.esm.js +1 -1364
- package/dist/numpy-ts.node.cjs +1 -1365
- package/dist/types/core/broadcasting.d.ts +16 -13
- package/dist/types/core/ndarray.d.ts +270 -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 +9 -0
- package/dist/types/ops/linalg.d.ts +79 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -5,27 +5,23 @@ Complete NumPy implementation for TypeScript and JavaScript
|
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|

|
|
7
7
|
|
|
8
|
-
**⚠️ WARNING:
|
|
8
|
+
**⚠️ WARNING: Under active development. API may change.**
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
12
12
|
## What is numpy-ts?
|
|
13
13
|
|
|
14
|
-
A complete
|
|
14
|
+
A complete NumPy 2.0+ implementation for TypeScript/JavaScript, validated against Python NumPy.
|
|
15
15
|
|
|
16
|
-
|
|
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
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
- ✅ **File Compatibility** - Read/write .npy and .npz files
|
|
22
|
-
- ✅ **Correctness First** - Validated against Python NumPy
|
|
23
|
-
|
|
24
|
-
### Not Goals
|
|
25
|
-
|
|
26
|
-
- ❌ Matching Python NumPy's exact performance (initially)
|
|
27
|
-
- ❌ C API compatibility
|
|
28
|
-
- ❌ Legacy NumPy 1.x deprecated functions
|
|
22
|
+
**Non-Goals:**
|
|
23
|
+
- Matching NumPy's C-optimized performance (initially)
|
|
24
|
+
- C API compatibility
|
|
29
25
|
|
|
30
26
|
---
|
|
31
27
|
|
|
@@ -108,6 +104,8 @@ const loaded = np.load('matrix.npy');
|
|
|
108
104
|
|
|
109
105
|
## Architecture
|
|
110
106
|
|
|
107
|
+
Pure TypeScript implementation with three layers:
|
|
108
|
+
|
|
111
109
|
```
|
|
112
110
|
┌────────────────────────────────┐
|
|
113
111
|
│ NumPy-Compatible API │
|
|
@@ -119,23 +117,21 @@ const loaded = np.load('matrix.npy');
|
|
|
119
117
|
└────────────┬───────────────────┘
|
|
120
118
|
│
|
|
121
119
|
┌────────────┴───────────────────┐
|
|
122
|
-
│
|
|
123
|
-
│
|
|
120
|
+
│ TypeScript/JavaScript Core │
|
|
121
|
+
│ Computational Engine │
|
|
124
122
|
└────────────────────────────────┘
|
|
125
123
|
```
|
|
126
124
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
**We use**: @stdlib for proven numerical computations
|
|
125
|
+
Built from scratch for correctness and NumPy compatibility.
|
|
130
126
|
|
|
131
127
|
---
|
|
132
128
|
|
|
133
129
|
## Key Features
|
|
134
130
|
|
|
135
131
|
### Comprehensive NumPy API
|
|
136
|
-
- **Array creation**: `zeros`, `ones`, `arange`, `linspace` (all support dtype parameter)
|
|
132
|
+
- **Array creation**: `zeros`, `ones`, `arange`, `linspace`, `eye` (all support dtype parameter)
|
|
137
133
|
- **Arithmetic operations**: `add`, `subtract`, `multiply`, `divide` with broadcasting
|
|
138
|
-
- **Linear algebra**: `matmul`
|
|
134
|
+
- **Linear algebra**: `matmul`, `dot`, `transpose`
|
|
139
135
|
- **Reductions**: `sum`, `mean`, `std`, `min`, `max` with axis support
|
|
140
136
|
- **DTypes**: 11 types supported (float32/64, int8/16/32/64, uint8/16/32/64, bool)
|
|
141
137
|
- Full dtype preservation across operations
|
|
@@ -199,85 +195,14 @@ import * as np from 'numpy-ts';
|
|
|
199
195
|
|
|
200
196
|
---
|
|
201
197
|
|
|
202
|
-
## Development Status
|
|
203
|
-
|
|
204
|
-
### Phase 0: Project Setup
|
|
205
|
-
- [x] Package configuration
|
|
206
|
-
- [x] TypeScript setup
|
|
207
|
-
- [x] Build system (esbuild)
|
|
208
|
-
- [x] Test framework (Vitest)
|
|
209
|
-
- [x] Documentation consolidated
|
|
210
|
-
- [x] Linting (ESLint + Prettier)
|
|
211
|
-
- [x] @stdlib investigation and integration
|
|
212
|
-
- [x] First working implementation
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
### Phase 1: Core Foundation
|
|
216
|
-
- [x] NDArray wrapper class (using @stdlib/ndarray)
|
|
217
|
-
- [x] Array creation: `zeros()`, `ones()`, `array()`, `arange()`, `linspace()`, `eye()`
|
|
218
|
-
- [x] Matrix operations: `matmul()` using optimized BLAS
|
|
219
|
-
- [x] Properties: `shape`, `ndim`, `size`, `dtype`, `data`, `strides`
|
|
220
|
-
- [x] View tracking: `base` attribute, `flags` property
|
|
221
|
-
- [x] Memory flags: `C_CONTIGUOUS`, `F_CONTIGUOUS`, `OWNDATA`
|
|
222
|
-
- [x] Arithmetic operations: `add()`, `subtract()`, `multiply()`, `divide()`, `mod()`, `floor_divide()`, `negative()`, `positive()`, `absolute()`, `sign()`, `reciprocal()`
|
|
223
|
-
- [x] Broadcasting - fully integrated into all operations
|
|
224
|
-
- [x] String-based slicing - `arr.slice('0:5', ':')`, `row()`, `col()`, etc.
|
|
225
|
-
- [x] Reductions with axis support - `sum(axis, keepdims)`, `mean()`, `max()`, `min()`
|
|
226
|
-
- [x] Comparison operations - `greater()`, `less()`, `equal()`, `isclose()`, `allclose()`
|
|
227
|
-
- [x] Reshape operations - `reshape()`, `flatten()`, `ravel()`, `transpose()`, `squeeze()`, `expand_dims()`
|
|
228
|
-
- [x] DType system - 11 types: float32/64, int8/16/32/64, uint8/16/32/64, bool
|
|
229
|
-
- Full dtype preservation
|
|
230
|
-
- NumPy-compatible promotion rules
|
|
231
|
-
- BigInt support for int64/uint64
|
|
232
|
-
- [x] Exponential operations - `sqrt()`, `power()`
|
|
233
|
-
- [x] Testing
|
|
234
|
-
- Unit tests for all operations
|
|
235
|
-
- NumPy validation tests (cross-checked against Python NumPy 2.3.3)
|
|
236
|
-
- Edge case validation (overflow, underflow, special values)
|
|
237
|
-
|
|
238
|
-
### Phase 2: Benchmarks & CI/CD
|
|
239
|
-
- [X] CI/CD (GitHub Actions)
|
|
240
|
-
- [X] PR workflow
|
|
241
|
-
- [X] Publish workflow
|
|
242
|
-
- [ ] Implement benchmarks
|
|
243
|
-
- [X] Auto-calibrated benchmark runner (100ms samples, ops/sec metrics)
|
|
244
|
-
- [X] Comparison against Python NumPy
|
|
245
|
-
- [X] Matching Python/TypeScript output format
|
|
246
|
-
- [X] Ops/sec visualization (HTML/PNG)
|
|
247
|
-
- [ ] **Result validation** - Verify numpy-ts and NumPy produce same results before benchmarking
|
|
248
|
-
- [ ] Regression tracking (vs. previous runs)
|
|
249
|
-
- [ ] Automated in CI/CD
|
|
250
|
-
|
|
251
|
-
### Phase 3: Essential Operations
|
|
252
|
-
- [x] Matrix operations (using @stdlib BLAS)
|
|
253
|
-
- [ ] Linear algebra (using @stdlib LAPACK) - eig, svd, qr, etc.
|
|
254
|
-
- [x] Reductions with axis support
|
|
255
|
-
- [x] Arithmetic functions - 11/11 complete
|
|
256
|
-
- [ ] Mathematical functions - 2/40+ (sqrt, power) - trigonometric, exponential, rounding, etc.
|
|
257
|
-
- [x] Comparison operations
|
|
258
|
-
- [x] dtype consistency testing
|
|
259
|
-
|
|
260
|
-
### Phase 4: Extended Features
|
|
261
|
-
- [ ] Random number generation
|
|
262
|
-
- [ ] FFT operations (using fft.js)
|
|
263
|
-
- [ ] I/O operations (.npy/.npz)
|
|
264
|
-
- [ ] Advanced indexing
|
|
265
|
-
- [ ] Complex numbers, datetime
|
|
266
|
-
- [ ] Optional WASM mode
|
|
267
|
-
|
|
268
|
-
See [API-REFERENCE.md](./docs/API-REFERENCE.md) for complete function checklist.
|
|
269
|
-
|
|
270
|
-
---
|
|
271
|
-
|
|
272
198
|
## Documentation
|
|
273
199
|
|
|
274
200
|
### User Documentation
|
|
275
|
-
- [API-REFERENCE.md](
|
|
201
|
+
- [API-REFERENCE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/API-REFERENCE.md) - Complete API checklist
|
|
276
202
|
|
|
277
203
|
### Developer Documentation
|
|
278
|
-
- [
|
|
279
|
-
- [
|
|
280
|
-
- [benchmarks/README.md](./benchmarks/README.md) - Performance benchmarking guide
|
|
204
|
+
- [TESTING-GUIDE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/TESTING-GUIDE.md) - How to add tests (unit, validation, benchmarks)
|
|
205
|
+
- [benchmarks/README.md](https://github.com/dupontcyborg/numpy-ts/blob/main/benchmarks/README.md) - Performance benchmarking guide
|
|
281
206
|
|
|
282
207
|
---
|
|
283
208
|
|
|
@@ -323,25 +248,26 @@ it('int8 overflow wraps like NumPy', () => {
|
|
|
323
248
|
|
|
324
249
|
## Design Decisions
|
|
325
250
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
### 2. No Complex Number Support (for now)
|
|
330
|
-
Removed in favor of simplicity and focus on core numeric types. Can be added back if there's demand.
|
|
251
|
+
**Pure TypeScript Implementation**
|
|
252
|
+
- Built from scratch without heavy dependencies
|
|
253
|
+
- Focus on correctness and NumPy compatibility
|
|
331
254
|
|
|
332
|
-
|
|
333
|
-
|
|
255
|
+
**BigInt for int64/uint64**
|
|
256
|
+
- Exact representation over convenience
|
|
257
|
+
- No precision loss (different type but fully accurate)
|
|
334
258
|
|
|
335
|
-
|
|
336
|
-
|
|
259
|
+
**String-Based Slicing**
|
|
260
|
+
- `arr.slice('0:5', ':')` instead of `arr[0:5, :]`
|
|
261
|
+
- TypeScript limitation, Pythonic compromise
|
|
337
262
|
|
|
338
|
-
|
|
339
|
-
|
|
263
|
+
**View Tracking**
|
|
264
|
+
- Track base array with `base` attribute
|
|
265
|
+
- Zero-copy optimizations where possible
|
|
266
|
+
- Matches NumPy semantics
|
|
340
267
|
|
|
341
|
-
|
|
342
|
-
Validate
|
|
343
|
-
|
|
344
|
-
See [ARCHITECTURE.md](./docs/ARCHITECTURE.md) for full rationale.
|
|
268
|
+
**Correctness First**
|
|
269
|
+
- Validate against Python NumPy before optimizing
|
|
270
|
+
- Performance improvements (WASM/SIMD) come later
|
|
345
271
|
|
|
346
272
|
---
|
|
347
273
|
|
|
@@ -360,8 +286,8 @@ npm test
|
|
|
360
286
|
|
|
361
287
|
### Adding New Features
|
|
362
288
|
|
|
363
|
-
1. Pick a function from [API-REFERENCE.md](
|
|
364
|
-
2. Follow the [TESTING-GUIDE.md](
|
|
289
|
+
1. Pick a function from [API-REFERENCE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/API-REFERENCE.md)
|
|
290
|
+
2. Follow the [TESTING-GUIDE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/TESTING-GUIDE.md) to add:
|
|
365
291
|
- Implementation in `src/`
|
|
366
292
|
- Unit tests in `tests/unit/`
|
|
367
293
|
- NumPy validation tests in `tests/validation/`
|
|
@@ -370,7 +296,7 @@ npm test
|
|
|
370
296
|
4. Run benchmarks: `npm run bench:quick`
|
|
371
297
|
5. Submit a pull request
|
|
372
298
|
|
|
373
|
-
See [TESTING-GUIDE.md](
|
|
299
|
+
See [TESTING-GUIDE.md](https://github.com/dupontcyborg/numpy-ts/blob/main/docs/TESTING-GUIDE.md) for detailed instructions on adding tests.
|
|
374
300
|
|
|
375
301
|
---
|
|
376
302
|
|
|
@@ -405,38 +331,36 @@ npm run bench:view
|
|
|
405
331
|
|
|
406
332
|
### Performance Overview
|
|
407
333
|
|
|
408
|
-

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