Skip to content

Commit 73bb0bb

Browse files
committed
Update parallel.R to vec_pany() and vec_pall()
Write the rest of the owl
1 parent 1aa0d0e commit 73bb0bb

File tree

10 files changed

+338
-406
lines changed

10 files changed

+338
-406
lines changed

NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,6 @@ export(list_check_all_vectors)
468468
export(list_combine)
469469
export(list_drop_empty)
470470
export(list_of)
471-
export(list_pall)
472-
export(list_pany)
473471
export(list_sizes)
474472
export(list_unchop)
475473
export(maybe_lossy_cast)
@@ -584,6 +582,8 @@ export(vec_math_base)
584582
export(vec_names)
585583
export(vec_names2)
586584
export(vec_order)
585+
export(vec_pall)
586+
export(vec_pany)
587587
export(vec_proxy)
588588
export(vec_proxy_compare)
589589
export(vec_proxy_equal)

NEWS.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# vctrs (development version)
22

3-
* New `list_pany()` and `list_pall()`, parallel variants of `any()` and `all()`
4-
(in the same way that `pmin()` and `pmax()` are parallel variants of `min()`
5-
and `max()`).
3+
* New `vec_pany()` and `vec_pall()`, parallel variants of `any()` and `all()` (in the same way that `pmin()` and `pmax()` are parallel variants of `min()` and `max()`).
64

