# ArrayFire Julia: Implementation of gfor?

**URL:** <https://discourse.julialang.org/t/arrayfire-julia-implementation-of-gfor/633>\
**Category:** GPU\
**Tags:** arrayfire\
**Created:** [November 29, 2016, 4:41pm UTC](https://discourse.julialang.org/t/arrayfire-julia-implementation-of-gfor/633 "2016-11-29T16:41:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedroborgesmelo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pedroborgesmelo/32/9459_2.png) [@pedroborgesmelo](https://discourse.julialang.org/u/pedroborgesmelo)\
**Post date:** [November 29, 2016, 4:41pm UTC](https://discourse.julialang.org/t/arrayfire-julia-implementation-of-gfor/633/1 "2016-11-29T16:41:14Z")

</div>

Hi!

Anyone knows how to implement something equivalent to gfor using the existing ArrayFire wrapper?  
I guess gfor is not wrapped…

Regards,

---

<div class="post-metadata">

**Author:** ![ranjan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranjan/32/4832_2.png) [@ranjan](https://discourse.julialang.org/u/ranjan)\
**Post date:** [November 29, 2016, 4:57pm UTC](https://discourse.julialang.org/t/arrayfire-julia-implementation-of-gfor/633/2 "2016-11-29T16:57:08Z")

</div>

Hey Pedro,

So here’s the thing: the gfor in the arrayfire library is simply syntactic sugar for the vector operations.

For example, something like

```julia
@gfor for i = 1:10
a[i] = a[i] + 1
end

```

is essentially the same as `a = a + 1`.

Please refer to [this](http://arrayfire.org/docs/page_gfor.htm#gfor) page for more details.

Thanks,  
Ranjan

---

<div class="post-metadata">

**Author:** ![pedroborgesmelo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pedroborgesmelo/32/9459_2.png) [@pedroborgesmelo](https://discourse.julialang.org/u/pedroborgesmelo)\
**Post date:** [November 29, 2016, 5:54pm UTC](https://discourse.julialang.org/t/arrayfire-julia-implementation-of-gfor/633/3 "2016-11-29T17:54:32Z")

</div>

Dear Ranjan,

Thanks for your reply.  
I need the gfor to do more complex things inside the for to save memory.

Julia does not find @gfor !

Regards,

---

<div class="post-metadata">

**Author:** ![pedroborgesmelo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pedroborgesmelo/32/9459_2.png) [@pedroborgesmelo](https://discourse.julialang.org/u/pedroborgesmelo)\
**Post date:** [November 29, 2016, 6:01pm UTC](https://discourse.julialang.org/t/arrayfire-julia-implementation-of-gfor/633/4 "2016-11-29T18:01:01Z")

</div>

Dear Ranjan,

I had not realized that there are several restrictions over the operations you can do inside the gfor.  
Maybe gfor is not what I’m searching for…

Thanks again,

---

<div class="post-metadata">

**Author:** ![ranjan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranjan/32/4832_2.png) [@ranjan](https://discourse.julialang.org/u/ranjan)\
**Post date:** [November 30, 2016, 5:03am UTC](https://discourse.julialang.org/t/arrayfire-julia-implementation-of-gfor/633/5 "2016-11-30T05:03:16Z")

</div>

Hey Pedro,

Since `gfor` is a simple syntax trick (which is why you see those restrictions), it is not going to save you memory. There are a few in place functions that ArrayFire.jl provides: `fft!, ifft!, svdfact!, chol!, lufact!` amongst others. Please do refer to the README on ArrayFire.jl to get that list.

I hope this helps,  
Ranjan
