• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang io.Pforan函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cpmech/gosl/io.Pforan函数的典型用法代码示例。如果您正苦于以下问题:Golang Pforan函数的具体用法?Golang Pforan怎么用?Golang Pforan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Pforan函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: check

func check(problem int, tolf, tolg float64) {
	io.Pf("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> problem %d <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", problem)
	opt := getfcn(problem)
	x := opt.RptXref
	f := make([]float64, opt.Nf)
	g := make([]float64, opt.Ng)
	h := make([]float64, opt.Nh)
	opt.MinProb(f, g, h, x, nil, 0)
	err := math.Abs(f[0] - opt.RptFref[0])
	io.Pforan("nx=%d nf=%d ng=%d nh=%d\n", opt.Nflt, opt.Nf, opt.Ng, opt.Nh)
	io.Pforan("x = %v\n", x)
	io.Pforan("f = %v  err = %v\n", f, err)
	io.Pforan("g = %v\n", g)
	io.Pforan("h = %v\n", h)
	for i := 0; i < opt.Ng; i++ {
		if g[i] < 0 {
			io.PfRed("unfeasible on g\n")
		}
	}
	for i := 0; i < opt.Nh; i++ {
		if math.Abs(h[i]) > opt.EpsH {
			io.PfRed("unfeasible on h\n")
		}
	}
	if err > tolf {
		io.PfRed("err is too big\n")
	}
}
开发者ID:cpmech,项目名称:goga,代码行数:28,代码来源:checkfcn.go


示例2: Test_quad01

func Test_quad01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("quad01")

	y := func(x float64) float64 {
		return math.Sqrt(1.0 + math.Pow(math.Sin(x), 3.0))
	}
	var err error
	Acor := 1.08268158558

	// trapezoidal rule
	var T Quadrature
	T = new(Trap)
	T.Init(y, 0, 1, 1e-11)
	A, err := T.Integrate()
	if err != nil {
		io.Pforan(err.Error())
	}
	io.Pforan("A  = %v\n", A)
	chk.Scalar(tst, "A", 1e-11, A, Acor)

	// Simpson's rule
	var S Quadrature
	S = new(Simp)
	S.Init(y, 0, 1, 1e-11)
	A, err = S.Integrate()
	if err != nil {
		io.Pforan(err.Error())
	}
	io.Pforan("A  = %v\n", A)
	chk.Scalar(tst, "A", 1e-11, A, Acor)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:33,代码来源:t_quadrature_test.go


示例3: Test_GOflt01

func Test_GOflt01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("GOflt01. float64")

	Init(1234)

	xmin := 10.0
	xmax := 20.0
	vals := make([]float64, NSAMPLES)

	// using Float64
	t0 := time.Now()
	for i := 0; i < NSAMPLES; i++ {
		vals[i] = Float64(xmin, xmax)
	}
	io.Pforan("time elapsed = %v\n", time.Now().Sub(t0))

	hist := Histogram{Stations: []float64{10, 12.5, 15, 17.5, 20}}
	hist.Count(vals, true)
	io.Pfpink(TextHist(hist.GenLabels("%4g"), hist.Counts, 60))

	// using Float64s
	t0 = time.Now()
	Float64s(vals, xmin, xmax)
	io.Pforan("time elapsed = %v\n", time.Now().Sub(t0))

	hist.Count(vals, true)
	io.Pfblue2(TextHist(hist.GenLabels("%4g"), hist.Counts, 60))
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:30,代码来源:t_random_test.go


示例4: Test_intordmut01

func Test_intordmut01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("intordmut01")

	var ops OpsData
	ops.SetDefault()
	ops.Pm = 1

	rnd.Init(0)

	a := []int{1, 2, 3, 4, 5, 6, 7, 8}
	io.Pforan("before: a = %v\n", a)
	ops.OrdSti = []int{2, 5, 4}
	IntOrdMutation(a, 0, &ops)
	io.Pfcyan("after:  a = %v\n", a)
	chk.Ints(tst, "a", a, []int{1, 2, 6, 7, 3, 4, 5, 8})
	nums := utl.IntRange2(1, 9)
	sort.Ints(a)
	chk.Ints(tst, "asorted = 12345678", a, nums)

	a = []int{1, 2, 3, 4, 5, 6, 7, 8}
	io.Pforan("\nbefore: a = %v\n", a)
	ops.OrdSti = nil
	IntOrdMutation(a, 0, &ops)
	io.Pfcyan("after:  a = %v\n", a)
	sort.Ints(a)
	chk.Ints(tst, "asorted = 12345678", a, nums)
}
开发者ID:postfix,项目名称:goga-1,代码行数:29,代码来源:t_opsints_test.go


