torch/csrc/autograd/python_variable_indexing.cpp
// We allow indexing by integers, slices, ellipsis, None, Variables,
// and tuples of those types. We also handle bools as if they were a
// Variable[ByteTensor].
We allow indexing by integers, slices, ellipsis, None, Variables,
and tuples of those types. We also handle bools as if they were a
Variable[ByteTensor].
We allow indexing by integers slices ellipsis None Variables and tuples of those types . We also handle bools as if they were a Variable [ ByteTensor ] .
static int64_t count_specified_dimensions(PyObject* index) {
  int64_t count = 0;
  auto size = PyTuple_GET_SIZE(index);
  for (Py_ssize_t i = 0; i < size; i++) {
    PyObject* obj = PyTuple_GET_ITEM(index, i);
    if (THPVariable_Check(obj)) {
      auto& var = reinterpret_cast<THPVariable*>(obj)->cdata;
      if (var.type().scalarType() == kByte) {
        count += var.dim();
      } else {
        count++;
      }
    } else if (obj != Py_None && obj != Py_Ellipsis && obj != Py_True && obj != Py_False) {
      count++;
    }
  }
  return count;
}
static int64_t count_specified_dimensions ( PyObject * index ) { int64_t count = 0 ; auto size = PyTuple_GET_SIZE ( index ) ; for ( Py_ssize_t i = 0 ; i < size ; i ++ ) { PyObject * obj = PyTuple_GET_ITEM ( index , i ) ; if ( THPVariable_Check ( obj ) ) { auto & var = reinterpret_cast < THPVariable * > ( obj ) -> cdata ; if ( var . type ( ) . scalarType ( ) == kByte ) { count += var . dim ( ) ; } else { count ++ ; } } else if ( obj != Py_None && obj != Py_Ellipsis && obj != Py_True && obj != Py_False ) { count ++ ; } } return count ; }
We allow indexing by integers, slices, ellipsis, None, Variables,
and tuples of those types.
We allow indexing by integers slices ellipsis None Variables and tuples of those types .
// Count the number of indexed dimensions (everything but ellipsis and None)