コード例 #1
0
    def backendRateCallbackBuckets(self,
                                   cpp_coords,
                                   coords_len,
                                   occupations,
                                   update,
                                   types_map,
                                   rate_constant,
                                   process_number,
                                   global_x,
                                   global_y,
                                   global_z):
        """
        Function called from C++ to get the rate. It function recieves
        the data from C++ and parse it to a Python friendly format to send it
        forward to the custom rate function.
        """
        # PERFORMME: move operations to C++.

        # Determine the occupations after the move.
        occupations_after = Backend.StdVectorTypeBucket()

        for i in range(len(update)):
            occupations_after.push_back(occupations[i].add(update[i]))

        # Call and return the custom rate.
        global_coordinate = (global_x, global_y, global_z)
        return self.rate(numpy.array(cpp_coords).reshape(coords_len,3),
                         stdVectorTypeBucketToPython(occupations, types_map),
                         stdVectorTypeBucketToPython(occupations_after, types_map),
                         rate_constant,
                         process_number,
                         global_coordinate)
コード例 #2
0
    def testStdVectorBucketTypeToPython(self):
        """ Test the buckets format conversion routine from C++ to Python. """
        empty_py_vector = stdVectorTypeBucketToPython(
            Backend.StdVectorTypeBucket(), Backend.StdVectorString())

        self.assertEqual(empty_py_vector, [])

        # Add a vector with content.
        cpp_map = Backend.StdVectorString(3)
        cpp_map[0] = "*"
        cpp_map[1] = "A"
        cpp_map[2] = "B"

        cpp_vector = Backend.StdVectorTypeBucket(4, Backend.TypeBucket(3))

        # [(1,"A")]
        cpp_vector[0][0] = 0
        cpp_vector[0][1] = 1
        cpp_vector[0][2] = 0

        # []
        cpp_vector[1][0] = 0
        cpp_vector[1][1] = 0
        cpp_vector[1][2] = 0

        # [(3,"A"), (1, "B")]
        cpp_vector[2][0] = 0
        cpp_vector[2][1] = 3
        cpp_vector[2][2] = 1

        # [(4,"A"), (5, "B")]
        cpp_vector[3][0] = 1
        cpp_vector[3][1] = 4
        cpp_vector[3][2] = 5

        # Translate to Python.
        py_vector = stdVectorTypeBucketToPython(cpp_vector, cpp_map)

        ref_py_vector = [[(1, "A")], [], [(3, "A"), (1, "B")],
                         [(4, "A"), (5, "B")]]

        # Check.
        self.assertEqual(py_vector, ref_py_vector)