Skip to content

Commit 3f2d08f

Browse files
authored
Merge pull request #8 from SciML/ap/fix-copy
Fix copy
2 parents 1d923de + 07e588d commit 3f2d08f

File tree

8 files changed

+67
-29
lines changed

8 files changed

+67
-29
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
style = "sciml"
22
annotate_untyped_fields_with_any = false
3+
join_lines_based_on_source = false

.github/workflows/CI.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ concurrency:
1313
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
1414
jobs:
1515
test:
16-
runs-on: ubuntu-latest
16+
runs-on: ${{ matrix.os }}
1717
strategy:
1818
fail-fast: false
1919
matrix:
2020
version:
2121
- "1"
22+
os:
23+
- ubuntu-latest
24+
- macos-latest
25+
- windows-latest
2226
steps:
2327
- uses: actions/checkout@v4
2428
- uses: julia-actions/setup-julia@v1
2529
with:
2630
version: ${{ matrix.version }}
27-
- uses: actions/cache@v3
31+
- uses: actions/cache@v4
2832
env:
2933
cache-name: cache-artifacts
3034
with:
@@ -36,7 +40,16 @@ jobs:
3640
${{ runner.os }}-
3741
- uses: julia-actions/julia-buildpkg@v1
3842
- uses: julia-actions/julia-runtest@v1
43+
env:
44+
JULIA_NUM_THREADS: 11
45+
RETESTITEMS_NWORKERS: 4
46+
RETESTITEMS_NWORKER_THREADS: 2
3947
- uses: julia-actions/julia-processcoverage@v1
40-
- uses: codecov/codecov-action@v3
4148
with:
42-
files: lcov.info
49+
directories: src
50+
- uses: codecov/codecov-action@v4
51+
with:
52+
file: lcov.info
53+
token: ${{ secrets.CODECOV_TOKEN }}
54+
verbose: true
55+
fail_ci_if_error: true

.github/workflows/Downstream.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ jobs:
5454
exit(0) # Exit immediately, as a success
5555
end
5656
- uses: julia-actions/julia-processcoverage@v1
57-
- uses: codecov/codecov-action@v3
57+
- uses: codecov/codecov-action@v4
5858
with:
5959
files: lcov.info
60+
token: ${{ secrets.CODECOV_TOKEN }}
61+
fail_ci_if_error: true

