dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
dlinear::onnx::Tensor Class Reference

Public Member Functions

 Tensor (std::initializer_list< std::int64_t > dims)
 Construct a tensor with the given dims.
 
 Tensor (std::int64_t value)
 Construct a tensor with the given value.
 
 Tensor (float value)
 Construct a tensor with the given value.
 
 Tensor (const std::vector< std::int64_t > &dims)
 Construct a tensor with the given dims.
 
 Tensor (xt::xarray< Expression > values)
 Construct a tensor with the given values.
 
 Tensor (const ::onnx::TensorProto &tensor)
 Construct a tensor with the given tensor.
 
 Tensor (const ::onnx::ValueInfoProto &value_info, const std::string &name)
 Construct a tensor with the given value_info.
 
const xt::xarray< Expression > & values () const
 Get read-only access to the values of the tensor.
 
std::size_t size () const
 Get read-only access to the size of the tensor.
 
std::size_t ndim () const
 Get read-only access to the number of dimensions of the tensor.
 
std::vector< std::int64_t > dims () const
 Get read-only access to the dimensions of the tensor.
 
std::int64_t dim (std::size_t i) const
 Get the dimension at index i of the tensor.
 
bool SameDim (const Tensor &o) const
 Check whether the two tensors have the same dimension.
 
bool Equal (const Tensor &o) const
 Compare two tensor to determine if they are equal.
 
TensorFlatten (std::int64_t axis)
 Flatten the tensor along the given axis.
 
TensorTranspose (const std::vector< std::int64_t > &perm={})
 Transpose the tensor with the given perm.
 
TensorReshape (std::initializer_list< std::int64_t > dims)
 Reshape the tensor with the given dims.
 
TensorReshape (const Tensor &tensor_dim, bool allow_zero)
 Reshape the tensor with the given tensor_dim.
 
TensorUnsqueeze (const Tensor &axes)
 Insert single-dimensional entries to the shape of an input tensor.
 
TensorAbs ()
 Apply the Abs function to the tensor.
 
TensorElementwise (const std::function< Expression(Expression)> &f)
 Apply the f function to each element of the tensor.
 
TensorSlice (const std::vector< std::int64_t > &starts, const std::vector< std::int64_t > &ends, const std::vector< std::int64_t > &axes={}, const std::vector< std::int64_t > &steps={})
 Slice the tensor with the given starts, ends, axes, and steps.
 
TensorSlice (const Tensor &starts, const Tensor &ends, const Tensor &axes={}, const Tensor &steps={})
 Slice the tensor with the given starts, ends, axes, and steps.
 
Tensor Concat (const Tensor &rhs, std::int64_t axis)
 Concatenate the tensor with the given rhs along the given axis.
 
Tensor Concat (const std::vector< Tensor > &rhs, std::int64_t axis)
 Concatenate the tensors with the given rhs along the given axis.
 
Tensor Gather (const Tensor &indices, std::int64_t axis)
 Gather the tensor with the given indices along the given axis.
 
Tensor MatMul (const Tensor &tensor) const
 Matrix multiplication of two tensors.
 
Tensor Convolution (const Tensor &w, const std::vector< std::int64_t > &dilations, std::int64_t group, const std::vector< std::int64_t > &kernel_shape, const std::vector< std::int64_t > &pads, const std::vector< std::int64_t > &strides) const
 Convolution of two tensors.
 
xt::xarray< ExpressionConvolution (const ImageView &image, const KernelView &kernel, const std::vector< std::size_t > &new_shape, const std::vector< std::int64_t > &dilations, std::int64_t group, const std::vector< std::int64_t > &pads, const std::vector< std::int64_t > &strides) const
 Convolution of two tensors.
 
Tensor Pad (const std::vector< std::int64_t > &pads) const
 Pad the tensor with the given pads.
 

Private Member Functions

std::size_t ComputeOffset (std::initializer_list< std::int64_t > dims) const
 Given a set of indices dims, compute the offset of the tensor.
 
std::size_t ComputeOffset (const std::int64_t *dims, std::size_t size) const
 Given a set of indices dims, compute the offset of the tensor.
 

Private Attributes

xt::xarray< Expressionvalues_
 Internal storage of the values of the tensor.
 

Detailed Description

Definition at line 22 of file Tensor.h.

Constructor & Destructor Documentation

◆ Tensor() [1/7]

