1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP
12 #define BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP
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>
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())
30 ::boost::compute::copy_n(matrix.data(), matrix.size(), buffer, queue);
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())
39 ::boost::compute::copy_n(buffer, matrix.size(), matrix.data(), queue);
42 /// Converts an \c Eigen::Matrix4f to a \c float16_.
43 inline float16_ eigen_matrix4f_to_float16(const Eigen::Matrix4f &matrix)
46 std::memcpy(&result, matrix.data(), 16 * sizeof(float));
50 /// Converts an \c Eigen::Matrix4d to a \c double16_.
51 inline double16_ eigen_matrix4d_to_double16(const Eigen::Matrix4d &matrix)
54 std::memcpy(&result, matrix.data(), 16 * sizeof(double));
58 } // end compute namespace
59 } // end boost namespace
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)
72 #endif // BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP