90e571752da8 — Chris Cannam 7 months ago
Add IntMatrix
3 files changed, 48 insertions(+), 0 deletions(-)

A => int-matrix.sig
A => int-matrix.sml
M matrix.mlb
A => int-matrix.sig +13 -0
@@ 0,0 1,13 @@ 
+
+(** Arithmetic matrix in which the element type is integer-valued.
+    Note entrywiseDivide is implemented using Int.quot. *)
+
+signature INT_MATRIX = sig
+
+    include ARITHMETIC_MATRIX
+
+    (** Entrywise absolute value. Return a matrix in which each
+        element has had the abs function applied to it. *)
+    val abs : matrix -> matrix
+                               
+end

          
A => int-matrix.sml +33 -0
@@ 0,0 1,33 @@ 
+
+structure IntMatrixFnArg = struct
+    structure EXT = IntTensorFnArg.EXT
+    structure REP = IntTensorFnArg.REP
+    structure EXT_SLICE = IntTensorFnArg.EXT_SLICE
+    structure REP_SLICE = IntTensorFnArg.REP_SLICE
+    structure OP = struct
+        open Int
+        type t = int
+        val zero = 0
+        val one = 1
+        fun isZero x = x = 0
+        val toString = StringInterpolate.I
+        val / = quot
+    end
+    fun fromExternal v = v
+    fun toExternal v = v
+    fun fromExternalSlice v = v
+    fun toExternalSlice v = v
+end
+                                
+structure IntMatrix :
+          INT_MATRIX
+= struct
+
+    structure A = ArithmeticMatrixFn(IntMatrixFnArg)
+    open A
+
+    fun abs m =
+        tabulate (order m, size m, fn ix => Int.abs (sub (m, ix)))
+              
+end
+

          
M matrix.mlb +2 -0
@@ 10,6 10,8 @@ ordered-matrix-fn.sml
 arithmetic-matrix.sig
 arithmetic-matrix-fn.sml
 int-tensor.sml
+int-matrix.sig
+int-matrix.sml
 real-tensor.sml
 real-matrix.sig
 real-matrix.sml