perm = [2, 3, 1]; sz = [1,2,3]; if ~isequal(size(ipermute(permute(zeros(sz), perm), perm)), sz) if exist('octave_config_info') error('FAILURE: You have a buggy version of ipermute. Try upgrading Octave (V3.3.3 is broken. V3.3.52+ works).'); else error('FAILURE: You have a buggy version of ipermute.'); end end % Test that fancy routine matches the behavior of the obvious Matlab routine % (when numerics aren't a problem) over a wide range of weird ND-array sizes % (This is really a test of ndhelper.m) sizes = {[1 3], [5 1], [10 3], [0], [0 9], [3 0], [3 1 4], [1 2 3], [1 1 1 4], [1 1 0 5], [0 0 0 1], [0 0 0], [0 0 0 1 0]}; for ii = 1:numel(sizes) sz = sizes{ii}; A = rand(sz); testclose(logcumsumexp(A), log(cumsum(exp(A)))); for dim = 1:length(sz) testclose(logcumsumexp(A, dim), log(cumsum(exp(A), dim))); end end % Test that answers are ok when numerics are horrible by comparing to LOGSUMEXP A = [-Inf -Inf -3000 -3000 -Inf -600 -599 -10 5 1000 999 Inf Inf 1000 Inf NaN 5 2]'; lcs = logcumsumexp(A); lcs2 = zeros(size(A)); for ii = 1:length(A) lcs2(ii) = logsumexp(A(1:ii)); end % If using Tom Minka's logsumexp, it fails (or at least used to fail) to deal % with NaNs correctly if there are Inf's in the array. I'll fix that here: if ~all(isnan(lcs2(end-2:end))) fprintf('WARNING: Problem with LOGSUMEXP detected while testing LOGCUMSUMEXP. Using the lightspeed rather than imurray version?\n'); lcs2(end-2:end) = NaN; end testclose(lcs, lcs2); fprintf('A warning (but not failure) on the previous line about NaN''s was expected.\n'); test_exit