nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/java/org/nd4j/linalg/cpu/nativecpu/ops/NativeOpExecutioner.java
@Override
    public void exec(Aggregate op) {
        // long st = profilingHookIn(op);

        if (memoryBlocks.get() == null)
            memoryBlocks.set(new HashMap<Integer, AggregateMemoryBlock>());

        if (memoryBlocks.get().get(op.opNum()) == null)
            memoryBlocks.get().put(op.opNum(), new AggregateMemoryBlock(op));

        AggregateMemoryBlock block = memoryBlocks.get().get(op.opNum());

        int numArguments = op.getArguments().size();
        int numIndexArguments = op.getIndexingArguments().size();
        int numRealArguments = op.getRealArguments().size();
        int numShapes = op.getShapes().size();
        int numIntArrays = op.getIntArrayArguments().size();

        PointerPointer arguments = block.getArgumentsPointer(); //new PointerPointer(numArguments);
        List<IntPointer> pointers = new ArrayList<>();
        PointerPointer intArrays = block.getArraysPointer(); //new PointerPointer(numIntArrays);

        for (int x = 0; x < numArguments; x++) {
            arguments.put(x, op.getArguments().get(x) == null ? null
                    : op.getArguments().get(x).data().addressPointer());
        }

        PointerPointer shapes = block.getShapesPointer(); //new PointerPointer(numShapes);

        for (int x = 0; x < numShapes; x++) {
            if (op.getShapes().get(x).dataType() != DataBuffer.Type.INT)
                throw new RuntimeException("ShapeBuffers should have INT data opType");

            shapes.put(x, op.getShapes().get(x) == null ? null : op.getShapes().get(x).addressPointer());
        }

        //int[] indexes = new int[numIndexArguments];
        IntPointer pointer = block.getIndexingPointer();
        for (int x = 0; x < numIndexArguments; x++) {
            pointer.put(x, op.getIndexingArguments().get(x));
        }

        //IntPointer pointer = new IntPointer(indexes);

        double[] reals = new double[numRealArguments];
        for (int x = 0; x < numRealArguments; x++) {
            //reals[x] = op.getRealArguments().get(x).doubleValue();
            if (Nd4j.dataType() == DataBuffer.Type.FLOAT)
                ((FloatPointer) block.getRealArgumentsPointer()).put(x, op.getRealArguments().get(x).floatValue());
            else
                ((DoublePointer) block.getRealArgumentsPointer()).put(x, op.getRealArguments().get(x).doubleValue());
        }

        for (int x = 0; x < numIntArrays; x++) {
            IntPointer intPtr = block.getIntArrays().get(x); //new IntPointer(op.getIntArrayArguments().get(x));
            intPtr.put(op.getIntArrayArguments().get(x), 0, op.getIntArrayArguments().get(x).length);
            intArrays.put(x, intPtr);
            pointers.add(intPtr);
        }

        //INDArray realsBuffer = Nd4j.create(reals);


        if (Nd4j.dataType() == DataBuffer.Type.FLOAT) {
            loop.execAggregateFloat(null, op.opNum(), arguments, numArguments, shapes, numShapes, pointer,
                    numIndexArguments, intArrays, numIntArrays, (FloatPointer) block.getRealArgumentsPointer(),
                    numRealArguments);
        } else if (Nd4j.dataType() == DataBuffer.Type.DOUBLE) {
            loop.execAggregateDouble(null, op.opNum(), arguments, numArguments, shapes, numShapes, pointer,
                    numIndexArguments, intArrays, numIntArrays, (DoublePointer) block.getRealArgumentsPointer(),
                    numRealArguments);
        } else {
            throw new UnsupportedOperationException("Half precision isn't supported on CPU");
        }
    }
