Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
pcmoritz committed Aug 18, 2017
1 parent 95cb9da commit aa1f300
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 37 deletions.
46 changes: 23 additions & 23 deletions cpp/src/arrow/python/arrow_to_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,26 @@ Status GetValue(std::shared_ptr<Array> arr, int32_t index, int32_t type, PyObjec
return Status::OK();
}

#define DESERIALIZE_SEQUENCE(CREATE_FN, SET_ITEM_FN) \
auto data = std::dynamic_pointer_cast<UnionArray>(array); \
int32_t size = array->length(); \
ScopedRef result(CREATE_FN(stop_idx - start_idx)); \
auto types = std::make_shared<Int8Array>(size, data->type_ids()); \
auto offsets = std::make_shared<Int32Array>(size, data->value_offsets()); \
for (int32_t i = start_idx; i < stop_idx; ++i) { \
if (data->IsNull(i)) { \
Py_INCREF(Py_None); \
SET_ITEM_FN(result.get(), i - start_idx, Py_None); \
} else { \
int32_t offset = offsets->Value(i); \
int8_t type = types->Value(i); \
std::shared_ptr<Array> arr = data->child(type); \
PyObject* value; \
RETURN_NOT_OK(GetValue(arr, offset, type, base, tensors, &value)); \
SET_ITEM_FN(result.get(), i - start_idx, value); \
} \
} \
*out = result.release(); \
#define DESERIALIZE_SEQUENCE(CREATE_FN, SET_ITEM_FN) \
auto data = std::dynamic_pointer_cast<UnionArray>(array); \
int32_t size = array->length(); \
ScopedRef result(CREATE_FN(stop_idx - start_idx)); \
auto types = std::make_shared<Int8Array>(size, data->type_ids()); \
auto offsets = std::make_shared<Int32Array>(size, data->value_offsets()); \
for (int32_t i = start_idx; i < stop_idx; ++i) { \
if (data->IsNull(i)) { \
Py_INCREF(Py_None); \
SET_ITEM_FN(result.get(), i - start_idx, Py_None); \
} else { \
int32_t offset = offsets->Value(i); \
int8_t type = types->Value(i); \
std::shared_ptr<Array> arr = data->child(type); \
PyObject* value; \
RETURN_NOT_OK(GetValue(arr, offset, type, base, tensors, &value)); \
SET_ITEM_FN(result.get(), i - start_idx, value); \
} \
} \
*out = result.release(); \
return Status::OK();

