Skip to content

Commit f909ce2

Browse files
committed
feat(matrices): add sampling
1 parent 48b6696 commit f909ce2

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Diff for: src/matrices/index.jl

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export
4040
RandSVD,
4141
Rohess,
4242
Rosser,
43+
Sampling,
4344
Toeplitz,
4445
Triw
4546

@@ -81,6 +82,7 @@ include("rando.jl")
8182
include("randsvd.jl")
8283
include("rohess.jl")
8384
include("rosser.jl")
85+
include("sampling.jl")
8486
include("toeplitz.jl")
8587
include("triw.jl")
8688

@@ -127,6 +129,7 @@ MATRIX_GROUPS[GROUP_BUILTIN] = Set([
127129
RandSVD,
128130
Rohess,
129131
Rosser,
132+
Sampling,
130133
Toeplitz,
131134
Triw,
132135
])

Diff for: src/matrices/sampling.jl

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Matrix with Application in Sampling Theory
3+
==========================================
4+
A nonsymmetric matrix with eigenvalues 0, 1, 2, ... n-1.
5+
6+
*Input options:*
7+
8+
+ vec: `vec` is a vector with no repeated elements.
9+
10+
+ dim: `dim` is the dimension of the matrix.
11+
`vec = [1:dim;]/dim`.
12+
13+
*References:*
14+
15+
**L. Bondesson and I. Traat**, A nonsymmetric matrix
16+
with integer eigenvalues, linear and multilinear algebra, 55(3)
17+
(2007), pp. 239-247
18+
"""
19+
struct Sampling{T<:Number} <: AbstractMatrix{T}
20+
n::Integer
21+
vec::Vector{T}
22+
23+
function Sampling(vec::Vector{T}) where {T<:Number}
24+
n = length(vec)
25+
return new{T}(n, vec)
26+
end
27+
end
28+
29+
# constructors
30+
Sampling(n::Integer) = Sampling{Float64}(n)
31+
Sampling{T}(n::Integer) where {T<:Number} = Sampling(T[1:n;] / n)
32+
33+
# metadata
34+
@properties Sampling [:eigen]
35+
36+
# properties
37+
size(A::Sampling) = (A.n, A.n)
38+
39+
# functions
40+
@inline Base.@propagate_inbounds function getindex(A::Sampling{T}, i::Integer, j::Integer) where {T}
41+
@boundscheck checkbounds(A, i, j)
42+
if i == j
43+
element = sum([A[i, index] for index = 1:A.n if index != i])
44+
else
45+
element = A.vec[i] / (A.vec[i] - A.vec[j])
46+
end
47+
return element
48+
end

0 commit comments

Comments
 (0)