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

Implement a new matrix object using flat lists in row-major form #5121

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions lib/matobjflist.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#############################################################################
##
## This file is part of GAP, a system for computational discrete algebra.
##
## SPDX-License-Identifier: GPL-2.0-or-later
##
## Copyright of GAP belongs to its developers, whose names are too numerous
## to list here. Please refer to the COPYRIGHT file for details.
##

############################################################################
#
# This is an implementation for nxm matrices
# stored as a flat n*m element list. In this
# file the representation, types and global
# functions are declared.


#############################################################################
##
## <#GAPDoc Label="IsFlistMatrixRep">
## <ManSection>
## <Filt Name="IsFlistMatrixRep" Arg='obj' Type="representation"/>
##
## <Description>
## An object <A>obj</A> in <Ref Filt="IsFlistMatrixRep"/> describes
## a matrix object that stores the matrix entries as a flat list. It is
## internally represented as a positional object
## (see <Ref Filt="IsPositionalObjectRep"/> that stores 4 entries:
## <Enum>
## <Item>
## its base domain
## (see <Ref Attr="BaseDomain" Label="for a matrix object"/>),
## </Item>
## <Item>
## the number of rows (see <Ref Attr="NumberRows" Label="for a matrix object"/>),
## </Item>
## <Item>
## the number of columns
## (see <Ref Attr="NumberColumns" Label="for a matrix object"/>), and
## </Item>
## <Item>
## a plain list (see <Ref Filt="IsPlistRep"/> of its entries.
## </Item>
## </Enum>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
# Here we declare the new representation and tell GAP which properties it
# implies. FListMatrices e.g. are positional objects and so on.
DeclareRepresentation( "IsFlistMatrixRep",
IsMatrixObj and IsMatrixOrMatrixObj and IsPositionalObjectRep
and IsNoImmediateMethodsObject
and HasNumberRows and HasNumberColumns
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain,
[] );

# If we implement our object a a positional object we often have to access its
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# If we implement our object a a positional object we often have to access its
# If we implement our object as a positional object we often have to access its

# properties in the code. To make that more readable we declare global
# variables. If you do this too make sure you use variables that are unique and
# unlikely to be used someplace else, even though that might mean using longer
# names. Here we prefixed the names with the name of the representation. See
# also Reference Manual Chapter 79 for more information about Objects.

# Some constants for matrix access:
# Position in the positional object of the base domain
BindGlobal( "FLISTREP_BDPOS", 1 );
# Position in the positional object of the number of rows
BindGlobal( "FLISTREP_NRPOS", 2 );
# Position in the positional object of the number of columns
BindGlobal( "FLISTREP_NCPOS", 3 );
# Position in the positional object of the list of entries
BindGlobal( "FLISTREP_ELSPOS", 4 );
Comment on lines +68 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to end files with a newline. Also, we can use BindConstant here for a tiny further speed-up.

Suggested change
BindGlobal( "FLISTREP_BDPOS", 1 );
# Position in the positional object of the number of rows
BindGlobal( "FLISTREP_NRPOS", 2 );
# Position in the positional object of the number of columns
BindGlobal( "FLISTREP_NCPOS", 3 );
# Position in the positional object of the list of entries
BindGlobal( "FLISTREP_ELSPOS", 4 );
BindConstant( "FLISTREP_BDPOS", 1 );
# Position in the positional object of the number of rows
BindConstant( "FLISTREP_NRPOS", 2 );
# Position in the positional object of the number of columns
BindConstant( "FLISTREP_NCPOS", 3 );
# Position in the positional object of the list of entries
BindConstant( "FLISTREP_ELSPOS", 4 );

Loading