Is there a way to implement the &
or &=
for nd4j arrays?
for example I want to find relative extrema so I wrote the following function:
private static INDArray boolrelextrema(
INDArray data, BiFunction<INDArray, INDArray, INDArray> comp, int order) {
if (order < 1) {
throw new IllegalArgumentException("Order must be >= 1");
}
if (data.isMatrix()) {
throw new IllegalArgumentException("Argrelextrema currently only supports 1-D arrays");
}
long length = data.length();
INDArray locs = Nd4j.createFromArray(IntStream.range(0, (int) length).toArray());
int[] shifts = IntStream.range(1, order + 1).toArray();
INDArray results = Nd4j.ones(DataType.BOOL, length);
for (int shift : shifts) {
// same as np.take(locs + shift, axis=0, mode='clip')
INDArray plus = data.get(NDArrayIndex.interval(shift, length));
plus = Nd4j.concat(0, plus, data.get(NDArrayIndex.point(length - 1)));
// same as np.take(locs - shift, axis=0, mode='clip')
INDArray minus = data.get(NDArrayIndex.interval(0, length - shift));
minus = Nd4j.concat(0, data.get(NDArrayIndex.point(0)), minus);
// find relative peaks
results = results
.eq(comp.apply(data, plus))
.eq(comp.apply(data, minus));
if (!results.any()) {
return results;
}
}
return results;
but instead of .eq()
, what I need in the results
calculation is
results &= comp.apply(data, plus)
results &= comp.apply(data, minus)
or perhaps
results = results
.and(comp.apply(data, plus))
.and(comp.apply(data, minus))
I can think of some workarounds, but I was hoping to be missing some native nd4j operation that would allow this. Thanks in advance!