cyqlone develop
Fast, parallel and vectorized solver for linear systems with optimal control structure.
Loading...
Searching...
No Matches
Exporting and loading .mat files

Detailed Description

Functions for exporting and loading matrices and OCP data to and from .mat files.

Files

file  matio.hpp
 Functions for exporting and loading matrices and OCP data to and from .mat files.

Typedefs

using cyqlone::mat_t = ::_mat_t
 Incomplete matio struct type.
using cyqlone::MatFilePtr = std::unique_ptr<mat_t, int (*)(mat_t *)>
 Owning handle to a matio file. The file will be closed when the handle goes out of scope.

Enumerations

enum class  cyqlone::MatioOpenMode { cyqlone::MatioOpenMode::Read , cyqlone::MatioOpenMode::Write }

Functions

MatFilePtr cyqlone::open_mat (const std::filesystem::path &filename, MatioOpenMode mode=MatioOpenMode::Read)
 Opens a .mat file for reading or writing.
MatFilePtr cyqlone::create_mat (const std::filesystem::path &filename)
 Create and open a new .mat file for writing.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, float value)
 Add a value to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, double value)
 Add a value to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, short value)
 Add a value to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, int value)
 Add a value to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, long value)
 Add a value to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, long long value)
 Add a value to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, unsigned short value)
 Add a value to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, unsigned int value)
 Add a value to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, unsigned long value)
 Add a value to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, unsigned long long value)
 Add a value to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, guanaqo::MatrixView< const double, index_t > data)
 Add a matrix to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, guanaqo::MatrixView< const float, index_t > data)
 Add a matrix to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, batmat::matrix::View< const double, index_t > data)
 Add a batch of matrices to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, batmat::matrix::View< const float, index_t > data)
 Add a batch of matrices to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, std::span< const float > data)
 Add a vector to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, std::span< const double > data)
 Add a vector to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, std::span< const unsigned short > data)
 Add a vector to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, std::span< const unsigned int > data)
 Add a vector to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, std::span< const unsigned long > data)
 Add a vector to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, std::span< const unsigned long long > data)
 Add a vector to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, std::span< const short > data)
 Add a vector to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, std::span< const int > data)
 Add a vector to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, std::span< const long > data)
 Add a vector to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, std::span< const long long > data)
 Add a vector to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, const SparseMatrix &matrix)
 Add a sparse matrix to an open .mat file.
void cyqlone::add_to_mat (mat_t *mat, const std::string &varname, const LinearOCPStorage &ocp)
 Add the data from a LinearOCPStorage to an open .mat file.
void cyqlone::read_from_mat (mat_t *mat, const std::string &varname, LinearOCPStorage &ocp)
 Load a LinearOCPStorage from a .mat file.
void cyqlone::read_from_mat (mat_t *mat, const std::string &varname, std::vector< float > &data)
 Load a vector from an open .mat file.
void cyqlone::read_from_mat (mat_t *mat, const std::string &varname, std::vector< double > &data)
 Load a vector from an open .mat file.
void cyqlone::read_from_mat (mat_t *mat, const std::string &varname, std::span< float > data)
 Load a vector from an open .mat file.
void cyqlone::read_from_mat (mat_t *mat, const std::string &varname, std::span< double > data)
 Load a vector from an open .mat file.
void cyqlone::ocp_dump_mat (const std::filesystem::path &filename, const LinearOCPStorage &ocp)
 Dump the data from a LinearOCPStorage to a new .mat file.

Typedef Documentation

◆ mat_t

using cyqlone::mat_t = ::_mat_t

#include <cyqlone/matio.hpp>

Incomplete matio struct type.

Definition at line 24 of file matio.hpp.

◆ MatFilePtr

typedef std::unique_ptr< mat_t, decltype(&Mat_Close)> cyqlone::MatFilePtr = std::unique_ptr<mat_t, int (*)(mat_t *)>

#include <cyqlone/matio.hpp>

Owning handle to a matio file. The file will be closed when the handle goes out of scope.

Definition at line 26 of file matio.hpp.

Enumeration Type Documentation

◆ MatioOpenMode

enum class cyqlone::MatioOpenMode
strong

#include <cyqlone/matio.hpp>

Enumerator
Read 
Write 

Definition at line 28 of file matio.hpp.

Function Documentation

◆ open_mat()

MatFilePtr cyqlone::open_mat ( const std::filesystem::path & filename,
MatioOpenMode mode = MatioOpenMode::Read )

#include <cyqlone/matio.hpp>

Opens a .mat file for reading or writing.

Exceptions
runtime_errorif the file cannot be opened.

Definition at line 89 of file matio.cpp.

◆ create_mat()

MatFilePtr cyqlone::create_mat ( const std::filesystem::path & filename)

#include <cyqlone/matio.hpp>

Create and open a new .mat file for writing.

Exceptions
runtime_errorif the file cannot be opened.
Examples
benchmarks/cyqpalm/spring-mass.cpp, solve-block-tridiagonal.cpp, solve-ocp.cpp, and test/test-pcr.cpp.

Definition at line 97 of file matio.cpp.

◆ add_to_mat() [1/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
float value )

#include <cyqlone/matio.hpp>

Add a value to an open .mat file.

Examples
benchmarks/cyqpalm/spring-mass.cpp, solve-block-tridiagonal.cpp, solve-ocp.cpp, and test/test-pcr.cpp.

Definition at line 122 of file matio.cpp.

◆ add_to_mat() [2/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
double value )

#include <cyqlone/matio.hpp>

Add a value to an open .mat file.

Definition at line 126 of file matio.cpp.

◆ add_to_mat() [3/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
short value )

#include <cyqlone/matio.hpp>

Add a value to an open .mat file.

Definition at line 146 of file matio.cpp.

◆ add_to_mat() [4/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
int value )

#include <cyqlone/matio.hpp>

Add a value to an open .mat file.

Definition at line 150 of file matio.cpp.

◆ add_to_mat() [5/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
long value )

#include <cyqlone/matio.hpp>

Add a value to an open .mat file.

Definition at line 154 of file matio.cpp.

◆ add_to_mat() [6/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
long long value )

#include <cyqlone/matio.hpp>

Add a value to an open .mat file.

Definition at line 158 of file matio.cpp.

◆ add_to_mat() [7/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
unsigned short value )

#include <cyqlone/matio.hpp>

Add a value to an open .mat file.

Definition at line 130 of file matio.cpp.

◆ add_to_mat() [8/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
unsigned int value )

#include <cyqlone/matio.hpp>

Add a value to an open .mat file.

Definition at line 134 of file matio.cpp.

◆ add_to_mat() [9/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
unsigned long value )

#include <cyqlone/matio.hpp>

Add a value to an open .mat file.

Definition at line 138 of file matio.cpp.

◆ add_to_mat() [10/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
unsigned long long value )

#include <cyqlone/matio.hpp>

Add a value to an open .mat file.

Definition at line 142 of file matio.cpp.

◆ add_to_mat() [11/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
guanaqo::MatrixView< const double, index_t > data )

#include <cyqlone/matio.hpp>

Add a matrix to an open .mat file.

Definition at line 162 of file matio.cpp.

◆ add_to_mat() [12/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
guanaqo::MatrixView< const float, index_t > data )

#include <cyqlone/matio.hpp>

Add a matrix to an open .mat file.

Definition at line 167 of file matio.cpp.

◆ add_to_mat() [13/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
batmat::matrix::View< const double, index_t > data )

#include <cyqlone/matio.hpp>

Add a batch of matrices to an open .mat file.

Definition at line 192 of file matio.cpp.

◆ add_to_mat() [14/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
batmat::matrix::View< const float, index_t > data )

#include <cyqlone/matio.hpp>

Add a batch of matrices to an open .mat file.

Definition at line 197 of file matio.cpp.

◆ add_to_mat() [15/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
std::span< const float > data )

#include <cyqlone/matio.hpp>

Add a vector to an open .mat file.

Definition at line 202 of file matio.cpp.

◆ add_to_mat() [16/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
std::span< const double > data )

#include <cyqlone/matio.hpp>

Add a vector to an open .mat file.

Definition at line 206 of file matio.cpp.

◆ add_to_mat() [17/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
std::span< const unsigned short > data )

#include <cyqlone/matio.hpp>

Add a vector to an open .mat file.

Definition at line 210 of file matio.cpp.

◆ add_to_mat() [18/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
std::span< const unsigned int > data )

#include <cyqlone/matio.hpp>

Add a vector to an open .mat file.

Definition at line 215 of file matio.cpp.

◆ add_to_mat() [19/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
std::span< const unsigned long > data )

#include <cyqlone/matio.hpp>

Add a vector to an open .mat file.

Definition at line 219 of file matio.cpp.

◆ add_to_mat() [20/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
std::span< const unsigned long long > data )

#include <cyqlone/matio.hpp>

Add a vector to an open .mat file.

Definition at line 223 of file matio.cpp.

◆ add_to_mat() [21/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
std::span< const short > data )

#include <cyqlone/matio.hpp>

Add a vector to an open .mat file.

Definition at line 228 of file matio.cpp.

◆ add_to_mat() [22/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
std::span< const int > data )

#include <cyqlone/matio.hpp>

Add a vector to an open .mat file.

Definition at line 232 of file matio.cpp.

◆ add_to_mat() [23/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
std::span< const long > data )

#include <cyqlone/matio.hpp>

Add a vector to an open .mat file.

Definition at line 236 of file matio.cpp.

◆ add_to_mat() [24/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
std::span< const long long > data )

#include <cyqlone/matio.hpp>

Add a vector to an open .mat file.

Definition at line 240 of file matio.cpp.

◆ add_to_mat() [25/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
const SparseMatrix & matrix )

#include <cyqlone/matio.hpp>

Add a sparse matrix to an open .mat file.

On the Python side, you can use the following code to load the sparse matrix:

from scipy.io import loadmat
from scipy.sparse import coo_matrix
mat = loadmat("file.mat")
data = mat["varname"][0, 0]
shape = data["num_rows"].item(), data["num_cols"].item()
rows = data["row_indices"].flatten()
cols = data["col_indices"].flatten()
values = data["values"].flatten()
matrix = coo_matrix((values, (rows, cols)), shape=shape)

Definition at line 244 of file matio.cpp.

◆ add_to_mat() [26/26]

void cyqlone::add_to_mat ( mat_t * mat,
const std::string & varname,
const LinearOCPStorage & ocp )

#include <cyqlone/matio.hpp>

Add the data from a LinearOCPStorage to an open .mat file.

Definition at line 282 of file matio.cpp.

◆ read_from_mat() [1/5]

void cyqlone::read_from_mat ( mat_t * mat,
const std::string & varname,
LinearOCPStorage & ocp )

#include <cyqlone/matio.hpp>

Load a LinearOCPStorage from a .mat file.

Definition at line 365 of file matio.cpp.

◆ read_from_mat() [2/5]

void cyqlone::read_from_mat ( mat_t * mat,
const std::string & varname,
std::vector< float > & data )

#include <cyqlone/matio.hpp>

Load a vector from an open .mat file.

Definition at line 507 of file matio.cpp.

◆ read_from_mat() [3/5]

void cyqlone::read_from_mat ( mat_t * mat,
const std::string & varname,
std::vector< double > & data )

#include <cyqlone/matio.hpp>

Load a vector from an open .mat file.

Definition at line 515 of file matio.cpp.

◆ read_from_mat() [4/5]

void cyqlone::read_from_mat ( mat_t * mat,
const std::string & varname,
std::span< float > data )

#include <cyqlone/matio.hpp>

Load a vector from an open .mat file.

Definition at line 491 of file matio.cpp.

◆ read_from_mat() [5/5]

void cyqlone::read_from_mat ( mat_t * mat,
const std::string & varname,
std::span< double > data )

#include <cyqlone/matio.hpp>

Load a vector from an open .mat file.

Definition at line 499 of file matio.cpp.

◆ ocp_dump_mat()

void cyqlone::ocp_dump_mat ( const std::filesystem::path & filename,
const LinearOCPStorage & ocp )

#include <cyqlone/matio.hpp>

Dump the data from a LinearOCPStorage to a new .mat file.

Definition at line 523 of file matio.cpp.