Add least-squares function by cpp