dlinear::onnx::Tensor::Tensor ( std::initializer_list< std::int64_t > dims)

Construct a tensor with the given dims.

Parameters
dimsdimensions of the tensor

Definition at line 56 of file Tensor.cpp.

◆ Tensor() [2/7]

dlinear::onnx::Tensor::Tensor ( std::int64_t value)
explicit

Construct a tensor with the given value.

Parameters
valuesingle value of the tensor

Definition at line 58 of file Tensor.cpp.

◆ Tensor() [3/7]

dlinear::onnx::Tensor::Tensor ( float value)
explicit

Construct a tensor with the given value.

Parameters
valuesingle value of the tensor

Definition at line 60 of file Tensor.cpp.

◆ Tensor() [4/7]

dlinear::onnx::Tensor::Tensor ( const std::vector< std::int64_t > & dims)
explicit

Construct a tensor with the given dims.

Parameters
dimsdimensions of the tensor

Definition at line 62 of file Tensor.cpp.

◆ Tensor() [5/7]

dlinear::onnx::Tensor::Tensor ( xt::xarray< Expression > values)
explicit

Construct a tensor with the given values.

Parameters
valuesxarray of expressions

Definition at line 64 of file Tensor.cpp.

◆ Tensor() [6/7]

dlinear::onnx::Tensor::Tensor ( const ::onnx::TensorProto & tensor)
explicit

Construct a tensor with the given tensor.

Parameters
tensortensor proto from the ONNX model

Definition at line 72 of file Tensor.cpp.

◆ Tensor() [7/7]

dlinear::onnx::Tensor::Tensor ( const ::onnx::ValueInfoProto & value_info,
const std::string & name )
explicit

Construct a tensor with the given value_info.

Parameters
value_infovalue info proto from the ONNX model
nameprefix name to give to the variables in the tensor

Definition at line 66 of file Tensor.cpp.

Member Function Documentation

◆ Abs()

Tensor & dlinear::onnx::Tensor::Abs ( )

Apply the Abs function to the tensor.

ONNX documentation.

Returns
reference to the tensor

Definition at line 216 of file Tensor.cpp.

◆ ComputeOffset() [1/2]

std::size_t dlinear::onnx::Tensor::ComputeOffset ( const std::int64_t * dims,
std::size_t size ) const
nodiscardprivate

Given a set of indices dims, compute the offset of the tensor.

Parameters
dimsset of indices
sizesize of the set of indices
Returns
offset of the tensor

Definition at line 603 of file Tensor.cpp.

◆ ComputeOffset() [2/2]

std::size_t dlinear::onnx::Tensor::ComputeOffset ( std::initializer_list< std::int64_t > dims) const
nodiscardprivate

Given a set of indices dims, compute the offset of the tensor.

Parameters
dimsset of indices
Returns
offset of the tensor

Definition at line 599 of file Tensor.cpp.

◆ Concat() [1/2]

Tensor dlinear::onnx::Tensor::Concat ( const std::vector< Tensor > & rhs,
std::int64_t axis )

Concatenate the tensors with the given rhs along the given axis.

ONNX documentation.

Parameters
rhsother tensors to concatenate with
axisWhich axis to concat on. A negative value means counting dimensions from the back Accepted range is \([-r, r-1]\) where \(r = \text{rank(inputs)}\)
Returns
new tensor with the concatenated values

Definition at line 258 of file Tensor.cpp.

◆ Concat() [2/2]

Tensor dlinear::onnx::Tensor::Concat ( const Tensor & rhs,
std::int64_t axis )

Concatenate the tensor with the given rhs along the given axis.

ONNX documentation.

Parameters
rhsother tensor to concatenate with
axisWhich axis to concat on. A negative value means counting dimensions from the back Accepted range is \([-r, r-1]\) where \(r = \text{rank(inputs)}\)
Returns
new tensor with the concatenated values

Definition at line 254 of file Tensor.cpp.

◆ Convolution() [1/2]

xt::xarray< Expression > dlinear::onnx::Tensor::Convolution ( const ImageView & image,
const KernelView & kernel,
const std::vector< std::size_t > & new_shape,
const std::vector< std::int64_t > & dilations,
std::int64_t group,
const std::vector< std::int64_t > & pads,
const std::vector< std::int64_t > & strides ) const
nodiscard

Convolution of two tensors.

ONNX documentation.

Parameters
imageinput tensor
kernelconvolution kernel
new_shapeshape of the output tensor
dilationsdilation value along each spatial axis of the filter
groupnumber of groups input channels and output channels are divided into
padspadding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. pads format should be as follow \([x1_{begin}, x2_{begin} \dots x1_{end}, x2_{end} \dots]\), where \(xi_{begin}\) is the number of pixels added at the beginning of axis \(i\) and \(xi_{end}\) is the number of pixels added at the end of axis \(i\).
stridesstride along each spatial axis
Returns

Definition at line 352 of file Tensor.cpp.

◆ Convolution() [2/2]

Tensor dlinear::onnx::Tensor::Convolution ( const Tensor & w,
const std::vector< std::int64_t > & dilations,
std::int64_t group,
const std::vector< std::int64_t > & kernel_shape,
const std::vector< std::int64_t > & pads,
const std::vector< std::int64_t > & strides ) const
nodiscard

Convolution of two tensors.

ONNX documentation.

Parameters
wconvolution kernel with shape \([M, C, k_1, k_2, \dots, k_n]\)
dilationsdilation value along each spatial axis of the filter
groupnumber of groups input channels and output channels are divided into
kernel_shapeshape of the convolution kernel. If not present, should be inferred from input W
padspadding for the beginning and ending along each spatial axis, it can take any value greater than or equal to 0. The value represent the number of pixels added to the beginning and end part of the corresponding axis. pads format should be as follow \([x1_{begin}, x2_{begin} \dots x1_{end}, x2_{end} \dots]\), where \(xi_{begin}\) is the number of pixels added at the beginning of axis \(i\) and \(xi_{end}\) is the number of pixels added at the end of axis \(i\).
stridesstride along each spatial axis
Returns

Definition at line 302 of file Tensor.cpp.

◆ dim()

std::int64_t dlinear::onnx::Tensor::dim ( std::size_t i) const
nodiscard

Get the dimension at index i of the tensor.

If the dimension requested is not present, it will return 1.

Parameters
iindex of the dimension
Returns
the dimension at the given index
1 if the i is out of bounds

Definition at line 142 of file Tensor.cpp.

◆ dims()

std::vector< std::int64_t > dlinear::onnx::Tensor::dims ( ) const
nodiscard

Get read-only access to the dimensions of the tensor.

Returns
dimensions of the tensor

Definition at line 140 of file Tensor.cpp.

◆ Elementwise()

Tensor & dlinear::onnx::Tensor::Elementwise ( const std::function< Expression(Expression)> & f)

Apply the f function to each element of the tensor.

Parameters
ffunction to apply to each element
Returns
reference to the tensor

Definition at line 221 of file Tensor.cpp.

◆ Equal()

bool dlinear::onnx::Tensor::Equal ( const Tensor & o) const
nodiscard

Compare two tensor to determine if they are equal.

Parameters
oother object to compare against
Returns
true the two object are equal
false if the two objects are different

Definition at line 152 of file Tensor.cpp.

◆ Flatten()

Tensor & dlinear::onnx::Tensor::Flatten ( std::int64_t axis)

Flatten the tensor along the given axis.

ONNX documentation.

Parameters
axisaxis to flatten along
Returns
reference to the tensor

Definition at line 160 of file Tensor.cpp.

◆ Gather()

Tensor dlinear::onnx::Tensor::Gather ( const Tensor & indices,
std::int64_t axis )

Gather the tensor with the given indices along the given axis.

ONNX documentation.

Parameters
indicestensor of any rank \(q\). All index values are expected to be within bounds \([-s, s-1]\) along axis of size \(s\). It is an error if any of the index values are out of bounds
axiswhich axis to concat on. A negative value means counting dimensions from the back Accepted range is \([-r, r-1]\) where \(r = \text{rank(inputs)}\)
Returns
new tensor with the gathered values

Definition at line 265 of file Tensor.cpp.

◆ MatMul()

Tensor dlinear::onnx::Tensor::MatMul ( const Tensor & tensor) const
nodiscard

Matrix multiplication of two tensors.

ONNX documentation.

Parameters
tensortensor to multiply with
Returns
new tensor with the multiplied values

Definition at line 436 of file Tensor.cpp.

◆ ndim()

std::size_t dlinear::onnx::Tensor::ndim ( ) const
inlinenodiscard

Get read-only access to the number of dimensions of the tensor.

Returns
number of dimensions of the tensor

Definition at line 69 of file Tensor.h.

◆ Pad()

Tensor dlinear::onnx::Tensor::Pad ( const std::vector< std::int64_t > & pads) const
nodiscard

Pad the tensor with the given pads.

ONNX documentation.

Parameters
padspadding for the beginning and ending along each spatial axis

Definition at line 412 of file Tensor.cpp.

◆ Reshape() [1/2]

Tensor & dlinear::onnx::Tensor::Reshape ( const Tensor & tensor_dim,
bool allow_zero )

Reshape the tensor with the given tensor_dim.

ONNX documentation.

Parameters
tensor_dimtensor containing the dimensions to reshape the tensor
allow_zerowhether to allow zero in the dimensions
Returns
reference to the tensor

Definition at line 185 of file Tensor.cpp.

◆ Reshape() [2/2]

Tensor & dlinear::onnx::Tensor::Reshape ( std::initializer_list< std::int64_t > dims)

Reshape the tensor with the given dims.

ONNX documentation.

Parameters
dimsdimensions to reshape the tensor
Returns
reference to the tensor

Definition at line 181 of file Tensor.cpp.

◆ SameDim()

bool dlinear::onnx::Tensor::SameDim ( const Tensor & o) const
nodiscard

Check whether the two tensors have the same dimension.

Parameters
otensor to compare with
Returns
true if the two tensors have the same dimension
false if the two tensors have different dimensions

Definition at line 147 of file Tensor.cpp.

◆ size()

std::size_t dlinear::onnx::Tensor::size ( ) const
inlinenodiscard

Get read-only access to the size of the tensor.

Returns
size of the tensor

Definition at line 67 of file Tensor.h.

◆ Slice() [1/2]

Tensor & dlinear::onnx::Tensor::Slice ( const std::vector< std::int64_t > & starts,
const std::vector< std::int64_t > & ends,
const std::vector< std::int64_t > & axes = {},
const std::vector< std::int64_t > & steps = {} )

Slice the tensor with the given starts, ends, axes, and steps.

ONNX documentation.

Parameters
starts1-D tensor of starting indices of corresponding axis in axes
ends1-D tensor of ending indices (exclusive) of corresponding axis in axes
axes1-D tensor of axes that starts and ends apply to. Negative value means counting dimensions from the back. Accepted range is \([-r, r-1]\) where \(r = \text{rank(input)}\). Behavior is undefined if an axis is repeated.
steps1-D tensor of slice step of corresponding axis in axes. Negative value means slicing backward. Cannot be 0. Defaults to 1.
Returns
reference to the tensor

Definition at line 230 of file Tensor.cpp.

◆ Slice() [2/2]

Tensor & dlinear::onnx::Tensor::Slice ( const Tensor & starts,
const Tensor & ends,
const Tensor & axes = {},
const Tensor & steps = {} )

Slice the tensor with the given starts, ends, axes, and steps.

ONNX documentation.

Parameters
starts1-D tensor of starting indices of corresponding axis in axes
ends1-D tensor of ending indices (exclusive) of corresponding axis in axes
axes1-D tensor of axes that starts and ends apply to. Negative value means counting dimensions from the back. Accepted range is \([-r, r-1]\) where \(r = \text{rank(input)}\). Behavior is undefined if an axis is repeated
steps1-D tensor of slice step of corresponding axis in axes. Negative value means slicing backward. Cannot be 0. Defaults to 1
Returns
reference to the tensor

Definition at line 226 of file Tensor.cpp.

◆ Transpose()

Tensor & dlinear::onnx::Tensor::Transpose ( const std::vector< std::int64_t > & perm = {})

Transpose the tensor with the given perm.

ONNX documentation.

Parameters
permpermutation of the dimensions
Returns
reference to the tensor

Definition at line 211 of file Tensor.cpp.

◆ Unsqueeze()

Tensor & dlinear::onnx::Tensor::Unsqueeze ( const Tensor & axes)

Insert single-dimensional entries to the shape of an input tensor.

ONNX documentation.

Parameters
axesaxes along which the tensor will be unsqueezed
Returns
reference to the tensor

Definition at line 171 of file Tensor.cpp.

◆ values()

const xt::xarray< Expression > & dlinear::onnx::Tensor::values ( ) const
inlinenodiscard

Get read-only access to the values of the tensor.

Returns
values of the tensor

Definition at line 65 of file Tensor.h.


The documentation for this class was generated from the following files: