Commit 89b66f7e authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

quantity.Discrete/on and cat is now working for constant quantities on an empty domain

parent 6145a465
...@@ -372,7 +372,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi ...@@ -372,7 +372,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
end end
for it = 1 : numel(varargin) for it = 1 : numel(varargin)
if isempty(varargin{it}) if isempty(varargin{it}) || isempty(varargin{it}(1).domain)
continue; continue;
end end
assert(numel(referenceGridName) == numel(varargin{it}(1).gridName), ... assert(numel(referenceGridName) == numel(varargin{it}(1).gridName), ...
...@@ -2116,15 +2116,16 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi ...@@ -2116,15 +2116,16 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
for k = 1:numel(obj) for k = 1:numel(obj)
v(:,k) = obj(k).valueDiscrete(:); v(:,k) = obj(k).valueDiscrete(:);
end end
value = reshape(v, [obj(1).gridSize(), size(obj)]);
value = reshape(v, [obj(1).gridSize(), size(obj)]);
if nargin == 2 && myDomain ~= obj(1).domain if nargin == 2 && myDomain ~= obj(1).domain
% if a new domain is specified for the evaluation of % if a new domain is specified for the evaluation of
% the quantity, ... % the quantity, ...
if obj.isConstant if obj.isConstant
% ... duplicate the constant value on the desired % ... duplicate the constant value on the desired
% domain % domain
value = repmat(value, [cellfun(@(v) numel(v), {myDomain.grid}), ones(1, length(size(obj)))]); value = repmat(v, [cellfun(@(v) numel(v), {myDomain.grid}), ones(1, length(size(obj)))]);
else else
%... do an interpolation based on the old data. %... do an interpolation based on the old data.
indexGrid = arrayfun(@(s) 1:s, size(obj), 'UniformOutput', false); indexGrid = arrayfun(@(s) 1:s, size(obj), 'UniformOutput', false);
......
...@@ -225,10 +225,17 @@ compareED = quantity.Discrete({tan(t*z), sin(t * z); cos(t * z), cos(t*z)}, 'gri ...@@ -225,10 +225,17 @@ compareED = quantity.Discrete({tan(t*z), sin(t * z); cos(t * z), cos(t*z)}, 'gri
testCase.verifyEqual(ED.on(), compareED.on()) testCase.verifyEqual(ED.on(), compareED.on())
% concatenation of a constant and a function: % concatenation of a constant and a function:
const = quantity.Discrete([5; 2], 'domain', quantity.Domain.empty); C = [5; 2];
const = quantity.Discrete(C, 'domain', quantity.Domain.empty);
% %
% [const, A] constA = [const, A];
% [A, const] testCase.verifyTrue(all(constA(1,1).on() == C(1)));
testCase.verifyTrue(all(constA(2,1).on() == C(2)));
Aconst = [A, const];
testCase.verifyTrue(all(Aconst(1,2).on() == C(1)));
testCase.verifyTrue(all(Aconst(2,2).on() == C(2)));
end end
...@@ -548,6 +555,9 @@ testCase.verifyEqual(permute(createTestData(linspace(0, 1, 21), linspace(0, 1, 2 ...@@ -548,6 +555,9 @@ testCase.verifyEqual(permute(createTestData(linspace(0, 1, 21), linspace(0, 1, 2
value(:,:,1,2) = 1+zGridA + zetaGridA.^2; value(:,:,1,2) = 1+zGridA + zetaGridA.^2;
value(:,:,2,3) = 1+zeros(numel(gridVecA), numel(gridVecB)); value(:,:,2,3) = 1+zeros(numel(gridVecA), numel(gridVecB));
end end
end end
function testOn2(testCase) function testOn2(testCase)
...@@ -897,12 +907,17 @@ testCase.verifyTrue( numeric.near( squeeze(double(s * a')), [sin(z * pi) * 42, c ...@@ -897,12 +907,17 @@ testCase.verifyTrue( numeric.near( squeeze(double(s * a')), [sin(z * pi) * 42, c
testCase.verifyTrue( numeric.near( squeeze(double(a * s)), [sin(z * pi) * 42, cos(z * pi) * 42])); testCase.verifyTrue( numeric.near( squeeze(double(a * s)), [sin(z * pi) * 42, cos(z * pi) * 42]));
end end
% function testOnConstant(testCase) function testOnConstant(testCase)
%
% const = quantity.Discrete([0 1; 2 3], 'domain', quantity.Domain.empty); A = [0 1; 2 3];
% const.on([1:5]); const = quantity.Discrete(A, 'domain', quantity.Domain.empty);
% C = const.on([1:5]);
% end
for k = 1:numel(A)
testCase.verifyTrue( all( A(k) == C(:,k) ));
end
end
function testIsConstant(testCase) function testIsConstant(testCase)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment