Skip to content

Commit

Permalink
Severely optimized Matrix.rows.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xd34df00d committed Nov 17, 2011
1 parent 9a6caf6 commit 01370f0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions hs/Matrix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,13 @@ invMat2 m | n == 0 = m
cM' = (-1) *| (dM' *|* cM *|* aMi)

rows :: Matrix e -> [[e]]
rows m = map getRow [0..r]
where (r, c) = dims m
getRow i = map snd $ filter (\((r, _), _) -> r == i) as
es = Matrix.elems m
as = assocs es
rows m = unfoldr (f . splitAt r) (Data.Array.elems $ Matrix.elems m)
where r = (snd $ dims m) + 1
f ([], _) = Nothing
f l = Just l

cols :: Matrix e -> [[e]]
cols = rows . trp
cols = transpose . rows

rowsAsMats :: Matrix e -> [Matrix e]
rowsAsMats = map (fromRows . listize) . rows
Expand Down

0 comments on commit 01370f0

Please sign in to comment.