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

bessel-via-amos.js

v1.0.0

Published

Transpile AMOS Fortran library to JavaScript/WebAssembly and export a couple of functions

Downloads

1

Readme

This is a very hastily-put-together library to export Scipy's kv and kve functions (modified Bessel functions of the second kind) to JavaScript/Node via WebAssembly.

The Scipy functions call a public domain Fortran library called AMOS, which were converted to C via f2c, which were then transpiled to WebAssembly via Emscripten.

This library adds some light library sugar around AMOS to give export a Scipy-like syntax.

Note: although AMOS and Scipy both operate on arrays of inputs, this library only exports JavaScript to handle scalar inputs because I can't figure out how to make Emscripten call AMOS' ZBESK routine fully. This is very much a proof-of-concept and AMOS deserves to be brought fully into WebAssembly (not just these two functions), and hopefully this library can help towards that goal.

Installation

npm i bessel-via-amos.js

Usage

TypeScript:

import amosPromise from 'bessel-via-amos.js';
(async function main() {
  const amos = await amosPromise;
  console.log(amos.kve(4.4, 3.3));
})();

Browser: I'm not sure but it hopefully won't be hard.

Dev

Diary of how I made this.

First set up miniconda, then

conda create -n amos-env
conda activate amos-env
conda install -c conda-forge f2c # might need more things

Now get AMOS, via Scipy.

git clone https://github.com/scipy/scipy.git --depth=1
cp -pr scipy/scipy/special/amos .
cd amos

curl -LO http://www.netlib.org/blas/i1mach.f 
curl -LO http://www.netlib.org/blas/r1mach.f
curl -LO http://www.netlib.org/blas/d1mach.f 

f2c *f

export CONDA_TOP_LEVEL=`conda info --envs | grep '*' | awk '{print $NF}'`

gcc -lf2c -L $CONDA_TOP_LEVEL/lib  -I $CONDA_TOP_LEVEL/include *c -o main
DYLD_LIBRARY_PATH=$CONDA_TOP_LEVEL/lib ./main

For emscripten, first install Emscripten and activate emsdk. Then

git clone https://github.com/gergondet/libf2c-emscripten
cd libf2c-emscripten
make -j4
cp f2c.h libf2c.a /PATH/TO/amos-js/amos

I haven't bundled these because likely as emsdk advances, these files will change?

Then back in amos, ensuring that emsdk is installed and activated,

emcc -lm -lf2c -L. *c

Confirm this runs and outputs something like cyr=7.443113:

node a.out.js

Now to make a library:

emcc -Os -lm -lf2c -L. -sMODULARIZE -sEXPORTED_FUNCTIONS=_kve,_kv,_zbesk_ *c

Now

cp a.out.* ../

And run node demo.js and confirm that it prints out 7.44311267732952.