Exemple #1
0
//export fit_go_f
func fit_go_f(x C.const_gsl_vector, fn unsafe.Pointer, f *C.gsl_vector) C.int {
	gofn := *((*FitData)(fn))
	gx := vecFromGSL(x)
	for i := 0; i < gofn.N; i++ {
		val, err := gofn.F(gx, i)
		if err != nil {
			// Assume that if F returns an error, x is outside
			// the domain.
			return C.GSL_EDOM
		}
		C.gsl_vector_set(f, C.size_t(i), C.double(val))
	}
	return C.GSL_SUCCESS
}
Exemple #2
0
// Convert v to GSL format.
func VecToGSL(v vec.Vector, target *C.gsl_vector) {
	dim := len(v)
	for i := 0; i < dim; i++ {
		C.gsl_vector_set(target, C.size_t(i), C.double(v[i]))
	}
}