Created
September 27, 2018 16:46
-
-
Save wesm/42f1682565ac9737fecc60d12a15927e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./lint.sh | |
/home/wesm/code/arrow/r/src/array.cpp had clang-format style issues | |
--- /home/wesm/code/arrow/r/src/array.cpp | |
+++ /home/wesm/code/arrow/r/src/array.cpp (after clang format) | |
@@ -40,9 +40,7 @@ | |
std::shared_ptr<arrow::Array> SimpleArray(SEXP x) { | |
Rcpp::Vector<RTYPE> vec(x); | |
std::vector<std::shared_ptr<arrow::Buffer>> buffers{ | |
- nullptr, | |
- std::make_shared<SimpleRBuffer<RTYPE>>(vec) | |
- }; | |
+ nullptr, std::make_shared<SimpleRBuffer<RTYPE>>(vec)}; | |
int null_count = 0; | |
if (RTYPE != RAWSXP) { | |
@@ -85,19 +83,20 @@ | |
return std::make_shared<ArrayType>(data); | |
} | |
-std::shared_ptr<arrow::Array> MakeBooleanArray(Rcpp::Vector<LGLSXP, Rcpp::NoProtectStorage> vec) { | |
+std::shared_ptr<arrow::Array> MakeBooleanArray( | |
+ Rcpp::Vector<LGLSXP, Rcpp::NoProtectStorage> vec) { | |
R_xlen_t n = vec.size(); | |
// allocate a buffer for the data | |
std::shared_ptr<arrow::Buffer> data_bitmap; | |
- R_ERROR_NOT_OK(arrow::AllocateBuffer(ceil(n/8), &data_bitmap)); | |
+ R_ERROR_NOT_OK(arrow::AllocateBuffer(ceil(n / 8), &data_bitmap)); | |
auto data_bitmap_data = data_bitmap->mutable_data(); | |
arrow::internal::FirstTimeBitmapWriter bitmap_writer(data_bitmap_data, 0, n); | |
R_xlen_t null_count = 0; | |
// loop until the first no null | |
R_xlen_t i = 0; | |
- for(; i < n; i++, bitmap_writer.Next()) { | |
+ for (; i < n; i++, bitmap_writer.Next()) { | |
if (vec[i] == 0) { | |
bitmap_writer.Clear(); | |
} else if (vec[i] == NA_LOGICAL) { | |
@@ -111,7 +110,7 @@ | |
if (i < n) { | |
// there has been a null before the end, so we need | |
// to collect that information in a null bitmap | |
- R_ERROR_NOT_OK(arrow::AllocateBuffer(ceil(n/8), &null_bitmap)); | |
+ R_ERROR_NOT_OK(arrow::AllocateBuffer(ceil(n / 8), &null_bitmap)); | |
auto null_bitmap_data = null_bitmap->mutable_data(); | |
arrow::internal::FirstTimeBitmapWriter null_bitmap_writer(null_bitmap_data, 0, n); | |
@@ -121,7 +120,7 @@ | |
} | |
// finish both bitmaps | |
- for(; i < n; i++, bitmap_writer.Next(), null_bitmap_writer.Next()) { | |
+ for (; i < n; i++, bitmap_writer.Next(), null_bitmap_writer.Next()) { | |
if (vec[i] == 0) { | |
bitmap_writer.Clear(); | |
null_bitmap_writer.Set(); | |
@@ -137,15 +136,14 @@ | |
} | |
bitmap_writer.Finish(); | |
- auto data = ArrayData::Make( | |
- std::make_shared<BooleanType>(), n, {std::move(null_bitmap), std::move(data_bitmap) }, null_count, 0 /*offset*/ | |
+ auto data = ArrayData::Make(std::make_shared<BooleanType>(), n, | |
+ {std::move(null_bitmap), std::move(data_bitmap)}, | |
+ null_count, 0 /*offset*/ | |
); | |
// return the right Array class | |
return std::make_shared<BooleanArray>(data); | |
- | |
-} | |
- | |
+} | |
} // namespace r | |
} // namespace arrow | |
@@ -153,20 +151,23 @@ | |
// [[Rcpp::export]] | |
std::shared_ptr<arrow::Array> Array__from_vector(SEXP x) { | |
switch (TYPEOF(x)) { | |
- case LGLSXP: | |
- return arrow::r::MakeBooleanArray(x); | |
- case INTSXP: | |
- if (Rf_isFactor(x)) { | |
+ case LGLSXP: | |
+ return arrow::r::MakeBooleanArray(x); | |
+ case INTSXP: | |
+ if (Rf_isFactor(x)) { | |
+ break; | |
+ } | |
+ return arrow::r::SimpleArray<INTSXP, arrow::Int32Type, | |
+ arrow::NumericArray<arrow::Int32Type>>(x); | |
+ case REALSXP: | |
+ // TODO: Dates, ... | |
+ return arrow::r::SimpleArray<REALSXP, arrow::DoubleType, | |
+ arrow::NumericArray<arrow::DoubleType>>(x); | |
+ case RAWSXP: | |
+ return arrow::r::SimpleArray<RAWSXP, arrow::Int8Type, | |
+ arrow::NumericArray<arrow::Int8Type>>(x); | |
+ default: | |
break; | |
- } | |
- return arrow::r::SimpleArray<INTSXP, arrow::Int32Type, arrow::NumericArray<arrow::Int32Type>>(x); | |
- case REALSXP: | |
- // TODO: Dates, ... | |
- return arrow::r::SimpleArray<REALSXP, arrow::DoubleType, arrow::NumericArray<arrow::DoubleType>>(x); | |
- case RAWSXP: | |
- return arrow::r::SimpleArray<RAWSXP, arrow::Int8Type, arrow::NumericArray<arrow::Int8Type>>(x); | |
- default: | |
- break; | |
} | |
stop("not handled"); | |
@@ -202,14 +203,16 @@ | |
LogicalVector vec(n); | |
// process the data | |
- arrow::internal::BitmapReader data_reader(array->data()->buffers[1]->data(), array->offset(), n); | |
+ arrow::internal::BitmapReader data_reader(array->data()->buffers[1]->data(), | |
+ array->offset(), n); | |
for (size_t i = 0; i < n; i++, data_reader.Next()) { | |
vec[i] = data_reader.IsSet(); | |
} | |
// then the null bitmap if needed | |
if (array->null_count()) { | |
- arrow::internal::BitmapReader null_reader(array->null_bitmap()->data(), array->offset(), n); | |
+ arrow::internal::BitmapReader null_reader(array->null_bitmap()->data(), | |
+ array->offset(), n); | |
for (size_t i = 0; i < n; i++, null_reader.Next()) { | |
if (null_reader.IsNotSet()) { | |
vec[i] = LogicalVector::get_na(); | |
@@ -223,17 +226,17 @@ | |
// [[Rcpp::export]] | |
SEXP Array__as_vector(const std::shared_ptr<arrow::Array>& array) { | |
switch (array->type_id()) { | |
- case Type::BOOL: | |
- return BooleanArray_to_Vector(array); | |
- case Type::INT8: | |
- return simple_Array_to_Vector<RAWSXP>(array); | |
- case Type::INT32: | |
- return simple_Array_to_Vector<INTSXP>(array); | |
- case Type::DOUBLE: | |
- return simple_Array_to_Vector<REALSXP>(array); | |
- default: | |
- break; | |
-} | |
+ case Type::BOOL: | |
+ return BooleanArray_to_Vector(array); | |
+ case Type::INT8: | |
+ return simple_Array_to_Vector<RAWSXP>(array); | |
+ case Type::INT32: | |
+ return simple_Array_to_Vector<INTSXP>(array); | |
+ case Type::DOUBLE: | |
+ return simple_Array_to_Vector<REALSXP>(array); | |
+ default: | |
+ break; | |
+ } | |
stop(tfm::format("cannot handle Array of type %d", array->type_id())); | |
return R_NilValue; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment