I would like to export huge numeric datasets in a format suitable for other programming languages. Say, .csv, .txt, and other similar.
Previously, when using versions <= 13.2, I have used ExportTable
package from this question. However, once I installed 14.1 (which introduced a lot of bugs in my previously working codes), the package stopped importing properly, and I was left with the extremely slow Export.
Okay, it is very fast if exported in the mx format, but it is not widely recognizable.
Is there any workaround nowadays allowing us to export the data fast in Mathematica?
Edit
So, consider a table
tab = RandomReal[{-10,10},{1000,1000}];
The fastest way to export it in Mathematica seems to be the binary format mx
:
Export["tab.mx",tab,"MX"];
It takes 0.04 s on my machine.
Exporting in .json format,
Export["tab.json",tab,"JSON"];
is an order of magnitude slower.
Exporting in Table
format
Export["tab.txt",tab,"Table"];
is another order of magnitude slower.
I want to maintain the speed of exporting in .mx format but with the final output being easily recognizable by any other framework. Previously, I used ExportTable
packaged, but it fails loading in 14.1@Windows 11 (although it worked on 13.2):
<<ExportTable`
LibraryFunction::libload: The function ExportTableG was not loaded from the file C:\Users\miksi\AppData\Roaming\Wolfram\Applications\ExportTable\ExportTable.dll.
The approach referred to by Domen also has some issues, at least at 14.1:
colsep = "\t";
rowsep = "\n";
prec = 16;
SetAttributes[doubletostring, Listable];
doubletostring[x_] := Internal`DoubleToString[x, False, prec];
Export[
"a.txt",
StringJoin[
Map[
row \[Function] StringJoin[Riffle[doubletostring /@ row, colsep], rowsep],
tab]
]
]; // AbsoluteTiming // First
StringJoin::string: String expected at position 1 in Internal
DoubleToString[-1.2255,False,16]<> <>Internal
DoubleToString[-2.59311,False,16]<> <>InternalDoubleToString[0.999274,False,16]<> <>Internal
DoubleToString[-7.61087,False,16]<> <>Internal`DoubleToString[2.91463,False,16]<> <><<1990>>.
Because of this, it looks like the status of this question is unresolved, and no adequate approaches exist.
So, my main question is whether it is possible to fix the ExportTable
package. Given my limited knowledge of C++, I cannot do it myself yet. An alternative question is whether some workarounds exist that provide an exporting speed at least within the order of magnitude in a .txt format. On top of that, I am interested in whether it is possible to export mixed data (numbers, strings) very fast if using .txt or .csv formats.
I would be grateful for any help.
ExportTable
package. $\endgroup$Internal`DoubleToString
isn't available anymore, so you should useInternal`MRealToString
instead, and then the code works. $\endgroup$