Re: [eigen] Custom expression type API stability
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: Re: [eigen] Custom expression type API stability
• From: Benoit Steiner <benoit.steiner.goog@xxxxxxxxx>
• Date: Thu, 18 Feb 2016 11:04:11 -0800
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=eT7gscZLNv5VEJUWihpvmA5Jp2x2FpSeAqEWSOy03V8=; b=a1887N9bcY8isjdHSkqQAUmLrRry3sdgAsgSA7vshcsLcUmihhyQWVwjDIN3O+6ERb zORiJWfbgeic075dry53Ti2hDXevBfIQ+y7o46kb2R5XlDpJH4PUP/6ihVY3OXUDxocZ 5UWqwxO5HRkHFIk4ETw2qjqCT+Hs7k8HHovEbLU+91v/K5RNf1Z4nME9oWurttr0kcoI Z+pCdqrsUuqAHUYSEdiOLwWuB1BvGPXoy/jULiKaKLUtoTrrC1SncXyjSp+idLMUXB4B 9kLQuSXWbitktQqAut8uw7aLFARY77LTNVeEb7nBbckikp0QQz8enUH6oPhImiXuAom5 JVng==

On Thu, Feb 18, 2016 at 4:46 AM, Dan Čermák wrote:
I need basically two different expressions:

1. given two vectors:
cond_vec and choice_vec -> result(i) = choice_vec(i) if cond_vec(i) > 0
else choice_vec(i+1)
this is rather simple and maybe doable otherwise (and I have already managed
that using the 3.3 development version, although it's probably ugly)

2. calculate reductions of 3d matrices times 2d matrices (they are not stored
fully, since they can be calculated fairly easily from e.g. a matrix and a
vector, or are highly sparse): result(i) = Sum_j,k M_ijk * K_jk (as a full
reduction) or result(i,j) = Sum_k M_ikj * K_kj
I would like to create some abstraction where I only need to provide a
function which calculates the elements or row/col of the contraction result..

You can use a tensor contraction code to do this:
Tensor<float, 3> M(m_dimensions)
Tensor<float, 3> K(k_dimensions);

For the first case
Eigen::array<Eigen::IndexPair<Eigen::DenseIndex>, 2> indices;
indices[0]= Eigen::IndexPair(1, 0);
indices[1]= Eigen::IndexPair(2, 1);
Tensor<float, 1> result = M.contract(K, indices);

For the second case
Eigen::array<Eigen::IndexPair<Eigen::DenseIndex>, 1> indices;
indices[0]= Eigen::IndexPair(1, 0);
Tensor<float, 2> result = M..contract(K, indices);

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