本文整理汇总了Golang中github.com/cpmech/gosl/utl.IntRange函数的典型用法代码示例。如果您正苦于以下问题:Golang IntRange函数的具体用法?Golang IntRange怎么用?Golang IntRange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IntRange函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_groups01
func Test_groups01(tst *testing.T) {
//verbose()
chk.PrintTitle("groups01")
Init(0)
ng := 3 // number of groups
nints := 12 // number of integers
size := nints / ng // groups size
ints := utl.IntRange(nints)
groups := utl.IntsAlloc(ng, size)
hists := make([]*IntHistogram, ng)
for i := 0; i < ng; i++ {
hists[i] = &IntHistogram{Stations: utl.IntRange(nints + 1)}
}
IntGetGroups(groups, ints)
io.Pfcyan("groups = %v\n", groups)
for i := 0; i < NSAMPLES; i++ {
IntGetGroups(groups, ints)
for j := 0; j < ng; j++ {
check_repeated(groups[j])
hists[j].Count(groups[j], false)
}
}
for i := 0; i < ng; i++ {
io.Pf("\n")
io.Pf(TextHist(hists[i].GenLabels("%d"), hists[i].Counts, 60))
}
}
示例2: PlotDerivs
// PlotDerivs plots derivatives of basis functions in I
// option = 0 : use CalcBasisAndDerivs
// 1 : use NumericalDeriv
func (o *Bspline) PlotDerivs(args string, npts, option int) {
nmks := 10
tt := utl.LinSpace(o.tmin, o.tmax, npts)
I := utl.IntRange(o.NumBasis())
f := make([]float64, len(tt))
lbls := []string{"N\\&dN", "numD"}
var cmd string
for _, i := range I {
for j, t := range tt {
switch option {
case 0:
o.CalcBasisAndDerivs(t)
f[j] = o.GetDeriv(i)
case 1:
f[j] = o.NumericalDeriv(t, i)
}
}
if strings.Contains(args, "marker") {
cmd = io.Sf("label=r'%s:%d', color=GetClr(%d, 2) %s", lbls[option], i, i, args)
} else {
cmd = io.Sf("label=r'%s:%d', marker=(None if %d %%2 == 0 else GetMrk(%d/2,1)), markevery=(%d-1)/%d, clip_on=0, color=GetClr(%d, 2) %s", lbls[option], i, i, i, npts, nmks, i, args)
}
plt.Plot(tt, f, cmd)
}
plt.Gll("$t$", io.Sf(`$\frac{\mathrm{d}N_{i,%d}}{\mathrm{d}t}$`, o.p), io.Sf("leg=1, leg_out=1, leg_ncol=%d, leg_hlen=1.5, leg_fsz=7", o.NumBasis()))
o.plt_ticks_spans()
}
示例3: 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))
}
示例4: Test_MTshuffleInts01
func Test_MTshuffleInts01(tst *testing.T) {
//verbose()
chk.PrintTitle("MTshuffleInts01. Mersenne Twister")
Init(0)
n := 10
nums := utl.IntRange(n)
io.Pfgreen("before = %v\n", nums)
MTintShuffle(nums)
io.Pfcyan("after = %v\n", nums)
sort.Ints(nums)
io.Pforan("sorted = %v\n", nums)
chk.Ints(tst, "nums", nums, utl.IntRange(n))
}
示例5: Init
func (g *Grid2D) Init(lx, ly float64, nx, ny int) {
g.Lx, g.Ly = lx, ly
g.Nx, g.Ny, g.N = nx, ny, nx*ny
g.Dx, g.Dy = g.Lx/float64(nx-1), g.Ly/float64(ny-1)
g.Dxx, g.Dyy = g.Dx*g.Dx, g.Dy*g.Dy
g.L = utl.IntRange3(0, g.N, g.Nx)
g.R = utl.IntAddScalar(g.L, g.Nx-1)
g.B = utl.IntRange(g.Nx)
g.T = utl.IntAddScalar(g.B, (g.Ny-1)*g.Nx)
}
示例6: Test_GOshuffleInts01
func Test_GOshuffleInts01(tst *testing.T) {
//verbose()
chk.PrintTitle("GOshuffleInts01")
Init(0)
n := 10
nums := utl.IntRange(n)
io.Pfgreen("before = %v\n", nums)
IntShuffle(nums)
io.Pfcyan("after = %v\n", nums)
sort.Ints(nums)
io.Pforan("sorted = %v\n", nums)
chk.Ints(tst, "nums", nums, utl.IntRange(n))
shufled := IntGetShuffled(nums)
io.Pfyel("shufled = %v\n", shufled)
sort.Ints(shufled)
chk.Ints(tst, "shufled", shufled, utl.IntRange(n))
}
示例7: Test_getunique01
func Test_getunique01(tst *testing.T) {
//verbose()
chk.PrintTitle("getunique01")
Init(0)
nsel := 5 // number of selections
size := 10
nums := utl.IntRange(size)
hist := IntHistogram{Stations: utl.IntRange(size + 5)}
sel := IntGetUnique(nums, nsel)
io.Pfgreen("nums = %v\n", nums)
io.Pfcyan("sel = %v\n", sel)
for i := 0; i < NSAMPLES; i++ {
sel := IntGetUnique(nums, nsel)
check_repeated(sel)
hist.Count(sel, false)
//io.Pfgrey("sel = %v\n", sel)
}
io.Pf(TextHist(hist.GenLabels("%d"), hist.Counts, 60))
}
示例8: FactoryNurbs1dCurveA
// FactoryNurbs1dCurveA generates a NURBS 1D curve
func FactoryNurbs1dCurveA() (b *Nurbs) {
verts := [][]float64{
{0.0, 0.0, 0, 1},
{1.0, 0.2, 0, 1},
{0.5, 1.5, 0, 1},
{2.5, 2.0, 0, 1},
{2.0, 0.4, 0, 1},
{3.0, 0.0, 0, 1},
}
knots := [][]float64{
{0, 0, 0, 0, 0.3, 0.7, 1, 1, 1, 1},
}
b = new(Nurbs)
b.Init(1, []int{3}, knots)
b.SetControl(verts, utl.IntRange(len(verts)))
return
}
示例9: Test_ends02
func Test_ends02(tst *testing.T) {
//verbose()
chk.PrintTitle("ends02")
rnd.Init(0)
size := 20
ncuts := 10
nsamples := 100
hist := rnd.IntHistogram{Stations: utl.IntRange(size + 3)}
for i := 0; i < nsamples; i++ {
ends := GenerateCxEnds(size, ncuts, nil)
hist.Count(ends, false)
}
io.Pf("%s\n", rnd.TextHist(hist.GenLabels("%d"), hist.Counts, 60))
}
示例10: ElemBryLocalInds
// ElemBryLocalInds returns the local (element) indices of control points @ boundaries
// (if element would have all surfaces @ boundaries)
func (o *Nurbs) ElemBryLocalInds() (I [][]int) {
switch o.gnd {
case 1:
return
case 2:
I = make([][]int, 2*o.gnd)
nx, ny := o.p[0]+1, o.p[1]+1
I[3] = utl.IntRange3(0, nx*ny, nx)
I[1] = utl.IntAddScalar(I[3], nx-1)
I[0] = utl.IntRange(nx)
I[2] = utl.IntAddScalar(I[0], (ny-1)*nx)
case 3:
I = make([][]int, 2*o.gnd)
chk.Panic("3D NURBS: ElemBryLocalInds: TODO") // TODO
}
return
}
示例11: Test_mwicz01
func Test_mwicz01(tst *testing.T) {
//verbose()
chk.PrintTitle("mwicz01. Michalewicz mutation")
var ops OpsData
ops.SetDefault()
ops.Pm = 1.0
ops.Tmax = 10
rnd.Init(0)
ops.Xrange = [][]float64{{0, 2}, {1, 3}, {2, 4}, {3, 5}, {4, 6}}
T := utl.IntRange(int(ops.Tmax))
for _, t := range T {
io.Pf("t=%v Δ=%v\n", t, ops.MwiczDelta(float64(t), 1))
}
for _, t := range T {
A := []float64{0, 1, 2, 3, 4}
FltMutationMwicz(A, t, &ops)
io.Pforan("A = %.8f\n", A)
}
if chk.Verbose {
b := 2.0
f := func(r, tb float64) float64 {
return math.Pow(r, math.Pow(1.0-tb, b))
}
np := 21
r, tb := utl.MeshGrid2D(0, 1, 0, 1, np, np) // tb = t/tmax
z := la.MatAlloc(np, np)
for i := 0; i < np; i++ {
for j := 0; j < np; j++ {
z[i][j] = f(r[i][j], tb[i][j])
}
}
plt.Surface(tb, r, z, "linewidth=0.8")
plt.Gll("tb", "r", "")
plt.SaveD("/tmp/goga", "test_mwicz01.eps")
//plt.Show()
}
}
示例12: Test_getunique02
func Test_getunique02(tst *testing.T) {
//verbose()
chk.PrintTitle("getunique02")
Init(0)
nsel := 5 // number of selections
start := 2
endp1 := 10
hist := IntHistogram{Stations: utl.IntRange(endp1 + 3)}
sel := IntGetUniqueN(start, endp1, nsel)
io.Pfcyan("sel = %v\n", sel)
for i := 0; i < NSAMPLES; i++ {
sel := IntGetUniqueN(start, endp1, nsel)
check_repeated(sel)
hist.Count(sel, false)
//io.Pfgrey("sel = %v\n", sel)
}
io.Pf(TextHist(hist.GenLabels("%d"), hist.Counts, 60))
}
示例13: FactoryNurbs2dStrip
// FactoryNurbs2dStrip generates a NURBS of a 2D strip (x-quadratic, y-linear)
func FactoryNurbs2dStrip() (b *Nurbs) {
verts := [][]float64{
{0.00, 0.00, 0, 0.80}, // 0
{0.25, 0.15, 0, 1.00}, // 1
{0.50, 0.00, 0, 0.70}, // 2
{0.75, 0.00, 0, 1.20}, // 3
{1.00, 0.10, 0, 1.10}, // 4
{0.00, 0.40, 0, 0.90}, // 5
{0.25, 0.55, 0, 0.60}, // 6
{0.50, 0.40, 0, 1.50}, // 7
{0.75, 0.40, 0, 1.40}, // 8
{1.00, 0.50, 0, 0.50}, // 9
}
knots := [][]float64{
{0, 0, 0, 1, 2, 3, 3, 3},
{0, 0, 1, 1},
}
b = new(Nurbs)
b.Init(2, []int{2, 1}, knots)
b.SetControl(verts, utl.IntRange(len(verts)))
return
}
示例14: Test_p01a
func Test_p01a(tst *testing.T) {
/* this tests simulates seepage flow along a column
* by reducing the initial hydrostatic pressure at
* at the bottom of the column
*
* Nodes / Tags Equations
*
* 8 o----o----o 9 (-5) 22 o----o----o 21
* | 14 | | 24 |
* | | | |
* 21 o o o 22 (-6) 25 o o o 23
* | 26 | | 26 |
* | | | |
* 6 o----o----o 7 (-4) 16 o----o----o 15
* | 13 | | 18 |
* | | | |
* 19 | o o 20 (-6) 19 | o o 17
* | 25 | | 20 |
* | | | |
* 4 o----o----o 5 (-3) 10 o----o----o 9
* | 12 | | 12 |
* | | | |
* 17 o o o 18 (-6) 13 o o o 11
* | 24 | | 14 |
* | | | |
* 2 o----o----o 3 (-2) 3 o----o----o 2
* | 11 | | 6 |
* | | | |
* 15 o o o 16 (-6) 7 o o o 5
* | 23 | | 8 |
* | | | |
* 0 o----o----o 1 (-1) 0 o----o----o 1
* 10 4
*/
//verbose()
chk.PrintTitle("p01a")
// start simulation
analysis := NewFEM("data/p01.sim", "", true, false, false, false, chk.Verbose, 0)
// set stage
err := analysis.SetStage(0)
if err != nil {
tst.Errorf("SetStage failed:\n%v", err)
return
}
// initialise solution vectros
err = analysis.ZeroStage(0, true)
if err != nil {
tst.Errorf("ZeroStage failed:\n%v", err)
return
}
// domain
dom := analysis.Domains[0]
// nodes and elements
chk.IntAssert(len(dom.Nodes), 27)
chk.IntAssert(len(dom.Elems), 4)
// check dofs
for _, nod := range dom.Nodes {
chk.IntAssert(len(nod.Dofs), 1)
chk.StrAssert(nod.Dofs[0].Key, "pl")
}
// check equations
nids, eqs := get_nids_eqs(dom)
chk.Ints(tst, "nids", nids, []int{
0, 1, 3, 2, 10, 16, 11, 15, 23,
5, 4, 18, 12, 17, 24,
7, 6, 20, 13, 19, 25,
9, 8, 22, 14, 21, 26,
})
chk.Ints(tst, "eqs", eqs, utl.IntRange(27))
// check pmap
pmaps := [][]int{
{0, 1, 2, 3, 4, 5, 6, 7, 8},
{3, 2, 9, 10, 6, 11, 12, 13, 14},
{10, 9, 15, 16, 12, 17, 18, 19, 20},
{16, 15, 21, 22, 18, 23, 24, 25, 26},
}
for i, ele := range dom.Elems {
e := ele.(*ElemP)
io.Pforan("e%d.pmap = %v\n", e.Id(), e.Pmap)
chk.Ints(tst, "pmap", e.Pmap, pmaps[i])
}
// constraints
chk.IntAssert(len(dom.EssenBcs.Bcs), 3)
var ct_pl_eqs []int // equations with pl prescribed [sorted]
for _, c := range dom.EssenBcs.Bcs {
chk.IntAssert(len(c.Eqs), 1)
eq := c.Eqs[0]
io.Pforan("key=%v eq=%v\n", c.Key, eq)
switch c.Key {
//.........这里部分代码省略.........
示例15: Test_out01
func Test_out01(tst *testing.T) {
// finalise analysis process and catch errors
defer func() {
if err := recover(); err != nil {
tst.Fail()
io.PfRed("ERROR: %v\n", err)
}
}()
// test title
//verbose()
chk.PrintTitle("out01")
// start simulation
processing := fem.NewFEM("data/onequa4.sim", "", true, true, false, false, chk.Verbose, 0)
// run simulation
err := processing.Run()
if err != nil {
tst.Errorf("Run failed:\n%v", err)
return
}
// start post-processing
Start("data/onequa4.sim", 0, 0)
// define points
Define("A B C D", N{0, 1, 2, 3})
Define("a b c d", P{{0, 0}, {0, 1}, {-1, 2}, {-1, 3}})
Define("!right side", Along{{1, 0}, {1, 1}})
io.Pfcyan("Entities = %v\n", Results)
// check slices
nnod := 4
nele := 1
nip := 4
chk.IntAssert(len(Dom.Nodes), nnod)
chk.IntAssert(len(Ipoints), nele*nip)
chk.IntAssert(len(Cid2ips), 1)
chk.IntAssert(len(Ipkey2ips), 4)
chk.IntAssert(len(Ipkeys), 4)
for key, ips := range Ipkey2ips {
chk.Ints(tst, io.Sf("%s : ips", key), ips, utl.IntRange(4))
}
// load results
LoadResults(nil)
// check points
nlabels := []string{"A", "B", "C", "D"}
for _, l := range nlabels {
if _, ok := Results[l]; !ok {
chk.Panic("1: %q alias in Entities is not available", l)
}
}
plabels := []string{"a", "b", "c", "d"}
for _, l := range plabels {
if _, ok := Results[l]; !ok {
chk.Panic("2: %q alias in Entities is not available", l)
}
}
if _, ok := Results["right side"]; !ok {
chk.Panic("3: %q alias in Entities is not available", "right side")
}
// check u-keys
ukeys := []string{"ux", "uy"}
for _, l := range nlabels {
for _, p := range Results[l] {
//io.Pfyel("p = %v\n", p)
if p == nil {
chk.Panic("1: p is nil")
}
for _, key := range ukeys {
if _, ok := p.Vals[key]; !ok {
chk.Panic("%s is not available in point", key)
}
}
}
}
// check s-keys
skeys := fem.StressKeys(Dom.Sim.Ndim)
for _, l := range plabels {
for _, p := range Results[l] {
//io.Pfgreen("q = %v\n", p)
if p == nil {
chk.Panic("2: p is nil")
}
for _, key := range skeys {
if _, ok := p.Vals[key]; !ok {
chk.Panic("%s is not available in point", key)
}
}
}
}
// check GetRes
uxC := GetRes("ux", "C", 0)
//.........这里部分代码省略.........