tech.v3.datatype.argops
Index-space algorithms. Implements a subset of the jvm-version.
argfilter
(argfilter pred options data)
(argfilter pred data)
(argfilter data)
Return an array of indexes that pass the filter.
arglast-every
(arglast-every rdr pred)
Return the last index where (pred (rdr idx) (rdr (dec idx))) was true by comparing every value and keeping track of the last index where pred was true.
argsort
(argsort compare-fn options data)
(argsort compare-fn data)
(argsort data)
Return an array of indexes that order the provided data by compare-fn. compare-fn must
be a boolean function such as < or >. You can use a full custom comparator returning
-1,0 or 1 by using the :comparator
option.
compare-fn
- Boolean binary predicate such as < or >.
Options:
:nan-strategy
- defaults to:last
- if the data has a numeric elemwise-datatype, a nan-aware comparsing will be used that will place nan data first, last, or throw an exception as specified by the three possible options -:first
,:last
, and:exception
.:comparator
- comparator to use. This overrides compare-fn and takes two arguments but returns a number.
Examples:
cljs.user> ;;Persistent vectors do not indicate datatype so nan-aware comparison is disabled.
cljs.user> (argops/argsort [##NaN 1 2 3 ##NaN])
#typed-buffer[[:int32 5][0 1 2 3 4]
cljs.user> ;;But with a container that indicates datatype nan will be handled
cljs.user> (argops/argsort (dtype/make-container :float32 [##NaN 1 2 3 ##NaN]))
#typed-buffer[[:int32 5][1 2 3 4 0]
cljs.user> ;;example setting nan strategy and using custom comparator.
cljs.user> (argops/argsort nil ;;no compare fn
{:nan-strategy :first
:comparator #(compare %2 %1)}
(dtype/make-container :float32 [##NaN 1 2 3 ##NaN]))
#typed-buffer[[:int32 5][0 4 3 2 1]
binary-search
(binary-search data target options)
(binary-search data target)
Returns a long result that points to just before the value or exactly points to the value. In the case where the target is after the last value will return elem-count. If value is present multiple times the index will point to the first value.
Options:
:comparator
- a specific comparator to use; defaults tocomparator
.
index-reducer-rf
(index-reducer-rf)
(index-reducer-rf acc v)
(index-reducer-rf acc)
Return a transduce-compatible index scanning rf.