Skip to content

Commit b6e5634

Browse files
committed
rename
1 parent a97089a commit b6e5634

File tree

12 files changed

+315
-22
lines changed

12 files changed

+315
-22
lines changed

Project.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
name = "BatchPOIKernels"
1+
name = "BatchConeKernels"
22
uuid = "afeb8112-68be-11f0-3c37-57b6e69465f2"
33
authors = ["Klamkin", "Michael <[email protected]> and contributors"]
44
version = "1.0.0-DEV"
55

66
[deps]
77
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
8+
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
89
ParametricOptInterface = "0ce4ce61-57bf-432b-a095-efac525d185e"
910

1011
[weakdeps]
1112
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
1213

1314
[extensions]
14-
BPKChainRulesCore = "ChainRulesCore"
15+
BCKChainRulesCore = "ChainRulesCore"
16+
17+
[compat]
18+
MathOptInterface = "1.42.0"
1519

1620
[extras]
1721
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1822

1923
[targets]
20-
test = ["Test"]
24+
test = ["Test"]

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# BatchPOIKernels.jl
1+
# BatchConeKernels.jl
22

3-
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://LearningToOptimize.github.io/BatchPOIKernels.jl/dev/)
4-
[![Build Status](https://github.com/LearningToOptimize/BatchPOIKernels.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/LearningToOptimize/BatchPOIKernels.jl/actions/workflows/CI.yml?query=branch%3Amain)
5-
[![Coverage](https://codecov.io/gh/LearningToOptimize/BatchPOIKernels.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/LearningToOptimize/BatchPOIKernels.jl)
3+
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://LearningToOptimize.github.io/BatchConeKernels.jl/dev/)
4+
[![Build Status](https://github.com/LearningToOptimize/BatchConeKernels.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/LearningToOptimize/BatchConeKernels.jl/actions/workflows/CI.yml?query=branch%3Amain)
5+
[![Coverage](https://codecov.io/gh/LearningToOptimize/BatchConeKernels.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/LearningToOptimize/BatchConeKernels.jl)

docs/make.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using Documenter
2-
using BatchPOIKernels
2+
using BatchConeKernels
33

44

55
include("definitions.jl")
66

77
makedocs(
8-
modules=[BatchPOIKernels],
9-
sitename = "BatchPOIKernels.jl",
8+
modules=[BatchConeKernels],
9+
sitename = "BatchConeKernels.jl",
1010
format = Documenter.HTML(;
1111
assets = ["assets/wider.css", "assets/redlinks.css"],
1212
mathengine = Documenter.MathJax3(Dict(
@@ -26,6 +26,6 @@ makedocs(
2626
# See "Hosting Documentation" and deploydocs() in the Documenter manual
2727
# for more information.
2828
deploydocs(
29-
repo="github.com/LearningToOptimize/BatchPOIKernels.jl.git",
29+
repo="github.com/LearningToOptimize/BatchConeKernels.jl.git",
3030
push_preview=true,
3131
)

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# BatchPOIKernels.jl
1+
# BatchConeKernels.jl
22

33
```@autodocs
4-
Modules = [BatchPOIKernels]
4+
Modules = [BatchConeKernels]
55
```

ext/BCKChainRulesCore.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module BCKChainRulesCore
2+
3+
using BatchConeKernels
4+
using ChainRulesCore
5+
6+
7+
end # module BCKChainRulesCore

ext/BPKChainRulesCore.jl

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/BatchPOIKernels.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
module BatchPOIKernels
1+
module BatchConeKernels
2+
3+
using MathOptInterface
4+
const MOI = MathOptInterface
25

36
using ParametricOptInterface
47
const POI = ParametricOptInterface
8+
const ParametricFunction = POI.ParametricFunction
59

610
using KernelAbstractions
711
const KA = KernelAbstractions
812

13+
include("paf.jl")
14+
include("pqf.jl")
15+
include("pvaf.jl")
16+
include("pvqf.jl")
17+
918
end

src/paf.jl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
mutable struct ParametricAffineFunction{T} <: ParametricFunction{T}
2+
# constant * parameter
3+
p::Vector{MOI.ScalarAffineTerm{T}}
4+
# constant * variable
5+
v::Vector{MOI.ScalarAffineTerm{T}}
6+
# constant
7+
c::T
8+
# to avoid unnecessary lookups in updates
9+
set_constant::T
10+
# cache to avoid slow getters
11+
current_constant::T
12+
end
13+
14+
15+
function evaluate(f::ParametricAffineFunction{T}, x::Vector{T}, θ::Vector{T}) where {T}
16+
ret = zero(T)
17+
# constant * parameter
18+
i=1
19+
for (term, θᵢ) in zip(f.p, θ)
20+
@assert term.variable.value == i; i+=1
21+
ret += term.coefficient * θᵢ
22+
end
23+
# constant * variable
24+
j=1
25+
for (term, xᵢ) in zip(f.v, x)
26+
@assert term.variable.value == j; j+=1
27+
ret += term.coefficient * xᵢ
28+
end
29+
# constant
30+
ret += f.c
31+
32+
return ret
33+
end
34+
35+
36+
struct PAFMatrix{VT,T}
37+
p::VT
38+
v::VT
39+
c::T
40+
end
41+
42+
function PAFMatrix(f::ParametricAffineFunction{T}, x::Vector{MOI.VariableIndex}, θ::Vector{MOI.VariableIndex}) where {T}
43+
nx = length(x)
44+
= length(θ)
45+
p = zeros(T, nθ)
46+
v = zeros(T, nx)
47+
c = zero(T)
48+
for term in f.p
49+
p[term.variable] += term.coefficient
50+
end
51+
for term in f.v
52+
v[term.variable] += term.coefficient
53+
end
54+
c = f.c
55+
return PAFMatrix(p, v, c)
56+
end
57+
58+
function evaluate(f::PAFMatrix{T}, x::Vector{T}, θ::Vector{T}) where {T}
59+
ret = zero(T)
60+
for (p, θ) in zip(f.p, θ)
61+
ret += p * θ
62+
end
63+
for (v, x) in zip(f.v, x)
64+
ret += v * x
65+
end
66+
ret += f.c
67+
return ret
68+
end

src/pqf.jl

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
mutable struct ParametricQuadraticFunction{T} <: ParametricFunction{T}
2+
# helper to efficiently update affine terms
3+
affine_data::Dict{MOI.VariableIndex,T}
4+
affine_data_np::Dict{MOI.VariableIndex,T}
5+
# constant * parameter * variable (in this order)
6+
pv::Vector{MOI.ScalarQuadraticTerm{T}}
7+
# constant * parameter * parameter
8+
pp::Vector{MOI.ScalarQuadraticTerm{T}}
9+
# constant * variable * variable
10+
vv::Vector{MOI.ScalarQuadraticTerm{T}}
11+
# constant * parameter
12+
p::Vector{MOI.ScalarAffineTerm{T}}
13+
# constant * variable
14+
v::Vector{MOI.ScalarAffineTerm{T}}
15+
# constant (does not include the set constant)
16+
c::T
17+
# to avoid unnecessary lookups in updates
18+
set_constant::T
19+
# cache data that is inside the solver to avoid slow getters
20+
current_terms_with_p::Dict{MOI.VariableIndex,T}
21+
current_constant::T
22+
end
23+
24+
function evaluate(f::ParametricQuadraticFunction{T}, x::Vector{T}, θ::Vector{T}) where {T}
25+
ret = zero(T)
26+
# constant * parameter * variable
27+
for (pv, θ) in zip(f.pv, θ)
28+
ret += pv.coefficient * θ[pv.variable_1.value] * x[pv.variable_2.value]
29+
end
30+
# constant * parameter * parameter
31+
for (pp, θ) in zip(f.pp, θ)
32+
ret += pp.coefficient * θ[pp.variable_1.value] * θ[pp.variable_2.value]
33+
end
34+
# constant * variable * variable
35+
for (vv, x) in zip(f.vv, x)
36+
ret += vv.coefficient * x[vv.variable_1.value] * x[vv.variable_2.value]
37+
end
38+
# constant * parameter
39+
for (p, θ) in zip(f.p, θ)
40+
ret += p.coefficient * θ[p.variable.value]
41+
end
42+
# constant * variable
43+
for (v, x) in zip(f.v, x)
44+
ret += v.coefficient * x[v.variable.value]
45+
end
46+
# constant
47+
ret += f.c
48+
49+
return ret
50+
end
51+
52+
struct PQFMatrix{MT,VT,T}
53+
pv::MT
54+
pp::MT
55+
vv::MT
56+
p::VT
57+
v::VT
58+
c::T
59+
end
60+
61+
function PQFMatrix(f::ParametricQuadraticFunction{T}, x::Vector{MOI.VariableIndex}, θ::Vector{MOI.VariableIndex}) where {T}
62+
nx = length(x)
63+
= length(θ)
64+
# NOTE: we rearrange to p'* pv * v
65+
pv = zeros(T, nθ, nx)
66+
for term in f.pv
67+
pv[term.variable_1.value, term.variable_2.value] += term.coefficient
68+
end
69+
pp = zeros(T, nθ, nθ)
70+
for term in f.pp
71+
pp[term.variable_1.value, term.variable_2.value] += term.coefficient
72+
end
73+
vv = zeros(T, nx, nx)
74+
for term in f.vv
75+
vv[term.variable_1.value, term.variable_2.value] += term.coefficient
76+
end
77+
p = zeros(T, nθ)
78+
for term in f.p
79+
p[term.variable.value] += term.coefficient
80+
end
81+
v = zeros(T, nx)
82+
for term in f.v
83+
v[term.variable.value] += term.coefficient
84+
end
85+
c = f.c
86+
return PQFMatrix(pv, pp, vv, p, v, c)
87+
end

src/pvaf.jl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
mutable struct ParametricVectorAffineFunction{T}
2+
# constant * parameter
3+
p::Vector{MOI.VectorAffineTerm{T}}
4+
# constant * variable
5+
v::Vector{MOI.VectorAffineTerm{T}}
6+
# constant
7+
c::Vector{T}
8+
# to avoid unnecessary lookups in updates
9+
set_constant::Vector{T}
10+
# cache to avoid slow getters
11+
current_constant::Vector{T}
12+
end
13+
14+
function evaluate(f::ParametricVectorAffineFunction{T}, x::Vector{T}, θ::Vector{T}) where {T}
15+
ret = zero(f.c)
16+
# constant * parameter
17+
for i in eachindex(ret)
18+
for (p, θ) in zip(f.p[i], θ)
19+
ret[i] += p.coef * θ
20+
end
21+
end
22+
# constant * variable
23+
for i in eachindex(ret)
24+
for (v, x) in zip(f.v[i], x)
25+
ret[i] += v.coef * x
26+
end
27+
end
28+
# constant
29+
for i in eachindex(ret)
30+
ret[i] += f.c[i]
31+
end
32+
33+
return ret
34+
end
35+
36+
37+
struct PVAFMatrix{MT,VT}
38+
P::MT
39+
V::MT
40+
c::VT
41+
end
42+
43+
function PVAFMatrix(f::ParametricVectorAffineFunction{T}, x::Vector{MOI.VariableIndex}, θ::Vector{MOI.VariableIndex}) where {T}
44+
nx = length(x)
45+
= length(θ)
46+
nf = length(f.c)
47+
48+
P = zeros(T, nf, nθ)
49+
V = zeros(T, nf, nx)
50+
c = zeros(T, nf)
51+
for i in eachindex(f.c)
52+
for (p, θ) in zip(f.p[i], θ)
53+
P[i, θ] += p.coef
54+
end
55+
end
56+
for i in eachindex(f.c)
57+
for (v, x) in zip(f.v[i], x)
58+
V[i, x] += v.coef
59+
end
60+
end
61+
c = f.c
62+
return PVAFMatrix(P, V, c)
63+
end

0 commit comments

Comments
 (0)