int run()
 {
    switch(type_)
    {
      case parameter: 
         return main_parameter_(context_);
      case singleton: 
         return main_singleton_();
      default: 
      BOOST_ASSERT_MSG(false, 
                       "boost::application handler type is not "
                       "implemented, must be 'parameter' or "
                       "'singleton' type");
    }
    return 0;
 }
Example #2
0
size_t global_allocator::calculate_mixin_offset(const char* buffer, size_t mixin_alignment)
{
    // now malloc (or new) should make sure to give us memory that's word aligned
    // that means that buffer should be aligned to sizeof(ptr)

    // WARNING: if you don't have a custom allocator and this assert fails
    // this means that memory not-aligned to the pointer size was allocated
    // Thie platform is strange and creepy and is not supported by the default allocator
    // you should write your own, that does allocate properly aligned memory
    BOOST_ASSERT_MSG(uintptr_t(buffer) % sizeof(object*) == 0,
        "allocators should always return memory aligned to sizeof(void*)");

    uintptr_t mixin_pos = ceil_scale(uintptr_t(buffer + sizeof(object*)), mixin_alignment);

    return mixin_pos - uintptr_t(buffer);
}
Example #3
0
void builder::pack(const boost::filesystem::path &src,
                   const boost::filesystem::path &bin,
                   const boost::filesystem::path &archive,
                   const archiver_ptr &archiver_) {
  // prepare empty directories
  filesystem::reset_dir(bin);
  tempfile root_ = tempfile::directory_in_directory(bin);
  tempfile bin_ = tempfile::directory_in_directory(bin);
  root_.auto_remove(false);
  bin_.auto_remove(false);
  // installation
  install(src, bin_.path(), root_.path());
  // packing
  BOOST_ASSERT_MSG(archiver_, "Archiver pointer should not be null");
  archiver_->pack_contents(archive, root_.path());
}
    void LoadStreetNames(const boost::filesystem::path &names_file)
    {
        boost::filesystem::ifstream name_stream(names_file, std::ios::binary);

        name_stream >> m_name_table;

        unsigned number_of_chars = 0;
        name_stream.read((char *)&number_of_chars, sizeof(unsigned));
        BOOST_ASSERT_MSG(0 != number_of_chars, "name file broken");
        m_names_char_list.resize(number_of_chars + 1); //+1 gives sentinel element
        name_stream.read((char *)&m_names_char_list[0], number_of_chars * sizeof(char));
        if (0 == m_names_char_list.size())
        {
            util::SimpleLogger().Write(logWARNING) << "list of street names is empty";
        }
    }
MGallery* MXMLHandler::loadProject(std::string path)
{
    QFile file(QString(path.c_str()));

    if (!file.open(QFile::ReadOnly | QFile::Text))
	return NULL;

    readFile(&file);

    if (!_galleries.size())
	return NULL;

    BOOST_ASSERT_MSG(_galleries.size() == 1, "There must be only one top gallery when exporting.");

    return _galleries.front();
}
Example #6
0
 void calc_beta_loglik(std::string const& prior, std::vector<arma::vec> const& beta_hyperp)
 {
     if (prior == "normal") 
     {
         BOOST_ASSERT_MSG(beta_hyperp.size() == 2, "Beta normal prior expects 2 hyperparameters.");
         loglik_beta = arma::accu( -arma::log(beta_hyperp[1]) - 0.5 * arma::square( (beta - beta_hyperp[0])/beta_hyperp[1]) );
     }
     else if (prior == "flat")
     {
          loglik_beta = 0.0;
     }
     else
     {
         throw std::runtime_error("Unknown prior on beta.");
     }
 }
Example #7
0
File: chol.hpp Project: atyuwen/nt2
    //==========================================================================
    // Return lower formatted result
    //==========================================================================
    typename  meta::
              call< tag::expand_
                    ( typename  meta::call<tag::tril_(data_t const&)>::type
                    , nt2_la_int
                    , nt2_la_int
                    )
                  >::type
    lower_result() const
    {
      BOOST_ASSERT_MSG( (uplo_ == 'L')
                      , "Upper Cholesky can't return lower result"
                      );

      nt2_la_int p = info_ > 0 ? info_-1 : height_;
      return nt2::expand(nt2::tril(values_), p, p);
    }
