# Speeding up a color transformation loop

**URL:** <https://discourse.julialang.org/t/speeding-up-a-color-transformation-loop/106445>\
**Category:** Performance\
**Created:** [November 19, 2023, 10:36pm UTC](https://discourse.julialang.org/t/speeding-up-a-color-transformation-loop/106445 "2023-11-19T22:36:24Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 21, 2023, 11:30am UTC](https://discourse.julialang.org/t/speeding-up-a-color-transformation-loop/106445/18 "2023-11-21T11:30:49Z")

</div>

> [@mpeters2](#):
>
> ` XYZlayers[j] = XYZlayers[j] .+ (images[i] .*IllumiCMF[j,i]) # multiply each image by the CMF/Illuminant combo`

Another thing: as I understand here `XYZlayers[j]` is an array. Here you are creating a new array on the right side of the equation and replacing the array on that position with this new array. You probably want to update the current array, with `XYXlayers[j] .= ... `(note the dot in `.=`). Alternatively, you can use, for simplicity:

```julia
     @. XYZlayers[j] = XYZlayers[j] + (images[i] * IllumiCMF[j,i])	

```

See: [Common allocation mistakes](https://discourse.julialang.org/t/common-allocation-mistakes/66127#h-2-creating-vectors-unintentionally-with-broadcasting-2)

edit: Indeed, the same @nsajko posted above.

---

_[View the full topic](https://discourse.julialang.org/t/speeding-up-a-color-transformation-loop/106445)._
