From 0f754f4e3d287ecad07eba0fe5d06d279f3c1acb Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Mon, 2 Feb 2026 15:21:18 +0000 Subject: [PATCH 1/2] Unifies the indices used by python and cpp to be same with matlab --- .github/workflows/runTests.yml | 2 +- .../alternativeLanguages/customBilayer.cpp | 10 ++++++---- .../alternativeLanguages/customBilayer.py | 10 ++++++---- targetFunctions/+domainsTF/processCustomFunction.m | 4 ++-- targetFunctions/+normalTF/processCustomFunction.m | 2 +- .../common/customModelFunctions/callCppFunction.m | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.github/workflows/runTests.yml b/.github/workflows/runTests.yml index e7cc1565f..0902c8465 100644 --- a/.github/workflows/runTests.yml +++ b/.github/workflows/runTests.yml @@ -36,7 +36,7 @@ jobs: build_and_test_mex: strategy: matrix: - platform: [windows-latest, ubuntu-latest, macos-15-intel, macos-latest] + platform: [windows-latest, ubuntu-22.04, macos-15-intel, macos-latest] runs-on: ${{ matrix.platform }} needs: [build_cpp] diff --git a/examples/miscellaneous/alternativeLanguages/customBilayer.cpp b/examples/miscellaneous/alternativeLanguages/customBilayer.cpp index 734510b5a..83691e7b8 100644 --- a/examples/miscellaneous/alternativeLanguages/customBilayer.cpp +++ b/examples/miscellaneous/alternativeLanguages/customBilayer.cpp @@ -13,6 +13,8 @@ extern "C" { LIB_EXPORT void customBilayer(std::vector& params, std::vector& bulkIn, std::vector& bulkOut, int contrast, std::vector& output, double* outputSize, double* rough) { + # Note - The first contrast number is 1 (not 0) so be careful if you use + # this variable for array indexing. double subRough = params[0]; double oxideThick = params[1]; double oxideHydration = params[2]; @@ -65,9 +67,9 @@ extern "C" { // Manually deal with hydration for layers in // this example. - double oxSLD = (oxideHydration * bulkOut[contrast]) + ((1 - oxideHydration) * oxideSLD); - double headSLD = (headHydration * bulkOut[contrast]) + ((1 - headHydration) * SLDhead); - double tailSLD = (bilayerHydration * bulkOut[contrast]) + ((1 - bilayerHydration) * SLDtail); + double oxSLD = (oxideHydration * bulkOut[contrast-1]) + ((1 - oxideHydration) * oxideSLD); + double headSLD = (headHydration * bulkOut[contrast-1]) + ((1 - headHydration) * SLDhead); + double tailSLD = (bilayerHydration * bulkOut[contrast-1]) + ((1 - bilayerHydration) * SLDtail); // Make the layers // oxide... @@ -77,7 +79,7 @@ extern "C" { // Water... output.push_back(waterThick); - output.push_back(bulkOut[contrast]); + output.push_back(bulkOut[contrast-1]); output.push_back(bilayerRough); // Heads... diff --git a/examples/miscellaneous/alternativeLanguages/customBilayer.py b/examples/miscellaneous/alternativeLanguages/customBilayer.py index 5cf896b58..66c18aa67 100644 --- a/examples/miscellaneous/alternativeLanguages/customBilayer.py +++ b/examples/miscellaneous/alternativeLanguages/customBilayer.py @@ -2,6 +2,8 @@ import numpy as np def customBilayer(params, bulk_in, bulk_out, contrast): + # Note - The first contrast number is 1 (not 0) so be careful if you use + # this variable for array indexing. params = params bulk_in = bulk_in bulk_out = bulk_out @@ -58,13 +60,13 @@ def customBilayer(params, bulk_in, bulk_out, contrast): # Manually deal with hydration for layers in # this example. - oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD) - headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead) - tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail) + oxSLD = (oxide_hydration * bulk_out[contrast-1]) + ((1 - oxide_hydration) * oxide_SLD) + headSLD = (headHydration * bulk_out[contrast-1]) + ((1 - headHydration) * SLDhead) + tailSLD = (bilayerHydration * bulk_out[contrast-1]) + ((1 - bilayerHydration) * SLDtail) # Make the layers oxide = [oxide_thick, oxSLD, sub_rough] - water = [waterThick, bulk_out[contrast], bilayerRough] + water = [waterThick, bulk_out[contrast-1], bilayerRough] head = [headThick, headSLD, bilayerRough] tail = [tailThick, tailSLD, bilayerRough] diff --git a/targetFunctions/+domainsTF/processCustomFunction.m b/targetFunctions/+domainsTF/processCustomFunction.m index df835e218..f4ac574f3 100644 --- a/targetFunctions/+domainsTF/processCustomFunction.m +++ b/targetFunctions/+domainsTF/processCustomFunction.m @@ -21,8 +21,8 @@ [output1, subRoughs(i)] = callMatlabFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 1); [output2, ~] = callMatlabFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 2); else - [output1, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i-1, 0); - [output2, ~] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i-1, 1); + [output1, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 1); + [output2, ~] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 2); end % If SLD is real, add dummy imaginary column diff --git a/targetFunctions/+normalTF/processCustomFunction.m b/targetFunctions/+normalTF/processCustomFunction.m index 28015c88d..2cc046fe6 100644 --- a/targetFunctions/+normalTF/processCustomFunction.m +++ b/targetFunctions/+normalTF/processCustomFunction.m @@ -16,7 +16,7 @@ if isnan(str2double(functionHandle)) [output, subRoughs(i)] = callMatlabFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 0); else - [output, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i-1, -1); + [output, subRoughs(i)] = callCppFunction(functionHandle, paramValues, bulkIns(i), bulkOuts, i, 0); end % If SLD is real, add dummy imaginary column diff --git a/targetFunctions/common/customModelFunctions/callCppFunction.m b/targetFunctions/common/customModelFunctions/callCppFunction.m index fbefd6e0e..260c41233 100644 --- a/targetFunctions/common/customModelFunctions/callCppFunction.m +++ b/targetFunctions/common/customModelFunctions/callCppFunction.m @@ -51,7 +51,7 @@ bulkOutArray = coder.ceval('convertPtr2Vector', coder.ref(bulkOut), numel(bulkOut)); % domain should either before 0 or 1. A value less than zero indicates no domains - if (domains < 0) + if (domains < 1) coder.ceval(['std::mem_fn&, std::vector&, std::vector&, int, ' ... 'std::vector&, double*, double*)>(&CallbackInterface::invoke)'], ... callback, paramsArray, bulkInArray, bulkOutArray, contrast, outArray, ... From ecd6aa54d1dc8935572071b2c085902865bbb03b Mon Sep 17 00:00:00 2001 From: Stephen Nneji Date: Tue, 3 Feb 2026 10:04:44 +0000 Subject: [PATCH 2/2] Addresses review comments --- targetFunctions/common/customModelFunctions/callCppFunction.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targetFunctions/common/customModelFunctions/callCppFunction.m b/targetFunctions/common/customModelFunctions/callCppFunction.m index 260c41233..0d7fcf816 100644 --- a/targetFunctions/common/customModelFunctions/callCppFunction.m +++ b/targetFunctions/common/customModelFunctions/callCppFunction.m @@ -50,7 +50,7 @@ bulkOutArray = coder.opaque('std::vector'); bulkOutArray = coder.ceval('convertPtr2Vector', coder.ref(bulkOut), numel(bulkOut)); - % domain should either before 0 or 1. A value less than zero indicates no domains + % domain should either be 1 or 2. A value less than 1 indicates no domains if (domains < 1) coder.ceval(['std::mem_fn&, std::vector&, std::vector&, int, ' ... 'std::vector&, double*, double*)>(&CallbackInterface::invoke)'], ...