Skip to content

Commit 0342ca4

Browse files
authored
Merge pull request #723 from zickgraf/finalize
Fix the finalize mess
2 parents df5e4b4 + 9f3a6eb commit 0342ca4

32 files changed

+67
-226
lines changed

ActionsForCAP/gap/ActionsCategory.gi

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ InstallMethod( LeftActionsCategory,
3636
function( acting_object, name, context_filter_list )
3737
local underlying_monoidal_category, preconditions, category_weight_list, i,
3838
structure_record, object_constructor, morphism_constructor,
39-
left_actions_category, identity_of_acting_object, tensor_preserves_epis, finalize;
39+
left_actions_category, identity_of_acting_object, tensor_preserves_epis;
4040

4141
underlying_monoidal_category := CapCategory( acting_object );
4242

@@ -264,11 +264,7 @@ InstallMethod( LeftActionsCategory,
264264

265265
## TODO: Logic for left_actions_category
266266

267-
finalize := CAP_INTERNAL_RETURN_OPTION_OR_DEFAULT( "FinalizeCategory", true );
268-
269-
if finalize = true then
270-
Finalize( left_actions_category );
271-
fi;
267+
Finalize( left_actions_category );
272268

273269
return left_actions_category;
274270

@@ -295,7 +291,7 @@ InstallMethod( RightActionsCategory,
295291
function( acting_object, name, context_filter_list )
296292
local underlying_monoidal_category, preconditions, category_weight_list, i,
297293
structure_record, object_constructor, morphism_constructor,
298-
right_actions_category, identity_of_acting_object, tensor_preserves_epis, finalize;
294+
right_actions_category, identity_of_acting_object, tensor_preserves_epis;
299295

300296
underlying_monoidal_category := CapCategory( acting_object );
301297

@@ -523,11 +519,7 @@ InstallMethod( RightActionsCategory,
523519

524520
## TODO: Logic for right_actions_category
525521

526-
finalize := CAP_INTERNAL_RETURN_OPTION_OR_DEFAULT( "FinalizeCategory", true );
527-
528-
if finalize = true then
529-
Finalize( right_actions_category );
530-
fi;
522+
Finalize( right_actions_category );
531523

532524
return right_actions_category;
533525

ActionsForCAP/gap/CoactionsCategory.gi

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ InstallMethod( LeftCoactionsCategory,
3535
function( coacting_object, name, context_filter_list )
3636
local underlying_monoidal_category, preconditions, category_weight_list, i,
3737
structure_record, object_constructor, morphism_constructor,
38-
left_coactions_category, identity_of_coacting_object, finalize;
38+
left_coactions_category, identity_of_coacting_object;
3939

4040
underlying_monoidal_category := CapCategory( coacting_object );
4141

@@ -242,11 +242,7 @@ InstallMethod( LeftCoactionsCategory,
242242

243243
## TODO: Logic for left_coactions_category
244244

245-
finalize := CAP_INTERNAL_RETURN_OPTION_OR_DEFAULT( "FinalizeCategory", true );
246-
247-
if finalize = true then
248-
Finalize( left_coactions_category );
249-
fi;
245+
Finalize( left_coactions_category );
250246

251247
return left_coactions_category;
252248

@@ -273,7 +269,7 @@ InstallMethod( RightCoactionsCategory,
273269
function( coacting_object, name, context_filter_list )
274270
local underlying_monoidal_category, preconditions, category_weight_list, i,
275271
structure_record, object_constructor, morphism_constructor,
276-
right_coactions_category, identity_of_coacting_object, finalize;
272+
right_coactions_category, identity_of_coacting_object;
277273

278274
underlying_monoidal_category := CapCategory( coacting_object );
279275

@@ -480,11 +476,7 @@ InstallMethod( RightCoactionsCategory,
480476

481477
## TODO: Logic for right_coactions_category
482478

483-
finalize := CAP_INTERNAL_RETURN_OPTION_OR_DEFAULT( "FinalizeCategory", true );
484-
485-
if finalize = true then
486-
Finalize( right_coactions_category );
487-
fi;
479+
Finalize( right_coactions_category );
488480

489481
return right_coactions_category;
490482

ActionsForCAP/gap/SemisimpleCategory.gi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ InstallMethod( SemisimpleCategory,
4747
function( underlying_category, membership_function, membership_function_name )
4848
local name, semisimple_category;
4949

50-
if not HasIsFinalized( underlying_category ) or not IsFinalized( underlying_category ) then
50+
if not IsFinalized( underlying_category ) then
5151

5252
Error( "the underlying category must be finalized" );
5353
return;

CAP/PackageInfo.g

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

1111
PackageName := "CAP",
1212
Subtitle := "Categories, Algorithms, Programming",
13-
Version := "2021.10-03",
13+
Version := "2021.10-04",
1414
Date := Concatenation( "01/", ~.Version{[ 6, 7 ]}, "/", ~.Version{[ 1 .. 4 ]} ),
1515
License := "GPL-2.0-or-later",
1616

CAP/gap/CAP.gi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ InstallGlobalFunction( "CREATE_CAP_CATEGORY_OBJECT",
244244

245245
obj := CallFuncList( ObjectifyWithAttributes, flatted_attribute_list );
246246

247+
SetIsFinalized( obj, false );
248+
247249
obj!.derivations_weight_list := MakeOperationWeightList( obj, CAP_INTERNAL_DERIVATION_GRAPH );
248250

249251
obj!.caches := rec( );

CAP/gap/Finalize.gd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ DeclareGlobalVariable( "CAP_INTERNAL_FINAL_DERIVATION_LIST" );
1111
DeclareGlobalFunction( "AddFinalDerivation" );
1212

1313

14-
DeclareProperty( "IsFinalized",
15-
IsCapCategory );
14+
DeclareAttribute( "IsFinalized",
15+
IsCapCategory,
16+
"mutable" );
1617

1718
DeclareOperation( "Finalize",
1819
[ IsCapCategory ] );

CAP/gap/Finalize.gi

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,21 @@ end );
162162
InstallMethod( Finalize,
163163
[ IsCapCategory ],
164164

165-
IsFinalized );
166-
167-
InstallMethod( IsFinalized,
168-
[ IsCapCategory ],
169-
170165
function( category )
171166
local current_final_derivation, derivation_list, i, n, weight_list, weight, add_name, current_installs, current_tester_func, current_additional_func;
172167

168+
if IsFinalized( category ) then
169+
170+
return true;
171+
172+
fi;
173+
174+
if ValueOption( "FinalizeCategory" ) = false then
175+
176+
return false;
177+
178+
fi;
179+
173180
derivation_list := ShallowCopy( CAP_INTERNAL_FINAL_DERIVATION_LIST.final_derivation_list );
174181

175182
if not category!.is_computable then
@@ -252,6 +259,8 @@ InstallMethod( IsFinalized,
252259

253260
od;
254261

262+
SetIsFinalized( category, true );
263+
255264
return true;
256265

257266
end );

CAP/gap/InstallAdds.gi

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ InstallGlobalFunction( CapInternalInstallAdd,
168168
current_function_argument_number, current_additional_filter_list_length, filter, input_human_readable_identifier_getter, input_sanity_check_functions,
169169
output_human_readable_identifier_getter, output_sanity_check_function, cap_jit_compiled_function;
170170

171-
if HasIsFinalized( category ) and IsFinalized( category ) then
171+
if IsFinalized( category ) then
172172
Error( "cannot add methods anymore, category is finalized" );
173173
fi;
174174

@@ -464,6 +464,15 @@ InstallGlobalFunction( CapInternalInstallAdd,
464464
function( arg )
465465
local redirect_return, pre_func_return, collect_timing_statistics, start_time, result, end_time, i;
466466

467+
if not IsFinalized( category ) then
468+
469+
Display( Concatenation(
470+
"WARNING: You are calling an operation in a unfinalized category with name \"", Name( category ),
471+
"\". This is fine for debugging purposes, but for production use you should finalize the category by calling `Finalize` (with the option `FinalizeCategory := true` if needed)."
472+
) );
473+
474+
fi;
475+
467476
if (redirect_function <> false) and (not IsBound( category!.redirects.( function_name ) ) or category!.redirects.( function_name ) <> false) then
468477
redirect_return := CallFuncList( redirect_function, arg );
469478
if redirect_return[ 1 ] = true then

CAP/gap/OppositeCategory.gi

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ InstallMethod( Opposite,
430430
[ IsCapCategory, IsString ],
431431

432432
function( category, name )
433-
local opposite_category, to_be_finalized;
433+
local opposite_category;
434434

435-
if not HasIsFinalized( category ) or not IsFinalized( category ) then
435+
if not IsFinalized( category ) then
436436
Error( "Input category must be finalized to create opposite category" );
437437
fi;
438438

@@ -554,17 +554,7 @@ InstallMethod( Opposite,
554554

555555
fi;
556556

557-
to_be_finalized := ValueOption( "FinalizeCategory" );
558-
559-
if to_be_finalized = false then
560-
561-
return opposite_category;
562-
563-
else
564-
565-
Finalize( opposite_category );
566-
567-
fi;
557+
Finalize( opposite_category );
568558

569559
return opposite_category;
570560

CAP/gap/ProductCategory.gi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ InstallMethodWithCrispCache( ProductOp,
182182
function( category_list, selector )
183183
local product_category, namestring;
184184

185-
if not ForAll( category_list, HasIsFinalized ) or not ForAll( category_list, IsFinalized ) then
185+
if not ForAll( category_list, IsFinalized ) then
186186
Error( "all categories for the product must be finalized" );
187187
fi;
188188

CompilerForCAP/gap/PrecompileCategory.gi

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ InstallGlobalFunction( "CapJitPrecompileCategory", function ( category_construct
269269
# check that category_constructor supports `FinalizeCategory`
270270
cat := CallFuncList( category_constructor, given_arguments : FinalizeCategory := false, no_precompiled_code := true );
271271

272-
if HasIsFinalized( cat ) then
272+
if IsFinalized( cat ) then
273273

274274
# COVERAGE_IGNORE_NEXT_LINE
275275
Error( "the category constructor must support the option `FinalizeCategory`" );
@@ -548,12 +548,6 @@ InstallGlobalFunction( "CapJitPrecompileCategory", function ( category_construct
548548
" \n",
549549
" ADD_FUNCTIONS_FOR_", compiled_category_name, "( cat );\n",
550550
" \n",
551-
" if ValueOption( \"FinalizeCategory\" ) = false then\n",
552-
" \n",
553-
" return cat;\n",
554-
" \n",
555-
" fi;\n",
556-
" \n",
557551
" Finalize( cat );\n",
558552
" \n",
559553
" return cat;\n",

FreydCategoriesForCAP/gap/AdditiveClosure.gi

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ InstallMethod( AdditiveClosure,
1515
[ IsCapCategory ],
1616

1717
function( underlying_category )
18-
local category, matrix_element_as_morphism, list_list_as_matrix, homalg_ring, precompiled_towers, remaining_constructors_in_tower, precompiled_functions_adder, to_be_finalized, info;
18+
local category, matrix_element_as_morphism, list_list_as_matrix, homalg_ring, precompiled_towers, remaining_constructors_in_tower, precompiled_functions_adder, info;
1919

2020
if not ( HasIsAbCategory( underlying_category ) and IsAbCategory( underlying_category ) ) then
2121

@@ -156,14 +156,6 @@ InstallMethod( AdditiveClosure,
156156

157157
category!.compiler_hints.precompiled_towers := precompiled_towers;
158158

159-
to_be_finalized := ValueOption( "FinalizeCategory" );
160-
161-
if to_be_finalized = false then
162-
163-
return category;
164-
165-
fi;
166-
167159
Finalize( category );
168160

169161
return category;

FreydCategoriesForCAP/gap/AdelmanCategory.gi

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ InstallMethod( AdelmanCategory,
1515
[ IsCapCategory ],
1616

1717
function( underlying_category )
18-
local adelman_category, func, to_be_finalized;
18+
local adelman_category, func;
1919

2020
if not HasIsAdditiveCategory( underlying_category ) then
2121

@@ -68,14 +68,6 @@ InstallMethod( AdelmanCategory,
6868

6969
INSTALL_FUNCTIONS_FOR_ADELMAN_CATEGORY( adelman_category );
7070

71-
to_be_finalized := ValueOption( "FinalizeCategory" );
72-
73-
if to_be_finalized = false then
74-
75-
return adelman_category;
76-
77-
fi;
78-
7971
Finalize( adelman_category );
8072

8173
return adelman_category;

FreydCategoriesForCAP/gap/CategoryOfColumns.gi

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ InstallMethod( CategoryOfColumns,
2020
[ IsHomalgRing ],
2121

2222
function( homalg_ring )
23-
local cat, to_be_finalized;
23+
local cat;
2424

2525
cat := CategoryOfColumnsAsOppositeOfCategoryOfRows( homalg_ring : FinalizeCategory := false );
2626

@@ -42,14 +42,6 @@ InstallMethod( CategoryOfColumns,
4242

4343
fi;
4444

45-
to_be_finalized := ValueOption( "FinalizeCategory" );
46-
47-
if to_be_finalized = false then
48-
49-
return cat;
50-
51-
fi;
52-
5345
Finalize( cat );
5446

5547
return cat;

FreydCategoriesForCAP/gap/CategoryOfColumnsAsOppositeOfCategoryOfRows.gi

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ InstallMethod( CategoryOfColumnsAsOppositeOfCategoryOfRows,
1515
[ IsHomalgRing ],
1616

1717
function( homalg_ring )
18-
local category_of_rows, op, to_be_finalized;
18+
local category_of_rows, op;
1919

2020
category_of_rows := CategoryOfRows( homalg_ring : FinalizeCategory := true );
2121

@@ -114,14 +114,6 @@ InstallMethod( CategoryOfColumnsAsOppositeOfCategoryOfRows,
114114

115115
INSTALL_FUNCTIONS_FOR_CATEGORY_OF_COLUMNS_AS_OPPOSITE_OF_CATEGORY_OF_ROWS( op );
116116

117-
to_be_finalized := ValueOption( "FinalizeCategory" );
118-
119-
if to_be_finalized = false then
120-
121-
return op;
122-
123-
fi;
124-
125117
Finalize( op );
126118

127119
return op;

FreydCategoriesForCAP/gap/CategoryOfGradedRowsAndColumns/CategoryOfGradedColumns.gi

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
InstallMethod( CategoryOfGradedColumns,
1919
[ IsHomalgGradedRing ],
2020
function( homalg_graded_ring )
21-
local category, to_be_finalized;
21+
local category;
2222

2323
# create category
2424
category := CreateCapCategory( Concatenation( "Category of graded columns over ", RingName( homalg_graded_ring ) ) );
@@ -47,14 +47,6 @@ InstallMethod( CategoryOfGradedColumns,
4747

4848
CapCategorySwitchLogicOff( category );
4949

50-
to_be_finalized := ValueOption( "FinalizeCategory" );
51-
52-
if to_be_finalized = false then
53-
54-
return category;
55-
56-
fi;
57-
5850
# finalise it
5951
Finalize( category );
6052

FreydCategoriesForCAP/gap/CategoryOfGradedRowsAndColumns/CategoryOfGradedRows.gi

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
InstallMethod( CategoryOfGradedRows,
1919
[ IsHomalgGradedRing ],
2020
function( homalg_graded_ring )
21-
local category, to_be_finalized;
21+
local category;
2222

2323
# construct the category
2424
category := CreateCapCategory( Concatenation( "Category of graded rows over ", RingName( homalg_graded_ring ) ) );
@@ -47,14 +47,6 @@ InstallMethod( CategoryOfGradedRows,
4747

4848
CapCategorySwitchLogicOff( category );
4949

50-
to_be_finalized := ValueOption( "FinalizeCategory" );
51-
52-
if to_be_finalized = false then
53-
54-
return category;
55-
56-
fi;
57-
5850
# finalise the category
5951
Finalize( category );
6052

0 commit comments

Comments
 (0)