public override TorchTensor forward(TorchTensor input) { var res = THSNN_Embedding_forward(handle, input.Handle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TorchTensor(res)); }
/// <summary> /// Rectified Linear Unit /// </summary> /// <param name="inPlace">Do the operation in-place. Default: False</param> /// <returns></returns> static public ReLU ReLU(bool inPlace = false) { var handle = THSNN_ReLU_ctor(inPlace, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new ReLU(handle, boxedHandle)); }
/// <summary> /// Forward pass. /// </summary> /// <param name="tensor">Input tensor</param> /// <returns></returns> public override TorchTensor forward(TorchTensor tensor) { var res = THSNN_ZeroPad2d_forward(handle, tensor.Handle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TorchTensor(res)); }
/// <summary> /// Continuously Differentiable Exponential Linear Unit /// </summary> /// <param name="negativeSlope">The α value for the LeakyReLU formulation. Default: 1.0</param> /// <param name="inPlace">Do the operation in-place. Default: False</param> /// <returns></returns> static public LeakyReLU LeakyReLU(double negativeSlope = 1.0, bool inPlace = false) { var handle = THSNN_LeakyReLU_ctor(negativeSlope, inPlace, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new LeakyReLU(handle, boxedHandle)); }
static public Conv2d Conv2d(long inputChannel, long outputChannel, long kernelSize, long stride = 1, long padding = 0, long dilation = 1, PaddingModes paddingMode = PaddingModes.Zeros, long groups = 1, bool bias = true) { var res = THSNN_Conv2d_ctor(inputChannel, outputChannel, kernelSize, stride, padding, dilation, (long)paddingMode, groups, bias, out var boxedHandle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new Conv2d(res, boxedHandle)); }
/// <summary> /// Element-wise arctangent of input / other with consideration of the quadrant. /// </summary> /// <param name="other"></param> /// <returns></returns> public TorchTensor atan2_(TorchTensor other) { var res = THSTensor_atan2_(handle, other.Handle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TorchTensor(res)); }
/// <summary> /// Pads the input tensor using replication of the input boundary. /// </summary> /// <param name="padding">The size of the padding.</param> /// <param name="value"></param> /// <returns></returns> static public ConstantPad2d ConstantPad2d(long padding, double value) { var handle = THSNN_ConstantPad2d_ctor(value, padding, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new ConstantPad2d(handle, boxedHandle)); }
public TorchTensor forward(TorchTensor input1, TorchTensor input2) { var res = THSNN_PairwiseDistance_forward(handle, input1.Handle, input2.Handle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TorchTensor(res)); }
static public PairwiseDistance PairwiseDistance(double p = 2.0, double eps = 1e-6, bool keep_dim = false) { var handle = THSNN_PairwiseDistance_ctor(p, eps, keep_dim, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new PairwiseDistance(handle, boxedHandle)); }
static public GRU GRU(long inputSize, long hiddenSize, long numLayers = 1, bool bias = true, bool batchFirst = false, double dropout = 0.0, bool bidirectional = false) { var res = THSNN_GRU_ctor(inputSize, hiddenSize, numLayers, bias, batchFirst, dropout, bidirectional, out var boxedHandle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new GRU(res, boxedHandle)); }
/// <summary> /// Reverses the PixelShuffle operation by rearranging elements in a tensor of shape (*, C, H * r, W * r) to a tensor of shape (*, C * r^2, H, W), where r is an downscale factor. /// </summary> /// <param name="downscaleFactor">Factor to increase spatial resolution by</param> /// <returns></returns> static public PixelUnshuffle PixelUnshuffle(long downscaleFactor) { var handle = THSNN_PixelUnshuffle_ctor(downscaleFactor, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new PixelUnshuffle(handle, boxedHandle)); }
public (TorchTensor, TorchTensor) forward(TorchTensor input, TorchTensor?h0 = null) { var res = THSNN_GRU_forward(handle, input.Handle, h0?.Handle ?? IntPtr.Zero, out IntPtr hN); if (res == IntPtr.Zero || hN == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TorchTensor(res), new TorchTensor(hN)); }
public TorchTensor Forward(TorchTensor tensor) { var res = THSNN_AdaptiveAvgPool2d_forward(handle.DangerousGetHandle(), tensor.Handle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TorchTensor(res)); }
public TorchTensor ifft(long n = -1, long dim = -1, FFTNormType norm = FFTNormType.Backward) { var res = THSTensor_ifft(handle, n, dim, (sbyte)norm); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TorchTensor(res)); }
/// <summary> /// Randomly zero out entire channels (a channel is a 2D feature map, e.g., the jj -th channel of the ii -th sample in the batched input is a 2D tensor \text{input}[i, j]input[i,j] ). /// Each channel will be zeroed out independently on every forward call with probability p using samples from a Bernoulli distribution. /// </summary> /// <param name="probability">Probability of an element to be zeroed. Default: 0.5</param> /// <param name="inPlace">If set to true, will do this operation in-place. Default: false</param> /// <returns></returns> static public AlphaDropout AlphaDropout(double probability = 0.5, bool inPlace = false) { var handle = THSNN_AlphaDropout_ctor(probability, inPlace, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new AlphaDropout(handle, boxedHandle)); }
/// <summary> /// Continuously Differentiable Exponential Linear Unit /// </summary> /// <param name="alpha">The α value for the CELU formulation. Default: 1.0</param> /// <param name="inPlace">Do the operation in-place. Default: False</param> /// <returns></returns> static public CELU CELU(double alpha = 1.0, bool inPlace = false) { var handle = THSNN_CELU_ctor(alpha, inPlace, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new CELU(handle, boxedHandle)); }
/// <summary> /// Sigmoid-Weighted Linear Unit /// </summary> /// <returns></returns> /// <remarks>The native libreary does not take an 'inplace' option, even though the PyTorch documentation mentions the parameter.</remarks> static public SiLU SiLU() { var handle = THSNN_SiLU_ctor(out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new SiLU(handle, boxedHandle)); }
static public Flatten Flatten(long startDim = 1, long endDim = -1) { var handle = THSNN_Flatten_ctor(startDim, endDim, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new Flatten(handle, boxedHandle)); }
/// <summary> /// Computes the arccosine of the elements of input. /// </summary> /// <returns></returns> public TorchTensor acos_() { var res = THSTensor_acos_(handle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TorchTensor(res)); }
public TorchTensor forward(TorchTensor tensor) { var res = THSNN_LayerNorm_forward(handle.DangerousGetHandle(), tensor.Handle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TorchTensor(res)); }
public TorchTensor forward(TorchTensor tensor) { var res = THSNN_LeakyReLU_forward(handle, tensor.Handle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TorchTensor(res)); }
/// <summary> /// Softmin /// </summary> /// <param name="dim">A dimension along which Softmin will be computed (so every slice along dim will sum to 1)</param> /// <returns></returns> static public Softmin Softmin(long dim) { var handle = THSNN_Softmin_ctor(dim, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new Softmin(handle, boxedHandle)); }
/// <summary> /// Applies Softmax over features to each spatial location /// </summary> /// <returns></returns> static public Softmax2d Softmax2d() { var handle = THSNN_Softmax2d_ctor(out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new Softmax2d(handle, boxedHandle)); }
static public Dropout Dropout(double probability = 0.5) { var handle = THSNN_Dropout_ctor(probability, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new Dropout(handle, boxedHandle)); }
static public Linear Linear(long inputSize, long outputSize, bool hasBias = true) { var res = THSNN_Linear_ctor(inputSize, outputSize, hasBias, out var boxedHandle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new Linear(res, boxedHandle)); }
/// <summary> /// Randomized Rectified Linear Unit /// </summary> /// <param name="lower">Lower bound of the uniform distribution. Default: 1/8</param> /// <param name="upper">Upper bound of the uniform distribution. Default: 1/3</param> /// <param name="inPlace">Do the operation in-place. Default: False</param> /// <returns></returns> static public RReLU RReLU(double lower = one_eighth, double upper = one_third, bool inPlace = false) { var handle = THSNN_RReLU_ctor(lower, upper, inPlace, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new RReLU(handle, boxedHandle)); }
/// <summary> /// Pads the input tensor using replication of the input boundary. /// </summary> /// <param name="padding">The size of the padding.</param> /// <returns></returns> static public ReplicationPad3d ReplicationPad3d(long padding) { var handle = THSNN_ReplicationPad3d_ctor(padding, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new ReplicationPad3d(handle, boxedHandle)); }
static public TransformerEncoderLayer TransformerEncoderLayer(long d_model = 512, long nhead = 8, long dim_feedforward = 2048, double dropout = 0.1, Transformer.Activations activation = NN.Transformer.Activations.ReLU) { var res = THSNN_TransformerEncoderLayer_ctor(d_model, nhead, dim_feedforward, dropout, (long)activation, out var boxedHandle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TransformerEncoderLayer(res, boxedHandle)); }
/// <summary> /// Pads the input tensor boundaries with zero. /// </summary> /// <param name="padding">The size of the padding.</param> /// <returns></returns> static public ZeroPad2d ZeroPad2d(long padding) { var handle = THSNN_ZeroPad2d_ctor(padding, out var boxedHandle); if (handle == IntPtr.Zero) { Torch.CheckForErrors(); } return(new ZeroPad2d(handle, boxedHandle)); }
static public TransformerDecoder TransformerDecoder(TransformerDecoderLayer decoder_layer, long num_layers) { var res = THSNN_TransformerDecoder_ctor(decoder_layer.handle, num_layers, out var boxedHandle); if (res == IntPtr.Zero) { Torch.CheckForErrors(); } return(new TransformerDecoder(res, boxedHandle)); }