Eigen::MatrixXd Reconstruction3D::computeP(	const std::vector<std::pair<Eigen::Vector2d, Eigen::Vector2d>>& points,
											const Eigen::MatrixXd& E)
{
	Eigen::JacobiSVD< Eigen::MatrixXd, Eigen::FullPivHouseholderQRPreconditioner > svd(E, Eigen::ComputeFullU | Eigen::ComputeFullV);
	Eigen::MatrixXd U = svd.matrixU();
	Eigen::MatrixXd Vt = svd.matrixV().transpose();


	Eigen::MatrixXd W(3, 3);
	W << 0.0, -1.0, 0.0,
		1.0, 0.0, 0.0,
		0.0, 0.0, 1.0;

	Eigen::VectorXd u3 = U.col(2);

	//std::cout << "--- Computing P Matrix: " << std::endl
	//	<< "E: " << std::endl << E << std::endl << std::endl
	//	<< "U: " << std::endl << U << std::endl << std::endl
	//	<< "D: " << std::endl << svd.singularValues() << std::endl << std::endl
	//	<< "Vt: " << std::endl << Vt << std::endl << std::endl
	//	<< "W: " << std::endl << W << std::endl << std::endl
	//	<< "u3 :" << u3 << std::endl << std::endl;

	Eigen::MatrixXd P0(Eigen::MatrixXd::Identity(3, 4)); // Just K0: no translation or rotation.

	Eigen::MatrixXd UWVt = U * W * Vt; // P without translation part.

	Eigen::MatrixXd P1(3, 4);
	P1.block(0, 0, 3, 3) = UWVt;
	P1.block(0, 3, 3, 1) = u3;

	Eigen::MatrixXd bestP1 = P0;
	int numCorrectSolutions = 0;
	if (checkP(points, P0, P1))
	{
		++numCorrectSolutions;
		bestP1 = P1;
	}

	P1.block(0, 3, 3, 1) = -u3;

	if (checkP(points, P0, P1))
	{
		++numCorrectSolutions;
		bestP1 = P1;
	}

	UWVt = U * W.transpose() * Vt;
	P1.block(0, 0, 3, 3) = UWVt;
	P1.block(0, 3, 3, 1) = u3;

	if (checkP(points, P0, P1))
	{
		++numCorrectSolutions;
		bestP1 = P1;
	}

	P1.block(0, 3, 3, 1) = -u3;


	if (checkP(points, P0, P1))
	{
		++numCorrectSolutions;
		bestP1 = P1;
	}

	std::cout << "Number of correct solutions: " << numCorrectSolutions << std::endl << std::endl;

	if (numCorrectSolutions < 1)
		std::cerr << "[Error]   : None of the results for P1 was accepted!" << std::endl << std::endl;
	else if (numCorrectSolutions > 1)
		std::cerr << "[Error]   : More than one solution found : " << numCorrectSolutions << std::endl << std::endl;
//	else
//		std::cerr << "[Info]    : Solution found for P: \n" << bestP1 << std::endl << std::endl;

	return bestP1;

}
Example #2
0
	(((b0##UL << 0x0)|(b1##UL << 0x1)|(b2##UL << 0x2)|(b3##UL << 0x3) |   \
	  (b4##UL << 0x4)|(b5##UL << 0x5)|(b6##UL << 0x6)|(b7##UL << 0x7) |   \
	  (b8##UL << 0x8)|(b9##UL << 0x9)|(ba##UL << 0xa)|(bb##UL << 0xb) |   \
	  (bc##UL << 0xc)|(bd##UL << 0xd)|(be##UL << 0xe)|(bf##UL << 0xf))    \
	 << (row % 32))
	/*
	 * Undefined/reserved opcodes, conditional jump, Opcode Extension
	 * Groups, and some special opcodes can not boost.
	 * This is non-const and volatile to keep gcc from statically
	 * optimizing it out, as variable_test_bit makes gcc think only
	 * *(unsigned long*) is used.
	 */
static volatile u32 twobyte_is_boostable[256 / 32] = {
	/*      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f          */
	/*      ----------------------------------------------          */
	W(0x00, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0) | /* 00 */
	W(0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1) , /* 10 */
	W(0x20, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) | /* 20 */
	W(0x30, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) , /* 30 */
	W(0x40, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) | /* 40 */
	W(0x50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) , /* 50 */
	W(0x60, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1) | /* 60 */
	W(0x70, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1) , /* 70 */
	W(0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) | /* 80 */
	W(0x90, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) , /* 90 */
	W(0xa0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1) | /* a0 */
	W(0xb0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1) , /* b0 */
	W(0xc0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1) | /* c0 */
	W(0xd0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1) , /* d0 */
	W(0xe0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1) | /* e0 */
	W(0xf0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0)   /* f0 */
Example #3
0
 /**
  * Evaluate the components of the acceleration due to gravity and the
  * centrifugal acceleration in geocentric coordinates.
  *
  * @param[in] lon the geographic longitude (degrees).
  * @param[out] gX the \e X component of the acceleration
  *   (m s<sup>&minus;2</sup>).
  * @param[out] gY the \e Y component of the acceleration
  *   (m s<sup>&minus;2</sup>).
  * @param[out] gZ the \e Z component of the acceleration
  *   (m s<sup>&minus;2</sup>).
  * @return \e W = \e V + &Phi; the sum of the gravitational and
  *   centrifugal potentials (m<sup>2</sup> s<sup>&minus;2</sup>).
  **********************************************************************/
 Math::real W(real lon, real& gX, real& gY, real& gZ) const {
   real clam, slam;
   CircularEngine::cossin(lon, clam, slam);
   return W(clam, slam, gX, gY, gZ);
 }
Example #4
0
int leap_gesture_equal(leap_gesture_ref gesture, leap_gesture_ref other)
{
    return W(gesture) == W(other);
}
Example #5
0
int do_kneel(string str)
{
    W("No, you don't feel at ease here, and you have no desire to call on " +
      "whatever being it is that is worshipped here.\n");
    return 1;
}
Example #6
0
leap_gesture_state leap_gesture_gesture_state(leap_gesture_ref gesture)
{
    return leap_gesture_state(W(gesture).state());
}
Example #7
0
float leap_gesture_duration_seconds(leap_gesture_ref gesture)
{
    return W(gesture).durationSeconds();
}
Example #8
0
Real Quat::GetPitch() const
{
    return atan2( 2 * ( Y() * Z() + W() * X() ), W() * W() - X() * X() - Y() * Y() + Z() * Z() );
}
Example #9
0
void TestStores2()
{
    B(s10, Stream storage, 0) W(s10a);
    W(s10b);
    W(s10c);
    {
        // s10a is original
        // s10b is a copy, random access
        // s10c is a serialized copy
        c4_StringProp p1 ("p1");
        c4_ViewProp p2 ("p2");
        c4_IntProp p3 ("p3");
        {
            c4_Storage s1 ("s10a", 1);
            s1.SetStructure("a[p1:S,p2[p3:I]]");
            c4_View v1 = s1.View("a");
            v1.Add(p1 ["one"]);
            v1.Add(p1 ["two"]);
            c4_View v2 = p2 (v1[0]);
            v2.Add(p3 [1]);
            v2 = p2 (v1[1]);
            v2.Add(p3 [11]);
            v2.Add(p3 [22]);
            v1.InsertAt(1, p1 ["three"]);
            v2 = p2 (v1[1]);
            v2.Add(p3 [111]);
            v2.Add(p3 [222]);
            v2.Add(p3 [333]);
            s1.Commit();
        }
        {
            c4_Storage s1 ("s10a", 0);
            c4_Storage s2 ("s10b", 1);
            s2.SetStructure("a[p1:S,p2[p3:I]]");
            s2.View("a") = s1.View("a");
            s2.Commit();
        }
        {
            c4_Storage s3 ("s10b", 0);

            c4_FileStream fs1 (fopen("s10c", "wb"), true);
            s3.SaveTo(fs1);
        }
        {
            c4_Storage s1 ("s10c", 0); // new after 2.01: serialized is no longer special

            c4_View v1 = s1.View("a");
            A(v1.GetSize() == 3);
            c4_View v2 = p2 (v1[0]);
            A(v2.GetSize() == 1);
            c4_View v3 = p2 (v1[1]);
            A(v3.GetSize() == 3);
            c4_View v4 = p2 (v1[2]);
            A(v4.GetSize() == 2);
        }
        {
            c4_Storage s1;

            c4_FileStream fs1 (fopen("s10c", "rb"), true);
            s1.LoadFrom(fs1);

            c4_View v1 = s1.View("a");
            A(v1.GetSize() == 3);
            c4_View v2 = p2 (v1[0]);
            A(v2.GetSize() == 1);
            c4_View v3 = p2 (v1[1]);
            A(v3.GetSize() == 3);
            c4_View v4 = p2 (v1[2]);
            A(v4.GetSize() == 2);
        }
        {
            c4_Storage s1 ("s10c", 1);

            c4_View v1 = s1.View("a");
            A(v1.GetSize() == 3);
            c4_View v2 = p2 (v1[0]);
            A(v2.GetSize() == 1);
            c4_View v3 = p2 (v1[1]);
            A(v3.GetSize() == 3);
            c4_View v4 = p2 (v1[2]);
            A(v4.GetSize() == 2);
            v1.Add(p1 ["four"]);
            s1.Commit();
        }
        {
            c4_Storage s1 ("s10c", 0);
            c4_View v1 = s1.View("a");
            A(v1.GetSize() == 4);
            c4_View v2 = p2 (v1[0]);
            A(v2.GetSize() == 1);
            c4_View v3 = p2 (v1[1]);
            A(v3.GetSize() == 3);
            c4_View v4 = p2 (v1[2]);
            A(v4.GetSize() == 2);
            c4_View v5 = p2 (v1[3]);
            A(v5.GetSize() == 0);
        }
    }
    D(s10a);
    D(s10b);
    D(s10c);
    R(s10a);
    R(s10b);
    R(s10c);
    E;

    B(s11, Commit and rollback, 0) W(s11a);
    {
        c4_IntProp p1 ("p1");
        {
            c4_Storage s1 ("s11a", 1);
            s1.SetStructure("a[p1:I]");
            c4_View v1 = s1.View("a");
            v1.Add(p1 [123]);
            s1.Commit();
        }
        {
            c4_Storage s1 ("s11a", 0);
            c4_View v1 = s1.View("a");
            A(v1.GetSize() == 1);
            A(p1 (v1[0]) == 123);
            v1.InsertAt(0, p1 [234]);
            A(v1.GetSize() == 2);
            A(p1 (v1[0]) == 234);
            A(p1 (v1[1]) == 123);
            s1.Rollback();
            // 19990916 - semantics changed, still 2 rows, but 0 props
            A(v1.GetSize() == 2);
            A(v1.NumProperties() == 0);
            v1 = s1.View("a");
            A(v1.GetSize() == 1);
            A(p1 (v1[0]) == 123);
        }
    }
    D(s11a);
    R(s11a);
    E;

    B(s12, Remove subview, 0) W(s12a);
    {
        c4_IntProp p1 ("p1"), p3 ("p3");
        c4_ViewProp p2 ("p2");
        {
            c4_Storage s1 ("s12a", 1);
            s1.SetStructure("a[p1:I,p2[p3:I]]");
            c4_View v1 = s1.View("a");
            c4_View v2;
            v2.Add(p3 [234]);
            v1.Add(p1 [123] + p2 [v2]);
            s1.Commit();
        }
        {
            c4_Storage s1 ("s12a", 1);
            c4_View v1 = s1.View("a");
            A(v1.GetSize() == 1);
            A(p1 (v1[0]) == 123);
            c4_View v2 = p2 (v1[0]);
            A(v2.GetSize() == 1);
            A(p3 (v2[0]) == 234);
            v1.RemoveAt(0);
            A(v1.GetSize() == 0);
            s1.Commit();
            A(v1.GetSize() == 0);
        }
    }
    D(s12a);
    R(s12a);
    E;

    B(s13, Remove middle subview, 0) W(s13a);
    {
        c4_IntProp p1 ("p1"), p3 ("p3");
        c4_ViewProp p2 ("p2");
        {
            c4_Storage s1 ("s13a", 1);
            s1.SetStructure("a[p1:I,p2[p3:I]]");
            c4_View v1 = s1.View("a");

            c4_View v2a;
            v2a.Add(p3 [234]);
            v1.Add(p1 [123] + p2 [v2a]);

            c4_View v2b;
            v2b.Add(p3 [345]);
            v2b.Add(p3 [346]);
            v1.Add(p1 [124] + p2 [v2b]);

            c4_View v2c;
            v2c.Add(p3 [456]);
            v2c.Add(p3 [457]);
            v2c.Add(p3 [458]);
            v1.Add(p1 [125] + p2 [v2c]);

            s1.Commit();
        }
        {
            c4_Storage s1 ("s13a", 1);
            c4_View v1 = s1.View("a");
            A(v1.GetSize() == 3);
            A(p1 (v1[0]) == 123);
            A(p1 (v1[1]) == 124);
            A(p1 (v1[2]) == 125);
            c4_View v2a = p2 (v1[0]);
            A(v2a.GetSize() == 1);
            A(p3 (v2a[0]) == 234);
            c4_View v2b = p2 (v1[1]);
            A(v2b.GetSize() == 2);
            A(p3 (v2b[0]) == 345);
            c4_View v2c = p2 (v1[2]);
            A(v2c.GetSize() == 3);
            A(p3 (v2c[0]) == 456);
            v1.RemoveAt(1);
            A(v1.GetSize() == 2);
            v2a = p2 (v1[0]);
            A(v2a.GetSize() == 1);
            A(p3 (v2a[0]) == 234);
            v2b = p2 (v1[1]);
            A(v2b.GetSize() == 3);
            A(p3 (v2b[0]) == 456);
            s1.Commit();
            A(v1.GetSize() == 2);
            A(p1 (v1[0]) == 123);
            A(p1 (v1[1]) == 125);
        }
    }
    D(s13a);
    R(s13a);
    E;

    B(s14, Replace attached subview, 0) W(s14a);
    {
        c4_IntProp p1 ("p1");
        c4_ViewProp p2 ("p2");
        {
            c4_Storage s1 ("s14a", 1);
            s1.SetStructure("a[p1:I,p2[p3:I]]");
            c4_View v1 = s1.View("a");

            v1.Add(p1 [123] + p2 [c4_View ()]);
            A(v1.GetSize() == 1);

            v1[0] = p2 [c4_View ()];
            A(v1.GetSize() == 1);
            A(p1 (v1[0]) == 0);

            s1.Commit();
        }
    }
    D(s14a);
    R(s14a);
    E;

    B(s15, Add after removed subviews, 0) W(s15a);
    {
        c4_IntProp p1 ("p1"), p3 ("p3");
        c4_ViewProp p2 ("p2");
        {
            c4_Storage s1 ("s15a", 1);
            s1.SetStructure("a[p1:I,p2[p3:I]]");
            c4_View v1 = s1.View("a");

            c4_View v2;
            v2.Add(p3 [234]);

            v1.Add(p1 [123] + p2 [v2]);
            v1.Add(p1 [456] + p2 [v2]);
            v1.Add(p1 [789] + p2 [v2]);
            A(v1.GetSize() == 3);

            v1[0] = v1[2];
            v1.RemoveAt(2);

            v1[0] = v1[1];
            v1.RemoveAt(1);

            v1.RemoveAt(0);

            v1.Add(p1 [111] + p2 [v2]);

            s1.Commit();
        }
    }
    D(s15a);
    R(s15a);
    E;

    B(s16, Add after removed ints, 0) W(s16a);
    {
        c4_IntProp p1 ("p1");

        c4_Storage s1 ("s16a", 1);
        s1.SetStructure("a[p1:I,p2[p3:I]]");
        c4_View v1 = s1.View("a");

        v1.Add(p1 [1]);
        v1.Add(p1 [2]);
        v1.Add(p1 [3]);

        v1.RemoveAt(2);
        v1.RemoveAt(1);
        v1.RemoveAt(0);

        v1.Add(p1 [4]);

        s1.Commit();

    }
    D(s16a);
    R(s16a);
    E;

    B(s17, Add after removed strings, 0) W(s17a);
    {
        c4_StringProp p1 ("p1");

        c4_Storage s1 ("s17a", 1);
        s1.SetStructure("a[p1:S,p2[p3:I]]");
        c4_View v1 = s1.View("a");

        v1.Add(p1 ["one"]);
        v1.Add(p1 ["two"]);
        v1.Add(p1 ["three"]);

        v1.RemoveAt(2);
        v1.RemoveAt(1);
        v1.RemoveAt(0);

        v1.Add(p1 ["four"]);

        s1.Commit();

    }
    D(s17a);
    R(s17a);
    E;

    B(s18, Empty storage, 0) W(s18a);
    {
        c4_Storage s1 ("s18a", 1);

    }
    D(s18a);
    R(s18a);
    E;

    B(s19, Empty view outlives storage, 0) W(s19a);
    {
        c4_View v1;
        c4_Storage s1 ("s19a", 1);
        v1 = s1.GetAs("a[p1:I,p2:S]");

    }
    D(s19a);
    R(s19a);
    E;
}
Example #10
0
Quat Quat::operator-() const
{
    return Quat( W(), -X(), -Y(), -Z() );
}
Example #11
0
Real Quat::GetRoll() const
{
    return atan2( 2 * ( X() * Y() + W() * Z() ), W() * W() + X() * X() - Y() * Y() - Z() * Z() );
}
Example #12
0
/*{{{  gen_list -- generate a clip list*/
static int gen_list(WINDOW *window)
{

  WINDOW *win = window;
  struct rect_list *list = NULL, *prev = (struct rect_list *)0;
  int x_cnt = 2, y_cnt = 2;
  int i, j;
  int count = 0;
  int skip; /* covered by another window - skip patch */
  int hold; /* hold for coalescing */

  /* build arrays of window coordinates: intersecting win's above win */

  x[0] = W(borderwid) + W(x0);
  y[0] = W(borderwid) + W(y0);
  x[1] = W(borderwid) + W(x0) + BIT_WIDE(W(window));
  y[1] = W(borderwid) + W(y0) + BIT_HIGH(W(window));

  for (win = active; win != window; win = W(next)) {
    if (!(in_win(win, x[0], y[0], x[1], y[1])))
      continue;

    if (W(x0) >= x[0] && W(x0) <= x[1])
      x[x_cnt++] = W(x0);

    if (W(y0) >= y[0] && W(y0) <= y[1])
      y[y_cnt++] = W(y0);

    if (W(x0) + BIT_WIDE(W(border)) >= x[0] && W(x0) + BIT_WIDE(W(border)) <= x[1])
      x[x_cnt++] = W(x0) + BIT_WIDE(W(border));

    if (W(y0) + BIT_HIGH(W(border)) >= y[0] && W(y0) + BIT_HIGH(W(border)) <= y[1])
      y[y_cnt++] = W(y0) + BIT_HIGH(W(border));

    if (y_cnt >= MAX_COORDS || x_cnt >= MAX_COORDS)
      break;
  }

  /* sort window coordinate lists */

  qsort(x, x_cnt, sizeof(int), cmp);
  qsort(y, y_cnt, sizeof(int), cmp);

  x_cnt--;
  y_cnt--;

  /* build list of covering rectangles */

  for (j = 0; j < y_cnt; j++) {

    if (y[j] == y[j + 1]) /* avoid zero-height patches */
      continue;

    for (hold = x_cnt, i = 0; i < x_cnt; i++) {

      if (x[i] == x[i + 1]) /* avoid zero-width patches */
        continue;

      /* see if patch is visible */

      for (skip = 0, win = active; win != window; win = W(next))
        if (in_win(win, x[i], y[j], x[i + 1], y[j + 1])) {
          skip++;
          break;
        }

      /* visible, add patch to list, or append to previous patch */

      if (!skip) {
        if (i == hold) { /* coalescing across */
          list->rect.wide += x[i + 1] - x[i];
          hold++;
        } else {   /* flush held rect */
          count++; /* only for debugging */
          list = malloc(sizeof(struct rect_list));
          list->rect.x = x[i] - W(x0);
          list->rect.y = y[j] - W(y0);
          list->rect.wide = x[i + 1] - x[i];
          list->rect.high = y[j + 1] - y[j];
          list->next = NULL;
          if (prev)
            prev->next = list;
          if (!W(clip_list)) /* set initial rectangle */
            W(clip_list) = (char *)list;
          prev = list;
          hold = i + 1; /* next 'i' to check for coalescing */
        }
      }
    }
  }

  /* look at rect list	DEBUG code, commented out!

	for(list=(struct rect_list *) W(clip_list);list;list = list->next) {
		int	x = list->rect.x,
			y = list->rect.y,
			wide = list->rect.wide,
			high = list->rect.high;
		in_mouseoff( x, y, wide, high );
		bit_blit(W(border), x, y, wide, high, BIT_NOT(BIT_DST),0L,0,0);
		dbgprintf('U',(stderr,"  Rect %d,%d  %dx%d\n", x, y, wide, high ));
		getchar();
		bit_blit(W(border), x, y, wide, high, BIT_NOT(BIT_DST),0L,0,0);
		MOUSE_ON(screen,mousex,mousey);
		}
DEBUG code, commented out! */

  dbgprintf('U', (stderr, "%s: Built clip list (%d)\r\n", W(tty), count));

  return (0); /* I'll think of something */
}
Example #13
0
// main function
int main(int argc, const char * argv[])
{
  gettimeofday(&start_timeval_rd1, NULL);
  SparseMatrix<double> Gx_a(NX,NA);
  Gx_a.resize(NX,NA);
  SparseMatrix<double> Gx_b(NX,NB);
  Gx_b.resize(NX,NB);
  SparseMatrix<double> Gx_c(NX,NC);
  Gx_c.resize(NX,NC);
  Gx_a.makeCompressed();
  Gx_b.makeCompressed();
  Gx_c.makeCompressed();
  // reading the partitions
  Gx_a = read_G_sparse((char *) FILE_GA , "GX_A" ,NX, NA);
  Gx_b = read_G_sparse((char *) FILE_GB , "GX_B" ,NX, NB);
  Gx_c = read_G_sparse((char *) FILE_GC , "GX_C" ,NX, NC);

  gettimeofday(&stop_timeval_rd1, NULL);
  measure_stop_rd1 = stop_timeval_rd1.tv_usec + (timestamp_t)stop_timeval_rd1.tv_sec * 1000000;
  measure_start_rd1 = start_timeval_rd1.tv_usec + (timestamp_t)start_timeval_rd1.tv_sec * 1000000;
  time_rd1 = (measure_stop_rd1 - measure_start_rd1) / 1000000.0L;
  printf("Exec Time reading matrices before preproc = %5.25e (Seconds)\n",time_rd1);
  
  // initialize W, Z_B,Z_C, mu_a, mu_b, mu_c;
  SparseMatrix<double> W(NA,KHID); W.resize(NA,KHID); W.makeCompressed();
  SparseMatrix<double> Z_B(NA,NB); Z_B.resize(NA,NB); Z_B.makeCompressed();
  SparseMatrix<double> Z_C(NA,NC); Z_C.resize(NA,NC); Z_C.makeCompressed();
  VectorXd mu_a(NA);
  VectorXd mu_b(NB); 
  VectorXd mu_c(NC);
  
  cout << "----------------------------Before whitening--------------------------" << endl;
  gettimeofday(&start_timeval_pre, NULL);  // measuring start time for pre processing
  second_whiten(Gx_a,Gx_b,Gx_c,W,Z_B,Z_C,mu_a,mu_b,mu_c);
  // whitened datapoints
  SparseMatrix<double> Data_a_G = W.transpose() * Gx_a.transpose();
  VectorXd Data_a_mu  = W.transpose() * mu_a;
  SparseMatrix<double> Data_b_G = W.transpose() * Z_B * Gx_b.transpose();
  VectorXd Data_b_mu  = W.transpose() * Z_B * mu_b;
  SparseMatrix<double> Data_c_G = W.transpose() * Z_C * Gx_c.transpose();
  VectorXd Data_c_mu  = W.transpose() * Z_C * mu_c;
  gettimeofday(&stop_timeval_pre, NULL);   // measuring stop time for pre processing
  
  measure_stop_pre = stop_timeval_pre.tv_usec + (timestamp_t)stop_timeval_pre.tv_sec * 1000000;
  measure_start_pre = start_timeval_pre.tv_usec + (timestamp_t)start_timeval_pre.tv_sec * 1000000;
  time_pre = (measure_stop_pre - measure_start_pre) / 1000000.0L;
  printf("time taken by preprocessing = %5.25e (Seconds)\n",time_pre);
    
  cout << "----------------------------After whitening---------------------------" << endl;
  // stochastic updates
  VectorXd lambda(KHID); 
  MatrixXd phi_new(KHID,KHID);
  cout << "------------------------------Before tensor decomposition----------------" << endl;
  gettimeofday(&start_timeval_stpm, NULL); // measuring start time for stochastic updates
  tensorDecom_alpha0(Data_a_G,Data_a_mu,Data_b_G,Data_b_mu,Data_c_G,Data_c_mu,lambda,phi_new);
  gettimeofday(&stop_timeval_stpm, NULL);  // measuring stop time for stochastic updates
  cout << "after tensor decomposition" << endl;
  measure_stop_stpm = stop_timeval_stpm.tv_usec + (timestamp_t)stop_timeval_stpm.tv_sec * 1000000;
  measure_start_stpm = start_timeval_stpm.tv_usec + (timestamp_t)start_timeval_stpm.tv_sec * 1000000;
  time_stpm = (measure_stop_stpm - measure_start_stpm) / 1000000.0L;
  cout << "------------------------------After tensor decomposition----------------" << endl;  
  printf("time taken by stochastic tensor decomposition = %5.25e (Seconds)\n",time_stpm);
  
  //cout <<  phi_new << endl; // optionally print eigenvectors
  cout << "the eigenvalues are:" << endl;
  cout << lambda << endl;
  
  
  // post processing
  cout << "------------Reading Gb_a, Gc_a---------"<<endl;
  gettimeofday(&start_timeval_rd2, NULL);
#ifdef CalErrALL
  // read the matrix Gab and Gac
  SparseMatrix<double> Gb_a(NB,NA);Gb_a.resize(NB,NA);
  SparseMatrix<double> Gc_a(NC,NA);Gc_a.resize(NC,NA);
  Gb_a = read_G_sparse((char *) FILE_Gb_a, "GB_A" ,NB, NA); Gb_a.makeCompressed();
  Gc_a = read_G_sparse((char *) FILE_Gc_a ,"GC_A" ,NC, NA); Gc_a.makeCompressed();
    // releasing memory of Gx_a, Gx_b, Gx_c;
    Gx_b.resize(0,0);Gx_c.resize(0,0);
#endif
  MatrixXd Inv_Lambda = (pinv_vector(lambda)).asDiagonal();
  SparseMatrix<double> inv_lam_phi = (Inv_Lambda.transpose() * phi_new.transpose()).sparseView();
    
  gettimeofday(&stop_timeval_rd2, NULL);
  measure_stop_rd2 = stop_timeval_rd2.tv_usec + (timestamp_t)stop_timeval_rd2.tv_sec * 1000000;
  measure_start_rd2 = start_timeval_rd2.tv_usec + (timestamp_t)start_timeval_rd2.tv_sec * 1000000;
  time_rd2 = (measure_stop_rd2 - measure_start_rd2) / 1000000.0L;
  cout << "------------After reading Gb_a, Gc_a---------"<<endl;
  printf("time taken for reading matrices after post processing = %5.25e (Seconds)\n",time_rd2);
  
  
  
  cout << "---------------------------Computing pi matrices-----------------------------" << endl;
  gettimeofday(&start_timeval_post, NULL);  // measuring start time for post processing
  
  SparseMatrix<double> pi_x(KHID,NX);pi_x.reserve(KHID*NX);pi_x.makeCompressed();
  SparseMatrix<double> pi_x_tmp1 = inv_lam_phi * W.transpose();
    
#ifdef CalErrALL
  SparseMatrix<double> pi_a(KHID,NA);pi_a.reserve(KHID*NA);pi_a.makeCompressed();
  SparseMatrix<double> pi_b(KHID,NB);pi_b.reserve(KHID*NB);pi_b.makeCompressed();
  SparseMatrix<double> pi_c(KHID,NC);pi_c.reserve(KHID*NC);pi_c.makeCompressed();
  
  pi_a = pi_x_tmp1 * Z_B * Gb_a;
  MatrixXd pi_a_full = (MatrixXd) pi_a;pi_a.resize(0,0);
    
  pi_b = pi_x_tmp1 * Gb_a.transpose();
  MatrixXd pi_b_full = (MatrixXd) pi_b;pi_b.resize(0,0);
    
  pi_c = pi_x_tmp1 * Gc_a.transpose();
  MatrixXd pi_c_full = (MatrixXd) pi_c;pi_c.resize(0,0);
#endif
    
  pi_x =pi_x_tmp1 * Gx_a.transpose();Gx_a.resize(0,0);
  MatrixXd pi_x_full = (MatrixXd) pi_x;pi_x.resize(0,0);
  gettimeofday(&stop_timeval_post, NULL);  // measuring stop time for post processing
  measure_stop_post = stop_timeval_post.tv_usec + (timestamp_t)stop_timeval_post.tv_sec * 1000000;
  measure_start_post = start_timeval_post.tv_usec + (timestamp_t)start_timeval_post.tv_sec * 1000000;
  time_post = (measure_stop_post - measure_start_post) / 1000000.0L;
  cout << "---------After post processing------------" << endl;
  printf("time taken for post processing = %5.25e (Seconds)\n",time_post);
  cout<<"-------------------------Concatenation for pi_est-------------------- "<< endl;
  
  // store true_pi
#ifdef CalErrALL
  long PI_LEN =(long) NX+NA+NB+NC;
#else
    long PI_LEN =(long) NX;
#endif
    
  MatrixXd My_pi_true_mat(KTRUE,PI_LEN);
  MatrixXd My_pi_est_mat(KHID,PI_LEN);
#ifdef CalErrALL
  for (int kk = 0; kk < KHID; kk++)
  {
    // for My_pi_est;
    VectorXd My_pi_est1(NX+NA);
    My_pi_est1 = concatenation_vector (pi_x_full.row(kk), pi_a_full.row(kk));
    VectorXd My_pi_est2(NX+NA+NB);
    My_pi_est2 =concatenation_vector (My_pi_est1, pi_b_full.row(kk));
    VectorXd My_pi_est3(NX+NA+NB+NC);
    My_pi_est3 =concatenation_vector (My_pi_est2, pi_c_full.row(kk));
    My_pi_est_mat.row(kk) = My_pi_est3;
  }
    pi_a_full.resize(0,0);
    pi_b_full.resize(0,0);
    pi_c_full.resize(0,0);
#else
    My_pi_est_mat =pi_x_full;
#endif
    pi_x_full.resize(0,0);
  
  // converting them to stochastic matrix
  My_pi_est_mat = normProbMatrix(My_pi_est_mat);
  SparseMatrix<double> sparse_my_pi_est_mat = My_pi_est_mat.sparseView();

  cout << "-----------Before writing results: W, Z_B,Z_C and pi-----------"<<endl;
  write_pi(FILE_PI_WRITE, sparse_my_pi_est_mat);
  write_pi(FILE_WHITE_WRITE, W);
  write_pi(FILE_INVLAMPHI_WRITE, inv_lam_phi);
  cout << "-----------After writing results---------"<< endl;
  
#ifdef ErrCal // set error calculation flag if it needs to be computed
  cout << "--------------------------------Calculating error------------------------------" << endl;
  gettimeofday(&start_timeval_error, NULL);  // measuring start time for error calculation
#ifdef CalErrALL
  // calculate error
  Gb_a.resize(0,0); Gc_a.resize(0,0);
  // read pi_true, i.e., ground truth matrices
  SparseMatrix<double> Pi_true_a(KTRUE,NA);Pi_true_a.makeCompressed();Pi_true_a = read_G_sparse((char *) FILE_Pi_a , "Pi_true_A" ,KTRUE, NA);
  MatrixXd Pi_true_a_full = (MatrixXd) Pi_true_a;  Pi_true_a.resize(0,0);
  SparseMatrix<double> Pi_true_b(KTRUE,NB);Pi_true_b.makeCompressed();Pi_true_b = read_G_sparse((char *) FILE_Pi_b , "Pi_true_B" ,KTRUE, NB);
  MatrixXd Pi_true_b_full = (MatrixXd) Pi_true_b;  Pi_true_b.resize(0,0);
  SparseMatrix<double> Pi_true_c(KTRUE,NC);Pi_true_c.makeCompressed();Pi_true_c = read_G_sparse((char *) FILE_Pi_c , "Pi_true_C" ,KTRUE, NC);
  MatrixXd Pi_true_c_full = (MatrixXd) Pi_true_c;  Pi_true_c.resize(0,0);
#endif
  SparseMatrix<double> Pi_true_x(KTRUE,NX);Pi_true_x.makeCompressed();Pi_true_x = read_G_sparse((char *) FILE_Pi_x , "Pi_true_X" ,KTRUE, NX);
  MatrixXd Pi_true_x_full = (MatrixXd) Pi_true_x;  Pi_true_x.resize(0,0);
  
  /*
  // this is only for yelp, comment this for DBLP
  long PI_LEN = (long)NX;
  MatrixXd My_pi_true_mat(KTRUE,PI_LEN);
  My_pi_true_mat =  Pi_true_x_full;
  MatrixXd My_pi_est_mat(KHID,PI_LEN); 
  My_pi_est_mat = pi_x_full;
  */    
  
  cout<<"-------------------------Concatenation for pi_true-------------------- "<< endl;
#ifdef CalErrALL
  for ( int k = 0; k < KTRUE; k++)
  {
    // for My_pi_true;
    VectorXd My_pi_true1(NX+NA);
    My_pi_true1 = concatenation_vector ((Pi_true_x_full.row(k)),(Pi_true_a_full.row(k)));
    VectorXd My_pi_true2(NX+NA+NB);
    My_pi_true2 =concatenation_vector (My_pi_true1, (Pi_true_b_full.row(k)));
    VectorXd My_pi_true3(NX+NA+NB+NC);
    My_pi_true3 =concatenation_vector (My_pi_true2, (Pi_true_c_full.row(k)));
    My_pi_true_mat.row(k) = My_pi_true3;
  } 
  Pi_true_a_full.resize(0,0);
  Pi_true_b_full.resize(0,0);
  Pi_true_c_full.resize(0,0);
#else
    My_pi_true_mat = Pi_true_x_full;
#endif
  Pi_true_x_full.resize(0,0);
    
    
    double thresh_vec[NUM_THRESH] = thresh_vec_def;
    //{0.3, 0.25, 0.2, 0.18, 0.15, 0.12, 0.1,0.08};
  double error_vec[NUM_THRESH] = {0.0};
  double match_vec[NUM_THRESH] = {0.0};
  
  for (int tttt = 0; tttt < NUM_THRESH; tttt++)
  {
    MatrixXd p_values=MatrixXd::Zero(KTRUE,KHID);
    MatrixXd errors=MatrixXd::Zero(KTRUE,KHID);	  
    for ( int k = 0; k < KTRUE; k++)
    {
      VectorXd my_pi_true_eigen = My_pi_true_mat.row(k);
      double *my_pi_true = my_pi_true_eigen.data();
      for (int kk = 0; kk < KHID; kk++)
      {
	VectorXd my_pi_est_eigen = My_pi_est_mat.row(kk);
	double *my_pi_est = my_pi_est_eigen.data();
	
	for(long lltt = 0; lltt < PI_LEN; lltt++)
	{
	  if(my_pi_est[lltt] < thresh_vec[tttt])
	    my_pi_est[lltt] = 0;
	  else
	    my_pi_est[lltt] = 1;
	}
	// calculate p-values and error
	double correlation = Calculate_Correlation(my_pi_est, my_pi_true, (long)PI_LEN); //{long}
	if (correlation > 0)
	{
	  p_values(k,kk)=Calculate_Pvalue(my_pi_true, my_pi_est, (long)PI_LEN); //{long}
	  if (p_values(k,kk) < PVALUE_TOLE)
	  {
	    errors(k,kk)=(my_pi_true_eigen - my_pi_est_eigen).cwiseAbs().sum();
	  }
	  else
	  {
	    errors(k,kk)=0;
	  }
	}
	else
	{
	  p_values(k,kk)=-1;
	  errors(k,kk)=0;
	}
      }
    }
    VectorXd matched = errors.rowwise().sum();
    double nnz =0;
    for(long calc=0; calc <KTRUE; calc++)
    {
      if(matched(calc)>0)
	nnz++;
    }
    error_vec[tttt]=(double)errors.sum()/((double)PI_LEN*KTRUE);
    match_vec[tttt]=((double)nnz)/((double)KTRUE);
  }
  gettimeofday(&stop_timeval_error, NULL);  // measuring stop time for error calculation
  measure_stop_error = stop_timeval_error.tv_usec + (timestamp_t)stop_timeval_error.tv_sec * 1000000;
  measure_start_error = start_timeval_error.tv_usec + (timestamp_t)start_timeval_error.tv_sec * 1000000;
  time_error = (measure_stop_error - measure_start_error) / 1000000.0L;
  cout << "---------After error calculation------------"<<endl;
  printf("time taken for error calculation = %5.25e (Seconds)\n",time_error);
  
  furongprintVector(thresh_vec, NUM_THRESH, "thresh vector "); // outputs are printed
  furongprintVector(error_vec, NUM_THRESH, "error vector ");
  furongprintVector(match_vec, NUM_THRESH, "match vector ");
#endif
  cout << "Program over" << endl;    
  printf("\ntime taken for execution of the whole program = %5.25e (Seconds)\n", time_rd1 + time_pre + time_stpm + time_rd2 + time_post);
  return 0;
}
void Reconstruction3D::computeP(const std::vector<std::pair<Eigen::Vector2d, Eigen::Vector2d>>& points,
								const Eigen::MatrixXd& E, 
								std::vector<Eigen::MatrixXd>& P_solutions)
{
	P_solutions.clear();

	Eigen::JacobiSVD< Eigen::MatrixXd, Eigen::FullPivHouseholderQRPreconditioner > svd(E, Eigen::ComputeFullU | Eigen::ComputeFullV);
	Eigen::MatrixXd U = svd.matrixU();
	Eigen::MatrixXd Vt = svd.matrixV().transpose();


	Eigen::MatrixXd W(3, 3);
	W << 0.0, -1.0, 0.0,
		1.0, 0.0, 0.0,
		0.0, 0.0, 1.0;
	
	
	Eigen::VectorXd u3 = U.col(2);

	//std::cout << "--- Computing P Matrix: " << std::endl
	//	<< "E: " << std::endl << E << std::endl << std::endl
	//	<< "U: " << std::endl << U << std::endl << std::endl
	//	<< "D: " << std::endl << svd.singularValues() << std::endl << std::endl
	//	<< "Vt: " << std::endl << Vt << std::endl << std::endl
	//	<< "W: " << std::endl << W << std::endl << std::endl
	//	<< "u3 :" << u3 << std::endl << std::endl;

	Eigen::MatrixXd P0(Eigen::MatrixXd::Identity(3, 4)); // Just K0: no translation or rotation.
	Eigen::MatrixXd UWVt = U * W * Vt; // P without translation part.

	Eigen::MatrixXd P1(3, 4);
	P1.block(0, 0, 3, 3) = UWVt;
	P1.block(0, 3, 3, 1) = u3;

	Eigen::MatrixXd bestP1;
	int numCorrectSolutions = 0;
	if (checkP(points, P0, P1))
	{
		++numCorrectSolutions;
		bestP1 = P1;

		std::cout << std::endl << "[Info]  Best solution for P: 1st" << std::endl << std::endl;
	}
	P_solutions.push_back(P1);

	P1.block(0, 3, 3, 1) = -u3;

	if (checkP(points, P0, P1))
	{
		++numCorrectSolutions;
		bestP1 = P1;
		std::cout << std::endl << "[Info]  Best solution for P: 2nd" << std::endl << std::endl;
	}
	P_solutions.push_back(P1);

	UWVt = U * W.transpose() * Vt;
	P1.block(0, 0, 3, 3) = UWVt;
	P1.block(0, 3, 3, 1) = u3;


	if (checkP(points, P0, P1))
	{
		++numCorrectSolutions;
		bestP1 = P1;
		std::cout << std::endl << "[Info]  Best solution for P: 3rd" << std::endl << std::endl;
	}
	P_solutions.push_back(P1);

	P1.block(0, 3, 3, 1) = -u3;


	if (checkP(points, P0, P1))
	{
		++numCorrectSolutions;
		bestP1 = P1;
		std::cout << std::endl << "[Info]  Best solution for P: 4th" << std::endl << std::endl;
	}
	P_solutions.push_back(P1);

	std::cout << "[Info]  Number of correct solutions: " << numCorrectSolutions << std::endl << std::endl;

}
Example #15
0
int32_t leap_gesture_id(leap_gesture_ref gesture)
{
    return W(gesture).id();
}
Example #16
0
static int16 SW(t_value arg1, t_value arg2)
{
  return W(arg1,arg2);
}
Example #17
0
leap_gesture_type leap_gesture_gesture_type(leap_gesture_ref gesture)
{
    return leap_gesture_type(W(gesture).type());
}
Example #18
0
t_stat fprint_sym_m (FILE *of, t_addr addr, t_value *val,
    UNIT *uptr, int32 sw)
{
  uint16 op, arg1, arg2, arg3;
  int16 sarg;
  t_stat size = 0;
  int optype, sz;
  t_bool hexdec = (sw & SWMASK('H')) ? TRUE : FALSE;
  addr = ADDR_OFF(addr);

  op = val[0];
  if (op > 0xe7) return SCPE_ARG;

  optype = optable[op].flags;
  if (optype > OP_ERROR) {
    fprintf(of,"%-8s", optable[op].name);
    switch (optype) {
    case OP_NULL:
      break;
    case OP_UB:
      size = 1; arg1 = UB(val[1]);
      print_hd(of, arg1, hexdec, FALSE);
      break;
    case OP_W:
      size = 2; sarg = W(val[1],val[2]);
      print_hd(of, sarg, hexdec, FALSE);
      break;
    case OP_AB:
      arg1 = B(val[1],val[2], &sz); size = sz;
      fprintf(of,"#%x", arg1*2);
      break;
    case OP_B:
      arg1 = B(val[1],val[2], &sz); size = sz;
      print_hd(of, arg1, hexdec, FALSE);
      break;
    case OP_DBB:
      arg1 = DB(val[1]);
      arg2 = B(val[2],val[3], &sz); size = sz+1;
      print_hd(of, arg1, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg2, hexdec, FALSE);
      break;
    case OP_UBB:
      arg1 = UB(val[1]);
      arg2 = B(val[2],val[3], &sz); size = sz+1;
      print_hd(of, arg1, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg2, hexdec, FALSE);
      break;
    case OP_BUB:
      arg1 = B(val[1],val[2], &sz); size = sz+1;
      arg2 = UB(val[sz+1]);
      print_hd(of, arg1, hexdec, FALSE); fputc(',',of); 
      print_hd(of, arg2, hexdec, TRUE);
      break;
    case OP_SB:
      size = 1; sarg = SB(val[1]);
      fprintf(of,"#%x", addr+sarg+2);
      break;
    case OP_SW:
      size = 2; sarg = SW(val[1],val[2]);
      fprintf(of,"#%x", addr+sarg+3);
      break;
    case OP_DBUB:
      size = 2; arg1 = DB(val[1]);
      arg2 = UB(val[2]);
      print_hd(of, arg1, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg2, hexdec, TRUE);
      break;
    case OP_UBUB:
      size = 2; arg1 = UB(val[1]);
      arg2 = UB(val[2]);
      print_hd(of, arg1, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg2, hexdec, TRUE);
      break;
    case OP_UBDBUB:
      size  = 3; arg1 = UB(val[1]);
      arg2 = DB(val[2]);
      arg3 = UB(val[3]);
      print_hd(of, arg1, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg2, hexdec, TRUE); fputc(',',of); 
      print_hd(of, arg3, hexdec, TRUE);
      break;
    case OP_DB:
      size = 1; arg1 = DB(val[1]);
      print_hd(of, arg1, hexdec, TRUE);
      break;
    }
    return -size;
  } else {
    fprintf(of,"%-8s","DB"); print_hd(of, op, hexdec, TRUE);
    return SCPE_OK;
  }
}
Example #19
0
int64_t leap_gesture_duration(leap_gesture_ref gesture)
{
    return W(gesture).duration();
}
Example #20
0
	
};

#endif /* ICONV_TO_UCS_CCS_WIN_1252 */

/*
 * 8-bit UCS -> win_1252 speed-optimized table (1794 bytes).
 * ======================================================================
 */

#if defined (ICONV_FROM_UCS_CCS_WIN_1252)

static _CONST unsigned char
from_ucs_speed_win_1252[] =
{
	W(0x00FF), /* Real 0xFF mapping. 0xFF is used to mark invalid codes */
	/* Heading Block */
	W(0x0202),W(0x0302),W(0x0402),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(0x0502),W(0x0602),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
	W(INVBLK),W(INVBLK),W(INVBLK),W(INVBLK),
Example #21
0
int leap_gesture_is_valid(leap_gesture_ref gesture)
{
    return W(gesture).isValid();
}
Example #22
0
// https://github.com/KubaO/stackoverflown/tree/master/questions/32484688
#include <iostream>

template <typename T, int N> static char * W__(const char (&src)[N], T) {
   static char storage[N];
   strcpy(storage, src);
   return storage;
}

#define W(x) W__(x, []{})

char * argv[] = {
   W("foo"),
   W("bar")
};

int main()
{
   std::cout << argv[0] << " " << argv[1] << std::endl;
}

Example #23
0
/**
    Purpose
    -------
    SLATRD reduces NB rows and columns of a real symmetric matrix A to
    symmetric tridiagonal form by an orthogonal similarity
    transformation Q' * A * Q, and returns the matrices V and W which are
    needed to apply the transformation to the unreduced part of A.

    If UPLO = MagmaUpper, SLATRD reduces the last NB rows and columns of a
    matrix, of which the upper triangle is supplied;
    if UPLO = MagmaLower, SLATRD reduces the first NB rows and columns of a
    matrix, of which the lower triangle is supplied.

    This is an auxiliary routine called by SSYTRD.

    Arguments
    ---------
    @param[in]
    uplo    magma_uplo_t
            Specifies whether the upper or lower triangular part of the
            symmetric matrix A is stored:
      -     = MagmaUpper: Upper triangular
      -     = MagmaLower: Lower triangular

    @param[in]
    n       INTEGER
            The order of the matrix A.

    @param[in]
    nb      INTEGER
            The number of rows and columns to be reduced.

    @param[in,out]
    A       REAL array, dimension (LDA,N)
            On entry, the symmetric matrix A.  If UPLO = MagmaUpper, the leading
            n-by-n upper triangular part of A contains the upper
            triangular part of the matrix A, and the strictly lower
            triangular part of A is not referenced.  If UPLO = MagmaLower, the
            leading n-by-n lower triangular part of A contains the lower
            triangular part of the matrix A, and the strictly upper
            triangular part of A is not referenced.
            On exit:
      -     if UPLO = MagmaUpper, the last NB columns have been reduced to
              tridiagonal form, with the diagonal elements overwriting
              the diagonal elements of A; the elements above the diagonal
              with the array TAU, represent the orthogonal matrix Q as a
              product of elementary reflectors;
      -     if UPLO = MagmaLower, the first NB columns have been reduced to
              tridiagonal form, with the diagonal elements overwriting
              the diagonal elements of A; the elements below the diagonal
              with the array TAU, represent the  orthogonal matrix Q as a
              product of elementary reflectors.
            See Further Details.

    @param[in]
    lda     INTEGER
            The leading dimension of the array A.  LDA >= (1,N).

    @param[out]
    e       REAL array, dimension (N-1)
            If UPLO = MagmaUpper, E(n-nb:n-1) contains the superdiagonal
            elements of the last NB columns of the reduced matrix;
            if UPLO = MagmaLower, E(1:nb) contains the subdiagonal elements of
            the first NB columns of the reduced matrix.

    @param[out]
    tau     REAL array, dimension (N-1)
            The scalar factors of the elementary reflectors, stored in
            TAU(n-nb:n-1) if UPLO = MagmaUpper, and in TAU(1:nb) if UPLO = MagmaLower.
            See Further Details.

    @param[out]
    W       REAL array, dimension (LDW,NB)
            The n-by-nb matrix W required to update the unreduced part
            of A.

    @param[in]
    ldw     INTEGER
            The leading dimension of the array W. LDW >= max(1,N).

    Further Details
    ---------------
    If UPLO = MagmaUpper, the matrix Q is represented as a product of elementary
    reflectors

       Q = H(n) H(n-1) . . . H(n-nb+1).

    Each H(i) has the form

       H(i) = I - tau * v * v'

    where tau is a real scalar, and v is a real vector with
    v(i:n) = 0 and v(i-1) = 1; v(1:i-1) is stored on exit in A(1:i-1,i),
    and tau in TAU(i-1).

    If UPLO = MagmaLower, the matrix Q is represented as a product of elementary
    reflectors

       Q = H(1) H(2) . . . H(nb).

    Each H(i) has the form

       H(i) = I - tau * v * v'

    where tau is a real scalar, and v is a real vector with
    v(1:i) = 0 and v(i+1) = 1; v(i+1:n) is stored on exit in A(i+1:n,i),
    and tau in TAU(i).

    The elements of the vectors v together form the n-by-nb matrix V
    which is needed, with W, to apply the transformation to the unreduced
    part of the matrix, using a symmetric rank-2k update of the form:
    A := A - V*W' - W*V'.

    The contents of A on exit are illustrated by the following examples
    with n = 5 and nb = 2:

    if UPLO = MagmaUpper:                       if UPLO = MagmaLower:

      (  a   a   a   v4  v5 )              (  d                  )
      (      a   a   v4  v5 )              (  1   d              )
      (          a   1   v5 )              (  v1  1   a          )
      (              d   1  )              (  v1  v2  a   a      )
      (                  d  )              (  v1  v2  a   a   a  )

    where d denotes a diagonal element of the reduced matrix, a denotes
    an element of the original matrix that is unchanged, and vi denotes
    an element of the vector defining H(i).

    @ingroup magma_ssyev_aux
    ********************************************************************/
extern "C" magma_int_t
magma_slatrd(magma_uplo_t uplo, magma_int_t n, magma_int_t nb,
             float *A,  magma_int_t lda,
             float *e, float *tau,
             float *W,  magma_int_t ldw,
             float *dA, magma_int_t ldda,
             float *dW, magma_int_t lddw)
{
#define A(i, j) (A + (j)*lda + (i))
#define W(i, j) (W + (j)*ldw + (i))

#define dA(i, j) (dA + (j)*ldda + (i))
#define dW(i, j) (dW + (j)*lddw + (i))

    magma_int_t i;
    
    float c_neg_one = MAGMA_S_NEG_ONE;
    float c_one     = MAGMA_S_ONE;
    float c_zero    = MAGMA_S_ZERO;

    float value = MAGMA_S_ZERO;
    
    magma_int_t ione = 1;

    magma_int_t i_n, i_1, iw;
    
    float alpha;
    float *f;

    if (n <= 0) {
        return 0;
    }

    magma_queue_t stream;
    magma_queue_create( &stream );
    magma_smalloc_cpu( &f, n );
    assert( f != NULL );  // TODO return error, or allocate outside slatrd

    if (uplo == MagmaUpper) {
        /* Reduce last NB columns of upper triangle */
        for (i = n-1; i >= n - nb; --i) {
            i_1 = i + 1;
            i_n = n - i - 1;
            
            iw = i - n + nb;
            if (i < n-1) {
                /* Update A(1:i,i) */
                #if defined(PRECISION_z) || defined(PRECISION_c)
                lapackf77_slacgv(&i_n, W(i, iw+1), &ldw);
                #endif
                blasf77_sgemv("No transpose", &i_1, &i_n, &c_neg_one, A(0, i+1), &lda,
                              W(i, iw+1), &ldw, &c_one, A(0, i), &ione);
                #if defined(PRECISION_z) || defined(PRECISION_c)
                lapackf77_slacgv(&i_n, W(i, iw+1), &ldw);
                lapackf77_slacgv(&i_n, A(i, i+1), &lda);
                #endif
                blasf77_sgemv("No transpose", &i_1, &i_n, &c_neg_one, W(0, iw+1), &ldw,
                              A(i, i+1), &lda, &c_one, A(0, i), &ione);
                #if defined(PRECISION_z) || defined(PRECISION_c)
                lapackf77_slacgv(&i_n, A(i, i+1), &lda);
                #endif
            }
            if (i > 0) {
                /* Generate elementary reflector H(i) to annihilate A(1:i-2,i) */
                alpha = *A(i-1, i);
                
                lapackf77_slarfg(&i, &alpha, A(0, i), &ione, &tau[i - 1]);
                
                e[i-1] = MAGMA_S_REAL( alpha );
                *A(i-1,i) = MAGMA_S_ONE;
                
                /* Compute W(1:i-1,i) */
                // 1. Send the block reflector  A(0:n-i-1,i) to the GPU
                magma_ssetvector( i, A(0, i), 1, dA(0, i), 1 );
                
                magma_ssymv(MagmaUpper, i, c_one, dA(0, 0), ldda,
                            dA(0, i), ione, c_zero, dW(0, iw), ione);
                
                // 2. Start putting the result back (asynchronously)
                magma_sgetmatrix_async( i, 1,
                                        dW(0, iw),         lddw,
                                        W(0, iw) /*test*/, ldw, stream );
                
                if (i < n-1) {
                    blasf77_sgemv(MagmaTransStr, &i, &i_n, &c_one, W(0, iw+1), &ldw,
                                  A(0, i), &ione, &c_zero, W(i+1, iw), &ione);
                }
                
                // 3. Here is where we need it // TODO find the right place
                magma_queue_sync( stream );
                
                if (i < n-1) {
                    blasf77_sgemv("No transpose", &i, &i_n, &c_neg_one, A(0, i+1), &lda,
                                  W(i+1, iw), &ione, &c_one, W(0, iw), &ione);
                    
                    blasf77_sgemv(MagmaTransStr, &i, &i_n, &c_one, A(0, i+1), &lda,
                                  A(0, i), &ione, &c_zero, W(i+1, iw), &ione);
                    
                    blasf77_sgemv("No transpose", &i, &i_n, &c_neg_one, W(0, iw+1), &ldw,
                                  W(i+1, iw), &ione, &c_one, W(0, iw), &ione);
                }
                
                blasf77_sscal(&i, &tau[i - 1], W(0, iw), &ione);
                
                #if defined(PRECISION_z) || defined(PRECISION_c)
                cblas_sdot_sub( i, W(0,iw), ione, A(0,i), ione, &value );
                #else
                value = cblas_sdot( i, W(0,iw), ione, A(0,i), ione );
                #endif
                alpha = tau[i - 1] * -0.5f * value;
                blasf77_saxpy(&i, &alpha, A(0, i), &ione,
                              W(0, iw), &ione);
            }
        }
    }
    else {
        /*  Reduce first NB columns of lower triangle */
        for (i = 0; i < nb; ++i) {
            /* Update A(i:n,i) */
            i_n = n - i;
            #if defined(PRECISION_z) || defined(PRECISION_c)
            lapackf77_slacgv(&i, W(i, 0), &ldw);
            #endif
            blasf77_sgemv("No transpose", &i_n, &i, &c_neg_one, A(i, 0), &lda,
                          W(i, 0), &ldw, &c_one, A(i, i), &ione);
            #if defined(PRECISION_z) || defined(PRECISION_c)
            lapackf77_slacgv(&i, W(i, 0), &ldw);
            lapackf77_slacgv(&i, A(i, 0), &lda);
            #endif
            blasf77_sgemv("No transpose", &i_n, &i, &c_neg_one, W(i, 0), &ldw,
                          A(i, 0), &lda, &c_one, A(i, i), &ione);
            #if defined(PRECISION_z) || defined(PRECISION_c)
            lapackf77_slacgv(&i, A(i, 0), &lda);
            #endif
        
            if (i < n-1) {
                /* Generate elementary reflector H(i) to annihilate A(i+2:n,i) */
                i_n = n - i - 1;
                alpha = *A(i+1, i);
                lapackf77_slarfg(&i_n, &alpha, A(min(i+2,n-1), i), &ione, &tau[i]);
                e[i] = MAGMA_S_REAL( alpha );
                *A(i+1,i) = MAGMA_S_ONE;
        
                /* Compute W(i+1:n,i) */
                // 1. Send the block reflector  A(i+1:n,i) to the GPU
                magma_ssetvector( i_n, A(i+1, i), 1, dA(i+1, i), 1 );
            
                magma_ssymv(MagmaLower, i_n, c_one, dA(i+1, i+1), ldda, dA(i+1, i), ione, c_zero,
                            dW(i+1, i), ione);
            
                // 2. Start putting the result back (asynchronously)
                magma_sgetmatrix_async( i_n, 1,
                                        dW(i+1, i), lddw,
                                        W(i+1, i),  ldw, stream );
        
                blasf77_sgemv(MagmaTransStr, &i_n, &i, &c_one, W(i+1, 0), &ldw,
                              A(i+1, i), &ione, &c_zero, W(0, i), &ione);
        
                blasf77_sgemv("No transpose", &i_n, &i, &c_neg_one, A(i+1, 0), &lda,
                              W(0, i), &ione, &c_zero, f, &ione);
                
                blasf77_sgemv(MagmaTransStr, &i_n, &i, &c_one, A(i+1, 0), &lda,
                              A(i+1, i), &ione, &c_zero, W(0, i), &ione);
        
                // 3. Here is where we need it
                magma_queue_sync( stream );
        
                if (i != 0)
                    blasf77_saxpy(&i_n, &c_one, f, &ione, W(i+1, i), &ione);
        
                blasf77_sgemv("No transpose", &i_n, &i, &c_neg_one, W(i+1, 0), &ldw,
                              W(0, i), &ione, &c_one, W(i+1, i), &ione);
                blasf77_sscal(&i_n, &tau[i], W(i+1,i), &ione);
                
                #if defined(PRECISION_z) || defined(PRECISION_c)
                cblas_sdot_sub( i_n, W(i+1,i), ione, A(i+1,i), ione, &value );
                #else
                value = cblas_sdot( i_n, W(i+1,i), ione, A(i+1,i), ione );
                #endif
                alpha = tau[i] * -0.5f * value;
                blasf77_saxpy(&i_n, &alpha, A(i+1, i), &ione, W(i+1,i), &ione);
            }
        }
    }

    magma_free_cpu( f );
    magma_queue_destroy( stream );

    return 0;
} /* magma_slatrd */
Example #24
0
int baffle_k(struct solver_data *solver, 
                            int x, double min_1, double min_2, double max_1, double max_2, 
                            double value, long int pos) {

  long int i, j, k, imin, jmin, kmin, imax, jmax, kmax;
  double delp, v_prime;
  double sgn = 1.0;
  
  if(baffle_setup(solver, x, pos, &imin, &jmin, &kmin, &imax, &jmax, &kmax, min_1, min_2, max_1, max_2)) return 0;
  
  if(value < 0.01) {
    return 0;
  }
  
  /* if(solver->p_flag != 0) return 0; */
  
  for(i=imin; i <= imax; i++) {
    for(j=jmin; j <= jmax; j++) {
      for(k=kmin; k <= kmax; k++) {   
        sgn = 1.0;
        switch(x) {
        case 0:
          if(AE(i,j,k) < solver->emf) continue;
          if(fabs(U(i,j,k)) < solver->emf) continue;
          
          delp = P(i,j,k) - P(i+1,j,k);
          
          if(delp < 0.0) sgn = -1.0;
          v_prime = sgn * sqrt((fabs(delp) * 2) / (solver->rho * value));
                    
          if(v_prime * U(i,j,k) < solver->emf * -1.0) v_prime = 0; /* this shouldn't cause a direction change */
          if(fabs(v_prime) > fabs(U(i,j,k)) && v_prime * U(i,j,k) > solver->emf) continue; /* and never speed up */
          else U(i,j,k) = v_prime;

          break;
        case 1:
          if(AN(i,j,k) < solver->emf) continue;
          if(fabs(V(i,j,k)) < solver->emf) continue;
          
          delp = P(i,j,k) - P(i,j+1,k);
          
          if(delp < 0.0) sgn = -1.0;
          v_prime = sgn * sqrt((fabs(delp) * 2) / (solver->rho * value));
                    
          if(v_prime * V(i,j,k) < solver->emf * -1.0) v_prime = 0; /* this shouldn't cause a direction change */
          if(fabs(v_prime) > fabs(V(i,j,k)) && v_prime * V(i,j,k) > solver->emf) continue; /* and never speed up */
          else V(i,j,k) = v_prime;

          break;
        case 2:
          if(AT(i,j,k) < solver->emf) continue;
          if(fabs(W(i,j,k)) < solver->emf) continue;
          
          delp = P(i,j,k) - P(i,j,k+1);
          
          if(delp < 0.0) sgn = -1.0;
          v_prime = sgn * sqrt((fabs(delp) * 2) / (solver->rho * value));
                    
          if(v_prime * W(i,j,k) < solver->emf * -1.0) v_prime = 0; /* this shouldn't cause a direction change */
          if(fabs(v_prime) > fabs(W(i,j,k)) && v_prime * W(i,j,k) > solver->emf) continue; /* and never speed up */
          else W(i,j,k) = v_prime;

          break;
        }          
      }
    }
  }

  return 0;
}
Example #25
0
File: textend.cpp Project: aosm/tcl
void TestExtend() {
  B(e01, Extend new file, 0)W(e01a);
   {
    c4_IntProp p1("p1");
    c4_Storage s1("e01a", 2);
    A(s1.Strategy().FileSize() == 0);
    c4_View v1 = s1.GetAs("a[p1:I]");
    v1.Add(p1[123]);
    s1.Commit();
    A(s1.Strategy().FileSize() == kSize1);
    v1.Add(p1[456]);
    s1.Commit();
    A(s1.Strategy().FileSize() == kSize2);
  }
  D(e01a);
  R(e01a);
  E;

  B(e02, Extend committing twice, 0)W(e02a);
   {
    c4_IntProp p1("p1");
    c4_Storage s1("e02a", 2);
    A(s1.Strategy().FileSize() == 0);
    c4_View v1 = s1.GetAs("a[p1:I]");
    v1.Add(p1[123]);
    s1.Commit();
    A(s1.Strategy().FileSize() == kSize1);
    s1.Commit();
    A(s1.Strategy().FileSize() == kSize1);
    v1.Add(p1[456]);
    s1.Commit();
    A(s1.Strategy().FileSize() == kSize2);
  }
  D(e02a);
  R(e02a);
  E;

  B(e03, Read during extend, 0)W(e03a);
   {
    c4_IntProp p1("p1");
    c4_Storage s1("e03a", 2);
    A(s1.Strategy().FileSize() == 0);
    c4_View v1 = s1.GetAs("a[p1:I]");
    v1.Add(p1[123]);
    s1.Commit();
    A(s1.Strategy().FileSize() == kSize1);

     {
      c4_Storage s2("e03a", 0);
      c4_View v2 = s2.View("a");
      A(v2.GetSize() == 1);
      A(p1(v2[0]) == 123);
    }

    v1.Add(p1[456]);
    s1.Commit();
    A(s1.Strategy().FileSize() == kSize2);

     {
      c4_Storage s3("e03a", 0);
      c4_View v3 = s3.View("a");
      A(v3.GetSize() == 2);
      A(p1(v3[0]) == 123);
      A(p1(v3[1]) == 456);
    }
  }
  D(e03a);
  R(e03a);
  E;

  B(e04, Extend during read, 0)W(e04a);
   {
    c4_IntProp p1("p1");

     {
      c4_Storage s1("e04a", 2);
      A(s1.Strategy().FileSize() == 0);
      c4_View v1 = s1.GetAs("a[p1:I]");
      v1.Add(p1[123]);
      s1.Commit();
      A(s1.Strategy().FileSize() == kSize1);
    }

    c4_Storage s2("e04a", 0);
    c4_View v2 = s2.View("a");
    A(v2.GetSize() == 1);
    A(p1(v2[0]) == 123);

    c4_Storage s3("e04a", 0); { // open, don't load

    
      c4_Storage s4("e04a", 2);
      A(s4.Strategy().FileSize() == kSize1);
      c4_View v4 = s4.View("a");
      v4.Add(p1[123]);
      s4.Commit();
      A(s4.Strategy().FileSize() > kSize1); // == kSize2);
    }

    c4_View v2a = s2.View("a");
    A(v2a.GetSize() == 1);
    A(p1(v2a[0]) == 123);

    c4_View v3 = s3.View("a");
    A(v3.GetSize() == 1);
    A(p1(v3[0]) == 123);

  }
  D(e04a);
  R(e04a);
  E;

  B(e05, Test memory mapping, 0)W(e05a);
   {
    // this is not a test of MK, but of the underlying system code

     {
      c4_FileStrategy fs;
      bool f1 = fs.DataOpen("e05a", 1);
      A(!f1);
      fs.DataWrite(0, "hi!", 3);
      A(fs._failure == 0);
      A(fs.FileSize() == 3);
      fs.DataCommit(0);
      A(fs.FileSize() == 3);
      fs.ResetFileMapping();
      if (fs._mapStart != 0) {
        A(fs._dataSize == 3);
        c4_String s((char*)fs._mapStart, 3);
        A(s == "hi!");
      }
      fs.DataWrite(3, "hello", 5);
      A(fs._failure == 0);
      A(fs.FileSize() == 8);
      fs.DataCommit(0);
      A(fs.FileSize() == 8);
      if (fs._mapStart != 0) {
        A(fs._dataSize == 3);
        c4_String s((char*)fs._mapStart, 8);
        A(s == "hi!hello");
      }
      fs.DataWrite(100, "wow!", 4);
      A(fs._failure == 0);
      A(fs.FileSize() == 104);
      fs.DataCommit(0);
      A(fs.FileSize() == 104);
      fs.ResetFileMapping();
      if (fs._mapStart != 0) {
        A(fs._dataSize == 104);
        c4_String s((char*)fs._mapStart + 100, 4);
        A(s == "wow!");
      }
    }

    // clear the file, so dump doesn't choke on it
    FILE *fp = fopen("e05a", "w");
    A(fp != 0);
    fclose(fp);

  }
  D(e05a);
  R(e05a);
  E;

  B(e06, Rollback during extend, 0)W(e06a);
   {
    c4_IntProp p1("p1");
    c4_Storage s1("e06a", 2);
    A(s1.Strategy().FileSize() == 0);
    c4_View v1 = s1.GetAs("a[p1:I]");
    v1.Add(p1[123]);
    s1.Commit();
    A(s1.Strategy().FileSize() == kSize1);

    c4_Storage s2("e06a", 0);
    c4_View v2 = s2.View("a");
    A(v2.GetSize() == 1);
    A(p1(v2[0]) == 123);

    v1.Add(p1[456]);
    s1.Commit();
    A(s1.Strategy().FileSize() == kSize2);
#if 0
    /* fails on NT + Samba, though it works fine with mmap'ing disabled */
    s2.Rollback();

    c4_View v2a = s2.View("a");
    A(v2a.GetSize() == 2);
    A(p1(v2a[0]) == 123);
    A(p1(v2a[1]) == 456);
#else 
    c4_View v2a = s2.View("a");
    A(v2a.GetSize() == 1);
    A(p1(v2a[0]) == 123);
#endif 
  }
  D(e06a);
  R(e06a);
  E;
}
Example #26
0
int baffle_swirl(struct solver_data *solver, 
                            int x, double min_1, double min_2, double max_1, double max_2, 
                            double *value, long int pos) {

  long int i, j, k, imin, jmin, kmin, imax, jmax, kmax;
  double count;
  double swirl, u_ave, v_ave, w_ave;
  
  if(baffle_setup(solver, x, pos, &imin, &jmin, &kmin, &imax, &jmax, &kmax, min_1, min_2, max_1, max_2)) {
    swirl = solver_mpi_sum(solver, 0);
    count = solver_mpi_sum(solver, 0);
    *value = swirl / count;
    if(isnan(*value)) *value = 0;
    return 0;
  }

  *value = 0;
  
  imin = max(imin-1,0);
  jmin = max(jmin-1,0);
  kmin = max(kmin-1,0);
  switch(x) {
  case 0:
    imax = max(imax-1,0);
    break;
  case 1:
    jmax = max(jmax-1,0);
    break;
  case 2:
    kmax = max(kmax-1,0);
    break;
  }
  
  swirl = 0;
  count = 0;
  
  for(i=imin; i <= imax; i++) {
    for(j=jmin; j <= jmax; j++) {
      for(k=kmin; k <= kmax; k++) {   
        /* find cell-centered velocity */
        u_ave = (U(i,j,k) + U(i+1,j,k)) / 2;
        v_ave = (V(i,j,k) + V(i,j+1,k)) / 2;
        w_ave = (W(i,j,k) + W(i,j,k+1)) / 2;        
      
        switch(x) {
        case 0:
          if((AE(i,j,k) + AE(i+1,j,k)) < (1-solver->emf) || fabs(u_ave) < solver->emf) continue;
          swirl = swirl + atan(sqrt(pow(v_ave,2) + pow(w_ave,2)) / fabs(u_ave)) * 180 / M_PI;
          count = count + 1;
          break;
        case 1:
          if((AN(i,j,k) + AN(i,j+1,k)) < (1-solver->emf) || fabs(v_ave) < solver->emf) continue;
          swirl = swirl + atan(sqrt(pow(u_ave,2) + pow(w_ave,2)) / fabs(v_ave)) * 180 / M_PI;
          count = count + 1;
          break;
        case 2:
          if((AT(i,j,k) + AT(i+1,j,k)) < (1-solver->emf) || fabs(w_ave) < solver->emf) continue;
          swirl = swirl + atan(sqrt(pow(u_ave,2) + pow(v_ave,2)) / fabs(w_ave)) * 180 / M_PI;
          count = count + 1;
          break;
        }        
      }
    }
  }
  
  swirl = solver_mpi_sum(solver, swirl);
  count = solver_mpi_sum(solver, count);
  *value = swirl / count;
  if(isnan(*value)) *value = 0;
  
  return 0;
}
Example #27
0
    .str_cal =            FT9000_STR_CAL,
    .chan_list =          {
	    	/* TBC */
               {   1,  99, RIG_MTYPE_MEM,  NEWCAT_MEM_CAP },
               { 100, 117, RIG_MTYPE_EDGE, NEWCAT_MEM_CAP },    /* two by two */
               RIG_CHAN_END,
                          },

    .rx_range_list1 =     {
           /* General coverage + ham */
	{kHz(30), MHz(60), FT9000_ALL_RX_MODES, -1, -1, FT9000_VFO_ALL, FT9000_TX_ANTS|RIG_ANT_5},
        RIG_FRNG_END,
    },

    .tx_range_list1 =     {
        FRQ_RNG_HF(1, FT9000_OTHER_TX_MODES, W(5), W(400), FT9000_VFO_ALL, FT9000_TX_ANTS),
        FRQ_RNG_HF(1, FT9000_AM_TX_MODES, W(2), W(100), FT9000_VFO_ALL, FT9000_TX_ANTS),	/* AM class */
        FRQ_RNG_6m(1, FT9000_OTHER_TX_MODES, W(5), W(400), FT9000_VFO_ALL, FT9000_TX_ANTS),
        FRQ_RNG_6m(1, FT9000_AM_TX_MODES, W(2), W(100), FT9000_VFO_ALL, FT9000_TX_ANTS),	/* AM class */

        RIG_FRNG_END,
    },

    .rx_range_list2 =     {
        {kHz(30), MHz(56), FT9000_ALL_RX_MODES, -1, -1, FT9000_VFO_ALL, FT9000_TX_ANTS|RIG_ANT_5},
        RIG_FRNG_END,
    },

    .tx_range_list2 =     {
        FRQ_RNG_HF(2, FT9000_OTHER_TX_MODES, W(5), W(400), FT9000_VFO_ALL, FT9000_TX_ANTS),
        FRQ_RNG_HF(2, FT9000_AM_TX_MODES, W(2), W(100), FT9000_VFO_ALL, FT9000_TX_ANTS),	/* AM class */
Example #28
0
int baffle_velocity_dev(struct solver_data *solver, 
                            int x, double min_1, double min_2, double max_1, double max_2, 
                            double *value, long int pos) {

  long int i, j, k, imin, jmin, kmin, imax, jmax, kmax, ip1, im1, jp1, jm1, kp1, km1;
  double count;
  double v_ave, v_dev;
  
  if(baffle_setup(solver, x, pos, &imin, &jmin, &kmin, &imax, &jmax, &kmax, min_1, min_2, max_1, max_2)) return 0;
  
  *value = 0;
    
  v_ave = 0;
  v_dev = 0;
  count = 0;
  
  for(i=imin; i <= imax; i++) {
    for(j=jmin; j <= jmax; j++) {
      for(k=kmin; k <= kmax; k++) {         
      
        switch(x) {
        case 0:
          if(AE(i,j,k) > (1-solver->emf) && (VOF(i,j,k) + VOF(i+1,j,k)) > solver->emf) {
          	jp1 = min(j+1, jmax);
          	jm1 = max(j-1, 0);
          	kp1 = min(k+1, kmax);
          	km1 = max(k-1, 0);
          	
          	if(AE(i,jp1,k) < (1-solver->emf)) continue;
          	if(AE(i,jm1,k) < (1-solver->emf)) continue;
          	if(AE(i,j,kp1) < (1-solver->emf)) continue;
          	if(AE(i,j,km1) < (1-solver->emf)) continue;
          	
            v_ave += U(i,j,k);
            count = count+1;
          }
          break;
        case 1:
          if(AN(i,j,k) > (1-solver->emf) && (VOF(i,j,k) + VOF(i,j+1,k)) > solver->emf) {
          	ip1 = min(i+1, imax);
          	im1 = max(i-1, 0);
          	kp1 = min(k+1, kmax);
          	km1 = max(k-1, 0);
          	
          	if(AN(ip1,j,k) < (1-solver->emf)) continue;
          	if(AN(im1,j,k) < (1-solver->emf)) continue;
          	if(AN(i,j,kp1) < (1-solver->emf)) continue;
          	if(AN(i,j,km1) < (1-solver->emf)) continue;
            v_ave += V(i,j,k);
            count = count+1;
          }
          break;
        case 2:
          if(AT(i,j,k) > (1-solver->emf) && (VOF(i,j,k) + VOF(i,j,k+1)) > solver->emf) {
          	ip1 = min(i+1, imax);
          	im1 = max(i-1, 0);
          	jp1 = min(j+1, jmax);
          	jm1 = max(j-1, 0);
          	
          	if(AT(ip1,j,k) < (1-solver->emf)) continue;
          	if(AT(im1,j,k) < (1-solver->emf)) continue;
          	if(AT(i,jp1,k) < (1-solver->emf)) continue;
          	if(AT(i,jm1,k) < (1-solver->emf)) continue;
            v_ave += W(i,j,k);
            count = count+1;
          }
          break;
        }        
      }
    }
  }
  
  v_ave = fabs(v_ave / count);
  
  for(i=imin; i <= imax; i++) {
    for(j=jmin; j <= jmax; j++) {
      for(k=kmin; k <= kmax; k++) {         
      
        switch(x) {
        case 0:
          if(AE(i,j,k) > (1-solver->emf) && (VOF(i,j,k) + VOF(i+1,j,k)) > solver->emf) {
          	v_dev = max(v_dev, fabs(U(i,j,k) / v_ave));
          }
          break;
        case 1:
          if(AN(i,j,k) > (1-solver->emf) && (VOF(i,j,k) + VOF(i,j+1,k)) > solver->emf) {
          	v_dev = max(v_dev, fabs(V(i,j,k) / v_ave));
          }
          break;
        case 2:
          if(AT(i,j,k) > (1-solver->emf) && (VOF(i,j,k) + VOF(i,j,k+1)) > solver->emf) {
          	v_dev = max(v_dev, fabs(W(i,j,k) / v_ave));
          }
          break;
        }        
      }
    }
  }
  
  *value = v_dev;
  
  return 0;
}
Example #29
0
int main(int argc, char **argv){
  if(argc<2){err("Need a file to serve\n");}
  fd=open(argv[1],O_RDWR|O_SYNC); if(-1==fd){err("Couldn't open file\n");};
  off64_t size=lseek64(fd,0,SEEK_END);__be64 wsz=htobe64(size);
  __be64 wmag=htobe64(init_magic); __be32 rmag=htobe32(reply_magic);
  W("NBDMAGIC",8);W(&wmag,8);W(&wsz,8); int i; for(i=0;i<128;i++){W("\0",1);}
  while(1){
    uint32_t m,t,l;char h[8];uint64_t f;
    R(&m,4);R(&t,4);R(h,8);R(&f,8);R(&l,4);
    in4(&m);in4(&t);in8(&f);in4(&l);
    if(m == request_magic && f < (uint64_t)1<<63 && l+f <= size){
      int64_t ll=l;
      lseek64(fd,f,SEEK_SET);
      if(t==0){
        W(&rmag,4);W("\0\0\0\0",4);W(h,8);
        for(;ll>0;ll-=B){r(rbuf,clip(ll));W(rbuf,clip(ll));}
      } else if(t==1){
        for(;ll>0;ll-=B){R(rbuf,clip(ll));w(rbuf,clip(ll));}
        W(&rmag,4);W("\0\0\0\0",4);W(h,8);
      }
    } else {
      W(&rmag,4);W("\1\0\0\0",4);W(h,8);
    }
  }
  return 0;
}
Example #30
0
void solver(const string samp_file, 
			const double theta, 
			const int num_iter, const int probes) {

	int number_of_nodes, len_samp;
	ifstream fin(samp_file + ".stat");
	
	fin >> number_of_nodes >> len_samp;	
	fin.close();

	vector<double> p(number_of_nodes, 1.0/number_of_nodes);	//uniform schedule	
	vector<double> cost(num_iter, 0);
	vector<clock_t> iteration_time(num_iter);
	

	int k, u;
	double pS, tmp;
	ofstream fout_p(samp_file+ "_probes-" + to_string(probes) + ".p");	
	for (int r=0; r < num_iter; ++r) {				
		// saving the schedule:
		for (double d : p) {
			fout_p << d << "\t";
		}
		fout_p << endl;		
		clock_t round_time = clock();
		fin.open(samp_file);
		vector<double> W(number_of_nodes, 0);			
		while (fin >> k) {
			pS = 0;
			deque<int> S; // TODO: check if it gets new everytime
			for (int i=0; i<k; ++i) {
				fin >> u;				
				pS += p[u];
				S.push_back(u);
			}			
			tmp = 1.0/(1 - theta*pow(1-pS,probes));
			cost[r] += tmp;

			// update W:
			tmp = pow(tmp,2)*pow(1-pS,probes-1);
			for (int v : S) {
				W[v] += tmp;
			}
		}		
		fin.close();		
		cost[r] /= len_samp;
		update(p, W);
		iteration_time[r] = clock()-round_time; 
	}
	fout_p.close();
	
	ofstream fout_conv(samp_file + "_probes-" + to_string(probes) + ".conv");
	for (double c : cost)
		fout_conv << c << "\t";
	fout_conv << endl;

	for (clock_t t : iteration_time)
		fout_conv << t << "\t";
	fout_conv << endl;
	fout_conv.close();

}