// MultiCosN takes a list of expressions and computes the
// n most similar words for each.
342965
func MultiCosN(m *Model, exprs []Expr, n int) ([][]Match, error) {
	if n == 0 {
		return make([][]Match, len(exprs)), nil
	}

	vecs := make([]Vector, len(exprs))
	for i, e := range exprs {
		v, err := e.Eval(m)
		if err != nil {
			return nil, err
		}
		vecs[i] = v
	}

	wg := &sync.WaitGroup{}
	wg.Add(len(vecs))
	ch := make(chan multiMatches, len(vecs))
	for i, v := range vecs {
		go func(i int, v Vector) {
			ch <- multiMatches{N: i, Matches: m.cosineN(v, n)}
			wg.Done()
		}(i, v)
	}
	wg.Wait()
	close(ch)

	result := make([][]Match, len(vecs))
	for r := range ch {
		result[r.N] = r.Matches
	}
	return result, nil
}
305387
func NewMultiaddrBytes(b []byte) (a Multiaddr, err error) {
	defer func() {
		if e := recover(); e != nil {
			log.Printf("Panic in NewMultiaddrBytes on input %q: %s", b, e)
			err = fmt.Errorf("%v", e)
		}
	}()

	if err := validateBytes(b); err != nil {
		return nil, err
	}

	return &multiaddr{bytes: b}, nil
}
1371693
func (c CountersFuncWithMultiLabels) String() string {
	m := c.f()
	if m == nil {
		return "{}"
	}
	b := bytes.NewBuffer(make([]byte, 0, 4096))
	fmt.Fprintf(b, "{")
	firstValue := true
	for k, v := range m {
		if firstValue {
			firstValue = false
		} else {
			fmt.Fprintf(b, ", ")
		}
		fmt.Fprintf(b, "%q: %v", k, v)
	}
	fmt.Fprintf(b, "}")
	return b.String()
}
58320
func NewTransaction(conn *Conn) *Transaction {
	return &Transaction{
		conn:     conn,
		commands: []*Command{NewCommand("MULTI")},
	}
}
1279867
func (rp *Reply) MultiValue() ([]*Reply, error) {
	if rp.Type == ErrorReply {
		return nil, errors.New(rp.Error)
	}
	if rp.Type != MultiReply {
		return nil, errors.New("invalid reply type, not multi bulk")
	}
	return rp.Multi, nil
}
696402
func MultiLine(logFn func(args ...interface{}), output string) {
	scanner := bufio.NewScanner(bytes.NewReader([]byte(output)))
	for scanner.Scan() {
		logFn(scanner.Text())
	}
}
1111499
func MultiLineString(b orb.Bound, mls orb.MultiLineString, opts ...Option) orb.MultiLineString {
	open := false
	if len(opts) > 0 {
		o := &options{}
		for _, opt := range opts {
			opt(o)
		}

		open = o.openBound
	}

	var result orb.MultiLineString
	for _, ls := range mls {
		r := line(b, ls, open)
		if len(r) != 0 {
			result = append(result, r...)
		}
	}
	return result
}
472427
func (b *Bucket) Multi(ctx context.Context, key, contType string, perm ACL) (MultiInt, error) {
	multis, _, err := b.ListMulti(ctx, key, "")
	if err != nil && !hasCode(err, "NoSuchUpload") {
		if !UsingFakeS3(ctx) {
			return nil, err
		}
		// fakes3 returns NoSuchKey instead of NoSuchUpload, and we want to continue
		// in that case, not abort
		if !hasCode(err, "NoSuchKey") {
			return nil, err
		}
	}
	for _, m := range multis {
		if m.Key == key {
			return m, nil
		}
	}

	return b.InitMulti(ctx, key, contType, perm)
}
1192361
func (self *InvoiceItemClient) ListN(count int, offset int) ([]*InvoiceItem, error) {
	return self.list("", count, offset)
}
573019
func (self *CouponClient) ListN(count int, offset int) ([]*Coupon, error) {
	// define a wrapper function for the Coupon List, so that we can
	// cleanly parse the JSON
	type listCouponResp struct{ Data []*Coupon }
	resp := listCouponResp{}

	// add the count and offset to the list of url values
	values := url.Values{
		"count":  {strconv.Itoa(count)},
		"offset": {strconv.Itoa(offset)},
	}

	err := query("GET", "/v1/coupons", values, &resp)
	if err != nil {
		return nil, err
	}
	return resp.Data, nil
}
330095
func concatOnAndWhereConds(join *Join, predicates []expression.Expression) []expression.Expression {
	equalConds, leftConds, rightConds, otherConds := join.EqualConditions, join.LeftConditions, join.RightConditions, join.OtherConditions
	ans := make([]expression.Expression, 0, len(equalConds)+len(leftConds)+len(rightConds)+len(predicates))
	for _, v := range equalConds {
		ans = append(ans, v)
	}
	ans = append(ans, leftConds...)
	ans = append(ans, rightConds...)
	ans = append(ans, otherConds...)
	ans = append(ans, predicates...)
	return ans
}
209603
func (p *Pollster) MultiSelect(l MultiList) ([]string, error) {
	var bad []string
	for _, s := range l.Options {
		if strings.Contains(s, ",") {
			bad = append(bad, s)
		}
	}
	if len(bad) > 0 {
		return nil, errors.Errorf("options may not contain commas: %q", bad)
	}
	if err := listTmpl.Execute(p.out, l); err != nil {
		return nil, err
	}

	// If there is only ever one option and that option also equals the default
	// option, then just echo out what that option is (above), then return that
	// option back.
	if len(l.Default) == 1 && len(l.Options) == 1 && l.Options[0] == l.Default[0] {
		return l.Default, nil
	}

	question, err := sprint(multiSelectTmpl, l)
	if err != nil {
		return nil, errors.Trace(err)
	}
	verify := multiVerify(l.Singular, l.Plural, l.Options, l.Default != nil)
	a, err := QueryVerify(question, p.scanner, p.out, p.errOut, verify)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if a == "" {
		return l.Default, nil
	}
	return multiSplit(a), nil
}
865131
func (r *Allocator) AllocateNext() (*mcs.Label, error) {
	offset, ok, err := r.alloc.AllocateNext()
	if err != nil {
		return nil, err
	}
	if !ok {
		return nil, ErrFull
	}
	label, ok := r.r.LabelAt(uint64(offset))
	if !ok {
		return nil, ErrNotInRange
	}
	return label, nil
}
425581
func (q *MultiMatchQuery) MaxExpansions(maxExpansions int) *MultiMatchQuery {
	q.maxExpansions = &maxExpansions
	return q
}
1333472
func multiExtractor(extractors ...empire.ProcfileExtractor) empire.ProcfileExtractor {
	return empire.ProcfileExtractorFunc(func(ctx context.Context, image image.Image, w *jsonmessage.Stream) ([]byte, error) {
		for _, extractor := range extractors {
			p, err := extractor.ExtractProcfile(ctx, image, w)

			// Yay!
			if err == nil {
				return p, nil
			}

			// Try the next one
			if _, ok := err.(*empire.ProcfileError); ok {
				continue
			}

			// Bubble up the error
			return p, err
		}

		return nil, &empire.ProcfileError{
			Err: errors.New("no suitable Procfile extractor found"),
		}
	})
}
640252
func (r *Route) MultiContainer() bool {
	return r.matchAll() || strings.Contains(r.FilterName, "*")
}
45863
func MultiSearch(ctx context.Context, req *SearchRequest, indexes ...Index) (*SearchResult, error) {

	searchStart := time.Now()
	asyncResults := make(chan *asyncSearchResult, len(indexes))

	// run search on each index in separate go routine
	var waitGroup sync.WaitGroup

	var searchChildIndex = func(in Index, childReq *SearchRequest) {
		rv := asyncSearchResult{Name: in.Name()}
		rv.Result, rv.Err = in.SearchInContext(ctx, childReq)
		asyncResults <- &rv
		waitGroup.Done()
	}

	waitGroup.Add(len(indexes))
	for _, in := range indexes {
		go searchChildIndex(in, createChildSearchRequest(req))
	}

	// on another go routine, close after finished
	go func() {
		waitGroup.Wait()
		close(asyncResults)
	}()

	var sr *SearchResult
	indexErrors := make(map[string]error)

	for asr := range asyncResults {
		if asr.Err == nil {
			if sr == nil {
				// first result
				sr = asr.Result
			} else {
				// merge with previous
				sr.Merge(asr.Result)
			}
		} else {
			indexErrors[asr.Name] = asr.Err
		}
	}

	// merge just concatenated all the hits
	// now lets clean it up

	// handle case where no results were successful
	if sr == nil {
		sr = &SearchResult{
			Status: &SearchStatus{
				Errors: make(map[string]error),
			},
		}
	}

	// sort all hits with the requested order
	if len(req.Sort) > 0 {
		sorter := newMultiSearchHitSorter(req.Sort, sr.Hits)
		sort.Sort(sorter)
	}

	// now skip over the correct From
	if req.From > 0 && len(sr.Hits) > req.From {
		sr.Hits = sr.Hits[req.From:]
	} else if req.From > 0 {
		sr.Hits = search.DocumentMatchCollection{}
	}

	// now trim to the correct size
	if req.Size > 0 && len(sr.Hits) > req.Size {
		sr.Hits = sr.Hits[0:req.Size]
	}

	// fix up facets
	for name, fr := range req.Facets {
		sr.Facets.Fixup(name, fr.Size)
	}

	// fix up original request
	sr.Request = req
	searchDuration := time.Since(searchStart)
	sr.Took = searchDuration

	// fix up errors
	if len(indexErrors) > 0 {
		if sr.Status.Errors == nil {
			sr.Status.Errors = make(map[string]error)
		}
		for indexName, indexErr := range indexErrors {
			sr.Status.Errors[indexName] = indexErr
			sr.Status.Total++
			sr.Status.Failed++
		}
	}

	return sr, nil
}