Пример #1
0
// [[Rcpp::export(".cyclopsReadData")]]
List cyclopsReadFileData(const std::string& fileName, const std::string& modelTypeName) {

		using namespace bsccs;
		Timer timer; 
    ModelType modelType = RcppCcdInterface::parseModelType(modelTypeName);        		
    InputReader* reader = new NewGenericInputReader(modelType,
    	bsccs::make_shared<loggers::RcppProgressLogger>(true), // make silent
    	bsccs::make_shared<loggers::RcppErrorHandler>());	
		reader->readFile(fileName.c_str()); // TODO Check for error

    XPtr<ModelData> ptr(reader->getModelData());
    
    
    const std::vector<double>& y = ptr->getYVectorRef();
    double total = std::accumulate(y.begin(), y.end(), 0.0);
    // delete reader; // TODO Test
       
    double time = timer();
    List list = List::create(
            Rcpp::Named("cyclopsDataPtr") = ptr,            
            Rcpp::Named("timeLoad") = time,
            Rcpp::Named("debug") = List::create(
            		Rcpp::Named("totalY") = total
            )
    );
    return list;
}
Пример #2
0
int main (const int argc, char const * const argv[]) {
#ifndef DENORMALS
    _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
    _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
#endif
  auto pairhmm = Pairhmm<
    //PairhmmScalarImpl<float>,
    //PairhmmScalarImpl<double>
    //PairhmmSSEFloatImpl,
    //PairhmmAVXFloatImpl,
    //PairhmmAVXDoubleImpl
    PairhmmAVXFloat2DiagsImpl,
    PairhmmAVXDouble2DiagsImpl
  >{};
  InputReader<TestcaseIterator> reader {};
  if (argc == 2)
    reader.from_file(argv[1]);
  double computation_time = 0.f;
  Chronos time;
  for (auto& testcase : reader) {
    time.reset();
    auto results = pairhmm.calculate(testcase);
    computation_time += time.elapsed();
    for (auto x : results)
      cout << x << endl;
  }
  std::cerr << "done in " << computation_time << "ms\n";
  return 0;
}
Пример #3
0
/** Reads a length value including a trailing unit specifier and returns it. */
static Length read_length (InputReader &ir) {
	Length length;
	ir.skipSpace();
	if (!isalpha(ir.peek())) {
		double val = ir.getDouble();
		string unit = isalpha(ir.peek()) ? ir.getString(2) : "pt";
		length = Length(val, unit);
	}
	return length;
}
Пример #4
0
/** Handles the "point" command that adds a point to the point list. */
void EmSpecialHandler::point (InputReader &ir, SpecialActions &actions) {
	DPair pos(actions.getX(), actions.getY());
	int n = ir.getInt();
	if (ir.getPunct() == ',') {
		pos.x(ir.getDouble());
		if (ir.getPunct() == ',')
			pos.y(ir.getDouble());
	}
	_points[n] = pos;
}
Пример #5
0
/** Reads a length (value + unit) and returns its value in PS points (bp).
 *  If no unit is specified, TeX points are assumed. */
