Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ErikQQY/AlmostBlockDiagonals.jl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.1.5
Choose a base ref
...
head repository: ErikQQY/AlmostBlockDiagonals.jl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.1.6
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Sep 6, 2024

  1. Remove the deprecated factorization and substitution part

    Signed-off-by: ErikQQY <2283984853@qq.com>
    ErikQQY committed Sep 6, 2024
    Copy the full SHA
    abd44b9 View commit details
  2. Remove the deprecated factorization and substitution part

    Signed-off-by: ErikQQY <2283984853@qq.com>
    ErikQQY committed Sep 6, 2024
    Copy the full SHA
    3e132f6 View commit details
  3. Update Project.toml

    Signed-off-by: ErikQQY <2283984853@qq.com>
    ErikQQY committed Sep 6, 2024
    2
    Copy the full SHA
    b6c0bcc View commit details
Showing with 3 additions and 210 deletions.
  1. +1 −1 Project.toml
  2. +2 −209 src/AlmostBlockDiagonals.jl
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AlmostBlockDiagonals"
uuid = "a95523ee-d6da-40b5-98cc-27bc505739d5"
authors = ["Qingyu Qu"]
version = "0.1.5"
version = "0.1.6"

[deps]
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
211 changes: 2 additions & 209 deletions src/AlmostBlockDiagonals.jl
Original file line number Diff line number Diff line change
@@ -373,8 +373,7 @@ function shift(ai::AbstractArray{T}, nrowi::I, ncoli::I, last::I, ai1::AbstractA
end

function substitution(IA::IntermediateAlmostBlockDiagonal, ipivot::AbstractArray{I}, x) where {I <: Integer}

# forward substitution
# forward substitution

indexx = 1
last = 0
@@ -389,7 +388,7 @@ function substitution(IA::IntermediateAlmostBlockDiagonal, ipivot::AbstractArray
indexx = indexx + last
end

# back substitution
# back substitution

nbp1::Int = nbloks + 1
for j = 1:nbloks
@@ -452,212 +451,6 @@ function backward_substitution(w::AbstractArray{T}, ncol::I, last::I, x) where {
return
end


## to deprecate

function fcblok(bloks, integs, nbloks, ipivot, scrtch)
info = 0
indexx = 1
indexn = 1
i = 1

while true
index = copy(indexn)
nrow::Int = integs[1,i]
ncol::Int = integs[2,i]
last::Int = integs[3,i]
info = @views factrb(bloks[index:index+nrow*ncol-1], ipivot[indexx:indexx+nrow-1], scrtch, nrow, ncol, last, info)
(info !== 0) && break

i == nbloks && return info
i = i+1
indexn::Int = nrow * ncol + index
indexx::Int = indexx + last

@views shiftb(bloks[index:index+nrow*ncol-1], nrow, ncol, last, bloks[indexn:indexn+Int(integs[1,i])*Int(integs[2,i])-1], Int(integs[1,i]), Int(integs[2,i]))
end
info = info + indexx - 1
return info
end

function factrb(w, ipivot, d, nrow, ncol, last, info)
w = reshape(w, nrow, ncol)
# initialize d
for i = 1:nrow
d[i] = 0.0
end

for j = 1:ncol
for i = 1:nrow
d[i] = max(d[i], abs(w[i, j]))
end
end

k = 1

while k <= last
(d[k] == 0.0) && (@goto n90)
(k == nrow) && (@goto n80)
l = k
kp1 = k+1
colmax = abs(w[k, k]) / d[k]

for i = kp1:nrow
if abs(w[i, k]) > colmax * d[i]
colmax = abs(w[i, k]) / d[i]
l = i
end
end
ipivot[k] = l
t = copy(w[l, k])
s = d[l]
if l !== k
w[l, k] = copy(w[k, k])
w[k, k] = copy(t)
d[l] = copy(d[k])
d[k] = copy(s)
end
( abs(t)+d[k] <= d[k] ) && (@goto n90)

t = -1.0/t
for i = kp1:nrow
w[i, k] = w[i, k] * t
end
for j=kp1:ncol
t = copy(w[l, j])
if l !== k
w[l,j] = copy(w[k,j])
w[k,j] = copy(t)
end
if ( t !== 0 )
for i = kp1:nrow
w[i,j] = w[i,j] + w[i,k] * t
end
end
end
k = kp1
end
return info

@label n80

(abs(w[nrow, nrow])+d[nrow] > d[nrow]) && return info

@label n90
info = k
return info
end

function shiftb(ai, nrowi::Int, ncoli::Int, last, ai1, nrowi1::Int, ncoli1::Int)
ai = reshape(ai, nrowi, ncoli)
ai1 = reshape(ai1, nrowi1, ncoli1)
mmax = nrowi - last
jmax = ncoli - last
(mmax < 1 || jmax < 1) && return

# put the remainder of block i into ai1

for j=1:jmax
for m=1:mmax
ai1[m, j] = ai[last+m,last+j]
end
end
(jmax == ncoli1) && return

# zero out the upper right corner of ai1

jmaxp1 = jmax + 1
for j=jmaxp1:ncoli1
for m=1:mmax
ai1[m, j] = 0.0
end
end

return
end

function sbblok(bloks, integs, nbloks, ipivot, x)
# forward substitution pass

index::Int = 1
indexx::Int = 1
last::Int = 0
for i = 1:nbloks
nrow::Int = integs[1,i]
ncol::Int = integs[2,i]
last = integs[3,i]
@views subfor(bloks[index:index+nrow*ncol-1], ipivot[indexx:indexx+last-1], nrow, ncol, last, x[indexx:indexx+nrow-1])

index = nrow * integs[2,i] + index
indexx = indexx + last
end

# back substitution pass

nbp1::Int = nbloks + 1
for j = 1:nbloks
i = nbp1 - j
nrow::Int = integs[1,i]
ncol::Int = integs[2,i]
last = integs[3,i]
index = index - nrow * ncol
indexx = indexx - last

@views subbak(bloks[index:index+nrow*ncol-1], nrow, ncol, last, x[indexx:indexx+ncol-1])
end
return
end

function subfor(w, ipivot, nrow, ncol, last, x)
w = reshape(w, nrow, ncol)
nrow == 1 && return
lstep = min(nrow-1 , last)
for k = 1:lstep
kp1 = k + 1
ip::Int = ipivot[k]
t = x[ip]
x[ip] = x[k]
x[k] = t
if t !== 0.0
for i = kp1:nrow
x[i] = x[i] + w[i,k] * t
end
end
end
return
end

function subbak(w, nrow, ncol, last, x)
w = reshape(w, nrow, ncol)
lp1 = last + 1
if ( lp1 <= ncol )
for j = lp1:ncol
t = - x[j]
if t !== 0.0
for i = 1:last
x[i] = x[i] + w[i, j] * t
end
end
end
end
if last !== 1
lm1 = last - 1
for kb = 1:lm1
km1 = last - kb
k = km1 + 1
x[k] = x[k]/w[k, k]
t = - x[k]
if t !== 0.0
for i = 1:km1
x[i] = x[i] + w[i, k] * t
end
end
end
end
x[1] = x[1]/w[1, 1]
return
end

export AlmostBlockDiagonal, IntermediateAlmostBlockDiagonal
export factor_shift, substitution