Re: [eigen] Casting matrices |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Casting matrices
- From: "Timothy Hunter" <tjhunter@xxxxxxxxxxxx>
- Date: Sun, 9 Nov 2008 16:19:03 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=TkizosqVbsnEdYeLgM6ZDGLW802u007U1jes5CiqbR0=; b=FvbKMqs/mqegF5lD0Bc4GMSzICZgixCyZYmZtWpStP9hHOooIS1fV9EpsjBGxIHv7H qaFHMBzzcQpm72n0oC6G32r23h2Sz71bkb9vguhs/Mb3kdWe2+QMA1xFYijvV1yRxtcc iAGFNh5fesOAwr7dc+c9vQat+R42ExWVrb2sU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=Y4zlUR8ZiM4xdKzrINJeQU2xhysADmyxYHplCgH1RxeDd5uFTSIHH+1DTWoLiymhle GoaEXVGb31NSLzv/0fMr9O4pArDEsFdJExtszx2y2phBs/kHpnftu7pO1UR3Ub468oR9 djgJM2x+FzAJIrfLs5G2A10HJofhMVXNpaz34=
I should read the documentation more carefully....
Maybe this feature should be added in the tutorial
(http://eigen.tuxfamily.org/api/TutorialCore.html) ?
On Sun, Nov 9, 2008 at 4:08 PM, Benoît Jacob <jacob@xxxxxxxxxxxxxxx> wrote:
> On Monday 10 November 2008 00:45:12 Timothy Hunter wrote:
>> Hello list,
>> I want to convert a Eigen::MatrixXi to a double * (already allocated
>> and of the right size).
>> A way to do it is to iterate:
>> for(int i=0;i<mat.rows();++i)
>> for(int j=0;j<mat.cols();++j)
>> double_ptr[i*mat.cols()+j] = static_cast<double>(mat(i,j));
>>
>> However I would like to use MatrixXd::Map in this occasion.
>
> Then all you need to do is:
>
> MatrixXf::Map(double_ptr, mat.rows(), mat.cols())
> = mat.cast<double>();
>
> Note that the Matrix::Map static method has been added in SVN very recently,
> beta1 is not enough. (The old way of constructing a Map<MatrixXf> explicitly
> is less practical here, cf. the thread on this list with Cristovao).
>
>>
>> More generally, it is not currently possible to do casting operations
>> like Vector3i = Vector3d and I want to add it on the wishlist if you
>> know of an elegant way to do it.
>
> It is already possible, you can do:
>
> Vector3d vd;
> Vector3i vi = vd.cast<int>();
>
> Cheers,
> Benoit
>
> ---
>
>