예제 #1
0
파일: randist.go 프로젝트: postfix/gsl-1
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))
}
예제 #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))
}
예제 #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())))
}
예제 #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)))
}
예제 #5
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #6
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #7
0
파일: randist.go 프로젝트: postfix/gsl-1
func Bernoulli(r *rng.GslRng, p float64) uint32 {
	return uint32(C.gsl_ran_bernoulli((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(p)))
}
예제 #8
0
파일: randist.go 프로젝트: postfix/gsl-1
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))
}
예제 #9
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #10
0
파일: randist.go 프로젝트: postfix/gsl-1
func Geometric(r *rng.GslRng, p float64) uint32 {
	return uint32(C.gsl_ran_geometric((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(p)))
}
예제 #11
0
파일: randist.go 프로젝트: postfix/gsl-1
func Logarithmic(r *rng.GslRng, p float64) uint32 {
	return uint32(C.gsl_ran_logarithmic((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(p)))
}
예제 #12
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #13
0
파일: randist.go 프로젝트: postfix/gsl-1
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))
}
예제 #14
0
파일: randist.go 프로젝트: postfix/gsl-1
func UgaussianRatioMethod(r *rng.GslRng) float64 {
	return float64(C.gsl_ran_ugaussian_ratio_method((*C.gsl_rng)(unsafe.Pointer(r.Ptr()))))
}
예제 #15
0
파일: randist.go 프로젝트: postfix/gsl-1
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))
}
예제 #16
0
파일: randist.go 프로젝트: postfix/gsl-1
func Logistic(r *rng.GslRng, a float64) float64 {
	return float64(C.gsl_ran_logistic((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(a)))
}
예제 #17
0
파일: randist.go 프로젝트: postfix/gsl-1
func Tdist(r *rng.GslRng, nu float64) float64 {
	return float64(C.gsl_ran_tdist((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(nu)))
}
예제 #18
0
파일: randist.go 프로젝트: postfix/gsl-1
func Ugaussian(r *rng.GslRng) float64 {
	return float64(C.gsl_ran_ugaussian((*C.gsl_rng)(unsafe.Pointer(r.Ptr()))))
}
예제 #19
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #20
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #21
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #22
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #23
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #24
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #25
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #26
0
파일: randist.go 프로젝트: postfix/gsl-1
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()))))
}
예제 #27
0
파일: monte.go 프로젝트: postfix/gsl-1
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))
}
예제 #28
0
파일: randist.go 프로젝트: postfix/gsl-1
func Poisson(r *rng.GslRng, mu float64) uint32 {
	return uint32(C.gsl_ran_poisson((*C.gsl_rng)(unsafe.Pointer(r.Ptr())), C.double(mu)))
}
예제 #29
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}
예제 #30
0
파일: randist.go 프로젝트: postfix/gsl-1
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)))
}