Class: Gsplat::Ops::ConcatCoefficients

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

Overview

Joins the direct-current and remaining SH coefficient blocks.

Class Method Summary collapse

Methods inherited from Autograd::Function

apply

Class Method Details

.backward(context, gradient) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/gsplat/ops/tensor_value_ops.rb', line 105

def backward(context, gradient)
  direct_count = context.saved_values.first
  [
    gradient[true, 0...direct_count, true].dup,
    gradient[true, direct_count...gradient.shape[1], true].dup
  ]
end

.forward(context, direct, rest) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/gsplat/ops/tensor_value_ops.rb', line 91

def forward(context, direct, rest)
  unless direct.ndim == 3 && rest.ndim == 3 &&
         direct.shape[0] == rest.shape[0] && direct.shape[2] == rest.shape[2]
    raise ShapeError, "cannot concatenate SH shapes #{direct.shape.inspect} and #{rest.shape.inspect}"
  end

  direct_count = direct.shape[1]
  output = direct.class.zeros(direct.shape[0], direct_count + rest.shape[1], direct.shape[2])
  output[true, 0...direct_count, true] = direct
  output[true, direct_count...output.shape[1], true] = rest
  context.save(direct_count)
  output
end