Skip to content

Commit b9ef47b

Browse files
committed
* Improved documentation slightly (@marcsous).
* Added code (unused) for fast allocation on some systems (@marcsous).
1 parent 9bf32cd commit b9ef47b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

MappedTensor.m

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
%
7676
% Dot referencing ('.') is not supported.
7777
%
78-
% sum(mtVar <, nDimension>) is supported, to avoid importing the entire tensor
79-
% into memory.
78+
% sum(mtVar <, nDimension, strOutType>) is supported, to avoid importing
79+
% the entire tensor into memory.
8080
%
8181
% Convenience functions:
8282
% SliceFunction: Execute a function on the entire tensor, by slicing it along
@@ -144,6 +144,9 @@
144144

145145
% Author: Dylan Muir <[email protected]>
146146
% Created: 19th November, 2010
147+
%
148+
% Thanks to @marcsous (https://github.com/marcsous) for bug reports and
149+
% fixes.
147150

148151
classdef MappedTensor < handle
149152
properties (SetAccess = private, GetAccess = private)
@@ -1371,12 +1374,16 @@ function make_complex(mtVar)
13711374
% - Get the name of a temporary file
13721375
strFilename = tempname;
13731376

1374-
% - Create the file
1375-
hFile = fopen(strFilename, 'w+');
1376-
1377-
% - Allocate enough space
1378-
fwrite(hFile, 0, 'uint8', nNumEntries-1);
1379-
fclose(hFile);
1377+
% - Fast allocation on some platforms
1378+
bFailed = true;
1379+
% [bFailed, ~] = system(sprintf('fallocate -l %i %s', nNumEntries, strFilename));
1380+
1381+
% - Slow fallback -- use Matlab to write data directly
1382+
if (bFailed)
1383+
hFile = fopen(strFilename, 'w+');
1384+
fwrite(hFile, 0, 'uint8', nNumEntries-1);
1385+
fclose(hFile);
1386+
end
13801387
end
13811388

13821389
function [nBytes, strStorageClass] = ClassSize(strClass)

0 commit comments

Comments
 (0)