This works:
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 containers are not co- or contra-variant, so [1,2,1]
, which is an array of concrete type Int
is not a subtype of an array of abstract type Integer
(Note, Int is an alias for your native integer type, Int64 on 64 bit machines, Int32 on 32 bit machines)
If you really want your input to be different types of integers, then parameterise the type of the input (using an outer constructor)
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])