Skip to content

Commit

Permalink
Deprecate findat() and findat!()
Browse files Browse the repository at this point in the history
findat() is equivalent to Base.indexin(), and adds to the long list of
find* functions for no reason.

findat!() has no equivalent yet in Base, but it's not used in StatsBase
and its definition can easily be copied to private repositories until Base
gets indexin!().
  • Loading branch information
nalimilan committed Sep 16, 2016
1 parent 07109b6 commit f58fa6c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 38 deletions.
18 changes: 0 additions & 18 deletions docs/source/misc.rst
Expand Up @@ -25,24 +25,6 @@ Miscellaneous Functions

Construct a dictionary that maps each distinct value in ``x`` to its first index.

.. function:: findat(a, x)

For each element in ``x``, find its first index in ``a``. If the value does not appear in ``a``, the corresponding index is ``0``.

**Examples:**

.. code-block:: julia
julia> findat([2,4,6], [2,3,4])
3-element Array{Int64,1}:
1
0
2
.. function:: findat!(r, a, x)

Write the results of ``findat(a, x)`` to a pre-allocated array ``r``.

.. function:: indicatormat(x, k[; sparse=false])

Construct a boolean matrix ``r`` of size ``(k, length(x))`` such that ``r[x[i], i] = true`` and all other elements are set to ``false``.
Expand Down
2 changes: 2 additions & 0 deletions src/deprecates.jl
Expand Up @@ -22,3 +22,5 @@ import Base.varm, Base.stdm
@deprecate adjR2(obj::StatisticalModel, variant::Symbol) adjr2(obj, variant)
@deprecate adjR²(obj::StatisticalModel, variant::Symbol) adjr²(obj, variant)

@deprecate findat(a, x) indexin(x, a)
@deprecate findat!(r, a, x) (y = indexin(x, a); copy!(r, y))
20 changes: 0 additions & 20 deletions src/misc.jl
Expand Up @@ -77,7 +77,6 @@ function inverse_rle{T}(vals::AbstractVector{T}, lens::IntegerVector)
end


# findat (get positions (within a) for elements in b)
"""
indexmap(a)
Expand Down Expand Up @@ -115,25 +114,6 @@ function levelsmap{T}(a::AbstractArray{T})
return d
end

function findat!{T}(r::IntegerArray, a::AbstractArray{T}, b::AbstractArray{T})
length(r) == length(b) || raise_dimerror()
d = indexmap(a)
@inbounds for i = 1 : length(b)
r[i] = get(d, b[i], 0)
end
return r
end


"""
findat(a, b)
For each element in `b`, find its first index in `a`. If the value does
not occur in `a`, the corresponding index is 0.
"""
findat(a::AbstractArray, b::AbstractArray) = findat!(Array(Int, size(b)), a, b)


# indicatormat

# x: input elements,
Expand Down

0 comments on commit f58fa6c

Please sign in to comment.