Пример #1
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;
}
Пример #2
0
int test_colt_nested_cells()
{
	char *outer1[] = { "1962", "1977", "1989", "2010" };
	char *outer2[] = { "1990", "2001", "2008", "2015" };
	char *outer3[] = { "1993", "2001", "2009", "2013" };

	char *inner1[] = { "Jan", "Feb", "March" };
	char *inner2[] = { "Apr", "May", "June" };
	char *inner3[] = { "July", "August", "September" };
	char *inner4[] = { "October", "November", "December" };

	char *deep1[] = { "14", "9", "2" };
	char *deep2[] = { "25", "4", "0" };

	char *head1[] = { "Birth", "start", "better", "bests" };
	char *head2[] = { "Mon1", "mon2", "Month3" };
	char *head3[] = { "father", "daughter", "son" };

	colt_nested_cells deepest1(deep1, 3, head3, "days");
	colt_nested_cells deepest2(deep2, 3, head3, "days");

	colt_nested_cells in11(inner1, 3, head2, "Months", &deepest1);
	colt_nested_cells in12(inner1, 3, head2, "Months", &deepest2);
	colt_nested_cells in2(inner2, 3, head2, "Months");
	colt_nested_cells in3(inner3, 3, head2, "Months");
	colt_nested_cells in4(inner4, 3, head2, "Months");

	colt_nested_cells out11(outer1, 4, head1, "Dates", &in11);
	colt_nested_cells out11a(outer1, 4, head1, "Dates", &in12);
	colt_nested_cells out12(outer1, 4, head1, "Dates", &in2);
	colt_nested_cells out13(outer1, 4, head1, "Dates", &in3);

	colt_nested_cells out21(outer2, 4, head1, "Dates", &in4);
	colt_nested_cells out22(outer2, 4, head1, "Dates", &in3);
	colt_nested_cells out23(outer2, 4, head1, "Dates", &in11);

	colt_nested_cells out31(outer3, 4, head1, "Dates", &in2);
	colt_nested_cells out32(outer3, 4, head1, "Dates", &in11);
	colt_nested_cells out33(outer3, 4, head1, "Dates", &in4);

	std::ofstream mine("mine.yml");
//	out11.start();
	out11.nested_output(NULL, 0, &mine);
	out11a.nested_output(&out11, 0, &mine);
	out12.nested_output(&out11a, 0, &mine);

	out23.nested_output(&out12, 0, &mine);
	out21.nested_output(&out23, 0, &mine);
	out22.nested_output(&out21, 0, &mine);

	out31.nested_output(&out22, 0, &mine);
	out32.nested_output(&out31, 0, &mine);
	out33.nested_output(&out32, 0, &mine);

//	out13.end(xxx+1);
//	out11.end();

}
Пример #3
0
int main(int argc, char **argv){
  if(argc<2){err("Need a file to serve\n");}
  if(argc<3){err("Need a port\n");}
  fd=open(argv[1],O_RDWR|O_SYNC); if(-1==fd){err("Couldn't open file\n");};
  int port=atoi(argv[2]);

  s = socket(AF_INET, SOCK_STREAM, 0);
  E(s);
  my_addr.sin_family = AF_INET;
  my_addr.sin_port = htons(port);
  my_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  memset(&(my_addr.sin_zero), '\0', 8);
  E(bind(s, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)));
  E(listen(s,0));
  s2 = accept(s,NULL,NULL);
  E(s2);
  int y=1,n=0;
  E(setsockopt(s2, SOL_SOCKET, SO_REUSEADDR, &y, sizeof(y) ));
  E(setsockopt(s2, IPPROTO_TCP, TCP_NODELAY, &y, sizeof(y) ));

  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;
}
// test to run processing/example.py
TEST_F(SignalProcessingInterfaceTest, exampleTest) {
    android::String8 functionName("example");
    int nInputs = 8;
    int nOutputs = 4;
    bool inputTypes[8] = { true, true, true, true, false, false, false, false };
    bool outputTypes[4] = { true, true, false, false };

    android::sp<Buffer> in0(new Buffer(16, 16, true));
    char* data0 = in0->getData();
    for (size_t i = 0; i < in0->getSize(); i++) {
        data0[i] = i;
    }
    android::sp<Buffer> in1(new Buffer(16, 16, true));
    char* data1 = in1->getData();
    for (size_t i = 0; i < in1->getSize(); i++) {
        data1[i] = i;
    }
    android::sp<Buffer> in2(new Buffer(8, 8, false));
    char* data2 = in2->getData();
    for (size_t i = 0; i < in2->getSize(); i++) {
        data2[i] = i;
    }
    android::sp<Buffer> in3(new Buffer(8, 8, false));
    char* data3 = in3->getData();
    for (size_t i = 0; i < in3->getSize(); i++) {
        data3[i] = i;
    }
    TaskCase::Value in4((int64_t)100);
    TaskCase::Value in5((int64_t)100);
    TaskCase::Value in6(1.0f);
    TaskCase::Value in7(1.0f);
    void* inputs[8] = { &in0, &in1, &in2, &in3, &in4, &in5, &in6, &in7 };

    android::sp<Buffer> out0(new Buffer(16, 16, true));
    char* outdata0 = out0->getData();
    for (size_t i = 0; i < out0->getSize(); i++) {
        outdata0[i] = 0xaa;
    }
    android::sp<Buffer> out1(new Buffer(8, 8, false));
    char* outdata1 = out1->getData();
    for (size_t i = 0; i < out1->getSize(); i++) {
        outdata1[i] = 0xbb;
    }
    TaskCase::Value out2((int64_t)1000);
    TaskCase::Value out3(-1.0f);
    void *outputs[4] = { &out0, &out1, &out2, &out3 };

    ASSERT_TRUE(mSp->run( functionName,
            nInputs, inputTypes, inputs,
            nOutputs, outputTypes, outputs) == TaskGeneric::EResultOK);
    ASSERT_TRUE(*(in0.get()) == *(out0.get()));
    ASSERT_TRUE(*(in2.get()) == *(out1.get()));
    ASSERT_TRUE(in4 == out2);
    ASSERT_TRUE(in6 == out3);
}
Пример #5
0
TEST(RealWordTest, OR)
{
  typedef NeuralNetwork<double, StepActivationFunction<double >> network;
  network nn;
  nn.setEntries(2);
  nn.setExits(1);
  nn.setLayersCount(1);
  nn.init();
  std::vector<double> in1(2);
  std::vector<double> in2(2);
  std::vector<double> in3(2);
  std::vector<double> in4(2);
  in1[0] = 0;
  in1[1] = 0;
  in2[0] = 1;
  in2[1] = 0;
  in3[0] = 0;
  in3[1] = 1;
  in4[0] = 1;
  in4[1] = 1;
  std::vector<double> out0(1);
  std::vector<double> out1(1);
  out0[0] = 0;
  out1[0] = 1;
  //uczenie
  for (int i = 0; i < 100; ++i)
  {
    nn.setInput(in1.begin(), in1.end());
    nn.calcOutput();
    nn.learn(out0.begin(), out0.end());
    nn.setInput(in2.begin(), in2.end());
    nn.calcOutput();
    nn.learn(out1.begin(), out1.end());
    nn.setInput(in3.begin(), in3.end());
    nn.calcOutput();
    nn.learn(out1.begin(), out1.end());
    nn.setInput(in4.begin(), in4.end());
    nn.calcOutput();
    nn.learn(out1.begin(), out1.end());
  }
  //test
  std::vector<double> out;
  nn.setInput(in1.begin(), in1.end());
  out = nn.calcOutput();
  ASSERT_EQ(out[0], 0);
  nn.setInput(in2.begin(), in2.end());
  out = nn.calcOutput();
  ASSERT_EQ(out[0], 1);
  nn.setInput(in3.begin(), in3.end());
  out = nn.calcOutput();
  ASSERT_EQ(out[0], 1);
  nn.setInput(in4.begin(), in4.end());
  out = nn.calcOutput();
  ASSERT_EQ(out[0], 1);
}
Пример #6
0
//void yacobi_process(double* xk0, const int mnum, const int proc_num, const double eps)
int main(int argc, char* argv[])
{
	if(argc != 2 || !isdigit(argv[1][0]))
	{
		printf("No argument number of process\nUsage: yacobi_starter 4\n");
		return 0;
	}
	init(argv, 0, 0, 0, true, false);
	std::vector<double> x0 = {0, 0 , 0, 0, 0};
	int proc_num = atoi(argv[1]),
		matr_num = 3;
	double eps = 0.00001;
	const char grname[] = "group1";
	input<double*> in1(1, 1, x0.data(), x0.size());
	input<int> in2(2, 1, matr_num, 1);
	input<int> in3(3, 1, proc_num, 1);
	input<double> in4(4, 1, eps, 1);

	INSTANTINATE(":prog_yacobi", "group1", 1, in1, in2, in3, in4);
	return 0;
}
Пример #7
0
TEST(RealWordTest, ORLinear)
{
  typedef NeuralNetwork<double, LinearActivationFunction<double >> network;
  network nn;
  nn.setEntries(2);
  nn.setExits(1);
  nn.setLayersCount(1);
  nn.init();
  std::vector<double> in1(2);
  std::vector<double> in2(2);
  std::vector<double> in3(2);
  std::vector<double> in4(2);
  in1[0] = 0;
  in1[1] = 0;
  in2[0] = 1;
  in2[1] = 0;
  in3[0] = 0;
  in3[1] = 1;
  in4[0] = 1;
  in4[1] = 1;
  std::vector<double> out0(1);
  std::vector<double> out1(1);
  out0[0] = 0;
  out1[0] = 1;
  //uczenie
  for (int i = 0; i < 1000; ++i)
  {
    std::vector<double> o;
    //   nn.printWages();
    nn.setInput(in1.begin(), in1.end());
    o = nn.calcOutput();
    //    for (auto d : o)
    //    {
    //      std::cout << d << " :answer 0 0 \n";
    //    }
    nn.learn(out0.begin(), out0.end());
    nn.setInput(in2.begin(), in2.end());
    o = nn.calcOutput();
    //    for (auto d : o)
    //    {
    //      std::cout << d << " :answer 1 0 \n";
    //    }
    nn.learn(out1.begin(), out1.end());
    nn.setInput(in3.begin(), in3.end());
    o = nn.calcOutput();
    //    for (auto d : o)
    //    {
    //      std::cout << d << " :answer 0 1 \n";
    //    }
    nn.learn(out1.begin(), out1.end());
    nn.setInput(in4.begin(), in4.end());
    o = nn.calcOutput();
    //    for (auto d : o)
    //    {
    //      std::cout << d << " :answer 1 1 \n";
    //    }
    nn.learn(out1.begin(), out1.end());
  }
  //  nn.printWages();
  //test
  std::vector<double> out;
  nn.setInput(in1.begin(), in1.end());
  out = nn.calcOutput();
  ASSERT_LT(out[0], 0.1);
  nn.setInput(in2.begin(), in2.end());
  out = nn.calcOutput();
  ASSERT_GT(out[0], 0.9);
  nn.setInput(in3.begin(), in3.end());
  out = nn.calcOutput();
  ASSERT_GT(out[0], 0.9);
  nn.setInput(in4.begin(), in4.end());
  out = nn.calcOutput();
  ASSERT_GT(out[0], 0.9);

}
Пример #8
0
TEST(RealWordTest, XORLinear)
{
  typedef NeuralNetwork<double, LinearActivationFunction<double >> network;
  network nn;
  //nn.setActivationfunction(LinearActivationFunction<double>(10));
  nn.setEntries(2);
  nn.setExits(1);
  nn.setLayersCount(2);
  nn.setNeurons(1, 2);
  nn.init();
  std::vector<double> in1(2);
  std::vector<double> in2(2);
  std::vector<double> in3(2);
  std::vector<double> in4(2);
  in1[0] = 0;
  in1[1] = 0;
  in2[0] = 1;
  in2[1] = 0;
  in3[0] = 0;
  in3[1] = 1;
  in4[0] = 1;
  in4[1] = 1;
  std::vector<double> out0(1);
  std::vector<double> out1(1);
  out0[0] = 0;
  out1[0] = 1;
  //uczenie
  for (int i = 0; i < 1000; ++i)
  {
    std::vector<double> o(1);

    nn.setInput(in1.begin(), in1.end());
    o = nn.calcOutput();
    nn.learn(out0.begin(), out0.end());
    //
    //    std::cout << "Wynik0: " << o[0] << "\n";
    //    nn.printWages();

    nn.setInput(in2.begin(), in2.end());
    o = nn.calcOutput();
    nn.learn(out1.begin(), out1.end());
    //
    //    std::cout << "Wynik1: " << o[0] << "\n";
    //    nn.printWages();

    nn.setInput(in3.begin(), in3.end());
    o = nn.calcOutput();
    nn.learn(out1.begin(), out1.end());
    //
    //    std::cout << "Wynik1: " << o[0] << "\n";
    //    nn.printWages();

    nn.setInput(in4.begin(), in4.end());
    o = nn.calcOutput();
    nn.learn(out0.begin(), out0.end());
    //
    //    std::cout << "Wynik0: " << o[0] << "\n";
    //    nn.printWages();

  }
  //test
  std::vector<double> out;
  std::vector<double> o(4);
  nn.setInput(in1.begin(), in1.end());
  out = nn.calcOutput();
  o[0] = out[0];
  EXPECT_LT(out[0], 0.1);
  nn.setInput(in2.begin(), in2.end());
  out = nn.calcOutput();
  o[1] = out[0];
  EXPECT_GT(out[0], 0.9);
  nn.setInput(in3.begin(), in3.end());
  out = nn.calcOutput();
  o[2] = out[0];
  EXPECT_GT(out[0], 0.9);
  nn.setInput(in4.begin(), in4.end());
  out = nn.calcOutput();
  o[3] = out[0];
  EXPECT_LT(out[0], 0.1);

  //std::cout << o[0] << " " << o[1] << " " << o[2] << " " << o[3] << "\n";
}
Пример #9
0
void astar::wczytaj_graf(){
  int id, wg, nr;
  ifstream in1("graf1.txt");
  ifstream in2("graf2.txt");
  ifstream in3("graf3.txt");
  ifstream in4("graf4.txt");
  ifstream in5("graf5.txt");
  ifstream in6("graf6.txt");
   for(int i = 0; i<10; i++)
    G1.dodaj_wierzcholek(i);
  for(int i = 0; i<100; i++)
    G2.dodaj_wierzcholek(i);
  for(int i = 0; i<1000; i++)
    G3.dodaj_wierzcholek(i);
  for(int i = 0; i<10000; i++)
    G4.dodaj_wierzcholek(i);
  for(int i = 0; i<50000; i++)
    G5.dodaj_wierzcholek(i);
  for(int i = 0; i<100000; i++)
    G6.dodaj_wierzcholek(i);

   for(int i = 0; i<10; i++){
    in1>>nr;
    for(int k = 0; k<5; k++){
      in1>>id>>wg;
     
      G1.dodaj_krawedz(i,id);
      
    }
  }
  for(int i = 0; i<100; i++){
    in2>>nr;
    for(int k = 0; k<5; k++){
      in2>>id>>wg;
      G2.dodaj_krawedz(i,id);
    }
  }
  for(int i = 0; i<1000; i++){
    in3>>nr;
    for(int k = 0; k<5; k++){
      in3>>id>>wg;
      G3.dodaj_krawedz(i,id);
    }
  }
  for(int i = 0; i<10000; i++){
    in4>>nr;
    for(int k = 0; k<5; k++){
      in4>>id>>wg;
      G4.dodaj_krawedz(i,id);
    }
  }
  for(int i = 0; i<50000; i++){
    in5>>nr;
    for(int k = 0; k<5; k++){
      in5>>id>>wg;
      G5.dodaj_krawedz(i,id);
    }
  }
  for(int i = 0; i<100000; i++){
    in6>>nr;
    for(int k = 0; k<5; k++){
      in6>>id>>wg;
      G6.dodaj_krawedz(i,id);
    }
  }

}
Пример #10
0
void graf_test::wczytaj_graf(){
  int id, wg, nr;
  ifstream in1("graf1.txt");
  ifstream in2("graf2.txt");
  ifstream in3("graf3.txt");
  ifstream in4("graf4.txt");
  ifstream in5("graf5.txt");
  ifstream in6("graf6.txt");
  for(int i = 0; i<10; i++)
    G1.dodaj_wierzcholek();
  for(int i = 0; i<100; i++)
    G2.dodaj_wierzcholek();
  for(int i = 0; i<1000; i++)
    G3.dodaj_wierzcholek();
  for(int i = 0; i<10000; i++)
    G4.dodaj_wierzcholek();
  for(int i = 0; i<50000; i++)
    G5.dodaj_wierzcholek();
  for(int i = 0; i<100000; i++)
    G6.dodaj_wierzcholek();
 
  /*dodano wierzcholki, teraz tworzymy liste incydencji*/
  for(int i = 0; i<10; i++){
    in1>>nr;
    for(int k = 0; k<5; k++){
      in1>>id>>wg;
      G1.dodaj_krawedz(i,id,wg);
    }
  }
  for(int i = 0; i<100; i++){
    in2>>nr;
    for(int k = 0; k<5; k++){
      in2>>id>>wg;
      G2.dodaj_krawedz(i,id,wg);
    }
  }
  for(int i = 0; i<1000; i++){
    in3>>nr;
    for(int k = 0; k<5; k++){
      in3>>id>>wg;
      G3.dodaj_krawedz(i,id,wg);
    }
  }
  for(int i = 0; i<10000; i++){
    in4>>nr;
    for(int k = 0; k<5; k++){
      in4>>id>>wg;
      G4.dodaj_krawedz(i,id,wg);
    }
  }
  for(int i = 0; i<50000; i++){
    in5>>nr;
    for(int k = 0; k<5; k++){
      in5>>id>>wg;
      G5.dodaj_krawedz(i,id,wg);
    }
  }
  for(int i = 0; i<100000; i++){
    in6>>nr;
    for(int k = 0; k<5; k++){
      in6>>id>>wg;
      G6.dodaj_krawedz(i,id,wg);
    }
  }
 G1.rysuj();
 
}