Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add special type for views of Band, macro to implement banded linear algebra #37

Merged
merged 29 commits into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f5cc302
add special time for views of Band
Oct 24, 2017
ff27d5d
export isbanded
Oct 26, 2017
24b63cf
reorganize files, macro for lin alg overrides
Oct 27, 2017
98e12ad
move macro to generic
dlfivefifty Oct 30, 2017
32417c0
add BlasBanded, BlasSymBanded and BlasStrided traits to dispatch linalg
dlfivefifty Nov 4, 2017
3d258a0
Merge branch 'master' of https://github.com/JuliaMatrices/BandedMatri…
dlfivefifty Nov 12, 2017
f80767f
using Test in 0.7
dlfivefifty Nov 12, 2017
96b95ac
Add @banded and @banded_interface macros for adding new banded matric…
dlfivefifty Nov 13, 2017
acb5b84
start using Zeros and Eye
Nov 20, 2017
35ca220
Deprecate BandedMatrix(data,...) for BandedMatrix{T}(data,...).
Nov 20, 2017
a8d3456
Fix deprecation warnings
Nov 20, 2017
532ea57
• BandedMatrix{T}(data,...) -> _BandedMatrix(data,...)
dlfivefifty Nov 21, 2017
c20884e
Straggler changes to _BandedMatrix
dlfivefifty Nov 21, 2017
94735b4
REQUIRE FillArrays v0.0.1
dlfivefifty Nov 25, 2017
1301823
At BandedMatrix(A::AbstractMatrix, bnds) that projects, and implement…
dlfivefifty Nov 27, 2017
e191ddb
tests pass again
dlfivefifty Nov 27, 2017
7bf0fed
Merge fillarrays
dlfivefifty Nov 29, 2017
93cdcac
REQUIRE Compat 0.38
Nov 30, 2017
a6391cb
Add constructor BandedMatrix{T}((n,m), (l,u))
dlfivefifty Nov 30, 2017
7bbeb50
BandedMatrix{T}(n,m,a,b) -> BandedMatrix{T}(uninitialized,n,m,a,b)
dlfivefifty Dec 2, 2017
e6ecc97
use uninitialized
dlfivefifty Dec 2, 2017
fab2e25
test BBandedMatrix{T}(uninitialized, (n,m), (a,b)) constructor
dlfivefifty Dec 2, 2017
8685b81
blasstructure -> memorylayout
dlfivefifty Dec 23, 2017
fcc4ccf
• αA_mul_B_plus_βC! -> scalemul!
dlfivefifty Dec 26, 2017
60ced52
Add fill! and shorthand BandError
dlfivefifty Jan 3, 2018
422c71d
add banded_copy!
dlfivefifty Jan 8, 2018
ca26051
scalemul! -> mul!
Feb 19, 2018
0529245
reorder mul! arguments
Feb 20, 2018
c316132
Update MemoryLayout
Feb 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/BandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ module BandedMatrices
using Base, Compat

import Base: getindex, setindex!, *, +, -, ==, <, <=, >,
>=, /, ^, \, transpose, showerror, reindex, checkbounds
>=, /, ^, \, transpose, showerror, reindex, checkbounds, @propagate_inbounds

import Base: convert, size, view
import Base: convert, size, view, indices, unsafe_indices, indices1,
first, last, size, length, unsafe_length, start, next, done, step,
to_indices, to_index, indices, show

import Base.BLAS: libblas
import Base.LAPACK: liblapack
Expand Down Expand Up @@ -48,19 +50,22 @@ export BandedMatrix,
bandwidth,
BandError,
band,
Band,
BandRange,
bandwidths,
colrange,
rowrange
rowrange,
isbanded



include("blas.jl")
include("lapack.jl")

include("AbstractBandedMatrix.jl")
include("Band.jl")
include("utils.jl")
include("generic/AbstractBandedMatrix.jl")
include("generic/Band.jl")
include("generic/utils.jl")
include("generic/linalg.jl")

