A numerical basis for strain-gradient plasticity theory: Rate-independent and rate-dependent formulations