"""Authored tiny numeric repeated-index accumulation, no external data."""
import itertools,json,platform
import numpy as np
def checked(indices,weights,size=4):
 if len(indices)!=len(weights) or len(indices)>16:raise ValueError('length')
 if any(type(i) is not int or not 0<=i<size for i in indices):raise ValueError('index')
 if any(type(v) is not int or abs(v)>1000 for v in weights):raise ValueError('weight')
 out=np.zeros(size,dtype=np.int64);np.add.at(out,np.array(indices,dtype=np.intp),np.array(weights,dtype=np.int64));return out.tolist()
def demo():
 idx=[1,1,3];w=[2,3,4];buffered=np.zeros(4,dtype=np.int64);buffered[idx]+=w
 expected=[0]*4
 for i,v in zip(idx,w,strict=True):expected[i]+=v
 actual=checked(idx,w);assert expected==actual==[0,5,0,4] and buffered.tolist()==[0,3,0,4]
 assert checked([],[])==[0,0,0,0]
 cases=0
 for n in range(4):
  for pairs in itertools.product(list(itertools.product(range(4),[1,2])),repeat=n):
   oracle=[0]*4
   for i,value in pairs:oracle[i]+=value
   assert checked([x[0] for x in pairs],[x[1] for x in pairs])==oracle;cases+=1
 assert cases==585 and checked([0,2],[3,-1])==[3,0,-1,0]
 rejects=[]
 for label,a,b in [('negative',[-1],[2]),('boolean',[True],[2]),('outside',[4],[2]),('mismatched',[1,2],[2])]:
  try:checked(a,b)
  except ValueError:rejects.append(label)
  else:raise AssertionError(label)
 return {'runtime':platform.python_version(),'numpy':np.__version__,'indices':idx,'weights':w,'buffered_augmented_assignment':buffered.tolist(),'unbuffered_add_at':actual,'independent_loop':expected,'exhaustive_short_accumulation_cases':cases,'unique_index_signed_weight_case':[3,0,-1,0],'rejected':rejects,'scope':'One-dimensional int64 authored tiny accumulator, nonnegative integer index policy; not view/copy ownership or a general dtype/overflow solution.'}
if __name__=='__main__':print(json.dumps(demo(),ensure_ascii=True,indent=2))
