# What beats a flat array with strides for variables?

**URL:** <https://discourse.julialang.org/t/what-beats-a-flat-array-with-strides-for-variables/751>\
**Category:** Machine Learning\
**Created:** [December 6, 2016, 12:15am UTC](https://discourse.julialang.org/t/what-beats-a-flat-array-with-strides-for-variables/751 "2016-12-06T00:15:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hpoit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpoit/32/245_2.png) [@hpoit](https://discourse.julialang.org/u/hpoit)\
**Post date:** [December 6, 2016, 12:15am UTC](https://discourse.julialang.org/t/what-beats-a-flat-array-with-strides-for-variables/751/1 "2016-12-06T00:15:53Z")

</div>

[Context - 10.A.1](https://books.google.com.br/books?id=7dzpHCHzNQ4C&pg=PA359&lpg=PA359&dq=Algorithm+10.A.1+%E2%80%94+Efficient+implementation+of+a+factor+product+operation.&source=bl&ots=pv6zGo6YrM&sig=MxO7DMX-cNkGoscm5Cvyrb2dzHo&hl=en&sa=X&ved=0ahUKEwjRpbv5lt7QAhVKC5AKHZvRD5cQ6AEIJjAC#v=onepage&q=Algorithm%2010.A.1%20%E2%80%94%20Efficient%20implementation%20of%20a%20factor%20product%20operation.&f=false)

I am wondering on how to support 10.A.1 on a range of data representations, managed by a dispatch system, for a library of operations (product, marginalization, maximization, reduction, …)

I don’t want the data type scattered into functions and having to dance around DataFrames’ pooling. 10.A.1 has enough behaviors to warrant a data type of its own. As Koller says, indexing the appropriate entries in each factor is a key design decision.

However this is my first attempt at this, hence my post here.

---

<div class="post-metadata">

**Author:** ![hpoit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpoit/32/245_2.png) [@hpoit](https://discourse.julialang.org/u/hpoit)\
**Post date:** [December 6, 2016, 10:34am UTC](https://discourse.julialang.org/t/what-beats-a-flat-array-with-strides-for-variables/751/2 "2016-12-06T10:34:18Z")

</div>

One guess is something involving [code generation for] different data arrangements depending on the factor operation.

I see the data bending itself to the operation, and not the operation losing its identity to access the data.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 6, 2016, 12:17pm UTC](https://discourse.julialang.org/t/what-beats-a-flat-array-with-strides-for-variables/751/3 "2016-12-06T12:17:14Z")

</div>

It would help a lot if you can post some code with what you have tried and what seems to not be working as well as you would want it to.

---

<div class="post-metadata">

**Author:** ![hpoit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpoit/32/245_2.png) [@hpoit](https://discourse.julialang.org/u/hpoit)\
**Post date:** [December 6, 2016, 4:46pm UTC](https://discourse.julialang.org/t/what-beats-a-flat-array-with-strides-for-variables/751/4 "2016-12-06T16:46:53Z")

</div>

(removed for violation of [Community Standards](http://julialang.org/community/standards/))

---

<div class="post-metadata">

**Author:** ![hpoit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpoit/32/245_2.png) [@hpoit](https://discourse.julialang.org/u/hpoit)\
**Post date:** [December 6, 2016, 4:53pm UTC](https://discourse.julialang.org/t/what-beats-a-flat-array-with-strides-for-variables/751/5 "2016-12-06T16:53:53Z")

</div>

So a type Factor having inner constructors for each operation I think is the answer.
