|
178 | 178 | methods |
179 | 179 | %% MappedTensor - CONSTRUCTOR |
180 | 180 | function [mtVar] = MappedTensor(varargin) |
| 181 | + |
| 182 | + % - Get a handle to the appropriate shim function (should be done |
| 183 | + % before any errors are thrown) |
| 184 | + [mtVar.hShimFunc, ... |
| 185 | + mtVar.hRepSumFunc, ... |
| 186 | + mtVar.hChunkLengthFunc] = GetMexFunctionHandles; |
| 187 | + |
181 | 188 | % - Filter arguments for properties |
182 | 189 | vbKeepArg = true(numel(varargin), 1); |
183 | 190 | nArg = 2; |
|
211 | 218 | otherwise |
212 | 219 | % - No other properties are supported |
213 | 220 | error('MappedTensor:InvalidProperty', ... |
214 | | - '*** MappedTensor: ''%s'' is not a valid property. Use the ''Class'' keyword to specify the tensor class.', varargin{nArg}); |
| 221 | + '*** MappedTensor: ''%s'' is not a valid property.', varargin{nArg}); |
215 | 222 | end |
216 | 223 | end |
217 | 224 |
|
|
251 | 258 | if (isscalar(vnTensorSize)) |
252 | 259 | vnTensorSize = vnTensorSize * [1 1]; |
253 | 260 | end |
254 | | - |
255 | 261 |
|
256 | 262 | % - Validate tensor size argument |
257 | 263 | try |
|
260 | 266 | error('MappedTensor:Arguments', ... |
261 | 267 | '*** MappedTensor: Error: ''vnTensorSize'' must be a positive integer vector.'); |
262 | 268 | end |
263 | | - |
| 269 | + |
264 | 270 | % - Make enough space for a temporary tensor |
265 | 271 | if (mtVar.bTemporary) |
266 | 272 | mtVar.strRealFilename = create_temp_file(prod(vnTensorSize) * mtVar.nClassSize + mtVar.nHeaderBytes); |
267 | 273 | end |
268 | 274 |
|
269 | | - % - Get a handle to the appropriate shim function |
270 | | - [mtVar.hShimFunc, ... |
271 | | - mtVar.hRepSumFunc, ... |
272 | | - mtVar.hChunkLengthFunc] = GetMexFunctionHandles; |
273 | | - |
274 | 275 | % - Open the file |
275 | 276 | if (isempty(mtVar.strMachineFormat)) |
276 | 277 | [mtVar.hRealContent, mtVar.strMachineFormat] = mtVar.hShimFunc('open', mtVar.strRealFilename); |
|
291 | 292 | '*** MappedTensor: Error: only ''ieee-be'' and ''ieee-le'' machine formats are supported.'); |
292 | 293 | end |
293 | 294 |
|
| 295 | + % - Record the original tensor size, remove trailing unitary dimensions |
| 296 | + if (vnTensorSize(end) == 1) && (numel(vnTensorSize) > 2) |
| 297 | + nLastNonUnitary = max(2, find(vnTensorSize ~= 1, 1, 'last')); |
| 298 | + vnTensorSize = vnTensorSize(1:nLastNonUnitary); |
| 299 | + end |
| 300 | + |
| 301 | + mtVar.vnOriginalSize = vnTensorSize; |
| 302 | + |
294 | 303 | % - Initialise dimension order |
295 | 304 | mtVar.vnDimensionOrder = 1:numel(vnTensorSize); |
296 | 305 |
|
297 | 306 | % - Record number of total elements |
298 | 307 | mtVar.nNumElements = prod(vnTensorSize); |
299 | | - |
300 | | - % - Record the original tensor size |
301 | | - mtVar.vnOriginalSize = vnTensorSize; |
302 | 308 | end |
303 | 309 |
|
304 | 310 | % delete - DESTRUCTOR |
@@ -487,7 +493,7 @@ function delete(mtVar) |
487 | 493 | % - Permute input data |
488 | 494 | tfData = ipermute(tfData, mtVar.vnDimensionOrder); |
489 | 495 |
|
490 | | - if (~isreal(tfData)) |
| 496 | + if (~isreal(tfData)) || (~isreal(mtVar)) |
491 | 497 | % - Assign to both real and complex parts |
492 | 498 | mt_write_data(mtVar.hShimFunc, mtVar.hRealContent, subs, mtVar.vnOriginalSize, mtVar.strClass, mtVar.nHeaderBytes, real(tfData) ./ mtVar.fRealFactor, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc); |
493 | 499 | mt_write_data(mtVar.hShimFunc, mtVar.hCmplxContent, subs, mtVar.vnOriginalSize, mtVar.strClass, mtVar.nHeaderBytes, imag(tfData) ./ mtVar.fComplexFactor, mtVar.bBigEndian, mtVar.hRepSumFunc, mtVar.hChunkLengthFunc); |
@@ -1376,7 +1382,11 @@ function make_complex(mtVar) |
1376 | 1382 |
|
1377 | 1383 | % - Fast allocation on some platforms |
1378 | 1384 | bFailed = true; |
1379 | | -% [bFailed, ~] = system(sprintf('fallocate -l %i %s', nNumEntries, strFilename)); |
| 1385 | +% if ispc() |
| 1386 | +% [bFailed, ~] = system(sprintf('fsutil file createnew %s %i', file, nbytes)); |
| 1387 | +% else |
| 1388 | +% [bFailed, ~] = system(sprintf('fallocate -l %i %s', nNumEntries, strFilename)); |
| 1389 | +% end |
1380 | 1390 |
|
1381 | 1391 | % - Slow fallback -- use Matlab to write data directly |
1382 | 1392 | if (bFailed) |
|
0 commit comments