TVM  0.9.4
matrix.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <tvm/internal/meta.h>
6 
7 #include <Eigen/Core>
8 
9 namespace tvm::diagnostic
10 {
17 template<typename MatrixOrMapType>
18 inline bool isInMatrix(typename MatrixOrMapType::Scalar const * ptr, MatrixOrMapType & M)
19 {
20  if constexpr(MatrixOrMapType::IsRowMajor)
21  {
22  static_assert(::tvm::internal::always_false<MatrixOrMapType>::value, "Only implemented for column-major matrices");
23  }
24  else
25  {
26  auto d = ptr - M.data();
27  if(d < 0)
28  return false;
29 
30  // within the column number
31  if(d >= M.cols() * M.colStride())
32  return false;
33 
34  // position in column
35  auto r = (d % M.colStride());
36  if(r >= M.rows() * M.rowStride())
37  return false;
38 
39  return (r % M.rowStride() == 0);
40  }
41 }
42 
47 template<typename MatrixT, typename MatrixOrMapType>
48 inline bool isInMatrix(const MatrixT & A, Eigen::Index i, Eigen::Index j, MatrixOrMapType & M)
49 { return isInMatrix(&A.coeff(i, j), M); }
50 
52 template<typename Derived>
53 inline bool hasElemAbsInRange(const Eigen::MatrixBase<Derived> & A,
54  typename Derived::Scalar emin,
55  typename Derived::Scalar emax)
56 { return (A.array().abs() >= emin && A.array().abs() <= emax).any(); }
57 
58 } // namespace tvm::diagnostic
Definition: meta.h:91
Definition: GraphProbe.h:26
bool isInMatrix(typename MatrixOrMapType::Scalar const *ptr, MatrixOrMapType &M)
Definition: matrix.h:18
bool hasElemAbsInRange(const Eigen::MatrixBase< Derived > &A, typename Derived::Scalar emin, typename Derived::Scalar emax)
Definition: matrix.h:53