Example #8
0
unsigned readHSGRFromStream(const boost::filesystem::path &hsgr_file,
                            std::vector<NodeT> &node_list,
                            std::vector<EdgeT> &edge_list,
                            unsigned *check_sum)
{
    if (!boost::filesystem::exists(hsgr_file))
    {
        throw osrm::exception("hsgr file does not exist");
    }
    if (0 == boost::filesystem::file_size(hsgr_file))
    {
        throw osrm::exception("hsgr file is empty");
    }

    boost::filesystem::ifstream hsgr_input_stream(hsgr_file, std::ios::binary);

    FingerPrint fingerprint_loaded, fingerprint_orig;
    hsgr_input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
    if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
    {
        SimpleLogger().Write(logWARNING) << ".hsgr was prepared with different build.\n"
                                            "Reprocess to get rid of this warning.";
    }

    unsigned number_of_nodes = 0;
    unsigned number_of_edges = 0;
    hsgr_input_stream.read((char *)check_sum, sizeof(unsigned));
    hsgr_input_stream.read((char *)&number_of_nodes, sizeof(unsigned));
    BOOST_ASSERT_MSG(0 != number_of_nodes, "number of nodes is zero");
    hsgr_input_stream.read((char *)&number_of_edges, sizeof(unsigned));

    SimpleLogger().Write() << "number_of_nodes: " << number_of_nodes
                           << ", number_of_edges: " << number_of_edges;

    // BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero");
    node_list.resize(number_of_nodes);
    hsgr_input_stream.read((char *)&(node_list[0]), number_of_nodes * sizeof(NodeT));

    edge_list.resize(number_of_edges);
    if (number_of_edges > 0)
    {
        hsgr_input_stream.read((char *)&(edge_list[0]), number_of_edges * sizeof(EdgeT));
    }
    hsgr_input_stream.close();

    return number_of_nodes;
}
Example #9
0
    Box(Eigen::Vector4d &center, Eigen::Vector4d& u, Eigen::Vector4d &v, 
	Eigen::Vector4d &w, unsigned int id, unsigned int matId, 
	double uWidth, double vWidth, double wWidth)
	: QuadricCollection(center, id, matId), u(u), v(v), w(w)  {
	BOOST_ASSERT_MSG(u[3] == 0 && v[3] == 0 && w[3] == 0, "u,v,w must have"
			 " fourth coordinate equal to zero!");//  Got u:\n"
			 // << u << "v:\n" << v << "w:\n" << w)

	// Prepare rotation matrix
	Eigen::Matrix4d R;
	R.row(0) = u;
	R.row(1) =  v;
	R.row(2) =  w;
	R.row(3) = Eigen::Vector4d(0, 0, 0, 1);
	
	/* Make all the planes forming the box (centered at origin). 
	   Plane normals will be unit vectors pointing in positive/negative
	   x, y, z directions. The points x on the plane with normal 
	   n = (a,b,c), distance d to origin satisfy n.p -d = 0, 
	   or x^T Q x = 0 where 
	   Q = |0   0   0   a/2|
	       |0   0   0   b/2|
	       |0   0   0   c/2|
	       |a/2 b/2 c/2  -d|
	  We define planes w.r.t. x, y, z axes, then rotate to u,v,w
	 */
	Eigen::Matrix4d posWPlane, negWPlane, posUPlane, negUPlane,
	    posVPlane, negVPlane;
	posWPlane = negWPlane = posUPlane = negUPlane = posVPlane =  negVPlane
	    = Eigen::Matrix4d::Zero();
	posUPlane.row(3) = posUPlane.col(3) = Eigen::Vector4d(0.5, 0, 0, -uWidth/2.0);
	negUPlane.row(3) = negUPlane.col(3) = Eigen::Vector4d(-0.5, 0, 0, -uWidth/2.0);

	posVPlane.row(3) = posVPlane.col(3) = Eigen::Vector4d(0, 0.5, 0, -vWidth/2.0);
	negVPlane.row(3) = negVPlane.col(3) = Eigen::Vector4d(0, -0.5, 0, -vWidth/2.0);

	posWPlane.row(3) = posWPlane.col(3) = Eigen::Vector4d(0, 0, 0.5, -wWidth/2.0);
	negWPlane.row(3) = negWPlane.col(3) = Eigen::Vector4d(0, 0, -0.5, -wWidth/2.0);

	addQuadric(R.transpose() * posWPlane * R);
	addQuadric(R.transpose() * negWPlane * R);
	addQuadric(R.transpose() * posUPlane * R);
	addQuadric(R.transpose() * negUPlane * R);
	addQuadric(R.transpose() * posVPlane * R);
	addQuadric(R.transpose() * negVPlane * R);
	
    }
Example #10
0
// @return  The IP4 address of the 'net_interface'.
vector<string> NetHelper::getIP4Address(const std::string& net_interface) {
    vector<string> ret_ip4_addr;

    //which family do we require , AF_INET or AF_INET6
    const int fm = AF_INET;

    struct ifaddrs *ifaddr = NULL;
    if (getifaddrs(&ifaddr) == -1) {
        perror("getifaddrs");
        BOOST_ASSERT(false);
        return ret_ip4_addr;
    }


    for (struct ifaddrs *ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
        if (ifa->ifa_addr == NULL) {
            continue;
        }

        bool is_this_netif = (strcmp(ifa->ifa_name, net_interface.c_str()) == 0);
        if (is_this_netif) {
            const int family = ifa->ifa_addr->sa_family;
            if (family == fm) {
                char host[NI_MAXHOST];
                int s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host,
                        NI_MAXHOST, NULL, 0, NI_NUMERICHOST);

                if (s != 0) {
                    ostringstream err;
                    err << "getnameinfo() failed: " << gai_strerror(s);
                    BOOST_ASSERT_MSG(false, err.str().c_str());
                    break;
                }
                else {
                    ret_ip4_addr.push_back(host);
                }
            }
        }
    }

    // clear
    freeifaddrs(ifaddr);
    ifaddr = NULL;

    // return
    return ret_ip4_addr;
}
HRESULT directx_samplegrabber_callback::SampleCB(double time,
                                                 IMediaSample *sample) {
    // Point the image sample to the media sample we have and then set the flag
    // to tell the application it can process it.
    BOOST_ASSERT_MSG(_stayAlive, "Should be alive when samplecb is called");
    sampleExchange_->signalSampleProduced(sample);

    // Wait for either this object to be destroyed/shutdown (_stayAlive ==
    // false), or for the application/consumer to finish with this sample (which
    // would return true from the wait function, rather than false as a timeout
    // does).
    while (_stayAlive &&
           !sampleExchange_->waitForSampleConsumed(WAIT_FOR_CONSUMER_TIMEOUT)) {
    }

    return S_OK;
}
inline session_manager_config::session_manager_config(
    const endpoint_type& the_accepting_endpoint,
    std::size_t the_max_session_count,
    std::size_t the_recycled_session_count,
    std::size_t the_max_stopping_sessions,
    int the_listen_backlog,
    const session_config& the_managed_session_config)
  : listen_backlog(the_listen_backlog)
  , max_session_count(the_max_session_count)
  , recycled_session_count(the_recycled_session_count)
  , max_stopping_sessions(the_max_stopping_sessions)
  , accepting_endpoint(the_accepting_endpoint)
  , managed_session_config(the_managed_session_config)
{
  BOOST_ASSERT_MSG(the_max_session_count > 0,
      "max_session_count must be > 0");
}
Example #13
0
 void compute( const FUNC& f, const X & ranges, const o_t & o)
 {
     init(o);
     itab_t facts =  ranges(nt2::_,begin_+1, nt2::_)-ranges(nt2::_,begin_, nt2::_);
     itab_t vols = nt2::prod(facts);
     input_t total_vol = globalasum1(vols);
     itab_t coefs = real_t(maxfunccnt_)*nt2::abs(vols)*nt2::rec(total_vol);
     BOOST_ASSERT_MSG(size(ranges, 2) == 2, "ranges must be a nx2xm expression");
     size_t l = size(ranges, 3);
     res_ = nt2::Zero<value_t>();
     for(size_t i=1; i <= l; ++i)
     {
         nbpts_ = coefs(i);
         res_ += compute(f, ranges(nt2::_,nt2::_,i), vols(i), facts(i));
         fcnt_+= nbpts_;
     }
 }
Example #14
0
PROPS & properties() {
    fibers::fiber_properties * props = fibers::context::active()->get_properties();
    if ( ! props) {
        // props could be nullptr if the thread's main fiber has not yet
        // yielded (not yet passed through algorithm_with_properties::
        // awakened()). Address that by yielding right now.
        yield();
        // Try again to obtain the fiber_properties subclass instance ptr.
        // Walk through the whole chain again because who knows WHAT might
        // have happened while we were yielding!
        props = fibers::context::active()->get_properties();
        // Could still be hosed if the running manager isn't a subclass of
        // algorithm_with_properties.
        BOOST_ASSERT_MSG( props, "this_fiber::properties not set");
    }
    return dynamic_cast< PROPS & >( * props );
}
Example #15
0
 BOOST_FORCEINLINE static void conf_bounds(const A0& a0, A1& a1,
                                           const value_type& alpha )
 {
   typedef nt2::memory::container<tag::table_, value_type, nt2::_2D>  semantic;
   NT2_AS_TERMINAL_IN(semantic, pcov, boost::proto::child_c<3>(a0));
   const In0& p  = boost::proto::child_c<0>(a0);
   const In1& mu = boost::proto::child_c<1>(a0);
   const In2& sigma = boost::proto::child_c<2>(a0);
   auto logx0 = -Sqrt_2<A0>()*erfcinv( nt2::Two<A0>()*p);
   auto xvar =   fma(fma(pcov(2,2), logx0, Two<value_type>()*pcov(1,2)), logx0, pcov(1,1));
   BOOST_ASSERT_MSG(nt2::globalall(nt2::is_nltz(xvar)), "Covariance matrix must be positive");
   value_type normz = -nt2::norminv(alpha*nt2::Half<value_type>());
   auto halfwidth = normz*nt2::sqrt(xvar);
   boost::proto::child_c<0>(a1) = exp(fma(sigma, logx0, mu));
   auto coef = exp(-halfwidth);
   boost::proto::child_c<1>(a1) = boost::proto::child_c<0>(a1)*coef;
   boost::proto::child_c<2>(a1) = boost::proto::child_c<0>(a1)/coef;
 }
Example #16
0
        bool try_lock()
        {
            int res;
            do
            {
                res = pthread_mutex_trylock(&m);
            } while (res == EINTR);
            if(res && (res!=EBUSY))
            {
                // The following throw_exception has been replaced by an assertion and just return false,
                // as this is an internal error and the user can do nothing with the exception.
                //boost::throw_exception(lock_error(res,"boost: mutex try_lock failed in pthread_mutex_trylock"));
                BOOST_ASSERT_MSG(false ,"boost: mutex try_lock failed in pthread_mutex_trylock");
                return false;
            }

            return !res;
        }
Example #17
0
void
Signal<Owner, TArgs...>::disconnect(typename SlotList::iterator it)
{
  if (m_isExecuting) {
    // during signal emission, only the currently executing handler can be disconnected
    BOOST_ASSERT_MSG(it == m_currentSlot, "cannot disconnect another handler from a handler");

    // this serves to indicate that the current slot needs to be erased from the list
    // after it finishes executing; we cannot do it here because of bug #2333
    m_currentSlot = m_slots.end();

    // expire all weak_ptrs, to prevent double disconnections
    it->disconnect.reset();
  }
  else {
    m_slots.erase(it);
  }
}
Example #18
0
// computes the distance of a given permutation
EdgeWeight ReturnDistance(const DistTableWrapper<EdgeWeight> &dist_table,
                          const std::vector<NodeID> &location_order,
                          const EdgeWeight min_route_dist,
                          const std::size_t component_size)
{
    EdgeWeight route_dist = 0;
    std::size_t i = 0;
    while (i < location_order.size() && (route_dist < min_route_dist))
    {
        route_dist += dist_table(location_order[i], location_order[(i + 1) % component_size]);
        BOOST_ASSERT_MSG(dist_table(location_order[i], location_order[(i + 1) % component_size]) !=
                             INVALID_EDGE_WEIGHT,
                         "invalid route found");
        ++i;
    }

    return route_dist;
}
Example #19
0
 BOOST_FORCEINLINE static void conf_bounds(const A0& a0, A1& a1,
                                           const value_type& alpha )
 {
   typedef nt2::memory::container<tag::table_, value_type, nt2::_2D>  semantic;
   NT2_AS_TERMINAL_IN(semantic, pcov, boost::proto::child_c<3>(a0));
   const In0& x  = boost::proto::child_c<0>(a0);
   const In1& mu = boost::proto::child_c<1>(a0);
   const In2& sigma = boost::proto::child_c<2>(a0);
   auto z = (log(if_zero_else(is_lez(x), x))-mu)/sigma;
   // this is [1, x0]*pcov*[1; x0]
   auto zvar = fma(fma(pcov(2,2), z, Two<value_type>()*pcov(1,2)), z, pcov(1,1));
   BOOST_ASSERT_MSG(nt2::globalall(nt2::is_gez(zvar)), "Covariance matrix must be positive");
   value_type normz = -nt2::norminv(alpha*nt2::Half<value_type>());
   auto halfwidth =  normz*nt2::sqrt(zvar)/sigma;
   boost::proto::child_c<0>(a1) = Half<value_type>()*nt2::erfc(-Sqrt_2o_2<value_type>()*z);
   boost::proto::child_c<1>(a1) = Half<value_type>()*nt2::erfc(-Sqrt_2o_2<value_type>()*(z-halfwidth));
   boost::proto::child_c<2>(a1) = Half<value_type>()*nt2::erfc(-Sqrt_2o_2<value_type>()*(z+halfwidth));
 }
