Generated Computers
Locals: an Apple Silicon engine that runs local LLMs up to 3x faster. A product of Generated Computers.
Translation pending
Documentation for ndarray-js
Translation pending
Developer toolsTypeScript · Jupyter NotebookGitHub @caph1993OnlineOwner unconfirmed
Have you tried it? One tap is enough. No sign-in needed.
No updates detected yet. GitHub releases will appear here.
Owners of public repositories under a personal GitHub account can sign in to verify ownership and manage the introduction themselves. No administrator approval is needed.
Sign in, generate a verification file, and commit it to this repository’s default branch within 30 minutes. Files on other branches or forks do not count. Then check the file below to manage the project without administrator approval. Keep the file to retain your access.
If needed, you will go to sign-in. After signing in, return here and press your chosen verification button again.
Run /nomorevibe verify in your project folder to verify ownership and manage the introduction yourself.
Verify in one minuteAsk about other verification options
Javascript library for n-dimensional arrays with numpy syntax
Taken from the repository README
Loading the full README.
Read the full README ↗ndarray-js is a reimplementation of numpy for javascript that aims to make the coding experience as similar to numpy as possible.
Documentation and interactive demo: click here.
The library implements a large subset of numpy operations (see the documentation website)
// Feature 1: A parsing system that can interpret numpy code as ndarray-js instructions
x = np`np.exp(0.5 * np.linspace(0, 1, 100).reshape(5, 4, 5)).mean(axis=0)`
y = np`(${x} * ${x}) / 2`
// Equivalent code:
x = np.exp(0.5 * np.linspace(0, 1, 100).reshape(5, 4, 5)).mean({axis:0})
y = np.divide(np.multiply(x * x), 2)
// Feature 2. Handling of args and kwargs following numpy order
x = np.geomspace(1, 10, 100).reshape([10,10])
x.mean({axis: -1, keepdims: true})
x.mean(-1, true)
x.mean(-1, {keepdims: true})
np.mean(x, {axis: -1})
// Feature 3. All types of indexing: (number, start:end:step, ':', '...', list of indices, NDArray boolean mask, NDArray boolean mask, NDArray indices)
y = x.index(2, ':', mask, '...', indices, '-1:-1:-2', -1);
y = np`${x}[2, :, ${mask}, ..., ${indices}, -1:-1:-2, -1]`;
// Feature 4. Broadcasting:
mu = np.array([1.5, 0]);
x = np.random.randn([100, 2]).add(x);
norm = x.pow(2).sum({axis: -1}).pow(0.5);
x.divide_assign(norm.index(':', 'None'));
for(let point2d of x){
console.log(point2d.tolist(), point2d.norm(), point2d.max());
if(np.all(point2d.equal(x.index(5)))) break;
}
// Feature 5. Most of numpy: all numeric dtypes (int8..uint64, float16..64, complex64/128), linalg, fft,
// numpy.polynomial, strings/char, npy/npz/text I/O, format_float_*, numpy-exact printing, and seeded random
// streams that reproduce numpy's (np.random.seed, RandomState, default_rng/PCG64 + SeedSequence).
np.random.seed(0);
np.random.rand(3); // [0.5488135, 0.71518937, 0.60276338], like numpy
np.random.default_rng(0).integers(0, 10, 5); // [0, 0, 1, 8, 6], like numpy
np.linalg.eigvals([[0, -1], [1, 0]]); // complex128, like numpy
np.fft.fft(np.arange(8));
Numpy-js can be used in:
<script src="https://cdn.jsdelivr.net/npm/ndarray-js@latest/dist/index.js"></script>npm install ndarray-jsCheck the documentation website for details.
'YYYY-MM-DD' strings).
sum, prod and cumsum of ints/bools are int64, like in numpy.2 from 2.0: np.array([1, 2]) is int32. Inside the template parser, float literals are kept as floats: np`np.array([1., 2])` is float64.npnp.arange(3) - np.arange(3).mean()`` is float, as in numpy).keepdims as the third argument: x.sum(axis, keepdims, dtype, out).np.array([1, 2], 'float32') + 1.5 stays float32.npm install --legacy-peer-deps
npx vitest run # unit tests, and differential tests against real numpy
NDARRAYJS_PYTHON=/path/to/venv/bin/python npx vitest run # python with numpy installed (default: python3)
The tests in tests/numpy/ evaluate the same numpy expression with python/numpy and with ndarray-js
(through its numpy-syntax parser) and compare values, shapes and dtype kinds (and that both raise on invalid input).
They are skipped when numpy is not available. Besides hand-written cases there are generated matrices
(every ufunc x dtypes x broadcasting, every reduction x axes/keepdims, ...), random expression chains
(tests/tools/gen_fuzz.py) and random indexed assignments through views (tests/tools/gen_fuzz_assign.py).
tests/types/ holds type-level checks of the public API (npm run typecheck), tests/unit/ JS-only behaviour and
performance sanity checks.
Not provided (yet):
numpy.ma (masked arrays), datetime64/timedelta64 and structured dtypes (the business-day functions work on 'YYYY-MM-DD' strings).Generator.multivariate_hypergeometric(method='count').Beyond numpy, np.group_by(keys, values?, axis?, func?) splits values by the distinct entries of keys:
const g = np.group_by(['b', 'a', 'b'], [10, 20, 30]);
g.keys.tolist(); // ['a', 'b']
g.groups.map(x => x.tolist()); // [[20], [10, 30]]
np.group_by([1, 0, 1], [1, 2, 3], {func: np.sum}).values.tolist(); // [2, 4]