10 #include <autogradpp/autograd.h> 12 #include <cnpy/cnpy.h> 13 #endif // WITHOUT_POSIX 24 torch::Tensor
repeat2d(torch::Tensor data, at::IntList sizes);
52 scatterSum2d(torch::Tensor positions, torch::Tensor data, at::IntList sizes);
62 torch::Tensor
makeBatch(ag::tensor_list
const&,
double pad = 0);
77 const std::vector<ag::Variant>& queries,
90 ag::Variant
const& batch,
93 double maskValue = -1);
96 torch::Tensor
pad2d(torch::Tensor input, at::IntList pad);
101 torch::Tensor
padNd(torch::Tensor input, at::IntList pad);
107 torch::Tensor
flip(torch::Tensor x,
int dim);
118 #ifndef WITHOUT_POSIX 120 #endif // WITHOUT_POSIX 128 torch::Tensor
squash(torch::Tensor x,
int i,
int j);
140 torch::Tensor
unsquash(torch::Tensor x,
int i, at::IntList sizes);
149 torch::Tensor
maskedSum(torch::Tensor x, torch::Tensor mask);
158 torch::Tensor
maskedMean(torch::Tensor x, torch::Tensor mask);
173 bool sizeAverage =
true,
197 torch::Tensor target,
198 torch::Tensor weight = {},
199 torch::Tensor mask = {},
200 Reduction::Reduction = Reduction::Reduction::Mean);
219 torch::Tensor target,
220 torch::Tensor weight = {},
221 torch::Tensor mask = {},
222 Reduction::Reduction = Reduction::Reduction::Mean);
246 float clampEpsilon = 0);
261 std::tuple<torch::Tensor, torch::Tensor>
maskedMax(
265 bool keepDim =
false);
284 float clampEpsilon = 0);
291 torch::Tensor
extendIndex(torch::Tensor y,
int axis,
int d);
297 void maskedCopy_(torch::Tensor x, torch::Tensor mask, torch::Tensor source);
305 maskedCopy(torch::Tensor x, torch::Tensor mask, torch::Tensor source);
320 torch::Tensor source,
321 bool accumulate =
false);
331 torch::Tensor
takeNd(torch::Tensor x, torch::Tensor index);
342 indexMean(
int size,
int dim, torch::Tensor index, torch::Tensor source);
347 torch::Tensor
unsqueezes(
int before, torch::Tensor x,
int after);
353 torch::Tensor
meshGrid(ag::tensor_list tensors);
torch::Tensor extendIndex(torch::Tensor y, int axis, int d)
Returns a byte tensor x such that selectIndex(x, y, axis) are only 1s.
Definition: operations.cpp:700
void putNd_(torch::Tensor x, torch::Tensor index, torch::Tensor source, bool accumulate)
Copies elements from source into x at positions determined by index.
Definition: operations.cpp:743
torch::Tensor meshGrid(ag::tensor_list tensors)
Takes N 1D tensors xi of size Xi and returns a tensor y of size X1 x ...
Definition: operations.cpp:795
torch::Tensor unsquash(torch::Tensor x, int i, at::IntList sizes)
Unsquash a dimension of a tensor into several dimensions.
Definition: operations.cpp:484
torch::Tensor pad2d(torch::Tensor input, at::IntList pad)
Zero-padding (only supports 3d input)
Definition: operations.cpp:344
torch::Tensor maskedSoftmax(torch::Tensor input, torch::Tensor mask, int dim, float clampEpsilon)
Compute a masked softmax of a tensor in a numerically stable way by removing the max value before exp...
Definition: operations.cpp:615
torch::Tensor maskedSum(torch::Tensor x, torch::Tensor mask)
Sum x across non-masked indices.
Definition: operations.cpp:495
torch::Tensor indexMean(int size, int dim, torch::Tensor index, torch::Tensor source)
Like zeros.index_add_ but with the mean.
Definition: operations.cpp:758
torch::Tensor mseLoss(torch::Tensor x, torch::Tensor y, torch::Tensor mask, bool sizeAverage, bool reduce)
Computes the MSE loss between x and y.
Definition: operations.cpp:521
torch::Tensor padNd(torch::Tensor input, at::IntList pad)
Zero-padding (for any number of dimensions) For every dimensions of the input, pad contains 2 element...
Definition: operations.cpp:371
UpsampleMode
Mimics pytorch's upsample function.
Definition: operations.h:110
ag::Variant makeBatchVariant(const std::vector< ag::Variant > &queries, double pad)
This function works similarly as makeBatch but handles more input types.
Definition: operations.cpp:221
torch::Tensor scatterSum2d(torch::Tensor positions, torch::Tensor data, at::IntList sizes)
Scatter data into dest at given positions.
Definition: operations.cpp:164
torch::Tensor unsqueezes(int before, torch::Tensor x, int after)
Do multiple unsqueezes on first and last dimensions.
Definition: operations.cpp:781
torch::Tensor crossEntropyLoss(torch::Tensor input, int dim, torch::Tensor target, torch::Tensor weight, torch::Tensor mask, Reduction::Reduction reduction)
Definition: operations.cpp:537
torch::Tensor squash(torch::Tensor x, int i, int j)
Squash contiguous dimensions of a tensor into a single dimension.
Definition: operations.cpp:470
torch::Tensor maskedCopy(torch::Tensor x, torch::Tensor mask, torch::Tensor source)
Immutable masked copy (equivalent to x.clone().maskedCopy_()).
Definition: operations.cpp:715
torch::Tensor flip(torch::Tensor x, int dim)
Flips a tensor along a given dimension.
Definition: operations.cpp:395
torch::Tensor upsample(torch::Tensor input, UpsampleMode mode, at::IntList size)
Definition: operations.cpp:441
torch::Tensor maskedMean(torch::Tensor x, torch::Tensor mask)
Average x over non-masked indices, returning 0 if all indices are masked.
Definition: operations.cpp:500
torch::Tensor takeNd(torch::Tensor x, torch::Tensor index)
Inverse operation of putNd_.
Definition: operations.cpp:752
void maskedCopy_(torch::Tensor x, torch::Tensor mask, torch::Tensor source)
For 1D tensors, this is equivalent to: x[i] <- source[i] if mask[i] == 1.
Definition: operations.cpp:709
at::Device getVariantDevice(ag::Variant const &x)
Utility to get the device of a variant.
Definition: operations.cpp:837
General utilities.
Definition: assert.cpp:7
torch::Tensor weightedMaskedSoftmax(torch::Tensor input, torch::Tensor mask, int dim, float clampEpsilon)
Compute a weighted masked softmax of a tensor in a numerically stable way by removing the max value b...
Definition: operations.cpp:662
torch::Tensor nllLoss(torch::Tensor input, int dim, torch::Tensor target, torch::Tensor weight, torch::Tensor mask, Reduction::Reduction reduction)
Definition: operations.cpp:570
std::vector< ag::Variant > unBatchVariant(ag::Variant const &batch, int stride, bool maskOut, double maskValue)
This function is the opposite of makeBatchVariant.
Definition: operations.cpp:274
std::tuple< torch::Tensor, torch::Tensor > maskedMax(torch::Tensor input, torch::Tensor mask, int dim, bool keepDim)
Compute a masked max/argmax of a tensor.
Definition: operations.cpp:644
ag::Variant applyTransform(ag::Variant input, const TensorTransform &fun)
Definition: operations.cpp:814
torch::Tensor repeat2d(torch::Tensor data, at::IntList sizes)
Repeat a 1D tensor so that you end up with a (#channels, sizes[0], size[1]) tensor.
Definition: operations.cpp:15
void clipGradientNorms(std::vector< torch::Tensor > parameters, float maxNorm)
Rescale gradients so that the norm of all gradients (concatenated) is smaller than maxNorm...
Definition: operations.cpp:598
torch::Tensor tensorFromNpyArray(cnpy::NpyArray array, torch::TensorOptions op)
Definition: operations.cpp:455
std::function< torch::Tensor(torch::Tensor)> TensorTransform
This is a convenience function to apply a tensor transformation to a complex type.
Definition: operations.h:362
void zerosToOnes_(torch::Tensor x)
Replace (in-place) all zeroes of x by ones.
Definition: operations.cpp:450
torch::Tensor makeBatch(ag::tensor_list const &lst, double pad)
Equivalent to a stack along dim 0 of the input, but with the values padded correct so the size is rec...
Definition: operations.cpp:186