Return the trace, the sum of the diagonal elements of the (super)
        operator.
540051
def trace(self) -> bk.BKTensor:
        
        N = self.qubit_nb
        R = self.rank
        if R == 1:
            raise ValueError('Cannot take trace of vector')

        tensor = bk.reshape(self.tensor, [2**(N*R//2)] * 2)
        tensor = bk.trace(tensor)
        return tensor
994200
public RayTraceResult trace()
	{
		RayTraceResult mop = null, firstHit = null;
		double tX, tY, tZ, min;
		int count = 0;
		boolean ret = false;

		int currentX = blockSrc.getX();
		int currentY = blockSrc.getY();
		int currentZ = blockSrc.getZ();

		while (!ret && count++ <= MAX_BLOCKS)
		{
			tX = ray.intersectX(currentX + (ray.direction.x > 0 ? 1 : 0));
			tY = ray.intersectY(currentY + (ray.direction.y > 0 ? 1 : 0));
			tZ = ray.intersectZ(currentZ + (ray.direction.z > 0 ? 1 : 0));

			min = getMin(tX, tY, tZ);

			// do not trace first block
			if (count != 1 || !hasOption(Options.IGNORE_FIRST_BLOCK))
				mop = rayTraceBlock(new BlockPos(currentX, currentY, currentZ), ray.getPointAt(min));
			if (firstHit == null)
				firstHit = mop;
			if (hasOption(Options.LOG_BLOCK_PASSED))
				blockPassed.put(new BlockPos(currentX, currentY, currentZ), mop);

			if (dest != null && currentX == blockDest.getX() && currentY == blockDest.getY() && currentZ == blockDest.getZ())
				ret = true;

			if (!ret)
			{
				if (min == tX)
					currentX += step.x;
				if (min == tY)
					currentY += step.y;
				if (min == tZ)
					currentZ += step.z;
			}

			if (dest != null && dest.equals(ray.getPointAt(min)))
				ret = true;

		}

		if (firstHit == null && dest != null)
			firstHit = new RayTraceResult(RayTraceResult.Type.MISS, dest.toVec3d(), null, new BlockPos(currentX, currentY, currentZ));

		firstHit = ChunkCollision.get().getRayTraceResult(	world,
															Pair.of(src, dest),
															firstHit,
															hasOption(Options.HIT_LIQUIDS),
															hasOption(Options.CHECK_COLLISION),
															true);

		if (!ret)
			MalisisCore.message("Trace fail : " + MAX_BLOCKS + " blocks passed (" + currentX + "," + currentY + "," + currentZ + ")");
		return firstHit;
	}
471593
def decompose_space(H, A):
    
    return OperatorTrace.create(
        OperatorTrace.create(A, over_space=H.operands[-1]),
        over_space=ProductSpace.create(*H.operands[:-1]))
513878
def traces(self):
        
        traces = []
        for v, c in zip(self.values.T, self.columns):
            traces.append(Trace(v, self.index, name=c))
        return traces
949926
def adjoint(self):
        """"""
        if not self.is_linear:
            raise ValueError('operator with nonzero pad_const ({}) is not'
                             ' linear and has no adjoint'
                             ''.format(self.pad_const))

        return -PartialDerivative(self.range, self.axis, self.domain,
                                  _ADJ_METHOD[self.method],
                                  _ADJ_PADDING[self.pad_mode],
                                  self.pad_const)
689529
def _call(self, x, out=None):
        """"""
        if out is None:
            return self.scalar * self.operator(x)
        else:
            self.operator(x, out=out)
            out *= self.scalar
975286
def _call(self, x):
        """"""
        if self.operator is None:
            return self.vector.inner(x) + self.constant
        elif self.vector is None:
            return x.inner(self.operator(x)) + self.constant
        else:
            tmp = self.operator(x)
            tmp += self.vector
            return x.inner(tmp) + self.constant
989578
public double trace() {
        double result = 0.0;

        for (int i = 0; i < rows; i++) {
            result += get(i, i);
        }

        return result;
    }
611250
@Override
	public double innerVectorHessian( DMatrixRMaj v ) {
		int M = A.getNumRows();

		double sum = 0;
		sum += innerProduct(v.data, 0, A, v.data, 0);
		sum += 2*innerProduct(v.data, 0, B, v.data, M);
		sum += innerProduct(v.data, M, D, v.data, M);

		return sum;
	}
941518
def sum(self):
        
        return self.mapPartitions(lambda x: [sum(x)]).fold(0, operator.add)
958530
public static double innerProdA(DMatrixD1 x, DMatrixD1 A , DMatrixD1 y )
    {
        int n = A.numRows;
        int m = A.numCols;

        if( x.getNumElements() != n )
            throw new IllegalArgumentException("Unexpected number of elements in x");
        if( y.getNumElements() != m )
            throw new IllegalArgumentException("Unexpected number of elements in y");

        double result = 0;

        for( int i = 0; i < m; i++ ) {
            double total = 0;

            for( int j = 0; j < n; j++ ) {
                total += x.get(j)*A.unsafe_get(j,i);
            }

            result += total*y.get(i);
        }

        return result;
    }
1139284
def _call(self, x, out=None):
        """"""
        if out is None:
            return self.operator(self.scalar * x)
        else:
            if self.__tmp is not None:
                tmp = self.__tmp
            else:
                tmp = self.domain.element()
            tmp.lincomb(self.scalar, x)
            self.operator(tmp, out=out)
474388
def _call(self, x, out=None):
        """"""
        # TODO: add optimization in case an operator appears repeatedly in a
        # row
        if out is None:
            out = self.range.zero()
            for i, j, op in zip(self.ops.row, self.ops.col, self.ops.data):
                out[i] += op(x[j])
        else:
            has_evaluated_row = np.zeros(len(self.range), dtype=bool)
            for i, j, op in zip(self.ops.row, self.ops.col, self.ops.data):
                if not has_evaluated_row[i]:
                    op(x[j], out=out[i])
                else:
                    # TODO: optimize
                    out[i] += op(x[j])

                has_evaluated_row[i] = True

            for i, evaluated in enumerate(has_evaluated_row):
                if not evaluated:
                    out[i].set_zero()

        return out
202948
def __get_trace_facvar(self, polynomial):
        
        facvar = [0] * (self.n_vars + 1)
        F = {}
        for i in range(self.matrix_var_dim):
            for j in range(self.matrix_var_dim):
                for key, value in \
                        polynomial[i, j].as_coefficients_dict().items():
                    skey = apply_substitutions(key, self.substitutions,
                                               self.pure_substitution_rules)
                    try:
                        Fk = F[skey]
                    except KeyError:
                        Fk = zeros(self.matrix_var_dim, self.matrix_var_dim)
                    Fk[i, j] += value
                    F[skey] = Fk
        # This is the tracing part
        for key, Fk in F.items():
            if key == S.One:
                k = 1
            else:
                k = self.monomial_index[key]
            for i in range(self.matrix_var_dim):
                for j in range(self.matrix_var_dim):
                    sym_matrix = zeros(self.matrix_var_dim,
                                       self.matrix_var_dim)
                    sym_matrix[i, j] = 1
                    facvar[k+i*self.matrix_var_dim+j] = (sym_matrix*Fk).trace()
        facvar = [float(f) for f in facvar]
        return facvar
584354
def _ss(self, class_def):
        """"""
        yc = self.y[class_def]
        css = yc - yc.mean()
        css *= css
        return sum(css)
1316812
def inv(self):
        

        if self.isdiagonal:
            inv = 1.0 / self.__x
            if (np.any(~np.isfinite(inv))):
                idx = np.isfinite(inv)
                np.savetxt("testboo.dat",idx)
                invalid = [self.row_names[i] for i in range(idx.shape[0]) if idx[i] == 0.0]
                raise Exception("Matrix.inv has produced invalid floating points " +
                                " for the following elements:" + ','.join(invalid))
            return type(self)(x=inv, isdiagonal=True,
                              row_names=self.row_names,
                              col_names=self.col_names,
                              autoalign=self.autoalign)
        else:
            return type(self)(x=la.inv(self.__x), row_names=self.row_names,
                              col_names=self.col_names,
                              autoalign=self.autoalign)
428758
private void makeSingularPositive() {
        numSingular = qralg.getNumberOfSingularValues();
        singularValues = qralg.getSingularValues();

        for( int i = 0; i < numSingular; i++ ) {
            double val = qralg.getSingularValue(i);

            if( val < 0 ) {
                singularValues[i] = 0.0 - val;

                if( computeU ) {
                    // compute the results of multiplying it by an element of -1 at this location in
                    // a diagonal matrix.
                    int start = i* Ut.numCols;
                    int stop = start+ Ut.numCols;

                    for( int j = start; j < stop; j++ ) {
                        Ut.set(j, 0.0 - Ut.get(j));
                    }
                }
            } else {
                singularValues[i] = val;
            }
        }
    }