Mercurial > hg > may
changeset 553:25b925cf3c98
Merge
author | Chris Cannam |
---|---|
date | Mon, 31 Mar 2014 10:28:42 +0100 |
parents | f20297bca167 (current diff) 25800b390b07 (diff) |
children | 3fdffd2d0649 |
files | |
diffstat | 2 files changed, 50 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/may/matrix.yeti Mon Mar 31 10:16:02 2014 +0100 +++ b/src/may/matrix.yeti Mon Mar 31 10:28:42 2014 +0100 @@ -933,16 +933,37 @@ minValue m = if width m == 0 or height m == 0 then 0 - else + elif isSparse? m then minv ll = fold min (head ll) (tail ll); - minv (map (.v) (enumerate m)); + minnz = minv (map (.v) (enumerate m)); + if minnz > 0 and nonZeroValues m < (width m * height m) then 0 + else minnz fi; + elif isRowMajor? m then + vec.min (vec.fromList (map vec.min (asRows m))); + else + vec.min (vec.fromList (map vec.min (asColumns m))); fi; maxValue m = if width m == 0 or height m == 0 then 0 - else + elif isSparse? m then maxv ll = fold max (head ll) (tail ll); - maxv (map (.v) (enumerate m)); + maxnz = maxv (map (.v) (enumerate m)); + if maxnz < 0 and nonZeroValues m < (width m * height m) then 0 + else maxnz fi; + elif isRowMajor? m then + vec.max (vec.fromList (map vec.max (asRows m))); + else + vec.max (vec.fromList (map vec.max (asColumns m))); + fi; + +total m = + if isSparse? m then + fold (+) 0 (map (.v) (enumerateSparse m)); + elif isRowMajor? m then + fold (+) 0 (map vec.sum (asRows m)); + else + fold (+) 0 (map vec.sum (asColumns m)); fi; mapRows rf m = @@ -1007,6 +1028,7 @@ scaled, minValue, maxValue, + total, asRows, asColumns, sum = sum', @@ -1071,6 +1093,7 @@ scaled is number -> matrix_t -> matrix_t, minValue is matrix_t -> number, maxValue is matrix_t -> number, + total is matrix_t -> number, asRows is matrix_t -> list<vec.vector_t>, asColumns is matrix_t -> list<vec.vector_t>, sum is list?<matrix_t> -> matrix_t,
--- a/src/may/matrix/test/test_matrix.yeti Mon Mar 31 10:16:02 2014 +0100 +++ b/src/may/matrix/test/test_matrix.yeti Mon Mar 31 10:28:42 2014 +0100 @@ -227,6 +227,29 @@ compareMatrices (mat.mapColumns (vec.scaled 2) m') m'' ), +"minValue-\(name)": \( + compare (mat.minValue (fromRows [[1,2],[3,4],[5,-1]])) (-1) and + compare (mat.minValue (fromRows [[1,2],[3,0],[5,-1]])) (-1) and + compare (mat.minValue (fromRows [[1,2],[3,0],[5,1]])) 0 and + compare (mat.minValue (fromRows [[],[],[]])) 0 +), + +"maxValue-\(name)": \( + compare (mat.maxValue (fromRows [[1,2],[3,4],[5,-1]])) 5 and + compare (mat.maxValue (fromRows [[1,2],[3,0],[5,-1]])) 5 and + compare (mat.maxValue (fromRows [[-1,-2],[-3,0],[-5,-1]])) 0 and + compare (mat.maxValue (fromRows [[-1,-2],[-3,-4],[-5,-1]])) (-1) and + compare (mat.maxValue (fromRows [[],[],[]])) 0 +), + +"total-\(name)": \( + compare (mat.total (fromRows [[1,2],[3,4],[5,-1]])) 14 and + compare (mat.total (fromRows [[1,2],[3,0],[5,-1]])) 10 and + compare (mat.total (fromRows [[-1,-2],[-3,0],[-5,-1]])) (-12) and + compare (mat.total (fromRows [[-1,-2],[-3,-4],[-5,-1]])) (-16) and + compare (mat.total (fromRows [[],[],[]])) 0 +), + "sum-\(name)": \( compareMatrices (mat.sum [constMatrix 2 { rows = 3, columns = 4 },