-
-
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
Type-stabilizing array concatenations #19387
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -872,16 +872,16 @@ typealias _TypedDenseConcatGroup{T} Union{Vector{T}, Matrix{T}, _Annotated_Typed | |
|
||
# Concatenations involving un/annotated sparse/special matrices/vectors should yield sparse arrays | ||
function cat(catdims, Xin::_SparseConcatGroup...) | ||
X = SparseMatrixCSC[issparse(x) ? x : sparse(x) for x in Xin] | ||
X = map(x -> SparseMatrixCSC(issparse(x) ? x : sparse(x)), Xin) | ||
T = promote_eltype(Xin...) | ||
Base.cat_t(catdims, T, X...) | ||
end | ||
function hcat(Xin::_SparseConcatGroup...) | ||
X = SparseMatrixCSC[issparse(x) ? x : sparse(x) for x in Xin] | ||
X = map(x -> SparseMatrixCSC(issparse(x) ? x : sparse(x)), Xin) | ||
hcat(X...) | ||
end | ||
function vcat(Xin::_SparseConcatGroup...) | ||
X = SparseMatrixCSC[issparse(x) ? x : sparse(x) for x in Xin] | ||
X = map(x -> SparseMatrixCSC(issparse(x) ? x : sparse(x)), Xin) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, why replace the comprehensions with Would Best! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just to avoid the allocation from creating the array, although it shouldn't make much of a difference.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused, don't both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is just for avoiding the array that holds the arrays. But as I said, it should make much of a difference and I can change it back if you think its better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your modifications look great to me --- thank you for the explanations! |
||
vcat(X...) | ||
end | ||
function hvcat(rows::Tuple{Vararg{Int}}, X::_SparseConcatGroup...) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1659,3 +1659,6 @@ let X = sparse([1 -1; -1 1]) | |
@test Y / 1 == Y | ||
end | ||
end | ||
|
||
# 19304 | ||
@inferred hcat(sparse(rand(2,1)), eye(2,2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're at it, could you choose the return type based on all input types (#2326)? Or do you think it should go into another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to handle that somehow, but I'd say that it would have to be addressed elsewhere. For one I have some ideas that would require the new sub-typing algorithm in place.