A function got exactly the type it expected, so why is it throwing a TypeError?

question

#1

Hello everyone!

I’m having a vexing problem with TypeError that is getting in the way of me producing a large amount of needed data.

Imagine a function foo whose return type is Array{T,2}, and a more complicated function bar whose return type is Array{Tuple{Array{Array{T,2},1},Array{Float64,1}},1}. I’m using parallel processing to produce a 2-dimensional array with dimensions NumberOfRows and NumberOfColumns.

The following code works without problems

MyFooArray = @parallel hcat for i=1:NumberOfColumns
[foo() for j=1:NumberOfRows]
end

The following also works OK

Column_1 = [bar() for j=1:NumberOfRows]
Column_2 = [bar() for j=1:NumberOfRows]
FirstTwoColumns = hcat(Column_1,Column_2)

Now here comes the problem. What I really want is not a 2d Array of Foos, but a 2d Array of Bars. In the last example, I produced one without a hitch, so hopefully I can produce a bigger one using a loop, right? Let’s try that

MyBarArray = @parallel hcat for i=1:NumberOfColumns
[bar() for j=1:NumberOfRows]
end

When I run this, julia throws the following TypeError

ERROR: TypeError: collect_to!: in typeassert, expected Array{Tuple{Array{Array{T,2},1},Array{Float64,1}},1}, got Array{Tuple{Array{Array{T,2},1},Array{Float64,1}},1}

What could be causing this? It got exactly the type it expected.

Thanks so much for your help.

Philip


@parallel vcat throws TypeError but @parallel hcat does not
#2

Can you please provide your foo() and bar() functions? Or at least some dummy functions that reproduce the error? It will be much easier to help if we can see a reproducible example.

Also, you can use triple backticks to quote your code like this:

```
code
```


#3

Hi Robin,

As an dummy example of what I meant by foo, let’s say that we have

MyFooArray = @parallel hcat for i=1:5
   [-rand(20,j)*rand(j,100) for j=1:10]
end

What I meant by bar is the function

function DowkerPersistentintervals(A::Matrix)::Tuple{Array{Array{T,2},1},Array{Float64,1}}

which computes the persistent homology intervals of the filtered Dowker complex of a matrix and is part of the Simplicial package


What works fine is the following

@everywhere using Simplicial
Column1=[DowkerPersistentintervals(-rand(20,j)*rand(j,100),1,2,"Core_$(myid())_Temp") for j = 1:10];
Column2=[DowkerPersistentintervals(-rand(20,j)*rand(j,100),1,2,"Core_$(myid())_Temp") for j = 1:10];
MySimpleBarArray=hcat(Column1,Column2)

Where things go sour is when I do this

MyBarArray = @parallel hcat for i=1:2
   [DowkerPersistentintervals(-rand(20,j)*rand(j,100),1,2,"Core_$(myid())_Temp") for j=1:10]
end

which should give the same result, as MySimpleBarArray, but instead throws

ERROR: TypeError: collect_to!: in typeassert, expected Array{Tuple{Array{Array{T,2},1},Array{Float64,1}},1}, got Array{Tuple{Array{Array{T,2},1},Array{Float64,1}},1}

Thanks so much for your help.


#4

Actually, never mind, for some reason it works for large data sets but not small ones. I don’t know why but I won’t complain about it. Consider the matter closed. Thanks anyhow.