partial sum implementation