3#ifndef poplar_Tensor_hpp
4#define poplar_Tensor_hpp
7#include <poplar/Interval.hpp>
8#include <poplar/Type.hpp>
9#include <poplar/TypeTraits.hpp>
14struct VariableInterval;
67 Tensor slice(std::size_t begin, std::size_t end,
unsigned dimension)
const &;
68 Tensor &&
slice(std::size_t begin, std::size_t end,
unsigned dimension) &&;
77 return slice(begin, end, 0);
87 return slice(region.begin(), region.end(), dimension);
98 Tensor slice(ArrayRef<std::size_t> begin, ArrayRef<std::size_t> end)
const;
107 std::vector<Tensor>
slices(ArrayRef<Interval> intervals,
108 unsigned dimension = 0)
const;
121 slices(
const std::vector<std::vector<Interval>> &intervals,
122 unsigned dimension = 0)
const;
133 std::vector<Tensor>
slices(
const poplar::ArrayRef<unsigned> &indices,
134 unsigned dimension = 0)
const;
204 ArrayRef<unsigned> destination)
const;
273 ArrayRef<std::size_t> newDims)
const;
365 std::size_t
dim(
unsigned i)
const;
371 std::vector<std::size_t>
shape()
const;
427 return getConstantData(val, TypeTraits::make<T>());
440 std::ostream &
output(std::ostream &os)
const;
483 Tensor(std::unique_ptr<core::Tensor>);
484 core::Tensor &getImpl()
const {
return *impl; }
485 std::unique_ptr<core::Tensor> *getPImpl() {
return &impl; }
486 bool valid()
const {
return impl.get() !=
nullptr; }
521 std::unique_ptr<core::Tensor> impl;
522 bool getConstantData(
void *dst,
const TypeTraits &traits)
const;
526bool inline operator!=(
const Tensor &a,
const Tensor &b) {
return !(a == b); }
546 unsigned dimension = 0) {
547 return concat({first, second}, dimension);
565 return append(first, second, 0);
A reference to a subset of tensor elements.
Definition: Tensor.hpp:38
Tensor flatten(unsigned dimBegin, unsigned dimEnd) const
Flatten a subset of the dimensions of a tensor.
Tensor flatten() const
Flatten the tensor.
std::ostream & outputRegions(std::ostream &os) const
Display the regions of the tensor on a stream.
std::size_t numElements() const
Get the total number of elements in the tensor.
Tensor broadcast(unsigned N, unsigned dimension) const
Broadcast/repeat the tensor along a specified dimension.
void dumpRegions() const
Display the regions of the tensor.
std::ostream & output(std::ostream &os) const
Display the expression representing the tensor on a stream.
Tensor operator[](std::size_t i) const &
Get the sub-tensor indexed by i in the first dimension of the tensor.
Tensor slice(ArrayRef< std::size_t > begin, ArrayRef< std::size_t > end) const
Get the sub-tensor given by slicing the tensor in multiple dimensions, starting at dimension 0.
bool isContiguous() const
Get whether the tensor is contiguous.
Tensor reshape(ArrayRef< std::size_t > shape) const
Reshape the tensor.
bool getConstantValue(T *val) const
Read a single element of data from a tensor if it is a constant.
Definition: Tensor.hpp:426
Tensor squeeze(ArrayRef< std::size_t > indices) const
Reduce dimension of tensor by removing singleton dimensions at specified indices of tensor.
Tensor dimRoll(unsigned dimIdx, unsigned newIdx=0) const
Roll a specified dimension to the specified dimension.
Definition: Tensor.hpp:217
Type elementType() const
Get the element type information for this tensor.
bool intersectsWith(const Tensor &other) const
Return whether this tensor intersects with another tensor.
bool hasMetadata() const
Check that the tensor has a metadata tensor.
bool containsAliases() const
Get whether the tensor contains an alias to the same storage location.
Tensor upsample(unsigned scale, unsigned dimension, UpsampleMethod method) const
Upsample the tensor.
Tensor getMetadata() const
getMetadata() retrieves the metadata tensor associated with the data tensor.
std::vector< Tensor > slices(const poplar::ArrayRef< unsigned > &indices, unsigned dimension=0) const
Get a vector of slices.
Tensor subSample(unsigned stride, unsigned dimension) const
Sub-sample the tensor.
bool isParallelWriteable() const
Get whether the elements of this tensor can be written in parallel.
bool containsConstant() const
Get whether the tensor contains any constant tensors.
Tensor index(ArrayRef< std::size_t > indices) const
Get the sub-tensor indexed by the specified indices.
Tensor reinterpret(const Type &type) const
Reinterpret the tensor as a new type.
std::string shapeToString() const
Report the shape of a Tensor as a string.
Tensor slice(std::size_t begin, std::size_t end, unsigned dimension) const &
Get the sub-tensor given by a specific range [begin, end) in one dimension of the tensor.
unsigned rank() const
Get the rank of the tensor.
std::vector< Tensor > slices(ArrayRef< Interval > intervals, unsigned dimension=0) const
Get a vector of slices.
std::string getDebugStr() const
Get the debug name associated with the tensor.
Tensor dimShufflePartial(ArrayRef< unsigned > source, ArrayRef< unsigned > destination) const
Permute some of a tensor's dimensions.
const std::vector< Interval > getContiguousRegions() const
Get the contiguous regions of a tensor.
std::size_t dim(unsigned i) const
Get a dimension of the tensor.
Tensor dimShuffle(ArrayRef< unsigned > permutation) const
Permute the dimensions of a tensor.
Tensor transpose() const
Transpose a 2-dimensional tensor.
Definition: Tensor.hpp:300
void dump() const
Display the expression representing the tensor.
Tensor expand(ArrayRef< std::size_t > indices) const
Expand tensor by adding singleton dimensions at specified indices of tensor.
Tensor slice(std::size_t begin, std::size_t end) const
Get the sub-tensor given by a specific range [begin, end) in the first dimension of the tensor.
Definition: Tensor.hpp:76
std::vector< std::size_t > shape() const
Get the shape of the tensor.
std::string getVarStr() const
getVarStr() and getDebugStr() retrieve a summary (limited to the first underlying variable) of inform...
Tensor reshapePartial(unsigned beginIndex, unsigned endIndex, ArrayRef< std::size_t > newDims) const
Reshape a range of dimensions of a tensor.
Tensor reverse(unsigned dimension) const
reverse this tensor along a specified dimension.
std::vector< Tensor > slices(const std::vector< std::vector< Interval > > &intervals, unsigned dimension=0) const
Get a vector of slices.
Tensor slice(const Interval ®ion, unsigned dimension=0) const
Get the sub-tensor given by a specific range [begin, end) in one dimension of the tensor.
Definition: Tensor.hpp:86
const std::vector< VariableInterval > getVarRegions() const
Get the contiguous regions of a tensor with reference to the variables allocated in the graph.
Class representing device data types.
Definition: Type.hpp:42
Poplar classes and functions.
Definition: ArrayRef.hpp:14
std::ostream & operator<<(std::ostream &os, const DebugNameAndId &dnai)
Display the path name of the DebugNameAndId.
Tensor concat(ArrayRef< Tensor > ts, unsigned dimension=0)
Concatenate several tensors.
UpsampleMethod
Enum passed to Tensor::upsample(unsigned scale, unsigned dimension) specifying the upsampling method.
Definition: Tensor.hpp:22
@ REPEAT
If dimension is of size s, for every i in [0, s), repeats the subtensor at index i scale times.
Tensor append(const Tensor &first, const Tensor &second, unsigned dimension)
Append a tensor as an element to another tensor.
A structure to provide information about arithmetic (integer and floating point) types.
Definition: TypeTraits.hpp:22