Skip to content

Commit

Permalink
Merge pull request #152 from JuliaLang/anj/covcor
Browse files Browse the repository at this point in the history
Add some compat stuff for the cov and cor API changes
  • Loading branch information
andreasnoack committed Mar 1, 2016
2 parents e01427f + 4f99451 commit a2bfc2c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ Currently, the `@compat` macro supports the following syntaxes:
Compat provides an unexported `Compat.Filesystem` method that is aliased to
`Base.FS` on Julia 0.3 and 0.4 and `Base.Filesystem` on Julia 0.5.

* `mktemp` and `mktempdir` now have variants which take a function as their first argument for automated cleanup. [#9017](https://github.com/JuliaLang/julia/pull/9017)
* `mktemp` and `mktempdir` now have variants which take a function as their first argument for automated cleanup. [#9017](https://github.com/JuliaLang/julia/pull/9017)

* `cov` and `cor` don't allow keyword arguments anymore. Loading Compat defines compatibility methods for the new API. [#13465](https://github.com/JuliaLang/julia/pull/13465)

## New types

Expand Down
14 changes: 14 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,20 @@ if VERSION < v"0.4.0-dev+1653"
end
end

if VERSION < v"0.5.0-dev+679"
import Base: cov, cor

cov(x::AbstractVector, corrected::Bool) = cov(x, corrected=corrected)
cov(X::AbstractMatrix, vardim::Integer) = cov(X, vardim=vardim)
cov(X::AbstractMatrix, vardim::Integer, corrected::Bool) = cov(X, vardim=vardim, corrected=corrected)
cov(x::AbstractVector, y::AbstractVector, corrected::Bool) = cov(x, y, corrected=corrected)
cov(X::AbstractMatrix, Y::AbstractMatrix, vardim::Integer) = cov(X, Y, vardim=vardim)
cov(X::AbstractMatrix, Y::AbstractMatrix, vardim::Integer, corrected::Bool) = cov(X, Y, vardim=vardim, corrected=corrected)

cor(X::AbstractMatrix, vardim::Integer) = cor(X, vardim=vardim)
cor(X::AbstractMatrix, Y::AbstractMatrix, vardim::Integer) = cor(X, Y, vardim=vardim)
end

if VERSION < v"0.5.0-dev+2228"
const readstring = readall
export readstring
Expand Down
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,20 @@ end

@test issymmetric([1 2 3; 2 2 3; 3 3 2])
@test !issymmetric([1 3 3; 2 2 3; 3 3 2])

let X = randn(10,2), Y = randn(10,2), x = randn(10), y = randn(10)
for b in (true, false)
if VERSION < v"0.5.0-dev+679"
@test cov(x, b) == cov(x, corrected=b)
end
for d in (1, 2)
@test size(cov(X, d), 1) == 8*d - 6
@test size(cov(X, d, b), 1) == 8*d - 6
@test size(cov(X, Y, d), 1) == 8*d - 6
@test size(cov(X, Y, d, b), 1) == 8*d - 6

@test size(cor(X, d), 1) == 8*d - 6
@test size(cor(X, Y, d), 1) == 8*d - 6
end
end
end

0 comments on commit a2bfc2c

Please sign in to comment.