File: format.go

package info (click to toggle)
mumax3 3.10-9
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 7,596 kB
  • sloc: makefile: 181; ansic: 155; sh: 77
file content (90 lines) | stat: -rw-r--r-- 2,058 bytes parent folder | download | duplicates (3)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package util

import (
	"bytes"
	"fmt"
	"io"
	"os"
)

// Produces nicely formatted output for multi-dimensional arrays.
func Println(array ...interface{}) {
	Fprint(os.Stdout, array...)
	fmt.Fprintln(os.Stdout)
}

// Produces nicely formatted output for multi-dimensional arrays.
func Print(array ...interface{}) {
	Fprint(os.Stdout, array...)
}

// Produces nicely formatted output for multi-dimensional arrays.
func Printf(format string, array ...interface{}) {
	Fprintf(os.Stdout, format, array...)
}

// Produces nicely formatted output for multi-dimensional arrays.
func Fprint(out io.Writer, array ...interface{}) {
	Fprintf(out, "%v", array...)
}

func Sprint(array ...interface{}) string {
	var buf bytes.Buffer
	Fprint(&buf, array...)
	return buf.String()
}

// Produces nicely formatted output for multi-dimensional arrays.
func Fprintf(out io.Writer, format string, array ...interface{}) {
	for _, arr := range array {
		switch a := arr.(type) {
		case [][][]float32:
			FprintfFloats(out, format, a)
		case [][][][]float32:
			FprintfTensors(out, format, a)
		case [3][][][]float32:
			FprintfTensors(out, format, a[:])
		case [3][3][][][]float32:
			Fprintf(out, format, a[0][:])
			Fprintf(out, format, a[1][:])
			Fprintf(out, format, a[2][:])
		default:
			fmt.Fprintf(out, format, a)
		}
	}
}

// Produces nicely formatted output.
func FprintfTensors(out io.Writer, format string, a [][][][]float32) {
	for i := range a {
		FprintfFloats(out, format, a[i])
		fmt.Fprintln(out)
	}
}

// Produces nicely formatted output.
func FprintfFloats(out io.Writer, format string, a [][][]float32) {
	format += " "
	for i := range a {
		for j := range a[i] {
			for _, v := range a[i][j] {
				fmt.Fprintf(out, format, v)
			}
			fmt.Fprintln(out)
		}
		fmt.Fprintln(out)
	}
}

//// Produces nicely formatted output.
//func FprintComplexs(out io.Writer, a [][][]complex64) {
//	for i := range a {
//		for j := range a[i] {
//			for _, v := range a[i][j] {
//				fmt.Fprint(out, v, " ")
//			}
//			fmt.Fprintln(out)
//		}
//		fmt.Fprintln(out)
//	}
//}