Documentation ¶
Index ¶
- func AllClose(tensor, other *Tensor, rtol, atol float64) bool
- func Equal(tensor, other *Tensor) bool
- func IsComplex(tensor *Tensor) bool
- func IsConj(tensor *Tensor) bool
- func IsDevice(deviceName string) bool
- func IsFloatingPoint(tensor *Tensor) bool
- func IsGradEnabled() bool
- func IsNonzero(tensor *Tensor) bool
- func ManualSeed(seed int64)
- func Numel(tensor *Tensor) int64
- func SetGradEnabled(value bool)
- func SetNumThreads(numThreads int32)
- func StdMean(tensor *Tensor) (*Tensor, *Tensor)
- func StdMeanByDim(tensor *Tensor, dim int, unbiased, keep_dims bool) (*Tensor, *Tensor)
- func ToSlice(tensor *Tensor) interface{}
- func TorchVersion() string
- func VarMean(tensor *Tensor) (*Tensor, *Tensor)
- func VarMeanByDim(tensor *Tensor, dim int, unbiased, keep_dims bool) (*Tensor, *Tensor)
- func Version() string
- type Device
- type Dtype
- type IValue
- func (ivalue *IValue) IsBool() bool
- func (ivalue *IValue) IsBoolList() bool
- func (ivalue *IValue) IsCapsule() bool
- func (ivalue *IValue) IsComplexDouble() bool
- func (ivalue *IValue) IsComplexDoubleList() bool
- func (ivalue *IValue) IsCustomClass() bool
- func (ivalue *IValue) IsDevice() bool
- func (ivalue *IValue) IsDouble() bool
- func (ivalue *IValue) IsDoubleList() bool
- func (ivalue *IValue) IsEnum() bool
- func (ivalue *IValue) IsFuture() bool
- func (ivalue *IValue) IsGenerator() bool
- func (ivalue *IValue) IsGenericDict() bool
- func (ivalue *IValue) IsInt() bool
- func (ivalue *IValue) IsIntList() bool
- func (ivalue *IValue) IsList() bool
- func (ivalue *IValue) IsModule() bool
- func (ivalue *IValue) IsNil() bool
- func (ivalue *IValue) IsObject() bool
- func (ivalue *IValue) IsPtrType() bool
- func (ivalue *IValue) IsPyObject() bool
- func (ivalue *IValue) IsQuantizer() bool
- func (ivalue *IValue) IsRRef() bool
- func (ivalue *IValue) IsScalar() bool
- func (ivalue *IValue) IsStorage() bool
- func (ivalue *IValue) IsStream() bool
- func (ivalue *IValue) IsString() bool
- func (ivalue *IValue) IsTensor() bool
- func (ivalue *IValue) IsTensorList() bool
- func (ivalue *IValue) IsTuple() bool
- func (ivalue *IValue) LengthDict() int64
- func (ivalue *IValue) LengthList() int64
- func (ivalue *IValue) LengthTuple() int64
- func (ivalue *IValue) ToBool() bool
- func (ivalue *IValue) ToComplexDouble() complex128
- func (ivalue *IValue) ToDevice() (device *Device)
- func (ivalue *IValue) ToDouble() float64
- func (ivalue *IValue) ToGenericDict() map[interface{}]*IValue
- func (ivalue *IValue) ToInt() int
- func (ivalue *IValue) ToList() []*IValue
- func (ivalue *IValue) ToNone() string
- func (ivalue *IValue) ToString() string
- func (ivalue *IValue) ToTensor() *Tensor
- func (ivalue *IValue) ToTensorList() []*Tensor
- func (ivalue *IValue) ToTuple() []*IValue
- type Tensor
- func Abs(tensor *Tensor) *Tensor
- func Abs_(tensor *Tensor) *Tensor
- func Add(tensor, other *Tensor, alpha float32) *Tensor
- func All(tensor *Tensor) *Tensor
- func AllByDim(tensor *Tensor, dim int, keep_dims bool) *Tensor
- func Any(tensor *Tensor) *Tensor
- func AnyByDim(tensor *Tensor, dim int, keep_dims bool) *Tensor
- func Arange(begin, end, step float32, options *TensorOptions) *Tensor
- func Argmax(tensor *Tensor) *Tensor
- func ArgmaxByDim(tensor *Tensor, dim int, keep_dims bool) *Tensor
- func Argmin(tensor *Tensor) *Tensor
- func ArgminByDim(tensor *Tensor, dim int, keep_dims bool) *Tensor
- func Cat(tensors []*Tensor, dim int64) *Tensor
- func Clamp(tensor, minimum, maximum *Tensor) *Tensor
- func ClampMax(tensor, maximum *Tensor) *Tensor
- func ClampMax_(tensor, maximum *Tensor) *Tensor
- func ClampMin(tensor, minimum *Tensor) *Tensor
- func ClampMin_(tensor, minimum *Tensor) *Tensor
- func Clamp_(tensor, minimum, maximum *Tensor) *Tensor
- func Concat(tensors []*Tensor, dim int64) *Tensor
- func Concatenate(tensors []*Tensor, dim int64) *Tensor
- func Decode(buffer []byte) (*Tensor, error)
- func Div(tensor, other *Tensor) *Tensor
- func Empty(size []int64, options *TensorOptions) *Tensor
- func EmptyLike(reference *Tensor) *Tensor
- func Eq(tensor, other *Tensor) *Tensor
- func Eye(n, m int64, options *TensorOptions) *Tensor
- func Flatten(tensor *Tensor, startDim, endDim int64) *Tensor
- func Full(size []int64, value float32, options *TensorOptions) *Tensor
- func FullLike(reference *Tensor, value float32) *Tensor
- func Greater(tensor, other *Tensor) *Tensor
- func GreaterEqual(tensor, other *Tensor) *Tensor
- func IndexSelect(tensor *Tensor, dim int64, index *Tensor) *Tensor
- func IsClose(tensor, other *Tensor, rtol, atol float64) *Tensor
- func IsFinite(tensor *Tensor) *Tensor
- func IsIn(tensor, other *Tensor) *Tensor
- func IsInf(tensor *Tensor) *Tensor
- func IsNaN(tensor *Tensor) *Tensor
- func IsNegInf(tensor *Tensor) *Tensor
- func IsPosInf(tensor *Tensor) *Tensor
- func IsReal(tensor *Tensor) *Tensor
- func Less(tensor, other *Tensor) *Tensor
- func LessEqual(tensor, other *Tensor) *Tensor
- func Linspace(begin, end float32, steps int64, options *TensorOptions) *Tensor
- func Load(path string) (*Tensor, error)
- func LogSoftmax(tensor *Tensor, dim int64) *Tensor
- func LogicalAnd(tensor, other *Tensor) *Tensor
- func LogicalNot(tensor *Tensor) *Tensor
- func LogicalOr(tensor, other *Tensor) *Tensor
- func LogicalXor(tensor, other *Tensor) *Tensor
- func Logspace(begin, end float32, steps int64, base float64, options *TensorOptions) *Tensor
- func MM(a, b *Tensor) *Tensor
- func Max(tensor *Tensor) *Tensor
- func Maximum(tensor, other *Tensor) *Tensor
- func Mean(tensor *Tensor) *Tensor
- func MeanByDim(tensor *Tensor, dim int, keep_dims bool) *Tensor
- func Median(tensor *Tensor) *Tensor
- func Min(tensor *Tensor) *Tensor
- func Minimum(tensor, other *Tensor) *Tensor
- func Mul(tensor, other *Tensor) *Tensor
- func NewTensor(data interface{}) *Tensor
- func NewTensorFromBlob(data unsafe.Pointer, dtype Dtype, sizes []int64) (output *Tensor)
- func NotEqual(tensor, other *Tensor) *Tensor
- func Ones(size []int64, options *TensorOptions) *Tensor
- func OnesLike(reference *Tensor) *Tensor
- func Permute(tensor *Tensor, dims ...int64) *Tensor
- func Pow(tensor *Tensor, exponent float64) *Tensor
- func Rand(size []int64, options *TensorOptions) *Tensor
- func RandInt(size []int64, low int64, high int64, options *TensorOptions) *Tensor
- func RandIntLike(reference *Tensor, low int64, high int64) *Tensor
- func RandLike(reference *Tensor) *Tensor
- func RandN(size []int64, options *TensorOptions) *Tensor
- func RandNLike(reference *Tensor) *Tensor
- func Range(begin, end, step float32, options *TensorOptions) *Tensor
- func Reshape(tensor *Tensor, shape ...int64) *Tensor
- func Sigmoid(tensor *Tensor) *Tensor
- func Slice(tensor *Tensor, dim, start, stop, step int64) *Tensor
- func Sqrt(tensor *Tensor) *Tensor
- func Sqrt_(tensor *Tensor) *Tensor
- func Square(tensor *Tensor) *Tensor
- func Square_(tensor *Tensor) *Tensor
- func Squeeze(tensor *Tensor, dim ...int64) *Tensor
- func Stack(tensors []*Tensor, dim int64) *Tensor
- func Std(tensor *Tensor) *Tensor
- func StdByDim(tensor *Tensor, dim int, unbiased bool, keep_dims bool) *Tensor
- func Sub(tensor, other *Tensor, alpha float32) *Tensor
- func Sum(tensor *Tensor) *Tensor
- func SumByDim(tensor *Tensor, dim int, keep_dims bool) *Tensor
- func Tanh(tensor *Tensor) *Tensor
- func TensorFromBlob(data unsafe.Pointer, dtype Dtype, sizes []int64) (output *Tensor)
- func Transpose(tensor *Tensor, dim0, dim1 int64) *Tensor
- func Unsqueeze(tensor *Tensor, dim int64) *Tensor
- func Var(tensor *Tensor) *Tensor
- func VarByDim(tensor *Tensor, dim int, unbiased, keep_dims bool) *Tensor
- func Zeros(size []int64, options *TensorOptions) *Tensor
- func ZerosLike(reference *Tensor) *Tensor
- func (tensor *Tensor) Abs() *Tensor
- func (tensor *Tensor) Abs_() *Tensor
- func (tensor *Tensor) Add(other *Tensor, alpha float32) *Tensor
- func (tensor *Tensor) Add_(other *Tensor, alpha float32) *Tensor
- func (tensor *Tensor) All() *Tensor
- func (tensor *Tensor) AllByDim(dim int, keep_dims bool) *Tensor
- func (tensor *Tensor) AllClose(other *Tensor, rtol, atol float64) bool
- func (tensor *Tensor) Any() *Tensor
- func (tensor *Tensor) AnyByDim(dim int, keep_dims bool) *Tensor
- func (tensor *Tensor) Argmax() *Tensor
- func (tensor *Tensor) ArgmaxByDim(dim int, keep_dims bool) *Tensor
- func (tensor *Tensor) Argmin() *Tensor
- func (tensor *Tensor) ArgminByDim(dim int, keep_dims bool) *Tensor
- func (tensor *Tensor) Backward()
- func (tensor *Tensor) CastTo(dtype Dtype) *Tensor
- func (tensor *Tensor) Clamp(minimum, maximum *Tensor) *Tensor
- func (tensor *Tensor) ClampMax(maximum *Tensor) *Tensor
- func (tensor *Tensor) ClampMax_(maximum *Tensor) *Tensor
- func (tensor *Tensor) ClampMin(minimum *Tensor) *Tensor
- func (tensor *Tensor) ClampMin_(minimum *Tensor) *Tensor
- func (tensor *Tensor) Clamp_(minimum, maximum *Tensor) *Tensor
- func (tensor *Tensor) Clone() (output *Tensor)
- func (tensor *Tensor) CopyTo(device *Device) *Tensor
- func (tensor *Tensor) Copy_(other *Tensor)
- func (tensor *Tensor) Detach() *Tensor
- func (tensor *Tensor) Dim() int64
- func (tensor *Tensor) Div(other *Tensor) *Tensor
- func (tensor *Tensor) Div_(other *Tensor) *Tensor
- func (tensor *Tensor) Dtype() Dtype
- func (tensor *Tensor) Encode() ([]byte, error)
- func (tensor *Tensor) Eq(other *Tensor) *Tensor
- func (tensor *Tensor) Equal(other *Tensor) bool
- func (tensor *Tensor) Expand(shape ...int64) *Tensor
- func (tensor *Tensor) ExpandAs(other *Tensor) *Tensor
- func (tensor *Tensor) Flatten(startDim, endDim int64) *Tensor
- func (tensor *Tensor) Grad() *Tensor
- func (tensor *Tensor) Greater(other *Tensor) *Tensor
- func (tensor *Tensor) GreaterEqual(other *Tensor) *Tensor
- func (tensor *Tensor) Index(index *Tensor) *Tensor
- func (tensor *Tensor) IndexSelect(dim int64, index *Tensor) *Tensor
- func (tensor *Tensor) IsClose(other *Tensor, rtol, atol float64) *Tensor
- func (tensor *Tensor) IsComplex() bool
- func (tensor *Tensor) IsConj() bool
- func (tensor *Tensor) IsFinite() *Tensor
- func (tensor *Tensor) IsFloatingPoint() bool
- func (tensor *Tensor) IsIn(other *Tensor) *Tensor
- func (tensor *Tensor) IsInf() *Tensor
- func (tensor *Tensor) IsNaN() *Tensor
- func (tensor *Tensor) IsNegInf() *Tensor
- func (tensor *Tensor) IsNonzero() bool
- func (tensor *Tensor) IsPosInf() *Tensor
- func (tensor *Tensor) IsReal() *Tensor
- func (tensor *Tensor) Item() interface{}
- func (tensor *Tensor) Less(other *Tensor) *Tensor
- func (tensor *Tensor) LessEqual(other *Tensor) *Tensor
- func (tensor *Tensor) LogSoftmax(dim int64) *Tensor
- func (tensor *Tensor) LogicalAnd(other *Tensor) *Tensor
- func (tensor *Tensor) LogicalNot() *Tensor
- func (tensor *Tensor) LogicalOr(other *Tensor) *Tensor
- func (tensor *Tensor) LogicalXor(other *Tensor) *Tensor
- func (tensor *Tensor) MM(other *Tensor) *Tensor
- func (tensor *Tensor) Max() *Tensor
- func (tensor *Tensor) MaxByDim(dim int, keep_dims bool) ValueIndexPair
- func (tensor *Tensor) Maximum(other *Tensor) *Tensor
- func (tensor *Tensor) Mean() *Tensor
- func (tensor *Tensor) MeanByDim(dim int, keep_dims bool) *Tensor
- func (tensor *Tensor) Median() *Tensor
- func (tensor *Tensor) MedianByDim(dim int, keep_dims bool) ValueIndexPair
- func (tensor *Tensor) Min() *Tensor
- func (tensor *Tensor) MinByDim(dim int, keep_dims bool) ValueIndexPair
- func (tensor *Tensor) Minimum(other *Tensor) *Tensor
- func (tensor *Tensor) Mul(other *Tensor) *Tensor
- func (tensor *Tensor) Mul_(other *Tensor) *Tensor
- func (tensor *Tensor) NotEqual(other *Tensor) *Tensor
- func (tensor *Tensor) Numel() int64
- func (tensor *Tensor) Permute(dims ...int64) *Tensor
- func (tensor *Tensor) Pow(exponent float64) *Tensor
- func (tensor *Tensor) RequiresGrad() bool
- func (tensor *Tensor) Reshape(shape ...int64) *Tensor
- func (tensor *Tensor) ReshapeAs(other *Tensor) *Tensor
- func (tensor *Tensor) Save(path string) error
- func (tensor *Tensor) SetData(other *Tensor)
- func (tensor *Tensor) SetRequiresGrad(requiresGrad bool)
- func (tensor *Tensor) Shape() []int64
- func (tensor *Tensor) Sigmoid() *Tensor
- func (tensor *Tensor) Slice(dim, start, stop, step int64) *Tensor
- func (tensor *Tensor) Sort(dim int64, descending bool) ValueIndexPair
- func (tensor *Tensor) Sqrt() *Tensor
- func (tensor *Tensor) Sqrt_() *Tensor
- func (tensor *Tensor) Square() *Tensor
- func (tensor *Tensor) Square_() *Tensor
- func (tensor *Tensor) Squeeze(dim ...int64) *Tensor
- func (tensor *Tensor) Std() *Tensor
- func (tensor *Tensor) StdByDim(dim int, unbiased bool, keep_dims bool) *Tensor
- func (tensor *Tensor) StdMean() (*Tensor, *Tensor)
- func (tensor *Tensor) StdMeanByDim(dim int, unbiased, keep_dims bool) (*Tensor, *Tensor)
- func (tensor *Tensor) String() string
- func (tensor *Tensor) Sub(other *Tensor, alpha float32) *Tensor
- func (tensor *Tensor) Sub_(other *Tensor, alpha float32) *Tensor
- func (tensor *Tensor) Sum() *Tensor
- func (tensor *Tensor) SumByDim(dim int, keep_dims bool) *Tensor
- func (tensor *Tensor) Tanh() *Tensor
- func (tensor *Tensor) To(device *Device, dtype Dtype) *Tensor
- func (tensor *Tensor) ToBytes() []byte
- func (tensor *Tensor) ToBytesUnsafe() []byte
- func (tensor *Tensor) ToSlice() interface{}
- func (tensor *Tensor) TopK(k, dim int64, largest, sorted bool) ValueIndexPair
- func (tensor *Tensor) Transpose(dim0, dim1 int64) *Tensor
- func (tensor *Tensor) Unsqueeze(dim int64) *Tensor
- func (tensor *Tensor) Var() *Tensor
- func (tensor *Tensor) VarByDim(dim int, unbiased, keep_dims bool) *Tensor
- func (tensor *Tensor) VarMean() (*Tensor, *Tensor)
- func (tensor *Tensor) VarMeanByDim(dim int, unbiased, keep_dims bool) (*Tensor, *Tensor)
- func (tensor *Tensor) View(shape ...int64) *Tensor
- func (tensor *Tensor) ViewAs(other *Tensor) *Tensor
- type TensorOptions
- type ValueIndexPair
- func MaxByDim(tensor *Tensor, dim int, keep_dims bool) ValueIndexPair
- func MedianByDim(tensor *Tensor, dim int, keep_dims bool) ValueIndexPair
- func MinByDim(tensor *Tensor, dim int, keep_dims bool) ValueIndexPair
- func Sort(tensor *Tensor, dim int64, descending bool) ValueIndexPair
- func TopK(tensor *Tensor, k, dim int64, largest, sorted bool) ValueIndexPair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllClose ¶
Return true if the two tensors are approximately equal to one another with given relative and absolute tolerances.
This function checks if all `tensor` and `other` satisfy the condition:
|tensor − other| <= atol + rtol * |other|
func IsFloatingPoint ¶
Return true if the tensor of a floating-point data-type.
func SetNumThreads ¶
func SetNumThreads(numThreads int32)
Set the number of threads used for intraop parallelism on CPU.
func StdMeanByDim ¶
Reduce a tensor to its mean value and standard deviation along given dimension.
func ToSlice ¶
func ToSlice(tensor *Tensor) interface{}
Convert a torch Tensor to a Go slice. This function implies a flattening of the tensor to return 1-dimensional vectors.
func VarMeanByDim ¶
Reduce a tensor to its mean value and variance along given dimension.
Types ¶
type Dtype ¶
type Dtype int8
An enumeration of the data-types available in torch. Typically it would be standard for "Invalid" to correspond to value 0; however, these codes are one-to-one with C++ codes in torch.
func GetDtypeOfKind ¶
Map an element type kind to its associated Dtype.
type IValue ¶
IValue wraps a C.IValue.
func NewIValue ¶
func NewIValue(data interface{}) (ivalue *IValue)
Create a new IValue from arbitrary data.
func (*IValue) IsBoolList ¶
Return true if the IValue is a list of booleans.
func (*IValue) IsComplexDouble ¶
Return true if the IValue is a complex double-precision floating-point value.
func (*IValue) IsComplexDoubleList ¶
Return true if the IValue is a list of complex double-precision floats.
func (*IValue) IsCustomClass ¶
Return true if the IValue is a custom class instance.
func (*IValue) IsDoubleList ¶
Return true if the IValue is a list of double-precision floats.
func (*IValue) IsGenerator ¶
Return true if the IValue is a Python generator.
func (*IValue) IsGenericDict ¶
Return true if the IValue is a dictionary.
func (*IValue) IsPyObject ¶
Return true if the IValue is a Python object instance.
func (*IValue) IsQuantizer ¶
Return true if the IValue is a quantizer.
func (*IValue) IsTensorList ¶
Return true if the IValue is a list of tensors.
func (*IValue) LengthDict ¶
If the ivalue is a dictionary, return the number of items in the dictionary.
func (*IValue) LengthList ¶
If the ivalue is a list, return the number of items in the list.
func (*IValue) LengthTuple ¶
If the ivalue is a tuple, return the number of items in the tuple.
func (*IValue) ToComplexDouble ¶
func (ivalue *IValue) ToComplexDouble() complex128
Convert the IValue to a complex double-precision float.
func (*IValue) ToGenericDict ¶
Convert the IValue to a generic dictionary of IValues (as a map of interfaces to IValues.)
func (*IValue) ToTensorList ¶
Convert the IValue to a list of tensors.
type Tensor ¶
Tensor wraps a pointer to a C.Tensor as an unsafe Pointer.
func Arange ¶
func Arange(begin, end, step float32, options *TensorOptions) *Tensor
Create an inclusive range tensor from begin position to end position along integer step size.
func ArgmaxByDim ¶
Reduce a tensor to its maximum index along the given dimension.
func ArgminByDim ¶
Reduce a tensor to its minimum index along the given dimension.
func Cat ¶
Concatenate the given sequence of tensors in the given dimension. All tensors must either have the same shape (except in the concatenating dimension) or be empty.
func Empty ¶
func Empty(size []int64, options *TensorOptions) *Tensor
Create a new tensor of given size filled with empty values.
func Flatten ¶
Flattens input dimensions by reshaping them into a one-dimensional tensor. Only dimensions starting with start_dim and ending with end_dim are flattened. The order of elements in input is unchanged.
Unlike NumPy’s flatten, which always copies input’s data, this function may return the original object, a view, or copy. If no dimensions are flattened, then the original object input is returned. Otherwise, if input can be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the flattened shape is input’s data copied. See (torch.Tensor).View() for details on when a view will be returned.
func Full ¶
func Full(size []int64, value float32, options *TensorOptions) *Tensor
Create a new tensor of given size filled with static values.
func GreaterEqual ¶
Compute tensor >= other element-wise.
func IndexSelect ¶
Return a new tensor which indexes the input tensor along dimension dim using the entries in index which is a LongTensor. The returned tensor has the same number of dimensions as the original tensor (input). The dimth dimension has the same size as the length of index; other dimensions have the same size as in the original tensor.
func IsClose ¶
Create a new tensor describing the element-wise approximate equality of two tensors with given relative and absolute tolerances.
This function checks if all `tensor` and `other` satisfy the condition:
|tensor − other| <= atol + rtol * |other|
func IsIn ¶
Test if each element of tensor is in other. Returns a boolean tensor of the same shape as tensor that is True for elements in other and False otherwise.
func IsNaN ¶
Returns a new tensor with boolean elements representing if each element of input is NaN or not. Complex values are considered NaN when either their real and/or imaginary part is NaN.
func IsReal ¶
Return a new tensor with boolean elements representing if each element of input is real-valued or not. All real-valued types are considered real. Complex values are considered real when their imaginary part is 0.
func Linspace ¶
func Linspace(begin, end float32, steps int64, options *TensorOptions) *Tensor
Create an linear space tensor from begin to end with given number of total steps.
func LogSoftmax ¶
Apply a softmax followed by a logarithm.
While mathematically equivalent to log(softmax(x)), doing these two operations separately is slower and numerically unstable. This function uses an alternative formulation to compute the output and gradient correctly.
func LogicalAnd ¶
Compute the element-wise logical AND of the given input tensors. Zeros are treated as False and non-zeros are treated as True.
func LogicalNot ¶
Computes the element-wise logical NOT of the given input tensor. If the input tensor is not a bool tensor, zeros are treated as False and non-zeros are treated as True.
func LogicalOr ¶
Compute the element-wise logical OR of the given input tensors. Zeros are treated as False and non-zeros are treated as True.
func LogicalXor ¶
Compute the element-wise logical XOR of the given input tensors. Zeros are treated as False and non-zeros are treated as True.
func Logspace ¶
func Logspace(begin, end float32, steps int64, base float64, options *TensorOptions) *Tensor
Create an logarithmic space tensor from begin to end with given number of total steps.
func MM ¶
Perform a matrix multiplication of the matrices A and B. If A is an (n×m) tensor, B is an (m×p) tensor, the output will be an (n×p) tensor.
func NewTensorFromBlob ¶
Create a new tensor that clones existing contiguous memory pointed to by data, of given data-type, and with given size. This function copies the input data, so subsequent in-place operations performed on the tensor will not mutate the input data.
func Ones ¶
func Ones(size []int64, options *TensorOptions) *Tensor
Create a new tensor of given size filled with ones.
func Pow ¶
Take the power of each element in input with exponent and returns a tensor with the result.
func Rand ¶
func Rand(size []int64, options *TensorOptions) *Tensor
Create a new tensor of given size filled with uniform random values.
func RandInt ¶
func RandInt(size []int64, low int64, high int64, options *TensorOptions) *Tensor
Create a new tensor of given size filled with random integers in [low, high).
func RandIntLike ¶
Create a tensor filled with random integers in [low, high) in the shape of a reference.
func RandN ¶
func RandN(size []int64, options *TensorOptions) *Tensor
Create a new tensor of given size filled with Gaussian random values.
func Range ¶
func Range(begin, end, step float32, options *TensorOptions) *Tensor
Create an exclusive range tensor from begin position to end position along integer step size.
func Sigmoid ¶
Computes the expit (also known as the logistic sigmoid function) of the elements of input.
func Slice ¶
Perform NumPy-like tensor slicing where dim is the dimension to slice along, start and stop determine the [start, stop) bounds of the index, and step describes the spacing between elements in the slice.
func Squeeze ¶
Return a tensor with all the dimensions of input of size 1 removed. For example, if input is of shape: (A×1×B×C×1×D) then the out tensor will be of shape: (A×B×C×D). When dim is given, a squeeze operation is done only in the given dimension. If input is of shape: (A×1×B), squeeze(input, 0) leaves the tensor unchanged, but squeeze(input, 1) will squeeze the tensor to the shape (A×B).
func Stack ¶
Concatenate a sequence of tensors along a new dimension. All tensors need to be of the same size.
func TensorFromBlob ¶
Create a tensor view that wraps around existing contiguous memory pointed to by data, of given data-type, and with given size. This function does not copy the data buffer so in-place operations performed on the tensor will mutate the input buffer.
func Transpose ¶
Return a tensor that is a transposed version of input. The given dimensions dim0 and dim1 are swapped.
If input is a strided tensor then the resulting out tensor shares its underlying storage with the input tensor, so changing the content of one would change the content of the other.
If input is a sparse tensor then the resulting out tensor does not share the underlying storage with the input tensor.
If input is a sparse tensor with compressed layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments dim0 and dim1 must be both batch dimensions, or must both be sparse dimensions. The batch dimensions of a sparse tensor are the dimensions preceding the sparse dimensions.
func Unsqueeze ¶
Return a new tensor with a dimension of size one inserted at the specified position. The returned tensor shares the same underlying data with this tensor. A dim value within the range [-input.dim() - 1, input.dim() + 1) can be used. Negative dim will correspond to unsqueeze() applied at dim = dim + input.dim() + 1.
func Zeros ¶
func Zeros(size []int64, options *TensorOptions) *Tensor
Create a new tensor of given size filled with zeros.
func (*Tensor) AllByDim ¶
Check if all values in the tensor evaluate to true along the given dimension.
func (*Tensor) AllClose ¶
Return true if the tensor is approximately equal to another with given relative and absolute tolerances.
This function checks if all `tensor` and `other` satisfy the condition:
|tensor − other| <= atol + rtol * |other|
func (*Tensor) AnyByDim ¶
Check if any values in the tensor evaluate to true along the given dimension.
func (*Tensor) ArgmaxByDim ¶
Reduce a tensor to its maximum index along the given dimension.
func (*Tensor) ArgminByDim ¶
Reduce a tensor to its minimum index along the given dimension.
func (*Tensor) Backward ¶
func (tensor *Tensor) Backward()
Compute gradients based on the results of a forward pass through the tensor.
func (*Tensor) Encode ¶
Encode a tensor into a pickled representation. Tensors are copied to the CPU before encoding.
func (*Tensor) Flatten ¶
Flattens input dimensions by reshaping them into a one-dimensional tensor. Only dimensions starting with start_dim and ending with end_dim are flattened. The order of elements in input is unchanged.
Unlike NumPy’s flatten, which always copies input’s data, this function may return the original object, a view, or copy. If no dimensions are flattened, then the original object input is returned. Otherwise, if input can be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the flattened shape is input’s data copied. See (torch.Tensor).View() for details on when a view will be returned.
func (*Tensor) GreaterEqual ¶
Compute tensor >= other element-wise.
func (*Tensor) IndexSelect ¶
Return a new tensor which indexes the input tensor along dimension dim using the entries in index which is a LongTensor. The returned tensor has the same number of dimensions as the original tensor (input). The dimth dimension has the same size as the length of index; other dimensions have the same size as in the original tensor.
func (*Tensor) IsClose ¶
Create a new tensor describing the element-wise approximate equality of the tensor to another with given relative and absolute tolerances.
This function checks if all `tensor` and `other` satisfy the condition:
|tensor − other| <= atol + rtol * |other|
func (*Tensor) IsFloatingPoint ¶
Return true if the tensor of a floating-point data-type.
func (*Tensor) IsIn ¶
Test if each element of tensor is in other. Returns a boolean tensor of the same shape as tensor that is True for elements in other and False otherwise.
func (*Tensor) IsInf ¶
Test if each element of the tensor is infinite (positive or negative) or not.
func (*Tensor) IsNaN ¶
Returns a new tensor with boolean elements representing if each element of input is NaN or not. Complex values are considered NaN when either their real and/or imaginary part is NaN.
func (*Tensor) IsReal ¶
Return a new tensor with boolean elements representing if each element of input is real-valued or not. All real-valued types are considered real. Complex values are considered real when their imaginary part is 0.
func (*Tensor) Item ¶
func (tensor *Tensor) Item() interface{}
Return the value of this tensor as a standard Go number. This only works for tensors with one element.
Users can do type assertion and get the value like:
```
if value, ok := a.Item().(float64); ok { // process the value }
```
This function currently only supports signed data types.
func (*Tensor) LogSoftmax ¶
Apply a softmax followed by a logarithm.
While mathematically equivalent to log(softmax(x)), doing these two operations separately is slower and numerically unstable. This function uses an alternative formulation to compute the output and gradient correctly.
func (*Tensor) LogicalAnd ¶
Compute the element-wise logical AND of the given input tensors. Zeros are treated as False and non-zeros are treated as True.
func (*Tensor) LogicalNot ¶
Computes the element-wise logical NOT of the given input tensor. If the input tensor is not a bool tensor, zeros are treated as False and non-zeros are treated as True.
func (*Tensor) LogicalOr ¶
Compute the element-wise logical OR of the given input tensors. Zeros are treated as False and non-zeros are treated as True.
func (*Tensor) LogicalXor ¶
Compute the element-wise logical XOR of the given input tensors. Zeros are treated as False and non-zeros are treated as True.
func (*Tensor) MM ¶
Perform a matrix multiplication of the matrices A and B. If A is an (n×m) tensor, B is an (m×p) tensor, the output will be an (n×p) tensor.
func (*Tensor) MaxByDim ¶
func (tensor *Tensor) MaxByDim(dim int, keep_dims bool) ValueIndexPair
Reduce a tensor to its maximum value along the given dimension.
func (*Tensor) MedianByDim ¶
func (tensor *Tensor) MedianByDim(dim int, keep_dims bool) ValueIndexPair
Reduce a tensor to its median value along the given dimension.
func (*Tensor) MinByDim ¶
func (tensor *Tensor) MinByDim(dim int, keep_dims bool) ValueIndexPair
Reduce a tensor to its minimum value along the given dimension.
func (*Tensor) Pow ¶
Take the power of each element in input with exponent and returns a tensor with the result.
func (*Tensor) RequiresGrad ¶
Return true if the tensor is taping gradients.
func (*Tensor) ReshapeAs ¶
Create a new tensor with an updated shape according to a reference tensor.
func (*Tensor) SetRequiresGrad ¶
Set the gradient taping state of the tensor to a new value.
func (*Tensor) Sigmoid ¶
Computes the expit (also known as the logistic sigmoid function) of the elements of input.
func (*Tensor) Slice ¶
Perform NumPy-like tensor slicing where dim is the dimension to slice along, start and stop determine the [start, stop) bounds of the index, and step describes the spacing between elements in the slice.
func (*Tensor) Sort ¶
func (tensor *Tensor) Sort(dim int64, descending bool) ValueIndexPair
Sort the elements of the input tensor along a given dimension by value. If descending is True then the elements are sorted in descending order by value. A struct of (Values, Indices) is returned, where the values are the sorted values and indices are the indices of the elements in the original input tensor.
func (*Tensor) Squeeze ¶
Return a tensor with all the dimensions of input of size 1 removed. For example, if input is of shape: (A×1×B×C×1×D) then the out tensor will be of shape: (A×B×C×D). When dim is given, a squeeze operation is done only in the given dimension. If input is of shape: (A×1×B), squeeze(input, 0) leaves the tensor unchanged, but squeeze(input, 1) will squeeze the tensor to the shape (A×B).
func (*Tensor) StdMeanByDim ¶
Reduce a tensor to its mean value and standard deviation along given dimension.
func (*Tensor) ToBytes ¶
Convert a tensor to a raw binary representation as a byte slice. Note that this operation implies a safe copy of the underlying data. There are no garbage collector side-effects from usage of this function.
func (*Tensor) ToBytesUnsafe ¶
Convert a tensor to a raw binary representation as a byte slice. Note that this is a copy-free operation and simply returns a slice with its header updated to point to the underlying tensor data. If the tensor is garbage collected, the slice will be invalidated. Usage of this function typically requires calls to `runtime.KeepAlive(tensor)` for the input tensor to prevent accidentally freeing the tensor before the byte slice is consumed.
func (*Tensor) ToSlice ¶
func (tensor *Tensor) ToSlice() interface{}
Convert the Tensor to a Go slice. This function implies a flattening of the tensor to return a 1-dimensional vector.
func (*Tensor) TopK ¶
func (tensor *Tensor) TopK(k, dim int64, largest, sorted bool) ValueIndexPair
Return the k largest elements of the given input tensor along a given dimension. If largest is False then the k smallest elements are returned. A struct of (Values, Indices) is returned with the values and indices of the largest k elements of each row of the input tensor in the given dimension dim. The boolean option sorted if True, will make sure that the returned k elements are themselves sorted.
func (*Tensor) Transpose ¶
Return a tensor that is a transposed version of input. The given dimensions dim0 and dim1 are swapped.
If input is a strided tensor then the resulting out tensor shares its underlying storage with the input tensor, so changing the content of one would change the content of the other.
If input is a sparse tensor then the resulting out tensor does not share the underlying storage with the input tensor.
If input is a sparse tensor with compressed layout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the arguments dim0 and dim1 must be both batch dimensions, or must both be sparse dimensions. The batch dimensions of a sparse tensor are the dimensions preceding the sparse dimensions.
func (*Tensor) Unsqueeze ¶
Return a new tensor with a dimension of size one inserted at the specified position. The returned tensor shares the same underlying data with this tensor. A dim value within the range [-input.dim() - 1, input.dim() + 1) can be used. Negative dim will correspond to unsqueeze() applied at dim = dim + input.dim() + 1.
func (*Tensor) VarMeanByDim ¶
Reduce a tensor to its mean value and variance along given dimension.
type TensorOptions ¶
type TensorOptions struct {
Pointer C.TensorOptions
}
TensorOptions wraps a C.TensorOptions.
func NewTensorOptions ¶
func NewTensorOptions() (options *TensorOptions)
Create a new TensorOptions.
func (*TensorOptions) Device ¶
func (options *TensorOptions) Device(device Device) *TensorOptions
Create a new TensorOptions with the given compute device.
func (*TensorOptions) Dtype ¶
func (options *TensorOptions) Dtype(value Dtype) *TensorOptions
Create a new TensorOptions with the given data type.
func (*TensorOptions) PinnedMemory ¶
func (options *TensorOptions) PinnedMemory(pinnedMemory bool) *TensorOptions
Create a new TensorOptions with the given memory pinning state.
func (*TensorOptions) RequiresGrad ¶
func (options *TensorOptions) RequiresGrad(requiresGrad bool) *TensorOptions
Create a new TensorOptions with the given gradient taping state.
type ValueIndexPair ¶
type ValueIndexPair struct {
Values, Indices *Tensor
}
A representation of the return type for a paired value/index selection call.
func MaxByDim ¶
func MaxByDim(tensor *Tensor, dim int, keep_dims bool) ValueIndexPair
Reduce a tensor to its maximum value along the given dimension.
func MedianByDim ¶
func MedianByDim(tensor *Tensor, dim int, keep_dims bool) ValueIndexPair
Reduce a tensor to its median value along the given dimension.
func MinByDim ¶
func MinByDim(tensor *Tensor, dim int, keep_dims bool) ValueIndexPair
Reduce a tensor to its minimum value along the given dimension.
func Sort ¶
func Sort(tensor *Tensor, dim int64, descending bool) ValueIndexPair
Sort the elements of the input tensor along a given dimension by value. If descending is True then the elements are sorted in descending order by value. A struct of (Values, Indices) is returned, where the values are the sorted values and indices are the indices of the elements in the original input tensor.
func TopK ¶
func TopK(tensor *Tensor, k, dim int64, largest, sorted bool) ValueIndexPair
Return the k largest elements of the given input tensor along a given dimension. If largest is False then the k smallest elements are returned. A struct of (Values, Indices) is returned with the values and indices of the largest k elements of each row of the input tensor in the given dimension dim. The boolean option sorted if True, will make sure that the returned k elements are themselves sorted.