I have a line in some R code I am writing that is quite slow. It applies logSumExp across a 4 dimensional array using the apply command. I'm wondering are there ways to speed it up!
Reprex: (this might take 10seconds or more to run)
library(microbenchmark)
library(matrixStats)
array4d <- array( runif(5*500*50*5 ,-1,0),
dim = c(5, 500, 50, 5) )
microbenchmark(
result <- apply(array4d, c(1,2,3), logSumExp)
)
Any advice appreciated!