@@ -223,7 +223,7 @@ julia> result = ipopt(m; print_level=0) # solve the problem
223223
224224```
225225"""
226- function ExaModel (c:: C ; kwargs ... ) where {C<: ExaCore }
226+ function ExaModel (c:: C ; prod = nothing ) where {C<: ExaCore }
227227 return ExaModel (
228228 c. obj,
229229 c. con,
@@ -254,15 +254,16 @@ end
254254)
255255
256256function append! (backend, a, b:: Base.Generator , lb)
257-
257+ b = _adapt_gen (b)
258+
258259 la = length (a)
259260 resize! (a, la + lb)
260261 map! (b. f, view (a, (la+ 1 ): (la+ lb)), convert_array (b. iter, backend))
261262 return a
262263end
263264
264265function append! (backend, a, b:: Base.Generator{UnitRange{I}} , lb) where {I}
265-
266+
266267 la = length (a)
267268 resize! (a, la + lb)
268269 map! (b. f, view (a, (la+ 1 ): (la+ lb)), b. iter)
@@ -367,6 +368,7 @@ Objective
367368```
368369"""
369370function objective (c:: C , gen) where {C<: ExaCore }
371+ gen = _adapt_gen (gen)
370372 f = SIMDFunction (gen, c. nobj, c. nnzg, c. nnzh)
371373 pars = gen. iter
372374
@@ -426,8 +428,9 @@ function constraint(
426428 start = zero (T),
427429 lcon = zero (T),
428430 ucon = zero (T),
429- ) where {T,C<: ExaCore{T} }
430-
431+ ) where {T,C<: ExaCore{T} }
432+
433+ gen = _adapt_gen (gen)
431434 f = SIMDFunction (gen, c. ncon, c. nnzj, c. nnzh)
432435 pars = gen. iter
433436
@@ -487,6 +490,8 @@ function _constraint(c, f, pars, start, lcon, ucon)
487490end
488491
489492function constraint! (c:: C , c1, gen:: Base.Generator ) where {C<: ExaCore }
493+
494+ gen = _adapt_gen (gen)
490495 f = SIMDFunction (gen, offset0 (c1, 0 ), c. nnzj, c. nnzh)
491496 pars = gen. iter
492497
@@ -621,7 +626,7 @@ function hess_coord!(
621626 x:: AbstractVector ,
622627 y:: AbstractVector ,
623628 hess:: AbstractVector ;
624- obj_weight = one (eltype (x)),
629+ obj_weight = one (eltype (x)),
625630)
626631
627632 fill! (hess, zero (eltype (hess)))
680685@inbounds @inline offset0 (a:: C , i) where {C<: ConstraintAug } = offset0 (a. f, a. itr, i)
681686@inbounds @inline offset0 (f:: F , itr, i) where {P<: Pair ,F<: SIMDFunction{P} } =
682687 f. o0 + f. f. first (itr[i], nothing )
688+ @inbounds @inline offset0 (f:: F , itr, i) where {T<: Tuple ,P<: Pair{T} ,F<: SIMDFunction{P} } = f. o0 + idxx (coord (itr, i, f. f. first), Base. size (itr))
689+
690+ @inline idx (itr, I) = @inbounds itr[I]
691+ @inline idx (itr:: Base.Iterators.ProductIterator{V} , I) where V = _idx (I- 1 , itr. iterators, Base. size (itr))
692+ @inline function _idx (n, (vec1, vec... ), (si1, si... ))
693+ d, r = divrem (n, si1)
694+ return (vec1[r + 1 ], _idx (d, vec, si)... )
695+ end
696+ @inline _idx (n, (vec,), :: Tuple{Int} ) = @inbounds vec[n + 1 ]
697+
698+ @inline idxx (coord, si) = _idxx (coord, si, 1 ) + 1
699+ @inline _idxx (coord, si, a) = a * (coord[1 ] - 1 ) + _idxx (coord[2 : end ], si[2 : end ], a* si[1 ])
700+ @inline _idxx (:: Tuple{} , :: Tuple{} , a) = 0
701+
702+ @inline coord (itr, i, (f,fs... )) = (f (idx (itr,i), nothing ), coord (itr, i, fs)... )
703+ @inline coord (itr, i, :: Tuple{} ) = ()
683704
684705for (thing, val) in [(:solution , 1 ), (:multipliers_L , 0 ), (:multipliers_U , 2 )]
685706 @eval begin
@@ -755,3 +776,7 @@ function multipliers(result::SolverCore.AbstractExecutionStats, y::Constraint)
755776 len = length (y. itr)
756777 return view (result. multipliers, o+ 1 : o+ len)
757778end
779+
780+
781+ _adapt_gen (gen) = Base. Generator (gen. f, collect (gen. iter))
782+ _adapt_gen (gen:: Base.Generator{P} ) where P <: Union{AbstractArray,AbstractRange} = gen
0 commit comments