Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/florianl/matf

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/florianl/matf

  • v0.0.0-20180627184710-937d4e2e11ce
  • Source
  • Go
  • Socket score

Version published
Created
Source

matf Build Status Coverage Status Go Report Card GoDoc

This is matf and it is written in golang. matf extracts the content from MATLABs MAT-files.

Why?

The idea of this project is, to make the content of mat-files available in golang.

Example

Load a simple matrix, saved in a matf-file, in gonum/mat.

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("        ")))

}

Simple example, using 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()
}

FAQs

Package last updated on 27 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc