-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathADNLPProblems.jl
More file actions
60 lines (49 loc) · 1.62 KB
/
ADNLPProblems.jl
File metadata and controls
60 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module ADNLPProblems
using Requires
const default_nvar = 100
const data_path = joinpath(@__DIR__, "..", "..", "data")
reshape_array(a, dims) = invoke(Base._reshape, Tuple{AbstractArray, typeof(dims)}, a, dims)
const _data_loaded = Dict{Symbol, Ref{Bool}}()
const _data_locks = Dict{Symbol, ReentrantLock}()
function _ensure_data!(key::Symbol, relpath::AbstractString)
flag = get!(_data_loaded, key, Ref(false))
flag[] && return
lck = get!(_data_locks, key, ReentrantLock())
lock(lck) do
flag[] && return
Base.include(@__MODULE__, joinpath(@__DIR__, "..", "..", "data", relpath))
flag[] = true
end
return
end
@init begin
@require ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a" begin
using JLD2, LinearAlgebra, SparseArrays, SpecialFunctions
"""
@adjust_nvar_warn(problem_name, n_orig, n)
Issue a warning if the number of variables was adjusted, showing both original and adjusted values.
This macro provides consistent warning messages across all problems with dimension adjustments.
# Example
```julia
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("woods", n_orig, n)
```
"""
macro adjust_nvar_warn(problem_name, n_orig, n)
return quote
($(esc(n)) == $(esc(n_orig))) ||
@warn(string($(esc(problem_name)), ": number of variables adjusted from ",
$(esc(n_orig)), " to ", $(esc(n))))
end
end
path = dirname(@__FILE__)
files = filter(x -> x[(end - 2):end] == ".jl", readdir(path))
for file in files
if file ≠ "ADNLPProblems.jl"
include(file)
end
end
end
end
end