Avoid a null-pointer dereference in _tri.cpp

Found using the clang static analyzer:
if PyArray_ContiguousFromObject returns NULL,
PyArray_NDIM(x) causes a null-pointer dereference.
Merge pull request #2993 from jkseppan/tri-null-pointer

Avoid a null-pointer dereference in _tri.cpp