nodes: 0, module; 1, function_definition; 2, function_name:compute; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, comment:# When we're moving, the feature-location input has no effect.; 15, if_statement; 16, if_statement; 17, identifier:deltaLocation; 18, tuple; 19, identifier:newLocation; 20, tuple; 21, identifier:featureLocationInput; 22, tuple; 23, identifier:featureLocationGrowthCandidates; 24, tuple; 25, identifier:learn; 26, True; 27, comment:"""
      Run one time step of the Location Memory algorithm.
  
      @param deltaLocation (sorted numpy array)
      @param newLocation (sorted numpy array)
      @param featureLocationInput (sorted numpy array)
      @param featureLocationGrowthCandidates (sorted numpy array)
      """; 28, assignment; 29, assignment; 30, comparison_operator:len(deltaLocation) == 0; 31, block; 32, else_clause; 33, comparison_operator:len(newLocation) > 0; 34, comment:# Drive activations by relaying this location SDR.; 35, block; 36, elif_clause; 37, elif_clause; 38, identifier:prevActiveCells; 39, attribute; 40, attribute; 41, subscript; 42, call; 43, integer:0; 44, expression_statement; 45, block; 46, call; 47, integer:0; 48, expression_statement; 49, if_statement; 50, comparison_operator:len(prevActiveCells) > 0; 51, block; 52, comparison_operator:len(featureLocationInput) > 0; 53, comment:# Drive activations with the featureLocationInput.; 54, block; 55, identifier:self; 56, identifier:activeCells; 57, identifier:self; 58, identifier:activeDeltaSegments; 59, call; 60, integer:0; 61, identifier:len; 62, argument_list; 63, assignment; 64, expression_statement; 65, identifier:len; 66, argument_list; 67, assignment; 68, identifier:learn; 69, comment:# Learn the delta.; 70, block; 71, call; 72, integer:0; 73, if_statement; 74, call; 75, integer:0; 76, expression_statement; 77, expression_statement; 78, attribute; 79, argument_list; 80, identifier:deltaLocation; 81, attribute; 82, subscript; 83, assignment; 84, identifier:newLocation; 85, attribute; 86, identifier:newLocation; 87, expression_statement; 88, comment:# Learn the featureLocationInput.; 89, expression_statement; 90, identifier:len; 91, argument_list; 92, comparison_operator:len(deltaLocation) > 0; 93, comment:# Drive activations by applying the deltaLocation to the current location.; 94, comment:# Completely ignore the featureLocationInput. It's outdated, associated; 95, comment:# with the previous location.; 96, block; 97, else_clause; 98, identifier:len; 99, argument_list; 100, assignment; 101, assignment; 102, identifier:np; 103, identifier:where; 104, binary_operator:(self.internalConnections.computeActivity(
          prevActiveCells, self.connectedPermanence
        ) >= self.activationThreshold)
        &
        (self.deltaConnections.computeActivity(
          deltaLocation, self.connectedPermanence
        ) >= self.activationThreshold); 105, identifier:self; 106, identifier:activeFeatureLocationSegments; 107, call; 108, integer:0; 109, attribute; 110, call; 111, identifier:self; 112, identifier:activeCells; 113, call; 114, call; 115, identifier:prevActiveCells; 116, call; 117, integer:0; 118, expression_statement; 119, expression_statement; 120, comment:# Keep previous active cells active.; 121, comment:# Modulate with the featureLocationInput.; 122, block; 123, identifier:featureLocationInput; 124, identifier:cellsForFeatureLocationSegments; 125, parenthesized_expression; 126, attribute; 127, call; 128, parenthesized_expression; 129, parenthesized_expression; 130, attribute; 131, argument_list; 132, identifier:self; 133, identifier:activeFeatureLocationSegments; 134, attribute; 135, argument_list; 136, attribute; 137, argument_list; 138, attribute; 139, argument_list; 140, identifier:len; 141, argument_list; 142, assignment; 143, assignment; 144, if_statement; 145, call; 146, identifier:self; 147, identifier:activeCells; 148, attribute; 149, argument_list; 150, comparison_operator:self.internalConnections.computeActivity(
          prevActiveCells, self.connectedPermanence
        ) >= self.activationThreshold; 151, comparison_operator:self.deltaConnections.computeActivity(
          deltaLocation, self.connectedPermanence
        ) >= self.activationThreshold; 152, identifier:np; 153, identifier:where; 154, comparison_operator:self.featureLocationConnections.computeActivity(
            featureLocationInput, self.connectedPermanence
          ) >= self.activationThreshold; 155, identifier:np; 156, identifier:empty; 157, integer:0; 158, keyword_argument; 159, identifier:self; 160, identifier:_learnTransition; 161, identifier:prevActiveCells; 162, identifier:deltaLocation; 163, identifier:newLocation; 164, identifier:self; 165, identifier:_learnFeatureLocationPair; 166, identifier:newLocation; 167, identifier:featureLocationInput; 168, identifier:featureLocationGrowthCandidates; 169, identifier:deltaLocation; 170, identifier:cellsForDeltaSegments; 171, call; 172, attribute; 173, call; 174, comparison_operator:len(self.activeFeatureLocationSegments) > 0; 175, block; 176, else_clause; 177, attribute; 178, argument_list; 179, identifier:np; 180, identifier:unique; 181, identifier:cellsForFeatureLocationSegments; 182, call; 183, attribute; 184, call; 185, attribute; 186, call; 187, attribute; 188, identifier:dtype; 189, string:"uint32"; 190, attribute; 191, argument_list; 192, identifier:self; 193, identifier:activeCells; 194, attribute; 195, argument_list; 196, call; 197, integer:0; 198, expression_statement; 199, expression_statement; 200, block; 201, attribute; 202, identifier:mapSegmentsToCells; 203, attribute; 204, attribute; 205, argument_list; 206, identifier:self; 207, identifier:activationThreshold; 208, attribute; 209, argument_list; 210, identifier:self; 211, identifier:activationThreshold; 212, attribute; 213, argument_list; 214, identifier:self; 215, identifier:activationThreshold; 216, attribute; 217, identifier:mapSegmentsToCells; 218, attribute; 219, identifier:np; 220, identifier:unique; 221, identifier:cellsForDeltaSegments; 222, identifier:len; 223, argument_list; 224, assignment; 225, assignment; 226, expression_statement; 227, identifier:self; 228, identifier:featureLocationConnections; 229, identifier:self; 230, identifier:activeFeatureLocationSegments; 231, attribute; 232, identifier:computeActivity; 233, identifier:prevActiveCells; 234, attribute; 235, attribute; 236, identifier:computeActivity; 237, identifier:deltaLocation; 238, attribute; 239, attribute; 240, identifier:computeActivity; 241, identifier:featureLocationInput; 242, attribute; 243, identifier:self; 244, identifier:internalConnections; 245, identifier:self; 246, identifier:activeDeltaSegments; 247, attribute; 248, identifier:cellsForFeatureLocationSegments; 249, parenthesized_expression; 250, attribute; 251, call; 252, assignment; 253, identifier:self; 254, identifier:internalConnections; 255, identifier:self; 256, identifier:connectedPermanence; 257, identifier:self; 258, identifier:deltaConnections; 259, identifier:self; 260, identifier:connectedPermanence; 261, identifier:self; 262, identifier:featureLocationConnections; 263, identifier:self; 264, identifier:connectedPermanence; 265, identifier:self; 266, identifier:activeFeatureLocationSegments; 267, call; 268, identifier:self; 269, identifier:activeCells; 270, attribute; 271, argument_list; 272, attribute; 273, identifier:prevActiveCells; 274, attribute; 275, argument_list; 276, identifier:np; 277, identifier:intersect1d; 278, identifier:prevActiveCells; 279, identifier:cellsForFeatureLocationSegments; 280, identifier:self; 281, identifier:activeCells; 282, attribute; 283, identifier:mapSegmentsToCells; 284, attribute; 285, identifier:self; 286, identifier:featureLocationConnections; 287, identifier:self; 288, identifier:activeFeatureLocationSegments
code: def compute(self, deltaLocation=(), newLocation=(),
                featureLocationInput=(), featureLocationGrowthCandidates=(),
                learn=True):
      """
      Run one time step of the Location Memory algorithm.
  
      @param deltaLocation (sorted numpy array)
      @param newLocation (sorted numpy array)
      @param featureLocationInput (sorted numpy array)
      @param featureLocationGrowthCandidates (sorted numpy array)
      """
      prevActiveCells = self.activeCells
  
      self.activeDeltaSegments = np.where(
        (self.internalConnections.computeActivity(
          prevActiveCells, self.connectedPermanence
        ) >= self.activationThreshold)
        &
        (self.deltaConnections.computeActivity(
          deltaLocation, self.connectedPermanence
        ) >= self.activationThreshold))[0]
  
      # When we're moving, the feature-location input has no effect.
      if len(deltaLocation) == 0:
        self.activeFeatureLocationSegments = np.where(
          self.featureLocationConnections.computeActivity(
            featureLocationInput, self.connectedPermanence
          ) >= self.activationThreshold)[0]
      else:
        self.activeFeatureLocationSegments = np.empty(0, dtype="uint32")
  
  
      if len(newLocation) > 0:
        # Drive activations by relaying this location SDR.
        self.activeCells = newLocation
  
        if learn:
          # Learn the delta.
          self._learnTransition(prevActiveCells, deltaLocation, newLocation)
  
          # Learn the featureLocationInput.
          self._learnFeatureLocationPair(newLocation, featureLocationInput,
                                         featureLocationGrowthCandidates)
  
  
      elif len(prevActiveCells) > 0:
        if len(deltaLocation) > 0:
          # Drive activations by applying the deltaLocation to the current location.
          # Completely ignore the featureLocationInput. It's outdated, associated
          # with the previous location.
  
          cellsForDeltaSegments = self.internalConnections.mapSegmentsToCells(
            self.activeDeltaSegments)
  
          self.activeCells = np.unique(cellsForDeltaSegments)
        else:
          # Keep previous active cells active.
          # Modulate with the featureLocationInput.
  
          if len(self.activeFeatureLocationSegments) > 0:
  
            cellsForFeatureLocationSegments = (
              self.featureLocationConnections.mapSegmentsToCells(
                self.activeFeatureLocationSegments))
            self.activeCells = np.intersect1d(prevActiveCells,
                                              cellsForFeatureLocationSegments)
          else:
            self.activeCells = prevActiveCells
  
      elif len(featureLocationInput) > 0:
        # Drive activations with the featureLocationInput.
  
        cellsForFeatureLocationSegments = (
          self.featureLocationConnections.mapSegmentsToCells(
            self.activeFeatureLocationSegments))
  
        self.activeCells = np.unique(cellsForFeatureLocationSegments)