Example #20
0
File: fold.hpp Project: atyuwen/nt2
    result_type operator()(Worker & w, std::size_t begin, std::size_t size, std::size_t grain)
    {

#ifndef BOOST_NO_EXCEPTIONS
      boost::exception_ptr exception;
#endif

      BOOST_ASSERT_MSG( size % grain == 0, "Reduce size not divisible by grain");
      std::ptrdiff_t nblocks  = size/grain;
      result_type reduced_out = w.neutral_(nt2::meta::as_<result_type>());

      #pragma omp parallel
      {
        // Dispatch group of blocks over each threads
        #pragma omp for schedule(static)
        for(std::ptrdiff_t n=0;n<nblocks;++n)
        {
          result_type out = w.neutral_(nt2::meta::as_<result_type>());

#ifndef BOOST_NO_EXCEPTIONS
          try
          {
#endif
            // Call operation
            w(out,begin+(std::size_t)n*grain,grain);

            #pragma omp critical
            reduced_out = w.bop_(reduced_out, out);

#ifndef BOOST_NO_EXCEPTIONS
          }
          catch(...)
          {

            #pragma omp critical
            exception = boost::current_exception();
          }
#endif

         }
      }

      return reduced_out;
    }
Example #21
0
    BOOST_FORCEINLINE void operator()(Expr& x, Sz const& sz, boost::mpl::true_)
    {
      #ifndef NDEBUG
      // Assert that we don't resize out of storage_size if
      // storage duration is not dynamic_
      typedef typename meta::option<Expr, tag::storage_size_>::type     ss_t;
      typedef typename meta::option<Expr, tag::storage_duration_>::type sd_t;
      typedef boost::is_same< typename sd_t::storage_duration_type
                            , nt2::dynamic_
                            >                                   is_dynamic_t;
      #endif

      BOOST_ASSERT_MSG
      (  is_dynamic_t::value || nt2::numel(sz) <= ss_t::storage_size_type::value
      , "Resizing over available storage size"
      );

      boost::proto::value(x).resize(sz);
    }
Example #22
0
void
fiber::start_() noexcept {
    context * ctx = context::active();
    ctx->attach( impl_.get() );
    switch ( impl_->get_policy() ) {
    case launch::post:
        // push new fiber to ready-queue
        // resume executing current fiber
        ctx->get_scheduler()->set_ready( impl_.get() );
        break;
    case launch::dispatch:
        // resume new fiber and push current fiber
        // to ready-queue
        impl_->resume( ctx);
        break;
    default:
        BOOST_ASSERT_MSG( false, "unknown launch-policy");
    }
}
Example #23
0
        message(nocopy_t, boost::asio::mutable_buffer const& buffer, Deleter&& deleter)
        {
            using D = typename std::decay<Deleter>::type;

            const auto call_deleter = [](void *buf, void *hint) {
                std::unique_ptr<D> deleter(reinterpret_cast<D*>(hint));
                BOOST_ASSERT_MSG(deleter, "!deleter");
                (*deleter)(buf);
            };

            std::unique_ptr<D> d(new D(std::forward<Deleter>(deleter)));
            auto rc = zmq_msg_init_data(&msg_,
                                        boost::asio::buffer_cast<void*>(buffer),
                                        boost::asio::buffer_size(buffer),
                                        call_deleter, d.get());
            if (rc)
                throw boost::system::system_error(make_error_code());
            d.release();
        }
Example #24
0
// returns true if checks passed, false if they failed
// We check the types of columns 0 and 1.
static bool checkColumnsTypes(PGresult * const result, const int numCols) {
  BOOST_ASSERT_MSG( (EXPECTED_NUM_COLS == numCols), "Unexpected bad number of columns: this should have been handled earlier" );

  bool typesAreCorrect = true; // leave as true until we find a bad type

  for (int i = 0; i != EXPECTED_NUM_COLS; ++i) {

    const Oid typeForCol = PQftype(result, i);
    if (expectedTypes[i] == typeForCol) {
      std::cout << "Correct type found for column " << i << '\n';
    } else {
      typesAreCorrect = false;
      std::cerr << "Incorrect type for column " << i << ": OID number of " << typeForCol << '\n';
    }

  }

  return typesAreCorrect;
}
Example #25
0
 result_type operator()(A0& out, const A1& in) const
 {
   size_t n = boost::proto::child_c<0>(in);
   BOOST_ASSERT_MSG(n!= 2, "There is no 2x2 magic matrix");
   out.resize(nt2::of_size(n, n));
   if(n%2 == 1) //Odd order
   {
     oddOrderMagicSquare(out,n);
   }
   else if(n%4 == 0)
   {
     evenx2(out,n);
   }
   else
   {
     evenx1(out,n);
   }
   return out;
 }
Example #26
0
size_t findMatchingRightParenthesis(const std::string &string, size_t leftParenthesisPosition)
{
	BOOST_ASSERT_MSG(string[leftParenthesisPosition] == '(', "Character is not a left parenthesis.");

	size_t count = 0;

	for (auto position = leftParenthesisPosition; position < string.size(); position++)
	{
		if (string[position] == '(')
			count++;

		if (string[position] == ')')
			count--;

		if (count == 0)
			return position;
	}

	return std::string::npos;
}
Example #27
0
// decrease number of concurrent queries
void OSRM_impl::decrease_concurrent_query_count()
{
    if (!barrier)
    {
        return;
    }
    // lock query
    boost::interprocess::scoped_lock<boost::interprocess::named_mutex> query_lock(
        barrier->query_mutex);

    // decrement query count
    --(barrier->number_of_queries);
    BOOST_ASSERT_MSG(0 <= barrier->number_of_queries, "invalid number of queries");

    // notify all processes that were waiting for this condition
    if (0 == barrier->number_of_queries)
    {
        barrier->no_running_queries_condition.notify_all();
    }
}
Example #28
0
void ASMGen::Disasm(std::ostream& out, DXBCShaderVariable const & var)
{
	if (0 == var.type_desc.elements)
	{
		this->Disasm(out, var, 0);
	}
	else
	{
		uint32_t stride = 0;
		switch (var.type_desc.var_class)
		{
		case SVC_SCALAR:
			stride = 4;
			break;
					
		case SVC_VECTOR:
			stride = 16;
			break;

		case SVC_MATRIX_ROWS:
		case SVC_MATRIX_COLUMNS:
			stride = var.type_desc.columns * 16;
			break;

		default:
			BOOST_ASSERT_MSG(false, "Unhandled type.");
			break;
		}
		out << "{";
		for (uint32_t i = 0; i < var.type_desc.elements; ++ i)
		{
			if (i != 0)
			{
				out << ",";
			}
			this->Disasm(out, var, stride * i);
						
		}
		out<<"}";
	}
}
// Encodes a chunk of memory to Base64.
inline std::string encodeBase64(const unsigned char *first, std::size_t size)
{
    std::vector<unsigned char> bytes{first, first + size};
    BOOST_ASSERT(!bytes.empty());

    std::size_t bytes_to_pad{0};

    while (bytes.size() % 3 != 0)
    {
        bytes_to_pad += 1;
        bytes.push_back(0);
    }

    BOOST_ASSERT(bytes_to_pad == 0 || bytes_to_pad == 1 || bytes_to_pad == 2);
    BOOST_ASSERT_MSG(0 == bytes.size() % 3, "base64 input data size is not a multiple of 3");

    std::string encoded{detail::Base64FromBinary{bytes.data()},
                        detail::Base64FromBinary{bytes.data() + (bytes.size() - bytes_to_pad)}};

    return encoded.append(bytes_to_pad, '=');
}
Example #30
0
void ProductNode::Forward()
{
    // weights of the edges are ignored in product node
    
    int i = 0;
    std::vector<Edge*>::iterator it = m_incomingEdges.begin();
    for (; it != m_incomingEdges.end(); ++it)
    {
        Node* incomingNeighbor = (*it)->GetNode1();

        BOOST_ASSERT((*it)->GetNode2() == this);
        BOOST_ASSERT_MSG(incomingNeighbor->GetDimension() == GetDimension()
            , "Invalid dimension");

        if (i == 0)
            m_activations = incomingNeighbor->GetActivations();
        else
            m_activations.dot(incomingNeighbor->GetActivations());
        i++;
    }
}