.github/workflows/FormatPR.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
# https://github.com/peter-evans/create-pull-request#reference-example
1616
- name: Create Pull Request
1717
id: cpr
18-
uses: peter-evans/create-pull-request@v5
18+
uses: peter-evans/create-pull-request@v6
1919
with:
2020
token: ${{ secrets.GITHUB_TOKEN }}
2121
commit-message: Format .jl files

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FastAlmostBandedMatrices"
22
uuid = "9d29842c-ecb8-4973-b1e9-a27b1157504e"
33
authors = ["Avik Pal"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
[![Join the chat at https://julialang.zulipchat.com #sciml-bridged](https://img.shields.io/static/v1?label=Zulip&message=chat&color=9558b2&labelColor=389826)](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged)
44

5-
[![CI](https://github.com/avik-pal/FastAlmostBandedMatrices.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/avik-pal/FastAlmostBandedMatrices.jl/actions/workflows/CI.yml)
6-
[![codecov](https://codecov.io/gh/avik-pal/FastAlmostBandedMatrices.jl/branch/main/graph/badge.svg?)](https://codecov.io/gh/avik-pal/FastAlmostBandedMatrices.jl)
5+
[![CI](https://github.com/SciML/FastAlmostBandedMatrices.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/SciML/FastAlmostBandedMatrices.jl/actions/workflows/CI.yml)
6+
[![codecov](https://codecov.io/gh/SciML/FastAlmostBandedMatrices.jl/branch/main/graph/badge.svg?)](https://codecov.io/gh/SciML/FastAlmostBandedMatrices.jl)
77
[![Package Downloads](https://shields.io/endpoint?url=https://pkgs.genieframework.com/api/v1/badge/FastAlmostBandedMatrices)](https://pkgs.genieframework.com?packages=FastAlmostBandedMatrices)
88
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)
99

src/FastAlmostBandedMatrices.jl

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import PrecompileTools: @recompile_invalidations, @setup_workload, @compile_work
44

55
@recompile_invalidations begin
66
using ArrayInterface, ArrayLayouts, BandedMatrices, ConcreteStructs, LazyArrays,
7-
LinearAlgebra, MatrixFactorizations, Reexport
7+
LinearAlgebra, MatrixFactorizations, Reexport
88
end
99

1010
import ArrayLayouts: MemoryLayout, sublayout, sub_materialize, MatLdivVec, materialize!,
11-
triangularlayout, triangulardata, zero!, _copyto!, colsupport, rowsupport, _qr, _qr!,
12-
_factorize, muladd!
11+
triangularlayout, triangulardata, zero!, _copyto!, colsupport,
12+
rowsupport, _qr, _qr!, _factorize, muladd!
1313
import BandedMatrices: _banded_qr!, bandeddata, banded_qr_lmul!
1414
import LinearAlgebra: ldiv!
1515
import MatrixFactorizations: QR, QRPackedQ, getQ, getR, QRPackedQLayout, AdjQRPackedQLayout
@@ -67,8 +67,8 @@ function AlmostBandedMatrix{T}(::UndefInitializer, mn::NTuple{2, Integer},
6767
return AlmostBandedMatrix(undef, T, mn, lu, rank)
6868
end
6969

70-
function AlmostBandedMatrix(::UndefInitializer, mn::NTuple{2, Integer},
71-
lu::NTuple{2, Integer}, rank::Integer)
70+
function AlmostBandedMatrix(
71+
::UndefInitializer, mn::NTuple{2, Integer}, lu::NTuple{2, Integer}, rank::Integer)
7272
return AlmostBandedMatrix(undef, Float64, mn, lu, rank)
7373
end
7474

@@ -160,6 +160,10 @@ end
160160
end
161161
end
162162

163+
function Base.copy(B::AlmostBandedMatrix)
164+
return AlmostBandedMatrix(copy(bandpart(B)), copy(fillpart(B)))
165+
end
166+
163167
function Base.setindex!(B::AlmostBandedMatrix, v, k::Integer, j::Integer)
164168
if k size(B.fill, 1)
165169
if j > k + bandwidth(B.bands, 2)
@@ -219,8 +223,7 @@ end
219223
# Pretty Printing
220224
# ---------------
221225
function _almost_banded_summary(io, B::AlmostBandedMatrix{T}, inds) where {T}
222-
print(io,
223-
Base.dims2string(length.(inds)),
226+
print(io, Base.dims2string(length.(inds)),
224227
" AlmostBandedMatrix{$T} with bandwidths $(almostbandwidths(B)) and fill \
225228
rank $(almostbandedrank(B))")
226229
end
@@ -267,8 +270,9 @@ function _almostbanded_qr(_, A)
267270
B, L = bandpart(A), fillpart(A)
268271
# Expand the bandsize for the QR factorization
269272
## Bypass the safety checks in `AlmostBandedMatrix`
270-
return almostbanded_qr!(AlmostBandedMatrix{eltype(A)}(BandedMatrix(copy(B), (l, l + u)),
271-
copy(L)), Val(true))
273+
return almostbanded_qr!(
274+
AlmostBandedMatrix{eltype(A)}(BandedMatrix(copy(B), (l, l + u)), copy(L)),
275+
Val(true))
272276
end
273277

274278
# Band size not yet expanded!
@@ -320,14 +324,14 @@ end
320324
L_right = L[:, jr2]
321325
U′ = U[kr, :]
322326
for j in 1:length(jr2)
323-
muladd!(-one(T), U′[(j + 1):end, :], L_right[:, j], one(T),
324-
B_right[(j + 1):end, j])
327+
muladd!(
328+
-one(T), U′[(j + 1):end, :], L_right[:, j], one(T), B_right[(j + 1):end, j])
325329
end
326330
banded_qr_lmul!(Q', B_right)
327331
banded_qr_lmul!(Q', U′)
328332
for j in 1:length(jr2)
329-
muladd!(one(T), U′[(j + 1):end, :], L_right[:, j], one(T),
330-
B_right[(j + 1):end, j])
333+
muladd!(
334+
one(T), U′[(j + 1):end, :], L_right[:, j], one(T), B_right[(j + 1):end, j])
331335
end
332336
k = last(jr1) + 1
333337
end
@@ -363,8 +367,8 @@ _almostbanded_widerect_ldiv!(::QR{T}, B) where {T} = error("Not implemented")
363367

364368
const UpperLayoutMatrix{T} = UpperTriangular{T, <:LayoutMatrix{T}}
365369

366-
for Typ in (:StridedVector, :StridedMatrix, :AbstractVecOrMat, :UpperLayoutMatrix,
367-
:LayoutMatrix)
370+
for Typ in (
371+
:StridedVector, :StridedMatrix, :AbstractVecOrMat, :UpperLayoutMatrix, :LayoutMatrix)
368372
@eval function ldiv!(A::QR{T, <:AlmostBandedMatrix}, B::$Typ{T}) where {T}
369373
m, n = size(A)
370374
if m == n
@@ -410,8 +414,8 @@ end
410414

411415
@inline __original_almostbandedrank(A) = size(first(__lowrankfillpart(A)), 2)
412416

413-
@views function _almostbanded_upper_ldiv!(::Type{Tri}, R::AbstractMatrix,
414-
b::AbstractVector{T}, buffer) where {T, Tri}
417+
@views function _almostbanded_upper_ldiv!(
418+
::Type{Tri}, R::AbstractMatrix, b::AbstractVector{T}, buffer) where {T, Tri}
415419
B = bandpart(R)
416420
U, V = __lowrankfillpart(R)
417421
fill!(buffer, zero(T))
@@ -472,8 +476,8 @@ end
472476
# Matrix Multiply
473477
# ---------------
474478

475-
@views function muladd!(α, A::AlmostBandedMatrix, B::AbstractVecOrMat, β,
476-
C::AbstractVecOrMat)
479+
@views function muladd!(
480+
α, A::AlmostBandedMatrix, B::AbstractVecOrMat, β, C::AbstractVecOrMat)
477481
L = fillpart(A)
478482
muladd!(α, L, B, β, selectdim(C, 1, 1:size(L, 1)))
479483
muladd!(α, exclusive_bandpart(A), B, β, selectdim(C, 1, (size(L, 1) + 1):size(C, 1)))
@@ -504,6 +508,6 @@ end
504508
end
505509

506510
export AlmostBandedMatrix, bandpart, fillpart, exclusive_bandpart, finish_part_setindex!,
507-
almostbandwidths, almostbandedrank
511+
almostbandwidths, almostbandedrank
508512

509513
end

test/runtests.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ using SafeTestsets, Test
1717
@test almostbandedrank(A) == 2
1818
end
1919

20+
@safetestset "Copy" begin
21+
using FastAlmostBandedMatrices
22+
23+
n = 5
24+
m = 2
25+
26+
A1 = AlmostBandedMatrix(brand(Float64, n, n, m + 1, m), rand(Float64, m, n))
27+
A2 = copy(A1)
28+
29+
@test !(A2 isa Matrix)
30+
@test A1 == A2
31+
32+
A2 = deepcopy(A1)
33+
34+
@test !(A2 isa Matrix)
35+
@test A1 == A2
36+
end
37+
2038
@safetestset "QR" begin
2139
using LinearAlgebra, FastAlmostBandedMatrices
2240
import MatrixFactorizations: QRPackedQ

0 commit comments

Comments
 (0)