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 3 commits
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
29 changes: 11 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
language: cpp
compiler:
- clang
language: julia
os:
- linux
julia:
- 0.4
- 0.5
- nightly
notifications:
email: false
env:
matrix:
- JULIAVERSION="juliareleases"
- JULIAVERSION="julianightlies"
before_install:
- sudo add-apt-repository ppa:staticfloat/julia-deps -y
- sudo add-apt-repository ppa:staticfloat/${JULIAVERSION} -y
- sudo apt-get update -qq -y
- sudo apt-get install libpcre3-dev julia -y
script:
- julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir())/SpecialMatrices`); Pkg.pin("SpecialMatrices"); Pkg.resolve()'
- julia -e 'using SpecialMatrices; @assert isdefined(:SpecialMatrices); @assert typeof(SpecialMatrices) === Module'
- if [ $JULIAVERSION = "julianightlies" ]; then julia --code-coverage test/runtests.jl; fi
- if [ $JULIAVERSION = "juliareleases" ]; then julia test/runtests.jl; fi
#script: # the default script is equivalent to the following
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("Example"); Pkg.test("Example"; coverage=true)';
after_success:
- if [ $JULIAVERSION = "julianightlies" ]; then julia -e 'cd(Pkg.dir("SpecialMatrices")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'; fi
- julia -e 'cd(Pkg.dir("SpecialMatrices")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ matrices which are used in linear algebra. Every special matrix has its own type
The full matrix is accessed by the command `full(A)`.

[![Build Status](https://travis-ci.org/jiahao/SpecialMatrices.jl.svg)](https://travis-ci.org/jiahao/SpecialMatrices.jl) [![Coverage Status](https://img.shields.io/coveralls/jiahao/SpecialMatrices.jl.svg)](https://coveralls.io/r/jiahao/SpecialMatrices.jl)
fp4code/fp-cauchy [![Build Status](https://travis-ci.org/fp4code/SpecialMatrices.jl.svg?branch=fp-cauchy)](https://travis-ci.org/fp4code/SpecialMatrices.jl)
[![Coverage Status](https://coveralls.io/repos/github/fp4code/SpecialMatrices.jl/badge.svg?branch=fp-cauchy)](https://coveralls.io/github/fp4code/SpecialMatrices.jl?branch=fp-cauchy)

## Currently supported special matrices

Expand Down
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