@@ -1596,14 +1596,14 @@ cat(n::Integer, x::Integer...) = reshape([x...], (ntuple(x->1, n-1)..., length(x
15961596"""
15971597 findnext(A, i::Integer)
15981598
1599- Find the next linear index >= `i` of a non-zero element of `A`, or `0` if not found.
1599+ Find the next linear index >= `i` of a true element of `A`, or `0` if not found.
16001600
16011601# Examples
16021602```jldoctest
1603- julia> A = [0 0; 1 0 ]
1604- 2×2 Array{Int64 ,2}:
1605- 0 0
1606- 1 0
1603+ julia> A = [false false; true false ]
1604+ 2×2 Array{Bool ,2}:
1605+ false false
1606+ true false
16071607
16081608julia> findnext(A,1)
160916092
@@ -1615,8 +1615,14 @@ julia> findnext(A,3)
16151615function findnext (A, start:: Integer )
16161616 l = endof (A)
16171617 i = start
1618+ warned = false
16181619 while i <= l
1619- if A[i] != 0
1620+ a = A[i]
1621+ if ! warned && ! (a isa Bool)
1622+ depwarn (" In the future `findnext` will only work on boolean collections. Use `findnext(x->x!=0, A)` instead." , :findnext )
1623+ warned = true
1624+ end
1625+ if a != 0
16201626 return i
16211627 end
16221628 i = nextind (A, i)
@@ -1646,58 +1652,6 @@ julia> findfirst(zeros(3))
16461652"""
16471653findfirst (A) = findnext (A, 1 )
16481654
1649- """
1650- findnext(A, v, i::Integer)
1651-
1652- Find the next linear index >= `i` of an element of `A` equal to `v` (using `==`), or `0` if not found.
1653-
1654- # Examples
1655- ```jldoctest
1656- julia> A = [1 4; 2 2]
1657- 2×2 Array{Int64,2}:
1658- 1 4
1659- 2 2
1660-
1661- julia> findnext(A,4,4)
1662- 0
1663-
1664- julia> findnext(A,4,3)
1665- 3
1666- ```
1667- """
1668- function findnext (A, v, start:: Integer )
1669- l = endof (A)
1670- i = start
1671- while i <= l
1672- if A[i] == v
1673- return i
1674- end
1675- i = nextind (A, i)
1676- end
1677- return 0
1678- end
1679- """
1680- findfirst(A, v)
1681-
1682- Return the linear index of the first element equal to `v` in `A`.
1683- Returns `0` if `v` is not found.
1684-
1685- # Examples
1686- ```jldoctest
1687- julia> A = [4 6; 2 2]
1688- 2×2 Array{Int64,2}:
1689- 4 6
1690- 2 2
1691-
1692- julia> findfirst(A,2)
1693- 2
1694-
1695- julia> findfirst(A,3)
1696- 0
1697- ```
1698- """
1699- findfirst (A, v) = findnext (A, v, 1 )
1700-
17011655"""
17021656 findnext(predicate::Function, A, i::Integer)
17031657
@@ -1754,14 +1708,14 @@ findfirst(testf::Function, A) = findnext(testf, A, 1)
17541708"""
17551709 findprev(A, i::Integer)
17561710
1757- Find the previous linear index <= `i` of a non-zero element of `A`, or `0` if not found.
1711+ Find the previous linear index <= `i` of a true element of `A`, or `0` if not found.
17581712
17591713# Examples
17601714```jldoctest
1761- julia> A = [0 0; 1 2 ]
1762- 2×2 Array{Int64 ,2}:
1763- 0 0
1764- 1 2
1715+ julia> A = [false false; true true ]
1716+ 2×2 Array{Bool ,2}:
1717+ false false
1718+ true true
17651719
17661720julia> findprev(A,2)
176717212
@@ -1772,8 +1726,14 @@ julia> findprev(A,1)
17721726"""
17731727function findprev (A, start:: Integer )
17741728 i = start
1729+ warned = false
17751730 while i >= 1
1776- A[i] != 0 && return i
1731+ a = A[i]
1732+ if ! warned && ! (a isa Bool)
1733+ depwarn (" In the future `findprev` will only work on boolean collections. Use `findprev(x->x!=0, A)` instead." , :findprev )
1734+ warned = true
1735+ end
1736+ a != 0 && return i
17771737 i = prevind (A, i)
17781738 end
17791739 return 0
@@ -1806,59 +1766,6 @@ julia> findlast(A)
18061766"""
18071767findlast (A) = findprev (A, endof (A))
18081768
1809- """
1810- findprev(A, v, i::Integer)
1811-
1812- Find the previous linear index <= `i` of an element of `A` equal to `v` (using `==`), or `0` if not found.
1813-
1814- # Examples
1815- ```jldoctest
1816- julia> A = [0 0; 1 2]
1817- 2×2 Array{Int64,2}:
1818- 0 0
1819- 1 2
1820-
1821- julia> findprev(A, 1, 4)
1822- 2
1823-
1824- julia> findprev(A, 1, 1)
1825- 0
1826- ```
1827- """
1828- function findprev (A, v, start:: Integer )
1829- i = start
1830- while i >= 1
1831- A[i] == v && return i
1832- i = prevind (A, i)
1833- end
1834- return 0
1835- end
1836-
1837- """
1838- findlast(A, v)
1839-
1840- Return the linear index of the last element equal to `v` in `A`.
1841- Returns `0` if there is no element of `A` equal to `v`.
1842-
1843- # Examples
1844- ```jldoctest
1845- julia> A = [1 2; 2 1]
1846- 2×2 Array{Int64,2}:
1847- 1 2
1848- 2 1
1849-
1850- julia> findlast(A,1)
1851- 4
1852-
1853- julia> findlast(A,2)
1854- 3
1855-
1856- julia> findlast(A,3)
1857- 0
1858- ```
1859- """
1860- findlast (A, v) = findprev (A, v, endof (A))
1861-
18621769"""
18631770 findprev(predicate::Function, A, i::Integer)
18641771
@@ -1952,9 +1859,7 @@ _index_remapper(iter) = OneTo(typemax(Int)) # safe for objects that don't imple
19521859"""
19531860 find(A)
19541861
1955- Return a vector of the linear indexes of the non-zeros in `A` (determined by `A[i]!=0`). A
1956- common use of this is to convert a boolean array to an array of indexes of the `true`
1957- elements. If there are no non-zero elements of `A`, `find` returns an empty array.
1862+ Return a vector of the linear indices of the true values in `A`.
19581863
19591864# Examples
19601865```jldoctest
@@ -1968,7 +1873,7 @@ julia> find(A)
19681873 1
19691874 4
19701875
1971- julia> find(zeros (3))
1876+ julia> find(falses (3))
197218770-element Array{Int64,1}
19731878```
19741879"""
@@ -1977,7 +1882,12 @@ function find(A)
19771882 I = Vector {Int} (nnzA)
19781883 cnt = 1
19791884 inds = _index_remapper (A)
1885+ warned = false
19801886 for (i,a) in enumerate (A)
1887+ if ! warned && ! (a isa Bool)
1888+ depwarn (" In the future `find(A)` will only work on boolean collections. Use `find(x->x!=0, A)` instead." , :find )
1889+ warned = true
1890+ end
19811891 if a != 0
19821892 I[cnt] = inds[i]
19831893 cnt += 1
@@ -1986,7 +1896,7 @@ function find(A)
19861896 return I
19871897end
19881898
1989- find (x:: Number ) = x == 0 ? Array {Int,1} (0 ) : [ 1 ]
1899+ find (x:: Bool ) = x ? [ 1 ] : Array {Int,1} (0 )
19901900find (testf:: Function , x:: Number ) = ! testf (x) ? Array {Int,1} (0 ) : [1 ]
19911901
19921902findn (A:: AbstractVector ) = find (A)
0 commit comments