added torch implementation