Class AbstractDependencyTracker<T,D>
- java.lang.Object
-
- org.nd4j.autodiff.samediff.internal.AbstractDependencyTracker<T,D>
-
- Direct Known Subclasses:
DependencyTracker
,HashDependencyTracker
,IdentityDependencyTracker
public abstract class AbstractDependencyTracker<T,D> extends Object
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDependencyTracker()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addDependency(T y, D x)
Add a dependency: y depends on x, as in x -> yvoid
addOrDependency(T y, D x1, D x2)
Add an "Or" dependency: Y requires either x1 OR x2 - i.e., (x1 or x2) -> Y
If either x1 or x2 (or both) are marked satisfied viamarkSatisfied(Object, boolean)
then the dependency is considered satisfiedprotected void
checkAndUpdateIfAllSatisfied(T y)
void
clear()
Clear all internal state for the dependency trackerDependencyList<T,D>
getDependencies(T y)
Get all dependencies x, for x -> y, and (x1 or x2) -> yT
getFirstNewAllSatisfiedMatching(@NonNull Predicate<T> predicate)
As pergetNewAllSatisfied()
but instead of returning the first dependee, it returns the first that matches the provided predicate.T
getNewAllSatisfied()
Returns the next new dependent (Y in X->Y) that has all dependees (Xs) marked as satisfied viamarkSatisfied(Object, boolean)
Throws an exception ifhasNewAllSatisfied()
returns false.
Note that once a value has been retrieved from here, no new dependencies of the form (X -> Y) can be added for this value; the value is considered "processed" at this point.List<T>
getNewAllSatisfiedList()
boolean
hasDependency(T y)
Check whether any dependencies x -> y exist, for y (i.e., anything previously added byaddDependency(Object, Object)
oraddOrDependency(Object, Object, Object)
boolean
hasNewAllSatisfied()
protected boolean
isAllSatisfied(T y)
boolean
isEmpty()
boolean
isSatisfied(D x)
void
markSatisfied(D x, boolean satisfied)
Mark the specified value as satisfied.protected abstract IDependencyMap<T,?>
newTMap()
protected abstract Set<T>
newTSet()
void
removeDependency(T y, D x)
Remove a dependency (x -> y)protected abstract String
toStringD(D d)
protected abstract String
toStringT(T t)
-
-
-
Method Detail
-
newTMap
protected abstract IDependencyMap<T,?> newTMap()
- Returns:
- A new map where the dependents (i.e., Y in "X -> Y") are the key
-
newTSet
protected abstract Set<T> newTSet()
- Returns:
- A new set where the dependents (i.e., Y in "X -> Y") are the key
-
toStringT
protected abstract String toStringT(T t)
- Returns:
- A String representation of the dependent object
-
toStringD
protected abstract String toStringD(D d)
- Returns:
- A String representation of the dependee object
-
clear
public void clear()
Clear all internal state for the dependency tracker
-
isEmpty
public boolean isEmpty()
- Returns:
- True if no dependencies have been defined
-
isSatisfied
public boolean isSatisfied(@NonNull D x)
- Returns:
- True if the dependency has been marked as satisfied using
markSatisfied(Object, boolean)
-
markSatisfied
public void markSatisfied(@NonNull D x, boolean satisfied)
Mark the specified value as satisfied. For example, if two dependencies have been previously added (X -> Y) and (X -> A) then after the markSatisfied(X, true) call, both of these dependencies are considered satisfied.- Parameters:
x
- Value to marksatisfied
- Whether to mark as satisfied (true) or unsatisfied (false)
-
hasDependency
public boolean hasDependency(@NonNull T y)
Check whether any dependencies x -> y exist, for y (i.e., anything previously added byaddDependency(Object, Object)
oraddOrDependency(Object, Object, Object)
- Parameters:
y
- Dependent to check- Returns:
- True if Y depends on any values
-
getDependencies
public DependencyList<T,D> getDependencies(@NonNull T y)
Get all dependencies x, for x -> y, and (x1 or x2) -> y- Parameters:
y
- Dependent to get dependencies for- Returns:
- List of dependencies
-
addDependency
public void addDependency(@NonNull T y, @NonNull D x)
Add a dependency: y depends on x, as in x -> y- Parameters:
y
- The dependentx
- The dependee that is required for Y
-
checkAndUpdateIfAllSatisfied
protected void checkAndUpdateIfAllSatisfied(@NonNull T y)
-
isAllSatisfied
protected boolean isAllSatisfied(@NonNull T y)
-
removeDependency
public void removeDependency(@NonNull T y, @NonNull D x)
Remove a dependency (x -> y)- Parameters:
y
- The dependent that currently requires Xx
- The dependee that is no longer required for Y
-
addOrDependency
public void addOrDependency(@NonNull T y, @NonNull D x1, @NonNull D x2)
Add an "Or" dependency: Y requires either x1 OR x2 - i.e., (x1 or x2) -> Y
If either x1 or x2 (or both) are marked satisfied viamarkSatisfied(Object, boolean)
then the dependency is considered satisfied- Parameters:
y
- Dependentx1
- Dependee 1x2
- Dependee 2
-
hasNewAllSatisfied
public boolean hasNewAllSatisfied()
- Returns:
- True if there are any new/unprocessed "all satisfied dependents" (Ys in X->Y)
-
getNewAllSatisfied
public T getNewAllSatisfied()
Returns the next new dependent (Y in X->Y) that has all dependees (Xs) marked as satisfied viamarkSatisfied(Object, boolean)
Throws an exception ifhasNewAllSatisfied()
returns false.
Note that once a value has been retrieved from here, no new dependencies of the form (X -> Y) can be added for this value; the value is considered "processed" at this point.- Returns:
- The next new "all satisfied dependent"
-
getNewAllSatisfiedList
public List<T> getNewAllSatisfiedList()
- Returns:
- As per
getNewAllSatisfied()
but returns all values
-
getFirstNewAllSatisfiedMatching
public T getFirstNewAllSatisfiedMatching(@NonNull @NonNull Predicate<T> predicate)
As pergetNewAllSatisfied()
but instead of returning the first dependee, it returns the first that matches the provided predicate. If no value matches the predicate, null is returned- Parameters:
predicate
- Predicate gor checking- Returns:
- The first value matching the predicate, or null if no values match the predicate
-
-