tech.v3.datatype

Support for programming with arrays and a fast set implementation for indexe (int32) values. For complex/higher order algorithms see tech.v3.datatype.argops. For mathematical primitives, see tech.v3.datatype.functional

->fast-nth

(->fast-nth item)

Given an arbitrary container, return the fastest idx->value accessor possible. If the item is agetable, this just wraps aget. Else, unless otherwise instructed, it will wrap #(-nth item %).

->js-set

(->js-set)(->js-set data)

Create a javascript set. These have superior performance when dealing with numeric data but they fail completely when dealing with clojure data such as persistent maps or keywords

->set

(->set data)

Convert arbitrary data into a set appropriate for the data. For numeric types, javascript sets are fastest else use a clojure set.

add!

(add! list item)

Add an item to a list.

add-all!

(add-all! list items)

add a countable sequence of items to a list

as-agetable

(as-agetable item)

Return something that you can safely call (aget item idx) and that will return data of the same datatype. For :int64 this may return BigNum objects.

as-datatype-accurate-agetable

(as-datatype-accurate-agetable item)

Only reduce to an aget-able item of the datatypes match. This avoids throwing away js array wrappers that may do more checking and that can accurately advertise elemwise datatypes.

as-js-array

(as-js-array item)

Return the js array data backing this container. The object returned may have a different elemwise-datatype than the container.

as-typed-array

(as-typed-array item)

Return the typed array data backing this container. The object returned may have a different elemwise-datatype than the container.

clone

(clone item)

Here for compat with jvm system. All of the datatype objects implement ICloneable so cljs.core/clone works fine.

copy!

(copy! src dest)

Copy src container into dest container.

counted?

(counted? item)

Return true of js arrays and anything implementing ICounted.

datatype

(datatype item)

Get the dataytpe of this object.

ecount

(ecount item)

Compatibility with jvm-version. All of the datatype objects implement ICounted so cljs.core/count works fine.

elemwise-datatype

(elemwise-datatype item)

Get the datatype of the elements in the container.

emap

(emap map-fn ret-dtype & args)

elementwise map a function over a sequences. Returns a countable/indexable array of results.

ensure-capacity!

(ensure-capacity! list buflen)

Ensure the list has at least this much capacity without changing the number of inserted items

ensure-indexable

(ensure-indexable item)

Ensure this object is indexable. If object is not indexable this calles (vec item)

ensure-typed-array

(ensure-typed-array item)

Ensure that itme is a typed array. Only works for numeric datatypes.

indexed-buffer

(indexed-buffer indexes data)

Reindex the buffer via the given indexes returning a new buffer. Unlike the jvm version this most likely results in a new container.

indexed-iterate!

(indexed-iterate! consume-fn data)

Efficiently iterate through the data calling consum-fn and passing in an index for every item.

Returns consume-fn.

indexed?

(indexed? item)

Return true for js arrays and anything implementing IIndexed.

integer-range?

(integer-range? item)

Return true if this is a clojure integer range object.

iterate!

(iterate! consume-fn data)

Efficiently iterate through the data calling consume-fn on every item.

Returns consume-fn.

list-coalesce!

(list-coalesce! data container)

Coalesce a possibly nested set of data into a single container that implements the dtype list protocol.

Example:

cljs.user> (dtype/list-coalesce! [[2 3 4][5 6 7]] (dtype/make-list :float32))
#list[[:float32 6][2 3 4 5 6 7]

make-container

(make-container dtype len-or-data)

Return a packed container of data. Container implements count, nth, and meta, with-meta, and elemwise-datatype. Uses typed-arrays for most primitive types and generic js arrays for anything else. The container itself cannot check that the input matches the datatype so that form of checking is not available in the js version (unlike the jvm version).

make-list

(make-list dtype & [init-buf-size])

Make a list. Lists implement the tech.v3.datatype.protocols/PListLike protocol - add!, add-all!, ensure-capacity!

numeric-type?

(numeric-type? dtype)

Return true if this datatype is a numeric type. True for :int8, :uint8 -> :int64, :uint64, float32, float64.

reify-reader

(reify-reader dtype n-elems idx->val-fn)(reify-reader n-elems idx->val-fn)

Create a new reader of elemwise-datatype dtype. The returned reader correctly implements hash and equiv such that it is indistinguishable from a persistent vector created as (mapv idx->val-fn (range n-elems))

reverse

(reverse item)

set->ordered-indexes

(set->ordered-indexes data)

Create an ordered int32 buffer of the items in the set.

set-and

(set-and lhs rhs)

Perform set-intersection. Implemented for efficiently js sets and clojure sets.

set-and-not

(set-and-not lhs rhs)

Perform set-difference. Implemented for efficiently js sets and clojure sets.

set-constant!

(set-constant! item idx elem-count value)

Set a constant value starting at idx and continuing elem-count values.

set-offset

(set-offset lhs off)

Offset every member of the set by a constant returning a new set

set-or

(set-or lhs rhs)

Perform set-union. Implemented for efficiently js sets and clojure sets.

set-predicate

(set-predicate set)

Create a predicate out of a set. For js sets, calls .has and for Clojure sets just returns the set object.

set-predicate-complement

(set-predicate-complement set)

Create a not-in-set predicate. See docs for set-predicate

set-value!

(set-value! item idx data)

Set value on the item. data may be a scalar or a sequence or Indexable object in which case it will be copied into item starting at idx.

Returns item

shape

(shape item)

sub-buffer

(sub-buffer item off & [len])

Create a sub-buffer that in most cases shared the backing store data with the parent buffer

sub-buffer-copy

(sub-buffer-copy item off & [len])

Create a copy of the data in the item from offset till len.