Construct a matrix of values for the given list of constraints
433757
def build_constraint_matrix(constrs)
      cbeg = []
      cind = []
      cval = []
      constrs.each.map do |constr|
        cbeg << cind.length
        constr.expression.terms.each do |var, coeff|
          cind << var.index
          cval << coeff
        end
      end

      [cbeg, cind, cval]
    end
1178258
def _add_constraints(self, relation):
        
        expression = relation.expression
        pairs = []
        for value_set in expression.value_sets():
            ind, val = zip(*((self._variables[variable], float(value))
                             for variable, value in value_set))
            pairs.append(cp.SparsePair(ind=ind, val=val))

        names = [next(self._constr_names) for _ in pairs]

        sense = self.CONSTR_SENSE_MAP[relation.sense]
        self._cp.linear_constraints.add(
            names=names, lin_expr=pairs,
            senses=tuple(repeat(sense, len(pairs))),
            rhs=tuple(repeat(float(-expression.offset), len(pairs))))

        return names
349045
def table2val_matrix(table):
    """"""
    if not is_simpletable(table):
        raise NotSimpleTable("Not able read a cell in the table as a string")
    rows = []
    for tr in table('tr'):
        row = []
        for td in tr('td'):
            td = tdbr2EOL(td)
            try:
                val = td.contents[0]
            except IndexError:
                row.append('')
            else:
                try:
                    val = float(val)
                    row.append(val)
                except ValueError:
                    row.append(val)
        rows.append(row)
    return rows
966043
def matrix_from_edges(edges):
    ''''''
    max_col = 0
    cols = []
    rows = []
    vals = []
    if type(edges) is defaultdict:
        edge_list = []
        for i, neighbors in edges.items():
            for j in neighbors:
                if i <= j:
                    edge_list.append((i,j))
        edges = edge_list
    for i, edge in enumerate(edges):
        s, t = edge[0], edge[1]
        weight = 1 if len(edge) == 2 else edge[2]
        cols.append(min(s,t))
        cols.append(max(s,t))
        rows.append(i)
        rows.append(i)
        vals.append(weight)
        vals.append(-weight)
        if cols[-1] > max_col:
            max_col = cols[-1]
    return coo_matrix((vals, (rows, cols)), shape=(rows[-1]+1, max_col+1))
579325
def withValues(cls, *values):
        

        class X(cls):
            subtypeSpec = cls.subtypeSpec + constraint.SingleValueConstraint(
                *values)

        X.__name__ = cls.__name__
        return X
486514
def constrained_by(self):
        
        if self._is_constraint is None:
            return []
        params = []
        for var in self.is_constraint._vars:
            param = var.get_parameter()
            if param.uniqueid != self.uniqueid:
                params.append(param)
        return params
89504
def makeQ(r1, r2, r3, r4=0):
    
    Q = np.asarray([
        [r4, -r3, r2, r1],
        [r3, r4, -r1, r2],
        [-r2, r1, r4, r3],
        [-r1, -r2, -r3, r4]])
    return Q
565436
def _build_matrix(p, q, deriv):
    """"""
    A = [([1 for _ in range(-p, q+1)])]
    for i in range(1, p + q + 1):
        A.append([j**i for j in range(-p, q+1)])
    return np.array(A)
375488
function fillMatrices(data, matrix, backtrackMatrix) {
  let nValues = matrix[0].length;

  // Shift values by the median to improve numeric stability
  let shift = data[Math.floor(nValues / 2)];

  // Cumulative sum and cumulative sum of squares for all values in data array
  let sums = [];
  let sumsOfSquares = [];

  // Initialize first column in matrix & backtrackMatrix
  for (let i = 0, shiftedValue; i < nValues; ++i) {
    shiftedValue = data[i] - shift;
    if (i === 0) {
      sums.push(shiftedValue);
      sumsOfSquares.push(shiftedValue * shiftedValue);
    } else {
      sums.push(sums[i - 1] + shiftedValue);
      sumsOfSquares.push(sumsOfSquares[i - 1] + shiftedValue * shiftedValue);
    }

    // Initialize for cluster = 0
    matrix[0][i] = ssq(0, i, sums, sumsOfSquares);
    backtrackMatrix[0][i] = 0;
  }

  // Initialize the rest of the columns
  let iMin;
  for (let cluster = 1; cluster < matrix.length; ++cluster) {
    if (cluster < matrix.length - 1) {
      iMin = cluster;
    } else {
      // No need to compute matrix[K-1][0] ... matrix[K-1][N-2]
      iMin = nValues - 1;
    }

    fillMatrixColumn(
      iMin,
      nValues - 1,
      cluster,
      matrix,
      backtrackMatrix,
      sums,
      sumsOfSquares
    );
  }
}
994813
def fermionic_constraints(a):
    
    substitutions = {}
    for i, ai in enumerate(a):
        substitutions[ai ** 2] = 0
        substitutions[Dagger(ai) ** 2] = 0
        substitutions[ai * Dagger(ai)] = 1.0 - Dagger(ai) * ai
        for aj in a[i+1:]:
            # substitutions[ai*Dagger(aj)] = -Dagger(ai)*aj
            substitutions[ai*Dagger(aj)] = -Dagger(aj)*ai
            substitutions[Dagger(ai)*aj] = -aj*Dagger(ai)
            substitutions[ai*aj] = -aj*ai
            substitutions[Dagger(ai) * Dagger(aj)] = - Dagger(aj) * Dagger(ai)

    return substitutions
