public Tensor transform(Tensor tensor) {
//TODO review
Tensor parent = tensor.getParent();
TensorWrapper wrapper = new TensorWrapper(tensor);
TensorLastTreeIterator iterator = new TensorLastTreeIterator(wrapper, new Guide(), EquivalentTransformation.INSTANCE);
Tensor current;
OUT_FOR:
while (iterator.hasNext()) {
current = iterator.next();
if (current instanceof Sum && ((Sum) current).isEmpty()) {
subsZero(iterator);
continue;
}
if (current.getClass() != getFromClasss())
continue;
T _current = (T) current;
if (_current.getName() != from.getName())
continue;
if (IndexMappings.createPortForSimpleTensor(from, _current, allowDiffStates).take() == null)
continue;
if (!canMatch(from, _current))
continue;
if (iterator.isUnderIterator(Derivative.onTargetIndicator, Integer.MAX_VALUE)) {
for (Tensor[] vars : derivativesVars) {
int i;
if ((i = Arrays.binarySearch(vars, current)) >= 0) {
if (!allowDiffStates) {
//TODO discover all possibiliyies