Skip to content

Commit

Permalink
fix: random not correctly filling rectangular matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Nov 19, 2015
1 parent 25d8853 commit a79c3eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class Matrix extends Array {
if (rng === undefined) rng = Math.random;
var matrix = Matrix.empty(rows, columns);
for (var i = 0; i < rows; i++) {
for (var j = 0; j < rows; j++) {
for (var j = 0; j < columns; j++) {
matrix[i][j] = rng();
}
}
Expand Down
10 changes: 7 additions & 3 deletions test/matrix/creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ describe('Matrix creation', function () {
Matrix.ones(2, 3).to2DArray().should.eql([[1, 1, 1], [1, 1, 1]]);
});
it('random', function () {
var random = Matrix.rand(2, 2);
var random2 = Matrix.rand(2, 2);
var random = Matrix.rand(2, 3);
var random2 = Matrix.rand(2, 3);
random.to2DArray().should.not.eql(random2.to2DArray());
random[0][0].should.be.within(0, 1);
for (var i = 0; i < 2; i++) {
for (var j = 0; j < 3; j++) {
random[i][j].should.be.within(0, 1);
}
}
});
it('random with custom RNG', function () {
function fakeRNG() { return 2; }
Expand Down

0 comments on commit a79c3eb

Please sign in to comment.