Description
Description
As discussed here, the logical functions don't support vectorization yet.
New functions
Add functions for the logical operators (==
,<
, <=
, >
, >=
) and their functions (logical_eq
, etc.) to allow containers as arguments and support broadcasting. The signatures will be, for example,
int logical_eq(scalar, scalar);
int[] logical_eq(scalars, scalars);
int[] logical_eq(scalar, scalars);
int[] logical_eq(scalars, scalar);
where
scalar
isint | real | complex
scalars
isscalar[] | vector | row_vector | complex_vector | complex_row_vector
.
If there are two scalar inputs, the existing function is called. If one of the arguments is a container, the other argument must be a container of the same shape or a scalar. With a scalar and container, the scalar is broadcast.
Vectorized logic
We also want to add two functions
int any(scalars);
int all(scalars);
where the first returns 0 if all of the arguments are 0 and 1 otherwise, and the second returns 0 if any of the arguments is 0 and 1 otherwise. We could also add a not
function that performs elementwise negation.
Example & Expected Output
data {
int N;
real x1[N];
real x2[N];
}
transformed data {
real y = sum(x1 > x2);
}
Current error:
No matches for: logical_gt(real[ ], real[ ])
Current Version:
v4.6.2