Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -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()
}
}
}

View file

@ -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()
}
}
}

View file

@ -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 }