From 917145f4c7d4f8ca812003f75708f46e0a717049 Mon Sep 17 00:00:00 2001 From: Mathias Louboutin Date: Mon, 24 Aug 2020 11:49:32 -0400 Subject: [PATCH] re-enable most test, PARSDMM test setup broken --- .github/workflows/cancel.yml | 16 ++++++++ .github/workflows/ci-test.yml | 54 +++++++++++++++++++++++++++ Project.toml | 15 ++++---- src/cg.jl | 2 +- test/runtests.jl | 51 +++++++++++++------------ test/test_PARSDMM.jl | 19 +++++----- test/test_Q_update.jl | 14 ++++--- test/test_TD_OPs.jl | 30 +++++++-------- test/test_adapt_rho_gamma_parallel.jl | 53 +++++++++++++------------- test/test_argmin_x.jl | 12 +++--- test/test_cg.jl | 4 +- test/test_projectors.jl | 6 +-- test/test_prox_l2s!.jl | 4 +- test/test_update_y_l.jl | 52 +++++++++++++------------- test/test_update_y_l_parallel.jl | 28 +++++++------- 15 files changed, 216 insertions(+), 144 deletions(-) create mode 100644 .github/workflows/cancel.yml create mode 100644 .github/workflows/ci-test.yml diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml new file mode 100644 index 0000000..0a63445 --- /dev/null +++ b/.github/workflows/cancel.yml @@ -0,0 +1,16 @@ +name: Cancel + +on: [push] + +jobs: + cancel: + name: 'Cancel Previous Runs' + runs-on: ubuntu-latest + timeout-minutes: 3 + steps: + - uses: styfle/cancel-workflow-action@0.4.0 + with: + # Ids to cancel op/judi + # https://api.github.com/repos/slimgroup/JUDI.jl/actions/workflows + workflow_id: 2306091 + access_token: ${{ github.token }} \ No newline at end of file diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml new file mode 100644 index 0000000..be9fed1 --- /dev/null +++ b/.github/workflows/ci-test.yml @@ -0,0 +1,54 @@ +name: CI-SetIntersectionProjection + +on: + # Trigger the workflow on push to master or pull request + # to be merged in master + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + + matrix: + version: ['1.1', '1.2', '1.3', '1.4', '1.5', 'nightly'] + os: [ubuntu-latest] + + include: + - version: 1.3 + os: macos-latest + + - version: 1.4 + os: macos-latest + + steps: + - name: Checkout SetIntersectionProjection + uses: actions/checkout@v2 + + - name: Setup julia + uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: x64 + + - name: Add SLIM registery + run: | + julia --color=yes --check-bounds=yes -e 'using Pkg;Pkg.update();Pkg.Registry.add(RegistrySpec(url="https://github.com/slimgroup/SLIMregistryJL.git"))' + + - name: Build SetIntersectionProjection + uses: julia-actions/julia-buildpkg@latest + + - name: Run tests + uses: julia-actions/julia-runtest@latest + + - uses: julia-actions/julia-uploadcodecov@latest + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/Project.toml b/Project.toml index 2c14f01..a68aee1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,21 +1,20 @@ - name = "SetIntersectionProjection" uuid = "335f7d24-6316-57dd-9c3a-df470f2b739e" authors = ["Bas Peters <1.bas.peters@gmail.com>"] -version = "0.0.0" +version = "0.1.0" [deps] Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" +DistributedArrays = "aaf54ef3-cdf8-58ed-94cc-d582ad619b94" +FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" +Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" +JOLI = "bb331ad6-a1cf-11e9-23da-9bcb53c69f6f" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +SortingAlgorithms = "a2af1166-a08f-5f64-846c-94a0d3cef48c" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" -JOLI = "bb331ad6-a1cf-11e9-23da-9bcb53c69f6f" Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a" -SortingAlgorithms = "a2af1166-a08f-5f64-846c-94a0d3cef48c" -Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" -Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" -DistributedArrays = "aaf54ef3-cdf8-58ed-94cc-d582ad619b94" diff --git a/src/cg.jl b/src/cg.jl index 75fbdaf..1eb869b 100644 --- a/src/cg.jl +++ b/src/cg.jl @@ -3,7 +3,7 @@ export cg function cg(A::SparseMatrixCSC{T1,Int},b::Array{T2,1}; kwargs...) where {T1,T2} x = zeros(promote_type(T1,T2),size(A,2)) # pre-allocate - return cg(v -> At_mul_B!(1.0,A,v,0.0,x),b;kwargs...) # multiply with transpose of A for efficiency + return cg(v -> mul!(x, transpose(A), v, 1.0, 0.0),b; kwargs...) # multiply with transpose of A for efficiency end cg(A,b::Vector;kwargs...) = cg(x -> A*x,b;kwargs...) diff --git a/test/runtests.jl b/test/runtests.jl index f71ec98..639f33a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,7 +12,7 @@ end @assert nprocs() > 3 @assert nworkers() >= 3 -@everywhere using DistributedArrays +@everywhere using DistributedArrays, SparseArrays @everywhere using JOLI @everywhere using SetIntersectionProjection @@ -23,32 +23,31 @@ end end - @testset "SetIntersectionProjection" begin -include("test_projectors.jl") -include("test_setup_constraints.jl") - -#still need to port the stuff below to Julia 1.1 - -# include("test_TD_OPs.jl") -# include("test_prox_l2s!.jl") -# include("test_argmin_x.jl") -# include("test_update_y_l.jl") -# -# #parallel scripts -# include("test_update_y_l_parallel.jl") -# include("test_adapt_rho_gamma_parallel.jl") -# -# #linear algebra subroutines -# include("test_cg.jl") -# include("test_CDS_Mvp.jl") -# include("test_CDS_scaled_add.jl") -# include("test_Q_update.jl") -# -# #test full algorithms -# include("test_PARSDMM.jl") -# include("test_PARSDMM_parallel.jl") -# include("test_PARSDMM_multilevel.jl") + include("test_projectors.jl") + include("test_setup_constraints.jl") + + #still need to port the stuff below to Julia 1.1 + + include("test_TD_OPs.jl") + include("test_prox_l2s!.jl") + include("test_argmin_x.jl") + include("test_update_y_l.jl") + + #parallel scripts + include("test_update_y_l_parallel.jl") + include("test_adapt_rho_gamma_parallel.jl") + + #linear algebra subroutines + include("test_cg.jl") + include("test_CDS_Mvp.jl") + include("test_CDS_scaled_add.jl") + include("test_Q_update.jl") + + #test full algorithms + # include("test_PARSDMM.jl") + # include("test_PARSDMM_parallel.jl") + # include("test_PARSDMM_multilevel.jl") end diff --git a/test/test_PARSDMM.jl b/test/test_PARSDMM.jl index 54758d5..45ac01d 100644 --- a/test/test_PARSDMM.jl +++ b/test/test_PARSDMM.jl @@ -5,11 +5,10 @@ options=PARSDMM_options() options.FL = Float64 options.parallel = false options.zero_ini_guess = true -options.linear_inv_prob_flag = false x=randn(100,201) -comp_grid=compgrid((1.0, 1.0),(100, 201)) +comp_grid = compgrid((1.0, 1.0),(100, 201)) x = vec(x) m2 = deepcopy(x) x_ini2 = deepcopy(x) @@ -18,8 +17,8 @@ constraint= Dict() #check if input returns if the input satisfies the constraints #bound constraints constraint["use_bounds"]=true - constraint["m_min"]=minimum(vec(x)) - constraint["m_max"]=maximum(vec(x)) + constraint["min"]=minimum(vec(x)) + constraint["max"]=maximum(vec(x)) (P_sub,TD_OP,TD_Prop) = setup_constraints(constraint,comp_grid,options.FL) (TD_OP,AtA,l,y) = PARSDMM_precompute_distribute(TD_OP,TD_Prop,comp_grid,options) @@ -33,8 +32,8 @@ constraint= Dict() #add a few convex constraints. The projected model should satisfy these constraints #bound constraints constraint["use_bounds"]=true - constraint["m_min"]=0.5*minimum(vec(x)) - constraint["m_max"]=0.5*maximum(vec(x)) + constraint["min"]=0.5*minimum(vec(x)) + constraint["max"]=0.5*maximum(vec(x)) #transform domain bounds (TD_OP, AtA_diag, dense, TD_n)=get_TD_operator(comp_grid,"D_z",options.FL) @@ -182,8 +181,8 @@ constraint= Dict() #add a few convex constraints which the model already satisfies #bound constraints constraint["use_bounds"]=false - constraint["m_min"]=1.0*minimum(vec(c_l_solution)) - constraint["m_max"]=1.456*maximum(vec(c_l_solution)) + constraint["min"]=1.0*minimum(vec(c_l_solution)) + constraint["max"]=1.456*maximum(vec(c_l_solution)) #transform domain bounds (TD_OP, AtA_diag, dense, TD_n)=get_TD_operator(comp_grid,"D_z",options.FL) @@ -236,8 +235,8 @@ constraint["TD_nuclear_operator_1"]="identity" #add a few convex constraints which the model already satisfies #bound constraints constraint["use_bounds"]=true - constraint["m_min"]=1.0*minimum(x) - constraint["m_max"]=0.50*maximum(x) + constraint["min"]=1.0*minimum(x) + constraint["max"]=0.50*maximum(x) #transform domain bounds (TD_OP, AtA_diag, dense, TD_n)=get_TD_operator(comp_grid,"D_z",options.FL) diff --git a/test/test_Q_update.jl b/test/test_Q_update.jl index 1031e76..1866412 100755 --- a/test/test_Q_update.jl +++ b/test/test_Q_update.jl @@ -2,7 +2,7 @@ #sparse matrix A=sprandn(100,100,0.1) - B=Vector{SparseMatrixCSC{Float64,Int64}}(2) + B=Vector{SparseMatrixCSC{Float64,Int64}}(undef, 2) B[1]=sprandn(100,100,0.1) B[2]=sprandn(100,100,0.1) #make sure all nonzero diagonals in B are also in A, otherwise CDS doesnt work @@ -14,7 +14,7 @@ maxit=100; p=2 log_PARSDMM = log_type_PARSDMM(zeros(maxit,p-1),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),0.00,0.00,0.00,0.00,0.00,0.00,0.00); - rho=Vector{Float64}(2) + rho=Vector{Float64}(undef, 2) rho[1]=1.0 rho[2]=1.0 log_PARSDMM.rho[1,1]=2.0 @@ -22,7 +22,7 @@ #add A = A+ 1.0*B[1] + 2.0*B[2] i=1 - ind_updated = find(rho .!= log_PARSDMM.rho[i,:]) #::Vector{Integer}# locate changed rho index + ind_updated = findall(rho .!= log_PARSDMM.rho[i,:]) #::Vector{Integer}# locate changed rho index ind_updated = convert(Array{Int64,1},ind_updated) #use explicit solution: if isempty(ind_updated) == false @@ -33,7 +33,11 @@ #use Q_update: TI=Int64 TF=Float64 - TD_Prop=set_properties(zeros(99),zeros(99),zeros(99),Vector{Tuple{TI,TI}}(99),Vector{Tuple{String,String}}(99),zeros(99),Vector{Vector{TI}}(99)) + TD_Prop=set_properties(zeros(Bool, 99), zeros(Bool, 99), zeros(Bool, 99), + fill!(Vector{Tuple{TI,TI}}(undef, 99), (0, 0)), + fill!(Vector{Tuple{String,String, String, String}}(undef, 99), ("", "", "", "")), + zeros(Bool, 99), + Vector{Vector{TI}}(undef,99)) A2=Q_update!(A2,B2,TD_Prop,rho,ind_updated,log_PARSDMM,i,[]) x=randn(size(A,2)) @@ -43,7 +47,7 @@ (R_A,offset_A)=mat2CDS(A3) (R_B1,offset_B1)=mat2CDS(B[1]) (R_B2,offset_B2)=mat2CDS(B[2]) - R_B=Vector{Array{Float64,2}}(2) + R_B=Vector{Array{Float64,2}}(undef, 2) R_B[1]=R_B1 R_B[2]=R_B2 TD_Prop.AtA_offsets[1]=offset_B1 diff --git a/test/test_TD_OPs.jl b/test/test_TD_OPs.jl index e5c17e3..7b75622 100644 --- a/test/test_TD_OPs.jl +++ b/test/test_TD_OPs.jl @@ -11,8 +11,8 @@ D2z = get_discrete_Grad(n1,n2,h1,h2,"D_z") x=zeros(n1,n2) #test on a 'cross' image - x[:,3]=1.0 - x[4,:]=1.0 + x[:,3].=1.0 + x[4,:].=1.0 a1 = D2x*vec(x); a1=reshape(a1,n1-1,n2) a2 = D2z*vec(x); a2=reshape(a2,n1,n2-1) @@ -21,17 +21,17 @@ a3b = reshape(a3b,n1-1,n2) #this test depends on the values of h1 and h2, as well as the type of derivative - @test a1==diff(x,1)./h1 - @test a2==diff(x,2)./h2 + @test a1==diff(x, dims=1)./h1 + @test a2==diff(x, dims=2)./h2 #some more general tests: - @test countnz(a1[:,3])==0 + @test count(!iszero, a1[:,3])==0 for i in [1 2 4 5 6] @test a1[:,1]==a1[:,i] end #some more general tests: - @test countnz(a2[4,:])==0 + @test count(!iszero, a2[4,:])==0 for i in [1 2 3 5 6 7 8 9] @test a2[1,:]==a2[i,:] end @@ -52,32 +52,32 @@ D3z = get_discrete_Grad(n1,n2,n3,h1,h2,h3,"D_z") x=zeros(n1,n2,n3) #test on a 'cross' image - x[2,:,:]=1.0 - x[:,4,:]=1.0 - x[:,:,3]=1.0 + x[2,:,:].=1.0 + x[:,4,:].=1.0 + x[:,:,3].=1.0 a1 = D3x*vec(x); a1=reshape(a1,n1-1,n2,n3) a2 = D3y*vec(x); a2=reshape(a2,n1,n2-1,n3) a3 = D3z*vec(x); a3=reshape(a3,n1,n2,n3-1) for i=1:n2 - @test a1[:,i,:]==diff(x[:,i,:],1)./h1 + @test a1[:,i,:]==diff(x[:,i,:], dims=1)./h1 end for i=1:n3 - @test a1[:,:,i]==diff(x[:,:,i],1)./h1 + @test a1[:,:,i]==diff(x[:,:,i], dims=1)./h1 end for i=1:n1 - @test a2[i,:,:]==diff(x[i,:,:],1)./h2 + @test a2[i,:,:]==diff(x[i,:,:], dims=1)./h2 end for i=1:n3 - @test a2[:,:,i]==diff(x[:,:,i],2)./h2 + @test a2[:,:,i]==diff(x[:,:,i], dims=2)./h2 end for i=1:n1 - @test a3[i,:,:]==diff(x[i,:,:],2)./h3 + @test a3[i,:,:]==diff(x[i,:,:], dims=2)./h3 end for i=1:n2 - @test a3[:,i,:]==diff(x[:,i,:],2)./h3 + @test a3[:,i,:]==diff(x[:,i,:], dims=2)./h3 end end diff --git a/test/test_adapt_rho_gamma_parallel.jl b/test/test_adapt_rho_gamma_parallel.jl index 491869a..5332ba9 100644 --- a/test/test_adapt_rho_gamma_parallel.jl +++ b/test/test_adapt_rho_gamma_parallel.jl @@ -8,70 +8,70 @@ p=2 i=10 -y=Vector{Vector{Float64}}(p) +y=Vector{Vector{Float64}}(undef, p) y[1]=randn(51) y[2]=randn(100) -y_0=Vector{Vector{Float64}}(p) +y_0=Vector{Vector{Float64}}(undef, p) y_0[1]=randn(51) y_0[2]=randn(100) -y_old=Vector{Vector{Float64}}(p) +y_old=Vector{Vector{Float64}}(undef, p) y_old[1]=randn(51) y_old[2]=randn(100) -l_old=Vector{Vector{Float64}}(p) +l_old=Vector{Vector{Float64}}(undef, p) l_old[1]=randn(51) l_old[2]=randn(100) -l=Vector{Vector{Float64}}(p) +l=Vector{Vector{Float64}}(undef, p) l[1]=randn(51) l[2]=randn(100) -d_l=Vector{Vector{Float64}}(p) +d_l=Vector{Vector{Float64}}(undef, p) d_l[1]=randn(51) d_l[2]=randn(100) -l_0=Vector{Vector{Float64}}(p) +l_0=Vector{Vector{Float64}}(undef, p) l_0[1]=randn(51) l_0[2]=randn(100) -l_hat=Vector{Vector{Float64}}(p) +l_hat=Vector{Vector{Float64}}(undef, p) l_hat[1]=randn(51) l_hat[2]=randn(100) -l_hat_0=Vector{Vector{Float64}}(p) +l_hat_0=Vector{Vector{Float64}}(undef, p) l_hat_0[1]=randn(51) l_hat_0[2]=randn(100) -d_l_hat=Vector{Vector{Float64}}(p) +d_l_hat=Vector{Vector{Float64}}(undef, p) d_l_hat[1]=randn(51) d_l_hat[2]=randn(100) -d_H_hat=Vector{Vector{Float64}}(p) +d_H_hat=Vector{Vector{Float64}}(undef, p) d_H_hat[1]=randn(51) d_H_hat[2]=randn(100) -d_G_hat=Vector{Vector{Float64}}(p) +d_G_hat=Vector{Vector{Float64}}(undef, p) d_G_hat[1]=randn(51) d_G_hat[2]=randn(100) rho=[1.234;10.23432] -gamma=Vector{Float64}(p) +gamma=Vector{Float64}(undef, p) gamma[1]=1.0 gamma[2]=1.345 -prox=Vector{Any}(p) +prox=Vector{Any}(undef, p) prox[1] = x -> 1.0.*x m=randn(100) prox[2] = x -> prox_l2s!(x,rho[2],m) -TD_OP=Vector{SparseMatrixCSC{Float64,Int64}}(p) -TD_OP[1] = speye(51,100)*2.0 -TD_OP[2] = speye(100) +TD_OP=Vector{SparseMatrixCSC{Float64,Int64}}(undef, p) +TD_OP[1] = sparse(I, 51, 100)*2.0 +TD_OP[2] = sparse(I, 100, 100) maxit=39 log_PSDMM = log_type_PARSDMM(zeros(maxit,p-1),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),0.00,0.00,0.00,0.00,0.00,0.00,0.00); -P_sub = Vector{Any}(1) +P_sub = Vector{Any}(undef, 1) P_sub[1] = prox[1] counter=12 -x_hat=Vector{Vector{Float64}}(p) +x_hat=Vector{Vector{Float64}}(undef, p) x_hat[1]=randn(51) x_hat[2]=randn(100) -r_pri=Vector{Vector{Float64}}(p) +r_pri=Vector{Vector{Float64}}(undef, p) r_pri[1]=randn(51) r_pri[2]=randn(100) -s=Vector{Vector{Float64}}(p) +s=Vector{Vector{Float64}}(undef, p) s[1]=randn(51) s[2]=randn(100) -s_0=Vector{Vector{Float64}}(p) +s_0=Vector{Vector{Float64}}(undef, p) s_0[1]=randn(51) s_0[2]=randn(100) @@ -125,10 +125,11 @@ for ii = 1:p end [@spawnat pid l_hat_d[:L] = l_old_d[:L] .+ rho_d[:L].* ( -s_d[:L] .+ y_old_d[:L] ) for pid in l_hat_d.pids] -copy!(l_hat_0_d,l_hat_d) -copy!(y_0_d,y_d) -copy!(s_0_d,s_d) -copy!(l_0_d,l_d) + +[@spawnat pid copy!(l_hat_0_d[:L],l_hat_d[:L]) for pid in l_hat_d.pids] +[@spawnat pid copy!(y_0_d[:L],y_d[:L]) for pid in l_hat_d.pids] +[@spawnat pid copy!(s_0_d[:L],s_d[:L]) for pid in l_hat_d.pids] +[@spawnat pid copy!(l_0_d[:L],l_d[:L]) for pid in l_hat_d.pids] @test isapprox(l_hat_0_d,l_hat_0,rtol=10*eps()) @test isapprox(l_hat,l_hat_d,rtol=10*eps()) diff --git a/test/test_argmin_x.jl b/test/test_argmin_x.jl index d9de206..4b78b0f 100644 --- a/test/test_argmin_x.jl +++ b/test/test_argmin_x.jl @@ -1,10 +1,10 @@ @testset "argmin_x" begin #test argmin_x.jl for CSC sparse matrix format -A=sprandn(100,100,0.01)+speye(100); +A=sprandn(100,100,0.01)+sparse(I, 100, 100); A=A'*A; -while rank(full(A))<100 - A=A+speye(100) +while rank(Array(A))<100 + A=A+sparse(I, 100, 100) end xt=randn(100) b=A*xt; @@ -36,10 +36,10 @@ x_min_solver="CG_normal" @test norm(A*x-b)/norm(b) <= 20*eps() #test argmin_x.jl for CDS sparse matrix format -A=sprandn(100,100,0.01)+speye(100); +A=sprandn(100,100,0.01)+sparse(I, 100, 100); A=A'*A; -while rank(full(A))<100 - A=A+speye(100) +while rank(Array(A))<100 + A=A+sparse(I, 100, 100) end xt=randn(100) b=A*xt; diff --git a/test/test_cg.jl b/test/test_cg.jl index 927d0aa..7a759ce 100644 --- a/test/test_cg.jl +++ b/test/test_cg.jl @@ -16,7 +16,7 @@ b=A*xt @test norm(A*x-b)/norm(b) <= 1.01e-14 #test with very good initial guess -x=deepcopy(xt)+eps(); +x=deepcopy(xt) .+ eps(); (x,flag,relres,iter2) = cg(A,b,tol=1e-5,maxIter=1000,x=x,out=0); @test norm(A*x-b)/norm(b) <= 1e-5 @test iter2 (1:1:100)) (x1,flag,relres1,iter1) = cg(A,b,tol=1e-12,maxIter=1000,out=0); #unpreconditioned cg Prec(input) = input./diag(A); #Jacobi preconditioner (x2,flag,relres2,iter2) = cg(A,b,tol=1e-12,maxIter=1000,M=Prec,out=0); diff --git a/test/test_projectors.jl b/test/test_projectors.jl index 6692274..c3940d3 100644 --- a/test/test_projectors.jl +++ b/test/test_projectors.jl @@ -252,7 +252,7 @@ M=randn(23*50,5) project_subspace!(x,M,false,("slice","z")) x=reshape(x,size(y)) - [@test isapprox(vec(x[:,:,i]),M*((M'*M)\(M'*vec(y[:,:,i]))),rtol=eps()*10) for i=1:11] + [@test isapprox(vec(x[:,:,i]),M*((M'*M)\(M'*vec(y[:,:,i]))),rtol=eps()*100) for i=1:11] #on tensor input: project every y slice onto the subspace x=randn(23,11,50) @@ -260,7 +260,7 @@ M=randn(23*50,5) x=project_subspace!(x,M,false,("slice","y")) x=reshape(x,size(y)) - [@test isapprox(vec(x[:,i,:]),M*((M'*M)\(M'*vec(y[:,i,:]))),rtol=eps()*10) for i=1:11] + [@test isapprox(vec(x[:,i,:]),M*((M'*M)\(M'*vec(y[:,i,:]))),rtol=eps()*100) for i=1:11] #on tensor input: project every x slice onto the subspace x=randn(11,23,50) @@ -268,7 +268,7 @@ M=randn(23*50,5) x=project_subspace!(x,M,false,("slice","x")) x=reshape(x,size(y)) - [@test isapprox(vec(x[i,:,:]),M*((M'*M)\(M'*vec(y[i,:,:]))),rtol=eps()*10) for i=1:11] + [@test isapprox(vec(x[i,:,:]),M*((M'*M)\(M'*vec(y[i,:,:]))),rtol=eps()*100) for i=1:11] #test projection onto relaxed histogram #first test exact histogram projection diff --git a/test/test_prox_l2s!.jl b/test/test_prox_l2s!.jl index 7ae8476..7a86f3d 100644 --- a/test/test_prox_l2s!.jl +++ b/test/test_prox_l2s!.jl @@ -12,8 +12,8 @@ y=deepcopy(x) prox_l2s!(x,rho,m) @test isapprox(x,y,rtol=1e-14) -x=Vector{Float64}(1); x[1]=2.0 -m=Vector{Float64}(1); m[1]=1.0 +x=Vector{Float64}(undef, 1); x[1]=2.0 +m=Vector{Float64}(undef, 1); m[1]=1.0 rho=3.0 prox_l2s!(x,rho,m) @test x[1]==(7/4) diff --git a/test/test_update_y_l.jl b/test/test_update_y_l.jl index 1c10bdf..53f9bd5 100644 --- a/test/test_update_y_l.jl +++ b/test/test_update_y_l.jl @@ -10,45 +10,45 @@ p=2 i=10 Blas_active = false -y=Vector{Vector{Float64}}(p) +y=Vector{Vector{Float64}}(undef, p) y[1]=randn(51) y[2]=randn(100) -y_old=Vector{Vector{Float64}}(p) +y_old=Vector{Vector{Float64}}(undef, p) y_old[1]=randn(51) y_old[2]=randn(100) -l_old=Vector{Vector{Float64}}(p) +l_old=Vector{Vector{Float64}}(undef, p) l_old[1]=randn(51) l_old[2]=randn(100) -l=Vector{Vector{Float64}}(p) +l=Vector{Vector{Float64}}(undef, p) l[1]=randn(51) l[2]=randn(100) rho=[1.234;10.23432] -gamma=Vector{Float64}(p) +gamma=Vector{Float64}(undef, p) gamma[1]=1.0 gamma[2]=1.345 -prox=Vector{Any}(p) +prox=Vector{Any}(undef, p) prox[1] = x -> 1.0.*x m=randn(100) prox[2] = x -> prox_l2s!(x,rho[2],m) -TD_OP = Vector{Union{SparseMatrixCSC{TF,TI},JOLI.joLinearFunction{TF,TF}}}(p) -TD_OP[1] = speye(51,100)*2.0 -TD_OP[2] = speye(100) +TD_OP = Vector{Union{SparseMatrixCSC{TF,TI},JOLI.joLinearFunction{TF,TF}}}(undef, p) +TD_OP[1] = sparse(1.0*I, 51,100)*2.0 +TD_OP[2] = sparse(1.0*I, 100, 100) maxit=39 log_PSDMM = log_type_PARSDMM(zeros(maxit,p-1),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit,p), zeros(maxit,p),zeros(maxit),zeros(maxit),0.00,0.00,0.00,0.00,0.00,0.00,0.00); -P_sub = Vector{Any}(1) +P_sub = Vector{Any}(undef, 1) P_sub[1] = prox[1] counter=12 -x_hat=Vector{Vector{Float64}}(p) +x_hat=Vector{Vector{Float64}}(undef, p) x_hat[1]=randn(51) x_hat[2]=randn(100) -r_pri=Vector{Vector{Float64}}(p) +r_pri=Vector{Vector{Float64}}(undef, p) r_pri[1]=randn(51) r_pri[2]=randn(100) -s=Vector{Vector{Float64}}(p) +s=Vector{Vector{Float64}}(undef, p) s[1]=randn(51) s[2]=randn(100) @@ -91,44 +91,44 @@ p=2 i=10 Blas_active = true -y=Vector{Vector{Float64}}(p) +y=Vector{Vector{Float64}}(undef, p) y[1]=randn(51) y[2]=randn(100) -y_old=Vector{Vector{Float64}}(p) +y_old=Vector{Vector{Float64}}(undef, p) y_old[1]=randn(51) y_old[2]=randn(100) -l_old=Vector{Vector{Float64}}(p) +l_old=Vector{Vector{Float64}}(undef, p) l_old[1]=randn(51) l_old[2]=randn(100) -l=Vector{Vector{Float64}}(p) +l=Vector{Vector{Float64}}(undef, p) l[1]=randn(51) l[2]=randn(100) rho=[1.234;10.23432] -gamma=Vector{Float64}(p) +gamma=Vector{Float64}(undef, p) gamma[1]=1.0 gamma[2]=1.345 -prox=Vector{Any}(p) +prox=Vector{Any}(undef, p) prox[1] = x -> 1.0.*x m=randn(100) prox[2] = x -> prox_l2s!(x,rho[2],m) -TD_OP = Vector{Union{SparseMatrixCSC{TF,TI},JOLI.joLinearFunction{TF,TF}}}(p) +TD_OP = Vector{Union{SparseMatrixCSC{TF,TI},JOLI.joLinearFunction{TF,TF}}}(undef, p) -TD_OP[1] = speye(51,100)*2.0 -TD_OP[2] = speye(100) +TD_OP[1] = sparse(1.0*I, 51,100)*2.0 +TD_OP[2] = sparse(1.0*I, 100, 100) maxit=39 log_PSDMM = log_type_PARSDMM(zeros(maxit,p-1),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),0.00,0.00,0.00,0.00,0.00,0.00,0.00); -P_sub = Vector{Any}(1) +P_sub = Vector{Any}(undef, 1) P_sub[1] = prox[1] counter=12 -x_hat=Vector{Vector{Float64}}(p) +x_hat=Vector{Vector{Float64}}(undef, p) x_hat[1]=randn(51) x_hat[2]=randn(100) -r_pri=Vector{Vector{Float64}}(p) +r_pri=Vector{Vector{Float64}}(undef, p) r_pri[1]=randn(51) r_pri[2]=randn(100) -s=Vector{Vector{Float64}}(p) +s=Vector{Vector{Float64}}(undef, p) s[1]=randn(51) s[2]=randn(100) diff --git a/test/test_update_y_l_parallel.jl b/test/test_update_y_l_parallel.jl index beb71ae..46de4f1 100644 --- a/test/test_update_y_l_parallel.jl +++ b/test/test_update_y_l_parallel.jl @@ -10,43 +10,43 @@ p=2 i=10 Blas_active = true -y=Vector{Vector{Float64}}(p) +y=Vector{Vector{Float64}}(undef, p) y[1]=randn(51) y[2]=randn(100) -y_old=Vector{Vector{Float64}}(p) +y_old=Vector{Vector{Float64}}(undef, p) y_old[1]=randn(51) y_old[2]=randn(100) -l_old=Vector{Vector{Float64}}(p) +l_old=Vector{Vector{Float64}}(undef, p) l_old[1]=randn(51) l_old[2]=randn(100) -l=Vector{Vector{Float64}}(p) +l=Vector{Vector{Float64}}(undef, p) l[1]=randn(51) l[2]=randn(100) rho=[1.234;10.23432] -gamma=Vector{Float64}(p) +gamma=Vector{Float64}(undef, p) gamma[1]=1.0 gamma[2]=1.345 -prox=Vector{Any}(p) +prox=Vector{Any}(undef, p) prox[1] = x -> 1.0.*x m=randn(100) prox[2] = x -> prox_l2s!(x,rho[2],m) -TD_OP = Vector{Union{SparseMatrixCSC{TF,TI},JOLI.joLinearFunction{TF,TF}}}(p) -TD_OP[1] = speye(51,100)*2.0 -TD_OP[2] = speye(100) +TD_OP = Vector{Union{SparseMatrixCSC{TF,TI},JOLI.joLinearFunction{TF,TF}}}(undef, p) +TD_OP[1] = sparse(1.0*I, 51,100)*2.0 +TD_OP[2] = sparse(1.0*I, 100, 100) maxit=39 log_PSDMM = log_type_PARSDMM(zeros(maxit,p-1),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),0.00,0.00,0.00,0.00,0.00,0.00,0.00); -P_sub = Vector{Any}(1) +P_sub = Vector{Any}(undef, 1) P_sub[1] = prox[1] counter=12 -x_hat=Vector{Vector{Float64}}(p) +x_hat=Vector{Vector{Float64}}(undef, p) x_hat[1]=randn(51) x_hat[2]=randn(100) -r_pri=Vector{Vector{Float64}}(p) +r_pri=Vector{Vector{Float64}}(undef, p) r_pri[1]=randn(51) r_pri[2]=randn(100) -s=Vector{Vector{Float64}}(p) +s=Vector{Vector{Float64}}(undef, p) s[1]=randn(51) s[2]=randn(100) @@ -73,7 +73,7 @@ set_feas_d=distribute(set_feas) ,P_sub_d[:L],x_hat_d[:L],r_pri_d[:L],s_d[:L],set_feas_d[:L]) for pid in y_d.pids] rhs_next_iter=zeros(length(x)) - rhs_next_iter=@parallel (+) for i=1:2 + rhs_next_iter=@distributed (+) for i=1:2 #rhs_d[i] TD_OP_d[i]'*(l_d[i].+y_d[i]) end