MCPcopy
hub / github.com/nlpodyssey/spago / testReduceSumForward

Function testReduceSumForward

mat/gradfn/reducesum_test.go:20–33  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18}
19
20func testReduceSumForward[T float.DType](t *testing.T) {
21 x := mat.NewDense[T](mat.WithBacking([]T{0.1, 0.2, 0.3, 0.0}), mat.WithGrad(true))
22
23 f := NewReduceSum(x)
24 assert.Equal(t, []mat.Tensor{x}, f.Operands())
25
26 y, err := f.Forward()
27 assert.Nil(t, err)
28 assert.InDeltaSlice(t, []T{0.6}, y.Data(), 1.0e-6)
29
30 err = f.Backward(mat.NewDense[T](mat.WithBacking([]T{0.5})))
31 assert.Nil(t, err)
32 assert.InDeltaSlice(t, []T{0.5, 0.5, 0.5, 0.5}, x.Grad().Data(), 1.0e-6)
33}

Callers

nothing calls this directly

Calls 8

WithBackingFunction · 0.92
WithGradFunction · 0.92
NewReduceSumFunction · 0.85
OperandsMethod · 0.65
ForwardMethod · 0.65
DataMethod · 0.65
BackwardMethod · 0.65
GradMethod · 0.65

Tested by

no test coverage detected