### NOTA BENE:  vector %*% Matrix  _and_  Matrix %*% vector :
### ---------   -----------------         -----------------
## The k-vector is treated as  (1,k)-matrix *or* (k,1)-matrix
## on both sides  whenever it "helps fit" the matrix dimensions:

## --------------- %*% ---------------------------------------------

 ## --------- v . v -----------------------------
 ## We *could* consider allowing more even here: could argue
 ## from the 'NOTA BENE' above that
> 5 %*% 3:4        ## should work, since
> 5 %*% rbind(3:4) ## does work, but
> 5 %*% cbind(3:4) ## does not.

 ## --------- v . M -----------------------------
> 1:3 %*% matrix(1:12, 3,4) ## (1, n)  if n == nrow(.)
     [,1] [,2] [,3] [,4]
[1,]   14   32   50   68
> 1:4 %*% matrix(1:12, 3,4)
Error in 1:4 %*% matrix(1:12, 3, 4) : non-conformable arguments
No suitable frames for recover()
> 1:4 %*% matrix(1:5, 1,5)  ##  (n, 1) if nrow(.) == 1
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    2    4    6    8   10
[3,]    3    6    9   12   15
[4,]    4    8   12   16   20
 ## --------- M . v -----------------------------
> matrix(1:4, 3,4) %*% 1:4  ##  (n, 1) if  n == ncol(.)
     [,1]
[1,]   26
[2,]   28
[3,]   26
> matrix(1:4, 3,4) %*% 1:3
Error in matrix(1:4, 3, 4) %*% 1:3 : non-conformable arguments
No suitable frames for recover()
> matrix(1:3, 3,1) %*% 1:3  ##  (1, n) if  ncol(.) == 1
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    4    6
[3,]    3    6    9
>

## --------------- crossprod -------------------------------------

 ## --------- M . v -----------------------------
> crossprod(matrix(1:4, 3,4), 1:3)  ## (n, 1) if  n == nrow(.)
     [,1]
[1,]   14
[2,]   12
[3,]   14
[4,]   20
> crossprod(matrix(1:4, 3,4), 1:4)
Error in crossprod(matrix(1:4, 3, 4), 1:4) : non-conformable arguments
> m <- matrix(1:2, 1,2); v <- 1:3
> crossprod(m,v)	 ##>>> *could* be nice  and use (1,n) as nrow(.)==1 <<<
Error in crossprod(m, v) : non-conformable arguments
##>> after all, crossprod(m,v) "should"== t(m) %*% v  and that does work:
> t(m) %*% v
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    4    6
>

 ## --------- v . M -----------------------------
> crossprod(1:3, matrix(1:4, 3,4))  ## (1, n)  if  n == nrow(.)
     [,1] [,2] [,3] [,4]
[1,]   14   12   14   20
> crossprod(1:4, matrix(1:4, 3,4))
Error in crossprod(1:4, matrix(1:4, 3, 4)) : non-conformable arguments
> crossprod(1:3, matrix(1:3, 1,3)) ##>>> *could* be nice  and use (n,1) as nrow(.)==1 <<<
Error in crossprod(1:3, matrix(1:3, 1, 3)) : non-conformable arguments
> crossprod(v,m)
Error in crossprod(v, m) : non-conformable arguments
##>> "as"   v %*% m   does work  and v could have been  A[1,] instead of A[1, , drop=TRUE]


> ## --------------- tcrossprod -------------------------------------

 ## --------- M . v -----------------------------
> tcrossprod(matrix(1:4, 3,4), 1:3)
Error in tcrossprod(matrix(1:4, 3, 4), 1:3) : non-conformable arguments
> tcrossprod(matrix(1:4, 3,4), 1:4)
Error in tcrossprod(matrix(1:4, 3, 4), 1:4) : non-conformable arguments
> tcrossprod(matrix(1:4, 1,4), 1:4)##>>> *could* be nice and use (n,1) as ncol(.) == 1 <<<
Error in tcrossprod(matrix(1:4, 1, 4), 1:4) : non-conformable arguments
##>> "as"   m %*% v   does work  and v could have been  A[1,] instead of  A[1, , drop=TRUE]
> matrix(1:4, 1,4) %*%  1:4
     [,1]
[1,]   30
> tcrossprod(matrix(1:2, 2,1), 1:5)  # v -> c(1, n)     as ncol(.) == 1
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    2    4    6    8   10
>

 ## --------- v . M -----------------------------
> tcrossprod(1:4, matrix(1:4, 3,4)) # v -> c(1, n)     as n == ncol(.)
     [,1] [,2] [,3]
[1,]   26   28   26
> tcrossprod(1:3, matrix(1:4, 3,4))
Error in tcrossprod(1:3, matrix(1:4, 3, 4)) : non-conformable arguments
> tcrossprod(1:3, matrix(1:3, 3,1)) # v -> c(n, 1)     as ncol(.) == 1
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    4    6
[3,]    3    6    9
>
 ##--------------------------- vector x vector -----------------

> 1:3 %*% 1:3         ## must have same n
     [,1]
[1,]   14

> crossprod(1:3, 1:3) ## must have same n
     [,1]
[1,]   14


> tcrossprod(1:3, 1:4) ## can have different length
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    2    4    6    8
[3,]    3    6    9   12

