Skip to content

Instantly share code, notes, and snippets.

@brucecrevensten
Created December 16, 2010 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brucecrevensten/743021 to your computer and use it in GitHub Desktop.
Save brucecrevensten/743021 to your computer and use it in GitHub Desktop.
thinking about oo-style reroll of ray's cudasar
# analysis of implicit object hierarchy for rayjanwilson/cudasar, with an eye towards creating a runtime-swappable algorithm for sar processing.
# basic idea here is that we'll use Builder pattern to assemble a SarProcessor,
# and make each distinct algorithm a little object hierarchy so that we can mix'n'match
# standard + cuda + other approaches for more interesting benchmarking
# the builder patterns
class SarProcessor:
def process(SarImage):
return self.azimuthCompression( self.RangeCompression( SarImage ), SarImage.metadata ) # need to pass the whole SarImage to get the L0
# abstract superclass...
class SarProcessorBuilder:
def rangeReferenceFunction(SarMetadata):
# etc
def rangeCompression():
# etc
def azimuthReferenceFunction(SarMetadata):
def azimuthCompression():
# concrete builder class... should inherit dry from SarProcessorBuilder.
class StandardSarProcessorBuilder(SarProcessorBuilder):
# concrete builder class...
class CudaSarProcessorBuilder(SarProcessorBuilder):
# overrides the functions in superclass with cuda implementations
# the 'director'...
class SarProcessorAssembler:
def build(SarProcessorBuilder, SarImage):
s = new SarProcessor()
s.rangeReferenceFunction = SarProcessorBuilder.rangeReferenceFunction # deferred binding
s.rangeCompressionFunction = SarProcessorBuilder.rangeCompressionFunction
s.azimuthReferenceFunction = SarProcessorBuilder.azimuthReferenceFunction
s.azimuthCompressionFunction = SarProcessorBuilder.azimuthCompressionFunction
return s
# example client code (pseudocode):
normalSarBuilder = StandardSarProcessorBuilder()
cudaSarBuilder = CudaSarProcessorBuilder()
normalSarProcessor = SarProcessorAssembler.build( normalSarBuilder )
cudaSarProcessor = SarProcessorAssembler.build(
# base class for L0, L1, etc sar images
class SarImage:
metadata SarImageMetadata; # no idea how to write this yet in python =)
class L0SarImage(SarImage):
def getL0Image(self):
# metadata wrapper
class SarImageMetadata:
# static wrapper subclass for dev/testing
class StaticSarImageMetadata(SarImageMetadata):
# something that can take the output and plot/visualize it
class SarVisualizer:
@rayjanwilson
Copy link

ah cool. yes i can see the builder pattern being a good fit for the processor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment