diff --git a/lib/Env.chpl b/lib/Env.chpl index 2194ce1a..b818da7b 100644 --- a/lib/Env.chpl +++ b/lib/Env.chpl @@ -6,7 +6,7 @@ param developmentAndTesting = !releaseChAI; // Minimum needed rank of dynamicTensor for *any* build -config param minRankNeeded = 6; +config param minRankNeeded = 4; // Maximum needed rank of dynamicTensor for a release build diff --git a/lib/NDArray.chpl b/lib/NDArray.chpl index 86f034e9..bc396145 100644 --- a/lib/NDArray.chpl +++ b/lib/NDArray.chpl @@ -149,24 +149,39 @@ record ndarray : serializable { _domain = dom; } - proc reshape(const dom: ?t): ndarray(rank,eltType) + proc reshape(const dom: ?t): ndarray(dom.rank,eltType) where isDomainType(t) - && dom.rank == rank { + /* && dom.rank == rank */ { var arr = new ndarray(eltType,dom); - const arrDom = arr.domain; - const selfDom = _domain; - - const inter = selfDom[arrDom]; - arr.data[inter] = data[inter]; + + const arrDom = arr.domain; + const selfDom = this.domain; + + ref arrData = arr.data; + const ref selfData = this.data; + + const arrShape = arrDom.shape; + const selfShape = selfDom.shape; + const selfShapeDivs = util.shapeDivisors((...selfShape)); + + const zero: eltType = 0; + + forall (i,idx) in arrDom.everyZip() { + const selfIdx = util.indexAtHelperMultiples(i,(...selfShapeDivs)); + const a = if util.shapeContains(selfShape,selfIdx) + then selfData[selfIdx] + else zero; + arrData[idx] = a; + } return arr; } - +/* proc reshape(const dom: ?t): ndarray(dom.rank,eltType) where isDomainType(t) && dom.rank != rank { var arr: ndarray(dom.rank,eltType) = new ndarray(eltType,dom); - + compilerError("Testing. Don't call me."); const selfDom = this.domain; const newDom = arr.domain; const ref selfData = this.data; @@ -200,7 +215,7 @@ record ndarray : serializable { // return arr; } - +*/ // This can optimized such that it doesn't use two heavy utility functions... proc reshape(newShape: int ...?newRank): ndarray(newRank,eltType) { diff --git a/lib/Utilities.chpl b/lib/Utilities.chpl index cb5537d2..504e802e 100644 --- a/lib/Utilities.chpl +++ b/lib/Utilities.chpl @@ -193,6 +193,26 @@ module Utilities { return idxs; } + inline proc shapeDivisors(shape: int...?rank): rank*int { + var prod = 1; + var divs: rank * int; + for param j in 0.. 1 { var idx: rank * int; var order = n; @@ -304,6 +324,14 @@ module Utilities { return arr; } + inline proc shapeContains(shape: ?rank*int, idx: ?idxRank*int): bool + where rank == idxRank { + var contained = true; + for param i in 0..