# General comments on my code for filling a matrix

**URL:** <https://discourse.julialang.org/t/general-comments-on-my-code-for-filling-a-matrix/100913>\
**Category:** General Usage\
**Created:** [June 27, 2023, 8:56pm UTC](https://discourse.julialang.org/t/general-comments-on-my-code-for-filling-a-matrix/100913 "2023-06-27T20:56:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 27, 2023, 9:20pm UTC](https://discourse.julialang.org/t/general-comments-on-my-code-for-filling-a-matrix/100913/2 "2023-06-27T21:20:26Z")

</div>

Your code is [not runnable](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757), it looks like it [uses global variables](https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-untyped-global-variables) (`grids`), it allocates lots of small temporary arrays (e.g. `thr_four_y`, `prob_3_success`, `output_2_success[q,mq,ϵ_1,ϵ_2] * prob_3_success`, and many many others) in the inner loops, it assigns to slices (e.g. `output_4_success[q,mq,ϵ_1,ϵ_2,:,:]`) in the [wrong order for locality](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-column-major), and so on… there are so many problems it is hard to comment on all of them.

You’ll get more detailed advice if you make a _small_ (20 lines or so) _runnable_ example that illustrates a simplified version of what you are trying to do, instead of pasting in a large-ish function like this.

---

_[View the full topic](https://discourse.julialang.org/t/general-comments-on-my-code-for-filling-a-matrix/100913)._
