Exemple #1
0
func Dir3d(r *rng.GslRng) (float64, float64, float64) {
	var _outptr_1 C.double
	var _outptr_2 C.double
	var _outptr_3 C.double
	C.gsl_ran_dir_3d((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), &_outptr_1, &_outptr_2, &_outptr_3)
	return *(*float64)(unsafe.Pointer(&_outptr_1)), *(*float64)(unsafe.Pointer(&_outptr_2)), *(*float64)(unsafe.Pointer(&_outptr_3))
}
Exemple #2
0
func Shuffle(rng *rng.GslRng, data interface{}, n int) {
	// data must be a slice
	dataType := reflect.TypeOf(data)
	if dataType.Kind() != reflect.Slice {
		gogsl.Error("rng.Shuffle() must have a slice as its second argument", gogsl.GSL_EINVAL)
		return
	}
	baseType := dataType.Elem()
	dataVal := reflect.ValueOf(data)
	sliceN := dataVal.Len()
	if sliceN < 0 {
		gogsl.Error("shuffle length may not be negative in rng.Shuffle()", gogsl.GSL_EINVAL)
		return
	}
	if sliceN < n {
		gogsl.Error("shuffle length too large for slice in rng.Shuffle()", gogsl.GSL_EINVAL)
		return
	}
	elementLen := baseType.Size()
	addr := dataVal.Index(0).UnsafeAddr()

	//hdr := (*reflect.SliceHeader)(unsafe.Pointer(addr))
	//void gsl_ran_shuffle (const gsl_rng * r, void * base, size_t n, size_t size)
	C.gsl_ran_shuffle((*C.gsl_rng)(unsafe.Pointer(rng.Ptr())),
		unsafe.Pointer(addr),
		C.size_t(n), C.size_t(elementLen))
}
Exemple #3
0
func Solve(r *rng.GslRng, x0 interface{},
	ef GslSimanEnergyFunctionType,
	takeStep GslSimanStepFunctionType,
	distance GslSimanMetricFunctionType,
	printPosition GslSimanPrintFunctionType,
	copyfunc GslSimanCopyFunctionType,
	copyConstructor GslSimanCopyConstructFunctionType,
	destructor GslSimanDestroyFunctionType,
	params *GslSimanParams) {

	impl := &GslSimanImplementation{
		energyFn: ef,
		stepFn:   takeStep,
		metricFn: distance,
		printFn:  printPosition,
		copyFn:   copyfunc,
		ctorFn:   copyConstructor,
		freeFn:   destructor,
		holdRefs: make(map[uintptr]*GslSimanArgument),
	}

	initialArg := &GslSimanArgument{
		impl: impl,
		x:    x0,
	}
	InitializeGslSimanParams(params)
	var printFn *[0]byte
	if impl.printFn != nil {
		printFn = (*[0]byte)(C._gsl_siman_print_function_proxy)
	}
	C.gsl_siman_solve((*C.gsl_rng)(unsafe.Pointer(r.Ptr())),
		unsafe.Pointer(initialArg),
		(*[0]byte)(C._gsl_siman_energy_function_proxy),
		(*[0]byte)(C._gsl_siman_step_function_proxy),
		(*[0]byte)(C._gsl_siman_metric_function_proxy),
		printFn,
		(*[0]byte)(C._gsl_siman_copy_function_proxy),
		(*[0]byte)(C._gsl_siman_ctor_function_proxy),
		(*[0]byte)(C._gsl_siman_dtor_function_proxy),
		C.size_t(GSL_SIMAN_ARGUMENT_SIZE),
		*(*C.gsl_siman_params_t)(unsafe.Pointer(params.CPtr())))
}
Exemple #4
0
// void gsl_ran_sample (const gsl_rng * r, void * dest, size_t k, void * src, size_t n, size_t size)
func Choose(rng *rng.GslRng, dest interface{}, src interface{}, n int) int {
	// data must be a slice
	destDataType := reflect.TypeOf(dest)
	if destDataType.Kind() != reflect.Slice {
		gogsl.Error("rng.Choose() must have a slice as its second argument", gogsl.GSL_EINVAL)
		return int(gogsl.GSL_EINVAL)
	}
	srcDataType := reflect.TypeOf(src)
	if srcDataType.Kind() != reflect.Slice {
		gogsl.Error("rng.Choose() must have a slice as its third argument", gogsl.GSL_EINVAL)
		return int(gogsl.GSL_EINVAL)
	}
	if destDataType != srcDataType {
		gogsl.Error("rng.Choose() source and destination data types must match", gogsl.GSL_EINVAL)
		return int(gogsl.GSL_EINVAL)
	}
	if n < 0 {
		gogsl.Error("length may not be negative in rng.Choose()", gogsl.GSL_EINVAL)
		return int(gogsl.GSL_EINVAL)
	}
	baseType := destDataType.Elem()
	destVal := reflect.ValueOf(dest)
	srcVal := reflect.ValueOf(src)
	sliceN := destVal.Len()
	if sliceN < n {
		gogsl.Error("sample length too large for slice in rng.Choose()", gogsl.GSL_EINVAL)
		return int(gogsl.GSL_EINVAL)
	}
	if srcVal.Len() < n {
		gogsl.Error("sample length too large for source in rng.Choose()", gogsl.GSL_EINVAL)
		return int(gogsl.GSL_EINVAL)
	}
	elementLen := baseType.Size()
	srcAddr := srcVal.Index(0).UnsafeAddr()
	destAddr := destVal.Index(0).UnsafeAddr()
	return int(C.gsl_ran_choose((*C.gsl_rng)(unsafe.Pointer(rng.Ptr())),
		unsafe.Pointer(destAddr), C.size_t(sliceN),
		unsafe.Pointer(srcAddr), C.size_t(srcVal.Len()),
		C.size_t(elementLen)))
}
Exemple #5
0
func Multinomial(r *rng.GslRng, k int, n uint32, p []float64, x []uint32) {
	_slice_header_3 := (*reflect.SliceHeader)(unsafe.Pointer(&p))
	_slice_header_4 := (*reflect.SliceHeader)(unsafe.Pointer(&x))
	C.gsl_ran_multinomial((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.size_t(k), C.uint(n), (*C.double)(unsafe.Pointer(_slice_header_3.Data)), (*C.uint)(unsafe.Pointer(_slice_header_4.Data)))
}
Exemple #6
0
func Fdist(r *rng.GslRng, nu1 float64, nu2 float64) float64 {
	return float64(C.gsl_ran_fdist((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(nu1), C.double(nu2)))
}
Exemple #7
0
func Bernoulli(r *rng.GslRng, p float64) uint32 {
	return uint32(C.gsl_ran_bernoulli((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(p)))
}
Exemple #8
0
func BivariateGaussian(r *rng.GslRng, sigmaX float64, sigmaY float64, rho float64) (float64, float64) {
	var _outptr_4 C.double
	var _outptr_5 C.double
	C.gsl_ran_bivariate_gaussian((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(sigmaX), C.double(sigmaY), C.double(rho), &_outptr_4, &_outptr_5)
	return *(*float64)(unsafe.Pointer(&_outptr_4)), *(*float64)(unsafe.Pointer(&_outptr_5))
}
Exemple #9
0
func GaussianZiggurat(r *rng.GslRng, sigma float64) float64 {
	return float64(C.gsl_ran_gaussian_ziggurat((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(sigma)))
}
Exemple #10
0
func Geometric(r *rng.GslRng, p float64) uint32 {
	return uint32(C.gsl_ran_geometric((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(p)))
}
Exemple #11
0
func Logarithmic(r *rng.GslRng, p float64) uint32 {
	return uint32(C.gsl_ran_logarithmic((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(p)))
}
Exemple #12
0
func Lognormal(r *rng.GslRng, zeta float64, sigma float64) float64 {
	return float64(C.gsl_ran_lognormal((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(zeta), C.double(sigma)))
}
Exemple #13
0
func DirNd(r *rng.GslRng, n int) float64 {
	var _outptr_2 C.double
	C.gsl_ran_dir_nd((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.size_t(n), &_outptr_2)
	return *(*float64)(unsafe.Pointer(&_outptr_2))
}
Exemple #14
0
func UgaussianRatioMethod(r *rng.GslRng) float64 {
	return float64(C.gsl_ran_ugaussian_ratio_method((*C.gsl_rng)(unsafe.Pointer(r.Ptr()))))
}
Exemple #15
0
func Dir2dTrigMethod(r *rng.GslRng) (float64, float64) {
	var _outptr_1 C.double
	var _outptr_2 C.double
	C.gsl_ran_dir_2d_trig_method((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), &_outptr_1, &_outptr_2)
	return *(*float64)(unsafe.Pointer(&_outptr_1)), *(*float64)(unsafe.Pointer(&_outptr_2))
}
Exemple #16
0
func Logistic(r *rng.GslRng, a float64) float64 {
	return float64(C.gsl_ran_logistic((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(a)))
}
Exemple #17
0
func Tdist(r *rng.GslRng, nu float64) float64 {
	return float64(C.gsl_ran_tdist((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(nu)))
}
Exemple #18
0
func Ugaussian(r *rng.GslRng) float64 {
	return float64(C.gsl_ran_ugaussian((*C.gsl_rng)(unsafe.Pointer(r.Ptr()))))
}
Exemple #19
0
func NegativeBinomial(r *rng.GslRng, p float64, n float64) uint32 {
	return uint32(C.gsl_ran_negative_binomial((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(p), C.double(n)))
}
Exemple #20
0
func Weibull(r *rng.GslRng, a float64, b float64) float64 {
	return float64(C.gsl_ran_weibull((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(a), C.double(b)))
}
Exemple #21
0
func Pascal(r *rng.GslRng, p float64, n uint32) uint32 {
	return uint32(C.gsl_ran_pascal((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(p), C.uint(n)))
}
Exemple #22
0
func Gumbel2(r *rng.GslRng, a float64, b float64) float64 {
	return float64(C.gsl_ran_gumbel2((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(a), C.double(b)))
}
Exemple #23
0
func Hypergeometric(r *rng.GslRng, n1 uint32, n2 uint32, t uint32) uint32 {
	return uint32(C.gsl_ran_hypergeometric((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.uint(n1), C.uint(n2), C.uint(t)))
}
Exemple #24
0
func GammaKnuth(r *rng.GslRng, a float64, b float64) float64 {
	return float64(C.gsl_ran_gamma_knuth((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(a), C.double(b)))
}
Exemple #25
0
func UgaussianTail(r *rng.GslRng, a float64) float64 {
	return float64(C.gsl_ran_ugaussian_tail((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(a)))
}
Exemple #26
0
func Discrete(r *rng.GslRng, g *GslRanDiscreteT) int {
	return int(C.gsl_ran_discrete((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), (*C.gsl_ran_discrete_t)(unsafe.Pointer(g.Ptr()))))
}
Exemple #27
0
func MiserIntegrate(f *gogsl.GslMonteFunction, xl []float64, xu []float64, dim int, calls int, r *rng.GslRng, s *GslMonteMiserState) (int32, float64, float64) {
	var _outptr_7 C.double
	var _outptr_8 C.double
	gogsl.InitializeGslMonteFunction(f)
	_slice_header_1 := (*reflect.SliceHeader)(unsafe.Pointer(&xl))
	_slice_header_2 := (*reflect.SliceHeader)(unsafe.Pointer(&xu))
	_result := int32(C.gsl_monte_miser_integrate((*C.gsl_monte_function)(unsafe.Pointer(f.CPtr())), (*C.double)(unsafe.Pointer(_slice_header_1.Data)), (*C.double)(unsafe.Pointer(_slice_header_2.Data)), C.size_t(dim), C.size_t(calls), (*C.gsl_rng)(unsafe.Pointer(r.Ptr())), (*C.gsl_monte_miser_state)(unsafe.Pointer(s.Ptr())), &_outptr_7, &_outptr_8))
	return _result, *(*float64)(unsafe.Pointer(&_outptr_7)), *(*float64)(unsafe.Pointer(&_outptr_8))
}
Exemple #28
0
func Poisson(r *rng.GslRng, mu float64) uint32 {
	return uint32(C.gsl_ran_poisson((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(mu)))
}
Exemple #29
0
func Dirichlet(r *rng.GslRng, k int, alpha []float64, theta []float64) {
	_slice_header_2 := (*reflect.SliceHeader)(unsafe.Pointer(&alpha))
	_slice_header_3 := (*reflect.SliceHeader)(unsafe.Pointer(&theta))
	C.gsl_ran_dirichlet((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.size_t(k), (*C.double)(unsafe.Pointer(_slice_header_2.Data)), (*C.double)(unsafe.Pointer(_slice_header_3.Data)))
}
Exemple #30
0
func GaussianRatioMethod(r *rng.GslRng, sigma float64) float64 {
	return float64(C.gsl_ran_gaussian_ratio_method((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(sigma)))
}