Example #1
0
func (d *AngleDegrees) ToAngleBytes() AngleBytes {
	norm := math.Fmod(float64(*d), 360)
	if norm < 0 {
		norm = 360 + norm
	}
	return AngleBytes(norm * 256.0 / 360.0)
}
func main() {
	flag.Parse()
	m := int64(*nrows)

	//Setup  profiling
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	if *memprofile != "" {
		f, err := os.Create(*memprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.WriteHeapProfile(f)
		f.Close()
		return
	}

	prev := make([]*big.Int, 1)
	one := big.NewInt(int64(1))
	prev[0] = one
	x := big.NewInt(int64(0))

	for row := int64(1); row < m; row++ {
		curr := make([]*big.Int, 1, row+1)
		curr[0] = one

		mid := int64(row/2) + 1
		var right int64
		if math.Fmod(float64(row), 2.0) == 0 {
			right = mid - 1
		} else {
			right = mid
		}

		for j := int64(1); j < mid; j++ {
			x = x.Add(prev[j-1], prev[j])
			curr = append(curr, x)
			x = big.NewInt(int64(0))
		}

		// Take a slice of the first half of the row, reverse it, and
		// append to the current row.
		s := make([]*big.Int, right)
		r := curr[0:right]
		copy(s, r)
		rev := reverse(s)
		curr = append(curr, rev...)
		//fmt.Println(curr)

		prev = curr[:]
	}
}
// TODO Depth first search for second element
// Once calculated launch calc of rest of row in a goroutine
// Store result in a map[rownum][]int
// Use big integer to prevent overflow if maxrows > what?
// Make maxrows a command line arg
func main() {
	flag.Parse()
	//Setup  profiling
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	if *memprofile != "" {
		f, err := os.Create(*memprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.WriteHeapProfile(f)
		f.Close()
		return
	}

	m := 10000 //max iterations
	prev := []int{1}
	//fmt.Println(prev)

	for row := 1; row < m; row++ {
		curr := make([]int, 1, row)
		curr[0] = 1

		mid := (row / 2)
		var right int
		if math.Fmod(float64(row), 2.0) == 0 {
			right = mid
		} else {
			right = mid + 1
		}

		for j := 1; j < mid; j++ {
			curr = append(curr, prev[j-1]+prev[j])
		}

		s := make([]int, right)
		r := curr[0:right]
		copy(s, r)
		rev := reverse(s)
		curr = append(curr, rev...)
		//		fmt.Println(curr)
		prev = curr
	}
}
Example #4
0
func (v *Subtitle) ShortStartTime() string {

	seconds := v.StartTimeInSecondsFixed()

	sign := ""
	if seconds < 0 {
		sign = "-"
	}

	m := int(math.Fabs(seconds) / 60)
	s := int(math.Fmod(math.Fabs(seconds), 60))

	return sign + fmt.Sprintf("%02d:%02d", m, s)
}
Example #5
0
func (ed EdgeDetector) Potential(img image.Image) (p float64) {

	// put a "sparse prior" on random steps
	// steps should usually be mostly in one direction
	// compare to coordinate descent and no prior

	// does it make sense to have extra benefit for getting a cross at two intersecting lines?
	// this could get fooled on the numbers
	// probably not...

	// activation for each line and pixel
	var delta, dist float64
	add := 0.0
	b := img.Bounds()
	for x := b.Min.X; x < b.Max.X; x++ {
		for y := b.Min.Y; y < b.Max.Y; y++ {
			for _, line := range ed.lines {
				// TODO may need to play with this formula
				dist = line.SquaredDistance(float64(x), float64(y))
				delta = DarknessAt(img, x, y) * math.Exp(-dist/line.radius)
				p += delta
				add += delta
				if math.IsInf(add, 1) {
					fmt.Printf("[Potential] hit inf!\n")
					os.Exit(1)
				}
			}
		}
	}
	p /= float64(len(ed.lines))
	add /= float64(len(ed.lines))

	// orientation of the lines
	remove := 0.0
	num_pairs := 0 // man up: N * (N-1) / 2
	N := len(ed.lines)
	for i := 1; i < N; i++ {
		for j := 0; j < i; j++ {
			num_pairs += 1
			dist = ed.lines[i].Angle(ed.lines[j])
			delta = math.Exp(-math.Fmod(dist, 90.0)) * ed.orientation_sensitivity
			/*p -= delta;*/ remove += delta
		}
	}
	remove /= float64(num_pairs)
	p -= remove

	fmt.Printf("[EdgeDetector.Potential] potential = %.2f\t(+%.2f, -%.2f)\n", p, add, remove)
	return p
}
Example #6
0
func (a Float) Mod(b Float) Float {
	return Float(math.Fmod(a.Float64(), b.Float64()))
}
func main() {
	if len(os.Args) < 2 {
		log.Fatalf("usage: %s iterations\n", os.Args[0])
	}

	flag.Parse()
	//Setup  profiling
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	if *memprofile != "" {
		f, err := os.Create(*memprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.WriteHeapProfile(f)
		f.Close()
		return
	}

	m, err := strconv.Atoi(os.Args[1]) //max iterations
	if err != nil {
		log.Fatalf("Could not convert %s to int.\n", os.Args[1])
	}
	one := int64(1)
	prev := []int64{one}
	//fmt.Println(prev)

	for row := 1; row < m; row++ {
		curr := make([]int64, 1, row)
		curr[0] = one

		mid := (row / 2)
		var right int
		if math.Fmod(float64(row), 2.0) == 0 {
			right = mid
		} else {
			right = mid + 1
		}

		for j := 1; j < mid; j++ {
			x := int64(prev[j-1] + prev[j])
			//			if int64(x) > maxint64 {
			if int64(x) < 0 {
				//				log.Fatalf("row %d point %d exceed maxint64:%e  value:%d\n",row, j, maxint64, prev[j])
				log.Fatalf("row %d point %d value:%e\n", row, j, x)
			}

			curr = append(curr, x)
		}

		s := make([]int64, right)
		r := curr[0:right]
		copy(s, r)
		rev := reverse(s)
		curr = append(curr, rev...)
		//		fmt.Println(curr)
		prev = curr
	}
	fmt.Printf("row: %d row_len: %d\n", prev, len(prev))
	//prev[:len(prev)/2])
}