Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lagoon/desk/lib/lagoon.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -994,15 +994,23 @@
=/ rtol (fill meta.a data:(scale meta.a +.tol))
(lte (abs (sub a b)) (add atol (mul rtol (abs b))))
::
:: Booleans use the numeric convention true=1, false=0 (see fun-scalar).
:: An element is truthy iff its encoded value is nonzero (also +0.0=0x0).
:: any: some element truthy <=> the max element is nonzero.
:: all: every element truthy <=> the min element is nonzero.
:: min/max reduce to an all-1s-shape scalar ray, so index with a
:: rank-matched zero index rather than assuming a fixed dimensionality.
++ any
|= [a=ray]
^- ?(%.y %.n)
(^lth (get-item (cumsum a) ~[0]) (roll shape.meta.a ^mul))
=/ dex (reap (lent shape.meta.a) 0)
!(=((get-item (max a) dex) 0))
::
++ all
|= [a=ray]
^- ?(%.y %.n)
=((get-item (cumsum a) ~[0]) 0)
=/ dex (reap (lent shape.meta.a) 0)
!(=((get-item (min a) dex) 0))
::
+$ ops $? %add
%sub
Expand Down
15 changes: 15 additions & 0 deletions lagoon/desk/tests/lib/lagoon-array-utils.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,21 @@
!>((get-item:la (max:la a) ~[0 0]))
!>((snag (argmax:la a) (ravel:la a)))
==
::
:: any/all over boolean rays (numeric convention: true=1.0, false=0.0).
:: any = some element truthy; all = every element truthy.
++ test-any-all ^- tang
=/ all-true (en-ray:la [meta=[shape=~[1 3] bloq=5 kind=%i754 tail=~] baum=~[~[.1.0 .1.0 .1.0]]])
=/ has-false (en-ray:la [meta=[shape=~[1 3] bloq=5 kind=%i754 tail=~] baum=~[~[.1.0 .0.0 .1.0]]])
=/ all-false (en-ray:la [meta=[shape=~[1 3] bloq=5 kind=%i754 tail=~] baum=~[~[.0.0 .0.0 .0.0]]])
;: weld
%+ expect-eq !>(%.y) !>((all:la all-true))
%+ expect-eq !>(%.y) !>((any:la all-true))
%+ expect-eq !>(%.n) !>((all:la has-false))
%+ expect-eq !>(%.y) !>((any:la has-false))
%+ expect-eq !>(%.n) !>((all:la all-false))
%+ expect-eq !>(%.n) !>((any:la all-false))
==

--
:: to-tank
Expand Down