Skip to content

Commit 6c195b2

Browse files
Fix for latest SymBuilder
1 parent 17cb0b3 commit 6c195b2

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

Utilities/SymBuilder/@SymBuilder/buildCFun.m

+48-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
end
1313
cb = [];
1414

15+
%See if we can use [] in symbolic var names
16+
sqOK = true;
17+
try
18+
if (exist('str2sym','file') == 2)
19+
str2sym('x[1]');
20+
else
21+
sym('x[1]');
22+
end
23+
catch
24+
sqOK = false;
25+
end
26+
1527
%Determine callback type
1628
switch(mode)
1729
case 'new'
@@ -98,26 +110,54 @@
98110
%Need to rename all variables to x[0]...x[n]
99111
xvar = cell(length(svar),1);
100112
for i = 1:length(xvar)
101-
xvar{i} = sprintf('x[%d]',i);
113+
if (sqOK)
114+
xvar{i} = sprintf('x[%d]',i);
115+
else
116+
xvar{i} = sprintf('x[%d]',i-1);
117+
end
102118
end
103119
%Ensure both columns
104120
if(size(svar,1) > 1), svar = svar.'; end
105121
if(size(xvar,1) > 1), xvar = xvar'; end
106122
%Subs out individual symbolic variables into our indexed list and converts to normal numbers
107-
wstate = warning('off','symbolic:sym:sym:DeprecateExpressions');
108-
eq = vpa(subs(sobj,svar,xvar),16); %this takes too long - any suggestions?
109-
warning(wstate);
123+
if (sqOK)
124+
eq = vpa(SymBuilder.symsubs(sobj,svar,xvar),16); %this takes too long - any suggestions?
125+
else
126+
eq = vpa(sobj, 16);
127+
end
128+
129+
% If we can't sub in c style indexed vars, explicit definition here
130+
if (~sqOK)
131+
fprintf(fp,' // Allocate C vars to Symbolic named vars\n');
132+
for i = 1:length(svar)
133+
t = 'double';
134+
if(cmode=='A')
135+
t = 'Type';
136+
end
137+
fprintf(fp,' const %s %s = %s;\n',t,char(svar(i)),xvar{i});
138+
end
139+
% Do the same if Hessian
140+
if (var=='H')
141+
for i = 1:ncon
142+
fprintf(fp,' const double lambda%d = lambda[%d];\n',i, i-1);
143+
end
144+
end
145+
fprintf(fp, '\n');
146+
end
147+
110148
%Sub out Lambda if Hessian
111149
if(var=='H')
112150
l = cell(ncon,1);
113151
l2 = cell(ncon,1);
114152
for i = 1:ncon
115153
l{i} = sprintf('lambda(%d)',i);
116-
l2{i} = sprintf('lambda[%d]',i);
154+
if (sqOK)
155+
l2{i} = sprintf('lambda[%d]',i);
156+
else
157+
l2{i} = sprintf('lambda%d',i);
158+
end
117159
end
118-
wstate = warning('off','symbolic:sym:sym:DeprecateExpressions');
119-
eq = subs(eq,l,l2);
120-
warning(wstate);
160+
eq = SymBuilder.symsubs(eq,l,l2);
121161
end
122162

123163
%Enter Equations (Var Type Dictates Entry Type)

Utilities/opti/optiHessCheck.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144

145145
%Display Warning
146146
if(~isOK && warn), optiwarn('OPTI:IncorrectHess',wstr); end
147-
if(isOK), optiinfo('OPTI Derivative Checker detected no problems in ''%s''',name); end
147+
if(isOK && warn), optiinfo('OPTI Derivative Checker detected no problems in ''%s''',name); end
148148

149149
function derError(name,msg)
150150
throwAsCaller(MException('OPTI:DERCHECK','OPTI Derivative Checker detected a problem in ''%s'':\n\n%s',name,msg));

0 commit comments

Comments
 (0)