newton_generic: use templated typedefs for Newton, etc.
cmake: use -O3 and -march=native for Release mode
check_output: minor improvements
main: add a template parameter to apply_newton