Why my type constructor is not recognized

I'm completely new to Julia (just started today), so forgive me if this is a stupid question, but despite the love of the language, I don’t find a lot of great debugging help there.

Basically, I just want to define an alternative constructor for a method that activates when I enter an array containing any type of Integer (int32, uint8, etc.).

I thought it would be relatively simple and the following is written:

type MyType
    weight_matrices::Array{Array{FloatingPoint}}

    MyType(layer_sizes::Array{Integer}) =
        new([
            rand(layer_sizes[i], layer_sizes[i+1]) for i in [1:length(layer_sizes)-1]
        ])
end

but when I tried to use it:

test = MyType([1,2,1])

I get an error message:

ERROR: no method MyType(Array{Int64, 1})

Switching the alternate constructor from Array{Integer}to Array{Int64}solves the problem, as one might speculate, but I do not want to limit its use.

, ? . , "" ( -?) , .

+3
1

:

type MyType     
       weight_matrices::Array{Array{FloatingPoint}}

       MyType(layer_sizes::Array{Int}) =
           new([
               rand(layer_sizes[i], layer_sizes[i+1]) for i in [1:length(layer_sizes)-1]
           ])
   end

julia> test = MyType([1,2,1])
MyType([
1x2 Array{FloatingPoint,2}:
 0.477698  0.454376,

2x1 Array{FloatingPoint,2}:
 0.318465
 0.280079])

Julia -, [1,2,1], Int, Integer

(. Int - , Int64 64- , Int32 32- )

, , ( )

type MyType                                
       weight_matrices::Array{Array{FloatingPoint}}
end

MyType{T<:Integer}(layer_sizes::Array{T}) =
           MyType([rand(layer_sizes[i], layer_sizes[i+1]) for i in                   [1:length(layer_sizes)-1]])

julia> test = MyType([1,2,1])
MyType([
 1x2 Array{FloatingPoint,2}:
 0.28085  0.10863,

2x1 Array{FloatingPoint,2}:
 0.245685
 0.277009])
0

All Articles