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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Matt J
Matt J el 14 de Mayo de 2013
Editada: Matt J el 14 de Mayo de 2013
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 comentarios
Nicholas Dinsmore
Nicholas Dinsmore el 20 de Mayo de 2013
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 el 20 de Mayo de 2013
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".

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by