Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced list indexing #192

Merged
merged 12 commits into from
Sep 4, 2015
Merged

Conversation

stevelinton
Copy link
Contributor

This is a cleaned up and rebased version of two old pull requests #83 and #28 (Thanks to @fingolfin and @markuspf for fixing the mess I'd made). It extends support for indexing into lists using indexes other than positive small integers. All such indexing ends up with GAP-level methods. It also adds the syntax l[i1,i2,....] which is mapped to l[[i1,i2,...]]. There is infrastructure in the kernel to allow for fast methods for the case of two indices (without creating the length 2 list) but this is currently not exported to GAP level.

Tests and documentation are still needed.

stevelinton and others added 9 commits July 9, 2015 09:46
… bit of old commented out code relating to the equivalent change for access some time ago.
Moreover,
- use of IS_POS_INTOBJ in multiple places for readability
  and efficiency
- enforce consistent behavior for ELM/ASS/ISB/UNB, and also between
  interpreted and compiled code: positive integers as before, while
  anything else (including non-positive integers) is sent through
  method dispatch
- some code cleanup (indention, uniform whitespace in comments, etc.)
This provides parser interpreter and coder support for multi-index access to lists
At the moment all such accesses are translated into calls to ELM_LIST with a single
argument which is a plain list of the indices, but there is kernel support for
a fast-path for two arguments later if one is needed.

At this stage printing of coded expressions, assignment, IsBound and Unbind are all
to do, as are nested list accesses. l[...][x,y].
@fingolfin
Copy link
Member

Really nice, thanks. Regarding tests: I guess that would involve InstallMethod invocations to setup so that one can test some non-trivial examples. That in turn makes it a bit more difficult to re-run tests, I guess (as InstallMethod would be called again and again)? That's certainly not an objection to anything, just an observation.

Anyway: I got a crash in the testsuite with this branch:

$ make testinstall
mkdir -p dev/log
( echo 'SetUserPreference("UseColorsInTerminal",false); \
        ReadGapRoot( "tst/testutil.g" ); \
            ReadGapRoot( "tst/testinstall.g" );' | ./bin/gap-default64.sh -b -m 100m -o 750m -A -q -x 80 -r  > \
            `date -u +dev/log/testinstall1_%Y-%m-%d-%H-%M` )
( echo 'SetUserPreference("UseColorsInTerminal",false); \
        ReadGapRoot( "tst/testutil.g" ); LoadAllPackages(); \
            ReadGapRoot( "tst/testinstall.g" );' | ./bin/gap-default64.sh -b -m 100m -o 750m -A -q -x 80 -r  > \
            `date -u +dev/log/testinstall2_%Y-%m-%d-%H-%M` )
Syntax warning: New syntax used -- intentional? in /Users/mhorn/Projekte/GAP/g\
ap.github/pkg/homalg/gap/HomalgFunctor.gi line 6301
    M := First( arg, IsStructureObjectOrObjectOrMorphism );
    ^
Syntax warning: arg used not as the last argument in /Users/mhorn/Projekte/GAP\
/gap.github/pkg/singular/gap/singular.g line 2529
GapInterface := function ( func, arg, out )
                                    ^
Syntax warning: New syntax used -- intentional? in /Users/mhorn/Projekte/GAP/g\
ap.github/pkg/fr-2.1.1/gap/group.gi line 1848
    Error := function(arg)
        ^
Assertion failed: (1 <= CountExpr), function PopExpr, file ../../src/code.c, line 356.
/bin/sh: line 3: 84361 Done                    echo 'SetUserPreference("UseColorsInTerminal",false); \
        ReadGapRoot( "tst/testutil.g" ); LoadAllPackages(); \
            ReadGapRoot( "tst/testinstall.g" );'
     84362 Abort trap: 6           | ./bin/gap-default64.sh -b -m 100m -o 750m -A -q -x 80 -r > `date -u +dev/log/testinstall2_%Y-%m-%d-%H-%M`
Makefile:223: recipe for target 'testinstall' failed
make: *** [testinstall] Error 134

@stevelinton
Copy link
Contributor Author

Yes, testing will need a little care. Can we safely assume that no one will run tests hundreds of times in the same copy of GAP? If so I can create a new filter to install methods on inside the tests.

Thanks for the crash report. I'll try LoadAllPackages().

The crash looks to be related to the partial variadic stuff rather than this, but maybe I've accidentally broken the error handling.

@fingolfin
Copy link
Member

It may or may not be related. I do get those warnings in master, too, of course, but not the crash. I did not yet try to track down what happens, just thought I should report it.

@fingolfin
Copy link
Member

Here is a small test case to trigger the crash:

function(M)
    local i, a;
    M{a}{a}[i][i];
end;

@stevelinton
Copy link
Contributor Author

Thanks I’ll get into it.

S

On 9 Jul 2015, at 17:21, Max Horn [email protected] wrote:

Here is a small test case to trigger the crash:

function(M)
local i, a;
M{a}{a}[i][i];
end;


Reply to this email directly or view it on GitHub.

@fingolfin
Copy link
Member

Tests pass now, and this looks pretty good overall.

One minor remark: The test checks whether functions using the new construct are printed correctly. But it only tests the multi-integer-index variant, i.e. a[1,2,3], but not a["abc"], a[[1,2,3]], a[fail, "x"], etc.

@stevelinton
Copy link
Contributor Author

I believe this is ready to merge

markuspf added a commit that referenced this pull request Sep 4, 2015
@markuspf markuspf merged commit 5a41067 into gap-system:master Sep 4, 2015
@olexandr-konovalov olexandr-konovalov added this to the GAP 4.8.0 milestone Sep 14, 2015
@olexandr-konovalov olexandr-konovalov changed the title WIP: Enhanced list indexing Enhanced list indexing Sep 14, 2015
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f447fc1 on stevelinton:sl/multi-index into ** on gap-system:master**.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants