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 Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by