Example #1
0
void cv::blendLinear( InputArray _src1, InputArray _src2, InputArray _weights1, InputArray _weights2, OutputArray _dst )
{
    int type = _src1.type(), depth = CV_MAT_DEPTH(type);
    Size size = _src1.size();

    CV_Assert(depth == CV_8U || depth == CV_32F);
    CV_Assert(size == _src2.size() && size == _weights1.size() && size == _weights2.size());
    CV_Assert(type == _src2.type() && _weights1.type() == CV_32FC1 && _weights2.type() == CV_32FC1);

    _dst.create(size, type);

    CV_OCL_RUN(_dst.isUMat(),
               ocl_blendLinear(_src1, _src2, _weights1, _weights2, _dst))

    Mat src1 = _src1.getMat(), src2 = _src2.getMat(), weights1 = _weights1.getMat(),
            weights2 = _weights2.getMat(), dst = _dst.getMat();

    if (depth == CV_8U)
    {
        BlendLinearInvoker<uchar> invoker(src1, src2, weights1, weights2, dst);
        parallel_for_(Range(0, src1.rows), invoker, dst.total()/(double)(1<<16));
    }
    else if (depth == CV_32F)
    {
        BlendLinearInvoker<float> invoker(src1, src2, weights1, weights2, dst);
        parallel_for_(Range(0, src1.rows), invoker, dst.total()/(double)(1<<16));
    }
}
Example #2
0
fivePointEleven() {
	// this is ok.
	// invoker((int (*)(char *, char *))callback, "you are pig.", "I am not a pig.");
	
	// this is also ok and simpler for the invoker to invoke the function.
	invoker(callback, "you are pig.", "I am not a pig.");
}
Example #3
0
int main() {
  auto t = new std::string("abc");
  auto f = invoker(*t);
  delete t;
  std::cout << "len: " << f.get() << std::endl;
  return 0;
}
Example #4
0
bool CContextMenuItem::Execute(const CFileItemPtr& item) const
{
  if (!item || !m_addon || m_library.empty() || IsGroup())
    return false;

  LanguageInvokerPtr invoker(new CContextItemAddonInvoker(&g_pythonParser, item));
  return (CScriptInvocationManager::GetInstance().ExecuteAsync(m_library, invoker, m_addon) != -1);
}
void ClientAgentInputFilter::HandleDrop(const char* buffer)
{
	BMessage msg(M_SUBMIT_INPUT);
	const char* place;
	int32 lines(0);

	BMessenger msgr(fWindow);

	while ((place = strchr(buffer, '\n'))) {
		BString str;

		str.Append(buffer, place - buffer);
		msg.AddString("data", str.String());
		++lines;
		buffer = place + 1;
	}

	if (*buffer) {
		msg.AddString("data", buffer);
		++lines;
	}

	int32 start, finish;
	fWindow->fInput->TextView()->GetSelection(&start, &finish);
	msg.AddInt32("selstart", start);
	msg.AddInt32("selend", finish);

	if (lines > 1) {
		if (true == vision_app->GetBool("Newbie Spam Mode")) {
			BString str;

			str += "As if there isn't enough, you ";
			str += "are about to add ";
			str << lines;
			str += " more lines of spam to ";
			str += "the internet.  How ";
			str += "would you like to go about this?";

			BAlert* alert(new BAlert("Spam", str.String(), "Cancel", "Spam!", "Single line",
									 B_WIDTH_FROM_WIDEST, B_OFFSET_SPACING, B_WARNING_ALERT));

			BMessage* invokeMsg(new BMessage(msg));
			BInvoker* invoker(new BInvoker(invokeMsg, msgr));
			invokeMsg->AddPointer("invoker", invoker);
			alert->Go(invoker);
		} else {
			msg.AddInt32("which", PASTE_MULTI);
			msgr.SendMessage(&msg);
		}
	}

	if (lines == 1) {
		msg.AddInt32("which", PASTE_SINGLE);
		msgr.SendMessage(&msg);
		fWindow->fInput->MakeFocus(false);
		fWindow->fInput->MakeFocus(true);
	}
}
Example #6
0
void ParameterOptimizer::update(const std::vector<Vector*>& vecs,
                                const ParameterConfig& conf,
                                size_t sparseId) {
  ParameterTraverseCallbackPrivate invoker(
      [&](const paddle::VectorPtr _vecs[],
          const paddle::ParameterConfig& config,
          size_t sid = -1UL) { m->optimizer->update(_vecs, config, sid); });
  invoker.apply(vecs, conf, sparseId);
}
Example #7
0
    void detect(cv::gpu::GpuMat& objects, cv::gpu::Stream& s) const
    {
        if (s)
            s.enqueueMemSet(objects, 0);
        else
            cudaMemset(objects.data, 0, sizeof(Detection));

        cudaSafeCall( cudaGetLastError());

        device::CascadeInvoker<device::GK107PolicyX4> invoker
        = device::CascadeInvoker<device::GK107PolicyX4>(levels, stages, nodes, leaves);

        cudaStream_t stream = cv::gpu::StreamAccessor::getStream(s);
        invoker(mask, hogluv, objects, downscales, stream);
    }
