Example #1
0
TEST(System, gemv_blocked_scaled_diagonal) {
  Set points;
  FieldRef<simit_float,2> b = points.addField<simit_float,2>("b");
  FieldRef<simit_float,2> c = points.addField<simit_float,2>("c");
  FieldRef<simit_float,2> a = points.addField<simit_float,2>("a");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();

  a.set(p0, {1.0, 2.0});
  a.set(p1, {3.0, 4.0});
  a.set(p2, {5.0, 6.0});

  b.set(p0, {1.0, 1.0});
  b.set(p1, {1.0, 1.0});
  b.set(p2, {1.0, 1.0});

  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();
  func.bind("points", &points);
  func.runSafe();

  ASSERT_EQ(30.0,  c.get(p0)(0));
  ASSERT_EQ(60.0,  c.get(p0)(1));

  ASSERT_EQ(210.0, c.get(p1)(0));
  ASSERT_EQ(280.0, c.get(p1)(1));

  ASSERT_EQ(550.0, c.get(p2)(0));
  ASSERT_EQ(660.0, c.get(p2)(1));
}
Example #2
0
TEST(ffi, vector_add) {
  Set points;
  FieldRef<simit_float> a = points.addField<simit_float>("a");
  FieldRef<simit_float> b = points.addField<simit_float>("b");
  FieldRef<simit_float> c = points.addField<simit_float>("c");

  ElementRef p0 = points.add();
  a.set(p0, 42.0);
  b.set(p0, 24.0);
  c.set(p0, -1.0);

  ElementRef p1 = points.add();
  a.set(p1, 20.0);
  b.set(p1, 14.0);
  c.set(p1, -1.0);

  ElementRef p2 = points.add();
  a.set(p2, 12.0);
  b.set(p2, 21.0);
  c.set(p2, -1.0);

  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();
  func.bind("points", &points);

  func.runSafe();

  SIMIT_EXPECT_FLOAT_EQ(66.0, (int)c.get(p0));
  SIMIT_EXPECT_FLOAT_EQ(34.0, (int)c.get(p1));
  SIMIT_EXPECT_FLOAT_EQ(33.0, (int)c.get(p2));
}
Example #3
0
TEST(System, gemv_input) {
  // Points
  Set points;
  FieldRef<simit_float> b = points.addField<simit_float>("b");
  FieldRef<simit_float> c = points.addField<simit_float>("c");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();

  b.set(p0, 1.0);
  b.set(p1, 2.0);
  b.set(p2, 3.0);

  // Taint c
  c.set(p0, 42.0);
  c.set(p2, 42.0);

  // Springs
  Set springs(points,points);
  FieldRef<simit_float> a = springs.addField<simit_float>("a");

  ElementRef s0 = springs.add(p0,p1);
  ElementRef s1 = springs.add(p1,p2);

  a.set(s0, 1.0);
  a.set(s1, 2.0);

  // Compile program and bind arguments
  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();

  simit::Tensor<simit_float, 2> cs;
  cs(0) = 1.0;
  cs(1) = 2.0;

  func.bind("c", &cs);

  func.bind("points", &points);
  func.bind("springs", &springs);

  func.runSafe();

  // Check that inputs are preserved
  ASSERT_EQ(1.0, b.get(p0));
  ASSERT_EQ(2.0, b.get(p1));
  ASSERT_EQ(3.0, b.get(p2));

  // Check that outputs are correct
  ASSERT_EQ(6.0, (simit_float)c.get(p0));
  ASSERT_EQ(26.0, (simit_float)c.get(p1));
  ASSERT_EQ(20.0, (simit_float)c.get(p2));
}
Example #4
0
TEST(System, gemv_blocked_computed) {
  // Points
  Set points;
  FieldRef<simit_float,2> b = points.addField<simit_float,2>("b");
  FieldRef<simit_float,2> c = points.addField<simit_float,2>("c");
  FieldRef<simit_float,2> x = points.addField<simit_float,2>("x");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();

  b.set(p0, {1.0, 2.0});
  b.set(p1, {3.0, 4.0});
  b.set(p2, {5.0, 6.0});

  x.set(p0, {1.0, 2.0});
  x.set(p1, {3.0, 4.0});
  x.set(p2, {5.0, 6.0});

  // Taint c
  c.set(p0, {42.0, 42.0});
  c.set(p2, {42.0, 42.0});

  // Springs
  Set springs(points,points);
  springs.add(p0,p1);
  springs.add(p1,p2);

  // Compile program and bind arguments
  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();

  func.bind("points", &points);
  func.bind("springs", &springs);

  func.runSafe();

  // Check that outputs are correct
  // TODO: add support for comparing a tensorref like so: b0 == {1.0, 2.0, 3.0}
  TensorRef<simit_float,2> c0 = c.get(p0);
  ASSERT_EQ(36.0, c0(0));
  ASSERT_EQ(72.0, c0(1));

  TensorRef<simit_float,2> c1 = c.get(p1);
  ASSERT_EQ(336.0, c1(0));
  ASSERT_EQ(472.0, c1(1));

  TensorRef<simit_float,2> c2 = c.get(p2);
  ASSERT_EQ(300.0, c2(0));
  ASSERT_EQ(400.0, c2(1));
}
Example #5
0
TEST(System, gemv_storage) {
  // This test tests whether we determine storage correctly for matrices
  // that do not come (directly) from maps
  // Points
  Set points;
  FieldRef<simit_float> b = points.addField<simit_float>("b");
  FieldRef<simit_float> c = points.addField<simit_float>("c");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();

  b.set(p0, 1.0);
  b.set(p1, 2.0);
  b.set(p2, 3.0);

  // Taint c
  c.set(p0, 42.0);
  c.set(p2, 42.0);

  // Springs
  Set springs(points,points);
  FieldRef<simit_float> a = springs.addField<simit_float>("a");

  ElementRef s0 = springs.add(p0,p1);
  ElementRef s1 = springs.add(p1,p2);

  a.set(s0, 1.0);
  a.set(s1, 2.0);

  // Compile program and bind arguments
  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();

  func.bind("points", &points);
  func.bind("springs", &springs);

  func.runSafe();

  // Check that inputs are preserved
  ASSERT_EQ(1.0, b.get(p0));
  ASSERT_EQ(2.0, b.get(p1));
  ASSERT_EQ(3.0, b.get(p2));

  // Check that outputs are correct
  ASSERT_EQ(6.0, c.get(p0));
  ASSERT_EQ(26.0, c.get(p1));
  ASSERT_EQ(20.0, c.get(p2));
}
Example #6
0
TEST(ffi, gemv_blocked) {
  // Points
  Set points;
  FieldRef<simit_float,2> b = points.addField<simit_float,2>("b");
  FieldRef<simit_float,2> c = points.addField<simit_float,2>("c");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();

  b.set(p0, {1.0, 2.0});
  b.set(p1, {3.0, 4.0});
  b.set(p2, {5.0, 6.0});

  // Taint c
  c.set(p0, {42.0, 42.0});
  c.set(p2, {42.0, 42.0});

  // Springs
  Set springs(points,points);
  FieldRef<simit_float,2,2> a = springs.addField<simit_float,2,2>("a");

  ElementRef s0 = springs.add(p0,p1);
  ElementRef s1 = springs.add(p1,p2);

  a.set(s0, {1.0, 2.0, 3.0, 4.0});
  a.set(s1, {5.0, 6.0, 7.0, 8.0});

  // Compile program and bind arguments
  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();
  func.bind("points", &points);
  func.bind("springs", &springs);
  func.runSafe();

  // Check that outputs are correct
  // TODO: add support for comparing a tensorref like so: b0 == {1.0, 2.0, 3.0}
  TensorRef<simit_float,2> c0 = c.get(p0);
  SIMIT_EXPECT_FLOAT_EQ(16.0, c0(0));
  SIMIT_EXPECT_FLOAT_EQ(36.0, c0(1));

  TensorRef<simit_float,2> c1 = c.get(p1);
  SIMIT_EXPECT_FLOAT_EQ(116.0, c1(0));
  SIMIT_EXPECT_FLOAT_EQ(172.0, c1(1));

  TensorRef<simit_float,2> c2 = c.get(p2);
  SIMIT_EXPECT_FLOAT_EQ(100.0, c2(0));
  SIMIT_EXPECT_FLOAT_EQ(136.0, c2(1));
}
Example #7
0
TEST(System, vector_dot_intrinsic) {
  Set points;
  FieldRef<simit_float> x = points.addField<simit_float>("x");
  FieldRef<simit_float> z = points.addField<simit_float>("z");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();
  ElementRef p3 = points.add();
  ElementRef p4 = points.add();
  ElementRef p5 = points.add();
  ElementRef p6 = points.add();
  ElementRef p7 = points.add();
  ElementRef p8 = points.add();
  ElementRef p9 = points.add();
  ElementRef p10 = points.add();
  x.set(p0, 1.0);
  x.set(p1, 2.0);
  x.set(p2, 3.0);
  x.set(p3, 4.0);
  x.set(p4, 5.0);
  x.set(p5, 6.0);
  x.set(p6, 7.0);
  x.set(p7, 8.0);
  x.set(p8, 9.0);
  x.set(p9, 10.0);
  x.set(p10, 11.0);

  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();
  func.bind("points", &points);

  func.runSafe();
  SIMIT_EXPECT_FLOAT_EQ(506.0, (int)z.get(p0));
}
Example #8
0
TEST(System, vector_dot) {
  Set points;
  FieldRef<simit_float> x = points.addField<simit_float>("x");
  FieldRef<simit_float> z = points.addField<simit_float>("z");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();
  x.set(p0, 1.0);
  x.set(p1, 2.0);
  x.set(p2, 3.0);

  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();
  func.bind("points", &points);

  func.runSafe();
  SIMIT_EXPECT_FLOAT_EQ(14.0, (int)z.get(p0));
}
Example #9
0
TEST(System, vector_dot_blocked) {
  Set points;
  FieldRef<simit_float,3> x = points.addField<simit_float,3>("x");
  FieldRef<simit_float> z = points.addField<simit_float>("z");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();
  x.set(p0, {1.0,2.0,3.0});
  x.set(p1, {4.0,5.0,6.0});
  x.set(p2, {7.0,8.0,9.0});

  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();
  func.bind("points", &points);

  func.runSafe();
  SIMIT_EXPECT_FLOAT_EQ(285.0, (simit_float)z.get(p0));
}
Example #10
0
TEST(System, gemv_assemble_from_points) {
  // Points
  Set points;
  FieldRef<simit_float> a = points.addField<simit_float>("a");
  FieldRef<simit_float> b = points.addField<simit_float>("b");
  FieldRef<simit_float> c = points.addField<simit_float>("c");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();

  b.set(p0, 1.0);
  b.set(p1, 2.0);
  b.set(p2, 3.0);

  a.set(p0, 1.0);
  a.set(p1, 2.0);
  a.set(p2, 3.0);

  c.set(p0, 42.0);

  // Springs
  Set springs(points,points);

  springs.add(p0,p1);
  springs.add(p1,p2);

  // Compile program and bind arguments
  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();

  func.bind("points", &points);
  func.bind("springs", &springs);

  func.runSafe();

  // Check that outputs are correct
  ASSERT_EQ(1.0, c.get(p0));
  ASSERT_EQ(4.0, c.get(p1));
  ASSERT_EQ(0.0, c.get(p2));
}
Example #11
0
TEST(ffi, gemv) {
  // Points
  Set points;
  FieldRef<simit_float> b = points.addField<simit_float>("b");
  FieldRef<simit_float> c = points.addField<simit_float>("c");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();

  b.set(p0, 1.0);
  b.set(p1, 2.0);
  b.set(p2, 3.0);

  // Taint c
  c.set(p0, 42.0);
  c.set(p2, 42.0);

  // Springs
  Set springs(points,points);
  FieldRef<simit_float> a = springs.addField<simit_float>("a");

  ElementRef s0 = springs.add(p0,p1);
  ElementRef s1 = springs.add(p1,p2);

  a.set(s0, 1.0);
  a.set(s1, 2.0);

  // Compile program and bind arguments
  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();

  func.bind("points", &points);
  func.bind("springs", &springs);

  func.runSafe();
  
  SIMIT_EXPECT_FLOAT_EQ(3.0, c.get(p0));
  SIMIT_EXPECT_FLOAT_EQ(13.0, c.get(p1));
  SIMIT_EXPECT_FLOAT_EQ(10.0, c.get(p2));
}
Example #12
0
TEST(System, gemv_diagonal_storage_and_sysreduced) {
  // Points
  Set points;
  FieldRef<simit_float> b = points.addField<simit_float>("b");
  FieldRef<simit_float> c = points.addField<simit_float>("c");
  FieldRef<simit_float> a = points.addField<simit_float>("a");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();

  a.set(p0, 1.0);
  a.set(p1, 3.0);
  a.set(p2, 2.0);

  // Springs
  Set springs(points,points);
  FieldRef<simit_float> d = springs.addField<simit_float>("d");

  ElementRef s0 = springs.add(p0,p1);
  ElementRef s1 = springs.add(p1,p2);

  d.set(s0, 1.0);
  d.set(s1, 2.0);


  // Compile program and bind arguments
  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();

  func.bind("points", &points);
  func.bind("springs", &springs);

  func.runSafe();

  // Check that outputs are correct
  ASSERT_EQ(2.0, (simit_float)c.get(p0));
 }
