Liking cljdoc? Tell your friends :D

uncomplicate.diamond.tensor

Contains type-agnostic general tensor functions. Does not contain functions related to deep neural networks (DNN); see the [[dnn]] namespace for these.

How to use

(ns test
  (:require [uncomplicate.diamond
             [tensor :refer :all]
             [native :refer :all]]))

Examples

The best and most accurate examples can be found in the comprehensive test suite, full examples, core tensor examples core DNN examples internal CPU engine tests, internal GPU engine tests,

There are quite a few tutorials on my blog dragan.rocks.

For the comprehensive real-world examples, with detailed tutorials and guides, see the Interactive Programming for Artificial intelligence book series, and specifically the Deep Learning for Programmers book.

Cheat Sheet

Tensors support typical core Fluokitten functions.

Contains type-agnostic general tensor functions. Does not contain functions related
to deep neural networks (DNN); see the [[dnn]] namespace for these.

### How to use

    (ns test
      (:require [uncomplicate.diamond
                 [tensor :refer :all]
                 [native :refer :all]]))

### Examples

The best and most accurate examples can be found in the
[comprehensive test suite](https://github.com/uncomplicate/deep-diamond/tree/master/test/uncomplicate/diamond),
[full examples](https://github.com/uncomplicate/deep-diamond/tree/master/test/uncomplicate/diamond/functional),
[core tensor examples](https://github.com/uncomplicate/deep-diamond/blob/master/test/uncomplicate/diamond/tensor_test.clj)
[core DNN examples](https://github.com/uncomplicate/deep-diamond/blob/master/test/uncomplicate/diamond/dnn_test.clj)
[internal CPU engine tests](https://github.com/uncomplicate/deep-diamond/tree/master/test/uncomplicate/diamond/internal/dnnl),
[internal GPU engine tests](https://github.com/uncomplicate/deep-diamond/tree/master/test/uncomplicate/diamond/internal/cudnn),


There are quite a few tutorials [on my blog dragan.rocks](http://dragan.rocks).

For the comprehensive real-world examples, with detailed tutorials and guides, see the
[Interactive Programming for Artificial intelligence book series](aiprobook.com), and specifically
the [Deep Learning for Programmers](https://aiprobook.com/deep-learning-for-programmers) book.

  ### Cheat Sheet

* Default engine (factory) binding: [[*diamond-factory*]], [[with-diamond]]. All functions can also receive
  engine through parameters.

* Tensor descriptor: [[desc]], [[shape]], [[layout]], [[data-type]],

* Create : [[tensor]], [[transformer]], [[batcher]], [[shuffler]]

* Inspect, transform, and manage tensors: [[view-tz]], [[revert]], [[input]], [[output]],
[[connector]], [[batch-size]], [[offset!]].


Tensors support typical core Fluokitten functions.
raw docstring

*diamond-factory*clj

The default factory binding. Most polymorphic functions that have factory as a parameter, have a version that uses this binding. The default is nil, though, and the user has to require a namespace that initializes and binds the default engine. The most common way is to require uncomplicate.diamond.native, which binds the DNNL based CPU engine as the default, but you are free to provide another implementation of your own, either by this root binding, or through Clojure's dynamic binding through with-diamond.

Please see [dnnl-tensor-test] for examples.

The default factory binding. Most polymorphic functions that have factory
as a parameter, have a version that uses this binding. The default is `nil`, though, and the
user has to require a namespace that initializes and binds the default engine. The most common
way is to require [[uncomplicate.diamond.native]], which binds the DNNL based CPU engine as the default,
but you are free to provide another implementation of your own, either by this root binding,
or through Clojure's dynamic binding through [[with-diamond]].

Please see [[dnnl-tensor-test]](https://github.com/uncomplicate/deep-diamond/blob/master/test/uncomplicate/diamond/internal/dnnl/dnnl_tensor_test.clj)
for examples.
raw docstring

batch-sizeclj

(batch-size x)

Determines batch size from tensor or descriptor's shape, depending on the context. Usually batch size is the first shape entry, but in some cases (RNN for example) it may be the second entry, or even something else.

Determines batch size from tensor or descriptor's shape, depending on the context.
Usually batch size is the first shape entry, but in some cases (RNN for example) it
may be the second entry, or even something else.
raw docstring

batcherclj

(batcher x y)
(batcher x y mb-size)

Creates a function that can transfer mini-batches of tensor x to tensor y.

Useful for, but not limited to, cycling through mini-batches during stochastic gradient descent. Assumes that the input data has already been shuffled (but does not depend on it technically).

Example:

(def t1 (tensor [2 3] :float :nc))
(def t2 (tensor [1 3] :float :cn))
(transfer! (range) t1)
(def bat (batcher t1 t2))

(bat)
=>
{:shape [1 3], :data-type :float, :layout [1 1]}
[   0.00    1.00    2.00 ]

(bat 1)
=>
{:shape [1 3], :data-type :float, :layout [1 1]}
[   3.00    4.00    5.00 ]
Creates a function that can transfer mini-batches of tensor `x` to tensor `y`.

Useful for, but not limited to, cycling through mini-batches
during stochastic gradient descent. Assumes that the input data has
already been shuffled (but does not depend on it technically).

Example:

    (def t1 (tensor [2 3] :float :nc))
    (def t2 (tensor [1 3] :float :cn))
    (transfer! (range) t1)
    (def bat (batcher t1 t2))

    (bat)
    =>
    {:shape [1 3], :data-type :float, :layout [1 1]}
    [   0.00    1.00    2.00 ]

    (bat 1)
    =>
    {:shape [1 3], :data-type :float, :layout [1 1]}
    [   3.00    4.00    5.00 ]
raw docstring

ConnectorCreatorcljprotocol

An object that can create a connection and provide its state in another shape, or gets its state from an object with another shape.

An object that can create a connection and provide its state in another shape,
or gets its state from an object with another shape.

connectorclj

(connector in out)

Creates a connector between in and out descriptor or tensor.

Creates a connector between `in` and `out` descriptor or tensor.
raw docstring

default-descclj

(default-desc tdesc)
(default-desc shape type)

Creates a general, technology-agnostic, tensor descriptor with default contiguous stride appropritate for input descriptors' shape.

Creates a general, technology-agnostic, tensor descriptor
with default contiguous stride appropritate for input descriptors' shape.
raw docstring

descclj

(desc tdesc)
(desc shape layout)
(desc shape type layout)

Creates a general, technology-agnostic, tensor descriptor.

The required parameter shape is a vector of tensor dimensions. Optionally, type and layout can be provided as keywords, that are later transformed to appropriate internal implementations supported by specific backends. Alternatively, layout might be provided as a vector of offsets.

Examples:

(desc [2 3 2]) => {:shape [2 3 2], :data-type nil, :layout nil}
(desc [2 3] :nc) => {:shape [2 3], :data-type nil, :layout :nc}
(desc [2 3 2 4] :nhwc) => {:shape [2 3 2 4], :data-type nil, :layout :nhwc}
Creates a general, technology-agnostic, tensor descriptor.

The required parameter `shape` is a vector of tensor dimensions.
Optionally, `type` and `layout` can be provided as keywords, that
are later transformed to appropriate internal implementations
supported by specific backends. Alternatively, `layout` might be
provided as a vector of offsets.

Examples:

    (desc [2 3 2]) => {:shape [2 3 2], :data-type nil, :layout nil}
    (desc [2 3] :nc) => {:shape [2 3], :data-type nil, :layout :nc}
    (desc [2 3 2 4] :nhwc) => {:shape [2 3 2 4], :data-type nil, :layout :nhwc}
raw docstring

offset!clj

(offset! tz n)

Destructively moves tensor's beginning to a different place in the underlying memory.

Destructively moves tensor's beginning to a different place in the underlying memory.
raw docstring

Revertcljprotocol

A directed transformation whose direction can be reverted.

A directed transformation whose direction can be reverted.

revertclj

(revert this)

Revert the direction of the transformation

Revert the direction of the transformation
raw docstring

shufflerclj

(shuffler x y)

Creates a function that can transfer randomly selected columns of tensor x to tensor y in mini-batches.

Useful for, but not limited to, cycling through mini-batches during stochastic gradient descent. The difference from batcher is that it randomly selects the grouping of columns. Shuffler is generally slower than plain batcher; it may or may not make a difference in speed.

Example:

(def t1 (tensor [2 3] :float :nc))
(def t2 (tensor [1 3] :float :cn))
(transfer! (range) t1)
(def bat (batcher t1 t2))

(bat)
=>
{:shape [1 3], :data-type :float, :layout [1 1]}
[   0.00    1.00    2.00 ]

(bat 1)
=>
{:shape [1 3], :data-type :float, :layout [1 1]}
[   3.00    4.00    5.00 ]
Creates a function that can transfer randomly selected columns
of tensor `x` to tensor `y` in mini-batches.

Useful for, but not limited to, cycling through mini-batches during
stochastic gradient descent. The difference from batcher is that it
randomly selects the grouping of columns. Shuffler is generally
slower than plain batcher; it may or may not make a difference in speed.

Example:

    (def t1 (tensor [2 3] :float :nc))
    (def t2 (tensor [1 3] :float :cn))
    (transfer! (range) t1)
    (def bat (batcher t1 t2))

    (bat)
    =>
    {:shape [1 3], :data-type :float, :layout [1 1]}
    [   0.00    1.00    2.00 ]

    (bat 1)
    =>
    {:shape [1 3], :data-type :float, :layout [1 1]}
    [   3.00    4.00    5.00 ]
raw docstring

tensorclj

(tensor desc)
(tensor tz-factory desc)
(tensor shape type layout)
(tensor tz-factory shape type layout)
(tensor tz-factory shape type layout batch-index)

Creates a technology-specific tensor.

The backend is determined by tz-factory, while the structure is provided either from a general or technology specific descriptor desc, or from directly provided descriptor parameters shape, type, and layout. If tz-factory is not provided, it is taken from the *diamond-factory* binding, which is by default [[internal/dnnl]].

Examples:

(tensor {:shape [2 3] :data-type :float :layout :nc})
=>
{:shape [2 3], :data-type :float, :layout [3 1]}
[   0.00    0.00    0.00    ⋯      0.00    0.00 ]

(tensor (desc [2 3] :float :nc))
=>
{:shape [2 3], :data-type :float, :layout [3 1]}
[   0.00    0.00    0.00    ⋯      0.00    0.00 ]

(tensor [2 3] :float :nc)
=>
{:shape [2 3], :data-type :float, :layout [3 1]}
[   0.00    0.00    0.00    ⋯      0.00    0.00 ]
Creates a technology-specific tensor.

The backend is determined by `tz-factory`, while the structure
is provided either from a general or technology specific descriptor
`desc`, or from directly provided descriptor parameters `shape`,
`type`, and `layout`. If `tz-factory` is not provided, it is
taken from the `*diamond-factory*` binding, which is by default
[[internal/dnnl]].

Examples:

    (tensor {:shape [2 3] :data-type :float :layout :nc})
    =>
    {:shape [2 3], :data-type :float, :layout [3 1]}
    [   0.00    0.00    0.00    ⋯      0.00    0.00 ]

    (tensor (desc [2 3] :float :nc))
    =>
    {:shape [2 3], :data-type :float, :layout [3 1]}
    [   0.00    0.00    0.00    ⋯      0.00    0.00 ]

    (tensor [2 3] :float :nc)
    =>
    {:shape [2 3], :data-type :float, :layout [3 1]}
    [   0.00    0.00    0.00    ⋯      0.00    0.00 ]
raw docstring

TensorContainercljprotocol

An object that can be viewed as a tensor.

An object that can be viewed as a tensor.

view-tzclj

(view-tz this)
(view-tz this sub)

View the object's underlying data through a (sub)tensor

View the object's underlying data through a (sub)tensor
raw docstring

TensorDescriptorcljprotocol

Generic tensor descriptor. Most Clojure and Java data types and structures (such as numbers, collections, persistent structures, etc. can be used as tensor descriptors). Technology-specific engines often provide their own implementation internally. Please see Deep Diamond tests, examples, and the Deep Learning for Programmers book.

Generic tensor descriptor. Most Clojure and Java data types and structures (such as numbers,
collections, persistent structures, etc. can be used as tensor descriptors). Technology-specific
engines often provide their own implementation internally. Please see Deep Diamond tests, examples,
and the [Deep Learning for Programmers](https://aiprobook.com/deep-learning-for-programmers) book.

data-typeclj

(data-type tz)

Data type of tensor entries (:float).

Data type of tensor entries (:float).

layoutclj

(layout tz)

Tensor layout, as a keyword (:nchw).

Tensor layout, as a keyword (:nchw).

shapeclj

(shape tz)

Tensor shape, as a vector ([2 3 4]).

Tensor shape, as a vector ([2 3 4]).
raw docstring

Transfercljprotocol

An operation that transfers input to output.

An operation that transfers input to output.

inputclj

(input this)

The input tensor of the Transfer.

The input tensor of the Transfer.

outputclj

(output this)

The output tensor of the Transfer.

The output tensor of the Transfer.
raw docstring

transformerclj

(transformer x y)

Creates a function optimized for transferring data from tensor x to tensor y.

Example:

(def t1 (tensor [2 3] :float :nc))
(transfer! (range) t1)
(def t2 (tensor [2 3] :float :cn))
(def tr-1-2 (transformer t1 t2))

(tr-1-2)
=>
{:shape [2 3], :data-type :float, :layout [1 2]}
[   0.00    3.00    1.00    ⋯      2.00    5.00 ]

t2
=>
{:shape [2 3], :data-type :float, :layout [1 2]}
[   0.00    3.00    1.00    ⋯      2.00    5.00 ]
Creates a function optimized for transferring data from tensor
`x` to tensor `y`.

Example:

    (def t1 (tensor [2 3] :float :nc))
    (transfer! (range) t1)
    (def t2 (tensor [2 3] :float :cn))
    (def tr-1-2 (transformer t1 t2))

    (tr-1-2)
    =>
    {:shape [2 3], :data-type :float, :layout [1 2]}
    [   0.00    3.00    1.00    ⋯      2.00    5.00 ]

    t2
    =>
    {:shape [2 3], :data-type :float, :layout [1 2]}
    [   0.00    3.00    1.00    ⋯      2.00    5.00 ]
raw docstring

with-diamondcljmacro

(with-diamond factory-fn params & body)

Dynamically binds a factory created by factory-fn with parameters params, and evaluates body in the context of that factory.

See [[*diamond-factory]].

Dynamically binds a factory created by `factory-fn` with parameters
`params`, and evaluates `body` in the context of that factory.

See [[*diamond-factory]].
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close