-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started exporting VMD class to python.
Required by basis vector methods in MDGeometry Refs #6027
- Loading branch information
1 parent
1dcfc55
commit 608c45f
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/VMD.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "MantidKernel/VMD.h" | ||
#include <boost/python/class.hpp> | ||
#include <boost/python/copy_const_reference.hpp> | ||
#include <boost/python/make_constructor.hpp> | ||
#include <boost/python/operators.hpp> | ||
#include <boost/python/return_value_policy.hpp> | ||
|
||
using Mantid::Kernel::VMD; | ||
using Mantid::Kernel::VMD_t; | ||
using namespace boost::python; | ||
|
||
void export_VMD() | ||
{ | ||
class_<VMD>("VMD", init<>("Default constructor gives an object with 1 dimension")) | ||
.def(init<VMD_t,VMD_t>("Constructs a 2 dimensional vector at the point given", args(("val0"),("val1")))) | ||
.def(init<VMD_t,VMD_t,VMD_t>("Constructs a 3 dimensional vector at the point given", | ||
args(("val0"),("val1"),("val2")))) | ||
.def(init<VMD_t,VMD_t,VMD_t,VMD_t>("Constructs a 4 dimensional vector at the point given", | ||
args(("val0"),("val1"),("val2"),("val3")))) | ||
.def(init<VMD_t,VMD_t,VMD_t,VMD_t,VMD_t>("Constructs a 5 dimensional vector at the point given", | ||
args(("val0"),("val1"),("val2"),("val3"),("val4")))) | ||
.def(init<VMD_t,VMD_t,VMD_t,VMD_t,VMD_t,VMD_t>("Constructs a 6 dimensional vector at the point given", | ||
args(("val0"),("val1"),("val2"),("val3"),("val5")))) | ||
|
||
.def("getNumDims", &VMD::getNumDims, "Returns the number of dimensions the contained in the vector") | ||
|
||
//----------------------------- special methods -------------------------------- | ||
.def("__getitem__", (const VMD_t &(VMD::*)(size_t)const)&VMD::operator[], return_value_policy<copy_const_reference>()) | ||
.def(self + self) | ||
.def(self += self) | ||
// cppcheck-suppress duplicateExpression | ||
.def(self - self) | ||
.def(self -= self) | ||
.def(self * self) | ||
.def(self *= self) | ||
.def(self / self) | ||
.def(self /= self) | ||
; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Code/Mantid/Framework/PythonInterface/test/python/mantid/kernel/VMDTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import unittest | ||
from mantid.kernel import VMD | ||
|
||
class VMDTest(unittest.TestCase): | ||
|
||
def test_default_construction_gives_object_with_single_dimension(self): | ||
one = VMD() | ||
self.assertEquals(1, one.getNumDims()) | ||
|
||
def test_constructors_with_dimension_pts(self): | ||
pts = [1] | ||
for i in range(2,7): | ||
pts.append(i) | ||
vector = VMD(*pts) #unpack list | ||
self.assertEquals(i, vector.getNumDims()) | ||
|
||
def test_value_access_is_read_only(self): | ||
vector = VMD(1.0,2.0) | ||
self.assertAlmostEqual(1.0, vector[0]) | ||
self.assertAlmostEqual(2.0, vector[1]) | ||
|
||
try: | ||
vector[1] = 5.0 | ||
except TypeError: | ||
pass | ||
except: | ||
self.fail("Operator setters have thrown an unexpected exception type. Expected TypeError.") | ||
else: | ||
self.fail("Operator setters have not thrown an exception. Expected to be read only.") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |