ghosted distributed array constructor
    @param arry numpy-like array
    @param numGhosts the number of ghosts (>= 0)
346231
def gdaArray(arry, dtype, numGhosts=1):
    
    a = numpy.array(arry, dtype)
    res = GhostedDistArray(a.shape, a.dtype)
    res.setNumberOfGhosts(numGhosts)
    res[:] = a
    return res
1336564
@Override
    public int[] apply(INDArray... outputs) {
        Preconditions.checkArgument(outputs.length == 1, "Argmax adapter can have only 1 output");
        val array = outputs[0];
        Preconditions.checkArgument(array.rank() < 3, "Argmax adapter requires 2D or 1D output");
        val result = array.rank() == 2 ? new int[(int) array.size(0)] : new int[1];

        if (array.rank() == 2) {
            val t = Nd4j.argMax(array, 1);
            for (int e = 0; e < t.length(); e++)
                result[e] = (int) t.getDouble(e);
        } else
            result[0] = (int) Nd4j.argMax(array, Integer.MAX_VALUE).getDouble(0);

        return result;
    }
}
1030177
private String chooseHost(String[] dbHosts) {
        String host = null;
        synchronized (m_lastHostLock) {
            if (dbHosts.length == 1) {
                host = dbHosts[0];
            } else if (!Utils.isEmpty(m_lastHost)) {
                for (int index = 0; host == null && index < dbHosts.length; index++) {
                    if (dbHosts[index].equals(m_lastHost)) {
                        host = dbHosts[(++index) % dbHosts.length];
                    }
                }
            }
            if (host == null) {
                host = dbHosts[new Random().nextInt(dbHosts.length)];
            }
            m_lastHost = host;
        }
        return host;
    }
750490
@Override
    public void setArray(INDArray arr) {
        if (this.arr.get() == null)
            this.arr.set(arr);
    }
10990
def ghostedDistArrayFactory(BaseClass):
    

    class GhostedDistArrayAny(BaseClass):
        """
        Ghosted distributed array. Each process owns data and exposes the
        halo region to other processes. These are accessed with tuples
        such (1, 0) for north, (-1, 0) for south, etc.
        """

        def __init__(self, shape, dtype):
            """
            Constructor
            @param shape shape of the array
            @param dtype numpy data type
            @param numGhosts the width of the halo
            """
            # call the parent Ctor
            BaseClass.__init__(self, shape, dtype)

        def setNumberOfGhosts(self, numGhosts):
            """
            Set the width of the ghost halo
            @param numGhosts halo thickness
            """
            # expose each window to other PE domains
            ndim = len(self.shape)
            for dim in range(ndim):
                for drect in (-1, 1):
                    # the window id uniquely specifies the
                    # location of the window. we use 0's to indicate
                    # a slab extending over the entire length for a
                    # given direction, a 1 represents a layer of
                    # thickness numGhosts on the high index side,
                    # -1 on the low index side.
                    winId = tuple([0 for i in range(dim)] +
                                  [drect] +
                                  [0 for i in range(dim+1, ndim)])

                    slce = slice(0, numGhosts)
                    if drect == 1:
                        slce = slice(self.shape[dim] -
                                     numGhosts, self.shape[dim])

                    slab = self.getSlab(dim, slce)

                    # expose MPI window
                    self.expose(slab, winId)

        def getSlab(self, dim, slce):
            """
            Get slab. A slab is a multi-dimensional slice extending in
            all directions except along dim where slce applies
            @param dim dimension (0=first index, 1=2nd index...)
            @param slce python slice object along dimension dim
            @return slab
            """
            shape = self.shape
            ndim = len(shape)

            slab = [slice(0, shape[i]) for i in range(dim)] + \
                   [slce] + [slice(0, shape[i]) for i in range(dim+1, ndim)]
            return slab

        def getEllipsis(self, winID):
            """
            Get the ellipsis for a given halo side

            @param winID a tuple of zeros and one +1 or -1.  To access
               the "north" side for instance, set side=(1, 0),
               (-1, 0) to access the south side, (0, 1) the east
               side, etc. This does not involve any communication.

            @return None if halo was not exposed (bad winID)
            """
            if winID in self.windows:
                return self.windows[winID]['slice']
            else:
                return None

    return GhostedDistArrayAny
