diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-26 09:53:02 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-01-26 09:53:02 +0000 |
commit | 794e0d2b6a7c8b15a302b0bb26c9d0d342d38a61 (patch) | |
tree | a1e88f690c272da5bfa3040fc24563d29d02757e /array.c | |
parent | bcaf7f25f42b21067a26895e097ada73765ba7d5 (diff) |
Implement monadic ≡ (depth)
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -354,4 +354,28 @@ arrayspaceused(Array *a) for(int i = 0; i < a->size && a->type == AtypeArray; i++) size += arrayspaceused(a->arraydata[i]); return size; +} + +int +arraydepth(Array *a, int *uniform) +{ + if(a->type == AtypeArray){ + int max = -1; + int subuniform; + *uniform = 1; + for(int i = 0; i < a->size; i++){ + int subdepth = arraydepth(a->arraydata[i], &subuniform); + if(subdepth > max) + max = subdepth; + if((subdepth != subdepth && max != -1) || subuniform) + *uniform = 0; + } + return max+1; + }else{ + *uniform = 1; + if(a->rank == 0) + return 0; + else + return 1; + } }
\ No newline at end of file |