ProjectTo{SparseMatrixCSC}
can incorrectly assume eltype
of projected value
#571
Labels
ProjectTo
related to the projection functionality
The example below attempts to project a
Unitful.Quantity
differential onto a sparse array ofFloat64
The error occurs here because we pre-allocate the
nzvals
vector usingproject_type(project.element)
. However,project_type
doesn't take into account the value we are projecting, which, in the case of aUnitful.Quantity
, can mean thatproject_type(ProjectTo(A)) != eltype(A)
.In the case of
SparseMatrixCSC
, we can rewrite the projection without preallocatingnzvals
usingmapreduce
to get a type-stable pullback that doesn't useproject_type
. In general, would it be better to get away withoutproject_type
and write projections which infer the type based on the input types?E- On closer inspection the
mapreduce
solution runs into issues if the differential isn't a homogeneous type,project_type
may be a necessary solution hereThe text was updated successfully, but these errors were encountered: