Skip to content

Commit 6838ce5

Browse files
committed
* Added a note about rounding when transparent casting and transparent scaling is performed (@marsous)
* Fixed a potential issue where casting was incorrectly performed when assigning data to the tensor
1 parent b14cd82 commit 6838ce5

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

MappedTensor.m

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
% tensor 'tExistingTensor' into a MappedTensor, of the appropriate class.
5454
%
5555
% The optional argument 'Like' allows you to create a MappedTensor with the
56-
% same class and complexity (i.e. real and complex) of 'tExistingTensor'.
56+
% same class and complexity (i.e. real or complex) of 'tExistingTensor'.
5757
% Note that sparse MappedTensors are not supported.
5858
%
5959
% Usage: size(mtVariable)
@@ -78,6 +78,13 @@
7878
% times (A*B, A.*B) as long as one of A or B is a scalar. Divide (A/B,
7979
% A./B, B\A, B.\A) is supported, as long as B is a scalar.
8080
%
81+
% Transparent casting to other classes is supported in O(1) time. Note that
82+
% due to transparent casting and tranparent O(1) scaling, rounding may
83+
% occur in a different class to the returned data, and therefore may not
84+
% match matlab rounding precisely. If this is an issue, index the tensor
85+
% and then scale the returned values rather than rely on O(1) scaling of
86+
% the entire tensor.
87+
%
8188
% Save and load is minimally supported -- data is NOT saved, but on load a new
8289
% mapped tensor will be generated and filled with zeros. Both save and load
8390
% generate warnings.
@@ -524,9 +531,9 @@ function delete(mtVar)
524531
else
525532
tfData = mtVar.fRealFactor .* tfData;
526533
end
527-
528-
% - Recast data, if required, to take into account scaling in
529-
% other class
534+
535+
% - Recast data, if required, to take into account scaling which
536+
% can occur in another class
530537
if (mtVar.bMustCast)
531538
tfData = cast(tfData, mtVar.strClass);
532539
end
@@ -565,20 +572,26 @@ function delete(mtVar)
565572

566573
% - Cast data, if required
567574
if (mtVar.bMustCast)
568-
tfData = cast(tfData, mtVar.strStorageClass);
575+
if (mtVar.bIsComplex)
576+
tfData = complex(cast(real(tfData) ./ mtVar.fRealFactor, mtVar.strStorageClass), ...
577+
cast(imag(tfData) ./ mtVar.fComplexFactor, mtVar.strStorageClass));
578+
579+
else
580+
tfData = cast(tfData ./ mtVar.fRealFactor, mtVar.strStorageClass);
581+
end
569582
end
570583

571584
% - Permute input data
572585
tfData = ipermute(tfData, mtVar.vnDimensionOrder);
573586

574587
if (~isreal(tfData)) || (~isreal(mtVar))
575588
% - Assign to both real and complex parts
576-
mt_write_data(mtVar.hShimFunc, mtVar.hRealContent, S, mtVar.vnOriginalSize, mtVar.strStorageClass, mtVar.nHeaderBytes, real(tfData) ./ mtVar.fRealFactor, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc);
577-
mt_write_data(mtVar.hShimFunc, mtVar.hCmplxContent, S, mtVar.vnOriginalSize, mtVar.strStorageClass, mtVar.nHeaderBytes, imag(tfData) ./ mtVar.fComplexFactor, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc);
589+
mt_write_data(mtVar.hShimFunc, mtVar.hRealContent, S, mtVar.vnOriginalSize, mtVar.strStorageClass, mtVar.nHeaderBytes, real(tfData), mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc);
590+
mt_write_data(mtVar.hShimFunc, mtVar.hCmplxContent, S, mtVar.vnOriginalSize, mtVar.strStorageClass, mtVar.nHeaderBytes, imag(tfData), mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc);
578591

579592
else
580593
% - Assign only real part
581-
mt_write_data(mtVar.hShimFunc, mtVar.hRealContent, S, mtVar.vnOriginalSize, mtVar.strStorageClass, mtVar.nHeaderBytes, tfData ./ mtVar.fRealFactor, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc);
594+
mt_write_data(mtVar.hShimFunc, mtVar.hRealContent, S, mtVar.vnOriginalSize, mtVar.strStorageClass, mtVar.nHeaderBytes, tfData, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc);
582595
end
583596
end
584597

@@ -744,6 +757,11 @@ function delete(mtVar)
744757
bIsInteger = ~isfloat(mtVar) & ~islogical(mtVar) & ~ischar(mtVar);
745758
end
746759

760+
% strfind - METHOD Overloaded strfind function
761+
function [nLoc] = strfind(mtVar, varargin) %#ok<INUSD>
762+
nLoc =[];
763+
end
764+
747765
%% Overloaded methods (uminus, uplus, times, mtimes, ldivide, rdivide, mldivide, mrdivide)
748766

749767
% uminus - METHOD Overloaded uminus operator (-mtVar)

0 commit comments

Comments
 (0)