本文整理汇总了C++中Matrix::Elements方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix::Elements方法的具体用法?C++ Matrix::Elements怎么用?C++ Matrix::Elements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix::Elements方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FormatContents
/// 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;
}
}
}
;
}
示例2: C
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,
//.........这里部分代码省略.........