Bouchard edges Sharapova in Madrid epic