1154267
protected static void constructM(List<Point2D_F64> obsPts,
									 DMatrixRMaj alphas, DMatrixRMaj M)
	{
		int N = obsPts.size();
		M.reshape(3*alphas.numCols,2*N,false);

		for( int i = 0; i < N; i++ ) {
			Point2D_F64 p2 = obsPts.get(i);

			int row = i*2;

			for( int j = 0; j < alphas.numCols; j++ ) {
				int col = j*3;

				double alpha = alphas.unsafe_get(i, j);
				M.unsafe_set(col, row, alpha);
				M.unsafe_set(col + 1, row, 0);
				M.unsafe_set(col + 2, row, -alpha * p2.x);
				M.unsafe_set(col    , row + 1, 0);
				M.unsafe_set(col + 1, row + 1, alpha);
				M.unsafe_set(col + 2, row + 1, -alpha * p2.y);
			}
		}
	}
609455
def _add_constraints(self, relation):
        
        expression = relation.expression
        names = []
        for value_set in expression.value_sets():
            values = ((self._variables[variable], value)
                      for variable, value in value_set)
            constr_name = next(self._constr_names)
            sense = self.CONSTR_SENSE_MAP[relation.sense]
            self._p.add_linear_constraint(
                sense=sense, values=values, rhs=-expression.offset,
                name=constr_name)
            names.append(constr_name)

        return names
1189604
def _split_constraints(constraints, concrete=True):
        

        splitted = [ ]
        for i in constraints:
            splitted.extend(i.split(['And']))

        l.debug("... splitted of size %d", len(splitted))

        concrete_constraints = [ ]
        variable_connections = { }
        constraint_connections = { }
        for n,s in enumerate(splitted):
            l.debug("... processing constraint with %d variables", len(s.variables))

            connected_variables = set(s.variables)
            connected_constraints = { n }

            if len(connected_variables) == 0:
                concrete_constraints.append(s)

            for v in s.variables:
                if v in variable_connections:
                    connected_variables |= variable_connections[v]
                if v in constraint_connections:
                    connected_constraints |= constraint_connections[v]

            for v in connected_variables:
                variable_connections[v] = connected_variables
                constraint_connections[v] = connected_constraints

        unique_constraint_sets = set()
        for v in variable_connections:
            unique_constraint_sets.add((frozenset(variable_connections[v]), frozenset(constraint_connections[v])))

        results = [ ]
        for v,c_indexes in unique_constraint_sets:
            results.append((set(v), [ splitted[c] for c in c_indexes ]))

        if concrete and len(concrete_constraints) > 0:
            results.append(({ 'CONCRETE' }, concrete_constraints))

        return results
581570
private GeneralMatrix fillVMatrix( int dim, Coordinate[] controlPoints ) {
        int controlPointsNum = controlPoints.length;
        GeneralMatrix V = new GeneralMatrix(controlPointsNum + 3, 1);

        for( int i = 0; i < controlPointsNum; i++ ) {
            V.setElement(i, 0, controlPoints[i].z);
        }

        V.setElement(V.getNumRow() - 3, 0, 0);
        V.setElement(V.getNumRow() - 2, 0, 0);
        V.setElement(V.getNumRow() - 1, 0, 0);

        return V;
    }
115679
function Matrix(m) {
  m = m || [1, 0, 0, 1, 0, 0];
  this.m = [m[0], m[1], m[2], m[3], m[4], m[5]];
}
135054
public static <T> Mapping<List<T>> list(Mapping<T> base, Constraint... constraints) {
        String mname = "list of " + base.meta().name;
        return new FieldMapping<>(
                InputMode.MULTIPLE,
                ((name, data) -> {
                    logger.debug("list - converting {}", name);

                    return indexes(name, data).stream()
                            .map(i -> base.convert(name + "[" + i + "]", data))
                            .collect(Collectors.toList());
                }),
                ((name, data, messages, options) -> {
                    logger.debug("list - validating {}", name);

                    return indexes(name, data).stream()
                            .flatMap(i -> base.validate(name + "[" + i + "]", data, messages, options).stream())
                            .collect(Collectors.toList());
                }), new MappingMeta(mname, List.class, base)
            ).constraint(constraints);
        }
271227
def transpose(matrix):

    

    return [[x[i] for x in matrix] for i in range(len(matrix[0]))]