Exemple #1
0
int main()
{
    int n = 1e7;
    printf("initializing v...\n");
    std::vector<double> &v = init_vector(n);
    double *a = &(v[0]);
    clock_t t;
    printf("done.\n");
    t = clock();
    printf("sum0: %f\n", sum0(a, n));
    printf("time: %d\n", clock() - t);
    t = clock();
    printf("sum1: %f\n", sum1(v));
    printf("time: %d\n", clock() - t);
    t = clock();
    printf("sum2: %f\n", sum2(v));
    printf("time: %d\n", clock() - t);
    t = clock();
    printf("sum3: %f\n", sum3(v));
    printf("time: %d\n", clock() - t);
    t = clock();
    printf("sum4: %f\n", sum4(v));
    printf("time: %d\n", clock() - t);
    return 0;
}
void Event_test::callOnce()
{
  ThreadSafeCounter count("gov.fnal.counter");
  bool wasChanged=false;
  
  AccessTestingProd* at(new AccessTestingProd("access","",demo::kThreadSafeBetweenInstances,count,wasChanged));
  std::vector<std::pair<std::string, std::string> > toGet;
  toGet.push_back(std::pair<std::string,std::string>("access",""));
  SumSyncProd* sum1(new SumSyncProd("sum1","",toGet));
  SumSyncProd* sum2(new SumSyncProd("sum2","",toGet));

  toGet.clear();
  toGet.push_back(std::pair<std::string,std::string>("sum1",""));
  toGet.push_back(std::pair<std::string,std::string>("sum2",""));
  SumSyncProd* sum3(new SumSyncProd("sum3","",toGet));

  demo::Event event;
  event.setIndex(1);
  
  event.addProducer(at);
  event.addProducer(sum1);
  event.addProducer(sum2);
  event.addProducer(sum3);
  
  CPPUNIT_ASSERT(event.get("sum3","")==2);
  CPPUNIT_ASSERT(count.value()==1);
  CPPUNIT_ASSERT(wasChanged==false);
}
Exemple #3
0
int main(void){
  long input[6] = {1,2,3,4,5,6};
  long size_in = 6;
  long out[6] = {0,0,0,0,0};
  long stopien = 1;
  int i;
 
  printf("Tablica in:\n");  
  for( i=0;i<6;i++)
    printf("%d = %ld\n", i ,input[i]);
 

  printf("\nStopien %d\n", stopien);
  deriv(input, size_in, out, stopien);

 
  printf("\nTablica out\n");
  for(i =  0; i<6;i++)
    printf("el %d = %ld\n", i, out[i]); 


  printf("\nsuma trzech doubli\n");
  printf(" 6.5 + 4.5 + 5.5 = %f\n", sum3(6.5,5.5,4.5));


  return 0;
}
Exemple #4
0
void BiorCoefTests()
{
    wave_object obj;
    double epsilon = 1e-10;
    double t1,t2,t3,t4,t5,t6;
    std::vector<std::string > waveletNames;
    waveletNames.push_back("bior1.1");
    waveletNames.push_back("bior1.3");
    waveletNames.push_back("bior1.5");
    waveletNames.push_back("bior2.2");
    waveletNames.push_back("bior2.4");
    waveletNames.push_back("bior2.6");
    waveletNames.push_back("bior2.8");
    waveletNames.push_back("bior3.1");
    waveletNames.push_back("bior3.3");
    waveletNames.push_back("bior3.5");
    waveletNames.push_back("bior3.7");
    waveletNames.push_back("bior3.9");
    waveletNames.push_back("bior4.4");
    waveletNames.push_back("bior5.5");
    waveletNames.push_back("bior6.8");

    for (unsigned int j = 0; j < waveletNames.size(); j++)
    {
        char * name = new char[waveletNames[j].size() + 1];
        memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
        obj = wave_init(name);// Initialize the wavelet
        
        t1 = sum1(obj->lpr, obj->lpr_len) - sqrt(2.0);
        t2 = sum1(obj->lpd, obj->lpd_len) - sqrt(2.0);
        
        t3 = sum2(obj->lpr, obj->lpr_len) - 1. / sqrt(2.0);
        t4 = sum2(obj->lpd, obj->lpd_len) - 1. / sqrt(2.0);
        
        t5 = sum3(obj->lpr, obj->lpr_len) - 1. / sqrt(2.0);
        t6 = sum3(obj->lpd, obj->lpd_len) - 1. / sqrt(2.0);
        
        if (fabs(t1) > epsilon || fabs(t2) > epsilon || fabs(t3) > epsilon || fabs(t4) > epsilon || fabs(t5) > epsilon || fabs(t6) > epsilon ) {
			printf("\n ERROR : Bior Coefficients Unit Test Failed. Exiting. \n");
			exit(-1);
		}
        
        
        wave_free(obj);
        delete[] name;
    }
}
Exemple #5
0
int main() {
  int a[] = {1, 2, 3, 5, 8};
  printf("%d\n", sum0(a)); // 错误
  printf("%d\n", sum1(a, 5));
  printf("%d\n", sum2(a, a+5));
  printf("%d\n", sum3(a, a+5));
  return 0;
}
Exemple #6
0
int main(){
	int a[] = {1,2,3,4,5};
	int t = sum(a, 5);
	int t1 = sum1(a, 5);
	int t2 = sum2(a, 5);
	int t3 = sum3(a, 5);
	printf("t = %d\nt1 = %d\nt2 = %d\nt3 = %d\n", t, t1, t2, t3);
	return t;
}
Exemple #7
0
void calc_sum(const uint_t &n) 
{
    std::ofstream ofs(OUTPUT);
    uint_t res = 0;

    if(ofs.is_open()) {
        res = sum3(n);
        ofs << res;
        ofs.close();
    }
}
Exemple #8
0
int solve(LL n, int k) {
    if(!k)
        return sum3(n);
    if(n <= pr[k - 1])
        return n > 0;
    if(n < maxn) {
        if(c[n] <= k)
            return n > 0;
        if(c[(int)sqrt(n)] <= k)
        	return (s[n] - s[pr[k - 1]] + (n > 0)) % mod;
    }
    return (solve(n, k - 1) - (LL)cub(pr[k - 1]) * solve(n / pr[k - 1], k - 1)) % mod;
}
 vector<int> maxSumOfThreeSubarrays(vector<int>& nums, int k) {
     vector<int> sum(nums.size() + 1);
     sum[0] = 0;
     for(int i=0; i<nums.size(); i++)
         sum[i+1] = sum[i] + nums[i];
     
     vector<int> sum1(nums.size(), 0), sum2(nums.size(), 0), sum3(nums.size(), 0);
     vector<vector<int>> result1(nums.size()), result2(nums.size()), result3(nums.size());
     
     for(int i=k-1; i < (nums.size() - (2 * k)); i++) {
         if(sum1[i-1] < sum[i+1] - sum[i-k+1]) {
             sum1[i] = sum[i+1] - sum[i-k+1];
             result1[i].push_back(i-k+1);
         }
         else {
             sum1[i] = sum1[i-1];
             result1[i] = result1[i-1];
         }
         //sum1[i] = max(sum1[i-1], sum[i+1] - sum[i-k+1]);
     }
     for(int i=(2*k)-1; i < (nums.size() - k); i++) {
         if(sum2[i-1] < sum1[i-k] + sum[i+1] - sum[i-k+1]) {
             sum2[i] = sum1[i-k] + sum[i+1] - sum[i-k+1];
             result2[i] = result1[i-k];
             result2[i].push_back(i-k+1);
         }
         else {
             sum2[i] = sum2[i-1];
             result2[i] = result2[i-1];
         }
         //sum2[i] = max(sum2[i-1], sum1[i-k] + sum[i+1] - sum[i-k+1]);
     }
     for(int i=(3*k)-1; i < nums.size(); i++) {
         if(sum3[i-1] < sum2[i-k] + sum[i+1] - sum[i-k+1]) {
             sum3[i] = sum2[i-k] + sum[i+1] - sum[i-k+1];
             result3[i] = result2[i-k];
             result3[i].push_back(i-k+1);
         }
         else {
             sum3[i] = sum3[i-1];
             result3[i] = result3[i-1];
         }
         //sum3[i] = max(sum3[i-1], sum2[i-k] + sum[i+1] - sum[i-k+1]);
     }
     
     return result3[nums.size()-1];
 }
