I know there have been a few questions about efficient memory storage on mathematica.stackexchange, but I could not find a sufficient answer for my problem (except that it might not work at all).
So what I do have is a large Array, which has Length 4 and is constructed via the following function (with input data from some 8bit per channel image):
(*definition*)
computeDistancesTest = Compile[{{imageData, _Real, 3}, {param, _Real}},
Map[1/(2.*Pi*param^2)*
Exp[-Total[(Transpose[imageData, {2, 3, 1}] - #)^2]/(2*
param^2)] &, imageData, {2}]
, CompilationTarget -> "C",
CompilationOptions -> {"InlineExternalDefinitions" -> True},
RuntimeOptions -> "Speed"];
(*creation*)
n=100;
testImageData = RandomReal[{0, 1}, {n, n, 3}];
distances = computeDistancesTest[testImageData, 1/10.];
The computeDistancesTest function has essentially computes some kind of distance value for each possible pair of pixels in the image. The created array has n^4 entries so by increasing n (corresponding to the image resolution) this array gets considerably more entries. As the function creating the array is compiled the output has MachinePrecision and is also a packed array due to containing all real numbers with the same Precision.
Here are the values I get with Mathematica 10.1 for n=100 (as set above):
Developer`PackedArrayQ[distances]
True
ByteCount@distances
800000168
So here are my questions:
- Why is the
ByteCountso high (8 bytes per entry seems way to much for me, especially considering that the array is a PackedArray)? - How can I reduce the memory consumed by the produced array considering that I want to handle images with resolutions that would make my 16 GB of RAM explode with the array created above?
- I do not need high Precision, so I could sacrifice
MachinePrecision, is there an option to reduce memory usage that way?
ByteCountthen? – Wizard Jun 05 '15 at 20:44