Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ext/ExaModelsLinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ const ExaNode = Union{
const VecExaNode = AbstractVector{<:ExaNode}
const MatExaNode = AbstractMatrix{<:ExaNode}

# --- ExaVector / ExaMatrix convenience constructors ---

# Variable constructors
ExaModels.ExaVector(c::ExaModels.ExaCore, n::Int; kwargs...) =
ExaModels.ExaVector(ExaModels.variable(c, n; kwargs...))
ExaModels.ExaMatrix(c::ExaModels.ExaCore, m::Int, n::Int; kwargs...) =
ExaModels.ExaMatrix(ExaModels.variable(c, m, n; kwargs...))

# Parameter constructors
ExaModels.ExaVector(c::ExaModels.ExaCore, start::AbstractVector) =
ExaModels.ExaVector(ExaModels.parameter(c, start))
ExaModels.ExaMatrix(c::ExaModels.ExaCore, start::AbstractMatrix) =
ExaModels.ExaMatrix(ExaModels.parameter(c, start))

# Type promotion: [x, 0] should give Vector{AbstractNode} with Null(0), not Vector{Any}
Base.promote_rule(::Type{<:ExaModels.AbstractNode}, ::Type{<:Real}) = ExaModels.AbstractNode
Base.convert(::Type{ExaModels.AbstractNode}, x::Real) =
Expand Down
2 changes: 2 additions & 0 deletions src/ExaModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ include("utils.jl")

export ExaModel,
ExaCore,
ExaVector,
ExaMatrix,
ExaModelsBackend,
Subexpr,
ReducedSubexpr,
Expand Down
14 changes: 14 additions & 0 deletions src/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ Parameter
θ ∈ R^{$(join(size(v.size)," × "))}
""",
)
const Indexable = Union{Variable, Parameter, Subexpr, ParameterSubexpr}

struct ExaVector{V<:Indexable} <: AbstractVector{AbstractNode}
var::V
end
Base.size(v::ExaVector) = (v.var.length,)
Base.getindex(v::ExaVector, i::Int) = v.var[i]

struct ExaMatrix{V<:Indexable} <: AbstractMatrix{AbstractNode}
var::V
end
Base.size(M::ExaMatrix) = M.var.size
Base.getindex(M::ExaMatrix, i::Int, j::Int) = M.var[i, j]

struct Objective{R,F,I} <: AbstractObjective
inner::R
f::F
Expand Down
Loading