Exemple #1
0
// Creates a complex matrix from a real matrix.
func NewReal(a mat.Const) *Mat {
	m, n := a.Dims()
	b := New(m, n)
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			b.Set(i, j, complex(a.At(i, j), 0))
		}
	}
	return b
}
Exemple #2
0
// Creates a complex matrix from a real matrix.
//
// Panics if a and b are not the same size.
func NewRealImag(a, b mat.Const) *Mat {
	if err := errIfDimsNotEq(a, b); err != nil {
		panic(err)
	}

	m, n := a.Dims()
	c := New(m, n)
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			c.Set(i, j, complex(a.At(i, j), b.At(i, j)))
		}
	}
	return c
}
Exemple #3
0
func checkEqualMat(t *testing.T, want, got mat.Const, eps float64) bool {
	m, n := want.Dims()
	p, q := got.Dims()
	if !(m == p && n == q) {
		t.Errorf("different size: want %dx%d, got %dx%d", m, n, p, q)
		return false
	}
	ok := true
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			x, y := want.At(i, j), got.At(i, j)
			if math.Abs(x-y) > eps {
				ok = false
				t.Errorf("different at %d, %d: want %g, got %g", i, j, x, y)
			}
		}
	}
	return ok
}