_PDFImpl.py
Go to the documentation of this file.
00001 """autogenerated by genpy from problib/PDFImpl.msg. Do not edit."""
00002 import sys
00003 python3 = True if sys.hexversion > 0x03000000 else False
00004 import genpy
00005 import struct
00006 
00007 import problib.msg
00008 
00009 class PDFImpl(genpy.Message):
00010   _md5sum = "fb6528e73eebd5785d5111d28934c039"
00011   _type = "problib/PDFImpl"
00012   _has_header = False #flag to mark the presence of a Header object
00013   _full_text = """uint8 GAUSSIAN=1
00014 uint8 UNIFORM=2
00015 uint8 DISJUNCTION_STRING = 3  # PMF
00016 uint8 DISJUNCTION_FLOAT = 4   # PMF
00017 uint8 DISJUNCTION_PDF = 5     # Mixture
00018 uint8 CONJUNCTION = 6
00019 
00020 uint8 type
00021 uint32 num_dimensions
00022 DimensionDescription[] dimensions
00023 
00024 # Gaussian
00025 float64[] mean
00026 float64[] covariance
00027 
00028 # Uniform
00029 float64 density
00030 
00031 # For both mixture and discrete 
00032 float64[] probabilities
00033 
00034 # mixture of PFDs (conjunction or disjunction)
00035 uint32[] sub_pdf_ptrs
00036 
00037 # discrete
00038 int32 domain_size
00039 float64[] values_float
00040 string[] values_string
00041 
00042 
00043 ================================================================================
00044 MSG: problib/DimensionDescription
00045 # example: object1.pos_x = ["object1", "pos_x"]
00046 string[] fields
00047 
00048 """
00049   # Pseudo-constants
00050   GAUSSIAN = 1
00051   UNIFORM = 2
00052   DISJUNCTION_STRING = 3
00053   DISJUNCTION_FLOAT = 4
00054   DISJUNCTION_PDF = 5
00055   CONJUNCTION = 6
00056 
00057   __slots__ = ['type','num_dimensions','dimensions','mean','covariance','density','probabilities','sub_pdf_ptrs','domain_size','values_float','values_string']
00058   _slot_types = ['uint8','uint32','problib/DimensionDescription[]','float64[]','float64[]','float64','float64[]','uint32[]','int32','float64[]','string[]']
00059 
00060   def __init__(self, *args, **kwds):
00061     """
00062     Constructor. Any message fields that are implicitly/explicitly
00063     set to None will be assigned a default value. The recommend
00064     use is keyword arguments as this is more robust to future message
00065     changes.  You cannot mix in-order arguments and keyword arguments.
00066 
00067     The available fields are:
00068        type,num_dimensions,dimensions,mean,covariance,density,probabilities,sub_pdf_ptrs,domain_size,values_float,values_string
00069 
00070     :param args: complete set of field values, in .msg order
00071     :param kwds: use keyword arguments corresponding to message field names
00072     to set specific fields.
00073     """
00074     if args or kwds:
00075       super(PDFImpl, self).__init__(*args, **kwds)
00076       #message fields cannot be None, assign default values for those that are
00077       if self.type is None:
00078         self.type = 0
00079       if self.num_dimensions is None:
00080         self.num_dimensions = 0
00081       if self.dimensions is None:
00082         self.dimensions = []
00083       if self.mean is None:
00084         self.mean = []
00085       if self.covariance is None:
00086         self.covariance = []
00087       if self.density is None:
00088         self.density = 0.
00089       if self.probabilities is None:
00090         self.probabilities = []
00091       if self.sub_pdf_ptrs is None:
00092         self.sub_pdf_ptrs = []
00093       if self.domain_size is None:
00094         self.domain_size = 0
00095       if self.values_float is None:
00096         self.values_float = []
00097       if self.values_string is None:
00098         self.values_string = []
00099     else:
00100       self.type = 0
00101       self.num_dimensions = 0
00102       self.dimensions = []
00103       self.mean = []
00104       self.covariance = []
00105       self.density = 0.
00106       self.probabilities = []
00107       self.sub_pdf_ptrs = []
00108       self.domain_size = 0
00109       self.values_float = []
00110       self.values_string = []
00111 
00112   def _get_types(self):
00113     """
00114     internal API method
00115     """
00116     return self._slot_types
00117 
00118   def serialize(self, buff):
00119     """
00120     serialize message into buffer
00121     :param buff: buffer, ``StringIO``
00122     """
00123     try:
00124       _x = self
00125       buff.write(_struct_BI.pack(_x.type, _x.num_dimensions))
00126       length = len(self.dimensions)
00127       buff.write(_struct_I.pack(length))
00128       for val1 in self.dimensions:
00129         length = len(val1.fields)
00130         buff.write(_struct_I.pack(length))
00131         for val2 in val1.fields:
00132           length = len(val2)
00133           if python3 or type(val2) == unicode:
00134             val2 = val2.encode('utf-8')
00135             length = len(val2)
00136           buff.write(struct.pack('<I%ss'%length, length, val2))
00137       length = len(self.mean)
00138       buff.write(_struct_I.pack(length))
00139       pattern = '<%sd'%length
00140       buff.write(struct.pack(pattern, *self.mean))
00141       length = len(self.covariance)
00142       buff.write(_struct_I.pack(length))
00143       pattern = '<%sd'%length
00144       buff.write(struct.pack(pattern, *self.covariance))
00145       buff.write(_struct_d.pack(self.density))
00146       length = len(self.probabilities)
00147       buff.write(_struct_I.pack(length))
00148       pattern = '<%sd'%length
00149       buff.write(struct.pack(pattern, *self.probabilities))
00150       length = len(self.sub_pdf_ptrs)
00151       buff.write(_struct_I.pack(length))
00152       pattern = '<%sI'%length
00153       buff.write(struct.pack(pattern, *self.sub_pdf_ptrs))
00154       buff.write(_struct_i.pack(self.domain_size))
00155       length = len(self.values_float)
00156       buff.write(_struct_I.pack(length))
00157       pattern = '<%sd'%length
00158       buff.write(struct.pack(pattern, *self.values_float))
00159       length = len(self.values_string)
00160       buff.write(_struct_I.pack(length))
00161       for val1 in self.values_string:
00162         length = len(val1)
00163         if python3 or type(val1) == unicode:
00164           val1 = val1.encode('utf-8')
00165           length = len(val1)
00166         buff.write(struct.pack('<I%ss'%length, length, val1))
00167     except struct.error as se: self._check_types(se)
00168     except TypeError as te: self._check_types(te)
00169 
00170   def deserialize(self, str):
00171     """
00172     unpack serialized message in str into this message instance
00173     :param str: byte array of serialized message, ``str``
00174     """
00175     try:
00176       if self.dimensions is None:
00177         self.dimensions = None
00178       end = 0
00179       _x = self
00180       start = end
00181       end += 5
00182       (_x.type, _x.num_dimensions,) = _struct_BI.unpack(str[start:end])
00183       start = end
00184       end += 4
00185       (length,) = _struct_I.unpack(str[start:end])
00186       self.dimensions = []
00187       for i in range(0, length):
00188         val1 = problib.msg.DimensionDescription()
00189         start = end
00190         end += 4
00191         (length,) = _struct_I.unpack(str[start:end])
00192         val1.fields = []
00193         for i in range(0, length):
00194           start = end
00195           end += 4
00196           (length,) = _struct_I.unpack(str[start:end])
00197           start = end
00198           end += length
00199           if python3:
00200             val2 = str[start:end].decode('utf-8')
00201           else:
00202             val2 = str[start:end]
00203           val1.fields.append(val2)
00204         self.dimensions.append(val1)
00205       start = end
00206       end += 4
00207       (length,) = _struct_I.unpack(str[start:end])
00208       pattern = '<%sd'%length
00209       start = end
00210       end += struct.calcsize(pattern)
00211       self.mean = struct.unpack(pattern, str[start:end])
00212       start = end
00213       end += 4
00214       (length,) = _struct_I.unpack(str[start:end])
00215       pattern = '<%sd'%length
00216       start = end
00217       end += struct.calcsize(pattern)
00218       self.covariance = struct.unpack(pattern, str[start:end])
00219       start = end
00220       end += 8
00221       (self.density,) = _struct_d.unpack(str[start:end])
00222       start = end
00223       end += 4
00224       (length,) = _struct_I.unpack(str[start:end])
00225       pattern = '<%sd'%length
00226       start = end
00227       end += struct.calcsize(pattern)
00228       self.probabilities = struct.unpack(pattern, str[start:end])
00229       start = end
00230       end += 4
00231       (length,) = _struct_I.unpack(str[start:end])
00232       pattern = '<%sI'%length
00233       start = end
00234       end += struct.calcsize(pattern)
00235       self.sub_pdf_ptrs = struct.unpack(pattern, str[start:end])
00236       start = end
00237       end += 4
00238       (self.domain_size,) = _struct_i.unpack(str[start:end])
00239       start = end
00240       end += 4
00241       (length,) = _struct_I.unpack(str[start:end])
00242       pattern = '<%sd'%length
00243       start = end
00244       end += struct.calcsize(pattern)
00245       self.values_float = struct.unpack(pattern, str[start:end])
00246       start = end
00247       end += 4
00248       (length,) = _struct_I.unpack(str[start:end])
00249       self.values_string = []
00250       for i in range(0, length):
00251         start = end
00252         end += 4
00253         (length,) = _struct_I.unpack(str[start:end])
00254         start = end
00255         end += length
00256         if python3:
00257           val1 = str[start:end].decode('utf-8')
00258         else:
00259           val1 = str[start:end]
00260         self.values_string.append(val1)
00261       return self
00262     except struct.error as e:
00263       raise genpy.DeserializationError(e) #most likely buffer underfill
00264 
00265 
00266   def serialize_numpy(self, buff, numpy):
00267     """
00268     serialize message with numpy array types into buffer
00269     :param buff: buffer, ``StringIO``
00270     :param numpy: numpy python module
00271     """
00272     try:
00273       _x = self
00274       buff.write(_struct_BI.pack(_x.type, _x.num_dimensions))
00275       length = len(self.dimensions)
00276       buff.write(_struct_I.pack(length))
00277       for val1 in self.dimensions:
00278         length = len(val1.fields)
00279         buff.write(_struct_I.pack(length))
00280         for val2 in val1.fields:
00281           length = len(val2)
00282           if python3 or type(val2) == unicode:
00283             val2 = val2.encode('utf-8')
00284             length = len(val2)
00285           buff.write(struct.pack('<I%ss'%length, length, val2))
00286       length = len(self.mean)
00287       buff.write(_struct_I.pack(length))
00288       pattern = '<%sd'%length
00289       buff.write(self.mean.tostring())
00290       length = len(self.covariance)
00291       buff.write(_struct_I.pack(length))
00292       pattern = '<%sd'%length
00293       buff.write(self.covariance.tostring())
00294       buff.write(_struct_d.pack(self.density))
00295       length = len(self.probabilities)
00296       buff.write(_struct_I.pack(length))
00297       pattern = '<%sd'%length
00298       buff.write(self.probabilities.tostring())
00299       length = len(self.sub_pdf_ptrs)
00300       buff.write(_struct_I.pack(length))
00301       pattern = '<%sI'%length
00302       buff.write(self.sub_pdf_ptrs.tostring())
00303       buff.write(_struct_i.pack(self.domain_size))
00304       length = len(self.values_float)
00305       buff.write(_struct_I.pack(length))
00306       pattern = '<%sd'%length
00307       buff.write(self.values_float.tostring())
00308       length = len(self.values_string)
00309       buff.write(_struct_I.pack(length))
00310       for val1 in self.values_string:
00311         length = len(val1)
00312         if python3 or type(val1) == unicode:
00313           val1 = val1.encode('utf-8')
00314           length = len(val1)
00315         buff.write(struct.pack('<I%ss'%length, length, val1))
00316     except struct.error as se: self._check_types(se)
00317     except TypeError as te: self._check_types(te)
00318 
00319   def deserialize_numpy(self, str, numpy):
00320     """
00321     unpack serialized message in str into this message instance using numpy for array types
00322     :param str: byte array of serialized message, ``str``
00323     :param numpy: numpy python module
00324     """
00325     try:
00326       if self.dimensions is None:
00327         self.dimensions = None
00328       end = 0
00329       _x = self
00330       start = end
00331       end += 5
00332       (_x.type, _x.num_dimensions,) = _struct_BI.unpack(str[start:end])
00333       start = end
00334       end += 4
00335       (length,) = _struct_I.unpack(str[start:end])
00336       self.dimensions = []
00337       for i in range(0, length):
00338         val1 = problib.msg.DimensionDescription()
00339         start = end
00340         end += 4
00341         (length,) = _struct_I.unpack(str[start:end])
00342         val1.fields = []
00343         for i in range(0, length):
00344           start = end
00345           end += 4
00346           (length,) = _struct_I.unpack(str[start:end])
00347           start = end
00348           end += length
00349           if python3:
00350             val2 = str[start:end].decode('utf-8')
00351           else:
00352             val2 = str[start:end]
00353           val1.fields.append(val2)
00354         self.dimensions.append(val1)
00355       start = end
00356       end += 4
00357       (length,) = _struct_I.unpack(str[start:end])
00358       pattern = '<%sd'%length
00359       start = end
00360       end += struct.calcsize(pattern)
00361       self.mean = numpy.frombuffer(str[start:end], dtype=numpy.float64, count=length)
00362       start = end
00363       end += 4
00364       (length,) = _struct_I.unpack(str[start:end])
00365       pattern = '<%sd'%length
00366       start = end
00367       end += struct.calcsize(pattern)
00368       self.covariance = numpy.frombuffer(str[start:end], dtype=numpy.float64, count=length)
00369       start = end
00370       end += 8
00371       (self.density,) = _struct_d.unpack(str[start:end])
00372       start = end
00373       end += 4
00374       (length,) = _struct_I.unpack(str[start:end])
00375       pattern = '<%sd'%length
00376       start = end
00377       end += struct.calcsize(pattern)
00378       self.probabilities = numpy.frombuffer(str[start:end], dtype=numpy.float64, count=length)
00379       start = end
00380       end += 4
00381       (length,) = _struct_I.unpack(str[start:end])
00382       pattern = '<%sI'%length
00383       start = end
00384       end += struct.calcsize(pattern)
00385       self.sub_pdf_ptrs = numpy.frombuffer(str[start:end], dtype=numpy.uint32, count=length)
00386       start = end
00387       end += 4
00388       (self.domain_size,) = _struct_i.unpack(str[start:end])
00389       start = end
00390       end += 4
00391       (length,) = _struct_I.unpack(str[start:end])
00392       pattern = '<%sd'%length
00393       start = end
00394       end += struct.calcsize(pattern)
00395       self.values_float = numpy.frombuffer(str[start:end], dtype=numpy.float64, count=length)
00396       start = end
00397       end += 4
00398       (length,) = _struct_I.unpack(str[start:end])
00399       self.values_string = []
00400       for i in range(0, length):
00401         start = end
00402         end += 4
00403         (length,) = _struct_I.unpack(str[start:end])
00404         start = end
00405         end += length
00406         if python3:
00407           val1 = str[start:end].decode('utf-8')
00408         else:
00409           val1 = str[start:end]
00410         self.values_string.append(val1)
00411       return self
00412     except struct.error as e:
00413       raise genpy.DeserializationError(e) #most likely buffer underfill
00414 
00415 _struct_I = genpy.struct_I
00416 _struct_i = struct.Struct("<i")
00417 _struct_BI = struct.Struct("<BI")
00418 _struct_d = struct.Struct("<d")


problib
Author(s): Sjoerd van den Dries
autogenerated on Tue Jan 7 2014 11:42:42