Permalink
Browse files

vectormath.transpose returns a one-row matrix.

The docs said that the transpose of a vector is a 1xN matrix, but the code (and the unit test!) made an Nx1 matrix.
This fixes the function so it makes a one-row matrix.
  • Loading branch information...
1 parent 4272dd6 commit 1ad842d97c1061fab4b7c9fab6b4a5bc4681d701 @christianp christianp committed Jun 22, 2016
Showing with 2 additions and 2 deletions.
  1. +1 −1 runtime/scripts/math.js
  2. +1 −1 tests/jme.html
@@ -1790,7 +1790,7 @@ var vectormath = Numbas.vectormath = {
* @returns {matrix}
*/
transpose: function(v) {
- var matrix = v.map(function(x){ return [x]; });
+ var matrix = [v.slice()];
matrix.rows = 1;
matrix.columns = v.length;
return matrix;
View
@@ -687,7 +687,7 @@ <h2 id="qunit-userAgent"></h2>
closeEquals(evaluate('det(matrix([2,4],[3,5]))').value,-2,'det(matrix([2,4],[3,5]))');
raisesNumbasError(function(){ evaluate('det(matrix([2,4,6],[3,5,7]))') },'matrixmath.abs.non-square','error on non-square matrix: det(matrix([2,4,6],[3,5,7]))');
raisesNumbasError(function(){ evaluate('det(matrix([1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]))') },'matrixmath.abs.too big',"can't work out determinants of big matrices: det(matrix([1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]))");
- deepCloseEqual(evaluate('transpose(vector(1,2,3))').value,[[1],[2],[3]],'transpose(vector(1,2,3))');
+ deepCloseEqual(evaluate('transpose(vector(1,2,3))').value,[[1,2,3]],'transpose(vector(1,2,3))');
deepCloseEqual(evaluate('transpose(matrix([1,2,3]))').value,[[1],[2],[3]],'transpose(matrix([1,2,3]))');
deepCloseEqual(evaluate('transpose(matrix([1],[2],[3]))').value,[[1,2,3]],'transpose(matrix([1],[2],[3]))');
deepCloseEqual(evaluate('transpose(transpose(matrix([1,2,3])))').value,[[1,2,3]],'transpose(transpose(matrix([1,2,3])))');

0 comments on commit 1ad842d

Please sign in to comment.