tensorflow/python/lib/core/py_func.cc
// Givens the 'call', prepares the token and inputs as a python tuple
// that is appropriate for calling the trampoline.
Givens the 'call', prepares the token and inputs as a python tuple
that is appropriate for calling the trampoline.
Givens the ' call ' prepares the token and inputs as a python tuple that is appropriate for calling the trampoline .
Status MakeArgTuple(const PyCall* call, TFE_Context* ctx, PyObject** tuple) {
  int64_t n = call->ins.size();
  PyObject* lst = PyList_New(n);
  CHECK(lst);
   Set device name to be empty if the device is CPU.
  const char* device_name = nullptr;
  if (call->device != nullptr && !IsCPUDevice(call->device))
    device_name = call->device->name().c_str();
  for (int64_t i = 0; i < n; ++i) {
    PyObject* arg = nullptr;
    if (call->eager) {
      Tensor t = call->ins[i];
      arg = EagerTensorFromHandle(tensorflow::wrap(
          tensorflow::unwrap(ctx)->CreateLocalHandleFromTFTensor(t,
                                                                 device_name)));
      if (arg == nullptr) {
        Py_DECREF(lst);
        return errors::Internal("Unable to procure EagerTensor from Tensor.");
      }
    } else {
      Status s = TensorToNdarray(call->ins[i], &arg);
      if (!s.ok()) {
        Py_DECREF(lst);
        return s;
      }
      arg = PyArray_Return(reinterpret_cast<PyArrayObject*>(arg));
    }
    PyList_SetItem(lst, i, arg);
  }
  *tuple = Py_BuildValue("(ssN)", call->token.c_str(), device_name, lst);
  CHECK(*tuple);
  return Status::OK();
}
Status MakeArgTuple ( const PyCall * call , TFE_Context * ctx , PyObject * * tuple ) { int64_t n = call -> ins . size ( ) ; PyObject * lst = PyList_New ( n ) ; CHECK ( lst ) ; const char * device_name = nullptr ; if ( call -> device != nullptr && ! IsCPUDevice ( call -> device ) ) device_name = call -> device -> name ( ) . c_str ( ) ; for ( int64_t i = 0 ; i < n ; ++ i ) { PyObject * arg = nullptr ; if ( call -> eager ) { Tensor t = call -> ins [ i ] ; arg = EagerTensorFromHandle ( tensorflow :: wrap ( tensorflow :: unwrap ( ctx ) -> CreateLocalHandleFromTFTensor ( t , device_name ) ) ) ; if ( arg == nullptr ) { Py_DECREF ( lst ) ; return errors :: Internal ( " " ) ; } } else { Status s = TensorToNdarray ( call -> ins [ i ] , & arg ) ; if ( ! s . ok ( ) ) { Py_DECREF ( lst ) ; return s ; } arg = PyArray_Return ( reinterpret_cast < PyArrayObject * > ( arg ) ) ; } PyList_SetItem ( lst , i , arg ) ; } * tuple = Py_BuildValue ( " " , call -> token . c_str ( ) , device_name , lst ) ; CHECK ( * tuple ) ; return Status :: OK ( ) ; }
Givens the 'call', prepares the token and inputs as a python tuple
that is appropriate for calling the trampoline.
Givens the ' call ' prepares the token and inputs as a python tuple that is appropriate for calling the trampoline .
// TFE_TensorHandle assumes that CPU is identified by nullptr. // // Set device name to be empty if the device is CPU.