Commit 6ea53921f6eb5258160cd851b6c45e7d9684ec8d
1 parent
b64bc218
Update
Showing
1 changed file
with
84 additions
and
48 deletions
doc/source/user_manual/manual/linalg.rst
| ... | ... | @@ -220,6 +220,8 @@ implemented in GammaLib: |
| 220 | 220 | All matrix classes derive from the abstract ``GMatrixBase`` class. |
| 221 | 221 | |
| 222 | 222 | |
| 223 | +.. _sec_matrix_storage: | |
| 224 | + | |
| 223 | 225 | Matrix storage classes |
| 224 | 226 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 225 | 227 | |
| ... | ... | @@ -317,9 +319,10 @@ course an equal number of rows and columns. And an empty matrix is not |
| 317 | 319 | allowed. All matrix elements are initialised to 0 by the matrix |
| 318 | 320 | allocation. |
| 319 | 321 | |
| 320 | -You can access matrix elements by the ``()`` operator, with the first | |
| 322 | +You can access matrix elements using the ``()`` operator, with the first | |
| 321 | 323 | argument specifying the row and the second argument the column to be |
| 322 | -accessed: | |
| 324 | +accessed (row and column indices run from 0 to the number of elements | |
| 325 | +minus one): | |
| 323 | 326 | |
| 324 | 327 | .. code-block:: cpp |
| 325 | 328 | |
| ... | ... | @@ -336,8 +339,6 @@ accessed: |
| 336 | 339 | } |
| 337 | 340 | } |
| 338 | 341 | |
| 339 | -Row and column indices run from 0 to the number of elements minus one. | |
| 340 | - | |
| 341 | 342 | You can dump the content of a matrix to the console using |
| 342 | 343 | |
| 343 | 344 | .. code-block:: cpp |
| ... | ... | @@ -349,80 +350,78 @@ Matrix arithmetics |
| 349 | 350 | ^^^^^^^^^^^^^^^^^^ |
| 350 | 351 | |
| 351 | 352 | The following description of matrix arithmetics applies to all storage |
| 352 | -classes (see section [sec:matrix:storage]). The following matrix | |
| 353 | -operators have been implemented in | |
| 353 | +classes (see :ref:`sec_matrix_storage`). The following matrix | |
| 354 | +operators have been implemented: | |
| 354 | 355 | |
| 355 | 356 | .. code-block:: cpp |
| 356 | 357 | |
| 357 | - C = A + B; // Matrix Matrix addition | |
| 358 | - C = A - B; // Matrix Matrix subtraction | |
| 359 | - C = A * B; // Matrix Matrix multiplication | |
| 360 | - C = A * v; // Matrix Vector multiplication | |
| 361 | - C = A * s; // Matrix Scalar multiplication | |
| 362 | - C = s * A; // Scalar Matrix multiplication | |
| 363 | - C = A / s; // Matrix Scalar division | |
| 364 | - C = -A; // Negation | |
| 365 | - A += B; // Matrix inplace addition | |
| 366 | - A -= B; // Matrix inplace subtraction | |
| 367 | - A *= B; // Matrix inplace multiplications | |
| 368 | - A *= s; // Matrix inplace scalar multiplication | |
| 369 | - A /= s; // Matrix inplace scalar division | |
| 358 | + GMatrix A; | |
| 359 | + GMatrix B; | |
| 360 | + GMatrix C; | |
| 361 | + ... | |
| 362 | + C = A + B; // Matrix Matrix addition | |
| 363 | + C = A - B; // Matrix Matrix subtraction | |
| 364 | + C = A * B; // Matrix Matrix multiplication | |
| 365 | + C = A * v; // Matrix Vector multiplication | |
| 366 | + C = A * s; // Matrix Scalar multiplication | |
| 367 | + C = s * A; // Scalar Matrix multiplication | |
| 368 | + C = A / s; // Matrix Scalar division | |
| 369 | + C = -A; // Negation | |
| 370 | + A += B; // Matrix inplace addition | |
| 371 | + A -= B; // Matrix inplace subtraction | |
| 372 | + A *= B; // Matrix inplace multiplications | |
| 373 | + A *= s; // Matrix inplace scalar multiplication | |
| 374 | + A /= s; // Matrix inplace scalar division | |
| 370 | 375 | |
| 371 | 376 | The comparison operators |
| 372 | 377 | |
| 373 | 378 | .. code-block:: cpp |
| 374 | 379 | |
| 375 | - int equal = (A == B); // True if all elements equal | |
| 376 | - int unequal = (A != B); // True if at least one elements unequal | |
| 380 | + int equal = (A == B); // True if all elements equal | |
| 381 | + int unequal = (A != B); // True if at least one elements unequal | |
| 377 | 382 | |
| 378 | 383 | allow to compare all elements of a matrix. If all elements are |
| 379 | -identical, the ``==`` operator returns ``true``, otherwise ``false``. If at least | |
| 380 | -one element differs, the ``!=`` operator returns true, is all elements are | |
| 381 | -identical it returns false. | |
| 382 | - | |
| 383 | -Matrix methods and functions | |
| 384 | -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 384 | +identical, the ``==`` operator returns ``true``, otherwise ``false``. | |
| 385 | +If at least one element differs, the ``!=`` operator returns true, | |
| 386 | +if all elements are identical it returns false. | |
| 385 | 387 | |
| 386 | -A number of methods has been implemented to manipulate matrixes. The | |
| 387 | -method | |
| 388 | 388 | |
| 389 | -.. code-block:: cpp | |
| 389 | +General matrix methods and functions | |
| 390 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 390 | 391 | |
| 391 | - A.clear(); // Set all elements to 0 | |
| 392 | +A number of methods have been implemented to manipulate matrixes. The | |
| 393 | +methods described in this section are available for all storage classes. | |
| 392 | 394 | |
| 393 | -sets all elements to 0. The methods | |
| 395 | +The methods | |
| 394 | 396 | |
| 395 | 397 | .. code-block:: cpp |
| 396 | 398 | |
| 397 | - int rows = A.rows(); // Returns number of rows in matrix | |
| 398 | - int cols = A.cols(); // Returns number of columns in matrix | |
| 399 | + int rows = A.rows(); // Returns number of rows in matrix | |
| 400 | + int cols = A.columns(); // Returns number of columns in matrix | |
| 401 | + int rows = A.size(); // Returns number of elements in matrix | |
| 399 | 402 | |
| 400 | 403 | provide access to the matrix dimensions, the methods |
| 401 | 404 | |
| 402 | 405 | .. code-block:: cpp |
| 403 | 406 | |
| 404 | - double sum = A.sum(); // Sum of all elements in matrix | |
| 405 | - double min = A.min(); // Returns minimum element of matrix | |
| 406 | - double max = A.max(); // Returns maximum element of matrix | |
| 407 | + double sum = A.sum(); // Sum of all elements in matrix | |
| 408 | + double min = A.min(); // Returns minimum element of matrix | |
| 409 | + double max = A.max(); // Returns maximum element of matrix | |
| 410 | + double fill = A.fill(); // Returns fraction of non-zero elements | |
| 407 | 411 | |
| 408 | 412 | inform about some matrix properties. The methods |
| 409 | 413 | |
| 410 | 414 | .. code-block:: cpp |
| 411 | 415 | |
| 412 | - GVector v_row = A.extract_row(row); // Puts row in vector | |
| 413 | - GVector v_column = A.extract_col(col); // Puts column in vector | |
| 416 | + GVector row_vector = A.row(row); // Extract matrix row into vector | |
| 417 | + GVector column_vector = A.col(column); // Extract matrix column into vector | |
| 414 | 418 | |
| 415 | -extract entire rows and columns from a matrix. Extraction of lower or | |
| 416 | -upper triangle parts of a matrix into another is performed using | |
| 419 | +extract entire rows and columns from a matrix into a vector. Conversely, | |
| 420 | +you may set entire rows or columns of a matrix using the methods | |
| 417 | 421 | |
| 418 | -.. code-block:: cpp | |
| 419 | - | |
| 420 | - B = A.extract_lower_triangle(); // B holds lower triangle | |
| 421 | - B = A.extract_upper_triangle(); // B holds upper triangle | |
| 422 | + A.row(row, row_vector); // Add vector to column | |
| 423 | + A.column(column, column_vector); // Puts vector in column | |
| 422 | 424 | |
| 423 | -``B`` is of the same storage class as ``A``, except for the case that ``A`` is a | |
| 424 | -``GSymMatrix`` object. In this case, ``B`` will be a full matrix of type | |
| 425 | -``GMatrix``. | |
| 426 | 425 | |
| 427 | 426 | The methods |
| 428 | 427 | |
| ... | ... | @@ -460,6 +459,43 @@ The absolute value of a matrix is provided by |
| 460 | 459 | |
| 461 | 460 | B = fabs(A); // B = |A| |
| 462 | 461 | |
| 462 | + | |
| 463 | +Specific matrix methods and functions | |
| 464 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 465 | + | |
| 466 | +Some methods do only exist for specific matrix storage classes. Although | |
| 467 | +these methods could in principle apply to all matrix classes, they have | |
| 468 | +for practical reasons not yet been implemented for all storage classes. | |
| 469 | +This may change in future versions of GammaLib. | |
| 470 | + | |
| 471 | + | |
| 472 | +GMatrix methods | |
| 473 | +~~~~~~~~~~~~~~~ | |
| 474 | + | |
| 475 | + | |
| 476 | +GMatrixSymmetric methods | |
| 477 | +~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 478 | + | |
| 479 | + | |
| 480 | +GMatrixSparse methods | |
| 481 | +~~~~~~~~~~~~~~~~~~~~~ | |
| 482 | + | |
| 483 | +Other methods | |
| 484 | +~~~~~~~~~~~~~ | |
| 485 | + | |
| 486 | +You can extract the lower or upper triangle of a matrix into another | |
| 487 | +matrix using | |
| 488 | + | |
| 489 | +.. code-block:: cpp | |
| 490 | + | |
| 491 | + GMatrix B = A.extract_lower_triangle(); // B holds lower triangle | |
| 492 | + GMatrix B = A.extract_upper_triangle(); // B holds upper triangle | |
| 493 | + | |
| 494 | +This method is implemented for storage classes ``GMatrix`` and | |
| 495 | +``GMatrixSymmetric``. | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 463 | 499 | Matrix factorisations |
| 464 | 500 | ^^^^^^^^^^^^^^^^^^^^^ |
| 465 | 501 | ... | ... |