Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime error:cgo argument has Go pointer to Go pointer #271

Open
ze2o opened this issue Jan 17, 2022 · 2 comments
Open

runtime error:cgo argument has Go pointer to Go pointer #271

ze2o opened this issue Jan 17, 2022 · 2 comments

Comments

@ze2o
Copy link

ze2o commented Jan 17, 2022

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))}
}
@dreaminglwj
Copy link

dreaminglwj commented Jan 17, 2022 via email

@riverlaker
Copy link

riverlaker commented Jan 17, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants