@Namespace(value="c10") @NoOffset @Properties(inherit=torch.class) public class IValue extends Pointer
IValue::Payload
, which holds primitive types
(int64_t
, bool
, double
, Device
) and Tensor
as values,
and all other types as a c10::intrusive_ptr
. In order to
optimize performance of the destructor and related operations by
making the Tensor
and c10::intrusive_ptr
paths generate the
same code, we represent a null c10::intrusive_ptr
as
UndefinedTensorImpl::singleton()
, *not* nullptr
.
IValues are used as inputs to and outputs from the TorchScript interpreter.
To retrieve the value contained within an IValue, use the .toX()
methods,
where X
is the type you are trying to get. Note that neither the .toX()
methods nor the templated .to<T>
functions do any kind of casting, they
only unwrap the contained value. For example:
\rst
.. code-block:: cpp
// Make the IValue
torch::IValue my_ivalue(26);
std::cout << my_ivalue << "\n";
// Unwrap the IValue
int64_t my_int = my_ivalue.toInt();
std::cout << my_int << "\n";
// This will throw an error!
// my_ivalue
is tagged as an int and cannot be used as another type
torch::Tensor my_tensor = my_ivalue.toTensor();
\endrstPointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter
Constructor and Description |
---|
IValue() |
IValue(AwaitPtr v) |
IValue(boolean b) |
IValue(byte l) |
IValue(BytePointer v) |
IValue(ConstantStringPtr v) |
IValue(Device d) |
IValue(Dimname dimname) |
IValue(double d) |
IValue(EnumHolderPtr v) |
IValue(FuturePtr v) |
IValue(Generator g) |
IValue(GenericDict v) |
IValue(GenericList v) |
IValue(int i) |
IValue(IValue rhs) |
IValue(long i) |
IValue(Pointer blob)
\private [doxygen private]
|
IValue(PyObjectHolderPtr v) |
IValue(QuantizerPtr v) |
IValue(RRefInterfacePtr v) |
IValue(Scalar s) |
IValue(Storage s) |
IValue(Stream s) |
IValue(String v) |
IValue(SymBool i) |
IValue(SymFloat i) |
IValue(SymInt i) |
IValue(TensorBase t) |
IValue(torch.Layout l) |
IValue(torch.MemoryFormat m) |
IValue(torch.QScheme qscheme) |
IValue(torch.ScalarType t) |
IValue(TuplePtr v) |
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, getDirectBufferAddress, getPointer, getPointer, getPointer, getPointer, hashCode, interruptDeallocatorThread, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetAddress, offsetof, offsetof, parseBytes, physicalBytes, physicalBytesInaccurate, position, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, sizeof, toString, totalBytes, totalCount, totalPhysicalBytes, withDeallocator, zero
public IValue(@ByVal TensorBase t)
public IValue(@ByVal @Cast(value="c10::intrusive_ptr<caffe2::Blob>*") Pointer blob)
public IValue(double d)
public IValue(@ByVal RRefInterfacePtr v)
public IValue(@ByVal QuantizerPtr v)
public IValue(int i)
public IValue(@ByVal ConstantStringPtr v)
public IValue(@StdString BytePointer v)
public IValue(@StdString String v)
public IValue(@ByVal GenericList v)
public IValue(@ByVal GenericDict v)
public IValue(@ByVal PyObjectHolderPtr v)
public IValue(@ByVal EnumHolderPtr v)
public IValue()
public IValue(torch.ScalarType t)
public IValue(torch.Layout l)
public IValue(torch.MemoryFormat m)
public IValue(@ByVal torch.QScheme qscheme)
@ByRef @Name(value="operator =") @NoException(value=true) public IValue put(@ByRef(value=true) IValue rhs)
public void dump()
public boolean equals(IValue rhs)
public boolean notEquals(IValue rhs)
@Cast(value="bool") public boolean is(@Const @ByRef IValue rhs)
this
is the same object as rhs
. The
semantics are the same as Python's is
operator.
NOTE: Like in Python, this operation is poorly defined for primitive types
like numbers and strings. Prefer to use ==
unless you really want to
check identity equality.@ByVal public IValue hash()
hash()
on these types will throw.public boolean _fastEqualsForContainer(IValue rhs)
@Cast(value="size_t") @NoException(value=true) public long use_count()
@NoException(value=true) public void swap(@ByRef IValue rhs)
public TensorImpl unsafeToTensorImpl()
@ByVal @Cast(value="c10::intrusive_ptr<caffe2::Blob>*") public Pointer toBlob()
@ByVal public static IValue make_capsule(@ByVal @Cast(value="c10::intrusive_ptr<torch::CustomClassHolder>*") Pointer blob)
@ByVal @Cast(value="c10::intrusive_ptr<torch::CustomClassHolder>*") public Pointer toCapsule()
public double toDouble()
@ByVal public DoubleComplex toComplexDouble()
@ByVal public RRefInterfacePtr toRRef()
@ByVal public QuantizerPtr toQuantizer()
@ByVal @Cast(value="std::vector<int64_t>*") public LongVector toIntVector()
@ByVal public SymIntVector toSymIntVector()
@ByVal @Name(value="toString") public ConstantStringPtr toConstantString()
@StdString public BytePointer toStringRef()
@ByVal @Cast(value="c10::optional<std::reference_wrapper<const std::string> >*") public Pointer toOptionalStringRef()
@StringView public BytePointer toStringView()
@ByVal public DoubleList toDoubleList()
@ByVal @Cast(value="std::vector<double>*") public DoubleVector toDoubleVector()
@ByVal public DoubleComplexList toComplexDoubleList()
@StdVector public DoubleComplex toComplexDoubleVector()
@ByVal public BooleanList toBoolList()
@ByVal public TensorList toTensorList()
@Cast(value={"","std::vector<torch::Tensor>"}) @StdMove public TensorVector toTensorVector()
@ByVal public TensorOptionalList toOptionalTensorList()
@StdVector public TensorOptional toOptionalTensorVector()
@ByVal public GenericList toList()
@ByVal public IValueArrayRef toListRef()
@ByVal public GenericDict toGenericDict()
@ByVal public PyObjectHolderPtr toPyObjectHolder()
@ByVal public EnumHolderPtr toEnumHolder()
@StdString public BytePointer toNone()
public torch.ScalarType toScalarType()
@ByVal public torch.Layout toLayout()
@ByVal public torch.MemoryFormat toMemoryFormat()
@ByVal public torch.QScheme toQScheme()
@StdString public BytePointer tagKind()
@Cast(value="bool") public boolean isSameIdentity(@Const @ByRef IValue rhs)
public void getSubValues(@ByRef HashAliasedIValues subValues)
@ByVal public IValue deepcopy(@ByVal(nullValue="c10::optional<at::Device>(c10::nullopt)") DeviceOptional device)
@ByVal public IValue deepcopy(@ByRef HashAliasedIValueMap memo, @ByVal(nullValue="c10::optional<at::Device>(c10::nullopt)") DeviceOptional device)
@ByVal public IValue deepcopy(@ByRef HashAliasedIValueMap memo)
Copyright © 2024. All rights reserved.