@Override
    public void exec(Aggregate op) {
        // long st = profilingHookIn(op);

        if (memoryBlocks.get() == null)
            memoryBlocks.set(new HashMap<Integer, AggregateMemoryBlock>());

        if (memoryBlocks.get().get(op.opNum()) == null)
            memoryBlocks.get().put(op.opNum(), new AggregateMemoryBlock(op));

        AggregateMemoryBlock block = memoryBlocks.get().get(op.opNum());

        int numArguments = op.getArguments().size();
        int numIndexArguments = op.getIndexingArguments().size();
        int numRealArguments = op.getRealArguments().size();
        int numShapes = op.getShapes().size();
        int numIntArrays = op.getIntArrayArguments().size();

        PointerPointer arguments = block.getArgumentsPointer(); //new PointerPointer(numArguments);
        List<IntPointer> pointers = new ArrayList<>();
        PointerPointer intArrays = block.getArraysPointer(); //new PointerPointer(numIntArrays);

        for (int x = 0; x < numArguments; x++) {
            arguments.put(x, op.getArguments().get(x) == null ? null
                    : op.getArguments().get(x).data().addressPointer());
        }

        PointerPointer shapes = block.getShapesPointer(); //new PointerPointer(numShapes);

        for (int x = 0; x < numShapes; x++) {
            if (op.getShapes().get(x).dataType() != DataBuffer.Type.INT)
                throw new RuntimeException("ShapeBuffers should have INT data opType");

            shapes.put(x, op.getShapes().get(x) == null ? null : op.getShapes().get(x).addressPointer());
        }

        //int[] indexes = new int[numIndexArguments];
        IntPointer pointer = block.getIndexingPointer();
        for (int x = 0; x < numIndexArguments; x++) {
            pointer.put(x, op.getIndexingArguments().get(x));
        }

        //IntPointer pointer = new IntPointer(indexes);

        double[] reals = new double[numRealArguments];
        for (int x = 0; x < numRealArguments; x++) {
            //reals[x] = op.getRealArguments().get(x).doubleValue();
            if (Nd4j.dataType() == DataBuffer.Type.FLOAT)
                ((FloatPointer) block.getRealArgumentsPointer()).put(x, op.getRealArguments().get(x).floatValue());
            else
                ((DoublePointer) block.getRealArgumentsPointer()).put(x, op.getRealArguments().get(x).doubleValue());
        }

        for (int x = 0; x < numIntArrays; x++) {
            IntPointer intPtr = block.getIntArrays().get(x); //new IntPointer(op.getIntArrayArguments().get(x));
            intPtr.put(op.getIntArrayArguments().get(x), 0, op.getIntArrayArguments().get(x).length);
            intArrays.put(x, intPtr);
            pointers.add(intPtr);
        }

        //INDArray realsBuffer = Nd4j.create(reals);


        if (Nd4j.dataType() == DataBuffer.Type.FLOAT) {
            loop.execAggregateFloat(null, op.opNum(), arguments, numArguments, shapes, numShapes, pointer,
                    numIndexArguments, intArrays, numIntArrays, (FloatPointer) block.getRealArgumentsPointer(),
                    numRealArguments);
        } else if (Nd4j.dataType() == DataBuffer.Type.DOUBLE) {
            loop.execAggregateDouble(null, op.opNum(), arguments, numArguments, shapes, numShapes, pointer,
                    numIndexArguments, intArrays, numIntArrays, (DoublePointer) block.getRealArgumentsPointer(),
                    numRealArguments);
        } else {
            throw new UnsupportedOperationException("Half precision isn't supported on CPU");
        }
    }
