iodide-project / iodide-transpiler

Transpiling numerical operations
MIT License
7 stars 1 forks source link

Iodide needs a Matrix First enviroment. #1

Open gregglind opened 5 years ago

gregglind commented 5 years ago

Problem statement: Matrix work in JS stinks.

  1. Manipulating N-dimensional-Matrices is common in scientific computation.
  2. Current Javascript doesn't optimize code affordances for Matrices.
  3. Python / NumPy / SciPy matrix support feels 'bolted-on'.
  4. R, Octave / Matlab have affordances that make Matrix work better.

Features that make N-dimentional-Matrix work awesome

  1. Literals for creating them
  2. Getters / slices / masking
  3. Operators that mimic matrix algebra usage (.*)
  4. Names of useful matrix functions ('ones', 'zeros', 'triangle', 'svd') are 'close' to the surface.
  5. '1-based' indexed.
  6. Numerical precision, complex numbers, etc.
  7. Fast performance of matrix operations on Floats, ints, etc.
gregglind commented 5 years ago

Proposed solution: Babel and TC39 work

Use Babel with transforms.

  1. Literals: create a matrix literal babel transform
  2. Slices: https://github.com/tc39/proposal-slice-notation
  3. Operators: https://github.com/keithamus/ecmascript-operator-overloading-proposal
  4. (Don't have a good solution. Littering the code with Matrix.ones seems terrible. See also the math object. We could pre load a lot more into the 'env', as with Node, or WebExtensions, or Window. This also has risks. Eslinting can help with a 'no-reassign-matrix' work.
  5. (I actually hate 1 based indexing)
  6. Wrap up LAPACK and friends.
hamilton commented 5 years ago

Thanks for the issue @gregglind! We've talked internally about making a babel mode for scientific computing needs (matrix stuff like broadcasting, precision, complex numbers, etc.) that connects to some library w/ an API, but not enough bandwidth right now to implement it. What you're proposing on a high-level matches a lot of what we've talked about on private channels.

WATLab syntax was something we were looking at earlier this year. @bcolloran has some strong thoughts about what this might all look like, so I'll let him chime in.

Layer-wise, we'll need:

  1. transpilation (get the syntax to solve the work flow issues)
  2. pure JS API
  3. backend of some sort (arrow? js typed arrays? etc.)

These clearly seem related, but could also be viewed as modular concerns.

hamilton commented 5 years ago

I've transferred this issue to our new repo, iodide-transpiler, to track progress.

guidocalvano commented 5 years ago

I also would prefer 0 based indexing. Numpy actually does not feel bolted on at all to me. In fact I greatly prefer it to both R and Matlab. Perhaps using webgl would be simpler way to accelerate matrix multiplication on gpu. This person accomplished it with a few hundred lines of code:

http://watmough.github.io/webgl-matrix-demo/ https://github.com/watmough/webgl-matrix-demo/blob/master/gpu_matrix.js