/* (non-Javadoc)
@see org.joml.Matrix4dc#reflect(double, double, double, double, org.joml.Matrix4d)
6169
public Matrix4d reflect(double a, double b, double c, double d, Matrix4d dest) {
        if ((properties & PROPERTY_IDENTITY) != 0)
            return dest.reflection(a, b, c, d);
        if ((properties & PROPERTY_IDENTITY) != 0)
            return dest.reflection(a, b, c, d);
        else if ((properties & PROPERTY_AFFINE) != 0)
            return reflectAffine(a, b, c, d, dest);
        return reflectGeneric(a, b, c, d, dest);
    }
452204
@Override
  public void evaluate(DoubleSolution solution) {
    int numberOfVariables = getNumberOfVariables() ;

    double[] x = new double[numberOfVariables] ;

    for (int i = 0; i < numberOfVariables; i++) {
      x[i] = solution.getVariableValue(i) ;
    }

    double sum = 0.0 ;
    for (int var = 0; var < numberOfVariables; var++) {
      double value = x[var];
      sum += value * value;
    }

    solution.setObjective(0, sum);
  }
18573
public Matrix4d getRepeatTransform(int repeat){

		Matrix4d transform = new Matrix4d();
		transform.setIdentity();

		int[] counts = getAxisCounts(repeat);

		for(int t = counts.length-1; t>=0; t--) {
			if( counts[t] == 0 )
				continue;
			Matrix4d axis = new Matrix4d(axes.get(t).getOperator());
			for(int i=0;i<counts[t];i++) {
				transform.mul(axis);
			}
		}
		return transform;
	}
932379
public Matrix4x3f reflection(Vector3fc normal, Vector3fc point) {
        return reflection(normal.x(), normal.y(), normal.z(), point.x(), point.y(), point.z());
    }
498361
public Matrix4d add(Matrix4dc other, Matrix4d dest) {
        dest.m00 = m00 + other.m00();
        dest.m01 = m01 + other.m01();
        dest.m02 = m02 + other.m02();
        dest.m03 = m03 + other.m03();
        dest.m10 = m10 + other.m10();
        dest.m11 = m11 + other.m11();
        dest.m12 = m12 + other.m12();
        dest.m13 = m13 + other.m13();
        dest.m20 = m20 + other.m20();
        dest.m21 = m21 + other.m21();
        dest.m22 = m22 + other.m22();
        dest.m23 = m23 + other.m23();
        dest.m30 = m30 + other.m30();
        dest.m31 = m31 + other.m31();
        dest.m32 = m32 + other.m32();
        dest.m33 = m33 + other.m33();
        dest.properties = 0;
        return dest;
    }
1014128
public void factorize(boolean checkSymmetry) throws Exception{
		if (checkSymmetry && !Property.TWELVE.isSymmetric(Q)) {
			throw new Exception("Matrix is not symmetric");
		}
		
		if(this.rescaler != null){
			double[] cn_00_original = null;
			double[] cn_2_original = null;
			double[] cn_00_scaled = null;
			double[] cn_2_scaled = null;
			if(log.isDebugEnabled()){
				cn_00_original = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(ColtUtils.fillSubdiagonalSymmetricMatrix(Q).toArray()), Integer.MAX_VALUE);
				log.debug("cn_00_original Q before scaling: " + ArrayUtils.toString(cn_00_original));
				cn_2_original = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(ColtUtils.fillSubdiagonalSymmetricMatrix(Q).toArray()), 2);
				log.debug("cn_2_original Q before scaling : " + ArrayUtils.toString(cn_2_original));
			}
			//scaling the Q matrix, we have:
			//Q1 = U.Q.U[T] = U.L.L[T].U[T] = (U.L).(U.L)[T] 
			//and because U is diagonal it preserves the triangular form of U.L, so
			//Q1 = U.Q.U[T] = L1.L1[T] is the new Cholesky decomposition  
			DoubleMatrix1D Uv = rescaler.getMatrixScalingFactorsSymm(Q);
			if(log.isDebugEnabled()){
				boolean checkOK = rescaler.checkScaling(ColtUtils.fillSubdiagonalSymmetricMatrix(Q), Uv, Uv);
				if(!checkOK){
					log.warn("Scaling failed (checkScaling = false)");
				}
			}
			this.U = Uv;
			this.Q = (SparseDoubleMatrix2D) ColtUtils.diagonalMatrixMult(Uv, Q, Uv);
			if(log.isDebugEnabled()){
				cn_00_scaled = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(ColtUtils.fillSubdiagonalSymmetricMatrix(Q).toArray()), Integer.MAX_VALUE);
				log.debug("cn_00_scaled Q after scaling : " + ArrayUtils.toString(cn_00_scaled));
				cn_2_scaled = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(ColtUtils.fillSubdiagonalSymmetricMatrix(Q).toArray()), 2);
				log.debug("cn_2_scaled Q after scaling  : " + ArrayUtils.toString(cn_2_scaled));
				
				if(cn_00_original[0] < cn_00_scaled[0] || cn_2_original[0] < cn_2_scaled[0]){
					//log.info("Q: " + ArrayUtils.toString(ColtUtils.fillSubdiagonalSymmetricMatrix(Q).toArray()));
					log.warn("Problematic scaling");
					//throw new RuntimeException("Scaling failed");
				}
			}
		}
		
		double threshold = Utils.getDoubleMachineEpsilon();
		//elements of L are stored in a single array for i<diagonalLength, 
		//and with arrays of dimension i+1 for i>=diagonalLength
		this.LData = new double[dim - diagonalLength + 1][];
		double[] LData0 = new double[diagonalLength];
		LData[0] = LData0;
		
		if(dim - diagonalLength == 1 && Double.compare(Q.getQuick(dim-1, dim-1), 1.)==0){
			//TODO: the second condition can always be true if the matrix is normalized on the last element
			//closed form decomposition
			//@see "S.Boyd and L.Vandenberghe, Convex Optimization, p. 671"
			for (int i = 0; i < dim-1; i++) {
				double d = Q.getQuick(i, i);
				if (d < Utils.getDoubleMachineEpsilon()) {
					throw new Exception("not positive definite matrix");
				}
				LData0[i] = Math.sqrt(d);
			}
			//now the last row of L
			double[] LData1 = new double[dim];
			for(int j=0; j<dim - 1; j++){
				LData1[j] = Q.getQuick(dim-1, j) / LData0[j];
			}
			double d = 0;
			for(int k=0; k<diagonalLength; k++){
				d += Math.pow(Q.getQuick(dim-1, k), 2) / Q.getQuick(k, k);
			}
			LData1[dim-1] = Math.sqrt(1 - d);
			LData[1] = LData1;
		}else{
			for (int i = 0; i < dim; i++) {
			    if (i < diagonalLength) {
					double d = Q.getQuick(i, i);
					if(!(d > threshold)){
						throw new Exception("not positive definite matrix");
					}
					LData0[i] = Math.sqrt(d);
				} else {

					LData[i - diagonalLength + 1] = new double[i + 1];
					double[] LDataI = LData[i - diagonalLength + 1];

					// j < i
					for (int j = 0; j < diagonalLength; j++) {
						// here LData is not null only in its diagonal
						LDataI[j] = 1.0 / LData[0][j] * (Q.getQuick(i, j));
					}
					for (int j = diagonalLength; j < i; j++) {
						double[] LDataJ = LData[j - diagonalLength + 1];
						double sum = 0.0;
						for (int k = 0; k < j; k++) {
							sum += LDataI[k] * LDataJ[k];
						}
						LDataI[j] = 1.0 / LDataJ[j] * (Q.getQuick(i, j) - sum);
					}
					// j==i
					double sum = 0.0;
					for (int k = 0; k < i; k++) {
						sum += Math.pow(LDataI[k], 2);
					}
					double d = Q.getQuick(i, i) - sum;
					if (d < Utils.getDoubleMachineEpsilon()) {
						throw new Exception("not positive definite matrix");
					}
					LDataI[i] = Math.sqrt(d);
				}
			}
		}
	}
177004
@Override
  public void evaluate(DoubleSolution solution) {
    int numberOfVariables = getNumberOfVariables() ;

    double[] x = new double[numberOfVariables] ;

    for (int i = 0; i < numberOfVariables; i++) {
      x[i] = solution.getVariableValue(i) ;
    }

    double result = 0.0;
    double a = 10.0;
    double w = 2 * Math.PI;

    for (int i = 0; i < numberOfVariables; i++) {
      result += x[i] * x[i] - a * Math.cos(w * x[i]);
    }
    result += a * numberOfVariables;

    solution.setObjective(0, result);
  }
1110923
def reflect(src, roffset, rpercent, rstrength)
      tmp_cc = Cairo::Context.new(Cairo::ImageSurface.new(src.width, src.height * (1.0 + rpercent) + roffset))
      tmp_cc.set_source(src, 0, 0)
      tmp_cc.paint
      # Flip affine magic from: http://cairographics.org/matrix_transform/
      matrix = Cairo::Matrix.new(1, 0, 0, -1, 0, 2 * src.height + roffset)
      tmp_cc.transform(matrix) # flips the coordinate system
      top_y    = src.height    # top of the reflection
      bottom_y = src.height * (1.0 - rpercent) + roffset # bottom of the reflection
      gradient = Cairo::LinearPattern.new(0, top_y, 0, bottom_y)
      gradient.add_color_stop_rgba(0.0, 0, 0, 0, rstrength) # start a little reflected
      gradient.add_color_stop_rgba(1.0, 0, 0, 0, 0.0)       # fade to nothing
      tmp_cc.set_source(src, 0, 0)
      tmp_cc.mask(gradient)
      return tmp_cc.target
    end
770261
public static void setMatrix(final double[][] m1, final int r0, final int r1, final int c0, final int c1, final double[][] m2) {
    assert r0 <= r1 && c0 <= c1 : ERR_INVALID_RANGE;
    assert r1 <= m1.length && c1 <= m1[0].length : ERR_MATRIX_DIMENSIONS;
    final int coldim = c1 - c0;
    for(int i = r0; i < r1; i++) {
      System.arraycopy(m2[i - r0], 0, m1[i], c0, coldim);
    }
  }
1298405
public void set( int index , double value ) {
        if( mat.getType() == MatrixType.DDRM ) {
            ((DMatrixRMaj) mat).set(index, value);
        } else if( mat.getType() == MatrixType.FDRM ) {
            ((FMatrixRMaj) mat).set(index, (float)value);
        } else {
            throw new RuntimeException("Not supported yet for this matrix type");
        }
    }
1241923
private void calMatrix() throws StructureException
	{
		int     i, j;
		double  dis;
		for(i = 0; i < pro1Len; i ++)   {
			for(j = 0; j < pro2Len; j ++)   {
				dis = Calc.getDistance(cod1[i],cod2[j]);

				if(dis < Dc) {
					sij[i][j] = Dc - dis;
				}
				else  {
					sij[i][j] = 0;
				}
			}
		}
	}
1334511
public double compute( DMatrix1Row mat ) {
        if( width != mat.numCols || width != mat.numRows ) {
            throw new RuntimeException("Unexpected matrix dimension");
        }

        // make sure everything is in the proper state before it starts
        initStructures();

//        System.arraycopy(mat.data,0,minorMatrix[0],0,mat.data.length);

        int level = 0;
        while( true ) {
            int levelWidth = width-level;
            int levelIndex = levelIndexes[level];

            if( levelIndex == levelWidth ) {
                if( level == 0 ) {
                    return levelResults[0];
                }
                int prevLevelIndex = levelIndexes[level-1]++;

                double val = mat.get((level-1)*width+levelRemoved[level-1]);
                if( prevLevelIndex % 2 == 0 ) {
                    levelResults[level-1] += val * levelResults[level];
                } else {
                    levelResults[level-1] -= val * levelResults[level];
                }

                putIntoOpen(level-1);

                levelResults[level] = 0;
                levelIndexes[level] = 0;
                level--;
            } else {
                int excluded = openRemove( levelIndex );

                levelRemoved[level] = excluded;

                if( levelWidth == minWidth ) {
                    createMinor(mat);
                    double subresult = mat.get(level*width+levelRemoved[level]);

                    subresult *= UnrolledDeterminantFromMinor_DDRM.det(tempMat);

                    if( levelIndex % 2 == 0 ) {
                        levelResults[level] += subresult;
                    } else {
                        levelResults[level] -= subresult;
                    }

                    // put it back into the list
                    putIntoOpen(level);
                    levelIndexes[level]++;
                } else {
                    level++;
                }
            }
        }
    }
179836
public Vector4d mul(Matrix4fc mat, Vector4d dest) {
        if ((mat.properties() & Matrix4fc.PROPERTY_AFFINE) != 0)
            return mulAffine(mat, dest);
        return mulGeneric(mat, dest);
    }
119516
public Vector3d reflect(Vector3dc normal, Vector3d dest) {
        return reflect(normal.x(), normal.y(), normal.z(), dest);
    }
1105523
public void applyMatrix()
	{
		transformMatrix.translate(new Vector3f(-0.5F, -0.5F, -0.5F));

		for (Vertex v : vertexes)
			v.applyMatrix(transformMatrix);

		resetMatrix();

		return;
	}
282375
void mirror() {
    for (int x = 0; x < bitMatrix.getWidth(); x++) {
      for (int y = x + 1; y < bitMatrix.getHeight(); y++) {
        if (bitMatrix.get(x, y) != bitMatrix.get(y, x)) {
          bitMatrix.flip(y, x);
          bitMatrix.flip(x, y);
        }
      }
    }
  }
1108978
@Override
  public void evaluate(DoubleSolution solution) {

    int numberOfVariables = solution.getNumberOfVariables();
    int numberOfObjectives = solution.getNumberOfObjectives();

    double[] x = new double[numberOfVariables];
    double[] f = new double[numberOfObjectives];

    for (int i = 0; i < numberOfVariables; i++) {
      x[i] = solution.getVariableValue(i);
    }

    // change x
    for (int i = numberOfObjectives - 1; i < numberOfVariables; i++) {
      x[i] = (1 + Math.cos((i + 1) / (double) numberOfVariables * Math.PI / 2)) * x[i] - 10 * x[0];
    }
    // evaluate eta,g
    double[] g = new double[numberOfObjectives];
    double sub1;
    for (int i = 0; i < numberOfObjectives; i = i + 2) {
      double[] tx = new double[sublen15[i]];
      sub1 = 0;
      for (int j = 0; j < nk15; j++) {
        System
            .arraycopy(x, len15[i] + numberOfObjectives - 1 + j * sublen15[i], tx, 0, sublen15[i]);
        sub1 += Griewank(tx);
      }
      g[i] = sub1 / (nk15 * sublen15[i]);
    }

    for (int i = 1; i < numberOfObjectives; i = i + 2) {
      double[] tx = new double[sublen15[i]];
      sub1 = 0;
      for (int j = 0; j < nk15; j++) {
        System
            .arraycopy(x, len15[i] + numberOfObjectives - 1 + j * sublen15[i], tx, 0, sublen15[i]);
        sub1 += Sphere(tx);
      }
      g[i] = sub1 / (nk15 * sublen15[i]);
    }

    // evaluate fm,fm-1,...,2,f1
    double subf1 = 1;
    f[numberOfObjectives - 1] =
        (1 - Math.sin(Math.PI * x[0] / 2)) * (1 + g[numberOfObjectives - 1]);
    for (int i = numberOfObjectives - 2; i > 0; i--) {
      subf1 *= Math.cos(Math.PI * x[numberOfObjectives - i - 2] / 2);
      f[i] = (1 - subf1 * Math.sin(Math.PI * x[numberOfObjectives - i - 1] / 2)) * (1 + g[i] + g[i
          + 1]);
    }
    f[0] = (1 - subf1 * Math.cos(Math.PI * x[numberOfObjectives - 2] / 2)) * (1 + g[0] + g[1]);

    for (int i = 0; i < numberOfObjectives; i++) {
      solution.setObjective(i, f[i]);
    }

  }