]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/compute/include/boost/compute/interop/eigen/core.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / interop / eigen / core.hpp
CommitLineData
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
21namespace boost {
22namespace compute {
23
24/// Copies \p matrix to \p buffer.
25template<class Derived>
26inline 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.
34template<class Derived>
35inline 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_.
43inline 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_.
51inline 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
61BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2i, int2)
62BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4i, int4)
63BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2f, float2)
64BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4f, float4)
65BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix2f, float8)
66BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix4f, float16)
67BOOST_COMPUTE_TYPE_NAME(Eigen::Vector2d, double2)
68BOOST_COMPUTE_TYPE_NAME(Eigen::Vector4d, double4)
69BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix2d, double8)
70BOOST_COMPUTE_TYPE_NAME(Eigen::Matrix4d, double16)
71
72#endif // BOOST_COMPUTE_INTEROP_EIGEN_EIGEN_HPP