Skip to content

Commit 01e5a22

Browse files
committed
* Changed order of scaling and casting, to apply operation after cast.
* Fixed bug relating to complex scaling factor
1 parent 1b4c506 commit 01e5a22

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

MappedTensor.m

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -502,15 +502,29 @@ function delete(mtVar)
502502
end
503503

504504
% - Reference the tensor data element
505+
tfData = mt_read_data(mtVar.hShimFunc, mtVar.hRealContent, S, vnReferencedTensorSize, mtVar.strStorageClass, mtVar.nHeaderBytes, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc);
506+
505507
if (mtVar.bIsComplex)
506-
% - Get the real and complex parts
507-
tfData = complex(mtVar.fRealFactor .* mt_read_data(mtVar.hShimFunc, mtVar.hRealContent, S, vnReferencedTensorSize, mtVar.strStorageClass, mtVar.nHeaderBytes, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc), ...
508-
mtVar.fComplexFactor .* mt_read_data(mtVar.hShimFunc, mtVar.hCmplxContent, S, vnReferencedTensorSize, mtVar.strStorageClass, mtVar.nHeaderBytes, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc));
509-
else
510-
% - Just return the real part
511-
tfData = mtVar.fRealFactor .* mt_read_data(mtVar.hShimFunc, mtVar.hRealContent, S, vnReferencedTensorSize, mtVar.strStorageClass, mtVar.nHeaderBytes, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc);
508+
tfImagData = mt_read_data(mtVar.hShimFunc, mtVar.hCmplxContent, S, vnReferencedTensorSize, mtVar.strStorageClass, mtVar.nHeaderBytes, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc);
509+
end
510+
511+
% - Cast data, if required
512+
if (mtVar.bMustCast)
513+
tfData = cast(tfData, mtVar.strClass);
514+
515+
if (mtVar.bIsComplex)
516+
tfImagData = cast(tfImagData, mtVar.strClass);
517+
end
512518
end
513519

520+
% - Apply scaling factors
521+
if (mtVar.bIsComplex)
522+
tfData = complex(mtVar.fRealFactor .* tfData, ...
523+
mtVar.fComplexFactor .* tfImagData);
524+
else
525+
tfData = mtVar.fRealFactor .* tfData;
526+
end
527+
514528
% - Permute dimensions
515529
tfData = permute(tfData, mtVar.vnDimensionOrder);
516530

@@ -523,11 +537,6 @@ function delete(mtVar)
523537
cnSize = num2cell(size(tfData));
524538
tfData = reshape(tfData, cnSize{1:nNumDims-1}, []);
525539
end
526-
527-
% - Cast data, if required
528-
if (mtVar.bMustCast)
529-
tfData = cast(tfData, mtVar.strClass);
530-
end
531540
end
532541

533542
% subsasgn - METHOD Overloaded subsasgn
@@ -772,7 +781,7 @@ function delete(mtVar)
772781
mtVar.fRealFactor = mtVar.fRealFactor .* fScalar;
773782

774783
if (mtVar.bIsComplex)
775-
mtVar.fCmplxFactor = mtVar.fCmplxFactor .* fScalar;
784+
mtVar.fComplexFactor = mtVar.fComplexFactor .* fScalar;
776785
end
777786
end
778787

0 commit comments

Comments
 (0)