sparseVector-class          package:Matrix          R Documentation

_S_p_a_r_s_e _V_e_c_t_o_r _C_l_a_s_s_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Sparse Vector Classes: The virtual mother class '"sparseVector"'
     has the five actual daughter classes '"dsparseVector"',
     '"isparseVector"', '"lsparseVector"', '"nsparseVector"', and
     '"zsparseVector"', where we've mainly implemented methods for the
     'd*', 'l*' and 'n*' ones.

_S_l_o_t_s:


     '_l_e_n_g_t_h': class '"numeric"' - the 'length' of the sparse vector. 
          Note that '"numeric"' can be considerably larger than the
          maximal '"integer"', '.Machine$integer.max', on purpose.

     '_i': class '"integer"' - the (1-based) indices of the non-zero
          entries.  Must _not_ be 'NA'.

     '_x': (for all but '"nsparseVector"'): the non-zero entries.  This
          is of class '"numeric"' for class '"dsparseVector"', 
          '"logical"' for class '"lsparseVector"', etc.

          Note that '"nsparseVector"'s have no 'x' slot. Further,
          mainly for ease of method definitions, we've defined the
          Further, mainly for ease of method definitions, we've defined
          the class union (see 'setClassUnion') of all sparse vector
          classes which _have_ an 'x' slot, as class '"xsparseVector"'.


_M_e_t_h_o_d_s:


     _l_e_n_g_t_h 'signature(x = "sparseVector")': simply extracts the
          'length' slot.

     _s_h_o_w 'signature(object = "sparseVector")': The 'show' method for
          sparse vectors prints _structural_ zeroes as '"."' using
          the non-exported 'prSpVector' function which allows further
          customization such as replacing '"."' by '" "' (blank).

          Note that 'options(max.print)' will influence how many
          entries of large sparse vectors are printed at all.

     _a_s._v_e_c_t_o_r 'signature(x = "sparseVector", mode = "character")'
          coerces sparse vectors to regular, i.e., atomic vectors.
          This is the same as 'as(x, "vector")'.

     _d_i_m<- 'signature(x = "sparseVector", value = "integer")' coerces a
          sparse vector to a sparse Matrix, i.e., an object inheriting
          from 'sparseMatrix', of the appropriate dimension.

     _r_e_p 'signature(x = "sparseVector")' repeat 'x', with the same
          argument list '(x, times, length.out, each, ...)' as the
          default method for rep().

     _O_p_s 'signature(e1 = "sparseVector", e2 = "*")': define arithmetic,
          compare and logic operations, (see 'Ops').

     _S_u_m_m_a_r_y 'signature(x = "sparseVector")': define all the 'Summary'
          methods.

_E_x_a_m_p_l_e_s:

     getClass("sparseVector")
     getClass("dsparseVector")
     getClass("xsparseVector")# those with an 'x' slot

     sx <- c(0,0,3, 3.2, 0,0,0,-3:1,0,0,2,0,0,5,0,0)
     (ss <- as(sx, "sparseVector"))

     ix <- as.integer(round(sx))
     (is <- as(ix, "sparseVector"))
     ## an "isparseVector" (!)

     ## rep() works too:
     (ri <- rep(is, length.out= 25))

     ## Using `dim<-`  as in base R :
     r <- ss
     dim(r) <- c(4,5) # becomes a sparse Matrix:
     r

     ## currently has "non-structural" FALSE -- printing as ":"
     (lis <- is & FALSE)
     (nn <- is[is == 0]) # all "structural" FALSE

     ## NA-case
     sN <- sx; sN[4] <- NA
     (svN <- as(sN, "sparseVector"))

     stopifnot(identical(is | FALSE, is != 0),
               validObject(svN), validObject(lis), as.logical(is.na(svN[4])),
               identical(is^2 > 0,   is & TRUE),
               all(!lis), !any(lis), length(nn@i) == 0, !any(nn), all(!nn),
               sum(lis) == 0, !prod(lis), range(lis) == c(0,0))

