Batching

Documentation for Batching.

Batching.batch_like โ€” Method
batch_like(input, output)

Return output as a batch similar to input, if input is a batch.

If input is not a AbstractBatch, then output is returned.

Examples

julia> xs = batch(ones(2, 3))
3-element Batching.ArrayBatch{SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.OneTo{Int64}, Int64}, true}, Matrix{Float64}, 2}:
 [1.0, 1.0]
 [1.0, 1.0]
 [1.0, 1.0]

julia> # Want to specialize `f` on the case of an `ArrayBatch`.
       function f(input::Batching.ArrayBatch)
           # Extract the underlying array.
           input_batch_maybe = Batching.value(input)
           # Broadcast `exp`.
           output_batch_maybe = exp.(input_batch_maybe)
           # Rewrap as a `batch` similar to `input`, e.g. preserving `eventdim(input)`.
           return batch_like(input, output_batch_maybe)
       end
f (generic function with 1 method)

julia> f(xs)
3-element Batching.ArrayBatch{SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.OneTo{Int64}, Int64}, true}, Matrix{Float64}, 2}:
 [2.718281828459045, 2.718281828459045]
 [2.718281828459045, 2.718281828459045]
 [2.718281828459045, 2.718281828459045]
source
Batching.value โ€” Method
value(x)

Returns the underlying storage used for the entire batch.

If x is not AbstractBatch, then this is the identity function.

source