Class: Gsplat::Ops::FeatureSlice
- Inherits:
-
Autograd::Function
- Object
- Autograd::Function
- Gsplat::Ops::FeatureSlice
- Defined in:
- lib/gsplat/ops/tensor_shape_ops.rb
Overview
Extracts a contiguous interval from the last tensor axis.
Class Method Summary collapse
Methods inherited from Autograd::Function
Class Method Details
.backward(context, gradient) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/gsplat/ops/tensor_shape_ops.rb', line 131 def backward(context, gradient) shape, start, stop = context.saved_values output = gradient.class.zeros(*shape) output[*Array.new(output.ndim - 1, true), start...stop] = gradient [output, nil] end |
.forward(context, value, range) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/gsplat/ops/tensor_shape_ops.rb', line 117 def forward(context, value, range) unless range.is_a?(Range) && range.begin.is_a?(Integer) && range.end.is_a?(Integer) raise ArgumentError, "feature range must have integer bounds" end stop = range.exclude_end? ? range.end : range.end + 1 unless range.begin.between?(0, value.shape[-1]) && stop.between?(range.begin, value.shape[-1]) raise ShapeError, "feature range #{range.inspect} is outside #{value.shape.inspect}" end context.save(value.shape, range.begin, stop) value[*Array.new(value.ndim - 1, true), range.begin...stop].dup end |