diff --git a/lib/apl/runtime.sx b/lib/apl/runtime.sx index 4bfd91e9..ca6fa2c7 100644 --- a/lib/apl/runtime.sx +++ b/lib/apl/runtime.sx @@ -732,3 +732,24 @@ (define apl-grade-up (fn (arr) (apl-grade arr true))) (define apl-grade-down (fn (arr) (apl-grade arr false))) + +(define apl-enclose (fn (arr) (apl-scalar arr))) + +(define + apl-disclose + (fn + (arr) + (let + ((shape (get arr :shape)) (ravel (get arr :ravel))) + (if + (= (len shape) 0) + (let + ((inner (first ravel))) + (if (= (type-of inner) "dict") inner (apl-scalar inner))) + (if + (= (len shape) 1) + (apl-scalar (first ravel)) + (let + ((inner-shape (rest shape)) + (inner-size (reduce * 1 (rest shape)))) + (make-array inner-shape (take ravel inner-size)))))))) diff --git a/lib/apl/test.sh b/lib/apl/test.sh index 5d546d1a..ecb69bee 100755 --- a/lib/apl/test.sh +++ b/lib/apl/test.sh @@ -4,9 +4,9 @@ set -uo pipefail cd "$(git rev-parse --show-toplevel)" -SX_SERVER="${SX_SERVER:-hosts/ocaml/_build/default/bin/sx_server.exe}" +SX_SERVER="${SX_SERVER:-/root/rose-ash/hosts/ocaml/_build/default/bin/sx_server.exe}" if [ ! -x "$SX_SERVER" ]; then - SX_SERVER="/root/rose-ash/hosts/ocaml/_build/default/bin/sx_server.exe" + SX_SERVER="hosts/ocaml/_build/default/bin/sx_server.exe" fi if [ ! -x "$SX_SERVER" ]; then echo "ERROR: sx_server.exe not found." @@ -23,7 +23,7 @@ cat > "$TMPFILE" << 'EPOCHS' (eval "(define apl-test-pass 0)") (eval "(define apl-test-fail 0)") (eval "(define apl-test-fails (list))") -(eval "(define (apl-test name got expected) (if (= got expected) (set! apl-test-pass (+ apl-test-pass 1)) (begin (set! apl-test-fail (+ apl-test-fail 1)) (set! apl-test-fails (append apl-test-fails (list {:name name :got got :expected expected}))))))") +(eval "(define apl-test (fn (name got expected) (if (= got expected) (set! apl-test-pass (+ apl-test-pass 1)) (begin (set! apl-test-fail (+ apl-test-fail 1)) (set! apl-test-fails (append apl-test-fails (list {:name name :got got :expected expected})))))))") (epoch 3) (load "lib/apl/tests/structural.sx") (epoch 4) diff --git a/lib/apl/tests/structural.sx b/lib/apl/tests/structural.sx index 9ad71b99..cfdf16cf 100644 --- a/lib/apl/tests/structural.sx +++ b/lib/apl/tests/structural.sx @@ -474,4 +474,44 @@ (apl-test "grade-up single element" (rv (apl-grade-up (make-array (list 1) (list 42)))) - (list 1)) \ No newline at end of file + (list 1)) + +(apl-test + "enclose shape is scalar" + (sh (apl-enclose (make-array (list 3) (list 1 2 3)))) + (list)) + +(apl-test + "enclose ravel length is 1" + (len (rv (apl-enclose (make-array (list 3) (list 1 2 3))))) + 1) + +(apl-test + "enclose inner ravel" + (rv (first (rv (apl-enclose (make-array (list 3) (list 1 2 3)))))) + (list 1 2 3)) + +(apl-test + "disclose of enclose round-trips ravel" + (rv (apl-disclose (apl-enclose (make-array (list 3) (list 10 20 30))))) + (list 10 20 30)) + +(apl-test + "disclose of enclose round-trips shape" + (sh (apl-disclose (apl-enclose (make-array (list 3) (list 10 20 30))))) + (list 3)) + +(apl-test + "disclose scalar ravel" + (rv (apl-disclose (apl-scalar 42))) + (list 42)) + +(apl-test + "disclose vector ravel" + (rv (apl-disclose (make-array (list 3) (list 5 6 7)))) + (list 5)) + +(apl-test + "disclose matrix returns first row" + (rv (apl-disclose (make-array (list 2 3) (list 1 2 3 4 5 6)))) + (list 1 2 3)) \ No newline at end of file