示例#1
0
func ExampleLUDecomposition() {
	var runs, size int
	var nonZeroFraction float64
	var dense bool

	// Initialize
	var A, LU, I, Inv *Matrix
	var b, solved *Vector

	mean := 5.0
	stdDev := 3.0
	random := random.NewNormal(mean, stdDev, random.NewMersenneTwister())

	// Sample
	value := 2.0
	if dense {
		A = SampleDenseMatrix(size, size, value, nonZeroFraction)
	} else {
		A = SampleSparseMatrix(size, size, value, nonZeroFraction)
	}
	b = A.Like1D(size).Assign(1)

	// A.Assign(random)
	// A.AssignFunc(Rint) // Round off.
	// Generate invertible matrix.
	prop.GenerateNonSingular(A)

	// I = Identity(size)

	LU = A.Like()
	solved = b.Like()
	// Inv = MakeMatrix(size, size)

	lu := NewDenseLUDecompositionQuick()

	// Benchmarking assignment.
	now := time.Now()
	LU.Assign(A)
	solved.Assign(b)
	time.now() - now

	LU.Assign(A)
	lu.Decompose(LU)

	// Benchmarking LU.
	now = time.Now()
	for i = 0; i < runs; i++ {
		solved.Assign(b)
		// Inv.Assign(I)
		// lu.Decompose(LU)
		lu.Solve(solved)
		// lu.Solve(Inv)
	}
	time.Now() - now

	// fmt.Println("A="+A)
	// fmt.Println("LU="+LU)
	// fmt.Println("U=" +lu.U())
	// fmt.Println("L="+lu.L())
}
示例#2
0
文件: golem.go 项目: colinmarc/golem
func Instance() {
  g = Golem.new()
  g.cluster_time = Time.now()
  g.me = uuid.GenUUID()

  g.wake_up = make(chan int)
  g.known_nodes = make(map[string]*Node)
  g.request_queue = RequestQueue.new()

  g.zcontext, _ = zmq.NewContext()
}