예제 #1
0
RValue Inst::Deref(CodeContext& context, RValue value, bool recursive)
{
	auto retVal = RValue(value.value(), value.stype());
	while (retVal.stype()->isPointer()) {
		retVal = RValue(new LoadInst(retVal, "", context), retVal.stype()->subType());
		if (!recursive)
			break;
	}
	return retVal;
}
예제 #2
0
void sinsp_filter_check_event::parse_filter_value(const char* str, uint32_t len)
{
	string val(str);

	if(m_field_id == TYPE_ARGRAW)
	{
		//
		// 'rawarg' is handled in a custom way
		//
		ASSERT(m_arginfo != NULL);
		return sinsp_filter_check::string_to_rawval(str, len, m_arginfo->type);
	}
	else if(m_field_id == TYPE_TYPE)
	{
		sinsp_evttables* einfo = m_inspector->get_event_info_tables();
		const struct ppm_event_info* etable = einfo->m_event_info;
		string stype(str, len);

		for(uint32_t j = 0; j < PPM_EVENT_MAX; j++)
		{
			if(stype == etable[j].name)
			{
				return sinsp_filter_check::parse_filter_value(str, len);
			}
		}

		throw sinsp_exception("unknown event type " + stype);
	}
	else
	{
		return sinsp_filter_check::parse_filter_value(str, len);
	}
}
예제 #3
0
void ChessSelectionWidget::okPushButtonClicked()
{
    if(isOK())
    {
        ChessType type = AIType;
        QString stype(tr("ai"));
        if(serverRadioButton->isChecked())
        {
            type = ServerType;
            stype = tr("server");
        }
        else if(clientRadioButton->isChecked())
        {
            type = ClientType;
            stype = tr("client");
        }
        else if(replayRadioButton->isChecked())
        {
            type = ReplayType;
            stype = tr("replay");
        }
        ChessColor color = RedColor;
        QString scolor("red");
        if(ClientType == type)
        {
            color = BlackColor;
            scolor = tr("black");
        }
        Chess_Info(tr("your selection: type=%1 color=%2 ip=%3 port=%4")
                   .arg(stype)
                   .arg(scolor)
                   .arg(ipLineEdit->text())
                   .arg(portSpinBox->value()));
        ChessInformation *ci = ChessInformation::instance();
        ci->init(type, color, ipLineEdit->text(), portSpinBox->value());
        Chess *chess = Chess::instance();
        chess->setAttribute(Qt::WA_DeleteOnClose);  //窗口关闭时自动删除
        this->hide();
        chess->show();
    }
    else
    {
        Chess_Warning(tr("error input, please check!"));
        QMessageBox::warning(this, tr("ERROR INPUT"), tr("ERROR INPUT, PLEASE CHECK!"));
    }
}
예제 #4
0
RValue Inst::SizeOf(CodeContext& context, string* name)
{
	auto isType = SUserType::lookup(context, name);
	auto isVar = context.loadSymbol(name);
	SType* stype = nullptr;

	if (isType && isVar) {
		context.addError(*name + " is ambigious, both a type and a variable");
	} else if (isType) {
		stype = isType;
	} else if (isVar) {
		stype = isVar.stype();
	} else {
		context.addError("type " + *name + " is not declared");
	}
	return SizeOf(context, stype);
}
예제 #5
0
                static v8::Handle<v8::Value> add_field(const v8::Arguments& args, Osmium::Export::Shapefile* shapefile) {
                    if (args.Length() < 3 || args.Length() > 4) {
                        throw std::runtime_error("Wrong number of arguments to add_field method.");
                    }

                    v8::String::Utf8Value name(args[0]);
                    std::string sname(*name);

                    v8::String::Utf8Value type(args[1]);
                    std::string stype(*type);

                    int width = args[2]->Int32Value();
                    int decimals = (args.Length() == 4) ? args[3]->Int32Value() : 0;

                    shapefile->add_field(sname, stype, width, decimals);

                    return v8::Integer::New(1);
                }
예제 #6
0
void DNSSDPluginAPI::browse_callback(DNSServiceRef sdref,
				     DNSServiceFlags flags,
				     uint32_t ifnum,
				     DNSServiceErrorType err,
				     const char* name,
				     const char* type,
				     const char* domain,
				     void* context) {
  if (context == NULL) return;
  if (err == kDNSServiceErr_NoError) {
      bool add = flags & kDNSServiceFlagsAdd ? true : false;
      std::string sname(name);
      std::string stype(type);
      std::string sdomain(domain);
      FB::VariantMap info = FB::variant_map_of<std::string>("add",add)
	("ifnum",ifnum)("name",sname)("type",stype)("domain",sdomain);
      static_cast<DNSSDPluginOp*>(context)->result(info);
  } else {
    static_cast<DNSSDPluginOp*>(context)->error("browse_callback",
						(int64_t) err);
  }
}
예제 #7
0
static inline
PluginType getPluginTypeFromString(const char* const ctype) noexcept
{
    CARLA_SAFE_ASSERT_RETURN(ctype != nullptr && ctype[0] != '\0', PLUGIN_NONE);
    carla_debug("CarlaBackend::getPluginTypeFromString(\"%s\")", ctype);

    CarlaString stype(ctype);

    if (stype.isEmpty())
        return PLUGIN_NONE;

    stype.toLower();

    if (stype == "none")
        return PLUGIN_NONE;
    if (stype == "internal")
        return PLUGIN_INTERNAL;
    if (stype == "ladspa")
        return PLUGIN_LADSPA;
    if (stype == "dssi")
        return PLUGIN_DSSI;
    if (stype == "lv2")
        return PLUGIN_LV2;
    if (stype == "vst")
        return PLUGIN_VST;
    if (stype == "vst3")
        return PLUGIN_VST3;
    if (stype == "au")
        return PLUGIN_AU;
    if (stype == "gig")
        return PLUGIN_GIG;
    if (stype == "sf2")
        return PLUGIN_SF2;
    if (stype == "sfz")
        return PLUGIN_SFZ;

    carla_stderr("CarlaBackend::getPluginTypeFromString(\"%s\") - invalid string type", ctype);
    return PLUGIN_NONE;
}
예제 #8
0
파일: main.cpp 프로젝트: 2202877/acl
int main(int argc, char* argv[])
{
	int   ch;
	acl::string server_addr("127.0.0.1:8888"), file("./xml.txt");
	acl::string stype("xml"), charset("gb2312");

	while ((ch = getopt(argc, argv, "hs:f:t:c:")) > 0)
	{
		switch (ch)
		{
		case 'h':
			usage(argv[0]);
			return 0;
		case 'f':
			file = optarg;
			break;
		case 't':
			stype = optarg;
			break;
		case 'c':
			charset = optarg;
			break;
		default:
			usage(argv[0]);
			return 0;
		}
	}

	// 将日志输出至屏幕
	acl::log::stdout_open(true);

	// 开始运行
	http_request_test request(server_addr, file, stype, charset);
	request.run();

	return 0;
}
예제 #9
0
파일: main.c 프로젝트: ombt/ombt
// start of theorem prover
main(int argc, char **argv)
{
	// current end of data
	SETINITEDATA();
	DISABLETRACE();

	// turn off buffering
	setbuf(stdout, NULL);

	// initialize some variables
	phases[EXPANDFILE] = 1;
	phases[PARSEFILE] = 1;
	phases[ADDEXTRAAXIOMS] = 1;
	phases[CONVERT2CNF] = 1;
	phases[RUNPROVER] = 1;

	// get command line options
	for (int c = 0; (c = getopt(argc, argv, "?L:W:M:D:U:c:S:s:T:C:N:P:m:I:vpt:r:eudR:")) != EOF; )
	{
		switch (c)
		{
		case 'D':
			// turn depth-calculation off
			if (String(optarg) == String("on"))
				usedepth = 1;
			else
				usedepth = 0;
			break;

		case 'U':
			// turn unit-literal option on or off for BFS
			if (String(optarg) == String("on"))
				unitliteral = 1;
			else
				unitliteral = 0;
			break;

		case 'c':
			// turn best-first checks on or off
			if (String(optarg) == String("on"))
				bfswithchecks = 1;
			else
				bfswithchecks = 0;
			break;

		case 's':
			// turn subsumption test on or off
			if (String(optarg) == String("on"))
				subsumptiontest = 1;
			else
				subsumptiontest = 0;
			break;

		case 'T':
			// turn tautolgy test on or off
			if (String(optarg) == String("on"))
				tautologytest = 1;
			else
				tautologytest = 0;
			break;

		case 'C':
			// turn complexity test on or off
			if (String(optarg) == String("on"))
				complexity = 1;
			else
				complexity = 0;
			break;

		case 'M':
			// maximum clause
			maxclause = atoi(optarg);
			if (maxclause <= 0)
				maxclause = INT_MAX;
			break;

		case 'S':
			// number of solutions to find
			solutionsrequired = atoi(optarg);
			if (solutionsrequired <= 0)
				solutionsrequired = INT_MAX;
			break;

		case 'L':
			// number of literals in a clause
			maxliterals = atoi(optarg);
			if (maxliterals <= 0)
				maxliterals = INT_MAX;
			break;

		case 'e':
			// echo input to stdout
			echo = 1;
			break;

		case 'd':
			// enable debug mode
			ENABLETRACE();
			break;

		case 'u':
			// enable memory usage reporting
			reportmemoryusage = 1;
			break;

		case 'R':
		{
			// set type of report
			String rtype(optarg);
			if (rtype == String("none"))
				reporttype = ReportNone;
			else if (rtype == String("both"))
				reporttype = ReportBoth;
			else if (rtype == String("parent"))
				reporttype = ReportParent;
			else if (rtype == String("stack"))
				reporttype = ReportStack;
			else 
			{
				ERRORD("unknown report type.", rtype, EINVAL);
				usage(argv[0]);
				return(2);
			}
			break;
		}

		case 'r':
		{
			// set type of search
			String stype(optarg);
			if (stype == String("sat"))
				searchtype = Saturation;
			else if (stype == String("bfs"))
				searchtype = BreadthFirst;
			else if (stype == String("dfshc"))
				searchtype = DepthFirstHillClimb;
			else if (stype == String("dfs"))
				searchtype = DepthFirst;
			else if (stype == String("best"))
				searchtype = BestFirst;
			else if (stype == String("iter"))
				searchtype = IterativeDeepening;
			else 
			{
				ERRORD("unknown search type.", stype, EINVAL);
				usage(argv[0]);
				return(2);
			}
			break;
		}


		case 'N':
		{
			// turn off phases to run
			String Popts(optarg);
			StringTokens Poptst(Popts, ",");
			for ( ; !Poptst.done(); Poptst++)
			{
				String Popt = Poptst();
				if (!phases.isInMap(Popt))
				{
					ERRORD("unknown phase.", Popt, EINVAL);
					return(2);
				}
				else
				{
					phases[Popt] = 0;
				}
			}
			break;
		}

		case 'P':
		{
			// turn off all phases
			phases[EXPANDFILE] = 0;
			phases[PARSEFILE] = 0;
			phases[ADDEXTRAAXIOMS] = 0;
			phases[CONVERT2CNF] = 0;
			phases[RUNPROVER] = 0;

			// turn on phases to run
			String Popts(optarg);
			StringTokens Poptst(Popts, ",");
			for ( ; !Poptst.done(); Poptst++)
			{
				String Popt = Poptst();
				if (!phases.isInMap(Popt))
				{
					ERRORD("unknown phase.", Popt, EINVAL);
					return(2);
				}
				else
				{
					phases[Popt] = 1;
				}
			}
			break;
		}

		case 'm':
			// maximum depth for search
			maxdepth = atoi(optarg);
			if (maxdepth <= 0)
				maxdepth = INT_MAX;
			break;

		case 'W':
			// weight factor 0<=weight<=10
			weight = atoi(optarg);
			if (weight < 0 || weight > 10)
			{
				ERRORD("weight out of range, 0<=W<=10.",
					weight, EINVAL);
				return(2);
			}
			break;

		case 'v':
			// verbose mode
			verbose = 1;
			break;

		case 'p':
			// use paramodulation 
			paramodulation = 1;
			ERROR("paramodulation (-p) not implemented.", EINVAL);
			return(2);
			// break;

		case 't':
			// base directory for temp
			tempbase = optarg;
			break;

		case 'I':
			// include directories
			if (includedirs.insertAtEnd(String(optarg)) != OK)
			{
				ERRORD("unable to save an include directory.",
					optarg, EINVAL);
				return(2);
			}
			break;

		case '?':
			usage(argv[0]);
			return(0);

		default:
			ERRORD("invalid command option.", c, EINVAL);
			return(2);
		}
	}

	// copy list of files to a list
	if (optind >= argc)
	{
		ERROR("no input files were given.", EINVAL);
		usage(argv[0]);
		return(2);
	}
	List<String> inputfiles;
	for (int arg = optind; arg < argc; arg++)
	{
		if (inputfiles.insertAtEnd(String(argv[arg])) != OK)
		{
			ERRORD("unable to save file.", argv[arg], errno);
			return(2);
		}
	}

	// command line options
	cout << "================== Program Options =============== " << endl;
	cout << "phases to RUN: " << phases << endl;
	cout << "temp base directory: " << tempbase << endl;
	cout << "extra include-directories: " << includedirs << endl;
	dumpoptval("echo input", echo);
	dumpoptval("debug mode (trace flag)", GETTRACE());
	dumpoptval("use verbose", verbose);
	dumpoptval("report memory usage", reportmemoryusage);
	cout << "maximum depth: ";
	if (maxdepth == INT_MAX)
		cout <<  "DISABLED";
	else
		cout << maxdepth;
	cout << endl;
	cout << "maximum clause: ";
	if (maxclause == INT_MAX)
		cout <<  "DISABLED";
	else
		cout << maxclause;
	cout << endl;
	cout << "solutions to find: ";
	if (solutionsrequired == INT_MAX)
		cout <<  "ALL SOLUTIONS";
	else
		cout << solutionsrequired;
	cout << endl;
	cout << "maximum literals in a clause: ";
	if (maxliterals == INT_MAX)
		cout <<  "NO LIMIT";
	else
		cout << maxliterals;
	cout << endl;
	cout << "best-first search g vs. h weight: " << weight << endl;
	dumpoptval("use paramodulation", paramodulation);
	dumpoptval("subsumption test", subsumptiontest);
	dumpoptval("tautology test", tautologytest);
	cout << "search type: ";
	switch (searchtype)
	{
	case Saturation:
		cout << "Saturation";
		break;
	case BreadthFirst:
		cout << "BreadthFirst";
		break;
	case DepthFirst:
		cout << "DepthFirst";
		break;
	case DepthFirstHillClimb:
		cout << "DepthFirstHillClimb";
		break;
	case BestFirst:
		cout << "BestFirst";
		break;
	case IterativeDeepening:
		cout << "IterativeDeepening";
		break;
	default:
		cout << "UNKNOWN !!!";
		break;
	}
	cout << endl;
	cout << "report type: ";
	switch (reporttype)
	{
	case ReportNone:
		cout << "ReportNone";
		break;
	case ReportBoth:
		cout << "ReportBoth";
		break;
	case ReportParent:
		cout << "ReportParent";
		break;
	case ReportStack:
		cout << "ReportStack";
		break;
	default:
		cout << "UNKNOWN !!!";
		break;
	}
	cout << endl;
	dumpoptval("depth for gvalue (bfs-only)", usedepth);
	dumpoptval("unit-preference for hvalue (bfs-only)", unitliteral);
	dumpoptval("children-redundancy removal (bfs-only)", bfswithchecks);
	dumpoptval("complexity-preference for hvalue (bfs-only)", complexity);
	cout << "================================================== " << endl;

	// expand any include files
	List<Tuple<String, String> > expandedfiles;
	if (verbose)
	{
		cout << endl;
		cout << "Input files are ... " << endl;
		ListIterator<String> ifIter(inputfiles);
		for ( ; !ifIter.done(); ifIter++)
		{
			cout << ifIter() << endl;
		}
	}
	if (expandFiles(inputfiles, expandedfiles) != OK)
	{
		ERROR("failed to expand files.", EINVAL);
		return(2);
	}
	if (verbose)
	{
		cout << endl;
		cout << "Expanded files are ... " << endl;
		ListIterator<Tuple<String, String> > xfIter(expandedfiles);
		for ( ; !xfIter.done(); xfIter++)
		{
			cout << "input file " << xfIter().key << " ===>> ";
			cout << "expanded file " << xfIter().data << endl;
		}
	}

	// create statistics entries
	initAllStatistics();

	// set signal handler
	(void) signal(SIGINT, handler);
	(void) signal(SIGHUP, handler);
	(void) signal(SIGQUIT, handler);

	// set current end of data
	SETFINALEDATA();
	DUMPDATA(cout);

	// parse and run theorem prover
	if (runatp(expandedfiles) != OK)
	{
		ERROR("failed to run theorem prover.", EINVAL);
		return(2);
	}

	// dump out statistics
	cout << endl;
	cout << "Total Run Time Statistics ..." << endl;
	cout << totalstatistics << endl;
	cout << endl;
	cout << "Total Program Statistics ..." << endl;
	cout << programstatistics << endl;

	// current end of data
	SETFINALEDATA();
	DUMPDATA(cout);

#ifdef MEMORYLEAK
	// dump memory leak data
	cout << endl;
	cout << "BFSNode Memory Leak Data: " << endl;
	cout << BFSNode::memoryleak << endl;
	cout << endl;
	cout << "Clause Memory Leak Data: " << endl;
	cout << Clause::memoryleak << endl;
	cout << endl;
	cout << "Literal Memory Leak Data: " << endl;
	cout << Literal::memoryleak << endl;
	cout << endl;
	cout << "Terms Memory Leak Data: " << endl;
	cout << Terms::memoryleak << endl;
#endif

	// all done
	return(0);
}
예제 #10
0
    ComponentPortDescription
    CPD_Handler::component_port_description (
                                             const Deployment::ComponentPortDescription& src)
    {
      DANCE_TRACE("CPD_Handler::component_port_description - reverse");
      ::XMLSchema::string< ACE_TCHAR > name (ACE_TEXT_CHAR_TO_TCHAR (src.name));
      ::XMLSchema::string< ACE_TCHAR > stype (ACE_TEXT_CHAR_TO_TCHAR (src.specificType));

      ::XMLSchema::string< ACE_TCHAR > tval (ACE_TEXT ("true"));
      ::XMLSchema::string< ACE_TCHAR > fval (ACE_TEXT ("false"));
      XMLSchema::boolean provider;
      XMLSchema::boolean  exclusiveProvider;
      XMLSchema::boolean exclusiveUser;
      XMLSchema::boolean optional;

      if (src.provider)
        provider = true;
      else
        provider = false;

      if (src.exclusiveUser)
        exclusiveUser = true;
      else
        provider = false;

      if (src.exclusiveProvider)
        exclusiveProvider = true;
      else
        provider = false;

      if (src.optional)
        optional = true;
      else
        provider = false;

      ComponentPortDescription cpd (name,
                                    provider,
                                    exclusiveProvider,
                                    exclusiveUser,
                                    optional,
                                    CCMComponentPortKind::Facet);

      switch (src.kind)
        {
        case ::Deployment::Facet:
          cpd.kind (CCMComponentPortKind::Facet);
          break;

        case ::Deployment::SimplexReceptacle:
          cpd.kind (CCMComponentPortKind::SimplexReceptacle);
          break;

        case ::Deployment::MultiplexReceptacle:
          cpd.kind (CCMComponentPortKind::MultiplexReceptacle);
          break;

        case ::Deployment::EventEmitter:
          cpd.kind (CCMComponentPortKind::EventEmitter);
          break;

        case ::Deployment::EventPublisher:
          cpd.kind (CCMComponentPortKind::EventPublisher);
          break;

        case ::Deployment::EventConsumer:
          cpd.kind (CCMComponentPortKind::EventConsumer);
          break;

        default:
          DANCE_DEBUG (DANCE_LOG_NONFATAL_ERROR,
            (LM_ERROR, ACE_TEXT("Invalid port kind in connection %C\n"),
            name.c_str ()));
        }

      for (CORBA::ULong i = 0; i < src.supportedType.length (); ++i)
        {
          //cpd.add_supportedType (XMLSchema::string< ACE_TCHAR > ((src.supportedType[i])));
        }

      return cpd;
    }
예제 #11
0
파일: chm_common.c 프로젝트: cran/Matrix
/**
 * Populate ans with the pointers from x and modify its scalar
 * elements accordingly. Note that later changes to the contents of
 * ans will change the contents of the SEXP.
 *
 * In most cases this function is called through the macros
 * AS_CHM_TR() or AS_CHM_TR__().  It is unusual to call it directly.
 *
 * @param ans a CHM_TR pointer
 * @param x pointer to an object that inherits from TsparseMatrix
 * @param check_Udiag boolean - should a check for (and consequent
 *  expansion of) a unit diagonal be performed.
 *
 * @return ans containing pointers to the slots of x, *unless*
 *	check_Udiag and x is unitriangular.
 */
CHM_TR as_cholmod_triplet(CHM_TR ans, SEXP x, Rboolean check_Udiag)
{
    static const char *valid[] = { MATRIX_VALID_Tsparse, ""};
    int ctype = R_check_class_etc(x, valid),
	*dims = INTEGER(GET_SLOT(x, Matrix_DimSym));
    SEXP islot = GET_SLOT(x, Matrix_iSym);
    int m = LENGTH(islot);
    Rboolean do_Udiag = (check_Udiag && ctype % 3 == 2 && (*diag_P(x) == 'U'));
    if (ctype < 0) error(_("invalid class of object to as_cholmod_triplet"));

    memset(ans, 0, sizeof(cholmod_triplet)); /* zero the struct */

    ans->itype = CHOLMOD_INT;	/* characteristics of the system */
    ans->dtype = CHOLMOD_DOUBLE;
				/* nzmax, dimensions, types and slots : */
    ans->nnz = ans->nzmax = m;
    ans->nrow = dims[0];
    ans->ncol = dims[1];
    ans->stype = stype(ctype, x);
    ans->xtype = xtype(ctype);
    ans->i = (void *) INTEGER(islot);
    ans->j = (void *) INTEGER(GET_SLOT(x, Matrix_jSym));
    ans->x = xpt(ctype, x);

    if(do_Udiag) {
	/* diagU2N(.) "in place", similarly to Tsparse_diagU2N [./Tsparse.c]
	   (but without new SEXP): */
	int k = m + dims[0];
	CHM_TR tmp = cholmod_l_copy_triplet(ans, &cl);
	int *a_i, *a_j;

	if(!cholmod_reallocate_triplet((size_t) k, tmp, &cl))
	    error(_("as_cholmod_triplet(): could not reallocate for internal diagU2N()"
		      ));

	/* TODO? instead of copy_triplet() & reallocate_triplet()
	 * ---- allocate to correct length + Memcpy() here, as in
	 * Tsparse_diagU2N() & chTr2Ralloc() below */
	a_i = tmp->i;
	a_j = tmp->j;
	/* add (@i, @j)[k+m] = k, @x[k+m] = 1.   for k = 0,..,(n-1) */
	for(k=0; k < dims[0]; k++) {
	    a_i[k+m] = k;
	    a_j[k+m] = k;

	    switch(ctype / 3) {
	    case 0: { /* "d" */
		double *a_x = tmp->x;
		a_x[k+m] = 1.;
		break;
	    }
	    case 1: { /* "l" */
		int *a_x = tmp->x;
		a_x[k+m] = 1;
		break;
	    }
	    case 2: /* "n" */
		break;
	    case 3: { /* "z" */
		double *a_x = tmp->x;
		a_x[2*(k+m)  ] = 1.;
		a_x[2*(k+m)+1] = 0.;
		break;
	    }
	    }
	} /* for(k) */

	chTr2Ralloc(ans, tmp);
	cholmod_l_free_triplet(&tmp, &c);

    } /* else :
       * NOTE: if(*diag_P(x) == 'U'), the diagonal is lost (!);
       * ---- that may be ok, e.g. if we are just converting from/to Tsparse,
       *      but is *not* at all ok, e.g. when used before matrix products */

    return ans;
}
예제 #12
0
파일: chm_common.c 프로젝트: cran/Matrix
/**
 * Populate ans with the pointers from x and modify its scalar
 * elements accordingly. Note that later changes to the contents of
 * ans will change the contents of the SEXP.
 *
 * In most cases this function is called through the macros
 * AS_CHM_SP() or AS_CHM_SP__().  It is unusual to call it directly.
 *
 * @param ans a CHM_SP pointer
 * @param x pointer to an object that inherits from CsparseMatrix
 * @param check_Udiag boolean - should a check for (and consequent
 *  expansion of) a unit diagonal be performed.
 * @param sort_in_place boolean - if the i and x slots are to be sorted
 *  should they be sorted in place?  If the i and x slots are pointers
 *  to an input SEXP they should not be modified.
 *
 * @return ans containing pointers to the slots of x, *unless*
 *	check_Udiag and x is unitriangular.
 */
