@Name(value="torch::autograd::Function<torch::nn::CrossMapLRN2d>") @Properties(inherit=torch.class) public class FunctionCrossMapLRN2d extends Pointer
forward
can take as many arguments as you want and should return either a
variable list or a Variable. Use of any direct Variable arguments will be
registered in the graph but no vectors/sets or any other data structures
will be traversed. You can use c10::optionaltorch::autograd::AutogradContext
as the
first argument. Variables can be saved in the ctx
using
ctx->save_for_backward
(see torch::autograd::AutogradContext::save_for_backward
) and other data
can be saved in the ctx->saved_data
map
(see torch::autograd::AutogradContext::saved_data
)
in the form of <std::string, at::IValue>
pairs.
backward
should take a pointer to torch::autograd::AutogradContext
and a variable list containing as many Variables as there were outputs from
forward
as arguments. It should return as many Variables as there were
inputs with each of them containing the gradient w.r.t. its corresponding
input. Variables saved in forward
can be accessed with
ctx->get_saved_variables
(see
torch::autograd::AutogradContext::get_saved_variables
) and other saved
data can be accessed from ctx->saved_data
.
For example:
class MyFunction : public Function<MyFunction> {
public:
static variable_list forward(AutogradContext *ctx, int n, Variable var) {
// Save data for backward in context
ctx->saved_data["n"] = n;
var.mul_(2);
// Mark var as modified by inplace operation
ctx->mark_dirty({var});
return {var};
}
static variable_list backward(AutogradContext *ctx, variable_list
grad_output) {
// Use data saved in forward
auto n = ctx->saved_data["n"].toInt();
return {grad_output[0]*n};
}
};
To use MyFunction
:
Variable x;
auto y = MyFunction::apply(6, x);
// Example backward call
y[0].sum().backward();
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter
Constructor and Description |
---|
FunctionCrossMapLRN2d()
Default native constructor.
|
FunctionCrossMapLRN2d(long size)
Native array allocator.
|
FunctionCrossMapLRN2d(Pointer p)
Pointer cast constructor.
|
Modifier and Type | Method and Description |
---|---|
FunctionCrossMapLRN2d |
getPointer(long i) |
FunctionCrossMapLRN2d |
position(long position) |
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, getDirectBufferAddress, getPointer, getPointer, getPointer, hashCode, interruptDeallocatorThread, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetAddress, offsetof, offsetof, parseBytes, physicalBytes, physicalBytesInaccurate, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, sizeof, toString, totalBytes, totalCount, totalPhysicalBytes, withDeallocator, zero
public FunctionCrossMapLRN2d()
public FunctionCrossMapLRN2d(long size)
Pointer.position(long)
.public FunctionCrossMapLRN2d(Pointer p)
Pointer(Pointer)
.public FunctionCrossMapLRN2d position(long position)
public FunctionCrossMapLRN2d getPointer(long i)
getPointer
in class Pointer
Copyright © 2024. All rights reserved.