Skip to content

Commit 83cccba

Browse files
authored
Merge pull request #699 from zickgraf/compiler_improvements
Improvements to the compiler and to the compilation of CategoryOfColumns
2 parents 36eec44 + 5774adb commit 83cccba

19 files changed

+1258
-393
lines changed

CAP/PackageInfo.g

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,11 @@
99
SetPackageInfo( rec(
1010

1111
PackageName := "CAP",
12-
1312
Subtitle := "Categories, Algorithms, Programming",
14-
15-
Version := Maximum( [
16-
"2021.02-03", ## Mohamed's version
17-
## this line prevents merge conflicts
18-
"2015.04-01", ## Oystein's version
19-
## this line prevents merge conflicts
20-
"2019.06-05", ## Sebas' version
21-
## this line prevents merge conflicts
22-
"2020.04-16", ## Sepp's version
23-
## this line prevents merge conflicts
24-
"2021.07-02", ## Fabian's version
25-
## this line prevents merge conflicts
26-
"2021.05-04", ## Kamal's version
27-
] ),
28-
13+
Version := "2021.08-01",
2914
Date := Concatenation( "01/", ~.Version{[ 6, 7 ]}, "/", ~.Version{[ 1 .. 4 ]} ),
3015
License := "GPL-2.0-or-later",
3116

32-
3317
Persons := [
3418
rec(
3519
IsAuthor := true,

CAP/gap/OppositeCategory.gi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,14 @@ end );
145145
BindGlobal( "CAP_INTERNAL_INSTALL_OPPOSITE_ADDS_FROM_CATEGORY",
146146

147147
function( opposite_category, category )
148-
local recnames, current_recname, current_entry, dual_operation_name,
148+
local only_primitive_operations, recnames, current_recname, current_entry, dual_operation_name,
149149
filter_list, input_arguments_names, return_type, func_string,
150150
dual_preprocessor_func_string, preprocessor_string, dual_arguments,
151151
dual_postprocessor_func_string, postprocessor_string, output_source_getter_string, output_range_getter_string, return_statement,
152152
func, current_add, list_of_attributes, attr, tester, setter, getter;
153153

154+
only_primitive_operations := ValueOption( "only_primitive_operations" ) = true;
155+
154156
recnames := RecNames( CAP_INTERNAL_METHOD_NAME_RECORD );
155157

156158
for current_recname in recnames do
@@ -187,6 +189,10 @@ BindGlobal( "CAP_INTERNAL_INSTALL_OPPOSITE_ADDS_FROM_CATEGORY",
187189
continue;
188190
fi;
189191

192+
if only_primitive_operations and not dual_operation_name in ListPrimitivelyInstalledOperationsOfCategory( category ) then
193+
continue;
194+
fi;
195+
190196
if current_entry.filter_list[1] <> "category" then
191197

192198
Display( Concatenation(

CompilerForCAP/PackageInfo.g

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ SetPackageInfo( rec(
1010

1111
PackageName := "CompilerForCAP",
1212
Subtitle := "Speed up computations in CAP categories",
13-
Version := Maximum( [
14-
"2021.07-01", ## Fabian's version
15-
## this line prevents merge conflicts
16-
] ),
13+
Version := "2021.08-01",
1714
Date := Concatenation( "01/", ~.Version{[ 6, 7 ]}, "/", ~.Version{[ 1 .. 4 ]} ),
1815
License := "GPL-2.0-or-later",
1916

CompilerForCAP/examples/PrecompileCategoryOfColumnsOfField.g

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,14 @@ category_constructor :=
1414
given_arguments := [ QQ ];;
1515
compiled_category_name := "CategoryOfColumnsOfFieldPrecompiled";;
1616
package_name := "FreydCategoriesForCAP";;
17-
operations := Intersection(
18-
ListPrimitivelyInstalledOperationsOfCategory( CategoryOfColumns( QQ ) ),
19-
CAP_JIT_INTERNAL_SAFE_OPERATIONS
20-
);;
21-
operations := Filtered(
22-
operations,
23-
o -> PositionSublist( o, "HomomorphismStructure" ) = fail
24-
);;
17+
operations := "primitive";;
2518

26-
filepath :=
27-
"precompiled_categories/CategoryOfColumnsOfFieldPrecompiled.gi";;
28-
old_file_content := ReadFileFromPackageForHomalg( package_name, filepath );;
29-
30-
CapJitPrecompileCategory(
19+
CapJitPrecompileCategoryAndCompareResult(
3120
category_constructor,
3221
given_arguments,
3322
package_name,
3423
compiled_category_name :
3524
operations := operations
36-
);
37-
38-
new_file_content := ReadFileFromPackageForHomalg( package_name, filepath );;
39-
40-
old_file_content = new_file_content;
41-
#! true
25+
);;
4226

4327
#! @EndExample

CompilerForCAP/examples/PrecompileLinearAlgebraForCAP.g

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,13 @@ operations := Difference( operations, [ "IsIdenticalToZeroMorphism" ] );;
4747
operations := Difference( operations, [ "IsZeroForMorphisms" ] );;
4848
Add( operations, "DirectSumFunctorialWithGivenDirectSums" );
4949

50-
filepath := "precompiled_categories/MatrixCategoryPrecompiled.gi";;
51-
old_file_content := ReadFileFromPackageForHomalg( package_name, filepath );;
52-
53-
CapJitPrecompileCategory(
50+
CapJitPrecompileCategoryAndCompareResult(
5451
category_constructor,
5552
given_arguments,
5653
package_name,
5754
compiled_category_name :
5855
operations := operations
59-
);
60-
61-
new_file_content := ReadFileFromPackageForHomalg( package_name, filepath );;
62-
63-
old_file_content = new_file_content;
64-
#! true
56+
);;
6557

6658
MatrixCategoryPrecompiled( QQ );
6759
#! Category of matrices over Q

CompilerForCAP/examples/PrecompileOppositeOfCategoryOfRowsOfField.g

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,14 @@ category_constructor :=
1414
given_arguments := [ QQ ];;
1515
compiled_category_name := "OppositeOfCategoryOfRowsOfFieldPrecompiled";;
1616
package_name := "FreydCategoriesForCAP";;
17-
operations := Intersection(
18-
ListPrimitivelyInstalledOperationsOfCategory( CategoryOfColumns( QQ ) ),
19-
CAP_JIT_INTERNAL_SAFE_OPERATIONS
20-
);;
21-
operations := Filtered(
22-
operations,
23-
o -> PositionSublist( o, "HomomorphismStructure" ) = fail
24-
);;
17+
operations := "primitive";;
2518

26-
filepath :=
27-
"precompiled_categories/OppositeOfCategoryOfRowsOfFieldPrecompiled.gi";;
28-
old_file_content := ReadFileFromPackageForHomalg( package_name, filepath );;
29-
30-
CapJitPrecompileCategory(
19+
CapJitPrecompileCategoryAndCompareResult(
3120
category_constructor,
3221
given_arguments,
3322
package_name,
3423
compiled_category_name :
3524
operations := operations
36-
);
37-
38-
new_file_content := ReadFileFromPackageForHomalg( package_name, filepath );;
39-
40-
old_file_content = new_file_content;
41-
#! true
25+
);;
4226

4327
#! @EndExample

CompilerForCAP/examples/PrecompileOppositeOfLinearAlgebraForCAP.g

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,13 @@ operations := Intersection(
2828
# https://github.com/gap-system/gap/issues/4523
2929
operations := Difference( operations, [ "LiftOrFail", "ColiftOrFail" ] );;
3030

31-
filepath := "precompiled_categories/OppositeOfMatrixCategoryPrecompiled.gi";;
32-
old_file_content := ReadFileFromPackageForHomalg( package_name, filepath );;
33-
34-
CapJitPrecompileCategory(
31+
CapJitPrecompileCategoryAndCompareResult(
3532
category_constructor,
3633
given_arguments,
3734
package_name,
3835
compiled_category_name :
3936
operations := operations
40-
);
41-
42-
new_file_content := ReadFileFromPackageForHomalg( package_name, filepath );;
43-
44-
old_file_content = new_file_content;
45-
#! true
37+
);;
4638

4739
ReadPackage(
4840
"LinearAlgebraForCAP",

CompilerForCAP/gap/PrecompileCategory.gd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
#! * Only categories with a zero object and zero morphisms can be compiled.
2525
#! * Not all CAP operations are available for compilation.
2626
#! * `WithGiven` operations can only be compiled if the object operation is computable.
27-
#! @Returns a record
2827
#! @Arguments category_constructor, given_arguments, package_name, compiled_category_name
2928
DeclareGlobalFunction( "CapJitPrecompileCategory" );
29+
30+
#! @Description
31+
#! Calls <Ref Func="CapJitPrecompileCategory" /> with the given arguments and displays a warning if this changes the contents of
32+
#! <A>package_name</A>`/precompiled_categories/`<A>compiled_category_name</A>`.gi`.
33+
#! @Arguments category_constructor, given_arguments, package_name, compiled_category_name
34+
DeclareGlobalFunction( "CapJitPrecompileCategoryAndCompareResult" );

CompilerForCAP/gap/PrecompileCategory.gi

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ InstallGlobalFunction( "CapJitPrecompileCategory", function ( category_construct
293293

294294
if ValueOption( "operations" ) = fail then
295295

296-
operations := Intersection( ListInstalledOperationsOfCategory( cat ) );
296+
operations := ListInstalledOperationsOfCategory( cat );
297+
298+
elif ValueOption( "operations" ) = "primitive" then
299+
300+
operations := ListPrimitivelyInstalledOperationsOfCategory( cat );
297301

298302
else
299303

@@ -479,6 +483,12 @@ InstallGlobalFunction( "CapJitPrecompileCategory", function ( category_construct
479483
od;
480484

481485
current_string := Concatenation(
486+
" \n",
487+
" if ValueOption( \"FinalizeCategory\" ) = false then\n",
488+
" \n",
489+
" return cat;\n",
490+
" \n",
491+
" fi;\n",
482492
" \n",
483493
" Finalize( cat );\n",
484494
" \n",
@@ -491,3 +501,45 @@ InstallGlobalFunction( "CapJitPrecompileCategory", function ( category_construct
491501
WriteFileInPackageForHomalg( package_name, Concatenation( "precompiled_categories/", compiled_category_name, ".gi" ), output_string );
492502

493503
end );
504+
505+
InstallGlobalFunction( "CapJitPrecompileCategoryAndCompareResult", function ( category_constructor, given_arguments, package_name, compiled_category_name )
506+
local filepath, dirs, complete_path, old_file_content, new_file_content;
507+
508+
filepath := Concatenation( "precompiled_categories/", compiled_category_name, ".gi" );
509+
510+
dirs := DirectoriesPackageLibrary( package_name, "gap" );
511+
512+
if Length( dirs ) <> 1 then
513+
514+
Error( Concatenation( "could not find gap directory of package ", package_name ) );
515+
516+
fi;
517+
518+
complete_path := Filename( dirs[1], filepath );
519+
520+
if IsExistingFile( complete_path ) then
521+
522+
old_file_content := ReadFileFromPackageForHomalg( package_name, filepath );
523+
524+
else
525+
526+
old_file_content := "";
527+
528+
fi;
529+
530+
CapJitPrecompileCategory(
531+
category_constructor,
532+
given_arguments,
533+
package_name,
534+
compiled_category_name
535+
);
536+
537+
new_file_content := ReadFileFromPackageForHomalg( package_name, filepath );
538+
539+
if old_file_content <> new_file_content then
540+
541+
Display( "WARNING: old and new file contents differ" );
542+
543+
fi;
544+
545+
end );

FreydCategoriesForCAP/PackageInfo.g

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,10 @@ SetPackageInfo( rec(
1010

1111
PackageName := "FreydCategoriesForCAP",
1212
Subtitle := "Freyd categories - Formal (co)kernels for additive categories",
13-
Version := Maximum( [
14-
"2019.03-04", ## Martin's version
15-
## this line prevents merge conflicts
16-
"2020.09-21", ## Sepp's version
17-
## this line prevents merge conflicts
18-
"2020.05-17", ## Mohamed's version
19-
## this line prevents merge conflicts
20-
"2021.07-03", ## Fabian's version
21-
## this line prevents merge conflicts
22-
"2020.04-18", ## Kamal's version
23-
] ),
13+
Version := "2021.08-01",
2414
Date := Concatenation( "01/", ~.Version{[ 6, 7 ]}, "/", ~.Version{[ 1 .. 4 ]} ),
2515
License := "GPL-2.0-or-later",
2616

27-
2817
Persons := [
2918
rec(
3019
IsAuthor := true,
@@ -99,7 +88,7 @@ PackageDoc := rec(
9988
Dependencies := rec(
10089
GAP := ">= 4.8",
10190
NeededOtherPackages := [ [ "GAPDoc", ">= 1.5" ],
102-
[ "CAP", ">= 2021.06-02" ],
91+
[ "CAP", ">= 2021.08-01" ],
10392
[ "MatricesForHomalg", ">= 2021.07-01" ],
10493
[ "GradedRingForHomalg", ">=2019.08.07" ],
10594
[ "LinearAlgebraForCAP", ">= 2020.05.16" ],

0 commit comments

Comments
 (0)