public abstract class Quantization
extends java.lang.Object
implements java.lang.Cloneable
It comprises a
This abstract class is designed to support specification of required numeric behavior through use of the yet-to-be-written FloatingQuantization and FixedQuantization classes. Knowledge of the required numeric behavior, rather than precise specification of an exact implementation, provides an opportunity for code generation to select appropriate types supported by a target architecture.
FixedQuantization provides for modulo equi-spaced values between the inclusive maximum and minimum limits. epsilon, the separation between values is given by (maximum - minimum) / (modulo - 1). Whether values beyond the maximum and minimum wrap-around is determined by the overflow strategy. FixedQuantization therefore describes the requirements of a single fixed point range comprising just a mantissa.
FloatingQuantization adds an exponent to support multiple floating point ranges; maximum defines the upper limit of the coarsest scale and tiny defines the smallest representable non-zero number on the finest scale. (tiny is the same as epsilon for FixedQuantization.)
If exactRounding is specified, code generation must ensure that arithmetic rounds to the specified epsilon. Otherwise, the code generator may use arithmetic with higher precision.
If exactOverflow is specified, code generation must ensure that arithmetic overflows saturate or wrap-around at the specified maximum and minimum. Otherwise, the code generator may use arithmetic with greater range.
The active class functionality is provided by the quantize method, which is normally invoked from FixPoint.quantize or ScalarToken.quantize to enforce quantization constraints upon the result of an unconstrained computation.
An instance of the class is immutable, meaning that its value is set in the constructor and cannot then be modified.
FixPoint
,
FixPointQuantization
,
Precision
,
Overflow
,
Rounding
Red |
Red (Ed.Willink) |
Modifier and Type | Field and Description |
---|---|
protected Overflow |
_overflow
The overflow strategy.
|
protected Rounding |
_rounding
The rounding strategy.
|
Constructor and Description |
---|
Quantization(Overflow overflow,
Rounding rounding)
Construct a Quantization with the given precision, overflow
strategy, and rounding strategy.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Return this, that is, return the reference to this object.
|
boolean |
equals(java.lang.Object object)
Return true if the indicated object describes the same
mapping to quantized values.
|
double |
getEpsilonValue()
Return the separation between quantized values.
|
boolean |
getExactOverflow()
Return the overflow bit-truth.
|
boolean |
getExactRounding()
Return the rounding bit-truth.
|
int |
getExponentBitLength()
Return the number of bits to represent the exponent.
|
int |
getFractionBitLength()
Return the number of bits representing the fractional part
of the mantissa.
|
int |
getIntegerBitLength()
Return the number of bits representing the integer part
of the mantissa.
|
int |
getMantissaBitLength()
Return the number of bits to represent the mantissa.
|
abstract Precision |
getMantissaPrecision()
Return the precision fore the mantissa of a compliant
2's complement representation.
|
java.math.BigInteger |
getMaximumUnscaledValue()
Return the maximum quantizable value after scaling so that
quantization levels are represented by adjacent integers.
|
double |
getMaximumValue()
Return the maximum quantizable value.
|
java.math.BigInteger |
getMinimumUnscaledValue()
Return the minimum quantizable value after scaling so that
quantization levels are represented by adjacent integers.
|
double |
getMinimumValue()
Return the minimum quantizable value.
|
java.math.BigInteger |
getModuloUnscaledValue()
Deprecated.
?
|
int |
getNumberOfBits()
Return the number of bits to represent the value.
|
double |
getNumberOfLevels()
Return the number of quantization levels in the mantissa.
|
Overflow |
getOverflow()
Return the overflow strategy.
|
abstract Precision |
getPrecision()
Return the Precision.
|
Rounding |
getRounding()
Return the rounding strategy.
|
double |
getTinyValue()
Return the quantizable value nearest to and above zero.
|
int |
hashCode()
Return a hash code value for this Quantization.
|
abstract java.lang.String |
toString()
Return a string representing this quantization.
|
protected Overflow _overflow
protected Rounding _rounding
public Quantization(Overflow overflow, Rounding rounding)
overflow
- The Overflow object to use by this Quantization
strategy.rounding
- The Rounding object to use by this Quantization
strategy.public java.lang.Object clone()
clone
in class java.lang.Object
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
object
- The Quantization object to use for equality
checking.public double getEpsilonValue()
public boolean getExactOverflow()
public boolean getExactRounding()
public int getExponentBitLength()
public int getFractionBitLength()
public int getIntegerBitLength()
public int getMantissaBitLength()
public abstract Precision getMantissaPrecision()
public java.math.BigInteger getMaximumUnscaledValue()
public double getMaximumValue()
public java.math.BigInteger getMinimumUnscaledValue()
public double getMinimumValue()
@Deprecated public java.math.BigInteger getModuloUnscaledValue()
public int getNumberOfBits()
public double getNumberOfLevels()
public Overflow getOverflow()
public abstract Precision getPrecision()
public Rounding getRounding()
public double getTinyValue()
public int hashCode()
hashCode
in class java.lang.Object
public abstract java.lang.String toString()
toString
in class java.lang.Object