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

Bug in CertainRows/Columns #188

Open
kamalsaleh opened this issue Dec 20, 2017 · 1 comment
Open

Bug in CertainRows/Columns #188

kamalsaleh opened this issue Dec 20, 2017 · 1 comment

Comments

@kamalsaleh
Copy link
Member

Hallo,
The output of the command CertainRows/CertainColumns applied on a matrix (for which HasEvalUnionOfRows/Columns is set to be true) may be wrong.

Bellow is an example of this situation.

LoadPackage( "rings" );
R := HomalgFieldOfRationals();
A := HomalgMatrix( "[ 1,2,3,4,5,6 ]", 2, 3, R );
B := HomalgMatrix( "[ 1,2,2,2,1,1, 1,1,1,0,2,4 ]", 4, 3, R );
u1 := UnionOfColumns( A, HomalgZeroMatrix( 2, 3, R ) );
u2 := UnionOfColumns( HomalgZeroMatrix( 4, 3, R ), B );
u := UnionOfRows( u1, u2 );
Display( u );
[ [ 1, 2, 3, 0, 0, 0 ],
[ 4, 5, 6, 0, 0, 0 ],
[ 0, 0, 0, 1, 2, 2 ],
[ 0, 0, 0, 2, 1, 1 ],
[ 0, 0, 0, 1, 1, 1 ],
[ 0, 0, 0, 0, 2, 4 ] ]
Display( CertainRows( u, [ 2, 1 ] ) );
[ [ 4, 5, 6, 0, 0, 0 ],
[ 1, 2, 3, 0, 0, 0 ] ]
Display( CertainRows( u, [ 3, 1 ] ) );
[ [ 1, 2, 3, 0, 0, 0 ],
[ 0, 0, 0, 1, 2, 2 ] ]

You can find a solution to this in my master branch (not sure if it is the best possible):
kamalsaleh@4879149

@sebasguts
Copy link
Contributor

The command CertainRows in this case of a stacked matrix calls the method

function ( M, plist )
    local  e, A, B, a, rowsA, rowsB, plistA, plistB;
    Info( InfoCOLEM, 2, COLEM.color, "\033[01mCOLEM\033[0m ", COLEM.color, "CertainRows( UnionOfRows )", "\033[0m" );
    e := EvalUnionOfRows( M );
    A := e[1];
    B := e[2];
    a := NrRows( A );
    rowsA := [ 1 .. a ];
    rowsB := [ 1 .. NrRows( B ) ];
    plistA := Filtered( plist, function ( x )
            return x in rowsA;
        end );
    plistB := Filtered( plist - a, function ( x )
            return x in rowsB;
        end );
    return UnionOfRows( CertainRows( A, plistA ), CertainRows( B, plistB ) );
end

As you see from the method, first all rows from the upper matrix are extracted, then all rows from the lower one.
This means all rows from the first matrix are always above the rows from the second matrix.

@kamalsaleh s solution is valid, but produces a lot of matrices in between.

mohamed-barakat added a commit to mohamed-barakat/homalg_project that referenced this issue Dec 21, 2017
mohamed-barakat added a commit to mohamed-barakat/homalg_project that referenced this issue Dec 21, 2017
and updated affected outputs in examples accordingly
HereAround pushed a commit to HereAround/homalg_project that referenced this issue Jun 18, 2020
and updated affected outputs in examples accordingly
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

No branches or pull requests

2 participants