Why does coder produce multiple copies of my function?

조회 수: 5(최근 30일)
Arwel
Arwel 2022년 7월 28일
답변: Fred Smith 2022년 8월 24일
Hi,
I'm trying to use coder to convert a large project into C++.
I want to do two things....
(1) Generate the mex file
(2) Generate standalone code which is as readable as possible.
When doing the second, I'm noticing some strange behaviour which I can't explain and I don't really want, namely that it seems to be duplicating sections of code for no apparent reason. The following example shows what I mean.....
One of the functions in my code looks like this.....
function [sldProfile,reflect,Simul,shifted_dat,theseLayers,resamLayers,chiSq,ssubs] = ...
standardTF_layers_core(contrastLayers, rough, ...
geometry, nba, nbs, resample, calcSld, sf, qshift,...
dataPresent, data, dataLimits, simLimits, repeatLayers,...
background,resol,backsType,params,paralellPoints,resamPars)
% This is the main reflectivity calculation for all Layers models in the
% standard target function.
%
% The function first arranges the
% roughness' in the correct order according
% to geometry. Then, if required it calculates the SLD profile and if
% requested resamples this into a number of zero-roughness layers
% (roughness resampling). It the applies any scalefactors and qz shifts
% the data requires. This is done before calculating the reflectivity to
% ensure that the reflectivity is calculated over the same range in qz as
% the shifted datapoints. The main reflectivity calculation is then
% called, including the resolution function. The calculation outputs two
% profiles - 'reflect' which is the same range as the points, and
% 'Simulation' which can be a different range to allow extrapolation.
% The background correction is the applied, and finally chi-squared is
% calculated.
%
% Inputs:
% contrastLayers :
% rough :
% geometry :
% nba :
% nbs :
% resample :
% calcSld :
% sf :
% qshift :
% dataPresent :
% data :
% dataLimits :
% simLimits :
% repeatLayers :
% background :
% resol :
% backsType :
% params :
% paralellPoints :
%
% Outputs:
%
%
%
% ------------------------------------------------------------------------
%
% (c) Arwel Hughes - 12/1/21
%
% Last Modified: 12/1/21 by Arwel Hughes.
%
% ------------------------------------------------------------------------
% Bulid up the layers matrix for this contrast
[theseLayers, ssubs] = groupLayers_Mod(contrastLayers,rough,geometry,nba,nbs);
% Make the SLD profiles.
% If resampling is needed, then enforce the calcSLD flag, so as to catch
% the error af trying to resample a non-existent profile.
if (resample == 1 && calcSld == 0)
calcSld = 1;
end
% If calc SLD flag is set, then calculate the SLD profile
if calcSld == 1
sldProfile = makeSLDProfiles(nba,nbs,theseLayers,ssubs,repeatLayers);
else
sldProfile = [0 0];
end
% If required, then resample the SLD
if resample == 1
layerSld = resampleLayers(sldProfile,resamPars);
resamLayers = layerSld;
else
layerSld = theseLayers;
resamLayers = [0 0 0];
end
% Apply scale factors and q shifts to the data
shifted_dat = shiftdata(sf,qshift,dataPresent,data,dataLimits,simLimits);
% Calculate the reflectivity
reflectivityType = 'standardAbeles_realOnly';
[reflect,Simul] = callReflectivity(nba,nbs,simLimits,repeatLayers,shifted_dat,layerSld,ssubs,resol,paralellPoints,reflectivityType);
% Apply background correction, either to the simulation or the data
[reflect,Simul,shifted_dat] = applyBackgroundCorrection(reflect,Simul,shifted_dat,background,backsType);
% Calculate chi squared.
chiSq = chiSquared(shifted_dat,reflect,params);
end
When I run the codegen, I set up a coder config object like this.....
%% Create configuration object of class 'coder.CodeConfig'.
cfg = coder.config('lib');
cfg.GenerateReport = true;
cfg.ReportPotentialDifferences = false;
cfg.GenCodeOnly = true;
cfg.InlineBetweenUserFunctions = 'Readability';
cfg.InlineBetweenMathWorksFunctions = 'Readability';
cfg.InlineBetweenUserAndMathWorksFunctions = 'Readability';
cfg.TargetLang = 'C++';
cfg.PreserveVariableNames = 'UserNames';
cfg.CppNamespace = 'RAT';
cfg.PreserveArrayDimensions = true;
cfg.MATLABSourceComments = true;
cfg.DataTypeReplacement = 'CBuiltIn';
..and then run coder using 'codegen'.
When I inspect the resulting code however, it seems to have duplicated this section of code four times, for no apparent reason I can figure out.... i.e. in the hpp..
#ifndef STANDARDTF_LAYERS_CORE_H
#define STANDARDTF_LAYERS_CORE_H
// Include files
#include "rtwtypes.h"
#include "coder_array.h"
#include "omp.h"
#include <cstddef>
#include <cstdlib>
// Function Declarations
namespace RAT {
void b_standardTF_layers_core(
const ::coder::array<double, 2U> &contrastLayers, double rough,
const ::coder::array<char, 2U> &geometry, double nba, double nbs,
double resample, double calcSld, double sf, double qshift,
double dataPresent, const ::coder::array<double, 2U> &data,
const double dataLimits[2], const double simLimits_data[],
const double repeatLayers[2], double background, double resol,
double backsType, double params, const double resamPars[2],
::coder::array<double, 2U> &sldProfile, ::coder::array<double, 2U> &reflect,
::coder::array<double, 2U> &Simul, ::coder::array<double, 2U> &shifted_dat,
::coder::array<double, 2U> &theseLayers,
::coder::array<double, 2U> &resamLayers, double *chiSq, double *ssubs);
void c_standardTF_layers_core(
const ::coder::array<double, 2U> &contrastLayers, double rough,
const ::coder::array<char, 2U> &geometry, double nba, double nbs,
double resample, double calcSld, double sf, double qshift,
double dataPresent, const ::coder::array<double, 2U> &data,
const double dataLimits[2], const double simLimits_data[],
const double repeatLayers[2], double background, double resol,
double backsType, double params, const double resamPars[2],
::coder::array<double, 2U> &sldProfile, ::coder::array<double, 2U> &reflect,
::coder::array<double, 2U> &Simul, ::coder::array<double, 2U> &shifted_dat,
::coder::array<double, 2U> &theseLayers,
::coder::array<double, 2U> &resamLayers, double *chiSq, double *ssubs);
void d_standardTF_layers_core(
const ::coder::array<double, 2U> &contrastLayers, double rough,
const ::coder::array<char, 2U> &geometry, double nba, double nbs,
double resample, double calcSld, double sf, double qshift,
double dataPresent, const ::coder::array<double, 2U> &data,
const double dataLimits[2], const double simLimits_data[],
const double repeatLayers[2], double background, double resol,
double backsType, double params, const double resamPars[2],
::coder::array<double, 2U> &sldProfile, ::coder::array<double, 2U> &reflect,
::coder::array<double, 2U> &Simul, ::coder::array<double, 2U> &shifted_dat,
::coder::array<double, 2U> &theseLayers,
::coder::array<double, 2U> &resamLayers, double *chiSq, double *ssubs);
void standardTF_layers_core(
const ::coder::array<double, 2U> &contrastLayers, double rough,
const ::coder::array<char, 2U> &geometry, double nba, double nbs,
double resample, double calcSld, double sf, double qshift,
double dataPresent, const ::coder::array<double, 2U> &data,
const double dataLimits[2], const double simLimits_data[],
const double repeatLayers[2], double background, double resol,
double backsType, double params, const double resamPars[2],
::coder::array<double, 2U> &sldProfile, ::coder::array<double, 2U> &reflect,
::coder::array<double, 2U> &Simul, ::coder::array<double, 2U> &shifted_dat,
::coder::array<double, 2U> &theseLayers,
::coder::array<double, 2U> &resamLayers, double *chiSq, double *ssubs);
}
..and, also in the generated cpp...
// Include files
#include "standardTF_layers_core.h"
#include "applyBackgroundCorrection.h"
#include "callReflectivity.h"
#include "chiSquared.h"
#include "groupLayers_Mod.h"
#include "makeSLDProfiles.h"
#include "resampleLayers.h"
#include "rt_nonfinite.h"
#include "shiftdata.h"
#include "coder_array.h"
// Function Definitions
namespace RAT {
void b_standardTF_layers_core(
const ::coder::array<double, 2U> &contrastLayers, double rough,
const ::coder::array<char, 2U> &geometry, double nba, double nbs,
double resample, double calcSld, double sf, double qshift,
double dataPresent, const ::coder::array<double, 2U> &data,
const double dataLimits[2], const double simLimits_data[],
const double repeatLayers[2], double background, double resol,
double backsType, double params, const double resamPars[2],
::coder::array<double, 2U> &sldProfile, ::coder::array<double, 2U> &reflect,
::coder::array<double, 2U> &Simul, ::coder::array<double, 2U> &shifted_dat,
::coder::array<double, 2U> &theseLayers,
::coder::array<double, 2U> &resamLayers, double *chiSq, double *ssubs)
{
::coder::array<double, 2U> b_data;
::coder::array<double, 2U> layerSld;
int i;
int loop_ub;
// This is the main reflectivity calculation for all Layers models in the
// standard target function.
//
// The function first arranges the
// roughness' in the correct order according
// to geometry. Then, if required it calculates the SLD profile and if
// requested resamples this into a number of zero-roughness layers
// (roughness resampling). It the applies any scalefactors and qz shifts
// the data requires. This is done before calculating the reflectivity to
// ensure that the reflectivity is calculated over the same range in qz as
// the shifted datapoints. The main reflectivity calculation is then
// called, including the resolution function. The calculation outputs two
// profiles - 'reflect' which is the same range as the points, and
// 'Simulation' which can be a different range to allow extrapolation.
// The background correction is the applied, and finally chi-squared is
// calculated.
//
// Inputs:
// contrastLayers :
// rough :
// geometry :
// nba :
// nbs :
// resample :
// calcSld :
// sf :
// qshift :
// dataPresent :
// data :
// dataLimits :
// simLimits :
// repeatLayers :
// background :
// resol :
// backsType :
// params :
// paralellPoints :
//
// Outputs:
//
//
//
// ------------------------------------------------------------------------
//
// (c) Arwel Hughes - 12/1/21
//
// Last Modified: 12/1/21 by Arwel Hughes.
//
// ------------------------------------------------------------------------
// Bulid up the layers matrix for this contrast
groupLayers_Mod(contrastLayers, rough, geometry, nba, nbs, theseLayers,
ssubs);
// Make the SLD profiles.
// If resampling is needed, then enforce the calcSLD flag, so as to catch
// the error af trying to resample a non-existent profile.
if ((resample == 1.0) && (calcSld == 0.0)) {
calcSld = 1.0;
}
// If calc SLD flag is set, then calculate the SLD profile
if (calcSld == 1.0) {
makeSLDProfiles(nba, nbs, theseLayers, *ssubs, repeatLayers, sldProfile);
} else {
sldProfile.set_size(1, 2);
sldProfile[0] = 0.0;
sldProfile[1] = 0.0;
}
// If required, then resample the SLD
if (resample == 1.0) {
resampleLayers(sldProfile, resamPars, layerSld);
resamLayers.set_size(layerSld.size(0), 3);
loop_ub = layerSld.size(0) * 3;
for (i = 0; i < loop_ub; i++) {
resamLayers[i] = layerSld[i];
}
} else {
layerSld.set_size(theseLayers.size(0), 3);
loop_ub = theseLayers.size(0) * 3;
for (i = 0; i < loop_ub; i++) {
layerSld[i] = theseLayers[i];
}
resamLayers.set_size(1, 3);
resamLayers[0] = 0.0;
resamLayers[1] = 0.0;
resamLayers[2] = 0.0;
}
// Apply scale factors and q shifts to the data
b_data.set_size(data.size(0), data.size(1));
loop_ub = data.size(0) * data.size(1) - 1;
for (i = 0; i <= loop_ub; i++) {
b_data[i] = data[i];
}
shiftdata(sf, qshift, dataPresent, b_data, dataLimits, simLimits_data,
shifted_dat);
// Calculate the reflectivity
b_callReflectivity(nba, nbs, simLimits_data, repeatLayers, shifted_dat,
layerSld, *ssubs, resol, reflect, Simul);
// Apply background correction, either to the simulation or the data
applyBackgroundCorrection(reflect, Simul, shifted_dat, background, backsType);
// Calculate chi squared.
*chiSq = chiSquared(shifted_dat, reflect, params);
}
void c_standardTF_layers_core(
const ::coder::array<double, 2U> &contrastLayers, double rough,
const ::coder::array<char, 2U> &geometry, double nba, double nbs,
double resample, double calcSld, double sf, double qshift,
double dataPresent, const ::coder::array<double, 2U> &data,
const double dataLimits[2], const double simLimits_data[],
const double repeatLayers[2], double background, double resol,
double backsType, double params, const double resamPars[2],
::coder::array<double, 2U> &sldProfile, ::coder::array<double, 2U> &reflect,
::coder::array<double, 2U> &Simul, ::coder::array<double, 2U> &shifted_dat,
::coder::array<double, 2U> &theseLayers,
::coder::array<double, 2U> &resamLayers, double *chiSq, double *ssubs)
{
::coder::array<double, 2U> b_data;
::coder::array<double, 2U> layerSld;
int i;
int loop_ub;
// This is the main reflectivity calculation for all Layers models in the
// standard target function.
//
// The function first arranges the
// roughness' in the correct order according
// to geometry. Then, if required it calculates the SLD profile and if
// requested resamples this into a number of zero-roughness layers
// (roughness resampling). It the applies any scalefactors and qz shifts
// the data requires. This is done before calculating the reflectivity to
// ensure that the reflectivity is calculated over the same range in qz as
// the shifted datapoints. The main reflectivity calculation is then
// called, including the resolution function. The calculation outputs two
// profiles - 'reflect' which is the same range as the points, and
// 'Simulation' which can be a different range to allow extrapolation.
// The background correction is the applied, and finally chi-squared is
// calculated.
//
// Inputs:
// contrastLayers :
// rough :
// geometry :
// nba :
// nbs :
// resample :
// calcSld :
// sf :
// qshift :
// dataPresent :
// data :
// dataLimits :
// simLimits :
// repeatLayers :
// background :
// resol :
// backsType :
// params :
// paralellPoints :
//
// Outputs:
//
//
//
// ------------------------------------------------------------------------
//
// (c) Arwel Hughes - 12/1/21
//
// Last Modified: 12/1/21 by Arwel Hughes.
//
// ------------------------------------------------------------------------
// Bulid up the layers matrix for this contrast
groupLayers_Mod(contrastLayers, rough, geometry, theseLayers, ssubs);
// Make the SLD profiles.
// If resampling is needed, then enforce the calcSLD flag, so as to catch
// the error af trying to resample a non-existent profile.
if ((resample == 1.0) && (calcSld == 0.0)) {
calcSld = 1.0;
}
// If calc SLD flag is set, then calculate the SLD profile
if (calcSld == 1.0) {
makeSLDProfiles(nba, nbs, theseLayers, *ssubs, repeatLayers, sldProfile);
} else {
sldProfile.set_size(1, 2);
sldProfile[0] = 0.0;
sldProfile[1] = 0.0;
}
// If required, then resample the SLD
if (resample == 1.0) {
resampleLayers(sldProfile, resamPars, layerSld);
resamLayers.set_size(layerSld.size(0), 3);
loop_ub = layerSld.size(0) * 3;
for (i = 0; i < loop_ub; i++) {
resamLayers[i] = layerSld[i];
}
} else {
layerSld.set_size(theseLayers.size(0), 3);
loop_ub = theseLayers.size(0) * 3;
for (i = 0; i < loop_ub; i++) {
layerSld[i] = theseLayers[i];
}
resamLayers.set_size(1, 3);
resamLayers[0] = 0.0;
resamLayers[1] = 0.0;
resamLayers[2] = 0.0;
}
// Apply scale factors and q shifts to the data
b_data.set_size(data.size(0), data.size(1));
loop_ub = data.size(0) * data.size(1) - 1;
for (i = 0; i <= loop_ub; i++) {
b_data[i] = data[i];
}
shiftdata(sf, qshift, dataPresent, b_data, dataLimits, simLimits_data,
shifted_dat);
// Calculate the reflectivity
callReflectivity(nba, nbs, simLimits_data, repeatLayers, shifted_dat,
layerSld, *ssubs, resol, reflect, Simul);
// Apply background correction, either to the simulation or the data
applyBackgroundCorrection(reflect, Simul, shifted_dat, background, backsType);
// Calculate chi squared.
*chiSq = chiSquared(shifted_dat, reflect, params);
}
void d_standardTF_layers_core(
const ::coder::array<double, 2U> &contrastLayers, double rough,
const ::coder::array<char, 2U> &geometry, double nba, double nbs,
double resample, double calcSld, double sf, double qshift,
double dataPresent, const ::coder::array<double, 2U> &data,
const double dataLimits[2], const double simLimits_data[],
const double repeatLayers[2], double background, double resol,
double backsType, double params, const double resamPars[2],
::coder::array<double, 2U> &sldProfile, ::coder::array<double, 2U> &reflect,
::coder::array<double, 2U> &Simul, ::coder::array<double, 2U> &shifted_dat,
::coder::array<double, 2U> &theseLayers,
::coder::array<double, 2U> &resamLayers, double *chiSq, double *ssubs)
{
::coder::array<double, 2U> b_data;
::coder::array<double, 2U> layerSld;
int i;
int loop_ub;
// This is the main reflectivity calculation for all Layers models in the
// standard target function.
//
// The function first arranges the
// roughness' in the correct order according
// to geometry. Then, if required it calculates the SLD profile and if
// requested resamples this into a number of zero-roughness layers
// (roughness resampling). It the applies any scalefactors and qz shifts
// the data requires. This is done before calculating the reflectivity to
// ensure that the reflectivity is calculated over the same range in qz as
// the shifted datapoints. The main reflectivity calculation is then
// called, including the resolution function. The calculation outputs two
// profiles - 'reflect' which is the same range as the points, and
// 'Simulation' which can be a different range to allow extrapolation.
// The background correction is the applied, and finally chi-squared is
// calculated.
//
// Inputs:
// contrastLayers :
// rough :
// geometry :
// nba :
// nbs :
// resample :
// calcSld :
// sf :
// qshift :
// dataPresent :
// data :
// dataLimits :
// simLimits :
// repeatLayers :
// background :
// resol :
// backsType :
// params :
// paralellPoints :
//
// Outputs:
//
//
//
// ------------------------------------------------------------------------
//
// (c) Arwel Hughes - 12/1/21
//
// Last Modified: 12/1/21 by Arwel Hughes.
//
// ------------------------------------------------------------------------
// Bulid up the layers matrix for this contrast
groupLayers_Mod(contrastLayers, rough, geometry, theseLayers, ssubs);
// Make the SLD profiles.
// If resampling is needed, then enforce the calcSLD flag, so as to catch
// the error af trying to resample a non-existent profile.
if ((resample == 1.0) && (calcSld == 0.0)) {
calcSld = 1.0;
}
// If calc SLD flag is set, then calculate the SLD profile
if (calcSld == 1.0) {
makeSLDProfiles(nba, nbs, theseLayers, *ssubs, repeatLayers, sldProfile);
} else {
sldProfile.set_size(1, 2);
sldProfile[0] = 0.0;
sldProfile[1] = 0.0;
}
// If required, then resample the SLD
if (resample == 1.0) {
resampleLayers(sldProfile, resamPars, layerSld);
resamLayers.set_size(layerSld.size(0), 3);
loop_ub = layerSld.size(0) * 3;
for (i = 0; i < loop_ub; i++) {
resamLayers[i] = layerSld[i];
}
} else {
layerSld.set_size(theseLayers.size(0), 3);
loop_ub = theseLayers.size(0) * 3;
for (i = 0; i < loop_ub; i++) {
layerSld[i] = theseLayers[i];
}
resamLayers.set_size(1, 3);
resamLayers[0] = 0.0;
resamLayers[1] = 0.0;
resamLayers[2] = 0.0;
}
// Apply scale factors and q shifts to the data
b_data.set_size(data.size(0), data.size(1));
loop_ub = data.size(0) * data.size(1) - 1;
for (i = 0; i <= loop_ub; i++) {
b_data[i] = data[i];
}
shiftdata(sf, qshift, dataPresent, b_data, dataLimits, simLimits_data,
shifted_dat);
// Calculate the reflectivity
b_callReflectivity(nba, nbs, simLimits_data, repeatLayers, shifted_dat,
layerSld, *ssubs, resol, reflect, Simul);
// Apply background correction, either to the simulation or the data
applyBackgroundCorrection(reflect, Simul, shifted_dat, background, backsType);
// Calculate chi squared.
*chiSq = chiSquared(shifted_dat, reflect, params);
}
void standardTF_layers_core(
const ::coder::array<double, 2U> &contrastLayers, double rough,
const ::coder::array<char, 2U> &geometry, double nba, double nbs,
double resample, double calcSld, double sf, double qshift,
double dataPresent, const ::coder::array<double, 2U> &data,
const double dataLimits[2], const double simLimits_data[],
const double repeatLayers[2], double background, double resol,
double backsType, double params, const double resamPars[2],
::coder::array<double, 2U> &sldProfile, ::coder::array<double, 2U> &reflect,
::coder::array<double, 2U> &Simul, ::coder::array<double, 2U> &shifted_dat,
::coder::array<double, 2U> &theseLayers,
::coder::array<double, 2U> &resamLayers, double *chiSq, double *ssubs)
{
::coder::array<double, 2U> b_data;
::coder::array<double, 2U> layerSld;
int i;
int loop_ub;
// This is the main reflectivity calculation for all Layers models in the
// standard target function.
//
// The function first arranges the
// roughness' in the correct order according
// to geometry. Then, if required it calculates the SLD profile and if
// requested resamples this into a number of zero-roughness layers
// (roughness resampling). It the applies any scalefactors and qz shifts
// the data requires. This is done before calculating the reflectivity to
// ensure that the reflectivity is calculated over the same range in qz as
// the shifted datapoints. The main reflectivity calculation is then
// called, including the resolution function. The calculation outputs two
// profiles - 'reflect' which is the same range as the points, and
// 'Simulation' which can be a different range to allow extrapolation.
// The background correction is the applied, and finally chi-squared is
// calculated.
//
// Inputs:
// contrastLayers :
// rough :
// geometry :
// nba :
// nbs :
// resample :
// calcSld :
// sf :
// qshift :
// dataPresent :
// data :
// dataLimits :
// simLimits :
// repeatLayers :
// background :
// resol :
// backsType :
// params :
// paralellPoints :
//
// Outputs:
//
//
//
// ------------------------------------------------------------------------
//
// (c) Arwel Hughes - 12/1/21
//
// Last Modified: 12/1/21 by Arwel Hughes.
//
// ------------------------------------------------------------------------
// Bulid up the layers matrix for this contrast
groupLayers_Mod(contrastLayers, rough, geometry, nba, nbs, theseLayers,
ssubs);
// Make the SLD profiles.
// If resampling is needed, then enforce the calcSLD flag, so as to catch
// the error af trying to resample a non-existent profile.
if ((resample == 1.0) && (calcSld == 0.0)) {
calcSld = 1.0;
}
// If calc SLD flag is set, then calculate the SLD profile
if (calcSld == 1.0) {
makeSLDProfiles(nba, nbs, theseLayers, *ssubs, repeatLayers, sldProfile);
} else {
sldProfile.set_size(1, 2);
sldProfile[0] = 0.0;
sldProfile[1] = 0.0;
}
// If required, then resample the SLD
if (resample == 1.0) {
resampleLayers(sldProfile, resamPars, layerSld);
resamLayers.set_size(layerSld.size(0), 3);
loop_ub = layerSld.size(0) * 3;
for (i = 0; i < loop_ub; i++) {
resamLayers[i] = layerSld[i];
}
} else {
layerSld.set_size(theseLayers.size(0), 3);
loop_ub = theseLayers.size(0) * 3;
for (i = 0; i < loop_ub; i++) {
layerSld[i] = theseLayers[i];
}
resamLayers.set_size(1, 3);
resamLayers[0] = 0.0;
resamLayers[1] = 0.0;
resamLayers[2] = 0.0;
}
// Apply scale factors and q shifts to the data
b_data.set_size(data.size(0), data.size(1));
loop_ub = data.size(0) * data.size(1) - 1;
for (i = 0; i <= loop_ub; i++) {
b_data[i] = data[i];
}
shiftdata(sf, qshift, dataPresent, b_data, dataLimits, simLimits_data,
shifted_dat);
// Calculate the reflectivity
callReflectivity(nba, nbs, simLimits_data, repeatLayers, shifted_dat,
layerSld, *ssubs, resol, reflect, Simul);
// Apply background correction, either to the simulation or the data
applyBackgroundCorrection(reflect, Simul, shifted_dat, background, backsType);
// Calculate chi squared.
*chiSq = chiSquared(shifted_dat, reflect, params);
}
}
Now, this function is called from several places in the project, but coder seems to have responded by making several copies of the same section of code, all of them identiacl as far as I can see!
I don't want this behaviour - what is going on and how can I stop it happening?
Cheers,
Arwel

답변(1개)

Fred Smith
Fred Smith 2022년 8월 24일
Hi Arwel,
MATLAB Coder is creating specializations of your function based on a heuristic. Notionally there is some difference (perhaps non-obvious) between these different versions.
If you look in the code generation report, you should see all the versions of this function that were created. You should see something like standardTF_layers_core > 1, standardTF_layers_core > 2, etc.... Select a particular specialization and then carefully examine the inputs to each version in the variables table or by hovering over the function header. You should see some difference. Maybe some inputs have different types or sizes. Maybe some inputs are constants with different values in different versions.
You can use coder.ignoreSize and coder.ignoreConst at call-sites to prevent unnecessary specialization on size or values. If you have many call-sites you can achieve the same thing by introducing a wrapper function, using coder.inline to force the wrapper to be inlined, and putting the coder.ignoreSize or coder.ignoreConst inside the wrapper.
Hope this helps.

범주

Find more on Configure Simulation Conditions in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by