@Override public Tensor<V> perform(Tensor<V> tensor) { Shape shape = tensor.shape(); Builder<V> builder = ImmutableTensor.builder(shape.dimensionSet()); for (Position position : shape.positionSet()) { builder.at(position).put(elementOperation.perform(tensor.get(position))); } return builder.build(); }
public <C extends Comparable<C>> Tensor<E> by( Class<C> coordinateClass, Range<C> coordinateRange) { checkNotNull(coordinateClass, "coordinateClass must not be null"); checkNotNull(coordinateRange, "coordinateRange must not be null"); ImmutableTensor.Builder<E> builder = ImmutableTensor.builder(tensor.shape().dimensionSet()); builder.setTensorContext(tensor.context()); for (Entry<Position, E> entry : tensor.asMap().entrySet()) { if (coordinateRange.contains(entry.getKey().coordinateFor(coordinateClass))) { builder.putAt(entry.getValue(), entry.getKey()); } } return builder.build(); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((backingTensor == null) ? 0 : backingTensor.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } AbstractTensorbacked<?> other = (AbstractTensorbacked<?>) obj; if (backingTensor == null) { if (other.backingTensor != null) { return false; } } else if (!backingTensor.equals(other.backingTensor)) { return false; } return true; }