diagonalMatrix-class         package:Matrix         R Documentation

_C_l_a_s_s "_d_i_a_g_o_n_a_l_M_a_t_r_i_x" _o_f _D_i_a_g_o_n_a_l _M_a_t_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Class "diagonalMatrix" is the virtual class of all diagonal
     matrices.

_O_b_j_e_c_t_s _f_r_o_m _t_h_e _C_l_a_s_s:

     A virtual Class: No objects may be created from it.

_S_l_o_t_s:


     '_d_i_a_g': code{"character"} string, either '"U"' or '"N"', where
          '"U"' means 'unit-diagonal'.

     '_D_i_m': matrix dimension, and

     '_D_i_m_n_a_m_e_s': the 'dimnames', a 'list', see the 'Matrix' class
          description.  Typically 'list(NULL,NULL)' for diagonal
          matrices.

_E_x_t_e_n_d_s:

     Class '"sparseMatrix"', directly.

_M_e_t_h_o_d_s:

     These are just a subset of the signature for which defined
     methods. Currently, there are (too) many explicit methods defined
     in order to ensure efficient methods for diagonal matrices.


     _c_o_e_r_c_e 'signature(from = "matrix", to = "diagonalMatrix")': ... 

     _c_o_e_r_c_e 'signature(from = "Matrix", to = "diagonalMatrix")': ... 

     _c_o_e_r_c_e 'signature(from = "diagonalMatrix", to = "generalMatrix")':
          ... 

     _c_o_e_r_c_e 'signature(from = "diagonalMatrix", to =
          "triangularMatrix")': ... 

     _c_o_e_r_c_e 'signature(from = "diagonalMatrix", to = "nMatrix")': ... 

     _c_o_e_r_c_e 'signature(from = "diagonalMatrix", to = "matrix")': ... 

     _c_o_e_r_c_e 'signature(from = "diagonalMatrix", to = "sparseVector")':
          ... 

     _t 'signature(x = "diagonalMatrix")': ... 

     %*% 'signature(x = "dgeMatrix", y = "diagonalMatrix")': ... 

     %*% 'signature(x = "matrix", y = "diagonalMatrix")': ... 

     %*% 'signature(x = "diagonalMatrix", y = "matrix")': ... 

     %*% 'signature(x = "diagonalMatrix", y = "dgeMatrix")': ... 

     _c_r_o_s_s_p_r_o_d 'signature(x = "diagonalMatrix", y = "dgeMatrix")': ...  
           and many more methods

     _s_o_l_v_e 'signature(a = "diagonalMatrix", b, ...)': is trivially
          implemented, of course.

     * 'signature(e1 = "ddiMatrix", e2="denseMatrix")': arithmetic and
          other operators from the 'Ops' group have a few dozen
          explicit method definitions, in order to keep the results
          _diagonal_ in many cases, including the following:

     / 'signature(e1 = "ddiMatrix", e2="denseMatrix")': the result is
          from class 'ddiMatrix' which is typically very desirable. 
          Note that when 'e2' contains off-diagonal zeros or 'NA's, we
          implicitly use 0 / x = 0, hence differing from traditional R
          arithmetic (where 0/0 |-> NaN), in order to preserve
          sparsity.

_S_e_e _A_l_s_o:

     'ddiMatrix' and 'ldiMatrix' are "actual" classes extending
     '"diagonalMatrix"'.

_E_x_a_m_p_l_e_s:

     I5 <- Diagonal(5)
     D5 <- Diagonal(x = 10*(1:5))
     ## trivial (but explicitly defined) methods:
     stopifnot(identical(crossprod(I5), I5),
               identical(tcrossprod(I5), I5),
               identical(crossprod(I5, D5), D5),
               identical(tcrossprod(D5, I5), D5),
               identical(solve(D5), solve(D5, I5)),
               all.equal(D5, solve(solve(D5)), tol = 1e-12)
               )
     solve(D5)

