Class TensorArray
- java.lang.Object
-
- org.nd4j.autodiff.functions.DifferentialFunction
-
- org.nd4j.linalg.api.ops.DynamicCustomOp
-
- org.nd4j.linalg.api.ops.impl.shape.tensorops.BaseTensorOp
-
- org.nd4j.linalg.api.ops.impl.shape.tensorops.TensorArray
-
- All Implemented Interfaces:
CustomOp
public class TensorArray extends BaseTensorOp
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.nd4j.linalg.api.ops.DynamicCustomOp
DynamicCustomOp.DynamicCustomOpsBuilder
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
clearOnRead
protected SDVariable
flow
protected DataType
tensorArrayDataType
-
Fields inherited from class org.nd4j.linalg.api.ops.DynamicCustomOp
axis, bArguments, dArguments, iArguments, inplaceCall, inputArguments, outputArguments, outputVariables, sArguments, tArguments
-
Fields inherited from class org.nd4j.autodiff.functions.DifferentialFunction
dimensions, extraArgs, inPlace, ownName, ownNameSetWithDefault, sameDiff, scalarValue
-
-
Constructor Summary
Constructors Constructor Description TensorArray()
TensorArray(String name, SameDiff sameDiff, DataType dataType)
TensorArray(SameDiff sameDiff, DataType dataType)
TensorArray(DataType dataType)
TensorArray(TensorArray ta)
TensorArray(TensorArray ta, SDVariable[] inputs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<DataType>
calculateOutputDataTypes(List<DataType> inputDataType)
Calculate the data types for the output arrays.SDVariable
concat(SDVariable flow)
void
configureFromArguments()
This allows a custom op to configure relevant fields from its arguments.static SDVariable
createEmpty(SameDiff sd, DataType dataType)
Create an empty sequence with the specified data type.static SDVariable
createEmpty(SameDiff sd, DataType dataType, String outputVarName)
Create an empty sequence with the specified data type.static SDVariable
createTensorArrayFrom(SameDiff sd, SDVariable[] inputs)
Create anTensorArray
op from the given inputs, note this is the same as callingcreateTensorArrayFrom(SameDiff, SDVariable[],String)
with null.static SDVariable
createTensorArrayFrom(SameDiff sd, SDVariable[] inputs, String outputVarName)
Create anTensorArray
op from the given inputsSDVariable
gather(SDVariable flow, int... indices)
SDVariable
gather(SDVariable flow, SDVariable indices)
int
getNumOutputs()
SameDiff
getSameDiff()
static TensorArray
getTensorArray(SameDiff sd, SDVariable sequenceVar)
Get the associatedTensorArray
instance related to this op.SDVariable
getVar()
void
initFromTensorFlow(NodeDef nodeDef, SameDiff initWith, Map<String,AttrValue> attributesForNode, GraphDef graph)
Initialize the function from the givenNodeDef
static SDVariable
itemAtIndex(SameDiff sd, SDVariable[] inputs)
Returns the item at the specified index in the specified list.static SDVariable
itemAtIndex(SameDiff sd, SDVariable[] inputs, String outputVarName)
Returns the item at the specified index in the specified list.String
opName()
This method returns op opName as stringOp.Type
opType()
The type of the opSDVariable
read(int index)
SDVariable
read(SDVariable index)
SDVariable
read(SDVariable from, SDVariable index)
SDVariable
remove(SDVariable value)
SDVariable
remove(SDVariable value, int idx)
SDVariable
remove(SDVariable value, SDVariable idx)
static SDVariable
removeFromTensorArray(SameDiff sameDiff, SDVariable inputSequence)
Remove the last element from the relevantTensorArray
static SDVariable
removeFromTensorArray(SameDiff sameDiff, SDVariable inputSequence, SDVariable position)
Remove an element from the relevantTensorArray
static SDVariable
removeFromTensorArray(SameDiff sameDiff, SDVariable inputSequence, SDVariable position, String outputVarName)
Remove an element from the relevantTensorArray
long[]
requiredShape()
Returns the required shape for elements in this tensor array.SDVariable
scatter(SDVariable flow, SDVariable value, int... indices)
SDVariable
scatter(SDVariable flow, SDVariable value, SDVariable indices)
SDVariable
size(SDVariable value)
static SDVariable
sizeOfTensorArray(SameDiff sd, SDVariable sequence)
Create an empty sequence with the specified data type.static SDVariable
sizeOfTensorArray(SameDiff sd, SDVariable sequence, String outputVarName)
Create an empty sequence with the specified data type.SDVariable
stack(SDVariable flow)
String
tensorflowName()
The opName of this function tensorflowString
toString()
SDVariable
unstack(SDVariable flow, SDVariable value)
SDVariable
write(SDVariable flow, int index, SDVariable value)
SDVariable
write(SDVariable flow, SDVariable index, SDVariable value)
-
Methods inherited from class org.nd4j.linalg.api.ops.impl.shape.tensorops.BaseTensorOp
calculateOutputShape, computeArrays, doDiff, onnxName
-
Methods inherited from class org.nd4j.linalg.api.ops.DynamicCustomOp
addBArgument, addDArgument, addIArgument, addIArgument, addInputArgument, addOutputArgument, addOutputsToOp, addSArgument, addTArgument, assertValidForExecution, bArgs, builder, calculateOutputShape, clearArrays, dArgs, generateFake, generateFake, getBArgument, getDescriptor, getIArgument, getInputArgument, getOutputArgument, getSArgument, getTArgument, getValue, iArgs, initFromOnnx, inputArguments, mappingsForFunction, numBArguments, numDArguments, numIArguments, numInputArguments, numOutputArguments, numSArguments, numTArguments, opHash, opNum, outputArguments, outputVariables, outputVariables, propertiesForFunction, removeIArgument, removeInputArgument, removeOutputArgument, removeSArgument, removeTArgument, sArgs, setInputArgument, setInputArguments, setOutputArgument, setPropertiesForFunction, setValueFor, tArgs, wrapFilterNull, wrapOrNull, wrapOrNull
-
Methods inherited from class org.nd4j.autodiff.functions.DifferentialFunction
arg, arg, argNames, args, attributeAdaptersForFunction, configFieldName, configureWithSameDiff, diff, dup, equals, getBooleanFromProperty, getDoubleValueFromProperty, getIntValueFromProperty, getLongValueFromProperty, getStringFromProperty, hashCode, isConfigProperties, larg, onnxNames, outputs, outputVariable, outputVariablesNames, rarg, replaceArg, setInstanceId, tensorflowNames
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.nd4j.linalg.api.ops.CustomOp
isInplaceCall
-
-
-
-
Field Detail
-
tensorArrayDataType
protected DataType tensorArrayDataType
-
flow
protected SDVariable flow
-
clearOnRead
protected boolean clearOnRead
-
-
Constructor Detail
-
TensorArray
public TensorArray(TensorArray ta)
-
TensorArray
public TensorArray(TensorArray ta, SDVariable[] inputs)
-
TensorArray
public TensorArray()
-
TensorArray
public TensorArray(DataType dataType)
-
-
Method Detail
-
tensorflowName
public String tensorflowName()
Description copied from class:DifferentialFunction
The opName of this function tensorflow- Overrides:
tensorflowName
in classDynamicCustomOp
- Returns:
-
configureFromArguments
public void configureFromArguments()
Description copied from interface:CustomOp
This allows a custom op to configure relevant fields from its arguments. This is needed when ops are created via reflection for things like model import.- Specified by:
configureFromArguments
in interfaceCustomOp
- Overrides:
configureFromArguments
in classDynamicCustomOp
-
initFromTensorFlow
public void initFromTensorFlow(NodeDef nodeDef, SameDiff initWith, Map<String,AttrValue> attributesForNode, GraphDef graph)
Description copied from class:DifferentialFunction
Initialize the function from the givenNodeDef
- Overrides:
initFromTensorFlow
in classBaseTensorOp
-
toString
public String toString()
- Overrides:
toString
in classBaseTensorOp
-
opName
public String opName()
Description copied from class:DynamicCustomOp
This method returns op opName as string- Specified by:
opName
in interfaceCustomOp
- Overrides:
opName
in classDynamicCustomOp
- Returns:
-
opType
public Op.Type opType()
Description copied from class:DifferentialFunction
The type of the op- Overrides:
opType
in classBaseTensorOp
- Returns:
-
getVar
public SDVariable getVar()
-
getSameDiff
public SameDiff getSameDiff()
-
read
public SDVariable read(int index)
-
read
public SDVariable read(SDVariable from, SDVariable index)
-
read
public SDVariable read(SDVariable index)
-
gather
public SDVariable gather(SDVariable flow, int... indices)
-
gather
public SDVariable gather(SDVariable flow, SDVariable indices)
-
stack
public SDVariable stack(SDVariable flow)
-
concat
public SDVariable concat(SDVariable flow)
-
write
public SDVariable write(SDVariable flow, int index, SDVariable value)
-
write
public SDVariable write(SDVariable flow, SDVariable index, SDVariable value)
-
scatter
public SDVariable scatter(SDVariable flow, SDVariable value, int... indices)
-
scatter
public SDVariable scatter(SDVariable flow, SDVariable value, SDVariable indices)
-
unstack
public SDVariable unstack(SDVariable flow, SDVariable value)
-
size
public SDVariable size(SDVariable value)
-
remove
public SDVariable remove(SDVariable value, SDVariable idx)
-
remove
public SDVariable remove(SDVariable value, int idx)
-
remove
public SDVariable remove(SDVariable value)
-
calculateOutputDataTypes
public List<DataType> calculateOutputDataTypes(List<DataType> inputDataType)
Description copied from class:DifferentialFunction
Calculate the data types for the output arrays. Though datatypes can also be inferred fromDifferentialFunction.calculateOutputShape()
, this method differs in that it does not require the input arrays to be populated. This is important as it allows us to do greedy datatype inference for the entire net - even if arrays are not available.- Overrides:
calculateOutputDataTypes
in classDifferentialFunction
- Parameters:
inputDataType
- The data types of the inputs- Returns:
- The data types of the outputs
-
getNumOutputs
public int getNumOutputs()
- Overrides:
getNumOutputs
in classBaseTensorOp
-
itemAtIndex
public static SDVariable itemAtIndex(SameDiff sd, SDVariable[] inputs)
Returns the item at the specified index in the specified list.- Parameters:
sd
- the same diff instance to useinputs
- the inputs including the relevant tensor array variable and position- Returns:
-
itemAtIndex
public static SDVariable itemAtIndex(SameDiff sd, SDVariable[] inputs, String outputVarName)
Returns the item at the specified index in the specified list. The output variable name to specify for the final output.- Parameters:
sd
- the same diff instance to useinputs
- the inputs including the relevant tensor array variable and positionoutputVarName
- the name of the output variable for the read- Returns:
-
requiredShape
public long[] requiredShape()
Returns the required shape for elements in this tensor array. If a second input is not present anIllegalArgumentException
is thrown.- Returns:
-
getTensorArray
public static TensorArray getTensorArray(SameDiff sd, SDVariable sequenceVar)
Get the associatedTensorArray
instance related to this op. Sometimes when a TensorArray op is returned it can be renamed or may not directly be the associatedTensorArray
instance. This helps discover the underlyingTensorArray
op for use to declare other operations to manipulate that instance such asread(int)
- Parameters:
sd
- the input instancesequenceVar
- the relevant variable to discover theTensorArray
for- Returns:
-
removeFromTensorArray
public static SDVariable removeFromTensorArray(SameDiff sameDiff, SDVariable inputSequence)
Remove the last element from the relevantTensorArray
- Parameters:
sameDiff
- the samediff instance to useinputSequence
- the relevant variable for the associatedTensorArray
- Returns:
-
removeFromTensorArray
public static SDVariable removeFromTensorArray(SameDiff sameDiff, SDVariable inputSequence, SDVariable position)
Remove an element from the relevantTensorArray
- Parameters:
sameDiff
- the samediff sinstance to useinputSequence
- the relevant variable for the associatedTensorArray
position
- the position to remove- Returns:
-
removeFromTensorArray
public static SDVariable removeFromTensorArray(SameDiff sameDiff, SDVariable inputSequence, SDVariable position, String outputVarName)
Remove an element from the relevantTensorArray
- Parameters:
sameDiff
- the samediff instance to useinputSequence
- the relevant variable for the associatedTensorArray
position
- the position to removeoutputVarName
- the name of the output variable- Returns:
-
sizeOfTensorArray
public static SDVariable sizeOfTensorArray(SameDiff sd, SDVariable sequence)
Create an empty sequence with the specified data type. An output variable name will be generated.- Parameters:
sd
- the samediff instance to usesequence
- the output variable of the sequence to get the size of- Returns:
- the output variable of the created sequence
-
sizeOfTensorArray
public static SDVariable sizeOfTensorArray(SameDiff sd, SDVariable sequence, String outputVarName)
Create an empty sequence with the specified data type. An output variable name will be generated.- Parameters:
sd
- the samediff instance to usesequence
- the output variable of the sequence to get the size ofoutputVarName
- the output name of the size variable- Returns:
- the output variable of the created sequence
-
createEmpty
public static SDVariable createEmpty(SameDiff sd, DataType dataType)
Create an empty sequence with the specified data type. An output variable name will be generated.- Parameters:
sd
- the samediff instance to usedataType
- the data type of the sequence- Returns:
- the output variable of the created sequence
-
createEmpty
public static SDVariable createEmpty(SameDiff sd, DataType dataType, String outputVarName)
Create an empty sequence with the specified data type.- Parameters:
sd
- the samediff instance to usedataType
- the data type of the sequenceoutputVarName
- the output variable name of the sequence- Returns:
- the output variable of the created sequence
-
createTensorArrayFrom
public static SDVariable createTensorArrayFrom(SameDiff sd, SDVariable[] inputs)
Create anTensorArray
op from the given inputs, note this is the same as callingcreateTensorArrayFrom(SameDiff, SDVariable[],String)
with null. The null value will avoid renaming the output- Parameters:
sd
- theSameDiff
instance to useinputs
- the input variables to create aTensorArray
for- Returns:
- the output variable for the tensor array
-
createTensorArrayFrom
public static SDVariable createTensorArrayFrom(SameDiff sd, SDVariable[] inputs, String outputVarName)
Create anTensorArray
op from the given inputs- Parameters:
sd
- theSameDiff
instance to useinputs
- the input variables to create aTensorArray
foroutputVarName
- the name of the output variable to use for the final output of the loop- Returns:
- the output variable for the tensor array
-
-