// BottleOne example
175875
func BottleOne(id int) (*Bottle, error) {
	for _, v := range bottles {
		if id == v.ID {
			return &v, nil
		}
	}
	return nil, ErrNoRow
}
1202554
func (nn *neuralnetwork2) train(examples []example) error {
	size := len(examples)
	batches := size / nn.BatchSize

	var start, end int
	if nn.BatchSize > size {
		batches = 1
		end = size
		G.WithBatchSize(float64(size))(nn.solver) // set it such that the solver doesn't get confused
	} else {
		end = nn.BatchSize
	}

	for batch := 0; batch < batches; batch++ {
		for _, ex := range examples[start:end] {
			nn.feats2vec(ex.features)
			tid := lookupTransition(ex.transition, nn.transitions)

			if err := G.UnsafeLet(nn.cost, G.S(tid)); err != nil {
				return err
			}

			if err := nn.vm.RunAll(); err != nil {
				return err
			}

			nn.vm.Reset()
		}
		if err := nn.solver.Step(nn.model); err != nil {
			err = errors.Wrapf(err, "Stepping on the model failed %v", batch)
			return err
		}

		if nn.costChan != nil {
			nn.costChan <- nn.costVal
		}

		start = end
		if start >= size {
			break
		}
		end += nn.BatchSize
		if end >= size {
			end = size
		}
	}

	return nil
}
911442
func NewClone(Expression node.Node) *Clone {
	return &Clone{
		FreeFloating: nil,
		Expr:         Expression,
	}
}
889588
func (p ResourcePersistence) getOne(resID string) (resourceDoc, error) {
	logger.Tracef("querying db for resource %q", resID)
	id := applicationResourceID(resID)
	var doc resourceDoc
	if err := p.base.One(resourcesC, id, &doc); err != nil {
		return doc, errors.Trace(err)
	}
	return doc, nil
}
1291936
func (t Term) ReadOne(dest interface{}, s QueryExecutor, optArgs ...RunOpts) error {
	res, err := t.Run(s, optArgs...)
	if err != nil {
		return err
	}
	return res.One(dest)
}
372815
func (h *Handle) EmptyClone() *Handle {
	newHandle := &Handle{
		store: h.store,
	}
	return newHandle
}
374364
func (c *CouchStore) ReadOne(key string) (error, caddyshack.StoreObject) {
	doc := couchdb.NewDocument(key, "", c.DbObj)
	jsonObj, err := doc.GetDocument()
	if err != nil {
		return err, nil
	}

	dynmaicObj := reflect.New(c.ObjType).Interface()
	err = json.Unmarshal(jsonObj, dynmaicObj)
	if err != nil {
		return err, nil
	}

	obj := dynmaicObj.(caddyshack.StoreObject)
	obj.SetKey(doc.Id)
	return err, obj
}
302801
func (t *TextStore) DestroyOne(key string) error {
	delete(t.dictionary, key)
	return nil
}
522993
func (db *DB) QueryOne(stmt Executable, i interface{}) error {
	result, err := db.Query(stmt)
	if err != nil {
		return err
	}
	// Close the result rows or sqlite3 will open another connection
	defer result.rows.Close()
	return result.One(i)
}
1292717
func ReadOne(rd io.Reader) (BSON, error) {
	// Read length of document.
	docLen, err := readInt32(rd)
	if err != nil {
		return nil, err
	}

	// Sanity check length.
	if docLen > maxDocLen {
		return nil, errors.New("Doc exceeded maximum size.")
	}

	// Read the document.
	buf := make([]byte, int(docLen))
	binary.LittleEndian.PutUint32(buf, uint32(docLen))
	if _, err := io.ReadFull(rd, buf[4:]); err != nil {
		return nil, err
	}

	return buf, nil
}
182426
func (t *MountTable) shallowClone() *MountTable {
	mt := &MountTable{
		Type:    t.Type,
		Entries: make([]*MountEntry, len(t.Entries)),
	}
	for i, e := range t.Entries {
		mt.Entries[i] = e
	}
	return mt
}
279758
func ReportOne(cl *trace.Client, metric *ssf.SSFSample) error {
	return ReportAsync(cl, []*ssf.SSFSample{metric}, nil)
}
992710
func (db *baseDB) ExecOne(query interface{}, params ...interface{}) (Result, error) {
	return db.execOne(context.TODO(), query, params...)
}
1037513
func (db *DB) NewBottle(account int) (model BottleModel, err error) {
	db.Lock()
	defer db.Unlock()
	if _, ok := db.accounts[account]; !ok {
		return model, fmt.Errorf("unknown account %d", account)
	}
	bottles, _ := db.bottles[account]
	newID := 0
	for {
		// newID has to be incremented in the loop, not
		// in the for statement, otherwise it gets
		// incremented on break, we skip the first
		// available new ID, and all new bottle IDs
		// get the identical second available new ID
		newID++
		for _, b := range bottles {
			if b.ID == newID {
				goto taken
			}
		}
		break
	taken:
		continue
	}
	model = BottleModel{ID: newID, AccountID: account}
	model.CreatedAt = time.Now()
	db.bottles[account] = append(db.bottles[account], &model)
	return
}
309751
func (wr *Wrangler) SplitClone(ctx context.Context, keyspace string, from, to []string) error {
	var fromShards, toShards []*topo.ShardInfo
	for _, shard := range from {
		si, err := wr.ts.GetShard(ctx, keyspace, shard)
		if err != nil {
			return vterrors.Wrapf(err, "GetShard(%s) failed", shard)
		}
		fromShards = append(fromShards, si)
	}
	for _, shard := range to {
		si, err := wr.ts.GetShard(ctx, keyspace, shard)
		if err != nil {
			return vterrors.Wrapf(err, "GetShard(%s) failed", shard)
		}
		toShards = append(toShards, si)
	}
	// TODO(sougou): validate from and to shards.

	for _, dest := range toShards {
		master, err := wr.ts.GetTablet(ctx, dest.MasterAlias)
		if err != nil {
			return vterrors.Wrapf(err, "GetTablet(%v) failed", dest.MasterAlias)
		}
		var ids []uint64
		for _, source := range fromShards {
			filter := &binlogdatapb.Filter{
				Rules: []*binlogdatapb.Rule{{
					Match:  "/.*",
					Filter: key.KeyRangeString(dest.KeyRange),
				}},
			}
			bls := &binlogdatapb.BinlogSource{
				Keyspace: keyspace,
				Shard:    source.ShardName(),
				Filter:   filter,
			}
			cmd := binlogplayer.CreateVReplicationState("VSplitClone", bls, "", binlogplayer.BlpStopped, master.DbName())
			qr, err := wr.TabletManagerClient().VReplicationExec(ctx, master.Tablet, cmd)
			if err != nil {
				return vterrors.Wrapf(err, "VReplicationExec(%v, %s) failed", dest.MasterAlias, cmd)
			}
			if err := wr.SourceShardAdd(ctx, keyspace, dest.ShardName(), uint32(qr.InsertId), keyspace, source.ShardName(), source.Shard.KeyRange, nil); err != nil {
				return vterrors.Wrapf(err, "SourceShardAdd(%s, %s) failed", dest.ShardName(), source.ShardName())
			}
			ids = append(ids, qr.InsertId)
		}
		// Start vreplication only if all metadata was successfully created.
		for _, id := range ids {
			cmd := fmt.Sprintf("update _vt.vreplication set state='%s' where id=%d", binlogplayer.VReplicationInit, id)
			if _, err = wr.TabletManagerClient().VReplicationExec(ctx, master.Tablet, cmd); err != nil {
				return vterrors.Wrapf(err, "VReplicationExec(%v, %s) failed", dest.MasterAlias, cmd)
			}
		}
	}
	return wr.refreshMasters(ctx, toShards)
}
1331732
func (tm *transactionManager) filterOne(
	transID string, addr *net.UDPAddr) *transaction {

	trans := tm.getByTransID(transID)
	if trans == nil || trans.node.addr.String() != addr.String() {
		return nil
	}

	return trans
}
216597
func (s ChocolateStorage) GetOne(id string) (model.Chocolate, error) {
	choc, ok := s.chocolates[id]
	if ok {
		return *choc, nil
	}

	return model.Chocolate{}, fmt.Errorf("Chocolate for id %s not found", id)
}