tk3369
December 9, 2017, 7:18pm
1
I would have thought that the fill() function is smarter. Now I have to cast to the widest type before calling it… Any thoughts? Am I too picky?
julia> fill(0, (Int64(10), Int32(8)))
ERROR: MethodError: no method matching fill(::Int64, ::Tuple{Int64,Int32})
Closest candidates are:
fill(::Any, ::Tuple{Vararg{Int64,N}} where N) at array.jl:253
fill(::Any, ::Integer...) at array.jl:254
julia> fill(0, (Int64(10), Int64(8)))
10×8 Array{Int64,2}:
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
I think it should accept all mixtures of subtypes of Integer
. Perhaps broaden the definition of Dims
?
I don’t think Dims
should be changed. In general, the approach taken is to create convenience methods which convert all values to Int
before calling the main method, to minimize the amount of code that needs to be recompiled. Looks like one such method is lacking or has a too strict signature.
opened 05:54PM - 29 Jul 17 UTC
closed 05:59PM - 16 Oct 23 UTC
arrays
```
Matrix{Float32}(3, 4) # works
Matrix{Float32}(0x3, 0x4) # work… s
Matrix{Float32}((3, 4)) # works
Matrix{Float32}((0x3, 0x4)) # errors
```
Would it be possible to broaden the `Matrix(Tuple)` constructor to allow types `<: Integer` in the Tuple?
Other constructors work:
```
julia> zeros(0x3,0x4)
3×4 Array{Float64,2}:
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
julia> zeros((0x3,0x4))
3×4 Array{Float64,2}:
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
```
opened 06:20PM - 29 Jul 17 UTC
closed 06:12PM - 16 Oct 23 UTC
arrays
See #23029 for related issue. This is one example of an inconsistency between Sh… aredMatrix construction and Matrix construction:
```
julia> SharedMatrix{Float32}(0x3, 0x4)
ERROR: MethodError: Cannot `convert` an object of type Tuple{UInt8,UInt8} to an object of type SharedArray{Float32,2}
This may have arisen from a call to the constructor SharedArray{Float32,2}(...),
since type constructors fall back to convert methods.
Stacktrace:
[1] #call#605(::Array{Any,1}, ::Type{SharedArray{Float32,2}}, ::UInt8, ::Vararg{UInt8,N} where N) at ./sharedarray.jl:146
[2] SharedArray{Float32,2}(::UInt8, ::UInt8) at ./sharedarray.jl:146
```
It would be nice if the constructors for `SharedMatrix` were the same as for `Matrix`.
opened 11:07AM - 14 Aug 17 UTC
closed 11:41AM - 14 Aug 17 UTC
Julia v0.6
```
a::Int64 = 5
b::Tuple{Int64, Int64} = (a, a)
Matrix{Int64}(… b)
```
This code works, but if you replace all instances of Int64 with Int32 it does not work anymore.
```
ERROR: MethodError: Cannot `convert` an object of type Tuple{Int32,Int32} to an object of type Array{Int32,2}
This may have arisen from a call to the constructor Array{Int32,2}(...),
since type constructors fall back to convert methods.
```
But if you write it a bit different
```
a::Int64 = 5
Matrix{Int64}(a, a)
```
this will work with either Int32 or Int64.
I think my first sample should work with any integer-version.
If you really want to use different Integer
types, I suggest that you just call Dims
of your tuple
julia> fill(0, Dims((Int64(10), Int32(8))))
10×8 Array{Int64,2}:
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
I’d favor just accepting Int
s, since we will always convert to that internally anyway, and let the user convert with e.g. Dims
instead.