static double read_length (InputReader &in) {
	double val = in.getDouble();
	string unitstr;
	if (isalpha(in.peek())) unitstr += in.get();
	if (isalpha(in.peek())) unitstr += in.get();
	Length::Unit unit = Length::Unit::PT;
	try {
		unit = Length::stringToUnit(unitstr);
	}
	catch (UnitException &e) {
	}
	return Length(val, unit).bp();
}
Пример #6
0
int main(int argc, char **argv)
{
    QApplication app(argc,argv);
    //QApplication::setStyle(QStyleFactory::create("Plastique"));
    QApplication::setPalette(QApplication::style()->standardPalette());

   // MainUser mainUser;
    //mainUser.show();
    InputReader inputDialog;
    inputDialog.show();

    return app.exec();
}
void DvisvgmSpecialHandler::preprocessRawDef (InputReader &ir) {
    if (_currentMacro == _macros.end())
        return;
    string str = ir.getLine();
    if (!str.empty())
        _currentMacro->second.push_back(string("D")+str);
}
Пример #8
0
int main(int argc, char* argv[])
{
	InputReader iReader;
	Validator validator;
	Grader grader;
	OutputWriter oWriter;
	
	iReader.scanSubmissionMethod(argc);
	iReader.scanInput();
	validator.validateInput(iReader.getInput());
	grader.grade(iReader.getInput());
	oWriter.displayResult(grader.getGrade());
	

	
	return 0;
}
void DvisvgmSpecialHandler::processRawDef (InputReader &ir, SpecialActions *actions) {
    if (_nestingLevel == 0) {
        string str = ir.getLine();
        if (!str.empty()) {
            expand_constants(str, actions);
            actions->appendToDefs(new XMLTextNode(str));
        }
    }
}
void DvisvgmSpecialHandler::processImg (InputReader &ir, SpecialActions *actions) {
    if (actions) {
        const double pt2bp = 72/72.27;
        double w = ir.getDouble()*pt2bp;
        double h = ir.getDouble()*pt2bp;
        string f = ir.getString();
        update_bbox(w, h, 0, actions);
        XMLElementNode *img = new XMLElementNode("image");
        img->addAttribute("x", actions->getX());
        img->addAttribute("y", actions->getY());
        img->addAttribute("width", w);
        img->addAttribute("height", h);
        img->addAttribute("xlink:href", f);
        if (!actions->getMatrix().isIdentity())
            img->addAttribute("transform", actions->getMatrix().getSVG());
        actions->appendToPage(img);
    }
}
Пример #11
0
void DvisvgmSpecialHandler::processRawDef (InputReader &ir, SpecialActions &actions) {
	if (_nestingLevel == 0) {
		string xml = ir.getLine();
		if (!xml.empty()) {
			expand_constants(xml, actions);
			_defsParser.parse(xml, actions);
		}
	}
}
Пример #12
0
static string read_entry (InputReader &in) {
	string entry;
	bool accept_slashes=true;
	while (!in.eof() && ((in.peek() == '/' && accept_slashes) || valid_name_char(in.peek()))) {
		if (in.peek() != '/')
			accept_slashes = false;
		entry += char(in.get());
	}
	if (entry.length() > 1) {
		// strip leading slashes
		// According to the PostScript specification, a single slash without further
		// following characters is a valid name.
		size_t n=0;
		while (n < entry.length() && entry[n] == '/')
			n++;
		entry = entry.substr(n);
	}
	return entry;
}
Пример #13
0
int main (int argc, char** argv) {
  if (argc < 2) {
    std::cout << "Usage: " << argv[0] << " <Subread Filename>" << std::endl;
    exit(1);
  }
  
  // Read the subread parameters from the file
  std::ifstream subread_file;
  unsigned int num_reads;
  unsigned int num_subreads_per_read;
  unsigned int subread_length;
  subread_file.open(argv[1]);
  subread_file.read((char *) (&num_reads), sizeof(unsigned int ));
  subread_file.read((char *) (&num_subreads_per_read), sizeof(unsigned int ));
  subread_file.read((char *) (&subread_length), sizeof(unsigned int ));
  unsigned int num_itcs = num_subreads_per_read * 2;
  assert(num_itcs % num_subreads_per_read == 0);
  
  // Store the subreads into lists to be used later
  std::queue<uint64_t>* subread_list = new std::queue<uint64_t>[num_itcs];
  unsigned int cur_subread = 0;
  while (cur_subread < num_reads * num_subreads_per_read) {
    uint64_t subread;
    unsigned int cur_itc = cur_subread % num_itcs;
    subread_file.read((char *) (&subread), sizeof(uint64_t));
    subread_list[cur_itc].push(subread);
    cur_subread++;
  }
  subread_file.close();
  
  // Instantiate the input reader
  InputReader* ir = new InputReader(argv[1], num_itcs);
  uint64_t start_cycle = ir->cycle_count();
  
  uint64_t num_subreads_read = 0;
  while (num_subreads_read < num_reads * num_subreads_per_read) {
    for (unsigned int i = 0; i < num_itcs; i++) {
      if (ir->SubReadReady(i)) {
        SubRead sr = ir->SubReadRequest(i);
        assert(sr.data == subread_list[i].front());
        subread_list[i].pop();
        num_subreads_read++;
      }
    }
    ir->NextClockCycle();
  }

    // Check that workload is done
  assert(ir->Done() == true);
  std::cout << "Conflict test took " << ir->cycle_count() - start_cycle << " cycles" << std::endl;
  
  std::cout << "Input Reader tests complete!" << std::endl;
  return 0;
}
Пример #14
0
/** Reads characters from an input stream until the pattern string or EOF is reached.
 *  The matching string is read too if found. An empty pattern matches any character, i.e.
 *  reading stops after the first character.
 *  @return true if the pattern was found */
