# Numeric.js 1.2.4

I’ve just released numeric.js version 1.2.4. This is mostly a bugfix release. There were a few fixes to make numeric.js work in strict mode. In addition to these small bugfixes, there was a small improvement to the linear programming routine.

Apart from numeric.js, I’ve also reworked the workshop. This is hard to see as a user, but the workshop used to be a complicated mess of divs using table layout, which has poor compatibility with IE. I’ve found a less complicated and more compatible way of implementing the workshop.

November 19, 2012 at 5:09 pm | 6 comments
Hi Sébastien,

it seems a variable declaration slipped your fingers:

numeric.js:3073

g = add(c,mul(alpha,p));

^

ReferenceError: g is not defined

Furthermore there still appears to be a bug in the linear solver. When I adapt your very LP example with equality constraints so that the variables must be between 0 and 1:

numeric.solveLP([1,2,3], /* minimize [1,2,3]*x */

[[1, 0, 0], [0, 1, 0], [0, 0, 1],[-1,0,0],[0,-1,0],[0,0,-1]], /* matrix A of inequality constraint */

[1,1,1,0,0,0], /* RHS b of inequality constraint */

[[1,1,1]], /* matrix Aeq of equality constraint */

[3] /* vector beq of equality constraint */

);

It will throw the following error:

numeric.js:478

default: throw new Error(‘numeric.dot only works on vectors and matrices’)

^

Error: numeric.dot only works on vectors and matrices

Do you happen to have some spare time these days to fix that? I’d love to use your library, but unfortunately this error makes that impossible in my case.

Best regards,

Michael

Dear Michael,

Sorry for not seeing your comment, it got caught in the spam filter!

I’ve fixed these bugs, will release 1.2.5 shortly.

Thanks,

Sébastien Loisel

Hi Sébastien,

No worries, I just realized you have a Git repository for this project so that I could have created an issue instead. Thank you very much for looking into it.

Best regards,

Michaeö

Is it planned for sparse matrices to have random access (random read/write to any entry)? For problems (like mine) with large very matrices, it seems confusing that we should have to create a large dense matrix just to create the sparse one.

If I’m just misunderstanding and this is actually already possible, please let me know!

Thanks again for developing this awesome library.

Dear Brandon,

Thanks for your question.

I humbly suggest that you may have a misconception. There are multiple sparse matrix storage formats, several of which are described here: http://en.wikipedia.org/wiki/Sparse_matrix

Numeric.js offers three storage formats for sparse matrices. The high performance sparse codes are the CCS (Column Compressed Storage) routines; this is the most widely used high-performance sparse storage format. It is difficult and inefficient to create CCS matrices incrementally by reading and writing individual entries. As mentioned in the Wikipedia article, matrices are not normally created incrementally in the CCS format.

A format which is better suited to incremental matrix construction is the Coordinate (COO) format. In the COO format, you list the coordinate of the nonzero entries along with the desired values. For example, the notation M=[[0,1,2,3,4],[1,2,3,4,5],[3,1,4,1,5]] indicates a matrix with nonzero entries [3,1,4,1,5] just above the main diagonal. It is straightforward to then append entries to these arrays and thus add new nonzero entries to M. A COO matrix can be converted to a CCS matrix using the function numeric.ccsScatter(M). Thus, you could build your matrix in COO format then convert to CCS format for efficient calculation.

Yet another good format for incremental construction is the Dictionary of Keys (DOK) format. DOK matrices are simply Javascript sparse Arrays. You can convert a COO matrix to a DOK matrix using numeric.sscatter(), and back to COO format using numeric.sgather().

To recap, the DOK matrix format might be easiest for you to use in order to incrementally construct a sparse matrix; however you will find that it is not a very fast format to use. In any case, once you have constructed your sparse matrix, you will almost certainly want to convert it to CCS format in order to do efficient numerical calculations with it.

Further examples can be found here: http://numericjs.com/workshop.php?link=4300ee0e171f8d0b7d316a2c1792b539b12a369ba4a3e3fef43bd114b0761aab

Fantastic! Thanks for the help I didn’t realize there were multiple sparse formats implemented in numericjs.

Thanks again!