summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--functions.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/functions.c b/functions.c
index 3b32cca..1479af0 100644
--- a/functions.c
+++ b/functions.c
@@ -571,14 +571,24 @@ fnGradeDown(Array *right)
Array *
fnIndexGenerator(Array *right)
{
- /* TODO only works for creating vectors */
- vlong n = right->intdata[0];
- Array *res = allocarray(AtypeInt, 1, n);
- res->shape[0] = n;
- vlong io = globalIO();
- for(vlong i = 0; i < n; i++)
- res->intdata[i] = i + io;
- return res;
+ Array *result = nil;
+ if(right->rank == 0){
+ vlong n = right->intdata[0];
+ if(n < 0)
+ throwerror(nil, EDomain);
+ result = allocarray(AtypeInt, 1, n);
+ result->shape[0] = n;
+ vlong io = globalIO();
+ for(vlong i = 0; i < n; i++)
+ result->intdata[i] = i + io;
+ }else if(right->rank == 1){
+ if(right->size == 0)
+ return rundfn(L"⊂⍬", nil, nil, nil, nil);
+ else
+ result = rundfn(L"↑,⌾⌿⍳¨⍵", nil, nil, nil, right);
+ }else
+ throwerror(nil, ERank);
+ return result;
}
Array *