random access incidence vector of HASSE_DIAGRAM->FACES

Questions and problems about using polymake go here.
ren
Posts: 38
Joined: 03 May 2011, 15:21

random access incidence vector of HASSE_DIAGRAM->FACES

Postby ren » 14 Nov 2016, 12:49

Not sure if this is intended behaviour, but this works:

Code: Select all

$simplexHasse = simplex(2)->HASSE_DIAGRAM; $simplexFace = $simplexHasse->FACES->[4]; print $simplexFace->[0]; print $simplexFace->[1];
while this does not:

Code: Select all

$simplexHasse = simplex(2)->HASSE_DIAGRAM; $simplexFace = $simplexHasse->FACES->[4]; print $simplexFace->[1];
And random access seems to be the only way to access the content of $simplexFace.

User avatar
hampe
Developer
Posts: 48
Joined: 29 Apr 2011, 10:42

Re: random access incidence vector of HASSE_DIAGRAM->FACES

Postby hampe » 14 Nov 2016, 13:38

The faces of a Hasse diagram are of type Set<Int>, which can be determined by calling

Code: Select all

print $simplexFace->type->full_name;
so random access is not actually foreseen in their interface (not quite sure, why the first version works, probably some perlish voodoo...).
There are various ways to access its elements on the perl side:
  • You can convert it, for example to a perl array or an Array<Int> via

    Code: Select all

    @sface = @{$simplexFace}; $sface_arr = new Array<Int>($simplexFace);
  • You can iterate over it using entire:

    Code: Select all

    for($it = entire($simplexFace);$it; $it++) { print $$it,"\n";};
Hope that helps!

ren
Posts: 38
Joined: 03 May 2011, 15:21

Re: random access incidence vector of HASSE_DIAGRAM->FACES

Postby ren » 14 Nov 2016, 14:31

Thanks, I will convert it to an array then!

User avatar
gawrilow
Main Author
Posts: 423
Joined: 25 Dec 2010, 17:40

Re: random access incidence vector of HASSE_DIAGRAM->FACES

Postby gawrilow » 14 Nov 2016, 16:07

... not quite sure, why the first version works, probably some perlish voodoo...
No vodoo at all. The Set behaves as any other container allowing to visit elements in ascending order. These three ways of iterating over set elements are equivalent, the first one having the smallest runtime overhead:

for my $elem (@$simplexFace) { ... }

for my $index (0..$#$simplexFace) { my $elem=$simplexFace->[$index]; ... }

for (my $iter=entire($simplexFace); $iter; ++$iter) { my $elem=$$iter; ... }

If you need true random access to its elements, then you indeed have to copy it into a plain perl array:

my @face=@$simplexFace;
my $elem=$face[$index];
...


Return to “Helpdesk”