Generated Computers
Locals: an Apple Silicon engine that runs local LLMs up to 3x faster. A product of Generated Computers.
翻譯準備中
尚未偵測到更新。GitHub 發布版本後會顯示在這裡。
個人 GitHub 帳號下公開儲存庫的擁有者可以登入並驗證所有權,自行管理介紹,無需管理員核准。
登入並產生驗證檔案,在 30 分鐘內將其提交至此儲存庫的預設分支。其他分支或分叉儲存庫中的檔案無效。然後在下方檢查檔案,即可無需管理員核准直接管理專案。請保留檔案以維持管理權限。
如需登入,將前往登入頁面。登入後請回到此處,再次點擊所選的驗證按鈕。
在專案資料夾中執行 /nomorevibe verify,即可驗證所有權並自行管理介紹。
一分鐘完成驗證Javascript library for n-dimensional arrays with numpy syntax
翻譯準備中
取自儲存庫 README
正在載入完整 README。
檢視完整 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]