本文整理汇总了Golang中github.com/cznic/mathutil.Min函数的典型用法代码示例。如果您正苦于以下问题:Golang Min函数的具体用法?Golang Min怎么用?Golang Min使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Min函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Seek
// Seek implements http.File.
func (f *HTTPFile) Seek(offset int64, whence int) (int64, error) {
if f.closed {
return 0, os.ErrInvalid
}
if offset < 0 {
return int64(f.off), fmt.Errorf("cannot seek before start of file")
}
switch whence {
case 0:
noff := int64(f.off) + offset
if noff > mathutil.MaxInt {
return int64(f.off), fmt.Errorf("seek target overflows int: %d", noff)
}
f.off = mathutil.Min(int(offset), len(f.content))
if f.off == int(offset) {
return offset, nil
}
return int64(f.off), io.EOF
case 1:
noff := int64(f.off) + offset
if noff > mathutil.MaxInt {
return int64(f.off), fmt.Errorf("seek target overflows int: %d", noff)
}
off := mathutil.Min(f.off+int(offset), len(f.content))
if off == f.off+int(offset) {
f.off = off
return int64(off), nil
}
f.off = off
return int64(off), io.EOF
case 2:
noff := int64(f.off) - offset
if noff < 0 {
return int64(f.off), fmt.Errorf("cannot seek before start of file")
}
f.off = len(f.content) - int(offset)
return int64(f.off), nil
default:
return int64(f.off), fmt.Errorf("seek: invalid whence %d", whence)
}
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:49,代码来源:httpfs.go
示例2: pickCellsToLearnOn
//Pick cells to form distal connections to.
func (tm *TemporalMemory) pickCellsToLearnOn(n int, segment int,
winnerCells []int, connections *TemporalMemoryConnections) []int {
candidates := make([]int, len(winnerCells))
copy(candidates, winnerCells)
for _, val := range connections.SynapsesForSegment(segment) {
syn := connections.DataForSynapse(val)
for idx, val := range candidates {
if val == syn.SourceCell {
candidates = append(candidates[:idx], candidates[idx+1:]...)
break
}
}
}
//Shuffle candidates
for i := range candidates {
j := rand.Intn(i + 1)
candidates[i], candidates[j] = candidates[j], candidates[i]
}
n = mathutil.Min(n, len(candidates))
return candidates[:n]
}
开发者ID:Fardinak,项目名称:htm,代码行数:26,代码来源:temporalMemory.go
示例3: ReadAt
func (f *mem) ReadAt(b []byte, off int64) (n int, err error) {
avail := f.size - off
pi := off >> f.pgBits
po := int(off) & f.pgMask
rem := len(b)
if int64(rem) >= avail {
rem = int(avail)
err = io.EOF
}
var zeroPage *[]byte
for rem != 0 && avail > 0 {
pg := f.m[pi]
if pg == nil {
if zeroPage == nil {
zeroPage = buffer.CGet(f.pgSize)
defer buffer.Put(zeroPage)
}
pg = zeroPage
}
nc := copy(b[:mathutil.Min(rem, f.pgSize)], (*pg)[po:])
pi++
po = 0
rem -= nc
n += nc
b = b[nc:]
}
return n, err
}
开发者ID:brgmnn,项目名称:syncthing,代码行数:28,代码来源:file.go
示例4: ReadAt
func (f *bitFiler) ReadAt(b []byte, off int64) (n int, err error) {
avail := f.size - off
pgI := off >> bfBits
pgO := int(off & bfMask)
rem := len(b)
if int64(rem) >= avail {
rem = int(avail)
err = io.EOF
}
for rem != 0 && avail > 0 {
pg := f.m[pgI]
if pg == nil {
pg = &bitPage{}
pg.pdata = buffer.CGet(bfSize)
pg.data = *pg.pdata
if f.parent != nil {
_, err = f.parent.ReadAt(pg.data, off&^bfMask)
if err != nil && !fileutil.IsEOF(err) {
return
}
err = nil
}
f.m[pgI] = pg
}
nc := copy(b[:mathutil.Min(rem, bfSize)], pg.data[pgO:])
pgI++
pgO = 0
rem -= nc
n += nc
b = b[nc:]
off += int64(nc)
}
return
}
开发者ID:brgmnn,项目名称:syncthing,代码行数:35,代码来源:xact.go
示例5: getTree
func (t *treeCache) getTree(db *DB, prefix int, name string, canCreate bool, cacheSize int) (r *lldb.BTree, err error) {
m := t.get()
r, ok := m[name]
if ok {
return
}
root, err := db.root()
if err != nil {
return
}
val, err := root.get(prefix, name)
if err != nil {
return
}
switch x := val.(type) {
case nil:
if !canCreate {
return
}
var h int64
r, h, err = lldb.CreateBTree(db.alloc, collate)
if err != nil {
return nil, err
}
if err = root.set(h, prefix, name); err != nil {
return nil, err
}
case int64:
if r, err = lldb.OpenBTree(db.alloc, collate, x); err != nil {
return nil, err
}
default:
return nil, &lldb.ErrINVAL{Src: "corrupted root directory value for", Val: fmt.Sprintf("%q, %q", prefix, name)}
}
if len(m) > cacheSize {
i, j, n := 0, cacheSize/2, mathutil.Min(cacheSize/20, 10)
loop:
for k := range m {
if i++; i >= j {
delete(m, k)
if n == 0 {
break loop
}
n--
}
}
}
m[name] = r
return
}
开发者ID:pmezard,项目名称:exp,代码行数:58,代码来源:etc.go
示例6: get2
func (c *cache) get2(n int) (r *node, isZeroed bool) {
s := *c
lens := len(s)
if lens == 0 {
return &node{b: make([]byte, n, mathutil.Min(2*n, maxBuf))}, true
}
i := sort.Search(lens, func(x int) bool { return len(s[x].b) >= n })
if i == lens {
i--
s[i].b, isZeroed = make([]byte, n, mathutil.Min(2*n, maxBuf)), true
}
r = s[i]
r.b = r.b[:n]
copy(s[i:], s[i+1:])
s = s[:lens-1]
*c = s
return
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:20,代码来源:falloc.go
示例7: Execute
// Execute implements Instruction.
//
// Stack frame before Execute:
//
// +----------------+
// | Return address |
// +----------------+
// SP -> | |
//
//
// Stack frame after Execute:
//
// +----------------+
// | Return address |
// +----------------+
// | Previous FP |
// +----------------+
// | [LNL]int | Parent Frame Pointers
// +----------------+
// | LNL | Lexical Nesting Level
// +----------------+
// FP -> | [NVars]int | Local variables
// +----------------+
// SP -> | ! Evaluation stack
func (n *Enter) Execute(m *VM) {
m.push(m.FP)
cur := 0
if n.LNL != 0 {
cur = m.read(m.FP - 1)
fp0x := m.FP - 1 - cur
for i := 0; i < mathutil.Min(cur, n.LNL); i++ {
m.push(m.read(fp0x))
fp0x++
}
}
if n.LNL > cur {
m.push(m.FP)
}
m.push(n.LNL)
m.FP = m.SP()
m.Stack = append(m.Stack, make([]int, n.NVars)...)
}
开发者ID:JamesLinus,项目名称:pl0,代码行数:42,代码来源:vm.go
示例8: PutBytes
// PutBytes stores b in the DB and returns its id. Zero length byte slices are
// guaranteed to return zero ID. PutBytes Locks the DB before updating it.
func (d *MemDB) PutBytes(b []byte) int {
if len(b) == 0 {
return 0
}
if len(b) == 1 {
return int(b[0]) + 1
}
d.mu.Lock() // W+
id := d.nextID
pi := id >> dbPageShift
if pi < len(d.pages) {
p := d.pages[pi]
off := id & dbPageMask
if n := cap(p) - off - maxUvarint; n >= len(b) {
p = p[:cap(p)]
l := binary.PutUvarint(p[off:], uint64(len(b)))
copy(p[off+l:], b)
n = l + len(b)
d.pages[pi] = p[:off+n]
d.nextID += n
d.mu.Unlock() // W-
return id + 257
}
pi++
}
p := make([]byte, mathutil.Max(dbPageSize, maxUvarint+len(b)))
p = p[:binary.PutUvarint(p, uint64(len(b)))]
p = append(p, b...)
d.pages = append(d.pages, p)
id = pi << dbPageShift
d.nextID = id + mathutil.Min(dbPageSize, len(p))
d.mu.Unlock() // W-
return id + 257
}
开发者ID:cznic,项目名称:xc,代码行数:45,代码来源:db.go
示例9: Readdir
// Readdir implements http.File.
func (f *HTTPFile) Readdir(count int) ([]os.FileInfo, error) {
if f.isFile {
return nil, fmt.Errorf("not a directory: %s", f.name)
}
if count <= 0 {
r := f.dirEntries
f.dirEntries = f.dirEntries[:0]
return r, nil
}
rq := mathutil.Min(count, len(f.dirEntries))
r := f.dirEntries[:rq]
f.dirEntries = f.dirEntries[rq:]
if len(r) != 0 {
return r, nil
}
return nil, io.EOF
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:21,代码来源:httpfs.go
示例10: ReadAt
// ReadAt implements Filer.
func (f *MemFiler) ReadAt(b []byte, off int64) (n int, err error) {
avail := f.size - off
pgI := off >> pgBits
pgO := int(off & pgMask)
rem := len(b)
if int64(rem) >= avail {
rem = int(avail)
err = io.EOF
}
for rem != 0 && avail > 0 {
pg := f.m[pgI]
if pg == nil {
pg = &zeroPage
}
nc := copy(b[:mathutil.Min(rem, pgSize)], pg[pgO:])
pgI++
pgO = 0
rem -= nc
n += nc
b = b[nc:]
}
return
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:24,代码来源:memfiler.go
示例11: readAt
func (f *File) readAt(b []byte, off int64, bits bool) (n int, err error) {
var fsize int64
if !bits {
fsize, err = f.Size()
if err != nil {
return
}
}
avail := fsize - off
pgI := off >> pgBits
pgO := int(off & pgMask)
rem := len(b)
if !bits && int64(rem) >= avail {
rem = int(avail)
err = io.EOF
}
for rem != 0 && (bits || avail > 0) {
v, err := (*Array)(f).Get(pgI)
if err != nil {
return n, err
}
pg, _ := v.([]byte)
if len(pg) == 0 {
pg = zeroPage[:]
}
nc := copy(b[:mathutil.Min(rem, pgSize)], pg[pgO:])
pgI++
pgO = 0
rem -= nc
n += nc
b = b[nc:]
}
return
}
开发者ID:pmezard,项目名称:exp,代码行数:37,代码来源:file.go
示例12: BenchmarkRollbackFiler
func BenchmarkRollbackFiler(b *testing.B) {
rng := rand.New(rand.NewSource(42))
type t struct {
off int64
b []byte
}
a := []t{}
for rem := b.N; rem > 0; {
off := rng.Int63()
n := mathutil.Min(rng.Intn(1e3)+1, rem)
a = append(a, t{off, rndBytes(rng, n)})
rem -= n
}
var r *RollbackFiler
f := NewMemFiler()
checkpoint := func(sz int64) (err error) {
return f.Truncate(sz)
}
r, err := NewRollbackFiler(f, checkpoint, f)
if err != nil {
b.Fatal(err)
}
if err := r.BeginUpdate(); err != nil {
b.Fatal(err)
}
b.ResetTimer()
for _, v := range a {
if _, err := r.WriteAt(v.b, v.off); err != nil {
b.Fatal(err)
}
}
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:37,代码来源:xact_test.go
示例13: main1
//.........这里部分代码省略.........
if err := p.SkeletonXErrors(b); err != nil {
return err
}
if err := b.Flush(); err != nil {
return err
}
if err := f.Close(); err != nil {
return err
}
}
msu := make(map[*y.Symbol]int, len(p.Syms)) // sym -> usage
for nm, sym := range p.Syms {
if nm == "" || nm == "ε" || nm == "$accept" || nm == "#" {
continue
}
msu[sym] = 0
}
var minArg, maxArg int
for _, state := range p.Table {
for _, act := range state {
msu[act.Sym]++
k, arg := act.Kind()
if k == 'a' {
continue
}
if k == 'r' {
arg = -arg
}
minArg, maxArg = mathutil.Min(minArg, arg), mathutil.Max(maxArg, arg)
}
}
su := make(symsUsed, 0, len(msu))
for sym, used := range msu {
su = append(su, symUsed{sym, used})
}
sort.Sort(su)
// ----------------------------------------------------------- Prologue
f := strutil.IndentFormatter(out, "\t")
f.Format("// CAUTION: Generated file - DO NOT EDIT.\n\n")
f.Format("%s", injectImport(p.Prologue))
f.Format(`
type %[1]sSymType %i%s%u
type %[1]sXError struct {
state, xsym int
}
`, *oPref, p.UnionSrc)
// ---------------------------------------------------------- Constants
nsyms := map[string]*y.Symbol{}
a := make([]string, 0, len(msu))
maxTokName := 0
for sym := range msu {
nm := sym.Name
if nm == "$default" || nm == "$end" || sym.IsTerminal && nm[0] != '\'' && sym.Value > 0 {
maxTokName = mathutil.Max(maxTokName, len(nm))
a = append(a, nm)
}
nsyms[nm] = sym
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:67,代码来源:main.go
示例14: flatten
// []interface{}{qltype, ...}->[]interface{}{lldb scalar type, ...}
// + long blobs are (pre)written to a chain of chunks.
func (s *file) flatten(data []interface{}) (err error) {
for i, v := range data {
tag := 0
var b []byte
switch x := v.(type) {
case []byte:
tag = qBlob
b = x
case *big.Int:
tag = qBigInt
b, err = s.codec.encode(x)
case *big.Rat:
tag = qBigRat
b, err = s.codec.encode(x)
case time.Time:
tag = qTime
b, err = s.codec.encode(x)
case time.Duration:
tag = qDuration
b, err = s.codec.encode(x)
default:
continue
}
if err != nil {
return
}
const chunk = 1 << 16
chunks := 0
var next int64
var buf []byte
for rem := len(b); rem > shortBlob; {
n := mathutil.Min(rem, chunk)
part := b[rem-n:]
b = b[:rem-n]
rem -= n
switch next {
case 0: // last chunk
buf, err = lldb.EncodeScalars([]interface{}{part}...)
default: // middle chunk
buf, err = lldb.EncodeScalars([]interface{}{next, part}...)
}
if err != nil {
return
}
h, err := s.a.Alloc(buf)
if err != nil {
return err
}
next = h
chunks++
}
switch next {
case 0: // single chunk
buf, err = lldb.EncodeScalars([]interface{}{tag, b}...)
default: // multi chunks
buf, err = lldb.EncodeScalars([]interface{}{tag, next, b}...)
}
if err != nil {
return
}
data[i] = buf
}
return
}
开发者ID:uabassguy,项目名称:ql,代码行数:71,代码来源:file.go
示例15: freeNSynapses
/*
Free up some synapses in this segment. We always free up inactive
synapses (lowest permanence freed up first) before we start to free up
active ones.
param numToFree number of synapses to free up
param inactiveSynapseIndices list of the inactive synapse indices.
*/
func (s *Segment) freeNSynapses(numToFree int, inactiveSynapseIndices []int) {
//Make sure numToFree isn't larger than the total number of syns we have
if numToFree > len(s.syns) {
panic("Number to free cannot be larger than existing synapses.")
}
if s.tp.params.Verbosity >= 5 {
fmt.Println("freeNSynapses with numToFree=", numToFree)
fmt.Println("inactiveSynapseIndices= ", inactiveSynapseIndices)
}
var candidates []int
// Remove the lowest perm inactive synapses first
if len(inactiveSynapseIndices) > 0 {
perms := make([]float64, len(inactiveSynapseIndices))
for idx, _ := range perms {
perms[idx] = s.syns[idx].Permanence
}
var indexes []int
floats.Argsort(perms, indexes)
//sort perms
cSize := mathutil.Min(numToFree, len(perms))
candidates = make([]int, cSize)
//indexes[0:cSize]
for i := 0; i < cSize; i++ {
candidates[i] = inactiveSynapseIndices[indexes[i]]
}
}
// Do we need more? if so, remove the lowest perm active synapses too
var activeSynIndices []int
if len(candidates) < numToFree {
for i := 0; i < len(s.syns); i++ {
if !utils.ContainsInt(i, inactiveSynapseIndices) {
activeSynIndices = append(activeSynIndices, i)
}
}
perms := make([]float64, len(activeSynIndices))
for i := range perms {
perms[i] = s.syns[i].Permanence
}
var indexes []int
floats.Argsort(perms, indexes)
moreToFree := numToFree - len(candidates)
//moreCandidates := make([]int, moreToFree)
for i := 0; i < moreToFree; i++ {
candidates = append(candidates, activeSynIndices[indexes[i]])
}
}
if s.tp.params.Verbosity >= 4 {
fmt.Printf("Deleting %v synapses from segment to make room for new ones: %v \n",
len(candidates), candidates)
fmt.Println("Before:", s.ToString())
}
// Delete candidate syns by copying undeleted to new slice
var newSyns []Synapse
for idx, val := range s.syns {
if !utils.ContainsInt(idx, candidates) {
newSyns = append(newSyns, val)
}
}
s.syns = newSyns
if s.tp.params.Verbosity >= 4 {
fmt.Println("After:", s.ToString())
}
}
开发者ID:Fardinak,项目名称:htm,代码行数:80,代码来源:segment.go
示例16: minmax
func minmax(a, b int) {
fmt.Println("Min:", mathutil.Min(a, b))
fmt.Println("Max:", mathutil.Max(a, b))
}
开发者ID:plumbum,项目名称:go-samples,代码行数:4,代码来源:math.go
示例17: infer
func (tp *TrivialPredictor) infer(activeColumns []int) {
numColsToPredict := int(0.5 + tp.AverageDensity*float64(tp.NumOfCols))
//for method in self.methods:
for _, method := range tp.Methods {
// Copy t-1 into t
copy(tp.State[method].ActiveStateLast, tp.State[method].ActiveState)
copy(tp.State[method].PredictedStateLast, tp.State[method].PredictedState)
copy(tp.State[method].ConfidenceLast, tp.State[method].Confidence)
utils.FillSliceBool(tp.State[method].ActiveState, false)
utils.FillSliceBool(tp.State[method].PredictedState, false)
utils.FillSliceFloat64(tp.State[method].Confidence, 0.0)
for _, val := range activeColumns {
tp.State[method].ActiveState[val] = true
}
var predictedCols []int
switch method {
case Random:
// Randomly predict N columns
//predictedCols = RandomInts(numColsToPredict, tp.NumOfCols)
break
case Zeroth:
// Always predict the top N most frequent columns
var inds []int
ints.Argsort(tp.ColumnCount, inds)
predictedCols = inds[len(inds)-numColsToPredict:]
break
case Last:
// Always predict the last input
for idx, val := range tp.State[method].ActiveState {
if val {
predictedCols = append(predictedCols, idx)
}
}
break
case All:
// Always predict all columns
for i := 0; i < tp.NumOfCols; i++ {
predictedCols = append(predictedCols, i)
}
break
case Lots:
// Always predict 2 * the top N most frequent columns
numColsToPredict := mathutil.Min(2*numColsToPredict, tp.NumOfCols)
var inds []int
ints.Argsort(tp.ColumnCount, inds)
predictedCols = inds[len(inds)-numColsToPredict:]
break
default:
panic("prediction method not implemented")
}
for _, val := range predictedCols {
tp.State[method].PredictedState[val] = true
tp.State[method].Confidence[val] = 1.0
}
if tp.Verbosity > 1 {
fmt.Println("Random prediction:", method)
fmt.Println(" numColsToPredict:", numColsToPredict)
fmt.Println(predictedCols)
}
}
}
开发者ID:Fardinak,项目名称:htm,代码行数:72,代码来源:trivialPredictor.go
示例18: NewSpatialPooler
//Creates a new spatial pooler
func NewSpatialPooler(spParams SpParams) *SpatialPooler {
sp := SpatialPooler{}
//Validate inputs
sp.numColumns = utils.ProdInt(spParams.ColumnDimensions)
sp.numInputs = utils.ProdInt(spParams.InputDimensions)
if sp.numColumns < 1 {
panic("Must have at least 1 column")
}
if sp.numInputs < 1 {
panic("must have at least 1 input")
}
if spParams.NumActiveColumnsPerInhArea < 1 && (spParams.LocalAreaDensity < 1) && (spParams.LocalAreaDensity >= 0.5) {
panic("Num active colums invalid")
}
sp.InputDimensions = spParams.InputDimensions
sp.ColumnDimensions = spParams.ColumnDimensions
sp.PotentialRadius = int(mathutil.Min(spParams.PotentialRadius, sp.numInputs))
sp.PotentialPct = spParams.PotentialPct
sp.GlobalInhibition = spParams.GlobalInhibition
sp.LocalAreaDensity = spParams.LocalAreaDensity
sp.NumActiveColumnsPerInhArea = spParams.NumActiveColumnsPerInhArea
sp.StimulusThreshold = spParams.StimulusThreshold
sp.SynPermInactiveDec = spParams.SynPermInactiveDec
sp.SynPermActiveInc = spParams.SynPermActiveInc
sp.SynPermBelowStimulusInc = spParams.SynPermConnected / 10.0
sp.SynPermConnected = spParams.SynPermConnected
sp.MinPctOverlapDutyCycles = spParams.MinPctOverlapDutyCycle
sp.MinPctActiveDutyCycles = spParams.MinPctActiveDutyCycle
sp.DutyCyclePeriod = spParams.DutyCyclePeriod
sp.MaxBoost = spParams.MaxBoost
sp.Seed = spParams.Seed
sp.SpVerbosity = spParams.SpVerbosity
// Extra parameter settings
sp.SynPermMin = 0
sp.SynPermMax = 1
sp.SynPermTrimThreshold = sp.SynPermActiveInc / 2.0
if sp.SynPermTrimThreshold >= sp.SynPermConnected {
panic("Syn perm threshold >= syn connected.")
}
sp.UpdatePeriod = 50
sp.InitConnectedPct = 0.5
/*
# Internal state
version = 1.0
iterationNum = 0
iterationLearnNum = 0
*/
/*
Store the set of all inputs that are within each column's potential pool.
'potentialPools' is a matrix, whose rows represent cortical columns, and
whose columns represent the input bits. if potentialPools[i][j] == 1,
then input bit 'j' is in column 'i's potential pool. A column can only be
connected to inputs in its potential pool. The indices refer to a
falttenned version of both the inputs and columns. Namely, irrespective
of the topology of the inputs and columns, they are treated as being a
one dimensional array. Since a column is typically connected to only a
subset of the inputs, many of the entries in the matrix are 0. Therefore
the the potentialPool matrix is stored using the SparseBinaryMatrix
class, to reduce memory footprint and compuation time of algorithms that
require iterating over the data strcuture.
*/
sp.potentialPools = NewDenseBinaryMatrix(sp.numColumns, sp.numInputs)
/*
Initialize the permanences for each column. Similar to the
'potentialPools', the permances are stored in a matrix whose rows
represent the cortial columns, and whose columns represent the input
bits. if permanences[i][j] = 0.2, then the synapse connecting
cortical column 'i' to input bit 'j' has a permanence of 0.2. Here we
also use the SparseMatrix class to reduce the memory footprint and
computation time of algorithms that require iterating over the data
structure. This permanence matrix is only allowed to have non-zero
elements where the potential pool is non-zero.
*/
//Assumes 70% sparsity
elms := make(map[int]float64, int(float64(sp.numColumns*sp.numInputs)*0.3))
sp.permanences = matrix.MakeSparseMatrix(elms, sp.numColumns, sp.numInputs)
/*
Initialize a tiny random tie breaker. This is used to determine winning
columns where the overlaps are identical.
*/
sp.tieBreaker = make([]float64, sp.numColumns)
for i := 0; i < len(sp.tieBreaker); i++ {
sp.tieBreaker[i] = 0.01 * rand.Float64()
}
/*
'connectedSynapses' is a similar matrix to 'permanences'
(rows represent cortial columns, columns represent input bits) whose
entries represent whether the cortial column is connected to the input
bit, i.e. its permanence value is greater than 'synPermConnected'. While
this information is readily available from the 'permanence' matrix,
//.........这里部分代码省略.........
开发者ID:Fardinak,项目名称:htm,代码行数:101,代码来源:spatialPooler.go
示例19: TestMarshal
//.........这里部分代码省略.........
//int64(1),
int8(2),
int16(3),
int32(4),
int64(5),
//uint64(6),
uint8(7),
uint16(8),
uint32(9),
uint64(10),
float32(11),
float64(12),
complex64(-1),
complex128(-2),
[]byte("abc"),
*big.NewInt(1),
*big.NewRat(3, 2),
"string",
now,
dur,
}},
}
for iTest, test := range tab {
r, err := Marshal(test.inst)
if g, e := err != nil, test.err; g != e {
t.Fatal(iTest, g, e)
}
if err != nil {
t.Log(err)
continue
}
for i := 0; i < mathutil.Min(len(r), len(test.r)); i++ {
g, e := r[i], test.r[i]
use(e)
switch x := g.(type) {
case bool:
switch y := e.(type) {
case bool:
if x != y {
t.Fatal(iTest, x, y)
}
default:
t.Fatalf("%d: %T <-> %T", iTest, x, y)
}
case int:
switch y := e.(type) {
case int64:
if int64(x) != y {
t.Fatal(iTest, x, y)
}
default:
t.Fatalf("%d: %T <-> %T", iTest, x, y)
}
case int8:
switch y := e.(type) {
case int8:
if x != y {
t.Fatal(iTest, x, y)
}
default:
t.Fatalf("%d: %T <-> %T", iTest, x, y)
}
case int16:
switch y := e.(type) {
开发者ID:pkf,项目名称:ql,代码行数:67,代码来源:introspection_test.go
注:本文中的github.com/cznic/mathutil.Min函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论