当前位置: 首页>>代码示例>>Golang>>正文


Golang proto.Float64函数代码示例

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


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

示例1: TestUpdate

func TestUpdate(t *testing.T) {
	neuralNetwork := CreateSimpleNetwork(t)
	inputs := mat64.NewDense(1, 2, []float64{0.05, 0.10})
	neuralNetwork.Forward(inputs)
	values := mat64.NewDense(1, 2, []float64{0.01, 0.99})
	neuralNetwork.Backward(values)
	learningConfiguration := neural.LearningConfiguration{
		Epochs:    proto.Int32(1),
		Rate:      proto.Float64(0.5),
		Decay:     proto.Float64(0),
		BatchSize: proto.Int32(1),
	}
	neuralNetwork.Update(learningConfiguration)
	expected_weights_0 := mat64.NewDense(
		3, 2, []float64{0.149780716, 0.24975114, 0.19956143, 0.29950229, 0.35,
			0.35})
	if !mat64.EqualApprox(
		neuralNetwork.Layers[0].Weight, expected_weights_0, 0.0001) {
		t.Errorf("weights 0 unexpected:\n%v",
			mat64.Formatted(neuralNetwork.Layers[0].Weight))
	}
	expected_weights_1 := mat64.NewDense(
		3, 2, []float64{0.35891648, 0.51130127, 0.408666186, 0.561370121, 0.6,
			0.6})
	if !mat64.EqualApprox(
		neuralNetwork.Layers[1].Weight, expected_weights_1, 0.0001) {
		t.Errorf("weights 1 unexpected:\n%v",
			mat64.Formatted(neuralNetwork.Layers[1].Weight))
	}
}
开发者ID:evilrobot69,项目名称:NeuralGo,代码行数:30,代码来源:network_test.go

示例2: Write

func (s *summary) Write(out *dto.Metric) error {
	sum := &dto.Summary{}
	qs := make([]*dto.Quantile, 0, len(s.objectives))

	s.bufMtx.Lock()
	s.mtx.Lock()

	if len(s.hotBuf) != 0 {
		s.swapBufs(time.Now())
	}
	s.bufMtx.Unlock()

	s.flushColdBuf()
	sum.SampleCount = proto.Uint64(s.cnt)
	sum.SampleSum = proto.Float64(s.sum)

	for _, rank := range s.sortedObjectives {
		qs = append(qs, &dto.Quantile{
			Quantile: proto.Float64(rank),
			Value:    proto.Float64(s.headStream.Query(rank)),
		})
	}

	s.mtx.Unlock()

	if len(qs) > 0 {
		sort.Sort(quantSort(qs))
	}
	sum.Quantile = qs

	out.Summary = sum
	out.Label = s.labelPairs
	return nil
}
开发者ID:gdvalle,项目名称:memcache_exporter,代码行数:34,代码来源:summary.go

示例3: makeServerRequest

func makeServerRequest(fix fixture, resID string, clients []clientWants, has float64) (*pb.GetServerCapacityResponse, error) {
	var wants []*pb.PriorityBandAggregate
	for _, client := range clients {
		wants = append(wants, &pb.PriorityBandAggregate{
			Priority:   proto.Int64(0),
			NumClients: proto.Int64(client.numClients),
			Wants:      proto.Float64(client.wants),
		})
	}

	req := &pb.GetServerCapacityRequest{
		ServerId: proto.String("server"),
		Resource: []*pb.ServerCapacityResourceRequest{
			{
				ResourceId: proto.String(resID),
				Has: &pb.Lease{
					ExpiryTime:      proto.Int64(0),
					RefreshInterval: proto.Int64(0),
					Capacity:        proto.Float64(0),
				},
				Wants: wants,
			},
		},
	}

	if has > 0 {
		req.Resource[0].Has = &pb.Lease{
			ExpiryTime:      proto.Int64(time.Now().Add(1 * time.Minute).Unix()),
			RefreshInterval: proto.Int64(1),
			Capacity:        proto.Float64(has),
		}
	}

	return fix.client.GetServerCapacity(context.Background(), req)
}
开发者ID:youtube,项目名称:doorman,代码行数:35,代码来源:server_test.go

示例4: makeRequest

func makeRequest(fix fixture, wants, has float64) (*pb.GetCapacityResponse, error) {
	req := &pb.GetCapacityRequest{
		ClientId: proto.String("client"),
		Resource: []*pb.ResourceRequest{
			{
				ResourceId: proto.String("resource"),
				Priority:   proto.Int64(1),
				Has: &pb.Lease{
					ExpiryTime:      proto.Int64(0),
					RefreshInterval: proto.Int64(0),
					Capacity:        proto.Float64(0),
				},
				Wants: proto.Float64(wants),
			},
		},
	}

	if has > 0 {
		req.Resource[0].Has = &pb.Lease{
			ExpiryTime:      proto.Int64(time.Now().Add(1 * time.Minute).Unix()),
			RefreshInterval: proto.Int64(5),
			Capacity:        proto.Float64(has),
		}
	}

	return fix.client.GetCapacity(context.Background(), req)
}
开发者ID:youtube,项目名称:doorman,代码行数:27,代码来源:server_test.go

示例5: TestParseTextFiles

func TestParseTextFiles(t *testing.T) {
	tests := []struct {
		path string
		out  string
	}{
		{
			path: "fixtures/textfile/no_metric_files",
			out:  "fixtures/textfile/no_metric_files.out",
		},
		{
			path: "fixtures/textfile/two_metric_files",
			out:  "fixtures/textfile/two_metric_files.out",
		},
		{
			path: "fixtures/textfile/nonexistent_path",
			out:  "fixtures/textfile/nonexistent_path.out",
		},
	}

	for i, test := range tests {
		c := textFileCollector{
			path: test.path,
		}

		// Suppress a log message about `nonexistent_path` not existing, this is
		// expected and clutters the test output.
		err := flag.Set("log.level", "fatal")
		if err != nil {
			t.Fatal(err)
		}

		mfs := c.parseTextFiles()
		textMFs := make([]string, 0, len(mfs))
		for _, mf := range mfs {
			if mf.GetName() == "node_textfile_mtime" {
				mf.GetMetric()[0].GetGauge().Value = proto.Float64(1)
				mf.GetMetric()[1].GetGauge().Value = proto.Float64(2)
			}
			textMFs = append(textMFs, proto.MarshalTextString(mf))
		}
		sort.Strings(textMFs)
		got := strings.Join(textMFs, "")

		want, err := ioutil.ReadFile(test.out)
		if err != nil {
			t.Fatalf("%d. error reading fixture file %s: %s", i, test.out, err)
		}

		if string(want) != got {
			t.Fatalf("%d. want:\n\n%s\n\ngot:\n\n%s", i, string(want), got)
		}
	}
}
开发者ID:juergenhoetzel,项目名称:node_exporter,代码行数:53,代码来源:textfile_test.go

示例6: TestOffer

func TestOffer(t *testing.T) {
	offer := util.NewOffer(util.NewOfferID("487c73d8-9951-f23c-34bd-8085bfd30c49"), util.NewFrameworkID("20150903-065451-84125888-5050-10715-0053"),
		util.NewSlaveID("20150903-065451-84125888-5050-10715-S1"), "slave0")

	if Offer(offer) != "slave0#30c49" {
		t.Errorf(`util.NewOffer(util.NewOfferID("487c73d8-9951-f23c-34bd-8085bfd30c49"), util.NewFrameworkID("20150903-065451-84125888-5050-10715-0053"), util.NewSlaveID("20150903-065451-84125888-5050-10715-S1"), "slave0") != "slave0#30c49"; actual %s`, Offer(offer))
	}

	offer.Resources = []*mesos.Resource{util.NewScalarResource("cpus", 4), util.NewScalarResource("mem", 512), util.NewRangesResource("ports", []*mesos.Value_Range{util.NewValueRange(31000, 32000)})}
	if Offer(offer) != "slave0#30c49 cpus:4.00 mem:512.00 ports:[31000..32000]" {
		t.Errorf("Expected slave0#30c49 cpus:4.00 mem:512.00 ports:[31000..32000]; actual %s", Offer(offer))
	}

	offer.Attributes = []*mesos.Attribute{&mesos.Attribute{
		Name:   proto.String("rack"),
		Type:   mesos.Value_SCALAR.Enum(),
		Scalar: &mesos.Value_Scalar{Value: proto.Float64(2)},
	}}
	if Offer(offer) != "slave0#30c49 cpus:4.00 mem:512.00 ports:[31000..32000] rack:2.00" {
		t.Errorf("Expected slave0#30c49 cpus:4.00 mem:512.00 ports:[31000..32000] rack:2.00; actual %s", Offer(offer))
	}

	offer.Resources = nil
	if Offer(offer) != "slave0#30c49 rack:2.00" {
		t.Errorf("Expected slave0#30c49 rack:2.00; actual %s", Offer(offer))
	}
}
开发者ID:elodina,项目名称:stack-deploy,代码行数:27,代码来源:pretty_test.go

示例7: TestAttribute

func TestAttribute(t *testing.T) {
	attr := Attribute(&mesos.Attribute{
		Name:   proto.String("rack"),
		Type:   mesos.Value_SCALAR.Enum(),
		Scalar: &mesos.Value_Scalar{Value: proto.Float64(2)},
	})
	if attr != "rack:2.00" {
		t.Errorf(`Attribute(&mesos.Attribute{
        Name: proto.String("rack"),
        Type: mesos.Value_SCALAR.Enum(),
        Scalar: &mesos.Value_Scalar{Value: proto.Float64(2)},
    }) != "rack:2.00"; actual %s`, attr)
	}

	attr = Attribute(&mesos.Attribute{
		Name: proto.String("datacenter"),
		Type: mesos.Value_TEXT.Enum(),
		Text: &mesos.Value_Text{Value: proto.String("DC-1")},
	})
	if attr != "datacenter:DC-1" {
		t.Errorf(`Attribute(&mesos.Attribute{
        Name: proto.String("datacenter"),
        Type: mesos.Value_TEXT.Enum(),
        Text: proto.String("DC-1"),
    }) != "datacenter:DC-1"; actual %s`, attr)
	}
}
开发者ID:elodina,项目名称:stack-deploy,代码行数:27,代码来源:pretty_test.go

示例8: lease

