Re: [eigen] is MAP oneway ? (urgent) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] is MAP oneway ? (urgent)
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Wed, 24 Jun 2009 14:19:45 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=dVfYHLrDgJLiM4DKM8D9CGqVUhRq1+n/Rsld9BoqFvI=; b=klxEFpl3qcZzJ2sL73IirskyfrIfLSJcr5HXv09E3RfvJUq7b6koB1dRxkLjG9FSOy 5USP/ZrL84J/ZAn6VjVeCY59WqPpJxx9Rw8X46iBKycoUazglbCd1mPt4DcI9/kgcCIE 5sgbyBeiODLrcQSufBAuV9bmZ8oP9uAqIzH3o=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=PmbMGOSvMQ5kTEdyNTKjkUf/tfXQymVWklUWr8bnDPB9cNHc18h573IPy0GjNdmaJn GHHK0y+Qo60GWrpaRHDGWb2cX5zPYHaFvJaobJM3OztR0dfDktlcU1/rEfIqtY9qzyMa fFnGJuj7kqErA3pR1ggfNy+o6em05wYaZBBOQ=
On Wed, Jun 24, 2009 at 2:13 PM, Helmut
Jarausch<jarausch@xxxxxxxxxxxxxxxxxxx> wrote:
> Hi,
>
> I have to write a function which is called by code which is
> written in C-style (though compiled with g++).
> It delivers me data in a C-array (double*) and expects me
> to modify this.
>
> When I tried the following example, I was a bit surprised.
> So, what does MAP do?
>
>
> #include <iostream>
> using std::cerr; using std::endl;
> #include <Eigen/Core>
> // import most common Eigen types
> USING_PART_OF_NAMESPACE_EIGEN
>
> int main() {
> double data[4] = {1, 2, 3, 4};
>
> VectorXd D = Eigen::Map<VectorXd>(data,4);
> cerr << "D before : " << D << endl;
> data[1]= 7;
> cerr << "D after : " << D << endl; // nothing has changed
> }
>
>
> So, do I have to copy all data from D.data() back to data?
>
> Is there something like "overlaying" an Eigen-Vector onto some raw
> C-array?
this is exactly what Map do, however you have to deal with Map object
directly, e.g.
double* c_like_data = whatever;
Eigen::Map<VectorXd> v(c_like_data, size);
then you can use "v" just like any other Eigen matrix/vector:
v *= 10;
is equivalent to:
for (int i=0; i<size; ++i)
c_like_data[i] *= 10;
gael.