
The code provided here (where the workaround for gcd() issue isn't needed anymore, at least in pgfplots 1.18) does:
work if the class used is e.g. article,
not work if the class used is beamer.
Indeed, the compilation of the following MCE:
\documentclass{beamer}
\usepackage{pgfplots}
\pgfplotss...