# LinearSolveFunction unusable if stored to disk?

I encounter a problem when saving a LinearSolveFunction to disk, where the LinearSolveFunction is obtained with LinearSolve for a non-square matrix. If I read the function object from disk, it can no longer be applied to an array.

For example:

In[1]:= a = LinearSolve[{{1, 0}, {0, 1}, {1, 0}}];
In[2]:= a >> "tst.m";
In[3]:= b = << "tst.m";


At this point, a===b and the displayed FullForm of a and b are equal. However:

In[4]:= a[{0, 0, 0}]
Out[4]= {0, 0}

In[5]:= b[{0, 0, 0}]
Out[5]= LinearSolveFunction[{3,2},{2,False,{{{1,0},{0,1},{1,0}}},{0,Automatic,Automatic},0}][{0,0,0}]


I am using Mathematica 8.0.4 (64bit) on Linux.

Is this a bug ? Is there a good workaround ? Of course, I could avoid caching the LinearSolve result altogether and save only the matrix to be "inverted".

-
I think I had a similar issue with InterpolatingFunction a while back, and I think I moved on without an answer –  Rojo Oct 24 '12 at 18:48
Your first line returns an error (matrix not square). –  b.gatessucks Oct 24 '12 at 19:41
–  Mr.Wizard Oct 24 '12 at 19:50

No, this is not a bug. Evaluating

a = LinearSolve[{{1, 0}, {0, 1}, {1, 0}}];


gives a message:

LinearSolve::sqmat1: "The matrix {{1,0},{0,1},{1,0}} is not square so a factorization will not be saved."


which states that the factorization will not be saved. So, once you apply b to the vector there is not factorization that can be used to solve this. Note that this is not an issue with square matrices.

-
It still seems a bit like a bug. Why can't it be written to the file? Why does a[{0, 0, 0}] give an answer when b[{0, 0, 0}] does not? –  user4368 Oct 25 '12 at 1:25
@Jason, because there is no factorization in b. This is not a bug. One may in a future version extend this, though. If you'd like that it might be a good idea to file a suggestion with the tech support. –  user21 Oct 25 '12 at 2:15
Thank you for the comments. Of course, the warning indicates that it doesn't precompute a factorization as it would for the rectangular case. However, I can't find a restriction for the applicability to non-rectangular matrices in the documentation. Indeed, it does work if everything is kept in memory. There appears to be some internal difference between a LinearSolveFunction returned by LinearSolve and one read in from disk, which is not visible at the FullForm level. I don't see why this should not be considered a bug. –  andreasm Oct 25 '12 at 7:51
I agree. I think that, at a minimum, the documentation should be improved. –  Rob2181 Oct 25 '12 at 13:02
The documentation does mentions this: ref/LinearSolveFunction. I field this as a suggestion for future improvement, but can not say when/if an extension will be implemented. –  user21 Oct 25 '12 at 23:45