Class: Gsplat::Ops::AddClampMin

Inherits:
Autograd::Function show all
Defined in:
lib/gsplat/ops/tensor_value_ops.rb

Overview

Adds an offset and applies a lower clamp.

Class Method Summary collapse

Methods inherited from Autograd::Function

apply

Class Method Details

.backward(context, gradient) ⇒ Object

rubocop:disable Metrics/AbcSize



17
18
19
20
# File 'lib/gsplat/ops/tensor_value_ops.rb', line 17

def backward(context, gradient)
  mask = gradient.class.cast(context.saved_values.fetch(0))
  [gradient * mask]
end

.forward(context, value, offset:, minimum:) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/gsplat/ops/tensor_value_ops.rb', line 8

def forward(context, value, offset:, minimum:)
  shifted = value + offset
  context.save(shifted.gt(minimum))
  below = shifted.lt(minimum)
  shifted[below] = minimum if below.any?
  shifted
end