I have a program that requires me to use my own array type. However, my own array definition seems to cause a type instability problem, leaving lots of performance on the table (potentially 2~3x improvements).
The issue can be reduced to the minimal working example below:
https://gist.github.com/jinliangwei/a10a2bffc1c4fdfa38acb495ff5c43d4
My program defines two custom array types DenseArrayAccessor
and DenseArray
. The former is essentially a wrapper on a Julia vector and the latter wraps on top of the DenseArrayAccessor
. In my actual program, DenseArray
contains other fields and supports other operations but those are unnecessary details for this question.
The train
function is what I am trying to optimize. @code_warntype
shows many warnings when H
and W
are DenseArray
s but those warnings are gone when I use DenseArrayAccessor
. Could someone please help me understand what caused this instability?