bertrandbev / eigen-js Goto Github PK
View Code? Open in Web Editor NEW⚡ Eigen-js is a port of the Eigen C++ linear algebra library
Home Page: https://bertrandbev.github.io/eigen-js/#/
⚡ Eigen-js is a port of the Eigen C++ linear algebra library
Home Page: https://bertrandbev.github.io/eigen-js/#/
Hi, firstly this is a AWESOME project!
I'm searching for some library like this one for a project of a desktop aplication built in Electron for my graduation in Engineering.
I need something fast and powerful to operations with matrices that sometimes reaches 1000 rows and columns. I've been thinkg about create a Addon for NodeJS in C++ using Eigen Library but I have some problems because it's not very simple.
Did you think that eigen-js could help me in this situation?
These matrices that I need to solve are generated from electrical circuits, so, most of them are with float numbers.
I'm trying to run eigen-js
in Node.js and I'm getting this error when instantiating a new Matrix:
TypeError: eigen_1.default.Matrix is not a constructor
Is this supposed to work on Node.js?
Why didn't you include the eigen js you built in the repo?
Thanks for making this library!
It would be nice to have a .d.ts
file, to make Eigen.js easier to use in TypeScript. Would you accept a pull request adding such a file, or would you prefer for those types to be added to DefinitelyTyped instead?
Hi @BertrandBev,
There's a badge in the repo that mentions that the license is MIT, but points to Naereen's copyright/license.
Could you please confirm the license of this repo?
Thanks!
Hey there 👋
First of all, thanks for this awesome project!
Are there any plans to incorporate the solve
methods for solving linear least squares systems yet?
I'm particularly interested in the solve methods from both the QR, and SVD classes.
If you're interested I'd try and create a PR, but I have to admit that C++ is not my strong suit 😅
P.S.: Here's a link to another Eigen port which could be used as inspiration: https://observablehq.com/@rreusser/eigen
(without the memory management implementation though, as far as I can tell).
Hey this looks like a great project! I have had a hard time finding something as powerful as Eigen for Javascript.
Do you have a list of features or roadmap you are working on?
eigen.Decompositions.lu()
returns wrong values which don't satisfy LU = A
.
Run the following code in demo page...
const M = new eig.Matrix([[2, 1], [1, 4]]);
const lu = eig.Decompositions.lu(M);
return {...lu, "L*U": lu.L.matMul(lu.U)}
...and you will get:
While the expected values are:
L = [[1, 0], [0.5, 1]],
U = [[2, 1], [0, 3.5]]
I used Emscripten compiled eigen_gen.js and eigen_gen.wasm to build the index.js of this project.
But when I run test.mjs I get an error of "TypeError: Cannot read properties of undefined (reading 'prototype')at Function.initClass(....\dist\index.js:1:1001402)"
The code snippet in index.js is:
var Q=g(1),B=g(2),C=g(3);function E(A){return Object.getOwnPropertyNames(A).filter(I=>"constructor"!==I&&"function"==typeof A[I])}class D{static add(...A){A.flat(1/0).forEach(A=>{D.objects.add(A)})}static pushException(...A){A.flat(1/0).forEach(A=>{const I=D.whitelist.get(A)||0;D.whitelist.set(A,I+1)})}static popException(...A){A.flat(1/0).forEach(A=>{const I=D.whitelist.get(A)||0;D.whitelist.set(A,I-1),D.whitelist.get(A)<=0&&D.whitelist.remove(A)})}static flush(){const A=[...D.objects].filter(A=>!D.whitelist.has(A));return A.forEach(A=>{A.delete(),D.objects.delete(A)}),A.length}static set(A,I,g){A[I]&&D.popException(A[I]),D.pushException(g),A[I]=g}static initClass(A,I){const g=function(...A){const g=new I(...A);return D.add(g),g},Q=[I,I.prototype];
This is driving me crazy. Can you give me an index.js that you compiled。
Hello, I have this code for an Extended Kalman filter in TypeScript.
import eigen from 'eigen'
export type NonLinearFunction = (x: eigen.Matrix) => eigen.Matrix
export type JacobianFunction = (x: eigen.Matrix) => eigen.Matrix
export class ExtendedKalmanFilter {
private x: eigen.Matrix
private P: eigen.Matrix
private Q: eigen.Matrix
private R: eigen.Matrix
private f: NonLinearFunction
private h: NonLinearFunction
private Fj: JacobianFunction
private Hj: JacobianFunction
constructor(
initialState: eigen.Matrix,
initialCovariance: eigen.Matrix,
processCovariance: eigen.Matrix,
measurementCovariance: eigen.Matrix,
stateTransition: NonLinearFunction,
observation: NonLinearFunction,
stateTransitionJacobian: JacobianFunction,
observationJacobian: JacobianFunction,
) {
this.x = initialState
this.P = initialCovariance
this.Q = processCovariance
this.R = measurementCovariance
this.f = stateTransition
this.h = observation
this.Fj = stateTransitionJacobian
this.Hj = observationJacobian
}
predict(): void {
this.x = this.f(this.x)
const F = this.Fj(this.x)
this.P = F.matMul(this.P).matMulSelf(F.transpose()).matAddSelf(this.Q)
}
update(z: eigen.Matrix): void {
const y = z.matSub(this.h(this.x))
const H = this.Hj(this.x)
const S = H.matMul(this.P).matMulSelf(H.transpose()).matAddSelf(this.R)
const K = this.P.matMul(H.transpose()).matMulSelf(S.inverse())
this.x = this.x.matAdd(K.matMul(y))
this.P = eigen.Matrix.identity(this.P.rows(), this.P.cols())
.matSub(K.matMul(H))
.matMul(this.P)
}
getState(): eigen.Matrix {
return this.x
}
getCovariance(): eigen.Matrix {
return this.P
}
}
I'm having memory issues running this in Node.js.
What's the proper way to use GC in this case?
Thanks!
Hey there, I tried forking this repo and building without OSQP as instructed in the readme using the latest version of emscripten:
emcc -D NO_OSQP -I lib/eigen -Isrc -s DISABLE_EXCEPTION_CATCHING=0 -s ASSERTIONS=0 -O3 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 --bind -o build/eigen_gen.js src/cpp/embind.cc
Then I indeed did a yarn build
, pushed the new index.js
that got generated, and tried to install the fork.
Upon trying to use it, I get greeted by the following error:
index.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'prototype')
at D.initClass (index.js:1:935979)
at index.js:1:936495
at Set.forEach (<anonymous>)
at index.js:1:936476
initClass @ index.js:1
(anonymous) @ index.js:1
(anonymous) @ index.js:1
Promise.then (async)
(anonymous) @ HSWFC.js:36
I suspected that it was because of the following piece of code at the end of eigen.mjs
that adds the GC to the classes, since it still has the QuadProgSolver
in there:
eig.ready = Module.then(module => {
const classes = new Set([
"Vector",
"Vector2d",
"Complex",
"Matrix",
"SparseMatrix",
"TripletVector",
"ComplexDenseMatrix",
"Solvers",
"Decompositions",
"QuadProgSolver",
"Random",
]);
classes.forEach(className => {
eig[className] = GC.initClass(classes, module[className])
})
addHelpers(eig);
})
After removing "QuadProgSolver"
it indeed started working. I'm not savvy enough in web build tools to come up with a nicer solution for this, but maybe it is good to put a disclaimer/warning in the readme for now about it, so people can still perform a functioning yarn build
without OSQP in there.
It is hoped that LU's method for solving linear systems can be added
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.