示例5: Test_binmut01

func Test_binmut01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("binmut01. mutation: binary")

	var ops OpsData
	ops.SetDefault()
	ops.Pm = 1.0
	ops.Tmax = 10
	ops.Nchanges = 3

	rnd.Init(0)

	A := []int{0, 1, 1, 1, 0, 0, 1, 0, 1, 1}
	a := make([]int, len(A))
	copy(a, A)
	io.Pforan("before: A = %v\n", A)
	IntBinMutation(A, 0, &ops)
	io.Pforan("after:  A = %v\n", A)
	ndiff := 0
	for i := 0; i < len(A); i++ {
		if A[i] != a[i] {
			ndiff++
		}
	}
	io.Pforan("number of changes = %v\n", ndiff)
	if ndiff != ops.Nchanges {
		tst.Errorf("binary mutation failed\n")
	}
}
开发者ID:postfix,项目名称:goga-1,代码行数:30,代码来源:t_opsints_test.go


示例6: Test_invs07

func Test_invs07(tst *testing.T) {

	//verbose()
	chk.PrintTitle("invs07")

	smp_a, smp_b, smp_β, smp_ϵ := -1.0, 0.0, 1.0, 1e-3

	σ := []float64{-1, -1, 0, 0}

	pcam, qcam, _ := M_pqw(σ)
	poct, qoct := pcam*SQ3, qcam*SQ2by3

	N := make([]float64, 3)
	n := make([]float64, 3)
	m := SmpDirector(N, σ, smp_a, smp_b, smp_β, smp_ϵ)
	SmpUnitDirector(n, m, N)
	psmp1, qsmp1, err := GenInvs(σ, n, smp_a)
	if err != nil {
		chk.Panic("M_GenInvs failed:\n%v", err)
	}

	psmp2, qsmp2, err := M_pq_smp(σ, smp_a, smp_b, smp_β, smp_ϵ)
	if err != nil {
		chk.Panic("M_pq_smp failed:\n%v", err)
	}
	io.Pforan("pcam,  qcam  = %v, %v\n", pcam, qcam)
	io.Pforan("poct,  qoct  = %v, %v\n", poct, qoct)
	io.Pforan("psmp1, qsmp1 = %v, %v\n", psmp1, qsmp1)
	io.Pforan("psmp2, qsmp2 = %v, %v\n", psmp2, qsmp2)
	chk.Scalar(tst, "p", 1e-15, psmp1, psmp2)
	chk.Scalar(tst, "q", 1e-15, qsmp1, qsmp2)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:32,代码来源:t_invariants_test.go


示例7: Test_MTint01

func Test_MTint01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("MTint01. integers (Mersenne Twister)")

	Init(1234)

	nints := 10
	vals := make([]int, NSAMPLES)

	// using MTint
	t0 := time.Now()
	for i := 0; i < NSAMPLES; i++ {
		vals[i] = MTint(0, nints-1)
	}
	io.Pforan("time elapsed = %v\n", time.Now().Sub(t0))

	hist := IntHistogram{Stations: utl.IntRange(nints + 1)}
	hist.Count(vals, true)
	io.Pfyel(TextHist(hist.GenLabels("%d"), hist.Counts, 60))

	// using MTints
	t0 = time.Now()
	MTints(vals, 0, nints-1)
	io.Pforan("time elapsed = %v\n", time.Now().Sub(t0))

	hist.Count(vals, true)
	io.Pfcyan(TextHist(hist.GenLabels("%d"), hist.Counts, 60))
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:29,代码来源:t_random_test.go


示例8: Test_brent03

func Test_brent03(tst *testing.T) {

	//verbose()
	chk.PrintTitle("brent03. minimum finding")

	ffcn := func(x float64) (res float64, err error) {
		return x*x*x - 2.0*x - 5.0, nil
	}

	var o Brent
	o.Init(ffcn)
	xa, xb := 0.0, 1.0
	x, err := o.Min(xa, xb, false)
	if err != nil {
		chk.Panic("%v", err)
	}
	y, err := ffcn(x)
	if err != nil {
		chk.Panic("%v", err)
	}
	xcor := math.Sqrt(2.0 / 3.0)
	io.Pforan("x      = %v (correct=%g)\n", x, xcor)
	io.Pforan("f(x)   = %v\n", y)
	io.Pforan("nfeval = %v\n", o.NFeval)
	io.Pforan("nit    = %v\n", o.It)

	//save := true
	save := false
	PlotYxe(ffcn, "results", "brent03.png", x, -1, 3, 101, "Brent", "'b-'", save, false, nil)
	chk.Scalar(tst, "xcorrect", 1e-8, x, xcor)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:31,代码来源:t_brent_test.go


示例9: Test_hash02

func Test_hash02(tst *testing.T) {

	//verbose()
	chk.PrintTitle("hash02")

	c1 := []float64{9.99999999, 9999.999999, 99.99998}
	c2 := []float64{9.99999998, 9999.999999, 99.99998}

	tol := 1e-15
	xmin := []float64{0, 0, 0}
	xmax := []float64{10, 10000, 100}
	xdel := []float64{0, 0, 0}
	for i := 0; i < 3; i++ {
		xdel[i] = xmax[i] - xmin[i]
	}

	h1 := HashPoint(c1, xmin, xdel, tol)
	h2 := HashPoint(c2, xmin, xdel, tol)

	io.Pforan("h1 = %v\n", h1)
	io.Pforan("h2 = %v\n", h2)

	if h1 == h2 {
		chk.Panic("h1 must not be equal to h2")
	}
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:26,代码来源:t_hashpoint_test.go


示例10: Test_2dinteg02

func Test_2dinteg02(tst *testing.T) {

	//verbose()
	chk.PrintTitle("2dinteg02. bidimensional integral")

	// Γ(1/4, 1)
	gamma_1div4_1 := 0.2462555291934987088744974330686081384629028737277219

	x := utl.LinSpace(0, 1, 11)
	y := utl.LinSpace(0, 1, 11)
	m, n := len(x), len(y)
	f := la.MatAlloc(m, n)
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			f[i][j] = 8.0 * math.Exp(-math.Pow(x[i], 2)-math.Pow(y[j], 4))
		}
	}
	dx, dy := x[1]-x[0], y[1]-y[0]
	Vt := Trapz2D(dx, dy, f)
	Vs := Simps2D(dx, dy, f)
	Vc := math.Sqrt(math.Pi) * math.Erf(1) * (math.Gamma(1.0/4.0) - gamma_1div4_1)
	io.Pforan("Vt = %v\n", Vt)
	io.Pforan("Vs = %v\n", Vs)
	io.Pfgreen("Vc = %v\n", Vc)
	chk.Scalar(tst, "Vt", 0.0114830435645548, Vt, Vc)
	chk.Scalar(tst, "Vs", 1e-4, Vs, Vc)

}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:28,代码来源:t_integ_test.go


示例11: Test_state01

func Test_state01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("state01")

	nsig, nalp, large, nle := 4, 1, false, true
	state0 := NewState(nsig, nalp, large, nle)
	io.Pforan("state0 = %+v\n", state0)
	chk.Vector(tst, "sig", 1.0e-17, state0.Sig, []float64{0, 0, 0, 0})
	chk.Vector(tst, "alp", 1.0e-17, state0.Alp, []float64{0})
	chk.Vector(tst, "epsE", 1.0e-17, state0.EpsE, []float64{0, 0, 0, 0})

	state0.Sig[0] = 10.0
	state0.Sig[1] = 11.0
	state0.Sig[2] = 12.0
	state0.Sig[3] = 13.0
	state0.Alp[0] = 20.0

	state1 := NewState(nsig, nalp, large, nle)
	state1.Set(state0)
	io.Pforan("state1 = %+v\n", state1)
	chk.Vector(tst, "sig", 1.0e-17, state1.Sig, []float64{10, 11, 12, 13})
	chk.Vector(tst, "alp", 1.0e-17, state1.Alp, []float64{20})

	state2 := state1.GetCopy()
	io.Pforan("state2 = %+v\n", state2)
	chk.Vector(tst, "sig", 1.0e-17, state2.Sig, []float64{10, 11, 12, 13})
	chk.Vector(tst, "alp", 1.0e-17, state2.Alp, []float64{20})
	chk.Vector(tst, "epsE", 1.0e-17, state2.EpsE, []float64{0, 0, 0, 0})
}
开发者ID:PatrickSchm,项目名称:gofem,代码行数:30,代码来源:t_state_test.go


