Yup I had the same problem the first time it happened the dealer replaced my fuel pump relay and the second time they replaced the egr valve. It stalled once more after the egr valve was replaced but I was too busy and fed up to take it in again and just let it be and it seems to have fixed...
I had the exact same problem took it to the dealer and they called mazda and were told to replace the EGR valve been fine ever since. Their explanation to me was that the valve was getting stuck open which caused the engine to stall and shut off.
Mine stalled out at 1100 km sitting at a stoplight went to get on the gas and no power.... So I took it to the dealer and they replaced my main and fuel pump relays been running fine since