static int64_t count_specified_dimensions(PyObject* index) {
// Count the number of indexed dimensions (everything but ellipsis and None)
int64_t count = 0;
- auto size = PyTuple_GET_SIZE(index);
+ auto size = PyTuple_GET_SIZE(index); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
for (Py_ssize_t i = 0; i < size; i++) {
- PyObject* obj = PyTuple_GET_ITEM(index, i);
+ PyObject* obj = PyTuple_GET_ITEM(index, i); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
if (THPVariable_Check(obj)) {
auto& var = reinterpret_cast<THPVariable*>(obj)->cdata;
if (var.type().scalarType() == kByte) {
} else {
count++;
}
- } else if (obj != Py_None && obj != Py_Ellipsis && obj != Py_True && obj != Py_False) {
+ } else if (obj != Py_None && obj != Py_Ellipsis && obj != Py_True && obj != Py_False) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
count++;
}
}
}
static Variable applySlicing(const Variable& self, PyObject* index, variable_list& outIndices) {
- int64_t size = PyTuple_GET_SIZE(index);
+ int64_t size = PyTuple_GET_SIZE(index); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
int64_t dim = 0;
int64_t specified_dims = count_specified_dimensions(index);
Variable result = self;
for (int64_t i = 0; i < size; i++) {
- PyObject* obj = PyTuple_GET_ITEM(index, i);
+ PyObject* obj = PyTuple_GET_ITEM(index, i); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
if (THPUtils_checkLong(obj)) {
result = applySelect(result, dim, THPUtils_unpackLong(obj));
} else if (PySlice_Check(obj)) {
dim++;
} else if (PyBool_Check(obj)) {
result = result.unsqueeze(dim);
- handle_var(boolToIndexingTensor(result, obj == Py_True));
+ handle_var(boolToIndexingTensor(result, obj == Py_True)); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
} else if (THPVariable_Check(obj)) {
auto& var = THPVariable_Unpack(obj);
auto scalar_type = var.type().scalarType();
if (treatSequenceAsTuple(index)) {
res = PySequence_Tuple(index);
} else {
- res = PyTuple_Pack(1, index);
+ res = PyTuple_Pack(1, index); // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
}
if (!res) throw python_error();
return res;
auto value = valueToTensor(self_.type(), py_value);
// handle simple types: integers, slices, ellipsis, bool
- if (index == Py_False) {
+ if (index == Py_False) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
// do nothing for false (technically we should check the size, but we don't have
// real 0-sized shapes.
return 0;
} else if (index == Py_Ellipsis) {
copy_to(self_, value);
return 0;
- } else if (index == Py_None || index == Py_True) {
+ } else if (index == Py_None || index == Py_True) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast)
copy_to(self_.unsqueeze(0), value);
return 0;
} else if (THPUtils_checkLong(index)) {