-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread_matrix.cpp
executable file
·72 lines (55 loc) · 2.04 KB
/
read_matrix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//-------------------------------------------------------------------------------------
// Copyright 2014 Michael Peeri
//
// This file is part of hmmdsl.
// hmmdsl is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// hmmdsl is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with hmmdsl. If not, see <http://www.gnu.org/licenses/>.
//-------------------------------------------------------------------------------------
#include "read_matrix.hpp"
namespace read_matrix
{
template<typename Scalar>
void read_matrix(const std::string& path, boost::multi_array<Scalar,2>& matrix)
{
using namespace spirit;
typedef boost::multi_array<Scalar,2> matrix_t;
plain_matrix_grammar_dispatchers::ParsingAdaptor<matrix_t> trans(matrix);
plain_matrix_grammar<matrix_t> g(trans);
iterator_t first(path);
iterator_t last = first.make_end();
parse_info<iterator_t> info = parse(first, last, g);
if( (!info.full) || (info.length == 0) )
{
std::cerr<< "Error: Input file "<< path<< " does not appear to be a valid fasta file!"<< std::endl;
assert(info.full);
}
}
template<typename Scalar>
Scalar test_read_matrix_sum(const std::string& path)
{
using namespace spirit;
typedef boost::multi_array<Scalar,2> matrix_t;
matrix_t matrix;
read_matrix(path, matrix);
Scalar sigma = 0.0;
const size_t m_end = matrix.shape()[0];
const size_t n_end = matrix.shape()[1];
for( size_t m=0; m< m_end; ++m )
for( size_t n=0; n< n_end; ++n )
{ sigma += matrix[m][n]; }
return sigma;
}
// Explicit instantiation
template
double test_read_matrix_sum<double>(const std::string& path);
} // namespace read_matrix