@ Override public void exec ( Aggregate op ) { // long st = profilingHookIn(op); if ( memoryBlocks . get ( ) == null ) memoryBlocks . set ( new HashMap < Integer , AggregateMemoryBlock > ( ) ) ; if ( memoryBlocks . get ( ) . get ( op . opNum ( ) ) == null ) memoryBlocks . get ( ) . put ( op . opNum ( ) , new AggregateMemoryBlock ( op ) ) ; AggregateMemoryBlock block = memoryBlocks . get ( ) . get ( op . opNum ( ) ) ; int numArguments = op . getArguments ( ) . size ( ) ; int numIndexArguments = op . getIndexingArguments ( ) . size ( ) ; int numRealArguments = op . getRealArguments ( ) . size ( ) ; int numShapes = op . getShapes ( ) . size ( ) ; int numIntArrays = op . getIntArrayArguments ( ) . size ( ) ; PointerPointer arguments = block . getArgumentsPointer ( ) ; //new PointerPointer(numArguments); List < IntPointer > pointers = new ArrayList <> ( ) ; PointerPointer intArrays = block . getArraysPointer ( ) ; //new PointerPointer(numIntArrays); for ( int x = 0 ; x < numArguments ; x ++ ) { arguments . put ( x , op . getArguments ( ) . get ( x ) == null ? null : op . getArguments ( ) . get ( x ) . data ( ) . addressPointer ( ) ) ; } PointerPointer shapes = block . getShapesPointer ( ) ; //new PointerPointer(numShapes); for ( int x = 0 ; x < numShapes ; x ++ ) { if ( op . getShapes ( ) . get ( x ) . dataType ( ) != DataBuffer . Type . INT ) throw new RuntimeException ( "ShapeBuffers should have INT data opType" ) ; shapes . put ( x , op . getShapes ( ) . get ( x ) == null ? null : op . getShapes ( ) . get ( x ) . addressPointer ( ) ) ; } //int[] indexes = new int[numIndexArguments]; IntPointer pointer = block . getIndexingPointer ( ) ; for ( int x = 0 ; x < numIndexArguments ; x ++ ) { pointer . put ( x , op . getIndexingArguments ( ) . get ( x ) ) ; } //IntPointer pointer = new IntPointer(indexes); double [ ] reals = new double [ numRealArguments ] ; for ( int x = 0 ; x < numRealArguments ; x ++ ) { //reals[x] = op.getRealArguments().get(x).doubleValue(); if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT ) ( ( FloatPointer ) block . getRealArgumentsPointer ( ) ) . put ( x , op . getRealArguments ( ) . get ( x ) . floatValue ( ) ) ; else ( ( DoublePointer ) block . getRealArgumentsPointer ( ) ) . put ( x , op . getRealArguments ( ) . get ( x ) . doubleValue ( ) ) ; } for ( int x = 0 ; x < numIntArrays ; x ++ ) { IntPointer intPtr = block . getIntArrays ( ) . get ( x ) ; //new IntPointer(op.getIntArrayArguments().get(x)); intPtr . put ( op . getIntArrayArguments ( ) . get ( x ) , 0 , op . getIntArrayArguments ( ) . get ( x ) . length ) ; intArrays . put ( x , intPtr ) ; pointers . add ( intPtr ) ; } //INDArray realsBuffer = Nd4j.create(reals); if ( Nd4j . dataType ( ) == DataBuffer . Type . FLOAT ) { loop . execAggregateFloat ( null , op . opNum ( ) , arguments , numArguments , shapes , numShapes , pointer , numIndexArguments , intArrays , numIntArrays , ( FloatPointer ) block . getRealArgumentsPointer ( ) , numRealArguments ) ; } else if ( Nd4j . dataType ( ) == DataBuffer . Type . DOUBLE ) { loop . execAggregateDouble ( null , op . opNum ( ) , arguments , numArguments , shapes , numShapes , pointer , numIndexArguments , intArrays , numIntArrays , ( DoublePointer ) block . getRealArgumentsPointer ( ) , numRealArguments ) ; } else { throw new UnsupportedOperationException ( "Half precision isn't supported on CPU" ) ; } }
This method takes arbitrary
sized list of {@link Aggregate},
and packs them into batches
Note here that this is mainly used for random number generation
for {@link RandomOp} and things like {@link org.nd4j.linalg.api.rng.distribution.Distribution}
@param op the list of {@link Aggregate} to
execute upon
This method takes arbitrary sized list of {