Jiahao Chen Add Matlab cases  over 8 years ago

Commit id: c1b6b7a7b4f98759203a0611067f534c41c7c250

deletions | additions      

       

DIR_EIGEN=/usr DIR_EIGEN=/usr/local/Cellar/eigen/3.2.6/  CXX=c++  CXXOPTS=-std=c++11 -Wall -Wno-unused-variable -Wno-deprecated-declarations  MATLAB=octave  TORCH=$(HOME)/torch/install/bin/th  all: bin/eigen3 matlab  r julia torch bin/eigen3  matlab: matlab.m  $(MATLAB) matlab.m  r: R.R  R -f R.R > /dev/null           

m1 = 6;  n1 = 5;  m2 = n1;  n2 = 4;  A = ones(m1, n1);  B = ones(m2, n2);  x = ones(1, m1);  y = ones(n1, 1);  alpha = ones(1);  assert(all(size(A*B) == [m1, n2]));  assert(all(size(alpha*A) == [m1, n1]));  assert(all(size(A*alpha) == [m1, n1]));         

R also has matrices, but no true scalars.  Its matrix multiplication operator is \verb|%*%| and its transposition operator  is \verb|t()|.  R's transposition operator semantics  promotes vectors $n$-vectors automatically  tocolumn  matrices before whenever linear algebraic  operations like \verb|t()| or \verb\%*%| are encountered.  By default, $n$-vectors behave as if they were $1\times n$ row matrices, except in  transposition, producing which produces  a row matrix, and in matrix--vector products, which  produce a column  matrix. Like Python, \verb|%*%| is also defined on two vectors to be the dot product.  However, unlike Python,  \verb|%*%| also permits has  a vector--matrix product, special case  where it implicitly  transposes if  the vector into second operand  is a length 1 vector, the result is  a row matrix before doing an ordinary matrix  multiplication. $1\times n$ matrix.  Extraneous singleton dimensions can be removed with \verb|drop()|. \verb|drop()|, which converts  either $n\times1$ or $1\times n$ matrices into $n$-vectors.  R's semantics of vectors and matrices are simple to reason about.  Perhaps the only behavior that some users may find surprising is imply  that transposition is not idempotent on vectors. Nevertheless, we've already seen precedent in the mathematical literature  that does...  \todo{cite}