Comment about 'self._providers = [k(self) for k in kprovcls]' in backend/openmp/base.py

Hi Freddie and everyone,
The more you learn, the more problems you encounter! Today, I want to discuss about a python operation in backend/openmp/base.py, which is very advanced. The code is shown as follow:

Instantiate mandatory kernel provider classes

kprovcls = [provider.OpenMPPointwiseKernelProvider,
blasext.OpenMPBlasExtKernels,
packing.OpenMPPackingKernels,
gimmik.OpenMPGiMMiKKernels]
self._providers = [k(self) for k in kprovcls]

The ‘self’ is brought into the class ‘k’. Using print function, I found that k(self) represents object and k denotes class. I am wondering what impact this will have?

print(provider.OpenMPPointwiseKernelProvider(self))

<pyfr.backends.openmp.provider.OpenMPPointwiseKernelProvider object at 0x7f5551a03b70>

print(provider.OpenMPPointwiseKernelProvider)

<class ‘pyfr.backends.openmp.provider.OpenMPPointwiseKernelProvider’>

Hi,

Here k corresponds to a class. Hence k(self) corresponds to creating an
instance of the class referred to by k passing self as the first
parameter, which results in an object.

Regards, Freddie.

Thank you very much. The ‘self._providers’ is passed to ‘backend’, which is used to register pointwise kernels. The backend.pointwise.register() in elements.py will get errors when using k instead of k(self).