diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-11 17:43:24 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-11 17:43:24 +0000 |
commit | 4a92ef13f83ec4fe79d6dd815f1b9fe492a404fe (patch) | |
tree | c5c263289354c2e2fd1f4822cfac389c23a9ffb7 /functions.c | |
parent | fe701a61f4d057597dab3d46ba0fe31e550b41df (diff) |
Add dyadic function application, and implement dyadic ⍴
Diffstat (limited to 'functions.c')
-rw-r--r-- | functions.c | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/functions.c b/functions.c index 8a5c959..71e5400 100644 --- a/functions.c +++ b/functions.c @@ -58,7 +58,62 @@ fnmonad monadfunctiondefs[] = { 0, /* ⊖ */ 0, /* ⍉ */ 0, /* ⍎ */ - 0, /* ⍕ */ + 0, /* ⍕ */ +}; + +fndyad dyadfunctiondefs[] = { + 0, /* + */ + 0, /* - */ + 0, /* × */ + 0, /* ÷ */ + 0, /* * */ + 0, /* ⍟ */ + 0, /* ⌹ */ + 0, /* ○ */ + 0, /* ! */ + 0, /* ? */ + 0, /* | */ + 0, /* ⌈ */ + 0, /* ⌊ */ + 0, /* ⊥ */ + 0, /* ⊤ */ + 0, /* ⊣ */ + 0, /* ⊢ */ + 0, /* = */ + 0, /* ≠ */ + 0, /* ≤ */ + 0, /* < */ + 0, /* > */ + 0, /* ≥ */ + 0, /* ≡ */ + 0, /* ≢ */ + 0, /* ∨ */ + 0, /* ∧ */ + 0, /* ⍲ */ + 0, /* ⍱ */ + 0, /* ↑ */ + 0, /* ↓ */ + 0, /* ⊂ */ + 0, /* ⊃ */ + 0, /* ⊆ */ + 0, /* ⌷ */ + 0, /* ⍋ */ + 0, /* ⍒ */ + 0, /* ⍳ */ + 0, /* ⍸ */ + 0, /* ∊ */ + 0, /* ⍷ */ + 0, /* ∪ */ + 0, /* ∩ */ + 0, /* ~ */ + 0, /* , */ + fnCatenateFirst, /* ⍪ */ + fnReshape, /* ⍴ */ + 0, /* ⌽ */ + 0, /* ⊖ */ + 0, /* ⍉ */ + 0, /* ⍎ */ + 0, /* ⍕ */ }; /* Monadic functions */ @@ -127,4 +182,23 @@ fnCatenateFirst(Array *left, Array *right) memcpy(res->rawdata, left->rawdata, datasizes[res->type]*left->size); memcpy(res->rawdata+datasizes[res->type]*left->size, right->rawdata, datasizes[res->type]*right->size); return res; +} + +Array * +fnReshape(Array *left, Array *right) +{ + vlong size = 1; + int i; + char *p; + for(i = 0; i < left->size; i++) + size *= left->intdata[i]; + if(left->size == 0) + size = 0; + + Array *res = mkarray(right->type, left->size, size); + for(i = 0; i < left->size; i++) + res->shape[i] = left->intdata[i]; + for(i = 0, p = res->rawdata; i < size; i++, p += datasizes[res->type]) + memcpy(p, right->rawdata + (datasizes[res->type] * (i % right->size)), datasizes[res->type]); + return res; }
\ No newline at end of file |