numpy-ts 0.1.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.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * numpy-ts - Complete NumPy implementation for TypeScript and JavaScript
3
+ *
4
+ * @module numpy-ts
5
+ */
6
+ export { NDArray, zeros, ones, array, arange, linspace, logspace, geomspace, eye, empty, full, identity, asarray, copy, zeros_like, ones_like, empty_like, full_like, } from './core/ndarray';
7
+ export declare const __version__: string;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Computation backend abstraction
3
+ *
4
+ * Internal module for element-wise and broadcast operations.
5
+ * Provides a swappable backend for different computation strategies.
6
+ *
7
+ * @internal
8
+ */
9
+ import { ArrayStorage } from '../core/storage';
10
+ /**
11
+ * Perform element-wise operation with broadcasting
12
+ *
13
+ * @param a - First array storage
14
+ * @param b - Second array storage
15
+ * @param op - Operation to perform (a, b) => result
16
+ * @param opName - Name of operation (for special handling)
17
+ * @returns Result storage
18
+ */
19
+ export declare function elementwiseBinaryOp(a: ArrayStorage, b: ArrayStorage, op: (a: number, b: number) => number, opName: string): ArrayStorage;
20
+ /**
21
+ * Perform element-wise comparison with broadcasting
22
+ * Returns boolean array (dtype: 'bool', stored as Uint8Array)
23
+ */
24
+ export declare function elementwiseComparisonOp(a: ArrayStorage, b: ArrayStorage, op: (a: number, b: number) => boolean): ArrayStorage;
25
+ //# sourceMappingURL=compute.d.ts.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Indexing utilities for array operations
3
+ * @internal
4
+ */
5
+ /**
6
+ * Compute row-major strides for a given shape
7
+ */
8
+ export declare function computeStrides(shape: readonly number[]): number[];
9
+ /**
10
+ * Convert multi-index to linear index in row-major order
11
+ */
12
+ export declare function multiIndexToLinear(indices: number[], shape: readonly number[]): number;
13
+ /**
14
+ * Convert outer index and axis index to full multi-index
15
+ * Used in reductions along a specific axis
16
+ *
17
+ * @param outerIdx - Linear index in the reduced (output) array
18
+ * @param axis - The axis being reduced
19
+ * @param axisIdx - Position along the reduction axis
20
+ * @param shape - Original array shape
21
+ * @returns Full multi-index in the original array
22
+ */
23
+ export declare function outerIndexToMultiIndex(outerIdx: number, axis: number, axisIdx: number, shape: readonly number[]): number[];
24
+ //# sourceMappingURL=indexing.d.ts.map
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Arithmetic operations
3
+ *
4
+ * Pure functions for element-wise arithmetic operations:
5
+ * add, subtract, multiply, divide
6
+ *
7
+ * These functions are used by NDArray methods but are separated
8
+ * to keep the codebase modular and testable.
9
+ */
10
+ import { ArrayStorage } from '../core/storage';
11
+ /**
12
+ * Add two arrays or array and scalar
13
+ *
14
+ * @param a - First array storage
15
+ * @param b - Second array storage or scalar
16
+ * @returns Result storage
17
+ */
18
+ export declare function add(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
19
+ /**
20
+ * Subtract two arrays or array and scalar
21
+ *
22
+ * @param a - First array storage
23
+ * @param b - Second array storage or scalar
24
+ * @returns Result storage
25
+ */
26
+ export declare function subtract(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
27
+ /**
28
+ * Multiply two arrays or array and scalar
29
+ *
30
+ * @param a - First array storage
31
+ * @param b - Second array storage or scalar
32
+ * @returns Result storage
33
+ */
34
+ export declare function multiply(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
35
+ /**
36
+ * Divide two arrays or array and scalar
37
+ *
38
+ * NumPy behavior: Integer division always promotes to float
39
+ * Type promotion rules:
40
+ * - float64 + anything → float64
41
+ * - float32 + integer → float32
42
+ * - integer + integer → float64
43
+ *
44
+ * @param a - First array storage
45
+ * @param b - Second array storage or scalar
46
+ * @returns Result storage with promoted float dtype
47
+ */
48
+ export declare function divide(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
49
+ //# sourceMappingURL=arithmetic.d.ts.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Comparison operations
3
+ *
4
+ * Element-wise comparison operations that return boolean arrays:
5
+ * greater, greater_equal, less, less_equal, equal, not_equal,
6
+ * isclose, allclose
7
+ */
8
+ import { ArrayStorage } from '../core/storage';
9
+ /**
10
+ * Element-wise greater than comparison (a > b)
11
+ */
12
+ export declare function greater(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
13
+ /**
14
+ * Element-wise greater than or equal comparison (a >= b)
15
+ */
16
+ export declare function greaterEqual(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
17
+ /**
18
+ * Element-wise less than comparison (a < b)
19
+ */
20
+ export declare function less(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
21
+ /**
22
+ * Element-wise less than or equal comparison (a <= b)
23
+ */
24
+ export declare function lessEqual(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
25
+ /**
26
+ * Element-wise equality comparison (a == b)
27
+ */
28
+ export declare function equal(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
29
+ /**
30
+ * Element-wise inequality comparison (a != b)
31
+ */
32
+ export declare function notEqual(a: ArrayStorage, b: ArrayStorage | number): ArrayStorage;
33
+ /**
34
+ * Element-wise "close" comparison with tolerance
35
+ * Returns true where |a - b| <= atol + rtol * |b|
36
+ */
37
+ export declare function isclose(a: ArrayStorage, b: ArrayStorage | number, rtol?: number, atol?: number): ArrayStorage;
38
+ /**
39
+ * Check if all elements are close (scalar result)
40
+ * Returns true if all elements satisfy isclose condition
41
+ */
42
+ export declare function allclose(a: ArrayStorage, b: ArrayStorage | number, rtol?: number, atol?: number): boolean;
43
+ //# sourceMappingURL=comparison.d.ts.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Linear algebra operations
3
+ *
4
+ * Pure functions for matrix operations (matmul, etc.).
5
+ * @module ops/linalg
6
+ */
7
+ import { ArrayStorage } from '../core/storage';
8
+ /**
9
+ * Matrix multiplication
10
+ * Requires 2D arrays with compatible shapes
11
+ *
12
+ * Note: Currently uses float64 precision for all operations.
13
+ * Integer inputs are promoted to float64 (matching NumPy behavior).
14
+ */
15
+ export declare function matmul(a: ArrayStorage, b: ArrayStorage): ArrayStorage;
16
+ //# sourceMappingURL=linalg.d.ts.map
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Reduction operations (sum, mean, max, min)
3
+ *
4
+ * Pure functions for reducing arrays along axes.
5
+ * @module ops/reduction
6
+ */
7
+ import { ArrayStorage } from '../core/storage';
8
+ /**
9
+ * Sum array elements over a given axis
10
+ */
11
+ export declare function sum(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
12
+ /**
13
+ * Compute the arithmetic mean along the specified axis
14
+ * Note: mean() returns float64 for integer dtypes, matching NumPy behavior
15
+ */
16
+ export declare function mean(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
17
+ /**
18
+ * Return the maximum along a given axis
19
+ */
20
+ export declare function max(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
21
+ /**
22
+ * Product array elements over a given axis
23
+ */
24
+ export declare function prod(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
25
+ /**
26
+ * Return the minimum along a given axis
27
+ */
28
+ export declare function min(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | number;
29
+ /**
30
+ * Return the indices of the minimum values along a given axis
31
+ */
32
+ export declare function argmin(storage: ArrayStorage, axis?: number): ArrayStorage | number;
33
+ /**
34
+ * Return the indices of the maximum values along a given axis
35
+ */
36
+ export declare function argmax(storage: ArrayStorage, axis?: number): ArrayStorage | number;
37
+ /**
38
+ * Compute the variance along the specified axis
39
+ * @param storage - Input array storage
40
+ * @param axis - Axis along which to compute variance
41
+ * @param ddof - Delta degrees of freedom (default: 0)
42
+ * @param keepdims - Keep dimensions (default: false)
43
+ */
44
+ export declare function variance(storage: ArrayStorage, axis?: number, ddof?: number, keepdims?: boolean): ArrayStorage | number;
45
+ /**
46
+ * Compute the standard deviation along the specified axis
47
+ * @param storage - Input array storage
48
+ * @param axis - Axis along which to compute std
49
+ * @param ddof - Delta degrees of freedom (default: 0)
50
+ * @param keepdims - Keep dimensions (default: false)
51
+ */
52
+ export declare function std(storage: ArrayStorage, axis?: number, ddof?: number, keepdims?: boolean): ArrayStorage | number;
53
+ /**
54
+ * Test whether all array elements along a given axis evaluate to True
55
+ */
56
+ export declare function all(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | boolean;
57
+ /**
58
+ * Test whether any array elements along a given axis evaluate to True
59
+ */
60
+ export declare function any(storage: ArrayStorage, axis?: number, keepdims?: boolean): ArrayStorage | boolean;
61
+ //# sourceMappingURL=reduction.d.ts.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Shape manipulation operations
3
+ *
4
+ * Pure functions for reshaping, transposing, and manipulating array dimensions.
5
+ * @module ops/shape
6
+ */
7
+ import { ArrayStorage } from '../core/storage';
8
+ /**
9
+ * Reshape array to a new shape
10
+ * Returns a view if array is C-contiguous, otherwise copies data
11
+ */
12
+ export declare function reshape(storage: ArrayStorage, newShape: number[]): ArrayStorage;
13
+ /**
14
+ * Return a flattened copy of the array
15
+ * Creates 1D array containing all elements in row-major order
16
+ * Always returns a copy (matching NumPy behavior)
17
+ */
18
+ export declare function flatten(storage: ArrayStorage): ArrayStorage;
19
+ /**
20
+ * Return a flattened array (view when possible, otherwise copy)
21
+ * Returns a view if array is C-contiguous, otherwise copies data
22
+ */
23
+ export declare function ravel(storage: ArrayStorage): ArrayStorage;
24
+ /**
25
+ * Transpose array (permute dimensions)
26
+ * Returns a view with transposed dimensions
27
+ */
28
+ export declare function transpose(storage: ArrayStorage, axes?: number[]): ArrayStorage;
29
+ /**
30
+ * Remove axes of length 1
31
+ * Returns a view with specified dimensions removed
32
+ */
33
+ export declare function squeeze(storage: ArrayStorage, axis?: number): ArrayStorage;
34
+ /**
35
+ * Expand the shape by inserting a new axis of length 1
36
+ * Returns a view with additional dimension
37
+ */
38
+ export declare function expandDims(storage: ArrayStorage, axis: number): ArrayStorage;
39
+ //# sourceMappingURL=shape.d.ts.map
package/package.json ADDED
@@ -0,0 +1,121 @@
1
+ {
2
+ "name": "numpy-ts",
3
+ "version": "0.1.0",
4
+ "description": "Complete NumPy implementation for TypeScript and JavaScript (under construction)",
5
+ "main": "dist/numpy-ts.node.cjs",
6
+ "browser": "dist/numpy-ts.browser.js",
7
+ "module": "dist/numpy-ts.esm.js",
8
+ "types": "dist/types/index.d.ts",
9
+ "type": "module",
10
+ "files": [
11
+ "dist/**/*.js",
12
+ "dist/**/*.cjs",
13
+ "dist/types/**/*.d.ts",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/types/index.d.ts",
20
+ "node": "./dist/numpy-ts.node.cjs",
21
+ "browser": "./dist/numpy-ts.browser.js",
22
+ "default": "./dist/numpy-ts.esm.js"
23
+ },
24
+ "./node": {
25
+ "types": "./dist/types/node.d.ts",
26
+ "default": "./dist/numpy-ts.node.cjs"
27
+ },
28
+ "./browser": {
29
+ "types": "./dist/types/browser.d.ts",
30
+ "default": "./dist/numpy-ts.browser.js"
31
+ }
32
+ },
33
+ "scripts": {
34
+ "dev": "esbuild src/index.ts --bundle --sourcemap --watch --outfile=dist/numpy-ts.dev.js",
35
+ "build": "npm run build:clean && tsx build.ts && npm run build:types",
36
+ "build:clean": "rm -rf dist",
37
+ "build:types": "tsc --emitDeclarationOnly --outDir dist/types",
38
+ "test": "vitest run --project=unit --project=validation",
39
+ "test:quick": "vitest run --project=quick",
40
+ "test:unit": "vitest run --project=unit",
41
+ "test:validation": "vitest run --project=validation",
42
+ "test:bundles": "npm run build && vitest run --project=bundle-node --project=bundle-esm --project=bundle-browser",
43
+ "test:ci": "npm run lint && npm run typecheck && npm test && npm run test:bundles",
44
+ "test:summary": "vitest run --reporter=tap | grep -E 'not ok|# tests'",
45
+ "test:watch": "vitest watch",
46
+ "test:coverage": "vitest run tests/unit --coverage",
47
+ "test:coverage:view": "vitest run tests/unit --coverage; open coverage/index.html",
48
+ "test:coverage:all": "vitest run --coverage",
49
+ "lint": "eslint src tests --ext .ts",
50
+ "lint:fix": "eslint src tests --ext .ts --fix",
51
+ "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
52
+ "format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
53
+ "typecheck": "tsc --noEmit",
54
+ "bench:build": "esbuild benchmarks/src/index.ts --bundle --platform=node --format=cjs --outfile=benchmarks/dist/bench.cjs",
55
+ "bench": "npm run bench:build && node benchmarks/dist/bench.cjs",
56
+ "bench:quick": "npm run bench:build && node benchmarks/dist/bench.cjs --quick",
57
+ "bench:standard": "npm run bench:build && node benchmarks/dist/bench.cjs --standard",
58
+ "bench:full": "npm run bench:build && node benchmarks/dist/bench.cjs --full",
59
+ "bench:category": "npm run bench:build && node benchmarks/dist/bench.cjs --category",
60
+ "bench:view": "open benchmarks/results/plots/latest.html || xdg-open benchmarks/results/plots/latest.html"
61
+ },
62
+ "keywords": [
63
+ "numpy",
64
+ "array",
65
+ "ndarray",
66
+ "matrix",
67
+ "linear-algebra",
68
+ "scientific-computing",
69
+ "math",
70
+ "statistics",
71
+ "fft",
72
+ "typescript",
73
+ "javascript"
74
+ ],
75
+ "author": "Nicolas Dupont",
76
+ "license": "MIT",
77
+ "repository": {
78
+ "type": "git",
79
+ "url": "https://github.com/dupontcyborg/numpy-ts.git"
80
+ },
81
+ "bugs": {
82
+ "url": "https://github.com/dupontcyborg/numpy-ts/issues"
83
+ },
84
+ "homepage": "https://github.com/dupontcyborg/numpy-ts#readme",
85
+ "devDependencies": {
86
+ "@stdlib/types": "^0.4.3",
87
+ "@types/node": "^24.9.1",
88
+ "@typescript-eslint/eslint-plugin": "^8.46.2",
89
+ "@typescript-eslint/parser": "^8.46.2",
90
+ "@vitest/browser": "^4.0.3",
91
+ "@vitest/browser-playwright": "^4.0.3",
92
+ "@vitest/coverage-v8": "^4.0.3",
93
+ "chart.js": "^4.5.1",
94
+ "chartjs-node-canvas": "^5.0.0",
95
+ "esbuild": "^0.25.11",
96
+ "eslint": "^9.38.0",
97
+ "eslint-config-prettier": "^10.1.8",
98
+ "eslint-plugin-prettier": "^5.0.1",
99
+ "husky": "^9.1.7",
100
+ "lint-staged": "^16.2.6",
101
+ "playwright": "^1.56.1",
102
+ "prettier": "^3.1.1",
103
+ "ts-node": "^10.9.2",
104
+ "tsx": "^4.20.6",
105
+ "typescript": "^5.3.3",
106
+ "vitest": "^4.0.3"
107
+ },
108
+ "dependencies": {
109
+ "@stdlib/blas": "^0.3.3",
110
+ "@stdlib/ndarray": "^0.3.3"
111
+ },
112
+ "engines": {
113
+ "node": ">=18.0.0"
114
+ },
115
+ "lint-staged": {
116
+ "*.ts": [
117
+ "eslint --fix",
118
+ "prettier --write"
119
+ ]
120
+ }
121
+ }