45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/gsplat/ops/tensor_shape_ops.rb', line 45
def forward(context, means, viewmats)
unless means.ndim == 2 && means.shape[-1] == 3 &&
viewmats.ndim == 3 && viewmats.shape[1..] == [4, 4]
raise ShapeError,
"expected means [N,3] and viewmats [C,4,4], " \
"got #{means.shape.inspect} and #{viewmats.shape.inspect}"
end
output = means.class.zeros(viewmats.shape[0], means.shape[0], 3)
viewmats.shape[0].times do |camera_index|
rotation = means.class.cast(viewmats[camera_index, 0...3, 0...3])
translation = means.class.cast(viewmats[camera_index, 0...3, 3])
camera_center = -translation.dot(rotation)
output[camera_index, true, true] = means - camera_center
end
context.save(means.shape)
output
end
|