Skip to content

Commit 07d9239

Browse files
committed
more copy dunders
1 parent ac5d49b commit 07d9239

4 files changed

Lines changed: 98 additions & 0 deletions

File tree

src/distributions.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ struct declare_integral_distributions {
2929
nb::call_guard<nb::gil_scoped_release>())
3030
.def("p", &std::geometric_distribution<ResultType>::p,
3131
nb::call_guard<nb::gil_scoped_release>())
32+
.def("__copy__", [](const std::geometric_distribution<ResultType>& self) {
33+
return std::geometric_distribution<ResultType>(self);
34+
}).def("__deepcopy__", [](
35+
const std::geometric_distribution<ResultType>& self, nb::dict) {
36+
return std::geometric_distribution<ResultType>(self);
37+
}, "memo"_a)
3238
.def("__repr__", [](const std::geometric_distribution<ResultType>& a) {
3339
return fmt::format("{}", a);
3440
}).def_static("__class_repr__", []() {
@@ -49,6 +55,12 @@ struct declare_integral_distributions {
4955
delta.def(nb::init<ResultType>(), "mean"_a)
5056
.def("mean", &reticula::delta_distribution<ResultType>::mean,
5157
nb::call_guard<nb::gil_scoped_release>())
58+
.def("__copy__", [](const reticula::delta_distribution<ResultType>& self) {
59+
return reticula::delta_distribution<ResultType>(self);
60+
}).def("__deepcopy__", [](
61+
const reticula::delta_distribution<ResultType>& self, nb::dict) {
62+
return reticula::delta_distribution<ResultType>(self);
63+
}, "memo"_a)
5264
.def("__repr__", [](
5365
const reticula::delta_distribution<ResultType>& a) {
5466
return fmt::format("{}", a);
@@ -72,6 +84,12 @@ struct declare_integral_distributions {
7284
nb::call_guard<nb::gil_scoped_release>())
7385
.def("b", &std::uniform_int_distribution<ResultType>::b,
7486
nb::call_guard<nb::gil_scoped_release>())
87+
.def("__copy__", [](const std::uniform_int_distribution<ResultType>& self) {
88+
return std::uniform_int_distribution<ResultType>(self);
89+
}).def("__deepcopy__", [](
90+
const std::uniform_int_distribution<ResultType>& self, nb::dict) {
91+
return std::uniform_int_distribution<ResultType>(self);
92+
}, "memo"_a)
7593
.def("__repr__", [](
7694
const std::uniform_int_distribution<ResultType>& a) {
7795
return fmt::format("{}", a);
@@ -98,6 +116,12 @@ struct declare_floating_point_distributions {
98116
nb::call_guard<nb::gil_scoped_release>())
99117
.def("lmbda", &std::exponential_distribution<ResultType>::lambda,
100118
nb::call_guard<nb::gil_scoped_release>())
119+
.def("__copy__", [](const std::exponential_distribution<ResultType>& self) {
120+
return std::exponential_distribution<ResultType>(self);
121+
}).def("__deepcopy__", [](
122+
const std::exponential_distribution<ResultType>& self, nb::dict) {
123+
return std::exponential_distribution<ResultType>(self);
124+
}, "memo"_a)
101125
.def("__repr__", [](
102126
const std::exponential_distribution<ResultType>& a) {
103127
return fmt::format("{}", a);
@@ -124,6 +148,14 @@ struct declare_floating_point_distributions {
124148
.def("mean",
125149
&reticula::power_law_with_specified_mean<ResultType>::mean,
126150
nb::call_guard<nb::gil_scoped_release>())
151+
.def("__copy__", [](
152+
const reticula::power_law_with_specified_mean<ResultType>& self) {
153+
return reticula::power_law_with_specified_mean<ResultType>(self);
154+
}).def("__deepcopy__", [](
155+
const reticula::power_law_with_specified_mean<ResultType>& self,
156+
nb::dict) {
157+
return reticula::power_law_with_specified_mean<ResultType>(self);
158+
}, "memo"_a)
127159
.def("__repr__", [](
128160
const reticula::power_law_with_specified_mean<ResultType>& a) {
129161
return fmt::format("{}", a);
@@ -153,6 +185,14 @@ struct declare_floating_point_distributions {
153185
.def("mean",
154186
&reticula::residual_power_law_with_specified_mean<ResultType>::mean,
155187
nb::call_guard<nb::gil_scoped_release>())
188+
.def("__copy__", [](
189+
const reticula::residual_power_law_with_specified_mean<ResultType>& self) {
190+
return reticula::residual_power_law_with_specified_mean<ResultType>(self);
191+
}).def("__deepcopy__", [](
192+
const reticula::residual_power_law_with_specified_mean<ResultType>& self,
193+
nb::dict) {
194+
return reticula::residual_power_law_with_specified_mean<ResultType>(self);
195+
}, "memo"_a)
156196
.def("__repr__", [](
157197
const reticula::residual_power_law_with_specified_mean<
158198
ResultType>& a) {
@@ -188,6 +228,14 @@ struct declare_floating_point_distributions {
188228
.def("phi",
189229
&reticula::hawkes_univariate_exponential<ResultType>::phi,
190230
nb::call_guard<nb::gil_scoped_release>())
231+
.def("__copy__", [](
232+
const reticula::hawkes_univariate_exponential<ResultType>& self) {
233+
return reticula::hawkes_univariate_exponential<ResultType>(self);
234+
}).def("__deepcopy__", [](
235+
const reticula::hawkes_univariate_exponential<ResultType>& self,
236+
nb::dict) {
237+
return reticula::hawkes_univariate_exponential<ResultType>(self);
238+
}, "memo"_a)
191239
.def("__repr__", [](
192240
const reticula::hawkes_univariate_exponential<ResultType>& a) {
193241
return fmt::format("{}", a);
@@ -208,6 +256,12 @@ struct declare_floating_point_distributions {
208256
nb::call_guard<nb::gil_scoped_release>())
209257
.def("mean", &reticula::delta_distribution<ResultType>::mean,
210258
nb::call_guard<nb::gil_scoped_release>())
259+
.def("__copy__", [](const reticula::delta_distribution<ResultType>& self) {
260+
return reticula::delta_distribution<ResultType>(self);
261+
}).def("__deepcopy__", [](
262+
const reticula::delta_distribution<ResultType>& self, nb::dict) {
263+
return reticula::delta_distribution<ResultType>(self);
264+
}, "memo"_a)
211265
.def("__repr__", [](
212266
const reticula::delta_distribution<ResultType>& a) {
213267
return fmt::format("{}", a);
@@ -231,6 +285,12 @@ struct declare_floating_point_distributions {
231285
nb::call_guard<nb::gil_scoped_release>())
232286
.def("b", &std::uniform_real_distribution<ResultType>::b,
233287
nb::call_guard<nb::gil_scoped_release>())
288+
.def("__copy__", [](const std::uniform_real_distribution<ResultType>& self) {
289+
return std::uniform_real_distribution<ResultType>(self);
290+
}).def("__deepcopy__", [](
291+
const std::uniform_real_distribution<ResultType>& self, nb::dict) {
292+
return std::uniform_real_distribution<ResultType>(self);
293+
}, "memo"_a)
234294
.def("__repr__", [](
235295
const std::uniform_real_distribution<ResultType>& a) {
236296
return fmt::format("{}", a);

src/implicit_event_graphs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ struct declare_implicit_event_graph_class {
5959
&Net::neighbours,
6060
"event"_a, "just_first"_a = true,
6161
nb::call_guard<nb::gil_scoped_release>())
62+
.def("__copy__", [](const Net& self) {
63+
return Net(self);
64+
}).def("__deepcopy__", [](const Net& self, nb::dict) {
65+
return Net(self);
66+
}, "memo"_a)
6267
.def("__repr__", [](const Net& a) {
6368
return fmt::format("{}", a);
6469
}).def_static("edge_type", []() {

src/interval_sets.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ struct declare_interval_set_types {
4747
nb::call_guard<nb::gil_scoped_release>())
4848
.def(nb::self == nb::self,
4949
nb::call_guard<nb::gil_scoped_release>())
50+
.def("__copy__", [](const IntSet& self) {
51+
return IntSet(self);
52+
}).def("__deepcopy__", [](const IntSet& self, nb::dict) {
53+
return IntSet(self);
54+
}, "memo"_a)
5055
.def("__repr__", [](const IntSet& c) {
5156
return fmt::format("{}", c);
5257
}).def_static("value_type", []() {

src/temporal_adjacency.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ struct declare_temporal_adjacency_class {
2727
return types::handle_for<typename Simple::EdgeType>();
2828
}).def_static("vertex_type", []() {
2929
return types::handle_for<typename Simple::VertexType>();
30+
}).def("__copy__", [](const Simple& self) {
31+
return Simple(self);
32+
}).def("__deepcopy__", [](const Simple& self, nb::dict) {
33+
return Simple(self);
34+
}, "memo"_a)
35+
.def("__repr__", [](const Simple& a) {
36+
return fmt::format("{}", a);
3037
}).def_static("__class_repr__", []() {
3138
return fmt::format("<class '{}'>", type_str<Simple>{}());
3239
}).def_static("__class_name__", []() {
@@ -52,6 +59,13 @@ struct declare_temporal_adjacency_class {
5259
return types::handle_for<typename LWT::EdgeType>();
5360
}).def_static("vertex_type", []() {
5461
return types::handle_for<typename LWT::VertexType>();
62+
}).def("__copy__", [](const LWT& self) {
63+
return LWT(self);
64+
}).def("__deepcopy__", [](const LWT& self, nb::dict) {
65+
return LWT(self);
66+
}, "memo"_a)
67+
.def("__repr__", [](const LWT& a) {
68+
return fmt::format("{}", a);
5569
}).def_static("__class_repr__", []() {
5670
return fmt::format("<class '{}'>", type_str<LWT>{}());
5771
}).def_static("__class_name__", []() {
@@ -78,6 +92,13 @@ struct declare_temporal_adjacency_class {
7892
return types::handle_for<typename Exp::EdgeType>();
7993
}).def_static("vertex_type", []() {
8094
return types::handle_for<typename Exp::VertexType>();
95+
}).def("__copy__", [](const Exp& self) {
96+
return Exp(self);
97+
}).def("__deepcopy__", [](const Exp& self, nb::dict) {
98+
return Exp(self);
99+
}, "memo"_a)
100+
.def("__repr__", [](const Exp& a) {
101+
return fmt::format("{}", a);
81102
}).def_static("__class_repr__", []() {
82103
return fmt::format("<class '{}'>", type_str<Exp>{}());
83104
}).def_static("__class_name__", []() {
@@ -105,6 +126,13 @@ struct declare_temporal_adjacency_class {
105126
return types::handle_for<typename Geom::EdgeType>();
106127
}).def_static("vertex_type", []() {
107128
return types::handle_for<typename Geom::VertexType>();
129+
}).def("__copy__", [](const Geom& self) {
130+
return Geom(self);
131+
}).def("__deepcopy__", [](const Geom& self, nb::dict) {
132+
return Geom(self);
133+
}, "memo"_a)
134+
.def("__repr__", [](const Geom& a) {
135+
return fmt::format("{}", a);
108136
}).def_static("__class_repr__", []() {
109137
return fmt::format("<class '{}'>", type_str<Geom>{}());
110138
}).def_static("__class_name__", []() {

0 commit comments

Comments
 (0)