This repository has been archived by the owner on May 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
address vcat return inconsistency #187
Closed
Closed
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1689728
address https://github.com/JuliaStats/NullableArrays.jl/issues/167
cjprybol a36f6a4
reorder import statements
cjprybol 5d9d982
move from operators files to nullablevector files
cjprybol 4aa635c
reduce the piracy
cjprybol 7d948a0
no more piracy!
cjprybol 1b64de2
passing tests
cjprybol 9cc8381
rearrange functions to cleanup comments
cjprybol b8c87b5
spacing
cjprybol bb0b1ee
add more tests and reorder tests to match function order
cjprybol b8211a9
no more stack overflows
cjprybol d28b7b8
Int64 -> Int
cjprybol 6c30d14
implement 2 argument cases and comment out 3 argument tests
cjprybol 2e2b98a
correct spacing issue
cjprybol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -311,3 +311,80 @@ function Base.empty!(X::NullableVector) | |
empty!(X.isnull) | ||
return X | ||
end | ||
|
||
function Base.promote_rule{T1,T2}(::Type{T1}, ::Type{Nullable{T2}}) | ||
promote_rule(Nullable{T2}, T1) | ||
end | ||
|
||
function Base.typed_hcat{T}(::Type{T}, A::AbstractVecOrMat...) | ||
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. It's not OK to override Base methods like this with signatures that only involve Base types. That will affect unrelated packages and is known as type piracy. 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. That makes perfect sense. Thanks for explaining what type piracy is |
||
nargs = length(A) | ||
nrows = size(A[1], 1) | ||
ncols = 0 | ||
dense = true | ||
for j = 1:nargs | ||
Aj = A[j] | ||
if size(Aj, 1) != nrows | ||
throw(ArgumentError("number of rows of each array must match (got $(map(x->size(x,1), A)))")) | ||
end | ||
dense &= isa(Aj,Array) | ||
nd = ndims(Aj) | ||
ncols += (nd==2 ? size(Aj,2) : 1) | ||
end | ||
i = findfirst(a -> isa(a, NullableArray), A) | ||
B = similar(full(A[i == 0 ? 1 : i]), T, nrows, ncols) | ||
pos = 1 | ||
if dense | ||
for k=1:nargs | ||
Ak = A[k] | ||
n = length(Ak) | ||
copy!(B, pos, Ak, 1, n) | ||
pos += n | ||
end | ||
else | ||
for k=1:nargs | ||
Ak = A[k] | ||
p1 = pos+(isa(Ak,AbstractMatrix) ? size(Ak, 2) : 1)-1 | ||
B[:, pos:p1] = Ak | ||
pos = p1+1 | ||
end | ||
end | ||
return B | ||
end | ||
|
||
function Base.typed_vcat{T}(::Type{T}, V::AbstractVector...) | ||
n::Int = 0 | ||
for Vk in V | ||
n += length(Vk) | ||
end | ||
i = findfirst(v -> isa(v, NullableArray), V) | ||
a = similar(full(V[i == 0 ? 1 : i]), T, n) | ||
pos = 1 | ||
for k=1:length(V) | ||
Vk = V[k] | ||
p1 = pos+length(Vk)-1 | ||
a[pos:p1] = Vk | ||
pos = p1+1 | ||
end | ||
a | ||
end | ||
|
||
function Base.typed_vcat{T}(::Type{T}, A::AbstractMatrix...) | ||
nargs = length(A) | ||
nrows = sum(a->size(a, 1), A)::Int | ||
ncols = size(A[1], 2) | ||
for j = 2:nargs | ||
if size(A[j], 2) != ncols | ||
throw(ArgumentError("number of columns of each array must match (got $(map(x->size(x,2), A)))")) | ||
end | ||
end | ||
i = findfirst(a -> isa(a, NullableArray), A) | ||
B = similar(full(A[i == 0 ? 1 : i]), T, nrows, ncols) | ||
pos = 1 | ||
for k=1:nargs | ||
Ak = A[k] | ||
p1 = pos+size(Ak,1)-1 | ||
B[pos:p1, :] = Ak | ||
pos = p1+1 | ||
end | ||
return B | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is not actually needed (and would have to live in Base anyway). Indeed you should never call
promote_rule
directly, but usepromote_type
instead. This already works: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.
Yes, you're right. I see now that
promote_type
has the consistency I was expecting frompromote_rule
. I'll need to learn more about those differences.