Return pivot permutation vector as a one-dimensional double array
@return     (double) piv
19799
public double[] getDoublePivot () {
      double[] vals = new double[m];
      for (int i = 0; i < m; i++) {
         vals[i] = (double) piv[i];
      }
      return vals;
   }
183425
@Override
    public DataBuffer getVectorCoordinates() {
        int idx;
        if (isRowVector()) {
            idx = 1;
        } else if (isColumnVector()) {
            idx = 0;
        } else {
            throw new UnsupportedOperationException();
        }

        // FIXME: int cast
        int[] temp = new int[(int) length()];
        for (int i = 0; i < length(); i++) {
            temp[i] = getUnderlyingIndicesOf(i).getInt(idx);
        }
        return Nd4j.createBuffer(temp);
    }
136266
def toArray(self):
        
        if self.isTransposed:
            return np.asfortranarray(
                self.values.reshape((self.numRows, self.numCols)))
        else:
            return self.values.reshape((self.numRows, self.numCols), order='F')
867218
def permutation_t(vector)
      ByteVector.new(
        vector.each.with_index.inject([]) do |b_arr, (byte, index)|
          b_arr[T[index]] = byte
          b_arr
        end.map(&:to_i)
      )
    end
1064363
def pivot_table(expr, value_index, value_ty, index_index, index_ty, columns_index, columns_ty, aggfunc):
    

    weld_obj = WeldObject(encoder_, decoder_)
    zip_var = weld_obj.update(expr)
    if isinstance(expr, WeldObject):
        zip_var = expr.obj_id
        weld_obj.dependencies[zip_var] = expr

    if aggfunc == 'sum':
        weld_template = """
          let bs = for(
            %(zip_expr)s,
            {dictmerger[{%(ity)s,%(cty)s},%(vty)s,+], dictmerger[%(ity)s,i64,+], dictmerger[%(cty)s,i64,+]},
            |b, i, e| {merge(b.$0, {{e.$%(id)s, e.$%(cd)s}, e.$%(vd)s}),
                       merge(b.$1, {e.$%(id)s, 1L}),
                       merge(b.$2, {e.$%(cd)s, 1L})}
          );
          let agg_dict = result(bs.$0);
          let ind_vec = sort(map(tovec(result(bs.$1)), |x| x.$0), |x, y| compare(x,y));
          let col_vec = map(tovec(result(bs.$2)), |x| x.$0);
          let pivot = map(
            col_vec,
            |x:%(cty)s|
            map(ind_vec, |y:%(ity)s| f64(lookup(agg_dict, {y, x})))
        );
        {ind_vec, pivot, col_vec}
    """
    elif aggfunc == 'mean':
        weld_template = """
          let bs = for(
            %(zip_expr)s,
            {dictmerger[{%(ity)s,%(cty)s},{%(vty)s, i64},+], dictmerger[%(ity)s,i64,+], dictmerger[%(cty)s,i64,+]},
            |b, i, e| {merge(b.$0, {{e.$%(id)s, e.$%(cd)s}, {e.$%(vd)s, 1L}}),
                       merge(b.$1, {e.$%(id)s, 1L}),
                       merge(b.$2, {e.$%(cd)s, 1L})}
          );
          let agg_dict = result(bs.$0);
          let ind_vec = sort(map(tovec(result(bs.$1)), |x| x.$0), |x, y| compare(x,y));
          let col_vec = map(tovec(result(bs.$2)), |x| x.$0);
          let pivot = map(
            col_vec,
            |x:%(cty)s|
            map(ind_vec, |y:%(ity)s| (
              let sum_len_pair = lookup(agg_dict, {y, x});
              f64(sum_len_pair.$0) / f64(sum_len_pair.$1))
            )
        );
        {ind_vec, pivot, col_vec}
    """

    else:
        raise Exception("Aggregate operation %s not supported." % aggfunc)

    weld_obj.weld_code = weld_template % {"zip_expr": zip_var,
                                          "ity": index_ty,
                                          "cty": columns_ty,
                                          "vty": value_ty,
                                          "id": index_index,
                                          "cd": columns_index,
                                          "vd": value_index}
    return weld_obj
762216
def _asarray(self, vec):
        
        shape = self.domain[0, 0].shape + self.pshape
        arr = np.empty(shape, dtype=self.domain.dtype)
        for i, xi in enumerate(vec):
            for j, xij in enumerate(xi):
                arr[..., i, j] = xij.asarray()

        return arr
571621
public static int[] getMatrixMultiplyShape(int[] left, int[] right) {
        if(Shape.shapeIsScalar(left)) {
            return right;
        }

        if(Shape.shapeIsScalar(right)) {
            return left;
        }

        if (left.length != 2 && right.length != 2) {
            throw new IllegalArgumentException("Illegal shapes for matrix multiply. Must be of length 2. Left shape: "
                    + Arrays.toString(left) + ", right shape: " + Arrays.toString(right));
        }

        for(int i = 0; i < left.length; i++) {
            if(left[i] < 1)
                throw new ND4JIllegalStateException("Left shape contained value < 0 at index " + i + " - left shape " + Arrays.toString(left));
        }



        for(int i = 0; i < right.length; i++) {
            if(right[i] < 1)
                throw new ND4JIllegalStateException("Right shape contained value < 0 at index " + i + " - right shape " + Arrays.toString(right));
        }


        if (left.length > 1 && left[1] != right[0])
            throw new IllegalArgumentException("Columns of left not equal to rows of right: left shape " + Arrays.toString(left)
                    + ", right shape " + Arrays.toString(right));

        if(left.length < right.length) {
            if(left[0] == right[0]) {
                return new int[] {1, right[1]};
            }
        }

        int[] shape = {left[0], right[1]};
        return shape;
    }
1063345
def tuple_as_vec(xyzw):
        
        vec = Vector4()
        vec[0] = xyzw[0]
        vec[1] = xyzw[1]
        vec[2] = xyzw[2]
        vec[3] = xyzw[3]
        return vec
658174
def _generate_permutation(self, npoints):
        
        i = np.arange(0, npoints)
        # permutation
        p = np.random.permutation(npoints)
        ip = np.empty_like(p)
        # inverse permutation
        ip[p[i]] = i
        return p, ip
149280
public float[] toFloatArray() {
        if (isParallel())
            return collect(DoubleCollector.toFloatArray());
        java.util.Spliterator.OfDouble spliterator = spliterator();
        long size = spliterator.getExactSizeIfKnown();
        FloatBuffer buf;
        if (size >= 0 && size <= Integer.MAX_VALUE) {
            buf = new FloatBuffer((int) size);
            spliterator.forEachRemaining((DoubleConsumer) buf::addUnsafe);
        } else {
            buf = new FloatBuffer();
            spliterator.forEachRemaining((DoubleConsumer) buf::add);
        }
        return buf.toArray();
    }
1169640
public double[][] inverse() {
    // Build permuted identity matrix efficiently:
    double[][] b = new double[piv.length][m];
    for(int i = 0; i < piv.length; i++) {
      b[piv[i]][i] = 1.;
    }
    return solveInplace(b);
  }
1083085
private int rankPermutationLexicographically(int[] permutation) {
        int rank = 0;
        int n = permutation.length;
        int[] counter = new int[n + 1];
        for (int i = 1; i < permutation.length; i++) {
            counter[i] = permutation[i - 1] + 1;
        }
        for (int j = 1; j <= n; j++) {
            rank += (counter[j] - 1) * factorial(n - j);
            for (int i = j + 1; i <= n; i++) {
                if (counter[i] > counter[j]) {
                    counter[i]--;
                }
            }
        }
        return rank + 1;
    }
700412
public Matrix transformRow(int i, VectorFunction function) {
        Matrix result = copy();
        VectorIterator it = result.iteratorOfRow(i);

        while (it.hasNext()) {
            double x = it.next();
            int j = it.index();
            it.set(function.evaluate(j, x));
        }

        return result;
    }
343644
public PermutationMatrix getP() {
        PermutationMatrix perm = PermutationMatrix.fromPartialPivots(piv);
        perm.transpose();
        return perm;
    }
825787
public double[] copyValues1D()
    {
        double v[] = new double[nCols];

        for (int c = 0; c < nCols; ++c) {
            v[c] = values[0][c];
        }

        return v;
    }
97672
public double[] dataVector(V p) {
    return strongEigenvectors.length > 0 ? times(strongEigenvectors, transposeTimes(strongEigenvectors, minusEquals(p.toArray(), centroid))) : EMPTY_VECTOR;
  }
724962
public double[] unhomogeneRelativeVector(double[] v) {
    assert (v.length == dim + 1);
    double[] dv = new double[dim];
    System.arraycopy(v, 0, dv, 0, dim);
    assert (Math.abs(v[dim]) < Double.MIN_NORMAL);
    return dv;
  }