Creates a tensor whose only non-zero entries are on its main
diagonal.

@param dimensionNumbers
@param dimensionSizes
@param value weight assigned to the keys on the main diagonal.
@return
198079
public static SparseTensor diagonal(int[] dimensionNumbers, int[] dimensionSizes, double value) {
    int minDimensionSize = Ints.min(dimensionSizes);
    double[] values = new double[minDimensionSize];
    Arrays.fill(values, value);

    return diagonal(dimensionNumbers, dimensionSizes, values);
  }
1032859
public void put(NumberVector val, double weight) {
    assert (val.getDimensionality() == elements.length);
    if(weight == 0) {
      return; // Skip zero weights.
    }
    final double nwsum = weight + wsum;
    for(int i = 0; i < elements.length; i++) {
      final double delta = val.doubleValue(i) - elements[i];
      final double rval = delta * weight / nwsum;
      elements[i] += rval;
    }
    wsum = nwsum;
  }
1068572
public DimensionKeyDescription withDimensions(java.util.Map<String, String> dimensions) {
        setDimensions(dimensions);
        return this;
    }
1363931
@Override
    public INDArray scalar(int value, long offset) {
        return create(new int[] {value}, new long[0], new long[0], DataType.INT, Nd4j.getMemoryManager().getCurrentWorkspace());
    }
1218643
public Matrix4 set (float[] values) {
        return set(values[0], values[1], values[2], values[3],
                   values[4], values[5], values[6], values[7],
                   values[8], values[9], values[10], values[11],
                   values[12], values[13], values[14], values[15]);
    }
1228815
public void setDimensions(java.util.Collection<Dimension> dimensions) {
        if (dimensions == null) {
            this.dimensions = null;
            return;
        }

        this.dimensions = new com.amazonaws.internal.SdkInternalList<Dimension>(dimensions);
    }
930260
public static INDArray rsub(INDArray x, INDArray y, INDArray z, int... dimensions) {
        if(dimensions == null || dimensions.length == 0) {
            validateShapesNoDimCase(x,y,z);
            return Nd4j.getExecutioner().exec(new OldSubOp(x,y,z));
        }

        return Nd4j.getExecutioner().exec(new BroadcastRSubOp(x,y,z,dimensions));
    }
900924
public static INDArrayIndex[] createCoveringShape(int[] shape) {
        INDArrayIndex[] ret = new INDArrayIndex[shape.length];
        for (int i = 0; i < ret.length; i++) {
            ret[i] = NDArrayIndex.interval(0, shape[i]);
        }
        return ret;
    }
42428
def tensor_dimension_to_mesh_axis(self, tensor_dimension, mesh_shape):
    
    val = [i for i, mesh_dimension in enumerate(mesh_shape)
           if (tensor_dimension.name, mesh_dimension.name) in self._pairs]
    if len(val) > 1:
      raise ValueError(
          "Tensor dimension maps to multiple mesh dimensions"
          " tensor_dimension=%s mesh_shape=%s layout=%s"
          % (tensor_dimension, mesh_shape, self._pairs))
    return val[0] if val else None
230594
public SDVariable squaredNorm(SDVariable x, int... dimensions) {
        return squaredNorm(null, x, false, dimensions);
    }
820601
public static INDArray reshapeWeights(long[] shape, INDArray paramsView, char flatteningOrder) {
        return paramsView.reshape(flatteningOrder, shape);
    }
1068121
@Override
    public INDArray scalar(float value) {
        if (Nd4j.dataType() == DataType.FLOAT || Nd4j.dataType() == DataType.HALF)
            return create(new float[] {value}, new int[0], new int[0], 0);
        else if (Nd4j.dataType() == DataType.DOUBLE)
            return scalar((double) value);
        else
            return scalar((int) value);
    }
1032883
def create_Dim(self, name,value):
        '''
        
        '''
        if not self._dimensions.has_key(name) :
            self.message(3, 'Create dimension {0}:{1}'.format(name,value))
            self._dimensions[name]=value
            self._dimensions['_ndims']=len(self._dimensions) - 1
        else :
            self.message(3, 'Dimension {0} already exists'.format(name))
597024
public void add(int dimension, float value) {
        if(this.map.containsKey(dimension))
            this.map.put(dimension, this.map.get(dimension) + value);
        else
            this.map.put(dimension, value);
    }
1134610
public static SparseMatrix zero(int rows, int columns, int capacity) {
        return CRSMatrix.zero(rows, columns, capacity);
    }
778587
protected static final SparseTensor elementwiseMultiplyNaive(SparseTensor big, Tensor small) {
    // Compute a mapping from keyNums of big to keyNums of small.
    int[] bigDimensions = big.getDimensionNumbers();
    int[] smallDimensions = small.getDimensionNumbers();
    int[] bigDimensionSizes = big.getDimensionSizes();
    int smallDimensionInd = smallDimensions.length - 1;
    int bigDimensionInd = bigDimensions.length - 1;
    // divisors, modulos and multipliers store the mapping from
    // bigKeyNum to
    // smallKeyNum.
    // They contain a series of division, modulo and multiplication
    // operations
    // whose results are added to get a smallKeyNum.
    long[] divisors = new long[smallDimensions.length];
    long[] modulos = new long[smallDimensions.length];
    long[] multipliers = new long[smallDimensions.length];
    int divisorInd = 0;
    long divisor = 1;
    long multiplier = 1;
    long modulo = 1;
    while (bigDimensionInd >= 0 && smallDimensionInd >= 0) {
      while (bigDimensions[bigDimensionInd] != smallDimensions[smallDimensionInd]) {
        divisor *= bigDimensionSizes[bigDimensionInd];
        bigDimensionInd--;
      }
      divisors[divisorInd] = divisor;

      modulo = 1;
      while (bigDimensionInd >= 0 && smallDimensionInd >= 0 &&
          bigDimensions[bigDimensionInd] == smallDimensions[smallDimensionInd]) {
        divisor *= bigDimensionSizes[bigDimensionInd];
        modulo *= bigDimensionSizes[bigDimensionInd];
        bigDimensionInd--;
        smallDimensionInd--;
      }
      modulos[divisorInd] = modulo;
      multipliers[divisorInd] = multiplier;
      divisorInd++;
      multiplier *= modulo;
    }

    // The result tensor is no larger than the larger (superset of
    // dimensions)
    // tensor.
    long[] resultKeyInts = new long[big.size()];
    double[] resultValues = new double[big.size()];
    // How many result values have been filled so far.
    int resultInd = 0;

    long bigKeyNum, smallKeyNum;
    double value;
    int numElements = big.size();
    for (int bigInd = 0; bigInd < numElements; bigInd++) {
      bigKeyNum = big.indexToKeyNum(bigInd);
      // map bigKeyNum to a smallKeyNum
      smallKeyNum = 0;
      for (int i = 0; i < divisorInd; i++) {
        smallKeyNum += ((bigKeyNum / divisors[i]) % modulos[i]) * multipliers[i];
      }
      value = small.get(smallKeyNum);

      if (value != 0.0) {
        resultKeyInts[resultInd] = bigKeyNum;
        resultValues[resultInd] = value * big.getByIndex(bigInd);
        resultInd++;
      }
    }

    return resizeIntoTable(big.getDimensionNumbers(), big.getDimensionSizes(), resultKeyInts,
        resultValues, resultInd);
  }
827941
public static LinearSolverDense<DMatrixRMaj> general(int numRows , int numCols ) {
        if( numRows == numCols )
            return linear(numRows);
        else
            return leastSquares(numRows,numCols);
    }