Example #8
0
bool CContextMenuItem::Execute(const CFileItemPtr& item) const
{
  if (!item || m_library.empty() || IsGroup())
    return false;

  ADDON::AddonPtr addon;
  if (!CServiceBroker::GetAddonMgr().GetAddon(m_addonId, addon))
    return false;

#ifdef HAS_PYTHON
  LanguageInvokerPtr invoker(new CContextItemAddonInvoker(&g_pythonParser, item));
  return (CScriptInvocationManager::GetInstance().ExecuteAsync(m_library, invoker, addon) != -1);
#else
  return false;
#endif
}
Example #9
0
void RealConnection::handleReadCommand(const boost::system::error_code & error, size_t size, CommandSize commandSize)
{
    if (error) {
        _lastErrorCode = error;
        disconnect();
        return;
    }

    std::istream inputStream(&_incoming);

    RequestID requestID;
    inputStream.read(reinterpret_cast<char *>(&requestID), sizeof(requestID));

    if (requestID & REQUEST_ID_RECEIVED_BIT) {
        // Process result
        requestID &= ~REQUEST_ID_RECEIVED_BIT;
        auto iter = _requestCallbacks.begin();
        while (iter != _requestCallbacks.end()) {
            if (iter->first == requestID) {
                iter->second(inputStream);
                _requestCallbacks.erase(iter);
                break;
            }
        }
    } else {
        std::string name;
        std::getline(inputStream, name, PACKET_END);

        std::stringstream result;
        if (invoker().invoke(name, inputStream, result, shared_from_this()) && requestID) {
            // Send result
            std::ostream outgoingStream{&_outgoing};
            CommandSize outgoingSize{sizeof(RequestID) + result.str().length()};
            outgoingStream.write(reinterpret_cast<char *>(&outgoingSize), sizeof(outgoingSize));
            requestID |= REQUEST_ID_RECEIVED_BIT;
            outgoingStream.write(reinterpret_cast<char *>(&requestID), sizeof(requestID));
            outgoingStream << result.str();
            write();
        }
    }

    if (_connected) {
        size -= commandSize;
        read(size);
    }
}
Example #10
0
bool RpcAdaptor::invokeMethod(const QByteArray &method, const QVariantList &args)
{
	QSlotInvoker invoker(this, method);
	if(!invoker.memberPresent())
	{
		if(_adaptParent)
		{
			QSlotInvoker invoker2(parent(),method);
			if(!invoker2.memberPresent())
			{
				qLog(Debug)<<"RpcAdaptor:: member "<<method<<" not found in "<<parent()<< " or "<<this;
				return false;
			}
			invoker2.invoke(args);
			return true;
		}else
			qLog(Debug)<<"RpcAdaptor:: member "<<method<<" not found in "<<this;
		return false;
	}
	invoker.invoke(args);
	return true;
}
Example #11
0
void AMQP_ClientOperations::Invoker::visit(const FileDeliverBody& body) {
    AMQP_ClientOperations::FileHandler::Invoker invoker(*target.getFileHandler());
    body.accept(invoker);
    result=invoker.getResult();
}
Example #12
0
    int train_rprop( const Mat& inputs, const Mat& outputs, const Mat& _sw, TermCriteria termCrit )
    {
        const int max_buf_size = 1 << 16;
        int i, iter = -1, count = inputs.rows;

        double prev_E = DBL_MAX*0.5;

        int max_iter = termCrit.maxCount;
        double epsilon = termCrit.epsilon;
        double dw_plus = params.rpDWPlus;
        double dw_minus = params.rpDWMinus;
        double dw_min = params.rpDWMin;
        double dw_max = params.rpDWMax;

        int l_count = layer_count();

        // allocate buffers
        vector<Mat> dw(l_count), dEdw(l_count), prev_dEdw_sign(l_count);

        int total = 0;
        for( i = 0; i < l_count; i++ )
        {
            total += layer_sizes[i];
            dw[i].create(weights[i].size(), CV_64F);
            dw[i].setTo(Scalar::all(params.rpDW0));
            prev_dEdw_sign[i] = Mat::zeros(weights[i].size(), CV_8S);
            dEdw[i] = Mat::zeros(weights[i].size(), CV_64F);
        }

        int dcount0 = max_buf_size/(2*total);
        dcount0 = std::max( dcount0, 1 );
        dcount0 = std::min( dcount0, count );
        int chunk_count = (count + dcount0 - 1)/dcount0;

        // run rprop loop
        /*
         y_i(t) = w_i(t)*x_{i-1}(t)
         x_i(t) = f(y_i(t))
         E = sum_over_all_samples(1/2*||u - x_N||^2)
         grad_N = (x_N - u)*f'(y_i)

         std::min(dw_i{jk}(t)*dw_plus, dw_max), if dE/dw_i{jk}(t)*dE/dw_i{jk}(t-1) > 0
         dw_i{jk}(t) = std::max(dw_i{jk}(t)*dw_minus, dw_min), if dE/dw_i{jk}(t)*dE/dw_i{jk}(t-1) < 0
         dw_i{jk}(t-1) else

         if (dE/dw_i{jk}(t)*dE/dw_i{jk}(t-1) < 0)
         dE/dw_i{jk}(t)<-0
         else
         w_i{jk}(t+1) = w_i{jk}(t) + dw_i{jk}(t)
         grad_{i-1}(t) = w_i^t(t)*grad_i(t)
         */
        for( iter = 0; iter < max_iter; iter++ )
        {
            double E = 0;

            for( i = 0; i < l_count; i++ )
                dEdw[i].setTo(Scalar::all(0));

            // first, iterate through all the samples and compute dEdw
            RPropLoop invoker(this, inputs, outputs, _sw, dcount0, dEdw, &E);
            parallel_for_(Range(0, chunk_count), invoker);
            //invoker(Range(0, chunk_count));

            // now update weights
            for( i = 1; i < l_count; i++ )
            {
                int n1 = layer_sizes[i-1], n2 = layer_sizes[i];
                for( int k = 0; k <= n1; k++ )
                {
                    CV_Assert(weights[i].size() == Size(n2, n1+1));
                    double* wk = weights[i].ptr<double>(k);
                    double* dwk = dw[i].ptr<double>(k);
                    double* dEdwk = dEdw[i].ptr<double>(k);
                    schar* prevEk = prev_dEdw_sign[i].ptr<schar>(k);

                    for( int j = 0; j < n2; j++ )
                    {
                        double Eval = dEdwk[j];
                        double dval = dwk[j];
                        double wval = wk[j];
                        int s = CV_SIGN(Eval);
                        int ss = prevEk[j]*s;
                        if( ss > 0 )
                        {
                            dval *= dw_plus;
                            dval = std::min( dval, dw_max );
                            dwk[j] = dval;
                            wk[j] = wval + dval*s;
                        }
                        else if( ss < 0 )
                        {
                            dval *= dw_minus;
                            dval = std::max( dval, dw_min );
                            prevEk[j] = 0;
                            dwk[j] = dval;
                            wk[j] = wval + dval*s;
                        }
                        else
                        {
                            prevEk[j] = (schar)s;
                            wk[j] = wval + dval*s;
                        }
                        dEdwk[j] = 0.;
                    }
                }
            }

            //printf("%d. E = %g\n", iter, E);
            if( fabs(prev_E - E) < epsilon )
                break;
            prev_E = E;
        }

        return iter;
    }
Example #13
0
void AMQP_ClientOperations::Invoker::visit(const ConnectionHeartbeatBody& body) {
    AMQP_ClientOperations::ConnectionHandler::Invoker invoker(*target.getConnectionHandler());
    body.accept(invoker);
    result=invoker.getResult();
}
Example #14
0
void AMQP_ClientOperations::Invoker::visit(const StreamConsumeOkBody& body) {
    AMQP_ClientOperations::StreamHandler::Invoker invoker(*target.getStreamHandler());
    body.accept(invoker);
    result=invoker.getResult();
}
Example #15
0
void ClientAgent::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
	// 22/8/99: this will now look for "text" to add to the
	// fInput view. -jamie
	case M_INPUT_FOCUS: {
		if (msg->HasString("text")) {
			BString newtext;
			newtext = fInput->Text();
			newtext.Append(msg->FindString("text"));
			fInput->SetText(newtext.String());
		}
		fInput->MakeFocus(true);
		// We don't like your silly selecting-on-focus.
		fInput->TextView()->Select(fInput->TextView()->TextLength(),
								   fInput->TextView()->TextLength());
	} break;

	case M_CLIENT_QUIT: {
		if (fIsLogging && !(msg->HasBool("vision:shutdown") && msg->FindBool("vision:shutdown"))) {
			BMessage logMessage(M_UNREGISTER_LOGGER);
			logMessage.AddString("name", fId.String());
			fSMsgr.SendMessage(&logMessage);
		}

		BMessage deathchant(M_CLIENT_SHUTDOWN);
		deathchant.AddPointer("agent", this);
		fSMsgr.SendMessage(&deathchant);

	} break;

	case M_THEME_FOREGROUND_CHANGE: {
		int16 which(msg->FindInt16("which"));
		if (which == C_INPUT || which == C_INPUT_BACKGROUND) {
			fActiveTheme->ReadLock();
			rgb_color fInputColor(fActiveTheme->ForegroundAt(C_INPUT));
			fInput->TextView()->SetFontAndColor(&fActiveTheme->FontAt(F_INPUT), B_FONT_ALL,
												&fInputColor);
			fInput->TextView()->SetViewColor(fActiveTheme->ForegroundAt(C_INPUT_BACKGROUND));
			fActiveTheme->ReadUnlock();
			fInput->TextView()->Invalidate();
		}
	} break;

	case M_THEME_FONT_CHANGE: {
		int16 which(msg->FindInt16("which"));
		if (which == F_INPUT) {
			fActiveTheme->ReadLock();
			rgb_color fInputColor(fActiveTheme->ForegroundAt(C_INPUT));
			fInput->TextView()->SetFontAndColor(&fActiveTheme->FontAt(F_INPUT), B_FONT_ALL,
												&fInputColor);
			fActiveTheme->ReadUnlock();
			Invalidate();
		}
	} break;

	case M_STATE_CHANGE: {
		if (msg->HasBool("bool")) {
			bool shouldStamp(vision_app->GetBool("timestamp"));
			if (fTimeStampState != shouldStamp) {
				if ((fTimeStampState = shouldStamp))
					fText->SetTimeStampFormat(vision_app->GetString("timestamp_format"));
				else
					fText->SetTimeStampFormat(NULL);
			}

			bool shouldLog = vision_app->GetBool("log_enabled");

			if (fIsLogging != shouldLog) {
				if ((fIsLogging = shouldLog)) {
					BMessage logMessage(M_REGISTER_LOGGER);
					logMessage.AddString("name", fId.String());
					fSMsgr.SendMessage(&logMessage);
				} else {
					BMessage logMessage(M_UNREGISTER_LOGGER);
					logMessage.AddString("name", fId.String());
					fSMsgr.SendMessage(&logMessage);
				}
			}
		} else if (msg->HasBool("string")) {
			BString which(msg->FindString("which"));
			if (which == "timestamp_format")
				fText->SetTimeStampFormat(vision_app->GetString("timestamp_format"));
		}
	} break;

	case M_SUBMIT_INPUT: {
		fCancelMLPaste = false;
		int32 which(0);

		msg->FindInt32("which", &which);

		if (msg->HasPointer("invoker")) {
			BInvoker* invoker(NULL);
			msg->FindPointer("invoker", reinterpret_cast<void**>(&invoker));
			delete invoker;
		}

		switch (which) {
		case PASTE_CANCEL:
			break;

		case PASTE_MULTI:
		case PASTE_MULTI_NODELAY: {
			BMessage* buffer(new BMessage(*msg));
			thread_id tid;

			// if there is some text in the input control already, submit it before
			// starting the timed paste
			if (fInput->TextView()->TextLength() != 0) {
				BString inputData(fInput->TextView()->Text());
				Submit(inputData.String(), true, true);
			}

			buffer->AddPointer("agent", this);
			buffer->AddPointer("window", Window());
			if (which == PASTE_MULTI_NODELAY) buffer->AddBool("delay", false);
			tid = spawn_thread(TimedSubmit, "Timed Submit", B_LOW_PRIORITY, buffer);
			resume_thread(tid);
		} break;

		case PASTE_SINGLE: {
			BString buffer;
			for (int32 i = 0; msg->HasString("data", i); ++i) {
				const char* data;
				msg->FindString("data", i, &data);
				buffer += (i ? " " : "");
				buffer += data;
			}

			int32 start, finish;

			if (msg->FindInt32("selstart", &start) == B_OK) {
				msg->FindInt32("selend", &finish);
				if (start != finish) fInput->TextView()->Delete(start, finish);

				if ((start == 0) && (finish == 0)) {
					fInput->TextView()->Insert(fInput->TextView()->TextLength(), buffer.String(),
											   buffer.Length());
					fInput->TextView()->Select(fInput->TextView()->TextLength(),
											   fInput->TextView()->TextLength());
				} else {
					fInput->TextView()->Insert(start, buffer.String(), buffer.Length());
					fInput->TextView()->Select(start + buffer.Length(), start + buffer.Length());
				}
			} else {
				fInput->TextView()->Insert(buffer.String());
				fInput->TextView()->Select(fInput->TextView()->TextLength(),
										   fInput->TextView()->TextLength());
			}
			fInput->TextView()->ScrollToSelection();
		} break;

		default:
			break;
		}
	} break;

	case M_PREVIOUS_INPUT: {
		fHistory->PreviousBuffer(fInput);
	} break;

	case M_NEXT_INPUT: {
		fHistory->NextBuffer(fInput);
	} break;

	case M_SUBMIT: {
		const char* buffer(NULL);
		bool clear(true), add2history(true);

		msg->FindString("input", &buffer);

		if (msg->HasBool("clear")) msg->FindBool("clear", &clear);

		if (msg->HasBool("history")) msg->FindBool("history", &add2history);

		Submit(buffer, clear, add2history);
	} break;

	case M_LAG_CHANGED: {
		msg->FindString("lag", &fMyLag);

		if (!IsHidden())
			vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_LAG, fMyLag.String());
	} break;

	case M_DISPLAY: {
		const char* buffer;

		for (int32 i = 0; msg->HasMessage("packed", i); ++i) {
			BMessage packed;

			msg->FindMessage("packed", i, &packed);
			packed.FindString("msgz", &buffer);
			Display(buffer, packed.FindInt32("fore"), packed.FindInt32("back"),
					packed.FindInt32("font"));
		}
	} break;

	case M_CHANNEL_MSG: {
		BString theNick;
		const char* theMessage(NULL);
		bool hasNick(false);
		bool isAction(false);
		BString knownAs;

		msg->FindString("nick", &theNick);
		msg->FindString("msgz", &theMessage);

		BString tempString;
		BString nickString;

		if (theMessage[0] == '\1') {
			BString aMessage(theMessage);
			aMessage.RemoveFirst("\1ACTION ");
			aMessage.RemoveLast("\1");

			tempString = " ";
			tempString += aMessage;
			tempString += "\n";

			nickString = "* ";
			nickString += theNick;
			isAction = true;
		} else {
			Display("<", theNick == fMyNick ? C_MYNICK : C_NICK);
			Display(theNick.String(), C_NICKDISPLAY);
			Display(">", theNick == fMyNick ? C_MYNICK : C_NICK);
			tempString += " ";
			tempString += theMessage;
			tempString += '\n';
		}

		// scan for presence of nickname, highlight if present
		if (theNick != fMyNick) FirstKnownAs(tempString, knownAs, &hasNick);

		tempString.Prepend(nickString);

		int32 dispColor = C_TEXT;
		if (hasNick) {
			BWindow* window(NULL);
			dispColor = C_MYNICK;
			if ((window = Window()) != NULL && !window->IsActive())
				system_beep(kSoundEventNames[(uint32)seNickMentioned]);
		} else if (isAction)
			dispColor = C_ACTION;

		Display(tempString.String(), dispColor);
	} break;

	case M_CHANGE_NICK: {
		const char* oldNick(NULL);

		msg->FindString("oldnick", &oldNick);

		if (fMyNick.ICompare(oldNick) == 0) fMyNick = msg->FindString("newnick");

		BMessage display;
		if (msg->FindMessage("display", &display) == B_NO_ERROR)
			ClientAgent::MessageReceived(&display);
	} break;

	case M_LOOKUP_WEBSTER: {
		BString lookup;
		msg->FindString("string", &lookup);
		lookup = StringToURI(lookup.String());
		lookup.Prepend("http://www.m-w.com/cgi-bin/dictionary?va=");
		vision_app->LoadURL(lookup.String());
	} break;

	case M_LOOKUP_GOOGLE: {
		BString lookup;
		msg->FindString("string", &lookup);
		lookup = StringToURI(lookup.String());
		lookup.Prepend("http://www.google.com/search?q=");
		vision_app->LoadURL(lookup.String());
	} break;

	case M_LOOKUP_ACRONYM: {
		BString lookup;
		msg->FindString("string", &lookup);
		lookup = StringToURI(lookup.String());
		lookup.Prepend("http://www.acronymfinder.com/af-query.asp?String=exact&Acronym=");
		lookup.Append("&Find=Find");
		vision_app->LoadURL(lookup.String());
	} break;

	case B_ESCAPE:
		fCancelMLPaste = true;
		break;

	case M_DCC_COMPLETE: {
		/// set up ///
		BString nick, file, size, type, completionMsg("[@] "), fAck;
		int32 rate, xfersize;
		bool completed(true);

		msg->FindString("nick", &nick);
		msg->FindString("file", &file);
		msg->FindString("size", &size);
		msg->FindString("type", &type);
		msg->FindInt32("transferred", &xfersize);
		msg->FindInt32("transferRate", &rate);

		BPath pFile(file.String());

		fAck << xfersize;

		if (size.ICompare(fAck)) completed = false;

		/// send mesage ///
		if (completed)
			completionMsg << S_CLIENT_DCC_SUCCESS;
		else
			completionMsg << S_CLIENT_DCC_FAILED;

		if (type == "SEND")
			completionMsg << S_CLIENT_DCC_SENDTYPE << pFile.Leaf() << S_CLIENT_DCC_TO;
		else
			completionMsg << S_CLIENT_DCC_RECVTYPE << pFile.Leaf() << S_CLIENT_DCC_FROM;

		completionMsg << nick << " (";

		if (!completed) completionMsg << fAck << "/";

		completionMsg << size << S_CLIENT_DCC_SIZE_UNITS "), ";
		completionMsg << rate << S_CLIENT_DCC_SPEED_UNITS "\n";

		Display(completionMsg.String(), C_CTCP_RPY);
	} break;

	default:
		BView::MessageReceived(msg);
	}
}
Example #16
0
void AMQP_ClientOperations::Invoker::visit(const MessageStopBody& body) {
    AMQP_ClientOperations::MessageHandler::Invoker invoker(*target.getMessageHandler());
    body.accept(invoker);
    result=invoker.getResult();
}
Example #17
0
void AMQP_ClientOperations::Invoker::visit(const ExecutionExceptionBody& body) {
    AMQP_ClientOperations::ExecutionHandler::Invoker invoker(*target.getExecutionHandler());
    body.accept(invoker);
    result=invoker.getResult();
}
Example #18
0
void AMQP_ClientOperations::Invoker::visit(const SessionGapBody& body) {
    AMQP_ClientOperations::SessionHandler::Invoker invoker(*target.getSessionHandler());
    body.accept(invoker);
    result=invoker.getResult();
}
auto option( Types ... args )
{
    return [=]( auto invoker ) { return invoker( args ... ); };
}