I'd be very interested to know if this exists as well. This issue 
consistently arises when building test fixtures. 
At the moment, I use this as a workaround (this may not apply for your use 
case):

```julia
using Base.Test

# Infer tightened element type of array.
function infer_eltype(ar::Array)
  # Determine element type by reduction loop
  el_type = None
  for el in ar
    el_type = typejoin(el_type, typeof(el))
  end

  # If element type cannot be determined, go with collection's element type
  if el_type == None
    el_type = eltype(ar)
  end

  # Return inferred element type
  return el_type
end

# Example use case
mat = {1.0 2; 3 4.0}
el_type = infer_eltype(mat)
tight_mat = convert(Array{el_type}, mat)
@test eltype(tight_mat) == Real
@test size(tight_mat) == size(mat)
@test isequal(tight_mat, mat)
```

Hope this helps.

On Monday, July 28, 2014 5:42:24 AM UTC+10, John Myles White wrote:
>
> Do we have a function that will take in an Array{Any}, compute the 
> typejoin of its elements and convert the Array to the tightest possible 
> type? 
>
>  — John 
>
>

Reply via email to