Mentions légales du service

Skip to content
Snippets Groups Projects
Commit c9b9ef49 authored by hhakim's avatar hhakim
Browse files

Write a MatBSR::toMatIOVar that allows to store the matrix as a matlab cell...

Write a MatBSR::toMatIOVar that allows to store the matrix as a matlab cell array of its buffers instead of converting it to a MatSparse.
parent 2b0fd98f
Branches
Tags
No related merge requests found
......@@ -298,9 +298,90 @@ namespace Faust
template <typename FPP>
matvar_t* MatBSR<FPP,Cpu>::toMatIOVar(bool transpose, bool conjugate) const
{
MatSparse<FPP, Cpu> smat(this->dim1, this->dim2);
smat.mat = bmat.to_sparse();
return smat.toMatIOVar(transpose, conjugate);
// MatSparse<FPP, Cpu> smat(this->dim1, this->dim2);
// smat.mat = bmat.to_sparse();
// return smat.toMatIOVar(transpose, conjugate);
int opt = typeid(bmat.data[0])==typeid(std::complex<Real<FPP>>(1.0,1.0))?MAT_F_COMPLEX:0;
size_t params_dims[2] = {1, 3}; // nrows, ncols, bnnz
int params[3] = {(int) this->getNbRow(), (int) this->getNbCol(), (int) this->getNBlocks()};
size_t nzb_dims[2] = {1, getNBlocks()}; // bcolinds size
size_t browptr_dims[2] = {1, getNbBlocksPerDim(0)+1};
size_t bcolinds_dims[2] = {1, getNBlocks()};
size_t bdata_dims[2] = {1, getNBlocks()*getNbBlockRow()*getNbBlockCol()};
size_t cell_dims[2] = { 1, 4};
matvar_t *matvars[5], *bsr_cell = nullptr;
mat_complex_split_t z = {nullptr,nullptr};
matio_types bdata_matio_type;
matio_classes bdata_matio_class;
using DenseMatMap = Eigen::Map<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>>;
if(std::is_same<FPP, float>::value)
{
bdata_matio_type = MAT_T_SINGLE;
bdata_matio_class = MAT_C_SINGLE;
}
else
{
bdata_matio_type = MAT_T_DOUBLE;
bdata_matio_class = MAT_C_DOUBLE;
}
matvars[4] = nullptr;
matvars[0] = Mat_VarCreate(NULL, MAT_C_INT32, MAT_T_INT32, 2, params_dims, params, 0); // copy needed because params is in the stack
matvars[1] = Mat_VarCreate("bcolinds", MAT_C_INT32, MAT_T_INT32, 2, bcolinds_dims, bmat.bcolinds, MAT_F_DONT_COPY_DATA);
matvars[2] = Mat_VarCreate("browptr", MAT_C_INT32, MAT_T_INT32, 2, browptr_dims, bmat.browptr, MAT_F_DONT_COPY_DATA);
// auto mat_browptr = Mat_CreateVer("test_bsr_browptr.mat", NULL, MAT_FT_MAT5);
// Mat_VarWrite(mat_browptr, matvars[2], MAT_COMPRESSION_NONE);
// Mat_Close(mat_browptr);
// auto mat_bcolinds = Mat_CreateVer("test_bsr_bcolinds.mat", NULL, MAT_FT_MAT5);
// Mat_VarWrite(mat_bcolinds, matvars[1], MAT_COMPRESSION_NONE);
// Mat_Close(mat_bcolinds);
DenseMatMap _bmat(bmat.data, getNbBlockRow(), getNBlocks()*getNbBlockCol());
if(opt)
{
// complex matrix
DenseMat<Real<FPP>> dst_re(getNbBlockRow(), getNBlocks()*getNbBlockCol());
DenseMat<Real<FPP>> dst_im(getNbBlockRow(), getNBlocks()*getNbBlockCol());
// DenseMat<FPP> tmp(getNbBlockRow(), getNBlocks()*getNbBlockCol());
// tmp = _bmat;
if(transpose)
{
dst_re = _bmat.real().template cast<Real<FPP>>().transpose();
// dst_im = _bmat.imag().template cast<Real<FPP>>().transpose();
for(int i=0;i<_bmat.rows()*_bmat.cols();i++)
dst_im.data()[i] = std::imag(_bmat.data()[i]);
dst_im.transposeInPlace();
}
else
{
dst_re = _bmat.real().template cast<Real<FPP>>();
// dst_im = _bmat.imag().template cast<Real<FPP>>();
for(int i=0;i<_bmat.rows()*_bmat.cols();i++)
dst_im.data()[i] = std::imag(_bmat.data()[i]);
}
if(conjugate)
dst_im *= Real<FPP>(-1);
z.Re = dst_re.data();
z.Im = dst_im.data();
matvars[3] = Mat_VarCreate(nullptr, bdata_matio_class, bdata_matio_type, 2, bdata_dims, &z /*mat.transpose().eval().data() // doesn't work so we copy above */, opt);
}
else
{
// real matrix // conjugate is ignored
if(transpose)
{
DenseMat<FPP> mat(getNbBlockRow(), getNBlocks()*getNbBlockCol());
mat = _bmat.transpose();
matvars[3] = Mat_VarCreate("bdata", bdata_matio_class, bdata_matio_type, 2, bdata_dims, mat.data(), MAT_F_DONT_COPY_DATA);
}
else
matvars[3] = Mat_VarCreate("bdata", bdata_matio_class, bdata_matio_type, 2, bdata_dims, bmat.data, MAT_F_DONT_COPY_DATA);
}
// auto mat = Mat_CreateVer("test_bsr_bdata.mat", NULL, MAT_FT_MAT5);
// Mat_VarWrite(mat, matvars[3], MAT_COMPRESSION_NONE);
// Mat_Close(mat);
bsr_cell = Mat_VarCreate("bsr_cell", MAT_C_CELL, MAT_T_CELL, 2, cell_dims, matvars, 0);
return bsr_cell;
}
template <typename FPP>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment