Skip to content

Commit db451b5

Browse files
committed
Renames variables
1 parent 03f3259 commit db451b5

3 files changed

Lines changed: 70 additions & 69 deletions

File tree

‎cpp/rat.cpp‎

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,38 @@ class Library: public CallbackInterface
3737

3838
void setOutput(py::tuple& result, std::vector<double>& output, double *outputSize)
3939
{
40-
int n_rows = 0, idx = 0;
41-
for (py::handle row_handle : result[0])
40+
int nRows = 0, idx = 0;
41+
for (py::handle rowHandle : result[0])
4242
{
43-
py::list rows = py::cast<py::list>(row_handle);
43+
py::list rows = py::cast<py::list>(rowHandle);
4444
for (py::handle value : rows)
4545
{
4646
output.push_back(py::cast<double>(value));
4747
idx++;
4848
}
49-
n_rows++;
49+
nRows++;
5050
}
5151

52-
outputSize[0] = n_rows;
53-
outputSize[1] = (n_rows == 0) ? 0 : idx / n_rows;
52+
outputSize[0] = nRows;
53+
outputSize[1] = (nRows == 0) ? 0 : idx / nRows;
5454
}
5555

5656
// Domain overload
57-
void invoke(std::vector<double>& params, std::vector<double>& bulk_in, std::vector<double>& bulk_out,
57+
void invoke(std::vector<double>& params, std::vector<double>& bulkIn, std::vector<double>& bulkOut,
5858
int contrast, int domainNumber, std::vector<double>& output, double *outputSize, double *roughness)
5959
{
6060
auto f = py::cast<std::function<py::tuple(py::list, py::list, py::list, int, int)>>(this->function);
61-
auto result = f(py::cast(params), py::cast(bulk_in), py::cast(bulk_out), contrast, domainNumber);
61+
auto result = f(py::cast(params), py::cast(bulkIn), py::cast(bulkOut), contrast, domainNumber);
6262
*roughness = py::cast<double>(result[1]);
6363
setOutput(result, output, outputSize);
6464
};
6565

6666
// Non-Domain overload
67-
void invoke(std::vector<double>& params, std::vector<double>& bulk_in, std::vector<double>& bulk_out,
67+
void invoke(std::vector<double>& params, std::vector<double>& bulkIn, std::vector<double>& bulkOut,
6868
int contrast, std::vector<double>& output, double *outputSize, double *roughness)
6969
{
7070
auto f = py::cast<std::function<py::tuple(py::list, py::list, py::list, int)>>(this->function);
71-
auto result = f(py::cast(params), py::cast(bulk_in), py::cast(bulk_out), contrast);
71+
auto result = f(py::cast(params), py::cast(bulkIn), py::cast(bulkOut), contrast);
7272
*roughness = py::cast<double>(result[1]);
7373
setOutput(result, output, outputSize);
7474
};
@@ -93,7 +93,7 @@ class DylibEngine
9393

9494
~DylibEngine(){};
9595

96-
py::tuple invoke(std::vector<double>& params, std::vector<double>& bulk_in, std::vector<double>& bulk_out, int contrast, int domain=DEFAULT_DOMAIN)
96+
py::tuple invoke(std::vector<double>& params, std::vector<double>& bulkIn, std::vector<double>& bulkOut, int contrast, int domain=DEFAULT_DOMAIN)
9797
{
9898
try{
9999
std::vector<double> tempOutput;
@@ -103,12 +103,12 @@ class DylibEngine
103103
if (domain != -1) {
104104
auto func = library->get_function<void(std::vector<double>&, std::vector<double>&, std::vector<double>&,
105105
int, int, std::vector<double>&, double*, double*)>(functionName);
106-
func(params, bulk_in, bulk_out, contrast, domain, tempOutput, outputSize, &roughness);
106+
func(params, bulkIn, bulkOut, contrast, domain, tempOutput, outputSize, &roughness);
107107
}
108108
else {
109109
auto func = library->get_function<void(std::vector<double>&, std::vector<double>&, std::vector<double>&,
110110
int, std::vector<double>&, double*, double*)>(functionName);
111-
func(params, bulk_in, bulk_out, contrast, tempOutput, outputSize, &roughness);
111+
func(params, bulkIn, bulkOut, contrast, tempOutput, outputSize, &roughness);
112112
}
113113

114114
py::list output;
@@ -142,13 +142,13 @@ struct PlotEventData
142142
std::string modelType;
143143
};
144144

145-
class EventStuff
145+
class EventBridge
146146
{
147147
public:
148148
std::unique_ptr<dylib> library;
149149
py::function callback;
150150

151-
EventStuff(py::function callback)
151+
EventBridge(py::function callback)
152152
{
153153
std::string filename = "eventManager" + std::string(dylib::extension);
154154
this->library = std::unique_ptr<dylib>(new dylib(std::getenv("RAT_PATH"), filename.c_str()));
@@ -233,7 +233,7 @@ class EventStuff
233233

234234
void registerEvent(EventTypes eventType)
235235
{
236-
std::function<void(const baseEvent& event)> caller = std::bind(&EventStuff::eventCallback, this, std::placeholders::_1);
236+
std::function<void(const baseEvent& event)> caller = std::bind(&EventBridge::eventCallback, this, std::placeholders::_1);
237237
auto addListener = library->get_function<void(EventTypes, std::function<void(const baseEvent&)>)>("addListener");
238238
addListener(eventType, caller);
239239
};
@@ -577,7 +577,7 @@ coder::array<real_T, 2U> pyArrayToRatArray2d(py::array_t<real_T> value)
577577
return result;
578578
}
579579

580-
coder::array<RAT::cell_0, 1U> py_array_to_unboundedx1_cell_0(py::list values)
580+
coder::array<RAT::cell_0, 1U> pyListToUnboundedCell0(py::list values)
581581
{
582582
coder::array<RAT::cell_0, 1U> result;
583583
result.set_size(values.size());
@@ -597,7 +597,7 @@ coder::array<RAT::cell_0, 1U> py_array_to_unboundedx1_cell_0(py::list values)
597597
return result;
598598
}
599599

600-
coder::array<RAT::cell_wrap_1, 1U> py_array_to_unboundedx1_cell_1(py::list values)
600+
coder::array<RAT::cell_wrap_1, 1U> pyListToUnboundedCell1(py::list values)
601601
{
602602
coder::array<RAT::cell_wrap_1, 1U> result;
603603
result.set_size(values.size());
@@ -613,7 +613,7 @@ coder::array<RAT::cell_wrap_1, 1U> py_array_to_unboundedx1_cell_1(py::list value
613613
return result;
614614
}
615615

616-
RAT::struct0_T createStruct0_T(const ProblemDefinition& problem)
616+
RAT::struct0_T createStruct0(const ProblemDefinition& problem)
617617
{
618618
RAT::struct0_T problem_struct;
619619

@@ -657,7 +657,7 @@ RAT::struct0_T createStruct0_T(const ProblemDefinition& problem)
657657
return problem_struct;
658658
}
659659

660-
RAT::struct1_T createStruct1T(const Limits& limits)
660+
RAT::struct1_T createStruct1(const Limits& limits)
661661
{
662662
RAT::struct1_T limits_struct;
663663
limits_struct.param = pyArrayToRatArray2d(limits.param);
@@ -672,7 +672,7 @@ RAT::struct1_T createStruct1T(const Limits& limits)
672672
return limits_struct;
673673
}
674674

675-
RAT::struct3_T create_struct3_T(const Checks& checks)
675+
RAT::struct3_T createStruct3(const Checks& checks)
676676
{
677677
RAT::struct3_T checks_struct;
678678
checks_struct.fitParam = pyArrayToRatArray1d(checks.fitParam);
@@ -687,24 +687,24 @@ RAT::struct3_T create_struct3_T(const Checks& checks)
687687
return checks_struct;
688688
}
689689

690-
RAT::struct4_T createStruct4T(const Priors& priors)
690+
RAT::struct4_T createStruct4(const Priors& priors)
691691
{
692692
RAT::struct4_T priors_struct;
693-
priors_struct.param = py_array_to_unboundedx1_cell_0(priors.param);
694-
priors_struct.backgroundParam = py_array_to_unboundedx1_cell_0(priors.backgroundParam);
695-
priors_struct.resolutionParam = py_array_to_unboundedx1_cell_0(priors.resolutionParam);
696-
priors_struct.qzshift = py_array_to_unboundedx1_cell_0(priors.qzshift);
697-
priors_struct.scalefactor = py_array_to_unboundedx1_cell_0(priors.scalefactor);
698-
priors_struct.bulkIn = py_array_to_unboundedx1_cell_0(priors.bulkIn);
699-
priors_struct.bulkOut = py_array_to_unboundedx1_cell_0(priors.bulkOut);
700-
priors_struct.domainRatio = py_array_to_unboundedx1_cell_0(priors.domainRatio);
701-
priors_struct.priorNames = py_array_to_unboundedx1_cell_1(priors.priorNames);
693+
priors_struct.param = pyListToUnboundedCell0(priors.param);
694+
priors_struct.backgroundParam = pyListToUnboundedCell0(priors.backgroundParam);
695+
priors_struct.resolutionParam = pyListToUnboundedCell0(priors.resolutionParam);
696+
priors_struct.qzshift = pyListToUnboundedCell0(priors.qzshift);
697+
priors_struct.scalefactor = pyListToUnboundedCell0(priors.scalefactor);
698+
priors_struct.bulkIn = pyListToUnboundedCell0(priors.bulkIn);
699+
priors_struct.bulkOut = pyListToUnboundedCell0(priors.bulkOut);
700+
priors_struct.domainRatio = pyListToUnboundedCell0(priors.domainRatio);
701+
priors_struct.priorNames = pyListToUnboundedCell1(priors.priorNames);
702702
priors_struct.priorValues = pyArrayToRatArray2d(priors.priorValues);
703703

704704
return priors_struct;
705705
}
706706

707-
coder::array<RAT::cell_wrap_2, 2U> py_array_to_rat_cell_wrap_2(py::list values)
707+
coder::array<RAT::cell_wrap_2, 2U> pyListToRatCellWrap2(py::list values)
708708
{
709709
coder::array<RAT::cell_wrap_2, 2U> result;
710710
result.set_size(1, values.size());
@@ -720,7 +720,7 @@ coder::array<RAT::cell_wrap_2, 2U> py_array_to_rat_cell_wrap_2(py::list values)
720720
return result;
721721
}
722722

723-
coder::array<RAT::cell_wrap_3, 2U> py_array_to_rat_cell_wrap_3(py::list values)
723+
coder::array<RAT::cell_wrap_3, 2U> pyListToRatCellWrap3(py::list values)
724724
{
725725
coder::array<RAT::cell_wrap_3, 2U> result;
726726
result.set_size(1, values.size());
@@ -735,7 +735,7 @@ coder::array<RAT::cell_wrap_3, 2U> py_array_to_rat_cell_wrap_3(py::list values)
735735
return result;
736736
}
737737

738-
coder::array<RAT::cell_wrap_4, 2U> py_array_to_rat_cell_wrap_4(py::list values)
738+
coder::array<RAT::cell_wrap_4, 2U> pyListToRatCellWrap4(py::list values)
739739
{
740740
coder::array<RAT::cell_wrap_4, 2U> result;
741741
result.set_size(1, values.size());
@@ -750,7 +750,7 @@ coder::array<RAT::cell_wrap_4, 2U> py_array_to_rat_cell_wrap_4(py::list values)
750750
return result;
751751
}
752752

753-
coder::array<RAT::cell_wrap_5, 1U> py_array_to_rat_cell_wrap_5(py::list values)
753+
coder::array<RAT::cell_wrap_5, 1U> pyListToRatCellWrap5(py::list values)
754754
{
755755
coder::array<RAT::cell_wrap_5, 1U> result;
756756
result.set_size(values.size());
@@ -765,7 +765,7 @@ coder::array<RAT::cell_wrap_5, 1U> py_array_to_rat_cell_wrap_5(py::list values)
765765
return result;
766766
}
767767

768-
coder::array<RAT::cell_wrap_6, 2U> py_array_to_rat_cell_wrap_6(py::list values)
768+
coder::array<RAT::cell_wrap_6, 2U> pyListToRatCellWrap6(py::list values)
769769
{
770770
coder::array<RAT::cell_wrap_6, 2U> result;
771771
result.set_size(1, values.size());
@@ -799,26 +799,26 @@ coder::array<RAT::cell_wrap_6, 2U> py_function_array_to_rat_cell_wrap_6(py::list
799799
RAT::cell_7 createCell7(const Cells& cells)
800800
{
801801
RAT::cell_7 cells_struct;
802-
cells_struct.f1 = py_array_to_rat_cell_wrap_2(cells.f1);
803-
cells_struct.f2 = py_array_to_rat_cell_wrap_3(cells.f2);
804-
cells_struct.f3 = py_array_to_rat_cell_wrap_2(cells.f3);
805-
cells_struct.f4 = py_array_to_rat_cell_wrap_2(cells.f4);
806-
cells_struct.f5 = py_array_to_rat_cell_wrap_4(cells.f5);
807-
cells_struct.f6 = py_array_to_rat_cell_wrap_5(cells.f6);
808-
cells_struct.f7 = py_array_to_rat_cell_wrap_6(cells.f7);
809-
cells_struct.f8 = py_array_to_rat_cell_wrap_6(cells.f8);
810-
cells_struct.f9 = py_array_to_rat_cell_wrap_6(cells.f9);
811-
cells_struct.f10 = py_array_to_rat_cell_wrap_6(cells.f10);
812-
cells_struct.f11 = py_array_to_rat_cell_wrap_6(cells.f11);
813-
cells_struct.f12 = py_array_to_rat_cell_wrap_6(cells.f12);
814-
cells_struct.f13 = py_array_to_rat_cell_wrap_6(cells.f13);
802+
cells_struct.f1 = pyListToRatCellWrap2(cells.f1);
803+
cells_struct.f2 = pyListToRatCellWrap3(cells.f2);
804+
cells_struct.f3 = pyListToRatCellWrap2(cells.f3);
805+
cells_struct.f4 = pyListToRatCellWrap2(cells.f4);
806+
cells_struct.f5 = pyListToRatCellWrap4(cells.f5);
807+
cells_struct.f6 = pyListToRatCellWrap5(cells.f6);
808+
cells_struct.f7 = pyListToRatCellWrap6(cells.f7);
809+
cells_struct.f8 = pyListToRatCellWrap6(cells.f8);
810+
cells_struct.f9 = pyListToRatCellWrap6(cells.f9);
811+
cells_struct.f10 = pyListToRatCellWrap6(cells.f10);
812+
cells_struct.f11 = pyListToRatCellWrap6(cells.f11);
813+
cells_struct.f12 = pyListToRatCellWrap6(cells.f12);
814+
cells_struct.f13 = pyListToRatCellWrap6(cells.f13);
815815
cells_struct.f14 = py_function_array_to_rat_cell_wrap_6(cells.f14);
816-
cells_struct.f15 = py_array_to_rat_cell_wrap_6(cells.f15);
817-
cells_struct.f16 = py_array_to_rat_cell_wrap_6(cells.f16);
818-
cells_struct.f17 = py_array_to_rat_cell_wrap_3(cells.f17);
819-
cells_struct.f18 = py_array_to_rat_cell_wrap_2(cells.f18);
820-
cells_struct.f19 = py_array_to_rat_cell_wrap_4(cells.f19);
821-
cells_struct.f20 = py_array_to_rat_cell_wrap_6(cells.f20);
816+
cells_struct.f15 = pyListToRatCellWrap6(cells.f15);
817+
cells_struct.f16 = pyListToRatCellWrap6(cells.f16);
818+
cells_struct.f17 = pyListToRatCellWrap3(cells.f17);
819+
cells_struct.f18 = pyListToRatCellWrap2(cells.f18);
820+
cells_struct.f19 = pyListToRatCellWrap4(cells.f19);
821+
cells_struct.f20 = pyListToRatCellWrap6(cells.f20);
822822

823823
return cells_struct;
824824
}
@@ -854,7 +854,7 @@ RAT::struct2_T createStruct2T(const Control& control)
854854
control_struct.resamPars[1] = control.resamPars.at(1);
855855
stringToRatArray(control.boundHandling, control_struct.boundHandling.data, control_struct.boundHandling.size);
856856
control_struct.adaptPCR = control.adaptPCR;
857-
control_struct.checks = create_struct3_T(control.checks);
857+
control_struct.checks = createStruct3(control.checks);
858858

859859
return control_struct;
860860
}
@@ -1176,11 +1176,11 @@ BayesResults bayesResultsFromStruct7T(const RAT::struct7_T results)
11761176
py::tuple RATMain(const ProblemDefinition& problem_def, const Cells& cells, const Limits& limits, const Control& control,
11771177
const Priors& priors)
11781178
{
1179-
RAT::struct0_T problem_def_struct = createStruct0T(problem_def);
1179+
RAT::struct0_T problem_def_struct = createStruct0(problem_def);
11801180
RAT::cell_7 cells_struct = createCell7(cells);
1181-
RAT::struct1_T limits_struct = createStruct1T(limits);
1181+
RAT::struct1_T limits_struct = createStruct1(limits);
11821182
RAT::struct2_T control_struct = createStruct2T(control);
1183-
RAT::struct4_T priors_struct = createStruct4T(priors);
1183+
RAT::struct4_T priors_struct = createStruct4(priors);
11841184

11851185
RAT::cell_wrap_9 results[6];
11861186
RAT::struct5_T problem;
@@ -1211,19 +1211,19 @@ class Module
12111211

12121212
PYBIND11_MODULE(rat_core, m) {
12131213
static Module module;
1214-
py::class_<EventStuff>(m, "EventStuff")
1214+
py::class_<EventBridge>(m, "EventBridge")
12151215
.def(py::init<py::function>())
1216-
.def("register", &EventStuff::registerEvent)
1217-
.def("clear", &EventStuff::clear);
1216+
.def("register", &EventBridge::registerEvent)
1217+
.def("clear", &EventBridge::clear);
12181218

12191219
py::enum_<EventTypes>(m, "EventTypes")
12201220
.value("Message", EventTypes::Message)
12211221
.value("Plot", EventTypes::Plot);
12221222

12231223
py::class_<DylibEngine>(m, "DylibEngine")
12241224
.def(py::init<std::string, std::string>())
1225-
.def("invoke", &DylibEngine::invoke, py::arg("params"), py::arg("bulk_in"),
1226-
py::arg("bulk_out"), py::arg("contrast"),
1225+
.def("invoke", &DylibEngine::invoke, py::arg("params"), py::arg("bulkIn"),
1226+
py::arg("bulkOut"), py::arg("contrast"),
12271227
py::arg("domain") = DEFAULT_DOMAIN);
12281228

12291229
py::class_<Predlims>(m, "Predlims")

‎examples/DSPC_custom_layers_example.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def fakePlot(event):
175175

176176
import time
177177
start = time.perf_counter()
178-
events.register(rat_core.EventTypes.Plot, fakePlot)
178+
events.register(events.EventTypes.Plot, fakePlot)
179179
problem, contrast_params, result, bayes_results = rat_core.RATMain(problem, cells, limits, control, priors)
180180
events.clear()
181181
print(time.perf_counter() - start, 'sec')

‎rat/events.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from rat import rat_core
2+
from rat.rat_core import EventTypes
23

34

45
def nofiy(event_type, data):
@@ -8,8 +9,8 @@ def nofiy(event_type, data):
89

910

1011
def register(event_type, callback):
11-
if not isinstance(event_type, rat_core.EventTypes):
12-
raise ValueError("event_type must be a rat_core.EventTypes enum")
12+
if not isinstance(event_type, EventTypes):
13+
raise ValueError("event_type must be a events.EventTypes enum")
1314

1415
if len(__event_callbacks[event_type]) == 0:
1516
__event_impl.register(event_type)
@@ -21,5 +22,5 @@ def clear():
2122
__event_callbacks.clear()
2223

2324

24-
__event_impl = rat_core.EventStuff(nofiy)
25-
__event_callbacks = {rat_core.EventTypes.Message: set(), rat_core.EventTypes.Plot: set()}
25+
__event_impl = rat_core.EventBridge(nofiy)
26+
__event_callbacks = {EventTypes.Message: set(), EventTypes.Plot: set()}

0 commit comments

Comments
 (0)