コード例 #1
0
ファイル: euler-p18.go プロジェクト: drio/euler
func load(fn string) *triangle {
	t := new(triangle)
	fd, buff := files.Xopen(fn)
	for line := range files.IterLines(buff) {
		numbers := []int{}
		for _, n := range strings.Split(line, " ") {
			if i, err := strconv.Atoi(n); err == nil {
				numbers = append(numbers, i)
			} else {
				log.Fatal("Problems parsing line.", err)
			}
		}
		t.data = append(t.data, numbers)
	}
	fd.Close()
	return t
}
コード例 #2
0
ファイル: euler-p22.go プロジェクト: drio/euler
func loadData(fn string) []byte {
	f, r := files.Xopen(fn)
	defer f.Close()

	var lineData []byte
	buff := make([]byte, 100000)
	var err error
	n := 1
	for n != 0 {
		if n, err = r.Read(buff); err == nil {
			lineData = append(lineData, buff...)
		} else {
			if err == io.EOF {
				break
			} else {
				log.Fatal("Problems reading file", err)
			}
		}
	}
	return lineData
}
コード例 #3
0
ファイル: urlness.go プロジェクト: drio/drio.go
func main() {
	o := parseArgs()

	// If the user wants us to generate a random kindship file, let's do it
	// and we are done
	if *o.nRandSamples > 0 {
		fmt.Print(urlness.GenRandomKindShip(*o.nRandSamples))
		return
	}

	inputData := new(urlness.Options)

	// link between file paths and their locations in the datastructure
	// that we will pass to the urlness package (inputData)
	fNamesToFiles := map[*string]*io.Reader{
		o.ksFname:    &inputData.KS,
		o.sexFname:   &inputData.Sex,
		o.pheFname:   &inputData.Phe,
		o.forceFname: &inputData.Force,
	}

	// Open the files and set the readers for them in inputData
	for path, reader := range fNamesToFiles {
		if *path != "" {
			file, r := files.Xopen(*path)
			*reader = r
			defer file.Close()
		}
	}

	// We know the Phi param has to be there for sure
	inputData.PhiFilter = *o.phiFilter

	// CPU Profiling
	// http://blog.golang.org/2011/06/profiling-go-programs.html
	if *o.cpuProfile != "" {
		f, err := os.Create(*o.cpuProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	// Run the appropiate routine
	if *o.optimal {
		fmt.Println(urlness.ComputeOptimal(*inputData))
	} else {
		m, l := urlness.Compute(*inputData) // matrix and list of unrelated samples
		fmt.Println(m)
		if *o.phiFilter != 0 {
			fmt.Fprintln(os.Stderr, l)
		}
	}

	// Mem profile
	// https://groups.google.com/forum/#!msg/golang-nuts/Nnp9HhLaJjA/y0yXlIDty0kJ
	if *o.memProfile != "" {
		f, err := os.Create(*o.memProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.WriteHeapProfile(f)
		defer f.Close()
	}

}