Viskores  1.0
Matrix.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_Matrix_h
19 #define viskores_Matrix_h
20 
21 #include <viskores/Assert.h>
22 #include <viskores/Math.h>
23 #include <viskores/TypeTraits.h>
24 #include <viskores/Types.h>
25 #include <viskores/VecTraits.h>
26 
27 namespace viskores
28 {
29 
40 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
41 class Matrix
42 {
43 public:
44  using ComponentType = T;
45  static constexpr viskores::IdComponent NUM_ROWS = NumRow;
46  static constexpr viskores::IdComponent NUM_COLUMNS = NumCol;
47 
50  Matrix() {}
51 
54  explicit Matrix(const ComponentType& value)
56  {
57  }
58 
64  {
65  VISKORES_ASSERT(rowIndex >= 0);
66  VISKORES_ASSERT(rowIndex < NUM_ROWS);
67  return this->Components[rowIndex];
68  }
69 
75  {
76  VISKORES_ASSERT(rowIndex >= 0);
77  VISKORES_ASSERT(rowIndex < NUM_ROWS);
78  return this->Components[rowIndex];
79  }
80 
86  viskores::IdComponent colIndex) const
87  {
88  VISKORES_ASSERT(rowIndex >= 0);
89  VISKORES_ASSERT(rowIndex < NUM_ROWS);
90  VISKORES_ASSERT(colIndex >= 0);
91  VISKORES_ASSERT(colIndex < NUM_COLUMNS);
92  return (*this)[rowIndex][colIndex];
93  }
94 
100  {
101  VISKORES_ASSERT(rowIndex >= 0);
102  VISKORES_ASSERT(rowIndex < NUM_ROWS);
103  VISKORES_ASSERT(colIndex >= 0);
104  VISKORES_ASSERT(colIndex < NUM_COLUMNS);
105  return (*this)[rowIndex][colIndex];
106  }
107 
108 private:
110 };
111 
115 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
118  viskores::IdComponent rowIndex)
119 {
120  return matrix[rowIndex];
121 }
122 
126 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
129  viskores::IdComponent columnIndex)
130 {
131  viskores::Vec<T, NumRow> columnValues;
132  for (viskores::IdComponent rowIndex = 0; rowIndex < NumRow; rowIndex++)
133  {
134  columnValues[rowIndex] = matrix(rowIndex, columnIndex);
135  }
136  return columnValues;
137 }
138 
141 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
143  viskores::IdComponent rowIndex,
144  const viskores::Vec<T, NumCol>& rowValues)
145 {
146  matrix[rowIndex] = rowValues;
147 }
148 
151 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
153  viskores::IdComponent columnIndex,
154  const viskores::Vec<T, NumRow>& columnValues)
155 {
156  for (viskores::IdComponent rowIndex = 0; rowIndex < NumRow; rowIndex++)
157  {
158  matrix(rowIndex, columnIndex) = columnValues[rowIndex];
159  }
160 }
161 
164 template <typename T,
165  viskores::IdComponent NumRow,
166  viskores::IdComponent NumCol,
167  viskores::IdComponent NumInternal>
170  const viskores::Matrix<T, NumInternal, NumCol>& rightFactor)
171 {
173  for (viskores::IdComponent rowIndex = 0; rowIndex < NumRow; rowIndex++)
174  {
175  for (viskores::IdComponent colIndex = 0; colIndex < NumCol; colIndex++)
176  {
177  T sum = T(leftFactor(rowIndex, 0) * rightFactor(0, colIndex));
178  for (viskores::IdComponent internalIndex = 1; internalIndex < NumInternal; internalIndex++)
179  {
180  sum = T(sum + (leftFactor(rowIndex, internalIndex) * rightFactor(internalIndex, colIndex)));
181  }
182  result(rowIndex, colIndex) = sum;
183  }
184  }
185  return result;
186 }
187 
190 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
192  const viskores::Matrix<T, NumRow, NumCol>& leftFactor,
193  const viskores::Vec<T, NumCol>& rightFactor)
194 {
195  viskores::Vec<T, NumRow> product;
196  for (viskores::IdComponent rowIndex = 0; rowIndex < NumRow; rowIndex++)
197  {
198  product[rowIndex] = viskores::Dot(viskores::MatrixGetRow(leftFactor, rowIndex), rightFactor);
199  }
200  return product;
201 }
202 
205 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
207  const viskores::Vec<T, NumRow>& leftFactor,
208  const viskores::Matrix<T, NumRow, NumCol>& rightFactor)
209 {
210  viskores::Vec<T, NumCol> product;
211  for (viskores::IdComponent colIndex = 0; colIndex < NumCol; colIndex++)
212  {
213  product[colIndex] = viskores::Dot(leftFactor, viskores::MatrixGetColumn(rightFactor, colIndex));
214  }
215  return product;
216 }
217 
220 template <typename T, viskores::IdComponent Size>
222 {
223  viskores::Matrix<T, Size, Size> result(T(0));
224  for (viskores::IdComponent index = 0; index < Size; index++)
225  {
226  result(index, index) = T(1.0);
227  }
228  return result;
229 }
230 
233 template <typename T, viskores::IdComponent Size>
235 {
236  matrix = viskores::MatrixIdentity<T, Size>();
237 }
238 
241 template <typename T, viskores::IdComponent NumRows, viskores::IdComponent NumCols>
244 {
246  for (viskores::IdComponent index = 0; index < NumRows; index++)
247  {
248  viskores::MatrixSetColumn(result, index, viskores::MatrixGetRow(matrix, index));
249 #ifdef VISKORES_ICC
250  // For reasons I do not really understand, the Intel compiler with with
251  // optimization on is sometimes removing this for loop. It appears that the
252  // optimizer sometimes does not recognize that the MatrixSetColumn function
253  // has side effects. I cannot fathom any reason for this other than a bug in
254  // the compiler, but unfortunately I do not know a reliable way to
255  // demonstrate the problem.
256  __asm__("");
257 #endif
258  }
259  return result;
260 }
261 
262 namespace detail
263 {
264 
265 // Used with MatrixLUPFactor.
266 template <typename T, viskores::IdComponent Size>
267 VISKORES_EXEC_CONT void MatrixLUPFactorFindPivot(
270  viskores::IdComponent topCornerIndex,
271  T& inversionParity,
272  bool& valid)
273 {
274  viskores::IdComponent maxRowIndex = topCornerIndex;
275  T maxValue = viskores::Abs(A(maxRowIndex, topCornerIndex));
276  for (viskores::IdComponent rowIndex = topCornerIndex + 1; rowIndex < Size; rowIndex++)
277  {
278  T compareValue = viskores::Abs(A(rowIndex, topCornerIndex));
279  if (maxValue < compareValue)
280  {
281  maxValue = compareValue;
282  maxRowIndex = rowIndex;
283  }
284  }
285 
286  if (maxValue < viskores::Epsilon<T>())
287  {
288  valid = false;
289  return;
290  }
291 
292  if (maxRowIndex != topCornerIndex)
293  {
294  // Swap rows in matrix.
295  viskores::Vec<T, Size> maxRow = viskores::MatrixGetRow(A, maxRowIndex);
296  viskores::MatrixSetRow(A, maxRowIndex, viskores::MatrixGetRow(A, topCornerIndex));
297  viskores::MatrixSetRow(A, topCornerIndex, maxRow);
298 
299  // Record change in permutation matrix.
300  viskores::IdComponent maxOriginalRowIndex = permutation[maxRowIndex];
301  permutation[maxRowIndex] = permutation[topCornerIndex];
302  permutation[topCornerIndex] = maxOriginalRowIndex;
303 
304  // Keep track of inversion parity.
305  inversionParity = -inversionParity;
306  }
307 }
308 
309 // Used with MatrixLUPFactor
310 template <typename T, viskores::IdComponent Size>
311 VISKORES_EXEC_CONT void MatrixLUPFactorFindUpperTriangleElements(
313  viskores::IdComponent topCornerIndex,
314  bool& valid)
315 {
316  // Compute values for upper triangle on row topCornerIndex
317  if (A(topCornerIndex, topCornerIndex) == 0)
318  {
319  valid = false;
320  return;
321  }
322  else
323  {
324  // Let's make the reciprocal approximation here.
325  // Doesn't make things much fast for small 'Size',
326  // but definitely improves performance as 'Size' gets large.
327  T rAdiag = 1 / A(topCornerIndex, topCornerIndex);
328  for (viskores::IdComponent colIndex = topCornerIndex + 1; colIndex < Size; colIndex++)
329  {
330  A(topCornerIndex, colIndex) *= rAdiag;
331  }
332  }
333 
334  // Update the rest of the matrix for calculations on subsequent rows
335  for (viskores::IdComponent rowIndex = topCornerIndex + 1; rowIndex < Size; rowIndex++)
336  {
337  for (viskores::IdComponent colIndex = topCornerIndex + 1; colIndex < Size; colIndex++)
338  {
339  A(rowIndex, colIndex) -= A(rowIndex, topCornerIndex) * A(topCornerIndex, colIndex);
340  }
341  }
342 }
343 
374 template <typename T, viskores::IdComponent Size>
377  T& inversionParity,
378  bool& valid)
379 {
380  // Initialize permutation.
381  for (viskores::IdComponent index = 0; index < Size; index++)
382  {
383  permutation[index] = index;
384  }
385  inversionParity = T(1);
386  valid = true;
387 
388  for (viskores::IdComponent rowIndex = 0; rowIndex < Size; rowIndex++)
389  {
390  MatrixLUPFactorFindPivot(A, permutation, rowIndex, inversionParity, valid);
391  if (!valid)
392  {
393  break;
394  }
395  MatrixLUPFactorFindUpperTriangleElements(A, rowIndex, valid);
396  if (!valid)
397  {
398  break;
399  }
400  }
401 }
402 
407 template <typename T, viskores::IdComponent Size>
411  const viskores::Vec<T, Size>& b)
412 {
413  // The LUP-factorization gives us PA = LU or equivalently A = inv(P)LU.
414  // Substituting into Ax = b gives us inv(P)LUx = b or LUx = Pb.
415  // Now consider the intermediate vector y = Ux.
416  // Substituting in the previous two equations yields Ly = Pb.
417  // Solving Ly = Pb is easy because L is triangular and P is just a
418  // permutation.
420  for (viskores::IdComponent rowIndex = 0; rowIndex < Size; rowIndex++)
421  {
422  y[rowIndex] = b[permutation[rowIndex]];
423  // Recall that L is stored in the lower triangle of LU including diagonal.
424  for (viskores::IdComponent colIndex = 0; colIndex < rowIndex; colIndex++)
425  {
426  y[rowIndex] -= LU(rowIndex, colIndex) * y[colIndex];
427  }
428  if (LU(rowIndex, rowIndex) == 0)
429  {
430  y[rowIndex] = std::numeric_limits<T>::quiet_NaN();
431  }
432  else
433  {
434  y[rowIndex] /= LU(rowIndex, rowIndex);
435  }
436  }
437 
438  // Now that we have y, we can easily solve Ux = y for x.
440  for (viskores::IdComponent rowIndex = Size - 1; rowIndex >= 0; rowIndex--)
441  {
442  // Recall that U is stored in the upper triangle of LU with the diagonal
443  // implicitly all 1's.
444  x[rowIndex] = y[rowIndex];
445  for (viskores::IdComponent colIndex = rowIndex + 1; colIndex < Size; colIndex++)
446  {
447  x[rowIndex] -= LU(rowIndex, colIndex) * x[colIndex];
448  }
449  }
450 
451  return x;
452 }
453 
454 } // namespace detail
455 
459 template <typename T, viskores::IdComponent Size>
462  const viskores::Vec<T, Size>& b,
463  bool& valid)
464 {
465  // First, we will make an LUP-factorization to help us.
468  T inversionParity; // Unused.
469  detail::MatrixLUPFactor(LU, permutation, inversionParity, valid);
470 
471  // Next, use the decomposition to solve the system.
472  return detail::MatrixLUPSolve(LU, permutation, b);
473 }
474 
478 template <typename T, viskores::IdComponent Size>
481  bool& valid)
482 {
483  // First, we will make an LUP-factorization to help us.
486  T inversionParity; // Unused
487  detail::MatrixLUPFactor(LU, permutation, inversionParity, valid);
488 
489  // We will use the decomposition to solve AX = I for X where X is
490  // clearly the inverse of A. Our solve method only works for vectors,
491  // so we solve for one column of invA at a time.
493  viskores::Vec<T, Size> ICol(T(0));
494  for (viskores::IdComponent colIndex = 0; colIndex < Size; colIndex++)
495  {
496  ICol[colIndex] = 1;
497  viskores::Vec<T, Size> invACol = detail::MatrixLUPSolve(LU, permutation, ICol);
498  ICol[colIndex] = 0;
499  viskores::MatrixSetColumn(invA, colIndex, invACol);
500  }
501  return invA;
502 }
503 
506 template <typename T, viskores::IdComponent Size>
508 {
509  // First, we will make an LUP-factorization to help us.
512  T inversionParity;
513  bool valid;
514  detail::MatrixLUPFactor(LU, permutation, inversionParity, valid);
515 
516  // If the matrix is singular, the factorization is invalid, but in that
517  // case we know that the determinant is 0.
518  if (!valid)
519  {
520  return 0;
521  }
522 
523  // The determinant is equal to the product of the diagonal of the L matrix,
524  // possibly negated depending on the parity of the inversion. The
525  // inversionParity variable is set to 1.0 and -1.0 for even and odd parity,
526  // respectively. This sign determines whether the product should be negated.
527  T product = inversionParity;
528  for (viskores::IdComponent index = 0; index < Size; index++)
529  {
530  product *= LU(index, index);
531  }
532  return product;
533 }
534 
535 // Specializations for common small determinants.
536 
537 template <typename T>
539 {
540  return A(0, 0);
541 }
542 
543 template <typename T>
545 {
546  return viskores::DifferenceOfProducts(A(0, 0), A(1, 1), A(1, 0), A(0, 1));
547 }
548 
549 template <typename T>
551 {
552  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) -
553  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);
554 }
555 
556 //---------------------------------------------------------------------------
557 // Implementations of traits for matrices.
558 
563 {
564 };
565 
566 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
567 struct TypeTraits<viskores::Matrix<T, NumRow, NumCol>>
568 {
571 
574  {
576  }
577 };
578 
581 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
582 struct VecTraits<viskores::Matrix<T, NumRow, NumCol>>
583 {
584 private:
586 
587 public:
588  using ComponentType = T;
590  static constexpr viskores::IdComponent NUM_COMPONENTS = NumRow * NumCol;
593 
596 
598  static const ComponentType& GetComponent(const MatrixType& matrix,
599  viskores::IdComponent component)
600  {
601  viskores::IdComponent colIndex = component % NumCol;
602  viskores::IdComponent rowIndex = component / NumCol;
603  return matrix(rowIndex, colIndex);
604  }
607  {
608  viskores::IdComponent colIndex = component % NumCol;
609  viskores::IdComponent rowIndex = component / NumCol;
610  return matrix(rowIndex, colIndex);
611  }
613  static void SetComponent(MatrixType& matrix, viskores::IdComponent component, T value)
614  {
615  GetComponent(matrix, component) = value;
616  }
617 
618  template <typename NewComponentType>
620 
621  template <typename NewComponentType>
624  NumRow,
625  NumCol>;
626 };
627 
628 //---------------------------------------------------------------------------
629 // Basic comparison operators.
630 
631 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
634 {
635  for (viskores::IdComponent colIndex = 0; colIndex < NumCol; colIndex++)
636  {
637  for (viskores::IdComponent rowIndex = 0; rowIndex < NumRow; rowIndex++)
638  {
639  if (a(rowIndex, colIndex) != b(rowIndex, colIndex))
640  return false;
641  }
642  }
643  return true;
644 }
645 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
648 {
649  return !(a == b);
650 }
651 
654 template <typename T, viskores::IdComponent NumRow, viskores::IdComponent NumCol>
655 VISKORES_CONT std::ostream& operator<<(std::ostream& stream,
657 {
658  stream << std::endl;
659  for (viskores::IdComponent row = 0; row < NumRow; ++row)
660  {
661  stream << "| ";
662  for (viskores::IdComponent col = 0; col < NumCol; ++col)
663  {
664  stream << mat(row, col) << "\t";
665  }
666  stream << "|" << std::endl;
667  }
668  return stream;
669 }
670 } // namespace viskores
671 
672 #endif //viskores_Matrix_h
viskores::SolveLinearSystem
viskores::Vec< T, Size > SolveLinearSystem(const viskores::Matrix< T, Size, Size > &A, const viskores::Vec< T, Size > &b, bool &valid)
Solve the linear system Ax = b for x.
Definition: Matrix.h:460
viskores::operator==
bool operator==(const viskores::Matrix< T, NumRow, NumCol > &a, const viskores::Matrix< T, NumRow, NumCol > &b)
Definition: Matrix.h:632
viskores::MatrixGetRow
const viskores::Vec< T, NumCol > & MatrixGetRow(const viskores::Matrix< T, NumRow, NumCol > &matrix, viskores::IdComponent rowIndex)
Returns a tuple containing the given row (indexed from 0) of the given matrix.
Definition: Matrix.h:116
Types.h
viskores::VecTraitsTagSizeStatic
A tag for vectors where the number of components are known at compile time.
Definition: VecTraits.h:44
viskores::VecTraits< viskores::Matrix< T, NumRow, NumCol > >::GetComponent
static const ComponentType & GetComponent(const MatrixType &matrix, viskores::IdComponent component)
Definition: Matrix.h:598
viskores::TypeTraitsMatrixTag
Tag used to identify 2 dimensional types (matrices).
Definition: Matrix.h:562
viskores::Matrix::NUM_COLUMNS
static constexpr viskores::IdComponent NUM_COLUMNS
Definition: Matrix.h:46
viskores::MatrixTranspose
viskores::Matrix< T, NumCols, NumRows > MatrixTranspose(const viskores::Matrix< T, NumRows, NumCols > &matrix)
Returns the transpose of the given matrix.
Definition: Matrix.h:242
viskores::VecTraits< viskores::Matrix< T, NumRow, NumCol > >::GetComponent
static ComponentType & GetComponent(MatrixType &matrix, viskores::IdComponent component)
Definition: Matrix.h:606
viskores::VecTraitsTagMultipleComponents
A tag for vectors that are "true" vectors (i.e.
Definition: VecTraits.h:31
viskores::TypeTraits< viskores::Matrix< T, NumRow, NumCol > >::ZeroInitialization
static viskores::Matrix< T, NumRow, NumCol > ZeroInitialization()
Definition: Matrix.h:573
Assert.h
viskores::Matrix::NUM_ROWS
static constexpr viskores::IdComponent NUM_ROWS
Definition: Matrix.h:45
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::Matrix< viskores::Float32, 4, 4 >::ComponentType
viskores::Float32 ComponentType
Definition: Matrix.h:44
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::Matrix::operator()
ComponentType & operator()(viskores::IdComponent rowIndex, viskores::IdComponent colIndex)
Parentheses are used to reference a matrix using mathematical tuple notation i.e.
Definition: Matrix.h:99
viskores::VecTraits< viskores::Matrix< T, NumRow, NumCol > >::BaseComponentType
typename viskores::VecTraits< T >::BaseComponentType BaseComponentType
Definition: Matrix.h:589
viskores::VecTraits::GetComponent
static const ComponentType & GetComponent(const T &vector, viskores::IdComponent)
Returns the value in a given component of the vector.
Definition: VecTraits.h:125
viskores::Matrix::operator()
const ComponentType & operator()(viskores::IdComponent rowIndex, viskores::IdComponent colIndex) const
Parentheses are used to reference a matrix using mathematical tuple notation i.e.
Definition: Matrix.h:85
TypeTraits.h
viskores::TypeTraits
The TypeTraits class provides helpful compile-time information about the basic types used in Viskores...
Definition: TypeTraits.h:69
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores::Matrix::operator[]
const viskores::Vec< ComponentType, NUM_COLUMNS > & operator[](viskores::IdComponent rowIndex) const
Brackets are used to reference a matrix like a 2D array (i.e.
Definition: Matrix.h:63
viskores::operator<<
std::ostream & operator<<(std::ostream &stream, const viskores::Bounds &bounds)
Helper function for printing bounds during testing.
Definition: Bounds.h:268
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Math.h
viskores::TypeTraitsUnknownTag
Tag used to identify types that aren't Real, Integer, Scalar or Vector.
Definition: TypeTraits.h:28
viskores::VecTraits::NUM_COMPONENTS
static constexpr viskores::IdComponent NUM_COMPONENTS
Number of components in the vector.
Definition: VecTraits.h:93
viskores::VecTraits
Traits that can be queried to treat any type as a Vec.
Definition: VecTraits.h:69
viskores::Matrix::Matrix
Matrix()
Creates an uninitialized matrix. The values in the matrix are not determined.
Definition: Matrix.h:50
viskores::VecTraits< viskores::Matrix< T, NumRow, NumCol > >::ComponentType
T ComponentType
Definition: Matrix.h:588
viskores::DifferenceOfProducts
T DifferenceOfProducts(T a, T b, T c, T d)
Definition: Math.h:2786
viskores::VecTraits< viskores::Matrix< T, NumRow, NumCol > >::SetComponent
static void SetComponent(MatrixType &matrix, viskores::IdComponent component, T value)
Definition: Matrix.h:613
viskores::Matrix
Basic Matrix type.
Definition: Matrix.h:41
viskores::MatrixGetColumn
viskores::Vec< T, NumRow > MatrixGetColumn(const viskores::Matrix< T, NumRow, NumCol > &matrix, viskores::IdComponent columnIndex)
Returns a tuple containing the given column (indexed from 0) of the given matrix.
Definition: Matrix.h:127
viskores::MatrixInverse
viskores::Matrix< T, Size, Size > MatrixInverse(const viskores::Matrix< T, Size, Size > &A, bool &valid)
Find and return the inverse of the given matrix.
Definition: Matrix.h:479
VISKORES_ASSERT
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
viskores::TypeTraits< viskores::Matrix< T, NumRow, NumCol > >::NumericTag
typename TypeTraits< T >::NumericTag NumericTag
Definition: Matrix.h:569
viskores::MatrixSetColumn
void MatrixSetColumn(viskores::Matrix< T, NumRow, NumCol > &matrix, viskores::IdComponent columnIndex, const viskores::Vec< T, NumRow > &columnValues)
Convenience function for setting a column of a matrix.
Definition: Matrix.h:152
viskores::MatrixIdentity
viskores::Matrix< T, Size, Size > MatrixIdentity()
Returns the identity matrix.
Definition: Matrix.h:221
viskores::MatrixSetRow
void MatrixSetRow(viskores::Matrix< T, NumRow, NumCol > &matrix, viskores::IdComponent rowIndex, const viskores::Vec< T, NumCol > &rowValues)
Convenience function for setting a row of a matrix.
Definition: Matrix.h:142
viskores::Matrix::Matrix
Matrix(const ComponentType &value)
Creates a matrix initialized with all values set to the provided value.
Definition: Matrix.h:54
viskores::Matrix::Components
viskores::Vec< viskores::Vec< ComponentType, NUM_COLUMNS >, NUM_ROWS > Components
Definition: Matrix.h:109
viskores::operator!=
bool operator!=(const viskores::Matrix< T, NumRow, NumCol > &a, const viskores::Matrix< T, NumRow, NumCol > &b)
Definition: Matrix.h:646
viskores::VecTraits::BaseComponentType
T BaseComponentType
Base component type in the vector.
Definition: VecTraits.h:86
viskores::VecTraits< viskores::Matrix< T, NumRow, NumCol > >::GetNumberOfComponents
static viskores::IdComponent GetNumberOfComponents(const MatrixType &)
Definition: Matrix.h:595
viskores::MatrixDeterminant
T MatrixDeterminant(const viskores::Matrix< T, Size, Size > &A)
Compute the determinant of a matrix.
Definition: Matrix.h:507
viskores::MatrixMultiply
viskores::Matrix< T, NumRow, NumCol > MatrixMultiply(const viskores::Matrix< T, NumRow, NumInternal > &leftFactor, const viskores::Matrix< T, NumInternal, NumCol > &rightFactor)
Standard matrix multiplication.
Definition: Matrix.h:168
viskores::Vec
A short fixed-length array.
Definition: Types.h:365
VecTraits.h
viskores::Matrix::operator[]
viskores::Vec< ComponentType, NUM_COLUMNS > & operator[](viskores::IdComponent rowIndex)
Brackets are used to referens a matrix like a 2D array i.e.
Definition: Matrix.h:74