Skip to content

Commit

Permalink
Avoid calls to eye and speye
Browse files Browse the repository at this point in the history
Due to the deprcation in Julia 0.7, they are replaces with
`Array{...}(I, ...)` or `SparseMatrixCSC{...}(I, ...)` (or just `I`
where possible). Requires Compat 0.36.
  • Loading branch information
martinholters committed Nov 23, 2017
1 parent 70bb08b commit 3649f56
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.5
Compat 0.35.0
Compat 0.36.0
DataStructures 0.2.9
IterTools 0.1.0
ProgressMeter 0.2.1
10 changes: 5 additions & 5 deletions src/ACME.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ end
model_matrices(circ::Circuit, t) = model_matrices(circ, Rational{BigInt}(t))

function tryextract(fq, numcols)
a = eye(eltype(fq), size(fq,2))
a = Matrix{eltype(fq)}(I, size(fq, 2), size(fq, 2))
if numcols size(fq,2)
return Nullable(a)
end
Expand Down Expand Up @@ -383,7 +383,7 @@ end

function nldecompose!(mats, nns, nqs)
fq = mats[:fq]
a = eye(eltype(fq), size(fq,2))
a = Matrix{eltype(fq)}(I, size(fq, 2), size(fq, 2))
sub_ranges = consecranges(nqs)
extracted_subs = Vector{Int}[]
rem_cols = 1:size(fq, 2)
Expand Down Expand Up @@ -483,7 +483,7 @@ nn(model::DiscreteModel, subidx) = size(model.fqs[subidx], 2)
nn(model::DiscreteModel) = sum([size(fq, 2) for fq in model.fqs])

function steadystate(model::DiscreteModel, u=zeros(nu(model)))
IA_LU = lufact(eye(nx(model))-model.a)
IA_LU = lufact(I-model.a)
steady_z = zeros(nn(model))
zoff = 1
for idx in 1:length(model.solvers)
Expand Down Expand Up @@ -762,12 +762,12 @@ function gensolve(a::SparseMatrixCSC, b, x, h, thresh=0.1)
end

gensolve(a, b, thresh=0.1) =
gensolve(a, b, spzeros(promote_type(eltype(a), eltype(b)), size(a)[2], size(b)[2]), speye(eltype(a), size(a)[2]), thresh)
gensolve(a, b, spzeros(promote_type(eltype(a), eltype(b)), size(a, 2), size(b, 2)), SparseMatrixCSC{eltype(a)}(I, size(a,2), size(a,2)), thresh)

function rank_factorize(a::SparseMatrixCSC)
f = a
nullspace = gensolve(a', spzeros(size(a, 2), 0))[2]
c = eye(eltype(a), size(a, 1))
c = Matrix{eltype(a)}(I, size(a, 1), size(a, 1))
while size(nullspace, 2) > 0
i, j = _indmax(abs.(nullspace))
c -= c[:, i] * nullspace[:, j]' / nullspace[i, j]
Expand Down
2 changes: 1 addition & 1 deletion src/circuit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ end
dl = ti[:, (!).(t)]
tv = spzeros(T, size(dl, 2), size(incidence, 2))
tv[:, t] = -dl.'
tv[:, (!).(t)] = speye(T, size(dl, 2))
tv[:, (!).(t)] = SparseMatrixCSC{T}(I, size(dl, 2), size(dl, 2))

tv, ti
end
Expand Down
9 changes: 5 additions & 4 deletions src/elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ Pins: `1`, `2`
"""
resistor(r) = Element(mv=-1, mi=r)

potentiometer(r, pos) = Element(mv=-eye(2), mi=[r*pos 0; 0 r*(1-pos)],
potentiometer(r, pos) = Element(mv=Matrix{Int}(-I, 2, 2), mi=[r*pos 0; 0 r*(1-pos)],
pins=[1, 2, 2, 3])
potentiometer(r) =
Element(mv=[eye(2); zeros(3, 2)], mi=[zeros(2, 2); eye(2); zeros(1, 2)],
mq=-eye(5), mu=[zeros(4, 1); -1],
Element(mv=[Matrix{Int}(I, 2, 2); zeros(3, 2)],
mi=[zeros(2, 2); Matrix{Int}(I, 2, 2); zeros(1, 2)],
mq=Matrix{Int}(-I, 5, 5), mu=[zeros(4, 1); -1],
nonlinear_eq = quote
let v1=q[1], v2=q[2], i1=q[3], i2=q[4], pos=q[5]
res[1] = v1 - $(r)*pos*i1
Expand Down Expand Up @@ -434,7 +435,7 @@ function bjt(typ; is=1e-12, η=1, isc=is, ise=is, ηc=η, ηe=η, βf=1000, βr=
end
return Element(mv=[1 0; 0 1; 0 0; 0 0],
mi = [-(re+rb) -rb; -rb -(rc+rb); 1 0; 0 1],
mq = -polarity*speye(4), nonlinear_eq = nonlinear_eq,
mq = Matrix{Int}(-polarity*I, 4, 4), nonlinear_eq = nonlinear_eq,
pins = [:base; :emitter; :base; :collector])
end

Expand Down
2 changes: 1 addition & 1 deletion src/kdtree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ isless(e1::AltEntry, e2::AltEntry) = isless(e1.delta_norm, e2.delta_norm)
end

@pfunction Alts(p::Vector{T}) [T] begin
Alts([AltEntry(1, zeros(p), zero(T))], typemax(T), 0, 1)
Alts([AltEntry(1, Vector{T}(length(p)), zero(T))], typemax(T), 0, 1)
end

@pfunction init!(alts::Alts{T}, best_dist, best_pidx) [T] begin
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ using ProgressMeter

# Pathological cases for topomat:
# two nodes, one loop branch (short-circuited) -> voltage==0, current arbitrary
@test ACME.topomat(spzeros(Int, 2, 1)) == (speye(1), spzeros(0, 1))
@test ACME.topomat(spzeros(Int, 2, 1)) == (hcat([1]), spzeros(0, 1))
# two nodes, one branch between them -> voltage arbitrary, current==0
@test ACME.topomat(sparse([1,2], [1,1], [1,-1])) == (spzeros(0, 1), speye(1))
@test ACME.topomat(sparse([1,2], [1,1], [1,-1])) == (spzeros(0, 1), hcat([1]))
end

@testset "LinearSolver" begin
Expand Down

0 comments on commit 3649f56

Please sign in to comment.