Esempio n. 1
0
    def _backend(self):
        """
        Query function for the c++ backend object.
        """
        if self.__backend is None:
            # Construct the c++ backend object.
            cpp_types = stringListToStdVectorString(self.__types)
            cpp_coords = numpy2DArrayToStdVectorStdVectorDouble(
                self.__lattice.sites())
            cpp_possible_types = Backend.StdMapStringInt(self.__possible_types)

            # Send in the coordinates and types to construct the backend configuration.
            self.__backend = Backend.Configuration(cpp_coords, cpp_types,
                                                   cpp_possible_types)

        # Return the backend.
        return self.__backend
Esempio n. 2
0
    def _backend(self):
        """
        Query function for the c++ backend object.
        """
        if self.__backend is None:
            # Construct the c++ backend object.
            cpp_types  = stringListToStdVectorString(self.__types)
            cpp_coords = numpy2DArrayToStdVectorStdVectorDouble(self.__lattice.sites())
            cpp_possible_types = Backend.StdMapStringInt(self.__possible_types)

            # Send in the coordinates and types to construct the backend configuration.
            self.__backend = Backend.Configuration(cpp_coords,
                                                   cpp_types,
                                                   cpp_possible_types)

        # Return the backend.
        return self.__backend
Esempio n. 3
0
    def testNumpy2DArrayToStdVectorStdVectorDouble(self):
        """ Test the conversion of a 2D numpy array to a std::vector representation. """
        nI = 3;
        nJ = 5;
        array = numpy.random.rand(nI,nJ)

        # Convert to c++
        cpp_array = numpy2DArrayToStdVectorStdVectorDouble(array)

        # Check the size.
        self.assertEqual(cpp_array.size(), nI)
        self.assertEqual(len(cpp_array[0]), nJ)

        # Convert back and check values.
        converted = []
        for row in cpp_array:
            converted.append(numpy.array(row))
        converted = numpy.array(converted)

        # Check.
        self.assertAlmostEqual(numpy.linalg.norm(array-converted), 0.0, 10)
    def testNumpy2DArrayToStdVectorStdVectorDouble(self):
        """ Test the conversion of a 2D numpy array to a std::vector representation. """
        nI = 3
        nJ = 5
        array = numpy.random.rand(nI, nJ)

        # Convert to c++
        cpp_array = numpy2DArrayToStdVectorStdVectorDouble(array)

        # Check the size.
        self.assertEqual(cpp_array.size(), nI)
        self.assertEqual(len(cpp_array[0]), nJ)

        # Convert back and check values.
        converted = []
        for row in cpp_array:
            converted.append(numpy.array(row))
        converted = numpy.array(converted)

        # Check.
        self.assertAlmostEqual(numpy.linalg.norm(array - converted), 0.0, 10)
Esempio n. 5
0
    def _backend(self, possible_types):
        """
        Query for the local configuration backend object.

        :param possible_types: A dict with the global mapping of type strings
                               to integers.

        :returns: The interactions object in C++
        """
        if self.__backend is None:
            # Construct the c++ backend object.
            cpp_types  = Backend.StdVectorString(self.__types)
            cpp_coords = numpy2DArrayToStdVectorStdVectorDouble(self.__coordinates)
            cpp_possible_types = Backend.StdMapStringInt(possible_types)

            # Send in the coordinates and types to construct the backend configuration.
            self.__backend = Backend.Configuration(cpp_coords,
                                                   cpp_types,
                                                   cpp_possible_types)

        # Return the backend.
        return self.__backend