예제 #1
0
파일: hello.C 프로젝트: brog2610/quinoa
  Main(CkArgMsg* m)
  {
    count = 2;
    //Process command-line arguments
    nElements=5;
    if(m->argc >1 ) nElements=atoi(m->argv[1]);
    delete m;

    //Start the computation
    CkPrintf("Running Hello on %d processors for %d elements\n",
	     CkNumPes(),nElements);
    mainProxy = thisProxy;

    //Allocate elements scattered down a sparse 3D line
    CProxy_Hello arr = CProxy_Hello::ckNew();
    for (int y=0;y<nElements;y++)
        arr(37,y,2*y+1).insert();
    arr.doneInserting();

    CProxy_Hello2 arr2 = CProxy_Hello2::ckNew();
    for (int y=0;y<nElements;y++)
        arr2(37,y,2*y+1).insert();
    arr2.doneInserting();

    arr(37,0,1).SayHi(17);
    arr2(37,0,1).SayHi2(17);
  };
예제 #2
0
 bool isValidSudoku(vector<vector<char>>& board) {
     
     int ctr1 = 0, ctr2 = 0;
     for(int i = 0; i < 9; i ++){
         vector<bool> arr1(9, false);
         vector<bool> arr2(9, false);
         vector<bool> arr3(9, false);
         int x = (i/3) * 3;
         int y = (i * 3) % 9;
         for(int j = 0; j < 9; j ++){
             if(board[i][j] !='.'){
                if(arr1[board[i][j]-1 - '0']) return false;
                else arr1[board[i][j]-1 - '0'] = true;
             }
             if(board[j][i] !='.'){
                if(arr2[board[j][i]-1- '0']) return false;
                else arr2[board[j][i]-1- '0'] = true;
             }
             if(board[x + j % 3][y + j / 3] !='.'){
                if(arr3[board[x + j % 3][y + j / 3] - 1 - '0']) return false;
                else arr3[board[x + j % 3][y + j / 3] - 1 - '0'] = true;
             }
         }//end for j
     }//end for i
     return true;
 }
