예제 #1
0
/** The transposes matrix src into dst
	Matricies must be the same type and appropriatly sized.
	dst(i,j)=src(j,i)
*/
merror mTranspose( const Mat* src, Mat* dst )
{
	int i,j;
	const Mat *A = src;
	Mat *D = dst;
	
	// Error checking
	if(src == NULL || dst == NULL)
		return mError(MAT_ERROR_NULL_PTR);


	// Are the matrices the same type?
	if(A->type != D->type)
	{
		mZero(D);
		return mError(MAT_ERROR_MISMATCHED_TYPES);
	}

	// Are the matrices the same size?
	if(A->cols != D->cols || A->rows != D->rows)
	{
		mZero(D);
		return mError(MAT_ERROR_MISMATCHED_SIZES);
	}


	// Transpose the matrix
	for(i = 0 ; i < A->rows ; i++)
		for(j = 0 ; j < A->cols ; j++)
			mSet(D,j,i, mGet(A,i,j));	

	return MAT_OK;
}
예제 #2
0
void SerialPortThread::mStart(SerialPortSettings::Settings __settings)
{
    m_serialPortMutex.lock();
    m_isStopped = false;
    m_serialPortMutex.unlock();

    mSet(__settings);

    if (!this->isRunning())
        this->start();
}
예제 #3
0
/** Scales all values of the matrix by the specified value
*/
merror mScale(Mat* mat, float scale)
{
	int i,j;
	
	if(mat == NULL)
		return mError(MAT_ERROR_NULL_PTR);
	
	for(i = 0 ; i < mat->rows ; i++)
		for(j = 0 ; j < mat->cols ; j++)
			mSet(mat,i,j, scale * mGet(mat,i,j));	

	return MAT_OK;
}
예제 #4
0
/** Sets all values of the matrix to the specified value
*/
merror mSetAll( Mat* mat, float value)
{
	int i,j;
	
	if(mat == NULL)
		return mError(MAT_ERROR_NULL_PTR);
	
	for(i = 0 ; i < mat->rows ; i++)
		for(j = 0 ; j < mat->cols ; j++)
			mSet(mat,i,j, value);	

	return MAT_OK;
}
예제 #5
0
/** Initializes to the identity matrix
*/
merror mSetIdentity( Mat* mat)
{
	int i;
	
	if(mat == NULL)
		return mError(MAT_ERROR_NULL_PTR);

	mZero(mat);
	for(i = 0 ; i < mat->rows && i < mat->cols ; i++)
		mSet(mat,i,i,1);

	return MAT_OK;
}
예제 #6
0
파일: ps3eye.c 프로젝트: michalsc/AROS
BOOPSI_DISPATCHER(IPTR, classdispatcher, cl, obj, msg) {
    mybug(0,("Class Dispatcher!\n"));

    switch (msg->MethodID) {

        case OM_NEW:
            return mNew(cl,obj,(APTR)msg);
        case OM_DISPOSE:
            return mDispose(cl,obj,(APTR)msg);

        case MUIM_Setup:
            return mSetup(cl,obj,(APTR)msg);
        case MUIM_Cleanup:
            return mCleanup(cl,obj,(APTR)msg);

        case OM_SET:
            return mSet(cl,obj,(APTR)msg);
        case OM_GET:
            return mGet(cl,obj,(APTR)msg);

        case MUIM_AskMinMax:
            return mAskMinMax(cl,obj,(APTR)msg);
        case MUIM_Hide:
            return mHide(cl,obj,(APTR)msg);
        case MUIM_Show:
            return mShow(cl,obj,(APTR)msg);

        case MUIM_Draw:
            return mDraw(cl,obj,(APTR)msg);

//        case MUIM_Action_HandlePsdEvents:
//            return mPsdEventHandler(cl,obj,(APTR)msg);

        case MUIM_Action_HandleTmrEvents:
            return mTmrEventHandler(cl,obj,(APTR)msg);

        default:
            return DoSuperMethodA(cl,obj,msg);
    }

    return 0;
}
예제 #7
0
/** Performs specified opperation on matrix data (element by element)
	This function implements several of the various element opperations that 
	can be performed on two or just one matrix. For example, if you wanted to 
	add two matricies together:
	\pre
	mElem(A, B, D, 0, 0, ELEM_ADD);
	\endpre

	All possible operations are listed in the mElementOpperation enumeration.
*/ 
merror mElem( const Mat* src1, const Mat* src2, Mat* dst, const float scaler, const uint32 bit_vector, int op)
{
	int i,j;
	const Mat *A = src1;
	const Mat *B = src2;
	Mat *D = dst;

	if(B != NULL) /*B will be NULL if we are just doing a scaler opperation*/
	{
		// Are ALL the matrices the same type?
		if(A->type != B->type || A->type != D->type )
		{
			mZero(D);
			return mError(MAT_ERROR_MISMATCHED_TYPES);
		}

		// Are the matrices the same size?
		if(    A->cols != B->cols || A->cols != D->cols 
			|| A->rows != B->rows || A->rows != D->rows )
		{
			mZero(D);
			return mError(MAT_ERROR_MISMATCHED_SIZES);
		}
	}
	else
	{
		// Are ALL the matrices the same type?
		if(A->type != D->type )
		{
			mZero(D);
			return mError(MAT_ERROR_MISMATCHED_TYPES);
		}

		// Are the matrices the same size?
		if(    A->cols != D->cols 
			|| A->rows != D->rows )
		{
			mZero(D);
			return mError(MAT_ERROR_MISMATCHED_SIZES);
		}
	}

	
	

	switch(op){
	case ELEM_ADD: 
		for(i = 0 ; i < A->rows ; i++)
			for(j = 0 ; j < A->cols ; j++)
				mSet(D,i,j, mGet(A,i,j) + mGet(B,i,j));	
		break;
	

	case ELEM_ADDS: 
		for(i = 0 ; i < A->rows ; i++)
			for(j = 0 ; j < A->cols ; j++)
				mSet(D,i,j, mGet(A,i,j) + scaler);	
		break;
	

	case ELEM_SUB: 
		for(i = 0 ; i < A->rows ; i++)
			for(j = 0 ; j < A->cols ; j++)
				mSet(D,i,j, mGet(A,i,j) - mGet(B,i,j));	
		break;

	case ELEM_SUBS: 
		for(i = 0 ; i < A->rows ; i++)
			for(j = 0 ; j < A->cols ; j++)
				mSet(D,i,j, mGet(A,i,j) - scaler);	
		break;

	case ELEM_MUL: 
		for(i = 0 ; i < A->rows ; i++)
			for(j = 0 ; j < A->cols ; j++)
				mSet(D,i,j, mGet(A,i,j) * mGet(B,i,j));	
		break;
	
	case ELEM_MULS: 
		for(i = 0 ; i < A->rows ; i++)
			for(j = 0 ; j < A->cols ; j++)
				mSet(D,i,j, mGet(A,i,j) * scaler);	
		break;
	
	case ELEM_DIV: 
		for(i = 0 ; i < A->rows ; i++)
			for(j = 0 ; j < A->cols ; j++)
				mSet(D,i,j, mGet(A,i,j) / mGet(B,i,j));	
		break;

	case ELEM_DIVS: 
		if(scaler == 0)
		{
			mZero(D);
			return mError(MAT_ERROR_DIVIDE_BY_0);
		}
		for(i = 0 ; i < A->rows ; i++)
			for(j = 0 ; j < A->cols ; j++)
				mSet(D,i,j, mGet(A,i,j) / scaler);	
		break;
	

	}
		
	return MAT_OK;
}
예제 #8
0
/** Performs generalized matrix multiplication
	The flags indicate if any of the three matricies should be transposed.

	- Flags:
		- MUL_A_T = Transpose source matrix A
		- MUL_B_T = Transpose source matrix B
		- MUL_D_T = Transpose destination matrix D

	\pre
	dst = alpha*src1T*src2 
	\endpre
*/
merror mGEMM(Mat* src1, Mat* src2, float alpha, Mat* dst , uint32 flags )
{
	int i, j, k, iend, jend, kend;
	float sum;
	Mat *A = src1;
	Mat *B = src2;
	Mat *D = dst;

	// Are ALL the matrices the same type?
	if(A->type != B->type || A->type != D->type )
	{
		mZero(D);
		return mError(MAT_ERROR_MISMATCHED_TYPES);
	}
	
	// Are A and B multiliable?
	{
		int A_dimension = (flags & MUL_A_T) ? A->rows : A->cols;
		int B_dimension = (flags & MUL_B_T) ? B->cols : B->rows;

		if(A_dimension != B_dimension)
		{
			mZero(D);
			return mError(MAT_MUL_ERROR_MISMATCHED_SIZE_AB);
		}
	}

	//Does the destination have the corerct number of rows?
	{
		int A_dimension = (flags & MUL_A_T) ? A->cols : A->rows;
		int D_dimension = (flags & MUL_D_T) ? D->cols : D->rows;

		if(A_dimension != D_dimension)
		{
			mZero(D);
			return mError(MAT_MUL_ERROR_MISMATCHED_ROWS_D);
		}
	}

	//Does the destination have the corerct number of cols?
	{
		int B_dimension = (flags & MUL_B_T) ? B->rows : B->cols;
		int D_dimension = (flags & MUL_D_T) ? D->rows : D->cols;

		if(B_dimension != D_dimension)
		{
			mZero(D);
			return mError(MAT_MUL_ERROR_MISMATCHED_COLS_D);
		}
	}

	
	iend = (flags & MUL_B_T) ? B->rows : B->cols;
	jend = (flags & MUL_A_T) ? A->cols : A->rows;
	kend = (flags & MUL_A_T) ? A->rows : A->cols;

	switch(flags){
	case 0:	
		/* No transposes. Straight multiply 
		 * indexes:
		 * i = bcol, dcol
		 * j = arow, drow
		 * k = acol, brow
		 */			
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{				
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,j,k) * mGet(B,k,i);
				mSet(D,j,i,alpha*sum);
			}
		}	
		break;		

	case MUL_A_T:
		/* Transpose: A
		 * indexes:
		 * i = bcol, dcol
		 * j = acol, drow
		 * k = arow, brow
		 */				
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,k,j) * mGet(B,k,i);
				mSet(D,j,i,alpha*sum);
			}
		}	
		break;		

	case MUL_B_T:
		/* Transpose: B
		 * indexes:
		 * i = brow, dcol
		 * j = arow, drow
		 * k = acol, bcol
		 */		
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)				
					sum += mGet(A,j,k) * mGet(B,i,k);				
				mSet(D,j,i,alpha*sum);
			}
		}	
		break;

	case MUL_B_T | MUL_A_T:	
		/* Transpose: A,B
		 * indexes:
		 * i = brow, dcol
		 * j = acol, drow
		 * k = arow, bcol
		 */		
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,k,j) * mGet(B,i,k);
				mSet(D,j,i,alpha*sum);
			}
		}
		break;

	case MUL_D_T:	
		/* Transpose: D
		 * indexes:
		 * i = bcol, drow
		 * j = arow, dcol
		 * k = acol, brow
		 */	
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,j,k) * mGet(B,k,i);
				mSet(D,i,j,alpha*sum);
			}
		}	
		break;

	case MUL_D_T | MUL_A_T:	
		/* Transpose: D,A
		 * indexes:
		 * i = bcol, drow
		 * j = acol, dcol
		 * k = arow, brow
		 */	
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,k,j) * mGet(B,k,i);
				mSet(D,i,j,alpha*sum);
			}
		}	
		break;

	case MUL_D_T | MUL_B_T:	
		/* Transpose: D,B
		 * indexes:
		 * i = brow, drow
		 * j = arow, dcol
		 * k = acol, bcol
		 */	
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,j,k) * mGet(B,i,k);
				mSet(D,i,j,alpha*sum);
			}
		}	
		break;

	case MUL_D_T | MUL_B_T | MUL_A_T:
		/* Transpose: D,B,A
		 * indexes:
		 * i = brow, drow
		 * j = acol, dcol
		 * k = arow, bcol
		 */	
		for(i = 0 ; i < iend ; i++)
		{
			for(j = 0 ; j < jend ; j++)
			{
				for(k = 0, sum = 0 ; k < kend ; k++)
					sum += mGet(A,k,j) * mGet(B,i,k);
				mSet(D,i,j,alpha*sum);
			}
		}	
		break;
	}

	return MAT_OK;
}