include("banded/BandedMatrix.jl")
include("banded/BandedLU.jl")
Expand All @@ -72,7 +77,7 @@ include("symbanded/SymBandedMatrix.jl")
include("symbanded/BandedCholesky.jl")
include("symbanded/linalg.jl")

include("interface.jl")
include("generic/interface.jl")
include("deprecate.jl")


Expand Down
58 changes: 42 additions & 16 deletions src/banded/BandedMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,37 +207,63 @@ end
@inline getindex(A::BandedMatrix, kr::Colon, jr::Colon) = copy(A)

# ~ indexing along a band
# we reduce it to converting a View

# scalar - band - colon
@inline function getindex(A::BandedMatrix{T}, b::Band) where {T}
@boundscheck checkband(A, b)
if b.i > 0
vec(A.data[A.u - b.i + 1, b.i+1:min(size(A,2),size(A,1)+b.i)])
elseif b.i == 0
vec(A.data[A.u - b.i + 1, 1:min(size(A,2),size(A,1))])
else # b.i < 0
vec(A.data[A.u - b.i + 1, 1:min(size(A,2),size(A,1)+b.i)])
@inline getindex(A::BandedMatrix{T}, b::Band) where {T} = Vector{T}(view(A, b))

# type to represent a view of a band
const BandedMatrixBand{T} = SubArray{T, 1, Base.ReshapedArray{T,1,BandedMatrix{T},
Tuple{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int}}}, Tuple{BandSlice}, false}


band(V::BandedMatrixBand) = first(parentindexes(V)).band.i

# gives a view of the parent's data matrix
function dataview(V::BandedMatrixBand)
A = parent(parent(V))
b = band(V)
m,n = size(A)
if b > 0
view(A.data, A.u - b + 1, b+1:min(n,m+b))
elseif b == 0
view(A.data, A.u - b + 1, 1:min(n,m))
else # b < 0
view(A.data, A.u - b + 1, 1:min(n,m+b))
end
end

@inline function view(A::BandedMatrix{T}, b::Band) where {T}
@boundscheck checkband(A, b)
if b.i > 0
view(A.data,A.u - b.i + 1, b.i+1:min(size(A,2),size(A,1)+b.i))
elseif b.i == 0
view(A.data,A.u - b.i + 1, 1:min(size(A,2),size(A,1)))
else # b.i < 0
view(A.data,A.u - b.i + 1, 1:min(size(A,2),size(A,1)+b.i))
function convert(::Type{Vector{T}}, V::BandedMatrixBand) where T
A = parent(parent(V))
if -A.l ≤ band(V) ≤ A.u
Vector{T}(dataview(V))
else
zeros(T, length(V))
end
end

convert(::Type{Array{T}}, A::BandedMatrixBand) where T = convert(Vector{T}, A)
convert(::Type{Array}, A::BandedMatrixBand) = convert(Vector{eltype(A)}, A)
convert(::Type{Vector}, A::BandedMatrixBand)= convert(Vector{eltype(A)}, A)


convert(::Type{AbstractArray{T}}, A::BandedMatrixBand{T}) where T = A
convert(::Type{AbstractVector{T}}, A::BandedMatrixBand{T}) where T = A
convert(::Type{AbstractArray}, A::BandedMatrixBand{T}) where T = A
convert(::Type{AbstractVector}, A::BandedMatrixBand{T}) where T = A

convert(::Type{AbstractArray{T}}, A::BandedMatrixBand) where T = convert(Vector{T}, A)
convert(::Type{AbstractVector{T}}, A::BandedMatrixBand) where T = convert(Vector{T}, A)


# scalar - BandRange - integer -- A[1, BandRange]
@inline getindex(A::AbstractMatrix, ::Type{BandRange}, j::Integer) = A[colrange(A, j), j]

# scalar - integer - BandRange -- A[1, BandRange]
@inline getindex(A::AbstractMatrix, k::Integer, ::Type{BandRange}) = A[k, rowrange(A, k)]



# ~ indexing along a row


Expand Down
Loading