Ejemplo n.º 1
0
func Test_conv05(tst *testing.T) {

	//verbose()
	chk.PrintTitle("conv05")

	var t TripletC
	t.Init(4, 3, 4*3+2, false)
	t.Put(0, 0, 1.0, 1.0)
	t.Put(0, 1, 2.0, 1.0)
	t.Put(0, 2, 3.0, 2.0)
	t.Put(1, 0, 4.0, 2.0)
	t.Put(1, 1, 5.0, 2.0)
	t.Put(1, 2, 6.0, 1.0)
	t.Put(2, 0, 7.0, 3.0)
	t.Put(2, 1, 8.0, 3.0)
	t.Put(2, 2, 9.0, 4.0)
	t.Put(3, 0, 4.0, 1.1)
	t.Put(3, 1, 11.0, 4.0)
	t.Put(3, 2, 12.0, 3.0)
	t.Put(3, 0, 3.0, 1.4) // repeated
	t.Put(3, 0, 3.0, 1.5) // repeated
	a := t.ToMatrix(nil)
	ad := a.ToDense()
	if chk.Verbose {
		PrintMatC("a", ad, "(%2g", " +%4gi)  ", false)
	}
	chk.MatrixC(tst, "a", 1.0e-17, ad, [][]complex128{
		{1 + 1i, 2 + 1i, 3 + 2i},
		{4 + 2i, 5 + 2i, 6 + 1i},
		{7 + 3i, 8 + 3i, 9 + 4i},
		{10 + 4i, 11 + 4i, 12 + 3i},
	})
}
Ejemplo n.º 2
0
func Test_conv04(tst *testing.T) {

	//verbose()
	chk.PrintTitle("conv04")

	var t TripletC
	t.Init(3, 3, 10, false)
	t.Put(0, 0, 5.0, 0)
	t.Put(0, 0, 5.0, 0)
	t.Put(0, 1, 11.0, 0)
	t.Put(0, 2, 12.0, 0)
	t.Put(1, 0, 20.0, 0)
	t.Put(1, 1, 21.0, 0)
	t.Put(1, 2, 22.0, 0)
	t.Put(2, 0, 30.0, 0)
	t.Put(2, 1, 31.0, 0)
	t.Put(2, 2, 32.0, 666.0)
	a := t.ToMatrix(nil)
	ad := a.ToDense()
	if chk.Verbose {
		PrintMatC("a", ad, "(%2g", " +%4gi)  ", false)
	}
	chk.MatrixC(tst, "a", 1.0e-17, ad, [][]complex128{
		{10, 11, 12},
		{20, 21, 22},
		{30, 31, 32 + 666i},
	})
}
Ejemplo n.º 3
0
func TestSparseLA08(tst *testing.T) {

	chk.PrintTitle("TestSparse LA08")

	var ta Triplet
	ta.Init(5, 6, 9)
	ta.Put(0, 0, 1)
	ta.Put(2, 0, 2)
	ta.Put(4, 0, 3)
	ta.Put(1, 2, 3)
	ta.Put(3, 2, 1)
	ta.Put(0, 3, 1)
	ta.Put(4, 3, 5)
	ta.Put(0, 5, 7)
	ta.Put(2, 5, 8)
	io.Pf("ta = %+v\n", ta)

	var tb Triplet
	tb.Init(5, 6, 12)
	tb.Put(1, 1, 1)
	tb.Put(3, 1, 8)
	tb.Put(0, 2, 1)
	tb.Put(1, 2, 2)
	tb.Put(2, 2, 3)
	tb.Put(3, 2, 4)
	tb.Put(4, 2, 5)
	tb.Put(2, 4, 5)
	tb.Put(0, 5, 1)
	tb.Put(1, 5, 4)
	tb.Put(2, 5, 2)
	tb.Put(4, 5, 1)
	io.Pf("tb = %+v\n", tb)

	var td TripletC
	td.Init(5, 6, ta.Len()+tb.Len(), false)
	α, β, μ := 0.1, 1.0, 2.0
	// d := (α+βi)*a + μ*b
	SpTriAddR2C(&td, α, β, &ta, μ, &tb)
	io.Pf("td = %+v\n", td)
	chk.MatrixC(tst, "d", 1e-16, td.ToMatrix(nil).ToDense(), [][]complex128{
		{0.1 + 1i, 0, 2.0, 0.1 + 1i, 0, 2.7 + 7i},
		{0, 2, 4.3 + 3i, 0, 0, 8.0},
		{0.2 + 2i, 0, 6.0, 0, 10, 4.8 + 8i},
		{0, 16, 8.1 + 1i, 0, 0, 0.0},
		{0.3 + 3i, 0, 10.0, 0.5 + 5i, 0, 2.0},
	})
}
Ejemplo n.º 4
0
func TestSparseLA06(tst *testing.T) {

	//verbose()
	chk.PrintTitle("TestSparse LA06")

	var ta Triplet
	ta.Init(5, 6, 9)
	ta.Put(0, 0, 1)
	ta.Put(2, 0, 2)
	ta.Put(4, 0, 3)
	ta.Put(1, 2, 3)
	ta.Put(3, 2, 1)
	ta.Put(0, 3, 1)
	ta.Put(4, 3, 5)
	ta.Put(0, 5, 7)
	ta.Put(2, 5, 8)
	a := ta.ToMatrix(nil)
	io.Pf("a = %+v\n", a)
	PrintMat("a", a.ToDense(), "%2g ", false)
	chk.Vector(tst, "a.x", 1e-17, a.x, []float64{1, 2, 3, 3, 1, 1, 5, 7, 8})
	chk.Ints(tst, "a.i", a.i, []int{0, 2, 4, 1, 3, 0, 4, 0, 2})
	chk.Ints(tst, "a.p", a.p, []int{0, 3, 3, 5, 7, 7, 9})

	var tb Triplet
	tb.Init(5, 6, 12)
	tb.Put(1, 1, 1)
	tb.Put(3, 1, 8)
	tb.Put(0, 2, 1)
	tb.Put(1, 2, 2)
	tb.Put(2, 2, 3)
	tb.Put(3, 2, 4)
	tb.Put(4, 2, 5)
	tb.Put(2, 4, 5)
	tb.Put(0, 5, 1)
	tb.Put(1, 5, 4)
	tb.Put(2, 5, 2)
	tb.Put(4, 5, 1)
	b := tb.ToMatrix(nil)
	io.Pf("b = %+v\n", b)
	PrintMat("b", b.ToDense(), "%2g ", false)
	chk.Vector(tst, "b.x", 1e-17, b.x, []float64{1, 8, 1, 2, 3, 4, 5, 5, 1, 4, 2, 1})
	chk.Ints(tst, "b.i", b.i, []int{1, 3, 0, 1, 2, 3, 4, 2, 0, 1, 2, 4})
	chk.Ints(tst, "b.p", b.p, []int{0, 0, 2, 7, 7, 8, 12})

	c, a2c, b2c := SpAllocMatAddMat(a, b)
	var d CCMatrixC
	SpInitSimilarR2C(&d, c)
	chk.Ints(tst, "c.i", c.i, []int{0, 2, 4, 1, 3, 0, 1, 2, 3, 4, 0, 4, 2, 0, 1, 2, 4})
	chk.Ints(tst, "c.p", c.p, []int{0, 3, 5, 10, 12, 13, 17})
	chk.Ints(tst, "d.i", d.i, []int{0, 2, 4, 1, 3, 0, 1, 2, 3, 4, 0, 4, 2, 0, 1, 2, 4})
	chk.Ints(tst, "d.p", d.p, []int{0, 3, 5, 10, 12, 13, 17})
	α, β, γ, μ := 0.1, 1.0, 0.1, 2.0
	//    c :=      γ*a + μ*b
	//    d := (α+βi)*a + μ*b
	SpMatAddMatC(&d, c, α, β, γ, a, μ, b, a2c, b2c)
	io.Pf("c = %+v\n", c)
	io.Pf("d = %+v\n", d)
	PrintMat("c", c.ToDense(), "%5.2f ", false)
	PrintMatC("d", d.ToDense(), "(%5.2f", "%5.2f) ", false)
	chk.Vector(tst, "c.x", 1e-16, c.x, []float64{0.1, 0.2, 0.3, 2, 16, 2, 4.3, 6, 8.1, 10, 0.1, 0.5, 10, 2.7, 8, 4.8, 2})
	chk.Vector(tst, "d.x", 1e-16, d.x, []float64{0.1, 0.2, 0.3, 2, 16, 2, 4.3, 6, 8.1, 10, 0.1, 0.5, 10, 2.7, 8, 4.8, 2})
	chk.Vector(tst, "d.z", 1e-17, d.z, []float64{1, 2, 3, 0, 0, 0, 3, 0, 1, 0, 1, 5, 0, 7, 0, 8, 0})
	chk.Ints(tst, "a2c", a2c, []int{0, 1, 2, 6, 8, 10, 11, 13, 15})
	chk.Ints(tst, "b2c", b2c, []int{3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, 16})
	chk.Matrix(tst, "c", 1e-16, c.ToDense(), [][]float64{
		{0.1, 0, 2.0, 0.1, 0, 2.7},
		{0, 2, 4.3, 0, 0, 8.0},
		{0.2, 0, 6.0, 0, 10, 4.8},
		{0, 16, 8.1, 0, 0, 0.0},
		{0.3, 0, 10.0, 0.5, 0, 2.0},
	})
	chk.MatrixC(tst, "d", 1e-16, d.ToDense(), [][]complex128{
		{0.1 + 1i, 0, 2.0, 0.1 + 1i, 0, 2.7 + 7i},
		{0, 2, 4.3 + 3i, 0, 0, 8.0},
		{0.2 + 2i, 0, 6.0, 0, 10, 4.8 + 8i},
		{0, 16, 8.1 + 1i, 0, 0, 0.0},
		{0.3 + 3i, 0, 10.0, 0.5 + 5i, 0, 2.0},
	})
}