void test_direct_trans()
{
	const index_t m = M == 0 ? DM : M;
	const index_t n = N == 0 ? DN : N;

	// M x N ==> N x M

	typedef typename mat_host<Tag1, double, M, N>::cmat_t cmat_t;
	typedef typename mat_host<Tag2, double, N, M>::mat_t mat_t;

	mat_host<Tag1, double, M, N> src(m, n);
	mat_host<Tag2, double, N, M> dst(n, m);

	src.fill_lin();

	cmat_t smat = src.get_cmat();
	mat_t dmat = dst.get_mat();

	transpose(smat, dmat);

	dense_matrix<double, N, M> rmat(n, m);
	for (index_t i = 0; i < m; ++i)
	{
		for (index_t j = 0; j < n; ++j) rmat(j, i) = smat(i, j);
	}

	ASSERT_MAT_EQ(n, m, dmat, rmat);

	// N x M ==> M x N

	typedef typename mat_host<Tag1, double, N, M>::cmat_t cmat2_t;
	typedef typename mat_host<Tag2, double, M, N>::mat_t mat2_t;

	mat_host<Tag1, double, N, M> src2(n, m);
	mat_host<Tag2, double, M, N> dst2(m, n);

	src2.fill_lin();

	cmat2_t smat2 = src2.get_cmat();
	mat2_t dmat2 = dst2.get_mat();

	transpose(smat2, dmat2);

	dense_matrix<double, M, N> rmat2(m, n);
	for (index_t i = 0; i < m; ++i)
	{
		for (index_t j = 0; j < n; ++j) rmat2(i, j) = smat2(j, i);
	}

	ASSERT_MAT_EQ(m, n, dmat2, rmat2);

}
示例#2
0
文件: vector.cpp 项目: rashaw1/LinAlg
// Get the outer product of two vectors (a matrix), assuming rhs vector 
// implies its transpose (otherwise it wouldn't work!)
Matrix outer(const Vector& u, const Vector& w)
{
  int usize = u.size();
  int wsize = w.size();
  Matrix rmat(usize, wsize); // Matrix that will be returned
  for (int i = 0; i < usize; i++){
    for (int j = 0; j < wsize; j++){
      // Calculate element ij of rmat
      rmat(i, j) = u(i)*w(j);
    }
  }
  return rmat;
}
示例#3
0
static void t_compensate(double* input, double* output, bool rz)
{
    const auto H = input[Yaw] * M_PI / -180;
    const auto P = input[Pitch] * M_PI / -180;
    const auto B = input[Roll] * M_PI / 180;

    const auto cosH = cos(H);
    const auto sinH = sin(H);
    const auto cosP = cos(P);
    const auto sinP = sin(P);
    const auto cosB = cos(B);
    const auto sinB = sin(B);

    double foo[] = {
        cosH * cosB - sinH * sinP * sinB,
        - sinB * cosP,
        sinH * cosB + cosH * sinP * sinB,
        cosH * sinB + sinH * sinP * cosB,
        cosB * cosP,
        sinB * sinH - cosH * sinP * cosB,
        - sinH * cosP,
        - sinP,
        cosH * cosP,
    };

    cv::Mat rmat(3, 3, CV_64F, foo);
    const cv::Mat tvec(3, 1, CV_64F, input);
    cv::Mat ret = rmat * tvec;

    const int max = !rz ? 3 : 2;

    for (int i = 0; i < max; i++)
        output[i] = ret.at<double>(i);
}
bool FlyingCamera::onSimCameraQuery(SimCameraQuery *query)
{
   SimObjectTransformQuery tquery;

   query->cameraInfo.fov       = g_rDefaultFOV;
   query->cameraInfo.nearPlane = DEFAULT_NEAR_PLANE;
   query->cameraInfo.farPlane  = getFarPlane();

   if (objFollow && objFollow->processQuery(&tquery))
   {
      Point3F  objPos = tquery.tmat.p;
      Vector3F x, y, z;
      RMat3F   rmat(EulerF(rotation.x - M_PI / 2, rotation.y, -rotation.z));

      tquery.tmat.p   += m_mul(Vector3F(0.0f, rDistance, 0.0f), rmat, &y);
      tquery.tmat.p.z += 2.0f;

      y.neg();
      y.normalize();
      m_cross(y, Vector3F(0.0f, 0.0f, 1.0f), &x);
      x.normalize();
      m_cross(x, y, &z);

      tquery.tmat.setRow(0, x);
      tquery.tmat.setRow(1, y);
      tquery.tmat.setRow(2, z);

      // Set our position
      findLOSPosition(tquery.tmat, objPos);
   }

   query->cameraInfo.tmat = getTransform();
   return (true);
}
 virtual void update(){
     std::shared_ptr<writer> dat(new writer(true));
     dat->add_data(data::create("Segment", num_seg), writer::PARAMETER);
     double avals[4] = {a1, a2, a3, ap};
     dat->add_data(data::create("Angles", avals, 4), writer::PARAMETER);
     holder->add_writer(dat);
     j1=rmat(a1)*wq*rmat(-1*a1);
     j2=rmat(a2)*wq*rmat(-1*a2);
     j3=rmat(a3)*wh*rmat(-1*a3);
     jp=rmat(ap)*wp*rmat(-1*ap);
     mvals = j1*jp*j2*j3;
 }
