Exemplo n.º 1
0
/// Re-arranges internal elements based on pre-configured or newly set options. Does not create or delete anything.
void UIMatrix::FormatContents()
{
	float labelHeightY = 0.0f;
//	if (label)
//		labelHeightY = label->sizeRatioY;
	float elementWidth = 1.0f / columns;
	float elementHeight = (1.0f - labelHeightY) / rows;

	Matrix<UIElement*> layoutMatrix; // Going downward in Y for each step.
	layoutMatrix.SetDefaultValue(NULL);
	layoutMatrix.SetSize(Vector2i(columns, rows));

	/// Create 'em.
	int formattedElements = 0;
	for (int y = 0; y < rows; ++y)
	{
		for (int x = 0; x < columns; ++x)
		{
			UIElement * element = matrixElements[formattedElements];
			layoutMatrix.Set(Vector2i(x, y), element);
			// Remove it first, if already there.
			RemoveChild(element);

			/// Give new alignments and size-ratios based on the matrix cell size.
			element->alignmentX = (x+0.5f) * elementWidth;
			element->alignmentY = 1.0f - (y + 0.5f) * elementHeight - labelHeightY;
			element->sizeRatioX = elementWidth;
			element->sizeRatioY = elementHeight;
			/// And add it!
			AddChild(element);
			// Make sure that the element is re-built next frame?
			++formattedElements;
			if (formattedElements >= matrixElements.Size())
				goto initialFormattingDone;
		}
	}
initialFormattingDone:
	/// After filling the matrix, set neighbour-elements accordingly.
	for (int i = 0; i < layoutMatrix.Elements(); ++i)
	{
		UIElement * element = layoutMatrix.Element(i);
		if (!element)
			continue;
		Vector2i matrixPos = layoutMatrix.GetLocationOf(element);
		/// Fetch right-left first.
		Vector2i leftPos = matrixPos + Vector2i(-1,0);
		if (layoutMatrix.ValidPosition(leftPos))
		{
			UIElement * left = layoutMatrix.GetItem(leftPos);
			if (left)
			{
				element->leftNeighbourName = left->name;
				left->rightNeighbourName = element->name;
			}
		}
		// Bottom-top neighbours
		Vector2i bottomPos = matrixPos + Vector2i(0, 1);
		if (layoutMatrix.ValidPosition(bottomPos))
		{
			UIElement * bottom = layoutMatrix.GetItem(bottomPos);
			if (bottom)
			{
				element->downNeighbourName = bottom->name;
				bottom->upNeighbourName = element->name;
			}
		}
	}

	;
}
Exemplo n.º 2
0
Matrix operator * (const Matrix& A, const Matrix& B)
{
    if (A.Clo() != B.Rlo() || A.Chi() != B.Rhi()) 
      Matpack.Error("Matrix operator * (const Matrix&, const Matrix&): "
                    "non conformant arguments\n");

    // allocate return matrix
    Matrix C(A.Rlo(),A.Rhi(),B.Clo(),B.Chi());
    
    //------------------------------------------------------------------------//
    // the BLAS version
    //------------------------------------------------------------------------//

#if defined ( _MATPACK_USE_BLAS_ )

    if ( LT(B) ) {                   // full matrix * lower triangle
#ifdef DEBUG
        cout << "GM*LT\n";
#endif
        checksquare(B);

        // copy A to C to protect from overwriting
        copyvec(C.Store(),A.Store(),A.Elements());

        charT   side('L'), uplo('U'), transc('N'), diag('N');
        intT    m(C.Cols()), n(C.Rows()),
                ldb(B.Cols()), ldc(C.Cols());
        doubleT alpha(1.0);
        
        F77NAME(dtrmm)(&side,&uplo,&transc,&diag,&m,&n,
                       &alpha,B.Store(),&ldb, C.Store(),&ldc);


    } else if ( UT(B) ) {             // full matrix * upper triangle
#ifdef DEBUG
        cout << "GM*UT\n";
#endif
        checksquare(B);

        // copy A to C to protect from overwriting
        copyvec(C.Store(),A.Store(),A.Elements());

        charT   side('L'), uplo('L'), transc('N'), diag('N');
        intT    m(C.Cols()), n(C.Rows()),
                ldb(B.Cols()), ldc(C.Cols());
        doubleT alpha(1.0);
        
        F77NAME(dtrmm)(&side,&uplo,&transc,&diag,&m,&n,
                       &alpha,B.Store(),&ldb, C.Store(),&ldc);


    } else if ( LT(A) ) {            // lower triangle * full matrix
#ifdef DEBUG
        cout << "LT*GM\n";
#endif

        checksquare(A);

        // copy B to C to protect from overwriting
        copyvec(C.Store(),B.Store(),B.Elements());

        charT   side('R'), uplo('U'), transc('N'), diag('N');
        intT    m(C.Cols()), n(C.Rows()),
                ldb(A.Cols()), ldc(C.Cols());
        doubleT alpha(1.0);
        
        F77NAME(dtrmm)(&side,&uplo,&transc,&diag,&m,&n,
                       &alpha,A.Store(),&ldb, C.Store(),&ldc);



    } else if ( UT(A) ) {            // upper triangle * full matrix
#ifdef DEBUG
        cout << "UT*GM\n";
#endif
        checksquare(A);

        // copy A to C to protect from overwriting
        copyvec(C.Store(),B.Store(),B.Elements());

        charT   side('R'), uplo('L'), transc('N'), diag('N');
        intT    m(C.Cols()), n(C.Rows()),
                ldb(A.Cols()), ldc(C.Cols());
        doubleT alpha(1.0);
        
        F77NAME(dtrmm)(&side,&uplo,&transc,&diag,&m,&n,
                       &alpha,A.Store(),&ldb, C.Store(),&ldc);

    } else /* GM(A) and GM(B) */ {   // GM*GM: full matrix * full matrix
#ifdef DEBUG
        cout << "GM*GM\n";
#endif

        charT   t('N');
        intT    m(B.Cols()), n(A.Rows()), k(B.Rows()),
                lda(A.Cols()), ldb(B.Cols()), ldc(C.Cols());
        doubleT alpha(1.0), beta(0.0);
        
        F77NAME(dgemm)(&t,&t, &m,&n,&k,
                       &alpha,B.Store(),&ldb, A.Store(),&lda, 
                       &beta,C.Store(),&ldc);
    }

    //------------------------------------------------------------------------//
    // the non-BLAS version
    //------------------------------------------------------------------------//

#else
    int  cl = A.cl,   ch = A.ch,
        arl = A.rl,  arh = A.rh,
        bcl = B.cl,  bch = B.ch;

    // avoid call to index operator that optimizes very badely
    double **a = A.M, **b = B.M, **c = C.M;
    for (int i = arl; i <= arh; i++)  {
        for (int j = bcl; j <= bch; j++) c[i][j] = 0.0;
        for (int l = cl; l <= ch; l++) {
            if ( a[i][l] != 0.0 ) {
                double temp = a[i][l];
                for (int j = bcl; j <= bch; j++)
                    c[i][j] += temp * b[l][j];
            }
        }
    }

#endif

    return C.Value();
}