]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //---------------------------------------------------------------------------// |
2 | // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> | |
3 | // | |
4 | // Distributed under the Boost Software License, Version 1.0 | |
5 | // See accompanying file LICENSE_1_0.txt or copy at | |
6 | // http://www.boost.org/LICENSE_1_0.txt | |
7 | // | |
8 | // See http://boostorg.github.com/compute for more information. | |
9 | //---------------------------------------------------------------------------// | |
10 | ||
11 | #ifndef BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP | |
12 | #define BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP | |
13 | ||
14 | #include <Eigen/Core> | |
15 | ||
16 | #include <boost/compute/command_queue.hpp> | |
17 | #include <boost/compute/algorithm/copy_n.hpp> | |
18 | #include <boost/compute/iterator/buffer_iterator.hpp> | |
19 | #include <boost/compute/type_traits/type_name.hpp> | |
20 | ||
21 | namespace boost { | |
22 | namespace compute { | |
23 | ||
24 | /// Copies \p matrix to \p buffer. | |
25 | template<class Derived> | |
26 | inline void eigen_copy_matrix_to_buffer(const Eigen::PlainObjectBase<Derived> &matrix, | |
27 | buffer_iterator<typename Derived::Scalar> buffer, | |
28 | command_queue &queue = system::default_queue()) | |
29 | { | |
30 | ::boost::compute::copy_n(matrix.data(), matrix.size(), buffer, queue); | |
31 | } | |
32 | ||
33 | /// Copies \p buffer to \p matrix. | |
34 | template<class Derived> | |
35 | inline void eigen_copy_buffer_to_matrix(const buffer_iterator<typename Derived::Scalar> buffer, | |
36 | Eigen::PlainObjectBase<Derived> &matrix, | |
37 | command_queue &queue = system::default_queue()) | |
38 | { | |
39 | ::boost::compute::copy_n(buffer, matrix.size(), matrix.data(), queue); | |
40 | } | |
41 | ||
42 | /// Converts an \c Eigen::Matrix4f to a \c float16_. | |
43 | inline float16_ eigen_matrix4f_to_float16(const Eigen::Matrix4f &matrix) | |
44 | { | |
45 | float16_ result; | |
46 | std::memcpy(&result, matrix.data(), 16 * sizeof(float)); | |
47 | return result; | |
48 | } | |
49 | ||
50 | /// Converts an \c Eigen::Matrix4d to a \c double16_. | |
51 | inline double16_ eigen_matrix4d_to_double16(const Eigen::Matrix4d &matrix) | |
52 | { | |
53 | double16_ result; | |
54 | std::memcpy(&result, matrix.data(), 16 * sizeof(double)); | |
55 | return result; | |
56 | } | |
57 | ||
58 | } // end compute namespace | |
59 | } // end boost namespace | |
60 | ||
61 | BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2i, int2) | |
62 | BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4i, int4) | |
63 | BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2f, float2) | |
64 | BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4f, float4) | |
65 | BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix2f, float8) | |
66 | BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix4f, float16) | |
67 | BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2d, double2) | |
68 | BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4d, double4) | |
69 | BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix2d, double8) | |
70 | BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix4d, double16) | |
71 | ||
72 | #endif // BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP |