def compute(self, inputs, outputs):
if not self.topDownMode:<EOL><INDENT>data = self.getNextRecord()<EOL>reset = data["<STR_LIT>"]<EOL>sequenceId = data["<STR_LIT>"]<EOL>categories = data["<STR_LIT>"]<EOL>self.encoder.encodeIntoArray(data, outputs["<STR_LIT>"])<EOL>if self.predictedField is not None and self.predictedField != "<STR_LIT>":<EOL><INDENT>allEncoders = list(self.encoder.encoders)<EOL>if self.disabledEncoder is not None:<EOL><INDENT>allEncoders.extend(self.disabledEncoder.encoders)<EOL><DEDENT>encoders = [e for e in allEncoders<EOL>if e[<NUM_LIT:0>] == self.predictedField]<EOL>if len(encoders) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % self.predictedField)<EOL><DEDENT>else:<EOL><INDENT>encoder = encoders[<NUM_LIT:0>][<NUM_LIT:1>]<EOL><DEDENT>actualValue = data[self.predictedField]<EOL>outputs["<STR_LIT>"][:] = encoder.getBucketIndices(actualValue)<EOL>if isinstance(actualValue, str):<EOL><INDENT>outputs["<STR_LIT>"][:] = encoder.getBucketIndices(actualValue)<EOL><DEDENT>else:<EOL><INDENT>outputs["<STR_LIT>"][:] = actualValue<EOL><DEDENT><DEDENT>outputs["<STR_LIT>"][:] = self.encoder.getScalars(data)<EOL>self._outputValues["<STR_LIT>"] = self.encoder.getEncodedValues(data)<EOL>encoders = self.encoder.getEncoderList()<EOL>prevOffset = <NUM_LIT:0><EOL>sourceEncodings = []<EOL>bitData = outputs["<STR_LIT>"]<EOL>for encoder in encoders:<EOL><INDENT>nextOffset = prevOffset + encoder.getWidth()<EOL>sourceEncodings.append(bitData[prevOffset:nextOffset])<EOL>prevOffset = nextOffset<EOL><DEDENT>self._outputValues['<STR_LIT>'] = sourceEncodings<EOL>for filter in self.postEncodingFilters:<EOL><INDENT>filter.process(encoder=self.encoder, data=outputs['<STR_LIT>'])<EOL><DEDENT>outputs['<STR_LIT>'][<NUM_LIT:0>] = reset<EOL>outputs['<STR_LIT>'][<NUM_LIT:0>] = sequenceId<EOL>self.populateCategoriesOut(categories, outputs['<STR_LIT>'])<EOL>if self.verbosity >= <NUM_LIT:1>:<EOL><INDENT>if self._iterNum == <NUM_LIT:0>:<EOL><INDENT>self.encoder.pprintHeader(prefix="<STR_LIT>")<EOL><DEDENT>if reset:<EOL><INDENT>print("<STR_LIT>" % sequenceId)<EOL><DEDENT>if self.verbosity >= <NUM_LIT:2>:<EOL><INDENT>print()<EOL><DEDENT><DEDENT>if self.verbosity >= <NUM_LIT:1>:<EOL><INDENT>self.encoder.pprint(outputs["<STR_LIT>"], prefix="<STR_LIT>" % (self._iterNum))<EOL>scalarValues = self.encoder.getScalars(data)<EOL>nz = outputs["<STR_LIT>"].nonzero()[<NUM_LIT:0>]<EOL>print("<STR_LIT>" % (len(nz)), nz)<EOL>print("<STR_LIT>", self.encoder.scalarsToStr(scalarValues))<EOL><DEDENT>if self.verbosity >= <NUM_LIT:2>:<EOL><INDENT>print("<STR_LIT>", str(data))<EOL><DEDENT>if self.verbosity >= <NUM_LIT:3>:<EOL><INDENT>decoded = self.encoder.decode(outputs["<STR_LIT>"])<EOL>print("<STR_LIT>", self.encoder.decodedToStr(decoded))<EOL><DEDENT>self._iterNum += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>spatialTopDownIn = inputs['<STR_LIT>']<EOL>spatialTopDownOut = self.encoder.topDownCompute(spatialTopDownIn)<EOL>values = [elem.value for elem in spatialTopDownOut]<EOL>scalars = [elem.scalar for elem in spatialTopDownOut]<EOL>encodings = [elem.encoding for elem in spatialTopDownOut]<EOL>self._outputValues['<STR_LIT>'] = values<EOL>outputs['<STR_LIT>'][:] = numpy.array(scalars)<EOL>self._outputValues['<STR_LIT>'] = encodings<EOL>temporalTopDownIn = inputs['<STR_LIT>']<EOL>temporalTopDownOut = self.encoder.topDownCompute(temporalTopDownIn)<EOL>values = [elem.value for elem in temporalTopDownOut]<EOL>scalars = [elem.scalar for elem in temporalTopDownOut]<EOL>encodings = [elem.encoding for elem in temporalTopDownOut]<EOL>self._outputValues['<STR_LIT>'] = values<EOL>outputs['<STR_LIT>'][:] = numpy.array(scalars)<EOL>self._outputValues['<STR_LIT>'] = encodings<EOL>assert len(spatialTopDownOut) == len(temporalTopDownOut), (<EOL>"<STR_LIT>"<EOL>"<STR_LIT:size>")<EOL><DEDENT>
Get a record from the dataSource and encode it.

Overrides :meth:`nupic.bindings.regions.PyRegion.PyRegion.compute`.