VTK-m  2.0
Matrix.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_Matrix_h
11 #define vtk_m_Matrix_h
12 
13 #include <vtkm/Assert.h>
14 #include <vtkm/Math.h>
15 #include <vtkm/TypeTraits.h>
16 #include <vtkm/Types.h>
17 #include <vtkm/VecTraits.h>
18 
19 namespace vtkm
20 {
21 
32 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
33 class Matrix
34 {
35 public:
36  using ComponentType = T;
37  static constexpr vtkm::IdComponent NUM_ROWS = NumRow;
38  static constexpr vtkm::IdComponent NUM_COLUMNS = NumCol;
39 
41  Matrix() {}
42 
44  explicit Matrix(const ComponentType& value)
46  {
47  }
48 
54  {
55  VTKM_ASSERT(rowIndex >= 0);
56  VTKM_ASSERT(rowIndex < NUM_ROWS);
57  return this->Components[rowIndex];
58  }
59 
65  {
66  VTKM_ASSERT(rowIndex >= 0);
67  VTKM_ASSERT(rowIndex < NUM_ROWS);
68  return this->Components[rowIndex];
69  }
70 
76  {
77  VTKM_ASSERT(rowIndex >= 0);
78  VTKM_ASSERT(rowIndex < NUM_ROWS);
79  VTKM_ASSERT(colIndex >= 0);
80  VTKM_ASSERT(colIndex < NUM_COLUMNS);
81  return (*this)[rowIndex][colIndex];
82  }
83 
89  {
90  VTKM_ASSERT(rowIndex >= 0);
91  VTKM_ASSERT(rowIndex < NUM_ROWS);
92  VTKM_ASSERT(colIndex >= 0);
93  VTKM_ASSERT(colIndex < NUM_COLUMNS);
94  return (*this)[rowIndex][colIndex];
95  }
96 
97 private:
99 };
100 
104 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
106  const vtkm::Matrix<T, NumRow, NumCol>& matrix,
107  vtkm::IdComponent rowIndex)
108 {
109  return matrix[rowIndex];
110 }
111 
115 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
117  vtkm::IdComponent columnIndex)
118 {
119  vtkm::Vec<T, NumRow> columnValues;
120  for (vtkm::IdComponent rowIndex = 0; rowIndex < NumRow; rowIndex++)
121  {
122  columnValues[rowIndex] = matrix(rowIndex, columnIndex);
123  }
124  return columnValues;
125 }
126 
129 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
131  vtkm::IdComponent rowIndex,
132  const vtkm::Vec<T, NumCol>& rowValues)
133 {
134  matrix[rowIndex] = rowValues;
135 }
136 
139 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
141  vtkm::IdComponent columnIndex,
142  const vtkm::Vec<T, NumRow>& columnValues)
143 {
144  for (vtkm::IdComponent rowIndex = 0; rowIndex < NumRow; rowIndex++)
145  {
146  matrix(rowIndex, columnIndex) = columnValues[rowIndex];
147  }
148 }
149 
152 template <typename T,
153  vtkm::IdComponent NumRow,
154  vtkm::IdComponent NumCol,
155  vtkm::IdComponent NumInternal>
157  const vtkm::Matrix<T, NumRow, NumInternal>& leftFactor,
158  const vtkm::Matrix<T, NumInternal, NumCol>& rightFactor)
159 {
161  for (vtkm::IdComponent rowIndex = 0; rowIndex < NumRow; rowIndex++)
162  {
163  for (vtkm::IdComponent colIndex = 0; colIndex < NumCol; colIndex++)
164  {
165  T sum = T(leftFactor(rowIndex, 0) * rightFactor(0, colIndex));
166  for (vtkm::IdComponent internalIndex = 1; internalIndex < NumInternal; internalIndex++)
167  {
168  sum = T(sum + (leftFactor(rowIndex, internalIndex) * rightFactor(internalIndex, colIndex)));
169  }
170  result(rowIndex, colIndex) = sum;
171  }
172  }
173  return result;
174 }
175 
178 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
180  const vtkm::Matrix<T, NumRow, NumCol>& leftFactor,
181  const vtkm::Vec<T, NumCol>& rightFactor)
182 {
183  vtkm::Vec<T, NumRow> product;
184  for (vtkm::IdComponent rowIndex = 0; rowIndex < NumRow; rowIndex++)
185  {
186  product[rowIndex] = vtkm::Dot(vtkm::MatrixGetRow(leftFactor, rowIndex), rightFactor);
187  }
188  return product;
189 }
190 
193 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
195  const vtkm::Vec<T, NumRow>& leftFactor,
196  const vtkm::Matrix<T, NumRow, NumCol>& rightFactor)
197 {
198  vtkm::Vec<T, NumCol> product;
199  for (vtkm::IdComponent colIndex = 0; colIndex < NumCol; colIndex++)
200  {
201  product[colIndex] = vtkm::Dot(leftFactor, vtkm::MatrixGetColumn(rightFactor, colIndex));
202  }
203  return product;
204 }
205 
208 template <typename T, vtkm::IdComponent Size>
210 {
211  vtkm::Matrix<T, Size, Size> result(T(0));
212  for (vtkm::IdComponent index = 0; index < Size; index++)
213  {
214  result(index, index) = T(1.0);
215  }
216  return result;
217 }
218 
221 template <typename T, vtkm::IdComponent Size>
223 {
224  matrix = vtkm::MatrixIdentity<T, Size>();
225 }
226 
229 template <typename T, vtkm::IdComponent NumRows, vtkm::IdComponent NumCols>
231  const vtkm::Matrix<T, NumRows, NumCols>& matrix)
232 {
234  for (vtkm::IdComponent index = 0; index < NumRows; index++)
235  {
236  vtkm::MatrixSetColumn(result, index, vtkm::MatrixGetRow(matrix, index));
237 #ifdef VTKM_ICC
238  // For reasons I do not really understand, the Intel compiler with with
239  // optimization on is sometimes removing this for loop. It appears that the
240  // optimizer sometimes does not recognize that the MatrixSetColumn function
241  // has side effects. I cannot fathom any reason for this other than a bug in
242  // the compiler, but unfortunately I do not know a reliable way to
243  // demonstrate the problem.
244  __asm__("");
245 #endif
246  }
247  return result;
248 }
249 
250 namespace detail
251 {
252 
253 // Used with MatrixLUPFactor.
254 template <typename T, vtkm::IdComponent Size>
255 VTKM_EXEC_CONT void MatrixLUPFactorFindPivot(vtkm::Matrix<T, Size, Size>& A,
257  vtkm::IdComponent topCornerIndex,
258  T& inversionParity,
259  bool& valid)
260 {
261  vtkm::IdComponent maxRowIndex = topCornerIndex;
262  T maxValue = vtkm::Abs(A(maxRowIndex, topCornerIndex));
263  for (vtkm::IdComponent rowIndex = topCornerIndex + 1; rowIndex < Size; rowIndex++)
264  {
265  T compareValue = vtkm::Abs(A(rowIndex, topCornerIndex));
266  if (maxValue < compareValue)
267  {
268  maxValue = compareValue;
269  maxRowIndex = rowIndex;
270  }
271  }
272 
273  if (maxValue < vtkm::Epsilon<T>())
274  {
275  valid = false;
276  return;
277  }
278 
279  if (maxRowIndex != topCornerIndex)
280  {
281  // Swap rows in matrix.
282  vtkm::Vec<T, Size> maxRow = vtkm::MatrixGetRow(A, maxRowIndex);
283  vtkm::MatrixSetRow(A, maxRowIndex, vtkm::MatrixGetRow(A, topCornerIndex));
284  vtkm::MatrixSetRow(A, topCornerIndex, maxRow);
285 
286  // Record change in permutation matrix.
287  vtkm::IdComponent maxOriginalRowIndex = permutation[maxRowIndex];
288  permutation[maxRowIndex] = permutation[topCornerIndex];
289  permutation[topCornerIndex] = maxOriginalRowIndex;
290 
291  // Keep track of inversion parity.
292  inversionParity = -inversionParity;
293  }
294 }
295 
296 // Used with MatrixLUPFactor
297 template <typename T, vtkm::IdComponent Size>
298 VTKM_EXEC_CONT void MatrixLUPFactorFindUpperTriangleElements(vtkm::Matrix<T, Size, Size>& A,
299  vtkm::IdComponent topCornerIndex,
300  bool& valid)
301 {
302  // Compute values for upper triangle on row topCornerIndex
303  if (A(topCornerIndex, topCornerIndex) == 0)
304  {
305  valid = false;
306  return;
307  }
308  else
309  {
310  // Let's make the reciprocal approximation here.
311  // Doesn't make things much fast for small 'Size',
312  // but definitely improves performance as 'Size' gets large.
313  T rAdiag = 1 / A(topCornerIndex, topCornerIndex);
314  for (vtkm::IdComponent colIndex = topCornerIndex + 1; colIndex < Size; colIndex++)
315  {
316  A(topCornerIndex, colIndex) *= rAdiag;
317  }
318  }
319 
320  // Update the rest of the matrix for calculations on subsequent rows
321  for (vtkm::IdComponent rowIndex = topCornerIndex + 1; rowIndex < Size; rowIndex++)
322  {
323  for (vtkm::IdComponent colIndex = topCornerIndex + 1; colIndex < Size; colIndex++)
324  {
325  A(rowIndex, colIndex) -= A(rowIndex, topCornerIndex) * A(topCornerIndex, colIndex);
326  }
327  }
328 }
329 
360 template <typename T, vtkm::IdComponent Size>
361 VTKM_EXEC_CONT void MatrixLUPFactor(vtkm::Matrix<T, Size, Size>& A,
363  T& inversionParity,
364  bool& valid)
365 {
366  // Initialize permutation.
367  for (vtkm::IdComponent index = 0; index < Size; index++)
368  {
369  permutation[index] = index;
370  }
371  inversionParity = T(1);
372  valid = true;
373 
374  for (vtkm::IdComponent rowIndex = 0; rowIndex < Size; rowIndex++)
375  {
376  MatrixLUPFactorFindPivot(A, permutation, rowIndex, inversionParity, valid);
377  if (!valid)
378  {
379  break;
380  }
381  MatrixLUPFactorFindUpperTriangleElements(A, rowIndex, valid);
382  if (!valid)
383  {
384  break;
385  }
386  }
387 }
388 
393 template <typename T, vtkm::IdComponent Size>
394 VTKM_EXEC_CONT vtkm::Vec<T, Size> MatrixLUPSolve(
395  const vtkm::Matrix<T, Size, Size>& LU,
396  const vtkm::Vec<vtkm::IdComponent, Size>& permutation,
397  const vtkm::Vec<T, Size>& b)
398 {
399  // The LUP-factorization gives us PA = LU or equivalently A = inv(P)LU.
400  // Substituting into Ax = b gives us inv(P)LUx = b or LUx = Pb.
401  // Now consider the intermediate vector y = Ux.
402  // Substituting in the previous two equations yields Ly = Pb.
403  // Solving Ly = Pb is easy because L is triangular and P is just a
404  // permutation.
406  for (vtkm::IdComponent rowIndex = 0; rowIndex < Size; rowIndex++)
407  {
408  y[rowIndex] = b[permutation[rowIndex]];
409  // Recall that L is stored in the lower triangle of LU including diagonal.
410  for (vtkm::IdComponent colIndex = 0; colIndex < rowIndex; colIndex++)
411  {
412  y[rowIndex] -= LU(rowIndex, colIndex) * y[colIndex];
413  }
414  if (LU(rowIndex, rowIndex) == 0)
415  {
416  y[rowIndex] = std::numeric_limits<T>::quiet_NaN();
417  }
418  else
419  {
420  y[rowIndex] /= LU(rowIndex, rowIndex);
421  }
422  }
423 
424  // Now that we have y, we can easily solve Ux = y for x.
426  for (vtkm::IdComponent rowIndex = Size - 1; rowIndex >= 0; rowIndex--)
427  {
428  // Recall that U is stored in the upper triangle of LU with the diagonal
429  // implicitly all 1's.
430  x[rowIndex] = y[rowIndex];
431  for (vtkm::IdComponent colIndex = rowIndex + 1; colIndex < Size; colIndex++)
432  {
433  x[rowIndex] -= LU(rowIndex, colIndex) * x[colIndex];
434  }
435  }
436 
437  return x;
438 }
439 
440 } // namespace detail
441 
445 template <typename T, vtkm::IdComponent Size>
447  const vtkm::Vec<T, Size>& b,
448  bool& valid)
449 {
450  // First, we will make an LUP-factorization to help us.
453  T inversionParity; // Unused.
454  detail::MatrixLUPFactor(LU, permutation, inversionParity, valid);
455 
456  // Next, use the decomposition to solve the system.
457  return detail::MatrixLUPSolve(LU, permutation, b);
458 }
459 
463 template <typename T, vtkm::IdComponent Size>
465  bool& valid)
466 {
467  // First, we will make an LUP-factorization to help us.
470  T inversionParity; // Unused
471  detail::MatrixLUPFactor(LU, permutation, inversionParity, valid);
472 
473  // We will use the decomposition to solve AX = I for X where X is
474  // clearly the inverse of A. Our solve method only works for vectors,
475  // so we solve for one column of invA at a time.
477  vtkm::Vec<T, Size> ICol(T(0));
478  for (vtkm::IdComponent colIndex = 0; colIndex < Size; colIndex++)
479  {
480  ICol[colIndex] = 1;
481  vtkm::Vec<T, Size> invACol = detail::MatrixLUPSolve(LU, permutation, ICol);
482  ICol[colIndex] = 0;
483  vtkm::MatrixSetColumn(invA, colIndex, invACol);
484  }
485  return invA;
486 }
487 
490 template <typename T, vtkm::IdComponent Size>
492 {
493  // First, we will make an LUP-factorization to help us.
496  T inversionParity;
497  bool valid;
498  detail::MatrixLUPFactor(LU, permutation, inversionParity, valid);
499 
500  // If the matrix is singular, the factorization is invalid, but in that
501  // case we know that the determinant is 0.
502  if (!valid)
503  {
504  return 0;
505  }
506 
507  // The determinant is equal to the product of the diagonal of the L matrix,
508  // possibly negated depending on the parity of the inversion. The
509  // inversionParity variable is set to 1.0 and -1.0 for even and odd parity,
510  // respectively. This sign determines whether the product should be negated.
511  T product = inversionParity;
512  for (vtkm::IdComponent index = 0; index < Size; index++)
513  {
514  product *= LU(index, index);
515  }
516  return product;
517 }
518 
519 // Specializations for common small determinants.
520 
521 template <typename T>
523 {
524  return A(0, 0);
525 }
526 
527 template <typename T>
529 {
530  return vtkm::DifferenceOfProducts(A(0, 0), A(1, 1), A(1, 0), A(0, 1));
531 }
532 
533 template <typename T>
535 {
536  return A(0, 0) * A(1, 1) * A(2, 2) + A(1, 0) * A(2, 1) * A(0, 2) + A(2, 0) * A(0, 1) * A(1, 2) -
537  A(0, 0) * A(2, 1) * A(1, 2) - A(1, 0) * A(0, 1) * A(2, 2) - A(2, 0) * A(1, 1) * A(0, 2);
538 }
539 
540 //---------------------------------------------------------------------------
541 // Implementations of traits for matrices.
542 
547 {
548 };
549 
550 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
551 struct TypeTraits<vtkm::Matrix<T, NumRow, NumCol>>
552 {
555 
558  {
560  }
561 };
562 
565 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
566 struct VecTraits<vtkm::Matrix<T, NumRow, NumCol>>
567 {
568 private:
570 
571 public:
572  using ComponentType = T;
574  static constexpr vtkm::IdComponent NUM_COMPONENTS = NumRow * NumCol;
577 
580 
582  static const ComponentType& GetComponent(const MatrixType& matrix, vtkm::IdComponent component)
583  {
584  vtkm::IdComponent colIndex = component % NumCol;
585  vtkm::IdComponent rowIndex = component / NumCol;
586  return matrix(rowIndex, colIndex);
587  }
590  {
591  vtkm::IdComponent colIndex = component % NumCol;
592  vtkm::IdComponent rowIndex = component / NumCol;
593  return matrix(rowIndex, colIndex);
594  }
596  static void SetComponent(MatrixType& matrix, vtkm::IdComponent component, T value)
597  {
598  GetComponent(matrix, component) = value;
599  }
600 
601  template <typename NewComponentType>
603 
604  template <typename NewComponentType>
607  NumRow,
608  NumCol>;
609 };
610 
611 //---------------------------------------------------------------------------
612 // Basic comparison operators.
613 
614 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
617 {
618  for (vtkm::IdComponent colIndex = 0; colIndex < NumCol; colIndex++)
619  {
620  for (vtkm::IdComponent rowIndex = 0; rowIndex < NumRow; rowIndex++)
621  {
622  if (a(rowIndex, colIndex) != b(rowIndex, colIndex))
623  return false;
624  }
625  }
626  return true;
627 }
628 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
631 {
632  return !(a == b);
633 }
634 
637 template <typename T, vtkm::IdComponent NumRow, vtkm::IdComponent NumCol>
638 VTKM_CONT std::ostream& operator<<(std::ostream& stream, const vtkm::Matrix<T, NumRow, NumCol>& mat)
639 {
640  stream << std::endl;
641  for (vtkm::IdComponent row = 0; row < NumRow; ++row)
642  {
643  stream << "| ";
644  for (vtkm::IdComponent col = 0; col < NumCol; ++col)
645  {
646  stream << mat(row, col) << "\t";
647  }
648  stream << "|" << std::endl;
649  }
650  return stream;
651 }
652 } // namespace vtkm
653 
654 #endif //vtk_m_Matrix_h
vtkm::Matrix::Matrix
VTKM_EXEC_CONT Matrix(const ComponentType &value)
Definition: Matrix.h:44
vtkm::Matrix::Matrix
VTKM_EXEC_CONT Matrix()
Definition: Matrix.h:41
vtkm::MatrixInverse
VTKM_EXEC_CONT vtkm::Matrix< T, Size, Size > MatrixInverse(const vtkm::Matrix< T, Size, Size > &A, bool &valid)
Find and return the inverse of the given matrix.
Definition: Matrix.h:464
vtkm::Matrix::operator()
const VTKM_EXEC_CONT ComponentType & operator()(vtkm::IdComponent rowIndex, vtkm::IdComponent colIndex) const
Parentheses are used to reference a matrix using mathematical tuple notation i.e.
Definition: Matrix.h:75
vtkm::VecTraitsTagMultipleComponents
A tag for vectors that are "true" vectors (i.e.
Definition: VecTraits.h:21
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in VTKm (an...
Definition: TypeTraits.h:61
Types.h
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::VecTraits< vtkm::Matrix< T, NumRow, NumCol > >::GetComponent
static VTKM_EXEC_CONT ComponentType & GetComponent(MatrixType &matrix, vtkm::IdComponent component)
Definition: Matrix.h:589
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::TypeTraits< vtkm::Matrix< T, NumRow, NumCol > >::NumericTag
typename TypeTraits< T >::NumericTag NumericTag
Definition: Matrix.h:553
vtkm::MatrixSetRow
VTKM_EXEC_CONT void MatrixSetRow(vtkm::Matrix< T, NumRow, NumCol > &matrix, vtkm::IdComponent rowIndex, const vtkm::Vec< T, NumCol > &rowValues)
Convenience function for setting a row of a matrix.
Definition: Matrix.h:130
vtkm::Matrix::NUM_COLUMNS
static constexpr vtkm::IdComponent NUM_COLUMNS
Definition: Matrix.h:38
vtkm::SolveLinearSystem
VTKM_EXEC_CONT vtkm::Vec< T, Size > SolveLinearSystem(const vtkm::Matrix< T, Size, Size > &A, const vtkm::Vec< T, Size > &b, bool &valid)
Solve the linear system Ax = b for x.
Definition: Matrix.h:446
vtkm::MatrixDeterminant
VTKM_EXEC_CONT T MatrixDeterminant(const vtkm::Matrix< T, Size, Size > &A)
Compute the determinant of a matrix.
Definition: Matrix.h:491
vtkm::VecTraits< vtkm::Matrix< T, NumRow, NumCol > >::BaseComponentType
typename vtkm::VecTraits< T >::BaseComponentType BaseComponentType
Definition: Matrix.h:573
Assert.h
vtkm::MatrixIdentity
VTKM_EXEC_CONT vtkm::Matrix< T, Size, Size > MatrixIdentity()
Returns the identity matrix.
Definition: Matrix.h:209
vtkm::VecTraits::BaseComponentType
typename vtkm::VecTraits< ComponentType >::BaseComponentType BaseComponentType
Base component type in the vector.
Definition: VecTraits.h:80
TypeTraits.h
vtkm::Matrix< vtkm::FloatDefault, 4, 4 >::ComponentType
vtkm::FloatDefault ComponentType
Definition: Matrix.h:36
vtkm::VecTraits::GetComponent
static const VTKM_EXEC_CONT ComponentType & GetComponent(const typename std::remove_const< VecType >::type &vector, vtkm::IdComponent component)
Returns the value in a given component of the vector.
vtkm::VecTraits< vtkm::Matrix< T, NumRow, NumCol > >::ComponentType
T ComponentType
Definition: Matrix.h:572
Math.h
vtkm::MatrixMultiply
VTKM_EXEC_CONT vtkm::Matrix< T, NumRow, NumCol > MatrixMultiply(const vtkm::Matrix< T, NumRow, NumInternal > &leftFactor, const vtkm::Matrix< T, NumInternal, NumCol > &rightFactor)
Standard matrix multiplication.
Definition: Matrix.h:156
vtkm::MatrixGetColumn
VTKM_EXEC_CONT vtkm::Vec< T, NumRow > MatrixGetColumn(const vtkm::Matrix< T, NumRow, NumCol > &matrix, vtkm::IdComponent columnIndex)
Returns a tuple containing the given column (indexed from 0) of the given matrix.
Definition: Matrix.h:116
vtkm::TypeTraitsMatrixTag
Tag used to identify 2 dimensional types (matrices).
Definition: Matrix.h:546
vtkm::Matrix::operator[]
VTKM_EXEC_CONT vtkm::Vec< ComponentType, NUM_COLUMNS > & operator[](vtkm::IdComponent rowIndex)
Brackets are used to referens a matrix like a 2D array i.e.
Definition: Matrix.h:64
vtkm::VecTraits< vtkm::Matrix< T, NumRow, NumCol > >::GetNumberOfComponents
static VTKM_EXEC_CONT vtkm::IdComponent GetNumberOfComponents(const MatrixType &)
Definition: Matrix.h:579
vtkm::VecTraits< vtkm::Matrix< T, NumRow, NumCol > >::GetComponent
static const VTKM_EXEC_CONT ComponentType & GetComponent(const MatrixType &matrix, vtkm::IdComponent component)
Definition: Matrix.h:582
vtkm::Matrix::NUM_ROWS
static constexpr vtkm::IdComponent NUM_ROWS
Definition: Matrix.h:37
vtkm::MatrixTranspose
VTKM_EXEC_CONT vtkm::Matrix< T, NumCols, NumRows > MatrixTranspose(const vtkm::Matrix< T, NumRows, NumCols > &matrix)
Returns the transpose of the given matrix.
Definition: Matrix.h:230
vtkm::operator<<
VTKM_CONT std::ostream & operator<<(std::ostream &stream, const vtkm::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:237
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::operator==
VTKM_EXEC_CONT bool operator==(const vtkm::Matrix< T, NumRow, NumCol > &a, const vtkm::Matrix< T, NumRow, NumCol > &b)
Definition: Matrix.h:615
vtkm::MatrixGetRow
const VTKM_EXEC_CONT vtkm::Vec< T, NumCol > & MatrixGetRow(const vtkm::Matrix< T, NumRow, NumCol > &matrix, vtkm::IdComponent rowIndex)
Returns a tuple containing the given row (indexed from 0) of the given matrix.
Definition: Matrix.h:105
vtkm::DifferenceOfProducts
VTKM_EXEC_CONT T DifferenceOfProducts(T a, T b, T c, T d)
Definition: Math.h:2728
vtkm::TypeTraits< vtkm::Matrix< T, NumRow, NumCol > >::ZeroInitialization
static VTKM_EXEC_CONT vtkm::Matrix< T, NumRow, NumCol > ZeroInitialization()
Definition: Matrix.h:557
vtkm::VecTraits< vtkm::Matrix< T, NumRow, NumCol > >::SetComponent
static VTKM_EXEC_CONT void SetComponent(MatrixType &matrix, vtkm::IdComponent component, T value)
Definition: Matrix.h:596
vtkm::TypeTraitsUnknownTag
Tag used to identify types that aren't Real, Integer, Scalar or Vector.
Definition: TypeTraits.h:20
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::Matrix
Basic Matrix type.
Definition: Matrix.h:33
vtkm::VecTraitsTagSizeStatic
A tag for vectors where the number of components are known at compile time.
Definition: VecTraits.h:34
vtkm::operator!=
VTKM_EXEC_CONT bool operator!=(const vtkm::Matrix< T, NumRow, NumCol > &a, const vtkm::Matrix< T, NumRow, NumCol > &b)
Definition: Matrix.h:629
vtkm::Matrix::operator()
VTKM_EXEC_CONT ComponentType & operator()(vtkm::IdComponent rowIndex, vtkm::IdComponent colIndex)
Parentheses are used to reference a matrix using mathematical tuple notation i.e.
Definition: Matrix.h:88
vtkm::VecTraits
The VecTraits class gives several static members that define how to use a given type as a vector.
Definition: VecTraits.h:66
vtkm::MatrixSetColumn
VTKM_EXEC_CONT void MatrixSetColumn(vtkm::Matrix< T, NumRow, NumCol > &matrix, vtkm::IdComponent columnIndex, const vtkm::Vec< T, NumRow > &columnValues)
Convenience function for setting a column of a matrix.
Definition: Matrix.h:140
VecTraits.h
vtkm::Matrix::operator[]
const VTKM_EXEC_CONT vtkm::Vec< ComponentType, NUM_COLUMNS > & operator[](vtkm::IdComponent rowIndex) const
Brackets are used to reference a matrix like a 2D array (i.e.
Definition: Matrix.h:53
vtkm::VecTraits::NUM_COMPONENTS
static constexpr vtkm::IdComponent NUM_COMPONENTS
Number of components in the vector.
Definition: VecTraits.h:86
vtkm::Matrix::Components
vtkm::Vec< vtkm::Vec< ComponentType, NUM_COLUMNS >, NUM_ROWS > Components
Definition: Matrix.h:98