Skip to content

Commit 6107ffa

Browse files
committed
Initial commit
0 parents  commit 6107ffa

File tree

109 files changed

+2390960
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2390960
-0
lines changed

.DS_Store

8 KB
Binary file not shown.

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

Annotation.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Created by Stephanos Tsoucas on 7/5/17.
3+
//
4+
5+
#ifndef BOOSTPYTHONHELLOWORLD_ANNOTATION_H
6+
#define BOOSTPYTHONHELLOWORLD_ANNOTATION_H
7+
8+
#include <armadillo>
9+
10+
using namespace arma;
11+
12+
class Annotation {
13+
14+
const vec bins;
15+
const vec domains;
16+
const mat &bin_data;
17+
const std::vector<std::pair<uword, uword>> anno;
18+
19+
public:
20+
Annotation(vec bin_state_distributions, vec domain_state_distributions,
21+
const mat &bin_data,
22+
const std::vector<std::pair<uword, uword>> &annotation_data)
23+
: bins(bin_state_distributions), domains(domain_state_distributions),
24+
bin_data(bin_data), anno(annotation_data) {}
25+
26+
const vec bin_state_coverage() const { return bins; }
27+
28+
const vec domain_state_coverage() const { return domains; }
29+
30+
const std::vector<std::pair<uword, uword>> &annotations() const {
31+
return anno;
32+
}
33+
};
34+
35+
#endif // BOOSTPYTHONHELLOWORLD_ANNOTATION_H

Annotation_Py.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Created by Stephanos Tsoucas on 7/5/17.
3+
//
4+
5+
#ifndef BOOSTPYTHONHELLOWORLD_ANNOTATION_PY_H
6+
#define BOOSTPYTHONHELLOWORLD_ANNOTATION_PY_H
7+
8+
#include "Annotation.h"
9+
#include "Arma_Numpy_Conversions.h"
10+
11+
class Annotation_Py {
12+
13+
const Annotation a;
14+
15+
public:
16+
Annotation_Py(const Annotation annotation) : a(annotation) {}
17+
18+
np::ndarray bin_state_distributions() {
19+
return from_vec(a.bin_state_coverage());
20+
}
21+
22+
np::ndarray domain_state_distributions() {
23+
return from_vec(a.domain_state_coverage());
24+
}
25+
26+
np::ndarray annotations() const { return from_vec_of_pairs(a.annotations()); }
27+
};
28+
29+
#endif // BOOSTPYTHONHELLOWORLD_ANNOTATION_PY_H

Arma_Numpy_Conversions.h

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// Created by Stephanos Tsoucas on 6/14/17.
3+
//
4+
5+
#ifndef BOOSTPYTHONHELLOWORLD_ARMA_NUMPY_CONVERSIONS_H
6+
#define BOOSTPYTHONHELLOWORLD_ARMA_NUMPY_CONVERSIONS_H
7+
8+
#include <armadillo>
9+
#include <boost/python.hpp>
10+
#include <boost/python/numpy.hpp>
11+
12+
namespace p = boost::python;
13+
namespace np = boost::python::numpy;
14+
namespace a = arma;
15+
16+
np::ndarray from_vec(const a::vec &v) {
17+
p::tuple shape = p::make_tuple(v.size());
18+
np::dtype dtype = np::dtype::get_builtin<double>();
19+
np::ndarray n = np::zeros(shape, dtype);
20+
21+
for (int i = 0; i < v.size(); i++) {
22+
n[i] = v(i);
23+
}
24+
25+
return n;
26+
}
27+
28+
np::ndarray from_mat(const a::mat &m) {
29+
p::tuple shape = p::make_tuple(m.n_rows, m.n_cols);
30+
np::dtype dtype = np::dtype::get_builtin<double>();
31+
np::ndarray n = np::zeros(shape, dtype);
32+
33+
for (int i = 0; i < m.n_rows; i++) {
34+
for (int j = 0; j < m.n_cols; j++) {
35+
n[i][j] = m(i, j);
36+
}
37+
}
38+
return n;
39+
}
40+
41+
np::ndarray from_cube(const a::cube &c) {
42+
p::tuple shape = p::make_tuple(c.n_slices, c.n_rows, c.n_cols);
43+
np::dtype dtype = np::dtype::get_builtin<double>();
44+
np::ndarray n = np::zeros(shape, dtype);
45+
46+
for (int slice = 0; slice < c.n_slices; slice++) {
47+
for (int i = 0; i < c.n_rows; i++) {
48+
for (int j = 0; j < c.n_cols; j++) {
49+
n[slice][i][j] = c(i, j, slice);
50+
}
51+
}
52+
}
53+
54+
return n;
55+
}
56+
57+
np::ndarray
58+
from_vec_of_pairs(const std::vector<std::pair<a::uword, a::uword>> &v) {
59+
p::tuple shape = p::make_tuple(v.size(), 2);
60+
np::dtype dtype = np::dtype::get_builtin<int>();
61+
np::ndarray n = np::zeros(shape, dtype);
62+
63+
for (int i = 0; i < v.size(); i++) {
64+
n[i][0] = v.at(i).first;
65+
n[i][1] = v.at(i).second;
66+
}
67+
68+
return n;
69+
}
70+
71+
#endif // BOOSTPYTHONHELLOWORLD_ARMA_NUMPY_CONVERSIONS_H

0 commit comments

Comments
 (0)