Create vector/matrix from istream

Issue #102 wontfix
Jonas Glesaaen created an issue

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)

  1. Fabien Péan

    https://bitbucket.org/blaze-lib/blaze/wiki/Vector%20Serialization

    https://bitbucket.org/blaze-lib/blaze/wiki/Matrix%20Serialization

       // Creating an archive that reads from the file "vector.blaze"
       blaze::Archive<std::ifstream> archive( "vector.blaze" );
    
       // Reconstitution of the vector from the archive
       archive >> vec;
    
     // Creating an archive that reads from the file "matrices.blaze"
       blaze::Archive<std::ifstream> archive( "matrices.blaze" );
    
       // Reconstituting the former D matrix into D1. Note that it is possible to reconstitute
       // the matrix into a differrent kind of matrix (StaticMatrix -> DynamicMatrix), but that
       // the type of elements has to be the same.
       archive >> D1;
    

    Aren't these url fulfilling your issue ?

  2. Jonas Glesaaen 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.

  3. Klaus Iglberger

    Hi Jonas!

    We're glad you found what you were looking for. Fabien: Thanks for providing the links!

    Best regards,

    Klaus!

  4. yingboma

    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;
    }
    
  5. Jonas Glesaaen reporter

    You are using the wrong stream-type. Since you are trying to write to a file you need an std::ofstream, not an std::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;
    }
    
  6. Log in to comment