Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

implemented NullableArray{T,N}(dims...) #152

Merged
merged 5 commits into from
Nov 13, 2016

Conversation

gustafsson
Copy link
Contributor

This is needed for instance when I have a NullableArray A of some type and want to create another one of the same type with only nulls in it like so: typeof(A)(size(A)...)

Johan Gustafsson added 3 commits October 3, 2016 05:02
This is needed for instance when I have a NullableArray of some type and want to create another one of the same type with only nulls in it.
@codecov-io
Copy link

codecov-io commented Oct 3, 2016

Current coverage is 85.89% (diff: 100%)

Merging #152 into master will increase coverage by 1.09%

@@             master       #152   diff @@
==========================================
  Files            14         14          
  Lines           862        865     +3   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            731        743    +12   
+ Misses          131        122     -9   
  Partials          0          0          

Powered by Codecov. Last update 04588eb...23c050f

(::Type{NullableArray{T,N}}){T,N}(dims::Vararg{Int,N}) = NullableArray(T, dims)
else
@compat (::Type{NullableArray{T,1}}){T,N}(x1) = NullableArray(T, x1)
@compat (::Type{NullableArray{T,2}}){T,N}(x1, x2) = NullableArray(T, x1, x2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why define these on 0.4 but not on 0.5? Performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 0.5 a single function takes care of all of them.

@davidagold
Copy link
Contributor

Is there any reason you can't use similar?

julia> A = collect(1:4)
4-element Array{Int64,1}:
 1
 2
 3
 4

julia> X = NullableArray(A)
4-element NullableArrays.NullableArray{Int64,1}:
 1
 2
 3
 4

julia> Y = similar(X)
4-element NullableArrays.NullableArray{Int64,1}:
 #NULL
 #NULL
 #NULL
 #NULL

@gustafsson
Copy link
Contributor Author

@davidagold similar is a good idea. I could do something like similar(T(),3,2,1) when I only have the type of a NullableArray but not an instance. Is it possible to do without creating an empty instance of T (perhaps it gets optimised away anyways?).

@gustafsson
Copy link
Contributor Author

I don't need this anymore.

@gustafsson gustafsson closed this Nov 1, 2016
@nalimilan
Copy link
Member

I think it would still be good to have.

@nalimilan nalimilan reopened this Nov 1, 2016
@gustafsson
Copy link
Contributor Author

@nalimilan ok, I fixed the errors on v"0.4"

@@ -34,6 +34,14 @@ end

@compat (::Type{NullableArray{T}}){T}(dims::Dims) = NullableArray(T, dims)
@compat (::Type{NullableArray{T}}){T}(dims::Int...) = NullableArray(T, dims)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this definition still useful?

Copy link
Contributor Author

@gustafsson gustafsson Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed in order to do things like NullableArray{Int}(3,2).

But a call to NullableArray{T}(dims::Int...) such as A(dim1,dim2) can always be replaced by A((dim1,dim2)) to call the other constructor with ::Dims instead. And A(dims...) can be replaced with A((dims...)). I think it is convenient keep this though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, I thought N could be inferred automatically in your new constructor, but that doesn't work for the call overloading syntax.

@nalimilan
Copy link
Member

@davidagold Good to merge?

function Base.convert{T,N}(::Type{NullableArray{T,N}}, dims::Int...)
length(dims) == N || throw(ArgumentError("Wrong number of arguments. Expected $N, got $(length(dims))."))
NullableArray(T, dims)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 4 space indents for consistency with the rest of the repo.

@davidagold
Copy link
Contributor

What's the failure?

@ararslan
Copy link
Member

ararslan commented Nov 8, 2016

Changed my review since my comments were addressed, but I think the cause of the test failure should be determined before this is merged.

@gustafsson
Copy link
Contributor Author

I don't see how the error is related to this PR. v0.4 and v0.5 pass. but not nightly. does the tests currently pass on master?

@nalimilan
Copy link
Member

nalimilan commented Nov 8, 2016

The error is unrelated, I'm able to reproduce it on master too. Trying to figure out what's going on...

EDIT: that's a bug in Base, see JuliaLang/julia#19270.

@nalimilan
Copy link
Member

All is green now, merging.

@nalimilan nalimilan merged commit 9027987 into JuliaStats:master Nov 13, 2016
@nalimilan
Copy link
Member

Damn, I screwed up and forgot to squash. Squashed and force-pushed manually.

@gustafsson gustafsson deleted the missing-constructor branch November 15, 2016 20:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants