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

26 views
Skip to first unread message

Kiny Wan

unread,
Jul 7, 2020, 7:33:57 AM7/7/20
to PyFR Mailing List
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'>

Freddie Witherden

unread,
Jul 7, 2020, 8:58:47 AM7/7/20
to pyfrmai...@googlegroups.com
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.

On 07/07/2020 06:33, Kiny Wan wrote:
> 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'>
>
> --
> You received this message because you are subscribed to the Google
> Groups "PyFR Mailing List" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pyfrmailingli...@googlegroups.com
> <mailto:pyfrmailingli...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pyfrmailinglist/df2ef118-0f48-4e9e-a018-03c00c1e1b60n%40googlegroups.com
> <https://groups.google.com/d/msgid/pyfrmailinglist/df2ef118-0f48-4e9e-a018-03c00c1e1b60n%40googlegroups.com?utm_medium=email&utm_source=footer>.
pEpkey.asc

Kiny Wan

unread,
Jul 8, 2020, 1:10:45 AM7/8/20
to PyFR Mailing List
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).
Reply all
Reply to author
Forward
0 new messages