candlewick 0.7.0-59-g23c6
A tiny cross-platform renderer based on SDL3
Loading...
Searching...
No Matches
Messages.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <string>
5
6#include <zmq.hpp>
7#include <msgpack.hpp>
8
9#include <Eigen/Core>
10
11namespace candlewick {
12namespace runtime {
13
15 struct ArrayMessage {
16 std::string dtype;
17 std::vector<long> dims;
18 std::vector<uint8_t> data;
19
20 size_t ndim() const noexcept { return dims.size(); }
21
23 };
24
26 inline msgpack::object_handle get_handle_from_zmq_msg(zmq::message_t &&msg) {
27 if (!msg.empty())
28 return msgpack::unpack(static_cast<const char *>(msg.data()), msg.size());
29 else
30 return msgpack::object_handle();
31 }
32
33 namespace detail {
34 template <typename S, typename T>
36 std::conditional_t<std::is_const_v<S>, std::add_const_t<T>, T>;
37
38 template <typename MatrixType>
39 Eigen::Map<MatrixType> get_eigen_view_msg_impl(
40 const ArrayMessage &spec,
42 const Eigen::Index rows = spec.dims[0];
43 using MapType = Eigen::Map<MatrixType>;
44 if constexpr (MatrixType::IsVectorAtCompileTime) {
45 return MapType{data, rows};
46 } else {
47 const Eigen::Index cols =
48 spec.ndim() == 2 ? spec.dims[1]
49 : 1; // assume runtime vector if ndim wrong
50 return MapType{data, rows, cols};
51 }
52 }
53 } // namespace detail
54
56 template <typename MatrixType>
57 Eigen::Map<MatrixType> get_eigen_view_from_spec(ArrayMessage &spec) {
58 using Scalar = typename MatrixType::Scalar;
59 Scalar *data = reinterpret_cast<Scalar *>(spec.data.data());
61 }
62
64 template <typename MatrixType>
65 Eigen::Map<const MatrixType>
67 using Scalar = typename MatrixType::Scalar;
68 const Scalar *data = reinterpret_cast<const Scalar *>(spec.data.data());
70 }
71
72} // namespace runtime
73} // namespace candlewick
Definition Messages.h:33
std::conditional_t< std::is_const_v< S >, std::add_const_t< T >, T > add_const_if_const_t
Definition Messages.h:35
Eigen::Map< MatrixType > get_eigen_view_msg_impl(const ArrayMessage &spec, add_const_if_const_t< MatrixType, typename MatrixType::Scalar > *data)
Definition Messages.h:39
Definition Messages.h:12
Eigen::Map< MatrixType > get_eigen_view_from_spec(ArrayMessage &spec)
Convert ArrayMessage to a mutable Eigen::Matrix view.
Definition Messages.h:57
msgpack::object_handle get_handle_from_zmq_msg(zmq::message_t &&msg)
Convert a ZMQ message (by move) to to a msgpack object.
Definition Messages.h:26
Definition Camera.h:8
Message for intermediate representation of a vector or matrix.
Definition Messages.h:15
size_t ndim() const noexcept
Definition Messages.h:20
MSGPACK_DEFINE(dtype, dims, data)
std::vector< long > dims
Definition Messages.h:17
std::vector< uint8_t > data
Definition Messages.h:18
std::string dtype
Definition Messages.h:16