Writes the upper triangular matrix into the specified matrix.

@param upper Where the upper triangular matrix is writen to.
195832
@Override
    public ZMatrixRMaj getUpper(ZMatrixRMaj upper )
    {
        int numRows = LU.numRows < LU.numCols ? LU.numRows : LU.numCols;
        int numCols = LU.numCols;

        upper = UtilDecompositons_ZDRM.checkZerosLT(upper, numRows,numCols);

        for( int i = 0; i < numRows; i++ ) {
            for( int j = i; j < numCols; j++ ) {
                int indexLU = LU.getIndex(i,j);
                int indexU = upper.getIndex(i,j);

                double real = LU.data[indexLU];
                double imaginary = LU.data[indexLU+1];

                upper.data[indexU] = real;
                upper.data[indexU+1] = imaginary;
            }
        }

        return upper;
    }
631493
@Override
    public void write(float[] b) throws IOException {
        write("float[]");
        long code = 0;
        for (int i = 0; i < b.length; i++) {
            code = 31 * code + Float.floatToIntBits(b[i]);
        }
        write(code);
    }
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
    }
223603
@Override
    public void solve(ZMatrixRMaj B, ZMatrixRMaj X) {
        if( X.numRows != numCols )
            throw new IllegalArgumentException("Unexpected dimensions for X");
        else if( B.numRows != numRows || B.numCols != X.numCols )
            throw new IllegalArgumentException("Unexpected dimensions for B");

        int BnumCols = B.numCols;

        Y.reshape(numRows,1);
        Z.reshape(numRows,1);

        // solve each column one by one
        for( int colB = 0; colB < BnumCols; colB++ ) {

            // make a copy of this column in the vector
            for( int i = 0; i < numRows; i++ ) {
                int indexB = B.getIndex(i,colB);
                Y.data[i*2]   = B.data[indexB];
                Y.data[i*2+1] = B.data[indexB+1];
            }

            // Solve Qa=b
            // a = Q'b
            CommonOps_ZDRM.mult(Qt, Y, Z);

            // solve for Rx = b using the standard upper triangular solver
            TriangularSolver_ZDRM.solveU(R.data, Z.data, numCols);

            // save the results
            for( int i = 0; i < numCols; i++ ) {
                X.set(i,colB,Z.data[i*2],Z.data[i*2+1]);
            }
        }
    }
667640
void writeChildren(TreeMap<Character, Long> counts) {
    int firstIndex = trie.nodes.length();
    counts.forEach((k, v) -> {
      if (v > 0) trie.nodes.add(new NodeData(k, (short) -1, -1, v, -1));
    });
    short length = (short) (trie.nodes.length() - firstIndex);
    trie.ensureParentIndexCapacity(firstIndex, length, index);
    update(n -> n.setFirstChildIndex(firstIndex).setNumberOfChildren(length));
    data = null;
  }
1194715
public void write(final OutputStream out) throws IOException {
        if (this.byteOrder == ByteOrder.BIG_ENDIAN) {
            out.write(MAGIC_BIG_ENDIAN);
        } else {
            out.write(MAGIC_LITTLE_ENDIAN);
        }
        out.write(this.body);
    }
176171
public static void zeroTriangle( boolean upper , DMatrixRBlock A )
    {
        int blockLength = A.blockLength;

        if( upper ) {
            for( int i = 0; i < A.numRows; i += blockLength ) {
                int h = Math.min(blockLength,A.numRows-i);

                for( int j = i; j < A.numCols; j += blockLength ) {
                    int w = Math.min(blockLength,A.numCols-j);

                    int index = i*A.numCols + h*j;

                    if( j == i ) {
                        for( int k = 0; k < h; k++ ) {
                            for( int l = k+1; l < w; l++ ) {
                                A.data[index + w*k+l ] = 0;
                            }
                        }
                    } else {
                        for( int k = 0; k < h; k++ ) {
                            for( int l = 0; l < w; l++ ) {
                                A.data[index + w*k+l ] = 0;
                            }
                        }
                    }
                }
            }
        } else {
            for( int i = 0; i < A.numRows; i += blockLength ) {
                int h = Math.min(blockLength,A.numRows-i);

                for( int j = 0; j <= i; j += blockLength ) {
                    int w = Math.min(blockLength,A.numCols-j);

                    int index = i*A.numCols + h*j;

                    if( j == i ) {
                        for( int k = 0; k < h; k++ ) {
                            int z = Math.min(k,w);
                            for( int l = 0; l < z; l++ ) {
                                A.data[index + w*k+l ] = 0;
                            }
                        }
                    } else {
                        for( int k = 0; k < h; k++ ) {
                            for( int l = 0; l < w; l++ ) {
                                A.data[index + w*k+l ] = 0;
                            }
                        }
                    }
                }
            }
        }
    }
623160
public void write( DataOutput out ) throws IOException {
    WritableUtils.writeVInt(out, blocks.length);
    for(int i=0; i<blocks.length; i++) {
      blocks[i].write(out);
    }
  }
364968
private void removeDuplicateRow(DoubleMatrix1D c,
			DoubleMatrix2D A, DoubleMatrix1D b, 
			DoubleMatrix1D lb, DoubleMatrix1D ub, 
			DoubleMatrix1D ylb, DoubleMatrix1D yub,
			DoubleMatrix1D zlb, DoubleMatrix1D zub) {
		//the position 0 is for empty rows, 1 is for row singleton and 2 for row doubleton
		int startingLength = 3;
		for(int i=startingLength; i<vRowLengthMap.length; i++){
			int[] vRowLengthMapI = vRowLengthMap[i];
			if(vRowLengthMapI == null || vRowLengthMapI.length < 1){
				//no rows has this number of nz
				continue;
			}
			
			boolean stop = false;
			for(int j=0; !stop && j<vRowLengthMapI.length; j++){
				short prow = (short)vRowLengthMapI[j];//the row of A that has this number of nz
				if(vRowPositions[prow].length==0 || prow < nOfSlackVariables){
					//the upper left part of A is diagonal if there are the slack variables:
					//there is no sparsity superset possible 
					continue;
				}
				short[] vRowPositionsProw = vRowPositions[prow];
				if(vRowPositionsProw.length != i){
					log.debug("Row "+prow+" has an unexpected number of nz: expected " + i + " but is " + vRowPositionsProw.length);
					throw new IllegalStateException();
				}
				for(int si=i; !stop && si<vRowLengthMap.length; si++){
					//look into rows with superset sparsity pattern
					int[] vRowLengthMapSI = vRowLengthMap[si];
					if(vRowLengthMapSI == null || vRowLengthMapSI.length < 1){
						continue;
					}
					for(int sj=0; sj<vRowLengthMapSI.length; sj++){
						if(si==i && sj <= j){
							continue;//look forward, not behind
						}
						short srow = (short)vRowLengthMapSI[sj];
						if(vRowPositions[srow].length==0){
							continue;
						}
						short[] vRowPositionsSrow = vRowPositions[srow];
						//same sparsity pattern?
						if(isSubsetSparsityPattern(vRowPositionsProw, vRowPositionsSrow)){
							log.debug("found superset sparsity pattern: row " + prow + " contained in row " + srow);
							
							//look for the higher number of coefficients that can be deleted
							Map<Double, List<Integer>> coeffRatiosMap = new HashMap<Double, List<Integer>>();
							for(short k=0; k<vRowPositionsProw.length; k++){
								short col = vRowPositionsProw[k];
								double APRL = A.getQuick(prow, col); 
								double ASRL = A.getQuick(srow, col);
								double ratio = -ASRL/APRL;
								//put the ratio and the column index in the map
								boolean added = false;
								for(Double keyRatio : coeffRatiosMap.keySet()){
									if(isZero(ratio - keyRatio)){
										coeffRatiosMap.get(keyRatio).add((int)col);
										added = true;
										break;
									}
								}
								if(!added){
									List<Integer> newList = new ArrayList<Integer>();
									newList.add((int)col);
									coeffRatiosMap.put(ratio, newList);
								}
							}
							//take the ratio(s) with the higher number of column indexes
							int maxNumberOfColumn = -1;
							List<Integer> candidatedColumns = null;
							for(Double keyRatio : coeffRatiosMap.keySet()){
								int size = coeffRatiosMap.get(keyRatio).size(); 
								if(size > maxNumberOfColumn){
									maxNumberOfColumn = size;
									candidatedColumns = coeffRatiosMap.get(keyRatio);
								}else if(size == maxNumberOfColumn){
									candidatedColumns.addAll(coeffRatiosMap.get(keyRatio));
								}
							}

							//look for the position with less column fill in
							short lessFilledColumn = -1;//cannot be greater
							int lessFilledColumnLength = this.originalMeq + 1;//cannot be greater
							for(short k=0; k<candidatedColumns.size(); k++){
								short col = candidatedColumns.get(k).shortValue();
								if(vColPositions[col].length>1 && vColPositions[col].length<lessFilledColumnLength ){
									lessFilledColumn = col;
									lessFilledColumnLength = vColPositions[col].length;
								}
							}
							log.debug("less filled column (" + lessFilledColumn +"): length=" + lessFilledColumnLength);
							double APRL = A.getQuick(prow, lessFilledColumn); 
							double ASRL = A.getQuick(srow, lessFilledColumn);
							double alpha = -ASRL/APRL;
							
							b.setQuick(srow, b.getQuick(srow) + alpha*b.getQuick(prow));
							//substitute A[prow] with A[prow] * alpha*A[row] for every nz entry of A[row]
							for(short t=0; t<vRowPositionsProw.length; t++){
								short cc = vRowPositionsProw[t];
								double nv = 0.;
								if(cc!=lessFilledColumn){
									nv = A.getQuick(srow, cc) + alpha*A.getQuick(prow, cc);
								}
								A.setQuick(srow, cc, nv);
								if(isZero(nv)){
									vRowPositions[srow] = removeElementFromSortedArray(vRowPositions[srow], cc);
									changeColumnsLengthPosition(cc, vColPositions[cc].length, vColPositions[cc].length-1);
									vColPositions[cc] = removeElementFromSortedArray(vColPositions[cc], srow);
									changeRowsLengthPosition(srow, vRowPositions[srow].length+1, vRowPositions[srow].length);
									A.setQuick(srow, cc, 0.);
								}
							}
							this.someReductionDone = true;
							stop = true;
							i=startingLength-1;//restart, ++ comes from the for loop
							break;
						}
					}
				}
			}
		}
	}
69099
public void write(Collection<? extends MapLayer> layers) throws IOException {
		if (this.progression != null) {
			this.progression.setProperties(0, 0, layers.size() + 1, false);
		}

		// Write the header
		if (!this.isHeaderWritten) {
			this.isHeaderWritten = true;
			writeHeader();
		}

		if (this.progression != null) {
			this.progression.increment();
		}

		final ObjectOutputStream oos = new ObjectOutputStream(this.tmpOutput);
		for (final MapLayer layer : layers) {
			oos.writeObject(layer);
			++this.length;
			if (this.progression != null) {
				this.progression.increment();
			}
		}
		if (this.progression != null) {
			this.progression.end();
		}
	}
1317476
protected void initUpperEquivalent()
	{
		this.upperEquivalent = new HashSet<Node>();

		for (PhysicalEntity eq : pe.getMemberPhysicalEntityOf())
		{
			Node node = (Node) graph.getGraphObject(eq);
			if (node != null) this.upperEquivalent.add(node);
		}

		upperEquivalentInited = true;
	}
1044684
public void write(Bean bean, boolean rootType, Appendable output) throws IOException {
        if (bean == null) {
            throw new NullPointerException("bean");
        }
        this.output = output;
        this.rootBean = bean;
        this.basePackage = (rootType ? bean.getClass().getPackage().getName() + "." : null);
        
        String type = rootBean.getClass().getName();
        writeHeader();
        output.append('<').append(BEAN);
        if (rootType) {
            appendAttribute(output, TYPE, type);
        }
        output.append('>').append(settings.getNewLine());
        writeBean(rootBean, settings.getIndent());
        output.append('<').append('/').append(BEAN).append('>').append(settings.getNewLine());
    }
930357
private void writeEnvelope(ByteWriter writer) throws IOException {

		if (envelope != null) {

			// Write x and y values
			writer.writeDouble(envelope.getMinX());
			writer.writeDouble(envelope.getMaxX());
			writer.writeDouble(envelope.getMinY());
			writer.writeDouble(envelope.getMaxY());

			// Write z values
			if (envelope.hasZ()) {
				writer.writeDouble(envelope.getMinZ());
				writer.writeDouble(envelope.getMaxZ());
			}

			// Write m values
			if (envelope.hasM()) {
				writer.writeDouble(envelope.getMinM());
				writer.writeDouble(envelope.getMaxM());
			}
		}
	}
937603
@Override
  public void write(JsonWriterImpl out, byte []value)
  {
    StringBuilder sb = new StringBuilder();

    Base64Util.encode(sb, value, 0, value.length);

    out.write(sb.toString());
  }
276192
@Override
    public DMatrixRMaj getUpper(DMatrixRMaj upper )
    {
        int numRows = LU.numRows < LU.numCols ? LU.numRows : LU.numCols;
        int numCols = LU.numCols;

        upper = UtilDecompositons_DDRM.checkZerosLT(upper,numRows,numCols);

        for( int i = 0; i < numRows; i++ ) {
            for( int j = i; j < numCols; j++ ) {
                upper.unsafe_set(i,j, LU.unsafe_get(i,j));
            }
        }

        return upper;
    }
476349
public void write(RowOutputInterface out) {

        out.writeSize(storageSize);
        out.writeData(rowData, tTable.colTypes);
        out.writeEnd();

        hasDataChanged = false;
    }
734414
@Override
  public void write (final int b)
  {
    final int nNewCount = m_nCount + 1;
    if (nNewCount > m_aBuf.length)
      m_aBuf = _enlarge (m_aBuf, Math.max (m_aBuf.length << 1, nNewCount));
    m_aBuf[m_nCount] = (byte) b;
    m_nCount = nNewCount;
  }