Runtime error: cgo argument has Go pointer to Go pointer

Hi I get an error related to C and Go pointers when the below function is called from another go code. The line where the error happens is highlighted with a comment “ERROR happens here”. I tried some of the solutions suggested in this forum and elsewhere but with no luck. Any help is appreciated. I am using go1.11.12 on linux/amd64.

func LevmarExpr(e expr.Expr, searchDim int, task ExprProblemType, guess []float64, train, test []*PointSet) []float64 {

ps := train[0].NumPoints()
PS := len(train) * ps

c := make([]float64, len(guess))
var cd callback_data
cd.Train = train
cd.Test = test
cd.E = e
cd.Coeff = c
cd.Task = task
cd.J = make([]expr.Expr, len(guess))
for i, _ := range cd.J {
	deriv := e.DerivConst(i)
	// simp := deriv.Simplify(expr.DefaultRules())
	cd.J[i] = deriv
}

// c/levmar inputs
coeff := make([]C.double, len(guess))
for i, g := range guess {
	coeff[i] = C.double(g)
}

y := make([]C.double, PS)
for i1, T := range train {
	for i2, p := range T.Points() {
		i := i1*ps + i2
		y[i] = C.double(p.Depnd(searchDim))
	}
}
ya := (*C.double)(unsafe.Pointer(&y[0]))
ca := (*C.double)(unsafe.Pointer(&coeff[0]))
ni := C.int(PS)
mi := C.int(len(c))

// C.levmar_dif(ya, ca, mi, ni, unsafe.Pointer(&cd))
C.levmar_der(ya, ca, mi, ni, unsafe.Pointer(&cd))   // ERROR happens here

for i, _ := range coeff {
	c[i] = float64(coeff[i])
}
return c

}

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.