One of the speed bottleneck in creating a FactorGraph is the time to create the variables_for_factors list, which is currently slow as we loop through the individual variables.
However, in the case where all the variable groups are NDVarArr we can speed up this step a lot proposing a generic get_factors interface where the user would define the general rule for the factors and the corresponding list would be generated with numba.
One options is to have a first argument which consists of variable groups for which we loop over dimensions, and a second argument which consists of variable groups for do not loop over,
For, example get_factors({x:(i, j), y:(k, l)}, {z:(i+k, j+l)}) would mean
factors = []
for i in range(x.shape[0]):
for j in range(x.shape[1]):
for k in range(y.shape[0]):
for l in range(y.shape[1]):
factors.append((x[i, j], y[k, l], z[i+k, j+l]))
One of the speed bottleneck in creating a
FactorGraphis the time to create thevariables_for_factorslist, which is currently slow as we loop through the individual variables.However, in the case where all the variable groups are
NDVarArrwe can speed up this step a lot proposing a generic get_factors interface where the user would define the general rule for the factors and the corresponding list would be generated with numba.One options is to have a first argument which consists of variable groups for which we loop over dimensions, and a second argument which consists of variable groups for do not loop over,
For, example
get_factors({x:(i, j), y:(k, l)}, {z:(i+k, j+l)})would mean