Gravar-mail: Algorithm for Training Neural Networks on Resistive Device Arrays