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

Clean and 100% covered Cauchy matrices #17

Merged
merged 26 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
33 changes: 16 additions & 17 deletions src/cauchy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@

export Cauchy

immutable Cauchy{T} <: AbstractMatrix{T}
x::Vector{T} #
y::Vector{T} #
end # immutable

function Cauchy(k::Number)
Cauchy([1:k],[1:k])
immutable Cauchy{T<:Number} <: AbstractMatrix{T}
x::Vector{T}
y::Vector{T}
end

function Cauchy(x::Vector)
Cauchy(x,x)
function Cauchy(x, y)
T = promote_type(eltype(x), eltype(y))
vx = Vector{T}(x)
vy = Vector{T}(y)
Cauchy(vx, vy)
end
function Cauchy(x)
vx = Vector(x)
Cauchy(vx, vx)
end
Cauchy(k::Number) = Cauchy(1:k)

# Define its size

size(A::Cauchy, dim::Integer) = length(A.x)
JeffFessler marked this conversation as resolved.
Show resolved Hide resolved
size(A::Cauchy)= size(A,1), size(A,1)
size(A::Cauchy) = (size(A.x,1), size(A.y,1))

# Index into a Cauchy
function getindex(A::Cauchy,i::Integer,j::Integer)
return 1.0/(A.x[i]+A.y[j])
end # getindex
end

# Dense version of Cauchy
full(A::Cauchy) =[A[i,j] for i=1:size(A,1), j=1:size(A,2)]
full(A::Cauchy) = [A[i,j] for i=1:size(A,1), j=1:size(A,2)]
3 changes: 3 additions & 0 deletions test/cauchy.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@test maxabs(1 ./ Cauchy(3) - [2 3 4; 3 4 5; 4 5 6]) < 1e-14
@test maxabs(1 ./ full(Cauchy(3)) - [2 3 4; 3 4 5; 4 5 6]) < 1e-14
@test maxabs(1 ./ Cauchy(1:3, [2im, 10]) - [1+2im 11; 2+2im 12; 3+2im 13]) < 1e-14