  The accuracy of density-functional theory (DFT) is determined by the quality
of the approximate functionals, such as exchange-correlation in electronic DFT
and the excess functional in the classical DFT formalism of fluids. The exact
functional is highly nonlocal for both electrons and fluids, yet most
approximate functionals are semi-local or nonlocal in a limited
weighted-density form. Machine-learned (ML) nonlocal density-functional
approximations are promising in both electronic and classical DFT, but have so
far employed disparate approaches with limited generality. Here, we formulate a
universal approximation framework and training protocol for nonlocal ML
functionals, combining features of equivariant convolutional neural networks
and the weighted-density approximation. We prototype this approach for several
1D and quasi-1D problems and demonstrate that a functional with exactly the
same hyperparameters achieves excellent accuracy for the hard-rod fluid, the
inhomogeneous Ising model, the exact exchange functional for electrons, the
electron kinetic energy functional for orbital-free DFT, as well as for liquid
water with 1D inhomogeneities. These results lay the foundation for a universal
ML approach to exact 3D functionals spanning electronic and classical DFT.
