diff --git a/src/ACME.jl b/src/ACME.jl index c4a0cdb8..a8f6bb8c 100644 --- a/src/ACME.jl +++ b/src/ACME.jl @@ -61,6 +61,15 @@ else end end +function _indmax(a::AbstractMatrix) + ind = indmax(a) + if isa(ind, CartesianIndex) # since 0.7.0-DEV.1660 + return (ind[1], ind[2]) + else + return ind2sub(size(a), ind) + end +end + include("kdtree.jl") include("solvers.jl") @@ -550,7 +559,7 @@ function model_matrices(circ::Circuit, t::Rational{BigInt}) warn("State update depends on indeterminate quantity") end while size(nullspace, 2) > 0 - i, j = ind2sub(size(nullspace), indmax(map(abs, nullspace))) + i, j = _indmax(map(abs, nullspace)) nullspace = nullspace[[1:i-1; i+1:end], [1:j-1; j+1:end]] f = f[:, [1:j-1; j+1:end]] for k in [:fv; :fi; :c; :fq] @@ -587,7 +596,7 @@ function tryextract(fq, numcols) for colcnt in 1:numcols # determine element with maximum absolute value in unprocessed columns # to use as pivot - i, j = ind2sub(size(fq), indmax(map(abs, fq[:,colcnt:end]))) + i, j = _indmax(map(abs, fq[:,colcnt:end])) j += colcnt-1 # swap pivot to first (unprocessed) column @@ -1000,7 +1009,7 @@ function rank_factorize(a::SparseMatrixCSC) nullspace = gensolve(a', spzeros(size(a, 2), 0))[2] c = eye(eltype(a), size(a, 1)) while size(nullspace, 2) > 0 - i, j = ind2sub(size(nullspace), indmax(map(abs, nullspace))) + i, j = _indmax(map(abs, nullspace)) c -= c[:, i] * nullspace[:, j]' / nullspace[i, j] c = c[:, [1:i-1; i+1:end]] nullspace -= nullspace[:, j] * vec(nullspace[i, :])' / nullspace[i, j] diff --git a/src/kdtree.jl b/src/kdtree.jl index 4886625b..0960138d 100644 --- a/src/kdtree.jl +++ b/src/kdtree.jl @@ -38,7 +38,7 @@ function KDTree(p::AbstractMatrix, Np=size(p,2)) return KDTree{typeof(cut_val),typeof(p)}(cut_dim, cut_val, [1], p) end - dim = indmax(var(p[:,1:Np],2)) + dim = indmax(vec(var(p[:,1:Np],2))) p_idx = sortperm(vec(p[dim,:])) min_idx[1] = 1 @@ -56,7 +56,7 @@ function KDTree(p::AbstractMatrix, Np=size(p,2)) min_idx[n] = cut_idx[parent_n]+1 max_idx[n] = max_idx[parent_n] end - dim = indmax(var(p[:,p_idx[min_idx[n]:max_idx[n]]],2)) + dim = indmax(vec(var(p[:,p_idx[min_idx[n]:max_idx[n]]],2))) idx = sortperm(vec(p[dim,p_idx[min_idx[n]:max_idx[n]]])) p_idx[min_idx[n]:max_idx[n]] = p_idx[idx + min_idx[n] - 1] cut_idx[n] = calc_cut_idx(min_idx[n], max_idx[n]) diff --git a/test/runtests.jl b/test/runtests.jl index 9bead634..60f3e547 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -88,7 +88,7 @@ end let ps = rand(6, 10000) t = ACME.KDTree(ps) p = rand(6) - best_p = ps[:,indmin(sum(abs2, broadcast(-, ps, p),1))] + best_p = ps[:,indmin(vec(sum(abs2, broadcast(-, ps, p),1)))] idx = ACME.indnearest(t, p) @test sum(abs2, p - best_p) ≈ sum(abs2, p - ps[:, idx]) end