Example #1
0
func TestSparseLA02(tst *testing.T) {

	chk.PrintTitle("TestSparse LA02")

	var t TripletC
	t.Init(3, 5, 15, false)
	t.Put(0, 0, 1, 0)
	t.Put(0, 1, 2, 0)
	t.Put(0, 2, 3, 0)
	t.Put(0, 3, 4, 0)
	t.Put(0, 4, 5, 0)
	t.Put(1, 0, 0.1, 0)
	t.Put(1, 1, 0.2, 0)
	t.Put(1, 2, 0.3, 0)
	t.Put(1, 3, 0.4, 0)
	t.Put(1, 4, 0.5, 0)
	t.Put(2, 0, 10, 0)
	t.Put(2, 1, 20, 0)
	t.Put(2, 2, 30, 0)
	t.Put(2, 3, 40, 0)
	t.Put(2, 4, 50, 0)

	a := t.ToMatrix(nil)
	ad := a.ToDense()
	u := []complex128{0.1, 0.2, 0.3, 0.4, 0.5}
	w := []complex128{10.0, 20.0, 30.0}
	r := []complex128{1000, 1000, 1000, 1000, 1000}
	s := []complex128{1000, 1000, 1000}

	PrintMatC("a", ad, "(%4g", " +%4gi)  ", false)
	PrintVecC("u", u, "(%4g", " +%4gi)  ", false)
	PrintVecC("w", w, "(%4g", " +%4gi)  ", false)
	PrintVecC("r", r, "(%4g", " +%4gi)  ", false)
	PrintVecC("s", s, "(%4g", " +%4gi)  ", false)

	io.Pf("\nfunc SpMatVecMul(v []float64, α float64, a [][]float64, u []float64)\n")
	p := make([]complex128, 3)
	SpMatVecMulC(p, 1, a, u) // p := 1*a*u
	PrintVecC("p = a*u", p, "(%2g", " +%4gi)  ", false)
	chk.VectorC(tst, "p = a*u", 1e-17, p, []complex128{5.5, 0.55, 55})

	io.Pf("\nfunc SpMatVecMulAdd(v []float64, α float64, a [][]float64, u []float64)\n")
	SpMatVecMulAddC(s, 1, a, u) // s += dot(a, u)
	PrintVecC("s += a*u", s, "(%2g", " +%4gi)  ", false)
	chk.VectorC(tst, "s += a*u", 1e-17, s, []complex128{1005.5, 1000.55, 1055})

	io.Pf("\nfunc SpMatTrVecMul(v []float64, α float64, a [][]float64, u []float64)\n")
	q := make([]complex128, 5)
	SpMatTrVecMulC(q, 1, a, w) // q = dot(transpose(a), w)
	PrintVecC("q = trans(a)*w", q, "(%2g", " +%4gi)  ", false)
	chk.VectorC(tst, "q = trans(a)*w", 1e-17, q, []complex128{312, 624, 936, 1248, 1560})

	io.Pf("\nfunc SpMatTrVecMulAdd(v []float64, α float64, a [][]float64, u []float64)\n")
	SpMatTrVecMulAddC(r, 1, a, w) // r += dot(transpose(a), w)
	PrintVecC("r += trans(a)*w", r, "(%2g", " +%4gi)  ", false)
	chk.VectorC(tst, "r += trans(a)*w", 1e-17, r, []complex128{1312, 1624, 1936, 2248, 2560})
}
Example #2
0
func TestSparseLA03(tst *testing.T) {

	chk.PrintTitle("TestSparse LA03")

	var t TripletC
	t.Init(3, 5, 15, false)
	t.Put(0, 0, 1, 0)
	t.Put(0, 1, 2, -1)
	t.Put(0, 2, 3, 0)
	t.Put(0, 3, 4, 3)
	t.Put(0, 4, 5, 2)
	t.Put(1, 0, 0.1, 1)
	t.Put(1, 1, 0.2, 0)
	t.Put(1, 2, 0.3, -2)
	t.Put(1, 3, 0.4, 0)
	t.Put(1, 4, 0.5, -1)
	t.Put(2, 0, 10, 0)
	t.Put(2, 1, 20, 2)
	t.Put(2, 2, 30, 0)
	t.Put(2, 3, 40, -1)
	t.Put(2, 4, 50, 0)

	a := t.ToMatrix(nil)
	ad := a.ToDense()
	u := []complex128{0.1, 0.2 + 10i, 0.3, 0.4 + 3i, 0.5}
	w := []complex128{10.0 + 1i, 20.0 - 0.5i, 30.0}
	r := []complex128{1000 + 1i, 1000 + 1i, 1000 + 1i, 1000 + 1i, 1000 + 1i}
	s := []complex128{1000 - 1i, 1000 - 1i, 1000 - 1i}

	PrintMatC("a", ad, "(%4g", " +%4gi)  ", false)
	PrintVecC("u", u, "(%4g", " +%4gi)  ", false)
	PrintVecC("w", w, "(%4g", " +%4gi)  ", false)
	PrintVecC("r", r, "(%4g", " +%4gi)  ", false)
	PrintVecC("s", s, "(%4g", " +%4gi)  ", false)

	io.Pf("\nfunc SpMatVecMul(v []float64, α float64, a [][]float64, u []float64)\n")
	p := make([]complex128, 3)
	SpMatVecMulC(p, 1, a, u) // p := 1*a*u
	PrintVecC("p = a*u", p, "(%2g", " +%4gi)  ", false)
	chk.VectorC(tst, "p = a*u", 1e-17, p, []complex128{6.5 + 34i, 0.55 + 2.2i, 38 + 320i})

	io.Pf("\nfunc SpMatVecMulAdd(v []float64, α float64, a [][]float64, u []float64)\n")
	SpMatVecMulAddC(s, 1, a, u) // s += dot(a, u)
	PrintVecC("s += a*u", s, "(%2g", " +%4gi)  ", false)
	chk.VectorC(tst, "s += a*u", 1e-15, s, []complex128{1006.5 + 33i, 1000.55 + 1.2i, 1038 + 319i})

	io.Pf("\nfunc SpMatTrVecMul(v []float64, α float64, a [][]float64, u []float64)\n")
	q := make([]complex128, 5)
	SpMatTrVecMulC(q, 1, a, w) // q = dot(transpose(a), w)
	PrintVecC("q = trans(a)*w", q, "(%2g", " +%4gi)  ", false)
	chk.VectorC(tst, "q = trans(a)*w", 1e-14, q, []complex128{312.5 + 20.95i, 625 + 51.9i, 935 - 37.15i, 1245 + 3.8i, 1557.5 + 4.75i})

	io.Pf("\nfunc SpMatTrVecMulAdd(v []float64, α float64, a [][]float64, u []float64)\n")
	SpMatTrVecMulAddC(r, 1, a, w) // r += dot(transpose(a), w)
	PrintVecC("r += trans(a)*w", r, "(%2g", " +%4gi)  ", false)
	chk.VectorC(tst, "r += trans(a)*w", 1e-14, r, []complex128{1312.5 + 21.95i, 1625 + 52.9i, 1935 - 36.15i, 2245 + 4.8i, 2557.5 + 5.75i})
}
Example #3
0
func Test_conv07(tst *testing.T) {

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

	r := []float64{1, 2, 3, 4, 5, 6}
	c := []float64{0.1, 0.2, 0.3, 0.4, 0.5, 0.6}
	rc := RCtoComplex(r, c)
	chk.VectorC(tst, "rc", 1e-17, rc, []complex128{1 + 0.1i, 2 + 0.2i, 3 + 0.3i, 4 + 0.4i, 5 + 0.5i, 6 + 0.6i})

	R, C := ComplexToRC(rc)
	chk.Vector(tst, "r", 1e-17, R, r)
	chk.Vector(tst, "c", 1e-17, C, c)
}
Example #4
0
func run_linsol_testC(tst *testing.T, t *TripletC, tol_cmp, tol_res float64, b, x_correct []complex128, verbose bool) {

	// info
	symmetric := false
	timing := false

	// allocate solver
	lis := GetSolver("umfpack")
	defer lis.Clean()

	// initialise solver
	err := lis.InitC(t, symmetric, verbose, timing)
	if err != nil {
		chk.Panic("%v", err.Error())
	}

	// factorise
	err = lis.Fact()
	if err != nil {
		chk.Panic("%v", err.Error())
	}

	// solve
	var dummy bool
	bR, bC := ComplexToRC(b)
	xR := make([]float64, len(b))
	xC := make([]float64, len(b))
	err = lis.SolveC(xR, xC, bR, bC, dummy) // x := inv(A) * b
	if err != nil {
		chk.Panic("%v", err.Error())
	}
	x := RCtoComplex(xR, xC)

	// output
	A := t.ToMatrix(nil)
	if verbose {
		io.Pforan("A.x = b\n")
		PrintMatC("A", A.ToDense(), "(%g", "%+gi) ", false)
		PrintVecC("x", x, "(%g", "%+gi) ", false)
		PrintVecC("b", b, "(%g", "%+gi) ", false)
	}

	// check
	chk.VectorC(tst, "x", tol_cmp, x, x_correct)
	CheckResidC(tst, tol_res, A.ToDense(), x, b)
}
Example #5
0
func TestVector01(tst *testing.T) {

	//verbose()
	chk.PrintTitle("TestVector 01")

	io.Pfyel("func VecFill(v []float64, s float64)\n")
	v := make([]float64, 5)
	VecFill(v, 666)
	PrintVec("v", v, "%5g", false)
	chk.Vector(tst, "v", 1e-17, v, []float64{666, 666, 666, 666, 666})

	io.Pfyel("\nfunc VecFillC(v []complex128, s complex128)\n")
	vc := make([]complex128, 5)
	VecFillC(vc, 666+666i)
	PrintVecC("vc", vc, "(%2g +", "%4gi) ", false)
	chk.VectorC(tst, "vc", 1e-17, vc, []complex128{666 + 666i, 666 + 666i, 666 + 666i, 666 + 666i, 666 + 666i})

	io.Pfyel("func VecClone(a []float64) (b []float64)\n")
	va := []float64{1, 2, 3, 4, 5, 6}
	vb := VecClone(va)
	PrintVec("vb", vb, "%5g", false)
	chk.Vector(tst, "vb==va", 1e-17, vb, va)

	io.Pfyel("\nfunc VecAccum(v []float64) (sum float64)\n")
	PrintVec("v", v, "%5g", false)
	sum := VecAccum(v)
	io.Pf("sum(v) = %23.15e\n", sum)
	chk.Scalar(tst, "sum(v)", 1e-17, sum, 5*666)

	io.Pfyel("\nfunc VecNorm(v []float64) (nrm float64)\n")
	PrintVec("v", v, "%5g", false)
	nrm := VecNorm(v)
	io.Pf("norm(v) = %23.15e\n", nrm)
	chk.Scalar(tst, "norm(v)", 1e-17, nrm, 1.489221273014860e+03)

	io.Pfyel("\nfunc VecNormDiff(u, v []float64) (nrm float64)\n")
	u := []float64{333, 333, 333, 333, 333}
	PrintVec("u", u, "%5g", false)
	PrintVec("v", v, "%5g", false)
	nrm = VecNormDiff(u, v)
	io.Pf("norm(u-v) = %23.15e\n", nrm)
	chk.Scalar(tst, "norm(u-v)", 1e-17, nrm, math.Sqrt(5.0*333.0*333.0))

	io.Pfyel("\nfunc VecDot(u, v []float64) (res float64)\n")
	u = []float64{0.1, 0.2, 0.3, 0.4, 0.5}
	PrintVec("u", u, "%5g", false)
	PrintVec("v", v, "%5g", false)
	udotv := VecDot(u, v)
	io.Pf("u dot v = %v\n", udotv)
	chk.Scalar(tst, "u dot v", 1e-12, udotv, 999)

	io.Pfyel("\nfunc VecCopy(a []float64, alp float64, b []float64)\n")
	a := make([]float64, len(u))
	VecCopy(a, 1, u)
	PrintVec("u     ", u, "%5g", false)
	PrintVec("a := u", a, "%5g", false)
	chk.Vector(tst, "a", 1e-17, a, []float64{0.1, 0.2, 0.3, 0.4, 0.5})

	io.Pfyel("\nfunc VecAdd(a []float64, alp float64, b []float64)\n")
	b := []float64{1.0, 2.0, 3.0, 4.0, 5.0}
	PrintVec("b        ", b, "%5g", false)
	VecAdd(b, 10, b) // b += 10.0*b
	PrintVec("b += 10*b", b, "%5g", false)
	chk.Vector(tst, "b", 1e-17, b, []float64{11, 22, 33, 44, 55})

	io.Pfyel("\nfunc VecAdd2(u []float64, alp float64, a []float64, bet float64, b []float64)\n")
	PrintVec("a", a, "%7g", false)
	PrintVec("b", b, "%7g", false)
	c := make([]float64, len(a))
	VecAdd2(c, 1, a, 10, b) // c = 1.0*a + 10.0*b
	PrintVec("c = 1*a+10*b", c, "%7g", false)
	chk.Vector(tst, "c", 1e-17, c, []float64{110.1, 220.2, 330.3, 440.4, 550.5})

	io.Pfyel("\nfunc VecMin(v []float64) (min float64)\n")
	PrintVec("a", a, "%5g", false)
	mina := VecMin(a)
	io.Pf("min(a) = %v\n", mina)
	chk.Scalar(tst, "min(a)", 1e-17, mina, 0.1)

	io.Pfyel("\nfunc VecMax(v []float64) (max float64)\n")
	PrintVec("a", a, "%5g", false)
	maxa := VecMax(a)
	io.Pf("max(a) = %v\n", maxa)
	chk.Scalar(tst, "max(a)", 1e-17, maxa, 0.5)

	io.Pfyel("\nfunc VecMinMax(v []float64) (min, max float64)\n")
	PrintVec("a", a, "%5g", false)
	min2a, max2a := VecMinMax(a)
	io.Pf("min(a) = %v\n", min2a)
	io.Pf("max(a) = %v\n", max2a)
	chk.Scalar(tst, "min(a)", 1e-17, min2a, 0.1)
	chk.Scalar(tst, "max(a)", 1e-17, max2a, 0.5)

	io.Pfyel("\nfunc VecLargest(u []float64, den float64) (largest float64)\n")
	PrintVec("b     ", b, "%5g", false)
	bdiv11 := []float64{b[0] / 11.0, b[1] / 11.0, b[2] / 11.0, b[3] / 11.0, b[4] / 11.0}
	PrintVec("b / 11", bdiv11, "%5g", false)
	maxbdiv11 := VecLargest(b, 11)
	io.Pf("max(b/11) = %v\n", maxbdiv11)
	chk.Scalar(tst, "max(b/11)", 1e-17, maxbdiv11, 5)

	io.Pfyel("\nfunc VecMaxDiff(a, b []float64) (maxdiff float64)\n")
	amb1 := []float64{a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3], a[4] - b[4]}
	amb2 := make([]float64, len(a))
	VecAdd2(amb2, 1, a, -1, b)
	PrintVec("a  ", a, "%7g", false)
	PrintVec("b  ", b, "%7g", false)
	PrintVec("a-b", amb1, "%7g", false)
	PrintVec("a-b", amb2, "%7g", false)
	maxdiffab := VecMaxDiff(a, b)
	io.Pf("maxdiff(a,b) = max(abs(a-b)) = %v\n", maxdiffab)
	chk.Vector(tst, "amb1 == amb2", 1e-17, amb1, amb2)
	chk.Scalar(tst, "maxdiff(a,b)", 1e-17, maxdiffab, 54.5)

	io.Pfyel("\nfunc VecMaxDiffC(a, b []complex128) (maxdiff float64)\n")
	az := []complex128{complex(a[0], 1), complex(a[1], 3), complex(a[2], 0.5), complex(a[3], 1), complex(a[4], 0)}
	bz := []complex128{complex(b[0], 1), complex(b[1], 6), complex(b[2], 0.8), complex(b[3], -3), complex(b[4], 1)}
	ambz := []complex128{az[0] - bz[0], az[1] - bz[1], az[2] - bz[2], az[3] - bz[3], az[4] - bz[4]}
	PrintVecC("az   ", az, "(%5g +", "%4gi) ", false)
	PrintVecC("bz   ", bz, "(%5g +", "%4gi) ", false)
	PrintVecC("az-bz", ambz, "(%5g +", "%4gi) ", false)
	maxdiffabz := VecMaxDiffC(az, bz)
	io.Pf("maxdiff(az,bz) = %v\n", maxdiffabz)
	chk.Scalar(tst, "maxdiff(az,bz)", 1e-17, maxdiffabz, 54.5)

	io.Pfyel("\nfunc VecScale(res []float64, Atol, Rtol float64, v []float64)\n")
	scal1 := make([]float64, len(a))
	VecScale(scal1, 0.5, 0.1, amb1)
	PrintVec("a-b            ", amb1, "%7g", false)
	PrintVec("0.5 + 0.1*(a-b)", scal1, "%7g", false)
	chk.Vector(tst, "0.5 + 0.1*(a-b)", 1e-15, scal1, []float64{-0.59, -1.68, -2.77, -3.86, -4.95})

	io.Pfyel("\nfunc VecScaleAbs(res []float64, Atol, Rtol float64, v []float64)\n")
	scal2 := make([]float64, len(a))
	VecScaleAbs(scal2, 0.5, 0.1, amb1)
	PrintVec("a-b            ", amb1, "%7g", false)
	PrintVec("0.5 + 0.1*|a-b|", scal2, "%7g", false)
	chk.Vector(tst, "0.5 + 0.1*|a-b|", 1e-15, scal2, []float64{1.59, 2.68, 3.77, 4.86, 5.95})

	io.Pfyel("\nfunc VecRms(u []float64) (rms float64)\n")
	PrintVec("v", v, "%5g", false)
	rms := VecRms(v)
	io.Pf("rms(v) = %23.15e\n", rms)
	chk.Scalar(tst, "rms(v)", 1e-17, rms, 666.0)

	io.Pfyel("func VecRmsErr(u []float64, Atol, Rtol float64, v []float64) (rms float64)\n")
	PrintVec("v", v, "%5g", false)
	rmserr := VecRmsErr(v, 0, 1, v)
	io.Pf("rmserr(v,v) = %23.15e\n", rmserr)
	chk.Scalar(tst, "rmserr(v,v,0,1)", 1e-17, rmserr, 1)

	io.Pfyel("func VecRmsError(u, w []float64, Atol, Rtol float64, v []float64) (rms float64)\n")
	PrintVec("v", v, "%5g", false)
	w := []float64{333, 333, 333, 333, 333}
	rmserr = VecRmsError(v, w, 0, 1, v)
	io.Pf("rmserr(v,w,v) = %23.15e\n", rmserr)
	chk.Scalar(tst, "rmserr(v,w,0,1,v)", 1e-17, rmserr, 0.5)
}
Example #6
0
func run_tests(N, n int, do_check bool, tst *testing.T) (dt []time.Duration, msg []string) {
	// allocate
	num_tests := 24
	dt = make([]time.Duration, num_tests)
	msg = make([]string, num_tests)

	// 0: check if v is filled with zero by default
	t0 := time.Now()
	v := make([]float64, N)
	v[0] += noise
	dt[0], msg[0] = time.Now().Sub(t0), "vector: alloc     "
	if do_check {
		chk.Vector(tst, msg[0], tol, v, []float64{})
	}

	// 1: matrix: allocate
	t0 = time.Now()
	a := MatAlloc(10, n)
	a[0][0] += noise
	dt[1], msg[1] = time.Now().Sub(t0), "matrix: alloc     "
	if do_check {
		chk.Matrix(tst, msg[1], tol, a, [][]float64{})
	}

	// 2: vector: fill
	u := make([]float64, N)
	t0 = time.Now()
	VecFill(u, 666.0)
	u[0] += 100 * noise
	dt[2], msg[2] = time.Now().Sub(t0), "vector: fill      "
	if do_check {
		chk.Vector(tst, msg[2], tol, u, ucorr0)
	}

	// 3: matrix: fill
	t0 = time.Now()
	MatFill(a, 666.0)
	a[0][0] += 100 * noise
	dt[3], msg[3] = time.Now().Sub(t0), "matrix: fill      "
	if do_check {
		chk.Matrix(tst, msg[3], tol, a, acorr0)
	}

	// 4: vector: norm (Euclidian)
	v[0], v[N-1] = 1.0/math.Sqrt(2.0), -1.0/math.Sqrt(2.0)
	t0 = time.Now()
	nrm := VecNorm(v)
	dt[4], msg[4] = time.Now().Sub(t0), "vector: norm      "
	if do_check {
		chk.Scalar(tst, msg[4], tol*10, nrm, 1.0+noise)
	}

	// 5: vector: min component
	v[N-1], v[1] = 1.0, -1.0
	t0 = time.Now()
	min := VecMin(v)
	dt[5], msg[5] = time.Now().Sub(t0), "vector: min       "
	if do_check {
		chk.Scalar(tst, msg[5], tol, min, -1.0+noise)
	}

	// 6: vector: max component
	t0 = time.Now()
	max := VecMax(v)
	dt[6], msg[6] = time.Now().Sub(t0), "vector: max       "
	if do_check {
		chk.Scalar(tst, msg[6], tol, max, 1.0+noise)
	}

	// 7: vector: min and max components
	t0 = time.Now()
	min, max = VecMinMax(v)
	dt[7], msg[7] = time.Now().Sub(t0), "vector: minmax    "
	if do_check {
		chk.Scalar(tst, msg[7], tol, min, -1.0+noise)
		chk.Scalar(tst, msg[7], tol, max, 1.0+noise)
	}

	// 8: matrix: a := a * s
	t0 = time.Now()
	MatScale(a, 0.5)
	dt[8], msg[8] = time.Now().Sub(t0), "matrix: scale     "
	if do_check {
		chk.Matrix(tst, msg[8], tol, a, acorr1)
	}

	// 9: vector: a := b
	t0 = time.Now()
	VecCopy(v, 1, u) // v := u
	v[0] += noise
	dt[9], msg[9] = time.Now().Sub(t0), "vector: copy      "
	if do_check {
		chk.Vector(tst, msg[9], tol, v, u)
	}

	// 10: vector: a += b * s
	t0 = time.Now()
	VecAdd(u, -1, v) // u += (-1.0)*v
	u[0] += noise
	dt[10], msg[10] = time.Now().Sub(t0), "vector: addscaled "
	if do_check {
		chk.Vector(tst, msg[10], tol, u, []float64{})
	}

	// 11: matrix: a := b * s
	t0 = time.Now()
	MatCopy(a, 1, bmat) // a := 1*bmat
	a[0][0] += noise
	dt[11], msg[11] = time.Now().Sub(t0), "matrix: copyscaled"
	if do_check {
		chk.Matrix(tst, msg[11], tol, a, bmat)
	}

	// 12: matrix: set diagonal with v
	t0 = time.Now()
	MatSetDiag(a, 1.5)
	a[0][0] += noise
	dt[12], msg[12] = time.Now().Sub(t0), "matrix: setdiag   "
	if do_check {
		chk.Matrix(tst, msg[12], tol, a, dmat)
	}

	// 13: vector: max difference
	t0 = time.Now()
	maxdiff := VecMaxDiff(bvec, dvec)
	dt[13], msg[13] = time.Now().Sub(t0), "vector: maxdiff   "
	if do_check {
		chk.Scalar(tst, msg[13], tol, maxdiff, float64(N-1)+100*noise)
	}

	// 14: matrix: max difference
	t0 = time.Now()
	maxdiff = MatMaxDiff(acorr0, acorr1)
	dt[14], msg[14] = time.Now().Sub(t0), "matrix: maxdiff   "
	if do_check {
		chk.Scalar(tst, msg[14], tol, maxdiff, 333.0+noise)
	}

	// 15: matrix: get col
	t0 = time.Now()
	col := MatGetCol(4, amat)
	dt[15], msg[15] = time.Now().Sub(t0), "matrix: getcol    "
	if do_check {
		chk.Vector(tst, msg[15], tol, col, avec)
	}

	// 16: vector: a := b * s
	t0 = time.Now()
	VecCopy(v, 0.5, bvec) // v := u * 0.5
	v[0] += noise
	dt[16], msg[16] = time.Now().Sub(t0), "vector: copyscaled"
	if do_check {
		chk.Vector(tst, msg[16], tol, v, evec)
	}

	// 17: vector: add: u := α*a + β*b
	t0 = time.Now()
	VecAdd2(u, 0.5, bvec, 0.5, dvec) // u := 0.5*bvec + 0.5*dvec
	v[0] += noise
	dt[17], msg[17] = time.Now().Sub(t0), "vector: add       "
	if do_check {
		chk.Vector(tst, msg[17], tol, u, fvec)
	}

	// 18: vector: dot product: s := u dot v
	t0 = time.Now()
	res := VecDot(bvec, bvec)
	res += noise
	dt[18], msg[18] = time.Now().Sub(t0), "vector: dot       "
	if do_check {
		chk.Scalar(tst, msg[18], tol, res, float64(N*(N+1)*(2*N+1)/6)) // Faulhaber's formula
	}

	// 19: vector: largest component (divided by den)
	t0 = time.Now()
	res = VecLargest(bvec, 2.0) // den = 1.0
	res += noise
	dt[19], msg[19] = time.Now().Sub(t0), "vector: largest   "
	if do_check {
		chk.Scalar(tst, msg[19], tol, res, float64(N)/2.0)
	}

	// 20: vectorC: fill
	uc := make([]complex128, N)
	t0 = time.Now()
	VecFillC(uc, 666+666i)
	dt[20], msg[20] = time.Now().Sub(t0), "vector: fillC     "
	if do_check {
		chk.VectorC(tst, msg[20], tol, uc, ucorZ0)
	}

	// 21: vector: max difference C
	t0 = time.Now()
	maxdiffC := VecMaxDiffC(bveZ, dveZ)
	dt[21], msg[21] = time.Now().Sub(t0), "vector: maxdiffC  "
	if do_check {
		chk.Scalar(tst, msg[21], tol, maxdiffC, float64(N-1)+100*noise)
	}

	// 22: vector: rms
	t0 = time.Now()
	sum_1toN_squared := float64(N*(N+1)*(2*N+1)) / float64(6) // Faulhaber's formula
	rms_corr := math.Sqrt(sum_1toN_squared / float64(N))
	rms := VecRms(bvec)
	dt[22], msg[22] = time.Now().Sub(t0), "vector: rms       "
	if do_check {
		chk.Scalar(tst, msg[22], 1e-17, rms, rms_corr+noise)
	}

	// 23: vector: rmserr
	t0 = time.Now()
	rmserr := VecRmsErr(v, 0, 1, v)
	dt[23], msg[23] = time.Now().Sub(t0), "vector: rmserr    "
	if do_check {
		chk.Scalar(tst, msg[23], 1e-17, rmserr, 1.0+noise)
	}

	return
}
Example #7
0
func Test_hlsolver02(tst *testing.T) {

	//verbose()
	chk.PrintTitle("hlsolver02. complex")

	// flag indicating to store (real,complex) values in monolithic form => 1D array
	xzmono := false

	// input matrix in Complex Triplet format
	var A TripletC
	A.Init(5, 5, 16, xzmono) // 5 x 5 matrix with 16 non-zeros

	// first column
	A.Put(0, 0, 19.73, 0) // i=0, j=0, real=19.73, complex=0
	A.Put(1, 0, 0, -0.51) // i=1, j=0, real=0, complex=-0.51

	// second column
	A.Put(0, 1, 12.11, -1) // i=0, j=1, real=12.11, complex=-1
	A.Put(1, 1, 32.3, 7)
	A.Put(2, 1, 0, -0.51)

	// third column
	A.Put(0, 2, 0, 5)
	A.Put(1, 2, 23.07, 0)
	A.Put(2, 2, 70, 7.3)
	A.Put(3, 2, 1, 1.1)

	// fourth column
	A.Put(1, 3, 0, 1)
	A.Put(2, 3, 3.95, 0)
	A.Put(3, 3, 50.17, 0)
	A.Put(4, 3, 0, -9.351)

	// fifth column
	A.Put(2, 4, 19, 31.83)
	A.Put(3, 4, 45.51, 0)
	A.Put(4, 4, 55, 0)

	// right-hand-side
	b := []complex128{
		77.38 + 8.82i,
		157.48 + 19.8i,
		1175.62 + 20.69i,
		912.12 - 801.75i,
		550 - 1060.4i,
	}

	// solve
	x, err := SolveComplexLinSys(&A, b)
	if err != nil {
		tst.Errorf("%v\n", err)
		return
	}

	// check
	x_correct := []complex128{
		3.3 - 1i,
		1 + 0.17i,
		5.5,
		9,
		10 - 17.75i,
	}
	chk.VectorC(tst, "x", 1e-3, x, x_correct)
	CheckResidC(tst, 1e-12, A.ToMatrix(nil).ToDense(), x, b)
}