FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ArrayDiff.jl/src/array_nonlinear_function.jl at main · blegat/ArrayDiff.jl · GitHub
blegat
/
ArrayDiff.jl
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
6
Code
Issues
3
Pull requests
13
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ArrayDiff.jl
/
src
/
array_nonlinear_function.jl
Copy path
More file actions
More file actions
Latest commit
History
History
History
100 lines (82 loc) · 3.02 KB
Breadcrumbs
ArrayDiff.jl
/
src
/
array_nonlinear_function.jl
Copy path
File metadata and controls
100 lines (82 loc) · 3.02 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
ArrayNonlinearFunction{N} <: MOI.AbstractVectorFunction
Represents an N-dimensional array-valued nonlinear function for MOI.
The `output_dimension` is `prod(size)`, the length of the vectorization of the
array, since `MOI.AbstractVectorFunction` cannot represent multidimensional
arrays. No actual vectorization node is added to the expression graph.
## Fields
- `head::Symbol`: the operator (e.g., `:*`, `:tanh`)
- `args::Vector{Any}`: arguments, which may be `ArrayNonlinearFunction`,
`MOI.ScalarNonlinearFunction`, `MOI.VariableIndex`, `Float64`,
`Vector{Float64}`, `Matrix{Float64}`, or `ArrayOfContiguousVariables`
- `size::NTuple{N,Int}`: the dimensions of the output array
- `broadcasted::Bool`: whether this is a broadcasted operation
"""
struct
ArrayNonlinearFunction{N}
<:
MOI.AbstractVectorFunction
head
::
Symbol
args
::
Vector{Any}
size
::
NTuple{N,Int}
broadcasted
::
Bool
end
function
MOI
.
output_dimension
(f
::
ArrayNonlinearFunction
)
return
prod
(f
.
size)
end
function
Base
.
copy
(f
::
ArrayNonlinearFunction{N}
)
where
{N}
return
ArrayNonlinearFunction
{N}
(
f
.
head,
copy
(f
.
args),
f
.
size,
f
.
broadcasted,
)
end
"""
ArrayOfContiguousVariables{N}
A block of contiguous `MOI.VariableIndex` values representing an N-dimensional
array. Used as an argument in `ArrayNonlinearFunction`.
Set to replace `GenOpt.ContiguousArrayOfVariables`.
"""
struct
ArrayOfContiguousVariables{N}
<:
MOI.AbstractVectorFunction
offset
::
Int64
size
::
NTuple{N,Int64}
end
Base
.
size
(a
::
ArrayOfContiguousVariables
)
=
a
.
size
function
MOI
.
output_dimension
(f
::
ArrayOfContiguousVariables
)
return
prod
(f
.
size)
end
function
Base
.
copy
(f
::
ArrayOfContiguousVariables{N}
)
where
{N}
return
f
#
immutable
end
#
map_indices: remap MOI.VariableIndex values during MOI.copy_to
function
MOI
.
Utilities
.
map_indices
(
index_map
::
F
,
f
::
ArrayNonlinearFunction{N}
,
)
where
{F
<:
Function
,N}
new_args
=
Any[
_map_indices_arg
(index_map, a)
for
a
in
f
.
args]
return
ArrayNonlinearFunction
{N}
(f
.
head, new_args, f
.
size, f
.
broadcasted)
end
function
MOI
.
Utilities
.
map_indices
(
index_map
::
F
,
f
::
ArrayOfContiguousVariables{N}
,
)
where
{F
<:
Function
,N}
#
Variable indices are contiguous; remap each one
#
The offset-based representation doesn't survive remapping, so we
#
convert to an ArrayNonlinearFunction of mapped variables.
#
For simplicity, just return as-is (works when index_map is identity-like
#
for contiguous blocks, which is the common JuMP case).
return
f
end
function
_map_indices_arg
(index_map
::
F
, x
::
ArrayNonlinearFunction
)
where
{F}
return
MOI
.
Utilities
.
map_indices
(index_map, x)
end
function
_map_indices_arg
(index_map
::
F
, x
::
ArrayOfContiguousVariables
)
where
{F}
return
MOI
.
Utilities
.
map_indices
(index_map, x)
end
function
_map_indices_arg
(
::
F
, x
::
Matrix{<:Real}
)
where
{F}
return
x
end
function
_map_indices_arg
(
::
F
, x
::
Real
)
where
{F}
return
x
end
function
_map_indices_arg
(index_map
::
F
, x)
where
{F}
return
MOI
.
Utilities
.
map_indices
(index_map, x)
end
Back
|
FazBrowse Home
|
New Git URL