I have some data generated from some program, and it appears that matrix multiplication on these data are about 10 times slower than on some random data:
Get["tb.dat"];
xls = Range[-500, 500, 1000/(1000 - 1)] // N;
Re[Conjugate[#].(xls*#)] & /@ tb; // AbsoluteTiming
(* {0.067147, Null} *)
tb2 = RandomComplex[{0., 1. + I}, Dimensions[tb]];
Re[Conjugate[#].(xls*#)] & /@ tb2; // AbsoluteTiming
(* {0.004564, Null} *)
So what are the reasons for the performance problem with my data?
The data files are here (6MB).
Update
Here is the same problem with the packed array. Since Save unpacks data, so I have to use DumpSave to demonstrate the problem:
DumpGet["tb3PK.dump"];
Developer`PackedArrayQ@tb3PK
(* True *)
xls = Range[-500, 500, 1000/(1000 - 1)] // N;
Re[Conjugate[#].(xls*#)] & /@ tb3PK; // AbsoluteTiming
(* {0.065747, Null} *)
tb2 = RandomComplex[{0., 1. + I}, Dimensions[tb3PK]];
Re[Conjugate[#].(xls*#)] & /@ tb2; // AbsoluteTiming
(* {0.003482, Null} *)
The file tb3PK.dump is here . I'm using OS X 10 and Mathematica version 10.0.1
RandomComplex
is. Try this:{{Developer`PackedArrayQ@tb, ByteCount@tb},{Developer`PackedArrayQ@tb2, ByteCount@tb2}}
. However according to what I have learned about packed arrays, your data should be packable becauseEqual @@ Map[Head, tb, {2}]
is true, i.e. all of your elements are of the same type. However,Developer`PackedArrayQ@Developer`ToPackedArray[tb]
returnsFalse
. I am not writing this as an answer as I hope that an answer will address how to pack your data. $\endgroup$tb3=Developer``ToPackedArray[tb]
is as slow as the unpacked data. I didn't know that Developer`ToPackedArray could fail to pack an array without giving any error message. $\endgroup$SetSystemOptions["CatchMachineUnderflow" -> False]
, it seems to me if the problem is caused by the auto convention to high precision, turn off it would resolve the problem ? $\endgroup$