Skip to content

Commit a4a7b77

Browse files
authored
1493 Bindings for get_times() function (#1494)
Add bindings for the get_times() function from the TimeSeries class
1 parent c82e29a commit a4a7b77

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

pycode/memilio-simulation/memilio/simulation/bindings/utils/time_series.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ void bind_time_series(py::module_& m, std::string const& name)
112112
self.get_num_time_points());
113113
return Eigen::Ref<mio::TimeSeries<double>::Matrix>(m);
114114
},
115-
py::return_value_policy::reference_internal);
115+
py::return_value_policy::reference_internal)
116+
117+
.def("get_times", [](const mio::TimeSeries<double>& self) {
118+
auto times_range = self.get_times();
119+
std::vector<double> times(times_range.begin(), times_range.end());
120+
return times;
121+
});
116122
}
117123

118124
} // namespace pymio

pycode/memilio-simulation/tests/test_time_series.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ def test_print_table(self):
6969
self.assertEqual(
7070
output, '\nTime a \n2.00 1.00\n3.50 2.00\n')
7171

72+
def test_get_times(self):
73+
"""Test get_times method"""
74+
ts = mio.TimeSeries(1)
75+
ts.add_time_point(1.5, np.r_[10.0])
76+
ts.add_time_point(2.5, np.r_[20.0])
77+
times = ts.get_times()
78+
self.assertEqual(times, [1.5, 2.5])
79+
7280
def test_print_table_with_separator(self):
7381
"""Test print_table with custom separator"""
7482
ts = mio.TimeSeries(1)

0 commit comments

Comments
 (0)