# Use of Lazy arrays

**URL:** <https://discourse.julialang.org/t/use-of-lazy-arrays/79779>\
**Category:** Performance\
**Tags:** lazy-evaluation\
**Created:** [April 21, 2022, 12:11pm UTC](https://discourse.julialang.org/t/use-of-lazy-arrays/79779 "2022-04-21T12:11:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siempie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/siempie/32/32790_2.png) [@Siempie](https://discourse.julialang.org/u/Siempie)\
**Post date:** [April 21, 2022, 12:11pm UTC](https://discourse.julialang.org/t/use-of-lazy-arrays/79779/1 "2022-04-21T12:11:44Z")

</div>

Hi,  
I am looking into the use of lazy evaluation and lazy arrays in Julia. For example the package LazyArrays.jl.

However i am not quite sure if i understand the benefits of lazy evaluation correctly. In my understanding it is primarily usefull for delaying evaluations until they are absolutely necessary.  
Can LazyArrays also be usefull when i am certain every calculation i make has to be calculated at some point?

Specifically i am interested in using it for a SparseMatrix\*DenseVector multiplication and DenseVector addition.  
Can Lazy evaluation be usefull for this?

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [April 21, 2022, 12:50pm UTC](https://discourse.julialang.org/t/use-of-lazy-arrays/79779/2 "2022-04-21T12:50:24Z")

</div>

> [@Siempie](#):
>
> In my understanding it is primarily usefull for delaying evaluations until they are absolutely necessary.

So I would think, too.

> [@Siempie](#):
>
> Can LazyArrays also be usefull when i am certain every calculation i make has to be calculated at some point?

In general lazy evaluation _could_ support [fusion](https://en.wikipedia.org/wiki/Deforestation_(computer_science)).

> [@Siempie](#):
>
> Specifically i am interested in using it for a SparseMatrix\*DenseVector multiplication and DenseVector addition.

I see two extreme cases

- you only need a slice of the result =\> that could be a bit faster
- you evaluate the result multiple times =\> that could be a bit slower

---

<div class="post-metadata">

**Author:** ![Siempie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/siempie/32/32790_2.png) [@Siempie](https://discourse.julialang.org/u/Siempie)\
**Post date:** [April 21, 2022, 4:01pm UTC](https://discourse.julialang.org/t/use-of-lazy-arrays/79779/3 "2022-04-21T16:01:07Z")

</div>

Thanks for the reply.

I need the whole result everytime. So that would mean it is not very usefull for me.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [April 21, 2022, 4:36pm UTC](https://discourse.julialang.org/t/use-of-lazy-arrays/79779/4 "2022-04-21T16:36:49Z")

</div>

> [@Siempie](#):
>
> I need the whole result everytime. So that would mean it is not very usefull for me.

I’m not absolutely sure, it depends on your problem (for example do you mean `SparseMatrixCSC` or do you have sparse matrices with special formal properties). Also [`LazyAlgebra`](https://emmt.github.io/LazyAlgebra.jl/dev/) looks like a package which makes use of fusion rules.
