Cannot do math with arrays that have more than 2 dimensions

95 views
Skip to first unread message

heather...@gmail.com

unread,
Jul 15, 2023, 2:53:26 PM7/15/23
to nimble-users
Hi Nimble community,

Looks like matrix math on 3-D arrays is not allowed, or at least not in the context I'm aiming for. I'm mostly writing this thread so that when I next encounter this error I will be able to find it on the NIMBLE google group and remember my solution. 

Is the work around just to write a NIMBLE function that takes the 3D object, turns it into 2D, does some math, then stores it? 

Here's the problem area in my code:
log(psi[i,k,t]) <- X2[i,1:5,t] %*% betaVector2[1:5,k] 

In theory, this should just be calculating a 1 row, 5 column matrix multiplied by a 5 row, 1 column matrix at each time step, but seems that NIMBLE says no. 

Here's the compiling output:
Warning, in eigenizing model_psi[getNodeFunctionIndexedInfo(ARG1_INDEXEDNODEINFO__,2), getNodeFunctionIndexedInfo(ARG1_INDEXEDNODEINFO__,1), getNodeFunctionIndexedInfo(ARG1_INDEXEDNODEINFO__,3)] the [ is still there but nDim is not 0 (not a scalar). Error : Cannot do math with arrays that have more than 2 dimensions. This occurred for: model_psi This was part of the call: model_psi[getNodeFunctionIndexedInfo(ARG1_INDEXEDNODEINFO__,2), getNodeFunctionIndexedInfo(ARG1_INDEXEDNODEINFO__,1), getNodeFunctionIndexedInfo(ARG1_INDEXEDNODEINFO__,3)] Error: There is some problem at the Eigen processing step for this code: { model$psi[getNodeFunctionIndexedInfo(INDEXEDNODEINFO_, 2), getNodeFunctionIndexedInfo(INDEXEDNODEINFO_, 1), getNodeFunctionIndexedInfo(INDEXEDNODEINFO_, 3)] <<- exp(model$X2[getNodeFunctionIndexedInfo(INDEXEDNODEINFO_, 2), 1:5, getNodeFunctionIndexedInfo(INDEXEDNODEINFO_, 3)] %*% model$betaVector2[1:5, getNodeFunctionIndexedInfo(INDEXEDNODEINFO_, 1)]) }

Many thanks! 

Heather Gaya
 


Daniel Turek

unread,
Jul 16, 2023, 7:09:09 AM7/16/23
to heather...@gmail.com, nimble-users
Heather, this might be a simple case using the inprod() function.  Try:

log(psi[i,k,t]) <- inprod(  X2[i,1:5,t], betaVector2[1:5,k]   )

This computes the vector inner product, the sum of the element-wise product of two vectors.

Cheers,
Daniel




--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/399c5496-4226-4c03-baa1-cbe3aa0a7cc9n%40googlegroups.com.

heather...@gmail.com

unread,
Aug 4, 2023, 1:27:57 PM8/4/23
to nimble-users
Just wanted to pop back in and say thank you! Inprod did the trick.

-Heather 

Reply all
Reply to author
Forward
0 new messages