DataArrays.jl icon indicating copy to clipboard operation
DataArrays.jl copied to clipboard

max of integer DataArrays results in Array{Any}. Breaks max of several DataArrays

Open mkriele opened this issue 11 years ago • 6 comments

The max function changes the type when applied to instances of DataArrays. As a side effect, taking the maximum of 3 or more instances ofDataArrays result in an error:

julia> u = DataArray([1,2,3]); v = DataArray([0,4,0]); w =[4,0,0];

julia> u = DataArray([1,2,3]); v = DataArray([0,4,0]); w = DataArray([4,0,0]);

julia> typeof(max(u,v))
Array{Any,1}

julia> max(u,v,w)
ERROR: no method isless(DataArray{Int64,1}, Array{Any,1})
 in max at operators.jl:71

I have this issue with Julia 0.3.0 preview (mac binary package). In Julia 0.2.0 max returns and Array{Int64, 1} While perhaps not ideal, at least this allowed to execute max(u,v,w).

mkriele avatar Feb 06 '14 18:02 mkriele

Not totally sure, but I think you probably want maximum, not max.

johnmyleswhite avatar Feb 06 '14 18:02 johnmyleswhite

maximum seems to give a 1-element Array{Int64,1}, but I am interested in a 3-element Array{Int64,1}, such that each component contains the maximum of the corresponding components of the original data arrays. The function max used to give me that and it continues to do so for ordinary arrays.

mkriele avatar Feb 06 '14 18:02 mkriele

We don't currently implement max in operators.jl, so we are falling back on the implementation in Base, which evidently changed between 0.2 and 0.3. We should implement max in operators.jl.

simonster avatar Feb 07 '14 04:02 simonster

Agreed, that's the easiest solution.

johnmyleswhite avatar Feb 07 '14 04:02 johnmyleswhite

max(::Array, ::Array) and maximum(::Array) do different things, and DataArrays matches the Base definitions. Looks like the original issue here is unresolved.

garborg avatar Dec 21 '14 22:12 garborg

Apologies for deleting the post. I realized the difference as soon as i read the documentation after I posted. So ended up deleting the post. Didnt realize you had answered it already! That was fast. For reference : (original post) Why does DataArrays not have 'max' compared to max(::Arrays) and have a maximum instead?

ajkl avatar Dec 21 '14 23:12 ajkl