From 1141b2e9b4fc90b5ce77a779d2154760e62d7643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20L=C3=B6fberg?= Date: Fri, 28 Jun 2024 10:51:42 +0200 Subject: [PATCH] Fixes #1418 entropy detection failed --- @sdpvar/mtimes.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/@sdpvar/mtimes.m b/@sdpvar/mtimes.m index f477410a..b374c44b 100644 --- a/@sdpvar/mtimes.m +++ b/@sdpvar/mtimes.m @@ -817,15 +817,21 @@ args = args.arg{1}; % Temporarily recast slog as log (slog is log(1+x)) if isequal(Y.extra.opname,'slog') - args = args + 1; - Y.extra.opname = 'log'; + if nnz(getbasematrix(X,0))==0 + % Not entropy but fits cross entropy + Z = -crossentropy(X,args + 1); + else + % Still hope for entropy + args = args + 1; + Y.extra.opname = 'log'; + end end % Detect the case log(f)*(k*f), and rescale to k*log(f)*f % to simplify comparison of function argument and outer argument if isequal(X.dim,args.dim) && isequal(size(X.basis),size(args.basis)) [~,~,a] = find(X.basis); [~,~,b] = find(args.basis); - if ~isequal(a,b) + if ~isequal(a,b) && all(size(a) == size(b)) c = a./b; if all(abs(c-c(1))<=1e-13) k = c(1);