bool StringMatcher::match (InputReader &ir) {
	int c;
	int i=0;
	const int len = static_cast<int>(_pattern.length());
	_charsRead = 0;
	while ((c = ir.get()) >= 0) {
		_charsRead++;
		while (i >= 0 && c != _pattern[i])
			i = _borders[i];
		if (++i == len)
			return true;
	}
	return false;
}
Пример #15
0
/** Reads characters from an input stream until the pattern string or EOF is reached
 *  and returns them as a string. The matching string is also appended to the returned string. */
string StringMatcher::read (InputReader &ir) {
	string ret;
	int c;
	int i=0;
	const int len = static_cast<int>(_pattern.length());
	while ((c = ir.get()) >= 0) {
		ret += char(c);
		while (i >= 0 && c != _pattern[i])
			i = _borders[i];
		if (++i == len)
			break;
	}
	_charsRead = ret.length();
	return ret;
}
void DvisvgmSpecialHandler::preprocessRawSet (InputReader &ir) {
    _nestingLevel++;
    string id = ir.getString();
    if (id.empty())
        throw SpecialException("definition of unnamed SVG fragment");
    if (_nestingLevel > 1)
        throw SpecialException("nested definition of SVG fragment '" + id + "'");

    _currentMacro = _macros.find(id);
    if (_currentMacro != _macros.end()) {
        _currentMacro = _macros.end();
        throw SpecialException("redefinition of SVG fragment '" + id + "'");
    }
    pair<string, StringVector> entry(id, StringVector());
    pair<MacroMap::iterator, bool> state = _macros.insert(entry);
    _currentMacro = state.first;
}
Пример #17
0
void DvisvgmSpecialHandler::processImg (InputReader &ir, SpecialActions &actions) {
	try {
		Length w = read_length(ir);
		Length h = read_length(ir);
		string f = ir.getString();
		update_bbox(w, h, Length(0), false, actions);
		auto img = util::make_unique<XMLElement>("image");
		img->addAttribute("x", actions.getX());
		img->addAttribute("y", actions.getY());
		img->addAttribute("width", w.bp());
		img->addAttribute("height", h.bp());
		img->addAttribute("xlink:href", f);
		if (!actions.getMatrix().isIdentity())
			img->addAttribute("transform", actions.getMatrix().toSVG());
		actions.svgTree().appendToPage(std::move(img));
	}
	catch (const UnitException &e) {
		throw SpecialException(string("dvisvgm:img: ") + e.what());
	}
}
Пример #18
0
/** Handles the "line" command that draws a straight line between two points
 *  from the point list. */
void EmSpecialHandler::line (InputReader &ir, SpecialActions& actions) {
	int pointnum1 = ir.getInt();
	int cut1 = 'p';
	if (isalpha(ir.peek()))
		cut1 = ir.get();
	ir.getPunct();
	int pointnum2 = ir.getInt();
	int cut2 = 'p';
	if (isalpha(ir.peek()))
		cut2 = ir.get();
	double linewidth = _linewidth;
	if (ir.getPunct() == ',')
		linewidth = read_length(ir);
	auto it1=_points.find(pointnum1);
	auto it2=_points.find(pointnum2);
	if (it1 != _points.end() && it2 != _points.end())
		create_line(it1->second, it2->second, char(cut1), char(cut2), linewidth, actions);
	else {
		// Line endpoints don't necessarily have to be defined before
		// a line definition. If a point isn't defined yet, we put the line
		// in a wait list and process the lines at the end of the page.
		_lines.emplace_back(Line(pointnum1, pointnum2, char(cut1), char(cut2), linewidth));
	}
}
Пример #19
0
void DvisvgmSpecialHandler::processRawPut (InputReader &ir, SpecialActions &actions) {
	if (_nestingLevel > 0)
		return;
	string id = ir.getString();
	auto it = _macros.find(id);
	if (it == _macros.end())
		throw SpecialException("undefined SVG fragment '" + id + "' referenced");

	StringVector &defvector = it->second;
	for (string &defstr : defvector) {
		char &type = defstr[0];
		string def = defstr.substr(1);
		if ((type == 'P' || type == 'D') && !def.empty()) {
			expand_constants(def, actions);
			if (type == 'P')
				_pageParser.parse(def, actions);
			else {          // type == 'D'
				_defsParser.parse(def, actions);
				type = 'L';  // locked
			}
		}
	}
}
void DvisvgmSpecialHandler::processRawPut (InputReader &ir, SpecialActions *actions) {
    if (_nestingLevel > 0)
        return;
    string id = ir.getString();
    MacroMap::iterator it = _macros.find(id);
    if (it == _macros.end())
        throw SpecialException("undefined SVG fragment '" + id + "' referenced");

    StringVector &defs = it->second;
    for (StringVector::iterator defs_it=defs.begin(); defs_it != defs.end(); ++defs_it) {
        char &type = defs_it->at(0);
        string def = defs_it->substr(1);
        if ((type == 'P' || type == 'D') && !def.empty()) {
            expand_constants(def, actions);
            if (type == 'P')
                actions->appendToPage(new XMLTextNode(def));
            else {          // type == 'D'
                actions->appendToDefs(new XMLTextNode(def));
                type = 'L';  // locked
            }
        }
    }
}
/** Evaluates the special dvisvgm:bbox.
 *  variant 1: dvisvgm:bbox [r[el]] <width> <height> [<depth>]
 *  variant 2: dvisvgm:bbox a[bs] <x1> <y1> <x2> <y2>
 *  variant 3: dvisvgm:bbox f[ix] <x1> <y1> <x2> <y2>
 *  variant 4: dvisvgm:bbox n[ew] <name> */
