Skip to content

Commit

Permalink
Finally use built-in stable unique (requires R2012...)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Löfberg committed Sep 3, 2024
1 parent 3d87091 commit 36700ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion extras/@optimizer/optimizer_precalc.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
sys.model.precalc.Qmap = [];
% R2012b...
try
[ii,jj,kk] = stableunique(sys.model.precalc.newmonomtable*gen_rand_hash(0,size(sys.model.precalc.newmonomtable,2),1));
%[ii,jj,kk] = stableunique(sys.model.precalc.newmonomtable*gen_rand_hash(0,size(sys.model.precalc.newmonomtable,2),1));
[ii,jj,kk] = unique(sys.model.precalc.newmonomtable*gen_rand_hash(0,size(sys.model.precalc.newmonomtable,2),1),'stable');
sys.model.precalc.S = sparse(kk,1:length(kk),1);
sys.model.precalc.skipped = setdiff(1:length(kk),jj);
sys.model.precalc.blkOneS = blkdiag(1,sys.model.precalc.S');
Expand Down
6 changes: 4 additions & 2 deletions extras/eliminatevariables.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@
if ~isequal(newmonomtable,model.precalc.newmonomtable)%~isempty(removethese)
skipped = [];
alreadyAdded = zeros(1,size(newmonomtable,1));
[ii,jj,kk,skipped] = stableunique(newmonomtable*model.hashCache(1:size(newmonomtable,2)));
%[ii,jj,kk,skipped] = stableunique(newmonomtable*gen_rand_hash(0,size(newmonomtable,2),1));
%[ii,jj,kk,skipped] = stableunique(newmonomtable*model.hashCache(1:size(newmonomtable,2)));
[ii,jj,kk] = unique(newmonomtable*model.hashCache(1:size(newmonomtable,2)),'stable');
skipped = setdiff(1:length(kk),jj);

S = sparse(kk,1:length(kk),1);
model.precalc.S = S;
model.precalc.skipped = skipped;
Expand Down

0 comments on commit 36700ac

Please sign in to comment.