Why doesn't the sparse command accept uintx as inputs for the location vectors in the long form of the command?

1 次查看(过去 30 天)
When I use the sparse command in the S = sparse(i,j,s,m,n) form, with vectors of type uintx for i & j, I get an error saying that type isn't supported. But since those are indexes would the sparse command have to convert to an integer format to use them? Now to be clear I am not trying to specify the contents ie the type of the sparse martix as an integer, the documentation clearly says only double and bool
As a note of the application. I have found that my function that generates a large sparse matrix, 25-50% faster if I change a single line of code to make the index arrays integers, which is understandable since integers=faster and smaller. I would have thought this would be supported. I could typecast the arrays but that seems like a redundant step.

采纳的回答

Matt J
Matt J 2013-5-14
编辑:Matt J 2013-5-14
SPARSE uses doubles to store index data. Why it doesn't pre-cast uintx input to doubles for you is a fair enough question, but the index data will eventually need to be converted to doubles one way or another. It is also a fair question why after 10 years only double and logical matrix entries are supported. Probably because SPARSE originated as 3rd party code, and now it's hard to change.
  7 个评论
Nicholas Dinsmore
Nicholas Dinsmore 2013-5-20
Guys, Thank you for your response. I do think that it is important for sparse to accept the int and uint as input. For a large sparse matrix it was surprising to me how much faster I could make the generation code just by using int instead of doubles of the indexing arithmetic(to see the benefit you need to give the JIT an opportunity to optimize). And because of the strength of the type system in matlab, it was very few lines of code to make things ints.
Matt J
Matt J 2013-5-20
For a large sparse matrix it was surprising to me how much faster I could make the generation code just by using int instead of doubles of the indexing arithmetic(to see the benefit you need to give the JIT an opportunity to optimize)
You mentioned this in your original posting as well, but to me at least it's not clear what you mean by the "generation code". If the matrix is generated by calling sparse() and if sparse() responds to integer inputs with an error, then how can it be "faster".

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sparse Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by