Example #1
0
int
test_main(int,char*[])
{
  const int ndims=3;
  typedef boost::multi_array_ref<int,ndims> array_ref;

  boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};

  int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
                 14,15,16,17,18,19,20,21,22,23};

  array_ref sma(data,sma_dims);

  //
  // subarray dims:
  // [base,stride,bound)
  // [0,1,2), [1,1,3), [0,2,4) 
  // 
  
  const array_ref& csma = sma;
  typedef array_ref::index_range range;
  array_ref::index_gen indices;
  array_ref::array_view<ndims>::type csma2 =
    csma[indices[range(0,2)][range(1,3)][range(0,4,2)]];

  for (array_ref::index i = 0; i != 2; ++i)
    for (array_ref::index j = 0; j != 2; ++j)
      for (array_ref::index k = 0; k != 2; ++k)
        csma2[i][j][k] = 0; // FAIL! csma2 is read only
  
  return boost::exit_success;
}
int
main()
{
  const int ndims=3;
  typedef boost::multi_array_ref<int,ndims> array_ref;

  boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};

  int data[] = {77,77,77,77,77,77,77,77,77,77,77,77, 
                 77,77,77,77,77,77,77,77,77,77,77,77}; 

  array_ref sma(data,sma_dims);

  int num = 0;
  for (array_ref::index i = 0; i != 2; ++i)
    for (array_ref::index j = 0; j != 3; ++j)
      for (array_ref::index k = 0; k != 4; ++k)
        sma[i][j][k] = num++;

  const array_ref& sma_const = sma;

  array_ref::const_subarray<ndims-1>::type sba = sma_const[0];

    for (array_ref::index j = 0; j != 3; ++j)
      for (array_ref::index k = 0; k != 4; ++k)
        sba[j][k] = num++; // FAIL! can't assign to const_subarray.

  return boost::report_errors();
}
Example #3
0
int
test_main(int,char*[])
{
  const int ndims=3;
  typedef boost::multi_array<int,ndims> array;

  boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
  array sma(sma_dims);

  int num = 0;
  for (array::index i = 0; i != 2; ++i)
    for (array::index j = 0; j != 3; ++j)
      for (array::index k = 0; k != 4; ++k)
        sma[i][j][k] = num++;

  const array& sma_const = sma;

  array::const_subarray<ndims-1>::type sba = sma_const[0];

    for (array::index j = 0; j != 3; ++j)
      for (array::index k = 0; k != 4; ++k)
        // FAIL! sba cannot be assigned to.
        sba[j][k] = num++;

  return boost::exit_success;
}
Example #4
0
int
test_main(int,char*[])
{
  const int ndims=3;
  typedef boost::multi_array<int,ndims> array;

  boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};

  int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
                 14,15,16,17,18,19,20,21,22,23};
  const int data_size = 24;

  array sma(sma_dims);
  sma.assign(data,data+data_size);

  //
  // subarray dims:
  // [base,stride,bound)
  // [0,1,2), [1,1,3), [0,2,4) 
  // 
  
  const array& csma = sma;
  typedef array::index_range range;
  array::index_gen indices;
  // FAIL! preserve constness (no const_array_view -> array_view).
  array::array_view<ndims>::type csma2 =
    csma[indices[range(0,2)][range(1,3)][range(0,4,2)]];

  return boost::exit_success;
}
Example #5
0
int
test_main(int,char*[])
{
  const int ndims=3;
  typedef boost::multi_array_ref<int,ndims> array_ref;

  boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};

  int data[] = {77,77,77,77,77,77,77,77,77,77,77,77, 
                 77,77,77,77,77,77,77,77,77,77,77,77}; 

  array_ref sma(data,sma_dims);

  int num = 0;
  for (array_ref::index i = 0; i != 2; ++i)
    for (array_ref::index j = 0; j != 3; ++j)
      for (array_ref::index k = 0; k != 4; ++k)
        sma[i][j][k] = num++;

  const array_ref& sma_const = sma;

  array_ref::subarray<ndims-1>::type sba = sma_const[0]; // FAIL!
                                                         // preserve constness

  return boost::exit_success;
}
Example #6
0
 Trigger(uhd::usrp::multi_usrp::sptr usrp, const std::vector<size_t> channels, const int samples, const std::string gating)
 :
 channels {channels},
 usrp {usrp},
 gating {gating}
 {
     for(const auto ch : channels)
         apply(sma(ch, samples));
 }
Example #7
0
int
test_main(int,char*[])
{
  const int ndims=3;
  typedef boost::multi_array_ref<int,ndims> array_ref;

  boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
  int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
                 14,15,16,17,18,19,20,21,22,23};
  array_ref sma(data,sma_dims);

  const array_ref& csma = sma;

  // FAIL! data() returns const int*.
  *csma.data() = 0;
  return boost::exit_success;
}
Example #8
0
int
test_main(int,char*[])
{
  const int ndims=3;
  typedef boost::multi_array_ref<int,ndims> array_ref;

  boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};

  int data[] = {77,77,77,77,77,77,77,77,77,77,77,77, 
                 77,77,77,77,77,77,77,77,77,77,77,77}; 

  array_ref sma(data,sma_dims);
  

  const array_ref& csma = sma;

  // FAIL! can't assign to const multi_array_ref.
  csma[0][0][0] = 5;

  return boost::exit_success;
}
Example #9
0
int
test_main(int,char*[])
{
  const int ndims=3;
  typedef boost::multi_array<int,ndims> array;

  boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
  array sma(sma_dims);

  int num = 0;
  for (array::index i = 0; i != 2; ++i)
    for (array::index j = 0; j != 3; ++j)
      for (array::index k = 0; k != 4; ++k)
        sma[i][j][k] = num++;


  array::const_subarray<ndims-1>::type csba = sma[0];

  // FAIL! Preserve constness (no const_subarray -> subarray conversion).
  array::subarray<ndims-1>::type sba = csba;

  return boost::exit_success;
}
Example #10
0
 ~Trigger()
 {
     for(const auto ch : channels)
         apply(sma(ch, 0));
 }
