-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreadth_cpp.cpp
More file actions
31 lines (29 loc) · 906 Bytes
/
Copy pathbreadth_cpp.cpp
File metadata and controls
31 lines (29 loc) · 906 Bytes
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
#include <gsl/gsl_math.h>
#include "bct_test.h"
DEFUN_DLD(breadth_cpp, args, , "Wrapper for C++ function.") {
if (args.length() != 2) {
return octave_value_list();
}
Matrix CIJ = args(0).matrix_value();
int source = args(1).int_value() - 1;
if (!error_state) {
gsl_matrix* CIJ_gsl = bct_test::to_gslm(CIJ);
gsl_vector* branch;
gsl_vector* distance = bct::breadth(CIJ_gsl, source, &branch);
for (int i = 0; i < (int)branch->size; i++) {
int value = (int)gsl_vector_get(branch, i);
if (gsl_isinf(gsl_vector_get(distance, i)) == 0 && value != -1) {
gsl_vector_set(branch, i, (double)value + 1.0);
}
}
octave_value_list ret;
ret(0) = octave_value(bct_test::from_gsl(distance));
ret(1) = octave_value(bct_test::from_gsl(branch));
gsl_matrix_free(CIJ_gsl);
gsl_vector_free(branch);
gsl_vector_free(distance);
return ret;
} else {
return octave_value_list();
}
}