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

Golang errors.Errorf函数代码示例

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

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



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

示例1: SelectionProbability

func (w *Walker) SelectionProbability(Q_, R_, u_ *Sparse) (float64, error) {
	Q := Q_.Dense()
	R := R_.Dense()
	u := u_.Dense()
	I := matrix.Eye(Q.Rows())
	IQ, err := I.Minus(Q)
	if err != nil {
		return 0, err
	}
	N := matrix.Inverse(IQ)
	B, err := N.Times(R)
	if err != nil {
		return 0, err
	}
	P, err := u.Times(B)
	if err != nil {
		return 0, err
	}
	if P.Rows() != P.Cols() && P.Rows() != 1 {
		return 0, errors.Errorf("Unexpected P shape %v %v", P.Rows(), P.Cols())
	}
	x := P.Get(0, 0)
	if x > 1.0 || x != x {
		return 0, errors.Errorf("could not accurately compute p")
	}
	return x, nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:27,代码来源:mine.go


示例2: UnmarshalBinary

func (emb *Embedding) UnmarshalBinary(bytes []byte) error {
	if emb.SG != nil || emb.Ids != nil {
		return errors.Errorf("Embedding is already loaded! will not load serialized data")
	}
	if len(bytes) < 8 {
		return errors.Errorf("bytes was too small %v < 8", len(bytes))
	}
	lenE := int(binary.BigEndian.Uint32(bytes[0:4]))
	lenV := int(binary.BigEndian.Uint32(bytes[4:8]))
	off := 8
	expected := 8 + lenV*8 + lenE*12
	if len(bytes) < expected {
		return errors.Errorf("bytes was too small %v < %v", len(bytes), expected)
	}
	ids := make([]int, lenV)
	sg := &SubGraph{
		V:   make([]Vertex, lenV),
		E:   make([]Edge, lenE),
		Adj: make([][]int, lenV),
	}
	for i := 0; i < lenV; i++ {
		s := off + i*8
		e := s + 4
		id := int(binary.BigEndian.Uint32(bytes[s:e]))
		s += 4
		e += 4
		color := int(binary.BigEndian.Uint32(bytes[s:e]))
		ids[i] = id
		sg.V[i].Idx = i
		sg.V[i].Color = color
		sg.Adj[i] = make([]int, 0, 5)
	}
	off += lenV * 8
	for i := 0; i < lenE; i++ {
		s := off + i*12
		e := s + 4
		src := int(binary.BigEndian.Uint32(bytes[s:e]))
		s += 4
		e += 4
		targ := int(binary.BigEndian.Uint32(bytes[s:e]))
		s += 4
		e += 4
		color := int(binary.BigEndian.Uint32(bytes[s:e]))
		sg.E[i].Src = src
		sg.E[i].Targ = targ
		sg.E[i].Color = color
		sg.Adj[src] = append(sg.Adj[src], i)
		sg.Adj[targ] = append(sg.Adj[targ], i)
	}
	emb.SG = sg
	emb.Ids = ids
	return nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:53,代码来源:embedding.go


示例3: CommonAncestor

func CommonAncestor(patterns []lattice.Pattern) (_ lattice.Pattern, err error) {
	if len(patterns) == 0 {
		return nil, errors.Errorf("no patterns given")
	} else if len(patterns) == 1 {
		return patterns[0], nil
	}
	switch patterns[0].(type) {
	case *digraph.SubgraphPattern:
		return digraphCommonAncestor(patterns)
	case *itemset.Pattern:
		return itemsetCommonAncestor(patterns)
	default:
		return nil, errors.Errorf("unknown pattern type %v", patterns[0])
	}
}
开发者ID:timtadh,项目名称:sfp,代码行数:15,代码来源:ancestor.go


示例4: digraphItemset

func digraphItemset(n *digraph.EmbListNode, attr string) (types.Set, error) {
	dt := n.Dt
	embs, err := n.Embeddings()
	if err != nil {
		return nil, err
	}
	s := set.NewSortedSet(len(embs))
	for _, emb := range embs {
		for _, vid := range emb.Ids {
			err := dt.NodeAttrs.DoFind(
				int32(vid),
				func(_ int32, attrs map[string]interface{}) error {
					if val, has := attrs[attr]; has {
						switch v := val.(type) {
						case string:
							s.Add(types.String(v))
						case int:
							s.Add(types.Int(v))
						default:
							return errors.Errorf("DBSCAN does not yet support attr type %T", val)
						}
					}
					return nil
				})
			if err != nil {
				return nil, err
			}
		}
	}
	return s, nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:31,代码来源:dbscan.go


示例5: Pattern

func (f *Formatter) Pattern(node lattice.Node) (string, error) {
	switch n := node.(type) {
	case *EmbListNode:
		if len(n.embeddings) > 0 {
			Pat := n.Pat.Pretty(n.Dt.Labels)
			allAttrs, err := f.loadAttrs(n.embeddings[0])
			if err != nil {
				return "", err
			}
			attrs := make(map[int]map[string]interface{})
			for id, _ := range allAttrs {
				attrs[id] = make(map[string]interface{})
				if size, has := allAttrs[id]["fontsize"]; has {
					attrs[id]["fontsize"] = size
				}
			}
			dot := n.embeddings[0].Dotty(n.Dt.Labels, attrs)
			return fmt.Sprintf("// %s\n\n%s\n", Pat, dot), nil
		} else {
			return fmt.Sprintf("// {0:0}\n\ndigraph{}\n"), nil
		}
	default:
		return "", errors.Errorf("unknown node type %v", node)
	}
}
开发者ID:timtadh,项目名称:sfp,代码行数:25,代码来源:fmt.go


示例6: mapEntry

func mapEntry(item types.Hashable) (*types.MapEntry, error) {
	if me, ok := item.(*types.MapEntry); ok {
		return me, nil
	} else {
		return nil, errors.Errorf("Must pass a *types.MapEntry, got %T", item)
	}
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:7,代码来源:mapset.go


示例7: CPUProfile

func CPUProfile(cpuProfile string) func() {
	errors.Logf("DEBUG", "starting cpu profile: %v", cpuProfile)
	f, err := os.Create(cpuProfile)
	if err != nil {
		log.Fatal(err)
	}
	err = pprof.StartCPUProfile(f)
	if err != nil {
		log.Fatal(err)
	}
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		sig := <-sigs
		errors.Logf("DEBUG", "closing cpu profile")
		pprof.StopCPUProfile()
		err := f.Close()
		errors.Logf("DEBUG", "closed cpu profile, err: %v", err)
		panic(errors.Errorf("caught signal: %v", sig))
	}()
	return func() {
		errors.Logf("DEBUG", "closing cpu profile")
		pprof.StopCPUProfile()
		err := f.Close()
		errors.Logf("DEBUG", "closed cpu profile, err: %v", err)
	}
}
开发者ID:timtadh,项目名称:sfp,代码行数:27,代码来源:cmd.go


示例8: Set

func (l *List) Set(i int, item types.Hashable) (err error) {
	if i < 0 || i >= len(l.list) {
		return errors.Errorf("Access out of bounds. len(*List) = %v, idx = %v", len(l.list), i)
	}
	l.list[i] = item
	return nil
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:7,代码来源:array_list.go


示例9: UnmarshalBinary

func (self *Int16) UnmarshalBinary(data []byte) error {
	if len(data) != 2 {
		return errors.Errorf("data wrong size")
	}
	*self = Int16(binary.LittleEndian.Uint16(data))
	return nil
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:7,代码来源:int.go


示例10: droppedVertexOnEdgeRm

func (b *Builder) droppedVertexOnEdgeRm(edgeIdx int) (drop bool, idx int, err error) {
	edge := &b.E[edgeIdx]
	rmSrc := true
	rmTarg := true
	for i := range b.E {
		e := &b.E[i]
		if e == edge {
			continue
		}
		if edge.Src == e.Src || edge.Src == e.Targ {
			// a kid edge
			rmSrc = false
		}
		if edge.Targ == e.Src || edge.Targ == e.Targ {
			// a parent edge
			rmTarg = false
		}
	}
	if rmSrc && rmTarg {
		return false, 0, errors.Errorf("would have removed both source and target %v %v", rmSrc, rmTarg)
	}
	rmV := rmSrc || rmTarg
	var rmVidx int
	if rmSrc {
		rmVidx = edge.Src
	}
	if rmTarg {
		rmVidx = edge.Targ
	}
	return rmV, rmVidx, nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:31,代码来源:builder.go


示例11: Transition

func Transition(cur lattice.Node, adjs []lattice.Node, weight Weight, debug bool) (float64, lattice.Node, error) {
	if len(adjs) <= 0 {
		return 1, nil, nil
	}
	if len(adjs) == 1 {
		return 1, adjs[0], nil
	}
	prs, err := TransitionPrs(cur, adjs, weight, debug)
	if err != nil {
		return 0, nil, err
	} else if prs == nil {
		return 1, nil, nil
	}
	s := stats.Round(stats.Sum(prs), 3)
	if s != 1.0 {
		weights := make([]float64, 0, len(adjs))
		for _, v := range adjs {
			wght, _ := weight(cur, v)
			weights = append(weights, wght)
		}
		return 0, nil, errors.Errorf("sum(%v) (%v) != 1.0 from %v", prs, s, weights)
	}
	i := stats.WeightedSample(prs)
	return prs[i], adjs[i], nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:25,代码来源:transition.go


示例12: labelset

func labelset(node lattice.Node) (types.Set, error) {
	switch n := node.(type) {
	case *digraph.EmbListNode:
		return digraphLabelset(n)
	default:
		return nil, errors.Errorf("DBSCAN does not yet support %T", n)
	}
}
开发者ID:timtadh,项目名称:sfp,代码行数:8,代码来源:dbscan.go


示例13: itemset

func itemset(node lattice.Node, attr string) (types.Set, error) {
	switch n := node.(type) {
	case *digraph.EmbListNode:
		return digraphItemset(n, attr)
	default:
		return nil, errors.Errorf("DBSCAN does not yet support %T", n)
	}
}
开发者ID:timtadh,项目名称:sfp,代码行数:8,代码来源:dbscan.go


示例14: UnmarshalBinary

func (sg *SubGraph) UnmarshalBinary(bytes []byte) error {
	if sg.V != nil || sg.E != nil || sg.Adj != nil {
		return errors.Errorf("sg is already loaded! will not load serialized data")
	}
	if len(bytes) < 8 {
		return errors.Errorf("bytes was too small %v < 8", len(bytes))
	}
	lenE := int(binary.BigEndian.Uint32(bytes[0:4]))
	lenV := int(binary.BigEndian.Uint32(bytes[4:8]))
	off := 8
	expected := 8 + lenV*4 + lenE*12
	if len(bytes) < expected {
		return errors.Errorf("bytes was too small %v < %v", len(bytes), expected)
	}
	sg.V = make([]Vertex, lenV)
	sg.E = make([]Edge, lenE)
	sg.Adj = make([][]int, lenV)
	for i := 0; i < lenV; i++ {
		s := off + i*4
		e := s + 4
		color := int(binary.BigEndian.Uint32(bytes[s:e]))
		sg.V[i].Idx = i
		sg.V[i].Color = color
		sg.Adj[i] = make([]int, 0, 5)
	}
	off += lenV * 4
	for i := 0; i < lenE; i++ {
		s := off + i*12
		e := s + 4
		src := int(binary.BigEndian.Uint32(bytes[s:e]))
		s += 4
		e += 4
		targ := int(binary.BigEndian.Uint32(bytes[s:e]))
		s += 4
		e += 4
		color := int(binary.BigEndian.Uint32(bytes[s:e]))
		sg.E[i].Src = src
		sg.E[i].Targ = targ
		sg.E[i].Color = color
		sg.Adj[src] = append(sg.Adj[src], i)
		sg.Adj[targ] = append(sg.Adj[targ], i)
	}
	sg.labelCache = bytes
	return nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:45,代码来源:subgraph.go


示例15: Random

func (s *SortedSet) Random() (item types.Hashable, err error) {
	if s.Size() <= 0 {
		return nil, errors.Errorf("Set is empty")
	} else if s.Size() <= 1 {
		return s.Get(0)
	}
	i := rand.Intn(s.Size())
	return s.Get(i)
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:9,代码来源:sortedset.go


示例16: Item

func (s *Sorted) Item(item types.Hashable) (types.Hashable, error) {
	i, has, err := s.Find(item)
	if err != nil {
		return nil, err
	} else if !has {
		return nil, errors.Errorf("Item not found %v", item)
	}
	return s.Get(i)
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:9,代码来源:sorted.go


示例17: LoadNode

func LoadNode(items []int32, dt *ItemSets) (n *Node, err error) {
	n, err = TryLoadNode(items, dt)
	if err != nil {
		return nil, err
	} else if n == nil {
		return nil, errors.Errorf("Expected node %v to be in embeddings store but it wasn't", items)
	}
	return n, nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:9,代码来源:node.go


示例18: addEdge

func (l *baseLoader) addEdge(sid, tid int32, color int, label string) (err error) {
	if l.excluded[sid] || l.excluded[tid] {
		return nil
	}
	if l.dt.Include != nil && !l.dt.Include.MatchString(label) {
		return nil
	}
	if l.dt.Exclude != nil && l.dt.Exclude.MatchString(label) {
		return nil
	}
	if sidx, has := l.vidxs[sid]; !has {
		return errors.Errorf("unknown src id %v", tid)
	} else if tidx, has := l.vidxs[tid]; !has {
		return errors.Errorf("unknown targ id %v", tid)
	} else {
		l.b.AddEdge(&l.b.V[sidx], &l.b.V[tidx], color)
	}
	return nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:19,代码来源:base_loader.go


示例19: Delete

func (s *Sorted) Delete(item types.Hashable) (err error) {
	i, has, err := s.Find(item)
	if err != nil {
		return err
	} else if !has {
		return errors.Errorf("item %v not in the table", item)
	}
	return s.list.Remove(i)
	return nil
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:10,代码来源:sorted.go


示例20: VE

func VE(node lattice.Node) (V, E int) {
	E = 0
	V = 0
	switch n := node.(type) {
	case *EmbListNode:
		return len(n.Pat.V), len(n.Pat.E)
	default:
		panic(errors.Errorf("unknown node type %T %v", node, node))
	}
	return V, E
}
开发者ID:timtadh,项目名称:sfp,代码行数:11,代码来源:digraph.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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