28#include <pybind11/pybind11.h> 
   31#include "utils/memory_overlap.hpp" 
   32#include "utils/output_validation.hpp" 
   34namespace dpnp::extensions::lapack::evd
 
   36namespace py = pybind11;
 
   38inline void common_evd_checks(sycl::queue &exec_q,
 
   39                              const dpctl::tensor::usm_ndarray &eig_vecs,
 
   40                              const dpctl::tensor::usm_ndarray &eig_vals,
 
   41                              const py::ssize_t *eig_vecs_shape,
 
   42                              const int expected_eig_vecs_nd,
 
   43                              const int expected_eig_vals_nd)
 
   45    const int eig_vecs_nd = eig_vecs.get_ndim();
 
   46    const int eig_vals_nd = eig_vals.get_ndim();
 
   48    if (eig_vecs_nd != expected_eig_vecs_nd) {
 
   49        throw py::value_error(
"The output eigenvectors array has ndim=" +
 
   50                              std::to_string(eig_vecs_nd) + 
", but a " +
 
   51                              std::to_string(expected_eig_vecs_nd) +
 
   52                              "-dimensional array is expected.");
 
   54    else if (eig_vals_nd != expected_eig_vals_nd) {
 
   55        throw py::value_error(
"The output eigenvalues array has ndim=" +
 
   56                              std::to_string(eig_vals_nd) + 
", but a " +
 
   57                              std::to_string(expected_eig_vals_nd) +
 
   58                              "-dimensional array is expected.");
 
   61    if (eig_vecs_shape[0] != eig_vecs_shape[1]) {
 
   62        throw py::value_error(
"Output array with eigenvectors must be square");
 
   65    dpctl::tensor::validation::CheckWritable::throw_if_not_writable(eig_vecs);
 
   66    dpctl::tensor::validation::CheckWritable::throw_if_not_writable(eig_vals);
 
   69    if (!dpctl::utils::queues_are_compatible(exec_q, {eig_vecs, eig_vals})) {
 
   70        throw py::value_error(
 
   71            "Execution queue is not compatible with allocation queues");
 
   74    auto const &overlap = dpctl::tensor::overlap::MemoryOverlap();
 
   75    if (overlap(eig_vecs, eig_vals)) {
 
   76        throw py::value_error(
"Arrays with eigenvectors and eigenvalues are " 
   77                              "overlapping segments of memory");
 
   80    const bool is_eig_vecs_f_contig = eig_vecs.is_f_contiguous();
 
   81    const bool is_eig_vals_c_contig = eig_vals.is_c_contiguous();
 
   82    if (!is_eig_vecs_f_contig) {
 
   83        throw py::value_error(
 
   84            "An array with input matrix / output eigenvectors " 
   85            "must be F-contiguous");
 
   87    else if (!is_eig_vals_c_contig) {
 
   88        throw py::value_error(
 
   89            "An array with output eigenvalues must be C-contiguous");