22027
function setHeadersFromArray (res, headers) {
  for (var i = 0; i < headers.length; i++) {
    res.setHeader(headers[i][0], headers[i][1])
  }
}
910399
protected void putBatch(Object[] objectArray) {

        int index = 0;
        synchronized (this) {
            while (index < objectArray.length && objectArray[index] != null) {
                put(objectArray[index]);
                index++;
            }
        }
        return;
    }
438488
public void broadcast(INDArray array) {
        if (array == null)
            return;

        Nd4j.getExecutioner().commit();

        val config = OpProfiler.getInstance().getConfig();
        val locality = config.isCheckLocality();

        if (locality)
            config.setCheckLocality(false);

        int numDevices = Nd4j.getAffinityManager().getNumberOfDevices();
        for (int i = 0; i < numDevices; i++) {
            // if current thread equal to this device - we just save it, without duplication
            if (Nd4j.getAffinityManager().getDeviceForCurrentThread() == i) {
                set(i, array);
            } else {
                set(i, Nd4j.getAffinityManager().replicateToDevice(i, array));
            }

        }

        config.setCheckLocality(locality);
    }
241155
public static int createDims(FlatBufferBuilder bufferBuilder,INDArray arr) {
        int[] tensorDimOffsets = new int[arr.rank()];
        int[] nameOffset = new int[arr.rank()];
        for(int i = 0; i < tensorDimOffsets.length; i++) {
            nameOffset[i] = bufferBuilder.createString("");
            tensorDimOffsets[i] = TensorDim.createTensorDim(bufferBuilder,arr.size(i),nameOffset[i]);
        }

        return Tensor.createShapeVector(bufferBuilder,tensorDimOffsets);
    }
1072772
function(arr) {
      var n = [], l=arr.length,i;
      for(i = 0 ; i < l ; i++) {
         if( !lang.isNull(arr[i]) && !lang.isUndefined(arr[i]) ) {
            n.push(arr[i]);
         }
      }
      return n;
   }
765452
function GhostServer(rootApp) {
    this.rootApp = rootApp;
    this.httpServer = null;
    this.connections = {};
    this.connectionId = 0;

    // Expose config module for use externally.
    this.config = config;
}
9852
public static void insertSort(int[] arrays) {
        for (int i = 1; i < arrays.length; i++) {
            int currentNumber = arrays[i];
            int j = i - 1;
            while (j >= 0 && arrays[j] > currentNumber) {
                arrays[j + 1] = arrays[j--];
            }
            arrays[j + 1] = currentNumber;
        }
    }
1047021
public static SparseTensor empty(List<Integer> dimensionNumbers, List<Integer> dimensionSizes) {
    return empty(Ints.toArray(dimensionNumbers), Ints.toArray(dimensionSizes));
  }
1364433
public void setArrayValues(java.util.Collection<Value> arrayValues) {
        if (arrayValues == null) {
            this.arrayValues = null;
            return;
        }

        this.arrayValues = new java.util.ArrayList<Value>(arrayValues);
    }
4722
public static void assertArraySize(int size, double[] array, Supplier<String> errmsg){
		if(array.length != size){
			throw new IllegalArgumentException(errmsg.get());
		}
	}
113516
function empty(arg0, datatype) {
    var A;
    if (Array.isArray(arg0)) {
        A = new ndarray_1.NDArray({ shape: arg0, datatype: datatype });
    }
    else {
        A = new ndarray_1.NDArray({ shape: [arg0], datatype: datatype });
    }
    return A;
}
471201
@SafeVarargs
    static <T> List<T> joinArrays(final T[]... arrays) {
        final List<T> all = new ArrayList<>();
        for (final T[] array : arrays) {
            for (int j = 0; j < array.length; j++) {
                all.add(array[j]);
            }
        }
        return all;
    }