From 2b73fb1cd84b449d9549a49afe6e100d0442e725 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Mon, 31 Jan 2022 22:09:17 +0000 Subject: Implement windowed reduce --- hybrids.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'hybrids.c') diff --git a/hybrids.c b/hybrids.c index 8042e5d..e7f7f4b 100644 --- a/hybrids.c +++ b/hybrids.c @@ -166,9 +166,6 @@ fnExpandFirst(Array *left, Array *right) Array * opReduceLast(Datum *lefto, Array *left, Array *right) { - if(left) - throwerror(L"left argument to f/", ENotImplemented); - right = fnTranspose(right); Array *tmp = opReduceFirst(lefto, left, right); Array *res = fnTranspose(tmp); @@ -194,8 +191,21 @@ opScanLast(Datum *lefto, Array *left, Array *right) Array * opReduceFirst(Datum *lefto, Array *left, Array *right) { - if(left) - throwerror(L"left argument to f⌿", ENotImplemented); + if(left){ + if(left->type != AtypeInt) + throwerror(nil, EType); + if(left->size != 1) + throwerror(nil, ELength); + vlong winsize = left->intdata[0]; + if(winsize > right->shape[0]) + throwerror(nil, EShape); + + Rune *code = L"n←(-|⍺)+1+≢⍵ ⋄" + L"ix←(⍳|⍺)∘+¨(⍳n)-⎕io ⋄" + L"ix←⍺{⍺<0:⌽¨⍵ ⋄ ⍵}ix ⋄" + L"↑⍵∘(⍶{⍶⌿(⊂⍵)⌷⍺})¨ix"; + return rundfn(code, lefto, nil, left, right); + } if(right->rank == 0) return fnSame(right); -- cgit v1.2.3