# Minor improvement to ValueFnIter\_Refine

**URL:** https://discourse.vfitoolkit.com/t/minor-improvement-to-valuefniter-refine/628
**Category:** Uncategorized
**Created:** [April 3, 2026, 3:29pm UTC](https://discourse.vfitoolkit.com/t/minor-improvement-to-valuefniter-refine/628 "2026-04-03T15:29:10Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![aledinola](https://discourse.vfitoolkit.com/letter_avatar_proxy/v4/letter/a/3ec8ea/32.png) [@aledinola](https://discourse.vfitoolkit.com/u/aledinola)
#### Post date: [April 3, 2026, 3:29pm UTC](https://discourse.vfitoolkit.com/t/minor-improvement-to-valuefniter-refine/628/1 "2026-04-03T15:29:10Z")

</div>

This is more a performance issue than a bug.

In `ValueFnIter/InfHorz/Refinement/ValueFnIter_Refine.m` I changed

`Policy=zeros(2,N_a,N_z);`

to

`Policy=zeros(2,N_a,N_z,'gpuArray');`

This keeps everything on the GPU instead of creating the final policy on the CPU and then filling it using `Policy_a`, `dstar`, etc. which are on the GPU:

```matlab
if n_d(1)>0
    Policy=zeros(2,N_a,N_z,'gpuArray');
    Policy(2,:,:)=shiftdim(Policy_a,-1);
    temppolicyindex=reshape(Policy_a,[1,N_a*N_z])+(0:1:N_a*N_z-1)*N_a;
    Policy(1,:,:)=reshape(dstar(temppolicyindex),[N_a,N_z]);
else
    Policy=Policy_a;
end

```

Not so important for performance since this is outside any hot loop, but still needs to be fixed.

This is also included in a PR, I think.

---

<div class="post-metadata">

### Author: ![robertdkirkby](https://discourse.vfitoolkit.com/user_avatar/discourse.vfitoolkit.com/robertdkirkby/32/287_2.png) [@robertdkirkby](https://discourse.vfitoolkit.com/u/robertdkirkby)
#### Post date: [April 6, 2026, 7:45pm UTC](https://discourse.vfitoolkit.com/t/minor-improvement-to-valuefniter-refine/628/2 "2026-04-06T19:45:07Z")

</div>

Merged this one 😃 nice little improvement.