Example #13
0
TEST(System, gemv_blocked_diagonal_storage) {
  Set points;
  FieldRef<simit_float,2> b = points.addField<simit_float,2>("b");
  FieldRef<simit_float,2> c = points.addField<simit_float,2>("c");
  FieldRef<simit_float,2> a = points.addField<simit_float,2>("a");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  ElementRef p2 = points.add();

  a.set(p0, {1.0, 2.0});
  a.set(p1, {3.0, 4.0});
  a.set(p2, {5.0, 6.0});

  b.set(p0, {1.0, 2.0});
  b.set(p1, {3.0, 4.0});
  b.set(p2, {5.0, 6.0});

  // Compile program and bind arguments
  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();

  func.bind("points", &points);

  func.runSafe();

  // Check that outputs are correct
  ASSERT_EQ(5.0,   c.get(p0)(0));
  ASSERT_EQ(10.0,  c.get(p0)(1));

  ASSERT_EQ(75.0,  c.get(p1)(0));
  ASSERT_EQ(100.0, c.get(p1)(1));

  ASSERT_EQ(305.0, c.get(p2)(0));
  ASSERT_EQ(366.0, c.get(p2)(1));
}
Example #14
0
TEST(System, vector_assign_blocked) {
  Set points;
  FieldRef<simit_float,2> x = points.addField<simit_float,2>("x");

  ElementRef p0 = points.add();
  ElementRef p1 = points.add();
  x.set(p0, {1.0, 2.0});
  x.set(p1, {3.0, 4.0});

  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();
  func.bind("points", &points);

  func.runSafe();

  SIMIT_EXPECT_FLOAT_EQ(2.0, x.get(p0)(0));
  SIMIT_EXPECT_FLOAT_EQ(4.0, x.get(p0)(1));
  SIMIT_EXPECT_FLOAT_EQ(6.0, x.get(p1)(0));
  SIMIT_EXPECT_FLOAT_EQ(8.0, x.get(p1)(1));
}
Example #15
0
TEST(System, vector_add_large_system) {
  Set points;
  FieldRef<simit_float> x = points.addField<simit_float>("x");

  std::vector<ElementRef> ps;
  for(size_t i = 0; i < 2557; ++i) {
    ps.push_back(points.add());
    x.set(ps.back(), (simit_float)i);
  }

  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();
  func.bind("points", &points);

  func.runSafe();

  for(size_t i = 0; i < ps.size(); ++i) {
    SIMIT_EXPECT_FLOAT_EQ(i*2, (size_t)x.get(ps[i]));
  }
}
Example #16
0
TEST(ffi, gemv_generics) {
  // Points
  Set points;
  FieldRef<simit_float> cPoints = points.addField<simit_float>("c");
  FieldRef<simit_float> bPoints = points.addField<simit_float>("b");
    
  ElementRef point0 = points.add();
  ElementRef point1 = points.add();
  ElementRef point2 = points.add();
  
  bPoints.set(point0, 1.0);
  bPoints.set(point1, 2.0);
  bPoints.set(point2, 3.0);
  
  // Taint cPoints
  cPoints.set(point0, 42.0);
  cPoints.set(point2, 42.0);

  // Springs
  Set springs(points,points);
  FieldRef<simit_float> aSprings = springs.addField<simit_float>("a");
  
  ElementRef spring0 = springs.add(point0,point1);
  ElementRef spring1 = springs.add(point1,point2);
  
  aSprings.set(spring0, 1.0);
  aSprings.set(spring1, 2.0);
  
  // Particles
  Set particles;
  FieldRef<simit_float> cParticles = particles.addField<simit_float>("c");
  FieldRef<simit_float> bParticles = particles.addField<simit_float>("b");
    
  ElementRef particle0 = particles.add();
  ElementRef particle1 = particles.add();
  
  bParticles.set(particle0, 1.0);
  bParticles.set(particle1, 2.0);
  
  // Taint cParticles
  cParticles.set(particle0, 42.0);
  cParticles.set(particle1, 42.0);

  // Connections
  Set connections(particles,particles);
  FieldRef<simit_float> aConnections = connections.addField<simit_float>("a");
  
  ElementRef connection0 = connections.add(particle0,particle1);
  
  aConnections.set(connection0, 1.0);

  // Compile program and bind arguments
  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();

  func.bind("points", &points);
  func.bind("springs", &springs);
  func.bind("particles", &particles);
  func.bind("connections", &connections);

  func.runSafe();
  
  SIMIT_EXPECT_FLOAT_EQ(3.0, cPoints.get(point0));
  SIMIT_EXPECT_FLOAT_EQ(13.0, cPoints.get(point1));
  SIMIT_EXPECT_FLOAT_EQ(10.0, cPoints.get(point2));
  
  SIMIT_EXPECT_FLOAT_EQ(3.0, cParticles.get(particle0));
  SIMIT_EXPECT_FLOAT_EQ(3.0, cParticles.get(particle1));
}
Example #17
0
TEST(ffi, gemv_blocked_generics) {
  // Points
  Set points;
  FieldRef<simit_float,2> bPoints = points.addField<simit_float,2>("b");
  FieldRef<simit_float,2> cPoints = points.addField<simit_float,2>("c");

  ElementRef point0 = points.add();
  ElementRef point1 = points.add();
  ElementRef point2 = points.add();

  bPoints.set(point0, {1.0, 2.0});
  bPoints.set(point1, {3.0, 4.0});
  bPoints.set(point2, {5.0, 6.0});

  // Taint c
  cPoints.set(point0, {42.0, 42.0});
  cPoints.set(point2, {42.0, 42.0});

  // Springs
  Set springs(points,points);
  FieldRef<simit_float,2,2> aSprings = springs.addField<simit_float,2,2>("a");

  ElementRef spring0 = springs.add(point0,point1);
  ElementRef spring1 = springs.add(point1,point2);

  aSprings.set(spring0, {1.0, 2.0, 3.0, 4.0});
  aSprings.set(spring1, {5.0, 6.0, 7.0, 8.0});

  // Particles
  Set particles;
  FieldRef<simit_float,2> bParticles = particles.addField<simit_float,2>("b");
  FieldRef<simit_float,2> cParticles = particles.addField<simit_float,2>("c");

  ElementRef particle0 = particles.add();
  ElementRef particle1 = particles.add();

  bParticles.set(particle0, {1.0, 2.0});
  bParticles.set(particle1, {3.0, 4.0});

  // Taint c
  cParticles.set(particle0, {42.0, 42.0});
  cParticles.set(particle1, {42.0, 42.0});

  // Connections
  Set connections(particles,particles);
  FieldRef<simit_float,2,2> aConnections = connections.addField<simit_float,2,2>("a");

  ElementRef connection0 = connections.add(particle0,particle1);

  aConnections.set(connection0, {1.0, 2.0, 3.0, 4.0});

  // Compile program and bind arguments
  Function func = loadFunction(TEST_FILE_NAME, "main");
  if (!func.defined()) FAIL();
  func.bind("points", &points);
  func.bind("springs", &springs);
  func.bind("particles", &particles);
  func.bind("connections", &connections);
  func.runSafe();

  // Check that outputs are correct
  // TODO: add support for comparing a tensorref like so: b0 == {1.0, 2.0, 3.0}
  TensorRef<simit_float,2> cPoints0 = cPoints.get(point0);
  SIMIT_EXPECT_FLOAT_EQ(16.0, cPoints0(0));
  SIMIT_EXPECT_FLOAT_EQ(36.0, cPoints0(1));

  TensorRef<simit_float,2> cPoints1 = cPoints.get(point1);
  SIMIT_EXPECT_FLOAT_EQ(116.0, cPoints1(0));
  SIMIT_EXPECT_FLOAT_EQ(172.0, cPoints1(1));

  TensorRef<simit_float,2> cPoints2 = cPoints.get(point2);
  SIMIT_EXPECT_FLOAT_EQ(100.0, cPoints2(0));
  SIMIT_EXPECT_FLOAT_EQ(136.0, cPoints2(1));
  
  TensorRef<simit_float,2> cParticles0 = cParticles.get(particle0);
  SIMIT_EXPECT_FLOAT_EQ(16.0, cParticles0(0));
  SIMIT_EXPECT_FLOAT_EQ(36.0, cParticles0(1));

  TensorRef<simit_float,2> cParticles1 = cParticles.get(particle1);
  SIMIT_EXPECT_FLOAT_EQ(16.0, cParticles1(0));
  SIMIT_EXPECT_FLOAT_EQ(36.0, cParticles1(1));

}