I guess I will post my follow up question here… what I really want to do is template over numeric types/kinds and array ranks… so I would like to be able to do something like
template <class data_type, class rank>
function myfunc_(x)
data_type :: x(:,:,:)
end function
end template
where the data_type can be real*4, real*8, integer*4, integer*8, integer*2 etc and rank is used to define the arrays of the right rank… ie
rank=3 => data_type :: x(:,:,:)
rank=5 => data_type :: x(:,:,:,:,:)
How can this best be achieved with PyF95++?
Thanks for any help
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Never mind I think I solved this one as well… at least the following seems to work using a POD:
template <class data_type, class data_kind, class data_rank>
function fpGetPr_(mx) result (fp)
pod colons from mypods
n = data_rank
src = "data_type(kind=data_kind), pointer :: fp($cols$)"
end pod colons
…
Hi,
I would like to template over different numerical types (ie normal real, double precision, 8,16,32,64 bit integers etc.)
How do I pass these as classes to a template? mymodule<real> works but mymodule<real*8> or mymodule<real(8)> doesn't.
Thanks
I guess I will post my follow up question here… what I really want to do is template over numeric types/kinds and array ranks… so I would like to be able to do something like
template <class data_type, class rank>
function myfunc_(x)
data_type :: x(:,:,:)
end function
end template
where the data_type can be real*4, real*8, integer*4, integer*8, integer*2 etc and rank is used to define the arrays of the right rank… ie
rank=3 => data_type :: x(:,:,:)
rank=5 => data_type :: x(:,:,:,:,:)
How can this best be achieved with PyF95++?
Thanks for any help
Sorry for the noise - of course I can pass an integer kind to the template and use that in the declaration.
So the only remaining question is how to template expressions like
data_type(kind=data_kind) :: x(:,:,:)
over ranks?
Never mind I think I solved this one as well… at least the following seems to work using a POD:
template <class data_type, class data_kind, class data_rank>
function fpGetPr_(mx) result (fp)
pod colons from mypods
n = data_rank
src = "data_type(kind=data_kind), pointer :: fp($cols$)"
end pod colons
…
with mypods.py:
def colons(blksrc, globalDict):
n = None
src = None
code = compile(blksrc, '', 'exec')
exec code
cols = n*':,'
cols = cols
block = src.replace('$cols$', cols)
return block
This is really a great tool!