Skip to content

Commit

Permalink
+Array$RangeEquals
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Sep 24, 2018
1 parent f860063 commit 9d208a4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions r/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Array__data <- function(array) {
.Call(`_arrow_Array__data`, array)
}

Array__RangeEquals <- function(self, other, start_idx, end_idx, other_start_idx) {
.Call(`_arrow_Array__RangeEquals`, self, other, start_idx, end_idx, other_start_idx)
}

ArrayData__get_type <- function(x) {
.Call(`_arrow_ArrayData__get_type`, x)
}
Expand Down
6 changes: 4 additions & 2 deletions r/R/array.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# under the License.

#' @include R6.R
#' @include ArrayData.R
#' @include Column.R

`arrow::Array` <- R6Class("arrow::Array",
inherit = `arrow::Object`,
Expand All @@ -40,6 +38,10 @@
} else {
`arrow::Array`$new(Array__Slice2(self, offset, length))
}
},
RangeEquals = function(other, start_idx, end_idx, other_start_idx) {
assert_that(inherits(other, "arrow::Array"))
Array__RangeEquals(self, other, start_idx, end_idx, other_start_idx)
}
)
)
Expand Down
16 changes: 16 additions & 0 deletions r/src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// Array__RangeEquals
bool Array__RangeEquals(const std::shared_ptr<arrow::Array>& self, const std::shared_ptr<arrow::Array>& other, int start_idx, int end_idx, int other_start_idx);
RcppExport SEXP _arrow_Array__RangeEquals(SEXP selfSEXP, SEXP otherSEXP, SEXP start_idxSEXP, SEXP end_idxSEXP, SEXP other_start_idxSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& >::type self(selfSEXP);
Rcpp::traits::input_parameter< const std::shared_ptr<arrow::Array>& >::type other(otherSEXP);
Rcpp::traits::input_parameter< int >::type start_idx(start_idxSEXP);
Rcpp::traits::input_parameter< int >::type end_idx(end_idxSEXP);
Rcpp::traits::input_parameter< int >::type other_start_idx(other_start_idxSEXP);
rcpp_result_gen = Rcpp::wrap(Array__RangeEquals(self, other, start_idx, end_idx, other_start_idx));
return rcpp_result_gen;
END_RCPP
}
// ArrayData__get_type
std::shared_ptr<arrow::DataType> ArrayData__get_type(const std::shared_ptr<arrow::ArrayData>& x);
RcppExport SEXP _arrow_ArrayData__get_type(SEXP xSEXP) {
Expand Down Expand Up @@ -1093,6 +1108,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_arrow_Array__Equals", (DL_FUNC) &_arrow_Array__Equals, 2},
{"_arrow_Array__ApproxEquals", (DL_FUNC) &_arrow_Array__ApproxEquals, 2},
{"_arrow_Array__data", (DL_FUNC) &_arrow_Array__data, 1},
{"_arrow_Array__RangeEquals", (DL_FUNC) &_arrow_Array__RangeEquals, 5},
{"_arrow_ArrayData__get_type", (DL_FUNC) &_arrow_ArrayData__get_type, 1},
{"_arrow_ArrayData__get_length", (DL_FUNC) &_arrow_ArrayData__get_length, 1},
{"_arrow_ArrayData__get_null_count", (DL_FUNC) &_arrow_ArrayData__get_null_count, 1},
Expand Down
4 changes: 4 additions & 0 deletions r/src/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,7 @@ std::shared_ptr<arrow::ArrayData> Array__data(const std::shared_ptr<arrow::Array
return array->data();
}

// [[Rcpp::export]]
bool Array__RangeEquals(const std::shared_ptr<arrow::Array>& self, const std::shared_ptr<arrow::Array>&other, int start_idx, int end_idx, int other_start_idx) {
return self->RangeEquals(*other, start_idx, end_idx, other_start_idx);
}
9 changes: 9 additions & 0 deletions r/tests/testthat/test-Array.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ test_that("Array", {
expect_equal(y$type(), int32())
expect_equal(y$length(), 15L)
expect_equal(y$as_vector(), c(1:10, 1:5))
expect_true(x$RangeEquals(y, 10, 24, 0))

z <- x$Slice(10, 5)
expect_equal(z$type(), int32())
expect_equal(z$length(), 5L)
expect_equal(z$as_vector(), c(1:5))
expect_true(x$RangeEquals(z, 10, 15, 0))

x_dbl <- array(c(1,2,3), c(4,5,6))
expect_equal(x_dbl$type(), float64())
Expand All @@ -49,3 +51,10 @@ test_that("Array", {
expect_equal(z_dbl$length(), 2L)
expect_equal(z_dbl$as_vector(), as.numeric(4:5))
})

test_that("Array supports NA", {
x_int <- array(1:10, NA)
x_dbl <- array(as.numeric(1:10), NA)
expect_true(x_int$IsNull(11))
expect_true(x_dbl$IsNull(11))
})

0 comments on commit 9d208a4

Please sign in to comment.