Exemplo n.º 1
0
UMat& UMat::setTo(InputArray _value, InputArray _mask)
{
    bool haveMask = !_mask.empty();
#ifdef HAVE_OPENCL
    int tp = type(), cn = CV_MAT_CN(tp), d = CV_MAT_DEPTH(tp);

    if( dims <= 2 && cn <= 4 && CV_MAT_DEPTH(tp) < CV_64F && ocl::useOpenCL() )
    {
        Mat value = _value.getMat();
        CV_Assert( checkScalar(value, type(), _value.kind(), _InputArray::UMAT) );
        int kercn = haveMask || cn == 3 ? cn : std::max(cn, ocl::predictOptimalVectorWidth(*this)),
                kertp = CV_MAKE_TYPE(d, kercn);

        double buf[16] = { 0, 0, 0, 0, 0, 0, 0, 0,
                           0, 0, 0, 0, 0, 0, 0, 0 };
        convertAndUnrollScalar(value, tp, (uchar *)buf, kercn / cn);

        int scalarcn = kercn == 3 ? 4 : kercn, rowsPerWI = ocl::Device::getDefault().isIntel() ? 4 : 1;
        String opts = format("-D dstT=%s -D rowsPerWI=%d -D dstST=%s -D dstT1=%s -D cn=%d",
                             ocl::memopTypeToStr(kertp), rowsPerWI,
                             ocl::memopTypeToStr(CV_MAKETYPE(d, scalarcn)),
                             ocl::memopTypeToStr(d), kercn);

        ocl::Kernel setK(haveMask ? "setMask" : "set", ocl::core::copyset_oclsrc, opts);
        if( !setK.empty() )
        {
            ocl::KernelArg scalararg(0, 0, 0, 0, buf, CV_ELEM_SIZE(d) * scalarcn);
            UMat mask;

            if( haveMask )
            {
                mask = _mask.getUMat();
                CV_Assert( mask.size() == size() && mask.type() == CV_8UC1 );
                ocl::KernelArg maskarg = ocl::KernelArg::ReadOnlyNoSize(mask),
                        dstarg = ocl::KernelArg::ReadWrite(*this);
                setK.args(maskarg, dstarg, scalararg);
            }
            else
            {
                ocl::KernelArg dstarg = ocl::KernelArg::WriteOnly(*this, cn, kercn);
                setK.args(dstarg, scalararg);
            }

            size_t globalsize[] = { cols * cn / kercn, (rows + rowsPerWI - 1) / rowsPerWI };
            if( setK.run(2, globalsize, NULL, false) )
            {
                CV_IMPL_ADD(CV_IMPL_OCL);
                return *this;
            }
        }
    }
#endif
    Mat m = getMat(haveMask ? ACCESS_RW : ACCESS_WRITE);
    m.setTo(_value, _mask);
    return *this;
}
Exemplo n.º 2
0
void checkBinOp(char const *op, symbol_t const *s1, symbol_t const *s2) {
	if(isVoid(&s1->type) || isVoid(&s2->type)) {
		yyerror("Les opérandes ne peuvent pas être de type void.");
	}
	else if(op == EQU || op == INF) {
		checkIndirectionLevel(s1, s2);
	}
	else if(op == SOU) {
		if(s1->type.indirectionCount != s2->type.indirectionCount && s2->type.indirectionCount > 0) {
			yyerror("Opérandes invalide pour l'opérateur de soustraction");
		}
	}
	else if(op == ADD) {
		checkScalar(s2);
	}
	else if(op == MUL || op == DIV) {
		checkScalar(s1);
		checkScalar(s2);
	}
}
Exemplo n.º 3
0
UMat& UMat::setTo(InputArray _value, InputArray _mask)
{
    bool haveMask = !_mask.empty();
    int tp = type(), cn = CV_MAT_CN(tp);
    if( dims <= 2 && cn <= 4 && cn != 3 && ocl::useOpenCL() )
    {
        Mat value = _value.getMat();
        CV_Assert( checkScalar(value, type(), _value.kind(), _InputArray::UMAT) );
        double buf[4];
        convertAndUnrollScalar(value, tp, (uchar*)buf, 1);

        char opts[1024];
        sprintf(opts, "-D dstT=%s", ocl::memopTypeToStr(tp));

        ocl::Kernel setK(haveMask ? "setMask" : "set", ocl::core::copyset_oclsrc, opts);
        if( !setK.empty() )
        {
            ocl::KernelArg scalararg(0, 0, 0, buf, CV_ELEM_SIZE(tp));
            UMat mask;

            if( haveMask )
            {
                mask = _mask.getUMat();
                CV_Assert( mask.size() == size() && mask.type() == CV_8U );
                ocl::KernelArg maskarg = ocl::KernelArg::ReadOnlyNoSize(mask);
                ocl::KernelArg dstarg = ocl::KernelArg::ReadWrite(*this);
                setK.args(maskarg, dstarg, scalararg);
            }
            else
            {
                ocl::KernelArg dstarg = ocl::KernelArg::WriteOnly(*this);
                setK.args(dstarg, scalararg);
            }

            size_t globalsize[] = { cols, rows };
            if( setK.run(2, globalsize, 0, false) )
                return *this;
        }
    }
    Mat m = getMat(haveMask ? ACCESS_RW : ACCESS_WRITE);
    m.setTo(_value, _mask);
    return *this;
}
Exemplo n.º 4
0
Mat& Mat::setTo(InputArray _value, InputArray _mask)
{
    if( !data )
        return *this;
    
    Mat value = _value.getMat(), mask = _mask.getMat();
    
    CV_Assert( checkScalar(value, type(), _value.kind(), _InputArray::MAT ));
    CV_Assert( mask.empty() || mask.type() == CV_8U );
    
    size_t esz = elemSize();
    BinaryFunc copymask = getCopyMaskFunc(esz);
    
    const Mat* arrays[] = { this, !mask.empty() ? &mask : 0, 0 };
    uchar* ptrs[2]={0,0};
    NAryMatIterator it(arrays, ptrs);
    int total = (int)it.size, blockSize0 = std::min(total, (int)((BLOCK_SIZE + esz-1)/esz));
    AutoBuffer<uchar> _scbuf(blockSize0*esz + 32);
    uchar* scbuf = alignPtr((uchar*)_scbuf, (int)sizeof(double));
    convertAndUnrollScalar( value, type(), scbuf, blockSize0 );
    
    for( size_t i = 0; i < it.nplanes; i++, ++it )
    {
        for( int j = 0; j < total; j += blockSize0 )
        {
            Size sz(std::min(blockSize0, total - j), 1);
            size_t blockSize = sz.width*esz;
            if( ptrs[1] )
            {
                copymask(scbuf, 0, ptrs[1], 0, ptrs[0], 0, sz, &esz);
                ptrs[1] += sz.width;
            }
            else
                memcpy(ptrs[0], scbuf, blockSize);
            ptrs[0] += blockSize;
        }
    }
    return *this;
}
Exemplo n.º 5
0
symbol_t *binOpEq(char const *op, dereferencedSymbol_t id, symbol_t *value) {
	symbol_t *r = id.symbol;

	if(id.dereferenceCount > 0) {
		char *oldName = id.symbol->name;
		symbol_t *dOp = dereferenceExp(id);
		id.symbol->name = "notTemp";
		symbol_t *res = binOp(op, dOp, value);
		id.symbol->name = oldName;
		affectation(id, res, false);
	}
	else {
		if(id.lvalue == false) {
			yyerror("L'expression n'est pas une lvalue.");
		}
		checkBinOp(op, r, value);
		checkScalar(value);
		assemblyOutput("%s %d %d %d", op, r->address, r->address, value->address);
	}

	freeIfTemp(value);

	return r;
}
Exemplo n.º 6
0
static void 
abv_init(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[], bool isStructInit)
{
  int result;
  char *bv_hostname = 0;
  struct RDA_MessageStart *pMsgStart;
  
  mxArray* OUT_STATE;
  
  /* copy the params to the out state */
  if(isStructInit) {
    // init with struct
    OUT_STATE = mxDuplicateArray(prhs[1]);
  } else {
    // init with property list
    int dims[2] = {1,1};
    OUT_STATE = mxCreateStructArray(2, dims, 0, NULL);
    // arguments have beed checked in mexFunction
    for(int i = 1; i < nrhs; i = i + 2) {
      addField(OUT_STATE, prhs[i], prhs[i + 1]);
    }
  }
  
  /* check for the needed fields values 
   * if they don't exist we will set the default values */
  checkString(OUT_STATE,FIELD_HOST, "127.0.0.1");
  
  /* Get server name (or use default "brainamp") */
  bv_hostname = getString(OUT_STATE, FIELD_HOST);

  /* open connection */
  result = initConnection(bv_hostname,&pMsgStart);
  free(bv_hostname);  
    
  if (result == IC_OKAY) {
    /* construct connection state structure */
    int nChans, lag, n;
    double orig_fs;
    mxArray *pArray;
    char *pChannelName;
    double *chan_sel;
    double *filter_buffer_sub;
    double *filter_buffer_a;
    double *filter_buffer_b;
    int iirFilterSize;
    
    nChans = pMsgStart->nChannels;
    orig_fs = 1000000.0 / ((double) pMsgStart->dSamplingInterval);
    
    /* Check fs */
    checkScalar(OUT_STATE,FIELD_FS,orig_fs);
    
    lag = (int) (orig_fs / getScalar(OUT_STATE, FIELD_FS));
    
    abv_assert(lag * (int)getScalar(OUT_STATE,FIELD_FS) == (int)orig_fs,"bbci_acquire_bv: The base frequency has to be a multiple of the requested frequency.");
    
    /* Overwrite the following fields */
    setScalar(OUT_STATE,FIELD_ORIG_FS, orig_fs);
    setScalar(OUT_STATE,FIELD_LAG, lag);
    setScalar(OUT_STATE,FIELD_BLOCK_NO, -1.0);
     /* this odd hack is because pMsgStart contains several variably
       sized arrays, and this is the way to get the channel names 
     */
    setStringCell(OUT_STATE, FIELD_CLAB,(char *) ((double*) pMsgStart->dResolutions + nChans), 1, nChans);
    
    
    /* Check the following fields */
    checkString(OUT_STATE,FIELD_MARKER_FORMAT, "numeric");
    abv_assert(1 == checkScalar(OUT_STATE, FIELD_RECONNECT, 1), "bbci_acquire_bv: Reconnect is no scalar.");
    abv_assert(1 == checkArray(OUT_STATE, FIELD_SCALE, 1, nChans, pMsgStart->dResolutions), "bbci_acquire_bv: Scale is no array or has wrong size.");
    
    chan_sel = (double *) malloc(nChans*sizeof(double));
    for (n = 0;n<nChans;n++) {
        chan_sel[n] = n+1;
    }
    abv_assert(1 == checkArray(OUT_STATE, FIELD_CHAN_SEL, 1, -nChans, chan_sel), "bbci_acquire_bv: chan_sel is no array.");  
    free(chan_sel);
    
    /* Create the default filters */
    
    filter_buffer_sub = (double *) malloc(lag*sizeof(double));
    for(n = 0; n < lag; ++n) {
      filter_buffer_sub[n] = 1.0 / (double)lag;
    }
    filter_buffer_a = (double *) malloc(sizeof(double));
    filter_buffer_a[0] = 1.0;
    filter_buffer_b = (double *) malloc(sizeof(double));
    filter_buffer_b[0] = 1.0;
    
    /* check the filters */
    abv_assert(1 == checkArray(OUT_STATE, FIELD_FILT_SUBSAMPLE, 1, lag, filter_buffer_sub), "bbci_acquire_bv: Subsample filter is no array or has the wrong size.");
    abv_assert(1 == checkArray(OUT_STATE, FIELD_FILT_A, 1, -1, filter_buffer_a), "bbci_acquire_bv: IIR filter aSubsample filter has the wrong size.");
    abv_assert(1 == checkArray(OUT_STATE, FIELD_FILT_B, 1, -1, filter_buffer_b), "bbci_acquire_bv: Subsample filter has the wrong size.");
    
    /* free the default filters */
    free(filter_buffer_sub);
    free(filter_buffer_a);
    free(filter_buffer_b);
    
    /* check if the iir filters have the same size */
    iirFilterSize = getArrayN(OUT_STATE, FIELD_FILT_A);
    
    abv_assert(getArrayN(OUT_STATE, FIELD_FILT_B) == iirFilterSize, "bbci_acquire_bv: bFilter and aFilter must have the same size.");
    
    
    /* get the arrays for the filters and create the filters */
    filter_buffer_sub = getArray(OUT_STATE, FIELD_FILT_SUBSAMPLE);
    filter_buffer_a = getArray(OUT_STATE, FIELD_FILT_A);
    filter_buffer_b = getArray(OUT_STATE, FIELD_FILT_B);
    
    filterFIRCreate(filter_buffer_sub, lag,nChans);
    filterIIRCreate(filter_buffer_a, filter_buffer_b, iirFilterSize, nChans);
    
    connected = 1;
  }
  
  plhs[0] = OUT_STATE;
  free(pMsgStart);
}