示例12: run_rootsol_test

// run_rootsol_test runs root solution test
//  Note: xguess is the trial solution for Newton's method (not Brent's)
func run_rootsol_test(tst *testing.T, xa, xb, xguess, tolcmp float64, ffcnA Cb_yxe, ffcnB Cb_f, JfcnB Cb_Jd, fname string, save, show bool) (xbrent float64) {

	// Brent
	io.Pfcyan("\n       - - - - - - - using Brent's method - - -- - - - \n")
	var o Brent
	o.Init(ffcnA)
	var err error
	xbrent, err = o.Solve(xa, xb, false)
	if err != nil {
		chk.Panic("%v", err)
	}
	var ybrent float64
	ybrent, err = ffcnA(xbrent)
	if err != nil {
		chk.Panic("%v", err)
	}
	io.Pforan("x      = %v\n", xbrent)
	io.Pforan("f(x)   = %v\n", ybrent)
	io.Pforan("nfeval = %v\n", o.NFeval)
	io.Pforan("nit    = %v\n", o.It)
	if math.Abs(ybrent) > 1e-10 {
		chk.Panic("Brent failed: f(x) = %g > 1e-10\n", ybrent)
	}

	// Newton
	io.Pfcyan("\n       - - - - - - - using Newton's method - - -- - - - \n")
	var p NlSolver
	p.Init(1, ffcnB, nil, JfcnB, true, false, nil)
	xnewt := []float64{xguess}
	var cnd float64
	cnd, err = p.CheckJ(xnewt, 1e-6, true, !chk.Verbose)
	io.Pforan("cond(J) = %v\n", cnd)
	if err != nil {
		chk.Panic("%v", err.Error())
	}
	err = p.Solve(xnewt, false)
	if err != nil {
		chk.Panic("%v", err.Error())
	}
	var ynewt float64
	ynewt, err = ffcnA(xnewt[0])
	if err != nil {
		chk.Panic("%v", err)
	}
	io.Pforan("x      = %v\n", xnewt[0])
	io.Pforan("f(x)   = %v\n", ynewt)
	io.Pforan("nfeval = %v\n", p.NFeval)
	io.Pforan("nJeval = %v\n", p.NJeval)
	io.Pforan("nit    = %v\n", p.It)
	if math.Abs(ynewt) > 1e-9 {
		chk.Panic("Newton failed: f(x) = %g > 1e-10\n", ynewt)
	}

	// compare Brent's and Newton's solutions
	PlotYxe(ffcnA, "results", fname, xbrent, xa, xb, 101, "Brent", "'b-'", save, show, func() {
		plt.PlotOne(xnewt[0], ynewt, "'g+', ms=15, label='Newton'")
	})
	chk.Scalar(tst, "xbrent - xnewt", tolcmp, xbrent, xnewt[0])
	return
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:62,代码来源:t_brent_test.go


示例13: Test_munkres04

func Test_munkres04(tst *testing.T) {

	//verbose()
	chk.PrintTitle("munkres04. row and column matrices")

	C := [][]float64{
		{1.0},
		{2.0},
		{0.5},
		{3.0},
		{4.0},
	}

	var mnk Munkres
	mnk.Init(len(C), len(C[0]))
	mnk.SetCostMatrix(C)
	mnk.Run()
	io.Pforan("links = %v\n", mnk.Links)
	io.Pforan("cost = %v  (13938)\n", mnk.Cost)
	chk.Ints(tst, "links", mnk.Links, []int{-1, -1, 0, -1, -1})
	chk.Scalar(tst, "cost", 1e-17, mnk.Cost, 0.5)

	C = [][]float64{
		{1.0, 2.0, 0.5, 3.0, 4.0},
	}
	mnk.Init(len(C), len(C[0]))
	mnk.SetCostMatrix(C)
	mnk.Run()
	io.Pforan("links = %v\n", mnk.Links)
	io.Pforan("cost = %v  (13938)\n", mnk.Cost)
	chk.Ints(tst, "links", mnk.Links, []int{2})
	chk.Scalar(tst, "cost", 1e-17, mnk.Cost, 0.5)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:33,代码来源:t_munkres_test.go


示例14: Test_mtdeb01

func Test_mtdeb01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("mtdeb01. Deb's mutation")

	var ops OpsData
	ops.SetDefault()
	ops.Pm = 1.0
	ops.Xrange = [][]float64{{-3, 3}, {-4, 4}}
	ops.EnfRange = true

	rnd.Init(0)

	A := []float64{-1, 1}
	io.Pforan("before: A = %v\n", A)
	FltMutationDeb(A, 10, &ops)
	io.Pforan("after:  A = %v\n", A)

	ha0 := rnd.Histogram{Stations: utl.LinSpace(-3, 3, 11)}

	nsamples := 1000
	aa := make([]float64, len(A))
	a0s := make([]float64, nsamples)
	for _, t := range []int{0, 50, 100} {
		for i := 0; i < nsamples; i++ {
			copy(aa, A)
			FltMutationDeb(aa, t, &ops)
			a0s[i] = aa[0]
		}
		ha0.Count(a0s, true)
		io.Pf("\ntime = %d\n", t)
		io.Pf("%s", rnd.TextHist(ha0.GenLabels("%.1f"), ha0.Counts, 60))
	}
}
开发者ID:postfix,项目名称:goga-1,代码行数:34,代码来源:t_opsfloats_test.go


示例15: Test_ind02

func Test_ind02(tst *testing.T) {

	//verbose()
	chk.PrintTitle("ind02. copy into")

	rnd.Init(0)

	nbases := 1
	A := get_individual(0, nbases)
	B := get_individual(1, nbases)

	fmts := map[string][]string{
		"int": {"%2d", "%4d", "%5d"}, // ints
		"flt": {"%6g", "%6g", "%5g"}, // floats
		"str": {"%4s", "%2s", "%2s"}, // strings
		"key": {"%3x", "%3x", "%3x"}, // keys
		"byt": {"%4s", "%4s", "%4s"}, // bytes
		"fun": {"%3s", "%3s", "%3s"}, // funcs
	}
	io.Pfpink("A = %v\n", A.Output(fmts, false))
	io.Pfcyan("B = %v\n", B.Output(fmts, false))

	var ops OpsData
	ops.SetDefault()
	ops.Pc = 1.0
	ops.Cuts = []int{1, 2}
	ops.Xrange = [][]float64{{0, 1}, {-20, 20}, {-300, 300}}

	a := A.GetCopy()
	b := A.GetCopy()
	IndCrossover(a, b, A, B, 0, &ops)

	io.Pforan("a = %v\n", a.Output(fmts, false))
	io.Pfblue2("b = %v\n", b.Output(fmts, false))

	chk.Ints(tst, "a.Ints   ", a.Ints, []int{1, -20, 300})
	chk.Ints(tst, "b.Ints   ", b.Ints, []int{-1, 20, -300})
	chk.Strings(tst, "a.Strings", a.Strings, []string{"abc", "Y", "c"})
	chk.Strings(tst, "b.Strings", b.Strings, []string{"X", "b", "Z"})
	// TODO: add other tests here
	io.Pf("\n")

	x := get_individual(0, nbases)
	x.Ovas = []float64{0, 0}
	x.Oors = []float64{0, 0, 0}
	io.Pfblue2("x = %v\n", x.Output(fmts, false))
	B.CopyInto(x)

	chk.Scalar(tst, "ova0", 1e-17, x.Ovas[0], 200)
	chk.Scalar(tst, "ova1", 1e-17, x.Ovas[1], 100)
	chk.Scalar(tst, "oor0", 1e-17, x.Oors[0], 15)
	chk.Scalar(tst, "oor1", 1e-17, x.Oors[1], 25)
	chk.Scalar(tst, "oor2", 1e-17, x.Oors[2], 35)

	io.Pforan("x = %v\n", x.Output(fmts, false))
	chk.String(tst, x.Output(fmts, false), B.Output(fmts, false))
}
开发者ID:postfix,项目名称:goga-1,代码行数:57,代码来源:t_individual_test.go


示例16: Test_igd01

func Test_igd01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("igd. igd metric with star equal to trial => igd=0")

	// load star values
	prob := "UF1"
	fStar, err := io.ReadMatrix(io.Sf("./examples/mulobj-cec09/cec09/pf_data/%s.dat", prob))
	if err != nil {
		tst.Errorf("cannot read fStar matrix:\n%v", err)
		return
	}
	npts := len(fStar)

	// optimiser
	var opt Optimiser
	opt.Default()
	opt.Nsol = npts
	opt.Ncpu = 1
	opt.FltMin = []float64{0, 0} // used to store fStar
	opt.FltMax = []float64{1, 1} // used to store fStar
	nf, ng, nh := 2, 0, 0

	// generator (store fStar into Flt)
	gen := func(sols []*Solution, prms *Parameters) {
		for i, sol := range sols {
			sol.Flt[0], sol.Flt[1] = fStar[i][0], fStar[i][1]
		}
	}

	// objective function (copy fStar from Flt into Ova)
	obj := func(f, g, h, x []float64, ξ []int, cpu int) {
		f[0], f[1] = x[0], x[1]
	}

	// initialise optimiser
	opt.Init(gen, nil, obj, nf, ng, nh)

	// compute igd
	igd := StatIgd(&opt, fStar)
	io.Pforan("igd = %v\n", igd)
	chk.Scalar(tst, "igd", 1e-15, igd, 0)

	// plot
	if chk.Verbose {
		fmt := &plt.Fmt{C: "red", M: ".", Ms: 1, Ls: "None", L: "solutions"}
		fS0 := utl.DblsGetColumn(0, fStar)
		fS1 := utl.DblsGetColumn(1, fStar)
		io.Pforan("len(fS0) = %v\n", len(fS0))
		plt.SetForEps(0.75, 300)
		opt.PlotAddOvaOva(0, 1, opt.Solutions, true, fmt)
		plt.Plot(fS0, fS1, io.Sf("'b.', ms=2, label='star(%s)', clip_on=0", prob))
		plt.Gll("$f_0$", "$f_1$", "")
		plt.SaveD("/tmp/goga", "igd01.eps")
	}
}
开发者ID:cpmech,项目名称:goga,代码行数:56,代码来源:t_igd_test.go


