# Typing error when using guvectorize

**URL:** <https://numba.discourse.group/t/typing-error-when-using-guvectorize/2069>\
**Category:** Support: What is this error message?\
**Created:** [August 16, 2023, 5:53am UTC](https://numba.discourse.group/t/typing-error-when-using-guvectorize/2069 "2023-08-16T05:53:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karie](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@Karie](https://numba.discourse.group/u/Karie)\
**Post date:** [August 16, 2023, 5:53am UTC](https://numba.discourse.group/t/typing-error-when-using-guvectorize/2069/1 "2023-08-16T05:53:59Z")

</div>

I am writing a code to update parameters. The code involves a total of `BURNIN+N` iterations, and in each iteration, the parameters are updated. The main program code is as follows:

```auto
@jit(nopython=True)
def MCMC(Y, V, mu, omega, psi, kappa, theta):   
    for i in range(1, BURNIN + N):
        mu = update_mu(deltat, i, T, Y, V, mu, omega, psi, kappa, theta) 
        omega, psi = update_omega_psi(deltat, i, T, Y, V, mu, omega, psi, kappa, theta)
        theta = update_theta(deltat, i, T, Y, V, mu, omega, psi, kappa, theta)
        kappa = update_kappa(deltat, i, T, Y, V, mu, omega, psi, kappa, theta)
        V = update_V(i, T, Y, V, mu, omega, psi, kappa, theta)   

```

The code for parameter updates is as follows:

```auto
@guvectorize([(float64, int64, int64, float64[:], float64[:,:], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:])], 
             '(),(),(),(n),(m,n),(m),(m),(m),(m),(m)->(m)', 
             nopython=True)      
def update_mu(deltat, i, T, Y, V, mu, omega, psi, kappa, theta, res):
    mustara = sum((omega[i-1] + psi[i-1]**2) * (Y[1:T+1] + 0.5 * V[i-1, :T] * deltat) / (omega[i-1] * V[i-1, :T]))
    mustarb = sum(psi[i-1] * (V[i-1, 1:T+1] - kappa[i-1] * theta[i-1] * deltat - (1 - kappa[i-1] * deltat) * V[i-1, :T]) / (omega[i-1] * V[i-1, :T]))
    mustar = (mustara - mustarb + (mu0 / sigma0**2)) / (deltat * sum((omega[i-1] + psi[i-1]**2) / (omega[i-1] * V[i-1, :T])) + 1 / sigma0**2)
    sigstar = np.sqrt(1 / (deltat * sum((omega[i-1] + psi[i-1]**2) / (omega[i-1] * V[i-1, :T])) + 1 / sigma0**2))
    res[i] = np.random.normal(mustar, sigstar)

```

For the parameter `mu`, the updated value from each iteration is stored in `res` and then reassigned to `mu`, which facilitates the next iteration. However, I encountered the following error:

```auto
TypingError: Cannot determine Numba type of <class 'numba.core.ir.UndefinedType'>

```

How to address this problem? Thanks in advance !

---

<div class="post-metadata">

**Author:** ![nelson2005](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/nelson2005/32/47_2.png) [@nelson2005](https://numba.discourse.group/u/nelson2005)\
**Post date:** [August 16, 2023, 9:22pm UTC](https://numba.discourse.group/t/typing-error-when-using-guvectorize/2069/2 "2023-08-16T21:22:53Z")

</div>

Someone may know the answer off the top of their head, but a minimal complete reproducer could be helpful if you can get one together.

---

<div class="post-metadata">

**Author:** ![Rutger](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/rutger/32/446_2.png) [@Rutger](https://numba.discourse.group/u/Rutger)\
**Post date:** [August 17, 2023, 9:19am UTC](https://numba.discourse.group/t/typing-error-when-using-guvectorize/2069/3 "2023-08-17T09:19:12Z")

</div>

It’s a little difficult to reason about without sample data, and especially things like the shapes of the input arrays.  
I find it confusing that you pass an integer along that you use for indexing, and only do calculations for that specific index, wouldn’t that eliminate the entire benefit of `guvectorize`?. And especially when you don’t provide the output (`res`), wouldn’t that trigger the creation of a new array (of size `m`) every time the function is called? While it will only set that single element (`i`) of the output array.
