Class Chop

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, SequenceActor, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class Chop
    extends SDFTransformer
    This actor reads a sequence of input tokens of any type, and writes a sequence of tokens constructed from the input sequence (possibly supplemented with zeros). The number of input tokens consumed is given by numberToRead, and the number of output tokens produced is given by numberToWrite. The offset parameter (default 0) specifies where in the output block the first (oldest) input that is read should go. If offset is positive and usePastInputs is true, then the first few outputs will come from values read in previous iterations.

    A simple use of this actor is to pad a block of inputs with zeros. Set offset to zero and use numberToWrite > numberToRead.

    Another simple use is to obtain overlapping windows from an input stream. Set usePastInputs to true, use numberToWrite > numberToRead, and set offset equal to numberToWrite - numberToRead.

    The general operation is illustrated with the following examples. If offset is positive, there two possible scenarios, illustrated by the following examples:

         iiiiii                  numberToRead = 6
          \    \                 offset = 2
         ppiiiiii00              numberToWrite = 10
    
         iiiiii                  numberToRead = 6
          \ \  \                 offset = 2
         ppiii                   numberToWrite = 5
     

    The symbol "i" refers to any input token. The leftmost symbol refers to the oldest input token of the ones consumed in a given firing. The symbol "p" refers to a token that is either zero (if usePastInputs is false) or is equal to a previously consumed input token (if usePastInputs is true). The symbol "0" refers to a zero-valued token. In the first of the above examples, the entire input block is copied to the output, and then filled out with zeros. In the second example, only a portion of the input block fits. The remaining input tokens are discarded, although they might be used in subsequent firings if usePastInputs is true.

    When the offset is negative, this indicates that the first offset input tokens that are read should be discarded. The corresponding scenarios are shown below:

         iiiiii                  numberToRead = 6
        / /  /                   offset = -2
         iiii000000              numberToWrite = 10
    
         iiiiii                  numberToRead = 6
        / / //                   offset = -2
         iii                     numberToWrite = 3
     

    In the first of these examples, the first two input tokens are discarded. In the second example, the first two and the last input token are discarded.

    The zero-valued tokens are constructed using the zero() method of the first input token that is read in the firing. This returns a zero-valued token with the same type as the input.

    Since:
    Ptolemy II 1.0
    Version:
    $Id$
    Author:
    Edward A. Lee
    Pt.AcceptedRating:
    Yellow (neuendor)
    Pt.ProposedRating:
    Green (eal)