// creates new CRecord object and fills it with the data of the record specified by inRecID CRecord* //** Thread Safe ** ADataStore::ReadRecord(RecIDT inRecID) { DB_DEBUG("ReadRecord("<<inRecID<<")"); CRecord* theRec = (CRecord*)nil; long size = GetRecordSize(inRecID); if (size > 0) { temp_buffer(DatabaseRec, p, size); // allocate a read buffer p->recID = inRecID; p->recSize = size; ReadRecord(p); theRec = MakeRecordObject(p); } return theRec; }
//put message into the log buffer void log(const Log::LogMessage &msg) { u8 logLevel = Ini.HLELogLvl.GetValue(); if (msg.mType != Log::TTY && logLevel != 0) { if (logLevel > static_cast<u32>(msg.mServerity)) { return; } } size_t size = msg.size(); std::vector<char> temp_buffer(size); msg.serialize(temp_buffer.data()); messages.pushRange(temp_buffer.begin(), temp_buffer.end()); if (!newLog.load()) { newLog = true; m_log->GetEventHandler()->QueueEvent(new wxCommandEvent(EVT_LOG_COMMAND)); } }
// Src and dst can be any size. Src has 4 components. Dst has 3 components. void LLImageRaw::compositeScaled4onto3(LLImageRaw* src) { LL_INFOS() << "compositeScaled4onto3" << LL_ENDL; LLImageRaw* dst = this; // Just for clarity. llassert( (4 == src->getComponents()) && (3 == dst->getComponents()) ); S32 temp_data_size = src->getWidth() * dst->getHeight() * src->getComponents(); llassert_always(temp_data_size > 0); std::vector<U8> temp_buffer(temp_data_size); // Vertical: scale but no composite for( S32 col = 0; col < src->getWidth(); col++ ) { copyLineScaled( src->getData() + (src->getComponents() * col), &temp_buffer[0] + (src->getComponents() * col), src->getHeight(), dst->getHeight(), src->getWidth(), src->getWidth() ); } // Horizontal: scale and composite for( S32 row = 0; row < dst->getHeight(); row++ ) { compositeRowScaled4onto3( &temp_buffer[0] + (src->getComponents() * src->getWidth() * row), dst->getData() + (dst->getComponents() * dst->getWidth() * row), src->getWidth(), dst->getWidth() ); } }
BOOL LLImageRaw::scale( S32 new_width, S32 new_height, BOOL scale_image_data ) { llassert((1 == getComponents()) || (3 == getComponents()) || (4 == getComponents()) ); S32 old_width = getWidth(); S32 old_height = getHeight(); if( (old_width == new_width) && (old_height == new_height) ) { return TRUE; // Nothing to do. } // Reallocate the data buffer. if (scale_image_data) { S32 temp_data_size = old_width * new_height * getComponents(); llassert_always(temp_data_size > 0); std::vector<U8> temp_buffer(temp_data_size); // Vertical for( S32 col = 0; col < old_width; col++ ) { copyLineScaled( getData() + (getComponents() * col), &temp_buffer[0] + (getComponents() * col), old_height, new_height, old_width, old_width ); } deleteData(); U8* new_buffer = allocateDataSize(new_width, new_height, getComponents()); // <FS:ND> Handle out of memory situations a bit more graceful than a crash if( !new_buffer ) return FALSE; // </FS:ND> // Horizontal for( S32 row = 0; row < new_height; row++ ) { copyLineScaled( &temp_buffer[0] + (getComponents() * old_width * row), new_buffer + (getComponents() * new_width * row), old_width, new_width, 1, 1 ); } } else { // copy out existing image data S32 temp_data_size = old_width * old_height * getComponents(); std::vector<U8> temp_buffer(temp_data_size); memcpy(&temp_buffer[0], getData(), temp_data_size); // allocate new image data, will delete old data U8* new_buffer = allocateDataSize(new_width, new_height, getComponents()); // <FS:ND> Handle out of memory situations a bit more graceful than a crash if( !new_buffer ) return FALSE; // </FS:ND> for( S32 row = 0; row < new_height; row++ ) { if (row < old_height) { memcpy(new_buffer + (new_width * row * getComponents()), &temp_buffer[0] + (old_width * row * getComponents()), getComponents() * llmin(old_width, new_width)); if (old_width < new_width) { // pad out rest of row with black memset(new_buffer + (getComponents() * ((new_width * row) + old_width)), 0, getComponents() * (new_width - old_width)); } } else { // pad remaining rows with black memset(new_buffer + (new_width * row * getComponents()), 0, new_width * getComponents()); } } } return TRUE ; }
/** The complete builtin. Used for specifying programmable tab-completions. Calls the functions in complete.c for any heavy lifting. Defined in builtin_complete.c */ static int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { ASSERT_IS_MAIN_THREAD(); wgetopter_t w; bool res=false; int argc=0; int result_mode=SHARED; int remove = 0; int authoritative = -1; wcstring short_opt; wcstring_list_t gnu_opt, old_opt; const wchar_t *comp=L"", *desc=L"", *condition=L""; bool do_complete = false; wcstring do_complete_param; wcstring_list_t cmd; wcstring_list_t path; wcstring_list_t wrap_targets; static int recursion_level=0; argc = builtin_count_args(argv); w.woptind=0; while (! res) { static const struct woption long_options[] = { { L"exclusive", no_argument, 0, 'x' }, { L"no-files", no_argument, 0, 'f' }, { L"require-parameter", no_argument, 0, 'r' }, { L"path", required_argument, 0, 'p' }, { L"command", required_argument, 0, 'c' }, { L"short-option", required_argument, 0, 's' }, { L"long-option", required_argument, 0, 'l' }, { L"old-option", required_argument, 0, 'o' }, { L"description", required_argument, 0, 'd' }, { L"arguments", required_argument, 0, 'a' }, { L"erase", no_argument, 0, 'e' }, { L"unauthoritative", no_argument, 0, 'u' }, { L"authoritative", no_argument, 0, 'A' }, { L"condition", required_argument, 0, 'n' }, { L"wraps", required_argument, 0, 'w' }, { L"do-complete", optional_argument, 0, 'C' }, { L"help", no_argument, 0, 'h' }, { 0, 0, 0, 0 } }; int opt_index = 0; int opt = w.wgetopt_long(argc, argv, L"a:c:p:s:l:o:d:frxeuAn:C::w:h", long_options, &opt_index); if (opt == -1) break; switch (opt) { case 0: if (long_options[opt_index].flag != 0) break; streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0], long_options[opt_index].name); builtin_print_help(parser, streams, argv[0], streams.err); res = true; break; case 'x': result_mode |= EXCLUSIVE; break; case 'f': result_mode |= NO_FILES; break; case 'r': result_mode |= NO_COMMON; break; case 'p': case 'c': { wcstring tmp; if (unescape_string(w.woptarg, &tmp, UNESCAPE_SPECIAL)) { if (opt=='p') path.push_back(tmp); else cmd.push_back(tmp); } else { streams.err.append_format(L"%ls: Invalid token '%ls'\n", argv[0], w.woptarg); res = true; } break; } case 'd': desc = w.woptarg; break; case 'u': authoritative=0; break; case 'A': authoritative=1; break; case 's': short_opt.append(w.woptarg); break; case 'l': gnu_opt.push_back(w.woptarg); break; case 'o': old_opt.push_back(w.woptarg); break; case 'a': comp = w.woptarg; break; case 'e': remove = 1; break; case 'n': condition = w.woptarg; break; case 'w': wrap_targets.push_back(w.woptarg); break; case 'C': { do_complete = true; const wchar_t *arg = w.woptarg ? w.woptarg : reader_get_buffer(); if (arg == NULL) { // This corresponds to using 'complete -C' in non-interactive mode // See #2361 builtin_missing_argument(parser, streams, argv[0], argv[w.woptind-1]); return STATUS_BUILTIN_ERROR; } do_complete_param = arg; break; } case 'h': builtin_print_help(parser, streams, argv[0], streams.out); return 0; case '?': builtin_unknown_option(parser, streams, argv[0], argv[w.woptind-1]); res = true; break; } } if (!res) { if (condition && wcslen(condition)) { const wcstring condition_string = condition; parse_error_list_t errors; if (parse_util_detect_errors(condition_string, &errors, false /* do not accept incomplete */)) { streams.err.append_format(L"%ls: Condition '%ls' contained a syntax error", argv[0], condition); for (size_t i=0; i < errors.size(); i++) { streams.err.append_format(L"\n%s: ", argv[0]); streams.err.append(errors.at(i).describe(condition_string)); } res = true; } } } if (!res) { if (comp && wcslen(comp)) { wcstring prefix; if (argv[0]) { prefix.append(argv[0]); prefix.append(L": "); } wcstring err_text; if (parser.detect_errors_in_argument_list(comp, &err_text, prefix.c_str())) { streams.err.append_format(L"%ls: Completion '%ls' contained a syntax error\n", argv[0], comp); streams.err.append(err_text); streams.err.push_back(L'\n'); res = true; } } } if (!res) { if (do_complete) { const wchar_t *token; parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token, 0, 0, 0); /* Create a scoped transient command line, so that bulitin_commandline will see our argument, not the reader buffer */ builtin_commandline_scoped_transient_t temp_buffer(do_complete_param); if (recursion_level < 1) { recursion_level++; std::vector<completion_t> comp; complete(do_complete_param, comp, COMPLETION_REQUEST_DEFAULT); for (size_t i=0; i< comp.size() ; i++) { const completion_t &next = comp.at(i); /* Make a fake commandline, and then apply the completion to it. */ const wcstring faux_cmdline = token; size_t tmp_cursor = faux_cmdline.size(); wcstring faux_cmdline_with_completion = completion_apply_to_command_line(next.completion, next.flags, faux_cmdline, &tmp_cursor, false); /* completion_apply_to_command_line will append a space unless COMPLETE_NO_SPACE is set. We don't want to set COMPLETE_NO_SPACE because that won't close quotes. What we want is to close the quote, but not append the space. So we just look for the space and clear it. */ if (!(next.flags & COMPLETE_NO_SPACE) && string_suffixes_string(L" ", faux_cmdline_with_completion)) { faux_cmdline_with_completion.resize(faux_cmdline_with_completion.size() - 1); } /* The input data is meant to be something like you would have on the command line, e.g. includes backslashes. The output should be raw, i.e. unescaped. So we need to unescape the command line. See #1127 */ unescape_string_in_place(&faux_cmdline_with_completion, UNESCAPE_DEFAULT); streams.out.append(faux_cmdline_with_completion); /* Append any description */ if (! next.description.empty()) { streams.out.push_back(L'\t'); streams.out.append(next.description); } streams.out.push_back(L'\n'); } recursion_level--; } } else if (w.woptind != argc) { streams.err.append_format(_(L"%ls: Too many arguments\n"), argv[0]); builtin_print_help(parser, streams, argv[0], streams.err); res = true; } else if (cmd.empty() && path.empty()) { /* No arguments specified, meaning we print the definitions of * all specified completions to stdout.*/ streams.out.append(complete_print()); } else { int flags = COMPLETE_AUTO_SPACE; if (remove) { builtin_complete_remove(cmd, path, short_opt.c_str(), gnu_opt, old_opt); } else { builtin_complete_add(cmd, path, short_opt.c_str(), gnu_opt, old_opt, result_mode, authoritative, condition, comp, desc, flags); } // Handle wrap targets (probably empty) // We only wrap commands, not paths for (size_t w=0; w < wrap_targets.size(); w++) { const wcstring &wrap_target = wrap_targets.at(w); for (size_t i=0; i < cmd.size(); i++) { (remove ? complete_remove_wrapper : complete_add_wrapper)(cmd.at(i), wrap_target); } } } } return res ? 1 : 0; }
// If srcValues and buffer are different, then the original values // are preserved, if they are the same srcValues will be overwritten void octree::gpuSort(my_dev::context &devContext, my_dev::dev_mem<uint4> &srcValues, my_dev::dev_mem<uint4> &output, my_dev::dev_mem<uint4> &buffer, int N, int numberOfBits, int subItems, tree_structure &tree) { #if defined (USE_B40C) sorter->sort(srcValues, output, N); #elif defined(USE_THRUST) && defined(USE_THRUST_96) //Extra buffer values my_dev::dev_mem<uint> permutation(devContext); // Permutation values, for sorting the int4 data my_dev::dev_mem<uint> temp_buffer(devContext); // temporary uint buffer //Permutation has to be allocated after the two previous //allocated buffers, get the right offset int memOffset = permutation.getGlobalMemAllignmentPadding(8*N); memOffset += 8*N; memOffset = permutation.cmalloc_copy(tree.generalBuffer1, N, memOffset); memOffset = temp_buffer.cmalloc_copy(tree.generalBuffer1, N, memOffset); thrust_sort_96b(srcValues, output, temp_buffer, permutation, N); #else //Extra buffer values my_dev::dev_mem<uint> simpleKeys(devContext); //Int keys, my_dev::dev_mem<uint> permutation(devContext); //Permutation values, for sorting the int4 data my_dev::dev_mem<int> output32b(devContext); //Permutation values, for sorting the int4 data my_dev::dev_mem<uint> valuesOutput(devContext); //Buffers for the values which are the indexes //Permutation has to be allocated after the two previous //allocated buffers, get the right offset int memOffset = simpleKeys.getGlobalMemAllignmentPadding(8*N); memOffset += 8*N; memOffset = simpleKeys.cmalloc_copy(tree.generalBuffer1, N, memOffset); memOffset = permutation.cmalloc_copy(tree.generalBuffer1, N, memOffset); memOffset = output32b.cmalloc_copy(tree.generalBuffer1, N, memOffset); memOffset = valuesOutput.cmalloc_copy(tree.generalBuffer1, N, memOffset); //Dimensions for the kernels that shuffle and extract data const int blockSize = 256; extractInt.setWork(N, blockSize); reOrderKeysValues.setWork(N, blockSize); //Idx depends on subitems, z goes first, x last if subitems = 3 //subitems = 3, than idx=2 //subitems = 2, than idx=1 //subitems = 1, than idx=0 //intIdx = subItems-1 int intIdx = subItems-1; //Extracts a 32bit key and fills a sequence extractInt.set_arg<cl_mem>(0, srcValues.p()); extractInt.set_arg<cl_mem>(1, simpleKeys.p()); extractInt.set_arg<cl_mem>(2, permutation.p()); extractInt.set_arg<uint>(3, &N); extractInt.set_arg<int>(4, &intIdx);//bit idx reOrderKeysValues.set_arg<cl_mem>(0, srcValues.p()); reOrderKeysValues.set_arg<cl_mem>(1, output.p()); reOrderKeysValues.set_arg<cl_mem>(2, valuesOutput.p()); reOrderKeysValues.set_arg<uint>(3, &N); extractInt.execute(execStream->s()); #ifdef USE_THRUST thrust_sort_32b(devContext, simpleKeys, permutation, output32b, simpleKeys, valuesOutput,permutation, N, 32); #else //Now sort the first 32bit keys //Using 32bit sort with key and value seperated gpuSort_32b(devContext, simpleKeys, permutation, output32b, simpleKeys, valuesOutput,permutation, N, 32); #endif //Now reorder the main keys //Use output as the new output/src value thing buffer reOrderKeysValues.execute(execStream->s()); if(subItems == 1) { //Only doing one 32bit sort. Data is already in output so done return; } //2nd set of 32bit keys //Idx depends on subitems, z goes first, x last if subitems = 3 //subitems = 3, than idx=1 //subitems = 2, than idx=0 //subitems = 1, completed previous round //intIdx = subItems-2 intIdx = subItems-2; extractInt.set_arg<cl_mem>(0, output.p()); extractInt.set_arg<int>(4, &intIdx);//smem size extractInt.execute(execStream->s()); #ifdef USE_THRUST thrust_sort_32b(devContext, simpleKeys, permutation, output32b, simpleKeys, valuesOutput,permutation, N, 32); #else //Now sort the 2nd 32bit keys //Using 32bit sort with key and value seperated gpuSort_32b(devContext, simpleKeys, permutation, output32b, simpleKeys, valuesOutput,permutation, N, 32); #endif reOrderKeysValues.set_arg<cl_mem>(0, output.p()); reOrderKeysValues.set_arg<cl_mem>(1, buffer.p()); reOrderKeysValues.execute(execStream->s()); if(subItems == 2) { //Doing two 32bit sorts. Data is in buffer //so move the data from buffer to output output.copy(buffer, buffer.get_size()); return; } //3th set of 32bit keys //Idx depends on subitems, z goes first, x last if subitems = 3 //subitems = 3, than idx=0 //subitems = 2, completed previous round //subitems = 1, completed previous round //intIdx = subItems-2 intIdx = 0; extractInt.set_arg<cl_mem>(0, buffer.p()); extractInt.set_arg<int>(4, &intIdx);//integer idx extractInt.execute(execStream->s()); //Now sort the final set of 32bit keys #ifdef USE_THRUST thrust_sort_32b(devContext, simpleKeys, permutation, output32b, simpleKeys, valuesOutput,permutation, N, 32); #else gpuSort_32b(devContext, simpleKeys, permutation, output32b, simpleKeys, valuesOutput,permutation, N, 32); #endif reOrderKeysValues.set_arg<cl_mem>(0, buffer.p()); reOrderKeysValues.set_arg<cl_mem>(1, output.p()); reOrderKeysValues.execute(execStream->s()); #endif // USE_THRUST_96 }
void Socket::SlotOnNewData(net::ClientId client_id, net::ServerId server_id, common::Byteset data) { common::Byteset temp_buffer(data); this->io_service_.post(boost::bind(&Socket::SlotOnNewDataHandler, this, client_id, server_id, temp_buffer)); }
/// The complete builtin. Used for specifying programmable tab-completions. Calls the functions in // complete.cpp for any heavy lifting. int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) { ASSERT_IS_MAIN_THREAD(); static int recursion_level = 0; wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); int result_mode = SHARED; int remove = 0; wcstring short_opt; wcstring_list_t gnu_opt, old_opt; const wchar_t *comp = L"", *desc = L"", *condition = L""; bool do_complete = false; wcstring do_complete_param; wcstring_list_t cmd_to_complete; wcstring_list_t path; wcstring_list_t wrap_targets; bool preserve_order = false; static const wchar_t *const short_options = L":a:c:p:s:l:o:d:frxeuAn:C::w:hk"; static const struct woption long_options[] = {{L"exclusive", no_argument, NULL, 'x'}, {L"no-files", no_argument, NULL, 'f'}, {L"require-parameter", no_argument, NULL, 'r'}, {L"path", required_argument, NULL, 'p'}, {L"command", required_argument, NULL, 'c'}, {L"short-option", required_argument, NULL, 's'}, {L"long-option", required_argument, NULL, 'l'}, {L"old-option", required_argument, NULL, 'o'}, {L"description", required_argument, NULL, 'd'}, {L"arguments", required_argument, NULL, 'a'}, {L"erase", no_argument, NULL, 'e'}, {L"unauthoritative", no_argument, NULL, 'u'}, {L"authoritative", no_argument, NULL, 'A'}, {L"condition", required_argument, NULL, 'n'}, {L"wraps", required_argument, NULL, 'w'}, {L"do-complete", optional_argument, NULL, 'C'}, {L"help", no_argument, NULL, 'h'}, {L"keep-order", no_argument, NULL, 'k'}, {NULL, 0, NULL, 0}}; int opt; wgetopter_t w; while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch (opt) { case 'x': { result_mode |= EXCLUSIVE; break; } case 'f': { result_mode |= NO_FILES; break; } case 'r': { result_mode |= NO_COMMON; break; } case 'k': { preserve_order = true; break; } case 'p': case 'c': { wcstring tmp; if (unescape_string(w.woptarg, &tmp, UNESCAPE_SPECIAL)) { if (opt == 'p') path.push_back(tmp); else cmd_to_complete.push_back(tmp); } else { streams.err.append_format(_(L"%ls: Invalid token '%ls'\n"), cmd, w.woptarg); return STATUS_INVALID_ARGS; } break; } case 'd': { desc = w.woptarg; break; } case 'u': { // This option was removed in commit 1911298 and is now a no-op. break; } case 'A': { // This option was removed in commit 1911298 and is now a no-op. break; } case 's': { short_opt.append(w.woptarg); if (w.woptarg[0] == '\0') { streams.err.append_format(_(L"%ls: -s requires a non-empty string\n"), cmd); return STATUS_INVALID_ARGS; } break; } case 'l': { gnu_opt.push_back(w.woptarg); if (w.woptarg[0] == '\0') { streams.err.append_format(_(L"%ls: -l requires a non-empty string\n"), cmd); return STATUS_INVALID_ARGS; } break; } case 'o': { old_opt.push_back(w.woptarg); if (w.woptarg[0] == '\0') { streams.err.append_format(_(L"%ls: -o requires a non-empty string\n"), cmd); return STATUS_INVALID_ARGS; } break; } case 'a': { comp = w.woptarg; break; } case 'e': { remove = 1; break; } case 'n': { condition = w.woptarg; break; } case 'w': { wrap_targets.push_back(w.woptarg); break; } case 'C': { do_complete = true; const wchar_t *arg = w.woptarg ? w.woptarg : reader_get_buffer(); if (arg == NULL) { // This corresponds to using 'complete -C' in non-interactive mode. // See #2361. builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } do_complete_param = arg; break; } case 'h': { builtin_print_help(parser, streams, cmd, streams.out); return STATUS_CMD_OK; } case ':': { builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } case '?': { builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]); return STATUS_INVALID_ARGS; } default: { DIE("unexpected retval from wgetopt_long"); break; } } } if (w.woptind != argc) { streams.err.append_format(BUILTIN_ERR_TOO_MANY_ARGUMENTS, cmd); builtin_print_error_trailer(parser, streams.err, cmd); return STATUS_INVALID_ARGS; } if (condition && std::wcslen(condition)) { const wcstring condition_string = condition; parse_error_list_t errors; if (parse_util_detect_errors(condition_string, &errors, false /* do not accept incomplete */)) { streams.err.append_format(L"%ls: Condition '%ls' contained a syntax error", cmd, condition); for (size_t i = 0; i < errors.size(); i++) { streams.err.append_format(L"\n%s: ", cmd); streams.err.append(errors.at(i).describe(condition_string)); } return STATUS_CMD_ERROR; } } if (comp && std::wcslen(comp)) { wcstring prefix; prefix.append(cmd); prefix.append(L": "); wcstring err_text; if (parser.detect_errors_in_argument_list(comp, &err_text, prefix.c_str())) { streams.err.append_format(L"%ls: Completion '%ls' contained a syntax error\n", cmd, comp); streams.err.append(err_text); streams.err.push_back(L'\n'); return STATUS_CMD_ERROR; } } if (do_complete) { const wchar_t *token; parse_util_token_extent(do_complete_param.c_str(), do_complete_param.size(), &token, 0, 0, 0); // Create a scoped transient command line, so that bulitin_commandline will see our // argument, not the reader buffer. builtin_commandline_scoped_transient_t temp_buffer(do_complete_param); if (recursion_level < 1) { recursion_level++; std::vector<completion_t> comp; complete(do_complete_param, &comp, COMPLETION_REQUEST_DEFAULT | COMPLETION_REQUEST_FUZZY_MATCH, parser.vars()); for (size_t i = 0; i < comp.size(); i++) { const completion_t &next = comp.at(i); // Make a fake commandline, and then apply the completion to it. const wcstring faux_cmdline = token; size_t tmp_cursor = faux_cmdline.size(); wcstring faux_cmdline_with_completion = completion_apply_to_command_line( next.completion, next.flags, faux_cmdline, &tmp_cursor, false); // completion_apply_to_command_line will append a space unless COMPLETE_NO_SPACE // is set. We don't want to set COMPLETE_NO_SPACE because that won't close // quotes. What we want is to close the quote, but not append the space. So we // just look for the space and clear it. if (!(next.flags & COMPLETE_NO_SPACE) && string_suffixes_string(L" ", faux_cmdline_with_completion)) { faux_cmdline_with_completion.resize(faux_cmdline_with_completion.size() - 1); } // The input data is meant to be something like you would have on the command // line, e.g. includes backslashes. The output should be raw, i.e. unescaped. So // we need to unescape the command line. See #1127. unescape_string_in_place(&faux_cmdline_with_completion, UNESCAPE_DEFAULT); streams.out.append(faux_cmdline_with_completion); // Append any description. if (!next.description.empty()) { streams.out.push_back(L'\t'); streams.out.append(next.description); } streams.out.push_back(L'\n'); } recursion_level--; } } else if (cmd_to_complete.empty() && path.empty()) { // No arguments specified, meaning we print the definitions of all specified completions // to stdout. streams.out.append(complete_print()); } else { int flags = COMPLETE_AUTO_SPACE; if (preserve_order) { flags |= COMPLETE_DONT_SORT; } if (remove) { builtin_complete_remove(cmd_to_complete, path, short_opt.c_str(), gnu_opt, old_opt); } else { builtin_complete_add(cmd_to_complete, path, short_opt.c_str(), gnu_opt, old_opt, result_mode, condition, comp, desc, flags); } // Handle wrap targets (probably empty). We only wrap commands, not paths. for (size_t w = 0; w < wrap_targets.size(); w++) { const wcstring &wrap_target = wrap_targets.at(w); for (size_t i = 0; i < cmd_to_complete.size(); i++) { (remove ? complete_remove_wrapper : complete_add_wrapper)(cmd_to_complete.at(i), wrap_target); } } } return STATUS_CMD_OK; }
void lu_factorize(matrix<SCALARTYPE, viennacl::row_major> & A) { typedef matrix<SCALARTYPE, viennacl::row_major> MatrixType; std::size_t max_block_size = 32; std::size_t num_blocks = (A.size2() - 1) / max_block_size + 1; std::vector<SCALARTYPE> temp_buffer(A.internal_size2() * max_block_size); // Iterate over panels for (std::size_t panel_id = 0; panel_id < num_blocks; ++panel_id) { std::size_t row_start = panel_id * max_block_size; std::size_t current_block_size = std::min<std::size_t>(A.size1() - row_start, max_block_size); viennacl::range block_range(row_start, row_start + current_block_size); viennacl::range remainder_range(row_start + current_block_size, A.size1()); // // Perform LU factorization on panel: // // Read from matrix to buffer: viennacl::backend::memory_read(A.handle(), sizeof(SCALARTYPE) * row_start * A.internal_size2(), sizeof(SCALARTYPE) * current_block_size * A.internal_size2(), &(temp_buffer[0])); // Factorize (kij-version): for (std::size_t k=0; k < current_block_size - 1; ++k) { for (std::size_t i=k+1; i < current_block_size; ++i) { temp_buffer[row_start + i * A.internal_size2() + k] /= temp_buffer[row_start + k * A.internal_size2() + k]; // write l_ik SCALARTYPE l_ik = temp_buffer[row_start + i * A.internal_size2() + k]; for (std::size_t j = row_start + k + 1; j < A.size1(); ++j) temp_buffer[i * A.internal_size2() + j] -= l_ik * temp_buffer[k * A.internal_size2() + j]; // l_ik * a_kj } } // Write back: viennacl::backend::memory_write(A.handle(), sizeof(SCALARTYPE) * row_start * A.internal_size2(), sizeof(SCALARTYPE) * current_block_size * A.internal_size2(), &(temp_buffer[0])); if (remainder_range.size() > 0) { // // Compute L_12 = [ (U_11)^{T}^{-1} A_{21}^T ]^T // viennacl::matrix_range<MatrixType> U_11(A, block_range, block_range); viennacl::matrix_range<MatrixType> A_21(A, remainder_range, block_range); viennacl::linalg::inplace_solve(trans(U_11), trans(A_21), viennacl::linalg::lower_tag()); // // Update remainder of A // viennacl::matrix_range<MatrixType> L_21(A, remainder_range, block_range); viennacl::matrix_range<MatrixType> U_12(A, block_range, remainder_range); viennacl::matrix_range<MatrixType> A_22(A, remainder_range, remainder_range); A_22 -= viennacl::linalg::prod(L_21, U_12); } } }
void lu_factorize(matrix<SCALARTYPE, viennacl::column_major> & A) { typedef matrix<SCALARTYPE, viennacl::column_major> MatrixType; std::size_t max_block_size = 32; std::size_t num_blocks = (A.size1() - 1) / max_block_size + 1; std::vector<SCALARTYPE> temp_buffer(A.internal_size1() * max_block_size); // Iterate over panels for (std::size_t panel_id = 0; panel_id < num_blocks; ++panel_id) { std::size_t col_start = panel_id * max_block_size; std::size_t current_block_size = std::min<std::size_t>(A.size1() - col_start, max_block_size); viennacl::range block_range(col_start, col_start + current_block_size); viennacl::range remainder_range(col_start + current_block_size, A.size1()); // // Perform LU factorization on panel: // // Read from matrix to buffer: viennacl::backend::memory_read(A.handle(), sizeof(SCALARTYPE) * col_start * A.internal_size1(), sizeof(SCALARTYPE) * current_block_size * A.internal_size1(), &(temp_buffer[0])); // Factorize (kji-version): for (std::size_t k=0; k < current_block_size; ++k) { SCALARTYPE a_kk = temp_buffer[col_start + k + k * A.internal_size1()]; for (std::size_t i=col_start+k+1; i < A.size1(); ++i) temp_buffer[i + k * A.internal_size1()] /= a_kk; // write l_ik for (std::size_t j=k+1; j < current_block_size; ++j) { SCALARTYPE a_kj = temp_buffer[col_start + k + j * A.internal_size1()]; for (std::size_t i=col_start+k+1; i < A.size1(); ++i) temp_buffer[i + j * A.internal_size1()] -= temp_buffer[i + k * A.internal_size1()] * a_kj; // l_ik * a_kj } } // Write back: viennacl::backend::memory_write(A.handle(), sizeof(SCALARTYPE) * col_start * A.internal_size1(), sizeof(SCALARTYPE) * current_block_size * A.internal_size1(), &(temp_buffer[0])); if (remainder_range.size() > 0) { // // Compute U_12: // viennacl::matrix_range<MatrixType> L_11(A, block_range, block_range); viennacl::matrix_range<MatrixType> A_12(A, block_range, remainder_range); viennacl::linalg::inplace_solve(L_11, A_12, viennacl::linalg::unit_lower_tag()); // // Update remainder of A // viennacl::matrix_range<MatrixType> L_21(A, remainder_range, block_range); viennacl::matrix_range<MatrixType> U_12(A, block_range, remainder_range); viennacl::matrix_range<MatrixType> A_22(A, remainder_range, remainder_range); A_22 -= viennacl::linalg::prod(L_21, U_12); } } }