Hi all,
Matrix transpose in pure golang is slow in HPC cases, and using package
gonum needs structure transformation which costs extra time. So a assembly
version may be a better solution.
Sizes of the matrix vary ([][]byte) or can be fixed for example (
[64][512]byte), and the element type may be int32 or int64 for general
scenarios.
Below is a golang version:
m := 64
n := 512
// orignial matrix
M := make([][]byte, m)
for i := 0; i < m; i++ {
M[i] = make([]byte, n)
}
func transpose(M [][]byte) [][]byte {
m := len(M)
n := len(M[0])
// transposed matrix
T := make([][]byte, n)
for i := 0; i < n; i++ {
T[i] = make([]byte, m)
}
var row []byte // a row in T
for i := 0; i < n; i++ {
row = T[i]
for j = 0; j < m; j++ {
row[j] = M[j][i]
}
}
return T
}
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/95987011-abb7-47a3-be04-8819b4f5d523o%40googlegroups.com.