[SciPy-User] Upcasting of sparse matrix
Dinesh Vadhia
dineshbvadhia at hotmail.com
Tue Nov 26 03:37:48 EST 2013
This question was asked a few years ago but still not convinced what the right approach is. Consider a simple binary matrix-vector calculation:
|1 0 1 0| |2.0|
|0 0 1 0| |1.1| = Ax
|0 0 0 1| |4.5|
If A is defined as a dtype=int matrix then during the Ax calculation is it upcast to a float to match x? The previous answer was that it is upcast and hence, to avoid a performance penalty define A as a dtype=float matrix.
However, it has been pointed out that A's dtype doesn't change, see <https://github.com/scipy/scipy/blob/master/scipy/sparse/compressed.py#L493>, where 'other.data' is not cast before being passed to the wrapped c++ routines. If so, maybe the blas module performs an automatic upcast or maybe not.
'A' has been tested on large matrices with both dtype=int and dtype=float and no significant timing differences were observed between the two. The reason for raising the question again is that A with dtype=int uses less memory than with dtype=float.
Would like to understand what is really going on. Thx!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20131126/6d3405f8/attachment.html>
More information about the SciPy-User
mailing list