Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored linalg's dot product #2367

Merged
merged 1 commit into from Jul 6, 2014

Conversation

khalednasr
Copy link
Contributor

  • Changed the template for the implementation structs from <class Info,enum Backend,template<class,Info...>class Vector,class T,Info... I> to <enum Backend, class Vector>. This is simpler and works with any matrix type
  • Eigen3 matrices are handled as described here. This makes the methods in the library work with any Eigen3 matrix type, including expressions.
  • ViennaCL matrices are handled using CGPUVector/CGPUMatrix

@lambday, @karlnapf, @lisitsyn, please take a look. If you guys are okay with those changes, I'll change the rest of the library in the same manner.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) when pulling 42829d4 on khalednasr:feature/linalg into db545fd on shogun-toolbox:feature/linalg.

@@ -121,123 +109,38 @@ struct dot<int,Backend::EIGEN3,Eigen::Matrix,T,Info...>
* @return the dot product of \f$\mathbf{a}\f$ and \f$\mathbf{b}\f$, computed
* as \f$\sum_i a_i b_i\f$
*/
static T compute(vector_type a, vector_type b)
template <class Derived1, class Derived2>
static T compute(const Eigen::MatrixBase<Derived1>& a, const Eigen::MatrixBase<Derived2>& b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khalednasr why should we use two different Derived here? will this enable us to call dot on vectors of two different scalar types or this is to be flexible about one fixed and one dynamic sized vectors? Via redux wrappers I think only a single vector type is handled. If it helps in terms of flexibility, could you please add a tiny unit-test for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lambday it was for flexibility, but I forgot to add another vector type to the redux wrapper. I'll take care of it in the next patch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type is a headache though!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can just always return float64_t?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ummm nah that doesn't work for, say, complex128_t and float64_t :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh I see. I guess we should restrict it to one vector type for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep that's what I was thinking! but it doesn't harm to keep it like this though. So no need to change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one can always directly call the linalg::implementation::dot if really necessary. But man will he be sorry for that :D

@lambday
Copy link
Member

lambday commented Jul 6, 2014

@khalednasr this looks superb and simpler. Travis had a upset stomach again so I restarted the build. I think this is the way to go for linalg. Please refactor the rest of the lib. Also, in the linalg::square method we compute element-wise square. So maybe change it to a better name? (sorry about that!).

@lambday
Copy link
Member

lambday commented Jul 6, 2014

@khalednasr oh and please add your name in the files you modified :)

@lambday
Copy link
Member

lambday commented Jul 6, 2014

@karlnapf @lisitsyn travis is green. Merging this one.

lambday added a commit that referenced this pull request Jul 6, 2014
@lambday lambday merged commit c14ff65 into shogun-toolbox:feature/linalg Jul 6, 2014
@karlnapf
Copy link
Member

karlnapf commented Jul 6, 2014

awesome!

@karlnapf
Copy link
Member

karlnapf commented Jul 6, 2014

we should very soon merge this backend thing. then this year's gsoc project can refactor a bit against that. thoughts?

@lambday
Copy link
Member

lambday commented Jul 6, 2014

@karlnapf absolutely. I guess just @khalednasr's next patch and then we're good to go! Later we'll iteratively add other modules. I am a bit concerned about merge conflicts - IIRC then OpenCV cmake stuffs and OpenCL/ViennaCL cmake stuff might be the culprit. Do we need to rebase against develop before merging with it?

@khalednasr
Copy link
Contributor Author

@lambday about the square() method, beside renaming, maybe it should be in another module(Elementwise.h for instance)? since it doesn't do any reduction.

Also, I think that having it return a new matrix can be inefficient, and would be problematic since all the template specializations would have to return the same type of matrix, which would be bad for the gpu specializations. Instead I suggest having it be something like square(const Matrix& A, Matrix& result). Same goes for rowwise_sum() and so on. What do you think?

@lambday
Copy link
Member

lambday commented Jul 6, 2014

@khalednasr I agree. It totally makes sense to move that to another module. Maybe a more general name - say, Util or something. We could have matrix-matrix multiplication, matrix square, matrix logarithm etc there as well.

Regarding second idea, I am not much aware of that. But if it indeed makes it efficient to have it this way then maybe its better. So +1 from me :)

@karlnapf
Copy link
Member

karlnapf commented Jul 8, 2014

@lambday we only need to rebase if we cannot merge this. I expect that, but it shouldnt be a too big hassle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants