1.2.3-SNAPSHOT permalink Arrow_down_16x16
  • (mmult & args)
Returns the matrix resulting from the matrix multiplication of the
the given arguments. Equivalent to R's %*% operator.

Examples:

(def A (matrix [[1 2 3]
[4 5 6]
[7 8 9]]))
(mmult A (trans A))
(mmult A (trans A) A)

References:
http://en.wikipedia.org/wiki/Matrix_multiplication
http://incanter.org/docs/parallelcolt/api/cern/colt/matrix/tdouble/DoubleMatrix2D.html

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/core.clj:661 top

(defn mmult
  " Returns the matrix resulting from the matrix multiplication of the
    the given arguments. Equivalent to R's %*% operator.

    Examples:

      (def A (matrix [[1 2 3]
                      [4 5 6]
                      [7 8 9]]))
      (mmult A (trans A))
      (mmult A (trans A) A)

    References:
      http://en.wikipedia.org/wiki/Matrix_multiplication
      http://incanter.org/docs/parallelcolt/api/cern/colt/matrix/tdouble/DoubleMatrix2D.html

  "
    ([& args]
     (reduce (fn [A B]
              (let [a (if (matrix? A) A (matrix A))
                    b (if (matrix? B) B (matrix B))
                    result (Matrix. (.zMult ^Matrix a ^Matrix b nil))]
                (if (and (= (.rows result) 1) (= (.columns result) 1))
                  (.getQuick result 0 0)
                  result)))
            args)))
Vars in incanter.core/mmult: = and defn fn let reduce
Used in 0 other vars

Comments top

No comments for mmult. Log in to add a comment.