npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nqx

v0.0.4

Published

Numerical computing extensions for JavaScript.

Downloads

10

Readme

nqx

A NumPy-like library in the browser, running on the GPU, with automatic differentiation and JIT compilation.

Accelerated numerical computing extensions for JavaScript.

This is a numerical computing library that runs in the browser through WebGPU, enabling fast matrix and linear algebra operations for machine learning, computer graphics, generative art, and scientific computing.

Getting Started

Install the package to add it to your JavaScript project.

npm install nqx

Then, you can start writing code:

import { createEngine } from nqx;

const nqx = createEngine("webgpu");
await nqx.ready();

const x = nqx.array([1, 2, 3]);
const y = nqx.array([4, 5, 6]);
const z = x.add(y);

await z.js();                   // [5, 7, 9]
await z.print();                // array([5., 7., 9.], dtype=float32)
await x.mul(y.add(1)).print();  // array([5., 12., 21.], dtype=float32)

Non-Bundler Usage

If you don't want to use a bundler or don't have an appropriate toolchain, you can import nqx directly from a CDN.

<script type="module">
  import { createEngine } from "https://unpkg.com/nqx/dist/nqx.js";

  const nqx = createEngine("webgpu");
  await nqx.ready();

  const x = nqx.array([1, 2, 3]);
  await x.print();
</script>

If you're not using JavaScript modules, you can still use a script tag. This allows you to access the library from the NQX global variable.

<script src="https://unpkg.com/nqx/dist/nqx.iife.js"></script>
<script>
  (async () => {
    const nqx = NQX.createEngine("webgpu");
    await nqx.ready();

    const x = nqx.array([1, 2, 3]);
    await x.print();
  })();
</script>

Development

This library is written in TypeScript and developed primarily using Vite. Run npm install to download dependencies and npm test to run tests, fully in the browser. You may need to install Chrome web driver components as prompted.

To bundle the library for distribution, run npm run build. This produces build artifacts in the dist folder.

Comparisons

This library is inspired by influential work in the Python ecosystem: NumPy and JAX, as well as the related libraries derived from them (to varying degrees: PyTorch, Tensorflow, Xarray, Dask, etc.). It's meant to fill the void of a simple, fast, and reliable system for numerical coding. What would be the JavaScript or web-based equivalent of that?

The state-of-the-art for GPU-accelerated computing in JavaScript has developers writing their own WebGL or WebGPU shaders, which is awkward and time-consuming. No Python developer would ever write their own CUDA kernels or BLAS implementations!

Compared to TensorFlow.js, nqx is much simpler and smaller, and it provides some key advantages:

  • Uses native JavaScript data types and has a concise API.
  • Not limited to machine learning use cases.
  • More flexible, offering forward and reverse-mode automatic differentiation for arbitrary functions, including second and higher derivatives.
  • (Planned) Includes a tracing JIT compiler for numerical operations with automatic kernel fusion.
  • (Planned) Has a multithreaded WebAssembly backend with clean exchange between arrays stored on CPU and GPU devices.

However, there are some drawbacks:

  • Newer library, not backed by a team of paid developers at Google.
  • No support for binary Node.js and legacy WebGL backends.
  • No plans for adding a Keras-like API.

License

nqx is provided under the MIT license. See LICENSE.