MAINT: fix usage of deprecated Numpy C API in optimize...

... and silence build warnings by defining ``NPY_NO_DEPRECATED_API``.