@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(); }