Skip to content

Commit

Permalink
ivy: matrix divide, mdiv
Browse files Browse the repository at this point in the history
Dead easy now we have matrix invert.

Moore-Penrose inverse will enable more uses; see issue #146
  • Loading branch information
robpike committed Aug 6, 2023
1 parent 6e13ebc commit 94a7a4c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Binary operators
In ivy: abs(A) gives count, A <= 0 inserts zero
Index of A⍳B iota The location (index) of B in A; 1+⌈/⍳⍴A if not found
In ivy: origin-1 if not found (i.e. 0 if one-indexed)
Matrix divide A⌹B Solution to system of linear equations Ax = B
Matrix divide A⌹B mdiv Solution to system of linear equations Ax = B
Rotation A⌽B rot The elements of B are rotated A positions left
Rotation A⊖B flip The elements of B are rotated A positions along the first axis
Logarithm A⍟B log Logarithm of B to base A
Expand Down
2 changes: 1 addition & 1 deletion mobile/help.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion parse/help.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions testdata/binary_matrix.ivy
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@
1 2 3
4 5 6

(2 2 rho 1 2 3 4) mdiv (2 2 rho 5 6 7 8)
5 4
-4 -3

(5 8) mdiv (2 2 rho 1 2 2 -1)
21/5 2/5

(2 3 rho iota 10) ** 5
1 32 243
1024 3125 7776
Expand Down
12 changes: 12 additions & 0 deletions value/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,18 @@ func init() {
},
},

{ // Matrix division
name: "mdiv",
elementwise: false,
whichType: binaryArithType,
fn: [numType]binaryFn{
// TODO: Other types?
matrixType: func(c Context, u, v Value) Value {
return innerProduct(c, v.(*Matrix).inverse(c), "+", "*", u)
},
},
},

{ // Euclidean integer division.
name: "div",
elementwise: true,
Expand Down

0 comments on commit 94a7a4c

Please sign in to comment.