parameters: (self)
docstring: Invoke the provided sampling strategy many times and generate a
          histogram in the parameter domain. If ``sample_func`` returns a tuple
          ``(positions, weights)`` instead of just positions, the samples are
          considered to be weighted.
docstring_summary: Invoke the provided sampling strategy many times and generate a
          histogram in the parameter domain. If ``sample_func`` returns a tuple
          ``(positions, weights)`` instead of just positions, the samples are
          considered to be weighted.
docstring_tokens: Invoke the provided sampling strategy many times and generate a histogram in the parameter domain . If sample_func returns a tuple ( positions weights ) instead of just positions the samples are considered to be weighted .
function: def tabulate_histogram(self):
          """
          Invoke the provided sampling strategy many times and generate a
          histogram in the parameter domain. If ``sample_func`` returns a tuple
          ``(positions, weights)`` instead of just positions, the samples are
          considered to be weighted.
          """
  
          # Generate a table of uniform variates
          from mitsuba.core import Float, Vector2f, Vector2u, Float32, \
              UInt64, PCG32
  
          rng = PCG32(initseq=ek.arange(UInt64, self.sample_count))
  
          samples_in = getattr(mitsuba.core, 'Vector%if' % self.sample_dim)()
          for i in range(self.sample_dim):
              samples_in[i] = rng.next_float32() if Float is Float32 \
                  else rng.next_float64()
  
          self.pdf_start = time.time()
  
          # Invoke sampling strategy
          samples_out = self.sample_func(samples_in)
  
          if type(samples_out) is tuple:
              weights_out = samples_out[1]
              samples_out = samples_out[0]
          else:
              weights_out = Float(1.0)
  
          # Map samples into the parameter domain
          xy = self.domain.map_backward(samples_out)
  
          # Sanity check
          eps = self.bounds.extents() * 1e-4
          in_domain = ek.all((xy >= self.bounds.min - eps) &
                             (xy <= self.bounds.max + eps))
          if not ek.all(in_domain):
              self._log('Encountered samples outside of the specified '
                        'domain: %s' % str(ek.compress(xy, ~in_domain)))
              self.fail = True
  
          # Normalize position values
          xy = (xy - self.bounds.min) / self.bounds.extents()
          xy = Vector2u(ek.clamp(xy * Vector2f(self.res), 0,
                                 Vector2f(self.res - 1)))
  
          # Compute a histogram of the positions in the parameter domain
          self.histogram = ek.zero(Float, ek.hprod(self.res))
  
          ek.scatter_add(
              target=self.histogram,
              index=xy.x + xy.y * self.res.x,
              source=weights_out
          )
  
          self.pdf_end = time.time()
  
          histogram_min = ek.hmin(self.histogram)
          if not histogram_min >= 0:
              self._log('Encountered a cell with negative sample '
                        'weights: %f' % histogram_min)
              self.fail = True
  
          self.histogram_sum = ek.hsum(self.histogram) / self.sample_count
          if self.histogram_sum > 1.1:
              self._log('Sample weights add up to a value greater '
                        'than 1.0: %f' % self.histogram_sum)
              self.fail = True
function_tokens: def tabulate_histogram ( self ) : # Generate a table of uniform variates from mitsuba . core import Float , Vector2f , Vector2u , Float32 , UInt64 , PCG32 rng = PCG32 ( initseq = ek . arange ( UInt64 , self . sample_count ) ) samples_in = getattr ( mitsuba . core , 'Vector%if' % self . sample_dim ) ( ) for i in range ( self . sample_dim ) : samples_in [ i ] = rng . next_float32 ( ) if Float is Float32 else rng . next_float64 ( ) self . pdf_start = time . time ( ) # Invoke sampling strategy samples_out = self . sample_func ( samples_in ) if type ( samples_out ) is tuple : weights_out = samples_out [ 1 ] samples_out = samples_out [ 0 ] else : weights_out = Float ( 1.0 ) # Map samples into the parameter domain xy = self . domain . map_backward ( samples_out ) # Sanity check eps = self . bounds . extents ( ) * 1e-4 in_domain = ek . all ( ( xy >= self . bounds . min - eps ) & ( xy <= self . bounds . max + eps ) ) if not ek . all ( in_domain ) : self . _log ( 'Encountered samples outside of the specified ' 'domain: %s' % str ( ek . compress ( xy , ~ in_domain ) ) ) self . fail = True # Normalize position values xy = ( xy - self . bounds . min ) / self . bounds . extents ( ) xy = Vector2u ( ek . clamp ( xy * Vector2f ( self . res ) , 0 , Vector2f ( self . res - 1 ) ) ) # Compute a histogram of the positions in the parameter domain self . histogram = ek . zero ( Float , ek . hprod ( self . res ) ) ek . scatter_add ( target = self . histogram , index = xy . x + xy . y * self . res . x , source = weights_out ) self . pdf_end = time . time ( ) histogram_min = ek . hmin ( self . histogram ) if not histogram_min >= 0 : self . _log ( 'Encountered a cell with negative sample ' 'weights: %f' % histogram_min ) self . fail = True self . histogram_sum = ek . hsum ( self . histogram ) / self . sample_count if self . histogram_sum > 1.1 : self . _log ( 'Sample weights add up to a value greater ' 'than 1.0: %f' % self . histogram_sum ) self . fail = True