Status DeserializeList(std::shared_ptr<Array> array, int32_t start_idx, int32_t stop_idx,
Expand All @@ -191,7 +191,8 @@ Status ReadSerializedPythonSequence(std::shared_ptr<io::RandomAccessFile> src,
int64_t bytes_read;
int32_t num_tensors;
// Read number of tensors
RETURN_NOT_OK(src->Read(sizeof(int32_t), &bytes_read, reinterpret_cast<uint8_t*>(&num_tensors)));
RETURN_NOT_OK(
src->Read(sizeof(int32_t), &bytes_read, reinterpret_cast<uint8_t*>(&num_tensors)));
RETURN_NOT_OK(ipc::RecordBatchStreamReader::Open(src, &reader));
RETURN_NOT_OK(reader->ReadNextRecordBatch(batch_out));
RETURN_NOT_OK(src->Tell(&offset));
Expand All @@ -206,8 +207,7 @@ Status ReadSerializedPythonSequence(std::shared_ptr<io::RandomAccessFile> src,

Status DeserializePythonSequence(std::shared_ptr<RecordBatch> batch,
std::vector<std::shared_ptr<Tensor>> tensors,
PyObject* base,
PyObject** out) {
PyObject* base, PyObject** out) {
PyAcquireGIL lock;
return DeserializeList(batch->column(0), 0, batch->num_rows(), base, tensors, out);
}
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/arrow/python/arrow_to_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ Status ReadSerializedPythonSequence(std::shared_ptr<io::RandomAccessFile> src,
// This acquires the GIL
Status DeserializePythonSequence(std::shared_ptr<RecordBatch> batch,
std::vector<std::shared_ptr<Tensor>> tensors,
PyObject* base,
PyObject** out);
PyObject* base, PyObject** out);

} // namespace py
} // namespace arrow
Expand Down
4 changes: 1 addition & 3 deletions cpp/src/arrow/python/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ class ARROW_EXPORT ScopedRef {

explicit ScopedRef(PyObject* obj) : obj_(obj) {}

~ScopedRef() {
Py_XDECREF(obj_);
}
~ScopedRef() { Py_XDECREF(obj_); }

void reset(PyObject* obj) {
Py_XDECREF(obj_);
Expand Down
18 changes: 9 additions & 9 deletions cpp/src/arrow/python/python_to_arrow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ Status CallCustomSerializationCallback(PyObject* elem, PyObject** serialized_obj
}

Status SerializeDict(std::vector<PyObject*> dicts, int32_t recursion_depth,
std::shared_ptr<Array>* out,
std::vector<PyObject*>* tensors_out);
std::shared_ptr<Array>* out, std::vector<PyObject*>* tensors_out);

Status SerializeArray(PyArrayObject* array, SequenceBuilder* builder,
std::vector<PyObject*>* subdicts,
std::vector<PyObject*>* tensors_out);

Status SerializeSequences(std::vector<PyObject*> sequences,
int32_t recursion_depth,
Status SerializeSequences(std::vector<PyObject*> sequences, int32_t recursion_depth,
std::shared_ptr<Array>* out,
std::vector<PyObject*>* tensors_out);

Expand Down Expand Up @@ -267,7 +265,8 @@ Status SerializeArray(PyArrayObject* array, SequenceBuilder* builder,
default: {
PyObject* serialized_object;
// The reference count of serialized_object will be decremented in SerializeDict
RETURN_NOT_OK(CallCustomSerializationCallback(reinterpret_cast<PyObject*>(array), &serialized_object));
RETURN_NOT_OK(CallCustomSerializationCallback(reinterpret_cast<PyObject*>(array),
&serialized_object));
RETURN_NOT_OK(builder->AppendDict(PyDict_Size(serialized_object)));
subdicts->push_back(serialized_object);
}
Expand All @@ -291,7 +290,8 @@ Status SerializeSequences(std::vector<PyObject*> sequences, int32_t recursion_de
RETURN_IF_PYERROR();
ScopedRef item;
while (item.reset(PyIter_Next(iterator.get())), item.get()) {
RETURN_NOT_OK(Append(item.get(), &builder, &sublists, &subtuples, &subdicts, tensors_out));
RETURN_NOT_OK(
Append(item.get(), &builder, &sublists, &subtuples, &subdicts, tensors_out));
}
}
std::shared_ptr<Array> list;
Expand Down Expand Up @@ -326,8 +326,8 @@ Status SerializeDict(std::vector<PyObject*> dicts, int32_t recursion_depth,
RETURN_NOT_OK(
Append(key, &result.keys(), &dummy, &key_tuples, &key_dicts, tensors_out));
DCHECK_EQ(dummy.size(), 0);
RETURN_NOT_OK(
Append(value, &result.vals(), &val_lists, &val_tuples, &val_dicts, tensors_out));
RETURN_NOT_OK(Append(value, &result.vals(), &val_lists, &val_tuples, &val_dicts,
tensors_out));
}
}
std::shared_ptr<Array> key_tuples_arr;
Expand Down Expand Up @@ -389,7 +389,7 @@ Status SerializePythonSequence(PyObject* sequence,
std::vector<PyObject*> tensors;
RETURN_NOT_OK(SerializeSequences(sequences, 0, &array, &tensors));
*batch_out = MakeBatch(array);
for (const auto &tensor : tensors) {
for (const auto& tensor : tensors) {
std::shared_ptr<Tensor> out;
RETURN_NOT_OK(NdarrayToTensor(default_memory_pool(), tensor, &out));
tensors_out->push_back(out);
Expand Down

0 comments on commit aa1f300

Please sign in to comment.