pure-lang-svn Mailing List for Pure
Status: Beta
Brought to you by:
agraef
You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
(141) |
Jun
(184) |
Jul
(97) |
Aug
(232) |
Sep
(196) |
Oct
|
Nov
|
Dec
|
---|
From: <ag...@us...> - 2008-09-28 20:42:47
|
Revision: 892 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=892&view=rev Author: agraef Date: 2008-09-28 20:42:41 +0000 (Sun, 28 Sep 2008) Log Message: ----------- Snapshot Of Pure 0.8. Added Paths: ----------- pure/releases/pure-0.8/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-28 07:28:06
|
Revision: 890 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=890&view=rev Author: agraef Date: 2008-09-28 07:28:01 +0000 (Sun, 28 Sep 2008) Log Message: ----------- Final polish (0.8 release). Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/NEWS Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-09-28 06:37:13 UTC (rev 889) +++ pure/trunk/ChangeLog 2008-09-28 07:28:01 UTC (rev 890) @@ -1,5 +1,7 @@ 2008-09-28 Albert Graef <Dr....@t-...> + * 0.8 release. + * test/test025.pure: matrix tests. NOTE: This test is expected to fail if Pure was built without GSL support. Modified: pure/trunk/NEWS =================================================================== --- pure/trunk/NEWS 2008-09-28 06:37:13 UTC (rev 889) +++ pure/trunk/NEWS 2008-09-28 07:28:01 UTC (rev 890) @@ -1,11 +1,11 @@ -** Pure 0.8 (in progress) +** Pure 0.8 2008-09-28 -This is a maintenance release. It fixes a rather annoying bug in catmap -(reported by Eddie Rucker) and some minor glitches in the Makefile and the -documentation. Also, the matrix conversion operations in matrices.pure have -been overhauled (in particular, the matrix pointer conversions are much more -complete now). Details can be found in the ChangeLog. +This is a maintenance release. It fixes a bug in catmap which slipped into the +0.6 release (reported by Eddie Rucker) and some minor glitches in the Makefile +and the documentation. Also, the matrix conversion operations in matrices.pure +have been overhauled (in particular, the matrix-pointer conversions are much +more complete now). Details can be found in the ChangeLog. ** Pure 0.7 2008-09-26 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-28 06:37:20
|
Revision: 889 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=889&view=rev Author: agraef Date: 2008-09-28 06:37:13 +0000 (Sun, 28 Sep 2008) Log Message: ----------- Updated ChangeLog. Modified Paths: -------------- pure/trunk/ChangeLog Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-09-28 06:35:33 UTC (rev 888) +++ pure/trunk/ChangeLog 2008-09-28 06:37:13 UTC (rev 889) @@ -1,3 +1,10 @@ +2008-09-28 Albert Graef <Dr....@t-...> + + * test/test025.pure: matrix tests. NOTE: This test is expected to + fail if Pure was built without GSL support. + + * test/test024.pure: catmap and stream tests. + 2008-09-27 Albert Graef <Dr....@t-...> * configure.ac: Bump version number. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-28 06:35:37
|
Revision: 888 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=888&view=rev Author: agraef Date: 2008-09-28 06:35:33 +0000 (Sun, 28 Sep 2008) Log Message: ----------- Add matrix tests. Added Paths: ----------- pure/trunk/test/test025.log pure/trunk/test/test025.pure Added: pure/trunk/test/test025.log =================================================================== --- pure/trunk/test/test025.log (rev 0) +++ pure/trunk/test/test025.log 2008-09-28 06:35:33 UTC (rev 888) @@ -0,0 +1,475 @@ +let x = {1,2,3;4,5,6}; +x; +{1,2,3;4,5,6} +x'; +{1,4;2,5;3,6} +reverse x; +{6,5,4;3,2,1} +#x; +6 +dim x; +2,3 +redim (3,2) x; +{1,2;3,4;5,6} +x!(1,1); +5 +x!!(0,0..2); +{1,2,3} +x!!(0..1,0..1); +{1,2;4,5} +diag x; +{1,5} +supdiag x 1; +{2} +subdiag x 1; +{4} +supdiag x 1===subdiag x (-1); +1 +let x = {1.0,2.0,3.0;4.0,5.0,6.0}; +x; +{1.0,2.0,3.0;4.0,5.0,6.0} +x'; +{1.0,4.0;2.0,5.0;3.0,6.0} +reverse x; +{6.0,5.0,4.0;3.0,2.0,1.0} +#x; +6 +dim x; +2,3 +redim (3,2) x; +{1.0,2.0;3.0,4.0;5.0,6.0} +x!(1,1); +5.0 +x!!(0,0..2); +{1.0,2.0,3.0} +x!!(0..1,0..1); +{1.0,2.0;4.0,5.0} +diag x; +{1.0,5.0} +supdiag x 1; +{2.0} +subdiag x 1; +{4.0} +supdiag x 1===subdiag x (-1); +1 +let x = {1.0+:-2.0,2.0+:-4.0,3.0+:-6.0;4.0+:1.0,5.0+:2.0,6.0+:3.0}; +x; +{1.0+:-2.0,2.0+:-4.0,3.0+:-6.0;4.0+:1.0,5.0+:2.0,6.0+:3.0} +x'; +{1.0+:-2.0,4.0+:1.0;2.0+:-4.0,5.0+:2.0;3.0+:-6.0,6.0+:3.0} +reverse x; +{6.0+:3.0,5.0+:2.0,4.0+:1.0;3.0+:-6.0,2.0+:-4.0,1.0+:-2.0} +#x; +6 +dim x; +2,3 +redim (3,2) x; +{1.0+:-2.0,2.0+:-4.0;3.0+:-6.0,4.0+:1.0;5.0+:2.0,6.0+:3.0} +x!(1,1); +5.0+:2.0 +x!!(0,0..2); +{1.0+:-2.0,2.0+:-4.0,3.0+:-6.0} +x!!(0..1,0..1); +{1.0+:-2.0,2.0+:-4.0;4.0+:1.0,5.0+:2.0} +diag x; +{1.0+:-2.0,5.0+:2.0} +supdiag x 1; +{2.0+:-4.0} +subdiag x 1; +{4.0+:1.0} +supdiag x 1===subdiag x (-1); +1 +let x = {1,2,3;4,5,6}; +{ + rule #0: y = dmatrix x + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = dmatrix x; +{ + rule #0: z = cmatrix y + state 0: #0 + <var> state 1 + state 1: #0 +} +let z = cmatrix y; +x; +{1,2,3;4,5,6} +y; +{1.0,2.0,3.0;4.0,5.0,6.0} +z; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +imatrix x===x; +1 +dmatrix y===y; +1 +cmatrix z===z; +1 +imatrix y===x; +1 +re z===y; +1 +im z===dmatrix (dim x); +1 +imatrix z; +{1,0,2,0,3,0;4,0,5,0,6,0} +dmatrix z; +{1.0,0.0,2.0,0.0,3.0,0.0;4.0,0.0,5.0,0.0,6.0,0.0} +let x = {1,2,3;4,5,6}; +{ + rule #0: y = int_matrix_view (3,2) (pointer x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = int_matrix_view (3,2) (pointer x); +x; +{1,2,3;4,5,6} +y; +{1,2;3,4;5,6} +list x==list y; +1 +dim x==reverse (dim y); +1 +{ + rule #0: y = double_matrix (2,3) (double_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = double_matrix (2,3) (double_pointer #<pointer 0> x); +x; +{1,2,3;4,5,6} +y; +{1.0,2.0,3.0;4.0,5.0,6.0} +x==y; +1 +{ + rule #0: y = float_matrix (2,3) (float_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = float_matrix (2,3) (float_pointer #<pointer 0> x); +x; +{1,2,3;4,5,6} +y; +{1.0,2.0,3.0;4.0,5.0,6.0} +x==y; +1 +{ + rule #0: y = complex_matrix (2,3) (complex_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = complex_matrix (2,3) (complex_pointer #<pointer 0> x); +x; +{1,2,3;4,5,6} +y; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +x==y; +1 +{ + rule #0: y = complex_float_matrix (2,3) (complex_float_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = complex_float_matrix (2,3) (complex_float_pointer #<pointer 0> x); +x; +{1,2,3;4,5,6} +y; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +x==y; +1 +{ + rule #0: y = int_matrix (2,3) (int_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = int_matrix (2,3) (int_pointer #<pointer 0> x); +x; +{1,2,3;4,5,6} +y; +{1,2,3;4,5,6} +x==y; +1 +{ + rule #0: y = short_matrix (2,3) (short_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = short_matrix (2,3) (short_pointer #<pointer 0> x); +x; +{1,2,3;4,5,6} +y; +{1,2,3;4,5,6} +x==y; +1 +{ + rule #0: y = byte_matrix (2,3) (byte_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = byte_matrix (2,3) (byte_pointer #<pointer 0> x); +x; +{1,2,3;4,5,6} +y; +{1,2,3;4,5,6} +x==y; +1 +{ + rule #0: x = dmatrix {1,2,3;4,5,6} + state 0: #0 + <var> state 1 + state 1: #0 +} +let x = dmatrix {1,2,3;4,5,6}; +{ + rule #0: y = double_matrix_view (3,2) (pointer x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = double_matrix_view (3,2) (pointer x); +x; +{1.0,2.0,3.0;4.0,5.0,6.0} +y; +{1.0,2.0;3.0,4.0;5.0,6.0} +list x==list y; +1 +dim x==reverse (dim y); +1 +{ + rule #0: y = double_matrix (2,3) (double_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = double_matrix (2,3) (double_pointer #<pointer 0> x); +x; +{1.0,2.0,3.0;4.0,5.0,6.0} +y; +{1.0,2.0,3.0;4.0,5.0,6.0} +x==y; +1 +{ + rule #0: y = float_matrix (2,3) (float_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = float_matrix (2,3) (float_pointer #<pointer 0> x); +x; +{1.0,2.0,3.0;4.0,5.0,6.0} +y; +{1.0,2.0,3.0;4.0,5.0,6.0} +x==y; +1 +{ + rule #0: y = complex_matrix (2,3) (complex_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = complex_matrix (2,3) (complex_pointer #<pointer 0> x); +x; +{1.0,2.0,3.0;4.0,5.0,6.0} +y; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +x==y; +1 +{ + rule #0: y = complex_float_matrix (2,3) (complex_float_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = complex_float_matrix (2,3) (complex_float_pointer #<pointer 0> x); +x; +{1.0,2.0,3.0;4.0,5.0,6.0} +y; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +x==y; +1 +{ + rule #0: y = int_matrix (2,3) (int_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = int_matrix (2,3) (int_pointer #<pointer 0> x); +x; +{1.0,2.0,3.0;4.0,5.0,6.0} +y; +{1,2,3;4,5,6} +x==y; +1 +{ + rule #0: y = short_matrix (2,3) (short_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = short_matrix (2,3) (short_pointer #<pointer 0> x); +x; +{1.0,2.0,3.0;4.0,5.0,6.0} +y; +{1,2,3;4,5,6} +x==y; +1 +{ + rule #0: y = byte_matrix (2,3) (byte_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = byte_matrix (2,3) (byte_pointer #<pointer 0> x); +x; +{1.0,2.0,3.0;4.0,5.0,6.0} +y; +{1,2,3;4,5,6} +x==y; +1 +{ + rule #0: x = cmatrix {1,2,3;4,5,6} + state 0: #0 + <var> state 1 + state 1: #0 +} +let x = cmatrix {1,2,3;4,5,6}; +{ + rule #0: y = complex_matrix_view (3,2) (pointer x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = complex_matrix_view (3,2) (pointer x); +x; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +y; +{1.0+:0.0,2.0+:0.0;3.0+:0.0,4.0+:0.0;5.0+:0.0,6.0+:0.0} +list x==list y; +1 +dim x==reverse (dim y); +1 +{ + rule #0: z = double_matrix_view (2,6) (pointer x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let z = double_matrix_view (2,6) (pointer x); +z; +{1.0,0.0,2.0,0.0,3.0,0.0;4.0,0.0,5.0,0.0,6.0,0.0} +cat (catmap (\(a/*0:01*/+:b/*0:1*/) -> [[a/*0:01*/,b/*0:1*/]] { + rule #0: a+:b = [[a,b]] + state 0: #0 + <app> state 1 + state 1: #0 + <app> state 2 + state 2: #0 + +: state 3 + state 3: #0 + <var> state 4 + state 4: #0 + <var> state 5 + state 5: #0 +}) x)==list z; +1 +{ + rule #0: y = double_matrix (2,6) (double_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = double_matrix (2,6) (double_pointer #<pointer 0> x); +x; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +y; +{1.0,0.0,2.0,0.0,3.0,0.0;4.0,0.0,5.0,0.0,6.0,0.0} +y==z; +1 +{ + rule #0: y = float_matrix (2,6) (float_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = float_matrix (2,6) (float_pointer #<pointer 0> x); +x; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +y; +{1.0,0.0,2.0,0.0,3.0,0.0;4.0,0.0,5.0,0.0,6.0,0.0} +y==z; +1 +{ + rule #0: y = complex_matrix (2,3) (complex_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = complex_matrix (2,3) (complex_pointer #<pointer 0> x); +x; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +y; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +x==y; +1 +{ + rule #0: y = complex_float_matrix (2,3) (complex_float_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = complex_float_matrix (2,3) (complex_float_pointer #<pointer 0> x); +x; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +y; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +x==y; +1 +{ + rule #0: y = int_matrix (2,6) (int_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = int_matrix (2,6) (int_pointer #<pointer 0> x); +x; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +y; +{1,0,2,0,3,0;4,0,5,0,6,0} +y==z; +1 +{ + rule #0: y = short_matrix (2,6) (short_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = short_matrix (2,6) (short_pointer #<pointer 0> x); +x; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +y; +{1,0,2,0,3,0;4,0,5,0,6,0} +y==z; +1 +{ + rule #0: y = byte_matrix (2,6) (byte_pointer #<pointer 0> x) + state 0: #0 + <var> state 1 + state 1: #0 +} +let y = byte_matrix (2,6) (byte_pointer #<pointer 0> x); +x; +{1.0+:0.0,2.0+:0.0,3.0+:0.0;4.0+:0.0,5.0+:0.0,6.0+:0.0} +y; +{1,0,2,0,3,0;4,0,5,0,6,0} +y==z; +1 Added: pure/trunk/test/test025.pure =================================================================== --- pure/trunk/test/test025.pure (rev 0) +++ pure/trunk/test/test025.pure 2008-09-28 06:35:33 UTC (rev 888) @@ -0,0 +1,129 @@ + +// matrix stuff + +// NOTE: This test will fail if Pure was built without GSL support. + +using math; + +// Basic matrix ops. + +// int matrix +let x = {1,2,3;4,5,6}; + +x; x'; reverse x; +#x; dim x; redim (3,2) x; +x!(1,1); x!!(0,0..2); x!!(0..1,0..1); +diag x; supdiag x 1; subdiag x 1; supdiag x 1===subdiag x (-1); + +// double matrix +let x = {1.0,2.0,3.0;4.0,5.0,6.0}; + +x; x'; reverse x; +#x; dim x; redim (3,2) x; +x!(1,1); x!!(0,0..2); x!!(0..1,0..1); +diag x; supdiag x 1; subdiag x 1; supdiag x 1===subdiag x (-1); + +// complex matrix +let x = {1.0+:-2.0,2.0+:-4.0,3.0+:-6.0;4.0+:1.0,5.0+:2.0,6.0+:3.0}; + +x; x'; reverse x; +#x; dim x; redim (3,2) x; +x!(1,1); x!!(0,0..2); x!!(0..1,0..1); +diag x; supdiag x 1; subdiag x 1; supdiag x 1===subdiag x (-1); + +// Numeric matrix conversions. + +let x = {1,2,3;4,5,6}; +let y = dmatrix x; +let z = cmatrix y; + +x;y;z; + +imatrix x===x; dmatrix y===y; cmatrix z===z; + +imatrix y===x; re z===y; im z===dmatrix (dim x); + +imatrix z; dmatrix z; + +// Matrix-pointer conversions. + +// int matrix +let x = {1,2,3;4,5,6}; +let y = int_matrix_view (3,2) (pointer x); +x; y; list x==list y; dim x == reverse (dim y); + +let y = double_matrix (2,3) (double_pointer NULL x); +x; y; x==y; + +let y = float_matrix (2,3) (float_pointer NULL x); +x; y; x==y; + +let y = complex_matrix (2,3) (complex_pointer NULL x); +x; y; x==y; + +let y = complex_float_matrix (2,3) (complex_float_pointer NULL x); +x; y; x==y; + +let y = int_matrix (2,3) (int_pointer NULL x); +x; y; x==y; + +let y = short_matrix (2,3) (short_pointer NULL x); +x; y; x==y; + +let y = byte_matrix (2,3) (byte_pointer NULL x); +x; y; x==y; + +// double matrix +let x = dmatrix {1,2,3;4,5,6}; +let y = double_matrix_view (3,2) (pointer x); +x; y; list x==list y; dim x == reverse (dim y); + +let y = double_matrix (2,3) (double_pointer NULL x); +x; y; x==y; + +let y = float_matrix (2,3) (float_pointer NULL x); +x; y; x==y; + +let y = complex_matrix (2,3) (complex_pointer NULL x); +x; y; x==y; + +let y = complex_float_matrix (2,3) (complex_float_pointer NULL x); +x; y; x==y; + +let y = int_matrix (2,3) (int_pointer NULL x); +x; y; x==y; + +let y = short_matrix (2,3) (short_pointer NULL x); +x; y; x==y; + +let y = byte_matrix (2,3) (byte_pointer NULL x); +x; y; x==y; + +// complex matrix +let x = cmatrix {1,2,3;4,5,6}; +let y = complex_matrix_view (3,2) (pointer x); +x; y; list x==list y; dim x == reverse (dim y); + +let z = double_matrix_view (2,6) (pointer x); +z; cat [[a,b]|a+:b=x]==list z; + +let y = double_matrix (2,6) (double_pointer NULL x); +x; y; y==z; + +let y = float_matrix (2,6) (float_pointer NULL x); +x; y; y==z; + +let y = complex_matrix (2,3) (complex_pointer NULL x); +x; y; x==y; + +let y = complex_float_matrix (2,3) (complex_float_pointer NULL x); +x; y; x==y; + +let y = int_matrix (2,6) (int_pointer NULL x); +x; y; y==z; + +let y = short_matrix (2,6) (short_pointer NULL x); +x; y; y==z; + +let y = byte_matrix (2,6) (byte_pointer NULL x); +x; y; y==z; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-27 16:18:49
|
Revision: 885 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=885&view=rev Author: agraef Date: 2008-09-27 16:18:43 +0000 (Sat, 27 Sep 2008) Log Message: ----------- Bump version number, update ChangeLog and NEWS. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/NEWS pure/trunk/configure pure/trunk/configure.ac Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-09-27 16:03:46 UTC (rev 884) +++ pure/trunk/ChangeLog 2008-09-27 16:18:43 UTC (rev 885) @@ -1,3 +1,16 @@ +2008-09-27 Albert Graef <Dr....@t-...> + + * configure.ac: Bump version number. + + * lib/matrices.pure, interpreter.cc/h: Added missing + complex->double/int matrix conversions. Thorough overhaul of + matrix<->pointer conversions, which now provide a complete set of + conversions from/to any reasonable C array representation, + including float, complex float, short and byte arrays. + + * lib/prelude.pure: Fix a bug in cat which broke catmap on + strings. Reported by Eddie Rucker. + 2008-09-25 Albert Graef <Dr....@t-...> * 0.7 release. Modified: pure/trunk/NEWS =================================================================== --- pure/trunk/NEWS 2008-09-27 16:03:46 UTC (rev 884) +++ pure/trunk/NEWS 2008-09-27 16:18:43 UTC (rev 885) @@ -1,6 +1,14 @@ -** Pure 0.7 (2008-09-26) +** Pure 0.8 (in progress) +This is a maintenance release. It fixes a rather annoying bug in catmap +(reported by Eddie Rucker) and some minor glitches in the Makefile and the +documentation. Also, the matrix conversion operations in matrices.pure have +been overhauled (in particular, the matrix pointer conversions are much more +complete now). Details can be found in the ChangeLog. + +** Pure 0.7 2008-09-26 + This release brings an important new feature: GSL (GNU Scientific Library) matrix support. Here's a brief overview of the new stuff. For more information on GSL please refer to http://www.gnu.org/software/gsl. Modified: pure/trunk/configure =================================================================== --- pure/trunk/configure 2008-09-27 16:03:46 UTC (rev 884) +++ pure/trunk/configure 2008-09-27 16:18:43 UTC (rev 885) @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.61 for pure 0.7. +# Generated by GNU Autoconf 2.61 for pure 0.8. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. @@ -572,8 +572,8 @@ # Identity of this package. PACKAGE_NAME='pure' PACKAGE_TARNAME='pure' -PACKAGE_VERSION='0.7' -PACKAGE_STRING='pure 0.7' +PACKAGE_VERSION='0.8' +PACKAGE_STRING='pure 0.8' PACKAGE_BUGREPORT='' # Factoring default headers for most tests. @@ -1199,7 +1199,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures pure 0.7 to adapt to many kinds of systems. +\`configure' configures pure 0.8 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1264,7 +1264,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of pure 0.7:";; + short | recursive ) echo "Configuration of pure 0.8:";; esac cat <<\_ACEOF @@ -1358,7 +1358,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -pure configure 0.7 +pure configure 0.8 generated by GNU Autoconf 2.61 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1372,7 +1372,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by pure $as_me 0.7, which was +It was created by pure $as_me 0.8, which was generated by GNU Autoconf 2.61. Invocation command line was $ $0 $@ @@ -6716,7 +6716,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by pure $as_me 0.7, which was +This file was extended by pure $as_me 0.8, which was generated by GNU Autoconf 2.61. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -6765,7 +6765,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -pure config.status 0.7 +pure config.status 0.8 configured by $0, generated by GNU Autoconf 2.61, with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" Modified: pure/trunk/configure.ac =================================================================== --- pure/trunk/configure.ac 2008-09-27 16:03:46 UTC (rev 884) +++ pure/trunk/configure.ac 2008-09-27 16:18:43 UTC (rev 885) @@ -2,7 +2,7 @@ dnl To regenerate the configury after changes: dnl autoconf -I config && autoheader -I config -AC_INIT(pure, 0.7) +AC_INIT(pure, 0.8) AC_CONFIG_AUX_DIR(config) dnl AC_CONFIG_MACRO_DIR(config) AC_CONFIG_HEADERS(config.h) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-27 16:03:53
|
Revision: 884 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=884&view=rev Author: agraef Date: 2008-09-27 16:03:46 +0000 (Sat, 27 Sep 2008) Log Message: ----------- Added missing complex->double/int matrix conversions, overhaul of matrix<->pointer conversions. Modified Paths: -------------- pure/trunk/lib/matrices.pure pure/trunk/runtime.cc pure/trunk/runtime.h Modified: pure/trunk/lib/matrices.pure =================================================================== --- pure/trunk/lib/matrices.pure 2008-09-27 13:11:09 UTC (rev 883) +++ pure/trunk/lib/matrices.pure 2008-09-27 16:03:46 UTC (rev 884) @@ -217,9 +217,9 @@ (either a pair denoting the number of rows and columns, or just the row size in order to create a row vector). */ -dmatrix (n::int,m::int) = dmatrix_dup (pointer 0,n,m); -cmatrix (n::int,m::int) = cmatrix_dup (pointer 0,n,m); -imatrix (n::int,m::int) = imatrix_dup (pointer 0,n,m); +dmatrix (n::int,m::int) = double_matrix (n,m) (pointer 0); +cmatrix (n::int,m::int) = complex_matrix (n,m) (pointer 0); +imatrix (n::int,m::int) = int_matrix (n,m) (pointer 0); dmatrix n::int = dmatrix (1,n); cmatrix n::int = cmatrix (1,n); @@ -233,8 +233,8 @@ extern expr* matrix_double(expr *x), expr* matrix_complex(expr *x), expr* matrix_int(expr *x); -dmatrix x::matrix = matrix_double x if imatrixp x || dmatrixp x; -imatrix x::matrix = matrix_int x if imatrixp x || dmatrixp x; +dmatrix x::matrix = matrix_double x if nmatrixp x; +imatrix x::matrix = matrix_int x if nmatrixp x; cmatrix x::matrix = matrix_complex x if nmatrixp x; private matrix_re matrix_im; @@ -374,94 +374,126 @@ important consideration (e.g., graphics, video and audio applications). The usual caveats apply. */ -/* Convert a matrix to a pointer, which points directly to the underlying C - array. You have to be careful when passing such a pointer to C functions if - the underlying data is non-contiguous; when in doubt, first use the 'pack' - function from above to place the data in contiguous storage. */ +/* Get a pointer to the underlying C array of a matrix. The data is *not* + copied. Hence you have to be careful when passing such a pointer to C + functions if the underlying data is non-contiguous; when in doubt, first + use the 'pack' function from above to place the data in contiguous storage, + or use one of the matrix-pointer conversion routines below. */ private pure_pointerval; extern expr* pure_pointerval(expr*); pointer x::matrix = pure_pointerval x; -/* Create a numeric matrix from a pointer, without copying the data. The - caller must ensure that the pointer points to properly initialized memory - big enough to accommodate the requested dimensions, which persists for the - entire lifetime of the matrix object. */ +/* Copy the contents of a matrix to a given pointer and return that pointer, + converting to the target data type on the fly if necessary. The given + pointer may also be NULL, in which case suitable memory is malloc'ed and + returned; otherwise the caller must ensure that the memory pointed to by p + is big enough for the contents of the given matrix. */ +private matrix_to_double_array; +private matrix_to_float_array; +private matrix_to_complex_array; +private matrix_to_complex_float_array; +private matrix_to_int_array; +private matrix_to_short_array; +private matrix_to_byte_array; +extern void* matrix_to_double_array(void* p, expr* x); +extern void* matrix_to_float_array(void* p, expr* x); +extern void* matrix_to_complex_array(void* p, expr* x); +extern void* matrix_to_complex_float_array(void* p, expr* x); +extern void* matrix_to_int_array(void* p, expr* x); +extern void* matrix_to_short_array(void* p, expr* x); +extern void* matrix_to_byte_array(void* p, expr* x); + +double_pointer p::pointer x::matrix + = matrix_to_double_array p x if nmatrixp x; +float_pointer p::pointer x::matrix + = matrix_to_float_array p x if nmatrixp x; +complex_pointer p::pointer x::matrix + = matrix_to_complex_array p x if nmatrixp x; +complex_float_pointer p::pointer x::matrix + = matrix_to_complex_float_array p x if nmatrixp x; +int_pointer p::pointer x::matrix + = matrix_to_int_array p x if nmatrixp x; +short_pointer p::pointer x::matrix + = matrix_to_short_array p x if nmatrixp x; +byte_pointer p::pointer x::matrix + = matrix_to_byte_array p x if nmatrixp x; + +/* Create a numeric matrix from a pointer, copying the data and converting it + from the source type on the fly if necessary. The source pointer p may also + be NULL, in which case the new matrix is filled with zeros instead. + Otherwise the caller must ensure that the pointer points to properly + initialized memory big enough for the requested dimensions. */ + private matrix_from_double_array; +private matrix_from_float_array; private matrix_from_complex_array; +private matrix_from_complex_float_array; private matrix_from_int_array; -extern expr* matrix_from_double_array(void* p, int n, int m); -extern expr* matrix_from_complex_array(void* p, int n, int m); -extern expr* matrix_from_int_array(void* p, int n, int m); +private matrix_from_short_array; +private matrix_from_byte_array; +extern expr* matrix_from_double_array(int n, int m, void* p); +extern expr* matrix_from_float_array(int n, int m, void* p); +extern expr* matrix_from_complex_array(int n, int m, void* p); +extern expr* matrix_from_complex_float_array(int n, int m, void* p); +extern expr* matrix_from_int_array(int n, int m, void* p); +extern expr* matrix_from_short_array(int n, int m, void* p); +extern expr* matrix_from_byte_array(int n, int m, void* p); -dmatrix (p::pointer,n::int,m::int) - = matrix_from_double_array p n m; -cmatrix (p::pointer,n::int,m::int) - = matrix_from_complex_array p n m; -imatrix (p::pointer,n::int,m::int) - = matrix_from_int_array p n m; +double_matrix (n::int,m::int) p::pointer + = matrix_from_double_array n m p; +float_matrix (n::int,m::int) p::pointer + = matrix_from_float_array n m p; +complex_matrix (n::int,m::int) p::pointer + = matrix_from_complex_array n m p; +complex_float_matrix (n::int,m::int) p::pointer + = matrix_from_complex_float_array n m p; +int_matrix (n::int,m::int) p::pointer + = matrix_from_int_array n m p; +short_matrix (n::int,m::int) p::pointer + = matrix_from_short_array n m p; +byte_matrix (n::int,m::int) p::pointer + = matrix_from_byte_array n m p; -dmatrix (p::pointer,n::int) - = dmatrix (p,1,n); -cmatrix (p::pointer,n::int) - = cmatrix (p,1,n); -imatrix (p::pointer,n::int) - = imatrix (p,1,n); +double_matrix n::int p::pointer + = double_matrix (1,n) p; +float_matrix n::int p::pointer + = float_matrix (1,n) p; +complex_matrix n::int p::pointer + = complex_matrix (1,n) p; +complex_float_matrix n::int p::pointer + = complex_float_matrix (1,n) p; +int_matrix n::int p::pointer + = int_matrix (1,n) p; +short_matrix n::int p::pointer + = short_matrix (1,n) p; +byte_matrix n::int p::pointer + = byte_matrix (1,n) p; -/* Create a numeric matrix from a pointer, copying the data to fresh memory. - The source pointer p may also be NULL, in which case the new matrix is - filled with zeros instead. */ +/* Create a numeric matrix view of existing data, without copying the data. + The data must be double, complex or int, the pointer must not be NULL and + the caller must also ensure that the memory persists for the entire + lifetime of the matrix object. */ -private matrix_from_double_array_dup; -private matrix_from_complex_array_dup; -private matrix_from_int_array_dup; -extern expr* matrix_from_double_array_dup(void* p, int n, int m); -extern expr* matrix_from_complex_array_dup(void* p, int n, int m); -extern expr* matrix_from_int_array_dup(void* p, int n, int m); +private matrix_from_double_array_nodup; +private matrix_from_complex_array_nodup; +private matrix_from_int_array_nodup; +extern expr* matrix_from_double_array_nodup(int n, int m, void* p); +extern expr* matrix_from_complex_array_nodup(int n, int m, void* p); +extern expr* matrix_from_int_array_nodup(int n, int m, void* p); -dmatrix_dup (p::pointer,n::int,m::int) - = matrix_from_double_array_dup p n m; -cmatrix_dup (p::pointer,n::int,m::int) - = matrix_from_complex_array_dup p n m; -imatrix_dup (p::pointer,n::int,m::int) - = matrix_from_int_array_dup p n m; +double_matrix_view (n::int,m::int) p::pointer + = matrix_from_double_array_nodup n m p; +complex_matrix_view (n::int,m::int) p::pointer + = matrix_from_complex_array_nodup n m p; +int_matrix_view (n::int,m::int) p::pointer + = matrix_from_int_array_nodup n m p; -dmatrix_dup (p::pointer,n::int) - = dmatrix_dup (p,1,n); -cmatrix_dup (p::pointer,n::int) - = cmatrix_dup (p,1,n); -imatrix_dup (p::pointer,n::int) - = imatrix_dup (p,1,n); - -/* Some additional functions for alternate base types. These work like the - routines above, but initialize the data from float, complex float, short - and byte arrays, respectively. */ - -private matrix_from_float_array_dup; -private matrix_from_complex_float_array_dup; -private matrix_from_short_array_dup; -private matrix_from_byte_array_dup; -extern expr* matrix_from_float_array_dup(void* p, int n, int m); -extern expr* matrix_from_complex_float_array_dup(void* p, int n, int m); -extern expr* matrix_from_short_array_dup(void* p, int n, int m); -extern expr* matrix_from_byte_array_dup(void* p, int n, int m); - -float_dmatrix_dup (p::pointer,n::int,m::int) - = matrix_from_float_array_dup p n m; -float_cmatrix_dup (p::pointer,n::int,m::int) - = matrix_from_complex_float_array_dup p n m; -short_imatrix_dup (p::pointer,n::int,m::int) - = matrix_from_short_array_dup p n m; -byte_imatrix_dup (p::pointer,n::int,m::int) - = matrix_from_byte_array_dup p n m; - -float_dmatrix_dup (p::pointer,n::int) - = float_dmatrix_dup (p,1,n); -float_cmatrix_dup (p::pointer,n::int) - = float_cmatrix_dup (p,1,n); -short_imatrix_dup (p::pointer,n::int) - = short_imatrix_dup (p,1,n); -byte_imatrix_dup (p::pointer,n::int) - = byte_imatrix_dup (p,1,n); +double_matrix_view n::int p::pointer + = double_matrix_view (1,n) p; +complex_matrix_view n::int p::pointer + = complex_matrix_view (1,n) p; +int_matrix_view n::int p::pointer + = int_matrix_view (1,n) p; Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-09-27 13:11:09 UTC (rev 883) +++ pure/trunk/runtime.cc 2008-09-27 16:03:46 UTC (rev 884) @@ -4882,6 +4882,19 @@ m2->data[i*m2->tda+j] = (double)m1->data[i*m1->tda+j]; return pure_double_matrix(m2); } + case EXPR::CMATRIX: { + gsl_matrix_complex *m1 = (gsl_matrix_complex*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + gsl_matrix *m2 = create_double_matrix(n, 2*m); + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + size_t k = i*m2->tda+2*j; + size_t l = 2*(i*m1->tda+j); + m2->data[k] = m1->data[l]; + m2->data[k+1] = m1->data[l+1]; + } + return pure_double_matrix(m2); + } default: return 0; } @@ -4945,6 +4958,19 @@ } case EXPR::IMATRIX: return x; + case EXPR::CMATRIX: { + gsl_matrix_complex *m1 = (gsl_matrix_complex*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + gsl_matrix_int *m2 = create_int_matrix(n, 2*m); + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + size_t k = i*m2->tda+2*j; + size_t l = 2*(i*m1->tda+j); + m2->data[k] = (int)m1->data[l]; + m2->data[k+1] = (int)m1->data[l+1]; + } + return pure_int_matrix(m2); + } default: return 0; } @@ -5019,7 +5045,7 @@ } extern "C" -pure_expr *matrix_from_double_array(void *p, uint32_t n1, uint32_t n2) +pure_expr *matrix_from_double_array_nodup(uint32_t n1, uint32_t n2, void *p) { #ifdef HAVE_GSL if (n1 == 0 || n2 == 0) // empty matrix @@ -5043,7 +5069,7 @@ } extern "C" -pure_expr *matrix_from_complex_array(void *p, uint32_t n1, uint32_t n2) +pure_expr *matrix_from_complex_array_nodup(uint32_t n1, uint32_t n2, void *p) { #ifdef HAVE_GSL if (n1 == 0 || n2 == 0) // empty matrix @@ -5069,7 +5095,7 @@ } extern "C" -pure_expr *matrix_from_int_array(void *p, uint32_t n1, uint32_t n2) +pure_expr *matrix_from_int_array_nodup(uint32_t n1, uint32_t n2, void *p) { #ifdef HAVE_GSL if (n1 == 0 || n2 == 0) // empty matrix @@ -5093,7 +5119,7 @@ } extern "C" -pure_expr *matrix_from_double_array_dup(void *p, uint32_t n1, uint32_t n2) +pure_expr *matrix_from_double_array(uint32_t n1, uint32_t n2, void *p) { #ifdef HAVE_GSL if (n1 == 0 || n2 == 0) // empty matrix @@ -5128,7 +5154,7 @@ } extern "C" -pure_expr *matrix_from_complex_array_dup(void *p, uint32_t n1, uint32_t n2) +pure_expr *matrix_from_complex_array(uint32_t n1, uint32_t n2, void *p) { #ifdef HAVE_GSL if (n1 == 0 || n2 == 0) // empty matrix @@ -5165,7 +5191,7 @@ } extern "C" -pure_expr *matrix_from_int_array_dup(void *p, uint32_t n1, uint32_t n2) +pure_expr *matrix_from_int_array(uint32_t n1, uint32_t n2, void *p) { #ifdef HAVE_GSL if (n1 == 0 || n2 == 0) // empty matrix @@ -5200,9 +5226,178 @@ } extern "C" -pure_expr *matrix_from_float_array_dup(void *p, uint32_t n1, uint32_t n2) +void *matrix_to_double_array(void *p, pure_expr *x) { #ifdef HAVE_GSL + switch (x->tag) { + case EXPR::CMATRIX: { + gsl_matrix_complex *m1 = (gsl_matrix_complex*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(double)); + if (!p) return 0; + double *q = (double*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + size_t l = 2*(i*m1->tda+j); + q[k++] = m1->data[l]; + q[k++] = m1->data[l+1]; + } + return p; + } + case EXPR::DMATRIX: { + gsl_matrix *m1 = (gsl_matrix*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(n*m*sizeof(double)); + if (!p) return 0; + double *q = (double*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) + q[k++] = m1->data[i*m1->tda+j]; + return p; + } + case EXPR::IMATRIX: { + gsl_matrix_int *m1 = (gsl_matrix_int*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(n*m*sizeof(double)); + if (!p) return 0; + double *q = (double*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) + q[k++] = (double)m1->data[i*m1->tda+j]; + return p; + } + default: + return 0; + } +#else + return 0; +#endif +} + +extern "C" +void *matrix_to_complex_array(void *p, pure_expr *x) +{ +#ifdef HAVE_GSL + switch (x->tag) { + case EXPR::CMATRIX: { + gsl_matrix_complex *m1 = (gsl_matrix_complex*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(double)); + if (!p) return 0; + double *q = (double*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + size_t l = 2*(i*m1->tda+j); + q[k++] = m1->data[l]; + q[k++] = m1->data[l+1]; + } + return p; + } + case EXPR::DMATRIX: { + gsl_matrix *m1 = (gsl_matrix*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(double)); + if (!p) return 0; + double *q = (double*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + q[k++] = m1->data[i*m1->tda+j]; + q[k++] = 0.0; + } + return p; + } + case EXPR::IMATRIX: { + gsl_matrix_int *m1 = (gsl_matrix_int*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(double)); + if (!p) return 0; + double *q = (double*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + q[k++] = (double)m1->data[i*m1->tda+j]; + q[k++] = 0.0; + } + return p; + } + default: + return 0; + } +#else + return 0; +#endif +} + +extern "C" +void *matrix_to_int_array(void *p, pure_expr *x) +{ +#ifdef HAVE_GSL + switch (x->tag) { + case EXPR::CMATRIX: { + gsl_matrix_complex *m1 = (gsl_matrix_complex*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(int)); + if (!p) return 0; + int *q = (int*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + size_t l = 2*(i*m1->tda+j); + q[k++] = (int)m1->data[l]; + q[k++] = (int)m1->data[l+1]; + } + return p; + } + case EXPR::DMATRIX: { + gsl_matrix *m1 = (gsl_matrix*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(n*m*sizeof(int)); + if (!p) return 0; + int *q = (int*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) + q[k++] = (int)m1->data[i*m1->tda+j]; + return p; + } + case EXPR::IMATRIX: { + gsl_matrix_int *m1 = (gsl_matrix_int*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(n*m*sizeof(int)); + if (!p) return 0; + int *q = (int*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) + q[k++] = m1->data[i*m1->tda+j]; + return p; + } + default: + return 0; + } +#else + return 0; +#endif +} + +extern "C" +pure_expr *matrix_from_float_array(uint32_t n1, uint32_t n2, void *p) +{ +#ifdef HAVE_GSL if (n1 == 0 || n2 == 0) // empty matrix return pure_double_matrix(create_double_matrix(n1, n2)); if (!p) @@ -5236,7 +5431,7 @@ } extern "C" -pure_expr *matrix_from_complex_float_array_dup(void *p, uint32_t n1, uint32_t n2) +pure_expr *matrix_from_complex_float_array(uint32_t n1, uint32_t n2, void *p) { #ifdef HAVE_GSL if (n1 == 0 || n2 == 0) // empty matrix @@ -5274,7 +5469,7 @@ } extern "C" -pure_expr *matrix_from_short_array_dup(void *p, uint32_t n1, uint32_t n2) +pure_expr *matrix_from_short_array(uint32_t n1, uint32_t n2, void *p) { #ifdef HAVE_GSL if (n1 == 0 || n2 == 0) // empty matrix @@ -5310,7 +5505,7 @@ } extern "C" -pure_expr *matrix_from_byte_array_dup(void *p, uint32_t n1, uint32_t n2) +pure_expr *matrix_from_byte_array(uint32_t n1, uint32_t n2, void *p) { #ifdef HAVE_GSL if (n1 == 0 || n2 == 0) // empty matrix @@ -5345,6 +5540,230 @@ #endif } +extern "C" +void *matrix_to_float_array(void *p, pure_expr *x) +{ +#ifdef HAVE_GSL + switch (x->tag) { + case EXPR::CMATRIX: { + gsl_matrix_complex *m1 = (gsl_matrix_complex*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(float)); + if (!p) return 0; + float *q = (float*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + size_t l = 2*(i*m1->tda+j); + q[k++] = (float)m1->data[l]; + q[k++] = (float)m1->data[l+1]; + } + return p; + } + case EXPR::DMATRIX: { + gsl_matrix *m1 = (gsl_matrix*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(n*m*sizeof(float)); + if (!p) return 0; + float *q = (float*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) + q[k++] = (float)m1->data[i*m1->tda+j]; + return p; + } + case EXPR::IMATRIX: { + gsl_matrix_int *m1 = (gsl_matrix_int*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(n*m*sizeof(float)); + if (!p) return 0; + float *q = (float*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) + q[k++] = (float)m1->data[i*m1->tda+j]; + return p; + } + default: + return 0; + } +#else + return 0; +#endif +} + +extern "C" +void *matrix_to_complex_float_array(void *p, pure_expr *x) +{ +#ifdef HAVE_GSL + switch (x->tag) { + case EXPR::CMATRIX: { + gsl_matrix_complex *m1 = (gsl_matrix_complex*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(float)); + if (!p) return 0; + float *q = (float*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + size_t l = 2*(i*m1->tda+j); + q[k++] = (float)m1->data[l]; + q[k++] = (float)m1->data[l+1]; + } + return p; + } + case EXPR::DMATRIX: { + gsl_matrix *m1 = (gsl_matrix*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(float)); + if (!p) return 0; + float *q = (float*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + q[k++] = (float)m1->data[i*m1->tda+j]; + q[k++] = 0.0; + } + return p; + } + case EXPR::IMATRIX: { + gsl_matrix_int *m1 = (gsl_matrix_int*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(float)); + if (!p) return 0; + float *q = (float*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + q[k++] = (float)m1->data[i*m1->tda+j]; + q[k++] = 0.0; + } + return p; + } + default: + return 0; + } +#else + return 0; +#endif +} + +extern "C" +void *matrix_to_short_array(void *p, pure_expr *x) +{ +#ifdef HAVE_GSL + switch (x->tag) { + case EXPR::CMATRIX: { + gsl_matrix_complex *m1 = (gsl_matrix_complex*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(short)); + if (!p) return 0; + short *q = (short*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + size_t l = 2*(i*m1->tda+j); + q[k++] = (short)m1->data[l]; + q[k++] = (short)m1->data[l+1]; + } + return p; + } + case EXPR::DMATRIX: { + gsl_matrix *m1 = (gsl_matrix*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(n*m*sizeof(short)); + if (!p) return 0; + short *q = (short*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) + q[k++] = (short)m1->data[i*m1->tda+j]; + return p; + } + case EXPR::IMATRIX: { + gsl_matrix_int *m1 = (gsl_matrix_int*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(n*m*sizeof(short)); + if (!p) return 0; + short *q = (short*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) + q[k++] = (short)m1->data[i*m1->tda+j]; + return p; + } + default: + return 0; + } +#else + return 0; +#endif +} + +extern "C" +void *matrix_to_byte_array(void *p, pure_expr *x) +{ +#ifdef HAVE_GSL + switch (x->tag) { + case EXPR::CMATRIX: { + gsl_matrix_complex *m1 = (gsl_matrix_complex*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(2*n*m*sizeof(int8_t)); + if (!p) return 0; + int8_t *q = (int8_t*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) { + size_t l = 2*(i*m1->tda+j); + q[k++] = (int8_t)m1->data[l]; + q[k++] = (int8_t)m1->data[l+1]; + } + return p; + } + case EXPR::DMATRIX: { + gsl_matrix *m1 = (gsl_matrix*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(n*m*sizeof(int8_t)); + if (!p) return 0; + int8_t *q = (int8_t*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) + q[k++] = (int8_t)m1->data[i*m1->tda+j]; + return p; + } + case EXPR::IMATRIX: { + gsl_matrix_int *m1 = (gsl_matrix_int*)x->data.mat.p; + size_t n = m1->size1, m = m1->size2; + if (n==0 || m==0) return p; + if (!p) p = malloc(n*m*sizeof(int8_t)); + if (!p) return 0; + int8_t *q = (int8_t*)p; + size_t k = 0; + for (size_t i = 0; i < n; i++) + for (size_t j = 0; j < m; j++) + q[k++] = (int8_t)m1->data[i*m1->tda+j]; + return p; + } + default: + return 0; + } +#else + return 0; +#endif +} + static uint32_t mpz_hash(const mpz_t z) { uint32_t h = 0; Modified: pure/trunk/runtime.h =================================================================== --- pure/trunk/runtime.h 2008-09-27 13:11:09 UTC (rev 883) +++ pure/trunk/runtime.h 2008-09-27 16:03:46 UTC (rev 884) @@ -715,10 +715,7 @@ pure_expr *matrix_transpose(pure_expr *x); -/* Convert between different types of numeric matrices. Note that any numeric - matrix can be converted to a complex matrix, but for the other conversions - the input must be a a double or integer matrix (see matrix_re and matrix_im - below to handle the complex->double case). */ +/* Convert between different types of numeric matrices. */ pure_expr *matrix_double(pure_expr *x); pure_expr *matrix_complex(pure_expr *x); @@ -740,25 +737,42 @@ matrix is still in use. The memory is *not* freed when the matrix is garbage-collected but remains in the ownership of the caller. */ -pure_expr *matrix_from_double_array(void *p, uint32_t n, uint32_t m); -pure_expr *matrix_from_complex_array(void *p, uint32_t n, uint32_t m); -pure_expr *matrix_from_int_array(void *p, uint32_t n, uint32_t m); +pure_expr *matrix_from_double_array_nodup(uint32_t n, uint32_t m, void *p); +pure_expr *matrix_from_complex_array_nodup(uint32_t n, uint32_t m, void *p); +pure_expr *matrix_from_int_array_nodup(uint32_t n, uint32_t m, void *p); /* The following routines work like the above, but copy the data to newly allocated memory, so the original data can be freed after the call. - Additional routines are provided for various alternate data sizes. Moreover, the source pointer p may also be NULL in which case the new matrix is filled with zeros instead. */ -pure_expr *matrix_from_double_array_dup(void *p, uint32_t n, uint32_t m); -pure_expr *matrix_from_complex_array_dup(void *p, uint32_t n, uint32_t m); -pure_expr *matrix_from_int_array_dup(void *p, uint32_t n, uint32_t m); +pure_expr *matrix_from_double_array(uint32_t n, uint32_t m, void *p); +pure_expr *matrix_from_complex_array(uint32_t n, uint32_t m, void *p); +pure_expr *matrix_from_int_array(uint32_t n, uint32_t m, void *p); -pure_expr *matrix_from_float_array_dup(void *p, uint32_t n, uint32_t m); -pure_expr *matrix_from_complex_float_array_dup(void *p, uint32_t n, uint32_t m); -pure_expr *matrix_from_short_array_dup(void *p, uint32_t n, uint32_t m); -pure_expr *matrix_from_byte_array_dup(void *p, uint32_t n, uint32_t m); +/* Copy data from the given matrix to the given data pointer, which is then + returned. If p is NULL then memory of sufficient size is malloc'ed; + otherwise p must point to a memory area of sufficient size. */ +void *matrix_to_double_array(void *p, pure_expr *x); +void *matrix_to_complex_array(void *p, pure_expr *x); +void *matrix_to_int_array(void *p, pure_expr *x); + +/* Additional routines for alternative base types. These work like the + routines above but take data consisting of base types which are not + directly supported by Pure GSL matrices: float, complex float, short, + byte. */ + +pure_expr *matrix_from_float_array(uint32_t n, uint32_t m, void *p); +pure_expr *matrix_from_complex_float_array(uint32_t n, uint32_t m, void *p); +pure_expr *matrix_from_short_array(uint32_t n, uint32_t m, void *p); +pure_expr *matrix_from_byte_array(uint32_t n, uint32_t m, void *p); + +void *matrix_to_float_array(void *p, pure_expr *x); +void *matrix_to_complex_float_array(void *p, pure_expr *x); +void *matrix_to_short_array(void *p, pure_expr *x); +void *matrix_to_byte_array(void *p, pure_expr *x); + /* Compute a 32 bit hash code of a Pure expression. This makes it possible to use arbitary Pure values as keys in a hash table. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-27 13:11:11
|
Revision: 883 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=883&view=rev Author: agraef Date: 2008-09-27 13:11:09 +0000 (Sat, 27 Sep 2008) Log Message: ----------- Update logs. Modified Paths: -------------- pure/trunk/test/prelude.log Modified: pure/trunk/test/prelude.log =================================================================== --- pure/trunk/test/prelude.log 2008-09-27 11:35:58 UTC (rev 882) +++ pure/trunk/test/prelude.log 2008-09-27 13:11:09 UTC (rev 883) @@ -1183,28 +1183,8 @@ state 8: #1 } end; cat [] = []; -cat xs@(_/*0:101*/:_/*0:11*/) = foldr ((+/*0*/)) [] xs/*0:1*/ with []+ys/*0:1*/ = ys/*0:1*/; xs@(_/*0:0101*/:_/*0:011*/)+ys/*0:1*/ = tick/*1*/ [] xs/*0:01*/ ys/*0:1*/ { - rule #0: []+ys = ys - rule #1: xs@(_:_)+ys = tick [] xs ys - state 0: #0 #1 - [] state 1 - <app> state 3 - state 1: #0 - <var> state 2 - state 2: #0 - state 3: #1 - <app> state 4 - state 4: #1 - : state 5 - state 5: #1 - <var> state 6 - state 6: #1 - <var> state 7 - state 7: #1 - <var> state 8 - state 8: #1 -}; tick zs/*0:001*/ (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ (x/*0:0101*/:zs/*0:001*/) (xs/*1:011*/+/*2*/ys/*1:1*/&) if thunkp xs/*0:011*/; tick zs/*0:001*/ (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tick/*1*/ (x/*0:0101*/:zs/*0:001*/) xs/*0:011*/ ys/*0:1*/; tick zs/*0:001*/ [] ys/*0:1*/ = tack/*1*/ zs/*0:001*/ ys/*0:1*/; tick zs/*0:001*/ xs/*0:01*/ ys/*0:1*/ = tack/*1*/ zs/*0:001*/ (xs/*0:01*/+/*1*/ys/*0:1*/) { - rule #0: tick zs (x:xs) ys = tack (x:zs) (xs+ys&) if thunkp xs +cat xs@(_/*0:101*/:_/*0:11*/) = foldr (tick/*0*/ []) [] xs/*0:1*/ with tick zs/*0:001*/ (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tack/*1*/ (x/*0:0101*/:zs/*0:001*/) (tick/*2*/ [] xs/*1:011*/ ys/*1:1*/&) if thunkp xs/*0:011*/; tick zs/*0:001*/ (x/*0:0101*/:xs/*0:011*/) ys/*0:1*/ = tick/*1*/ (x/*0:0101*/:zs/*0:001*/) xs/*0:011*/ ys/*0:1*/; tick zs/*0:001*/ [] ys/*0:1*/ = tack/*1*/ zs/*0:001*/ ys/*0:1*/; tick zs/*0:001*/ xs/*0:01*/ ys/*0:1*/ = tack/*1*/ zs/*0:001*/ (xs/*0:01*/+ys/*0:1*/) { + rule #0: tick zs (x:xs) ys = tack (x:zs) (tick [] xs ys&) if thunkp xs rule #1: tick zs (x:xs) ys = tick (x:zs) xs ys rule #2: tick zs [] ys = tack zs ys rule #3: tick zs xs ys = tack zs (xs+ys) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-27 11:36:02
|
Revision: 882 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=882&view=rev Author: agraef Date: 2008-09-27 11:35:58 +0000 (Sat, 27 Sep 2008) Log Message: ----------- Initial import. Added Paths: ----------- pure-csv/ pure-csv/branches/ pure-csv/releases/ pure-csv/trunk/ pure-csv/trunk/COPYING pure-csv/trunk/Makefile pure-csv/trunk/README pure-csv/trunk/csv.c pure-csv/trunk/csv.pure pure-csv/trunk/examples/ pure-csv/trunk/examples/read-sample1.csv pure-csv/trunk/examples/read-sample2.csv pure-csv/trunk/examples/read-sample3.csv pure-csv/trunk/examples/read-sample4.csv pure-csv/trunk/examples/read-sample5.csv pure-csv/trunk/examples/read-samples.pure pure-csv/trunk/examples/write-sample1.csv pure-csv/trunk/examples/write-sample2.csv pure-csv/trunk/examples/write-sample3.csv pure-csv/trunk/examples/write-sample4.csv pure-csv/trunk/examples/write-samples.pure Added: pure-csv/trunk/COPYING =================================================================== --- pure-csv/trunk/COPYING (rev 0) +++ pure-csv/trunk/COPYING 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. Added: pure-csv/trunk/Makefile =================================================================== --- pure-csv/trunk/Makefile (rev 0) +++ pure-csv/trunk/Makefile 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,41 @@ + +# Package name and version number: +dist = pure-csv-$(version) +version = 0.1 + +# Try to guess the installation prefix (this needs GNU make): +prefix = $(patsubst %/bin/pure,%,$(shell which pure 2>/dev/null)) +ifeq ($(strip $(prefix)),) +# Fall back to /usr/local. +prefix = /usr/local +endif + +# Platform-specific stuff, edit this as needed. +#PIC = -fPIC # uncomment for x86-64 compilation +DLL = .so # .dll on Windows + +DISTFILES = COPYING Makefile README examples/*.pure examples/*.csv \ +csv.c csv.pure + +all: csv$(DLL) + +csv$(DLL): csv.c + gcc -shared -o $@ $< $(PIC) -lpure + +clean: + rm -f *$(DLL) *~ *.a *.o + +install: + test -d "$(DESTDIR)$(prefix)/lib/pure" || mkdir -p "$(DESTDIR)$(prefix)/lib/pure" + cp csv.pure csv$(DLL) "$(DESTDIR)$(prefix)/lib/pure" + +uninstall: + rm -f "$(DESTDIR)$(prefix)/lib/pure/csv.pure" "$(DESTDIR)$(prefix)/lib/pure/csv$(DLL)" + +dist: + rm -rf $(dist) + mkdir $(dist) && mkdir $(dist)/examples + for x in $(DISTFILES); do ln -sf $$PWD/$$x $(dist)/$$x; done + rm -f $(dist).tar.gz + tar cfzh $(dist).tar.gz $(dist) + rm -rf $(dist) Added: pure-csv/trunk/README =================================================================== --- pure-csv/trunk/README (rev 0) +++ pure-csv/trunk/README 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,89 @@ + +PURE-CSV - Comma Separated Value interface for the Pure programming language +======== = ===== ========= ===== ========= === === ==== =========== ======== + +The CSV library provides an interface to read and write comma separated value +files. The reading and writing functions are loosely based on Python's CSV +module (http://docs.python.org/lib/module-csv.html) + +INSTALLATION + +Run 'make' to compile the module and 'make install' (as root) to install it in +the Pure library directory. This requires GNU make. + +The 'make install' step is only necessary for system-wide installation. 'make' +will try to guess your Pure installation directory, if it gets it wrong, you +can specify the installation prefix as follows: 'make install prefix=/usr'. +Make sure that you get this right, otherwise the Pure interpreter won't be +able to find the installed module. + +USAGE + +Data records are represented as lists of strings and numeric data. Dialects +are created using csv_dialect with a list of specifications outlined in +csv.pure. + +- csv_list (s::string, dialect) + csv_list s::string + + Converts a CSV formatted string s to a list of fields according to the + dialect specified. If no dialect is specified, conversion is performed using + RFC 4180 rules (http://www.ietf.org/rfc/rfc4180.txt). Invalidly formatted + CSV causes return of a 'csv_error msg' term (see NOTES below). + +- csv_str (x:xs) + csv_str ((x:xs), dialect) + + Converts a list of fields, which includes only strings, integers, and + doubles to a CSV formatted string according to the dialect specified. If + no dialect is specified, conversion is performed using RFC 4180 rules + (http://www.ietf.org/rfc/rfc4180.txt). Lists that are not strings, integers, + or floats invoke a 'csv_error msg' term (see NOTES below). + +- csv_fgets (f::pointer, dialect) + csv_fgets f::pointer + + Is equivalent to csv_list except that reading is from file f. + +- csv_fputs ((x:xs), dialect, f) + csv_fputs ((x:xs), f) + + Is equivalent to csv_str except that writing is to file f. + +- csv_fget (name::string, dialect) + csv_fget name::string + + Reads a named file and returns a list of records. These procedures should + only be used on data files that are small enough to fit in the computers + RAM. + +- csv_fput (name::string, recs, dialect) + csv_fput (name::string, recs) + + Writes list of records to a named file. Each record is converted according + to the rules stated in the csv_str procedure. + +NOTES + +- Errors in the conversion routines (input that does not abide by the + dialect rules; records containing field types other than strings, integers + and floats) cause a special 'csv_error msg' term to be returned, where msg + is a string describing the particular error. To handle error conditions, + your application should either check for these, or define csv_error to + directly handle the error in some way (e.g., provide a default value, or + raise an exception). For instance: + + csv_error msg = throw msg; + +- MS Excel files should be written using "=""0004""" if leading 0s are + significant. Use the same technique if leading space is significant. Use this + quirk only if written files are going to be imported to MS Excel. + +EXAMPLES + +Examples are provided in the examples subdirectory. See "readsamples.pure" for +reading csv files and "writesamples.pure" for writing. + +September 24, 2008 +Eddie Rucker +er...@bm... Added: pure-csv/trunk/csv.c =================================================================== --- pure-csv/trunk/csv.c (rev 0) +++ pure-csv/trunk/csv.c 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,452 @@ +/* Port of CSV module from Q to Pure + + Author: Eddie Rucker + Date: July 3, 2008 +*/ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <pure/runtime.h> + +#define STRSIZE 128 +#define BUFSIZE 1024 + +#define QUOTE_ALL 0 +#define QUOTE_STRINGS 1 +#define QUOTE_EMBEDDED 2 + +#define error_handler(msg) \ + return pure_app(pure_symbol(pure_sym("csv_error")), pure_cstring_dup(msg)) + +/* Return a CSV record as a Pure string. + Input: + fp: File pointer to read from + quote: Pure string representing CSV quotes + + Output: + pure_string representing a CSV record. The string may have embedded '\n's. + Does not check for badly formated records. + + Exceptions: + csv_error msg is invoked f there is a system memory allocation error, + beyond end of file, or a file error is encountered. +*/ +pure_expr *c_csv_fgets(FILE *fp, char *quote) { + char *bf, *tb, *s; + int quote_count = 0, n_quote; + long sz = BUFSIZE, n = 0; + pure_expr *ret; + + if (!(s = bf = (char *)malloc(sz))) { + error_handler("malloc error"); + } + + n_quote = strlen(quote); + while (1) { + s = bf + n; + if (n > sz) { + if (!(tb = realloc(bf, sz <<= 1))) { + free(bf); + error_handler("realloc error"); + } + s = (bf = tb) + n; + } + tb = fgets(s, BUFSIZE, fp); + if (ferror(fp)) { + free(bf); + return 0; + } + if (tb == NULL) { + if (n == 0) + return NULL; + else + return pure_cstring(bf); + } + n += strlen(s); + if (*(bf+n-1) != '\n') + continue; + while (*s) { + if (!strncmp(s, quote, n_quote)) { + ++quote_count; + s += n_quote; + } else + ++s; + } + if (!(quote_count & 1)) + /* let pure handle freeing bf */ + return pure_cstring(bf); + } +} + +/* Convert a string to a number. + Input: + s: string to be converted. + cvt_flag: 0 -> no conversion, 1 -> attempt conversion + + Output: + Pure int, Pure double, or Pure string depending on cvt_flag=1 and + s obeys strtol and strtod specs. +*/ +pure_expr *convert_string(char *s, int cvt_flag) { + long i; + double d; + char *p; + + if (cvt_flag) { + i = strtol(s, &p, 0); + if (*p == 0) + return pure_int(i); + d = strtod(s, &p); + if (*p == 0) + return pure_double(d); + } + return pure_cstring_dup(s); +} + +#define putfld(len) \ + if (n_fld + len >= fld_sz) { \ + if (!(tfld = (char *)realloc(fld, fld_sz <<= 1))) \ + goto done; \ + fld = tfld; \ + } \ + fldp = fld + n_fld; \ + strncpy(fldp, s, len); \ + n_fld += len \ + + +#define putrec(qt) \ + *(fldp + 1) = 0; \ + if (n_rec >= rec_sz - 1) { \ + if (!(trec = (pure_expr **)realloc(rec, (rec_sz+=64)*sizeof(pure_expr)))) \ + goto done; \ + rec = trec; \ + } \ + rec[n_rec++] = convert_string(fld, qt) + +#define free_params \ + free(delimiter); \ + free(escape); \ + free(quote); \ + free(lineterm); \ + free(elems) + +/* Convert a CSV string to a list of fields + input: + dialect: (Conversion flag, field delimeter char, string delimeter char) + s: CSV formatted string + + Output: record of fields + + Exceptions: + Invokes 'csv_error MSG' if the string is badly formatted, or memory error + + Notes: + \r char is treated as white space except inside "" +*/ +pure_expr *c_csvstr_to_list(char *s, pure_expr *dialect) { + size_t n_elems; + pure_expr **elems, **rec, **trec; + int n, st = 0, fld_sz = 256, n_fld, rec_sz = 64, n_ws = 0, n_rec = 0, + n_delimiter, n_escape, n_quote, n_lineterm, skipspace_f, esc_eq_quote, + quoting_style; + char *fld, *tfld, *fldp, errmsg[80], *delimiter, *escape, *quote, *lineterm; + + if (!(pure_is_listv(dialect, &n_elems, &elems) + && n_elems == 6 + && pure_is_cstring_dup(elems[0], &delimiter) + && pure_is_cstring_dup(elems[1], &escape) + && pure_is_cstring_dup(elems[2], "e) + && pure_is_int(elems[3], "ing_style) + && pure_is_cstring_dup(elems[4], &lineterm) + && pure_is_int(elems[5], &skipspace_f))) + return 0; + + if (!(fld = (char *)malloc(fld_sz))) { + free_params; + error_handler("malloc error"); + } + + if (!(rec = (pure_expr **)malloc(rec_sz*sizeof(pure_expr)))) { + free(fld); + free_params; + error_handler("malloc error"); + } + n_delimiter = strlen(delimiter); + n_escape = strlen(escape); + n_quote = strlen(quote); + esc_eq_quote = !strcmp(escape, quote); + n_lineterm = strlen(lineterm); + fldp = fld; + while (st < 10) { + switch (st) { + case 0: + fldp = fld; + *fldp = 0; + n_fld = 0; + if (!strncmp(s, delimiter, n_delimiter)) { + putrec(QUOTE_ALL); + s += n_delimiter; + } else if (!strncmp(s, quote, n_quote)) { + s += n_quote; + st = 1; + } else if (!*s || *s == EOF || !strncmp(s, lineterm, n_lineterm)) { + putrec(QUOTE_ALL); + st = 10; + } else if (isspace(*s) && skipspace_f) { + ++s; + } else if (!strncmp(s, escape, n_escape)) { + sprintf(errmsg, "column %d: unexpected escape.", n_fld+1); + st = 20; + } else { + putfld(1); + ++s; + st = 4; + } + break; + case 1: + if (!strncmp(s, quote, n_quote)) { + s += n_quote; + st = 2; + } else if (!*s || *s == EOF) { + sprintf(errmsg, "column %d: expected {%s}.", + n_fld+1, quote); + st = 20; + } else if (!strncmp(s, escape, n_escape)) { + s += n_escape; + putfld(n_escape); + ++s; + } else { + putfld(1); + ++s; + } + break; + case 2: + if (!strncmp(s, quote, n_quote) && esc_eq_quote) { + putfld(n_quote); + s += n_quote; + st = 1; + } else if (!strncmp(s, delimiter, n_delimiter)) { + putrec(QUOTE_ALL); + s += n_delimiter; + st = 0; + } else if (!*s || *s == EOF || !strncmp(s, lineterm, n_lineterm)) { + putrec(QUOTE_ALL); + st = 10; + } else if (isspace(*s)) { + ++s; + st = 3; + } else { + sprintf(errmsg, "column %d: expected {%s}.", + n_fld+1, delimiter); + st = 20; + } + break; + case 3: + if (!strncmp(s, delimiter, n_delimiter)) { + putrec(QUOTE_ALL); + s += n_delimiter; + st = 0; + } else if (!*s || *s == '\n' || *s == EOF) { + putrec(QUOTE_ALL); + st = 10; + } else if (isspace(*s)) { + ++s; + } else { + sprintf(errmsg, "column %d: expected {%s}.", + n_fld+1, delimiter); + st = 20; + } + break; + case 4: + if (!strncmp(s, quote, n_quote) || !strncmp(s, escape, n_escape)) { + sprintf(errmsg, "column %d: expected {%s}.", + n_fld+1, delimiter); + st = 20; + } else if (!strncmp(s, delimiter, n_delimiter)) { + fldp -= n_ws; + n_fld -= n_ws; + putrec(quoting_style); + s += n_delimiter; + st = 0; + } else if (!*s || *s == EOF || !strncmp(s, lineterm, n_lineterm)) { + putrec(quoting_style); + st = 10; + } else if (isspace(*s)) { + n_ws = n_ws ? n_ws+1 : 1; + putfld(1); + ++s; + } else { + n_ws = 0; + putfld(1); + ++s; + } + break; + } + } + done: + free(fld); + free_params; + if (st == 10) + return pure_listv(n_rec, realloc(rec, sizeof(pure_expr)*n_rec)); + else { + for (n = 0; n < n_rec; ++n) + pure_free(rec[n]); + free(rec); + if (st==20) + error_handler(errmsg); + error_handler("malloc error"); + + } +} + +#define resize_str \ + if (len > sz) { \ + if (!(ts = (char *)realloc(s, sz <<= 1))) { \ + free(s); \ + error_handler("realloc error"); \ + } \ + s = ts; \ + } \ + t = s + mrk + + +#define insert \ + mrk = len; \ + len += strlen(tb); \ + resize_str; \ + strncpy(t, tb, len - mrk) + +/* Convert list to a CSV formated string + Input: + dialect: (Conversion flag, field delimeter char, string delimeter char) + list: record to be converted + + Output: CSV formatted string + + Exceptions: + Invokes csv_error if no more memory is available or if field cannot be + converted. + + Notes: + \r char is treated as white space except inside "" +*/ +pure_expr *c_list_to_csvstr(pure_expr *list, pure_expr *dialect) { + size_t n_elems; + int i, n, k, sz = 256, mrk, quote_cnt, delim_cnt, lineterm_cnt, len = 0, + skipspace_f, n_escape, n_quote, n_delimiter, n_lineterm, quoting_style, + ival; + char *s, *ts, *p, *sval, tb[48], errmsg[80], *escape, *quote, *delimiter, + *lineterm; + double dval; + pure_expr **elems, **xs; + register char *t; + + if (!(pure_is_listv(dialect, &n_elems, &elems) + && n_elems == 6 + && pure_is_string_dup(elems[0], &delimiter) + && pure_is_string_dup(elems[1], &escape) + && pure_is_string_dup(elems[2], "e) + && pure_is_int(elems[3], "ing_style) + && pure_is_string_dup(elems[4], &lineterm) + && pure_is_int(elems[5], &skipspace_f) + && pure_is_listv(list, &n_elems, &xs))) { + return 0; + } + + if (!(s = (char *)malloc(sz))) { + free_params; + error_handler("malloc error"); + } + + n_escape = strlen(escape); + n_quote = strlen(quote); + n_delimiter = strlen(delimiter); + n_lineterm = strlen(lineterm); + for (i = 0; i < n_elems; ++i) { + if (pure_is_int(xs[i], &ival)) { + if (!quoting_style) + sprintf(tb, "%s%d%s%s", quote, ival, quote, delimiter); + else + sprintf(tb, "%d%s", ival, delimiter); + insert; + } else if (pure_is_double(xs[i], &dval)) { + if (!quoting_style) + sprintf(tb, "%s%.16g%s%s", quote, dval, quote, delimiter); + else + sprintf(tb, "%.16g%s", dval, delimiter); + insert; + } else if (pure_is_cstring_dup(xs[i], &sval)) { + quote_cnt = 0; + delim_cnt = 0; + lineterm_cnt = 0; + p = sval; + if (skipspace_f && quoting_style == QUOTE_EMBEDDED) + while (isspace(*p) + && strncmp(p, quote, n_delimiter) + && strncmp(p, delimiter, n_delimiter) + && strncmp(p, lineterm, n_lineterm)) + ++p; + k = p - sval; + mrk = len; + while (*p) { + if (!strncmp(p, quote, n_quote)) { + ++quote_cnt; + p += n_quote; + len += n_escape + n_quote; + } else if (!strncmp(p, delimiter, n_delimiter)) { + ++delim_cnt; + p += n_delimiter; + len += n_delimiter; + } else if (!strncmp(p, lineterm, n_lineterm)) { + ++lineterm_cnt; + p += n_lineterm; + len += n_lineterm; + } else { + ++len; + ++p; + } + } + len += n_delimiter; + p = sval + k; + if (quoting_style == QUOTE_EMBEDDED + && !(quote_cnt+delim_cnt+lineterm_cnt)) { + resize_str; + k = len - mrk - 1; + strncpy(t, p, k); + t += k; + } else { + /* Add space for surrounding quotes */ + len += n_quote << 1; + resize_str; + strncpy(t, quote, n_quote); + t += n_quote; + while (*p) { + if (!strncmp(p, quote, n_quote)) { + strncpy(t, escape, n_escape); + t += n_escape; + strncpy(t, quote, n_quote); + t += n_quote; + p += n_quote; + } else + *t++ = *p++; + } + strncpy(t, quote, n_quote); + t += n_quote; + } + strncpy(t, delimiter, n_delimiter); + t += n_delimiter; + } else { + sprintf(errmsg, "field %d: invalid conversion type.", + i+1); + free_params; + error_handler(errmsg); + } + } + mrk = (len -= n_delimiter); /* write over last delimiter */ + len += n_lineterm; + resize_str; + strcpy(t, lineterm); + free_params; + return pure_cstring((char *)realloc(s, len+1)); +} Added: pure-csv/trunk/csv.pure =================================================================== --- pure-csv/trunk/csv.pure (rev 0) +++ pure-csv/trunk/csv.pure 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,178 @@ +/* This file is part of the Pure programming system. + + The Pure programming system is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) any + later version. + + The Pure programming system is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* The CSV library provides an interface to read and write comma separated + value files. The reading and writing functions are loosely based on + Python's csv module (http://docs.python.org/lib/module-csv.html) + + Author: Robert E. Rucker + Email: er...@bm... + Date: July 15, 2008 +*/ + +using "lib:csv"; +using system; + +/* User may define csv_error for custom error handling. */ +csv_error msg; + +private c_csv_fgets c_csvstr_to_list c_list_to_csvstr; + +/* Read a string with embedded '\n's within quotes. No error checking! */ +extern expr *c_csv_fgets(FILE *fp, char *quote); + +/* Convert a CSV string to a list (record). + s: CSV formated string to be converted to a list of fields. + Dialect: CSV format specification. If none is given, defaults to + RFC4180 for Windows and UNIX for all other OSs. + NOTE: Rec must contain ONLY strings, integers, and floating point numbers. + If a field is some other type, the 'csv_error MSG' rule is invoked. +*/ +extern expr *c_csvstr_to_list(char *str, expr *dialect); + +/* Convert a list (record) to a CSV string. + Rec: list of fields to be converted to CSV format. + Dialect: CSV format specification. If none is given, defaults to + RFC4180 for Windows and UNIX for all other OSs. + NOTE: Rec must contain ONLY strings, integers, and floating point numbers. + If a field is some other type, the 'csv_error MSG' rule is invoked. +*/ +extern expr *c_list_to_csvstr(expr *list, expr *dialect); + +/* Public dialect Options +CSV_DELIMITER: Field delimiter. Defaults to ",". + +CSV_ESCAPE: Embedded escape character. Defaults to "\"". + Reading: The escape character is dropped and + the next char is inserted into the field. + Writing: The escape character is written into the + output stream. + +CSV_QUOTE: Quote character. Defaults to "\"". + Note: If embedded quotes are doubled, csv_escape must equal + csv_quote. The csv_dialect function will + automatically set the csv_escape character to + csv_quote if csv_escape is not specified. + +CSV_QUOTING_STYLE: Quoting options: Defaults to csv_quote_strings. + See QuoteStyle constants below. + +CSV_LINETERMINATOR: Record terminator. Defaults to "\r\n". + +CSV_SKIPSPACE: Skip white space flag. Defaults to true. + Reading/Writing: If true, white spaces before fields are + removed. Quoted fields always retain + white space. +*/ +const CSV_QUOTE_ALL = 0; +const CSV_QUOTE_STRINGS = 1; +const CSV_QUOTE_EMBEDDED = 2; + +const CSV_DELIMITER = 0; +const CSV_ESCAPE = 1; +const CSV_QUOTE = 2; +const CSV_QUOTING_STYLE = 3; +const CSV_LINETERMINATOR = 4; +const CSV_SKIPSPACE = 5; + +/* Defaults are set to RFC 4180 (http://www.ietf.org/rfc/rfc4180.txt) except + for the \r\n pair */ +let csv_defaults = [",", "\"", "\"", 1, "\n", 1]; + +/* Create a dialect base on the list of dialect options given above. + See RFC4180 and EXCEL constants below for example usage. +*/ +csv_dialect opts + = zipwith ((lookup) opts2) (0..5) csv_defaults + when + opts2 = if any (\(x=>y) -> x==CSV_ESCAPE) opts then + opts + else + opts + [CSV_ESCAPE=>(lookup opts CSV_QUOTE "\"")]; + end + with + lookup [] k::int v = v; + lookup ((x=>y):xs) k::int _ = y if k == x; + lookup ((x=>y):xs) k::int v = lookup xs k v; + end; + +const CSV_RFC4180 = csv_dialect [CSV_LINETERMINATOR => "\r\n"]; +const CSV_UNIX = csv_defaults; +const CSV_EXCEL = csv_dialect [CSV_QUOTING_STYLE => CSV_QUOTE_EMBEDDED]; +const CSV_DEFAULTS + = if (substr sysinfo 0 5) == "mingw" then + CSV_RFC4180 + else + CSV_UNIX; + +/* List to CSV string conversion functions */ + csv_str rec@[] +| csv_str rec@(_:_) + = c_list_to_csvstr rec CSV_DEFAULTS; + + csv_str (rec@[], dialect@(_:_)) +| csv_str (rec@(_:_), dialect @(_:_)) + = c_list_to_csvstr rec dialect; + +/* File writing functions */ + csv_fputs (rec@[], f::pointer) +| csv_fputs (rec@(_:_), f::pointer) + = fputs (c_list_to_csvstr rec CSV_DEFAULTS) f; + + csv_fputs (rec@[], dialect@(_:_), f::pointer) +| csv_fputs (rec@(_:_), dialect@(_:_), f::pointer) + = fputs (c_list_to_csvstr rec dialect) f; + +/* CSV string to list converstion functions */ +csv_list s::string + = c_csvstr_to_list s CSV_DEFAULTS; +csv_list (s::string, dialect@(_:_)) + = c_csvstr_to_list s dialect; + +/* File reading functions */ +csv_fgets f::pointer + = c_csvstr_to_list (c_csv_fgets f (CSV_DEFAULTS!CSV_QUOTE)) CSV_DEFAULTS; +csv_fgets (f::pointer, dialect@(_:_)) + = c_csvstr_to_list (c_csv_fgets f (dialect!CSV_QUOTE)) dialect; + +/* Read a whole file at one time */ +csv_fget (name::string, dialect@(_:_)) + = read (csv_fgets (f, dialect)) [] + with + read s acc = fclose f $$ reverse acc if feof f; + read s acc = read (csv_fgets (f, dialect)) (s:acc); + end + when + f = fopen name "r"; + end; + +csv_fget name::string + = csv_fget (name, CSV_DEFAULTS); + +/* Write a whole file at one time */ +csv_fput (name::string, recs, dialect@(_:_)) + = write recs f + with + write [] f = fclose f $$ (); + write (x:xs) f = csv_fputs (x, dialect, f) $$ write xs f; + end + when + f = fopen name "w"; + end; + +csv_fput (name::string, recs) + = csv_fput (name, recs, CSV_DEFAULTS); Added: pure-csv/trunk/examples/read-sample1.csv =================================================================== --- pure-csv/trunk/examples/read-sample1.csv (rev 0) +++ pure-csv/trunk/examples/read-sample1.csv 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,7 @@ +,,4,"0004" +"embedded +new +lines", "4", 0.1, "----" +"this, has an embedded ," ,, 3.2, "0000" +"embedded ""quotes""", "-10", 0 , " " +, , , 2.3e-4 , 54-23 \ No newline at end of file Added: pure-csv/trunk/examples/read-sample2.csv =================================================================== --- pure-csv/trunk/examples/read-sample2.csv (rev 0) +++ pure-csv/trunk/examples/read-sample2.csv 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,4 @@ + 4 "0004" +"this has an embedded tab" 3.2 "0000" +" this""quotes""" "-10, 0" " " + 2.3e-4 54-23 \ No newline at end of file Added: pure-csv/trunk/examples/read-sample3.csv =================================================================== --- pure-csv/trunk/examples/read-sample3.csv (rev 0) +++ pure-csv/trunk/examples/read-sample3.csv 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,4 @@ + 4 '0004' +'this has an embedded tab' 3.2 '0000' +'embedded ''quotes''' '-10' 0 ' ' + 2.3e-4 54-23 \ No newline at end of file Added: pure-csv/trunk/examples/read-sample4.csv =================================================================== --- pure-csv/trunk/examples/read-sample4.csv (rev 0) +++ pure-csv/trunk/examples/read-sample4.csv 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,4 @@ +,,4,"0004" +"%"a,b%"", 3.2, "0000" +"a","b","%"%"",9 +4,3,,,-9.4 Added: pure-csv/trunk/examples/read-sample5.csv =================================================================== --- pure-csv/trunk/examples/read-sample5.csv (rev 0) +++ pure-csv/trunk/examples/read-sample5.csv 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,4 @@ +,,4,"0004" +"this, has an embedded ," ,, 3.2, "0000" +embedded ""quotes"", "-10", 0 , " " +," , , 2.3e-4 , "54-23 Added: pure-csv/trunk/examples/read-samples.pure =================================================================== --- pure-csv/trunk/examples/read-samples.pure (rev 0) +++ pure-csv/trunk/examples/read-samples.pure 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,27 @@ +#!/usr/local/bin/pure -x + +using csv; +using system; + +/* Define a few dialects */ +const QUOTE_ALL = csv_dialect [CSV_QUOTING_STYLE=>CSV_QUOTE_ALL]; +const TAB_DELIM = csv_dialect [CSV_DELIMITER=>"\t"]; +const TAB_DELIM_SINGLE_QUOTE = csv_dialect [CSV_DELIMITER=>"\t", CSV_QUOTE=>"'"]; +const ESC_QUOTES = csv_dialect [CSV_ESCAPE=>"%"]; + +main + = puts "Reading 'read-sample1.csv' (standard CSV)" $$ + puts (str $ csv_fget "read-sample1.csv") $$ + puts "\nReading 'read-sample1.csv' (standard CSV, no conversions)" $$ + puts (str $ csv_fget ("read-sample1.csv", QUOTE_ALL)) $$ + puts "\nReading 'read-sample2.csv' (tab delimitied)" $$ + puts (str $ csv_fget ("read-sample2.csv", TAB_DELIM)) $$ + puts "\nReading 'read-sample3.csv' (tab delimited, single quoted)" $$ + puts (str $ csv_fget ("read-sample3.csv", TAB_DELIM_SINGLE_QUOTE)) $$ + puts "\nReading 'read-sample4.csv' (escaped quotes)" $$ + puts (str $ csv_fget ("read-sample4.csv", ESC_QUOTES)) $$ + puts "\nReading 'read-sample5.csv' (Malformed)" $$ + puts (str $ csv_fget ("read-sample5.csv", CSV_DEFAULTS)) $$ + puts "\ndone." $$ (); + +main; Property changes on: pure-csv/trunk/examples/read-samples.pure ___________________________________________________________________ Added: svn:executable + * Added: pure-csv/trunk/examples/write-sample1.csv =================================================================== --- pure-csv/trunk/examples/write-sample1.csv (rev 0) +++ pure-csv/trunk/examples/write-sample1.csv 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,3 @@ +"this"," that ","23","-3","" +"a ""b""","c c","10","3.2"," " +"a, b","","0","0","00" Added: pure-csv/trunk/examples/write-sample2.csv =================================================================== --- pure-csv/trunk/examples/write-sample2.csv (rev 0) +++ pure-csv/trunk/examples/write-sample2.csv 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,3 @@ +"this y" " that " 23 -3 "" +"a ""b""" "c c" 10 3.2 " " +"a, b" "" 0 0 "00" Added: pure-csv/trunk/examples/write-sample3.csv =================================================================== --- pure-csv/trunk/examples/write-sample3.csv (rev 0) +++ pure-csv/trunk/examples/write-sample3.csv 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,3 @@ +'this y' ' that ' 23 -3 '' +'a ''b''' 'c c' 10 3.2 ' ' +'a, b' '' 0 0 '00' Added: pure-csv/trunk/examples/write-sample4.csv =================================================================== --- pure-csv/trunk/examples/write-sample4.csv (rev 0) +++ pure-csv/trunk/examples/write-sample4.csv 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,3 @@ +"this"," that ",23,-3,"" +"a %"b%"","c c",10,3.2," " +"a, b","",0,0,"00" Added: pure-csv/trunk/examples/write-samples.pure =================================================================== --- pure-csv/trunk/examples/write-samples.pure (rev 0) +++ pure-csv/trunk/examples/write-samples.pure 2008-09-27 11:35:58 UTC (rev 882) @@ -0,0 +1,44 @@ +#!/usr/local/bin/pure -x + +/* To run: + At the command line> pure -i writesamples.pure + At the prompt ==> main; + Using your favorite editor open the write samples to see what was wrought. +*/ + +using csv; +using system; + +/* Define a few dialects */ +const QUOTE_ALL = csv_dialect [CSV_QUOTING_STYLE=>CSV_QUOTE_ALL]; +const TAB_DELIM = csv_dialect [CSV_DELIMITER=>"\t"]; +const TAB_DELIM_SINGLE_QUOTE = csv_dialect [CSV_DELIMITER=>"\t", CSV_QUOTE=>"'"]; +const ESC_QUOTES = csv_dialect [CSV_ESCAPE=>"%"]; + +/* Define a few sample data lists */ +let sample1 = [["this", " that ", 23, -3.0, ""], + ["a \"b\"", "c c", 10, 3.2, " "], + ["a, b", "", 0, 0.0, "00"]]; + +let sample2 = [["this\ty", " that ", 23, -3.0, ""], + ["a \"b\"", "c c", 10, 3.2, " "], + ["a, b", "", 0, 0.0, "00"]]; + +let sample3 = [["this\ty", " that ", 23, -3.0, ""], + ["a 'b'", "c c", 10, 3.2, " "], + ["a, b", "", 0, 0.0, "00"]]; + +main + = puts "Writing 'write-sample1.csv' (standard CSV)" $$ + puts (str $ csv_fput ("write-sample1.csv", sample1)) $$ + puts "\nWriting 'write-sample1.csv' (standard CSV, no conversions)" $$ + puts (str $ csv_fput ("write-sample1.csv", sample1, QUOTE_ALL)) $$ + puts "\nWriting 'write-sample2.csv' (tab delimitied)" $$ + puts (str $ csv_fput ("write-sample2.csv", sample2, TAB_DELIM)) $$ + puts "\nWriting 'write-sample3.csv' (tab delimited, single quoted)" $$ + puts (str $ csv_fput ("write-sample3.csv", sample3, TAB_DELIM_SINGLE_QUOTE)) $$ + puts "\nWriting 'write-sample4.csv' (escaped quotes)" $$ + puts (str $ csv_fput ("write-sample4.csv", sample1, ESC_QUOTES)) $$ + puts "\ndone." $$ (); + +main; Property changes on: pure-csv/trunk/examples/write-samples.pure ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-27 05:35:51
|
Revision: 881 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=881&view=rev Author: agraef Date: 2008-09-27 05:35:40 +0000 (Sat, 27 Sep 2008) Log Message: ----------- Fix some minor glitches in the documentation. Modified Paths: -------------- pure/trunk/pure.1.in Modified: pure/trunk/pure.1.in =================================================================== --- pure/trunk/pure.1.in 2008-09-27 04:57:33 UTC (rev 880) +++ pure/trunk/pure.1.in 2008-09-27 05:35:40 UTC (rev 881) @@ -416,7 +416,9 @@ ``conses'', and `,' produces ``pairs''. As indicated, Pure provides the usual syntactic sugar for list values in brackets, such as [x,y,z], which is exactly the same as x:y:z:[]. Moreover, the prelude also provides an infix `..' -operator to denote arithmetic sequences such as 1..10 or 1.0,1.2..3.0. +operator to denote arithmetic sequences such as 1..10. Sequences with +arbitrary stepsizes can be written by denoting the first two sequence +elements using the `:' operator, as in 1.0:1.2..3.0. .sp Pure's tuples are a bit unusual: They are constructed by just ``pairing'' things using the `,' operator, for which the empty tuple acts as a neutral @@ -914,7 +916,7 @@ .nf primes n = sieve (2..n) \fBwith\fP sieve [] = []; - sieve (p:qs) = p : sieve [q; q = qs; q mod p]; + sieve (p:qs) = p : sieve [q | q = qs; q mod p]; \fBend\fP; .fi .sp @@ -941,12 +943,12 @@ in check. .sp .nf -queens n = search n 1 [] \fBwith\fP - search n i p = [reverse p] \fBif\fP i>n; - = cat [search n (i+1) ((i,j):p); j = 1..n; safe (i,j) p]; - safe (i,j) p = not any (check (i,j)) p; +queens n = search n 1 [] \fBwith\fP + search n i p = [reverse p] \fBif\fP i>n; + = cat [search n (i+1) ((i,j):p) | j = 1..n; safe (i,j) p]; + safe (i,j) p = not any (check (i,j)) p; check (i1,j1) (i2,j2) - = i1==i2 || j1==j2 || i1+j1==i2+j2 || i1-j1==i2-j2; + = i1==i2 || j1==j2 || i1+j1==i2+j2 || i1-j1==i2-j2; \fBend\fP; .fi .SS Lazy Evaluation and Streams @@ -1103,7 +1105,7 @@ to denote an upper (or lower) infinite bound for the sequence, e.g.: .sp .nf -> let u = 1..inf; let v = -1.0,-1.2..-inf; +> let u = 1..inf; let v = -1.0:-1.2..-inf; > takel 10 u; takel 10 v; [1,2,3,4,5,6,7,8,9,10] [-1.0,-1.2,-1.4,-1.6,-1.8,-2.0,-2.2,-2.4,-2.6,-2.8] @@ -1126,7 +1128,7 @@ appropriate stream result: .sp .nf -> \fBlet\fP rats = [m,n-m; n=2..inf; m=1..n-1; gcd m (n-m) == 1]; rats; +> \fBlet\fP rats = [m,n-m | n=2..inf; m=1..n-1; gcd m (n-m) == 1]; rats; (1,1):#<thunk 0xb5fd08b8> > takel 10 rats; [(1,1),(1,2),(2,1),(1,3),(3,1),(1,4),(2,3),(3,2),(4,1),(1,5)] @@ -1139,7 +1141,7 @@ .sp .nf all_primes = sieve (2..inf) \fBwith\fP - sieve (p:qs) = p : sieve [q; q = qs; q mod p] &; + sieve (p:qs) = p : sieve [q | q = qs; q mod p] &; \fBend\fP; .fi .sp @@ -1423,8 +1425,8 @@ .sp .nf > \fBusing\fP system; -> f = [printf "%g\en" (2^x+1); x=1..5; x mod 2]; -> g = void [printf "%g\en" (2^x+1); x=1..5; x mod 2]; +> f = [printf "%g\en" (2^x+1) | x=1..5; x mod 2]; +> g = void [printf "%g\en" (2^x+1) | x=1..5; x mod 2]; > \fBshow\fP f g f = catmap (\ex -> if x mod 2 then [printf "%g\n" (2^x+1)] else []) (1..5); g = do (\ex -> if x mod 2 then [printf "%g\n" (2^x+1)] else []) (1..5); @@ -1447,7 +1449,7 @@ the outermost `catmap' if the list comprehension binds multiple variables: .sp .nf -> u = void [puts $ str (x,y); x=1..2; y=1..3]; +> u = void [puts $ str (x,y) | x=1..2; y=1..3]; > \fBshow\fP u u = do (\ex -> catmap (\ey -> [puts (str (x,y))]) (1..3)) (1..2); .fi @@ -1456,7 +1458,7 @@ a nested list comprehension which expands to a nested `do': .sp .nf -> v = void [void [puts $ str (x,y); y=1..3]; x=1..2]; +> v = void [void [puts $ str (x,y) | y=1..3] | x=1..2]; > \fBshow\fP v v = do (\ex -> [do (\ey -> [puts (str (x,y))]) (1..3)]) (1..2); .fi @@ -1810,12 +1812,12 @@ regularly returns with () to indicate that there is no solution. .sp .nf -queens1 n = catch reverse (search n 1 []) \fBwith\fP - search n i p = throw p \fBif\fP i>n; - = void [search n (i+1) ((i,j):p); j = 1..n; safe (i,j) p]; - safe (i,j) p = not any (check (i,j)) p; +queens1 n = catch reverse (search n 1 []) \fBwith\fP + search n i p = throw p \fBif\fP i>n; + = void [search n (i+1) ((i,j):p) | j = 1..n; safe (i,j) p]; + safe (i,j) p = not any (check (i,j)) p; check (i1,j1) (i2,j2) - = i1==i2 || j1==j2 || i1+j1==i2+j2 || i1-j1==i2-j2; + = i1==i2 || j1==j2 || i1+j1==i2+j2 || i1-j1==i2-j2; \fBend\fP; .fi .PP @@ -2449,9 +2451,11 @@ .sp .nf > \fBshow\fP -g foldl* +foldl f a x::matrix = foldl f a (list x); foldl f a s::string = foldl f a (chars s); foldl f a [] = a; foldl f a (x:xs) = foldl f (f a x) xs; +foldl1 f x::matrix = foldl1 f (list x); foldl1 f s::string = foldl1 f (chars s); foldl1 f (x:xs) = foldl f x xs; .fi This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-27 04:57:43
|
Revision: 880 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=880&view=rev Author: agraef Date: 2008-09-27 04:57:33 +0000 (Sat, 27 Sep 2008) Log Message: ----------- Add comment which triggers Emacs nroff mode. Modified Paths: -------------- pure/trunk/pure.1.in Modified: pure/trunk/pure.1.in =================================================================== --- pure/trunk/pure.1.in 2008-09-27 04:41:02 UTC (rev 879) +++ pure/trunk/pure.1.in 2008-09-27 04:57:33 UTC (rev 880) @@ -3177,3 +3177,6 @@ .TP .B Q Another term rewriting language by yours truly, \fIhttp://q-lang.sf.net\fP. +Comment] Local Variables: +Comment] mode: nroff +Comment] End: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-27 04:41:08
|
Revision: 879 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=879&view=rev Author: agraef Date: 2008-09-27 04:41:02 +0000 (Sat, 27 Sep 2008) Log Message: ----------- Simplify definition of cat. Modified Paths: -------------- pure/trunk/lib/prelude.pure Modified: pure/trunk/lib/prelude.pure =================================================================== --- pure/trunk/lib/prelude.pure 2008-09-27 04:15:24 UTC (rev 878) +++ pure/trunk/lib/prelude.pure 2008-09-27 04:41:02 UTC (rev 879) @@ -452,16 +452,14 @@ /* Concatenate a list of lists. */ cat [] = []; -cat xs@(_:_) = foldr (+) [] xs +cat xs@(_:_) = foldr (tick []) [] xs with /* Unfortunately, the global list concatenation operator (+) isn't fully lazy in Pure, because it's also used for arithmetic operations. Using it here would make foldr (and hence cat) eager. Therefore we use our own concatenation operation here, which properly deals with the case that ys is an infinite stream when applied recursively. */ - []+ys = ys; - xs@(_:_)+ys = tick [] xs ys; - tick zs (x:xs) ys = tack (x:zs) ((xs+ys)&) if thunkp xs; + tick zs (x:xs) ys = tack (x:zs) (tick [] xs ys&) if thunkp xs; = tick (x:zs) xs ys; tick zs [] ys = tack zs ys; tick zs xs ys = tack zs (xs+ys); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-27 04:15:34
|
Revision: 878 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=878&view=rev Author: agraef Date: 2008-09-27 04:15:24 +0000 (Sat, 27 Sep 2008) Log Message: ----------- Fix some minor glitches in the install procedure. Modified Paths: -------------- pure/trunk/Makefile.in Modified: pure/trunk/Makefile.in =================================================================== --- pure/trunk/Makefile.in 2008-09-26 12:33:14 UTC (rev 877) +++ pure/trunk/Makefile.in 2008-09-27 04:15:24 UTC (rev 878) @@ -218,6 +218,7 @@ # installation install: pure$(EXE) etc/pure-mode.el pure.1 + rm -rf $(addprefix $(DESTDIR), $(includedir)/pure $(includedir)/pure-$(version) $(libdir)/pure $(libdir)/pure-$(version)) for x in $(addprefix $(DESTDIR), $(bindir) $(includedir)/pure-$(version) $(libdir)/pure-$(version) $(man1dir)); do $(INSTALL) -d $$x; done $(INSTALL) pure$(EXE) $(DESTDIR)$(bindir)/pure-$(version)$(EXE) ln -sf $(bindir)/pure-$(version)$(EXE) $(DESTDIR)$(bindir)/pure$(EXE) @@ -233,7 +234,7 @@ ln -sf $(man1dir)/pure-$(version).1 $(DESTDIR)$(man1dir)/pure.1 uninstall: - rm -rf $(DESTDIR)$(bindir)/pure$(EXE) $(DESTDIR)$(bindir)/pure-$(version)$(EXE) $(DESTDIR)$(libdir)/$(libpure) $(DESTDIR)$(libdir)/$(libpurelnk) $(DESTDIR)$(includedir)/pure $(DESTDIR)$(includedir)/pure-$(version) $(DESTDIR)$(libdir)/pure $(DESTDIR)$(libdir)/pure-$(version) $(DESTDIR)$(man1dir)/pure.1 $(DESTDIR)$(man1dir)/pure-$(version).1 + rm -rf $(addprefix $(DESTDIR), $(bindir)/pure$(EXE) $(bindir)/pure-$(version)$(EXE) $(libdir)/$(libpurelnk) $(libdir)/$(libpure) $(includedir)/pure $(includedir)/pure-$(version) $(libdir)/pure $(libdir)/pure-$(version) $(man1dir)/pure.1 $(man1dir)/pure-$(version).1) # roll a distribution tarball This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-26 12:34:54
|
Revision: 875 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=875&view=rev Author: agraef Date: 2008-09-26 11:32:06 +0000 (Fri, 26 Sep 2008) Log Message: ----------- gpure.lang file was missing from the distribution. Modified Paths: -------------- pure/trunk/Makefile.in Modified: pure/trunk/Makefile.in =================================================================== --- pure/trunk/Makefile.in 2008-09-26 10:08:00 UTC (rev 874) +++ pure/trunk/Makefile.in 2008-09-26 11:32:06 UTC (rev 875) @@ -112,7 +112,7 @@ Makefile.in configure.ac configure config.h.in \ config/aclocal.m4 config/config.guess config/config.sub config/install-sh \ $(SOURCE) $(EXTRA_SOURCE) w3centities.c \ -pure.cc pure.1 pure.1.in etc/pure-mode.el.in etc/pure.* \ +pure.cc pure.1 pure.1.in etc/pure-mode.el.in etc/pure.* etc/gpure.lang \ examples/*.pure examples/*.c examples/libor/*.pure lib/*.pure \ test/*.pure test/*.log This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-26 12:06:35
|
Revision: 876 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=876&view=rev Author: agraef Date: 2008-09-26 12:06:29 +0000 (Fri, 26 Sep 2008) Log Message: ----------- gpure.lang file was missing from the distribution. Modified Paths: -------------- pure/releases/pure-0.7/Makefile.in Modified: pure/releases/pure-0.7/Makefile.in =================================================================== --- pure/releases/pure-0.7/Makefile.in 2008-09-26 11:32:06 UTC (rev 875) +++ pure/releases/pure-0.7/Makefile.in 2008-09-26 12:06:29 UTC (rev 876) @@ -112,7 +112,7 @@ Makefile.in configure.ac configure config.h.in \ config/aclocal.m4 config/config.guess config/config.sub config/install-sh \ $(SOURCE) $(EXTRA_SOURCE) w3centities.c \ -pure.cc pure.1 pure.1.in etc/pure-mode.el.in etc/pure.* \ +pure.cc pure.1 pure.1.in etc/pure-mode.el.in etc/pure.* etc/gpure.lang \ examples/*.pure examples/*.c examples/libor/*.pure lib/*.pure \ test/*.pure test/*.log This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-26 09:54:24
|
Revision: 873 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=873&view=rev Author: agraef Date: 2008-09-26 09:54:16 +0000 (Fri, 26 Sep 2008) Log Message: ----------- Updated INSTALL. Modified Paths: -------------- pure/trunk/INSTALL Modified: pure/trunk/INSTALL =================================================================== --- pure/trunk/INSTALL 2008-09-26 00:16:01 UTC (rev 872) +++ pure/trunk/INSTALL 2008-09-26 09:54:16 UTC (rev 873) @@ -17,7 +17,11 @@ the gcc frontend available for LLVM). You'll also need a Bourne-compatible shell and GNU make, which are also readily available on most platforms. +A binary package in msi format is provided for Windows users in the download +area of the pure-lang.sf.net project page. Ports and packages for other +systems are also available; see the SYSTEM NOTES section below for details. + BASIC INSTALLATION ===== ============ @@ -31,23 +35,49 @@ STEP 1. Make sure you have all the necessary dependencies installed (-dev denotes corresponding development packages): -- GNU make, GNU C++ and the corresponding libraries; +- GNU make, GNU C/C++ and the corresponding libraries; - flex and bison (these are only required when compiling the Pure SVN sources, see the INSTALLING FROM SVN SOURCES section below); -- libgmp, -dev; +- the GNU multiprecision library (libgmp, -dev); -- libreadline, -dev; +- the GNU scientific library (libgsl, -dev; this isn't a strict requirement, +but you certainly want to have this library in order to make GSL matrices work +in Pure); -- libltdl, -dev; +- the GNU readline library (libreadline, -dev); -- subversion (only needed to fetch the SVN sources, see below). +- the GNU ltdl library (libltdl, -dev; only required for building LLVM); +- subversion (this is only needed to fetch the SVN sources, see below). + E.g., the required packages for Ubuntu are: make, g++, g++ 4.0 multilib, flex, -bison, libgmp3c2, libgmp3-dev, readline5-dev, libltdl3, libldtl3-dev, -subversion. +bison, libgmp3c2, libgmp3-dev, libgsl0, libgsl0-dev, readline5-dev, libltdl3, +libldtl3-dev, subversion. +All dependencies are available as free software. Here are some links if you +need or want to install the dependencies from source: + +- GNU C/C++: http://gcc.gnu.org + +- GNU make: http://www.gnu.org/software/make + +- Flex: http://flex.sourceforge.net + +- Bison: http://www.gnu.org/software/bison + +- GMP: http://www.gnu.org/software/gmp + +- GSL: http://www.gnu.org/software/gsl + +- GNU readline: http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html + +- GNU ltdl (part of the libtool software): http://www.gnu.org/software/libtool + +Subversion is available from http://subversion.tigris.org. There's also a very +nice Windows frontend, TortoiseSVN, see http://tortoisesvn.tigris.org. + STEP 2. Get and unpack the LLVM 2.3 sources at: http://llvm.org/releases/download.html#2.3 @@ -124,6 +154,16 @@ > 6*7; 42 +Check that GSL support is available: + +> show gsl_version +let gsl_version = "1.9"; + +(If this doesn't display anything then please review your installation process +and make sure that you have GSL installed. The configure program should show +that GSL support is available in the summary. You can run Pure without this, +but then the numeric GSL matrices won't be available.) + Read the online documentation (this invokes the Pure manual page): > help @@ -304,6 +344,12 @@ this as a workaround for systems on which LLVM refuses to be linked into shared libraries. +GSL support should be enabled automatically, if the GSL libraries and headers +are available on your system. If configure fails to find these then you may +have to set CPPFLAGS and LDFLAGS accordingly and/or use --enable-gsl to +forcibly enable GSL support. You can also specify --disable-gsl if you don't +want/need the GSL matrices, but this isn't recommended. + RUNNING PURE FROM THE SOURCE DIRECTORY ------- ---- ---- --- ------ --------- @@ -385,6 +431,15 @@ Linux is the primary development platform for this software, and the sources should build out of the box on all recent Linux distributions. +Binary packages for openSUSE are maintained by Toni Graffy as part of the +Packman project: http://packman.links2linux.de/package/pure + +Alvaro Castro Castilla has contributed a Gentoo ebuild, which is currently +available at http://bugs.gentoo.org/show_bug.cgi?id=231966. + +We're still looking for people who can maintain Debian and Fedora packages, +please let us know if you want to help with that. + MAC OSX --- --- @@ -411,9 +466,11 @@ A binary package in msi format is available as well (see "Downloads" on the Pure website), which includes all required libraries and some shortcuts to run -the Pure interpreter and read online documentation in html help format. +the Pure interpreter and read online documentation in html help format, as +well as "PurePad", an alternative GUI frontend for editing and running Pure +scripts on Windows. -August 2008 +September 2008 Albert Graef <Dr.Graef at t-online.de> Eddie Rucker <erucker at bmc.edu> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-25 15:25:54
|
Revision: 870 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=870&view=rev Author: agraef Date: 2008-09-25 15:25:48 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Updated NEWS. Modified Paths: -------------- pure/trunk/NEWS Modified: pure/trunk/NEWS =================================================================== --- pure/trunk/NEWS 2008-09-25 15:24:27 UTC (rev 869) +++ pure/trunk/NEWS 2008-09-25 15:25:48 UTC (rev 870) @@ -1,5 +1,5 @@ -** Pure 0.7 (in progress) +** Pure 0.7 (2008-09-26) This release brings an important new feature: GSL (GNU Scientific Library) matrix support. Here's a brief overview of the new stuff. For more This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-25 15:24:37
|
Revision: 869 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=869&view=rev Author: agraef Date: 2008-09-25 15:24:27 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Updated ChangeLog. Modified Paths: -------------- pure/trunk/ChangeLog Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-09-25 11:17:42 UTC (rev 868) +++ pure/trunk/ChangeLog 2008-09-25 15:24:27 UTC (rev 869) @@ -1,5 +1,7 @@ 2008-09-25 Albert Graef <Dr....@t-...> + * 0.7 release. + * examples/gauss.pure, examples/linalg.pure: Add some examples for doing matrix computations in Pure. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-25 11:17:53
|
Revision: 868 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=868&view=rev Author: agraef Date: 2008-09-25 11:17:42 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Update logs. Modified Paths: -------------- pure/trunk/test/prelude.log Modified: pure/trunk/test/prelude.log =================================================================== --- pure/trunk/test/prelude.log 2008-09-25 11:03:44 UTC (rev 867) +++ pure/trunk/test/prelude.log 2008-09-25 11:17:42 UTC (rev 868) @@ -311,7 +311,12 @@ stream (x/*0:101*/:xs/*0:11*/) = x/*0:101*/:stream xs/*1:11*/&; stream () = []; stream xs@(_/*0:101*/,_/*0:11*/) = stream (list xs/*0:1*/); -xs/*0:01*/!!ns/*0:1*/ = catmap (nth/*0*/ xs/*0:01*/) ns/*0:1*/ with nth xs/*0:01*/ n/*0:1*/ = catch (cst []) [xs/*1:01*/!n/*1:1*/] { +xs/*0:01*/!!ns/*0:1*/ = if tuplep xs/*1:01*/ then tuple ys/*0:*/ else ys/*0:*/ when ys/*0:*/ = catmap (nth/*0*/ xs/*0:01*/) ns/*0:1*/ { + rule #0: ys = catmap (nth xs) ns + state 0: #0 + <var> state 1 + state 1: #0 +} end with nth xs/*0:01*/ n/*0:1*/ = catch (cst []) [xs/*1:01*/!n/*1:1*/] { rule #0: nth xs n = catch (cst []) [xs!n] state 0: #0 <var> state 1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-25 11:03:46
|
Revision: 867 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=867&view=rev Author: agraef Date: 2008-09-25 11:03:44 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Updated NEWS. Modified Paths: -------------- pure/trunk/NEWS Modified: pure/trunk/NEWS =================================================================== --- pure/trunk/NEWS 2008-09-25 10:58:00 UTC (rev 866) +++ pure/trunk/NEWS 2008-09-25 11:03:44 UTC (rev 867) @@ -1,9 +1,9 @@ ** Pure 0.7 (in progress) -Basic GSL (GNU Scientific Library) matrix support has been implemented, -including matrix comprehensions. Here's a brief overview of the new features. -For more information on GSL please refer to http://www.gnu.org/software/gsl. +This release brings an important new feature: GSL (GNU Scientific Library) +matrix support. Here's a brief overview of the new stuff. For more +information on GSL please refer to http://www.gnu.org/software/gsl. GSL double, complex and integer matrices can be created with the new {x,y;u,v} syntax, which works more or less like Octave/MATLAB matrices, but using curly @@ -29,12 +29,12 @@ Pure also provides so-called matrix comprehensions as a convenient means to create matrices from a template expression (which can denote either a scalar -or a submatrix), drawing values from lists and (optionally) filtering the -elements with predicates. These work pretty much like list comprehensions, but -return matrices instead of lists. Generator clauses in matrix comprehensions -alternate between row and column generation so that customary mathematical -notation carries over quite easily. E.g., here's a simple example which -illustrates how you can define a function which returns a square identity +or a submatrix), drawing values from lists or matrices and (optionally) +filtering the elements with predicates. These work pretty much like list +comprehensions, but return matrices instead of lists. Generator clauses in +matrix comprehensions alternate between row and column generation so that +customary mathematical notation carries over quite easily. Here's a simple +example showing how to define a function which returns a square identity matrix of a given dimension: > eye n = {i==j|i=1..n;j=1..n}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-25 10:58:02
|
Revision: 866 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=866&view=rev Author: agraef Date: 2008-09-25 10:58:00 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Updated ChangeLog. Modified Paths: -------------- pure/trunk/ChangeLog Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-09-25 10:56:40 UTC (rev 865) +++ pure/trunk/ChangeLog 2008-09-25 10:58:00 UTC (rev 866) @@ -3,6 +3,8 @@ * examples/gauss.pure, examples/linalg.pure: Add some examples for doing matrix computations in Pure. + * runtime.cc, lib/matrices.pure: Minor bugfixes. + 2008-09-23 Albert Graef <Dr....@t-...> * lib/matrices.pure: Moved the matrix operations from This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-25 10:56:45
|
Revision: 865 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=865&view=rev Author: agraef Date: 2008-09-25 10:56:40 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Updated ChangeLog. Modified Paths: -------------- pure/trunk/ChangeLog Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-09-25 10:55:23 UTC (rev 864) +++ pure/trunk/ChangeLog 2008-09-25 10:56:40 UTC (rev 865) @@ -1,3 +1,8 @@ +2008-09-25 Albert Graef <Dr....@t-...> + + * examples/gauss.pure, examples/linalg.pure: Add some examples for + doing matrix computations in Pure. + 2008-09-23 Albert Graef <Dr....@t-...> * lib/matrices.pure: Moved the matrix operations from This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-25 10:55:28
|
Revision: 864 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=864&view=rev Author: agraef Date: 2008-09-25 10:55:23 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Add basic matrix examples. Added Paths: ----------- pure/trunk/examples/linalg.pure Added: pure/trunk/examples/linalg.pure =================================================================== --- pure/trunk/examples/linalg.pure (rev 0) +++ pure/trunk/examples/linalg.pure 2008-09-25 10:55:23 UTC (rev 864) @@ -0,0 +1,87 @@ + +/* Basic routines for Pure matrices. 2008-09-25 AG */ + +/* This is intended to become a grab bag for useful definitions of matrix + operations (mostly linear algebra) and emulations of operations provided as + builtins in numeric computation software like Octave. These examples also + illustrate the use of Pure's matrix operations and, in particular, matrix + comprehensions. Note, however, that we're striving for clarity rather than + efficiency in these definitions, so some routines may be quite slow + compared to hand-tuned C code. */ + +/* Some convenience functions for generating zero and identity matrices with + given dimensions. These create double matrices by default, use the prelude + functions imatrix and cmatrix to convert as needed. */ + +zeros n::int = zeros (n,n); +zeros (n::int,m::int) = dmatrix (n,m); + +eye n::int = eye (n,n); +eye (n::int,m::int) = {double (i==j) | i=0..n-1; j = 0..m-1}; + +/* Basic matrix arithmetic. */ + +/* Mixed matrix-scalar arithmetic. */ + +a + x::matrix = map (\x->a+x) x if not matrixp a; +x::matrix + a = map (\x->x+a) x if not matrixp a; + +a - x::matrix = map (\x->a-x) x if not matrixp a; +x::matrix * a = map (\x->x-a) x if not matrixp a; + +a * x::matrix = map (\x->a*x) x if not matrixp a; +x::matrix * a = map (\x->x*a) x if not matrixp a; + +a / x::matrix = map (\x->a/x) x if not matrixp a; +x::matrix / a = map (\x->x/a) x if not matrixp a; + +/* Element-wise arithmetic. */ + +x::matrix + y::matrix = zipwith (+) x y if dim x==dim y; +x::matrix - y::matrix = zipwith (-) x y if dim x==dim y; + +/* Dot product. */ + +dot x::matrix y::matrix = foldl (+) 0 [x!i*y!i | i=0..#x-1] + if vectorp x && vectorp y && #x==#y; + +/* Matrix multiplication. (The redim is needed to properly handle all empty + matrix cases. See the Octave manual for an explanation of this issue.) */ + +x::matrix * y::matrix = redim (dim x!0,dim y!1) + {dot u v | u = rows x; v = cols y} + if dim x!1==dim y!0; + +/* Convenience functions to print matrices in "short" or "long" format a la + Octave. These also emulate Octave's way to show empty matrices along with + their dimensions. FIXME: This isn't quite the same as Octave's display + algorithm yet, as it uses fixed point format, and only double and int + matrices are supported right now. Contributions are welcome. ;-) */ + +using system; + +// Uncomment one of these to enable. +__show__ x::matrix = short_format x; +//__show__ x::matrix = long_format x; + +short_format x::matrix += if null x then sprintf "{}(%dx%d)" (dim x) + else strcat [printd j (x!(i,j))|i=0..n-1; j=0..m-1] + "\n" +with printd 0 = sprintf "\n%10.5f"; printd _ = sprintf "%10.5f" end +when n,m = dim x end if dmatrixp x; += if null x then sprintf "{}(%dx%d)" (dim x) + else strcat [printd j (x!(i,j))|i=0..n-1; j=0..m-1] + "\n" +with printd 0 = sprintf "\n%10d"; printd _ = sprintf "%10d" end +when n,m = dim x end if imatrixp x; += sprintf "{}(%dx%d)" (dim x) if null x; + +long_format x::matrix += if null x then sprintf "{}(%dx%d)" (dim x) + else strcat [printd j (x!(i,j))|i=0..n-1; j=0..m-1] + "\n" +with printd 0 = sprintf "\n%20.15f"; printd _ = sprintf "%20.15f" end +when n,m = dim x end if dmatrixp x; += if null x then sprintf "{}(%dx%d)" (dim x) + else strcat [printd j (x!(i,j))|i=0..n-1; j=0..m-1] + "\n" +with printd 0 = sprintf "\n%20d"; printd _ = sprintf "%20d" end +when n,m = dim x end if imatrixp x; += sprintf "{}(%dx%d)" (dim x) if null x; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-25 10:53:00
|
Revision: 863 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=863&view=rev Author: agraef Date: 2008-09-25 10:52:57 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Cosmetic changes. Modified Paths: -------------- pure/trunk/examples/gauss.pure pure/trunk/pure.1.in Modified: pure/trunk/examples/gauss.pure =================================================================== --- pure/trunk/examples/gauss.pure 2008-09-25 10:48:21 UTC (rev 862) +++ pure/trunk/examples/gauss.pure 2008-09-25 10:52:57 UTC (rev 863) @@ -26,7 +26,8 @@ i and p accordingly and return the result. */ step (p,i,x) j -= if max_x>0 then += if max_x==0 then p,i,x + else // updated row permutation and index: transp i max_i p, i+1, {// the top rows of the matrix remain unchanged: @@ -35,7 +36,6 @@ {x!(i,l)/x!(i,j) | l=0..m-1}; // subtract suitable multiples of the pivot row: {x!(k,l)-x!(k,j)*x!(i,l)/x!(i,j) | k=i+1..n-1; l=0..m-1}} - else p,i,x when n,m = dim x; max_i, max_x = pivot i (col x j); x = if max_x>0 then swap x i max_i else x; Modified: pure/trunk/pure.1.in =================================================================== --- pure/trunk/pure.1.in 2008-09-25 10:48:21 UTC (rev 862) +++ pure/trunk/pure.1.in 2008-09-25 10:52:57 UTC (rev 863) @@ -1261,7 +1261,8 @@ // One pivoting and elimination step in column j of the matrix: step (p,i,x) j -= \fBif\fP max_x>0 \fBthen\fP += \fBif\fP max_x==0 \fBthen\fP p,i,x + \fBelse\fP // updated row permutation and index: transp i max_i p, i+1, {// the top rows of the matrix remain unchanged: @@ -1270,7 +1271,6 @@ {x!(i,l)/x!(i,j) | l=0..m-1}; // subtract suitable multiples of the pivot row: {x!(k,l)-x!(k,j)*x!(i,l)/x!(i,j) | k=i+1..n-1; l=0..m-1}} - \fBelse\fP p,i,x \fBwhen\fP n,m = dim x; max_i, max_x = pivot i (col x j); x = \fBif\fP max_x>0 \fBthen\fP swap x i max_i \fBelse\fP x; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-25 10:48:27
|
Revision: 862 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=862&view=rev Author: agraef Date: 2008-09-25 10:48:21 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Update documentation. Modified Paths: -------------- pure/trunk/pure.1.in Modified: pure/trunk/pure.1.in =================================================================== --- pure/trunk/pure.1.in 2008-09-25 10:15:40 UTC (rev 861) +++ pure/trunk/pure.1.in 2008-09-25 10:48:21 UTC (rev 862) @@ -1205,9 +1205,10 @@ .fi .PP Second, matrix comprehensions make it easy to express a variety of algorithms -which would be implemented using `for' loops in conventional programming -languages. To illustrate the use of matrix comprehensions, here is how we can -define an operation to create a square identity matrix of a given dimension: +which would typically be implemented using `for' loops in conventional +programming languages. To illustrate the use of matrix comprehensions, here is +how we can define an operation to create a square identity matrix of a given +dimension: .sp .nf > eye n = {i==j | i = 1..n; j = 1..n}; @@ -1224,14 +1225,12 @@ notation very closely. .PP As a slightly more comprehensive example (no pun intended!), here is a -definition of matrix multiplication in Pure. Let's start out with the simple -case of the ``dot'' product of two vectors: +definition of matrix multiplication in Pure. The building block here is the +``dot'' product of two vectors which can be defined as follows: .sp .nf -> x::matrix * y::matrix = sum [x!i*y!i | i=0..#x-1] -> \fBif\fP vectorp x && vectorp y; -> sum = foldl (+) 0; -> {1,2,3}*{1,0,1}; +> dot x::matrix y::matrix = foldl (+) 0 [x!i*y!i | i=0..#x-1]; +> dot {1,2,3} {1,0,1}; 4 .fi .PP @@ -1240,11 +1239,11 @@ the definition above.) .PP The general matrix product now boils down to a simple matrix comprehension -which just multiplies all rows of x with all columns of y (the rows and cols -functions are prelude operations found in matrices.pure): +which just computes the dot product of all rows of x with all columns of y +(the rows and cols functions are prelude operations found in matrices.pure): .sp .nf -> x::matrix * y::matrix = {u*v | u = rows x; v = cols y}; +> x::matrix * y::matrix = {dot u v | u = rows x; v = cols y}; > {0,1;1,0;1,1}*{1,2,3;4,5,6}; {4,5,6;1,2,3;5,7,9} .fi This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-25 10:15:48
|
Revision: 861 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=861&view=rev Author: agraef Date: 2008-09-25 10:15:40 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Make redim take the dimension as its first argument. This is much more convenient. Modified Paths: -------------- pure/trunk/lib/matrices.pure Modified: pure/trunk/lib/matrices.pure =================================================================== --- pure/trunk/lib/matrices.pure 2008-09-25 09:46:09 UTC (rev 860) +++ pure/trunk/lib/matrices.pure 2008-09-25 10:15:40 UTC (rev 861) @@ -262,19 +262,19 @@ private matrix_redim; extern expr* matrix_redim(expr* x, int n, int m); -redim x::matrix (n::int,m::int) +redim (n::int,m::int) x::matrix = matrix_redim x n m if n>=0 && m>=0 && n*m==#x; /* You can also redim a matrix to a given row size. In this case the row size must divide the total size of the matrix, */ -redim x::matrix m::int = redim x (#x div m,m) if m>0 && #x mod m==0; +redim m::int x::matrix = redim (#x div m,m) x if m>0 && #x mod m==0; = x if m==0 && #x==0; /* Convert a matrix to a row or column vector. */ -rowvector x::matrix = redim x (1,#x); -colvector x::matrix = redim x (#x,1); +rowvector x::matrix = redim (1,#x) x; +colvector x::matrix = redim (#x,1) x; /* Transpose a matrix. */ @@ -323,7 +323,7 @@ head x::matrix = x!0 if not null x; init x::matrix = x!!(0..#x-2) if not null x; last x::matrix = x!(#x-1) if not null x; -map f x::matrix = flip redim (dim x) $ colcat (map f (list x)); +map f x::matrix = redim (dim x) $ colcat (map f (list x)); scanl f a x::matrix = colcat (scanl f a (list x)); scanl1 f x::matrix = colcat (scanl1 f (list x)); scanr f a x::matrix = colcat (scanr f a (list x)); @@ -338,19 +338,19 @@ zip3dim x::matrix y::matrix z::matrix = min (dim x!0) (min (dim y!0) (dim z!0)),dim x!1; -zip x::matrix y::matrix = flip redim (zipdim x y) $ +zip x::matrix y::matrix = redim (zipdim x y) $ colcat (zip (list x) (list y)) if dim x!1==dim y!1; zip3 x::matrix y::matrix z::matrix - = flip redim (zip3dim x y z) $ + = redim (zip3dim x y z) $ colcat (zip3 (list x) (list y) (list z)) if dim x!1==dim y!1 && dim x!1==dim z!1; zipwith f x::matrix y::matrix - = flip redim (zipdim x y) $ + = redim (zipdim x y) $ colcat (zipwith f (list x) (list y)) if dim x!1==dim y!1; zipwith3 f x::matrix y::matrix z::matrix - = flip redim (zip3dim x y z) $ + = redim (zip3dim x y z) $ colcat (zipwith3 f (list x) (list y) (list z)) if dim x!1==dim y!1 && dim x!1==dim z!1; dowith f x::matrix y::matrix @@ -360,12 +360,12 @@ = dowith3 f (list x) (list y) (list z) if dim x!1==dim y!1 && dim x!1==dim z!1; -unzip x::matrix = flip redim (dim x) (colcat u), - flip redim (dim x) (colcat v) +unzip x::matrix = redim (dim x) (colcat u), + redim (dim x) (colcat v) when u,v = unzip (list x) end; -unzip3 x::matrix = flip redim (dim x) (colcat u), - flip redim (dim x) (colcat v), - flip redim (dim x) (colcat w) +unzip3 x::matrix = redim (dim x) (colcat u), + redim (dim x) (colcat v), + redim (dim x) (colcat w) when u,v,w = unzip3 (list x) end; /* Low-level operations for converting between matrices and raw pointers. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |