@Namespace(value="tensorflow") @NoOffset @Properties(inherit=tensorflow.class) public class Tensor extends AbstractTensor
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter
Constructor and Description |
---|
Tensor()
\brief Creates a 1-dimensional, 0-element float tensor.
|
Tensor(Allocator a,
int type,
TensorShape shape)
\brief Creates a tensor with the input
type and shape , using
the allocator a to allocate the underlying buffer. |
Tensor(Allocator a,
int type,
TensorShape shape,
AllocationAttributes allocation_attr)
\brief Creates a tensor with the input
type and shape , using
the allocator a and the specified "allocation_attr" to
allocate the underlying buffer. |
Tensor(bfloat16 scalar_value) |
Tensor(boolean scalar_value) |
Tensor(byte scalar_value) |
Tensor(BytePointer scalar_value) |
Tensor(double scalar_value) |
Tensor(double[] scalar_value) |
Tensor(DoubleBuffer scalar_value) |
Tensor(DoublePointer scalar_value) |
Tensor(float... scalar_value) |
Tensor(float scalar_value) |
Tensor(FloatBuffer scalar_value) |
Tensor(FloatPointer scalar_value) |
Tensor(int type)
\brief Creates an empty Tensor of the given data type.
|
Tensor(int type,
TensorShape shape)
\brief Creates a Tensor of the given
type and shape . |
Tensor(int type,
TensorShape shape,
Pointer data) |
Tensor(int type,
TensorShape shape,
TensorBuffer buf)
\brief Creates a tensor with the input datatype, shape and buf.
|
Tensor(long scalar_value) |
Tensor(Pointer p)
Pointer cast constructor.
|
Tensor(ResourceHandle scalar_value) |
Tensor(short scalar_value) |
Tensor(String scalar_value) |
Tensor(Tensor other)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
long |
AllocatedBytes() |
void |
AsProtoField(TensorProto proto)
\brief Fills in
proto with *this tensor's content. |
void |
AsProtoTensorContent(TensorProto proto) |
Status |
BitcastFrom(Tensor other,
int dtype,
TensorShape shape)
Copy the other tensor into this tensor, reshape it and reinterpret the
buffer's datatype.
|
boolean |
CopyFrom(Tensor other,
TensorShape shape)
\brief Copy the other tensor into this tensor and reshape it.
|
BytePointer |
DebugString() |
BytePointer |
DebugString(int num_values)
A human-readable summary of the tensor suitable for debugging.
|
BytePointer |
DeviceSafeDebugString() |
long |
dim_size(int d)
Convenience accessor for the tensor shape.
|
int |
dims()
\brief Convenience accessor for the tensor shape.
|
int |
dtype()
Returns the data type.
|
void |
FillDescription(TensorDescription description)
Fill in the
TensorDescription proto with metadata about the
tensor that is useful for monitoring and debugging. |
boolean |
FromProto(Allocator a,
TensorProto other) |
boolean |
FromProto(TensorProto other)
\brief Parse
other and construct the tensor. |
boolean |
IsAligned()
Returns true iff this tensor is aligned.
|
boolean |
IsInitialized()
\brief If necessary, has this Tensor been initialized?
Zero-element Tensors are always considered initialized, even if they
have never been assigned to and do not have any memory allocated.
|
boolean |
IsSameSize(Tensor b) |
long |
NumElements()
Convenience accessor for the tensor shape.
|
Tensor |
put(Tensor other)
Assign operator.
|
TensorShape |
shape()
Returns the shape of the tensor.
|
boolean |
SharesBufferWith(Tensor b) |
Tensor |
Slice(long dim0_start,
long dim0_limit)
\brief Slice this tensor along the 1st dimension.
|
Tensor |
SubSlice(long index)
\brief Select a subslice from this tensor along the 1st dimension.
|
BytePointer |
SummarizeValue(long max_entries) |
BytePointer |
SummarizeValue(long max_entries,
boolean print_v2)
Render the first
max_entries values in *this into a string. |
BytePointer |
tensor_data()
\brief Returns a
StringPiece mapping the current tensor's buffer. |
long |
TotalBytes()
Returns the estimated memory usage of this tensor.
|
void |
UnsafeCopyFromInternal(Tensor other,
int dtype,
TensorShape shape)
Like BitcastFrom, but CHECK fails if any preconditions are not met.
|
create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, createBuffer, createBuffer, createIndexer, createIndexer, createStringArray
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 Tensor(Pointer p)
Pointer(Pointer)
.public Tensor()
c++
Tensor(DT_FLOAT, TensorShape({}))
public Tensor(@Cast(value="tensorflow::DataType") int type, @Const @ByRef TensorShape shape)
type
and shape
. If
LogMemory::IsEnabled() the allocation is logged as coming from
an unknown kernel and step. Calling the Tensor constructor
directly from within an Op is deprecated: use the
OpKernelConstruction/OpKernelContext allocate_* methods to
allocate a new tensor, which record the kernel and step.
The underlying buffer is allocated using a CPUAllocator
.public Tensor(Allocator a, @Cast(value="tensorflow::DataType") int type, @Const @ByRef TensorShape shape)
type
and shape
, using
the allocator a
to allocate the underlying buffer. If
LogMemory::IsEnabled() the allocation is logged as coming from
an unknown kernel and step. Calling the Tensor constructor
directly from within an Op is deprecated: use the
OpKernelConstruction/OpKernelContext allocate_* methods to
allocate a new tensor, which record the kernel and step.
a
must outlive the lifetime of this Tensor.public Tensor(Allocator a, @Cast(value="tensorflow::DataType") int type, @Const @ByRef TensorShape shape, @Const @ByRef AllocationAttributes allocation_attr)
type
and shape
, using
the allocator a
and the specified "allocation_attr" to
allocate the underlying buffer. If the kernel and step are known
allocation_attr.allocation_will_be_logged should be set to true
and LogMemory::RecordTensorAllocation should be called after the
tensor is constructed. Calling the Tensor constructor directly
from within an Op is deprecated: use the
OpKernelConstruction/OpKernelContext allocate_* methods to
allocate a new tensor, which record the kernel and step.
a
must outlive the lifetime of this Tensor.public Tensor(@Cast(value="tensorflow::DataType") int type, TensorShape shape, TensorBuffer buf)
public Tensor(@Cast(value="tensorflow::DataType") int type, TensorShape shape, Pointer data)
public Tensor(@Cast(value="tensorflow::DataType") int type)
public Tensor(float scalar_value)
public Tensor(double scalar_value)
public Tensor(@StdString BytePointer scalar_value)
public Tensor(@StdString String scalar_value)
public Tensor(@ByVal @Cast(value="tensorflow::complex64*") FloatPointer scalar_value)
public Tensor(@ByVal @Cast(value="tensorflow::complex64*") FloatBuffer scalar_value)
public Tensor(@ByVal @Cast(value="tensorflow::complex128*") DoublePointer scalar_value)
public Tensor(@ByVal @Cast(value="tensorflow::complex128*") DoubleBuffer scalar_value)
public Tensor(@ByVal ResourceHandle scalar_value)
@Cast(value="tensorflow::DataType") public int dtype()
dtype
in class AbstractTensor
@Const @ByRef public TensorShape shape()
public int dims()
TensorShape
in tensor_shape.h
.dims
in class AbstractTensor
@Cast(value="tensorflow::int64") public long dim_size(int d)
dim_size
in class AbstractTensor
@Cast(value="tensorflow::int64") public long NumElements()
NumElements
in class AbstractTensor
@Cast(value="bool") public boolean IsInitialized()
@Cast(value="size_t") public long TotalBytes()
TotalBytes
in class AbstractTensor
@ByRef @Name(value="operator =") public Tensor put(@Const @ByRef Tensor other)
@Cast(value="bool") public boolean CopyFrom(@Const @ByRef Tensor other, @Const @ByRef TensorShape shape)
true
iff other.shape()
has the same number of elements of the given
shape
.@ByVal public Tensor Slice(@Cast(value="tensorflow::int64") long dim0_start, @Cast(value="tensorflow::int64") long dim0_limit)
I.e., the returned tensor satisfies
returned[i, ...] == this[dim0_start + i, ...].
The returned tensor shares the underlying tensor buffer with this
tensor.
NOTE: The returned tensor may not satisfy the same alignment
requirement as this tensor depending on the shape. The caller
must check the returned tensor's alignment before calling certain
methods that have alignment requirement (e.g., flat()
, tensor()
).
NOTE: When fed with an N-dimensional tensor, this method returns a tensor
also with N dimensions. If you want to select a sub tensor, see SubSlice.
REQUIRES: dims()
>= 1
REQUIRES: 0 <= dim0_start <= dim0_limit <= dim_size(0)
@ByVal public Tensor SubSlice(@Cast(value="tensorflow::int64") long index)
flat()
, tensor()
).
REQUIRES: dims()
>= 1
REQUIRES: 0 <= dim0_start < dim_size(0)
@Cast(value="bool") public boolean FromProto(@Const @ByRef TensorProto other)
other
and construct the tensor.
Returns true
iff the parsing succeeds. If the parsing fails,
the state of *this
is unchanged.
@Cast(value="bool") public boolean FromProto(Allocator a, @Const @ByRef TensorProto other)
public void AsProtoField(TensorProto proto)
proto
with *this
tensor's content.
AsProtoField()
fills in the repeated field for proto.dtype()
, while
AsProtoTensorContent()
encodes the content in proto.tensor_content()
in a compact form.public void AsProtoTensorContent(TensorProto proto)
@StdString public BytePointer SummarizeValue(@Cast(value="tensorflow::int64") long max_entries, @Cast(value="bool") boolean print_v2)
max_entries
values in *this
into a string.@StdString public BytePointer SummarizeValue(@Cast(value="tensorflow::int64") long max_entries)
@StdString public BytePointer DebugString(int num_values)
@StdString public BytePointer DebugString()
@StdString public BytePointer DeviceSafeDebugString()
public void FillDescription(TensorDescription description)
TensorDescription
proto with metadata about the
tensor that is useful for monitoring and debugging.@tensorflow.StringPiece public BytePointer tensor_data()
StringPiece
mapping the current tensor's buffer.
The returned StringPiece
may point to memory location on devices
that the CPU cannot address directly.
NOTE: The underlying tensor buffer is refcounted, so the lifetime
of the contents mapped by the StringPiece
matches the lifetime of
the buffer; callers should arrange to make sure the buffer does
not get destroyed while the StringPiece
is still used.
REQUIRES: DataTypeCanUseMemcpy(dtype())
.tensor_data
in class AbstractTensor
@ByVal public Status BitcastFrom(@Const @ByRef Tensor other, @Cast(value="tensorflow::DataType") int dtype, @Const @ByRef TensorShape shape)
other
tensor and the given type and shape
are "compatible" (i.e. they occupy the same number of bytes).
Specifically:
shape.num_elements() * DataTypeSize(type)
must equal
other.num_elements() * DataTypeSize(other.dtype())
In addition, this function requires:
* DataTypeSize(other.dtype()) != 0
* DataTypeSize(type) != 0
If any of the requirements are not met, errors::InvalidArgument is
returned.public void UnsafeCopyFromInternal(@Const @ByRef Tensor other, @Cast(value="tensorflow::DataType") int dtype, @Const @ByRef TensorShape shape)
Copyright © 2022. All rights reserved.