CHM_SP as_cholmod_sparse(CHM_SP ans, SEXP x,
			 Rboolean check_Udiag, Rboolean sort_in_place)
{
    static const char *valid[] = { MATRIX_VALID_Csparse, ""};
    int *dims = INTEGER(GET_SLOT(x, Matrix_DimSym)),
	ctype = R_check_class_etc(x, valid);
    SEXP islot = GET_SLOT(x, Matrix_iSym);

    if (ctype < 0) error(_("invalid class of object to as_cholmod_sparse"));
    if (!isValid_Csparse(x))
	error(_("invalid object passed to as_cholmod_sparse"));
    memset(ans, 0, sizeof(cholmod_sparse)); /* zero the struct */

    ans->itype = CHOLMOD_INT;	/* characteristics of the system */
    ans->dtype = CHOLMOD_DOUBLE;
    ans->packed = TRUE;
				/* slots always present */
    ans->i = INTEGER(islot);
    ans->p = INTEGER(GET_SLOT(x, Matrix_pSym));
				/* dimensions and nzmax */
    ans->nrow = dims[0];
    ans->ncol = dims[1];
    /* Allow for over-allocation of the i and x slots.  Needed for
     * sparse X form in lme4.  Right now it looks too difficult to
     * check for the length of the x slot, because of the xpt
     * utility, but the lengths of x and i should agree. */
    ans->nzmax = LENGTH(islot);
				/* values depending on ctype */
    ans->x = xpt(ctype, x);
    ans->stype = stype(ctype, x);
    ans->xtype = xtype(ctype);

    /* are the columns sorted (increasing row numbers) ?*/
    ans->sorted = check_sorted_chm(ans);
    if (!(ans->sorted)) { /* sort columns */
	if(sort_in_place) {
	    if (!cholmod_sort(ans, &c))
		error(_("in_place cholmod_sort returned an error code"));
	    ans->sorted = 1;
	}
	else {
	    CHM_SP tmp = cholmod_copy_sparse(ans, &c);
	    if (!cholmod_sort(tmp, &c))
		error(_("cholmod_sort returned an error code"));

#ifdef DEBUG_Matrix
	    /* This "triggers" exactly for return values of dtCMatrix_sparse_solve():*/
	    /* Don't want to translate this: want it report */
	    Rprintf("Note: as_cholmod_sparse() needed cholmod_sort()ing\n");
#endif
	    chm2Ralloc(ans, tmp);
	    cholmod_free_sparse(&tmp, &c);
	}
    }

    if (check_Udiag && ctype % 3 == 2 // triangular
	&& (*diag_P(x) == 'U')) { /* diagU2N(.)  "in place" : */
	double one[] = {1, 0};
	CHM_SP eye = cholmod_speye(ans->nrow, ans->ncol, ans->xtype, &c);
	CHM_SP tmp = cholmod_add(ans, eye, one, one, TRUE, TRUE, &c);

#ifdef DEBUG_Matrix_verbose /* happens quite often, e.g. in ../tests/indexing.R : */
	Rprintf("Note: as_cholmod_sparse(<ctype=%d>) - diagU2N\n", ctype);
#endif
	chm2Ralloc(ans, tmp);
	cholmod_free_sparse(&tmp, &c);
	cholmod_free_sparse(&eye, &c);
    } /* else :
       * NOTE: if(*diag_P(x) == 'U'), the diagonal is lost (!);
       * ---- that may be ok, e.g. if we are just converting from/to Tsparse,
       *      but is *not* at all ok, e.g. when used before matrix products */

    return ans;
}
예제 #13
0
void  denominatorStatistic(int nsub, 
   int * n_swidth, int *n_twidth, int * n_0width, denlist * allDenominators, 
   FILE * fd)
{ 
   int i;
   catrec    cr;
   denlist    den_, den_tmp;
   deninforec   dendescript={0};
    
   (*n_swidth)  = 0;
   (*n_twidth)  = 0;
   (*n_0width) = 0;

   den_ =NULL;
   
   fseek(catalog,0,SEEK_SET);
   while (FREAD1(cr,catalog))
   {
      
      if (cr.nsub_ == nsub)
      { 
         whichArchive(cr.nFile,'r');
         dendescript.cr_pos = ftell(catalog) - sizeof(cr);

         fseek(archiv,cr.denompos,SEEK_SET);
         readDenominators();
         dendescript.tot_den=denrno; 

         for (i = 0; i < dendescript.tot_den; i++)
         {  
            dendescript.denarr[i].power=denom[i].power;
            dendescript.denarr[i].width=denom[i].width;
            den_tmp = den_;  
            while (den_tmp != NULL &&
              (  strcmp(denom[i].momStr,den_tmp->momStr)
              ||  denom[i].mass!=den_tmp->mass 
              ||  denom[i].width!=den_tmp->width ) ) den_tmp=den_tmp->next;
            if(den_tmp == NULL)
            {  
               den_tmp = (denlist)getmem_((unsigned)sizeof(denlistrec));
               den_tmp->next = den_;
               strcpy(den_tmp->momStr,denom[i].momStr);
               den_tmp->mass=denom[i].mass;
               den_tmp->width=denom[i].width;
               den_tmp->stype= stype(denom[i].momStr);
               den_ = den_tmp;
               if(denom[i].width) 
               { if(den_tmp->stype) den_tmp->order_num= ++(*n_swidth);
                         else       den_tmp->order_num= ++(*n_twidth);
               }  else              den_tmp->order_num= ++(*n_0width);
            }
            dendescript.denarr[i].order_num=den_tmp->order_num;
            dendescript.denarr[i].stype=den_tmp->stype;
         }      
         if(fd) FWRITE1(dendescript,fd);
      }  /* if CR.nsub_ =nsub */
   }
   
/*   if(ArchNum) fclose(archiv);  */
   whichArchive(0,0);
  *allDenominators=den_;
}