<p>
Extracts all diagonal elements from 'input' and places them inside the 'out' vector. Elements
are in sequential order.
</p>


@param input Matrix.  Not modified.
@param out Vector containing diagonal elements.  Modified.
429423
public static void diag( DMatrix5x5 input , DMatrix5 out ) {
        out.a1 = input.a11;
        out.a2 = input.a22;
        out.a3 = input.a33;
        out.a4 = input.a44;
        out.a5 = input.a55;
    }
1105490
public void setInputs(INDArray... inputs) {
        if (inputs != null && inputs.length != this.numInputArrays) {
            throw new IllegalArgumentException("Invalid input array: network has " + numInputArrays
                    + " inputs, but array is of length " + inputs.length);
        }
        this.inputs = inputs;
    }
365361
public static void magnitude(ZMatrixD1 input , DMatrixD1 output ) {
        if( input.numCols != output.numCols || input.numRows != output.numRows ) {
            throw new IllegalArgumentException("The matrices are not all the same dimension.");
        }

        final int length = input.getDataLength();

        for( int i = 0; i < length; i += 2 ) {
            double real = input.data[i];
            double imaginary = input.data[i+1];

            output.data[i/2] = Math.sqrt(real*real + imaginary*imaginary);
        }
    }
1008037
public void setInputs(java.util.Collection<String> inputs) {
        if (inputs == null) {
            this.inputs = null;
            return;
        }

        this.inputs = new java.util.ArrayList<String>(inputs);
    }
702973
private void resetMatrixB() {
		// find the magnitude of the largest diagonal element
		double maxDiag = 0;
		for( int i = 0; i < N; i++ ) {
			double d = Math.abs(B.get(i,i));
			if( d > maxDiag )
				maxDiag = d;
		}

		B.zero();
		for( int i = 0; i < N; i++ ) {
			B.set(i,i,maxDiag);
		}
	}
741390
public static void convert(DMatrix input , DMatrix output ) {
        if( output instanceof ReshapeMatrix ) {
            ((ReshapeMatrix)output).reshape(input.getNumRows(),input.getNumCols());
        } else {
            if (input.getNumRows() != output.getNumRows())
                throw new IllegalArgumentException("Number of rows do not match");
            if (input.getNumCols() != output.getNumCols())
                throw new IllegalArgumentException("Number of columns do not match");
        }

        for( int i = 0; i < input.getNumRows(); i++  ) {
            for( int j = 0; j < input.getNumCols(); j++ ) {
                output.unsafe_set(i,j,input.unsafe_get(i,j));
            }
        }
    }
692125
@Deprecated
	public void addFirstInput(Operator<IN1>... input) {
		this.input1 = Operator.createUnionCascade(this.input1, input);
	}
630169
public static DMatrixRMaj extractColumn(DMatrixRMaj a , int column , DMatrixRMaj out ) {
        if( out == null)
            out = new DMatrixRMaj(a.numRows,1);
        else if( !MatrixFeatures_DDRM.isVector(out) || out.getNumElements() != a.numRows )
            throw new MatrixDimensionException("Output must be a vector of length "+a.numRows);

        int index = column;
        for (int i = 0; i < a.numRows; i++, index += a.numCols ) {
            out.data[i] = a.data[index];
        }
        return out;
    }
813301
public static DMatrix3x3 convert(DMatrixRMaj input , DMatrix3x3 output ) {
        if( output == null)
            output = new DMatrix3x3();

        if( input.getNumRows() != output.getNumRows() )
            throw new IllegalArgumentException("Number of rows do not match");
        if( input.getNumCols() != output.getNumCols() )
            throw new IllegalArgumentException("Number of columns do not match");

        output.a11 = input.data[0];
        output.a12 = input.data[1];
        output.a13 = input.data[2];
        output.a21 = input.data[3];
        output.a22 = input.data[4];
        output.a23 = input.data[5];
        output.a31 = input.data[6];
        output.a32 = input.data[7];
        output.a33 = input.data[8];

        return output;
    }
970547
public void setInputs(Collection<String> inputs) {
    List<String> newInputs = new ArrayList<String>();
    if (inputs != null) {
      newInputs.addAll(inputs);
    }
    this.inputs = newInputs;
  }
275311
private void pldltptBK() throws Exception {
		//matrix S will be changed by the factorization, ad we do not want to change the matrix passed in by the client
		DoubleMatrix2D S = (rescaler==null)? this.Q.copy() : this.Q;
		int n = S.rows();
		DoubleMatrix2D A = S.copy();
		this.P = DoubleFactory2D.sparse.identity(n);
		this.D = DoubleFactory2D.sparse.make(n, n);
		this.L = DoubleFactory2D.sparse.make(n, n);
		DoubleMatrix2D LT = ALG.transpose(L);//@TODO: remove and work only with L
		double mu = (1 + Math.sqrt(17)) / 8;
		int s = 0;
		for (int j = 0; j < n; j++) {
			//log.debug("j: " + j);
			DoubleMatrix2D LPart = null;
			DoubleMatrix2D LTPart = null;
			DoubleMatrix2D APart = null;
			DoubleMatrix2D DPart = null;
			
			//Determine largest off-diagonal element in column j
			double lambda = -1;
			int r = -1;
			for(int rr = j+1; rr<n; rr++){
				double d = Math.abs(A.getQuick(rr, j)); 
				if(d > lambda){
					lambda = d;
					r = rr;
				}
			}
			double ajj = A.getQuick(j, j);
			if (Math.abs(ajj) > mu*lambda) {
				// Choose a 1 x 1 pivot,
				D.setQuick(j, j, ajj);
				s = 1;
			} else {
				//Determine largest off-diagonal element in row/column r
				double sigma = -1;
				for(int rr = 0; rr<n; rr++){
					if(rr==r){
						continue;
					}
					double d = Math.abs(A.getQuick(rr, r)); 
					if(d > sigma){
						sigma = d;
					}
				}
				if(sigma * Math.abs(ajj) > mu*lambda*lambda){
					//Choose a 1 x 1 pivot,
					D.setQuick(j, j, A.getQuick(j, j));
					s = 1;
				}else if(Math.abs(A.getQuick(r, r)) > mu*sigma){
					//Symmetrically permute row/column r to position j
				  A = ColtUtils.symmPermutation(A, r, j);
					P.setQuick(r, r, 0);
					P.setQuick(j, j, 0);
					P.setQuick(r, j, 1);
					P.setQuick(j, r, 1);
					//Choose a 1 x 1 pivot,
					D.setQuick(j, j, A.getQuick(j, j));
					s = 1;
				}else{
					//Symmetrically permute rows/columns r and p to positions j and j + 1 respectively
					int t = j+1;
					//int v = j+1;
					A = ColtUtils.symmPermutation(A, r, t);
					P.setQuick(r, r, 0);
					P.setQuick(t, t, 0);
					P.setQuick(r, t, 1);
					P.setQuick(t, r, 1);
//					A = Utils.symmPermutation(A, p, v);
//					P.setQuick(p, p, 0);
//					P.setQuick(v, v, 0);
//					P.setQuick(p, v, 1);
//					P.setQuick(v, p, 1);
					//Choose a 2 x pivot,
					//D(j:j+1)(j:j+1) =  A(j:j+1)(j:j+1)
					D.setQuick(j, j, A.getQuick(j, j));
					D.setQuick(j, j+1, A.getQuick(j, j+1));
					D.setQuick(j+1, j, A.getQuick(j+1, j));
					D.setQuick(j+1, j+1, A.getQuick(j+1, j+1));
					s = 2;
				}
			}
			//log.debug("s: " + s);

			// L(j:n)(j:j+s-1) = A(j:n)(j:j+s-1).DInv(j:j+s-1)(j:j+s-1)
			APart = A.viewPart(j, j, n - j, 1 + s - 1);
//			if(s==2){
//				try{
//					ColtUtils.invert2x2Matrix(D.viewPart(j, j, 1 + s - 1, 1 + s - 1));
//				}catch(Exception e){
//					throw e;
//				}
//			}
			DPart = ALG.inverse(D.viewPart(j, j, 1 + s - 1, 1 + s - 1));
			LPart = L.viewPart(j, j, n - j, 1 + s - 1);
			DoubleMatrix2D AD = ALG.mult(APart, DPart);
			for (int rr = 0; rr < LPart.rows(); rr++) {
				for (int cc = 0; cc < LPart.columns(); cc++) {
					LPart.setQuick(rr, cc, AD.getQuick(rr, cc));
				}
			}

			// A(j+s-1:n)(j+s-1:n) = A(j+s-1:n)(j+s-1:n) -
			// L(j+s-1:n)(j:j+s-1).D(j:j+s-1)(j:j+s-1).LT(j:j+s-1)(j+s-1:n)
			LPart = L.viewPart(j + s - 1, j, n - (j + s - 1), 1 + s - 1);
			DPart = D.viewPart(j, j, 1 + s - 1, 1 + s - 1);
			LTPart = LT.viewPart(j, j + s - 1, s, n - (j + s - 1));
			APart = A.viewPart(j + s - 1, j + s - 1, n - (j + s - 1), n - (j + s - 1));
			DoubleMatrix2D LDLT = ALG.mult(LPart, ALG.mult(DPart, LTPart));
			for (int rr = 0; rr < APart.rows(); rr++) {
				for (int cc = 0; cc < APart.columns(); cc++) {
					APart.setQuick(rr, cc, APart.getQuick(rr, cc) - LDLT.getQuick(rr, cc));
				}
			}
			//logger.debug("L: " + ArrayUtils.toString(L.toArray()));
			//logger.debug("A: " + ArrayUtils.toString(A.toArray()));

			j = j + s - 1;
		}
	}
716087
public void setMatrix(int[] matrix) {
		this.matrix = matrix;
		sum = 0;
		for (int i = 0; i < matrix.length; i++)
			sum += matrix[i];
	}
1071662
private void writeMatrix(DataOutputStream output, MLArray array) throws IOException
    {
        OSArrayTag tag;
        ByteArrayOutputStream buffer;
        DataOutputStream bufferDOS;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);

        //flags
        writeFlags(dos, array);

        //dimensions
        writeDimensions(dos, array);

        //array name
        writeName(dos, array);

        switch ( array.getType() )
        {
            case MLArray.mxCHAR_CLASS:
                //write char data
                buffer = new ByteArrayOutputStream();
                bufferDOS = new DataOutputStream(buffer);
                Character[] ac = ((MLChar)array).exportChar();
                for( int i = 0; i < ac.length; i++ )
                {
                	String temp = new StringBuffer().append(ac[i].charValue()).toString();
                	bufferDOS.write(temp.getBytes("UTF-8"));
                }
                tag = new OSArrayTag(MatDataTypes.miUTF8, buffer.toByteArray() );
                tag.writeTo( dos );

                break;
            case MLArray.mxDOUBLE_CLASS:

                tag = new OSArrayTag(MatDataTypes.miDOUBLE,
                                ((MLNumericArray<?>)array).getRealByteBuffer() );
                tag.writeTo( dos );

                //write real imaginary
                if ( array.isComplex() )
                {
                    tag = new OSArrayTag(MatDataTypes.miDOUBLE,
                            ((MLNumericArray<?>)array).getImaginaryByteBuffer() );
                    tag.writeTo( dos );
                }
                break;
            case MLArray.mxSINGLE_CLASS:

                tag = new OSArrayTag(MatDataTypes.miSINGLE,
                                ((MLNumericArray<?>)array).getRealByteBuffer() );
                tag.writeTo( dos );

                //write real imaginary
                if ( array.isComplex() )
                {
                    tag = new OSArrayTag(MatDataTypes.miSINGLE,
                            ((MLNumericArray<?>)array).getImaginaryByteBuffer() );
                    tag.writeTo( dos );
                }
                break;
            case MLArray.mxUINT8_CLASS:

                tag = new OSArrayTag(MatDataTypes.miUINT8,
                        ((MLNumericArray<?>)array).getRealByteBuffer() );
                tag.writeTo( dos );

                //write real imaginary
                if ( array.isComplex() )
                {
                    tag = new OSArrayTag(MatDataTypes.miUINT8,
                            ((MLNumericArray<?>)array).getImaginaryByteBuffer() );
                    tag.writeTo( dos );
                }
                break;
            case MLArray.mxINT8_CLASS:

                tag = new OSArrayTag(MatDataTypes.miINT8,
                        ((MLNumericArray<?>)array).getRealByteBuffer() );
                tag.writeTo( dos );

                //write real imaginary
                if ( array.isComplex() )
                {
                    tag = new OSArrayTag(MatDataTypes.miINT8,
                            ((MLNumericArray<?>)array).getImaginaryByteBuffer() );
                    tag.writeTo( dos );
                }
                break;
            case MLArray.mxINT16_CLASS:

                tag = new OSArrayTag(MatDataTypes.miINT16,
                        ((MLNumericArray<?>)array).getRealByteBuffer() );
                tag.writeTo( dos );

                //write real imaginary
                if ( array.isComplex() )
                {
                    tag = new OSArrayTag(MatDataTypes.miINT16,
                            ((MLNumericArray<?>)array).getImaginaryByteBuffer() );
                    tag.writeTo( dos );
                }
                break;
	    case MLArray.mxINT32_CLASS:
		tag = new OSArrayTag(MatDataTypes.miINT32,
			((MLNumericArray<?>)array).getRealByteBuffer() );
		tag.writeTo( dos );

		if ( array.isComplex() )
		{
		    tag = new OSArrayTag(MatDataTypes.miINT32,
		         ((MLNumericArray<?>)array).getImaginaryByteBuffer() );
		    tag.writeTo( dos );
		}
		break;
            case MLArray.mxINT64_CLASS:

                tag = new OSArrayTag(MatDataTypes.miINT64,
                        ((MLNumericArray<?>)array).getRealByteBuffer() );
                tag.writeTo( dos );

                //write real imaginary
                if ( array.isComplex() )
                {
                    tag = new OSArrayTag(MatDataTypes.miINT64,
                            ((MLNumericArray<?>)array).getImaginaryByteBuffer() );
                    tag.writeTo( dos );
                }
                break;
            case MLArray.mxUINT64_CLASS:

                tag = new OSArrayTag(MatDataTypes.miUINT64,
                        ((MLNumericArray<?>)array).getRealByteBuffer() );
                tag.writeTo( dos );

                //write real imaginary
                if ( array.isComplex() )
                {
                    tag = new OSArrayTag(MatDataTypes.miUINT64,
                            ((MLNumericArray<?>)array).getImaginaryByteBuffer() );
                    tag.writeTo( dos );
                }
                break;
            case MLArray.mxSTRUCT_CLASS:
                //field name length
                int itag = 4 << 16 | MatDataTypes.miINT32 & 0xffff;
                dos.writeInt( itag );
                dos.writeInt( ((MLStructure)array).getMaxFieldLenth() );

                //get field names
                tag = new OSArrayTag(MatDataTypes.miINT8, ((MLStructure)array).getKeySetToByteArray() );
                tag.writeTo( dos );

                for ( MLArray a : ((MLStructure)array).getAllFields() )
                {
                    writeMatrix(dos, a);
                }
                break;
            case MLArray.mxCELL_CLASS:
                for ( MLArray a : ((MLCell)array).cells() )
                {
                    writeMatrix(dos, a);
                }
                break;
            case MLArray.mxSPARSE_CLASS:
                int[] ai;
                //write ir

                buffer = new ByteArrayOutputStream();
                bufferDOS = new DataOutputStream(buffer);
                ai = ((MLSparse)array).getIR();
                for ( int i : ai )
                {
                        bufferDOS.writeInt( i );
                }
                tag = new OSArrayTag(MatDataTypes.miINT32, buffer.toByteArray() );
                tag.writeTo( dos );
                //write jc
                buffer = new ByteArrayOutputStream();
                bufferDOS = new DataOutputStream(buffer);
                ai = ((MLSparse)array).getJC();
                for ( int i : ai )
                {
                        bufferDOS.writeInt( i );
                }
                tag = new OSArrayTag(MatDataTypes.miINT32, buffer.toByteArray() );
                tag.writeTo( dos );
                //write real
                buffer = new ByteArrayOutputStream();
                bufferDOS = new DataOutputStream(buffer);

                Double[] ad = ((MLSparse)array).exportReal();

                for ( int i = 0; i < ad.length; i++ )
                {
                    bufferDOS.writeDouble( ad[i].doubleValue() );
                }

                tag = new OSArrayTag(MatDataTypes.miDOUBLE, buffer.toByteArray() );
                tag.writeTo( dos );
                //write real imaginary
                if ( array.isComplex() )
                {
                    buffer = new ByteArrayOutputStream();
                    bufferDOS = new DataOutputStream(buffer);
                    ad = ((MLSparse)array).exportImaginary();
                    for ( int i = 0; i < ad.length; i++ )
                    {
                        bufferDOS.writeDouble( ad[i].doubleValue() );
                    }
                    tag = new OSArrayTag(MatDataTypes.miDOUBLE, buffer.toByteArray() );
                    tag.writeTo( dos );
                }
                break;
            default:
                throw new MatlabIOException("Cannot write matrix of type: " + MLArray.typeToString( array.getType() ));

        }


        //write matrix
        output.writeInt(MatDataTypes.miMATRIX); //matrix tag
        output.writeInt( baos.size() ); //size of matrix
        output.write( baos.toByteArray() ); //matrix data
    }
6984
public void add(String input) {
        TrieNode currentNode = root;

        for(char c: input.toCharArray()) {
            Map<Character, TrieNode> children = currentNode.getChildren();
            TrieNode matchingNode = children.get(c);
            if(matchingNode != null) {
                currentNode = matchingNode;
            } else {
                TrieNode newNode = new TrieNode();
                children.put(c, newNode);
                currentNode = newNode;
            }
        }
        currentNode.end=true; // this is the end of an input that was added, there may be more children
    }
1022487
public static void printMatrix(double[][] matrix)
    {
        StringBuffer sb = new StringBuffer();
        sb.append('[').append('\n');
        for ( double[] line : matrix ) {
            for ( double column : line ) {
                sb.append(column).append(", ");
            }
            sb.append('\n');
        }
        sb.append(']');
        System.out.println(sb.toString());
    }
1005258
public static DMatrixRMaj convert(DMatrix2 input , DMatrixRMaj output ) {
        if( output == null)
            output = new DMatrixRMaj(2,1);

        if( output.getNumRows() != 1 && output.getNumCols() != 1 )
            throw new IllegalArgumentException("One row or column must have a length of 1 for it to be a vector");
        int length = Math.max(output.getNumRows(),output.getNumCols());
        if( length != 2 )
            throw new IllegalArgumentException("Length of input vector is not 2.  It is "+length);

        output.data[0] = input.a1;
        output.data[1] = input.a2;

        return output;
    }
990311
public static void diag( DMatrix6x6 input , DMatrix6 out ) {
        out.a1 = input.a11;
        out.a2 = input.a22;
        out.a3 = input.a33;
        out.a4 = input.a44;
        out.a5 = input.a55;
        out.a6 = input.a66;
    }