toon-members
[Top][All Lists]

## Re: [Toon-members] Efficient (dynamic) slicing

 From: Rafael Spring Subject: Re: [Toon-members] Efficient (dynamic) slicing Date: Thu, 25 Feb 2010 14:42:07 -0800

```Thank you for the explanation.

```
void fillSubMatrix(Matrix<-1, -1, double, TooN::Internal::Slice<-1, 1> >& slice) {
```// write something to the sclice
}
```
```
```
It looks like that would work. I use the template code above to avoid any reference to TooN internals, and to have generality across different kinds of slice.
```
```
Ok, so the real situation is that fillSubMatrix() is virtual (sorry, should have mentioned that in my first mail). That would probably require to be explicit about the template parameters, right? Can I now assume that the proposed pattern would not result in temp. matrix data being allocated from the heap? Or is there a better practice than this?
```
class Foo {
//...
```
virtual void fillSubMatrix(Matrix<-1, -1, double, TooN::Internal::Slice<-1, 1> >& slice) {
```  // write something to the sclice
}
};

void bar() {
//...
```
myObject->fillSubMatrix(mMatrix.slice(i, 0, inc, mMatrix.num_cols ())); ?
```}

```
I am also a little confused by the Matrix documentation. For the slice () method there is an example:
```
Matrix<> m(3,3);
// Extract the top-left 2x2 matrix
Matrix<2> b = m.slice(0,0,2,2);

```
Is Matrix b now a copy of m's top left 2x2 or is b just referencing this data? Would then the following be a reference?
```
```
Matrix<Dynamic, Dynamic, double, TooN::Internal::Slice<-1,1> > b = m.slice(0,0,2,2);
```

Thanks,
Rafael

```
```
-Ed

--
(You can't go wrong with psycho-rats.)(http://mi.eng.cam.ac.uk/~er258)

/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r 230 350 m 0 1 179{ 1 index show 88 rotate 4 mul 0 rmoveto}for/s 12
d f pop 235 420 translate 0 0 moveto 1 2 scale show showpage
```
```

```