[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] Reshape function
- From: Keir Mierle <mierle@xxxxxxxxx>
- Date: Fri, 20 Feb 2009 22:27:21 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=eYJKH4AlRSzW+3XIsTu5v3ugD/7C2Cj8E+yk3pE6iSc=; b=FDK5KG0MSbATSZ+jip3mWGlLcxgNpNMKPApkdHl2UeQITjtqtMfuunn3NPDa1OVAYI ptrPP2Gs4ZF3/2UhDOYRnQIXqMdvdr0A16+gXknvokZxGfJcAqUgZSWmEKujwAFcr4L1 m27B2NlPFTGJjD5sZvhSy/sjbnP2jXzB10Ins=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=HXRJdKplexFKl9vl51HaY9PX8fpH69bRRfT+ZjtX7V3rBDFIu+OR9YFejcSXlcz+AY Bun8pebTDPxUnVGRmbAa7KNyGRJ/CMk8WPgCJvY4FIvRtinFuAH67ZPuv4Z6mu8ronA8 GiEyTFl53S8OiWCCbMUXLqmixwYV/2QrblsSQ=
It would be nice if Eigen had a reshape function like numpy and matlab:
In [15]: x = random.rand(12)
In [16]: x
Out[16]:
array([ 0.98782169, 0.24576577, 0.43955455, 0.54305616, 0.00266062,
0.48190312, 0.55144744, 0.36710248, 0..04064906, 0.34286723,
0.13652416, 0.01933417])
In [17]: reshape(x, (3, 4))
Out[17]:
array([[ 0.98782169, 0.24576577, 0.43955455, 0.54305616],
[ 0.00266062, 0.48190312, 0.55144744, 0.36710248],
[ 0.04064906, 0.34286723, 0.13652416, 0.01933417]])
In [18]: reshape(x, (6, 2))
Out[18]:
array([[ 0.98782169, 0.24576577],
[ 0.43955455, 0.54305616],
[ 0.00266062, 0.48190312],
[ 0.55144744, 0.36710248],
[ 0.04064906, 0.34286723],
[ 0.13652416, 0.01933417]])
I mail because some of my old libmv1 code used this, and I am porting it to libmv2. I use this a fair amount in numpy. Here's what I propose:
Matrix<...> mymatrix(12, 1);
mymatrix.reshape(3, 4); // In place.
This should do the same thing as resize, but does not allow changing the number of elements, and does not change the contents. I'm not sure what the semantics should be around column vs row major; I suspect it's best to not do anything fancy (i.e. reshape() with differing row/col major will give different results).
Keir