Skip to content

Commit

Permalink
[oblas] Fix use of conjugate transpose in zherk
Browse files Browse the repository at this point in the history
  • Loading branch information
cpmech committed Mar 16, 2024
1 parent ab6e75e commit 4c5ce3c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
9 changes: 8 additions & 1 deletion la/oblas/oblas.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ func Zherk(up, trans bool, n, k int, alpha float64, a []complex128, lda int, bet
C.cblas_zherk(
cblasColMajor,
cUplo(up),
cTrans(trans),
cConjTrans(trans),
C.blasint(n),
C.blasint(k),
C.double(alpha),
Expand Down Expand Up @@ -767,6 +767,13 @@ func cTrans(trans bool) uint32 {
return cblasNoTrans
}

func cConjTrans(trans bool) uint32 {
if trans {
return cblasConjTrans
}
return cblasNoTrans
}

func cUplo(up bool) uint32 {
if up {
return cblasUpper
Expand Down
71 changes: 70 additions & 1 deletion la/oblas/t_oblas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ func TestZherk01(tst *testing.T) {
up = false
Zherk(up, trans, n, k, alpha, a, lda, beta, cLo, ldc)

// compare resulting up(c) matrix
// compare resulting lo(c) matrix
chk.Deep2c(tst, "using lo(c): c := 3⋅a⋅aᵀ + c", 1e-17, ColMajorCtoSlice(n, n, cLo), [][]complex128{
{31 + 0i, +0 + 0i, +0 + 0i, +0 + 0i},
{21 + 5i, 33 + 0i, +0 + 0i, +0 + 0i},
Expand All @@ -1226,6 +1226,75 @@ func TestZherk01(tst *testing.T) {
})
}

func TestZherk02(tst *testing.T) {

verbose()
chk.PrintTitle("Zherk02")

// c matrices
c := SliceToColMajorC([][]complex128{ // must be Hermitian: c = c^H
{+4 + 0i, 0 + 1i, -3 + 1i, 0 + 2i},
{+0 - 1i, 3 + 0i, +1 + 0i, 2 + 0i},
{-3 - 1i, 1 + 0i, +4 + 0i, 1 - 1i},
{+0 - 2i, 2 + 0i, +1 + 1i, 4 + 0i},
})
cUp := SliceToColMajorC([][]complex128{
{+4 + 0i, 0 + 1i, -3 + 1i, 0 + 2i},
{+0 + 0i, 3 + 0i, +1 + 0i, 2 + 0i},
{+0 + 0i, 0 + 0i, +4 + 0i, 1 - 1i},
{+0 + 0i, 0 + 0i, +0 + 0i, 4 + 0i},
})
cLo := SliceToColMajorC([][]complex128{
{+4 + 0i, 0 + 0i, +0 + 0i, 0 + 0i},
{+0 - 1i, 3 + 0i, +0 + 0i, 0 + 0i},
{-3 - 1i, 1 + 0i, +4 + 0i, 0 + 0i},
{+0 - 2i, 2 + 0i, +1 + 1i, 4 + 0i},
})

// n-size
n := 4 // c.N

// check cUp and cLo
checkUploC(tst, "Zherk02", n, c, cLo, cUp, 1e-17, 1e-17)

// a matrix
a := SliceToColMajorC([][]complex128{
{1.0 - 1.0i, 2.0 + 0.0i, 1.0 + 0.0i, 1.0 + 0.0i},
{3.0 + 1.0i, 1.0 + 0.0i, 3.0 + 0.0i, 1.0 + 2.0i},
})

// sizes
k := 2 // a.M

// constants
alpha, beta := 3.0, -2.0

// run zherk with up(c)
up, trans := true, true
lda, ldc := k, n
Zherk(up, trans, n, k, alpha, a, lda, beta, cUp, ldc)

// compare resulting up(c) matrix
chk.Deep2c(tst, "using up(c): c := 3 aᴴ⋅a - 2 c", 1e-17, ColMajorCtoSlice(n, n, cUp), [][]complex128{
{28.0 + 0.0i, 15.0 + 1.0i, 36.0 - 8.0i, 18.0 + 14.0i},
{0.0 + 0.0i, 9.0 + 0.0i, 13.0 + 0.0i, 5.0 + 6.0i},
{0.0 + 0.0i, 0.0 + 0.0i, 22.0 + 0.0i, 10.0 + 20.0i},
{0.0 + 0.0i, 0.0 + 0.0i, 0.0 + 0.0i, 10.0 + 0.0i},
})

// run zherk with lo(c)
up = false
Zherk(up, trans, n, k, alpha, a, lda, beta, cLo, ldc)

// compare resulting lo(c) matrix
chk.Deep2c(tst, "using lo(c): c := 3 aᴴ⋅a - 2 c", 1e-17, ColMajorCtoSlice(n, n, cLo), [][]complex128{
{28.0 + 0.0i, 0.0 + 0.0i, 0.0 + 0.0i, 0.0 + 0.0i},
{15.0 - 1.0i, 9.0 + 0.0i, 0.0 + 0.0i, 0.0 + 0.0i},
{36.0 + 8.0i, 13.0 + 0.0i, 22.0 + 0.0i, 0.0 + 0.0i},
{18.0 - 14.0i, 5.0 - 6.0i, 10.0 - 20.0i, 10.0 + 0.0i},
})
}

func TestDpotrf01(tst *testing.T) {

//verbose()
Expand Down

0 comments on commit 4c5ce3c

Please sign in to comment.