From 36700acaa26e9ed96b37a4d1d9d65df783f2caa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20L=C3=B6fberg?= Date: Tue, 3 Sep 2024 12:23:17 +0200 Subject: [PATCH] Finally use built-in stable unique (requires R2012...) --- extras/@optimizer/optimizer_precalc.m | 3 ++- extras/eliminatevariables.m | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/extras/@optimizer/optimizer_precalc.m b/extras/@optimizer/optimizer_precalc.m index 32e26f58..d58c8ed7 100644 --- a/extras/@optimizer/optimizer_precalc.m +++ b/extras/@optimizer/optimizer_precalc.m @@ -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'); diff --git a/extras/eliminatevariables.m b/extras/eliminatevariables.m index f6321154..ed9aee5b 100644 --- a/extras/eliminatevariables.m +++ b/extras/eliminatevariables.m @@ -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;