The unique(itr, dim) function seems broken to me. It will return repeated
elements unless there are exactly the same number of repeated elements
along a dim for all other indices of the array (actually even then it often
will return repeated elements). For example:

julia> a=[[3,1,2,3,1] [1,1,2,1,1]]
5x2 Array{Int64,2}:
 3  1
 1  1
 2  2
 3  1
 1  1

julia> unique(a, 1)
3x2 Array{Int64,2}:
 3  1
 1  1
 2  2

This is incorrect for the second column. Shouldn't it produce something
like:

julia> myunique(a, 1)
2-element Array{Array{Int64,1},1}:
 [3,1,2]
 [1,2]

which the following code will produce:

function myunique{T,N}(A::Array{T,N}, dim::Int)

    1 <= dim <= N || error("dim outside range 1:N")

    sza = size(A)
    szb = (sza[1:dim-1]..., sza[dim+1:end]...)

    R1 = CartesianRange(sza[1:dim-1])
    R2 = CartesianRange(sza[dim+1:end])

    reshape(Vector{T}[unique(A[i,:,j]) for i in R1, j in R2], szb)

end

and it works in higher dimensions as well. Maybe I'm just not understanding
how unique(itr, dim) is suppose to work.


On Wed, Jan 13, 2016 at 4:22 PM, Dan <[email protected]> wrote:

> Essentially, not much. `union` accepts multiple arguments with multiple
> types, but `unique` accepts a single collection.
> For example:
> union(1,2,3,3) == unique([1,2,3,3])
> This would probably make `union` slightly slower.
>
>
> On Wednesday, January 13, 2016 at 11:58:18 PM UTC+2, Sheehan Olver wrote:
>>
>> Is there a difference between these two commands:
>>
>> *julia> **unique([1,2,3,3])*
>>
>> *3-element Array{Int64,1}:*
>>
>> * 1*
>>
>> * 2*
>>
>> * 3*
>>
>>
>> *julia> **union([1,2,3,3])*
>>
>> *3-element Array{Int64,1}:*
>>
>> * 1*
>>
>> * 2*
>>
>> * 3*
>>
>>

Reply via email to