Re: [eigen] how to create a "virtual" array or matrix? |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] how to create a "virtual" array or matrix?*From*: Manoj Rajagopalan <rmanoj@xxxxxxxxx>*Date*: Mon, 7 Jun 2010 16:42:10 -0400*Organization*: EECS Dept., University of Michigan, Ann Arbor, MI, USA

Hi David, IIUC, you want an "encoded" representation of 2D position vectors, in real-space or k-space, i.e., you would like to generate the positions from grid-point info as opposed to explicitly storing the coordinates. AFAIK, the best way to achieve this in Eigen is when your 2D mesh is a tensor-mesh (i.e., cartesian-product) of two 1-D meshes and each 1D mesh is linearly-spaced. Then you can simply declare two such encoded 1D meshes and explicitly manage the 2D relation between them yourself (eg. loop-nesting-order etc). For example, a 1D linearly-spaced mesh [-0.5,0.5) with points spaced at 0.05 (which is useful for representing 1D Wigner-Seitz cells) can be declared like: VectorXd::SequentialLinSpacedReturnType const x_mesh= VectorXd::LinSpaced(Sequential_t(), -0.5, 0.45, 20); VectorXd::RandomAccessLinSpacedReturnType const x_mesh= VectorXd::LinSpaced(-0.5, 0.45, 20); The first version allows better vectorization since it assumes you will iterate sequentially through the mesh, always. If you are going to perform random-access on the mesh points, the second version is better. Note that the upper and lower bounds of the mesh are inclusive and that we provide the total number of points, N (eigen divides mesh-length by N-1). Refer to DenseBase.h and Functors.h. The above discussion refers to Eigen 3. cheers! Manoj On Monday 07 June 2010 03:20:09 pm David Roundy wrote: > Hi all, > > I'd like to create an object that describes an easily-computable > array. In particular, I want to work with some vectors describing > functions of position. In order to easily manipulate these, I'd like > to create an object containing the value $|\vec{r}|^2$. I could, of > course, fill a vector with this value, but that would be a waste of > memory, since it's really cheap to compute. And these vectors will > eventually end up being quite large (maybe a GB or so), so I'd prefer > not to allocate the memory. In the past, I'd have just written a loop > to sum over all positions, but that leads to ugly and hard-to-maintain > code, since a non-trivial loop then shows up many times in the code > (there's a bit of trickiness involving finding the Wigner-Seitz cell). > And it seems that template expressions provide almost precisely what > I want. > > Is there a class that does this, e.g. something like > > class VirtualMatrix<...? { > VirtualMatrix(double (*func)(int, int)); > } > > which could just take a function of indices and turns it into a matrix? > > If there isn't something like this built into eigen, would it be easy > to create? I've tried (briefly) to create a new class deriving > MatrixBase, but immediately ran into trouble. Perhaps I just know too > little about C++ templates to use eigen effectively. :( > > David Roundy

**References**:**[eigen] how to create a "virtual" array or matrix?***From:*David Roundy

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] how to create a "virtual" array or matrix?** - Next by Date:
**[eigen] log10 support?** - Previous by thread:
**Re: [eigen] how to create a "virtual" array or matrix?** - Next by thread:
**[eigen] log10 support?**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |