# BatchIntegralFunction not appearing to work as intended

**URL:** <https://discourse.julialang.org/t/batchintegralfunction-not-appearing-to-work-as-intended/109513>\
**Category:** Modelling & Simulations\
**Tags:** question, diffeq, sciml, integral\
**Created:** [January 31, 2024, 1:37pm UTC](https://discourse.julialang.org/t/batchintegralfunction-not-appearing-to-work-as-intended/109513 "2024-01-31T13:37:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HSnowden](https://avatars.discourse-cdn.com/v4/letter/h/58f4c7/32.png) [@HSnowden](https://discourse.julialang.org/u/HSnowden)\
**Post date:** [January 31, 2024, 1:37pm UTC](https://discourse.julialang.org/t/batchintegralfunction-not-appearing-to-work-as-intended/109513/1 "2024-01-31T13:37:57Z")

</div>

I am trying to implement a batch integral function using the new BatchIntegralFunction rather than then deprecated nout/batch keywords. However, when I do, the in-place vector to fill place the answer in is the incorrect size therefore it returns a broadcasting error. Please can you take a look at the MWE below and see where I went wrong. Thank you very much

```julia
function f(y, u, p)
    Threads.@threads for i in 1:length(u)
        y[1, i] = sin(u[i])*p[1]
        y[2, i] = cos(u[i])*p[2]
    end
end
p=[1,2]
int=BatchIntegralFunction(f,zeros(2),max_batch=2)
prob = IntegralProblem(int, 1, 3,p)#; nout = 2,nbatch=2
sol = solve(prob, CubatureJLh(); reltol = 1e-3, abstol = 1e-3)
sol.u

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [February 1, 2024, 1:48am UTC](https://discourse.julialang.org/t/batchintegralfunction-not-appearing-to-work-as-intended/109513/2 "2024-02-01T01:48:10Z")

</div>

Open an issue.

---

<div class="post-metadata">

**Author:** ![lxvm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lxvm/32/50010_2.png) [@lxvm](https://discourse.julialang.org/u/lxvm)\
**Post date:** [February 3, 2024, 4:05am UTC](https://discourse.julialang.org/t/batchintegralfunction-not-appearing-to-work-as-intended/109513/3 "2024-02-03T04:05:09Z")

</div>

Hi there, the prototype you passed to the BatchIntegralFunction is missing a batching dimension. Specifically, the prototype should have the same type as `y`, and the same shape along all dimensions, although the batching dimension is unspecified and can have length zero. The following works for me:

```julia
function f(y, u, p)
    Threads.@threads for i in 1:length(u)
        y[1, i] = sin(u[i])*p[1]
        y[2, i] = cos(u[i])*p[2]
    end
end
p=[1,2]
int=BatchIntegralFunction(f,zeros(2, 0),max_batch=2)
prob = IntegralProblem(int, 1, 3,p)#; nout = 2,nbatch=2
sol = solve(prob, CubatureJLh(); reltol = 1e-3, abstol = 1e-3)
sol.u

```

This is a point which is lacking in the Integrals.jl documentation so I am opening a pr.
