Commit 0f816f2c authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Discrete.on(): minor changes, but improved performance (running all...

quantity.Discrete.on(): minor changes, but improved performance (running all unittests.quantity now takes 65sec instead of 85sec).
parent eba097ff
......@@ -423,7 +423,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
if nargin == 1
% case 0: no domain was specified, hence the value is requested
% on the default grid defined by obj(1).domain.
value = obj.obj2value(obj(1).domain);
value = reshape(cat(numel(obj(1).domain)+1, obj(:).valueDiscrete), ...
[obj(1).domain.gridLength(), size(obj)]);
elseif nargin == 2 && (iscell(myDomain) || isnumeric(myDomain))
% case 1: a domain is specified by myDomain as agrid
......@@ -442,8 +443,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
for k = 1:length(newGrid)
myDomain(k) = quantity.Domain(gridNames{k}, newGrid{k});
end
value = reshape(obj.obj2value(myDomain), ...
[myDomain.gridLength, size(obj)]);
value = reshape(obj.obj2value(myDomain), [myDomain.gridLength, size(obj)]);
else
% Since in the remaining cases the order of the domains is not
% neccessarily equal to the order in obj(1).domain, this is
......@@ -1086,7 +1086,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% at() evaluates the object at one point and returns it as array
% with the same size as size(obj).
value = reshape(obj.on(point), size(obj));
end
end % at()
function value = atIndex(obj, varargin)
% ATINDEX returns the valueDiscrete at the requested index.
......@@ -1129,7 +1129,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
value = reshape([value{:}], [outputSize, size(obj)]);
end
end
end % atIndex()
function n = nargin(obj)
% FIXME: check if all funtions in this object have the same
......@@ -2471,12 +2471,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% obj2value(obj, myDomain) returns the valueDiscrete in the
% form size(value) = [myDomain.gridLength objSize]
v = zeros([numel(obj(1).valueDiscrete), numel(obj)]);
for k = 1:numel(obj)
v(:,k) = obj(k).valueDiscrete(:);
end
value = reshape(v, [obj(1).domain.gridLength(), size(obj)]);
value = reshape(cat(numel(obj(1).domain)+1, obj(:).valueDiscrete), ...
[obj(1).domain.gridLength(), size(obj)]);
if nargin >= 2 && ~isequal( myDomain, obj(1).domain )
% if a new domain is specified for the evaluation of
......@@ -2484,7 +2480,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
if obj.isConstant
% ... duplicate the constant value on the desired
% domain
value = repmat(v, [cellfun(@(v) numel(v), {myDomain.grid}), ones(1, length(size(obj)))]);
value = repmat(value(:).', [myDomain.n, ones(1, ndims(obj))]);
else
%... do an interpolation based on the old data.
indexGrid = arrayfun(@(s) 1:s, size(obj), 'UniformOutput', false);
......
......@@ -91,13 +91,13 @@ classdef Function < quantity.Discrete
end
value = reshape( cell2mat(value), [ gridLength(myDomain), size(obj)]);
end
end
end % obj2value()
function n = nargin(obj)
% FIXME: check if all funtions in this object have the same
% number of input values.
n = numel(obj(1).grid);
end
end % nargin()
end
% -------------
......
......@@ -1157,7 +1157,7 @@ bc = permute(bc, [ 1 2 4 3 5 ]);
B = quantity.Discrete(b, [Z, T], 'size', [ 2, 2 ]);
C = quantity.Discrete(c, [V, T], 'size', [2, 3]);
BC = B*C;
testCase.verifyTrue(numeric.near(bc, BC.on));
testCase.verifyTrue(numeric.near(bc, BC.on()));
%%
z = linspace(0,1).';
......@@ -1189,13 +1189,13 @@ function testOnConstant(testCase)
A = [0 1; 2 3];
const = quantity.Discrete(A, quantity.Domain.empty);
C = const.on([1:5]);
C = const.on(1:1:5);
for k = 1:numel(A)
testCase.verifyTrue( all( A(k) == C(:,k) ));
end
end
end % testOnConstant()
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