From c582247ba667504452862dc5f8a007999ea367ca Mon Sep 17 00:00:00 2001 From: dos-reis Date: Tue, 14 May 2013 07:38:41 +0000 Subject: * algebra/array2.spad.pamphlet (InnerTwoDimensionalArray) [map]: Move implementation from TwoDimensionalArrayCategory. --- src/ChangeLog | 5 +++++ src/algebra/array2.spad.pamphlet | 25 ++++++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 1e25e2e0..1ef3785e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2013-05-14 Gabriel Dos Reis + + * algebra/array2.spad.pamphlet (InnerTwoDimensionalArray) [map]: + Move implementation from TwoDimensionalArrayCategory. + 2013-05-14 Gabriel Dos Reis * algebra/array2.spad.pamphlet (TwoDimensionalArrayCategory): Move diff --git a/src/algebra/array2.spad.pamphlet b/src/algebra/array2.spad.pamphlet index 1f23e4fb..9be6ee45 100644 --- a/src/algebra/array2.spad.pamphlet +++ b/src/algebra/array2.spad.pamphlet @@ -142,21 +142,6 @@ TwoDimensionalArrayCategory(R,Row,Col): Category == Definition where entryList --% Creation - -- array creation requires an initial element used to - -- populate the array. This is a best effort attempt - -- to supply such element, when semantics permits. - sampleElement(): R == - R has sample: () -> R => sample()$R - NIL$Lisp -- better obfuscation welcome. - - map(f,m,n,r) == - maxRow := max(maxRowIndex m,maxRowIndex n) - maxCol := max(maxColIndex m,maxColIndex n) - ans := new(max(nrows m,nrows n),max(ncols m,ncols n),sampleElement()) - for i in minRowIndex(m)..maxRow repeat - for j in minColIndex(m)..maxCol repeat - qsetelt!(ans,i,j,f(elt(m,i,j,r),elt(n,i,j,r))) - ans setRow!(m,i,v) == i < minRowIndex(m) or i > maxRowIndex(m) => @@ -310,6 +295,16 @@ InnerTwoDimensionalArray(R,Row,Col):_ t.i := map(f,rep(m).i,rep(n).i) per t + map(f,m,n,r) == + nrows m = nrows n and ncols m = ncols n => map(f,m,n) + nr := max(nrows m,nrows n) + nc := max(ncols m,ncols n) + t: Rep := new(nr,sample$PrimitiveArray(R)) + for i in 1..nr repeat + t.i := [[f(elt(m,i,j,r),elt(n,i,j,r)) + for j in 1..nc]]$PrimitiveArray(R) + per t + @ \section{domain ARRAY2 TwoDimensionalArray} -- cgit v1.2.3