# Vector function representation

**URL:** <https://discourse.julialang.org/t/vector-function-representation/52779>\
**Category:** Performance\
**Tags:** question\
**Created:** [January 3, 2021, 4:32pm UTC](https://discourse.julialang.org/t/vector-function-representation/52779 "2021-01-03T16:32:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shawnfrost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shawnfrost/32/20744_2.png) [@shawnfrost](https://discourse.julialang.org/u/shawnfrost)\
**Post date:** [January 3, 2021, 4:32pm UTC](https://discourse.julialang.org/t/vector-function-representation/52779/1 "2021-01-03T16:32:51Z")

</div>

Hi,  
Some background: I’m new to writing distributed programs and I’m trying to write a variation of the SSA algorithm in Julia. My system has a lot of reactions, and I need to calculate the propensity of these reactions over and over. I use a dependency graph, so whenever a reaction fires I use that dependency graph to figure out which reactions’ propensities I need to update.

Now, I have these propensities stored in an array and I also have an array of functions, where the ith element is a function that calculates the propensity of the ith reaction. A basic version of these functions look something like this: `() -> rate[x]*reactants[y]` So if I know a reaction occurs and I need to update the propensities of, say, reactions 1,2 and 3, I run a simple loop and access the 1st, 2nd and 3rd elements of this array and run them, and update the propensity array based on their results.

My question is is there a more efficient way for me to represent/store these functions or rewrite them in a vectorized form? The actual calculation for all of these functions can be represented as matrix multiplication of some slice of the rate/reactant vectors, but I need a way to access each of these functions. The simpler way is probably to have a switch statement which will encode how to carry out the calculations, so I can just pass the reaction number and it will figure out which calculation to run, but that isn’t really “vectorized” and I would prefer to have as little control logic as possible.

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 4, 2021, 12:52pm UTC](https://discourse.julialang.org/t/vector-function-representation/52779/2 "2021-01-04T12:52:47Z")

</div>

> [@shawnfrost](#):
>
> is there a more efficient way for me to represent/store these functions or rewrite them in a vectorized form

It is very hard to answer this question without an MWE we can run, to see how you implemented it, what the functions look like typically, the scale of the problem, etc.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757/):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …
