Skip to content

Commit

Permalink
Merge pull request #58 from davidclemens/improve-dataPool-performance
Browse files Browse the repository at this point in the history
Add listeners to dataPool
  • Loading branch information
davidclemens authored Apr 23, 2021
2 parents 8f860a4 + d65937c commit 42c7767
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
40 changes: 38 additions & 2 deletions +DataKit/+Metadata/@sparseBitmask/setBit.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function obj = setBit(obj,i,j,bit,highlow)
function obj = setBit(obj,i,j,bit,highlow,varargin)

% Note:
% if the same bit at the same index is adressed multiple times with
Expand All @@ -17,6 +17,17 @@

import DataKit.arrayhom

if nargin == 5
fastMode = true;
elseif nargin == 6
fastMode = varargin{1};
if ~isscalar(fastMode) || ~islogical(fastMode)
error('Dingi:DataKit:Metadata:sparseBitmask:setBit:invalidFastModeInput',...
'FastMode has to be provided as a scalar logical.')
end
end


if any(bit(:) > 52) || any(bit(:) < 1)
error('Dingi:DataKit:Metadata:sparseBitmask:setBit:bitPositionExceedsLimit',...
'A bit position exceeds the limits. Only bits 1 to 52 can be set.')
Expand Down Expand Up @@ -48,13 +59,37 @@
highlow(highlow > 0) = 1;

[i,j,bit,highlow] = arrayhom(i,j,bit,highlow);

if ~fastMode
[u,uind] = unique(cat(2,i,j,bit),'rows');

i = u(:,1);
j = u(:,2);
bit = u(:,3);
highlow = highlow(uind);
end

if nnz(obj.Bitmask) == 0
% no non-zero elements
bitmaskNew = bitset(zeros(size(bit)),bit,highlow);
obj.Bitmask = sparse(i,j,bitmaskNew,Sz(1),Sz(2));
else

% non-zero elements already exist

%%{
ind = sub2ind(obj.Sz,i,j);
bitmaskIn = full(obj.Bitmask(ind));

if ~fastMode
[uInd,~,uIndInd2] = unique(ind);
bitmaskIn = bitset(bitmaskIn,bit,highlow);
bitmaskOut = accumarray(uIndInd2,bitmaskIn,size(uInd),@sum);
obj.Bitmask(uInd) = bitmaskOut;
else
obj.Bitmask(ind) = bitset(bitmaskIn,bit,highlow);
end
%}
%{
[iBm,jBm] = find(obj.Bitmask);
indBm = sub2ind(obj.Sz,iBm,jBm);
Expand Down Expand Up @@ -86,6 +121,7 @@
bitmask(indChange) = bitmaskChange;
obj.Bitmask = bitmask;
%}
end

% for ii = 1:n
Expand Down
2 changes: 1 addition & 1 deletion +DataKit/+Metadata/@sparseBitmask/sparseBitmask.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
methods
disp(obj)
obj = initializeBitmask(obj,i,j,bit,sz)
obj = setBit(obj,i,j,bit,highlow)
obj = setBit(obj,i,j,bit,highlow,varargin)
varargout = getBit(obj,varargin)
end
methods (Static, Hidden)
Expand Down
2 changes: 2 additions & 0 deletions +DataKit/@dataPool/applyCalibrationFunction.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@

obj.Data{poolIdx}(:,variableIdx) = fh(time,obj.DataRaw{poolIdx}(:,variableIdx));

obj.IndexNeedsUpdating = true;

if nargout == 1
varargout{1} = obj;
end
Expand Down
2 changes: 2 additions & 0 deletions +DataKit/@dataPool/setInfoProperty.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

obj.Info(pool).(property)(idx) = value;

obj.IndexNeedsUpdating = true;

if nargout == 1
varargout{1} = obj;
end
Expand Down
2 changes: 2 additions & 0 deletions +DataKit/@dataPool/setMeasuringDeviceProperty.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

obj.Info(pool).VariableMeasuringDevice(idx).(property) = value;

obj.IndexNeedsUpdating = true;

if nargout == 1
varargout{1} = obj;
end
Expand Down
2 changes: 1 addition & 1 deletion +GearKit/@gearDeployment/calibrateMeasuringDevices.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ function calibrateMeasuringDevices(obj)
obj.data.setInfoProperty(pool(v),var(v),'Variable',valueVariableInfo.Variable);
end
end

printDebugMessage('Info','Calibrating %s measuring device(s)... done',char(obj.gearType))
end
8 changes: 5 additions & 3 deletions +Tests/+DataKit/+Metadata/+sparseBitmask/setBit_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function testIndexExceedsSize(testCase)
% setBit(testCase.Bitmask,testCase.Sz(1) + 1,1,1,1),...
% 'Dingi:DataKit:Metadata:sparseBitmask:setBit:subscriptsExceedBitmaskSize')
end
function testSetBit(testCase,i,j,bit,hl)
function testSetBitFastModeDisabled(testCase,i,j,bit,hl)
import matlab.unittest.fixtures.SuppressedWarningsFixture
import DataKit.Metadata.sparseBitmask
import DataKit.arrayhom
Expand All @@ -147,7 +147,7 @@ function testSetBit(testCase,i,j,bit,hl)

% get actual value
BitmaskA = testCase.Bitmask;
act = setBit(BitmaskA,i,j,bit,hl);
act = setBit(BitmaskA,i,j,bit,hl,false); % test without fastMode
act = act.Bitmask;

% determine expected bitmask
Expand All @@ -159,7 +159,9 @@ function testSetBit(testCase,i,j,bit,hl)
[uBits,~,uBitsInd] = unique(cat(2,ind,bit2),'rows'); % get unique index-bit touples
for ii = 1:size(uBits,1)
mask = uBitsInd == ii;
highlow = max(hl2(mask)); % if the same bit is addressed multiple times set it to the max of the corresponding highlow values.
highlow = hl2(find(mask,1)); % if the same bit is addressed multiple times set it to the first of the corresponding highlow values.
% highlow = max(hl2(mask)); % if the same bit is addressed multiple times set it to the first of the corresponding highlow values.

exp(uBits(ii,1)) = bitset(full(exp(uBits(ii,1))),uBits(ii,2),highlow);
end

Expand Down

0 comments on commit 42c7767

Please sign in to comment.