[pure-lang-svn] SF.net SVN: pure-lang:[831] pure/trunk/lib/primitives.pure
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-09-22 21:52:50
|
Revision: 831 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=831&view=rev Author: agraef Date: 2008-09-22 21:36:31 +0000 (Mon, 22 Sep 2008) Log Message: ----------- Add matrix/list conversion operations. Modified Paths: -------------- pure/trunk/lib/primitives.pure Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-09-22 21:14:10 UTC (rev 830) +++ pure/trunk/lib/primitives.pure 2008-09-22 21:36:31 UTC (rev 831) @@ -469,6 +469,20 @@ cols x::matrix = map (col x) (0..m-1) when _,m::int = dim x end; +/* Convert a matrix to a list and vice versa. */ + +list x::matrix = [[x!(i,j) | j=0..m-1] | i=0..n-1] + when n::int,m::int = dim x end; +matrix [] = {}; +matrix xs@(x:_) = rowcatmap colcat xs; + +/* Convenience functions to create vectors from lists. */ + +rowvector xs@[] | rowvector xs@(_:_) + = colcat xs; +colvector xs@[] | colvector xs@(_:_) + = rowcat xs; + /* Extract (sub-,super-) diagonals from a matrix. Sub- and super-diagonals for k=0 return the main diagonal. Indices for sub- and super-diagonals can also be negative, in which case the corresponding super- or sub-diagonal is This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |