Mercurial > hg > may
changeset 240:f22ae9bfe49f sparse
Fix sparse matrix enumerate
author | Chris Cannam |
---|---|
date | Mon, 20 May 2013 15:08:14 +0100 |
parents | 741784624bb6 |
children | e777a713027b |
files | yetilab/matrix/matrix.yeti yetilab/matrix/test/test_matrix.yeti |
diffstat | 2 files changed, 16 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/yetilab/matrix/matrix.yeti Mon May 20 14:40:52 2013 +0100 +++ b/yetilab/matrix/matrix.yeti Mon May 20 15:08:14 2013 +0100 @@ -140,22 +140,20 @@ fi; enumerateSparse m = - (enumerate vv ix ptr jn n = - case vv of - v::rest: - { v, i = ix[n], j = jn } :. - if n + 1 >= head ptr - then \(enumerate rest ix (tail ptr) (jn + 1) (n + 1)) - else \(enumerate rest ix ptr jn (n + 1)) - fi; - _: []; - esac; + (enumerate { values, indices, pointers } = + concat + (map do i: + start = pointers[i]; + end = pointers[i+1]; + map2 do j v: { i, j, v } done + (slice indices start end) + (vec.list (vec.slice values start end)) + done [0..length pointers - 2]); case m of - SparseCSC { values, indices, pointers, extent }: - enumerate (vec.list values) indices (list pointers) 0 0; - SparseCSR { values, indices, pointers, extent }: - map do { i, j, v }: { i = j, j = i, v } done - (enumerate (vec.list values) indices (list pointers) 0 0); + SparseCSC d: + map do { i, j, v }: { i = j, j = i, v } done (enumerate d); + SparseCSR d: + enumerate d; _: []; esac); @@ -398,6 +396,7 @@ _: zeroSizeMatrix (); esac; +//!!! inconsistent with std.slice which has start..end not start+count (see also vec.slice/rangeOf) rowSlice start count m = //!!! doc: storage order same as input if isRowMajor? m then DenseRows (array (map ((flip getRow) m) [start .. start + count - 1]))
--- a/yetilab/matrix/test/test_matrix.yeti Mon May 20 14:40:52 2013 +0100 +++ b/yetilab/matrix/test/test_matrix.yeti Mon May 20 15:08:14 2013 +0100 @@ -377,10 +377,10 @@ rowhash = makeTests "row-dense" mat.flipped; sparsecolhash = makeTests "column-sparse" (mat.toSparse 0); sparserowhash = makeTests "row-sparse" ((mat.toSparse 0) . (mat.flipped)); -//sparserowhash2 = makeTests "row-sparse2" ((mat.flipped) . (mat.toSparse 0)); +sparserowhash2 = makeTests "row-sparse2" ((mat.flipped) . (mat.toSparse 0)); all = [:]; -for [ colhash, rowhash, sparsecolhash, sparserowhash /*, sparserowhash2 */ ] do h: +for [ colhash, rowhash, sparsecolhash, sparserowhash, sparserowhash2 ] do h: for (keys h) do k: all[k] := h[k] done; done;