Mantid
Loading...
Searching...
No Matches
VMD.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#include "MantidKernel/VMD.h"
9#include <boost/python/class.hpp>
10#include <boost/python/copy_const_reference.hpp>
11#include <boost/python/make_constructor.hpp>
12#include <boost/python/operators.hpp>
13#include <boost/python/return_arg.hpp>
14#include <boost/python/return_internal_reference.hpp>
15#include <boost/python/return_value_policy.hpp>
16
19using namespace boost::python;
20
21namespace {
29VMD_t getItem(VMD &self, const size_t index) {
30 if (index < self.getNumDims()) {
31 return self[index];
32 } else
33 throw std::out_of_range("VMD index out of range. index=" + std::to_string(index) +
34 ", len=" + std::to_string(self.getNumDims()));
35}
36
44void setItem(VMD &self, const size_t index, const VMD_t value) {
45 if (index < self.getNumDims()) {
46 self[index] = value;
47 } else
48 throw std::out_of_range("VMD index out of range. index=" + std::to_string(index) +
49 ", len=" + std::to_string(self.getNumDims()));
50}
51} // namespace
52
53GNU_DIAG_OFF("self-assign-overloaded")
54void export_VMD() {
55 class_<VMD>("VMD", init<>(arg("self"), "Default constructor gives an object with 1 dimension"))
56 .def(init<VMD_t, VMD_t>("Constructs a 2 dimensional vector at the point given",
57 (arg("self"), arg("val0"), arg("val1"))))
58 .def(init<VMD_t, VMD_t, VMD_t>("Constructs a 3 dimensional vector at the point given",
59 (arg("self"), arg("val0"), arg("val1"), arg("val2"))))
60 .def(init<VMD_t, VMD_t, VMD_t, VMD_t>("Constructs a 4 dimensional vector at the point given",
61 (arg("self"), arg("val0"), arg("val1"), arg("val2"), arg("val3"))))
62 .def(init<VMD_t, VMD_t, VMD_t, VMD_t, VMD_t>(
63 "Constructs a 5 dimensional vector at the point given",
64 (arg("self"), arg("val0"), arg("val1"), arg("val2"), arg("val3"), arg("val4"))))
65 .def(init<VMD_t, VMD_t, VMD_t, VMD_t, VMD_t, VMD_t>(
66 "Constructs a 6 dimensional vector at the point given",
67 (arg("self"), arg("val0"), arg("val1"), arg("val2"), arg("val3"), arg("val4"), arg("val5"))))
68
69 .def("getNumDims", &VMD::getNumDims, arg("self"), "Returns the number of dimensions the contained in the vector")
70
71 .def("scalar_prod", &VMD::scalar_prod, (arg("self"), arg("other")),
72 "Returns the scalar product of this vector with another. If the "
73 "number of dimensions do not match a RuntimeError is raised")
74
75 .def("cross_prod", &VMD::cross_prod, (arg("self"), arg("other")),
76 "Returns the cross product of this vector with another. If the "
77 "number of dimensions do not match a RuntimeError is raised")
78
79 .def("norm", &VMD::norm, arg("self"), "Returns the length of the vector")
80
81 .def("norm2", &VMD::norm2, arg("self"), "Returns the the squared length of the vector")
82
83 .def("normalize", &VMD::normalize, arg("self"),
84 "Normalizes the length of the vector "
85 "to unity and returns the length "
86 "before it was normalized")
87
88 .def("angle", &VMD::angle, (arg("self"), arg("other")),
89 "Returns the angle between the vectors in "
90 "radians (0 < theta < pi). If the dimensions "
91 "do not match a RuntimeError is raised")
92
93 //----------------------------- special methods
94 //--------------------------------
95 .def("__getitem__", &getItem, (arg("self"), arg("value")))
96 .def("__setitem__", &setItem, (arg("self"), arg("index"), arg("value")))
97 .def(self == self)
98 .def(self != self) // must define != as Python's default is to compare
99 // object address
100 .def("__add__", &VMD::operator+, (arg("left"), arg("right")))
101 .def("__iadd__", &VMD::operator+=, return_self<>(), (arg("self"), arg("other")))
102 .def("__sub__", &VMD::operator-, (arg("left"), arg("right")))
103 .def("__isub__", &VMD::operator-=, return_self<>(), (arg("self"), arg("other")))
104 .def(self * self)
105 .def(self *= self)
106 .def(self / self)
107 .def(self /= self);
108}
109
110GNU_DIAG_ON("self-assign-overloaded")
double value
The value of the point.
Definition: FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
PyObject * getItem(WorkspaceGroup &self, const int &index)
void export_VMD()
Definition: VMD.cpp:54
#define GNU_DIAG_ON(x)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
float VMD_t
Underlying data type for the VMD type.
Definition: VMD.h:83
std::string to_string(const wide_integer< Bits, Signed > &n)