Code Monkey home page Code Monkey logo

node-lapack's Introduction

node-lapack

A node.js wrapper for the high-performance LAPACK linear algebra library.

Prerequisites

This library require LAPACK to be built and installed as a shared library. In time the entire build process may be unified into this project, but that's some time away.

In the meantime I've placed some basic LAPACK build instructions at the end of this document.

Installation

npm install lapack

Usage

var lapack = require('lapack');

/*
LAPACK functions
*/

var result = lapack.sgeqrf([
    [1, 2, 3],
    [3, 4, 5],
    [5, 6, 7]
]);

console.log(result.R);
console.log(result.tau);

result = sgesvd('A', 'A', [
    [1, 2, 3],
    [3, 4, 5],
    [5, 6, 7]
]);

console.log(result.U);
console.log(result.S);
console.log(result.VT);

result = lapack.sgetrf([
    [1, 2, 3],
    [3, 4, 5],
    [5, 6, 7]
]);

console.log(result.LU);
console.log(result.IPIV);

/*
conveniently wrapped processes
*/

// perform a complete LU factorization
var lu = lapack.lu([
    [1, 2, 3],
    [3, 4, 5],
    [5, 6, 7]
]);

console.log(lu.L);
console.log(lu.U);
console.log(lu.P);


// perform a complete QR factorization
var qr = lapack.qr([
    [1, 2, 3],
    [3, 4, 5],
    [5, 6, 7]
]);

console.log(qr.Q);
console.log(qr.R);

// solve a system of linear equations

var a = [
	[2, 4],
	[2, 8]];

var b = [[2], 
	[4]];

var result = lapack.sgesv(a, b);
console.log(result.X);
console.log(result.P);

LAPACK Building

These instructions are raw and a work in progress, but should work fine for linux and MacOS. The net result will be LAPACK and BLAS shared libraries.

If you haven't done so already download the LAPACK source http://www.netlib.org/lapack/

After unpacking the source create a make.inc based on the make.inc.example provided. For the purposes of this document I'll assume you have the "gfortran" fortran compiler installed.

Then make the following changes:

make.inc

CHANGE:

FORTRAN  = gfortran
OPTS     = -O2
DRVOPTS  = $(OPTS)
NOOPT    = -O0
LOADER   = gfortran
LOADOPTS =

TO:

UNAME := $(shell uname)

FORTRAN  = gfortran
OPTS     = -O2 -fPIC
DRVOPTS  = $(OPTS)
NOOPT    = -O0 -fPIC
LOADER   = gfortran
LOADOPTS =

ifeq ($(UNAME), Darwin)
LIBEXT=dylib
else
LIBEXT=so
endif

BLAS/SRC/Makefile

CHANGE:

all: $(BLASLIB)

TO:

all: $(BLASLIB) libblas.$(LIBEXT)

libblas.$(LIBEXT):
    $(FORTRAN) -shared -o $@ *.o
    cp $@ ../../$@

CHANGE:

clean:
    rm -f *.o

TO:

clean:
    rm -f *.o
    rm -f *.a
    rm -f *.$(LIBEXT)

SRC/Makefile

CHANGE:

all: ../$(LAPACKLIB)

TO:

all: ../$(LAPACKLIB) liblapack.$(LIBEXT)

liblapack.$(LIBEXT):
    gfortran -shared -o $@ $(ALLOBJ) -lblas -L..
    cp $@ ../$@

CHANGE:

clean:
    rm -f *.o

TO:

clean:
    rm -f *.o
    rm -f *.a
    rm -f *.$(LIBEXT)

Compiling

make blaslib
make lapacklib

Installing

# for linux
cp liblapack.so libblas.so /usr/lib
# for macos
# NOTE! this might be dangerous now. macs ship with liblapack.dylib now?
# regardless, i don't suggest installing a custom lapack right now on Mac
cp liblapack.dylib libblas.dylib /usr/lib

License

Copyright (c) 2011, Chris Umbel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

node-lapack's People

Contributors

addaleax avatar chrisumbel avatar kkoch986 avatar stephenway avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-lapack's Issues

Node-ffi doesn't have any Pointer object anymore

Hi,

I'm trying to install node-lapack to be used with sylvester, but it appears that the current version doesn't work with the last node-ffi.

The main trouble I encounter when running the example from README.md is that in lapack.js, you create new FFI.Pointer instances which do not exist in the current node-ffi. Is there something to rewrite because node-ffi was updated? How to change it so that it works with the current node-ffi version?

Where is this FFI.Pointer function?

Question regarding this module

Hi, I'm working on a 2d physics engine and want to use the LAPACK routines for performance reasons.

Your library looks very interesting.

I need to be able to solve systems of linear equations. AFAIK, the best way to do this in LAPACK is to first obtain a LU-factorization using sgetrf, and then use the result of that to solve a certain vector using sgetrs.

I noticed that the source code of your library does have an implementation for sgetrf, but not for sgetrs. Why is that and how can we solve numerous vectors in a high-performance way for one matrix?

Kind regards,
Bas

Published package still depends on deprecated `node-ffi`

The package I'm getting from npm is throwing this warning

npm WARN deprecated [email protected]: Use the 'ffi' package instead. See https://github.com/rbranson/node-ffi/wiki/API-changes-from-v0.x-to-v1.x

It looks like the dependency has been updated with #4, but an updated package was never published to npm. Can you publish a new version to npm, please?

Install failing for node V9.11.1 on ubuntu?

I'm using node V9.11.1 and am using ubuntu with lapack and libblas installed using

sudo apt-get install libblas-dev liblapack-dev

I see the error below, which looks like a Nan error, probably due to changes in Nan. So at any rate, I can't yet install the tool.

../src/ffi.cc:40:54: warning: ‘Nan::Maybe Nan::ForceSet(v8::Localv8::Object, v8::Localv8::Value, v8::Localv8::Value, v8::PropertyAttribute)’ is deprecated [-Wdeprecated-declarations]
static_cast(ReadOnly|DontDelete))
^
../src/ffi.cc:103:3: note: in expansion of macro ‘SET_ENUM_VALUE’
SET_ENUM_VALUE(RTLD_NODELETE);
^~~~~~~~~~~~~~
In file included from ../../nan/nan.h:197:0,
from ../src/ffi.h:23,
from ../src/ffi.cc:3:
../../nan/nan_maybe_43_inl.h:130:35: note: declared here
NAN_DEPRECATED inline Maybe ForceSet(
^~~~~~~~
../src/ffi.cc:111:153: error: no matching function for call to ‘v8::Object::ForceSet(v8::Localv8::String, v8::Localv8::Value, v8::PropertyAttribute)’
XT").ToLocalChecked(), WrapPointer((char *)RTLD_NEXT), static_cast(ReadOnly | DontDelete));

svdJS has null value issues

Using the following on matlab / octave:

A = [ 1, 2; 3, 4; 5, 6];
[u, s, v] = svd(A)

I obtain:

u =
  -0.22985   0.88346   0.40825
  -0.52474   0.24078  -0.81650
  -0.81964  -0.40190   0.40825

  s =
  9.52552  0.00000
  0.00000  0.51430
  0.00000  0.00000

  v =
  -0.61963  -0.78489
  -0.78489   0.61963

Now with the js implementation:

require('sylvester');
var A = $M([
  [1, 2],
  [3, 4],
  [5, 6]
]);
var svd = A.svd();
console.log(JSON.stringify(svd));

I obtain nothing because it crashes:

  /[...]/node_modules/sylvester/lib/node-sylvester
  /matrix.js:60
    var e = S.triu(1).unroll().norm();
              ^
  TypeError: Cannot call method 'triu' of null
    at Object.svdJs (/[...]/node_modules/sylvester
  /lib/node-sylvester/matrix.js:60:15)

Is it an issue with the qr factorization? Looks like at some point the R in qrJs() becomes null and everything crashes from there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.