3
votes

I'm still getting acquainted with the way Julia works and I have an encountered an odd error that I have been unable to surmount:

I have a composite type declared as follows

type Mesh
    domain::Tuple
    resolution::Tuple
    stepsize::Tuple
    data::Array{TransferFunction, 2}

where a TransferFunction is another composite type that I have defined.

When I try and create an instance of this type (with an empty TransferFunction array) using a constructor,

my_mesh = Mesh((100, 100), (100,100), (1, 1), Array(TransferFunction, 2))

I get the following error message:

ERROR: `convert` has no method matching convert(::Type{Array{TransferFunction,2}}, ::Array{TransferFunction,1})

I'm not sure where the Array(TransferFunction, 1) is coming from. I'm assuming that this is a simple problem with a simple solution, but after delving through the Julia docs, I have been unable to find why this is error message is happening.

Anyone have any ideas?

1

1 Answers

4
votes

Array(TransferFunction, 2) doesn't create a two-dimensional matrix — it's a 2-element vector. But Array{TransferFunction, 2} is the type of a two-dimensional matrix of arbitrary size. Which do you intend?

You can either change Array(TransferFunction, 2) to Array(TransferFunction, 2, 1) if you really want a matrix of transfer functions, or you can change the type declaration from a Matrix to a Vector: Array{TransferFunction, 1}. It's a little confusion that the Array constructor arguments and type parameters look so similar, but mean very different things.

One way to help avoid this confusion is to use the Matrix or Vector typealiases in your declarations, e.g., Vector{TransferFunction} instead of Array{TransferFunction, 1}.