75
* Experimental "partial" type support has been removed. This idea never panned out and was not widely used. The following functions have been removed (#2101):
86

R/parallel.R

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
#' multiple inputs at once. They work similarly to how [pmin()] and [pmax()] are
66
#' parallel variants of [min()] and [max()].
77
#'
8-
#' @inheritParams rlang::args_dots_empty
98
#' @inheritParams rlang::args_error_context
109
#'
11-
#' @param x A list of logical vectors of equal size.
10+
#' @param ... Logical vectors of equal size.
1211
#'
13-
#' @param missing Handling of missing values. One of:
12+
#' @param .missing Handling of missing values. One of:
1413
#'
1514
#' - `NULL`, no special behavior is applied. Missings are treated the same way
1615
#' as `|` or `&`.
@@ -19,53 +18,52 @@
1918
#'
2019
#' - `TRUE` to treat missing values as `TRUE`.
2120
#'
22-
#' @param size An optional output size. Only useful to specify if `x` could be
23-
#' an empty list.
21+
#' @param .size An optional output size. Only useful to specify if it is possible
22+
#' for no inputs to be provided.
2423
#'
25-
#' @param x_arg Argument name used in error messages.
24+
#' @param .arg Argument name used in error messages.
2625
#'
27-
#' @returns A logical vector the same size as the vectors in `x`.
26+
#' @returns A logical vector the same size as the vectors in `...`.
2827
#'
2928
#' @details
30-
#' `list_pany()` and `list_pall()` are consistent with [any()] and [all()] when
29+
#' `vec_pany()` and `vec_pall()` are consistent with [any()] and [all()] when
3130
#' there are no inputs to process in parallel:
3231
#'
33-
#' - `any()` returns `FALSE` with no inputs. Similarly,
34-
#' `list_pany(list(), size = 1)` returns `FALSE`.
32+
#' - `any()` returns `FALSE` with no inputs. Similarly, `vec_pany(.size = 1)`
33+
#' returns `FALSE`.
3534
#'
36-
#' - `all()` returns `TRUE` with no inputs. Similarly,
37-
#' `list_pall(list(), size = 1)` returns `TRUE`.
35+
#' - `all()` returns `TRUE` with no inputs. Similarly, `vec_pall(.size = 1)`
36+
#' returns `TRUE`.
3837
#'
3938
#' @name parallel-operators
4039
#'
4140
#' @examples
4241
#' a <- c(TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, NA, NA, NA)
4342
#' b <- c(TRUE, FALSE, NA, TRUE, FALSE, NA, TRUE, FALSE, NA)
44-
#' x <- list(a, b)
4543
#'
4644
#' # Default behavior treats missings like `|` does
47-
#' list_pany(x)
45+
#' vec_pany(a, b)
4846
#' a | b
4947
#'
5048
#' # Default behavior treats missings like `&` does
51-
#' list_pall(x)
49+
#' vec_pall(a, b)
5250
#' a & b
5351
#'
5452
#' # Remove missings from the computation, like `na_rm = TRUE`
55-
#' list_pany(x, missing = FALSE)
53+
#' vec_pany(a, b, .missing = FALSE)
5654
#' (a & !is.na(a)) | (b & !is.na(b))
5755
#'
58-
#' list_pall(x, missing = TRUE)
56+
#' vec_pall(a, b, .missing = TRUE)
5957
#' (a | is.na(a)) & (b | is.na(b))
6058
#'
61-
#' # `list_pall()` can be used to implement a `dplyr::filter()` style API
59+
#' # `vec_pall()` can be used to implement a `dplyr::filter()` style API
6260
#' df <- data_frame(id = seq_along(a), a = a, b = b)
6361
#'
6462
#' keep_rows <- function(x, ...) {
65-
#' vec_slice(x, list_pall(list(...), missing = FALSE))
63+
#' vec_slice(x, vec_pall(..., .missing = FALSE))
6664
#' }
6765
#' drop_rows <- function(x, ...) {
68-
#' vec_slice(x, !list_pall(list(...), missing = FALSE))
66+
#' vec_slice(x, !vec_pall(..., .missing = FALSE))
6967
#' }
7068
#'
7169
#' # "Keep / Drop the rows when both a and b are TRUE"
@@ -74,37 +72,33 @@
7472
#' drop_rows(df, a, b)
7573
#'
7674
#' # Same empty behavior as `any()` and `all()`
77-
#' list_pany(list(), size = 1)
75+
#' vec_pany(.size = 1)
7876
#' any()
7977
#'
80-
#' list_pall(list(), size = 1)
78+
#' vec_pall(.size = 1)
8179
#' all()
8280
NULL
8381

8482
#' @rdname parallel-operators
8583
#' @export
86-
list_pany <- function(
87-
x,
84+
vec_pany <- function(
8885
...,
89-
missing = NULL,
90-
size = NULL,
91-
x_arg = caller_arg(x),
92-
error_call = current_env()
86+
.missing = NULL,
87+
.size = NULL,
88+
.arg = "",
89+
.error_call = current_env()
9390
) {
94-
check_dots_empty0(...)
95-
.Call(ffi_list_pany, x, missing, size, environment())
91+
.Call(ffi_vec_pany, list2(...), .missing, .size, environment())
9692
}
9793

9894
#' @rdname parallel-operators
9995
#' @export
100-
list_pall <- function(
101-
x,
96+
vec_pall <- function(
10297
...,
103-
missing = NULL,
104-
size = NULL,
105-
x_arg = caller_arg(x),
106-
error_call = current_env()
98+
.missing = NULL,
99+
.size = NULL,
100+
.arg = "",
101+
.error_call = current_env()
107102
) {
108-
check_dots_empty0(...)
109-
.Call(ffi_list_pall, x, missing, size, environment())
103+
.Call(ffi_vec_pall, list2(...), .missing, .size, environment())
110104
}

man/parallel-operators.Rd

Lines changed: 33 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/decl/parallel-decl.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
static
2-
r_obj* list_parallel(
2+
r_obj* vec_parallel(
33
r_obj* xs,
4-
enum list_parallel_missing missing,
4+
enum vec_parallel_missing missing,
55
r_ssize size,
66
struct vctrs_arg* p_xs_arg,
77
struct r_lazy error_call,
8-
enum list_parallel_variant parallel
8+
enum vec_parallel_variant parallel
99
);
1010

1111
static inline
12-
void list_parallel_init(const int* v_x, enum list_parallel_missing missing, r_ssize size, int* v_out);
12+
void vec_parallel_init(const int* v_x, enum vec_parallel_missing missing, r_ssize size, int* v_out);
1313
static inline
14-
void list_parallel_init_missing_as_na(const int* v_x, r_ssize size, int* v_out);
14+
void vec_parallel_init_missing_as_na(const int* v_x, r_ssize size, int* v_out);
1515
static inline
16-
void list_parallel_init_missing_as_false(const int* v_x, r_ssize size, int* v_out);
16+
void vec_parallel_init_missing_as_false(const int* v_x, r_ssize size, int* v_out);
1717
static inline
18-
void list_parallel_init_missing_as_true(const int* v_x, r_ssize size, int* v_out);
18+
void vec_parallel_init_missing_as_true(const int* v_x, r_ssize size, int* v_out);
1919

2020
static inline
21-
void list_pany_fill(const int* v_x, enum list_parallel_missing missing, r_ssize size, int* v_out);
21+
void vec_pany_fill(const int* v_x, enum vec_parallel_missing missing, r_ssize size, int* v_out);
2222
static inline
23-
void list_pall_fill(const int* v_x, enum list_parallel_missing missing, r_ssize size, int* v_out);
23+
void vec_pall_fill(const int* v_x, enum vec_parallel_missing missing, r_ssize size, int* v_out);
2424
static inline
25-
void list_pany_fill_missing_as_na(const int* v_x, r_ssize size, int* v_out);
25+
void vec_pany_fill_missing_as_na(const int* v_x, r_ssize size, int* v_out);
2626
static inline
27-
void list_pall_fill_missing_as_na(const int* v_x, r_ssize size, int* v_out);
27+
void vec_pall_fill_missing_as_na(const int* v_x, r_ssize size, int* v_out);
2828
static inline
29-
void list_pany_fill_missing_as_false(const int* v_x, r_ssize size, int* v_out);
29+
void vec_pany_fill_missing_as_false(const int* v_x, r_ssize size, int* v_out);
3030
static inline
31-
void list_pall_fill_missing_as_false(const int* v_x, r_ssize size, int* v_out);
31+
void vec_pall_fill_missing_as_false(const int* v_x, r_ssize size, int* v_out);
3232
static inline
33-
void list_pany_fill_missing_as_true(const int* v_x, r_ssize size, int* v_out);
33+
void vec_pany_fill_missing_as_true(const int* v_x, r_ssize size, int* v_out);
3434
static inline
35-
void list_pall_fill_missing_as_true(const int* v_x, r_ssize size, int* v_out);
35+
void vec_pall_fill_missing_as_true(const int* v_x, r_ssize size, int* v_out);
3636

3737
static
38-
enum list_parallel_missing parse_list_parallel_missing(r_obj* missing, struct r_lazy error_call);
38+
enum vec_parallel_missing parse_vec_parallel_missing(r_obj* missing, struct r_lazy error_call);
3939

4040
static
4141
r_ssize compute_size(r_ssize size, r_obj* xs);

src/init.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ extern r_obj* ffi_vec_replace_when(r_obj*, r_obj*, r_obj*, r_obj*);
171171
extern r_obj* ffi_vec_recode_values(r_obj*, r_obj*, r_obj*, r_obj*, r_obj*, r_obj*, r_obj*, r_obj*, r_obj*);
172172
extern r_obj* ffi_vec_replace_values(r_obj*, r_obj*, r_obj*, r_obj*, r_obj*, r_obj*);
173173
extern r_obj* ffi_vec_if_else(r_obj*, r_obj*, r_obj*, r_obj*, r_obj*, r_obj*);
174-
extern r_obj* ffi_list_pany(r_obj*, r_obj*, r_obj*, r_obj*);
175-
extern r_obj* ffi_list_pall(r_obj*, r_obj*, r_obj*, r_obj*);
174+
extern r_obj* ffi_vec_pany(r_obj*, r_obj*, r_obj*, r_obj*);
175+
extern r_obj* ffi_vec_pall(r_obj*, r_obj*, r_obj*, r_obj*);
176176

177177

178178
// Maturing
@@ -374,8 +374,8 @@ static const R_CallMethodDef CallEntries[] = {
374374
{"ffi_vec_recode_values", (DL_FUNC) &ffi_vec_recode_values, 9},
375375
{"ffi_vec_replace_values", (DL_FUNC) &ffi_vec_replace_values, 6},
376376
{"ffi_vec_if_else", (DL_FUNC) &ffi_vec_if_else, 6},
377-
{"ffi_list_pany", (DL_FUNC) &ffi_list_pany, 4},
378-
{"ffi_list_pall", (DL_FUNC) &ffi_list_pall, 4},
377+
{"ffi_vec_pany", (DL_FUNC) &ffi_vec_pany, 4},
378+
{"ffi_vec_pall", (DL_FUNC) &ffi_vec_pall, 4},
379379
{"ffi_exp_vec_cast", (DL_FUNC) &exp_vec_cast, 2},
380380
{NULL, NULL, 0}
381381
};

0 commit comments

Comments
 (0)