23#include <boost/program_options.hpp>
24#include "arccore/alina/AlinaUtils.h"
25#include "arccore/alina/ValueTypeComplex.h"
26#include "arccore/alina/IO.h"
29namespace io = Alina::IO;
30namespace po = boost::program_options;
31using Alina::precondition;
37 std::ofstream f(ofile, std::ios::binary);
38 precondition(f,
"Failed to open output file for writing.");
42 std::vector<ptrdiff_t> ptr, col;
45 std::tie(rows, cols) = ifile(ptr, col, val);
47 precondition(io::write(f, rows),
"File I/O error.");
48 precondition(io::write(f, ptr),
"File I/O error.");
49 precondition(io::write(f, col),
"File I/O error.");
50 precondition(io::write(f, val),
"File I/O error.");
53 <<
"Wrote " << rows <<
" by " << cols <<
" sparse matrix, "
54 << ptr.back() <<
" nonzeros" << std::endl;
60 std::tie(rows, cols) = ifile(val);
62 precondition(io::write(f, rows),
"File I/O error.");
63 precondition(io::write(f, cols),
"File I/O error.");
64 precondition(io::write(f, val),
"File I/O error.");
67 <<
"Wrote " << rows <<
" by " << cols <<
" dense matrix"
73int main(
int argc,
char* argv[])
75 po::options_description desc(
"Options");
77 desc.add_options()(
"help,h",
"Show this help.")(
"input,i", po::value<std::string>()->required(),
78 "Input matrix in the MatrixMarket format.")(
"output,o", po::value<std::string>()->required(),
79 "Output binary file.");
82 po::store(po::parse_command_line(argc, argv, desc), vm);
84 if (vm.count(
"help")) {
85 std::cout << desc << std::endl;
91 io::mm_reader read(vm[
"input"].as<std::string>());
92 precondition(!read.is_integer(),
"Integer matrices are not supported!");
94 if (read.is_complex()) {
95 convert<std::complex<double>>(read, vm[
"output"].as<std::string>());
98 convert<double>(read, vm[
"output"].as<std::string>());
bool is_sparse() const
Matrix in the file is sparse.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-