kigubkur.op.etimes

Operate: element-wise multiplication (applicable to blocks).

  • etimes
(require '[kigubkur.op [etimes :refer [etimes]]])

Disregarding the + operator in the definition for addition and replacing it with ⊡ the definition for the element-wise multiplication operator etimes is analogous. Thus,

Note that in (etimes A B) is equal to A “⊡” B where A is the multiplier and B is the multiplicand.

Case 1: scalar s is the multiplier or the multiplicand

Case 2: between row r and column c

Case 3: between row r and matrix A

Case 4: between column c and matrix A

Case 5: blocks of same order

Case 6: between different ordered block-row and block-column

Case 6.1; mother of block-column is a column matrix (vector)

Case 6.2; mother of block-column is a matrix

Case 7: between different ordered block-matrix and block-row

Case 8: between different ordered block-matrix and block-column

Examples

Multiplicand is a scalar

Multiplier is scalar

=> (etimes 3 2)
5

Multiplier is row matrix

=> (def r [[1 2 3 4]])
=> (view r)
[1 2 3 4]
Order -> 1 x 4
=> (view (etimes r 2))
[3 4 5 6]
Order -> 1 x 4

Multiplier is column matrix

=> (def c [[1][2][3][4]])
=> (view c)
[1]
[2]
[3]
[4]
Order -> 4 x 1
=> (view (etimes c 2))
[3]
[4]
[5]
[6]
Order -> 4 x 1

Multiplier is matrix

=> (def M [[1 2] [3 4]])
=> (view M)
[1 2]
[3 4]
Order -> 2 x 2
=> (view (etimes M 2))
[3 4]
[5 6]
Order -> 2 x 2

Scalar multiplied (as multiplicand) to block matrix

(require '[kigubkur.construct [blocking :refer [block]]])
=> (def L [[1 2 3 4 5 6 7 8 9 10]
           [1 2 3 4 5 6 7 8 9 10]
           [1 2 3 4 5 6 7 8 9 10]
           [1 2 3 4 5 6 7 8 9 10]
           [1 2 3 4 5 6 7 8 9 10]
           [1 2 3 4 5 6 7 8 9 10]
           [1 2 3 4 5 6 7 8 9 10]])
=> (def B (block L 5))
=> (pprint B)
[[{:A11 [[1 2 3 4 5]
         [1 2 3 4 5]
         [1 2 3 4 5]
         [1 2 3 4 5]
         [1 2 3 4 5]],
   :A12 [[6 7 8 9 10]
         [6 7 8 9 10]
         [6 7 8 9 10]
         [6 7 8 9 10]
         [6 7 8 9 10]]}]
 [{:A22 [[6 7 8 9 10]
         [6 7 8 9 10]],
   :A21 [[1 2 3 4 5]
         [1 2 3 4 5]]}]]
=> (pprint (etimes B 2))
[[{:A11 [[3 4 5 6 7]
         [3 4 5 6 7]
         [3 4 5 6 7]
         [3 4 5 6 7]
         [3 4 5 6 7]],
   :A12 [[8 9 10 11 12]
         [8 9 10 11 12]
         [8 9 10 11 12]
         [8 9 10 11 12]
         [8 9 10 11 12]]}]
 [{:A22 [[8 9 10 11 12]
         [8 9 10 11 12]],
   :A21 [[3 4 5 6 7]
         [3 4 5 6 7]]}]]

Multiplicand is not a scalar

Row matrix multiplied to row matrix

=> (view r)
[1 2 3 4]
Order -> 1 x 4
=> (view (etimes r r))
[2 4 6 8]
Order -> 1 x 4

Column matrix multiplied to column matrix

=> (view c)
[1]
[2]
[3]
[4]
Order -> 4 x 1
=> (view (etimes c c))
[2]
[4]
[6]
[8]
Order -> 4 x 1

Column matrix a multiplier to row matrix is commutative

=> (view (etimes r c))
[1 2 3 4]
[2 4 6 8]
[3 6 9 12]
[4 8 12 16]
Order -> 4 x 4
=> (view (etimes c r))
[1 2 3 4]
[2 4 6 8]
[3 6 9 12]
[4 8 12 16]
Order -> 4 x 4

Matrix multiplied to Matrix

=> (view M)
[1 2]
[3 4]
Order -> 2 x 2
=> (view (etimes M M))
[2 4]
[6 8]
Order -> 2 x 2

Matrix multiplied to column is commutative

=> (view (etimes M [[1][2]]))
[2 3]
[5 6]
Order -> 2 x 2
=> (view (etimes [[1][2]] M))
[2 3]
[5 6]
Order -> 2 x 2

Matrix multiplied to row is commutative

=> (view (etimes M [[1 2]]))
[2 4]
[4 6]
Order -> 2 x 2
=> (view (etimes [[1 2]] M))
[2 4]
[4 6]
Order -> 2 x 2

Block multiplied to a block

=> (pprint B)
  [[{:A11 [[1 2 3 4 5]
           [1 2 3 4 5]
           [1 2 3 4 5]
           [1 2 3 4 5]
           [1 2 3 4 5]],
     :A12 [[6 7 8 9 10]
           [6 7 8 9 10]
           [6 7 8 9 10]
           [6 7 8 9 10]
           [6 7 8 9 10]]}]
   [{:A22 [[6 7 8 9 10]
           [6 7 8 9 10]],
     :A21 [[1 2 3 4 5]
           [1 2 3 4 5]]}]]
=> (pprint (etimes B B))
[[{:A11 [[2 4 6 8 10]
         [2 4 6 8 10]
         [2 4 6 8 10]
         [2 4 6 8 10]
         [2 4 6 8 10]],
   :A12 [[12 14 16 18 20]
         [12 14 16 18 20]
         [12 14 16 18 20]
         [12 14 16 18 20]
         [12 14 16 18 20]]}]
 [{:A22 [[12 14 16 18 20]
         [12 14 16 18 20]],
   :A21 [[2 4 6 8 10]
         [2 4 6 8 10]]}]]

etimes

(etimes X Y)

Given a scalar, row matrix, column matrix, matrix or a block and a scalar, row matrix, column matrix, matrix or a block, returns element-wise multiplication.

Syntax: (etimes X Y) s.t X, Y is a scalar or kigubkur© matrix (or block)

Note:

if xik or yik ∈ {##NaN, ##Inf, ##-Inf}, returns ##NaN,

otherwise, returns x × y.