예제 #3
0
파일: main.cpp 프로젝트: vt4a2h/ex_02
int main()
{
    // Примеры использования одномерного статического массива.
    fixed_arrays::FixedArray<int, 5> arr1 {5, 2, 4, 1, 8};
    std::copy(arr1.begin(), arr1.end(), std::ostream_iterator<int>(std::cout, " "));
    std::cout << std::endl;

    fixed_arrays::FixedArray<int, 5> arr2(arr1);
    std::copy(arr2.begin(), arr2.end(), std::ostream_iterator<int>(std::cout, " "));
    std::cout << std::endl;

    std::transform(arr2.begin(), arr2.end(), arr1.begin(), [](int &i){ return i*2; });
    std::copy(arr1.begin(), arr1.end(), std::ostream_iterator<int>(std::cout, " "));
    std::cout << std::endl;

    // Примеры использования двумероного статического массива.
     fixed_arrays::FixedArray2D<int, 3, 2> arr2d{ {7, 5, 1}, {12, 30, 8} };

     std::for_each(arr2d.begin(), arr2d.end(), [](decltype(arr2d[0]) a){std::sort(a.begin(), a.end());} );

     std::for_each(arr2d.begin(), arr2d.end(),
        [](decltype(arr2d[0]) a){
            std::copy(a.begin(), a.end(), std::ostream_iterator<int>(std::cout, " "));
            std::cout << std::endl;
        }
     );

    return 0;
}
double ComputeMahalanobisDistance::Evaluate(vtkPoints * candidate, unsigned int index)
{
    MeasurementVectorType arr2(3);
    arr2.SetDataSameSize(candidate->GetPoint(index));
    std::cout << "Sample: " << arr2 << std::endl;
    std::cout <<"Dist: "<<m_DistanceCalculator->Evaluate(arr2)<<std::endl;
    return m_DistanceCalculator->Evaluate(arr2);
}
void ComputeMahalanobisDistance::Evaluate(vtkPoints * candidate,vtkDataArray* distances)
{
    distances->Allocate(candidate->GetNumberOfPoints());
    MeasurementVectorType arr2(3);
    for (unsigned int i=0;i<candidate->GetNumberOfPoints();i++)
    {
       arr2.SetDataSameSize(candidate->GetPoint(i));
       distances->SetTuple1(i,m_DistanceCalculator->Evaluate(arr2));
    }
}
예제 #6
0
void test3()
{
    ByteArray arr1("BC02");
    ByteArray arr2("1234");
    arr1.append(arr2);
    assert(arr1.size() == 4);
    assert(arr1[0] == 0xBC);
    assert(arr1[1] == 0x02);
    assert(arr1[2] == 0x12);
    assert(arr1[3] == 0x34);
}
예제 #7
0
int main()
{
	/////////////////////////////////////////////////////////////////////
	/// Exmaple for use:
	/////////////////////////////////////////////////////////////////////
	std::random_device rd;
	std::mt19937 gen(rd());
	std::uniform_int_distribution<> dis (-100, 100);

	std::vector <int> arr (25);
	std::vector <int> arr1 (25);
	std::vector <int> arr2 (25);

	for(int i = 0 ; i < 25; i++)
	{
		arr  [i] = dis (gen);
		arr1 [i] = arr [i];
		arr2 [i] = arr [i];
	}
	for (int i = 0 ; i < 25 ; i ++)
	{
		std::cout << arr [i] << " ";
	}
	std::cout << std::endl;

	////////////////////////////////////////////////////////////////////
	/// Use Standart Sort
	////////////////////////////////////////////////////////////////////
	std::sort (begin (arr1), end (arr1), cmp2 ());
	for (int i = 0 ; i < 25 ; i ++)
	{
		std::cout << arr1 [i] << " ";
	}
	std::cout << std::endl;

	/////////////////////////////////////////////////////////////////////
	/// Use atdc sort
	/////////////////////////////////////////////////////////////////////
	atdc_sort (std::begin (arr2), std::end (arr2), cmp1 ());
	
	for(int i = 0 ; i < (int)arr2.size () ; i ++)
	{
		std::cout << arr2 [i] << " ";
	}
	std::cout << std::endl;
	return 0;
}
예제 #8
0
//-----------------------------------------------------------------------------
// Returns true if a array attribute is equal
//-----------------------------------------------------------------------------
static bool IsArrayEqual( CDmElement *pElement1, CDmElement *pElement2, const char *pArrayAttribute )
{
	CDmrElementArray<> arr1( pElement1, pArrayAttribute );
	CDmrElementArray<> arr2( pElement2, pArrayAttribute );
	int nCount = arr1.IsValid() ? arr1.Count() : 0;
	int nCount2 = arr2.IsValid() ? arr2.Count() : 0;
	if ( nCount != nCount2 )
		return false;
	for ( int i = 0; i < nCount; ++i )
	{
		if ( !IsScalarAttributesEqual( arr1[i], arr2[i] ) )
			return false;
	}

	return true;

}
예제 #9
0
int main(){

	Array<double, int> arr1(10); // start index = 1
	Array<double, int> arr2(10,-1); // start index = -1
	Array<double, int> arr3(10, 0, 3.14); // start index = 0, all values = 3.14

	print(arr1);
	print(arr2);
	print(arr3);

	Matrix<double, int> m1(10, 10);
	Matrix<double, int> m2(10, 10, -2, 3.14);

	print(m1);
	print(m2);

	return 0;
}
예제 #10
0
//-----------------------------------------------------------------------------
// Returns true if a def is equal
//-----------------------------------------------------------------------------
static bool IsDefEqual( CDmElement *pElement1, CDmElement *pElement2 )
{
	if ( !IsScalarAttributesEqual( pElement1, pElement2 ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "renderer" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "operator" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "initializer" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "emitter" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "forcegenerator" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "constraint" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "children" ) )
		return false;

	CDmrElementArray<> arr1( pElement1, "children" );
	CDmrElementArray<> arr2( pElement2, "children" );
	int nCount = arr1.IsValid() ? arr1.Count() : 0;
	int nCount2 = arr2.IsValid() ? arr2.Count() : 0;
	if ( nCount != nCount2 )
		return false;
	for ( int i = 0; i < nCount; ++i )
	{
		CDmElement *pChild1 = arr1[i]->GetValueElement<CDmElement>( "child" );
		CDmElement *pChild2 = arr2[i]->GetValueElement<CDmElement>( "child" );
		if ( !pChild1 || !pChild2 )
		{
			if ( pChild1 || pChild2 )
				return false;
			continue;
		}
		if ( !IsDefEqual( pChild1, pChild2 ) )
			return false;
	}

	return true;
}
예제 #11
0
int Solution::maxArr(vector<int> &A) {
    int ans = INT_MIN;
    vector<int> arr1(A.size()+1), arr2(A.size()+1);
    
    for(int i=0; i<A.size(); i++){
        arr1[i] = A[i]+(i+1);
        arr2[i] = A[i]-(i+1);
    }
    
    int max1=INT_MIN, max2=INT_MIN, min1=INT_MAX, min2=INT_MAX;
    
    for(int i=0; i<A.size(); i++){
        max1=max(max1, arr1[i]);
        max2=max(max2, arr2[i]);
        
        min1=min(min1, arr1[i]);
        min2=min(min2, arr2[i]);
    }
    
    
    return max(abs(max1-min1), abs(max2-min2));
}
예제 #12
0
파일: main.cpp 프로젝트: preyko/talw2
int main() {
	RLIdentRegister* iregister = new RLIdentRegister();
    RLType::setRegister(iregister);

    std::cout << "Test 1\n";
    RLArray array(RLType::Number);

    array.setElem(1,&RLNumber(100));
    array.setElem(2,&RLNumber(112));
    array.setElem(2,&RLBool(false));

    //array.print();

    RLArray* array2 = array.copy();

    std::cout << array.applyBinary(compare,array2) << std::endl;

    array2->getElem(2)->applyUnary(increment);

    std::cout << array.applyBinary(compare,array2) << std::endl;

    array.print();
    array2->print();

    std::cout << "Test 1\n";
    RLArray arr1(RLType::Number);
    RLArray arr2(RLType::Number);

    arr1.setElem(1,&RLNumber(101));
    arr1.setElem(2,&RLNumber(102));

    arr1.setElem(2,&RLNumber(101));
    arr1.setElem(1,&RLNumber(102));

    std::cout << arr1.applyBinary(compare,&arr2) << std::endl;

	delete iregister;
}
예제 #13
0
void eseqclusteravg::finalize()
{
  while (incmaxit!=smatrix.end()){
    while (completemerges.size() && (incmaxit!=smatrix.end() && completemerges.begin()->dist>=incmaxdist || incmaxit==smatrix.end() && completemerges.begin()->dist>=lastdist)){
      if (completemerges.begin()->dist<thres) return;
      mergeComplete(lastdist);
    }
    double avgdist=0.0;
    std::list<long> &arr(incluster[incmaxit->x]);
    std::list<long> &arr2(incluster[incmaxit->y]);
    for (std::list<long>::iterator i=arr.begin(); i!=arr.end(); ++i){
      for (std::list<long>::iterator j=arr2.begin(); j!=arr2.end(); ++j){
//        cout << "dist: " << *i << "," << *j << ": " << fdist(*i,*j) << endl;
        avgdist+=fdist((*seqarr).values(*i),(*seqarr).values(*j),seqlen);
      }
    }
    avgdist=avgdist/(arr.size()*arr2.size());
    incmaxit->count=arr.size()*arr2.size();
    incmaxit->dist=avgdist;
    cout << "# calculating avg cluster distance: " << incmaxit->x << "," << incmaxit->y << " : " << incmaxdist << " : " << avgdist << endl;
    completemerges.insert(*incmaxit);
    getIncompleteMaxDist(lastdist,incmaxdist,incmaxit);
  }
}
예제 #14
0
int main()
{
    std::cout << std::boolalpha;
    constexpr unsigned sizes[]{4, 5, 3, 8, 6};

// Construction
    std::cout << "Construction : " << std::endl;
    std::array<char, sizes[0]> arr0{}, arr0b{{'f', 'r', 's', 'r'}}; // default
    std::array<char, sizes[1]> arr1 = {'e', 'q', 'g', 't', 'e'}, arr1b({0 + 'a', 4 + 'a', 5 + 'a', 2 + 'a', 3 + 'a'}); // braced list
    std::array<char, sizes[2]> arr2({'d', 's', 'a'}), arr2b = {7, 7, 'u'};

// Print elements
    print(arr0, "arr0");
    print(arr0b, "arr0b");
    print(arr1, "arr1");
    print(arr1b, "arr1b");
    print(arr2, "arr2");
    print(arr2b, "arr2b");

// Type aliases
    std::array<char, sizes[0]>::iterator it0(arr0.begin()); // iterator
    std::array<char, sizes[1]>::const_iterator cit1(arr1.begin()); // const_iterator
    std::array<char, sizes[0]>::reverse_iterator rit0(--arr0.rbegin()); // iterator
    std::array<char, sizes[1]>::const_reverse_iterator crit1(--arr1.crbegin()); // const_reverse_iterator
std::array<char, sizes[1]>::size_type sz1 = arr1.size(); // size_type
    std::array<char, sizes[2]>::difference_type diff2 = arr2.cend() - arr2.cbegin(); // difference_type
    std::array<char, sizes[2]>::value_type val2 = arr2[0]; // value_type
    std::array<char, sizes[2]>::reference ref2 = arr2[1]; // reference
    std::array<char, sizes[2]>::const_reference cref2 =arr2[3]; // const_reference

// Print iterators
    std::cout << "it0 : " << *it0 << std::endl;
    std::cout << "rit0 : " << *rit0 << std::endl;
    std::cout << "cit1 : " << *cit1 << std::endl;
    std::cout << "crit1 : " << *crit1 << std::endl;

    std::cout << "val2 : " << val2 << std::endl;
    std::cout << "ref2 : " << ref2 << std::endl;
    std::cout << "cref2 : " << cref2 << std::endl;

// Size operations
    std::cout << "arr1.size : " << sz1 << std::endl;
    std::cout << "arr2 size : " << diff2 << std::endl; // number of elements in container
    std::cout << "arr0.max_size : " << arr0.max_size() << std::endl;// max number of elements container can hold
    std::cout << "arr1.max_size : " << arr1.max_size() << std::endl; // true if container empty, false otherwise
    std::cout << "arr2.max_size : " << arr2.max_size() << std::endl;

// Swap
    std::cout << "Assignment and swap : " << std::endl;
    arr0 = arr0b; // copy assignment of object
    arr1b = {'a', 'b', 'c', 'd'}; // copy assignment of braced list
    arr2.swap(arr2b); // member style swap
    swap(arr1, arr1b); // function style swap

// Print elements
    print(arr0, "arr0");
    print(arr0b, "arr0b");
    print(arr1, "arr1");
    print(arr1b, "arr1b");
    print(arr2, "arr2");
    print(arr2b, "arr2b");

// Relational operations
    std::cout << "Relational operations : " << std::endl;
    std::cout << "arr0 == arr0b : " << (arr0 == arr0b) << std::endl; // ==
    std::cout << "arr1 != arr1b : " << (arr1 != arr1b) << std::endl; // !=
    std::cout << "arr2 < arr2b : " << (arr2 < arr2b) << std::endl; // <
    std::cout << "arr2 <= arr2b : " << (arr2 <= arr2b) << std::endl; // <=
    std::cout << "arr1 > arr1b : " << (arr1 > arr1b) << std::endl; // >
    std::cout << "arr0 >= arr0b : " << (arr0 >= arr0b) << std::endl; // >=

    return 0;
}
예제 #15
0
TEST_P(TestGetSubPatch3D, SubPatch)
{
  Go::SplineVolume vol(GetParam().n, GetParam().n, GetParam().n,
      GetParam().p+1, GetParam().p+1, GetParam().p+1,
      GetParam().knots.begin(), GetParam().knots.begin(), GetParam().knots.begin(),
      GetParam().coefs.begin(), GetParam().dim, GetParam().rational);
  size_t numcoefs0 = vol.basis(0).numCoefs()/2 + GetParam().p;
  Go::SplineVolume vol0 = MultiPatchModelGenerator3D::getSubPatch(&vol,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1);
  size_t numcoefs1 = vol.basis(0).numCoefs() - numcoefs0 + GetParam().p;
  size_t start1 = numcoefs0 - GetParam().p;
  Go::SplineVolume vol1 = MultiPatchModelGenerator3D::getSubPatch(&vol,
      start1, numcoefs1, GetParam().p+1,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1);

  // Check first sub-knot-vector
  std::vector<double> arr0(GetParam().knots.begin(), GetParam().knots.begin()+GetParam().lknots0);
  std::vector<double> arr1(vol0.basis(0).begin(), vol0.basis(0).end());
  std::cout << "sub-knot-vector 0" << std::endl;
  check_vector_double_near(arr0, arr1);

  // Check second sub-knot-vector
  std::vector<double> arr2(GetParam().knots.end()-GetParam().lknots1, GetParam().knots.end());
  std::vector<double> arr3(vol1.basis(0).begin(), vol1.basis(0).end());
  std::cout << "sub-knot-vector 1" << std::endl;
  check_vector_double_near(arr2, arr3);
  std::vector<double> arrX(vol.coefs_begin(), vol.coefs_end());

  // Check first sub-control net
  std::vector<double>::const_iterator i0 = GetParam().rational ? vol0.rcoefs_begin() : vol0.coefs_begin();
  std::vector<double>::const_iterator i1 = GetParam().rational ? vol0.rcoefs_end() : vol0.coefs_end();
  std::vector<double> arr4(i0, i1);
  std::cout << "sub-node-vector 0" << std::endl;
  check_vector_double_near(GetParam().coefs0, arr4);

  // Check second sub-control net
  std::vector<double>::const_iterator i2 = GetParam().rational ? vol1.rcoefs_begin() : vol1.coefs_begin();
  std::vector<double>::const_iterator i3 = GetParam().rational ? vol1.rcoefs_end() : vol1.coefs_end();
  std::vector<double> arr5(i2, i3);
  std::cout << "sub-node-vector 1" << std::endl;
  check_vector_double_near(GetParam().coefs1, arr5);

  // Evaluate function at points
  double xiA(0.3333), xiB(2), xiC(4.2);
  RealFunc* f = utl::parseRealFunc("(1-y*y)*(3.14159-x)*(1-z)", "expression");
  Go::SplineVolume* fh = SplineUtils::project(&vol, *f);
  Go::SplineVolume fh0 = MultiPatchModelGenerator3D::getSubPatch(fh,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1);
  Go::SplineVolume fh1 = MultiPatchModelGenerator3D::getSubPatch(fh,
      start1, numcoefs1, GetParam().p+1,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1);
  Go::Point fA, fB, fC, fA0, fB0, fB1, fC1;
  fh->point(fA, xiA, xiA, xiA);
  fh->point(fB, xiB, xiA, xiA);
  fh->point(fC, xiC, xiA, xiA);

  std::cout << "point evaluation" << std::endl;
  fh0.point(fA0, xiA, xiA, xiA);
  check_point_near(fA, fA0);
  fh0.point(fB0, xiB, xiA, xiA);
  check_point_near(fB, fB0);
  fh1.point(fB1, xiB, xiA, xiA);
  check_point_near(fB, fB1);
  fh1.point(fC1, xiC, xiA, xiA);
  check_point_near(fC, fC1);

  // Check FEM topology
  std::stringstream str0, str1;
  str0 << "700 1 0 0\n" << vol0;
  str1 << "700 1 0 0\n" << vol1;
  ASMs3D pch0, pch1;
  pch0.resetNumbering();
  pch0.read(str0);
  pch1.read(str1);
  std::cout << "element/node numbers" << std::endl;
  ASSERT_TRUE(pch0.generateFEMTopology());
  ASSERT_TRUE(pch1.generateFEMTopology());
  std::vector<int> myMLGE = pch1.getMyElementNums();
  check_vector_int_equals_range(myMLGE, GetParam().mlge1);
  std::vector<int> myMLGN = pch1.getMyNodeNums();
  check_vector_int_equals_range(myMLGN, GetParam().mlgn1);
}
double kshell_tri_interp(vector<double> &x, vector<double> &y, vector<double> &z, vector<double> &data, double x0, double y1, double z1, int KK)
{
  //cout << "Entering kshel" << endl;
  int NI = 53;
  int NJ = 60;
  int NK = 65;
  double p[NI][NJ];
  double q[NI][NJ];
  double data1[NI][NJ];
  double d = 0.0;
  double p1,q1;

  for(int i = 0; i < NI; i++)
  {
    for(int j = 0; j < NJ; j++)
    {
      p[i][j] = x[shellIndex(i,j,KK)];
      q[i][j] = sqrt(pow(y[shellIndex(i,j,KK)],2.0)+pow(z[shellIndex(i,j,KK)],2.0));
      p1=x0;
      q1=sqrt(pow(y1,2.0)+pow(z1,2.0));
      data1[i][j] = data[shellIndex(i,j,KK)];
    }
  }

  //Find out which triangle is (p1.q1) in
  //search through (i,j) pairs, each cell is divided into two triangles
  // 1 (i,j) (i+1,j),(i,j+1)
  // 2 (i+1,j+1) (i+1,j), (i,j+1)

  double s1[2];
  double s2[2];
  double s3[2];
  double s4[2];
  double xx1,yy1,ff1,xx2,yy2,ff2,xx3,yy3,ff3;

  for(int i = 0; i < NI-1; i++)
  {
    for(int j = 0; j < NJ-1; j++)
    {
      s1[0] = p[i][j]-p1;
      s1[1] = q[i][j]-q1;
      s2[0] = p[i+1][j]-p1;
      s2[1] = q[i+1][j]-q1;
      s3[0] = p[i+1][j+1]-p1;
      s3[1] = q[i+1][j+1]-q1;
      s4[0] = p[i][j+1]-p1;
      s4[1] = q[i][j+1]-q1;

      //Triangle 1, ANG(12)+ANG(24)+ANG(41)=2*pi
      double theta12, theta24, theta41;
      theta12=acos((s1[0]*s2[0]+s1[1]*s2[1])/sqrt((pow(s1[0],2)+pow(s1[1],2))*(pow(s2[0],2)+pow(s2[1],2))));
      theta24=acos((s2[0]*s4[0]+s2[1]*s4[1])/sqrt((pow(s2[0],2)+pow(s2[1],2))*(pow(s4[0],2)+pow(s4[1],2))));
      theta41=acos((s4[0]*s1[0]+s4[1]*s1[1])/sqrt((pow(s4[0],2)+pow(s4[1],2))*(pow(s1[0],2)+pow(s1[1],2))));

      if(abs(theta12+theta24+theta41-2.0*PI) < 0.001)
      {
        xx1=p[i][j];
        yy1=q[i][j];
        ff1=data1[i][j];
        xx2=p[i+1][j];
        yy2=q[i+1][j];
        ff2=data1[i+1][j];
        xx3=p[i][j+1];
        yy3=q[i][j+1];
        ff3=data1[i][j+1];
        break;
      }

      //Triangle 2, ANG(23)+ANG(34)+ANG(42)=2*pi
      double theta23, theta34, theta42;
      theta23=acos((s2[0]*s3[0]+s2[1]*s3[1])/sqrt((pow(s2[0],2)+pow(s2[1],2))*(pow(s3[0],2)+pow(s3[1],2))));
      theta34=acos((s3[0]*s4[0]+s3[1]*s4[1])/sqrt((pow(s3[0],2)+pow(s3[1],2))*(pow(s4[0],2)+pow(s4[1],2))));
      theta42=acos((s4[0]*s2[0]+s4[1]*s2[1])/sqrt((pow(s4[0],2)+pow(s4[1],2))*(pow(s2[0],2)+pow(s2[1],2))));


      if(abs(theta23+theta34+theta42-2.0*PI) < 0.001)
      {
        xx1=p[i+1][j+1];
        yy1=q[i+1][j+1];
        ff1=data1[i+1][j+1];
        xx2=p[i+1][j];
        yy2=q[i+1][j];
        ff2=data1[i+1][j];
        xx3=p[i][j+1];
        yy3=q[i][j+1];
        ff3=data1[i][j+1];
        break;
      }

    }
  }

  Array2D< double > arr1(3,3);
  Array2D< double > arr2(3,3);
  Array2D< double > arr3(3,3);
  Array2D< double > arr(3,3);

  double temp[3][3] = { {xx1, yy1, 1},
                       {xx2, yy2, 1},
                       {xx3, yy3, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr[i][j] = temp[i][j];
    }
  }

  double temp1[3][3] = { {p1, q1, 1},
                        {xx2, yy2, 1},
                        {xx3, yy3, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr1[i][j] = temp1[i][j];
    }
  }

  double temp2[3][3] = { {p1, q1, 1},
                        {xx1, yy1, 1},
                        {xx3, yy3, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr2[i][j] = temp2[i][j];
    }
  }

  double temp3[3][3] = { {p1, q1, 1},
                        {xx1, yy1, 1},
                        {xx2, yy2, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr3[i][j] = temp3[i][j];
    }
  }

  JAMA::LU< double > compute(arr);
  JAMA::LU< double > compute1(arr1);
  JAMA::LU< double > compute2(arr2);
  JAMA::LU< double > compute3(arr3);

  d = (ff1*compute1.det() - ff2*compute2.det() + ff3*compute3.det())/compute.det();


  return d;


}
예제 #17
0
TEST(Stack_DgVariableArray2D, creation_DgVariableArray2D)
{
  Dg::VariableArray2D<int> arr;

  int x0[3] = {0, 1, 2};
  int x1[2] = {3, 4};
  int x2[4] = {5, 6, 7, 8};
  int x3[1] = {9};
  int x4[5] = {10, 11, 12, 13, 14};

  arr.push_back(x0, 3);
  arr.push_back(x1, 2);
  arr.push_back(x2, 4);
  arr.push_back(x3, 1);
  arr.push_back(x4, 5);

  CHECK(arr(0, 0) == 0);
  CHECK(arr(0, 1) == 1);
  CHECK(arr(0, 2) == 2);
  CHECK(arr(1, 0) == 3);
  CHECK(arr(1, 1) == 4);
  CHECK(arr(2, 0) == 5);
  CHECK(arr(2, 1) == 6);
  CHECK(arr(2, 2) == 7);
  CHECK(arr(2, 3) == 8);
  CHECK(arr(3, 0) == 9);
  CHECK(arr(4, 0) == 10);
  CHECK(arr(4, 1) == 11);
  CHECK(arr(4, 2) == 12);
  CHECK(arr(4, 3) == 13);
  CHECK(arr(4, 4) == 14);

  Dg::VariableArray2D<int> arr1(arr);
  Dg::VariableArray2D<int> arr2 = arr;

  CHECK(arr1(0, 0) == 0);
  CHECK(arr1(0, 1) == 1);
  CHECK(arr1(0, 2) == 2);
  CHECK(arr1(1, 0) == 3);
  CHECK(arr1(1, 1) == 4);
  CHECK(arr1(2, 0) == 5);
  CHECK(arr1(2, 1) == 6);
  CHECK(arr1(2, 2) == 7);
  CHECK(arr1(2, 3) == 8);
  CHECK(arr1(3, 0) == 9);
  CHECK(arr1(4, 0) == 10);
  CHECK(arr1(4, 1) == 11);
  CHECK(arr1(4, 2) == 12);
  CHECK(arr1(4, 3) == 13);
  CHECK(arr1(4, 4) == 14);

  CHECK(arr2(0, 0) == 0);
  CHECK(arr2(0, 1) == 1);
  CHECK(arr2(0, 2) == 2);
  CHECK(arr2(1, 0) == 3);
  CHECK(arr2(1, 1) == 4);
  CHECK(arr2(2, 0) == 5);
  CHECK(arr2(2, 1) == 6);
  CHECK(arr2(2, 2) == 7);
  CHECK(arr2(2, 3) == 8);
  CHECK(arr2(3, 0) == 9);
  CHECK(arr2(4, 0) == 10);
  CHECK(arr2(4, 1) == 11);
  CHECK(arr2(4, 2) == 12);
  CHECK(arr2(4, 3) == 13);
  CHECK(arr2(4, 4) == 14);
}