golearn icon indicating copy to clipboard operation
golearn copied to clipboard

runtime error:cgo argument has Go pointer to Go pointer

Open ze2o opened this issue 3 years ago • 2 comments

there is a error when I run TestLogistic.Error info is "Line 20: - runtime error: cgo argument has Go pointer to Go pointer ", file is "golearn-master/linear_models/logistic_test.go"

When Initing prob.c_prob.x and prob.c_prob.y in func NewProblem, it allocates memory in Go, we need to allocate the pointer memory in C, not Go.

func NewProblem(X [][]float64, y []float64, bias float64) *Problem {
	prob := Problem{}
	prob.c_prob.l = C.int(len(X))
	prob.c_prob.n = C.int(len(X[0]) + 1)

	prob.c_prob.x = convert_features(X, bias)
	c_y := make([]C.double, len(y))
	for i := 0; i < len(y); i++ {
		c_y[i] = C.double(y[i])
	}
	prob.c_prob.y = &c_y[0]
	prob.c_prob.bias = C.double(-1)

	return &prob
}

So there is error in function Fit to call Train

func Train(prob *Problem, param *Parameter) *Model {
	libLinearHookPrintFunc() // Sets up logging
	tmpCProb := &prob.c_prob
	tmpCParam := &param.c_param
	return &Model{unsafe.Pointer(C.train(tmpCProb, tmpCParam))}
}

ze2o avatar Jan 17 '22 08:01 ze2o

您好,您的邮件已收到,我会尽快查看,^_^

dreaminglwj avatar Jan 17 '22 08:01 dreaminglwj

邮件已收到,谢谢!                  ——赵淼

riverlaker avatar Jan 17 '22 08:01 riverlaker