A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,17 @@
|
|||
def assertConformable = { a, b ->
|
||||
assert a instanceof List
|
||||
assert b instanceof List
|
||||
assert a.every { it instanceof List && it.size() == b.size() }
|
||||
assert b.every { it instanceof List && it.size() == b[0].size() }
|
||||
}
|
||||
|
||||
def matmulWOIL = { a, b ->
|
||||
assertConformable(a, b)
|
||||
|
||||
def bt = b.transpose()
|
||||
a.collect { ai ->
|
||||
bt.collect { btj ->
|
||||
[ai, btj].transpose().collect { it[0] * it[1] }.sum()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
def matmulWOT = { a, b ->
|
||||
assertConformable(a, b)
|
||||
|
||||
(0..<a.size()).collect { i ->
|
||||
(0..<b[0].size()).collect { j ->
|
||||
(0..<b.size()).collect { k -> a[i][k] * b[k][j] }.sum()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
def m4by2 = [ [ 1, 2 ],
|
||||
[ 3, 4 ],
|
||||
[ 5, 6 ],
|
||||
[ 7, 8 ] ]
|
||||
|
||||
def m2by3 = [ [ 1, 2, 3 ],
|
||||
[ 4, 5, 6 ] ]
|
||||
|
||||
matmulWOIL(m4by2, m2by3).each { println it }
|
||||
println()
|
||||
matmulWOT(m4by2, m2by3).each { println it }
|
||||
Loading…
Add table
Add a link
Reference in a new issue