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

- quantity.Discrete: removed unnecessary reshape which was already included in obj2value

- misc.indexGrid: new function replacing slow arrayfun-usage.
parent d06a111e
function myGrid = indexGrid(mySize)
% INDEXGRID creates a cell array of grid vectors. For every element of the mySize integer array one
% cell contain 1 : 1 : mySize(it) is created.
%% Example
% myGrid = misc.indexGrid([1, 2, 3]);
% myGrid{:}
% ans =
% 1
% ans =
% 1 2
% ans =
% 1 2 3
myGrid = cell(numel(mySize), 1);
for it = 1 : numel(myGrid)
myGrid{it} = 1 : 1 : mySize(it);
end
end % indexGrid()
\ No newline at end of file
......@@ -443,7 +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 = obj.obj2value(myDomain);
else
% Since in the remaining cases the order of the domains is not
% neccessarily equal to the order in obj(1).domain, this is
......@@ -466,7 +466,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
'The cell entries for a new grid have to be vectors')
newGrid = myDomain;
myDomain = quantity.Domain.empty();
clear('myDomain');
myDomain(1:length(newGrid)) = quantity.Domain();
for k = 1:length(newGrid)
myDomain(k) = quantity.Domain(gridNames{k}, newGrid{k});
end
......@@ -484,7 +485,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% new domain in the same order as the original one.
gridPermuteIdx = obj(1).domain.getPermutationIdx(myDomain);
assert( any(gridPermuteIdx ~= 0), "grid could not be found.")
assert(any(gridPermuteIdx ~= 0), "grid could not be found.")
end
% get the valueDiscrete data for this object. Apply the
% permuted myDomain. Then the obj2value will be evaluated
......@@ -492,8 +493,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% the new order will be done in the next step.
originalOrderedDomain(gridPermuteIdx) = myDomain;
value = obj.obj2value(originalOrderedDomain);
value = permute(reshape(value, [originalOrderedDomain.gridLength, size(obj)]), ...
[gridPermuteIdx, numel(gridPermuteIdx)+(1:ndims(obj))]);
value = permute(value, [gridPermuteIdx, numel(gridPermuteIdx)+(1:ndims(obj))]);
end
end % if isempty(obj)
end % on()
......@@ -502,17 +502,17 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% get the interpolant of the obj;
if isempty(obj)
value = zeros(size(obj));
indexGrid = arrayfun(@(s)linspace(1,s,s), size(obj), 'UniformOutput', false);
indexGrid = misc.indexGrid(size(obj));
interpolant = numeric.interpolant(...
[indexGrid{:}], value);
else
myGrid = obj(1).grid;
value = obj.obj2value();
indexGrid = arrayfun(@(s)linspace(1,s,s), size(obj), 'UniformOutput', false);
indexGrid = misc.indexGrid(size(obj));
interpolant = numeric.interpolant(...
[myGrid, indexGrid{:}], value);
end
end
end % interpolant()
function assertSameGrid(a, varargin)
......@@ -2483,7 +2483,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
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);
indexGrid = misc.indexGrid(size(obj));
tempInterpolant = numeric.interpolant(...
[obj(1).grid, indexGrid{:}], value);
tempGrid = {myDomain.grid};
......@@ -2491,7 +2491,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
end
end
end
end % obj2value()
function result = diag2vec(obj)
% This method creates a vector of quantities by selecting the
......
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