Exemplo n.º 1
0
/* Matrix subtraction C = A - B */
extern void amMinus(ArrayMatrix C, ArrayMatrix A, ArrayMatrix B)
{
	mwSignedIndex nelem;

	/* Number of elements */
	nelem = intmax(A.nelem, B.nelem);

	if (A.complex || B.complex) {
		zplus(C.data, A.data, B.data, A.nelem > 1, B.nelem > 1, A.nrow*A.ncol, B.nrow*B.ncol, nelem, 1);
	} else {
		dplus(C.data, A.data, B.data, A.nelem > 1, B.nelem > 1, A.nrow*A.ncol, B.nrow*B.ncol, nelem, 1);
	}

}
Exemplo n.º 2
0
/* subroutine for addition of two complex array matrices using DAXPY */
void zplus(
				   double	*C,
				   double	*A,
				   double	*B,
				   mwSignedIndex a_is_array,
				   mwSignedIndex b_is_array,
				   mwSignedIndex block_a,
				   mwSignedIndex block_b,
				   mwSignedIndex nelem,
				   mwSignedIndex minus
				   )
{
	double *pA, *pB, *pC;
	mwSignedIndex n;
	mwSignedIndex stride_a, stride_b;
	mwSignedIndex inca = 1, incb = 1, incc = 1;
	double alpha[2];
	mwSignedIndex block;

	alpha[0] = 1.0; alpha[1] = 0.0;
	if (minus) alpha[0] = -1.0;

	stride_a = block_a * a_is_array;
	stride_b = block_b * b_is_array;

	pA = A; pB = B; pC = C;
	if ((stride_a > 0) & (stride_a == stride_b)) {
		/* Both are matrices and both are arrays */
		block = stride_a * nelem;
		/* first copy A to C */
		BLASCALL(zcopy)(&block, pA, &inca, pC, &incc);
		/* then add alpha*B to C */
		BLASCALL(zaxpy)(&block, &alpha, pB, &incb, pC, &incc);
	} else {
		block = intmax(block_a, block_b);
		/* set increment to 0 if scalar */
		inca = block_a > 1;
		incb = block_b > 1;
		for (n = 0; n < nelem; n++) {
			/* first copy A to C */
		        BLASCALL(zcopy)(&block, pA, &inca, pC, &incc);
			/* then add alpha*B to C */
			BLASCALL(zaxpy)(&block, &alpha, pB, &incb, pC, &incc);
			pA += 2*stride_a;
			pB += 2*stride_b;
			pC += 2*block;
		}
	}
}
Exemplo n.º 3
0
int SIMD_SUFFIX(mblocks_sub44_mests)( uint8_t *blk,  uint8_t *ref,
					int ilow,int jlow,
					int ihigh, int jhigh, 
					int h, int rowstride, 
					int threshold,
					me_result_s *resvec)
{
	int32_t x,y;
	uint8_t *currowblk = blk;
	uint8_t *curblk;
	me_result_s *cres = resvec;
	int      gridrowstride = rowstride;
	int weight;

        SIMD_SUFFIX(init_qblock_sad)(ref, h, rowstride);
	for( y=jlow; y <= jhigh ; y+=4)
	{
		curblk = currowblk;
		// You'd think prefetching curblk+4*rowstride would help here.
		// I have found *NO* measurable increase in performance...
		
		for( x = ilow; x <= ihigh; x += 4)
		{
			if( (x & 15) == (ilow & 15) )
			{
				load_blk( curblk, rowstride, h );
                                curblk += 4;
			}
			weight = SIMD_SUFFIX(qblock_sad)(ref, h, rowstride);
			shift_blk(8);
			if( weight <= threshold )
			{
				threshold = intmin(weight<<2,threshold);
				/* Rough and-ready absolute distance penalty */
				/* NOTE: This penalty is *vital* to correct operation 
				   as otherwise the sub-mean filtering won't work on very
				   uniform images.
				 */
				cres->weight = (uint16_t)(weight+(intmax(abs(x),abs(y))<<2));
				cres->x = (uint8_t)x;
				cres->y = (uint8_t)y;
				++cres;
			}
		}
		currowblk += gridrowstride;
	}
	emms();
	return cres - resvec;
}
Exemplo n.º 4
0
static void circle_test(Rcel *cel)
{
SHORT width = cel->width, height = cel->height;
SHORT xcen = width/2, ycen = height/2;
SHORT maxdiam = intmax(width,height)-2;
SHORT step = maxdiam/10;
static SHORT color = 0;
SHORT diam;
Chlidat chd;

chd.cel = cel;
for (diam=maxdiam; diam>=0; diam -= step)
	{
	chd.color = ++color;
	dcircle(xcen,ycen,diam,NULL,NULL,clip_chliout,&chd,TRUE);
	}
}
Exemplo n.º 5
0
/* Matrix multiplication C = A * B */
extern void amMul(ArrayMatrix C, ArrayMatrix A, ArrayMatrix B)
{
	mwSignedIndex np, nrow, ncol, nelem;

	/* Number of elements */
	nelem = intmax(A.nelem, B.nelem);

	/* Check if any of the arguments are a scalar */
	if (amIsScalar(A)) {
		/* Call scalar multiplication with A and B interchanged */
		nrow = B.nrow;
		ncol = B.ncol;
		if (A.complex || B.complex) {
			/* Complex multiplication */
			zsmul(C.data, B.data, A.data, B.nelem > 1, A.nelem > 1, nrow, ncol, nelem);
		} else {
			/* Real multiplication */
			dsmul(C.data, B.data, A.data, B.nelem > 1, A.nelem > 1, nrow, ncol, nelem);
		}
	} else if (amIsScalar(B)) {
		nrow = A.nrow;
		ncol = A.ncol;
		if (A.complex || B.complex) {
			/* Complex multiplication */
			zsmul(C.data, A.data, B.data, A.nelem > 1, B.nelem > 1, nrow, ncol, nelem);
		} else {
			/* Real multiplication */
			dsmul(C.data, A.data, B.data, A.nelem > 1, B.nelem > 1, nrow, ncol, nelem);
		}
	} else {
		nrow = A.nrow;
		ncol = B.ncol;
		np = A.ncol;
		if (A.complex || B.complex) {
			/* Complex multiplication */
			zgemul(C.data, A.data, B.data, A.nelem > 1, B.nelem > 1, np, nrow, ncol, nelem);
		} else {
			/* Real multiplication */
			dgemul(C.data, A.data, B.data, A.nelem > 1, B.nelem > 1, np, nrow, ncol, nelem);
		}
	}

}
Exemplo n.º 6
0
/* Solves AX=B */
extern void amSolve(ArrayMatrix X, ArrayMatrix A, ArrayMatrix B)
{
	mwSignedIndex n, nelem;
	mwSignedIndex block, stride, inc = 1;
	double *pB, *pX;

	nelem = intmax(A.nelem, B.nelem);

	if (A.complex || B.complex) {
		/* first copy B to X */
		pB = B.data;
		pX = X.data;
		if (B.nelem > 1) {
			block = nelem * B.nrow * B.ncol;
			BLASCALL(zcopy)(&block, pB, &inc, pX, &inc);
		} else {
			block = B.nrow * B.ncol;
			for (n = 0; n < nelem; n++) {
			  BLASCALL(zcopy)(&block, pB, &inc, pX, &inc);
			  pX += 2*block;
			}
		}
		znsolve(A.data, X.data, A.nelem > 1, 1, A.ncol, X.ncol, nelem);

	} else {
		pB = B.data;
		pX = X.data;
		if (B.nelem > 1) {
			block = nelem * B.nrow * B.ncol;
			BLASCALL(dcopy)(&block, pB, &inc, pX, &inc);
		} else {
			block = B.nrow * B.ncol;
			for (n = 0; n < nelem; n++) {
			  BLASCALL(dcopy)(&block, pB, &inc, pX, &inc);
				pX += block;
			}
		}

		dnsolve(A.data, X.data, A.nelem > 1, 1, A.ncol, X.ncol, nelem);

	}
}
Exemplo n.º 7
0
char* maf_mafLine_imputeLine(mafLine_t* ml) {
  // HEY!
  // IF you want to print a maf block, use maf_mafBlock_print(mafBlock_t *m). That is all.
  //
  // given a mafLine_t *, return a fresh char *
  // that represents a pretty print of the maf line.
  // i.e. it could be printed directly into a .maf file
  // uint32max = 4294967296 which is ~ 5 * 10^10
  char *s = (char*) de_malloc(2 + intmax(strlen(maf_mafLine_getSpecies(ml)), 15) +
                              15 + 15 + 3 + 15 + maf_mafLine_getSequenceFieldLength(ml) +
                              1 + 32); // extra 32 for possbile overflow from formatting
  sprintf(s, "s %-15s %10" PRIu64 " %10" PRIu64 " %c %10" PRIu64 " %s",
          maf_mafLine_getSpecies(ml),
          maf_mafLine_getStart(ml),
          maf_mafLine_getLength(ml),
          maf_mafLine_getStrand(ml),
          maf_mafLine_getSourceLength(ml),
          maf_mafLine_getSequence(ml));
  return s;
}
Exemplo n.º 8
0
void Meter::HandleLayout()
{
   int iconWidth = mIcon->GetWidth();
   int iconHeight = mIcon->GetHeight();
   int menuWidth = 17;
   int menuHeight = 14;
   int width = mWidth;
   int height = mHeight;
   int left = 0, top = 0;
   int right, bottom;
   int barw, barh;
   int i;

   mRuler.SetFlip(true);
   mRuler.SetLabelEdges(true);

   switch(mStyle) {
   default:
      wxPrintf(wxT("Style not handled yet!\n"));
      break;
   case VerticalStereo:
      #if WANT_METER_MENU
         mMenuRect = wxRect(mWidth - menuWidth - 5, mHeight - menuHeight - 2,
                            menuWidth, menuHeight);
         if (mHeight < (menuHeight + iconHeight + 8))
            mIconPos = wxPoint(-999, -999); // Don't display
         else
      #endif // WANT_METER_MENU
            mIconPos = wxPoint(mWidth - iconWidth - 1, 1);
      width = intmin(mWidth-(iconWidth+2), mWidth-(menuWidth+3));
      if (width >= mLeftSize.x + mRightSize.x + 24) {
         mLeftTextPos = wxPoint(2, height-2-mLeftSize.y);
         mRightTextPos = wxPoint(width-mLeftSize.x, height-2-mLeftSize.y);
         left += mLeftSize.x+4;
         width -= mLeftSize.x + mRightSize.x + 8;
      }
      barw = (width-2)/2;
      barh = height - 4;
      mNumBars = 2;
      mBar[0].vert = true;
      ResetBar(&mBar[0], false);
      mBar[0].r = wxRect(left + width/2 - barw - 1, 2, barw, barh);
      if (mClip) {
         mBar[0].rClip = mBar[0].r;
         mBar[0].rClip.height = 3;
         mBar[0].r.y += 4;
         mBar[0].r.height -= 4;
      }
      mBar[1].vert = true;
      ResetBar(&mBar[1], false);
      mBar[1].r = wxRect(left + width/2 + 1, 2, barw, barh);
      if (mClip) {
         mBar[1].rClip = mBar[1].r;
         mBar[1].rClip.height = 3;
         mBar[1].r.y += 4;
         mBar[1].r.height -= 4;
      }
      mRuler.SetOrientation(wxVERTICAL);
      mRuler.SetBounds(mBar[1].r.x + mBar[1].r.width + 1,
                       mBar[1].r.y,
                       mBar[1].r.x + width,
                       mBar[1].r.y + mBar[1].r.height);
      if (mDB) {
         mRuler.SetRange(0, -mDBRange);
         mRuler.SetFormat(Ruler::LinearDBFormat);
      }
      else {
         mRuler.SetRange(1, 0);
         mRuler.SetFormat(Ruler::RealFormat);
      }
      #if WANT_METER_MENU
         mRuler.OfflimitsPixels(mMenuRect.y-mBar[1].r.y, mBar[1].r.height);
      #endif // WANT_METER_MENU
      break;
   case HorizontalStereo:
      if (mWidth < menuWidth + iconWidth + 8) {
         mIconPos = wxPoint(-999, -999); // Don't display icon
         #if WANT_METER_MENU
            mMenuRect = wxRect(2, mHeight - menuHeight - 2,
                               menuWidth, menuHeight);
         #endif // WANT_METER_MENU
      }         
      else {
         mIconPos = wxPoint(2, mHeight - iconHeight);
         #if WANT_METER_MENU
            mMenuRect = wxRect(iconWidth + 2, mHeight - menuHeight - 5,
                               menuWidth, menuHeight);
         #endif // WANT_METER_MENU
      }
      height = intmin(height-(menuHeight+3), height-iconHeight) - 2;
      left = 2 + intmax(mLeftSize.x, mRightSize.x);
      width -= left;
      mLeftTextPos = wxPoint(2, (height)/4 - mLeftSize.y/2);
      mRightTextPos = wxPoint(2, (height*3)/4 - mLeftSize.y/2);
      barw = width - 4;
      barh = (height-2)/2;
      mNumBars = 2;
      mBar[0].vert = false;
      ResetBar(&mBar[0], false);
      mBar[0].r = wxRect(left+2, height/2 - barh - 1, barw, barh);
      if (mClip) {
         mBar[0].rClip = mBar[0].r;
         mBar[0].rClip.x += mBar[0].rClip.width-3;
         mBar[0].rClip.width = 3;
         mBar[0].r.width -= 4;
      }
      mBar[1].vert = false;
      ResetBar(&mBar[1], false);
      mBar[1].r = wxRect(left+2, height/2 + 1, barw, barh);
      if (mClip) {
         mBar[1].rClip = mBar[1].r;
         mBar[1].rClip.x += mBar[1].rClip.width-3;
         mBar[1].rClip.width = 3;
         mBar[1].r.width -= 4;
      }
      mRuler.SetOrientation(wxHORIZONTAL);
      mRuler.SetBounds(mBar[1].r.x,
                       mBar[1].r.y + mBar[1].r.height + 1,
                       mBar[1].r.x + mBar[1].r.width,
                       mWidth);
      if (mDB) {
         mRuler.SetRange(-mDBRange, 0);
         mRuler.SetFormat(Ruler::LinearDBFormat);
      }
      else {
         mRuler.SetRange(0, 1);
         mRuler.SetFormat(Ruler::RealFormat);
      }
      #if WANT_METER_MENU
         mRuler.OfflimitsPixels(0, mMenuRect.x+mMenuRect.width-4);
      #endif // WANT_METER_MENU
      break;
   case Waveform:
      mNumBars = 0;
      break;
   }

   if (mNumBars > 0) {
      // Compute bounding rectangle of all bars (to save time when
      // blitting just the bars to the screen)
      left = mBar[0].r.x;
      top = mBar[0].r.y;
      right = mBar[0].r.x + mBar[0].r.width;
      bottom = mBar[0].r.y + mBar[0].r.height;
      for(i=1; i<mNumBars; i++) {
         left = intmin(left, mBar[i].r.x);
         top = intmin(top, mBar[i].r.y);
         right = intmax(right, mBar[i].r.x + mBar[i].r.width);
         bottom = intmax(bottom, mBar[i].r.y + mBar[i].r.height);
         left = intmin(left, mBar[i].rClip.x);
         top = intmin(top, mBar[i].rClip.y);
         right = intmax(right, mBar[i].rClip.x + mBar[i].rClip.width);
         bottom = intmax(bottom, mBar[i].rClip.y + mBar[i].rClip.height);

      }
      mAllBarsRect = wxRect(left, top, right-left+1, bottom-top+1);
   }

   CreateIcon(mIconPos.y % 4);

   mLayoutValid = true;
}