# Error optimizing using autodifferentation

**URL:** https://discourse.julialang.org/t/error-optimizing-using-autodifferentation/35478
**Category:** General Usage
**Tags:** package, differentiation, optimization
**Created:** [March 3, 2020, 6:30pm UTC](https://discourse.julialang.org/t/error-optimizing-using-autodifferentation/35478 "2020-03-03T18:30:19Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![rpm](https://avatars.discourse-cdn.com/v4/letter/r/c57346/32.png) [@rpm](https://discourse.julialang.org/u/rpm)
#### Post date: [April 23, 2020, 4:42pm UTC](https://discourse.julialang.org/t/error-optimizing-using-autodifferentation/35478/8 "2020-04-23T16:42:05Z")

</div>

I wanted to share a few things that helped me resolve this issue!

The two key principles I found were that:  
1/ I needed to make many parts of the code into arrays instead of vectors (so size of the object would be (X,) as opposed to (X,1))  
2/ Sometimes updating vectors using vec[i] caused problems; instead, adding had no issues. I wonder if this reflects that direct updates are not differentiable in any sense that I understand.

Unfortunately, I don’t have a 100% clear understanding of why these changes matter and want to note that these adjustments did not need to be made everywhere in the code. I do not have a good understanding of which scenarios require these changes and which do not

---

_[View the full topic](https://discourse.julialang.org/t/error-optimizing-using-autodifferentation/35478)._