示例17: Test_fun05

func Test_fun05(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fun05. zero and one")

	io.Pforan("Zero(666,nil) = %v\n", Zero.F(666, nil))
	io.Pforan("One(666,nil)  = %v\n", One.F(666, nil))
	chk.Scalar(tst, "zero", 1e-17, Zero.F(666, nil), 0)
	chk.Scalar(tst, "one ", 1e-17, One.F(666, nil), 1)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:10,代码来源:t_fun_test.go


示例18: Test_hist01

func Test_hist01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("hist01")

	lims := []float64{0, 1, 2, 3, 4, 5}
	hist := Histogram{Stations: lims}

	idx := hist.FindBin(-3.3)
	chk.IntAssert(idx, -1)

	idx = hist.FindBin(7.0)
	chk.IntAssert(idx, -1)

	for i, x := range lims {
		idx = hist.FindBin(x)
		io.Pforan("x=%g idx=%d\n", x, idx)
		if i < len(lims)-1 {
			chk.IntAssert(idx, i)
		} else {
			chk.IntAssert(idx, -1)
		}
	}

	idx = hist.FindBin(0.5)
	chk.IntAssert(idx, 0)

	idx = hist.FindBin(1.5)
	chk.IntAssert(idx, 1)

	idx = hist.FindBin(2.5)
	chk.IntAssert(idx, 2)

	idx = hist.FindBin(3.99999999999999)
	chk.IntAssert(idx, 3)

	idx = hist.FindBin(4.999999)
	chk.IntAssert(idx, 4)

	hist.Count([]float64{
		0, 0.1, 0.2, 0.3, 0.9, // 5
		1, 1, 1, 1.2, 1.3, 1.4, 1.5, 1.99, // 8
		2, 2.5, // 2
		3, 3.5, // 2
		4.1, 4.5, 4.9, // 3
		-3, -2, -1,
		5, 6, 7, 8,
	}, true)
	io.Pforan("counts = %v\n", hist.Counts)
	chk.Ints(tst, "counts", hist.Counts, []int{5, 8, 2, 2, 3})

	labels := hist.GenLabels("%g")
	io.Pforan("labels = %v\n", labels)
}
开发者ID:yunpeng1,项目名称:gosl,代码行数:54,代码来源:t_hist_test.go


