mljs/matrix

matrix.addColumn() available in node, but not in browser

Closed this issue · 1 comments

I'm trying to use a library built on top of this library (https://github.com/mljs/regression-multivariate-linear) and getting errors (mljs/regression-multivariate-linear#9).

So I created a new create-react-app app and a node.js app and imported ml-matrix to both. In the browser, addColumn is not a method on an instance of the matrix. In node.js, it is.

Browser (Chrome and Safari, Mac):

import Matrix from 'ml-matrix'
const matrix = Matrix.ones(5, 5)
console.log('matrix: ', matrix)  // [1, 1, 1, 1, 1, rows: 5, columns: 5]
console.log('matrix.addColumn: ', matrix.addColumn)  // Uncaught TypeError: matrix.addColumn is not a function

Node.js (version 11)

const { Matrix } = require('ml-matrix')
const matrix = Matrix.ones(5, 5)
console.log('matrix: ', matrix)
matrix:  Matrix [
  [ 1, 1, 1, 1, 1 ],
  [ 1, 1, 1, 1, 1 ],
  [ 1, 1, 1, 1, 1 ],
  [ 1, 1, 1, 1, 1 ],
  [ 1, 1, 1, 1, 1 ],
  rows: 5,
  columns: 5 ]

console.log('matrix.addColumn: ', matrix.addColumn(new Array(matrix.length).fill(0)))
matrix.addColumn:  Matrix [
  [ 1, 1, 1, 1, 1, 0 ],
  [ 1, 1, 1, 1, 1, 0 ],
  [ 1, 1, 1, 1, 1, 0 ],
  [ 1, 1, 1, 1, 1, 0 ],
  [ 1, 1, 1, 1, 1, 0 ],
  rows: 5,
  columns: 6 ]

This may be related to this ticket #69 but it's a different error so I opened a new ticket.

I looked at the rollup config: the output is called matrix.js, which was last updated about a year ago. Also, .gitignore excludes /matrix.js, maybe the compiled file isn't being committed (but works on the developers machines who are compiling this repo). Not sure - just a guess. Anybody have suggestions?

Closing in favor of #69