-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scalartype
function?
#15303
Comments
Do I understand correctly that your If so, there's a related function that would make sense as well, namely a fixed point for |
In the first and third example above, your implementation of Do I understand correctly that in the MD example, the |
Oops, didn't mean to close. Sorry for the spam! |
+1 for something like this. For example when doing automatic differentiation on a function that normally takes a |
Just ran into the need for |
Consider a collection
c
of numeric objects and assume I want to retrieve the underlying scalar type. The prototypical example isVector{T <: Number}
, for which the desired type can be obtained by callingeltype(c)
. The purpose ofeltype
is to return the type obtained when iterating the collection, however, and it is just a lucky coincidence that forVector{T}
the scalar type and the element type agree. In many other cases, this is no longer true.eltype
of that collection isVector{T}
whilescalartype
should beT
.(i,j,v)
triplets of the non-zero elements (that's not what the JuliaSparseMatrixCSC
class does). Theneltype
would be(Int,Int,T)
whilescalartype
should beT
.eltype
would beArray{T,N}
whilescalartype
would beT
.I recently ended up implementing a new
scalartype
function in every module for which this problem occurs, but obviously that might soon lead to name collisions. Would it make sense to provide such a function in JuliaBase
such that every library only adds new methods for its types? The coding effort for this change should be absolutely minimal:scalartype(x) = scalartype(typeof(x))
somewhere.Array
,Factorization
,SparseMatrixCSC
.The downside of the proposed feature is that it adds a new function and thus additional complexity to the ecosystem. I can't think of a better solution to this problem, however, and I highly assume I am not the only one who has ever run into this issue.
The text was updated successfully, but these errors were encountered: