/** * \en * insert new row in table and replace tag to value * \_en * \ru * Вставляет новую строку в таблицу, заменяет теги на значения, удаляет тег секции из строки таблицы. * Выполняет рекурсивный поиск узла, содержащего строку таблицы. У этого узла есть * специальное имя(w:r), которое распознается функцией. После того, как узел найден, строка строка дублируется, * а из текущей строки удаляются все теги секции, чтобы избежать мнократного размножения строк таблицы. * \_ru * \param node - \en context for inserting \_en \ru узел, в который происходит вставка \_ru * \see searchTags() */ void aMSOTemplate::insertRowValues(QDomNode node) { QDomNode n = node; while(!n.parentNode().isNull()) { n = n.parentNode(); QDomElement e = n.toElement(); if( n.nodeName()=="Row" ) { QDomAttr a = n.toElement().attributeNode( "ss:Index" ); n.parentNode().insertAfter(n.cloneNode(true),n); clearTags(n,true); QMap<QString,QString>::Iterator it; for ( it = values.begin(); it != values.end(); ++it ) { searchTags(n,it.key()); } int rowIndex = a.value().toInt(); if (rowIndex == 0) { rowIndex = getRowIndex(n); n.toElement().setAttribute("ss:Index",rowIndex); } n.nextSibling().toElement().setAttribute("ss:Index",rowIndex+1); } } }
/** * STEP1: exclusive values at the same box/row/col * STEP2: check whether the index has the unique value to set * * e.g.: for sudoku with digits below, we want process index `25`(3,8): * ┌───────┬───────┬───────┐ * | | 2 3 | 1 | * | 3 | 7 | 6 | * | 7 | 9 | 2 | * ├───────┼───────┼───────┤ * | 1 6 | | 3 | * | | 4 9 | | * | 2 | | 8 5 | * ├───────┼───────┼───────┤ * | 1 | 8 | 7 | * | 7 | 4 | 8 | * | 4 | 2 5 | | * └───────┴───────┴───────┘ * available values: {1,2,3,4,5,6,7,8,9} * * STEP1: exclusive values at the same box/row/col * ┌───────┬───────┬───────┐ * | | 2 3 | 1 | * | 3 | 7 | 6 | * | 7 | 9 | x 2 | * ├───────┼───────┼───────┤ * | 1 6 | | 3 | * | | 4 9 | | * | 2 | | 8 5 | * ├───────┼───────┼───────┤ * | 1 | 8 | 7 | * | 7 | 4 | 8 | * | 4 | 2 5 | | * └───────┴───────┴───────┘ * available values: { , ,3,4,5, ,7,8,9} // by box * available values: { , ,3,4,5, , ,8, } // by row * available values: { , , ,4, , , , , } // by col * * STEP2: check whether the index has the unique value to set * available values: { , , ,4, , , , , } * the unique value is 4. */ int Sudoku::stepIndex(int index) { int availables[9] = {1,2,3,4,5,6,7,8,9}; // STEP1: exclusive values at the same box/row/col int indexs[9] = {0}; getBoxIndex(index, indexs); removeValuesWithDataIndexs(availables, mData, indexs); getRowIndex(index, indexs); removeValuesWithDataIndexs(availables, mData, indexs); getColIndex(index, indexs); removeValuesWithDataIndexs(availables, mData, indexs); // STEP2: check whether the index has the unique value to set int value = 0; for (int i = 0; i < 9; i++) { if (availables[i] != 0) { if (value != 0) { return 0; } value = availables[i]; } } // as not return, means we found the unique value for this index mCount++; mData[index] = value; outputDataStep(value, index, "exclusiveRange"); updateDataTips(value, index); return value; }
QRect ImageOverlayRegionFinder::growRegion(int row, int column, QBitArray &mask) { QRect region; region.setCoords(column, row, column, row); QQueue<int> queue; queue.enqueue(getDataIndex(row, column)); while (!queue.isEmpty()) { int i = queue.dequeue(); if (m_overlay.getData()[i] > 0 && !mask.testBit(i)) { mask.setBit(i); row = getRowIndex(i); column = getColumnIndex(i); if (row < region.top()) { region.setTop(row); } if (row > region.bottom()) { region.setBottom(row); } if (column < region.left()) { region.setLeft(column); } if (column > region.right()) { region.setRight(column); } if (column - 1 >= 0) { queue.enqueue(getDataIndex(row, column - 1)); } if (column + 1 < static_cast<signed>(m_overlay.getColumns())) { queue.enqueue(getDataIndex(row, column + 1)); } if (row - 1 >= 0) { queue.enqueue(getDataIndex(row - 1, column)); } if (row + 1 < static_cast<signed>(m_overlay.getRows())) { queue.enqueue(getDataIndex(row + 1, column)); } } } return region; }
void Sudoku::updateDataTips(int value, int index) { int indexs[9] = {0}; if (value != 0) { getBoxIndex(index, indexs); removeTipsWithDataIndexs(mTips, indexs, value); getRowIndex(index, indexs); removeTipsWithDataIndexs(mTips, indexs, value); getColIndex(index, indexs); removeTipsWithDataIndexs(mTips, indexs, value); } }
void ThreadedDyscoColumn<DataType>::loadBlock(size_t blockIndex) { if(blockIndex < nBlocksInFile()) { readCompressedData(blockIndex, _packedBlockReadBuffer.data(), _blockSize); const size_t nPolarizations = _shape[0], nChannels = _shape[1], nRows = nRowsInBlock(), nMetaFloats = metaDataFloatCount(nRows, nPolarizations, nChannels, _antennaCount); unsigned char* symbolStart = _packedBlockReadBuffer.data() + nMetaFloats*sizeof(float); BytePacker::unpack(_bitsPerSymbol, _unpackedSymbolReadBuffer.data(), symbolStart, symbolCount(nRows, nPolarizations, nChannels)); float* metaData = reinterpret_cast<float*>(_packedBlockReadBuffer.data()); initializeDecode(_timeBlockBuffer.get(), metaData, nRows, _antennaCount); uint64_t startRow = getRowIndex(blockIndex); _timeBlockBuffer->resize(nRows); for(size_t blockRow=0; blockRow!=nRows; ++blockRow) { int a1 = (*_ant1Col)(startRow + blockRow), a2 = (*_ant2Col)(startRow + blockRow); decode(_timeBlockBuffer.get(), _unpackedSymbolReadBuffer.data(), blockRow, a1, a2); } } _currentBlock = blockIndex; _isCurrentBlockChanged = false; }
char getKey() { char* port_ptr = make_pointer(PORT_ADDR(CONFIG_KEYPAD_OUT_PORT)); volatile char* pin_ptr = make_pointer(CONFIG_KEYPAD_OUT_PORT); char col = 0, row = 0; for(col = 0; col < 4; col++) { add_to_port(PORT_ADDR(CONFIG_KEYPAD_OUT_PORT), 0xf0); subtract_from_port(PORT_ADDR(CONFIG_KEYPAD_OUT_PORT), (1 << col) << 4); _delay_ms(1); row = *(pin_ptr) & 0x0f; if(row != 0x0f) { while((*(pin_ptr) & 0x0f) != 0x0F); break; } } if(col < 4) { row = getRowIndex(row); return keymap[row][col]; } return '\0'; }
int main(int argc, char *argv[]) { FILE *input_file, *output_file, *time_file; if (argc < 4) { fprintf(stderr, "Invalid input parameters\n"); fprintf(stderr, "Usage: %s inputfile outputfile timefile \n", argv[0]); exit(1); } else { input_file = fopen(argv[1], "r"); output_file = fopen(argv[2], "w"); time_file = fopen(argv[3], "w"); if (!input_file || !output_file || !time_file) exit(1); } MM_typecode matcode; if (mm_read_banner(input_file, &matcode) != 0) { printf("Could not process Matrix Market banner.\n"); exit(1); } if (!mm_is_matrix(matcode) || !mm_is_real(matcode) || !mm_is_coordinate(matcode)) { printf("Sorry, this application does not support "); printf("Market Market type: [%s]\n", mm_typecode_to_str(matcode)); exit(1); } mtxMatrix inputMatrix, fullMatrix, LMatrix, UMatrix, UMatrixTranspose, MMatrix; ReadMatrix(inputMatrix, input_file); Timer timer; getRowIndex(&inputMatrix, inputMatrix.RowIndex); inputMatrix.RowIndex[inputMatrix.N] = inputMatrix.NZ; int diagNum = 0; for (int i = 0; i < inputMatrix.N; i++) { for (int j = inputMatrix.RowIndex[i]; j < inputMatrix.RowIndex[i + 1]; j++) { if (i == inputMatrix.Col[j]) diagNum++; } } if (mm_is_symmetric(matcode)) { InitializeMatrix(inputMatrix.N, 2 * inputMatrix.NZ - diagNum, fullMatrix); TriangleToFull(&inputMatrix, &fullMatrix); FreeMatrix(inputMatrix); } else { fullMatrix = inputMatrix; } int *diag = new int[fullMatrix.N]; for (int i = 0; i < fullMatrix.N; i++) { for (int j = fullMatrix.RowIndex[i]; j < fullMatrix.RowIndex[i + 1]; j++) { if (i == fullMatrix.Col[j]) diag[i] = j; } } // for (int i = 0; i < fullMatrix.N + 1; i++) { // printf("RowIndex[%i] = %i\n", i, fullMatrix.RowIndex[i]); // } // // // for (int i = 0; i < fullMatrix.N; i++) { // printf("input[%i]= %lf\n", i, fullMatrix.Value[inputMatrix.RowIndex[i]]); // } // // for (int i = 0; i < fullMatrix.N; i++) { // printf("diag[%i]= %d\n", i, diag[i]); // } timer.start(); ilu0(fullMatrix, fullMatrix.Value, diag); LUmatrixSeparation(fullMatrix, diag, LMatrix, UMatrix); Transpose(UMatrix, UMatrixTranspose); Multiplicate(LMatrix, UMatrixTranspose, MMatrix); timer.stop(); std::ofstream timeLog; timeLog.open(argv[3]); timeLog << timer.getElapsed(); WriteFullMatrix(MMatrix, output_file, matcode); FreeMatrix(fullMatrix); return 0; }