Documentation ¶
Overview ¶
Package matf extracts the content from MAT-files and make it available in golang. In golang, then you can use your favorite Machine Learning environment, to further use of the extracted data.
For example, you can use the data in gonum:
package main import ( "fmt" "io" "log" "os" "reflect" "github.com/florianl/matf" "gonum.org/v1/gonum/mat" ) func main() { modelfile, err := matf.Open(os.Args[1]) if err != nil { log.Fatal(err) return } defer matf.Close(modelfile) element, err := matf.ReadDataElement(modelfile) if err != nil && err != io.EOF { log.Fatal(err) return } r, c, _, err := element.Dimensions() data := []float64{} slice := reflect.ValueOf(element.Content.(matf.NumPrt).RealPart) for i := 0; i < slice.Len(); i++ { value := reflect.ValueOf(slice.Index(i).Interface()).Float() data = append(data, value) } dense := mat.NewDense(r, c, data) fmt.Printf("dense = %v\n", mat.Formatted(dense, mat.Prefix(" "))) }
Or use it in gorgonia:
package main import ( "io" "log" "os" "reflect" "github.com/florianl/matf" "gorgonia.org/gorgonia" "gorgonia.org/tensor" ) func main() { modelfile, err := matf.Open(os.Args[1]) if err != nil { log.Fatal(err) return } defer matf.Close(modelfile) element, err := matf.ReadDataElement(modelfile) if err != nil && err != io.EOF { log.Fatal(err) return } r, c, _, err := element.Dimensions() data := []float64{} slice := reflect.ValueOf(element.Content.(matf.NumPrt).RealPart) for i := 0; i < slice.Len(); i++ { value := reflect.ValueOf(slice.Index(i).Interface()).Float() data = append(data, value) } t := tensor.New(tensor.WithShape(r,c), tensor.WithBacking(data)) g := gorgonia.NewGraph() w := gorgonia.NewMatrix(g, gorgonia.Float64, gorgonia.WithShape(r,c), gorgonia.WithValue(t)) gorgonia.Must(gorgonia.Sigmoid(w)) m := gorgonia.NewTapeMachine(g) if err := m.RunAll(); err != nil { log.Fatal(err) return } m.Reset() }
Index ¶
Constants ¶
View Source
const ( MiInt8 int = 1 MiUint8 int = 2 MiInt16 int = 3 MiUint16 int = 4 MiInt32 int = 5 MiUint32 int = 6 MiSingle int = 7 MiDouble int = 9 MiInt64 int = 12 MiUint64 int = 13 MiMatrix int = 14 MiCompressed int = 15 MiUtf8 int = 16 MiUtf16 int = 17 MiUtf32 int = 18 )
List of all MAT-File Data Types
View Source
const ( MxCellClass int = 1 MxStructClass int = 2 MxObjectClass int = 3 MxCharClass int = 4 MxSparseClass int = 5 MxDoubleClass int = 6 MxSingleClass int = 7 MxInt8Class int = 8 MxUint8Class int = 9 MxInt16Class int = 10 MxUint16Class int = 11 MxInt32Class int = 12 MxUint32Class int = 13 MxInt64Class int = 14 MxUint64Class int = 15 )
List of all MAT-File Array Types
View Source
const ( ClassMask = 0x0F // Mask to extract the containing class from an array. FlagComplex = 1 << 11 // If set, the data element contains an imaginary part. FlagGlobal = 1 << 10 // MATLAB uses this element on global scope. FlagLogical = 1 << 9 // Array is used for logical indexing. )
Basic binary flags for various array types
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Header ¶
type Header struct { Text string // Some kind of descriptive text containing various information. SubsystemDataOffset []byte // Contains the sybsystem-specific data. Version uint16 // MATLAB version used, to create this file. EndianIndicator uint16 // Indicates, if the file was written on a Big Endian or Little Endian system. }
Header contains informations about the MAT-file
type MatMatrix ¶
type MatMatrix struct { Name string Flags uint32 Class uint32 Dim Content interface{} // Can contain NumPrt, StructPrt, CellPrt or CharPrt - depending on the value in Class. }
MatMatrix represents a matrix
func ReadDataElement ¶
ReadDataElement returns the next data element. It returns io.EOF, if no further elements are available
type Matf ¶
type Matf struct { Header // contains filtered or unexported fields }
Matf represents the MAT-file
Click to show internal directories.
Click to hide internal directories.