typename boost::enable_if<boost::is_same<T, typename U::value_type>, void>::type copy(symbol<T[]> const& src, U& dst) { function_requires<RandomAccessContainerConcept<U> >(); assert(typename U::difference_type(src.size()) == (dst.end() - dst.begin())); CUDA_CALL(cudaMemcpyFromSymbol(&*dst.begin(), reinterpret_cast<char const*>(src.data()), src.size() * sizeof(T), 0, cudaMemcpyDeviceToHost)); }
// copy all symbol data from another symbol into a symbol from list void reel::copySymbol(symbol temp, int offset) { // set the name of the symbol offset from the base of the list to the name of temp list[offset].setName(temp.getName()); // set the value of the symbol offset from the base of the list to the value of temp list[offset].setValue(temp.getValue()); };
typename boost::enable_if<boost::is_same<T, typename U::value_type>, void>::type copy(U const& src, symbol<T[]> const& dst) { function_requires<RandomAccessContainerConcept<U> >(); assert((src.end() - src.begin()) == typename U::difference_type(dst.size())); CUDA_CALL(cudaMemcpyToSymbol(reinterpret_cast<char const*>(dst.data()), &*src.begin(), (src.end() - src.begin()) * sizeof(T), 0, cudaMemcpyHostToDevice)); }
bool split_name(symbol const& name, symbol & prefix, symbol & suffix) const { if (name.is_numerical()) return false; char const* str = name.bare_str(); char const* period = strchr(str,'.'); if (!period) return false; svector<char> prefix_((unsigned)(period-str), str); prefix_.push_back(0); prefix = symbol(prefix_.c_ptr()); suffix = symbol(period + 1); return true; }
symbol Path::nodir (symbol name_s) { const std::string name = name_s.name (); size_t start = name.size (); for (;start > 0; start--) { const char prev = name[start-1]; if (prev == '/') break; #if !defined (__unix) if (prev == '\\' || prev == ':') break; #endif // !unix } std::string result; for (;start < name.size (); start++) result += name[start]; return result; }
static unsigned pp_symbol(std::ostream & out, symbol const & s) { if (is_smt2_quoted_symbol(s)) { std::string str = mk_smt2_quoted_symbol(s); out << str; return static_cast<unsigned>(str.length()); } else if (s.is_numerical()) { std::string str = s.str(); out << str; return static_cast<unsigned>(str.length()); } else { out << s.bare_str(); return static_cast<unsigned>(strlen(s.bare_str())); } }
symbol_distribution::symbol_distribution(const symbol &s) : total_frequencies(1) { for (int i = 0; i < ARITHMETIC_SYMBOL_COUNT; i++) { frequencies[i] = 0u; } frequencies[s.get_sequential_code()] = 1u; }
bool Path::set_directory (symbol directory_s) { const std::string& directory = directory_s.name (); const char *const dir = directory.c_str (); const bool result = chdir (dir) == 0 || (mkdir (dir, 0777) == 0 && chdir (dir) == 0); if (!result) /* Do nothing */; else if (directory[0] == '/' #ifndef __unix__ || directory[0] == '\\' || directory[1] == ':' #endif ) // Already absolute. current_directory = directory; else // Make it absolute. current_directory = get_cwd (); std::ostringstream tmp; tmp << "Changing directory to '" << directory << "' " << (result ? "success" : "failure"); Assertion::debug (tmp.str ()); return result; }
std::auto_ptr<std::istream> Path::open_file (symbol name_s) const { const std::string& name = name_s.name (); struct Message : std::ostringstream { ~Message () { Assertion::debug (this->str ()); } } tmp; tmp << "In directory '" << get_directory () << "':"; std::auto_ptr<std::istream> in; // Absolute filename. if (name[0] == '.' || name[0] == '/' #ifndef __unix__ || name[0] == '\\' || name[1] == ':' #endif ) { tmp << "\nOpening absolute file name '" << name << "'"; in.reset (new std::ifstream (name.c_str ())); return in; } tmp << "\nLooking for file '" << name << "'"; // Look in path. for (unsigned int i = 0; i < path.size (); i++) { const symbol dir = (path[i] == "." ? current_directory : path[i]); const symbol file = dir + DIRECTORY_SEPARATOR + name; tmp << "\nTrying '" << file << "'"; if (path[i] == ".") tmp << " (cwd)"; in.reset (new std::ifstream (file.name ().c_str ())); if (in->good ()) { tmp << " success!"; return in; } } tmp << "\nGiving up"; daisy_assert (in.get ()); return in; // Return last bad stream. }
std::string ensure_quote(symbol const& s) { std::string str; if (is_smt2_quoted_symbol(s)) str = mk_smt2_quoted_symbol(s); else str = s.str(); return str; }
void PrinterFile::Implementation::print_object (const FrameModel& value, const Library& library, const FrameModel *const original, int indent) { const symbol element = value.type_name (); if (!library.check (element)) { out << "<unknown " << element << ">"; return; } // Check original. if (original && original->type_name () == element) { out << "original"; // Check if we added something over the original. if (value.subset (metalib, *original)) return; out << " "; print_alist (value, original, indent + 9, false); return; } const FrameModel& element_frame = library.model (element); // Check if we added something over the library. if (value.subset (metalib, element_frame)) { // We didn't. print_symbol (element); return; } // Library element with additional attributes. print_symbol (element); out << " "; print_alist (value, &element_frame, indent + 1 + element.name ().length () // Buglet: Wrong indentation for elements with strange chars. + (is_identifier (element.name ()) ? 0 : 2), false); }
double symbol_distribution::get_accumulated_probability(const symbol &s) const { double result = 0.0; for (unsigned int i = 0; i < s.get_sequential_code(); i++) { result += static_cast<double>(frequencies[i]) / static_cast<double>(total_frequencies); } return result; }
void ChemistryMulti::check_ignore (const symbol chem, Treelog& msg) { if (ignored (chem)) return; msg.message ("Fate of '" + chem.name () + "' will not be traced"); ignore.push_back (chem); }
void set_next_arg(cmd_context & ctx, symbol const & s) override { cmd * c = ctx.find_cmd(s); if (c == nullptr) { std::string err_msg("unknown command '"); err_msg = err_msg + s.bare_str() + "'"; throw cmd_exception(std::move(err_msg)); } m_cmds.push_back(s); }
virtual void set_next_arg(cmd_context & ctx, symbol const & s) { cmd * c = ctx.find_cmd(s); if (c == 0) { std::string err_msg("unknown command '"); err_msg = err_msg + s.bare_str() + "'"; throw cmd_exception(err_msg); } m_cmds.push_back(s); }
void DestinationTable::initialize (const symbol log_dir, const symbol objid, const symbol description, const Volume& volume, const std::vector<std::pair<symbol, symbol>/**/>& /**/ parameters) { const std::string fn = log_dir.name () + file.name (); out.open (fn.c_str ()); print_header.start (out, objid, file, parsed_from_file); for (size_t i = 0; i < parameters.size (); i++) print_header.parameter (out, parameters[i].first, parameters[i].second); print_header.interval (out, volume); print_header.log_description (out, description); out.flush (); }
void symbol:: copy( symbol s ){ int l = strlen(s.name); name = new char[l+1]; char* tmp = new char[20]; s.getname(tmp); strcopy(name, tmp); value = s.value; bonus = s.bonus; delete[] tmp; }
// If x is real then U.diff(x)-I*V.diff(x) represents both conjugate(U+I*V).diff(x) // and conjugate((U+I*V).diff(x)) static ex conjugate_expl_derivative(const ex & arg, const symbol & s) { if (s.info(info_flags::real)) return conjugate(arg.diff(s)); else { exvector vec_arg; vec_arg.push_back(arg); return fderivative(ex_to<function>(conjugate(arg)).get_serial(),0,vec_arg).hold()*arg.diff(s); } }
void insert(symbol const & name, param_kind k, char const * descr) { SASSERT(!name.is_numerical()); info i; if (m_info.find(name, i)) { SASSERT(i.first == k); return; } m_info.insert(name, info(k, descr)); m_names.push_back(name); }
void PrinterFile::print_entry (const Frame& frame, const symbol key) { if (frame.check (key)) { impl->out << "(" << key << " "; const int indent = 2 + key.name ().length (); impl->print_entry (frame, NULL, key, indent, false); impl->out << ")\n"; } }
symbol // Return DIM without time. Oldunits::Content::crop_time (const symbol dim_s) { const std::string& dim = dim_s.name (); daisy_assert (dim.size () > 0); size_t end; for (end = dim.size () - 1; dim[end] != '/'; end--) daisy_assert (end > 0); std::string result; for (int i = 0; i < end; i++) result += dim[i]; return result; }
std::string mk_smt2_quoted_symbol(symbol const & s) { SASSERT(is_smt2_quoted_symbol(s)); string_buffer<> buffer; buffer.append('|'); char const * str = s.bare_str(); while (*str) { if (*str == '|' || *str == '\\') buffer.append('\\'); buffer.append(*str); str++; } buffer.append('|'); return std::string(buffer.c_str()); }
bool // True iff FROM and TO have same time unit. Oldunits::Content::time_match (const symbol from_s, const symbol to_s) { const std::string& from = from_s.name (); const std::string& to = to_s.name (); const size_t from_size = from.size (); const size_t to_size = to.size (); for (int i = 1; true; i++) { if (i > from_size || i > to_size) return false; const char from_c = from[from_size - i]; const char to_c = to[to_size - i]; if (from_c != to_c) return false; if (from_c == '/') return true; } }
void SummaryBalance::print_balance (std::ostream& out, const symbol title, const double total, const symbol dim, const int /* dim_size */, const int max_size, const int width) const { out << std::string (max_size + 3, ' ') << std::string (width, '-') << "\n" << std::string (max_size - title.name ().size (), ' ') << title << " = "; out.width (width); out << total; if (dim != Attribute::Unknown ()) out << " [" << dim << "]"; out << "\n"; }
void PrinterFile::print_comment (const symbol comment_s) { const std::string& comment = comment_s.name (); std::vector<std::string> text; int last = 0; for (;;) { const int next = comment.find ('\n', last); if (next < 0) break; text.push_back (comment.substr (last, next - last)); last = next + 1; } text.push_back (comment.substr (last)); for (unsigned int i = 0; i < text.size (); i++) impl->out << ";; " << text[i] << "\n"; }
bool operator()(symbol const & lhs, def const & rhs) const { return operator()(lhs.c_str(), rhs.name()); }
const char * name(void) const { return name_.c_str(); }
unsigned int symbol_distribution::get_emissions(const symbol &s) const { return frequencies[s.get_sequential_code()]; }
bool symbol_distribution::has_only_the_symbol(const symbol &s) const { return frequencies[s.get_sequential_code()] == 1 && total_frequencies == 1; }
double symbol_distribution::get_probability_of(const symbol &s) const { int index = s.get_sequential_code(); return static_cast<double>(frequencies[index]) / static_cast<double>(total_frequencies); }