Commit f5b9d15b authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

quantity.Discrete/zeros will return an empty array if the requested size for...

quantity.Discrete/zeros will return an empty array if the requested size for zeros contains 0 as size. quantity.Discrete/compose works on quantities defined on quantity.EquidistantDomain
parent f1cd2f5a
......@@ -327,14 +327,21 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% newValues will be reshaped into the form
% f(z, t, zeta)
newValues = reshape( newValues, [tmpDomain.gridLength, 1] );
% now the common domains, i.e., zeta = z must be merged:
% for this, find the index of the common domain in list of
% temporary combined domain
% Before, do a cast to quantity.Domain in order to handle also
% quantity.EquidistantDomain objects.
intersectDomain = intersect( ...
quantity.Domain( originalDomain( ~logOfDomain ) ), ...
quantity.Domain( g(1).domain ) );
if ~logOfDomain == 0
intersectDomain = [];
else
% now the common domains, i.e., zeta = z must be merged:
% For this, use intersect to find the common domains. The
% comparison is applied to the domain names. This is
% required, because intersect only works with objects of
% the same type. If one of the domains is an
% quantity.EquidistantDomain, the direct call of intersect
% on the domains will lead to an error.
intersectDomain = intersect( ...
[originalDomain( ~logOfDomain ).name], ...
[g(1).domain.name] );
end
if ~isempty(intersectDomain)
......@@ -2236,8 +2243,12 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
domain, myParser.Results.gridName);
end
O = zeros([domain.gridLength, valueSize(:)']);
P = quantity.Discrete(O, 'size', valueSize, 'domain', domain, varargin{:});
if any( valueSize == 0)
P = quantity.Discrete.empty(valueSize);
else
O = zeros([domain.gridLength, valueSize(:)']);
P = quantity.Discrete(O, 'size', valueSize, 'domain', domain, varargin{:});
end
end
function q = value2cell(value, gridSize, valueSize)
......
......@@ -329,7 +329,8 @@ classdef (InferiorClasses = {?quantity.EquidistantDomain}) Domain < ...
end
end % for it = 1 : numel(result)
end % ishomogenious
end % methods
end % methods (Public)
methods (Access = protected)
......
......@@ -3,7 +3,7 @@ classdef EquidistantDomain < quantity.Domain
%definition of a function. The discretization points are equally
%distributed over the domain.
properties (Access = protected)
properties (SetAccess = protected)
stepSize;
end
......@@ -33,18 +33,18 @@ classdef EquidistantDomain < quantity.Domain
name = '',
lower = [],
upper = [],
optArgs.stepNumber = [];
optArgs.stepSize = [];
optArgs.stepNumber double {mustBeInteger};
optArgs.stepSize double {mustBePositive};
optArgs.exactBoundary = quantity.DomainBoundary.lower;
end
if nargin > 1
if ~isempty(optArgs.stepSize) && ~isempty(optArgs.stepNumber)
if isfield(optArgs, 'stepSize') && isfield(optArgs, 'stepNumber')
warning('If both, stepSize and stepNumber is set; steSize is chosen and stepNumber is neglected!')
end
if ~isempty(optArgs.stepSize)
if isfield(optArgs, 'stepSize')
if optArgs.exactBoundary == quantity.DomainBoundary.lower
grid = lower : optArgs.stepSize : upper;
elseif optArgs.exactBoundary == quantity.DomainBoundary.upper
......@@ -55,17 +55,26 @@ classdef EquidistantDomain < quantity.Domain
grid = [grid grid(end) + optArgs.stepSize];
end
end
elseif ~isempty(optArgs.stepNumber)
grid = linspace(lower, upper, optArgs.stepNumber);
stepSize = optArgs.stepSize;
else
grid = linspace(lower, upper);
if isfield(optArgs, 'stepNumber')
grid = linspace(lower, upper, optArgs.stepNumber);
else
grid = linspace(lower, upper);
end
stepSize = grid(2) - grid(1);
end
else
grid = [];
end
obj@quantity.Domain(name, grid);
obj.stepSize = optArgs.stepSize;
obj.stepSize = stepSize;
end
function d = quantity.Domain(obj)
......
......@@ -105,6 +105,15 @@ Mog = M.compose(g, 'domain', tau);
MoG(1:2, 1:2) = FoG;
testCase.verifyEqual( MoG.on, MoG.on, 'AbsTol', 5e-16)
% verify the case if one of the domains is a quantity.EquidistantDomain
z = quantity.EquidistantDomain("z", 0, 1, 'stepNumber', 11);
tau = quantity.EquidistantDomain("tau", 0, 2, 'stepNumber', 31);
f = quantity.Discrete( z.grid + tau.grid', 'domain', [z, tau]);
fog = f.compose(g, 'domain', tau);
testCase.verifyEqual( fog.on, FoG.on, 'AbsTol', 5e-16)
end
function testCastDiscrete2Function(testCase)
......@@ -1296,11 +1305,16 @@ testCase.verifyEqual(referenceResult, permute(ax2.on(), [1, 3, 2]), 'AbsTol', 1e
end
function testZeros(testCase)
z = quantity.Discrete.zeros([2, 7, 8], {linspace(0,10)', linspace(0, 23, 11)}, 'gridName', {'a', 'b'});
O = zeros(100, 11, 2, 7, 8);
testCase.verifyEqual(z.on(), O);
% test the creation of empty zeros:
e = quantity.Discrete.zeros([3, 0], quantity.Domain.defaultGrid(10));
testCase.verifyEmpty( e );
end
function testChangeGrid(testCase)
......
......@@ -18,7 +18,6 @@ tc.TestData.d = d;
end
function testIsequidistant(tc)
tc.verifyTrue(tc.TestData.a.isequidistant);
tc.verifyTrue(all(isequidistant(tc.TestData.d)));
......
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