Exemple #10
0
int main()
{
	int i;
	for (i = 0; i < N; i++)
		a[i] = rand() % 1000;

	preprocess3();
	printf("%d\n", sum3(0, 20));
	printf("%d\n", sum3(10, 100));
	printf("%d\n", sum3(5, 500));
	printf("%d\n", sum3(0, 0));
	printf("%d\n", sum3(N - 1, N));
	printf("%d\n", sum3(0, N));
	printf("%d\n", sum3(1, 0));
	return 0;
}
Exemple #11
0
void CoifCoefTests()
{
    wave_object obj;
    double epsilon = 1e-15;
    double t1,t2,t3,t4,t5;
    std::vector<std::string > waveletNames;
    waveletNames.resize(17);
    for (unsigned int i = 0; i < waveletNames.size(); i++)
    {
        waveletNames[i] = std::string("coif") + patch::to_string(i + 1);
    }

    for (unsigned int j = 0; j < waveletNames.size(); j++)
    {
        char * name = new char[waveletNames[j].size() + 1];
        memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
        obj = wave_init(name);// Initialize the wavelet
        t1 = sum1(obj->lpr, obj->lpr_len) - sqrt(2.0);
        t2 = sum2(obj->lpr, obj->lpr_len) - 1. / sqrt(2.0);
        t3 = sum3(obj->lpr, obj->lpr_len) - 1. / sqrt(2.0);
        t4 = sum4(obj->lpr, obj->lpr_len) - 1.;
        
        if (fabs(t1) > epsilon || fabs(t2) > epsilon || fabs(t3) > epsilon || fabs(t4) > epsilon) {
			printf("\n ERROR : Coif Coefficients Unit Test Failed. Exiting. \n");
			exit(-1);
		}
        
        for (int m = 1; m < (obj->lpr_len / 2) - 1;m++) {
			t5 = sum5(obj->lpr, obj->lpr_len, m);
            if (fabs(t5) > epsilon) {
				printf("\n ERROR : Coif Coefficients Unit Test Failed. Exiting. \n");
				exit(-1);
			}
		}
        wave_free(obj);
        delete[] name;
    }
}
void Event_test::simultaneousThreadUnsafeOneEvent()
{
  ThreadSafeCounter count("gov.fnal.counter");
  bool wasChanged=false;
  
  AccessTestingProd* at1(new AccessTestingProd("access1","",demo::kThreadUnsafe,count,wasChanged));
  AccessTestingProd* at2(new AccessTestingProd("access2","",demo::kThreadUnsafe,count,wasChanged));
  std::vector<std::pair<std::string, std::string> > toGet;
  toGet.push_back(std::pair<std::string,std::string>("access1",""));
  toGet.push_back(std::pair<std::string,std::string>("access2",""));
  SumGetterProd* sum3(new SumGetterProd("sum3","",toGet));
  
  demo::Event event;
  event.setIndex(1);
  
  event.addProducer(at1);
  event.addProducer(at2);
  event.addProducer(sum3);
  
  CPPUNIT_ASSERT(event.get("sum3","")==2);
  CPPUNIT_ASSERT(count.value()==2);
  CPPUNIT_ASSERT(wasChanged==false);
}
Exemple #13
0
int main() {
	f2(sum3());

	void ablabla3;
	f2(ablabla3);
 }