import ast,json,pathlib,subprocess,time,resource from common1133 import ROOT,SOURCE,guard start=time.process_time();child0=resource.getrusage(resource.RUSAGE_CHILDREN).ru_utime+resource.getrusage(resource.RUSAGE_CHILDREN).ru_stime ns={};nodes=[n for n in ast.parse((SOURCE/'split1090.py').read_text()).body if isinstance(n,ast.FunctionDef) and n.name in ['columns_of','verify']] exec(compile(ast.Module(body=nodes,type_ignores=[]),'served-functions','exec'),ns) class Scalar: def __init__(self,v):self.shape=(1,1);self.indptr=[0,1];self.indices=[0];self.data=[v] def tocsc(self):return self A,E=Scalar(-1),Scalar(1);label=[['normalization',5]] assert guard(ns['verify'],A,E,[1],label,[1],[1]) assert not guard(ns['verify'],Scalar(1),E,[1],label,[-1],[1]) assert not guard(ns['verify'],A,E,[1],label,[1.0],[1]) assert not guard(ns['verify'],A,E,[1],label,[True],[1]) assert not guard(ns['verify'],A,E,[1],label,[],[1]) assert not guard(ns['verify'],A,E,[0],label,[1],[1]) M=[[1,1],[1,-1]];p=101 inp=ROOT/'toy1133.txt';fac=ROOT/'toy-factor1133.txt' inp.write_text('2 4\n0 0 1\n0 1 1\n1 0 1\n1 1 -1\n3 5\n') x=subprocess.run([str(ROOT/'sparse1133'),'factor',str(inp),str(fac),str(p)],capture_output=True,text=True);assert x.returncode==0,x.stderr sol=subprocess.run([str(ROOT/'sparse1133'),'solve',str(fac)],input='3 5\n1 0\n0 1\n',capture_output=True,text=True);assert sol.returncode==0 for row,b in zip(sol.stdout.splitlines(),[[3,5],[1,0],[0,1]]): v=list(map(int,row.split()));assert len(v)==2 assert [sum(a*z for a,z in zip(r,v))%p for r in M]==b sing=ROOT/'singular1133.txt';sing.write_text('2 4\n0 0 1\n0 1 1\n1 0 1\n1 1 1\n1 1\n') x=subprocess.run([str(ROOT/'sparse1133'),'factor',str(sing),str(ROOT/'singular-factor.txt'),str(p)],capture_output=True,text=True);assert x.returncode==3 and 'ZERO_PIVOT' in x.stdout # A corrupted inverse pivot is accepted as input by the solve helper but must be # rejected by the independent residual check, which is the acceptance boundary. lines=fac.read_text().splitlines();a=lines[1].split();a[2]=str((int(a[2])+1)%p);lines[1]=' '.join(a) bad=ROOT/'bad-factor1133.txt';bad.write_text('\n'.join(lines)+'\n') x=subprocess.run([str(ROOT/'sparse1133'),'solve',str(bad)],input='3 5\n',capture_output=True,text=True);v=list(map(int,x.stdout.split()));assert [sum(a*z for a,z in zip(r,v))%p for r in M]!=[3,5] child=resource.getrusage(resource.RUSAGE_CHILDREN) receipt={'cpu_seconds':time.process_time()-start+child.ru_utime+child.ru_stime-child0,'maxrss_bytes':max(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss,child.ru_maxrss)} (ROOT/'controls-receipt1133.json').write_text(json.dumps(receipt,sort_keys=True)+'\n') print('CONTROLS1133 GUARD_VALID1_REJECT5 MODULAR_RHS3 SINGULAR_REJECT CORRUPT_FACTOR_RESIDUAL_REJECT')