sloisel / numeric

Numerical analysis in Javascript
http://www.numericjs.com/
Other
1.42k stars 177 forks source link

numeric.ones & numeric.zeros #6

Closed ericjang closed 12 years ago

ericjang commented 12 years ago

In matlab, numpy and many other linalg packages, there is a convenient constructor for a matrix of zeros or ones.

I understand these implementations are rather trivial given that rep is around but they are pretty convenient to have around for familiarity's sake with other packages.

numeric.ones = function identity(n) { return numeric.rep(n,1);}

numeric.zeros = function identity(n) {return numeric.rep(n,0);}

sloisel commented 12 years ago

Hi Eric,

Thanks for this comment. It was a conscious decision not to include numeric.ones and numeric.zeros. The reason is that there's only one of me and early on I noticed that, as I would optimize and rewrite functions, it was advantageous to concentrate on fewer functions. As you point out, the function numeric.ones and numeric.zeros are "syntactic sugar" for numeric.rep and so I did not include those functions.

Thanks,

Sébastien Loisel

auduno commented 11 years ago

I agree with Eric, zeros and ones were probably the first functions that I looked for, and I ended up creating my own utility function until I realized I could use numeric.rep. Perhaps you could add a line to the documentation where you point out that you can use rep as a replacement for zeros and ones, it's a bit hard to "spot" when skimming the documentation.

Otherwise, thanks for a great library!