File: sparselist.gd

package info (click to toggle)
gap 4r8p6-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 33,476 kB
  • ctags: 7,663
  • sloc: ansic: 108,841; xml: 47,807; sh: 3,628; perl: 2,342; makefile: 796; asm: 62; awk: 6
file content (103 lines) | stat: -rw-r--r-- 3,821 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#############################################################################
##
#W  sparselist.gd               GAP library                      Steve Linton
##
##
#Y  Copyright (C)  1996,  Lehrstuhl D für Mathematik,  RWTH Aachen,  Germany
#Y  (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
#Y  Copyright (C) 2002 The GAP Group
##
##  This file declares the operations for sparse lists
##



#############################################################################
##
#O  SparseStructureOfList( <list> )
##
##  This operation returns a sparse structure of <list>
##  The return value is a length three list, of which the first
##  position may or may not be bound. If bound, it is the default
##  value, if not bound, the default is to be unbound. The default value
##  must by immutable
##
##  The second entry is a dense duplicate-free list of integers
##  between  1 and Length(<list>) inclusive, representing the
##  positions where non-default entries may appear. 
##
##  The third entry is a list not longer than the second entry, giving 
##  the values that appear in the positions given in the second
##  entry. Holes in this list represent holes in the original list.
##
##  The second and third entries may be mutable (to avoid copying in
##  time-critical code) but should not be changed.
##

DeclareOperation( "SparseStructureOfList", [IsList]);

#############################################################################
##
#F  IsSparseList( <l> )
##
##  A sparse list is a list for which the sparse structure and corresponding
##  sparse methods should be used.
##
##  The filter is ranked up so that sparse list methods will beat
##  competing methods for finite, homogenous, etc. lists, which is
##  usually right
##

DeclareFilter( "IsSparseList", IsList );
RANK_FILTERS[FLAG1_FILTER(IsSparseList)] := 20;

#############################################################################
##
#F  SparseListBySortedList  ( <poss>, <vals>, <len>, <default> )
#F  SparseListBySortedListNC( <poss>, <vals>, <len>, <default> )
##
##  These two functions can be used to create homogeneous sparse
##  lists, in a representation where the positions are stored as a
##  sorted list and the values as a corresponding list. These lists
##  must be dense.
##
##  The NC version refrains from both checking and copying its arguments
##  The non-NC version makes a shallow copy of <poss> and <vals>
##

DeclareGlobalFunction( "SparseListBySortedList");
DeclareGlobalFunction( "SparseListBySortedListNC");

#############################################################################
##
#P IsSparseRowVector( <sl> ) 
##
##  A sparse list is a sparse row vector if it is dense and its default value 
##  is a common Zero of all its non-default values
##  

DeclareProperty( "IsSparseRowVector", IsSparseList);
InstallTrueMethod( IsRowVector, IsSparseRowVector );
InstallTrueMethod( IsHomogeneousList, IsSparseRowVector );
InstallTrueMethod( IsCollection, IsSparseRowVector );

#############################################################################
##
#F  SparseVectorBySortedList  ( <poss>, <vals>, <len>[, <zero>] )
#F  SparseVectorBySortedListNC( <poss>, <vals>, <len>[, <zero>])
##
##  These two functions can be used to create sparse row vectors using
##  the SparseListBySortedList representation, but knowing a priori
##  that they are sparse row vectors. The optional <zero> argument is
##  needed only when <poss> and <vals> are empty.
##
##  The NC version refrains from both checking and copying its arguments
##  The non-NC version makes a shallow copy of <poss> and <vals>
##

DeclareGlobalFunction( "SparseVectorBySortedList");
DeclareGlobalFunction( "SparseVectorBySortedListNC");

#############################################################################
##
#E