Refine search
/** * An {@link ReactiveElasticsearchQueryExecution} that wraps the results of the given delegate with the given result * processing. */ @RequiredArgsConstructor final class ResultProcessingExecution implements ReactiveElasticsearchQueryExecution { private final @NonNull ReactiveElasticsearchQueryExecution delegate; private final @NonNull Converter<Object, Object> converter; @Override public Object execute(Query query, Class<?> type, String indexName, String indexType, @Nullable Class<?> targetType) { return converter.convert(delegate.execute(query, type, indexName, indexType, targetType)); } }
@RequiredArgsConstructor @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) static class ExecutableRemoveSupport<T> implements ExecutableRemove<T>, RemoveWithCollection<T> { @NonNull MongoTemplate template; @NonNull Class<T> domainType; Query query; @Nullable String collection;
@Override public Response contentType(@NonNull String contentType) { this.headers.put("Content-Type", contentType); return this; }
/** * This method samples value from Source array to Target, with probabilites provided in Probs argument * * @param source * @param probs * @param target * @return */ public static INDArray choice(@NonNull INDArray source, @NonNull INDArray probs, @NonNull INDArray target, @NonNull org.nd4j.linalg.api.rng.Random rng) { if (source.length() != probs.length()) throw new ND4JIllegalStateException("Nd4j.choice() requires lengths of Source and Probs to be equal"); return Nd4j.getExecutioner().exec(new Choice(source, probs, target), rng); }
/** * This op fills Z with binomial distribution over given trials with single given probability for all trials * @param z * @param trials * @param probability */ public BinomialDistribution(@NonNull INDArray z, int trials, double probability) { init(z, z, z, z.lengthLong()); this.trials = trials; this.probability = probability; this.extraArgs = new Object[] {(double) this.trials, this.probability}; }
/** * This op fills Z with binomial distribution over given trials with probability for each trial given as probabilities INDArray * * @param z * @param probabilities */ public BinomialDistributionEx(@NonNull INDArray z, @NonNull INDArray probabilities) { // FIXME: int cast this(z, (int) probabilities.length(), probabilities); }
public static INDArray tailor4d2d(@NonNull INDArray data) { long instances = data.size(0); long channels = data.size(1); long height = data.size(2); long width = data.size(3); INDArray in2d = Nd4j.create(channels, height * width * instances); long tads = data.tensorssAlongDimension(3, 2, 0); for (int i = 0; i < tads; i++) { INDArray thisTAD = data.tensorAlongDimension(i, 3, 2, 0); in2d.putRow(i, Nd4j.toFlattened(thisTAD)); } return in2d.transposei(); }
public static INDArray tailor3d2d(@NonNull INDArray data, INDArray mask) { if (data.size(0) != mask.size(0) || data.size(2) != mask.size(1)) { throw new IllegalArgumentException( "Invalid mask array/data combination: got data with shape [minibatch, vectorSize, timeSeriesLength] = " INDArray subset = Nd4j.pullRows(as2d, 1, rowsToPull); //Tensor along dimension 1 == rows return subset;
/** * Atan2 operation, new INDArray instance will be returned * Note the order of x and y parameters is opposite to that of java.lang.Math.atan2 * * @param x the abscissa coordinate * @param y the ordinate coordinate * @return the theta from point (r, theta) when converting (x,y) from to cartesian to polar coordinates */ public static INDArray atan2(@NonNull INDArray x, @NonNull INDArray y) { return Nd4j.getExecutioner() .execAndReturn(new OldAtan2Op(x, y, Nd4j.createUninitialized(x.shape(), x.ordering()))); }
/** * This method does element-wise comparison for 2 equal-sized matrices, for each element that matches Condition * * @param to * @param from * @param condition */ public static void replaceWhere(@NonNull INDArray to, @NonNull INDArray from, @NonNull Condition condition) { if (!(condition instanceof BaseCondition)) throw new UnsupportedOperationException("Only static Conditions are supported"); if (to.lengthLong() != from.lengthLong()) throw new IllegalStateException("Mis matched length for to and from"); Nd4j.getExecutioner().exec(new CompareAndReplace(to, from, condition)); }
/** * Choose from the inputs based on the given condition. * This returns a row vector of all elements fulfilling the * condition listed within the array for input. * The double and integer arguments are only relevant * for scalar operations (like when you have a scalar * you are trying to compare each element in your input against) * * @param input the input to filter * @param tArgs the double args * @param iArgs the integer args * @param condition the condition to filter based on * @return a row vector of the input elements that are true * ffor the given conditions */ public static INDArray chooseFrom(@NonNull INDArray[] input, @NonNull List<Double> tArgs, @NonNull List<Integer> iArgs, @NonNull Condition condition) { Choose choose = new Choose(input,iArgs,tArgs,condition); Nd4j.getExecutioner().exec(choose); int secondOutput = choose.getOutputArgument(1).getInt(0); if(secondOutput < 1) { return null; } INDArray ret = choose.getOutputArgument(0).get(NDArrayIndex.interval(0,secondOutput)); ret = ret.reshape(ret.length()); return ret; }
/** * @param mean row vector of means * @param std row vector of standard deviations */ public DistributionStats(@NonNull INDArray mean, @NonNull INDArray std) { Transforms.max(std, Nd4j.EPS_THRESHOLD, false); if (std.min(1) == Nd4j.scalar(Nd4j.EPS_THRESHOLD)) { logger.info("API_INFO: Std deviation found to be zero. Transform will round up to epsilon to avoid nans."); } this.mean = mean; this.std = std; }
/** * Meshgrid op. Returns a pair of arrays where values are broadcast on a 2d grid.<br> * For example, if x = [1,2,3,4] and y = [5,6,7], then:<br> * out[0] =<br> * [1,2,3,4]<br> * [1,2,3,4]<br> * [1,2,3,4]<br> * <br> * out[1] =<br> * [5,5,5,5]<br> * [6,6,6,6]<br> * [7,7,7,7]<br> * <br> * * @param x X array input * @param y Y array input * @return INDArray[] of length 2, shape [y.length, x.length] */ public static INDArray[] meshgrid(@NonNull INDArray x, @NonNull INDArray y){ Preconditions.checkArgument(x.isVectorOrScalar(), "X must be a vector"); Preconditions.checkArgument(y.isVectorOrScalar(), "Y must be a vector"); INDArray xOut = Nd4j.createUninitialized(y.length(), x.length()); INDArray yOut = Nd4j.createUninitialized(y.length(), x.length()); CustomOp op = DynamicCustomOp.builder("meshgrid") .addInputs(x, y) .addOutputs(xOut, yOut) .build(); Nd4j.getExecutioner().exec(op); return new INDArray[]{xOut, yOut}; }
/** * Choose from the inputs based on the given condition. * This returns a row vector of all elements fulfilling the * condition listed within the array for input * @param input the input to filter * @param condition the condition to filter based on * @return a row vector of the input elements that are true * ffor the given conditions */ public static INDArray chooseFrom(@NonNull INDArray[] input,@NonNull Condition condition) { Choose choose = new Choose(input,condition); Nd4j.getExecutioner().exec(choose); int secondOutput = choose.getOutputArgument(1).getInt(0); if(secondOutput < 1) { return null; } return choose.getOutputArgument(0); }
public ByteBuffer asFlatBuffers(@NonNull ExecutorConfiguration configuration) { Nd4j.getExecutioner().commit(); FlatBufferBuilder bufferBuilder = new FlatBufferBuilder(1024); val idCounter = new AtomicInteger(0); int array = arr.toFlatArray(bufferBuilder); int id = IntPair.createIntPair(bufferBuilder, idCounter.get(), 0); int array = arr.toFlatArray(bufferBuilder); int id = IntPair.createIntPair(bufferBuilder, ++idx, 0);
@RequiredArgsConstructor @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) static class ExecutableAggregationSupport<T> implements AggregationWithAggregation<T>, ExecutableAggregation<T>, TerminatingAggregation<T> { @NonNull MongoTemplate template; @NonNull Class<T> domainType; @Nullable Aggregation aggregation; @Nullable String collection;
/** * Add blade loader * * @param loader * @return */ public Blade addLoader(@NonNull BladeLoader loader) { this.loaders.add(loader); return this; }
/** * Cosine similarity * * @param d1 the first vector * @param d2 the second vector * @return the cosine similarities between the 2 arrays * */ public static double cosineSim(@NonNull INDArray d1, @NonNull INDArray d2) { return Nd4j.getExecutioner().execAndReturn(new CosineSimilarity(d1, d2, d1.length())).getFinalResult() .doubleValue(); }