@@ -519,6 +519,7 @@ struct Control {
519519 std::string boundHandling {};
520520 boolean_T adaptPCR;
521521 Checks checks {};
522+ std::string IPCFilePath {};
522523};
523524
524525
@@ -541,7 +542,27 @@ void stringToRatCharArray(std::string value, coder::array<char_T, 2U>& result)
541542 }
542543}
543544
544- coder::array<real_T, 2U > pyArrayToRatArray1d (py::array_t <real_T> value)
545+ coder::array<real_T, 1U > pyArrayToRatRowArray1d (py::array_t <real_T> value)
546+ {
547+ coder::array<real_T, 1U > result;
548+
549+ py::buffer_info buffer_info = value.request ();
550+
551+ if (buffer_info.size == 0 )
552+ return result;
553+
554+ if (buffer_info.ndim != 1 )
555+ throw std::runtime_error (" Expects a 1D numeric array" );
556+
557+ result.set_size (buffer_info.shape [0 ]);
558+ for (int32_T idx0{0 }; idx0 < buffer_info.shape [0 ]; idx0++) {
559+ result[idx0] = value.at (idx0);
560+ }
561+
562+ return result;
563+ }
564+
565+ coder::array<real_T, 2U > pyArrayToRatColArray1d (py::array_t <real_T> value)
545566{
546567 coder::array<real_T, 2U > result;
547568
@@ -619,8 +640,9 @@ coder::array<RAT::cell_0, 1U> pyListToUnboundedCell0(py::list values)
619640 !py::isinstance<py::float_>(value[2 ]) || !py::isinstance<py::float_>(value[3 ]))
620641 throw std::runtime_error (" Expects a 2D list where each row must contain 4 elements. "
621642 " Columns 1 and 2 must be strings and Columns 3 and 4 must be numeric arrays" );
622- stringToRatCharArray (value[0 ].cast <std::string>(), result[idx].f1 );
623- stringToRatCharArray (value[1 ].cast <std::string>(), result[idx].f2 );
643+
644+ stringToRatArray (value[0 ].cast <std::string>(), result[idx].f1 .data , result[idx].f1 .size );
645+ stringToRatArray (value[1 ].cast <std::string>(), result[idx].f2 .data , result[idx].f2 .size );
624646 result[idx].f3 = value[2 ].cast <real_T>();
625647 result[idx].f4 = value[3 ].cast <real_T>();
626648 idx++;
@@ -662,30 +684,30 @@ RAT::struct0_T createStruct0(const ProblemDefinition& problem)
662684 stringToRatArray (problem.geometry , problem_struct.geometry .data , problem_struct.geometry .size );
663685 stringToRatArray (problem.TF , problem_struct.TF .data , problem_struct.TF .size );
664686
665- problem_struct.contrastBackgroundParams = customCaller (" Problem.contrastBackgroundParams" , pyArrayToRatArray1d , problem.contrastBackgroundParams );
666- problem_struct.contrastBackgroundActions = customCaller (" Problem.contrastBackgroundActions" , pyArrayToRatArray1d , problem.contrastBackgroundActions );
667- problem_struct.resample = customCaller (" Problem.resample" , pyArrayToRatArray1d , problem.resample );
668- problem_struct.dataPresent = customCaller (" Problem.dataPresent" , pyArrayToRatArray1d , problem.dataPresent );
669- problem_struct.oilChiDataPresent = customCaller (" Problem.oilChiDataPresent" , pyArrayToRatArray1d , problem.oilChiDataPresent );
670- problem_struct.contrastQzshifts = customCaller (" Problem.contrastQzshifts" , pyArrayToRatArray1d , problem.contrastQzshifts );
671- problem_struct.contrastScalefactors = customCaller (" Problem.contrastScalefactors" , pyArrayToRatArray1d , problem.contrastScalefactors );
672- problem_struct.contrastBulkIns = customCaller (" Problem.contrastBulkIns" , pyArrayToRatArray1d , problem.contrastBulkIns );
673- problem_struct.contrastBulkOuts = customCaller (" Problem.contrastBulkOuts" , pyArrayToRatArray1d , problem.contrastBulkOuts );
674- problem_struct.contrastResolutionParams = customCaller (" Problem.contrastResolutionParams" , pyArrayToRatArray1d , problem.contrastResolutionParams );
675- problem_struct.backgroundParams = customCaller (" Problem.backgroundParams" , pyArrayToRatArray1d , problem.backgroundParams );
676- problem_struct.qzshifts = customCaller (" Problem.qzshifts" , pyArrayToRatArray1d , problem.qzshifts );
677- problem_struct.scalefactors = customCaller (" Problem.scalefactors" , pyArrayToRatArray1d , problem.scalefactors );
678- problem_struct.bulkIn = customCaller (" Problem.bulkIn" , pyArrayToRatArray1d , problem.bulkIn );
679- problem_struct.bulkOut = customCaller (" Problem.bulkOut" , pyArrayToRatArray1d , problem.bulkOut );
680- problem_struct.resolutionParams = customCaller (" Problem.resolutionParams" , pyArrayToRatArray1d , problem.resolutionParams );
681- problem_struct.params = customCaller (" Problem.params" , pyArrayToRatArray1d , problem.params );
682-
683- problem_struct.contrastCustomFiles = customCaller (" Problem.contrastCustomFiles" , pyArrayToRatArray1d , problem.contrastCustomFiles );
684- problem_struct.contrastDomainRatios = customCaller (" Problem.contrastDomainRatios" , pyArrayToRatArray1d , problem.contrastDomainRatios );
685- problem_struct.domainRatio = customCaller (" Problem.domainRatio" , pyArrayToRatArray1d , problem.domainRatio );
686-
687- problem_struct.fitParams = customCaller (" Problem.fitParams" , pyArrayToRatArray1d , problem.fitParams );
688- problem_struct.otherParams = customCaller (" Problem.otherParams" , pyArrayToRatArray1d , problem.otherParams );
687+ problem_struct.contrastBackgroundParams = customCaller (" Problem.contrastBackgroundParams" , pyArrayToRatColArray1d , problem.contrastBackgroundParams );
688+ problem_struct.contrastBackgroundActions = customCaller (" Problem.contrastBackgroundActions" , pyArrayToRatColArray1d , problem.contrastBackgroundActions );
689+ problem_struct.resample = customCaller (" Problem.resample" , pyArrayToRatColArray1d , problem.resample );
690+ problem_struct.dataPresent = customCaller (" Problem.dataPresent" , pyArrayToRatColArray1d , problem.dataPresent );
691+ problem_struct.oilChiDataPresent = customCaller (" Problem.oilChiDataPresent" , pyArrayToRatColArray1d , problem.oilChiDataPresent );
692+ problem_struct.contrastQzshifts = customCaller (" Problem.contrastQzshifts" , pyArrayToRatColArray1d , problem.contrastQzshifts );
693+ problem_struct.contrastScalefactors = customCaller (" Problem.contrastScalefactors" , pyArrayToRatColArray1d , problem.contrastScalefactors );
694+ problem_struct.contrastBulkIns = customCaller (" Problem.contrastBulkIns" , pyArrayToRatColArray1d , problem.contrastBulkIns );
695+ problem_struct.contrastBulkOuts = customCaller (" Problem.contrastBulkOuts" , pyArrayToRatColArray1d , problem.contrastBulkOuts );
696+ problem_struct.contrastResolutionParams = customCaller (" Problem.contrastResolutionParams" , pyArrayToRatColArray1d , problem.contrastResolutionParams );
697+ problem_struct.backgroundParams = customCaller (" Problem.backgroundParams" , pyArrayToRatColArray1d , problem.backgroundParams );
698+ problem_struct.qzshifts = customCaller (" Problem.qzshifts" , pyArrayToRatColArray1d , problem.qzshifts );
699+ problem_struct.scalefactors = customCaller (" Problem.scalefactors" , pyArrayToRatColArray1d , problem.scalefactors );
700+ problem_struct.bulkIn = customCaller (" Problem.bulkIn" , pyArrayToRatColArray1d , problem.bulkIn );
701+ problem_struct.bulkOut = customCaller (" Problem.bulkOut" , pyArrayToRatColArray1d , problem.bulkOut );
702+ problem_struct.resolutionParams = customCaller (" Problem.resolutionParams" , pyArrayToRatColArray1d , problem.resolutionParams );
703+ problem_struct.params = customCaller (" Problem.params" , pyArrayToRatColArray1d , problem.params );
704+
705+ problem_struct.contrastCustomFiles = customCaller (" Problem.contrastCustomFiles" , pyArrayToRatColArray1d , problem.contrastCustomFiles );
706+ problem_struct.contrastDomainRatios = customCaller (" Problem.contrastDomainRatios" , pyArrayToRatColArray1d , problem.contrastDomainRatios );
707+ problem_struct.domainRatio = customCaller (" Problem.domainRatio" , pyArrayToRatColArray1d , problem.domainRatio );
708+
709+ problem_struct.fitParams = customCaller (" Problem.fitParams" , pyArrayToRatRowArray1d , problem.fitParams );
710+ problem_struct.otherParams = customCaller (" Problem.otherParams" , pyArrayToRatRowArray1d , problem.otherParams );
689711 problem_struct.fitLimits = customCaller (" Problem.fitLimits" , pyArrayToRatArray2d, problem.fitLimits );
690712 problem_struct.otherLimits = customCaller (" Problem.otherLimits" , pyArrayToRatArray2d, problem.otherLimits );
691713
@@ -710,14 +732,14 @@ RAT::struct1_T createStruct1(const Limits& limits)
710732RAT::struct3_T createStruct3 (const Checks& checks)
711733{
712734 RAT::struct3_T checks_struct;
713- checks_struct.fitParam = customCaller (" Checks.fitParam" , pyArrayToRatArray1d , checks.fitParam );
714- checks_struct.fitBackgroundParam = customCaller (" Checks.fitBackgroundParam" , pyArrayToRatArray1d , checks.fitBackgroundParam );
715- checks_struct.fitQzshift = customCaller (" Checks.fitQzshift" , pyArrayToRatArray1d , checks.fitQzshift );
716- checks_struct.fitScalefactor = customCaller (" Checks.fitScalefactor" , pyArrayToRatArray1d , checks.fitScalefactor );
717- checks_struct.fitBulkIn = customCaller (" Checks.fitBulkIn" , pyArrayToRatArray1d , checks.fitBulkIn );
718- checks_struct.fitBulkOut = customCaller (" Checks.fitBulkOut" , pyArrayToRatArray1d , checks.fitBulkOut );
719- checks_struct.fitResolutionParam = customCaller (" Checks.fitResolutionParam" , pyArrayToRatArray1d , checks.fitResolutionParam );
720- checks_struct.fitDomainRatio = customCaller (" Checks.fitDomainRatio" , pyArrayToRatArray1d , checks.fitDomainRatio );
735+ checks_struct.fitParam = customCaller (" Checks.fitParam" , pyArrayToRatColArray1d , checks.fitParam );
736+ checks_struct.fitBackgroundParam = customCaller (" Checks.fitBackgroundParam" , pyArrayToRatColArray1d , checks.fitBackgroundParam );
737+ checks_struct.fitQzshift = customCaller (" Checks.fitQzshift" , pyArrayToRatColArray1d , checks.fitQzshift );
738+ checks_struct.fitScalefactor = customCaller (" Checks.fitScalefactor" , pyArrayToRatColArray1d , checks.fitScalefactor );
739+ checks_struct.fitBulkIn = customCaller (" Checks.fitBulkIn" , pyArrayToRatColArray1d , checks.fitBulkIn );
740+ checks_struct.fitBulkOut = customCaller (" Checks.fitBulkOut" , pyArrayToRatColArray1d , checks.fitBulkOut );
741+ checks_struct.fitResolutionParam = customCaller (" Checks.fitResolutionParam" , pyArrayToRatColArray1d , checks.fitResolutionParam );
742+ checks_struct.fitDomainRatio = customCaller (" Checks.fitDomainRatio" , pyArrayToRatColArray1d , checks.fitDomainRatio );
721743
722744 return checks_struct;
723745}
@@ -780,7 +802,7 @@ coder::array<RAT::cell_wrap_4, 2U> pyListToRatCellWrap4(py::list values)
780802 for (py::handle array: values)
781803 {
782804 py::array_t <real_T> casted_array = py::cast<py::array>(array);
783- result[idx].f1 = customCaller (" $id[" + std::to_string (idx) +" ]" , pyArrayToRatArray1d , casted_array);
805+ result[idx].f1 = customCaller (" $id[" + std::to_string (idx) +" ]" , pyArrayToRatColArray1d , casted_array);
784806 idx++;
785807 }
786808
@@ -897,13 +919,16 @@ RAT::struct2_T createStruct2T(const Control& control)
897919 stringToRatArray (control.boundHandling , control_struct.boundHandling .data , control_struct.boundHandling .size );
898920 control_struct.adaptPCR = control.adaptPCR ;
899921 control_struct.checks = createStruct3 (control.checks );
922+ stringToRatArray (control.IPCFilePath , control_struct.IPCFilePath .data , control_struct.IPCFilePath .size );
900923
901924 return control_struct;
902925}
903926
904- py::array_t <real_T> pyArrayFromRatArray1d (coder::array<real_T, 2U > array)
927+
928+ template <typename T>
929+ py::array_t <real_T> pyArrayFromRatArray1d (T array, bool isCol=true )
905930{
906- auto size = (array. size ( 0 ) > 1 ) ? array.size (0 ) : array.size (1 );
931+ auto size = isCol ? array.size (1 ) : array.size (0 );
907932 auto result_array = py::array_t <real_T>(size);
908933 std::memcpy (result_array.request ().ptr , array.data (), result_array.nbytes ());
909934
@@ -1040,37 +1065,38 @@ ProblemDefinition problemDefinitionFromStruct0T(const RAT::struct0_T problem)
10401065 problem_def.TF .resize (problem.TF .size [1 ]);
10411066 memcpy (&problem_def.TF [0 ], problem.TF .data , problem.TF .size [1 ]);
10421067
1043- problem_def.contrastBackgroundParams = pyArrayFromRatArray1d (problem.contrastBackgroundParams );
1044- problem_def.contrastBackgroundActions = pyArrayFromRatArray1d (problem.contrastBackgroundActions );
1045- problem_def.resample = pyArrayFromRatArray1d (problem.resample );
1046- problem_def.dataPresent = pyArrayFromRatArray1d (problem.dataPresent );
1047- problem_def.oilChiDataPresent = pyArrayFromRatArray1d (problem.oilChiDataPresent );
1048- problem_def.contrastQzshifts = pyArrayFromRatArray1d (problem.contrastQzshifts );
1049- problem_def.contrastScalefactors = pyArrayFromRatArray1d (problem.contrastScalefactors );
1050- problem_def.contrastBulkIns = pyArrayFromRatArray1d (problem.contrastBulkIns );
1051- problem_def.contrastBulkOuts = pyArrayFromRatArray1d (problem.contrastBulkOuts );
1052- problem_def.contrastResolutionParams = pyArrayFromRatArray1d (problem.contrastResolutionParams );
1053- problem_def.backgroundParams = pyArrayFromRatArray1d (problem.backgroundParams );
1054- problem_def.qzshifts = pyArrayFromRatArray1d (problem.qzshifts );
1055- problem_def.scalefactors = pyArrayFromRatArray1d (problem.scalefactors );
1056- problem_def.bulkIn = pyArrayFromRatArray1d (problem.bulkIn );
1057- problem_def.bulkOut = pyArrayFromRatArray1d (problem.bulkOut );
1058- problem_def.resolutionParams = pyArrayFromRatArray1d (problem.resolutionParams );
1059- problem_def.params = pyArrayFromRatArray1d (problem.params );
1060-
1061- problem_def.contrastCustomFiles = pyArrayFromRatArray1d (problem.contrastCustomFiles );
1062- problem_def.contrastDomainRatios = pyArrayFromRatArray1d (problem.contrastDomainRatios );
1063- problem_def.domainRatio = pyArrayFromRatArray1d (problem.domainRatio );
1064-
1065- problem_def.fitParams = pyArrayFromRatArray1d (problem.fitParams );
1066- problem_def.otherParams = pyArrayFromRatArray1d (problem.otherParams );
1067- problem_def.fitLimits = pyArrayFromRatArray2d (problem.fitLimits );
1068- problem_def.otherLimits = pyArrayFromRatArray2d (problem.otherLimits );
1068+ problem_def.contrastBackgroundParams = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.contrastBackgroundParams );
1069+ problem_def.contrastBackgroundActions = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.contrastBackgroundActions );
1070+ problem_def.resample = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.resample );
1071+ problem_def.dataPresent = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.dataPresent );
1072+ problem_def.oilChiDataPresent = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.oilChiDataPresent );
1073+ problem_def.contrastQzshifts = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.contrastQzshifts );
1074+ problem_def.contrastScalefactors = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.contrastScalefactors );
1075+ problem_def.contrastBulkIns = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.contrastBulkIns );
1076+ problem_def.contrastBulkOuts = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.contrastBulkOuts );
1077+ problem_def.contrastResolutionParams = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.contrastResolutionParams );
1078+ problem_def.backgroundParams = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.backgroundParams );
1079+ problem_def.qzshifts = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.qzshifts );
1080+ problem_def.scalefactors = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.scalefactors );
1081+ problem_def.bulkIn = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.bulkIn );
1082+ problem_def.bulkOut = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.bulkOut );
1083+ problem_def.resolutionParams = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.resolutionParams );
1084+ problem_def.params = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.params );
1085+
1086+ problem_def.contrastCustomFiles = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.contrastCustomFiles );
1087+ problem_def.contrastDomainRatios = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.contrastDomainRatios );
1088+ problem_def.domainRatio = pyArrayFromRatArray1d<coder::array<real_T, 2U >> (problem.domainRatio );
1089+
1090+ problem_def.fitParams = pyArrayFromRatArray1d<coder::array<real_T, 1U >> (problem.fitParams , false );
1091+ problem_def.otherParams = pyArrayFromRatArray1d<coder::array<real_T, 1U >> (problem.otherParams , false );
1092+ problem_def.fitLimits = pyArrayFromRatArray2d (problem.fitLimits );
1093+ problem_def.otherLimits = pyArrayFromRatArray2d (problem.otherLimits );
10691094
10701095 return problem_def;
10711096}
10721097
1073- py::list pyList1DFromRatCellWrap (const coder::array<RAT::cell_wrap_10, 1U >& values)
1098+ template <typename T>
1099+ py::list pyList1DFromRatCellWrap (const T& values)
10741100{
10751101 py::list result;
10761102
@@ -1081,7 +1107,8 @@ py::list pyList1DFromRatCellWrap(const coder::array<RAT::cell_wrap_10, 1U>& valu
10811107 return result;
10821108}
10831109
1084- py::list pyList2dFromRatCellWrap (const coder::array<RAT::cell_wrap_10, 2U >& values)
1110+ template <typename T>
1111+ py::list pyList2dFromRatCellWrap (const T& values)
10851112{
10861113 py::list result;
10871114 int32_T idx {0 };
@@ -1129,10 +1156,10 @@ BayesResults bayesResultsFromStruct8T(const RAT::struct8_T results)
11291156
11301157 bayesResults.chain = pyArrayFromRatArray2d (results.chain );
11311158
1132- bayesResults.predictionIntervals .reflectivity = pyList1DFromRatCellWrap (results.predictionIntervals .reflectivity );
1133- bayesResults.predictionIntervals .sld = pyList2dFromRatCellWrap (results.predictionIntervals .sld );
1134- bayesResults.predictionIntervals .reflectivityXData = pyList1DFromRatCellWrap (results.predictionIntervals .reflectivityXData );
1135- bayesResults.predictionIntervals .sldXData = pyList2dFromRatCellWrap (results.predictionIntervals .sldXData );
1159+ bayesResults.predictionIntervals .reflectivity = pyList1DFromRatCellWrap<coder::array<RAT::cell_wrap_11, 1U >> (results.predictionIntervals .reflectivity );
1160+ bayesResults.predictionIntervals .sld = pyList2dFromRatCellWrap<coder::array<RAT::cell_wrap_11, 2U >> (results.predictionIntervals .sld );
1161+ bayesResults.predictionIntervals .reflectivityXData = pyList1DFromRatCellWrap<coder::array<RAT::cell_wrap_12, 1U >> (results.predictionIntervals .reflectivityXData );
1162+ bayesResults.predictionIntervals .sldXData = pyList2dFromRatCellWrap<coder::array<RAT::cell_wrap_12, 2U >> (results.predictionIntervals .sldXData );
11361163 bayesResults.predictionIntervals .sampleChi = pyArray1dFromBoundedArray<coder::bounded_array<real_T, 1000U , 1U >>(results.predictionIntervals .sampleChi );
11371164
11381165 bayesResults.confidenceIntervals .percentile95 = pyArrayFromRatArray2d (results.confidenceIntervals .percentile95 );
@@ -1445,7 +1472,8 @@ PYBIND11_MODULE(rat_core, m) {
14451472 .def_readwrite (" pUnitGamma" , &Control::pUnitGamma)
14461473 .def_readwrite (" boundHandling" , &Control::boundHandling)
14471474 .def_readwrite (" adaptPCR" , &Control::adaptPCR)
1448- .def_readwrite (" checks" , &Control::checks);
1475+ .def_readwrite (" checks" , &Control::checks)
1476+ .def_readwrite (" IPCFilePath" , &Control::IPCFilePath);
14491477
14501478 py::class_<ProblemDefinition>(m, " ProblemDefinition" )
14511479 .def (py::init<>())
0 commit comments