libsequence  1.9.5
VariantMatrixViews.cc
1 #include <Sequence/VariantMatrixViews.hpp>
2 #include <stdexcept>
3 
4 namespace
5 {
6  template <typename T, typename VM>
7  T
8  row_view_wrapper(VM& m, const std::size_t row)
9  {
10  if (row >= m.nsites)
11  {
12  throw std::out_of_range("row index out of range");
13  }
14  return T(m.data.data() + row * m.nsam, m.nsam);
15  }
16  template <typename T, typename VM>
17  T
18  col_view_wrapper(VM& m, const std::size_t col)
19  {
20  if (col >= m.nsam)
21  {
22  throw std::out_of_range("column index out of range");
23  }
24  return T(m.data.data() + col, m.nsam * m.nsites, m.nsam);
25  }
26 }
27 
28 namespace Sequence
29 {
30 
32  get_RowView(const VariantMatrix& m, const std::size_t row)
33  {
34  return row_view_wrapper<ConstRowView>(m, row);
35  }
36 
37  RowView
38  get_RowView(VariantMatrix& m, const std::size_t row)
39  {
40  return row_view_wrapper<RowView>(m, row);
41  }
42 
44  get_ConstRowView(const VariantMatrix& m, const std::size_t row)
45  {
46  return row_view_wrapper<ConstRowView>(m, row);
47  }
48 
50  get_ConstRowView(VariantMatrix& m, const std::size_t row)
51  {
52  return row_view_wrapper<ConstRowView>(m, row);
53  }
54 
55  ColView
56  get_ColView(VariantMatrix& m, const std::size_t col)
57  {
58  return col_view_wrapper<ColView>(m, col);
59  }
61  get_ColView(const VariantMatrix& m, const std::size_t col)
62  {
63  return col_view_wrapper<ConstColView>(m, col);
64  }
66  get_ConstColView(VariantMatrix& m, const std::size_t col)
67  {
68  return col_view_wrapper<ConstColView>(m, col);
69  }
71  get_ConstColView(const VariantMatrix& m, const std::size_t col)
72  {
73  return col_view_wrapper<ConstColView>(m, col);
74  }
75 }
Implementation details for Sequence::RowView and Sequence::ConstRowView.
internal::row_view_< const std::int8_t * > ConstRowView
Const view of a VariantMatrix row (a variable site)
The namespace in which this library resides.
ConstRowView get_RowView(const VariantMatrix &m, const std::size_t row)
Return a ConstRowView from VariantMatrix m at row row. std::out_of_range is thrown if row is out of r...
ConstRowView get_ConstRowView(const VariantMatrix &m, const std::size_t row)
Return a ConstRowView from VariantMatrix m at row row. std::out_of_range is thrown if row is out of r...
Matrix representation of variation data.
ColView get_ColView(VariantMatrix &m, const std::size_t col)
Return a ColView from VariantMatrix m at col col. std::out_of_range is thcoln if col is out of range...
ConstColView get_ConstColView(VariantMatrix &m, const std::size_t col)
Return a ConstColView from VariantMatrix m at col col. std::out_of_range is thcoln if col is out of r...
Implementation details for Sequence::ColView and Sequence::ConstColView.