ptolemy.domains.sdf.lib
Class Chop

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

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: Chop.java,v 1.26 2004/04/13 05:12:26 cxh Exp $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Yellow (neuendor)
Proposed Rating:
Green (eal)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
 ptolemy.data.expr.Parameter numberToRead
          The number of input tokens to read.
 ptolemy.data.expr.Parameter numberToWrite
          The number of tokens to write to the output.
 ptolemy.data.expr.Parameter offset
          Start of output block relative to start of input block.
 ptolemy.data.expr.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
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
Chop(ptolemy.kernel.CompositeEntity container, java.lang.String name)
          Construct an actor in the specified container with the specified name.
 
Method Summary
 void attributeChanged(ptolemy.kernel.util.Attribute attribute)
          Check the validity of parameter values, set production and consumption rates on the ports, and, if necessary, invalidate the current schedule.
 void fire()
          Consume the specified number of input tokens, and produce the specified number of output tokens.
 
Methods inherited from class ptolemy.domains.sdf.lib.SDFTransformer
prefire
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, initialize, inputPortList, iterate, newReceiver, outputPortList, postfire, preinitialize, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
initialize, iterate, postfire, preinitialize, stop, stopFire, terminate, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

numberToRead

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


numberToWrite

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


offset

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


usePastInputs

public ptolemy.data.expr.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.

Constructor Detail

Chop

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

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

attributeChanged

public void attributeChanged(ptolemy.kernel.util.Attribute attribute)
                      throws ptolemy.kernel.util.IllegalActionException
Check the validity of parameter values, set production and consumption rates on the ports, and, if necessary, invalidate the current schedule.

Parameters:
attribute - The attribute that has changed.
Throws:
ptolemy.kernel.util.IllegalActionException - If the parameters are out of range.

fire

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

Throws:
ptolemy.kernel.util.IllegalActionException - If there is no director.