optimizer_test.go 927 字节
Newer Older
H
Helin Wang 已提交
1 2
package pserver

D
dongzhihong 已提交
3 4
import (
	"io/ioutil"
D
dongzhihong 已提交
5
	"reflect"
D
dongzhihong 已提交
6 7
	"testing"
)
H
Helin Wang 已提交
8

D
dongzhihong 已提交
9 10 11
func TestOptimizerCreateRelease(t *testing.T) {
	p := Parameter{
		Name:        "a",
D
dongzhihong 已提交
12
		ElementType: Int32,
D
dzhwinter 已提交
13
	}
D
dongzhihong 已提交
14
	p.Content = []byte{1, 3}
D
dongzhihong 已提交
15
	config, err := ioutil.ReadFile("./cclient/test/testdata/optimizer.pb.txt")
D
dongzhihong 已提交
16 17 18
	if err != nil {
		t.Fatalf("read optimizer proto failed")
	}
D
dongzhihong 已提交
19 20 21 22 23
	param := ParameterWithConfig{
		Param:  p,
		Config: config,
	}
	o := newOptimizer(param)
H
Helin Wang 已提交
24 25
	o.Cleanup()
}
D
dongzhihong 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

func TestOptimizerFull(t *testing.T) {
	p := Parameter{
		Name:        "a",
		ElementType: Float32,
	}
	p.Content = []byte{1, 3}
	config, err := ioutil.ReadFile("./cclient/test/testdata/optimizer.pb.txt")
	if err != nil {
		t.Fatalf("read optimizer proto failed")
	}
	param := ParameterWithConfig{
		Param:  p,
		Config: config,
	}
	o := newOptimizer(param)
	g := Gradient(p)
	if !reflect.DeepEqual(p.Content, o.GetWeights()) {
		t.FailNow()
	}
	o.UpdateParameter(g)
	o.Cleanup()
}