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 CHANGED
@@ -5,28 +5,23 @@ Complete NumPy implementation for TypeScript and JavaScript
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
6
6
  ![Under Construction](https://img.shields.io/badge/Under%20Construction-red)
7
7
 
8
- > [!WARNING]
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, functionally-equivalent implementation of NumPy 2.0+ for the JavaScript ecosystem. (At least that's the goal!)
14
+ A complete NumPy 2.0+ implementation for TypeScript/JavaScript, validated against Python NumPy.
16
15
 
17
- ### Goals
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
- - ✅ **100% NumPy 2.0+ API** - All 800+ functions
20
- - **Full Type Safety** - Complete TypeScript definitions
21
- - **Cross-Platform** - Node.js and browsers
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
- Computational Backend
124
- @stdlib (BLAS/LAPACK)
120
+ TypeScript/JavaScript Core
121
+ Computational Engine
125
122
  └────────────────────────────────┘
126
123
  ```
127
124
 
128
- **We build**: NumPy API, NDArray class, broadcasting, slicing, view tracking
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` (using optimized BLAS)
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 (Future)
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/node';
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](./docs/API-REFERENCE.md) - Complete API checklist
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](./docs/ARCHITECTURE.md) - Design and implementation details
280
- - [TESTING-GUIDE.md](./docs/TESTING-GUIDE.md) - How to add tests (unit, validation, benchmarks)
281
- - [IMPLEMENTATION-NOTES.md](./docs/IMPLEMENTATION-NOTES.md) - Development notes and decisions
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
- ### 1. BigInt for int64/uint64
329
- Exact representation over convenience. Different type but no precision loss.
252
+ **Pure TypeScript Implementation**
253
+ - Built from scratch without heavy dependencies
254
+ - Focus on correctness and NumPy compatibility
330
255
 
331
- ### 2. No Complex Number Support (for now)
332
- Removed in favor of simplicity and focus on core numeric types. Can be added back if there's demand.
256
+ **BigInt for int64/uint64**
257
+ - Exact representation over convenience
258
+ - No precision loss (different type but fully accurate)
333
259
 
334
- ### 3. String-Based Slicing
335
- `arr.slice('0:5', ':')` instead of `arr[0:5, :]` - TypeScript limitation, Pythonic compromise.
260
+ **String-Based Slicing**
261
+ - `arr.slice('0:5', ':')` instead of `arr[0:5, :]`
262
+ - TypeScript limitation, Pythonic compromise
336
263
 
337
- ### 4. View Tracking
338
- Track base array for views with `base` attribute. Enables zero-copy optimizations and matches NumPy semantics.
264
+ **View Tracking**
265
+ - Track base array with `base` attribute
266
+ - Zero-copy optimizations where possible
267
+ - Matches NumPy semantics
339
268
 
340
- ### 5. @stdlib Under the Hood
341
- Use battle-tested BLAS/LAPACK implementations. Focus on API, not reimplementing algorithms.
269
+ **Correctness First**
270
+ - Validate against Python NumPy before optimizing
271
+ - Performance improvements (WASM/SIMD) come later
342
272
 
343
- ### 6. Correctness First
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](./docs/API-REFERENCE.md)
366
- 2. Follow the [TESTING-GUIDE.md](./docs/TESTING-GUIDE.md) to add:
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](./docs/TESTING-GUIDE.md) for detailed instructions on adding tests.
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
- # Run quick benchmarks (~1-2 min)
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
- # Run comprehensive benchmarks (~30-60 min)
403
- npm run bench:full
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
- ![Benchmark Results](./benchmarks/results/plots/latest.png)
337
+ ![Benchmark Results](https://github.com/dupontcyborg/numpy-ts/blob/main/benchmarks/results/plots/latest.png)
412
338
 
413
- See [benchmarks/README.md](./benchmarks/README.md) for detailed benchmarking guide.
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** (Pure JS + @stdlib):
420
- - 10-100x slower than NumPy - acceptable for correctness focus
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
- **v3.0** (Advanced):
426
- - 1-10x slower - SIMD, GPU for specific operations
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
- Focus is correctness and completeness first, then performance.
354
+ Correctness and completeness first, then performance.
429
355
 
430
356
  ---
431
357
 
432
358
  ## License
433
359
 
434
- [MIT License](./LICENSE) - Copyright (c) 2025 Nicolas Dupont
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!** ⭐