NDArray.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5 * Karlsruhe Institute of Technology (KIT), all rights reserved.
6 *
7 * ArmarX is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * ArmarX is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu)
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24#pragma once
25
26// STD/STL
27#include <cstddef>
28#include <functional>
29#include <map>
30#include <memory>
31#include <numeric>
32#include <vector>
33
34// Base class
36
37// ArmarX
38#include "../container/Dict.h"
39
40// Types
42
43namespace armarx::aron::data
44{
45 class NDArray;
46 using NDArrayPtr = std::shared_ptr<NDArray>;
47
48 class NDArray : public detail::ComplexVariant<data::dto::NDArray, NDArray>
49 {
50 public:
51 // constructors
52 NDArray(const Path& path = Path());
53 NDArray(const data::dto::NDArrayPtr&, const Path& path = Path());
54 NDArray(const std::vector<int>&,
55 const std::string&,
56 const std::vector<unsigned char>&,
57 const Path& path = Path());
58
59 // operators
60 using detail::ComplexVariant<data::dto::NDArray, NDArray>::operator==;
61
62 virtual bool operator==(const NDArray&) const override;
63 bool operator==(const NDArrayPtr&) const override;
64
65 // static methods
66 static PointerType FromNDArrayDTO(const data::dto::NDArrayPtr& aron);
67 static data::dto::NDArrayPtr ToNDArrayDTO(const PointerType& navigator);
68
69 /// Return dimensions in a readable string such as "(2, 3, 4)".
70 static std::string DimensionsToString(const std::vector<int>& dimensions);
71
72 // public member functions
73 DictPtr getAsDict() const;
74
75 unsigned char* getData() const;
76 void setData(unsigned int, const unsigned char*);
77
78 std::vector<unsigned char> getDataAsVector() const;
79
80 std::vector<int> getShape() const;
81 void setShape(const std::vector<int>&);
82 void addToShape(int);
83
84 std::string getType() const;
85 void setType(const std::string&);
86
87 data::dto::NDArrayPtr toNDArrayDTO() const;
88
89 // virtual implementations
90 using Base::clone;
91 NDArrayPtr clone(const Path& p) const override;
92
93 virtual std::string getShortName() const override;
94 virtual std::string getFullName() const override;
95
96 virtual type::VariantPtr recalculateType() const override;
97 virtual bool fullfillsType(const type::VariantPtr&) const override;
98 };
99} // namespace armarx::aron::data
100
101namespace armarx::aron
102{
103 template <typename... _Args>
105 make_ndarray(_Args&&... args)
106 {
107 return std::make_shared<aron::data::NDArray>(args...);
108 }
109} // namespace armarx::aron
The Path class.
Definition Path.h:36
virtual std::string getShortName() const override
get a short str representation of this variant
Definition NDArray.cpp:190
void setData(unsigned int, const unsigned char *)
Definition NDArray.cpp:134
static PointerType FromNDArrayDTO(const data::dto::NDArrayPtr &aron)
Definition NDArray.cpp:102
data::dto::NDArrayPtr toNDArrayDTO() const
Definition NDArray.cpp:183
virtual type::VariantPtr recalculateType() const override
recalculate the type of a data variant. Please not tha the mapping ist NOT bijective,...
Definition NDArray.cpp:203
static std::string DimensionsToString(const std::vector< int > &dimensions)
Return dimensions in a readable string such as "(2, 3, 4)".
Definition NDArray.cpp:257
virtual std::string getFullName() const override
get the full str representation of this variant
Definition NDArray.cpp:196
std::vector< unsigned char > getDataAsVector() const
Definition NDArray.cpp:141
std::string getType() const
Definition NDArray.cpp:165
unsigned char * getData() const
Definition NDArray.cpp:128
NDArray(const Path &path=Path())
Definition NDArray.cpp:39
virtual bool operator==(const NDArray &) const override
Definition NDArray.cpp:64
virtual bool fullfillsType(const type::VariantPtr &) const override
checks, if the current data variant fullfills the given type
Definition NDArray.cpp:210
std::vector< int > getShape() const
Definition NDArray.cpp:147
void setShape(const std::vector< int > &)
Definition NDArray.cpp:153
DictPtr getAsDict() const
Definition NDArray.cpp:119
static data::dto::NDArrayPtr ToNDArrayDTO(const PointerType &navigator)
Definition NDArray.cpp:112
void setType(const std::string &)
Definition NDArray.cpp:171
A convenience header to include all aron files (full include, not forward declared)
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::shared_ptr< NDArray > NDArrayPtr
Definition NDArray.h:46
std::shared_ptr< Variant > VariantPtr
aron::data::NDArrayPtr make_ndarray(_Args &&... args)
Definition NDArray.h:105