Example #11
0
	void loop(int dir)
		try
	{
		if (opt_.verbose) cybozu::PutLog(cybozu::LogInfo, "loop %d start", dir);
		assert(dir == 0 || dir == 1);
		cybozu::Socket &from = s_[dir];
		cybozu::Socket &to = s_[1 - dir];
		const bool needShutdown = dir == 1;
		const int intervalSec = 3;
		SMAverage sma(intervalSec);
		std::vector<char> buf(12 * 1024);
		while (!g_quit) {
			switch ((int)state_) {
			case Sleep:
				waitMsec(10);
				continue;
			case Ready:
				waitMsec(1);
				continue;
			case Error:
				if (!to.isValid()) {
					if (opt_.verbose) cybozu::PutLog(cybozu::LogInfo, "loop %d %d toSleep", dir, (int)state_);
					state_ = Sleep;
				} else {
					waitMsec(1);
				}
				break;
			case Running:
				if (!from.isValid()) {
					cybozu::PutLog(cybozu::LogInfo, "loop %d %d from is not valid", dir, (int)state_);
					state_ = Error;
					continue;
				}
				try {
					while (!from.queryAccept()) {
					}
					if (g_quit) break;
					const size_t readSize = from.readSome(buf.data(), buf.size());
					if (opt_.verbose) cybozu::PutLog(cybozu::LogInfo, "loop %d %d readSize %d", dir, (int)state_, (int)readSize);
					if (opt_.rateMbps > 0) {
						sma.append(readSize, getCurTimeSec());
						while (sma.getBps(getCurTimeSec()) * 1e-6 > opt_.rateMbps) {
							waitMsec(10);
						}
					}
					if (readSize > 0) {
						if (!g_stop && to.isValid()) to.write(buf.data(), readSize);
						continue;
					}
				} catch (std::exception& e) {
					cybozu::PutLog(cybozu::LogInfo, "loop %d %d ERR %s", dir, (int)state_, e.what());
					state_ = Error;
					from.close();
					continue;
				}
				if (needShutdown) {
					if (opt_.verbose) cybozu::PutLog(cybozu::LogInfo,"loop %d %d shutdown", dir, (int)state_);
					const bool dontThrow = true;
					to.shutdown(1, dontThrow); // write disallow
				}
				if (opt_.verbose) cybozu::PutLog(cybozu::LogInfo, "loop %d %d close", dir, (int)state_);
				from.close();
				if (opt_.verbose) cybozu::PutLog(cybozu::LogInfo, "loop %d %d isValid %d", dir, (int)state_, from.isValid());
				break;
			}
		}
		if (opt_.verbose) cybozu::PutLog(cybozu::LogInfo, "loop %d end", dir);
	} catch (...) {
		ep_ = std::current_exception();
		s_[0].close();
		s_[1].close();
		state_ = Sleep;
	}
Example #12
0
double ao(QVector<bid*> vec,int ind){
    return sma(vec,ind,34)-sma(vec,ind,5);
}
Example #13
0
 void loop(int dir)
     try
 {
     if (opt_.verbose) cybozu::PutLog(cybozu::LogInfo, "[%d] loop %d start", id_, dir);
     assert(dir == 0 || dir == 1);
     cybozu::Socket &from = s_[dir];
     cybozu::Socket &to = s_[1 - dir];
     const int intervalSec = 3;
     SMAverage sma(intervalSec);
     std::vector<char> buf(1024);
     while (!g_quit) {
         switch ((int)state_) {
         case Sleep:
             waitMsec(10);
             continue;
         case Ready:
             waitMsec(1);
             continue;
         case Running2:
         case Running1:
             if (!from.isValid()) {
                 waitMsec(1);
                 continue;
             }
             try {
                 while (!g_quit && !from.queryAccept()) {
                 }
                 if (g_quit) continue;
                 size_t readSize = from.readSome(buf.data(), buf.size());
                 if (opt_.rateMbps > 0) {
                     sma.append(readSize, cybozu::GetCurrentTimeSec());
                     while (double rate = sma.getBps(cybozu::GetCurrentTimeSec()) > opt_.rateMbps * 1e6) {
                         if (opt_.verbose) cybozu::PutLog(cybozu::LogDebug, "[%d] loop %d %d rate %f", id_, dir, (int)state_, rate);
                         waitMsec(1);
                     }
                 }
                 if (readSize > 0) {
                     if (!g_stop && to.isValid()) {
                         if (opt_.delaySec) {
                             waitMsec(opt_.delaySec * 1000);
                         }
                         to.write(buf.data(), readSize);
                     }
                 } else {
                     to.shutdown(1, dontThrow); // write disallow
                     from.close();
                     state_--;
                 }
             } catch (std::exception& e) {
                 cybozu::PutLog(cybozu::LogInfo, "[%d] loop %d %d ERR %s", id_, dir, (int)state_, e.what());
                 from.close(dontThrow);
                 state_--;
             }
             break;
         case Running0:
             {
                 int expected = Running0;
                 state_.compare_exchange_strong(expected, Sleep);
             }
             break;
         }
     }
     if (opt_.verbose) cybozu::PutLog(cybozu::LogInfo, "[%d] loop %d end", id_, dir);
 } catch (std::exception& e) {
     cybozu::PutLog(cybozu::LogError, "[%d] caught an error and terminate: %s", id_, e.what());
     exit(1);
 }