Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Package gomatrix Is a go package for scientific operations with matrices in F2.
package gomatrix
import (
"fmt"
)
// PrettyPrint prints the matrix to stdout
func (f *F2) PrettyPrint() {
f.printWithSeperators(" ", "\n")
}
// PrintLaTex prints the matrix as latex code
func (f *F2) PrintLaTex() {
fmt.Printf("\\begin{bmatrix}\n")
f.printWithSeperators(" & ", "\\\n")
fmt.Printf("\\end{bmatrix}\n")
}
// PrintCSV prints the matrix as csv
func (f *F2) PrintCSV() {
f.printWithSeperators(", ", "\n")
}
// printWithSeperators prints the matrix with custom seperators
//
// @param string valSep The seperator for the single values
// @param string lineSep The line seperator
func (f *F2) printWithSeperators(valSep, lineSep string) {
for _, row := range f.Rows {
for i := 0; i < f.M; i++ {
if i == f.M-1 {
fmt.Printf("%d ", row.Bit(i))
continue
}
fmt.Printf("%d%s", row.Bit(i), valSep)
}
fmt.Print(lineSep)
}
}