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

ndarray-tests

v1.3.0

Published

Test numerical properties of ndarrays

Downloads

21

Readme

ndarray-tests

Build Status npm version Dependency Status

Test numerical properties of ndarrays

Intro

I very quickly got sick of testing matrix equality by hand over and over. This package implements methods for testing near-equality and other properties of ndarrays. Its goal is to be a set of test helpers so that it's not necessary to hard-code numbers. Decompositions aren't always unique (e.g. orthogonal columns may be chosen arbitrarily in some cases as long as they're orthogonal), so it's probably better to test properties than numbers.

Note that some obvious tests are ommitted because they're one-liners.

Please feel free to make any suggestions/contributions for how to more clearly and consistently define specific property tests.

Usage

Require the library and use the methods described below. The onFalse callback is optional and serves only to simplify passing data while allowing the function to return a boolean. Tolerances are always assumed to be zero (exact equality) unless otherwise specified.

var ndtest = require('ndarray-tests');

ndtest.matrixIsOrthogonal(A,B,1e-4); // returns boolean


// Returns boolean and if it fails, passes explanation to callback
ndtest.matrixIsOrthogonal(A,B,1e-4,function(message) {
  console.log(message);
});

Methods:

same dimensions:

Keep it simple and just ask, e.g.: assert( a.dimension === b.dimension )

same shape:

Keep it simple and just ask, e.g.: assert.deepEqual( a.shape, b.shape )

================

equal( a, b [, tol] [, onFalse] )

Test whether the maximum element-wise difference between a and b (the L-infinity norm of (a - b)) is less than the tolerance. Works on arrays of any dimension. The test will return false if any entry is NaN.

approximatelyEqual( a, b [, tol] [, onFalse] )

Alias for equal, just to make things read clearly.

================

Vector tests:

vectorIsNormalized( a [, tol], [, onFalse] )

Test whether the L-2 norm of a is within tol of unity.

vectorsAreOrthogonal( a, b, [, tol], [, onFalse] )

Test whether the inner product of vectors a and b is within tol of zero.

vectorsAreOrthonormal( a, b, [, tol], [, onFalse] )

Test whether vectors a and b are both normalized and orthogonal using vectorIsNormalized and vectorsAreOrthogonal.

================

Matrix tests:

matrixIsSymmetric( a [, tol], [, onFalse] )

Test for element-wise symmetry. Returns false if the difference between any element and its counterpart is greater than the tolerance.

matrixColsAreNormalized( a [, tol], [, onFalse] )

Test whether the L2 norm of every column is within tol of 1.

matrixColsAreOrthogonal( a [, tol], [, onFalse] )

Test whether the pairwise inner product of all column pairs is less than tol.

matrixIsOrthogonal( a [, tol], [, onFalse] )

Checks for squareness, column normality, and pair-wise column orthogonality to check if the matrix is orthogonal. tol is passed to the matrixColsAreNormal and matrixColsAreOrthogonal

matrixIsUpperTriangular( a, [, tol] [, onFalse] )

Check whether all entries below the diagonal are within tol of zero. Works on tall and wide two-dimensional ndarrays.

matrixIsLowerTriangular( a, [, tol] [, onFalse] )

Check whether all entries above the diagonal are within tol of zero. Works on tall and wide two-dimensional ndarrays.

TO DO:

  • diagonal( a, [, tol] [, onFalse] )
  • separate column methods to allow testing of specific pair-wise columns (or maybe that's simple enough that it's unnecessary)

Credits

(c) 2015 Ricky Reusser. MIT License