diff --git a/NEWS.md b/NEWS.md index a66404e1cf104..742fa8831e2a3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -364,14 +364,15 @@ This section lists changes that do not have deprecation warnings. trait; see its documentation for details. Types which support subtraction (operator `-`) must now implement `widen` for hashing to work inside heterogeneous arrays. - * `findn(x::AbstractArray)` has been deprecated in favor of `find(!iszero, x)`, which + * `findn(x::AbstractArray)` has been deprecated in favor of `findall(!iszero, x)`, which now returns cartesian indices for multidimensional arrays (see below, [#25532]). - * `find` now returns the same type of indices as `keys`/`pairs` for `AbstractArray`, - `AbstractDict`, `AbstractString`, `Tuple` and `NamedTuple` objects ([#24774]). + * `find` has been renamed to `findall`, and now returns the same type of indices + as `keys`/`pairs` for `AbstractArray`, `AbstractDict`, `AbstractString`, `Tuple` + and `NamedTuple` objects ([#24774], [#25545]). In particular, this means that it returns `CartesianIndex` objects for matrices and higher-dimensional arrays instead of linear indices as was previously the case. - Use `LinearIndices(a)[find(f, a)]` to compute linear indices. + Use `LinearIndices(a)[findall(f, a)]` to compute linear indices. * `AbstractSet` objects are now considered equal by `==` and `isequal` if all of their elements are equal ([#25368]). This has required changing the hashing algorithm @@ -938,7 +939,7 @@ Deprecated or removed `similar(::Associative, ::Pair{K, V})` has been deprecated in favour of `empty(::Associative, K, V)` ([#24390]). - * `findin(a, b)` has been deprecated in favor of `find(occursin(b), a)` ([#24673]). + * `findin(a, b)` has been deprecated in favor of `findall(occursin(b), a)` ([#24673]). * The generic implementations of `strides(::AbstractArray)` and `stride(::AbstractArray, ::Int)` have been deprecated. Subtypes of `AbstractArray` that implement the newly introduced strided @@ -1198,3 +1199,4 @@ Command-line option changes [#25365]: https://github.com/JuliaLang/julia/issues/25365 [#25424]: https://github.com/JuliaLang/julia/issues/25424 [#25532]: https://github.com/JuliaLang/julia/issues/25532 +[#25545]: https://github.com/JuliaLang/julia/issues/25545 diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 5655741ace0c3..11d8522867095 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1052,7 +1052,7 @@ get(A::AbstractArray, I::Dims, default) = checkbounds(Bool, A, I...) ? A[I...] : function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{AbstractRange,AbstractVector{Int}}, default::T) where T # 1d is not linear indexing - ind = find(occursin(indices1(A)), I) + ind = findall(occursin(indices1(A)), I) X[ind] = A[I[ind]] Xind = indices1(X) X[first(Xind):first(ind)-1] = default @@ -1061,7 +1061,7 @@ function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{AbstractRange,Ab end function get!(X::AbstractArray{T}, A::AbstractArray, I::Union{AbstractRange,AbstractVector{Int}}, default::T) where T # Linear indexing - ind = find(occursin(1:length(A)), I) + ind = findall(occursin(1:length(A)), I) X[ind] = A[I[ind]] X[1:first(ind)-1] = default X[last(ind)+1:length(X)] = default diff --git a/base/array.jl b/base/array.jl index 192b9518b200c..f5f779311a247 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1718,7 +1718,7 @@ true findlast(testf::Function, A) = findprev(testf, A, endof(A)) """ - find(f::Function, A) + findall(f::Function, A) Return a vector `I` of the indices or keys of `A` where `f(A[I])` returns `true`. If there are no such elements of `A`, return an empty array. @@ -1736,7 +1736,7 @@ julia> x = [1, 3, 4] 3 4 -julia> find(isodd, x) +julia> findall(isodd, x) 2-element Array{Int64,1}: 1 2 @@ -1745,12 +1745,12 @@ julia> A = [1 2 0; 3 4 0] 2×3 Array{Int64,2}: 1 2 0 3 4 0 -julia> find(isodd, A) +julia> findall(isodd, A) 2-element Array{CartesianIndex{2},1}: CartesianIndex(1, 1) CartesianIndex(2, 1) -julia> find(!iszero, A) +julia> findall(!iszero, A) 4-element Array{CartesianIndex{2},1}: CartesianIndex(1, 1) CartesianIndex(2, 1) @@ -1763,20 +1763,20 @@ Dict{Symbol,Int64} with 3 entries: :B => -1 :C => 0 -julia> find(x -> x >= 0, d) +julia> findall(x -> x >= 0, d) 2-element Array{Symbol,1}: :A :C ``` """ -find(testf::Function, A) = collect(first(p) for p in _pairs(A) if testf(last(p))) +findall(testf::Function, A) = collect(first(p) for p in _pairs(A) if testf(last(p))) _pairs(A::Union{AbstractArray, AbstractDict, AbstractString, Tuple, NamedTuple}) = pairs(A) _pairs(iter) = zip(OneTo(typemax(Int)), iter) # safe for objects that don't implement length """ - find(A) + findall(A) Return a vector `I` of the `true` indices or keys of `A`. If there are no such elements of `A`, return an empty array. @@ -1796,7 +1796,7 @@ julia> A = [true, false, false, true] false true -julia> find(A) +julia> findall(A) 2-element Array{Int64,1}: 1 4 @@ -1806,25 +1806,25 @@ julia> A = [true false; false true] true false false true -julia> find(A) +julia> findall(A) 2-element Array{Int64,1}: 1 4 -julia> find(falses(3)) +julia> findall(falses(3)) 0-element Array{Int64,1} ``` """ -function find(A) +function findall(A) if !(eltype(A) === Bool) && !all(x -> x isa Bool, A) - depwarn("In the future `find(A)` will only work on boolean collections. Use `find(x->x!=0, A)` instead.", :find) + depwarn("In the future `findall(A)` will only work on boolean collections. Use `findall(x->x!=0, A)` instead.", :find) end collect(first(p) for p in _pairs(A) if last(p) != 0) end -find(x::Bool) = x ? [1] : Vector{Int}() -find(testf::Function, x::Number) = !testf(x) ? Vector{Int}() : [1] -find(p::OccursIn, x::Number) = x in p.x ? Vector{Int}() : [1] +findall(x::Bool) = x ? [1] : Vector{Int}() +findall(testf::Function, x::Number) = !testf(x) ? Vector{Int}() : [1] +findall(p::OccursIn, x::Number) = x in p.x ? Vector{Int}() : [1] """ findnz(A) @@ -2076,7 +2076,7 @@ function _sortedfindin(v, w) return out end -function find(pred::OccursIn{<:Union{Array{<:Real},Real}}, x::Array{<:Real}) +function findall(pred::OccursIn{<:Union{Array{<:Real},Real}}, x::Array{<:Real}) if issorted(x, Sort.Forward) && issorted(pred.x, Sort.Forward) return _sortedfindin(x, pred.x) else @@ -2085,7 +2085,7 @@ function find(pred::OccursIn{<:Union{Array{<:Real},Real}}, x::Array{<:Real}) end # issorted fails for some element types so the method above has to be restricted # to element with isless/< defined. -find(pred::OccursIn, x::Union{AbstractArray, Tuple}) = _findin(x, pred.x) +findall(pred::OccursIn, x::Union{AbstractArray, Tuple}) = _findin(x, pred.x) # Copying subregions function indcopy(sz::Dims, I::Vector) diff --git a/base/bitarray.jl b/base/bitarray.jl index f17fdc018e44c..90aaa5cd646b9 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1598,7 +1598,7 @@ function findprev(testf::Function, B::BitArray, start::Integer) end #findlast(testf::Function, B::BitArray) = findprev(testf, B, 1) ## defined in array.jl -function find(B::BitArray) +function findall(B::BitArray) l = length(B) nnzB = count(B) ind = first(keys(B)) @@ -1632,7 +1632,7 @@ function find(B::BitArray) end # For performance -find(::typeof(!iszero), B::BitArray) = find(B) +findall(::typeof(!iszero), B::BitArray) = findall(B) function findnz(B::BitMatrix) nnzB = count(B) diff --git a/base/client.jl b/base/client.jl index a3819b9e6c1dc..755ade852d765 100644 --- a/base/client.jl +++ b/base/client.jl @@ -254,7 +254,7 @@ try_include(mod::Module, path::AbstractString) = isfile(path) && include(mod, pa function process_options(opts::JLOptions) if !isempty(ARGS) - idxs = find(x -> x == "--", ARGS) + idxs = findall(x -> x == "--", ARGS) length(idxs) > 0 && deleteat!(ARGS, idxs[1]) end quiet = (opts.quiet != 0) diff --git a/base/deprecated.jl b/base/deprecated.jl index 93e97f884d544..c22bd417105ce 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1179,7 +1179,7 @@ end # (2) base/linalg/qr.jl # (3) base/linalg/lq.jl -@deprecate find(x::Number) find(!iszero, x) +@deprecate find(x::Number) findall(!iszero, x) @deprecate findnext(A, v, i::Integer) findnext(equalto(v), A, i) @deprecate findfirst(A, v) findfirst(equalto(v), A) @deprecate findprev(A, v, i::Integer) findprev(equalto(v), A, i) @@ -2783,11 +2783,13 @@ end @deprecate ismatch(r::Regex, s::AbstractString) contains(s, r) -@deprecate findin(a, b) find(occursin(b), a) +@deprecate findin(a, b) findall(occursin(b), a) -@deprecate findn(a::AbstractVector) (find(!iszero, a),) -@deprecate findn(x::AbstractMatrix) (I = find(!iszero, x); (getindex.(I, 1), getindex.(I, 2))) -@deprecate findn(a::AbstractArray{T, N}) where {T, N} (I = find(!iszero, x); ntuple(i -> getindex.(I, i), N)) +@deprecate find findall + +@deprecate findn(x::AbstractVector) (findall(!iszero, x),) +@deprecate findn(x::AbstractMatrix) (I = findall(!iszero, x); (getindex.(I, 1), getindex.(I, 2))) +@deprecate findn(x::AbstractArray{T, N}) where {T, N} (I = findall(!iszero, x); ntuple(i -> getindex.(I, i), N)) # issue #9053 if Sys.iswindows() diff --git a/base/exports.jl b/base/exports.jl index 44c0bd03fe84b..b7734faeefdcd 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -482,7 +482,7 @@ export eachmatch, endswith, equalto, - find, + findall, findfirst, findlast, findmax, diff --git a/base/libgit2/index.jl b/base/libgit2/index.jl index e96a4dbedf295..be4baf7580c04 100644 --- a/base/libgit2/index.jl +++ b/base/libgit2/index.jl @@ -178,7 +178,7 @@ function Base.getindex(idx::GitIndex, i::Integer) return elem end -function Base.find(path::String, idx::GitIndex) +function Base.findall(path::String, idx::GitIndex) pos_ref = Ref{Csize_t}(0) ret = ccall((:git_index_find, :libgit2), Cint, (Ref{Csize_t}, Ptr{Cvoid}, Cstring), pos_ref, idx.ptr, path) diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index 83215bff1d122..56f745340e493 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -605,7 +605,7 @@ eigvals(M::Bidiagonal) = M.dv function eigvecs(M::Bidiagonal{T}) where T n = length(M.dv) Q = Matrix{T}(uninitialized, n,n) - blks = [0; find(x -> x == 0, M.ev); n] + blks = [0; findall(x -> x == 0, M.ev); n] v = zeros(T, n) if M.uplo == 'U' for idx_block = 1:length(blks) - 1, i = blks[idx_block] + 1:blks[idx_block + 1] #index of eigenvector diff --git a/base/linalg/dense.jl b/base/linalg/dense.jl index 76109f7fd63e8..e683008349049 100644 --- a/base/linalg/dense.jl +++ b/base/linalg/dense.jl @@ -1295,7 +1295,7 @@ function pinv(A::StridedMatrix{T}, tol::Real) where T Sinv = zeros(Stype, length(SVD.S)) index = SVD.S .> tol*maximum(SVD.S) Sinv[index] = one(Stype) ./ SVD.S[index] - Sinv[find(.!isfinite.(Sinv))] = zero(Stype) + Sinv[findall(.!isfinite.(Sinv))] = zero(Stype) return SVD.Vt' * (Diagonal(Sinv) * SVD.U') end function pinv(A::StridedMatrix{T}) where T diff --git a/base/linalg/lapack.jl b/base/linalg/lapack.jl index 27141c6c8ae25..4204be47f30f5 100644 --- a/base/linalg/lapack.jl +++ b/base/linalg/lapack.jl @@ -3759,7 +3759,7 @@ for (stev, stebz, stegr, stein, elty) in chklapackerror(info[]) if any(ifail .!= 0) # TODO: better error message / type - error("failed to converge eigenvectors:\n$(find(!iszero, ifail))") + error("failed to converge eigenvectors:\n$(findall(!iszero, ifail))") end z end diff --git a/base/pkg/read.jl b/base/pkg/read.jl index e68e8457d25e7..37ac994f9bb30 100644 --- a/base/pkg/read.jl +++ b/base/pkg/read.jl @@ -64,7 +64,7 @@ function isfixed(pkg::AbstractString, prepo::LibGit2.GitRepo, avail::Dict=availa LibGit2.isdirty(prepo) && return true LibGit2.isattached(prepo) && return true LibGit2.need_update(prepo) - if find("REQUIRE", LibGit2.GitIndex(prepo)) === nothing + if findall("REQUIRE", LibGit2.GitIndex(prepo)) === nothing isfile(pkg,"REQUIRE") && return true end head = string(LibGit2.head_oid(prepo)) @@ -185,7 +185,7 @@ function requires_path(pkg::AbstractString, avail::Dict=available(pkg)) head = LibGit2.with(LibGit2.GitRepo, pkg) do repo LibGit2.isdirty(repo, "REQUIRE") && return pkgreq LibGit2.need_update(repo) - if find("REQUIRE", LibGit2.GitIndex(repo)) === nothing + if findall("REQUIRE", LibGit2.GitIndex(repo)) === nothing isfile(pkgreq) && return pkgreq end string(LibGit2.head_oid(repo)) diff --git a/base/pkg/resolve/interface.jl b/base/pkg/resolve/interface.jl index 25cf8f2774858..eae90dc39b0f3 100644 --- a/base/pkg/resolve/interface.jl +++ b/base/pkg/resolve/interface.jl @@ -354,7 +354,7 @@ function enforce_optimality!(sol::Vector{Int}, interface::Interface) staged = staged_next end - for p0 in find(uninst) + for p0 in findall(uninst) sol[p0] = spp[p0] end diff --git a/base/pkg/resolve/maxsum.jl b/base/pkg/resolve/maxsum.jl index c35bdc5aa9b58..5bf7c6deda4e1 100644 --- a/base/pkg/resolve/maxsum.jl +++ b/base/pkg/resolve/maxsum.jl @@ -390,7 +390,7 @@ function decimate1(p0::Int, graph::Graph, msgs::Messages) s0 = indmax(fld0) # only do the decimation if it is consistent with # the previously decimated nodes - for p1 in find(decimated) + for p1 in findall(decimated) haskey(adjdict[p0], p1) || continue s1 = indmax(fld[p1]) j1 = adjdict[p0][p1] diff --git a/base/tuple.jl b/base/tuple.jl index 2fa6d80d17ff7..15f51e2975072 100644 --- a/base/tuple.jl +++ b/base/tuple.jl @@ -21,7 +21,7 @@ size(t::Tuple, d) = (d == 1) ? length(t) : throw(ArgumentError("invalid tuple di @eval getindex(t::Tuple, i::Int) = getfield(t, i, $(Expr(:boundscheck))) @eval getindex(t::Tuple, i::Real) = getfield(t, convert(Int, i), $(Expr(:boundscheck))) getindex(t::Tuple, r::AbstractArray{<:Any,1}) = ([t[ri] for ri in r]...,) -getindex(t::Tuple, b::AbstractArray{Bool,1}) = length(b) == length(t) ? getindex(t, find(b)) : throw(BoundsError(t, b)) +getindex(t::Tuple, b::AbstractArray{Bool,1}) = length(b) == length(t) ? getindex(t, findall(b)) : throw(BoundsError(t, b)) # returns new tuple; N.B.: becomes no-op if i is out-of-bounds setindex(x::Tuple, v, i::Integer) = (@_inline_meta; _setindex(v, i, x...)) diff --git a/doc/src/base/arrays.md b/doc/src/base/arrays.md index 894e36c735cd1..c379ab6aa4ae4 100644 --- a/doc/src/base/arrays.md +++ b/doc/src/base/arrays.md @@ -122,8 +122,8 @@ Base.flipdim Base.circshift Base.circshift! Base.circcopy! -Base.find(::Any) -Base.find(::Function, ::Any) +Base.findall(::Any) +Base.findall(::Function, ::Any) Base.findnz Base.findfirst(::Any) Base.findfirst(::Function, ::Any) diff --git a/doc/src/manual/arrays.md b/doc/src/manual/arrays.md index b90ebe6e2f315..b14e7e371a263 100644 --- a/doc/src/manual/arrays.md +++ b/doc/src/manual/arrays.md @@ -494,13 +494,13 @@ julia> A[CartesianIndex.(axes(A, 1), axes(A, 2)), :] Often referred to as logical indexing or indexing with a logical mask, indexing by a boolean array selects elements at the indices where its values are `true`. Indexing by a boolean vector `B` is effectively the same as indexing by the -vector of integers that is returned by [`find(B)`](@ref). Similarly, indexing +vector of integers that is returned by [`findall(B)`](@ref). Similarly, indexing by a `N`-dimensional boolean array is effectively the same as indexing by the vector of `CartesianIndex{N}`s where its values are `true`. A logical index must be a vector of the same length as the dimension it indexes into, or it must be the only index provided and match the size and dimensionality of the array it indexes into. It is generally more efficient to use boolean arrays as -indices directly instead of first calling [`find`](@ref). +indices directly instead of first calling [`findall`](@ref). ```jldoctest julia> x = reshape(1:16, 4, 4) diff --git a/stdlib/Dates/test/ranges.jl b/stdlib/Dates/test/ranges.jl index 2b8d4e03acc84..33099a2fd5de3 100644 --- a/stdlib/Dates/test/ranges.jl +++ b/stdlib/Dates/test/ranges.jl @@ -26,7 +26,7 @@ let @test_throws ArgumentError minimum(dr) @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] - @test find(occursin(dr), dr) == Int64[] + @test findall(occursin(dr), dr) == Int64[] @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @@ -58,7 +58,7 @@ let if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test find(occursin(dr), dr) == [1:len;] + @test findall(occursin(dr), dr) == [1:len;] @test length([dr;]) == len @test dr == dr1 @test hash(dr) == hash(dr1) @@ -84,7 +84,7 @@ let @test_throws ArgumentError minimum(dr) @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] - @test find(occursin(dr), dr) == Int64[] + @test findall(occursin(dr), dr) == Int64[] @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @@ -116,7 +116,7 @@ let if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test find(occursin(dr), dr) == [1:len;] + @test findall(occursin(dr), dr) == [1:len;] @test length([dr;]) == len @test dr == dr1 @test hash(dr) == hash(dr1) @@ -144,7 +144,7 @@ let @test_throws ArgumentError minimum(dr) @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] - @test find(occursin(dr), dr) == Int64[] + @test findall(occursin(dr), dr) == Int64[] @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @@ -176,7 +176,7 @@ let if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test find(occursin(dr), dr) == [1:len;] + @test findall(occursin(dr), dr) == [1:len;] @test length([dr;]) == len @test dr == dr1 @test hash(dr) == hash(dr1) @@ -202,7 +202,7 @@ let @test_throws ArgumentError minimum(dr) @test_throws ArgumentError maximum(dr) @test_throws BoundsError dr[1] - @test find(occursin(dr), dr) == Int64[] + @test findall(occursin(dr), dr) == Int64[] @test [dr;] == T[] @test isempty(reverse(dr)) @test length(reverse(dr)) == 0 @@ -234,7 +234,7 @@ let if len < 10000 dr1 = [i for i in dr] @test length(dr1) == len - @test find(occursin(dr), dr) == [1:len;] + @test findall(occursin(dr), dr) == [1:len;] @test length([dr;]) == len @test dr == dr1 @test hash(dr) == hash(dr1) @@ -293,7 +293,7 @@ drs2 = map(x->Dates.Date(first(x)):step(x):Dates.Date(last(x)), drs) @test map(length, drs) == map(x->size(x)[1], drs) @test map(length, drs) == map(x->length(Dates.Date(first(x)):step(x):Dates.Date(last(x))), drs) @test map(length, drs) == map(x->length(reverse(x)), drs) -@test all(x->find(occursin(x), x)==[1:length(x);], drs[1:4]) +@test all(x->findall(occursin(x), x)==[1:length(x);], drs[1:4]) @test isempty(dr2) @test all(x->reverse(x) == range(last(x), -step(x), length(x)), drs) @test all(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)), drs[4:end]) @@ -371,7 +371,7 @@ drs = Any[dr, dr1, dr2, dr3, dr4, dr5, dr6, dr7, dr8, dr9, dr10, dr11, dr12, dr13, dr14, dr15, dr16, dr17, dr18, dr19, dr20] @test map(length, drs) == map(x->size(x)[1], drs) -@test all(x->find(occursin(x), x) == [1:length(x);], drs[1:4]) +@test all(x->findall(occursin(x), x) == [1:length(x);], drs[1:4]) @test isempty(dr2) @test all(x->reverse(x) == last(x): - step(x):first(x), drs) @test all(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)), drs[4:end]) @@ -557,7 +557,7 @@ drs = Any[dr, dr1, dr2, dr3, dr8, dr9, dr10, dr11, dr12, dr13, dr14, dr15, dr16, dr17, dr18, dr19, dr20] @test map(length, drs) == map(x->size(x)[1], drs) -@test all(x->find(occursin(x), x) == [1:length(x);], drs[1:4]) +@test all(x->findall(occursin(x), x) == [1:length(x);], drs[1:4]) @test isempty(dr2) @test all(x->reverse(x) == last(x): - step(x):first(x), drs) @test all(x->minimum(x) == (step(x) < zero(step(x)) ? last(x) : first(x)), drs[4:end]) diff --git a/stdlib/Profile/src/Profile.jl b/stdlib/Profile/src/Profile.jl index 0aafb1c0443d5..ede5039ec4599 100644 --- a/stdlib/Profile/src/Profile.jl +++ b/stdlib/Profile/src/Profile.jl @@ -442,7 +442,7 @@ end ## A tree representation # Identify and counts repetitions of all unique backtraces function tree_aggregate(data::Vector{UInt64}) - iz = find(iszero, data) # find the breaks between backtraces + iz = findall(iszero, data) # find the breaks between backtraces treecount = Dict{Vector{UInt64},Int}() istart = 1 + btskip for iend in iz diff --git a/stdlib/Random/test/runtests.jl b/stdlib/Random/test/runtests.jl index 2f4865c857389..bd53e8238a84c 100644 --- a/stdlib/Random/test/runtests.jl +++ b/stdlib/Random/test/runtests.jl @@ -14,7 +14,7 @@ using Random: Sampler, SamplerRangeFast, SamplerRangeInt, MT_CACHE_F, MT_CACHE_I srand(0) rand() x = rand(384) - @test find(x .== rand()) == [] + @test findall(x .== rand()) == [] end @test rand() != rand() diff --git a/stdlib/SparseArrays/docs/src/index.md b/stdlib/SparseArrays/docs/src/index.md index f5d1652cae6e5..e5598736af9e1 100644 --- a/stdlib/SparseArrays/docs/src/index.md +++ b/stdlib/SparseArrays/docs/src/index.md @@ -115,14 +115,14 @@ julia> R = sparsevec(I,V) The inverse of the [`sparse`](@ref) and [`sparsevec`](@ref) functions is [`findnz`](@ref), which retrieves the inputs used to create the sparse array. -[`find(!iszero, x)`](@ref) returns the cartesian indices of non-zero entries in `x` +[`findall(!iszero, x)`](@ref) returns the cartesian indices of non-zero entries in `x` (including stored entries equal to zero). ```jldoctest sparse_function julia> findnz(S) ([1, 4, 5, 3], [4, 7, 9, 18], [1, 2, 3, -5]) -julia> find(!iszero, S) +julia> findall(!iszero, S) 4-element Array{CartesianIndex{2},1}: CartesianIndex(1, 4) CartesianIndex(4, 7) @@ -132,7 +132,7 @@ julia> find(!iszero, S) julia> findnz(R) ([1, 3, 4, 5], [1, -5, 2, 3]) -julia> find(!iszero, R) +julia> findall(!iszero, R) 4-element Array{Int64,1}: 1 3 diff --git a/stdlib/SparseArrays/src/SparseArrays.jl b/stdlib/SparseArrays/src/SparseArrays.jl index 1d4b396376d6b..82774480af694 100644 --- a/stdlib/SparseArrays/src/SparseArrays.jl +++ b/stdlib/SparseArrays/src/SparseArrays.jl @@ -22,7 +22,7 @@ import Base: @get!, acos, acosd, acot, acotd, acsch, asech, asin, asind, asinh, sin, sinc, sind, sinh, sinpi, squeeze, start, sum, summary, tan, tand, tanh, trace, transpose!, tril!, triu!, trunc, vecnorm, abs, abs2, broadcast, ceil, complex, cond, conj, convert, copy, copyto!, adjoint, diagm, - exp, expm1, factorize, find, findmax, findmin, findnz, float, getindex, + exp, expm1, factorize, findall, findmax, findmin, findnz, float, getindex, vcat, hcat, hvcat, cat, imag, indmax, ishermitian, kron, length, log, log1p, max, min, maximum, minimum, norm, one, promote_eltype, real, reshape, rot180, rotl90, rotr90, round, scale!, setindex!, similar, size, transpose, tril, diff --git a/stdlib/SparseArrays/src/abstractsparse.jl b/stdlib/SparseArrays/src/abstractsparse.jl index 7ec75e1e6d03e..af145bb216b60 100644 --- a/stdlib/SparseArrays/src/abstractsparse.jl +++ b/stdlib/SparseArrays/src/abstractsparse.jl @@ -44,9 +44,9 @@ function Base.reinterpret(::Type, A::AbstractSparseArray) end # The following two methods should be overloaded by concrete types to avoid -# allocating the I = find(...) -_sparse_findnextnz(v::AbstractSparseArray, i::Integer) = (I = find(!iszero, v); n = searchsortedfirst(I, i); n<=length(I) ? I[n] : nothing) -_sparse_findprevnz(v::AbstractSparseArray, i::Integer) = (I = find(!iszero, v); n = searchsortedlast(I, i); !iszero(n) ? I[n] : nothing) +# allocating the I = findall(...) +_sparse_findnextnz(v::AbstractSparseArray, i::Integer) = (I = findall(!iszero, v); n = searchsortedfirst(I, i); n<=length(I) ? I[n] : nothing) +_sparse_findprevnz(v::AbstractSparseArray, i::Integer) = (I = findall(!iszero, v); n = searchsortedlast(I, i); !iszero(n) ? I[n] : nothing) function findnext(f::typeof(!iszero), v::AbstractSparseArray, i::Integer) j = _sparse_findnextnz(v, i) diff --git a/stdlib/SparseArrays/src/sparsematrix.jl b/stdlib/SparseArrays/src/sparsematrix.jl index 40ce469a5f9d5..e9fb76a4e562c 100644 --- a/stdlib/SparseArrays/src/sparsematrix.jl +++ b/stdlib/SparseArrays/src/sparsematrix.jl @@ -1263,16 +1263,16 @@ dropzeros(A::SparseMatrixCSC, trim::Bool = true) = dropzeros!(copy(A), trim) ## Find methods -function find(S::SparseMatrixCSC) +function findall(S::SparseMatrixCSC) if !(eltype(S) <: Bool) - Base.depwarn("In the future `find(A)` will only work on boolean collections. Use `find(x->x!=0, A)` instead.", :find) + Base.depwarn("In the future `findall(A)` will only work on boolean collections. Use `findall(x->x!=0, A)` instead.", :findall) end - return find(x->x!=0, S) + return findall(x->x!=0, S) end -function find(p::Function, S::SparseMatrixCSC) +function findall(p::Function, S::SparseMatrixCSC) if p(zero(eltype(S))) - return invoke(find, Tuple{Function, Any}, p, S) + return invoke(findall, Tuple{Function, Any}, p, S) end numnz = nnz(S) @@ -1288,8 +1288,8 @@ function find(p::Function, S::SparseMatrixCSC) return inds end -find(p::Base.OccursIn, x::SparseMatrixCSC) = - invoke(find, Tuple{Base.OccursIn, AbstractArray}, p, x) +findall(p::Base.OccursIn, x::SparseMatrixCSC) = + invoke(findall, Tuple{Base.OccursIn, AbstractArray}, p, x) function findnz(S::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} numnz = nnz(S) @@ -2292,12 +2292,12 @@ end getindex(A::SparseMatrixCSC{<:Any,<:Integer}, I::AbstractRange{Bool}, J::AbstractVector{Bool}) = error("Cannot index with AbstractRange{Bool}") getindex(A::SparseMatrixCSC{<:Any,<:Integer}, I::AbstractRange{Bool}, J::AbstractVector{<:Integer}) = error("Cannot index with AbstractRange{Bool}") -getindex(A::SparseMatrixCSC, I::AbstractRange{<:Integer}, J::AbstractVector{Bool}) = A[I,find(J)] -getindex(A::SparseMatrixCSC, I::Integer, J::AbstractVector{Bool}) = A[I,find(J)] -getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::Integer) = A[find(I),J] -getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = A[find(I),find(J)] -getindex(A::SparseMatrixCSC, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = A[I,find(J)] -getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = A[find(I),J] +getindex(A::SparseMatrixCSC, I::AbstractRange{<:Integer}, J::AbstractVector{Bool}) = A[I,findall(J)] +getindex(A::SparseMatrixCSC, I::Integer, J::AbstractVector{Bool}) = A[I,findall(J)] +getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::Integer) = A[findall(I),J] +getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = A[findall(I),findall(J)] +getindex(A::SparseMatrixCSC, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = A[I,findall(J)] +getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = A[findall(I),J] ## setindex! function setindex!(A::SparseMatrixCSC{Tv,Ti}, v, i::Integer, j::Integer) where Tv where Ti @@ -2636,17 +2636,17 @@ end # Logical setindex! -setindex!(A::SparseMatrixCSC, x::Matrix, I::Integer, J::AbstractVector{Bool}) = setindex!(A, sparse(x), I, find(J)) -setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::Integer) = setindex!(A, sparse(x), find(I), J) -setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = setindex!(A, sparse(x), find(I), find(J)) -setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = setindex!(A, sparse(x), I, find(J)) -setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = setindex!(A, sparse(x), find(I),J) - -setindex!(A::Matrix, x::SparseMatrixCSC, I::Integer, J::AbstractVector{Bool}) = setindex!(A, Array(x), I, find(J)) -setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::Integer) = setindex!(A, Array(x), find(I), J) -setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = setindex!(A, Array(x), find(I), find(J)) -setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = setindex!(A, Array(x), I, find(J)) -setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = setindex!(A, Array(x), find(I), J) +setindex!(A::SparseMatrixCSC, x::Matrix, I::Integer, J::AbstractVector{Bool}) = setindex!(A, sparse(x), I, findall(J)) +setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::Integer) = setindex!(A, sparse(x), findall(I), J) +setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = setindex!(A, sparse(x), findall(I), findall(J)) +setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = setindex!(A, sparse(x), I, findall(J)) +setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = setindex!(A, sparse(x), findall(I),J) + +setindex!(A::Matrix, x::SparseMatrixCSC, I::Integer, J::AbstractVector{Bool}) = setindex!(A, Array(x), I, findall(J)) +setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::Integer) = setindex!(A, Array(x), findall(I), J) +setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = setindex!(A, Array(x), findall(I), findall(J)) +setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = setindex!(A, Array(x), I, findall(J)) +setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = setindex!(A, Array(x), findall(I), J) setindex!(A::SparseMatrixCSC, x, I::AbstractVector{Bool}) = throw(BoundsError()) function setindex!(A::SparseMatrixCSC, x, I::AbstractMatrix{Bool}) diff --git a/stdlib/SparseArrays/src/sparsevector.jl b/stdlib/SparseArrays/src/sparsevector.jl index dd9c979bd349b..936c09b809d9e 100644 --- a/stdlib/SparseArrays/src/sparsevector.jl +++ b/stdlib/SparseArrays/src/sparsevector.jl @@ -2,7 +2,7 @@ ### Common definitions -import Base: sort, find, findnz +import Base: sort, findall, findnz import Base.LinAlg: promote_to_array_type, promote_to_arrays_ ### The SparseVector @@ -672,16 +672,16 @@ function getindex(A::SparseMatrixCSC{Tv,Ti}, I::AbstractVector) where {Tv,Ti} SparseVector(n, rowvalB, nzvalB) end -function find(x::SparseVector) +function findall(x::SparseVector) if !(eltype(x) <: Bool) - Base.depwarn("In the future `find(A)` will only work on boolean collections. Use `find(x->x!=0, A)` instead.", :find) + Base.depwarn("In the future `findall(A)` will only work on boolean collections. Use `findall(x->x!=0, A)` instead.", :findall) end - return find(x->x!=0, x) + return findall(x->x!=0, x) end -function find(p::Function, x::SparseVector{<:Any,Ti}) where Ti +function findall(p::Function, x::SparseVector{<:Any,Ti}) where Ti if p(zero(eltype(x))) - return invoke(find, Tuple{Function, Any}, p, x) + return invoke(findall, Tuple{Function, Any}, p, x) end numnz = nnz(x) I = Vector{Ti}(uninitialized, numnz) @@ -704,8 +704,8 @@ function find(p::Function, x::SparseVector{<:Any,Ti}) where Ti return I end -find(p::Base.OccursIn, x::SparseVector{<:Any,Ti}) where {Ti} = - invoke(find, Tuple{Base.OccursIn, AbstractArray}, p, x) +findall(p::Base.OccursIn, x::SparseVector{<:Any,Ti}) where {Ti} = + invoke(findall, Tuple{Base.OccursIn, AbstractArray}, p, x) function findnz(x::SparseVector{Tv,Ti}) where {Tv,Ti} numnz = nnz(x) @@ -797,8 +797,8 @@ function getindex(x::AbstractSparseVector{Tv,Ti}, I::AbstractUnitRange) where {T SparseVector(length(I), rind, rval) end -getindex(x::AbstractSparseVector, I::AbstractVector{Bool}) = x[find(I)] -getindex(x::AbstractSparseVector, I::AbstractArray{Bool}) = x[find(I)] +getindex(x::AbstractSparseVector, I::AbstractVector{Bool}) = x[findall(I)] +getindex(x::AbstractSparseVector, I::AbstractArray{Bool}) = x[findall(I)] @inline function getindex(x::AbstractSparseVector{Tv,Ti}, I::AbstractVector) where {Tv,Ti} # SparseMatrixCSC has a nicely optimized routine for this; punt S = SparseMatrixCSC(x.n, 1, Ti[1,length(x.nzind)+1], x.nzind, x.nzval) diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index bdbd652e3877e..299b7dfe85e94 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -537,7 +537,7 @@ end @testset "issue described in https://groups.google.com/d/msg/julia-users/Yq4dh8NOWBQ/GU57L90FZ3EJ" begin A = sparse(I, 5, 5) - @test find(A) == find(x -> x == true, A) == find(Array(A)) + @test findall(A) == findall(x -> x == true, A) == findall(Array(A)) end @testset "issue #5824" begin @@ -1405,7 +1405,7 @@ end targetnumnegzeros = 5 for (m, n) in ((largedim, largedim), (smalldim, largedim), (largedim, smalldim)) local A = sprand(m, n, nzprob) - struczerosA = find(x -> x == 0, A) + struczerosA = findall(x -> x == 0, A) poszerosinds = unique(rand(struczerosA, targetnumposzeros)) negzerosinds = unique(rand(struczerosA, targetnumnegzeros)) Aposzeros = setindex!(copy(A), 2, poszerosinds) diff --git a/stdlib/SparseArrays/test/sparsevector.jl b/stdlib/SparseArrays/test/sparsevector.jl index 199f49ab6d963..7554b47045496 100644 --- a/stdlib/SparseArrays/test/sparsevector.jl +++ b/stdlib/SparseArrays/test/sparsevector.jl @@ -270,13 +270,13 @@ end @test SparseArrays.dropstored!(x, 5) == SparseVector(10, [7, 9], [7.0, 9.0]) end -@testset "find and findnz" begin - @test find(!iszero, spv_x1) == find(!iszero, x1_full) - @test find(spv_x1 .> 1) == find(x1_full .> 1) - @test find(x->x>1, spv_x1) == find(x->x>1, x1_full) - @test findnz(spv_x1) == (find(!iszero, x1_full), filter(x->x!=0, x1_full)) +@testset "findall and findnz" begin + @test findall(!iszero, spv_x1) == findall(!iszero, x1_full) + @test findall(spv_x1 .> 1) == findall(x1_full .> 1) + @test findall(x->x>1, spv_x1) == findall(x->x>1, x1_full) + @test findnz(spv_x1) == (findall(!iszero, x1_full), filter(x->x!=0, x1_full)) let xc = SparseVector(8, [2, 3, 5], [1.25, 0, -0.75]), fc = Array(xc) - @test find(!iszero, xc) == find(!iszero, fc) + @test findall(!iszero, xc) == findall(!iszero, fc) @test findnz(xc) == ([2, 5], [1.25, -0.75]) end end @@ -1038,7 +1038,7 @@ end let testdims = (10, 20, 30), nzprob = 0.4, targetnumposzeros = 5, targetnumnegzeros = 5 for m in testdims v = sprand(m, nzprob) - struczerosv = find(x -> x == 0, v) + struczerosv = findall(x -> x == 0, v) poszerosinds = unique(rand(struczerosv, targetnumposzeros)) negzerosinds = unique(rand(struczerosv, targetnumnegzeros)) vposzeros = setindex!(copy(v), 2, poszerosinds) diff --git a/stdlib/SuiteSparse/test/cholmod.jl b/stdlib/SuiteSparse/test/cholmod.jl index 14fd2f4d5c7d4..7d8ada341e5a3 100644 --- a/stdlib/SuiteSparse/test/cholmod.jl +++ b/stdlib/SuiteSparse/test/cholmod.jl @@ -735,7 +735,7 @@ end B = CHOLMOD.Sparse(A) C = B'B # Change internal representation to symmetric (upper/lower) - o = fieldoffset(CHOLMOD.C_Sparse{eltype(C)}, find(fieldnames(CHOLMOD.C_Sparse{eltype(C)}) .== :stype)[1]) + o = fieldoffset(CHOLMOD.C_Sparse{eltype(C)}, findall(fieldnames(CHOLMOD.C_Sparse{eltype(C)}) .== :stype)[1]) for uplo in (1, -1) unsafe_store!(Ptr{Int8}(pointer(C)), uplo, Int(o) + 1) @test convert(Symmetric{Float64,SparseMatrixCSC{Float64,Int}}, C) == Symmetric(A'A) diff --git a/test/abstractarray.jl b/test/abstractarray.jl index c30f702536a78..820c2ae81ad5d 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -436,13 +436,13 @@ function test_vector_indexing(::Type{T}, shape, ::Type{TestAbstractArray}) where mask = bitrand(shape) @testset "test logical indexing" begin - @test B[mask] == A[mask] == B[find(mask)] == A[find(mask)] == LinearIndices(mask)[find(mask)] - @test B[vec(mask)] == A[vec(mask)] == LinearIndices(mask)[find(mask)] + @test B[mask] == A[mask] == B[findall(mask)] == A[findall(mask)] == LinearIndices(mask)[findall(mask)] + @test B[vec(mask)] == A[vec(mask)] == LinearIndices(mask)[findall(mask)] mask1 = bitrand(size(A, 1)) mask2 = bitrand(size(A, 2)) @test B[mask1, mask2, trailing2] == A[mask1, mask2, trailing2] == - B[LinearIndices(mask1)[find(mask1)], LinearIndices(mask2)[find(mask2)], trailing2] - @test B[mask1, 1, trailing2] == A[mask1, 1, trailing2] == LinearIndices(mask)[find(mask1)] + B[LinearIndices(mask1)[findall(mask1)], LinearIndices(mask2)[findall(mask2)], trailing2] + @test B[mask1, 1, trailing2] == A[mask1, 1, trailing2] == LinearIndices(mask)[findall(mask1)] end end end diff --git a/test/arrayops.jl b/test/arrayops.jl index 6dac579200b76..7157ca70e3360 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -269,30 +269,30 @@ end a = [3, 5, -7, 6] b = [4, 6, 2, -7, 1] - ind = find(occursin(b), a) + ind = findall(occursin(b), a) @test ind == [3,4] - @test find(occursin(Int[]), a) == Int[] - @test find(occursin(a), Int[]) == Int[] + @test findall(occursin(Int[]), a) == Int[] + @test findall(occursin(a), Int[]) == Int[] a = [1,2,3,4,5] b = [2,3,4,6] - @test find(occursin(b), a) == [2,3,4] - @test find(occursin(a), b) == [1,2,3] - @test find(occursin(Int[]), a) == Int[] - @test find(occursin(a), Int[]) == Int[] + @test findall(occursin(b), a) == [2,3,4] + @test findall(occursin(a), b) == [1,2,3] + @test findall(occursin(Int[]), a) == Int[] + @test findall(occursin(a), Int[]) == Int[] a = Vector(1:3:15) b = Vector(2:4:10) - @test find(occursin(b), a) == [4] - @test find(occursin(b), [a[1:4]; a[4:end]]) == [4,5] + @test findall(occursin(b), a) == [4] + @test findall(occursin(b), [a[1:4]; a[4:end]]) == [4,5] - @test find(occursin(NaN), [1.0, NaN, 2.0]) == [2] - @test find(occursin(NaN), [1.0, 2.0, NaN]) == [3] + @test findall(occursin(NaN), [1.0, NaN, 2.0]) == [2] + @test findall(occursin(NaN), [1.0, 2.0, NaN]) == [3] - @testset "find(::OccursIn, b) for uncomparable element types" begin + @testset "findall(::OccursIn, b) for uncomparable element types" begin a = [1 + 1im, 1 - 1im] - @test find(occursin(1 + 1im), a) == [1] - @test find(occursin(a), a) == [1,2] + @test findall(occursin(1 + 1im), a) == [1] + @test findall(occursin(a), a) == [1,2] end rt = Base.return_types(setindex!, Tuple{Array{Int32, 3}, UInt8, Vector{Int}, Int16, UnitRange{Int}}) @@ -425,11 +425,11 @@ end @test X[end,Y[end]] == 11 end -@testset "find, findfirst, findnext, findlast, findprev" begin +@testset "findall, findfirst, findnext, findlast, findprev" begin a = [0,1,2,3,0,1,2,3] - @test find(!iszero, a) == [2,3,4,6,7,8] - @test find(a.==2) == [3,7] - @test find(isodd,a) == [2,4,6,8] + @test findall(!iszero, a) == [2,3,4,6,7,8] + @test findall(a.==2) == [3,7] + @test findall(isodd,a) == [2,4,6,8] @test findfirst(!iszero, a) == 2 @test findfirst(a.==0) == 1 @test findfirst(a.==5) == nothing @@ -460,18 +460,18 @@ end @test findnext(equalto(0x00), [0x00, 0x01, 0x00], 2) == 3 @test findprev(equalto(0x00), [0x00, 0x01, 0x00], 2) == 1 end -@testset "find with Matrix" begin +@testset "findall with Matrix" begin A = [1 2 0; 3 4 0] - @test find(isodd, A) == [CartesianIndex(1, 1), CartesianIndex(2, 1)] - @test find(!iszero, A) == [CartesianIndex(1, 1), CartesianIndex(2, 1), + @test findall(isodd, A) == [CartesianIndex(1, 1), CartesianIndex(2, 1)] + @test findall(!iszero, A) == [CartesianIndex(1, 1), CartesianIndex(2, 1), CartesianIndex(1, 2), CartesianIndex(2, 2)] end -@testset "find with general iterables" begin +@testset "findall with general iterables" begin s = "julia" - @test find(c -> c == 'l', s) == [3] + @test findall(c -> c == 'l', s) == [3] g = Base.Unicode.graphemes("日本語") - @test find(isascii, g) == Int[] - @test find(!iszero, (i % 2 for i in 1:10)) == 1:2:9 + @test findall(isascii, g) == Int[] + @test findall(!iszero, (i % 2 for i in 1:10)) == 1:2:9 end @testset "findmin findmax indmin indmax" begin diff --git a/test/bitarray.jl b/test/bitarray.jl index 0d468b8ac7923..9d768195f0a9e 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -234,7 +234,7 @@ timesofar("constructors") @check_bit_operation getindex(b1, m1) BitVector end - t1 = find(bitrand(l)) + t1 = findall(bitrand(l)) @check_bit_operation getindex(b1, t1) BitVector for j = 1:l @@ -272,7 +272,7 @@ timesofar("constructors") y = rand(0.0:1.0) @check_bit_operation setindex!(b1, y, 1:100) T - t1 = find(bitrand(l)) + t1 = findall(bitrand(l)) x = rand(Bool) @check_bit_operation setindex!(b1, x, t1) T b2 = bitrand(length(t1)) @@ -1090,7 +1090,7 @@ timesofar("datamove") @check_bit_operation findfirst(x->true, b1) Union{Int,Nothing} @check_bit_operation findfirst(x->false, b1) Union{Int,Nothing} - @check_bit_operation find(b1) Vector{Int} + @check_bit_operation findall(b1) Vector{Int} end b1 = trues(v1) @@ -1106,8 +1106,8 @@ timesofar("datamove") end b1 = bitrand(n1, n2) - @check_bit_operation find(b1) Vector{CartesianIndex{2}} - @check_bit_operation find(!iszero, b1) Vector{CartesianIndex{2}} + @check_bit_operation findall(b1) Vector{CartesianIndex{2}} + @check_bit_operation findall(!iszero, b1) Vector{CartesianIndex{2}} @check_bit_operation findnz(b1) Tuple{Vector{Int}, Vector{Int}, BitArray} end diff --git a/test/dict.jl b/test/dict.jl index 8b3cd568c1dd6..45d60f6210eb5 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -760,9 +760,9 @@ end @test map(string, keys(d)) == Set(["1","3"]) end -@testset "find" begin - @test @inferred find(equalto(1), Dict(:a=>1, :b=>2)) == [:a] - @test @inferred sort(find(equalto(1), Dict(:a=>1, :b=>1))) == [:a, :b] - @test @inferred isempty(find(equalto(1), Dict())) - @test @inferred isempty(find(equalto(1), Dict(:a=>2, :b=>3))) +@testset "findall" begin + @test @inferred findall(equalto(1), Dict(:a=>1, :b=>2)) == [:a] + @test @inferred sort(findall(equalto(1), Dict(:a=>1, :b=>1))) == [:a, :b] + @test @inferred isempty(findall(equalto(1), Dict())) + @test @inferred isempty(findall(equalto(1), Dict(:a=>2, :b=>3))) end \ No newline at end of file diff --git a/test/libgit2.jl b/test/libgit2.jl index 7d66638add955..cd0db741a2aba 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -1278,7 +1278,7 @@ mktempdir() do dir LibGit2.with(LibGit2.GitRepo(test_repo)) do repo # check index for file LibGit2.with(LibGit2.GitIndex(repo)) do idx - i = find(test_file, idx) + i = findall(test_file, idx) @test i !== nothing idx_entry = idx[i] @test idx_entry !== nothing @@ -1286,7 +1286,7 @@ mktempdir() do dir @test idx_entry_str == "IndexEntry($(string(idx_entry.id)))" @test LibGit2.stage(idx_entry) == 0 - i = find("zzz", idx) + i = findall("zzz", idx) @test i === nothing idx_str = sprint(show, idx) @test idx_str == "GitIndex:\nRepository: $(LibGit2.repository(idx))\nNumber of elements: 1\n" diff --git a/test/linalg/schur.jl b/test/linalg/schur.jl index ea28b2f8fa74c..d6dc09132aa3b 100644 --- a/test/linalg/schur.jl +++ b/test/linalg/schur.jl @@ -56,7 +56,7 @@ aimg = randn(n,n)/2 S = schurfact(ordschura) select = bitrand(n) O = ordschur(S, select) - sum(select) != 0 && @test S.values[find(select)] ≈ O.values[1:sum(select)] + sum(select) != 0 && @test S.values[findall(select)] ≈ O.values[1:sum(select)] @test O.vectors*O.Schur*O.vectors' ≈ ordschura @test_throws ErrorException f.A Snew = Base.LinAlg.Schur(S.T, S.Z, S.values) @@ -90,7 +90,7 @@ aimg = randn(n,n)/2 @test S.Q*S.S*S.Z' ≈ a1_sf @test S.Q*S.T*S.Z' ≈ a2_sf # Make sure that we have sorted it correctly - @test NS.values[find(select)] ≈ S.values[1:m] + @test NS.values[findall(select)] ≈ S.values[1:m] Snew = Base.LinAlg.GeneralizedSchur(NS.S, NS.T, NS.alpha, NS.beta, NS.Q, NS.Z) SchurNew = ordschur!(copy(Snew), select) diff --git a/test/namedtuple.jl b/test/namedtuple.jl index df5e5d274e3f3..c20bc717f4615 100644 --- a/test/namedtuple.jl +++ b/test/namedtuple.jl @@ -209,7 +209,7 @@ abstr_nt_22194_3() @test typeof(Base.structdiff(NamedTuple{(:a, :b), Tuple{Int32, Union{Int32, Nothing}}}((1, Int32(2))), (a=0,))) === NamedTuple{(:b,), Tuple{Union{Int32, Nothing}}} -@test @inferred find(equalto(1), (a=1, b=2)) == [:a] -@test @inferred find(equalto(1), (a=1, b=1)) == [:a, :b] -@test @inferred isempty(find(equalto(1), NamedTuple())) -@test @inferred isempty(find(equalto(1), (a=2, b=3))) \ No newline at end of file +@test @inferred findall(equalto(1), (a=1, b=2)) == [:a] +@test @inferred findall(equalto(1), (a=1, b=1)) == [:a, :b] +@test @inferred isempty(findall(equalto(1), NamedTuple())) +@test @inferred isempty(findall(equalto(1), (a=2, b=3))) \ No newline at end of file diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 0e2634d74addd..60ec245c711f7 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -360,16 +360,16 @@ pmax, ipmax = findmax(parent(A)) @test A[iamax] == amax @test amax == parent(A)[ipmax] z = OffsetArray([0 0; 2 0; 0 0; 0 0], (-3,-1)) -I = find(!iszero, z) +I = findall(!iszero, z) @test I == [CartesianIndex(-1, 0)] I,J,N = findnz(z) @test I == [-1] @test J == [0] @test N == [2] -@test find(!iszero,h) == [-2:1;] -@test find(x->x>0, h) == [-1,1] -@test find(x->x<0, h) == [-2,0] -@test find(x->x==0, h) == [2] +@test findall(!iszero,h) == [-2:1;] +@test findall(x->x>0, h) == [-1,1] +@test findall(x->x<0, h) == [-2,0] +@test findall(x->x==0, h) == [2] @test mean(A_3_3) == median(A_3_3) == 5 @test mean(x->2x, A_3_3) == 10 @test mean(A_3_3, 1) == median(A_3_3, 1) == OffsetArray([2 5 8], (0,A_3_3.offsets[2])) diff --git a/test/perf/sparse/fem.jl b/test/perf/sparse/fem.jl index 1adef267fd116..e43c4eeb0321b 100644 --- a/test/perf/sparse/fem.jl +++ b/test/perf/sparse/fem.jl @@ -14,7 +14,7 @@ end function get_free(N) L = zeros(Int, N, N) L[2:N-1, 2:N-1] = 1 - return find(L) + return findall(L) end # timing of assembly, slice and solve diff --git a/test/perf/threads/lbm3d/lbm3d.jl b/test/perf/threads/lbm3d/lbm3d.jl index 047044d2ac3e0..0dd6059d1bd04 100644 --- a/test/perf/threads/lbm3d/lbm3d.jl +++ b/test/perf/threads/lbm3d/lbm3d.jl @@ -148,7 +148,7 @@ function lbm3d(n) BOUND[:,:,1] = 1 BOUND[:,1,:] = 1 - ON = find(BOUND); # matrix offset of each Occupied Node + ON = findall(BOUND); # matrix offset of each Occupied Node TO_REFLECT = [ON+CI[2] ON+CI[3] ON+CI[4] ON+CI[5] ON+CI[6] ON+CI[7] ON+CI[8] ON+CI[9] ON+CI[10] ON+CI[11] ON+CI[12] ON+CI[13] ON+CI[14] ON+CI[15] ON+CI[16] ON+CI[17] ON+CI[18] ON+CI[19]] REFLECTED = [ON+CI[3] ON+CI[2] ON+CI[5] ON+CI[4] ON+CI[7] ON+CI[6] ON+CI[11] ON+CI[10] ON+CI[9] ON+CI[8] ON+CI[15] ON+CI[14] ON+CI[13] ON+CI[12] ON+CI[19] ON+CI[18] ON+CI[17] ON+CI[16]] diff --git a/test/ranges.jl b/test/ranges.jl index 8acb419dce83f..3f3dae951cc41 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -250,14 +250,14 @@ end @test length(0.0:-0.5) == 0 @test length(1:2:0) == 0 end - @testset "find(::OccursIn, ::Array)" begin - @test find(occursin(3:20), [5.2, 3.3]) == find(occursin(Vector(3:20)), [5.2, 3.3]) + @testset "findall(::OccursIn, ::Array)" begin + @test findall(occursin(3:20), [5.2, 3.3]) == findall(occursin(Vector(3:20)), [5.2, 3.3]) let span = 5:20, r = -7:3:42 - @test find(occursin(span), r) == 5:10 + @test findall(occursin(span), r) == 5:10 r = 15:-2:-38 - @test find(occursin(span), r) == 1:6 + @test findall(occursin(span), r) == 1:6 end end @testset "reverse" begin @@ -1110,16 +1110,16 @@ end @test intersect(r, Base.OneTo(2)) == Base.OneTo(2) @test intersect(r, 0:5) == 1:3 @test intersect(r, 2) === intersect(2, r) === 2:2 - @test find(occursin(r), r) === find(occursin(1:length(r)), r) === - find(occursin(r), 1:length(r)) === 1:length(r) + @test findall(occursin(r), r) === findall(occursin(1:length(r)), r) === + findall(occursin(r), 1:length(r)) === 1:length(r) io = IOBuffer() show(io, r) str = String(take!(io)) @test str == "Base.OneTo(3)" end let r = Base.OneTo(7) - @test find(occursin(2:(length(r) - 1)), r) === 2:(length(r) - 1) - @test find(occursin(r), 2:(length(r) - 1)) === 1:(length(r) - 2) + @test findall(occursin(2:(length(r) - 1)), r) === 2:(length(r) - 1) + @test findall(occursin(r), 2:(length(r) - 1)) === 1:(length(r) - 2) end end diff --git a/test/sorting.jl b/test/sorting.jl index 427a8c902b911..cfc6e86b9ae86 100644 --- a/test/sorting.jl +++ b/test/sorting.jl @@ -221,7 +221,7 @@ randnans(n) = reinterpret(Float64,[rand(UInt64)|0x7ff8000000000000 for i=1:n]) function randn_with_nans(n,p) v = randn(n) - x = find(rand(n).: Integer end -@testset "find" begin - @test @inferred find(equalto(1), (1, 2)) == [1] - @test @inferred find(equalto(1), (1, 1)) == [1, 2] - @test @inferred isempty(find(equalto(1), ())) - @test @inferred isempty(find(equalto(1), (2, 3))) +@testset "findall" begin + @test @inferred findall(equalto(1), (1, 2)) == [1] + @test @inferred findall(equalto(1), (1, 1)) == [1, 2] + @test @inferred isempty(findall(equalto(1), ())) + @test @inferred isempty(findall(equalto(1), (2, 3))) end \ No newline at end of file