Skip to content

Commit 9bef9f2

Browse files
committed
feat(matrices): add minij
1 parent 0bb83ba commit 9bef9f2

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

src/matrices/index.jl

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
export
22
list_groups,
3-
list_matrices
3+
list_matrices,
4+
Minij
45

56
# include all matrices
7+
include("minij.jl")
68

79
# matrix groups
810
const MATRIX_GROUPS = Dict{Group,Set{Type{<:AbstractMatrix}}}()
911
MATRIX_GROUPS[Group(:builtin)] = Set([
12+
Minij,
1013
])
1114
MATRIX_GROUPS[Group(:user)] = Set([])
1215

src/matrices/minij.jl

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
MIN[I,J] Matrix
3+
===============
4+
A matrix with `(i,j)` entry `min(i,j)`. It is a symmetric positive
5+
definite matrix. The eigenvalues and eigenvectors are known
6+
explicitly. Its inverse is tridiagonal.
7+
8+
*Input options:*
9+
10+
+ [type,] dim: the dimension of the matrix.
11+
12+
*Groups:* ["inverse", "symmetric", "posdef", "eigen"]
13+
14+
*References:*
15+
16+
**J. Fortiana and C. M. Cuadras**, A family of matrices,
17+
the discretized Brownian bridge, and distance-based regression,
18+
Linear Algebra Appl., 264 (1997), 173-188. (For the eigensystem of A.)
19+
"""
20+
struct Minij{T<:Integer} <: AbstractMatrix{T}
21+
n::Int
22+
23+
function Minij(::Type{T}, n::Int) where {T<:Integer}
24+
n > 0 || throw(ArgumentError("$n ≤ 0"))
25+
return new{T}(n)
26+
end
27+
end
28+
29+
# constructors
30+
Minij(n::Int) = Minij(Int, n)
31+
32+
# metadata
33+
@properties Minij [:symmetric, :inverse, :posdef, :eigen]
34+
35+
# properties
36+
size(s::Minij) = (s.n, s.n)
37+
LinearAlgebra.isdiag(::Minij) = false
38+
LinearAlgebra.ishermitian(::Minij) = true
39+
LinearAlgebra.isposdef(::Minij) = true
40+
LinearAlgebra.issymmetric(::Minij) = true
41+
LinearAlgebra.adjoint(A::Minij) = A
42+
LinearAlgebra.transpose(A::Minij) = A
43+
44+
# functions
45+
@inline Base.Base.@propagate_inbounds function getindex(A::Minij{T}, i::Integer, j::Integer) where {T}
46+
@boundscheck checkbounds(A, i, j)
47+
return T(min(i, j))
48+
end
49+
50+
function LinearAlgebra.inv(A::Minij{T}) where {T}
51+
if A.n == 1
52+
return ones(T, 1, 1)
53+
else
54+
return SymTridiagonal(2 * ones(T, A.n), -ones(T, A.n - 1))
55+
end
56+
end

0 commit comments

Comments
 (0)