Commit c8c68149 authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Discrete.isConstant is renamed into .isNumber - closes issue #43

parent 675ddf17
......@@ -155,11 +155,10 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end
end
function itIs = isConstant(obj)
% the quantity is interpreted as constant if it has no grid or
% it has a grid that is only defined at one point.
function itIs = isNumber(obj)
% the quantity is interpreted as constant if it has no grid.
itIs = isempty(obj(1).domain);
end % isConstant()
end % isNumber()
function valueDiscrete = get.valueDiscrete(obj)
% check if the value discrete for this object
......@@ -430,7 +429,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% Check if the object has a domain with a name:
% If there is no name, the object has an empty quantity.Domain, i.e., it is a
% constant. Then, the gridNames should be ''
% The check "isConstant" can not be used here, because it also returns true, if
% The check "isNumber()" can not be used here, because it also returns true, if
% the constant value is defined over a domain.
if isempty(obj(1).domain)
gridNames = repmat({''}, length(newGrid));
......@@ -477,7 +476,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end
% verify the domain
if obj(1).isConstant
if obj(1).isNumber()
gridPermuteIdx = 1:length(myDomain);
else
assert(numel(myDomain) == numel(obj(1).domain), ...
......@@ -1077,7 +1076,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% a quantity.Domain. The following strange form of concatenation an empty Domain
% with the required domain, ensures that the result is an array of quantity.Domain
% objects.
newDomain = [quantity.Domain.empty, obj(1).domain];
newDomain = [quantity.Domain.empty(), obj(1).domain];
% here substitution starts:
% The first (gridName2Replace{1}, values{1})-pair is
......@@ -1489,7 +1488,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end
end
if obj(1).isConstant
if obj(1).isNumber()
newDomain(1:length( gridNew )) = quantity.Domain();
for it = 1 : length(gridNew)
newDomain(it) = ...
......@@ -1547,7 +1546,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
assert( intersect(obj(1).gridName, optArgs.gridName) == optArgs.gridName );
if obj(1).isConstant
if obj(1).isNumber()
error("Not yet implemented")
else
gridIndexNew = obj(1).domain.gridIndex(optArgs.gridName);
......@@ -1623,7 +1622,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
myDomain = [quantity.Domain(gridName1, myGrid), ...
quantity.Domain(gridName2, myGrid)];
if obj.isConstant
if obj.isNumber()
% for a constant system matrix, the matrix exponential
% function can be used.
z = sym(gridName1, 'real');
......@@ -1743,7 +1742,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
function P = mtimes(a, b)
% TODO rewrite the selection of the special cases! the
% if-then-cosntruct is pretty ugly!
% if-then-construct is pretty ugly!
% numeric computation of the matrix product
if isempty(b) || isempty(a)
......@@ -1779,7 +1778,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
return
end
end
if a.isConstant() && ~b.isConstant()
if a.isNumber() && ~b.isNumber()
% If the first argument a is constant value, then bad
% things will happen. To avoid this, we calculate
% a * b = (b' * a')'
......@@ -1788,8 +1787,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
P = (b' * a')';
P.setName(a(1).name + " " + b(1).name);
return
elseif a.isConstant() && b.isConstant() ...
&& isempty( a(1).domain ) && isempty(b(1).domain)
elseif a.isNumber() && b.isNumber()
P = a.on() * b.on();
return
end
......@@ -2256,7 +2254,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
k uint64 = 1;
end
if obj.isConstant && isempty(obj(1).gridName)
if obj.isNumber() && isempty(obj(1).gridName)
result = quantity.Discrete(zeros(size(obj)), obj(1).domain, ...
'size', size(obj), 'name', "(d_{.}" + obj(1).name + ")");
return
......@@ -2605,7 +2603,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
if nargin >= 2 && ~isequal( myDomain, obj(1).domain )
% if a new domain is specified for the evaluation of
% the quantity, ...
if obj.isConstant
if obj.isNumber()
% ... duplicate the constant value on the desired
% domain
value = repmat(value(:).', [myDomain.n, ones(1, ndims(obj))]);
......@@ -2750,13 +2748,13 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% [valDiscrete] = ...
% expandValueDiscrete(obj, newDomain) expands the
% discrete values on a new domain. So that a function
% f(z,t) = f(z) + f(t)
% f(z,t) = f1(z) + f2(t)
% can be computed.
gridJoinedLength = newDomain.gridLength;
% get the index of obj.grid in the joined grid
[idx, logicalIdx] = newDomain.gridIndex([obj(1).domain.name]);
[~, logicalIdx] = newDomain.gridIndex([obj(1).domain.name]);
% evaluate the
valDiscrete = obj.on( newDomain(logicalIdx) );
oldDim = ndims(valDiscrete);
......@@ -2773,7 +2771,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
gridIndex(gridOrder) = 1:numel(logicalIdx);
valDiscrete = permute(valDiscrete, [gridIndex, numel(logicalIdx)+(1:ndims(obj))]);
end
end % expandValueDiscrete()
function result = diff_inner(obj, k, diffGridName)
......
......@@ -191,7 +191,7 @@ classdef PolynomialOperator < handle & matlab.mixin.Copyable
end
function C = adj(obj)
assert(obj(1).coefficient.isConstant())
assert(obj(1).coefficient.isNumber())
C = polyMatrix.polynomial2coefficients(misc.adj(sym( obj )), obj(1).s);
c = cell(1, size(C, 3));
......@@ -204,7 +204,7 @@ classdef PolynomialOperator < handle & matlab.mixin.Copyable
end
function C = det(A)
assert(A(1).coefficient.isConstant())
assert(A(1).coefficient.isNumber())
C = det( sym(A) );
C = polyMatrix.polynomial2coefficients(C, A(1).s);
......
......@@ -1354,16 +1354,16 @@ end
end % testOnConstant()
function testIsConstant(testCase)
function testIsNumber(testCase)
C = quantity.Discrete(rand(3,7), quantity.Domain.empty());
testCase.verifyTrue(C.isConstant());
testCase.verifyTrue(C.isNumber());
z = linspace(0, pi)';
A = quantity.Discrete(sin(z), quantity.Domain("z", z));
testCase.verifyFalse(A.isConstant());
testCase.verifyFalse(A.isNumber());
end
end % testIsNumber()
function testMTimesConstant(testCase)
......
......@@ -19,7 +19,7 @@ tc.verifyEqual(K2.diff("z", 1).on(), zeros([4, 5, 2, 2]));
end % testDiffOfConstants
function testZeroOn(tc)
% unittest to fix a bug related with isConstant usage in on() of symbolic
% unittest to fix a bug related with isNumber() usage in on() of symbolic
z = quantity.Domain("z", linspace(0, 1, 11));
quan = 0 * quantity.Symbolic(1-0.5*sym("z"), z, 'name', "Gamma");
tc.verifyEqual(quan.on({linspace(0, 1, 5)}), zeros(5, 1));
......@@ -919,7 +919,7 @@ testCase.verifyEqual(magic700, q.on(myDomain2));
%%
p = quantity.Symbolic([0 0 0 0 z], myDomain);
testCase.verifyFalse(p.isConstant());
testCase.verifyFalse(p.isNumber());
%%
......@@ -934,7 +934,7 @@ end
end % testConstantValues()
function testIsConstant(testCase)
function testIsNumber(testCase)
syms z
Q_constant = quantity.Symbolic(1, quantity.Domain.empty());
Q_var = quantity.Symbolic(z, quantity.Domain('z', 1:2));
......@@ -943,9 +943,9 @@ testCase.verifyError(...
@() quantity.Symbolic(z, quantity.Domain.empty()), ...
'symbolic:sym:matlabFunction:InvalidVars' );
testCase.verifyTrue(Q_constant.isConstant);
testCase.verifyFalse(Q_var.isConstant);
end
testCase.verifyTrue(Q_constant.isNumber());
testCase.verifyFalse(Q_var.isNumber());
end % testIsNumber()
function testEqual(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