Git Product home page Git Product logo

newmatic's Introduction

newmatic

Create new MAT-files optimized for partial reading and writing of large arrays.

This tool solves a few problems I ran into when using matfile, namely:

  • Inability to control data chunking: Arrays in MAT-files are saved in "chunks". The most natural and performant way to read/write to these arrays is to access one chunk at a time. MATLAB chooses the chunk size automatically, and it may (read: almost certainly) not be the most efficient choice for your workload. The recommended solution is to use third-party tools to "repack" your MAT-file after you create it (see section "Accelerate Save and Load Operations for Version 7.3 MAT-Files" in the MAT-file versions documentation). This should make us all sad.

  • Repetitive and cryptic array size initialization: Assigning a value to the very last element in the array serves a similar purpose as pre-allocating arrays for in-memory variables. The recommended approach is fine, but not easy for the uninitiated to parse and ugly to look at.

Fortunately, (a) MAT-files are HDF5 formatted under the hood, and (b) MATLAB includes utilities for working with HDF5 files directly (i.e., without any external tools). newmatic provides an alternative interface for creating "customized" MAT-files that perform well for partial IO.

Additional notes:

  • newmatic only allocates arrays. If you want to include other data types (strings, cell arrays, whatever), you can add them to the file created by newmatic in the usual way.

Example Usage

There are two key functions in this package:

  • newmatic_variable is used to define the name, data type, array size, and chunk size for variables created by newmatic
  • newmatic creates a MAT-file with the specified variables

Here is a small example demonstrating how to create a MAT-file with two arrays (created by newmatic) and a cell array (not created by newmatic).

mat = newmatic(...
    'my-mat-file.mat', ...
    newmatic_variable('x', 'double', [1000, 1000, 20], [1000, 1000, 1]), ...
    newmatic_variable('y', 'double', [1000, 10, 10], [5000, 10, 10]));
mat.z = {'a', 'cell', 'array'};

References

Special shout out to the hdf5storage python package for helping me work out the details of making a MATLAB-compatible HDF5 file.

newmatic's People

Contributors

keithfma avatar beigeone avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.