Commit 19caf494 by Jakob Gabriel

### quantity.Discrete:

```- fixed infinite loop in mtimes()

quantity.Discrete & .Symbolic:
- renamed variables in isConstant() to improve readability```
parent 224b169b
 ... ... @@ -159,10 +159,10 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete %--------------------------- % --- getter and setters --- %--------------------------- function i = isConstant(obj) function itIs = isConstant(obj) % the quantity is interpreted as constant if it has no grid or % it has a grid that is only one point. i = isempty(obj.gridSize) || prod(obj.gridSize) == 1; itIs = isempty(obj.gridSize) || prod(obj.gridSize) == 1; end function doNotCopy = get.doNotCopy(obj) doNotCopy = obj.doNotCopyPropertiesName(); ... ... @@ -1143,9 +1143,11 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete if isa(a, 'double') P = (b' * a')'; % this recursion is safe, because isa(b, 'double') is considered in % the if above. return end if a.isConstant == 1 && b.isConstant == false if a.isConstant() && ~b.isConstant() % If the first argument a is constant value, then bad % things will happen. To avoid this, we calculate % a * b = (b' * a')' ... ... @@ -1154,7 +1156,7 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete P = (b' * a')'; return end if all(size(b) == 1) % b is a scalar value if numel(b) == 1 % b is a scalar value for k = 1:numel(a) P(k) = innerMTimes(a(k), b); end ... ... @@ -1162,15 +1164,19 @@ classdef (InferiorClasses = {?quantity.Symbolic, ?quantity.Operator}) Discrete return end if all(size(a) == 1) % TODO test the case a is double and b is scalar and vice % versa P = (b' * a')'; return if numel(a) == 1 % in the previous version this was implemented recursivley with % P = (b' * a')'; but this was an ininite loop for numel(a) == 1 % and b.isConstant() for k = 1:numel(b) P(k) = innerMTimes(a, b(k)); end P = reshape(P, size(b)); return end P = innerMTimes(a, b); end end function P = innerMTimes(a, b) assert(size(a, 2) == size(b, 1), ['For multiplication the ', ... ... ...
 ... ... @@ -93,11 +93,11 @@ classdef Symbolic < quantity.Function end end function i = isConstant(obj) i = true; function itIs = isConstant(obj) itIs = true; for k = 1:numel(obj) i = i && isempty(symvar(obj(k).sym)); if ~i itIs = itIs && isempty(symvar(obj(k).sym)); if ~itIs break end end ... ...
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