An integrated photonics computing system implements a residue number system (RNS) to achieve orders of magnitude improvements in computational speed per watt over the current state-of-the-art. RNS and nanophotonics have a natural affinity where most operations can be achieved as spatial routing using electrically controlled directional coupler switches, thereby giving rise to an innovative processing-in-network (PIN) paradigm. The system provides a path for attojoule-per-bit efficient and fast electro-optic switching devices, and uses them to develop optical compute engines based on residue arithmetic leading to multi-purpose nanophotonic computing.