Class BasicConvolution

All Implemented Interfaces:
Cloneable, ArrayProcessor, ArrayProcessorWithContextSwitching, Convolution

public class BasicConvolution extends AbstractConvolution implements Convolution
  • Method Details

    • getInstance

      public static BasicConvolution getInstance(ArrayContext context, boolean incrementByHalfForInteger)
      Returns new instance of this class.
      Parameters:
      context - the context that will be used by this object; may be null, then it will be ignored.
      incrementByHalfForInteger - if true, when the type of the convolution result is integer, the precise result is automatically increments by 0.5 before casting.
      Returns:
      new instance of this class.
    • getCorrectingUnsignedInstance

      public static BasicConvolution getCorrectingUnsignedInstance(ArrayContext context)
      Returns new instance of this class, correcting unsigned convolutions results. If the type of the convolution result is an unsigned number in terms of AlgART libraries — byte, short, char — it is automatically incremented by 128 (byte) or 32768 (short and char).
      Parameters:
      context - the context that will be used by this object; may be null, then it will be ignored.
      Returns:
      new instance of this class.
    • isPseudoCyclic

      public boolean isPseudoCyclic()
      Description copied from interface: Convolution
      Returns true, if this class works in the default pseudo-cyclic continuation mode.

      More precisely, it means that when the value in some element of the processed matrix, returned by a method of this class, depends on elements of the source matrix, lying outside its bounds, then it is supposed that the values outside the source matrix are calculated as described in Matrix.ContinuationMode.PSEUDO_CYCLIC. Exactly such behaviour is specified in the comments to the Convolution.convolution(Matrix, WeightedPattern) method as the default definition of convolution.

      This method returns true in BasicConvolution implementation. However, it usually returns false in ContinuedConvolution class — excepting the only degenerated case when the used continuation mode is PSEUDO_CYCLIC.

      Specified by:
      isPseudoCyclic in interface Convolution
      Specified by:
      isPseudoCyclic in class AbstractConvolution
      Returns:
      whether this class works in the pseudo-cyclic continuation mode.
    • asConvolution

      public <T extends PArray> Matrix<T> asConvolution(Class<? extends T> requiredType, Matrix<? extends PArray> src, WeightedPattern pattern)
      Description copied from interface: Convolution
      Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the convolution of the source matrix by the specified pattern. See Convolution.convolution(Class, Matrix, WeightedPattern) method about the "convolution" term.

      The matrix, returned by this method, is immutable, and the class of its built-in array implements one of the basic interfaces BitArray, CharArray, ByteArray, ShortArray, IntArray, LongArray, FloatArray or DoubleArray. The class of desired interface (one of 8 possible classes) must be passed as requiredType argument. So, it defines the element type of the returned matrix. For example, if requiredType=ByteArray.class, the returned matrix consists of byte elements. The rules of casting the real numbers, results of the convolution, to the desired element type are the same as in Arrays.asFuncArray(boolean, net.algart.math.functions.Func, Class, PArray...) method with the argument truncateOverflows=true.

      The result is usually "lazy", that means that this method finishes immediately and all actual calculations are performed while getting elements of the returned matrix. It is true for all implementations provided by this package. However, some implementations may not support lazy dilation; then this method will be equivalent to Convolution.convolution(Class, Matrix, WeightedPattern).

      Please note: this method does not require time, but the resulting matrix can work slowly! for example, reading all its content than work much slower than Convolution.convolution(Class, Matrix, WeightedPattern) method for some complex patterns. Usually you should use it only for very little patterns, or if you know that the implementation of this interface does not provide better algorithm for non-"lazy" Convolution.convolution(Class, Matrix, WeightedPattern) method.

      Specified by:
      asConvolution in interface Convolution
      Specified by:
      asConvolution in class AbstractConvolution
      Parameters:
      requiredType - desired type of the built-in array in the returned matrix.
      src - the source matrix.
      pattern - the pattern.
      Returns:
      the "lazy" matrix containing the convolution of the source matrix with the given pattern.