func lease(c context.Context, maxTasks int, queueName string, leaseTime int, groupByTag bool, tag []byte) ([]*Task, error) {
	if queueName == "" {
		queueName = "default"
	}
	req := &pb.TaskQueueQueryAndOwnTasksRequest{
		QueueName:    []byte(queueName),
		LeaseSeconds: proto.Float64(float64(leaseTime)),
		MaxTasks:     proto.Int64(int64(maxTasks)),
		GroupByTag:   proto.Bool(groupByTag),
		Tag:          tag,
	}
	res := &pb.TaskQueueQueryAndOwnTasksResponse{}
	if err := internal.Call(c, "taskqueue", "QueryAndOwnTasks", req, res); err != nil {
		return nil, err
	}
	tasks := make([]*Task, len(res.Task))
	for i, t := range res.Task {
		tasks[i] = &Task{
			Payload:    t.Body,
			Name:       string(t.TaskName),
			Method:     "PULL",
			ETA:        time.Unix(0, *t.EtaUsec*1e3),
			RetryCount: *t.RetryCount,
			Tag:        string(t.Tag),
		}
	}
	return tasks, nil
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:28,代码来源:taskqueue.go

示例9: Float64P

// Float64P parses the given string representation of a floating point number,
// and returns a pointer to a float64 whose value is same as the parsed number.
func Float64P(val string) (*float64, error) {
	f, err := Float64(val)
	if err != nil {
		return nil, err
	}
	return proto.Float64(f), nil
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:9,代码来源:proto2_convert.go

示例10: Write

func (cn *Conn) Write(b []byte) (n int, err error) {
	const lim = 1 << 20 // max per chunk

	for n < len(b) {
		chunk := b[n:]
		if len(chunk) > lim {
			chunk = chunk[:lim]
		}

		req := &pb.SendRequest{
			SocketDescriptor: &cn.desc,
			Data:             chunk,
			StreamOffset:     &cn.offset,
		}
		res := &pb.SendReply{}
		if !cn.writeDeadline.IsZero() {
			req.TimeoutSeconds = proto.Float64(cn.writeDeadline.Sub(time.Now()).Seconds())
		}
		if err = cn.c.Call("remote_socket", "Send", req, res, opts(cn.writeDeadline)); err != nil {
			// assume zero bytes were sent in this RPC
			break
		}
		n += int(res.GetDataSent())
	}

	cn.offset += int64(n)
	return
}
开发者ID:SiroDiaz,项目名称:csuf,代码行数:28,代码来源:socket.go

示例11: SetSafeCapacity

// SetSafeCapacity sets the safe capacity in a response.
func (res *Resource) SetSafeCapacity(resp *pb.ResourceResponse) {
	res.mu.RLock()
	defer res.mu.RUnlock()

	// If the resource configuration does not have a safe capacity
	// configured we return a dynamic safe capacity which equals
	// the capacity divided by the number of clients that we
	// know about.
	// TODO(josv): The calculation of the dynamic safe capacity
	// needs to take sub clients into account (in a multi-server tree).
	if res.config.SafeCapacity == nil {
		resp.SafeCapacity = proto.Float64(*res.config.Capacity / float64(res.store.Count()))
	} else {
		resp.SafeCapacity = proto.Float64(*res.config.SafeCapacity)
	}
}
开发者ID:youtube,项目名称:doorman,代码行数:17,代码来源:resource.go

示例12: createDriver

func createDriver(scheduler *Scheduler, settings *Settings) (*mesossched.MesosSchedulerDriver, error) {
	publishedAddr := net.ParseIP(settings.MessengerAddress)
	bindingPort := settings.MessengerPort
	credential, err := getCredential(settings)

	if err != nil {
		return nil, err
	}

	return mesossched.NewMesosSchedulerDriver(mesossched.DriverConfig{
		Master: settings.Master,
		Framework: &mesosproto.FrameworkInfo{
			Id:              getFrameworkID(settings),
			Name:            proto.String(settings.Name),
			User:            proto.String(settings.User),
			Checkpoint:      proto.Bool(settings.Checkpoint),
			FailoverTimeout: proto.Float64(settings.FailoverTimeout),
			Principal:       getPrincipalID(credential),
		},
		Scheduler:        scheduler,
		BindingAddress:   net.ParseIP("0.0.0.0"),
		PublishedAddress: publishedAddr,
		BindingPort:      bindingPort,
		Credential:       credential,
		WithAuthContext:  getAuthContext,
	})
}
开发者ID:klarna,项目名称:eremetic,代码行数:27,代码来源:driver.go

示例13: testSafeCapacity

func testSafeCapacity(t *testing.T) {
	template := makeResourceTemplate("res_with_safe_caoacity", pb.Algorithm_FAIR_SHARE)
	template.SafeCapacity = proto.Float64(10.0)
	s, err := MakeTestServer(template,
		makeResourceTemplate("*", pb.Algorithm_FAIR_SHARE))
	if err != nil {
		t.Errorf("MakeTestServer: %v", err)
	}

	res := s.getOrCreateResource("res_with_safe_capacity")
	res.store.Assign("client1", fiveMinutes, fiveSeconds, 10, 100, 1)
	res.store.Assign("client2", fiveMinutes, fiveSeconds, 10, 100, 1)
	resp := &pb.ResourceResponse{}
	res.SetSafeCapacity(resp)

	if *resp.SafeCapacity != 10 {
		t.Errorf("*resp.SafeCapacity: want:10, got:%v", *resp.SafeCapacity)
	}

	res = s.getOrCreateResource("res_without_safe_capacity")
	res.store.Assign("client1", fiveMinutes, fiveSeconds, 10, 100, 1)
	res.store.Assign("client2", fiveMinutes, fiveSeconds, 10, 100, 1)
	resp = &pb.ResourceResponse{}
	res.SetSafeCapacity(resp)

	if *resp.SafeCapacity != 50 {
		t.Errorf("*resp.SafeCapacity: want:50, got:%v", *resp.SafeCapacity)
	}
}
开发者ID:youtube,项目名称:doorman,代码行数:29,代码来源:resource_test.go

示例14: Read

func (cn *Conn) Read(b []byte) (n int, err error) {
	const maxRead = 1 << 20
	if len(b) > maxRead {
		b = b[:maxRead]
	}

	req := &pb.ReceiveRequest{
		SocketDescriptor: &cn.desc,
		DataSize:         proto.Int32(int32(len(b))),
	}
	res := &pb.ReceiveReply{}
	if !cn.readDeadline.IsZero() {
		req.TimeoutSeconds = proto.Float64(cn.readDeadline.Sub(time.Now()).Seconds())
	}
	if err := cn.c.Call("remote_socket", "Receive", req, res, opts(cn.readDeadline)); err != nil {
		return 0, err
	}
	if len(res.Data) == 0 {
		return 0, io.EOF
	}
	if len(res.Data) > len(b) {
		return 0, fmt.Errorf("socket: internal error: read too much data: %d > %d", len(res.Data), len(b))
	}
	return copy(b, res.Data), nil
}
开发者ID:SiroDiaz,项目名称:csuf,代码行数:25,代码来源:socket.go

示例15: NewNotification

func NewNotification(ty string, m map[string]interface{}) *Notification {
	res := &Notification{}
	res.Type = ty
	for k, v := range m {
		variant := &attribute.Variant{}
		switch v := v.(type) {
		case bool:
			variant.BoolValue = proto.Bool(v)
		// Minor annoyance here to have to do these casts, but it would be
		// a huge annoyance elsewhere:
		case int:
			variant.IntValue = proto.Int64(int64(v))
		case int32:
			variant.IntValue = proto.Int64(int64(v))
		case int64:
			variant.IntValue = proto.Int64(v)
		case uint:
			variant.UintValue = proto.Uint64(uint64(v))
		case uint32:
			variant.UintValue = proto.Uint64(uint64(v))
		case uint64:
			variant.UintValue = proto.Uint64(v)
		case float32:
			variant.FloatValue = proto.Float64(float64(v))
		case float64:
			variant.FloatValue = proto.Float64(v)
		case string:
			variant.StringValue = proto.String(v)
		case []byte:
			variant.BlobValue = v
		case MessageValue:
			variant.MessageValue = v.Value
		case FourccValue:
			variant.FourccValue = proto.String(v.Value)
		case entity.EntityId:
			variant.EntityidValue = &v
		default:
			log.Panicf("error: can't convert %s: %T to attribute", k, v)
		}
		res.Attributes = append(res.Attributes, &attribute.Attribute{
			Name:  proto.String(k),
			Value: variant,
		})
	}
	return res
}
开发者ID:thlac,项目名称:stove,代码行数:46,代码来源:notification.go


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