void DvisvgmSpecialHandler::processBBox (InputReader &ir, SpecialActions *actions) {
    const double pt2bp = 72/72.27;
    ir.skipSpace();
    int c = ir.peek();
    if (isalpha(c)) {
        while (!isspace(ir.peek()))  // skip trailing characters
            ir.get();
        if (c == 'n') {
            ir.skipSpace();
            string name;
            while (isalnum(ir.peek()))
                name += char(ir.get());
            ir.skipSpace();
            if (!name.empty() && ir.eof())
                actions->bbox(name, true); // create new user box
        }
        else if (c == 'a' || c == 'f') {
            double p[4];
            for (int i=0; i < 4; i++)
                p[i] = ir.getDouble()*pt2bp;
            BoundingBox b(p[0], p[1], p[2], p[3]);
            if (c == 'a')
                actions->embed(b);
            else {
                actions->bbox() = b;
                actions->bbox().lock();
            }
        }
    }
    else
        c = 'r';   // no mode specifier => relative box parameters

    if (c == 'r') {
        double w = ir.getDouble()*pt2bp;
        double h = ir.getDouble()*pt2bp;
        double d = ir.getDouble()*pt2bp;
        update_bbox(w, h, d, actions);
    }
}
Пример #22
0
/** Evaluates the special dvisvgm:bbox.
 *  variant 1: dvisvgm:bbox [r[el]] <width> <height> [<depth>] [transform]
 *  variant 2: dvisvgm:bbox a[bs] <x1> <y1> <x2> <y2> [transform]
 *  variant 3: dvisvgm:bbox f[ix] <x1> <y1> <x2> <y2> [transform]
 *  variant 4: dvisvgm:bbox n[ew] <name>
 *  variant 5: dvisvgm:bbox lock | unlock */
void DvisvgmSpecialHandler::processBBox (InputReader &ir, SpecialActions &actions) {
	ir.skipSpace();
	if (ir.check("lock"))
		actions.bbox().lock();
	else if (ir.check("unlock"))
		actions.bbox().unlock();
	else {
		int c = ir.peek();
		try {
			if (!isalpha(c))
				c = 'r';   // no mode specifier => relative box parameters
			else {
				while (!isspace(ir.peek()))  // skip trailing characters
					ir.get();
				if (c == 'n') {   // "new": create new local bounding box
					ir.skipSpace();
					string name;
					while (isalnum(ir.peek()))
						name += char(ir.get());
					ir.skipSpace();
					if (!name.empty() && ir.eof())
						actions.bbox(name, true); // create new user box
				}
				else if (c == 'a' || c == 'f') {  // "abs" or "fix"
					Length lengths[4];
					for (Length &len : lengths)
						len = read_length(ir);
					BoundingBox b(lengths[0], lengths[1], lengths[2], lengths[3]);
					ir.skipSpace();
					if (ir.check("transform"))
						b.transform(actions.getMatrix());
					if (c == 'a')
						actions.embed(b);
					else {
						actions.bbox() = b;
						actions.bbox().lock();
					}
				}
			}
			if (c == 'r') {
				Length w = read_length(ir);
				Length h = read_length(ir);
				Length d = read_length(ir);
				ir.skipSpace();
				update_bbox(w, h, d, ir.check("transform"), actions);
			}
		}
		catch (const UnitException &e) {
			throw SpecialException(string("dvisvgm:bbox: ") + e.what());
		}
	}
}
Пример #23
0
void CommandLine::handle_version (InputReader &ir, const Option &opt, bool longopt) {
    if (ir.eof() || getBoolArg(ir, opt, longopt, _version_arg))
        _version_given = true;
}
Пример #24
0
void CommandLine::handle_trace_all (InputReader &ir, const Option &opt, bool longopt) {
    if (ir.eof() || getBoolArg(ir, opt, longopt, _trace_all_arg))
        _trace_all_given = true;
}
Пример #25
0
void CommandLine::handle_progress (InputReader &ir, const Option &opt, bool longopt) {
    if (ir.eof() || getDoubleArg(ir, opt, longopt, _progress_arg))
        _progress_given = true;
}
Пример #26
0
void CommandLine::handle_no_specials (InputReader &ir, const Option &opt, bool longopt) {
    if (ir.eof() || getStringArg(ir, opt, longopt, _no_specials_arg))
        _no_specials_given = true;
}
Пример #27
0
void CommandLine::handle_cache (InputReader &ir, const Option &opt, bool longopt) {
    if (ir.eof() || getStringArg(ir, opt, longopt, _cache_arg))
        _cache_given = true;
}
Пример #28
0
/** Parses a single line in dvipdfmx mapfile format.
 *  @param[in] ir the input stream must be assigned to this reader */