示例19: Test_fourlayers01

func Test_fourlayers01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("fourlayers01")

	analysis := NewFEM("data/fourlayers.sim", "", true, false, false, false, chk.Verbose, 0)

	doms := NewDomains(analysis.Sim, analysis.DynCfs, analysis.HydSta, 0, 1, false)
	if len(doms) == 0 {
		tst.Errorf("NewDomains failed\n")
		return
	}
	dom := doms[0]

	io.Pforan("stage # 0\n")
	err := dom.SetStage(0)
	if err != nil {
		tst.Errorf("SetStage # 0 failed\n%v", err)
		return
	}
	nids, eqs := get_nids_eqs(dom)
	chk.Ints(tst, "nids", nids, []int{1, 2, 14, 12, 0, 10})
	chk.Ints(tst, "eqs", eqs, []int{0, 1, 12, 2, 3, 4, 5, 6, 7, 13, 8, 9, 10, 11})

	io.Pforan("stage # 1\n")
	err = dom.SetStage(1)
	if err != nil {
		tst.Errorf("SetStage # 1 failed\n%v", err)
		return
	}
	nids, eqs = get_nids_eqs(dom)
	chk.Ints(tst, "nids", nids, []int{10, 12, 9, 6, 1, 2, 14, 0, 8})
	chk.Ints(tst, "eqs", eqs, []int{0, 1, 2, 3, 19, 4, 5, 20, 6, 7, 8, 9, 18, 10, 11, 12, 13, 14, 15, 16, 17})

	io.Pforan("stage # 2\n")
	err = dom.SetStage(2)
	if err != nil {
		tst.Errorf("SetStage # 2 failed\n%v", err)
		return
	}
	nids, eqs = get_nids_eqs(dom)
	chk.Ints(tst, "nids", nids, []int{10, 12, 9, 6, 1, 2, 14, 0, 7, 11, 8, 13})
	chk.Ints(tst, "eqs", eqs, []int{0, 1, 2, 3, 25, 4, 5, 26, 6, 7, 8, 9, 24, 10, 11, 12, 13, 14, 15, 16, 17, 27, 18, 19, 20, 21, 22, 23})

	io.Pforan("stage # 3\n")
	err = dom.SetStage(3)
	if err != nil {
		tst.Errorf("SetStage # 3 failed\n%v", err)
		return
	}
	nids, eqs = get_nids_eqs(dom)
	chk.Ints(tst, "nids", nids, []int{7, 13, 5, 4, 10, 12, 9, 6, 1, 2, 14, 11, 3, 0, 8})
	chk.Ints(tst, "eqs", eqs, []int{0, 1, 33, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 31, 12, 13, 32, 14, 15, 16, 17, 30, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29})
}
开发者ID:PaddySchmidt,项目名称:gofem,代码行数:54,代码来源:t_multistages_test.go


示例20: Test_mylab09

func Test_mylab09(tst *testing.T) {

	//verbose()
	chk.PrintTitle("mylab09. arg min and max")

	u := []float64{1, 2, 3, -5, 60, -10, 8}
	imin, imax := DblArgMinMax(u)
	io.Pforan("imin = %v (5)\n", imin)
	io.Pforan("imax = %v (4)\n", imax)
	chk.IntAssert(imin, 5)
	chk.IntAssert(imax, 4)
}
开发者ID:PaddySchmidt,项目名称:gosl,代码行数:12,代码来源:t_mylab_test.go



注:本文中的github.com/cpmech/gosl/io.Pforan函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang io.Pfpink函数代码示例发布时间:2022-05-23
下一篇:
Golang io.Pfgreen函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap