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

nadder

v0.0.3

Published

ndarray/tensor data processing for modern browsers

Downloads

12

Readme

nadder

Easy n-dimensional data manipulation with NumPy syntax.

Installation

npm i nadder # or yarn add nadder, or pnpm add nadder

Usage

import { ndarray, array, add, evaluate, arange } from 'nadder';

const dataSource = new Float32Array(1_000_000);
// load data into dataSource manually here...

// Initialize (1000, 1000) ndarray
const t = ndarray(dataSource, [1000, 1000]);

// NumPy slicing fully supported
console.log(t['100:110, 305:300:-1']);

t['..., :100'] = 1.23;

// np.newaxis is now +
console.log(t['0, 0, +']);

const leapYears = Array.from(
    { length: 1000 },
    (_, i) => i % 4 == 0 && (i % 400 == 0 || i % 100 != 0)
);

// nadder.array automatically creates an efficient representation of your
// Array object and translates nested lists into dimensions in the ndarray
const boolIndex = array(leapYears);

// You can even use other ndarrays in the indices!

console.log(t[`..., ${boolIndex}`]);

// You can evaluate things using a Python-esque DSL
console.log(evaluate`${t}[:, 0] * 2 + 1 / ${arange(1000)}`)

// ufuncs also supported through explicit syntax
// broadcasting, typecasting done automatically
console.log(add(t, boolIndex));

The embedded DSL supports a wide variety of common constructs and Python syntax (e.g. @ matrix multiplication, // floor division, keyword arguments). All syntax works both on scalars and ndarrays. The DSL can also use JavaScript values interpolated within the code.

import { parse, argument, arange } from 'nadder';

const calcTrace = parse`
  mat = ${argument('matrix')}.astype(float64);
  n = mat.shape[0];
  trace = 0;

  if ${process.env.DEBUG} {
    ${console.log}(mat);
  }

  for i in arange(n) {
    trace += mat[i, i];
  }

  # Last line with no semicolon is the return value
  trace
`;

// 13
const example = calcTrace({
  matrix: array([
    [1, 4, 5],
    [2, 3, 6],
    [7, 1, 9]
  ])
});

// [154., 158., 162., 166., 170.]
const multiElem = calcTrace({
  matrix: arange(1, 81).reshape(4, 4, 5)
});

Features

  • NumPy syntax and evaluation via evaluate
    • Python-esque syntax and ndarray manipulation
    • Support for most numeric operations
    • Conditionals, for/while loops, JavaScript interpolation
  • Ergonomic NumPy slicing, broadcasting with or without evaluate
    • All NumPy bracket syntax and indexing routines supported
  • Matrix manipulation and matmul
  • Tiny: under 20kB gzipped
  • Performant view-based manipulation; minimal copying
  • Fast bitset-backed boolean ndarrays
  • Interleaved complex numbers
  • Arithmetic, algebraic, and trigonometric operations for real and complex numbers
  • Full TypeScript support
  • In progress: support for most NumPy manipulations, more fast paths for higher performance, fast WASM modules

Limitations

  • Fortran (column-major) memory layout supported indirectly
  • Limited Complex64 support (Complex128 fully supported)

License

MIT