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


Golang sort.Float64Slice函数代码示例

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


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

示例1: testSortFn

func testSortFn(t *testing.T, fn sortFn, fnName string) {
	for _, test := range []sort.Interface{
		sort.IntSlice([]int{660, 14, 796, 336, 223, 594, 419, 574, 372, 103, 991, 718, 436, 351, 844, 277, 668, 250, 330, 86}),
		sort.Float64Slice([]float64{213.237, 458.642, 978.311, 547.351, 57.8992, 245.518, 445.638, 251.79, 960.202, 100.069, 483.136, 407.858, 496.913, 562.943, 557.959, 219.648, 164.599, 843.304, 671.732, 222.676}),
		sort.StringSlice([]string{"assaults", "brackish", "monarchism", "ascribe", "mechanize", "andiron", "overpricing", "jading", "hauliers", "snug", "zodiac", "credit", "tremendous", "palavered", "hibiscuses", "amplest", "interrogated", "geologic", "unorthodoxy", "propagated"}),
	} {
		// Make a copy to avoid modification of the original slice.
		var data sort.Interface
		switch v := test.(type) {
		case sort.IntSlice:
			data = append(sort.IntSlice(nil), v...)
		case sort.Float64Slice:
			data = append(sort.Float64Slice(nil), v...)
		case sort.StringSlice:
			data = append(sort.StringSlice(nil), v...)
		default:
			t.Errorf("missing case: cannot copy %T", v)
			continue
		}
		fn(data)
		if !sort.IsSorted(data) {
			t.Errorf("%s(%v)", fnName, test)
			t.Errorf(" got %v", data)
			sort.Sort(data)
			t.Errorf("want %v", data)
		}
	}
}
开发者ID:mrekucci,项目名称:epi,代码行数:28,代码来源:algorithm_test.go

示例2: writeGff3

func writeGff3(chromMapDict map[string]*ContigMap, comparisonMethod *string) {

	for chrom, value := range chromMapDict {
		// Open a file-handle for this chromosome
		var (
			chromFh *os.File
			err     error
			f       string = chrom + OutputSuffix
		)
		log.Println("Writing gff3 for", f)

		// Try to create the file
		if chromFh, err = os.Create(f); err != nil {
			log.Fatal(err)
		}
		currentContig := value.firstContig

		chromFh.WriteString("##gff-version3\n")
		// TODO: Find a way to replace the -1. Not easy and not important.
		chromFh.WriteString("##sequence-region  " + currentContig.chromosome + "   1   -1\n")

		for currentContig != nil {
			lineSlice := getGff3Line(currentContig)
			chromFh.WriteString(strings.Join(lineSlice, "\t") + "\n")

			if len(currentContig.dictOfPartners) > 0 {
				// We can place unplaced contigs here!
				// sort the keys of the dictOfPartners by score
				scores := make([]float64, len(currentContig.dictOfPartners))
				i := 0
				for key, _ := range currentContig.dictOfPartners {
					scores[i] = key
					i++
				}
				// With Hamming, the lowest score is the best, so normal sorting is alright - in all other cases, high is better, so we have to invert
				if *comparisonMethod == "hamming" {
					// sort by lowest to highest
					sort.Sort(sort.Float64Slice(scores))
				} else {
					sort.Sort(sort.Reverse(sort.Float64Slice(scores)))
				}

				// Each value for the keys is a slice of contigs - we can't sort these, so keep them the way they showed up
				// In 99.9999% of cases the slice has only one contig
				for _, score := range scores {
					contigs := currentContig.dictOfPartners[score]
					for _, c := range contigs {
						lineSlice := getGff3Line(c)
						chromFh.WriteString(strings.Join(lineSlice, "\t") + "\n")
					}
				}
			}
			currentContig = currentContig.nextContig
		}
	}
}
开发者ID:philippbayer,项目名称:contigPlacer,代码行数:56,代码来源:contigPlacer.go

示例3: main

func main() {
	files, _ := ioutil.ReadDir("../")
	sort.Sort(ByTime(files))
	for i := 0; i < len(files); i++ {
		fmt.Println(files[i].ModTime())
		// 2015-08-10 14:43:35 +0800 CST
		// 2015-08-10 16:03:25 +0800 CST
		// ...
	}

	d := []int{5, 2, 4, 6, 5, 5, 1, 11, 43, 0, -1}
	sort.Sort(sort.IntSlice(d))
	fmt.Println(d) // [-1 0 1 2 4 5 5 5 6 11 43]

	a := []float64{1.2, -1, 0.0, 1.0, 89.2, 0.0001, 1.2345}
	sort.Sort(sort.Float64Slice(a))
	fmt.Println(a) // [-1 0 0.0001 1 1.2 1.2345 89.2]

	s := []string{"PHP", "go", "Go", "java", "python", "c"}
	sort.Sort(sort.StringSlice(s))
	fmt.Println(s) // [Go PHP c go java python]

	fruits := []string{"peach", "banana", "kiwi"}
	sort.Sort(ByLenth(fruits))
	fmt.Println(fruits) // [banana kiwi peach]
}
开发者ID:upccup,项目名称:cuplearn,代码行数:26,代码来源:sort.go

示例4: Zsort

func (self *DB) Zsort(name string) {
	//
	//self.mu.Lock()

	values := make([]float64, len(self.zmp[name]))
	tm := make(map[float64][]NF, len(self.zmp[name]))
	for i := 0; i < len(self.zmp[name]); i += 1 {
		value := self.zmp[name][i].Value
		values[i] = value
		tm[value] = append(tm[value], self.zmp[name][i])
	}
	a := sort.Float64Slice(values[0:])
	sort.Sort(a)

	var temp []NF
	var old float64
	for i := 0; i < len(a); i += 1 {
		if old != a[i] {
			temp = append(temp, tm[a[i]]...)
		}
		old = a[i]
	}
	self.zmp[name] = temp
	//self.mu.Unlock()
}
开发者ID:chybatronik,项目名称:fuzzy_ga,代码行数:25,代码来源:data.go

示例5: TestSVD_vsEig

func TestSVD_vsEig(t *testing.T) {
	m, n := 150, 100
	a := randMat(m, n)
	g := mat.Mul(mat.T(a), a)

	// Take eigen decomposition of Gram matrix.
	_, eigs, err := EigSymm(g)
	if err != nil {
		t.Fatal(err)
	}
	// Sort in descending order.
	sort.Sort(sort.Reverse(sort.Float64Slice(eigs)))
	// Take square root of eigenvalues.
	for i := range eigs {
		// Clip small negative values to zero.
		eigs[i] = math.Sqrt(math.Max(0, eigs[i]))
	}

	// Take singular value decomposition.
	_, svals, _, err := SVD(a)
	if err != nil {
		t.Fatal(err)
	}

	testSliceEq(t, eigs, svals)
}
开发者ID:jvlmdr,项目名称:lin-go,代码行数:26,代码来源:svd_test.go

示例6: compute

func (nv *NearestValueThreshold) compute(data map[string]float64, total int) (float64, error, string) {
	var err error
	var msg string
	testValue := float64(0)

	testFloat, err := strconv.ParseFloat(nv.Value, 64)
	if err != nil {
		msg = fmt.Sprintf("Error converting value to float: %s", err)
		logrus.Error(msg)
		return testValue, err, msg
	}

	fm, _ := numeric.ND_Mapper(data)
	keys := fm.FloatSlice
	m := fm.Float2String
	sort.Sort(sort.Float64Slice(keys))

	for _, k := range keys {
		if testFloat >= k {
			testValue = data[m[k]]
		} else {
			break
		}
	}

	testValue = testValue * 100
	return testValue, err, msg
}
开发者ID:ARodri,项目名称:hume,代码行数:28,代码来源:nearestvalue_threshold.go

示例7: main

func main() {
	intList := []int{2, 4, 3, 5, 7, 6, 9, 8, 1, 0}
	float8List := []float64{4.2, 5.9, 12.3, 10.0, 50.4, 99.9, 31.4, 27.81828, 3.14}
	stringList := []string{"a", "c", "b", "d", "f", "i", "z", "x", "w", "y"}
	fmt.Println("------------正序---------------")
	sort.Ints(intList)
	sort.Float64s(float8List)
	sort.Strings(stringList)
	fmt.Printf("%v\n%v\n%v\n", intList, float8List, stringList)
	fmt.Println("------------倒序---------------")
	sort.Sort(sort.Reverse(sort.IntSlice(intList)))
	sort.Sort(sort.Reverse(sort.Float64Slice(float8List)))
	sort.Sort(sort.Reverse(sort.StringSlice(stringList)))
	fmt.Printf("%v\n%v\n%v\n", intList, float8List, stringList)
	fmt.Println("-------------结构体(特定字段)排序-----------")
	people := []Person{
		{"zhang san", 12},
		{"li si", 30},
		{"wang wu", 52},
		{"zhao liu", 26},
	}
	fmt.Println(people)
	sort.Sort(PersonWrapper{people, func(p, q *Person) bool {
		return q.Age < p.Age //Age 递减排序
	}})
	fmt.Println(people)
	sort.Sort(PersonWrapper{people, func(p, q *Person) bool {
		return p.Name < q.Name //Name 递增排序
	}})
	fmt.Println(people)
}
开发者ID:dongjun111111,项目名称:notes,代码行数:31,代码来源:小工具_对数组与结构体进行排序(正序、倒序).go

示例8: filteredProbabilities

func (bc *BayesianClassifier) filteredProbabilities(tokens []string, categories []string) (map[string][]float64, error) {
	probs, err := bc.probabilities(tokens, categories)
	if err != nil {
		return nil, err
	}

	for cat, pr := range probs {
		if bc.MinProbabilityStrength > 0.0 {
			i := 0
			for i < len(pr) {
				dist := math.Abs(pr[i] - 0.5)
				if dist >= bc.MinProbabilityStrength {
					i++
				} else {
					if i == len(pr)-1 {
						pr = pr[:len(pr)-1]
						break
					}
					pr[i] = pr[len(pr)-1]
					pr = pr[:len(pr)-1]
				}
			}
		}

		if bc.MaxDiscriminators > 0 && len(pr) > bc.MaxDiscriminators {
			sort.Sort(sort.Float64Slice(pr))
			pr = pr[:bc.MaxDiscriminators]
		}

		probs[cat] = pr
	}

	return probs, nil
}
开发者ID:samuel,项目名称:go-classifier,代码行数:34,代码来源:bayes.go

示例9: Finalize

//NEAREST RANK METHOD (USES ONLY MEMBERS OF POPULATION - NO INTERPOLATION)
func (p *Percentile) Finalize() error {
	p.result = make(map[string]float64)

	fm, _ := numeric.ND_Mapper(p.counts)
	keys := fm.FloatSlice
	m := fm.Float2String
	totalFloat := fm.TotalFloat
	sort.Sort(sort.Float64Slice(keys))

	for c := float64(0); c < 100; c++ {
		threshold := totalFloat * c / 100
		sum := float64(0)
		//keep index of key coorsponding to last sum
		var i int
		var k float64
		for i, k = range keys {
			sum += p.counts[m[k]]
			if sum >= threshold {
				break
			}
		}
		p.result[strconv.FormatFloat(c, 'f', -1, 64)] = keys[i]
	}

	return nil
}
开发者ID:ARodri,项目名称:hume,代码行数:27,代码来源:percentile.go

示例10: Export

// Export the set of values in the Ring Buffer, where the latest value
// will be last in the array.  If the Buffer was not full, 0 will be exported.
func (buf *RingBuffer) Export() []float64 {
	buf.mu.Lock()
	defer buf.mu.Unlock()

	length := len(buf.values)
	data := make([]float64, length)

	idx := 0
	for i := buf.oldest; i < len(buf.values); i++ {
		v := buf.values[i]
		if v != nil {
			data[idx] = *v
			idx++
		}
	}

	for i := 0; i < buf.oldest; i++ {
		v := buf.values[i]
		if v != nil {
			data[idx] = *v
			idx++
		}
	}

	sort.Reverse(sort.Float64Slice(data))
	shrink := make([]float64, idx)
	copy(shrink, data)

	return shrink
}
开发者ID:rquelle,项目名称:inspeqtor,代码行数:32,代码来源:ring_buffer.go

示例11: doloop

func doloop() {
	var f0 float64 // Nominal lens focal length
	var fm float64 // Focal length at minimum focus distance
	var md float64 // Minimum focus distance w/out extension
	var err error  // Error return
	var exlist []float64

	flag.Parse()
	if flag.NArg() < 3 {
		println("Sorry, need 3+ args")
		return
	}
	f0, err = strconv.ParseFloat(flag.Arg(0), 64)
	if err != nil {
		println("Sorry - bad focal length")
		return
	}
	md, err = strconv.ParseFloat(flag.Arg(1), 64)
	if err != nil {
		println("Sorry - bad minimum distance")
		return
	}
	exlist = getext()
	sort.Sort(sort.Reverse(sort.Float64Slice(exlist)))
	mdm := 1000 * md
	fm = f0 * (mdm - f0) / mdm
	fmt.Printf("Lens: %5.0f mm, Min focus: %0.3f m, Fmin %0.1f mm\n", f0, md, fm)
	calcext(exlist, f0, fm)
	return
}
开发者ID:longborough,项目名称:Go.Pieces,代码行数:30,代码来源:extube.go

示例12: BinarySuffix

// BinarySuffix returns the given number with a binary suffix.
func BinarySuffix(number float64) string {
	var str string
	if number < 0 {
		str = "-"
		number = math.Abs(number)
	}
	var binarySuffixPrefixes = map[float64]string{
		1125899906842624: "%.2f PB",
		1099511627776:    "%.2f TB",
		1073741824:       "%.2f GB",
		1048576:          "%.2f MB",
		1024:             "%.1f kB",
	}
	intSlice := make([]float64, 0, len(binarySuffixPrefixes))
	for num := range binarySuffixPrefixes {
		intSlice = append(intSlice, num)
	}
	sort.Sort(sort.Reverse(sort.Float64Slice(intSlice)))
	for _, size := range intSlice {
		if size <= number {
			var value float64
			if number >= BinaryConvertThreshold {
				value = number / float64(size)
			}
			return str + fmt.Sprintf(binarySuffixPrefixes[size], value)
		}
	}
	return fmt.Sprintf("%s%.0f bytes", str, number)
}
开发者ID:sbani,项目名称:go-humanizer,代码行数:30,代码来源:binary_suffix.go

示例13: NewSlice

func NewSlice(n []float64) *Slice {
	s := &Slice{Float64Slice: sort.Float64Slice(n), idx: make([]int, len(n))}
	for i := range s.idx {
		s.idx[i] = i
	}
	return s
}
开发者ID:whitezhang,项目名称:TDT-Web,代码行数:7,代码来源:main.go

示例14: Percentiles

func (h *Histogram) Percentiles(percentiles ...float64) []int {
	result := make([]int, len(percentiles))
	if percentiles == nil || len(percentiles) == 0 {
		return result
	}

	sort.Sort(sort.Float64Slice(percentiles))

	accum := 0
	p_idx := int(math.Max(1.0, percentiles[0]*float64(h.n)))
	for i, j := 0, 0; i < len(percentiles) && j < len(h.values); j++ {
		accum += h.values[j]

		for accum >= p_idx {
			result[i] = j
			i++
			if i >= len(percentiles) {
				break
			}
			p_idx = int(math.Max(1.0, percentiles[i]*float64(h.n)))
		}
	}

	return result
}
开发者ID:benbooth493,项目名称:bender,代码行数:25,代码来源:hist.go

示例15: Float64StableSum

// Float64StableSum returns the sum of the elements of the given []float64
// in a relatively stable manner.
func Float64StableSum(s []float64) float64 {
	sort.Sort(sort.Float64Slice(s))
	sum := 0.0
	for _, elem := range s {
		sum += elem
	}
	return sum
}
开发者ID:1394,项目名称:skia-buildbot,代码行数:10,代码来源:util.go


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