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

Function testSafeLogForward

mat/gradfn/misc_test.go:41–53  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func testSafeLogForward[T float.DType](t *testing.T) {
42 x := mat.NewDense[T](mat.WithBacking([]T{0.1, 0.2, 0.3, 0.0}), mat.WithGrad(true))
43 f := NewLog(x)
44 y, err := f.Forward()
45 assert.Nil(t, err)
46
47 assert.InDeltaSlice(t, []T{-2.3025855, -1.6094379, -1.203972, mat.Inf[T](-1)}, y.Data(), 1.0e-5)
48
49 err = f.Backward(mat.NewDense[T](mat.WithBacking([]T{-1.0, 0.5, 0.8, 0.0})))
50 assert.Nil(t, err)
51
52 assert.InDeltaSlice(t, []T{-10.0, 2.5, 2.6666666666, 0}, x.Grad().Data(), 1.0e-6)
53}
54
55func TestTan_Forward(t *testing.T) {
56 t.Run("float32", testTanForward[float32])

Callers

nothing calls this directly

Calls 7

WithBackingFunction · 0.92
WithGradFunction · 0.92
NewLogFunction · 0.85
ForwardMethod · 0.65
DataMethod · 0.65
BackwardMethod · 0.65
GradMethod · 0.65

Tested by

no test coverage detected