示例#6
0
//------------------------------------------------------------------------------
// bool MatrixEvaluate()
//------------------------------------------------------------------------------
Rmatrix MathElement::MatrixEvaluate()
{
   #ifdef DEBUG_EVALUATE
   MessageInterface::ShowMessage
      ("MathElement::MatrixEvaluate() this='%s', refObjectName='%s', refObject=<%p>, "
       "elementType=%d\n", GetName().c_str(), refObjectName.c_str(), refObject, elementType);
   #endif
   
   // If this MathElement is function Input, just return since it is handled in
   // the FunctionRunner
   
   if (isFunctionInput)
      throw MathException("MathElement::MatrixEvaluate() Function input should "
                          "not be handled here");
   
   if (elementType == Gmat::RMATRIX_TYPE)
   {
      if (refObject)
      {
         #ifdef DEBUG_EVALUATE
         Rmatrix rmat = refObject->GetRmatrix();
         MessageInterface::ShowMessage
            ("MathElement::MatrixEvaluate() It's an Array: %s matVal =\n%s\n",
             refObject->GetName().c_str(), rmat.ToString().c_str());
         #endif
         
         ElementWrapper *wrapper = FindWrapper(refObjectName);
         return wrapper->EvaluateArray();
      }
      else
      {
         #ifdef DEBUG_EVALUATE
         MessageInterface::ShowMessage
            ("MathElement::MatrixEvaluate() It's a Rmatrix. matVal =\n%s\n",
             matrix.ToString().c_str());
         #endif
         
         return matrix;
      }
   }
   else
   {
      Real rval = Evaluate();
      
      #ifdef DEBUG_EVALUATE
      MessageInterface::ShowMessage
         ("MathElement::MatrixEvaluate() It's a number: rval = %f\n", rval);
      #endif
      
      // Set matrix 1x1 and return
      Rmatrix rmat(1, 1, rval);
      return rmat;
      //throw MathException("MathElement::MatrixEvaluate() Invalid matrix");
   }
}
void WorldEditorSelection::setRotate(const EulerF & rot)
{
   for( iterator iter = begin(); iter != end(); ++ iter )
   {
      SceneObject* object = dynamic_cast< SceneObject* >( *iter );
      if( !object )
         continue;

      MatrixF mat = object->getTransform();
      Point3F pos;
      mat.getColumn(3, &pos);

      MatrixF rmat(rot);
      rmat.setPosition(pos);

      object->setTransform(rmat);
   }
}
 ///Randomly rotate sgrid_m
 void NonLocalECPComponent::randomize_grid(ParticleSet::ParticlePos_t& sphere, bool randomize)
 {
   if(randomize) {
     //const RealType twopi(6.28318530718);
     //RealType phi(twopi*Random()),psi(twopi*Random()),cth(Random()-0.5),
     RealType phi(TWOPI*((*myRNG)())), psi(TWOPI*((*myRNG)())), cth(((*myRNG)())-0.5);
     RealType sph(std::sin(phi)),cph(std::cos(phi)),
     sth(std::sqrt(1.0-cth*cth)),sps(std::sin(psi)),
     cps(std::cos(psi));
     TensorType rmat( cph*cth*cps-sph*sps, sph*cth*cps+cph*sps,-sth*cps,
         -cph*cth*sps-sph*cps,-sph*cth*sps+cph*cps, sth*sps,
         cph*sth,             sph*sth,             cth     );
     SpherGridType::iterator it(sgridxyz_m.begin());
     SpherGridType::iterator it_end(sgridxyz_m.end());
     SpherGridType::iterator jt(rrotsgrid_m.begin());
     int ic=0;
     while(it != it_end) {*jt = dot(rmat,*it); ++it; ++jt;}
     //copy the radomized grid to sphere
     std::copy(rrotsgrid_m.begin(), rrotsgrid_m.end(), sphere.begin());
   } else {
     //copy sphere to the radomized grid
     std::copy(sphere.begin(), sphere.end(), rrotsgrid_m.begin());
   }
 }
示例#9
0
int
pw_user(struct userconf * cnf, int mode, struct cargs * args)
{
	int	        rc, edited = 0;
	char           *p = NULL;
	char					 *passtmp;
	struct carg    *a_name;
	struct carg    *a_uid;
	struct carg    *arg;
	struct passwd  *pwd = NULL;
	struct group   *grp;
	struct stat     st;
	char            line[_PASSWORD_LEN+1];
	FILE	       *fp;
	char *dmode_c;
	void *set = NULL;

	static struct passwd fakeuser =
	{
		NULL,
		"*",
		-1,
		-1,
		0,
		"",
		"User &",
		"/nonexistent",
		"/bin/sh",
		0
#if defined(__FreeBSD__)
		,0
#endif
	};


	/*
	 * With M_NEXT, we only need to return the
	 * next uid to stdout
	 */
	if (mode == M_NEXT)
	{
		uid_t next = pw_uidpolicy(cnf, args);
		if (getarg(args, 'q'))
			return next;
		printf("%ld:", (long)next);
		pw_group(cnf, mode, args);
		return EXIT_SUCCESS;
	}

	/*
	 * We can do all of the common legwork here
	 */

	if ((arg = getarg(args, 'b')) != NULL) {
		cnf->home = arg->val;
	}

	if ((arg = getarg(args, 'M')) != NULL) {
		dmode_c = arg->val;
		if ((set = setmode(dmode_c)) == NULL)
			errx(EX_DATAERR, "invalid directory creation mode '%s'",
			    dmode_c);
		cnf->homemode = getmode(set, _DEF_DIRMODE);
		free(set);
	}

	/*
	 * If we'll need to use it or we're updating it,
	 * then create the base home directory if necessary
	 */
	if (arg != NULL || getarg(args, 'm') != NULL) {
		int	l = strlen(cnf->home);

		if (l > 1 && cnf->home[l-1] == '/')	/* Shave off any trailing path delimiter */
			cnf->home[--l] = '\0';

		if (l < 2 || *cnf->home != '/')		/* Check for absolute path name */
			errx(EX_DATAERR, "invalid base directory for home '%s'", cnf->home);

		if (stat(cnf->home, &st) == -1) {
			char	dbuf[MAXPATHLEN];

			/*
			 * This is a kludge especially for Joerg :)
			 * If the home directory would be created in the root partition, then
			 * we really create it under /usr which is likely to have more space.
			 * But we create a symlink from cnf->home -> "/usr" -> cnf->home
			 */
			if (strchr(cnf->home+1, '/') == NULL) {
				strcpy(dbuf, "/usr");
				strncat(dbuf, cnf->home, MAXPATHLEN-5);
				if (mkdir(dbuf, _DEF_DIRMODE) != -1 || errno == EEXIST) {
					chown(dbuf, 0, 0);
					/*
					 * Skip first "/" and create symlink:
					 * /home -> usr/home
					 */
					symlink(dbuf+1, cnf->home);
				}
				/* If this falls, fall back to old method */
			}
			strlcpy(dbuf, cnf->home, sizeof(dbuf));
			p = dbuf;
			if (stat(dbuf, &st) == -1) {
				while ((p = strchr(p + 1, '/')) != NULL) {
					*p = '\0';
					if (stat(dbuf, &st) == -1) {
						if (mkdir(dbuf, _DEF_DIRMODE) == -1)
							goto direrr;
						chown(dbuf, 0, 0);
					} else if (!S_ISDIR(st.st_mode))
						errx(EX_OSFILE, "'%s' (root home parent) is not a directory", dbuf);
					*p = '/';
				}
			}
			if (stat(dbuf, &st) == -1) {
				if (mkdir(dbuf, _DEF_DIRMODE) == -1) {
				direrr:	err(EX_OSFILE, "mkdir '%s'", dbuf);
				}
				chown(dbuf, 0, 0);
			}
		} else if (!S_ISDIR(st.st_mode))
			errx(EX_OSFILE, "root home `%s' is not a directory", cnf->home);
	}

	if ((arg = getarg(args, 'e')) != NULL)
		cnf->expire_days = atoi(arg->val);

	if ((arg = getarg(args, 'y')) != NULL)
		cnf->nispasswd = arg->val;

	if ((arg = getarg(args, 'p')) != NULL && arg->val)
		cnf->password_days = atoi(arg->val);

	if ((arg = getarg(args, 'g')) != NULL) {
		if (!*(p = arg->val))	/* Handle empty group list specially */
			cnf->default_group = "";
		else {
			if ((grp = GETGRNAM(p)) == NULL) {
				if (!isdigit((unsigned char)*p) || (grp = GETGRGID((gid_t) atoi(p))) == NULL)
					errx(EX_NOUSER, "group `%s' does not exist", p);
			}
			cnf->default_group = newstr(grp->gr_name);
		}
	}
	if ((arg = getarg(args, 'L')) != NULL)
		cnf->default_class = pw_checkname((u_char *)arg->val, 0);

	if ((arg = getarg(args, 'G')) != NULL && arg->val) {
		int i = 0;

		for (p = strtok(arg->val, ", \t"); p != NULL; p = strtok(NULL, ", \t")) {
			if ((grp = GETGRNAM(p)) == NULL) {
				if (!isdigit((unsigned char)*p) || (grp = GETGRGID((gid_t) atoi(p))) == NULL)
					errx(EX_NOUSER, "group `%s' does not exist", p);
			}
			if (extendarray(&cnf->groups, &cnf->numgroups, i + 2) != -1)
				cnf->groups[i++] = newstr(grp->gr_name);
		}
		while (i < cnf->numgroups)
			cnf->groups[i++] = NULL;
	}

	if ((arg = getarg(args, 'k')) != NULL) {
		if (stat(cnf->dotdir = arg->val, &st) == -1 || !S_ISDIR(st.st_mode))
			errx(EX_OSFILE, "skeleton `%s' is not a directory or does not exist", cnf->dotdir);
	}

	if ((arg = getarg(args, 's')) != NULL)
		cnf->shell_default = arg->val;

	if ((arg = getarg(args, 'w')) != NULL)
		cnf->default_password = boolean_val(arg->val, cnf->default_password);
	if (mode == M_ADD && getarg(args, 'D')) {
		if (getarg(args, 'n') != NULL)
			errx(EX_DATAERR, "can't combine `-D' with `-n name'");
		if ((arg = getarg(args, 'u')) != NULL && (p = strtok(arg->val, ", \t")) != NULL) {
			if ((cnf->min_uid = (uid_t) atoi(p)) == 0)
				cnf->min_uid = 1000;
			if ((p = strtok(NULL, " ,\t")) == NULL || (cnf->max_uid = (uid_t) atoi(p)) < cnf->min_uid)
				cnf->max_uid = 32000;
		}
		if ((arg = getarg(args, 'i')) != NULL && (p = strtok(arg->val, ", \t")) != NULL) {
			if ((cnf->min_gid = (gid_t) atoi(p)) == 0)
				cnf->min_gid = 1000;
			if ((p = strtok(NULL, " ,\t")) == NULL || (cnf->max_gid = (gid_t) atoi(p)) < cnf->min_gid)
				cnf->max_gid = 32000;
		}

		arg = getarg(args, 'C');
		if (write_userconfig(arg ? arg->val : NULL))
			return EXIT_SUCCESS;
		warn("config update");
		return EX_IOERR;
	}

	if (mode == M_PRINT && getarg(args, 'a')) {
		int             pretty = getarg(args, 'P') != NULL;
		int		v7 = getarg(args, '7') != NULL;
		SETPWENT();
		while ((pwd = GETPWENT()) != NULL)
			print_user(pwd, pretty, v7);
		ENDPWENT();
		return EXIT_SUCCESS;
	}

	if ((a_name = getarg(args, 'n')) != NULL)
		pwd = GETPWNAM(pw_checkname((u_char *)a_name->val, 0));
	a_uid = getarg(args, 'u');

	if (a_uid == NULL) {
		if (a_name == NULL)
			errx(EX_DATAERR, "user name or id required");

		/*
		 * Determine whether 'n' switch is name or uid - we don't
		 * really don't really care which we have, but we need to
		 * know.
		 */
		if (mode != M_ADD && pwd == NULL
		    && strspn(a_name->val, "0123456789") == strlen(a_name->val)
		    && *a_name->val) {
			(a_uid = a_name)->ch = 'u';
			a_name = NULL;
		}
	}

	/*
	 * Update, delete & print require that the user exists
	 */
	if (mode == M_UPDATE || mode == M_DELETE ||
	    mode == M_PRINT  || mode == M_LOCK   || mode == M_UNLOCK) {

		if (a_name == NULL && pwd == NULL)	/* Try harder */
			pwd = GETPWUID(atoi(a_uid->val));

		if (pwd == NULL) {
			if (mode == M_PRINT && getarg(args, 'F')) {
				fakeuser.pw_name = a_name ? a_name->val : "nouser";
				fakeuser.pw_uid = a_uid ? (uid_t) atol(a_uid->val) : -1;
				return print_user(&fakeuser,
						  getarg(args, 'P') != NULL,
						  getarg(args, '7') != NULL);
			}
			if (a_name == NULL)
				errx(EX_NOUSER, "no such uid `%s'", a_uid->val);
			errx(EX_NOUSER, "no such user `%s'", a_name->val);
		}

		if (a_name == NULL)	/* May be needed later */
			a_name = addarg(args, 'n', newstr(pwd->pw_name));

		/*
		 * The M_LOCK and M_UNLOCK functions simply add or remove
		 * a "*LOCKED*" prefix from in front of the password to
		 * prevent it decoding correctly, and therefore prevents
		 * access. Of course, this only prevents access via
		 * password authentication (not ssh, kerberos or any
		 * other method that does not use the UNIX password) but
		 * that is a known limitation.
		 */

		if (mode == M_LOCK) {
			if (strncmp(pwd->pw_passwd, locked_str, sizeof(locked_str)-1) == 0)
				errx(EX_DATAERR, "user '%s' is already locked", pwd->pw_name);
			passtmp = malloc(strlen(pwd->pw_passwd) + sizeof(locked_str));
			if (passtmp == NULL)	/* disaster */
				errx(EX_UNAVAILABLE, "out of memory");
			strcpy(passtmp, locked_str);
			strcat(passtmp, pwd->pw_passwd);
			pwd->pw_passwd = passtmp;
			edited = 1;
		} else if (mode == M_UNLOCK) {
			if (strncmp(pwd->pw_passwd, locked_str, sizeof(locked_str)-1) != 0)
				errx(EX_DATAERR, "user '%s' is not locked", pwd->pw_name);
			pwd->pw_passwd += sizeof(locked_str)-1;
			edited = 1;
		} else if (mode == M_DELETE) {
			/*
			 * Handle deletions now
			 */
			char            file[MAXPATHLEN];
			char            home[MAXPATHLEN];
			uid_t           uid = pwd->pw_uid;
			struct group    *gr;
			char            grname[LOGNAMESIZE];

			if (strcmp(pwd->pw_name, "root") == 0)
				errx(EX_DATAERR, "cannot remove user 'root'");

			if (!PWALTDIR()) {
				/*
				 * Remove opie record from /etc/opiekeys
		        	 */

				rmopie(pwd->pw_name);

				/*
				 * Remove crontabs
				 */
				snprintf(file, sizeof(file), "/var/cron/tabs/%s", pwd->pw_name);
				if (access(file, F_OK) == 0) {
					sprintf(file, "crontab -u %s -r", pwd->pw_name);
					system(file);
				}
			}
			/*
			 * Save these for later, since contents of pwd may be
			 * invalidated by deletion
			 */
			sprintf(file, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
			strlcpy(home, pwd->pw_dir, sizeof(home));
			gr = GETGRGID(pwd->pw_gid);
			if (gr != NULL)
				strlcpy(grname, gr->gr_name, LOGNAMESIZE);
			else
				grname[0] = '\0';

			rc = delpwent(pwd);
			if (rc == -1)
				err(EX_IOERR, "user '%s' does not exist", pwd->pw_name);
			else if (rc != 0) {
				warn("passwd update");
				return EX_IOERR;
			}

			if (cnf->nispasswd && *cnf->nispasswd=='/') {
				rc = delnispwent(cnf->nispasswd, a_name->val);
				if (rc == -1)
					warnx("WARNING: user '%s' does not exist in NIS passwd", pwd->pw_name);
				else if (rc != 0)
					warn("WARNING: NIS passwd update");
				/* non-fatal */
			}

			grp = GETGRNAM(a_name->val);
			if (grp != NULL &&
			    (grp->gr_mem == NULL || *grp->gr_mem == NULL) &&
			    strcmp(a_name->val, grname) == 0)
				delgrent(GETGRNAM(a_name->val));
			SETGRENT();
			while ((grp = GETGRENT()) != NULL) {
				int i, j;
				char group[MAXLOGNAME];
				if (grp->gr_mem != NULL) {
					for (i = 0; grp->gr_mem[i] != NULL; i++) {
						if (!strcmp(grp->gr_mem[i], a_name->val)) {
							for (j = i; grp->gr_mem[j] != NULL; j++)
								grp->gr_mem[j] = grp->gr_mem[j+1];
							strlcpy(group, grp->gr_name, MAXLOGNAME);
							chggrent(group, grp);
						}
					}
				}
			}
			ENDGRENT();

			pw_log(cnf, mode, W_USER, "%s(%ld) account removed", a_name->val, (long) uid);

			if (!PWALTDIR()) {
				/*
				 * Remove mail file
				 */
				remove(file);

				/*
				 * Remove at jobs
				 */
				if (getpwuid(uid) == NULL)
					rmat(uid);

				/*
				 * Remove home directory and contents
				 */
				if (getarg(args, 'r') != NULL && *home == '/' && getpwuid(uid) == NULL) {
					if (stat(home, &st) != -1) {
						rm_r(home, uid);
						pw_log(cnf, mode, W_USER, "%s(%ld) home '%s' %sremoved",
						       a_name->val, (long) uid, home,
						       stat(home, &st) == -1 ? "" : "not completely ");
					}
				}
			}
			return EXIT_SUCCESS;
		} else if (mode == M_PRINT)
			return print_user(pwd,
					  getarg(args, 'P') != NULL,
					  getarg(args, '7') != NULL);

		/*
		 * The rest is edit code
		 */
		if ((arg = getarg(args, 'l')) != NULL) {
			if (strcmp(pwd->pw_name, "root") == 0)
				errx(EX_DATAERR, "can't rename `root' account");
			pwd->pw_name = pw_checkname((u_char *)arg->val, 0);
			edited = 1;
		}

		if ((arg = getarg(args, 'u')) != NULL && isdigit((unsigned char)*arg->val)) {
			pwd->pw_uid = (uid_t) atol(arg->val);
			edited = 1;
			if (pwd->pw_uid != 0 && strcmp(pwd->pw_name, "root") == 0)
				errx(EX_DATAERR, "can't change uid of `root' account");
			if (pwd->pw_uid == 0 && strcmp(pwd->pw_name, "root") != 0)
				warnx("WARNING: account `%s' will have a uid of 0 (superuser access!)", pwd->pw_name);
		}

		if ((arg = getarg(args, 'g')) != NULL && pwd->pw_uid != 0) {	/* Already checked this */
			gid_t newgid = (gid_t) GETGRNAM(cnf->default_group)->gr_gid;
			if (newgid != pwd->pw_gid) {
				edited = 1;
				pwd->pw_gid = newgid;
			}
		}

		if ((arg = getarg(args, 'p')) != NULL) {
			if (*arg->val == '\0' || strcmp(arg->val, "0") == 0) {
				if (pwd->pw_change != 0) {
					pwd->pw_change = 0;
					edited = 1;
				}
			}
			else {
				time_t          now = time(NULL);
				time_t          expire = parse_date(now, arg->val);

				if (pwd->pw_change != expire) {
					pwd->pw_change = expire;
					edited = 1;
				}
			}
		}

		if ((arg = getarg(args, 'e')) != NULL) {
			if (*arg->val == '\0' || strcmp(arg->val, "0") == 0) {
				if (pwd->pw_expire != 0) {
					pwd->pw_expire = 0;
					edited = 1;
				}
			}
			else {
				time_t          now = time(NULL);
				time_t          expire = parse_date(now, arg->val);

				if (pwd->pw_expire != expire) {
					pwd->pw_expire = expire;
					edited = 1;
				}
			}
		}

		if ((arg = getarg(args, 's')) != NULL) {
			char *shell = shell_path(cnf->shelldir, cnf->shells, arg->val);
			if (shell == NULL)
				shell = "";
			if (strcmp(shell, pwd->pw_shell) != 0) {
				pwd->pw_shell = shell;
				edited = 1;
			}
		}

		if (getarg(args, 'L')) {
			if (cnf->default_class == NULL)
				cnf->default_class = "";
			if (strcmp(pwd->pw_class, cnf->default_class) != 0) {
				pwd->pw_class = cnf->default_class;
				edited = 1;
			}
		}

		if ((arg  = getarg(args, 'd')) != NULL) {
			if (strcmp(pwd->pw_dir, arg->val))
				edited = 1;
			if (stat(pwd->pw_dir = arg->val, &st) == -1) {
				if (getarg(args, 'm') == NULL && strcmp(pwd->pw_dir, "/nonexistent") != 0)
				  warnx("WARNING: home `%s' does not exist", pwd->pw_dir);
			} else if (!S_ISDIR(st.st_mode))
				warnx("WARNING: home `%s' is not a directory", pwd->pw_dir);
		}

		if ((arg = getarg(args, 'w')) != NULL &&
		    getarg(args, 'h') == NULL && getarg(args, 'H') == NULL) {
			login_cap_t *lc;

			lc = login_getpwclass(pwd);
			if (lc == NULL ||
			    login_setcryptfmt(lc, "sha512", NULL) == NULL)
				warn("setting crypt(3) format");
			login_close(lc);
			pwd->pw_passwd = pw_password(cnf, args, pwd->pw_name);
			edited = 1;
		}

	} else {
		login_cap_t *lc;

		/*
		 * Add code
		 */

		if (a_name == NULL)	/* Required */
			errx(EX_DATAERR, "login name required");
		else if ((pwd = GETPWNAM(a_name->val)) != NULL)	/* Exists */
			errx(EX_DATAERR, "login name `%s' already exists", a_name->val);

		/*
		 * Now, set up defaults for a new user
		 */
		pwd = &fakeuser;
		pwd->pw_name = a_name->val;
		pwd->pw_class = cnf->default_class ? cnf->default_class : "";
		pwd->pw_uid = pw_uidpolicy(cnf, args);
		pwd->pw_gid = pw_gidpolicy(cnf, args, pwd->pw_name, (gid_t) pwd->pw_uid);
		pwd->pw_change = pw_pwdpolicy(cnf, args);
		pwd->pw_expire = pw_exppolicy(cnf, args);
		pwd->pw_dir = pw_homepolicy(cnf, args, pwd->pw_name);
		pwd->pw_shell = pw_shellpolicy(cnf, args, NULL);
		lc = login_getpwclass(pwd);
		if (lc == NULL || login_setcryptfmt(lc, "sha512", NULL) == NULL)
			warn("setting crypt(3) format");
		login_close(lc);
		pwd->pw_passwd = pw_password(cnf, args, pwd->pw_name);
		edited = 1;

		if (pwd->pw_uid == 0 && strcmp(pwd->pw_name, "root") != 0)
			warnx("WARNING: new account `%s' has a uid of 0 (superuser access!)", pwd->pw_name);
	}

	/*
	 * Shared add/edit code
	 */
	if ((arg = getarg(args, 'c')) != NULL) {
		char	*gecos = pw_checkname((u_char *)arg->val, 1);
		if (strcmp(pwd->pw_gecos, gecos) != 0) {
			pwd->pw_gecos = gecos;
			edited = 1;
		}
	}

	if ((arg = getarg(args, 'h')) != NULL ||
	    (arg = getarg(args, 'H')) != NULL) {
		if (strcmp(arg->val, "-") == 0) {
			if (!pwd->pw_passwd || *pwd->pw_passwd != '*') {
				pwd->pw_passwd = "*";	/* No access */
				edited = 1;
			}
		} else {
			int             fd = atoi(arg->val);
			int		precrypt = (arg->ch == 'H');
			int             b;
			int             istty = isatty(fd);
			struct termios  t;
			login_cap_t	*lc;

			if (istty) {
				if (tcgetattr(fd, &t) == -1)
					istty = 0;
				else {
					struct termios  n = t;

					/* Disable echo */
					n.c_lflag &= ~(ECHO);
					tcsetattr(fd, TCSANOW, &n);
					printf("%s%spassword for user %s:",
					     (mode == M_UPDATE) ? "new " : "",
					     precrypt ? "encrypted " : "",
					     pwd->pw_name);
					fflush(stdout);
				}
			}
			b = read(fd, line, sizeof(line) - 1);
			if (istty) {	/* Restore state */
				tcsetattr(fd, TCSANOW, &t);
				fputc('\n', stdout);
				fflush(stdout);
			}
			if (b < 0) {
				warn("-%c file descriptor", precrypt ? 'H' :
				    'h');
				return EX_IOERR;
			}
			line[b] = '\0';
			if ((p = strpbrk(line, "\r\n")) != NULL)
				*p = '\0';
			if (!*line)
				errx(EX_DATAERR, "empty password read on file descriptor %d", fd);
			if (precrypt) {
				if (strchr(line, ':') != NULL)
					return EX_DATAERR;
				pwd->pw_passwd = line;
			} else {
				lc = login_getpwclass(pwd);
				if (lc == NULL ||
				    login_setcryptfmt(lc, "sha512", NULL) == NULL)
					warn("setting crypt(3) format");
				login_close(lc);
				pwd->pw_passwd = pw_pwcrypt(line);
			}
			edited = 1;
		}
	}

	/*
	 * Special case: -N only displays & exits
	 */
	if (getarg(args, 'N') != NULL)
		return print_user(pwd,
				  getarg(args, 'P') != NULL,
				  getarg(args, '7') != NULL);

	if (mode == M_ADD) {
		edited = 1;	/* Always */
		rc = addpwent(pwd);
		if (rc == -1) {
			warnx("user '%s' already exists", pwd->pw_name);
			return EX_IOERR;
		} else if (rc != 0) {
			warn("passwd file update");
			return EX_IOERR;
		}
		if (cnf->nispasswd && *cnf->nispasswd=='/') {
			rc = addnispwent(cnf->nispasswd, pwd);
			if (rc == -1)
				warnx("User '%s' already exists in NIS passwd", pwd->pw_name);
			else
				warn("NIS passwd update");
			/* NOTE: we treat NIS-only update errors as non-fatal */
		}
	} else if (mode == M_UPDATE || mode == M_LOCK || mode == M_UNLOCK) {
		if (edited) {	/* Only updated this if required */
			rc = chgpwent(a_name->val, pwd);
			if (rc == -1) {
				warnx("user '%s' does not exist (NIS?)", pwd->pw_name);
				return EX_IOERR;
			} else if (rc != 0) {
				warn("passwd file update");
				return EX_IOERR;
			}
			if ( cnf->nispasswd && *cnf->nispasswd=='/') {
				rc = chgnispwent(cnf->nispasswd, a_name->val, pwd);
				if (rc == -1)
					warn("User '%s' not found in NIS passwd", pwd->pw_name);
				else
					warn("NIS passwd update");
				/* NOTE: NIS-only update errors are not fatal */
			}
		}
	}

	/*
	 * Ok, user is created or changed - now edit group file
	 */

	if (mode == M_ADD || getarg(args, 'G') != NULL) {
		int i;
		for (i = 0; cnf->groups[i] != NULL; i++) {
			grp = GETGRNAM(cnf->groups[i]);
			grp = gr_add(grp, pwd->pw_name);
			/*
			 * grp can only be NULL in 2 cases:
			 * - the new member is already a member
			 * - a problem with memory occurs
			 * in both cases we want to skip now.
			 */
			if (grp == NULL)
				continue;
			chggrent(cnf->groups[i], grp);
			free(grp);
		}
	}


	/* go get a current version of pwd */
	pwd = GETPWNAM(a_name->val);
	if (pwd == NULL) {
		/* This will fail when we rename, so special case that */
		if (mode == M_UPDATE && (arg = getarg(args, 'l')) != NULL) {
			a_name->val = arg->val;		/* update new name */
			pwd = GETPWNAM(a_name->val);	/* refetch renamed rec */
		}
	}
	if (pwd == NULL)	/* can't go on without this */
		errx(EX_NOUSER, "user '%s' disappeared during update", a_name->val);

	grp = GETGRGID(pwd->pw_gid);
	pw_log(cnf, mode, W_USER, "%s(%ld):%s(%ld):%s:%s:%s",
	       pwd->pw_name, (long) pwd->pw_uid,
	    grp ? grp->gr_name : "unknown", (long) (grp ? grp->gr_gid : -1),
	       pwd->pw_gecos, pwd->pw_dir, pwd->pw_shell);

	/*
	 * If adding, let's touch and chown the user's mail file. This is not
	 * strictly necessary under BSD with a 0755 maildir but it also
	 * doesn't hurt anything to create the empty mailfile
	 */
	if (mode == M_ADD) {
		if (!PWALTDIR()) {
			sprintf(line, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
			close(open(line, O_RDWR | O_CREAT, 0600));	/* Preserve contents &
									 * mtime */
			chown(line, pwd->pw_uid, pwd->pw_gid);
		}
	}

	/*
	 * Let's create and populate the user's home directory. Note
	 * that this also `works' for editing users if -m is used, but
	 * existing files will *not* be overwritten.
	 */
	if (!PWALTDIR() && getarg(args, 'm') != NULL && pwd->pw_dir && *pwd->pw_dir == '/' && pwd->pw_dir[1]) {
		copymkdir(pwd->pw_dir, cnf->dotdir, cnf->homemode, pwd->pw_uid, pwd->pw_gid);
		pw_log(cnf, mode, W_USER, "%s(%ld) home %s made",
		       pwd->pw_name, (long) pwd->pw_uid, pwd->pw_dir);
	}


	/*
	 * Finally, send mail to the new user as well, if we are asked to
	 */
	if (mode == M_ADD && !PWALTDIR() && cnf->newmail && *cnf->newmail && (fp = fopen(cnf->newmail, "r")) != NULL) {
		FILE           *pfp = popen(_PATH_SENDMAIL " -t", "w");
		
		if (pfp == NULL)
			warn("sendmail");
		else {
			fprintf(pfp, "From: root\n" "To: %s\n" "Subject: Welcome!\n\n", pwd->pw_name);
			while (fgets(line, sizeof(line), fp) != NULL) {
				/* Do substitutions? */
				fputs(line, pfp);
			}
			pclose(pfp);
			pw_log(cnf, mode, W_USER, "%s(%ld) new user mail sent",
			    pwd->pw_name, (long) pwd->pw_uid);
		}
		fclose(fp);
	}

	return EXIT_SUCCESS;
}
示例#10
0
//checking all the sequence for the time being
McoStatus Cmysurface::findboundary(double *inlab, double *boundlab, double *boundcmy, int16* yes)
{

	double	r1,r2,r3;
	register double	a1,a2,a3,a4,a5,a6,a7,a8,a9;
	double	s1,s2,s3;
	double	determ;
	McoStatus status;
	int32 i,j,k;
	int32 total_tri;	//total # of triangles
	int32 start;
	double sdata[9];	//data of core matrix
	double rdata[3]; 	//data of right matrix
	Matrix rmat(3, 1);
	Matrix lmat(3, 1);
	Matrix s(3);
	double the1, the2, t;
	int32 two_d_offset, total_squares;
	int32 p1, p2, p3;
	double L;
	
	//assume no compression needed
	*yes = 0;
	
	//screen L value, min and max
	L = inlab[0];
	if( L > _maxgrayL){
		L = _maxgrayL - 0.1;
		*yes = 1;
	}	
	if( L < _mingrayL){
		L = _mingrayL + 0.1;	
		*yes = 1;
	}	
	
	//screen a,b value
	if( fabs(inlab[1]) < SCREEN_DELTA && fabs(inlab[2]) < SCREEN_DELTA ){
		boundlab[0] = L;
		boundlab[1] = inlab[1];
		boundlab[2] = inlab[2];
		return MCO_SUCCESS;
	}		
	
	//some optimization here to improve the speed
	//first guess which plane the point may cross
	/*
	if( inlab[1] >= 0 && inlab[2] >= 0){
		
		sq[0] = 0;
		sq[1] = 1;
		if(inlab[1] > inlab[2] ){
			sq[2] = 
	*/
	
	two_d_offset = 3*_one_d_points*_one_d_points;
	total_squares = (_one_d_points-1)*(_one_d_points-1);
	
	for(i = 0; i < 6; i++){//c=0,c=1,...
		for( j = 0; j < total_squares; j++){//squares in one plane
			for( k = 0; k <= 3; k += 3){//two triangles in one square
				start = i*two_d_offset + _start_id[j];
				
				//x0 - x3
				p3 = start + _tri_id[2+k];
				r1 = L - _slab[p3];
				r2 = -_slab[p3+1];
				r3 = -_slab[p3+2];
				//rmat.loadstruct(rdata);
				
				//core matrix
				p1 = start + _tri_id[k];
				p2 = start + _tri_id[1+k];
				
				//left col
				a1 = _slab[p1] - _slab[p3];
				a4 = _slab[p1+1] - _slab[p3+1];
				a7 = _slab[p1+2] - _slab[p3+2];
				
				//middle col
				a2 = _slab[p2] - _slab[p3];
				a5 = _slab[p2+1] - _slab[p3+1];
				a8 = _slab[p2+2] - _slab[p3+2];
				
				//right col
				a3 = 0;
				a6 = -inlab[1];
				a9 = -inlab[2];
				//s.loadstruct(sdata);
				
				determ = a1*(a5*a9 - a6*a8) - a2*(a4*a9 - a6*a7) + a3*(a4*a8 - a5*a7);
				
				if (determ == 0) return MCO_SINGULAR;
								
				s1 = (a5*a9 - a6*a8)*r1 - (a2*a9 - a3*a8)*r2 + (a2*a6 - a3*a5)*r3;
				s1 = s1/determ;
				
				s2 = - (a4*a9 - a6*a7)*r1 + (a1*a9 - a3*a7)*r2 - (a1*a6 - a3*a4)*r3;
				s2 = s2/determ;
				
				s3 = (a4*a8 - a5*a7)*r1 - (a1*a8 - a2*a7)*r2 + (a1*a5 - a2*a4)*r3;
				s3 = s3/determ;


				the1 = s1;
				the2 = s2;
				t = s3;
								
				//check where is the crossing point, or even it exists
				if( the1 >= 0 && the2 >= 0 && the1+the2 <= 1){ //cross the current triangle
					if( t > 1){ //inlab is inside the gamut
						boundlab[0] = L;
						boundlab[1] = inlab[1];
						boundlab[2] = inlab[2];
						return MCO_SUCCESS;
					}
					else if( t >= 0){ //inlab is outside the gamut, need compression
					
						//compute the crossing point
						boundlab[0] = L;
						boundlab[1] = inlab[1]*t;
						boundlab[2] = inlab[2]*t;
						*yes = 1;
						//for test only, find corresponding c,m,y value
						/*
						boundcmy[0] = _scmy[p1]*the1+_scmy[p2]*the2+_scmy[p3]*(1-the1-the2);
						boundcmy[1] = _scmy[p1+1]*the1+_scmy[p2+1]*the2+_scmy[p3+1]*(1-the1-the2);
						boundcmy[2] = _scmy[p1+2]*the1+_scmy[p2+2]*the2+_scmy[p3+2]*(1-the1-the2);
						*/
						return MCO_SUCCESS;
					}
					//else t < 0 on the reverse side of gray axis
				}	
			}	
		}
	}
	
	return MCO_FAILURE; //should change this return value
}						
示例#11
0
//function to find the maxL and minL of gray scale
void Cmysurface::_findminmax(void)
{
	McoStatus status;
	int32 i,j,k;
	int32 total_tri;	//total # of triangles
	int32 start;
	double sdata[9];	//data of core matrix
	double rdata[3]; 	//data of right matrix
	Matrix rmat(3, 1);
	Matrix lmat(3, 1);
	Matrix s(3);
	double the1, the2, t;
	int32 two_d_offset, total_squares;
	int32 p1, p2, p3;
	double inlab[3];
	double L;
	
	//set inlab(p4 is always 100, p0 is always 0)
	inlab[0] = 100;
	inlab[1] = 0;
	inlab[2] = 0;
	
	
	_mingrayL = 100;
	_maxgrayL = 0;

		
	two_d_offset = 3*_one_d_points*_one_d_points;
	total_squares = (_one_d_points-1)*(_one_d_points-1);
	
	for(i = 0; i < 6; i++){//c=0,c=1,...
		for( j = 0; j < total_squares; j++){//squares in one plane
			for( k = 0; k <= 3; k += 3){//two triangles in one square
				start = i*two_d_offset + _start_id[j];
				
				//x0 - x3( y0 is 0 0 0
				p3 = start + _tri_id[2+k];
				rdata[0] = -_slab[p3];
				rdata[1] = -_slab[p3+1];
				rdata[2] = -_slab[p3+2];
				rmat.loadstruct(rdata);
				
				//core matrix
				p1 = start + _tri_id[k];
				p2 = start + _tri_id[1+k];
				
				//left col
				sdata[0] = _slab[p1] - _slab[p3];
				sdata[3] = _slab[p1+1] - _slab[p3+1];
				sdata[6] = _slab[p1+2] - _slab[p3+2];
				
				//middle col
				sdata[1] = _slab[p2] - _slab[p3];
				sdata[4] = _slab[p2+1] - _slab[p3+1];
				sdata[7] = _slab[p2+2] - _slab[p3+2];
				
				//right col
				sdata[2] = -inlab[0];
				sdata[5] = -inlab[1];
				sdata[8] = -inlab[2];
				s.loadstruct(sdata);
				
				//compute
				s.inv();
				if( (status = s.get_status()) == MCO_SUCCESS){ //singular or ?
					
					lmat = s*rmat;
					lmat.getval(1, 1, &the1);
					lmat.getval(2, 1, &the2);
					lmat.getval(3, 1, &t);
					
					//check where is the crossing point, or even it exists
					if( the1 >= 0 && the2 >= 0 && the1+the2 <= 1){ //cross the current triangle
						if( t >= 0 && t <= 1){
						
							L = t*inlab[0];
							if( L > _maxgrayL)
								_maxgrayL = L;
								
							if( L < _mingrayL)
								_mingrayL = L;	
						}
						//else t < 0 on the reverse side of gray axis
					}
				}		
			}	
		}
	}
	
	return;
}					
TransformationMatrix& TransformationMatrix::rotate3d(double rx, double ry, double rz)
{
    // angles are in degrees. Switch to radians
    rx = deg2rad(rx);
    ry = deg2rad(ry);
    rz = deg2rad(rz);
    
    TransformationMatrix mat;
    
    rz /= 2.0f;
    double sinA = sin(rz);
    double cosA = cos(rz);
    double sinA2 = sinA * sinA;
    
    mat.m_matrix[0][0] = 1.0f - 2.0f * sinA2;
    mat.m_matrix[0][1] = 2.0f * sinA * cosA;
    mat.m_matrix[0][2] = 0.0f;
    mat.m_matrix[1][0] = -2.0f * sinA * cosA;
    mat.m_matrix[1][1] = 1.0f - 2.0f * sinA2;
    mat.m_matrix[1][2] = 0.0f;
    mat.m_matrix[2][0] = 0.0f;
    mat.m_matrix[2][1] = 0.0f;
    mat.m_matrix[2][2] = 1.0f;
    mat.m_matrix[0][3] = mat.m_matrix[1][3] = mat.m_matrix[2][3] = 0.0f;
    mat.m_matrix[3][0] = mat.m_matrix[3][1] = mat.m_matrix[3][2] = 0.0f;
    mat.m_matrix[3][3] = 1.0f;
    
    TransformationMatrix rmat(mat);
    
    ry /= 2.0f;
    sinA = sin(ry);
    cosA = cos(ry);
    sinA2 = sinA * sinA;
    
    mat.m_matrix[0][0] = 1.0f - 2.0f * sinA2;
    mat.m_matrix[0][1] = 0.0f;
    mat.m_matrix[0][2] = -2.0f * sinA * cosA;
    mat.m_matrix[1][0] = 0.0f;
    mat.m_matrix[1][1] = 1.0f;
    mat.m_matrix[1][2] = 0.0f;
    mat.m_matrix[2][0] = 2.0f * sinA * cosA;
    mat.m_matrix[2][1] = 0.0f;
    mat.m_matrix[2][2] = 1.0f - 2.0f * sinA2;
    mat.m_matrix[0][3] = mat.m_matrix[1][3] = mat.m_matrix[2][3] = 0.0f;
    mat.m_matrix[3][0] = mat.m_matrix[3][1] = mat.m_matrix[3][2] = 0.0f;
    mat.m_matrix[3][3] = 1.0f;
    
    rmat.multLeft(mat);

    rx /= 2.0f;
    sinA = sin(rx);
    cosA = cos(rx);
    sinA2 = sinA * sinA;
    
    mat.m_matrix[0][0] = 1.0f;
    mat.m_matrix[0][1] = 0.0f;
    mat.m_matrix[0][2] = 0.0f;
    mat.m_matrix[1][0] = 0.0f;
    mat.m_matrix[1][1] = 1.0f - 2.0f * sinA2;
    mat.m_matrix[1][2] = 2.0f * sinA * cosA;
    mat.m_matrix[2][0] = 0.0f;
    mat.m_matrix[2][1] = -2.0f * sinA * cosA;
    mat.m_matrix[2][2] = 1.0f - 2.0f * sinA2;
    mat.m_matrix[0][3] = mat.m_matrix[1][3] = mat.m_matrix[2][3] = 0.0f;
    mat.m_matrix[3][0] = mat.m_matrix[3][1] = mat.m_matrix[3][2] = 0.0f;
    mat.m_matrix[3][3] = 1.0f;
    
    rmat.multLeft(mat);

    multLeft(rmat);
    return *this;
}
示例#13
0
int process_options(int argc, char** argv, bool rmat_generator, struct options* options)
{
  // Options common for both generators
  po::options_description common("Common options");
  common.add_options()
    ("help", "print this message")    
    ("name", po::value<std::string>(&options->global.graphname), "graph name")
    ("threads", po::value<int>(&options->global.nthreads)->default_value(DEFAULT_NTHREADS), "number of threads")
    ("buffer-size", po::value<size_t>(&options->global.buffer_size), "buffer size in bytes")
    ("bpt", po::value<int>(&options->global.buffers_per_thread)->default_value(DEFAULT_BUFFERS_PER_THREAD), "number of buffers per thread")
    ("symmetric", "emit also a reverse edge for each generated edge")
    ("seed1", po::value<uint64_t>(&options->rng.userseed1)->default_value(DEFAULT_RNG_USERSEED1), "first 64b of seed for rng")
    ("seed2", po::value<uint64_t>(&options->rng.userseed2)->default_value(DEFAULT_RNG_USERSEED2), "second 64b of seed for rng")
  ;

  // Options specific to ER
  po::options_description er("Erdos-Renyi");
  er.add_options()
    ("vertices", po::value<vertex_t>(&options->erdos_renyi.vertices)->default_value(DEFAULT_ER_VERTICES), "number of vertices")
    ("edges", po::value<edge_t>(&options->erdos_renyi.edges)->default_value(DEFAULT_ER_EDGES), "number of edges")
    ("self-loops", "allow self loops")
    ("bipartite", po::value<vertex_t>(&options->erdos_renyi.bipartite), "argument should specify the number of vertices on the left side")
  ;

  // Options specific to RMAT
  po::options_description rmat("R-MAT");
  rmat.add_options()
    ("scale", po::value<int>(&options->rmat.scale)->default_value(DEFAULT_RMAT_SCALE), "log2 of the number of vertices")
    ("edges", po::value<edge_t>(&options->rmat.edges)->default_value(DEFAULT_RMAT_EDGES), "number of edges")
    ("a", po::value<double>(&options->rmat.a)->default_value(DEFAULT_RMAT_A, "0.57"), "a, b, c, d are RMAT probabilities (usually a = 3b = 3c > d)")
    ("b", po::value<double>(&options->rmat.b)->default_value(DEFAULT_RMAT_B, "0.19"), "")
    ("c", po::value<double>(&options->rmat.c)->default_value(DEFAULT_RMAT_C, "0.19"), "")
    ("xscale_interval", po::value<unsigned int>(&options->rmat.xscale_interval)->default_value(1), "# xscale machines")
    ("xscale_node", po::value<unsigned int>(&options->rmat.xscale_node)->default_value(0), "xscale machine number")
  ;

  po::options_description cmdline_options;
  if (rmat_generator)
    cmdline_options.add(common).add(rmat);
  else
    cmdline_options.add(common).add(er);

  // Store options
  bool err = false;
  po::variables_map vm;
  try {
    po::store(po::parse_command_line(argc, argv, cmdline_options), vm);
    po::notify(vm);
  } catch (boost::program_options::error) {
    err = true;
  }

  // Help
  if (vm.count("help") || !vm.count("name") || err)
  {
    std::cout << "Usage: " << (rmat_generator ? "rmat" : "erdor-renyi") << " --name graphname [options]\n";
    std::cout << "       " << (rmat_generator ? "rmat" : "erdor-renyi") << " --help\n";
    std::cout << cmdline_options << "\n";
    return 1;
  }

  // Process options (where needed)
  if (vm.count("buffer-size")) {
    options->global.buffer_size = vm["buffer-size"].as<size_t>();
  } else {
    options->global.buffer_size = 0;
  }
  if (vm.count("symmetric")) {
    options->global.symmetric = true;
  } else {
    options->global.symmetric = false;
  }
  if (vm.count("self-loops")) {
    options->erdos_renyi.self_loops = true;
  } else {
    options->erdos_renyi.self_loops = false;
  }
  if (!vm.count("bipartite")) {
    options->erdos_renyi.bipartite = 0;
  }

  return 0;  
}
示例#14
0
bool SequentialSolver::LocalSubKKT::projected_primal_and_bilateral( AssembledSystem& res,
                                                              const AssembledSystem& sys,
                                                              real eps,
                                                              bool only_lower)
{
    scoped::timer step("subsystem primal-bilateral");

    projection_basis(P, sys.P, sys.isPIdentity);

    if(sys.n)
    {
        unsigned nb_bilaterals = projection_bilateral( Q, Q_unil, sys );

        if( !nb_bilaterals ) // no bilateral constraints
        {
            res.H = rmat();
            return false;
        }
        else
        {
            filter_kkt(res.H, sys.H, P, Q, sys.J, sys.C, eps, sys.isPIdentity, nb_bilaterals == sys.n, only_lower);

            res.dt = sys.dt;
            res.m = res.H.rows();
            res.n = Q_unil.cols();
            res.P.resize( res.m, res.m );
            res.P.setIdentity();
            res.isPIdentity = true;

            if( res.n ) // there are non-bilat constraints
            {
                // keep only unilateral constraints in C
                res.C.resize( res.n, res.n );
                res.C = Q_unil.transpose() * sys.C * Q_unil;

                // compute J_unil and resize it
                res.J.resize( res.n, res.m );

                static rmat tmp; // try to improve matrix allocation

                tmp = Q_unil.transpose() * sys.J * P;
                for( rmat::Index i = 0; i < tmp.rows(); ++i)
                {
                    res.J.startVec( i );
                    for(rmat::InnerIterator it(tmp, i); it; ++it) {
                        res.J.insertBack(i, it.col()) = it.value();
                    }
                }
                res.J.finalize();
            }
            else
            {
                res.J = rmat();
                res.C = rmat();
            }

            return true;
        }
    }
    else // no constraints
    {
        res.H = rmat();
        return false;
    }
}