Skip to content
Snippets Groups Projects
Commit 1fa7a827 authored by Daniel Jankowski's avatar Daniel Jankowski
Browse files

Added: some print functions for the matrix

parent 82009a79
No related branches found
No related tags found
No related merge requests found
Pipeline #4272 passed
print.go 0 → 100644
// 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)
}
}
// Package gomatrix Is a go package for scientific operations with matrices in F2.
package gomatrix
import (
"math/big"
"testing"
)
func TestPrettyPrint(t *testing.T) {
tests := []struct {
matrix *F2
}{
{
matrix: NewF2(3, 3).Set([]*big.Int{big.NewInt(5), big.NewInt(3), big.NewInt(2)}),
},
}
for _, test := range tests {
test.matrix.PrettyPrint()
test.matrix.PrintLaTex()
test.matrix.PrintCSV()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment