ptolemy.backtrack.automatic.ptolemy.domains.sdf.lib
Class Chop

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.domains.sdf.lib.SDFTransformer
                              extended by ptolemy.backtrack.automatic.ptolemy.domains.sdf.lib.Chop
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, SequenceActor, TypedActor, Rollbackable, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class Chop
extends SDFTransformer
implements Rollbackable

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: Chop.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Yellow (neuendor)
Proposed Rating:
Green (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  Token[] _buffer
           
private  int _highLimit
           
private  int _inputIndex
           
private  int _lowLimit
           
private  int _numberToRead
           
private  int _numberToWrite
           
private  int _offsetValue
           
private  Token[] _pastBuffer
           
private  boolean _pastNeedsInitializing
           
private  boolean _usePast
           
protected  Checkpoint $CHECKPOINT
           
private  FieldRecord $RECORD$_buffer
           
private  FieldRecord $RECORD$_highLimit
           
private  FieldRecord $RECORD$_inputIndex
           
private  FieldRecord $RECORD$_lowLimit
           
private  FieldRecord $RECORD$_numberToRead
           
private  FieldRecord $RECORD$_numberToWrite
           
private  FieldRecord $RECORD$_offsetValue
           
private  FieldRecord $RECORD$_pastBuffer
           
private  FieldRecord $RECORD$_pastNeedsInitializing
           
private  FieldRecord $RECORD$_usePast
           
protected  CheckpointRecord $RECORD$$CHECKPOINT
           
private  FieldRecord[] $RECORDS
           
 Parameter numberToRead
          The number of input tokens to read.
 Parameter numberToWrite
          The number of tokens to write to the output.
 Parameter offset
          Start of output block relative to start of input block.
 Parameter usePastInputs
          If offset is greater than 0, specify whether to use previously read inputs (otherwise use zeros).
 
Fields inherited from class ptolemy.domains.sdf.lib.SDFTransformer
input, input_tokenConsumptionRate, output, output_tokenInitProduction, output_tokenProductionRate
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
Chop(CompositeEntity container, java.lang.String name)
          Construct an actor in the specified container with the specified name.
 
Method Summary
private  Token $ASSIGN$_buffer(int index0, Token newValue)
           
private  Token[] $ASSIGN$_buffer(Token[] newValue)
           
private  int $ASSIGN$_highLimit(int newValue)
           
private  int $ASSIGN$_inputIndex(int newValue)
           
private  int $ASSIGN$_lowLimit(int newValue)
           
private  int $ASSIGN$_numberToRead(int newValue)
           
private  int $ASSIGN$_numberToWrite(int newValue)
           
private  int $ASSIGN$_offsetValue(int newValue)
           
private  Token $ASSIGN$_pastBuffer(int index0, Token newValue)
           
private  Token[] $ASSIGN$_pastBuffer(Token[] newValue)
           
private  boolean $ASSIGN$_pastNeedsInitializing(boolean newValue)
           
private  boolean $ASSIGN$_usePast(boolean newValue)
           
private  Token[] $BACKUP$_buffer()
           
private  Token[] $BACKUP$_pastBuffer()
           
 void $COMMIT(long timestamp)
          Commit changes up to the given timestamp, but not including changes made at timestamp and afterward.
 Checkpoint $GET$CHECKPOINT()
          Get the checkpoint object that monitors this rollbackable object.
 void $RESTORE(long timestamp, boolean trim)
          Restore a previous state to all the private fields of this rollbackable object.
 java.lang.Object $SET$CHECKPOINT(Checkpoint checkpoint)
          Set the checkpoint object of this rollbackable object.
 void attributeChanged(Attribute attribute)
          Check the validity of parameter values and using the new values, recompute the size of the internal buffers.
 void fire()
          Consume the specified number of input tokens, and produce the specified number of output tokens.
 void initialize()
          Override the base class to ensure that the past buffer gets initialized.
 
Methods inherited from class ptolemy.domains.sdf.lib.SDFTransformer
prefire
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

$CHECKPOINT

protected transient Checkpoint $CHECKPOINT

numberToRead

public Parameter numberToRead
The number of input tokens to read. This is an integer, with default 128.


numberToWrite

public Parameter numberToWrite
The number of tokens to write to the output. This is an integer, with default 64.


offset

public Parameter offset
Start of output block relative to start of input block. This is an integer, with default 0.


usePastInputs

public Parameter usePastInputs
If offset is greater than 0, specify whether to use previously read inputs (otherwise use zeros). This is a boolean, with default true.


_highLimit

private int _highLimit

_inputIndex

private int _inputIndex

_lowLimit

private int _lowLimit

_numberToRead

private int _numberToRead

_numberToWrite

private int _numberToWrite

_offsetValue

private int _offsetValue

_buffer

private Token[] _buffer

_pastBuffer

private Token[] _pastBuffer

_usePast

private boolean _usePast

_pastNeedsInitializing

private boolean _pastNeedsInitializing

$RECORD$$CHECKPOINT

protected transient CheckpointRecord $RECORD$$CHECKPOINT

$RECORD$_highLimit

private transient FieldRecord $RECORD$_highLimit

$RECORD$_inputIndex

private transient FieldRecord $RECORD$_inputIndex

$RECORD$_lowLimit

private transient FieldRecord $RECORD$_lowLimit

$RECORD$_numberToRead

private transient FieldRecord $RECORD$_numberToRead

$RECORD$_numberToWrite

private transient FieldRecord $RECORD$_numberToWrite

$RECORD$_offsetValue

private transient FieldRecord $RECORD$_offsetValue

$RECORD$_buffer

private transient FieldRecord $RECORD$_buffer

$RECORD$_pastBuffer

private transient FieldRecord $RECORD$_pastBuffer

$RECORD$_usePast

private transient FieldRecord $RECORD$_usePast

$RECORD$_pastNeedsInitializing

private transient FieldRecord $RECORD$_pastNeedsInitializing

$RECORDS

private transient FieldRecord[] $RECORDS
Constructor Detail

Chop

public Chop(CompositeEntity container,
            java.lang.String name)
     throws IllegalActionException,
            NameDuplicationException
Construct an actor in the specified container with the specified name.

Parameters:
container - The container.
name - The name.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the name coincides with an actor already in the container.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
Check the validity of parameter values and using the new values, recompute the size of the internal buffers.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that has changed.
Throws:
IllegalActionException - If the parameters are out of range.

fire

public void fire()
          throws IllegalActionException
Consume the specified number of input tokens, and produce the specified number of output tokens.

Specified by:
fire in interface Executable
Overrides:
fire in class AtomicActor
Throws:
IllegalActionException - If there is no director.

initialize

public void initialize()
                throws IllegalActionException
Override the base class to ensure that the past buffer gets initialized.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If the superclass throws it.

$ASSIGN$_highLimit

private final int $ASSIGN$_highLimit(int newValue)

$ASSIGN$_inputIndex

private final int $ASSIGN$_inputIndex(int newValue)

$ASSIGN$_lowLimit

private final int $ASSIGN$_lowLimit(int newValue)

$ASSIGN$_numberToRead

private final int $ASSIGN$_numberToRead(int newValue)

$ASSIGN$_numberToWrite

private final int $ASSIGN$_numberToWrite(int newValue)

$ASSIGN$_offsetValue

private final int $ASSIGN$_offsetValue(int newValue)

$ASSIGN$_buffer

private final Token[] $ASSIGN$_buffer(Token[] newValue)

$ASSIGN$_buffer

private final Token $ASSIGN$_buffer(int index0,
                                    Token newValue)

$BACKUP$_buffer

private final Token[] $BACKUP$_buffer()

$ASSIGN$_pastBuffer

private final Token[] $ASSIGN$_pastBuffer(Token[] newValue)

$ASSIGN$_pastBuffer

private final Token $ASSIGN$_pastBuffer(int index0,
                                        Token newValue)

$BACKUP$_pastBuffer

private final Token[] $BACKUP$_pastBuffer()

$ASSIGN$_usePast

private final boolean $ASSIGN$_usePast(boolean newValue)

$ASSIGN$_pastNeedsInitializing

private final boolean $ASSIGN$_pastNeedsInitializing(boolean newValue)

$COMMIT

public void $COMMIT(long timestamp)
Description copied from interface: Rollbackable
Commit changes up to the given timestamp, but not including changes made at timestamp and afterward.

Specified by:
$COMMIT in interface Rollbackable
Parameters:
timestamp - The timestamp.

$RESTORE

public void $RESTORE(long timestamp,
                     boolean trim)
Description copied from interface: Rollbackable
Restore a previous state to all the private fields of this rollbackable object.

Specified by:
$RESTORE in interface Rollbackable
Parameters:
timestamp - The timestamp taken at the time when the previous state was recorded.
trim - Whether to delete the records used for the rollback.
See Also:
Checkpoint.rollback(long, boolean)

$GET$CHECKPOINT

public final Checkpoint $GET$CHECKPOINT()
Description copied from interface: Rollbackable
Get the checkpoint object that monitors this rollbackable object.

Specified by:
$GET$CHECKPOINT in interface Rollbackable
Returns:
The checkpoint object.

$SET$CHECKPOINT

public final java.lang.Object $SET$CHECKPOINT(Checkpoint checkpoint)
Description copied from interface: Rollbackable
Set the checkpoint object of this rollbackable object. A merge operation is performed on the current checkpoint object and the new checkpoint object, so that the two checkpoint objects monitor the same set of objects when this function returns.

Specified by:
$SET$CHECKPOINT in interface Rollbackable
Parameters:
checkpoint - The new checkpoint object.
Returns:
This rollbackable object itself.
See Also:
Checkpoint.setCheckpoint(Checkpoint)