diff options
Diffstat (limited to 'functions.c')
-rw-r--r-- | functions.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/functions.c b/functions.c new file mode 100644 index 0000000..6ff653a --- /dev/null +++ b/functions.c @@ -0,0 +1,54 @@ +#include <u.h> +#include <libc.h> +#include <bio.h> + +#include "apl9.h" + +Array * +fnCatenateFirst(Array *left, Array *right) +{ + /* not even close to being right, but it works for stranding :) */ + if(left->rank == 0) + left = fnRavel(left); + if(right->rank == 0) + right = fnRavel(right); + + print("Catenating: %S and %S\n", pparray(left), pparray(right)); + /* assume two vectors of same type for now */ + Array *res = mkarray(left->type, 1, left->size+right->size); + res->shape[0] = left->shape[0] + right->shape[0]; + 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 * +fnNest(Array *right) +{ + if(simplearray(right)) + return fnEnclose(right); + else + return right; +} + +Array * +fnEnclose(Array *right) +{ + if(simplescalar(right)) + return right; + else{ + Array *res = mkarray(AtypeArray, 0, 1); + res->arraydata[0] = right; + return res; + } +} + +Array * +fnRavel(Array *right) +{ + Array *res = duparray(right); + res->rank = 1; + res->shape = realloc(res->shape, sizeof(int) * 1); + res->shape[0] = res->size; + return res; +}
\ No newline at end of file |