PolyCon icon indicating copy to clipboard operation
PolyCon copied to clipboard

Array support

Open szaghi opened this issue 9 years ago • 3 comments

Hi Chris, Nice project, congrats!

I have just give it a very superficial read, but the type_guard method is a very nice idea.

I read that you are searching a way to support array. I have used in the past unlimited polymorphic and transfer... thus I underdtand the problems hidden in this kind of stuffs. I find a solution that works for my case. The key of my solution was to use something like the smallest variable available (hopefully 1 byte) for the storage. You are using characters: I am not sure but I think that 1 character is, in the most cases, larger than 1 byte (I guess 4 bytes). My solution was to exploit the kind selection of integer in order to find the smallest integer that hopefully is 1 byte in the most architectures, thus my storage is something like

integer, parameter:: I1P  = selected_int_kind(2)
integer(I1P), alloatable :: storage(:)

Now storage can be allocated with the rigth dimension exploiting just the transfer function:

np = size(transfer(input, storage)) ; allocate(storage(1:np)) ; storage = transfer(input, storage)

I use such a strategy in some project like this https://github.com/szaghi/BeFoR64/blob/master/src/Lib_Pack_Data.f90#L88

I hope to be on topic... I have to study with more details your great container.

See you soon.

szaghi avatar Dec 20 '15 18:12 szaghi

The issue isn't with storage but with avoiding the need to implement a bunch of different versions of the type-guard functions for arrays of different ranks.

cmacmackin avatar Dec 20 '15 20:12 cmacmackin

Ah, ok sorry gor my mistake. Anyhow, do you have tried to use character(1) as minimal block storage? Is it 1 byte? When I tried I remember I faced with some problem, I think that we can use inquire to check its storage extent.

Why you do not use class(*) instead to relay on transfer. Admittely, I have not deeply read your container.

See you soon.

szaghi avatar Dec 20 '15 20:12 szaghi

I did switch to using 1-byte integer arrays, because they are guaranteed to be as small as possible. The reason I didn't use class(*) is because they are completely incapable of holding arrays. If I'm not mistaken, using it would also require slightly more complex type-guarding, as its type would also need to be tested. Plus, compilers can be buggy when dealing with unlimited polymorphic entities, so I try to minimize them.

On 15-12-20 04:20 PM, Stefano Zaghi wrote:

Ah, ok sorry gor my mistake. Anyhow, do you have tried to use character(1) as minimal block storage? Is it 1 byte? When I tried I remember I faced with some problem, I think that we can use |inquire| to check its storage extent.

Why you do not use |class(*)| instead to relay on |transfer|. Admittely, I have not deeply read your container.

See you soon.

— Reply to this email directly or view it on GitHub https://github.com/cmacmackin/PolyCon/issues/1#issuecomment-166151394.

Chris MacMackin cmacmackin.github.io http://cmacmackin.github.io

cmacmackin avatar Dec 20 '15 20:12 cmacmackin