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 booleanclearOnReadprotected SDVariableflowprotected DataTypetensorArrayDataType-
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.SDVariableconcat(SDVariable flow)voidconfigureFromArguments()This allows a custom op to configure relevant fields from its arguments.static SDVariablecreateEmpty(SameDiff sd, DataType dataType)Create an empty sequence with the specified data type.static SDVariablecreateEmpty(SameDiff sd, DataType dataType, String outputVarName)Create an empty sequence with the specified data type.static SDVariablecreateTensorArrayFrom(SameDiff sd, SDVariable[] inputs)Create anTensorArrayop from the given inputs, note this is the same as callingcreateTensorArrayFrom(SameDiff, SDVariable[],String)with null.static SDVariablecreateTensorArrayFrom(SameDiff sd, SDVariable[] inputs, String outputVarName)Create anTensorArrayop from the given inputsSDVariablegather(SDVariable flow, int... indices)SDVariablegather(SDVariable flow, SDVariable indices)intgetNumOutputs()SameDiffgetSameDiff()static TensorArraygetTensorArray(SameDiff sd, SDVariable sequenceVar)Get the associatedTensorArrayinstance related to this op.SDVariablegetVar()voidinitFromTensorFlow(NodeDef nodeDef, SameDiff initWith, Map<String,AttrValue> attributesForNode, GraphDef graph)Initialize the function from the givenNodeDefstatic SDVariableitemAtIndex(SameDiff sd, SDVariable[] inputs)Returns the item at the specified index in the specified list.static SDVariableitemAtIndex(SameDiff sd, SDVariable[] inputs, String outputVarName)Returns the item at the specified index in the specified list.StringopName()This method returns op opName as stringOp.TypeopType()The type of the opSDVariableread(int index)SDVariableread(SDVariable index)SDVariableread(SDVariable from, SDVariable index)SDVariableremove(SDVariable value)SDVariableremove(SDVariable value, int idx)SDVariableremove(SDVariable value, SDVariable idx)static SDVariableremoveFromTensorArray(SameDiff sameDiff, SDVariable inputSequence)Remove the last element from the relevantTensorArraystatic SDVariableremoveFromTensorArray(SameDiff sameDiff, SDVariable inputSequence, SDVariable position)Remove an element from the relevantTensorArraystatic SDVariableremoveFromTensorArray(SameDiff sameDiff, SDVariable inputSequence, SDVariable position, String outputVarName)Remove an element from the relevantTensorArraylong[]requiredShape()Returns the required shape for elements in this tensor array.SDVariablescatter(SDVariable flow, SDVariable value, int... indices)SDVariablescatter(SDVariable flow, SDVariable value, SDVariable indices)SDVariablesize(SDVariable value)static SDVariablesizeOfTensorArray(SameDiff sd, SDVariable sequence)Create an empty sequence with the specified data type.static SDVariablesizeOfTensorArray(SameDiff sd, SDVariable sequence, String outputVarName)Create an empty sequence with the specified data type.SDVariablestack(SDVariable flow)StringtensorflowName()The opName of this function tensorflowStringtoString()SDVariableunstack(SDVariable flow, SDVariable value)SDVariablewrite(SDVariable flow, int index, SDVariable value)SDVariablewrite(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:DifferentialFunctionThe opName of this function tensorflow- Overrides:
tensorflowNamein classDynamicCustomOp- Returns:
-
configureFromArguments
public void configureFromArguments()
Description copied from interface:CustomOpThis 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:
configureFromArgumentsin interfaceCustomOp- Overrides:
configureFromArgumentsin classDynamicCustomOp
-
initFromTensorFlow
public void initFromTensorFlow(NodeDef nodeDef, SameDiff initWith, Map<String,AttrValue> attributesForNode, GraphDef graph)
Description copied from class:DifferentialFunctionInitialize the function from the givenNodeDef- Overrides:
initFromTensorFlowin classBaseTensorOp
-
toString
public String toString()
- Overrides:
toStringin classBaseTensorOp
-
opName
public String opName()
Description copied from class:DynamicCustomOpThis method returns op opName as string- Specified by:
opNamein interfaceCustomOp- Overrides:
opNamein classDynamicCustomOp- Returns:
-
opType
public Op.Type opType()
Description copied from class:DifferentialFunctionThe type of the op- Overrides:
opTypein 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:DifferentialFunctionCalculate 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:
calculateOutputDataTypesin classDifferentialFunction- Parameters:
inputDataType- The data types of the inputs- Returns:
- The data types of the outputs
-
getNumOutputs
public int getNumOutputs()
- Overrides:
getNumOutputsin 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 anIllegalArgumentExceptionis thrown.- Returns:
-
getTensorArray
public static TensorArray getTensorArray(SameDiff sd, SDVariable sequenceVar)
Get the associatedTensorArrayinstance related to this op. Sometimes when a TensorArray op is returned it can be renamed or may not directly be the associatedTensorArrayinstance. This helps discover the underlyingTensorArrayop for use to declare other operations to manipulate that instance such asread(int)- Parameters:
sd- the input instancesequenceVar- the relevant variable to discover theTensorArrayfor- 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 associatedTensorArrayposition- 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 associatedTensorArrayposition- 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 anTensorArrayop 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- theSameDiffinstance to useinputs- the input variables to create aTensorArrayfor- Returns:
- the output variable for the tensor array
-
createTensorArrayFrom
public static SDVariable createTensorArrayFrom(SameDiff sd, SDVariable[] inputs, String outputVarName)
Create anTensorArrayop from the given inputs- Parameters:
sd- theSameDiffinstance to useinputs- the input variables to create aTensorArrayforoutputVarName- the name of the output variable to use for the final output of the loop- Returns:
- the output variable for the tensor array
-
-