void MapLine::parseDVIPDFMLine (InputReader &ir) {
	ir.skipSpace();
	if (ir.peek() != '-') {
		_encname = ir.getString();
		if (_encname == "default" || _encname == "none")
			_encname.clear();
	}
	ir.skipSpace();
		if (ir.peek() != '-')
		_fontfname = ir.getString();
	if (!_fontfname.empty()) {
		parseFilenameOptions(_fontfname);
	}
	ir.skipSpace();
	while (ir.peek() == '-') {
		ir.get();
		int option = ir.get();
		if (!isprint(option))
			throw MapLineException("option character expected");
		ir.skipSpace();
		switch (option) {
			case 's': // slant
				if (!ir.parseDouble(_slant))
					throw_number_expected('s');
				break;
			case 'e': // extend
				if (!ir.parseDouble(_extend))
					throw_number_expected('e');
				break;
			case 'b': // bold
				if (!ir.parseDouble(_bold))
					throw_number_expected('b');
				break;
			case 'r': //remap (deprecated)
				break;
			case 'i': // ttc index
				if (!ir.parseInt(_fontindex, false))
					throw_number_expected('i', true);
				break;
			case 'p': // UCS plane
				int dummy;
				if (!ir.parseInt(dummy, false))
					throw_number_expected('p', true);
				break;
			case 'u': // to unicode
				ir.getString();
				break;
			case 'v': // stemV
				int stemv;
				if (!ir.parseInt(stemv, true))
					throw_number_expected('v', true);
				break;
			case 'm': // map single chars
				ir.skipUntil("-");
				break;
			case 'w': // writing mode (horizontal=0, vertical=1)
				int vertical;
				if (!ir.parseInt(vertical, false))
					throw_number_expected('w', true);
				break;
			default:
				ostringstream oss;
				oss << "invalid option: -" << option;
				throw MapLineException(oss.str());
		}
		ir.skipSpace();
	}
}
Пример #29
0
/** Parses a single line in dvips mapfile format.
 *  @param[in] ir the input stream must be assigned to this reader */
void MapLine::parseDVIPSLine (InputReader &ir) {
	ir.skipSpace();
	if (ir.peek() != '<' && ir.peek() != '"')
		_psname = ir.getString();
	ir.skipSpace();
	while (ir.peek() == '<' || ir.peek() == '"') {
		if (ir.peek() == '<') {
			ir.get();
			if (ir.peek() == '[')
				ir.get();
			string name = ir.getString();
			if (name.length() > 4 && name.substr(name.length()-4) == ".enc")
				_encname = name.substr(0, name.length()-4);
			else
				_fontfname = name;
		}
		else {  // ir.peek() == '"' => list of PS font operators
			string options = ir.getQuotedString('"');
			StringInputBuffer sib(options);
			BufferInputReader sir(sib);
			while (!sir.eof()) {
				double number;
				if (sir.parseDouble(number)) {
					// operator with preceding numeric parameter (value opstr)
					string opstr = sir.getString();
					if (opstr == "SlantFont")
						_slant = number;
					else if (opstr == "ExtendFont")
						_extend = number;
				}
				else {
					// operator without parameter => skip for now
					sir.getString();
				}
			}
		}
		ir.skipSpace();
	}
}
Пример #30
0
void CommandLine::handle_zip (InputReader &ir, const Option &opt, bool longopt) {
    if (ir.eof() || getIntArg(ir, opt, longopt, _zip_arg))
        _zip_given = true;
}