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

Extend the check of isConstant to values that also have a grid. By this, some...

Extend the check of isConstant to values that also have a grid. By this, some computations can be simplified.
parent 5ee5a6e5
......@@ -162,6 +162,14 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% the quantity is interpreted as constant if it has no grid or
% it has a grid that is only defined at one point.
itIs = isempty(obj(1).domain);
if ~itIs
itIs = true;
% or if all entries have the same value
for k = 1:numel(obj)
itIs = itIs && all( diff( obj(k).valueDiscrete ) == 0, 'all');
end
end
end % isConstant()
function doNotCopy = get.doNotCopy(obj)
......
......@@ -1121,6 +1121,15 @@ z = linspace(0, pi)';
A = quantity.Discrete(sin(z), 'grid', z, 'gridName', 'z');
testCase.verifyFalse(A.isConstant());
c = quantity.Discrete(rand(1) + 0 * z, 'grid', z, 'gridName', 'z');
testCase.verifyTrue( c.isConstant() );
C = [c; c];
testCase.verifyTrue( C.isConstant() );
B = [A; C];
testCase.verifyFalse( B.isConstant() );
end
function testMTimesConstant(testCase)
......@@ -1144,7 +1153,6 @@ verifyTrue(testCase, numeric.near(Ac.on(), ac));
verifyTrue(testCase, numeric.near(AC.on(), ac));
verifyTrue(testCase, numeric.near(cA.on(), ca, 1e-12));
verifyTrue(testCase, numeric.near(CA.on(), ca, 1e-12));
end
function testMPower(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