本文整理汇总了Golang中github.com/cpmech/gosl/chk.Ints函数的典型用法代码示例。如果您正苦于以下问题:Golang Ints函数的具体用法?Golang Ints怎么用?Golang Ints使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Ints函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_serial02
func Test_serial02(tst *testing.T) {
//verbose()
chk.PrintTitle("serial02")
A := [][][]float64{
{{1, 3, 4}, {6}, {232, 23, 292, 2023}, {2, 3}},
{{0}, {1}, {0}},
{{0, 5, 6, 8, 3, 0}},
}
// serialize
PrintDeep3("A", A)
I, P, S := Deep3Serialize(A)
Deep3GetInfo(I, P, S, true)
// check serialization
chk.Ints(tst, "I", I, []int{0, 0, 0, 0, 1, 1, 1, 2})
chk.Ints(tst, "P", P, []int{0, 3, 4, 8, 10, 11, 12, 13, 19})
chk.Vector(tst, "S", 1e-16, S, []float64{1, 3, 4, 6, 232, 23, 292, 2023, 2, 3, 0, 1, 0, 0, 5, 6, 8, 3, 0})
// deserialize
B := Deep3Deserialize(I, P, S, false)
PrintDeep3("B", B)
// check deserialization
chk.Deep3(tst, "A", 1e-16, A, B)
}
示例2: 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)
}
示例3: checkinput
func checkinput(tst *testing.T, m *Mesh, nverts, ncells int, X [][]float64, vtags, ctags, parts []int, types []string, V [][]int, etags, ftags [][]int) {
if len(m.Verts) != nverts {
tst.Errorf("nverts is incorrect: %d != %d", len(m.Verts), nverts)
return
}
if len(m.Cells) != ncells {
tst.Errorf("ncells is incorrect: %d != %d", len(m.Cells), ncells)
return
}
io.Pfyel("\nvertices:\n")
for i, v := range m.Verts {
io.Pf("%+v\n", v)
chk.Vector(tst, io.Sf("vertex %2d: X", v.Id), 1e-15, v.X, X[v.Id])
if v.Tag != vtags[i] {
tst.Errorf("vtag is incorrect: %d != %d", v.Tag, vtags[i])
return
}
}
io.Pfyel("\ncells:\n")
for i, c := range m.Cells {
io.Pf("%+v\n", c)
if c.Tag != ctags[i] {
tst.Errorf("ctag is incorrect: %d != %d", c.Tag, ctags[i])
return
}
if c.Part != parts[i] {
tst.Errorf("part is incorrect: %d != %d", c.Part, parts[i])
return
}
chk.String(tst, types[i], c.Type)
chk.Ints(tst, io.Sf("cell %2d : V", c.Id), c.V, V[c.Id])
chk.Ints(tst, io.Sf("cell %2d : edgetags", c.Id), c.EdgeTags, etags[c.Id])
}
}
示例4: TestMyLab03b
func TestMyLab03b(tst *testing.T) {
//verbose()
chk.PrintTitle("mylab03b")
a := []int{1, 2, 3, -1, -2, 0, 8, -3}
b := IntFilter(a, func(i int) bool {
if a[i] < 0 {
return true
}
return false
})
c := IntNegOut(a)
io.Pf("a = %v\n", a)
io.Pf("b = %v\n", b)
io.Pf("c = %v\n", c)
chk.Ints(tst, "b", b, []int{1, 2, 3, 0, 8})
chk.Ints(tst, "c", c, []int{1, 2, 3, 0, 8})
A := []float64{1, 2, 3, -1, -2, 0, 8, -3}
s := DblSum(A)
mi, ma := DblMinMax(A)
io.Pf("A = %v\n", A)
io.Pf("sum(A) = %v\n", s)
io.Pf("min(A) = %v\n", mi)
io.Pf("max(A) = %v\n", ma)
chk.Scalar(tst, "sum(A)", 1e-17, s, 8)
chk.Scalar(tst, "min(A)", 1e-17, mi, -3)
chk.Scalar(tst, "max(A)", 1e-17, ma, 8)
}
示例5: Test_serial01
func Test_serial01(tst *testing.T) {
//verbose()
chk.PrintTitle("serial01")
A := [][][]float64{
{{100, 101, 102}, {103}, {104, 105}},
{{106}, {107}},
{{108}, {109, 110}},
{{111}},
{{112, 113, 114, 115}, {116}, {117, 118}, {119, 120, 121}},
}
// serialize
PrintDeep3("A", A)
I, P, S := Deep3Serialize(A)
Deep3GetInfo(I, P, S, true)
// check serialization
chk.Ints(tst, "I", I, []int{0, 0, 0, 1, 1, 2, 2, 3, 4, 4, 4, 4})
chk.Ints(tst, "P", P, []int{0, 3, 4, 6, 7, 8, 9, 11, 12, 16, 17, 19, 22})
Scor := LinSpace(100, 121, 22)
io.Pf("Scor = %v\n", Scor)
chk.Vector(tst, "S", 1e-16, S, Scor)
// deserialize
B := Deep3Deserialize(I, P, S, false)
PrintDeep3("B", B)
// check deserialization
chk.Deep3(tst, "A", 1e-16, A, B)
}
示例6: 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)
}
示例7: 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))
}
示例8: Test_bins02
func Test_bins02(tst *testing.T) {
//verbose()
chk.PrintTitle("bins02. find along line (2D)")
// bins
var bins Bins
bins.Init([]float64{-0.2, -0.2}, []float64{0.8, 1.8}, 5)
// fill bins structure
maxit := 5 // number of entries
ID := make([]int, maxit)
for k := 0; k < maxit; k++ {
x := float64(k) / float64(maxit)
ID[k] = k
err := bins.Append([]float64{x, 2*x + 0.2}, ID[k])
if err != nil {
chk.Panic(err.Error())
}
}
// add more points to bins
for i := 0; i < 5; i++ {
err := bins.Append([]float64{float64(i) * 0.1, 1.8}, 100+i)
if err != nil {
chk.Panic(err.Error())
}
}
// message
for _, bin := range bins.All {
if bin != nil {
io.Pf("%v\n", bin)
}
}
// find points along diagonal
ids := bins.FindAlongSegment([]float64{0.0, 0.2}, []float64{0.8, 1.8}, 1e-8)
io.Pforan("ids = %v\n", ids)
chk.Ints(tst, "ids", ids, ID)
// find additional points
ids = bins.FindAlongSegment([]float64{-0.2, 1.8}, []float64{0.8, 1.8}, 1e-8)
io.Pfcyan("ids = %v\n", ids)
chk.Ints(tst, "ids", ids, []int{100, 101, 102, 103, 104, 4})
// draw
if chk.Verbose {
plt.SetForPng(1, 500, 150)
bins.Draw2d(true, true, true, true, map[int]bool{8: true, 9: true, 10: true})
plt.SetXnticks(15)
plt.SetYnticks(15)
plt.SaveD("/tmp/gosl/gm", "test_bins02.png")
}
}
示例9: Test_sort07
func Test_sort07(tst *testing.T) {
//verbose()
chk.PrintTitle("sort07. sort 3 ints")
x := []int{0, 10, 1, 3}
IntSort3(&x[0], &x[1], &x[2])
chk.Ints(tst, "sort3(x)", x, []int{0, 1, 10, 3})
x = []int{0, 10, 1, 3}
IntSort4(&x[0], &x[1], &x[2], &x[3])
chk.Ints(tst, "sort4(x)", x, []int{0, 1, 3, 10})
}
示例10: Test_sort02
func Test_sort02(tst *testing.T) {
//verbose()
chk.PrintTitle("sort02")
i := []int{33, 0, 7, 8}
x := []float64{1000.33, 0, -77.7, 88.8}
y := []float64{1e-5, 1e-7, 1e-2, 1e-9}
z := []float64{-8000, -7000, 0, -1}
io.Pforan("by 'i'\n")
I, X, Y, Z, err := SortQuadruples(i, x, y, z, "i")
if err != nil {
tst.Errorf("%v\n", err)
}
chk.Ints(tst, "i", I, []int{0, 7, 8, 33})
chk.Vector(tst, "x", 1e-16, X, []float64{0, -77.7, 88.8, 1000.33})
chk.Vector(tst, "y", 1e-16, Y, []float64{1e-7, 1e-2, 1e-9, 1e-5})
chk.Vector(tst, "z", 1e-16, Z, []float64{-7000, 0, -1, -8000})
io.Pforan("by 'x'\n")
I, X, Y, Z, err = SortQuadruples(i, x, y, z, "x")
if err != nil {
tst.Errorf("%v\n", err)
}
chk.Ints(tst, "i", I, []int{7, 0, 8, 33})
chk.Vector(tst, "x", 1e-16, X, []float64{-77.7, 0.0, 88.8, 1000.33})
chk.Vector(tst, "y", 1e-16, Y, []float64{1e-2, 1e-7, 1e-9, 1e-5})
chk.Vector(tst, "z", 1e-16, Z, []float64{0, -7000, -1, -8000})
io.Pforan("by 'y'\n")
I, X, Y, Z, err = SortQuadruples(i, x, y, z, "y")
if err != nil {
tst.Errorf("%v\n", err)
}
chk.Ints(tst, "i", I, []int{8, 0, 33, 7})
chk.Vector(tst, "x", 1e-16, X, []float64{88.8, 0, 1000.33, -77.7})
chk.Vector(tst, "y", 1e-16, Y, []float64{1e-9, 1e-7, 1e-5, 1e-2})
chk.Vector(tst, "z", 1e-16, Z, []float64{-1, -7000, -8000, 0})
io.Pforan("by 'z'\n")
I, X, Y, Z, err = SortQuadruples(i, x, y, z, "z")
if err != nil {
tst.Errorf("%v\n", err)
}
chk.Ints(tst, "i", I, []int{33, 0, 8, 7})
chk.Vector(tst, "x", 1e-16, X, []float64{1000.33, 0, 88.8, -77.7})
chk.Vector(tst, "y", 1e-16, Y, []float64{1e-5, 1e-7, 1e-9, 1e-2})
chk.Vector(tst, "z", 1e-16, Z, []float64{-8000, -7000, -1, 0})
}
示例11: Test_sort01
func Test_sort01(tst *testing.T) {
//verbose()
chk.PrintTitle("sort01")
i := []int{33, 0, 7, 8}
x := []float64{1000.33, 0, -77.7, 88.8}
io.Pforan("by 'i'\n")
I, X, _, _, err := SortQuadruples(i, x, nil, nil, "i")
if err != nil {
tst.Errorf("%v\n", err)
}
chk.Ints(tst, "i", I, []int{0, 7, 8, 33})
chk.Vector(tst, "x", 1e-16, X, []float64{0, -77.7, 88.8, 1000.33})
io.Pforan("by 'x'\n")
I, X, _, _, err = SortQuadruples(i, x, nil, nil, "x")
if err != nil {
tst.Errorf("%v\n", err)
}
chk.Ints(tst, "i", I, []int{7, 0, 8, 33})
chk.Vector(tst, "x", 1e-16, X, []float64{-77.7, 0.0, 88.8, 1000.33})
x = []float64{1000.33, 0, -77.7, 88.8}
DblSort4(&x[0], &x[1], &x[2], &x[3])
io.Pforan("x = %v\n", x)
chk.Vector(tst, "x", 1e-16, x, []float64{-77.7, 0.0, 88.8, 1000.33})
x = []float64{1, 10.33, 0, -8.7}
DblSort4(&x[0], &x[1], &x[2], &x[3])
io.Pforan("x = %v\n", x)
chk.Vector(tst, "x", 1e-16, x, []float64{-8.7, 0, 1, 10.33})
x = []float64{100.33, 10, -77.7, 8.8}
DblSort4(&x[0], &x[1], &x[2], &x[3])
io.Pforan("x = %v\n", x)
chk.Vector(tst, "x", 1e-16, x, []float64{-77.7, 8.8, 10, 100.33})
x = []float64{-10.33, 0, 7.7, -8.8}
DblSort4(&x[0], &x[1], &x[2], &x[3])
io.Pforan("x = %v\n", x)
chk.Vector(tst, "x", 1e-16, x, []float64{-10.33, -8.8, 0, 7.7})
x = []float64{-1000.33, 8, -177.7, 0.8}
DblSort4(&x[0], &x[1], &x[2], &x[3])
io.Pforan("x = %v\n", x)
chk.Vector(tst, "x", 1e-16, x, []float64{-1000.33, -177.7, 0.8, 8})
}
示例12: Test_bins02
// Test for function FindAlongLine (2D)
func Test_bins02(tst *testing.T) {
//verbose()
chk.PrintTitle("bins02")
var bins Bins
bins.Init([]float64{0, 0}, []float64{1, 1}, 10)
// fill bins structure
maxit := 10 // number of entries
ID := make([]int, maxit)
for k := 0; k < maxit; k++ {
x := float64(k) / float64(maxit)
ID[k] = k * 11
err := bins.Append([]float64{x, x}, ID[k])
if err != nil {
chk.Panic(err.Error())
}
}
ids := bins.FindAlongLine([]float64{0, 0}, []float64{10, 10}, 0.0000001)
io.Pforan("ids = %v\n", ids)
chk.Ints(tst, "check FindAlongLine", ID, ids)
}
示例13: Test_bins03
func Test_bins03(tst *testing.T) {
//verbose()
chk.PrintTitle("bins03. find along line (3D)")
// bins
var bins Bins
bins.Init([]float64{0, 0, 0}, []float64{10, 10, 10}, 10)
// fill bins structure
maxit := 10 // number of entries
ID := make([]int, maxit)
var err error
for k := 0; k < maxit; k++ {
x := float64(k) / float64(maxit) * 10
ID[k] = k * 11
err = bins.Append([]float64{x, x, x}, ID[k])
if err != nil {
chk.Panic(err.Error())
}
}
// find points along diagonal
ids := bins.FindAlongSegment([]float64{0, 0, 0}, []float64{10, 10, 10}, 0.0000001)
io.Pforan("ids = %v\n", ids)
chk.Ints(tst, "ids", ID, ids)
}
示例14: main
func main() {
mpi.Start(false)
defer func() {
mpi.Stop(false)
}()
if mpi.Rank() == 0 {
io.PfYel("\nTest MPI 03\n")
}
if mpi.Size() != 3 {
chk.Panic("this test needs 3 processors")
}
x := []int{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
n := len(x)
id, sz := mpi.Rank(), mpi.Size()
start, endp1 := (id*n)/sz, ((id+1)*n)/sz
for i := start; i < endp1; i++ {
x[i] = i
}
//io.Pforan("x = %v\n", x)
// IntAllReduceMax
w := make([]int, n)
mpi.IntAllReduceMax(x, w)
var tst testing.T
chk.Ints(&tst, fmt.Sprintf("IntAllReduceMax: x @ proc # %d", id), x, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
//io.Pfred("x = %v\n", x)
}
示例15: 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})
}