Esempio n. 1
0
func TestMatMul(t *testing.T) {
	const (
		m = 3
		k = 4
		n = 5
	)

	alpha := rand.NormFloat64()
	a, b := randMat(m, k), randMat(k, n)
	got := blas.MatMul(alpha, a, b)
	want := mat.Scale(alpha, mat.Mul(a, b))
	checkEqualMat(t, want, got, 1e-9)

	// Try with non-copying transposes.
	alpha = rand.NormFloat64()
	a, b = randMat(k, m).T(), randMat(k, n)
	got = blas.MatMul(alpha, a, b)
	want = mat.Scale(alpha, mat.Mul(a, b))
	checkEqualMat(t, want, got, 1e-9)

	alpha = rand.NormFloat64()
	a, b = randMat(m, k), randMat(n, k).T()
	got = blas.MatMul(alpha, a, b)
	want = mat.Scale(alpha, mat.Mul(a, b))
	checkEqualMat(t, want, got, 1e-9)

	alpha = rand.NormFloat64()
	a, b = randMat(k, m).T(), randMat(n, k).T()
	got = blas.MatMul(alpha, a, b)
	want = mat.Scale(alpha, mat.Mul(a, b))
	checkEqualMat(t, want, got, 1e-9)
}
Esempio n. 2
0
func TestGenMatMul(t *testing.T) {
	const (
		m = 3
		k = 4
		n = 5
	)
	alpha, beta := rand.NormFloat64(), rand.NormFloat64()
	a, b, c := randMat(m, k), randMat(k, n), randMat(m, n)
	want := mat.Plus(mat.Scale(alpha, mat.Mul(a, b)), mat.Scale(beta, c))
	// Over-write c with result.
	blas.GenMatMul(alpha, a, b, beta, c)
	checkEqualMat(t, want, c, 1e-9)
}