public class TensorBlock extends Object implements CacheBlock, Externalizable
TensorBlock
is the most top level representation of a tensor. There are two types of data representation
which can be used: Basic/Homogeneous and Data/Heterogeneous
Basic supports only one ValueType
, while Data supports multiple ValueType
s along the column
axis.
The format determines if the TensorBlock
uses a BasicTensorBlock
or a DataTensorBlock
for storing the data.Modifier and Type | Field and Description |
---|---|
static int[] |
DEFAULT_DIMS |
static Types.ValueType |
DEFAULT_VTYPE |
Constructor and Description |
---|
TensorBlock()
Create a
TensorBlock with [0,0] dimension and homogeneous representation (aka. |
TensorBlock(BasicTensorBlock basicTensor)
Wrap the given
BasicTensorBlock inside a TensorBlock . |
TensorBlock(DataTensorBlock dataTensor)
Wrap the given
DataTensorBlock inside a TensorBlock . |
TensorBlock(double value)
Create a [1,1] basic FP64
TensorBlock containing the given value. |
TensorBlock(int[] dims,
boolean basic)
Create a
TensorBlock with the given dimensions and the given data representation (basic/data). |
TensorBlock(TensorBlock that)
Copy constructor
|
TensorBlock(Types.ValueType[] schema,
int[] dims)
Create a data
TensorBlock with the given schema and the given dimensions. |
TensorBlock(Types.ValueType vt,
int[] dims)
Create a basic
TensorBlock with the given ValueType and the given dimensions. |
Modifier and Type | Method and Description |
---|---|
TensorBlock |
allocateBlock()
If data is not yet allocated, allocate.
|
TensorBlock |
binaryOperations(BinaryOperator op,
TensorBlock thatValue,
TensorBlock result) |
void |
compactEmptyBlock()
Free unnecessarily allocated empty block.
|
TensorBlock |
copy(int[] lower,
int[] upper,
TensorBlock src)
Copy a part of another
TensorBlock |
TensorBlock |
copy(TensorBlock src) |
TensorBlock |
copyExact(int[] lower,
int[] upper,
TensorBlock src)
Copy a part of another
TensorBlock . |
Object |
get(int[] ix) |
double |
get(int r,
int c) |
BasicTensorBlock |
getBasicTensor() |
DataTensorBlock |
getDataTensor() |
int |
getDim(int i) |
int[] |
getDims() |
long |
getExactBlockDataSerializedSize(BasicTensorBlock bt)
Get the exact serialized size of a
BasicTensorBlock if written by
TensorBlock.writeBlockData(DataOutput,BasicTensorBlock) . |
long |
getExactSerializedSize()
Get the exact serialized size in bytes of the cache block.
|
long |
getInMemorySize()
Get the in-memory size in bytes of the cache block.
|
long |
getLength() |
long[] |
getLongDims() |
void |
getNextIndexes(int[] ix)
Calculates the next index array.
|
static void |
getNextIndexes(int[] dims,
int[] ix)
Calculates the next index array.
|
long |
getNonZeros() |
int |
getNumColumns() |
int |
getNumDims() |
int |
getNumRows() |
Types.ValueType[] |
getSchema()
Get the schema if this
TensorBlock is heterogeneous. |
Types.ValueType |
getValueType()
Get the
ValueType if this TensorBlock is homogeneous. |
boolean |
isAllocated() |
boolean |
isBasic() |
boolean |
isEmpty() |
boolean |
isEmpty(boolean safe) |
boolean |
isMatrix() |
boolean |
isShallowSerialize()
Indicates if the cache block is subject to shallow serialized,
which is generally true if in-memory size and serialized size
are almost identical allowing to avoid unnecessary deep serialize.
|
boolean |
isShallowSerialize(boolean inclConvert)
Indicates if the cache block is subject to shallow serialized,
which is generally true if in-memory size and serialized size
are almost identical allowing to avoid unnecessary deep serialize.
|
boolean |
isVector() |
void |
merge(CacheBlock that,
boolean appendOnly)
Merge the given block into the current block.
|
void |
readExternal(ObjectInput in) |
void |
readFields(DataInput in) |
void |
reset()
Reset all cells to 0.
|
void |
reset(int[] dims)
Reset data with new dimensions.
|
static Types.ValueType |
resultValueType(Types.ValueType in1,
Types.ValueType in2) |
void |
set(int[] ix,
Object v)
Set a cell to the value given as an `Object`.
|
void |
set(int r,
int c,
double v)
Set a cell in a 2-dimensional tensor.
|
void |
set(MatrixBlock other) |
void |
set(Object v) |
TensorBlock |
slice(int[] offsets,
TensorBlock outBlock)
Slice the current block and write into the outBlock.
|
CacheBlock |
slice(int rl,
int ru,
int cl,
int cu,
CacheBlock block)
Slice a sub block out of the current block and write into the given output block.
|
void |
toShallowSerializeBlock()
Converts a cache block that is not shallow serializable into
a form that is shallow serializable.
|
void |
write(DataOutput out) |
void |
writeBlockData(DataOutput out,
BasicTensorBlock bt)
Write a
BasicTensorBlock . |
void |
writeExternal(ObjectOutput out) |
public static final int[] DEFAULT_DIMS
public static final Types.ValueType DEFAULT_VTYPE
public TensorBlock()
TensorBlock
with [0,0] dimension and homogeneous representation (aka. basic).public TensorBlock(int[] dims, boolean basic)
TensorBlock
with the given dimensions and the given data representation (basic/data).dims
- dimensionsbasic
- if true then basic TensorBlock
else a data type of TensorBlock
.public TensorBlock(Types.ValueType vt, int[] dims)
TensorBlock
with the given ValueType
and the given dimensions.vt
- value typedims
- dimensionspublic TensorBlock(Types.ValueType[] schema, int[] dims)
TensorBlock
with the given schema and the given dimensions.schema
- schema of the columnsdims
- dimensionspublic TensorBlock(double value)
TensorBlock
containing the given value.value
- value to put insidepublic TensorBlock(BasicTensorBlock basicTensor)
BasicTensorBlock
inside a TensorBlock
.basicTensor
- basic tensor blockpublic TensorBlock(DataTensorBlock dataTensor)
DataTensorBlock
inside a TensorBlock
.dataTensor
- basic tensor blockpublic TensorBlock(TensorBlock that)
that
- TensorBlock
to copypublic void reset()
public void reset(int[] dims)
dims
- new dimensionspublic boolean isBasic()
public boolean isAllocated()
public TensorBlock allocateBlock()
TensorBlock
public BasicTensorBlock getBasicTensor()
public DataTensorBlock getDataTensor()
public Types.ValueType getValueType()
ValueType
if this TensorBlock
is homogeneous.ValueType
if homogeneous, null otherwisepublic Types.ValueType[] getSchema()
TensorBlock
is heterogeneous.public int getNumDims()
public int getNumRows()
getNumRows
in interface CacheBlock
public int getNumColumns()
getNumColumns
in interface CacheBlock
public long getInMemorySize()
CacheBlock
getInMemorySize
in interface CacheBlock
public boolean isShallowSerialize()
CacheBlock
isShallowSerialize
in interface CacheBlock
public boolean isShallowSerialize(boolean inclConvert)
CacheBlock
isShallowSerialize
in interface CacheBlock
inclConvert
- if true report blocks as shallow serialize that are
currently not amenable but can be brought into an amenable form
via toShallowSerializeBlock
.public void toShallowSerializeBlock()
CacheBlock
toShallowSerializeBlock
in interface CacheBlock
public void compactEmptyBlock()
CacheBlock
compactEmptyBlock
in interface CacheBlock
public CacheBlock slice(int rl, int ru, int cl, int cu, CacheBlock block)
CacheBlock
slice
in interface CacheBlock
rl
- row lowerru
- row uppercl
- column lowercu
- column upperblock
- cache blockpublic void merge(CacheBlock that, boolean appendOnly)
CacheBlock
merge
in interface CacheBlock
that
- cache blockappendOnly
- ?public int getDim(int i)
public int[] getDims()
public long[] getLongDims()
public static void getNextIndexes(int[] dims, int[] ix)
dims
- the dims array for which we have to decide the next indexix
- the index array which will be incremented to the next index arraypublic void getNextIndexes(int[] ix)
ix
- the index array which will be incremented to the next index arraypublic boolean isVector()
public boolean isMatrix()
public long getLength()
public boolean isEmpty()
public boolean isEmpty(boolean safe)
public long getNonZeros()
public Object get(int[] ix)
public double get(int r, int c)
public void set(Object v)
public void set(MatrixBlock other)
public void set(int[] ix, Object v)
ix
- indexes in each dimension, starting with 0v
- value to setpublic void set(int r, int c, double v)
r
- row of the cellc
- column of the cellv
- value to setpublic TensorBlock slice(int[] offsets, TensorBlock outBlock)
offsets
- offsets where the slice startsoutBlock
- sliced result blockpublic TensorBlock copy(TensorBlock src)
public TensorBlock copy(int[] lower, int[] upper, TensorBlock src)
TensorBlock
lower
- lower index of elements to copy (inclusive)upper
- upper index of elements to copy (exclusive)src
- source TensorBlock
TensorBlock
public TensorBlock copyExact(int[] lower, int[] upper, TensorBlock src)
TensorBlock
. The difference to copy()
is that
this allows for exact sub-blocks instead of taking all consecutive data elements from lower to upper.lower
- lower index of elements to copy (inclusive)upper
- upper index of elements to copy (exclusive)src
- source TensorBlock
TensorBlock
public long getExactSerializedSize()
CacheBlock
getExactSerializedSize
in interface CacheBlock
public long getExactBlockDataSerializedSize(BasicTensorBlock bt)
BasicTensorBlock
if written by
TensorBlock.writeBlockData(DataOutput,BasicTensorBlock)
.bt
- BasicTensorBlock
public void write(DataOutput out) throws IOException
write
in interface org.apache.hadoop.io.Writable
IOException
public void writeBlockData(DataOutput out, BasicTensorBlock bt) throws IOException
BasicTensorBlock
.out
- output streambt
- source BasicTensorBlock
IOException
- if writing with the output stream failspublic void readFields(DataInput in) throws IOException
readFields
in interface org.apache.hadoop.io.Writable
IOException
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException
readExternal
in interface Externalizable
IOException
public TensorBlock binaryOperations(BinaryOperator op, TensorBlock thatValue, TensorBlock result)
public static Types.ValueType resultValueType(Types.ValueType in1, Types.ValueType in2)
Copyright © 2020 The Apache Software Foundation. All rights reserved.