Class AbstractConvolution
- All Implemented Interfaces:
Cloneable
,ArrayProcessor
,ArrayProcessorWithContextSwitching
,Convolution
- Direct Known Subclasses:
BasicConvolution
-
Field Summary
Modifier and TypeFieldDescriptionprotected final boolean
protected final boolean
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractConvolution
(ArrayContext context, boolean incrementForUnsigned, boolean incrementByHalfForInteger) Creates an instance of this class with the given context. -
Method Summary
Modifier and TypeMethodDescriptionasConvolution
(Class<? extends T> requiredType, Matrix<? extends PArray> src, WeightedPattern pattern) 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.asConvolution
(Matrix<? extends PArray> src, WeightedPattern pattern) Equivalent toasConvolution
(src.type
(PArray.class), src, pattern).context
(ArrayContext newContext) This method is implemented here via cloning this object (by standard clone() call) and replacing the value of the field, where a reference to the current context is stored, with newContext value.convolution
(Class<? extends T> requiredType, Matrix<? extends PArray> src, WeightedPattern pattern) Matrix<? extends UpdatablePArray>
convolution
(Matrix<? extends PArray> src, WeightedPattern pattern) This implementation just creates a lazy convolution viaasConvolution(Class, Matrix, WeightedPattern)
method and copies it into a newly created matrix viaMatrices.copy(ArrayContext, Matrix, Matrix)
method.void
convolution
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, WeightedPattern pattern) double
abstract boolean
Returns true, if this class works in the defaultpseudo-cyclic continuation mode
.Methods inherited from class net.algart.arrays.AbstractArrayProcessorWithContextSwitching
context, contextPart, memoryModel
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.algart.arrays.ArrayProcessor
context
-
Field Details
-
incrementForUnsigned
protected final boolean incrementForUnsigned -
incrementByHalfForInteger
protected final boolean incrementByHalfForInteger
-
-
Constructor Details
-
AbstractConvolution
protected AbstractConvolution(ArrayContext context, boolean incrementForUnsigned, boolean incrementByHalfForInteger) Creates an instance of this class with the given context.- Parameters:
context
- the context used by this instance for all operations.incrementForUnsigned
- if true, when 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).incrementByHalfForInteger
- if true, when the type of the convolution result is integer, the precise result is automatically increments by 0.5 before casting.
-
-
Method Details
-
context
Description copied from class:AbstractArrayProcessorWithContextSwitching
This method is implemented here via cloning this object (by standard clone() call) and replacing the value of the field, where a reference to the current context is stored, with newContext value. This technique is suitable for most implementation. However, if you need, you can override this method; maybe, it is enough to override clone() instead.
- Specified by:
context
in interfaceArrayProcessorWithContextSwitching
- Specified by:
context
in interfaceConvolution
- Overrides:
context
in classAbstractArrayProcessorWithContextSwitching
- Parameters:
newContext
- another context, used by the returned instance; may be null.- Returns:
- new instance with another context.
-
isPseudoCyclic
public abstract boolean isPseudoCyclic()Description copied from interface:Convolution
Returns true, if this class works in the defaultpseudo-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 theConvolution.convolution(Matrix, WeightedPattern)
method as the default definition of convolution.This method returns true in
BasicConvolution
implementation. However, it usually returns false inContinuedConvolution
class — excepting the only degenerated case when the usedcontinuation mode
isPSEUDO_CYCLIC
.- Specified by:
isPseudoCyclic
in interfaceConvolution
- Returns:
- whether this class works in the pseudo-cyclic continuation mode.
-
increment
- Specified by:
increment
in interfaceConvolution
-
asConvolution
public Matrix<? extends PArray> asConvolution(Matrix<? extends PArray> src, WeightedPattern pattern) Description copied from interface:Convolution
Equivalent toasConvolution
(src.type
(PArray.class), src, pattern). In other words, the element type of the returned matrix is chosen the same as in src matrix.- Specified by:
asConvolution
in interfaceConvolution
- Parameters:
src
- the source matrix.pattern
- the pattern.- Returns:
- the "lazy" matrix containing the convolution of the source matrix with the given pattern.
-
asConvolution
public abstract <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. SeeConvolution.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
orDoubleArray
. 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 inArrays.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 interfaceConvolution
- 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.
-
convolution
public Matrix<? extends UpdatablePArray> convolution(Matrix<? extends PArray> src, WeightedPattern pattern) This implementation just creates a lazy convolution viaasConvolution(Class, Matrix, WeightedPattern)
method and copies it into a newly created matrix viaMatrices.copy(ArrayContext, Matrix, Matrix)
method. This method should be usually overridden to provide better implementations.- Specified by:
convolution
in interfaceConvolution
- Parameters:
src
- the source matrix.pattern
- the pattern.- Returns:
- the result of convolution of the source matrix with the given pattern.
- Throws:
NullPointerException
- if one of the arguments is null.- See Also:
-
convolution
public <T extends PArray> Matrix<? extends T> convolution(Class<? extends T> requiredType, Matrix<? extends PArray> src, WeightedPattern pattern) - Specified by:
convolution
in interfaceConvolution
-
convolution
public void convolution(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, WeightedPattern pattern) - Specified by:
convolution
in interfaceConvolution
-