tensorflow/compiler/mlir/tfrt/jit/python_binding/conversion_utils.cc
// Converts Python array to the Memref Descriptor.
Converts Python array to the Memref Descriptor.
Converts Python array to the Memref Descriptor .
void ConvertPyArrayMemrefDesc(const pybind11::array& array,
                              MemrefDesc* memref) {
  auto py_dtype = [](pybind11::dtype dtype) -> char {
    if (dtype.kind() == 'i' && dtype.itemsize() == 8) return 'q';
    return dtype.char_();
  };
  memref->dtype = DType(FromPythonStructFormat(py_dtype(array.dtype())));
  memref->data = const_cast<void*>(array.data());
  memref->offset = 0;
  auto rank = array.ndim();
  memref->sizes.resize(rank);
  memref->strides.resize(rank);
  for (ssize_t d = 0; d < rank; ++d) {
    memref->sizes[d] = array.shape(d);
    memref->strides[d] = array.strides(d) / array.itemsize();
  }
}
void ConvertPyArrayMemrefDesc ( const pybind11 :: array & array , MemrefDesc * memref ) { auto py_dtype = [ ] ( pybind11 :: dtype dtype ) -> char { if ( dtype . kind ( ) == ' ' && dtype . itemsize ( ) == 8 ) return ' ' ; return dtype . char_ ( ) ; } ; memref -> dtype = DType ( FromPythonStructFormat ( py_dtype ( array . dtype ( ) ) ) ) ; memref -> data = const_cast < void * > ( array . data ( ) ) ; memref -> offset = 0 ; auto rank = array . ndim ( ) ; memref -> sizes . resize ( rank ) ; memref -> strides . resize ( rank ) ; for ( ssize_t d = 0 ; d < rank ; ++ d ) { memref -> sizes [ d ] = array . shape ( d ) ; memref -> strides [ d ] = array . strides ( d ) / array . itemsize ( ) ; } }
Converts Python array to the Memref Descriptor.
Converts Python array to the Memref Descriptor .
// np.int64 array for some reason has `i` dtype, however according to the // documentation it must be `q`.