@@ -330,45 +330,54 @@ def to_block_files(m, fn):
330
330
is_varblock_0 = varblocks == 0
331
331
is_conblock_L = conblocks == N + 1
332
332
333
- for key , suffix in zip (["labels" , "coeffs" , "vars" ], ["row" , "data" , "col" ]):
333
+ keys = ["labels" , "coeffs" , "vars" ]
334
+
335
+ def filtered (arr , mask , key ):
336
+ """
337
+ Set coefficients to zero for mask, keep others unchanged.
338
+
339
+ PIPS requires this information to set the shape of sub-matrices.
340
+ """
341
+ assert key in keys
342
+ if key == "coeffs" :
343
+ return np .where (mask , arr , 0 )
344
+ return arr
345
+
346
+ for key , suffix in zip (keys , ["row" , "data" , "col" ]):
334
347
arr = cons .ravel (key , "vars" , filter_missings = True )
335
348
for n in tqdm (range (N + 1 ), desc = f"Write constraint { key } " ):
336
349
337
350
is_conblock_n = conblocks == n
338
351
is_varblock_n = varblocks == n
339
352
340
- mask = is_conblock_n & is_varblock_0
341
- arr [mask & is_equality ].tofile (path / f"block{ n } " / f"A_{ suffix } " , sep = "\n " )
342
- arr [mask & ~ is_equality ].tofile (
353
+ mask = is_conblock_n & is_equality
354
+ filtered (arr [mask ], is_varblock_0 [mask ], key ).tofile (
355
+ path / f"block{ n } " / f"A_{ suffix } " , sep = "\n "
356
+ )
357
+ mask = is_conblock_n & ~ is_equality
358
+ filtered (arr [mask ], is_varblock_0 [mask ], key ).tofile (
343
359
path / f"block{ n } " / f"C_{ suffix } " , sep = "\n "
344
360
)
345
361
346
- mask = is_conblock_L & is_varblock_n
347
- arr [mask & is_equality ] .tofile (
362
+ mask = is_conblock_L & is_equality
363
+ filtered ( arr [mask ], is_varblock_n [ mask ], key ) .tofile (
348
364
path / f"block{ n } " / f"BL_{ suffix } " , sep = "\n "
349
365
)
350
- arr [mask & ~ is_equality ].tofile (
366
+ mask = is_conblock_L & ~ is_equality
367
+ filtered (arr [mask ], is_varblock_n [mask ], key ).tofile (
351
368
path / f"block{ n } " / f"DL_{ suffix } " , sep = "\n "
352
369
)
353
370
354
371
if n :
355
- mask = is_conblock_n & is_varblock_n
356
- arr [mask & is_equality ] .tofile (
372
+ mask = is_conblock_n & is_equality
373
+ filtered ( arr [mask ], is_varblock_n [ mask ], key ) .tofile (
357
374
path / f"block{ n } " / f"B_{ suffix } " , sep = "\n "
358
375
)
359
- arr [mask & ~ is_equality ].tofile (
376
+ mask = is_conblock_n & ~ is_equality
377
+ filtered (arr [mask ], is_varblock_n [mask ], key ).tofile (
360
378
path / f"block{ n } " / f"D_{ suffix } " , sep = "\n "
361
379
)
362
380
363
- if key == "labels" :
364
- mask = is_conblock_n & is_equality
365
- all_rows = np .sort (np .unique (arr [mask ]))
366
- all_rows .tofile (path / f"block{ n } " / "A-B_rows" , sep = "\n " )
367
-
368
- mask = is_conblock_n & ~ is_equality
369
- all_rows = np .sort (np .unique (arr [mask ]))
370
- all_rows .tofile (path / f"block{ n } " / "C-D_rows" , sep = "\n " )
371
-
372
381
373
382
def non_bool_dict (d ):
374
383
"""
0 commit comments