1 (* Copyright (C
) 1999-2006, 2008 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
4 * MLton is released under a BSD
-style license
.
5 * See the file MLton
-LICENSE for details
.
8 structure Array2
: ARRAY2
=
25 else loop (c
- 1, sub (a
, r
, c
) :: ac
)
26 in loop (nCols a
- 1, [])
28 in loop (nRows a
- 1, [])
31 fun layout f a
= List.layout (List.layout f
) (toList a
)
33 fun wholeRegion a
: 'a region
=
34 {base
= a
, row
= 0, col
= 0, nrows
= NONE
, ncols
= NONE
}
38 in (appi
RowMajor (fn (r
, c
, x
) =>
47 fun equals (a
, a
', f
) =
49 andalso nCols a
= nCols a
'
50 andalso foralli (a
, fn (r
, c
, x
) => f (x
, sub (a
', r
, c
)))
52 fun forall (a
, f
) = foralli (a
, f
o #
3)
54 fun tabulate (r
, c
, f
) = Pervasive
.Array2
.tabulate
RowMajor (r
, c
, f
)
57 foldi
RowMajor (fn (r
, c
, a
, ()) => f (r
, c
, a
)) () (wholeRegion a
)
59 fun foreach (a
, f
) = foreachi (a
, f
o #
3)
61 fun copy a
= tabulate (nRows a
, nCols a
, fn (r
, c
) => sub (a
, r
, c
))
63 fun new (r
, c
, x
) = tabulate (r
, c
, fn _
=> x
)