[pure-lang-svn] SF.net SVN: pure-lang:[786] pure/trunk/lib/primitives.pure
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-09-18 13:35:50
|
Revision: 786 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=786&view=rev Author: agraef Date: 2008-09-18 20:35:54 +0000 (Thu, 18 Sep 2008) Log Message: ----------- Add some basic matrix operations (type checking predicates for vectors). Modified Paths: -------------- pure/trunk/lib/primitives.pure Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-09-18 20:19:31 UTC (rev 785) +++ pure/trunk/lib/primitives.pure 2008-09-18 20:35:54 UTC (rev 786) @@ -46,6 +46,22 @@ cmatrixp x = case x of _::cmatrix = 1; _ = 0 end; imatrixp x = case x of _::imatrix = 1; _ = 0 end; +/* Pure represents row and column vectors as matrices with 1 row or column, + respectively. The following predicates allow you to check for these special + kinds of matrices. */ + +vectorp x = matrixp x && (n==1 || m==1 when n::int,m::int = dim x end); +rowvectorp x = matrixp x && dim x!0==1; +colvectorp x = matrixp x && dim x!1==1; + +cvectorp x = cmatrixp x && (n==1 || m==1 when n::int,m::int = dim x end); +rowcvectorp x = cmatrixp x && dim x!0==1; +colcvectorp x = cmatrixp x && dim x!1==1; + +ivectorp x = imatrixp x && (n==1 || m==1 when n::int,m::int = dim x end); +rowivectorp x = imatrixp x && dim x!0==1; +colivectorp x = imatrixp x && dim x!1==1; + /* Predicates to check for function objects, global (unbound) variables, function applications, proper lists, list nodes and tuples. */ @@ -409,7 +425,7 @@ x::imatrix!(i::int,j::int) = matrix_elem x i j if (i>=0 && i<n && j>=0 && j<m - when n,m = dim x end); + when n::int,m::int = dim x end); = throw out_of_bounds otherwise; /* IEEE floating point infinities and NaNs. Place these after the definitions This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |