Create vector/matrix from istream
I was browsing through the wiki today to check if there were any specific routines available for more efficient reading and writing of vectors and matrices from Blaze (so that one can e.g. store sparse matrices more optimally) as I need to print a million or so matrices (with complex elements) and store them for later use.
Not that it is extremely important for me to have something that is more efficient than what you provide with the stream operator. However, I noticed that there is no way of reading a matrix from a file. There is no corresponding >> to the << already implemented.
Am I just blind and can't fint it? If this is not the case it would be great to have a instream operator to go with the outstream one. Writing a parser is a bit of a hassle as blaze adds quite a few additional braces. Also, for the future, a more efficient file-storage format that doesn't need to be anything more than "blaze-consistent" would be really great.
Comments (7)
-
-
reporter Thanks a lot, yes that is exactly what I meant. It was just me being blind >_< or more specifically, not knowing that this is what the word "serialization" meant.
-
Hi Jonas!
We're glad you found what you were looking for. Fabien: Thanks for providing the links!
Best regards,
Klaus!
-
- changed status to wontfix
The feature to serialize vectors and matrices has been introduced in Blaze 1.3 (see the release archive).
-
Sorry, I don't know what should I do. I got the error.
In file included from smallGemm.cpp:2: In file included from /home/arch/build/blaze-3.1/blaze/Util.h:73: In file included from /home/arch/build/blaze-3.1/blaze/util/Serialization.h:43: /home/arch/build/blaze-3.1/blaze/util/serialization/Archive.h:323:12: error: no member named 'write' in 'std::basic_ifstream<char>' stream_.write( reinterpret_cast<const CharType*>( &value ), sizeof( T ) ); ~~~~~~~ ^
by the source file.
#include <blaze/Math.h> #include <blaze/Util.h> #include <iostream> #include <fstream> using blaze::StaticMatrix; using blaze::columnMajor; int main(){ StaticMatrix<double,5UL,5UL,columnMajor> A; blaze::Archive<std::ifstream> archive("matrix.blaze"); archive << A; return 0; }
-
reporter You are using the wrong stream-type. Since you are trying to write to a file you need an
std::ofstream
, not anstd::ifstream
.So the code should be
#include <blaze/Math.h> #include <blaze/Util.h> #include <fstream> using blaze::StaticMatrix; using blaze::columnMajor; int main(){ StaticMatrix<double,5UL,5UL,columnMajor> A; blaze::Archive<std::ofstream> archive("matrix.blaze"); archive << A; return 0; }
-
Thank you very much! I am sorry for asking a stupid question... I am new to C++.
- Log in to comment
https://bitbucket.org/blaze-lib/blaze/wiki/Vector%20Serialization
https://bitbucket.org/blaze-lib/blaze/wiki/Matrix%20Serialization
Aren't these url fulfilling your issue ?