Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
structure Matrix = struct
|
||||
local
|
||||
open Array2
|
||||
fun mapscalar f (x, scalar) =
|
||||
tabulate RowMajor (nRows x, nCols x, fn (i,j) => f(sub(x,i,j),scalar))
|
||||
fun map2 f (x, y) =
|
||||
tabulate RowMajor (nRows x, nCols x, fn (i,j) => f(sub(x,i,j),sub(y,i,j)))
|
||||
in
|
||||
infix splus sminus stimes
|
||||
val op splus = mapscalar Int.+
|
||||
val op sminus = mapscalar Int.-
|
||||
val op stimes = mapscalar Int.*
|
||||
val op + = map2 Int.+
|
||||
val op - = map2 Int.-
|
||||
val op * = map2 Int.*
|
||||
val fromList = fromList
|
||||
fun toList a =
|
||||
List.tabulate(nRows a, fn i => List.tabulate(nCols a, fn j => sub(a,i,j)))
|
||||
end
|
||||
end;
|
||||
|
||||
(* example *)
|
||||
let open Matrix
|
||||
infix splus sminus stimes
|
||||
val m1 = fromList [[1,2],[3,4]]
|
||||
val m2 = fromList [[4,3],[2,1]]
|
||||
val s = 2
|
||||
in
|
||||
List.map toList [m1+m2, m1-m2, m1*m2,
|
||||
m1 splus s, m1 sminus s, m1 stimes s]
|
||||
end;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
val it =
|
||||
[[[5,5],[5,5]],[[~3,~1],[1,3]],[[4,6],[6,4]],[[3,4],[5,6]],[[~1,0],[1,2]],
|
||||
[[2,4],[6,8]]] : int list list list
|
||||
Loading…
Add table
Add a link
Reference in a new issue