Skip to content

Commit d503546

Browse files
committed
Removed overloaded plus and minus methods from `MappedTensor.
1 parent dacb8c6 commit d503546

File tree

1 file changed

+13
-61
lines changed

1 file changed

+13
-61
lines changed

MappedTensor.m

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,13 @@
7474
% Transposition just swaps the first two dimensions, leaving the trailing
7575
% dimensions unpermuted.
7676
%
77-
% Unary plus (+A) and minus (-A) are supported. Binary plus (A+B), minus (A-B),
78-
% times (A*B, A.*B) as long as one of A or B is a scalar. Divide (A/B,
79-
% A./B, B\A, B.\A) is supported, as long as B is a scalar.
77+
% Unary plus (+A) and minus (-A) are supported. Binary plus (A+B) and
78+
% minus (A-B) are not supported, since they require a full load of the
79+
% tensor to implement. Perform addition or subtraction on a referenced
80+
% portion of the tensor, or use SliceFunction to perform the operation.
81+
% Multiplication using times (A*B, A.*B) is supported as long as one of A
82+
% or B is a scalar. Divide (A/B, A./B, B\A, B.\A) is supported, as long as
83+
% B is a scalar.
8084
%
8185
% Transparent casting to other classes is supported in O(1) time. Note that
8286
% due to transparent casting and tranparent O(1) scaling, rounding may
@@ -856,67 +860,15 @@ function delete(mtVar)
856860
%% Overloaded methods (plus, minus)
857861

858862
% plus - METHOD Overloaded binary 'plus' operator (A+B)
859-
function [mtVar] = plus(varargin)
860-
% - Are the inputs numeric?
861-
vbIsNumeric = cellfun(@isnumeric, varargin);
862-
863-
% - Are the inputs scalar?
864-
vbIsScalar = cellfun(@isscalar, varargin);
865-
866-
% - Are the inputs of class MappedTensor
867-
vbIsTensor = cellfun(@(o)(isa(o, 'MappedTensor')), varargin);
868-
869-
% - Can we perform the operation?
870-
if (nnz(vbIsNumeric & vbIsScalar & ~vbIsTensor) ~= 1)
871-
error('MappedTensor:InvalidPlusOperands', ...
872-
'*** MappedTensor: ''plus'' (A+B) is only supported for a MappedTensor object and a scalar.');
873-
end
874-
875-
% - Get the scalar value
876-
fScalar = varargin{vbIsNumeric & vbIsScalar};
877-
mtVar = varargin{vbIsTensor};
878-
879-
% - Find a dimension to slice along
880-
vnTensorSize = size(mtVar);
881-
nSliceDim = numel(vnTensorSize);
882-
883-
% - Perform the addition slice-wise
884-
fhAddition = @(tSlice)(tSlice + fScalar);
885-
SliceFunction(mtVar, fhAddition, nSliceDim);
863+
function [varargout] = plus(varargin) %#ok<STOUT>
864+
error('MappedTensor:NotImplemented', ...
865+
'*** MappedTensor: ''plus'' (A+B) must be performed on a referenced portion of the tensor, or else explicitly with ''SliceFunction''.');
886866
end
887867

888868
% minus - METHOD Overloaded binary 'minus' operator (A-B)
889-
function [mtVar] = minus(varargin)
890-
% - Are the inputs numeric?
891-
vbIsNumeric = cellfun(@isnumeric, varargin);
892-
893-
% - Are the inputs scalar?
894-
vbIsScalar = cellfun(@isscalar, varargin);
895-
896-
% - Are the inputs of class MappedTensor
897-
vbIsTensor = cellfun(@(o)(isa(o, 'MappedTensor')), varargin);
898-
899-
% - Can we perform the operation?
900-
if (nnz(vbIsNumeric & vbIsScalar & ~vbIsTensor) ~= 1)
901-
error('MappedTensor:InvalidMinusOperands', ...
902-
'*** MappedTensor: ''minus'' (A-B) is only supported for a MappedTensor object and a scalar.');
903-
end
904-
905-
% - Get the scalar value
906-
fScalar = varargin{vbIsNumeric & vbIsScalar};
907-
mtVar = varargin{vbIsTensor};
908-
909-
% - Find a dimension to slice along
910-
vnTensorSize = size(mtVar);
911-
nSliceDim = numel(vnTensorSize);
912-
913-
% - Perform the subtraction slice-wise
914-
if (vbIsScalar(1))
915-
fhSubtraction = @(tSlice)(fScalar - tSlice);
916-
else
917-
fhSubtraction = @(tSlice)(tSlice - fScalar);
918-
end
919-
SliceFunction(mtVar, fhSubtraction, nSliceDim);
869+
function [varargout] = minus(varargin) %#ok<STOUT>
870+
error('MappedTensor:NotImplemented', ...
871+
'*** MappedTensor: ''minus'' (A-B) must be performed on a referenced portion of the tensor, or else explicitly with ''SliceFunction''.');
920872
end
921873

922874
%% disp - METHOD Overloaded disp function

0 commit comments

Comments
 (0)