# Re: [Rd] matrix bands

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Fri, 26 Aug 2011 18:11:02 +0200

>>>>> Jeremy David Silver <jds_at_dmu.dk>
>>>>> on Fri, 26 Aug 2011 15:08:03 +0200 writes:

```    > Thanks for the suggestion, Martin!  I looked at both
> Matrix::band and Matrix::bandSparse. Maybe I misunderstand the
> help pages and the examples, but from what I can see neither of
> them provides the functionality I was looking for.

> For the getter version of the function I was looking for, I
> can't use Matrix::band (by extracting the non-zero elements)
```
> because this would require the assumption that the specified     > band is entirely non-zero, e.g.:

> band3 <- function(x,n){
> x <- Matrix::band(x,n,n)
> x[x!=0] ## works for a dense matrix, but not if band n has zeroes
> }

> As for the setter version of the function I was looking for, it should
> set the values of a specified band in an existing matrix to be the
> vector of values provided. As far as I understand, Matrix::bandSparse
> constructs a matrix rather than modifying the values of an existing matrix.

Yes, you are right. The current bandSparse() doesn't do that... and while you could use constructions like

diag(A[,-1]) <- dd
there will probably better (more efficient) alternatives.

> The functions included in my last post filled this gap. If Matrix::band
> and Matrix::bandSparse can set/get bands in this way, I would like to
> see how this can be done. If not, then perhaps they could be extended to
> achieve this functionality.

That's a good suggestion, and I'll look at it, further I'll look at your examples of "getting" ... and at the moment I'm still a bit curious why, i.e., to what end / in what application you need them [ rather than band(*,.,.) ]. We may e-talk about this off-public if you want.

Martin

> On 2011-08-26 14:08, Martin Maechler wrote:
> >>>>>> Jeremy David Silver<jds_at_dmu.dk>
> >>>>>> on Fri, 26 Aug 2011 13:23:43 +0200 writes:
> > > Dear R developers, I was looking for a function analogous
> > > to base::diag() for getting and setting bands of a
> > > matrix. The closest I could find was Matrix::band(), but
> > > this was not exactly what I wanted for two
> > > reasons. Firstly, Matrix::band() returns a matrix rather
> > > than just the specified band. Secondly, Matrix::band()
> > > cannot be used for setting the values for a matrix band.
> >
> > Yes, but did you not look at help(band)
> > or not look carefully enough ?
> >
> > --->
> >
> >
> > ‘bandSparse’ for the _construction_ of a banded sparse matrix
> > directly from its non-zero diagonals.
> >
> >
> >
> > > Setting or getting a matrix band could be of interest for
> > > sufficiently many users that you might consider including
> > > it in base R. Alternatively, something like this could be
> > > included in the Matrix package.
> >
> > well, see above and let us know if you see anything lacking in
> > bandSparse().
> > Till now we haven't got much feedback about it, and there may
> > well be room for improvement.
> >
> > Martin Maechler, ETH Zurich and co- maintainer("Matrix")

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 26 Aug 2011 - 16:12:47 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 26 Aug 2011 - 20:20:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.