# Efficiently extracting rows from VectorAffineFunction structs in MOI

**URL:** https://discourse.julialang.org/t/efficiently-extracting-rows-from-vectoraffinefunction-structs-in-moi/48408
**Category:** Optimization (Mathematical)
**Tags:** question, jump, optimization
**Created:** [October 15, 2020, 4:40am UTC](https://discourse.julialang.org/t/efficiently-extracting-rows-from-vectoraffinefunction-structs-in-moi/48408 "2020-10-15T04:40:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![asa](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@asa](https://discourse.julialang.org/u/asa)
#### Post date: [October 15, 2020, 4:40am UTC](https://discourse.julialang.org/t/efficiently-extracting-rows-from-vectoraffinefunction-structs-in-moi/48408/1 "2020-10-15T04:40:20Z")

</div>

The `MOI.VectorAffineFunction ` type is used to define linear vector valued functions in MathOptInterface. I am trying to extract a row of such an object itself with type `VectorAffineFunction`, for example with `f = MOI.VectorAffineFunction( [MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1, y)), MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(1, x1)), MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(10, x2)),], [0.0, 0.0], ) ` Is there a good way of doing this? I am trying to avoid messing around too much with loops over the output index for each term.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [October 15, 2020, 6:38am UTC](https://discourse.julialang.org/t/efficiently-extracting-rows-from-vectoraffinefunction-structs-in-moi/48408/2 "2020-10-15T06:38:22Z")

</div>

Loops over the output index are the way to go.

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [October 15, 2020, 1:17pm UTC](https://discourse.julialang.org/t/efficiently-extracting-rows-from-vectoraffinefunction-structs-in-moi/48408/4 "2020-10-15T13:17:18Z")

</div>

If `f` is a `MOI.VectorAffineFunction` and `i` is an integer between `1` and `MOI.output_dimension(f)` then `MOI.Utilities.eachscalar(f)[i]` gives a `MOI.ScalarAffineFunction` and `MOI.Utilities.eachscalar(f)[[i]]` gives a `MOI.VectorAffineFunction`

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [October 15, 2020, 8:59pm UTC](https://discourse.julialang.org/t/efficiently-extracting-rows-from-vectoraffinefunction-structs-in-moi/48408/5 "2020-10-15T20:59:33Z")

</div>

Ah, I keep forgetting about `eachscalar`.
