-
Notifications
You must be signed in to change notification settings - Fork 36
Introduce JuliaFormatter with style=blue #220
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
Changes from 9 commits
e9b08e9
4ce86f5
45660a6
6f96081
febfae8
59e1ee8
dbec702
9909892
cacfdee
9eded25
53fc498
f0f7cd9
b4d450a
bf19369
0f57bc9
a47c170
f7872d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
style = "blue" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,29 @@ jobs: | |
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
path-to-lcov: ./lcov.info | ||
|
||
format: | ||
st-- marked this conversation as resolved.
Show resolved
Hide resolved
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: julia-actions/setup-julia@latest | ||
with: | ||
version: 1 | ||
|
||
st-- marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- uses: actions/checkout@v1 | ||
- name: Install JuliaFormatter and format | ||
# The version of JuliaFormatter used is just to show how to specify the version. The latest | ||
# version would be preferrable. | ||
run: | | ||
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.12.2"))' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like that the version number has to be updated manually if there is a new version of JuliaFortmatter. We could just install the latest version but this means we would end up with breaking changes without realizing. Ideally, we would add a Project.toml file in some directory and be notified about breaking releases by CompatHelper. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, that'd be nice. I'm not sure how you'd go about sorting it out with the Project.toml (feel free to make those changes on this branch or a separate PR). I do think it's overall better to pin the version of the formatter, as otherwise it can be hard to figure out how exactly to get the local formatter be in sync with the cloud format-checker.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Similar to the package, tests, and documentation, we can specify the SemVer-compatible versions in a separate project environment. CompatHelper will automatically create a PR on Github if a new breaking release is available (we are not notified about non-breaking releases).
I think specifying the version that we use in a project environment is the best we can do. We can't control which version of JuliaFormatter developers use in their editors or install globally but if they load our project environment it will always be compatible. |
||
julia -e 'using JuliaFormatter; format(".", verbose=true)' | ||
- name: Format check | ||
run: | | ||
julia -e ' | ||
out = Cmd(`git diff --name-only`) |> read |> String | ||
if out == "" | ||
exit(0) | ||
else | ||
@error "Some files have not been formatted !!!" | ||
write(stdout, out) | ||
exit(1) | ||
end' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,106 @@ | ||
using Plots; pyplot(); | ||
using Plots; | ||
pyplot(); | ||
using Distributions | ||
using LinearAlgebra | ||
using KernelFunctions | ||
# Translational invariants kernels | ||
|
||
default(lw=3.0,titlefontsize=28,tickfontsize=18) | ||
default(; lw=3.0, titlefontsize=28, tickfontsize=18) | ||
|
||
x₀ = 0.0; l = 0.1 | ||
x₀ = 0.0; | ||
l = 0.1; | ||
n_grid = 101 | ||
fill(x₀,n_grid,1) | ||
xrange = reshape(collect(range(-3,3,length=n_grid)),:,1) | ||
fill(x₀, n_grid, 1) | ||
xrange = reshape(collect(range(-3, 3; length=n_grid)), :, 1) | ||
|
||
k = transform(SqExponentialKernel(),1.0) | ||
K1 = kernelmatrix(k,xrange,obsdim=1) | ||
p = heatmap(K1,yflip=true,colorbar=false,framestyle=:none,background_color=RGBA(0.0,0.0,0.0,0.0)) | ||
savefig(joinpath(@__DIR__,"src","assets","heatmap_sqexp.png")) | ||
k = transform(SqExponentialKernel(), 1.0) | ||
K1 = kernelmatrix(k, xrange; obsdim=1) | ||
p = heatmap( | ||
K1; | ||
yflip=true, | ||
colorbar=false, | ||
framestyle=:none, | ||
background_color=RGBA(0.0, 0.0, 0.0, 0.0), | ||
) | ||
savefig(joinpath(@__DIR__, "src", "assets", "heatmap_sqexp.png")) | ||
|
||
k = @kernel Matern32Kernel FunctionTransform(x -> (sin.(x)) .^ 2) | ||
K2 = kernelmatrix(k, xrange; obsdim=1) | ||
p = heatmap( | ||
K2; | ||
yflip=true, | ||
colorbar=false, | ||
framestyle=:none, | ||
background_color=RGBA(0.0, 0.0, 0.0, 0.0), | ||
) | ||
savefig(joinpath(@__DIR__, "src", "assets", "heatmap_matern.png")) | ||
|
||
k = @kernel Matern32Kernel FunctionTransform(x->(sin.(x)).^2) | ||
K2 = kernelmatrix(k,xrange,obsdim=1) | ||
p = heatmap(K2,yflip=true,colorbar=false,framestyle=:none,background_color=RGBA(0.0,0.0,0.0,0.0)) | ||
savefig(joinpath(@__DIR__,"src","assets","heatmap_matern.png")) | ||
k = transform(PolynomialKernel(; c=0.0, d=2.0), LinearTransform(randn(3, 1))) | ||
K3 = kernelmatrix(k, xrange; obsdim=1) | ||
p = heatmap( | ||
K3; | ||
yflip=true, | ||
colorbar=false, | ||
framestyle=:none, | ||
background_color=RGBA(0.0, 0.0, 0.0, 0.0), | ||
) | ||
savefig(joinpath(@__DIR__, "src", "assets", "heatmap_poly.png")) | ||
|
||
k = | ||
0.5 * SqExponentialKernel() * transform(LinearKernel(), 0.5) + | ||
0.4 * (@kernel Matern32Kernel() FunctionTransform(x -> sin.(x))) | ||
K4 = kernelmatrix(k, xrange; obsdim=1) | ||
p = heatmap( | ||
K4; | ||
yflip=true, | ||
colorbar=false, | ||
framestyle=:none, | ||
background_color=RGBA(0.0, 0.0, 0.0, 0.0), | ||
) | ||
savefig(joinpath(@__DIR__, "src", "assets", "heatmap_prodsum.png")) | ||
|
||
k = transform(PolynomialKernel(c=0.0,d=2.0), LinearTransform(randn(3,1))) | ||
K3 = kernelmatrix(k,xrange,obsdim=1) | ||
p = heatmap(K3,yflip=true,colorbar=false,framestyle=:none,background_color=RGBA(0.0,0.0,0.0,0.0)) | ||
savefig(joinpath(@__DIR__,"src","assets","heatmap_poly.png")) | ||
|
||
k = 0.5*SqExponentialKernel()*transform(LinearKernel(),0.5) + 0.4*(@kernel Matern32Kernel() FunctionTransform(x->sin.(x))) | ||
K4 = kernelmatrix(k,xrange,obsdim=1) | ||
p = heatmap(K4,yflip=true,colorbar=false,framestyle=:none,background_color=RGBA(0.0,0.0,0.0,0.0)) | ||
savefig(joinpath(@__DIR__,"src","assets","heatmap_prodsum.png")) | ||
|
||
plot(heatmap.([K1,K2,K3,K4],yflip=true,colorbar=false)...,layout=(2,2)) | ||
savefig(joinpath(@__DIR__,"src","assets","heatmap_combination.png")) | ||
plot(heatmap.([K1, K2, K3, K4], yflip=true, colorbar=false)...; layout=(2, 2)) | ||
savefig(joinpath(@__DIR__, "src", "assets", "heatmap_combination.png")) | ||
|
||
## | ||
|
||
for k in [SqExponentialKernel,ExponentialKernel] | ||
K = kernelmatrix(k(),xrange,obsdim=1) | ||
v = rand(MvNormal(K+1e-7I)) | ||
plot(xrange,v,lab="",title="f(x)",framestyle=:none) |> display | ||
savefig(joinpath(@__DIR__,"src","assets","GP_sample_$(k).png")) | ||
plot(xrange,kernel.(k(),x₀,xrange),lab="",ylims=(0,1.1),title="k(0,x)") |> display | ||
savefig(joinpath(@__DIR__,"src","assets","kappa_function_$(k).png")) | ||
for k in [SqExponentialKernel, ExponentialKernel] | ||
K = kernelmatrix(k(), xrange; obsdim=1) | ||
v = rand(MvNormal(K + 1e-7I)) | ||
display(plot(xrange, v; lab="", title="f(x)", framestyle=:none)) | ||
savefig(joinpath(@__DIR__, "src", "assets", "GP_sample_$(k).png")) | ||
display(plot(xrange, kernel.(k(), x₀, xrange); lab="", ylims=(0, 1.1), title="k(0,x)")) | ||
savefig(joinpath(@__DIR__, "src", "assets", "kappa_function_$(k).png")) | ||
end | ||
|
||
for k in [GammaExponentialKernel(1.0,1.5)] | ||
sparse =1 | ||
while !isposdef(kernelmatrix(k,xrange*sparse,obsdim=1) + 1e-5I); sparse += 1; end | ||
v = rand(MvNormal(kernelmatrix(k,xrange*sparse,obsdim=1)+1e-7I)) | ||
plot(xrange,v,lab="",title="f(x)",framestyle=:none) |> display | ||
savefig(joinpath(@__DIR__,"src","assets","GP_sample_GammaExponentialKernel.png")) | ||
plot(xrange,kernel.(k,x₀,xrange),lab="",ylims=(0,1.1),title="k(0,x)") |> display | ||
savefig(joinpath(@__DIR__,"src","assets","kappa_function_GammaExponentialKernel.png")) | ||
for k in [GammaExponentialKernel(1.0, 1.5)] | ||
sparse = 1 | ||
while !isposdef(kernelmatrix(k, xrange * sparse; obsdim=1) + 1e-5I) | ||
sparse += 1 | ||
end | ||
v = rand(MvNormal(kernelmatrix(k, xrange * sparse; obsdim=1) + 1e-7I)) | ||
display(plot(xrange, v; lab="", title="f(x)", framestyle=:none)) | ||
savefig(joinpath(@__DIR__, "src", "assets", "GP_sample_GammaExponentialKernel.png")) | ||
display(plot(xrange, kernel.(k, x₀, xrange); lab="", ylims=(0, 1.1), title="k(0,x)")) | ||
savefig( | ||
joinpath(@__DIR__, "src", "assets", "kappa_function_GammaExponentialKernel.png") | ||
) | ||
end | ||
|
||
for k in [MaternKernel,Matern32Kernel,Matern52Kernel] | ||
K = kernelmatrix(k(),xrange,obsdim=1) | ||
v = rand(MvNormal(K+1e-7I)) | ||
plot(xrange,v,lab="",title="f(x)",framestyle=:none) |> display | ||
savefig(joinpath(@__DIR__,"src","assets","GP_sample_$(k).png")) | ||
plot(xrange,kernel.(k(),x₀,xrange),lab="",ylims=(0,1.1),title="k(0,x)") |> display | ||
savefig(joinpath(@__DIR__,"src","assets","kappa_function_$(k).png")) | ||
for k in [MaternKernel, Matern32Kernel, Matern52Kernel] | ||
K = kernelmatrix(k(), xrange; obsdim=1) | ||
v = rand(MvNormal(K + 1e-7I)) | ||
display(plot(xrange, v; lab="", title="f(x)", framestyle=:none)) | ||
savefig(joinpath(@__DIR__, "src", "assets", "GP_sample_$(k).png")) | ||
display(plot(xrange, kernel.(k(), x₀, xrange); lab="", ylims=(0, 1.1), title="k(0,x)")) | ||
savefig(joinpath(@__DIR__, "src", "assets", "kappa_function_$(k).png")) | ||
end | ||
|
||
|
||
for k in [RationalQuadraticKernel] | ||
K = kernelmatrix(k(),xrange,obsdim=1) | ||
v = rand(MvNormal(K+1e-7I)) | ||
plot(xrange,v,lab="",title="f(x)",framestyle=:none) |> display | ||
savefig(joinpath(@__DIR__,"src","assets","GP_sample_$(k).png")) | ||
plot(xrange,kernel.(k(),x₀,xrange),lab="",ylims=(0,1.1),title="k(0,x)") |> display | ||
savefig(joinpath(@__DIR__,"src","assets","kappa_function_$(k).png")) | ||
K = kernelmatrix(k(), xrange; obsdim=1) | ||
v = rand(MvNormal(K + 1e-7I)) | ||
display(plot(xrange, v; lab="", title="f(x)", framestyle=:none)) | ||
savefig(joinpath(@__DIR__, "src", "assets", "GP_sample_$(k).png")) | ||
display(plot(xrange, kernel.(k(), x₀, xrange); lab="", ylims=(0, 1.1), title="k(0,x)")) | ||
savefig(joinpath(@__DIR__, "src", "assets", "kappa_function_$(k).png")) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate from the others as format-testing should be independent of the host/version matrix and it seems more sensible to only run it once (and then it's easier to distinguish format failure from the "regular" tests)