Package dev.nm.number.doublearray
Class CompositeDoubleArrayOperation
- java.lang.Object
-
- dev.nm.number.doublearray.CompositeDoubleArrayOperation
-
- All Implemented Interfaces:
DoubleArrayOperation
public class CompositeDoubleArrayOperation extends Object implements DoubleArrayOperation
It is desirable to have multiple implementations and switch between them for, e.g., performance reason.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCompositeDoubleArrayOperation.ImplementationChooserSpecify which implementation to use.
-
Constructor Summary
Constructors Constructor Description CompositeDoubleArrayOperation(int arrayLengthThreshold, DoubleArrayOperation impl1, DoubleArrayOperation impl2)Construct aCompositeDoubleArrayOperationthat chooses an implementation by array length.CompositeDoubleArrayOperation(CompositeDoubleArrayOperation.ImplementationChooser chooser)Construct aCompositeDoubleArrayOperationby supplying the multiplexing criterion and the multipleDoubleArrayOperations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double[]add(double[] arr1, double[] arr2)Add twodoublearrays, entry-by-entry.double[]divide(double[] arr1, double[] arr2)Divide onedoublearray by another, entry-by-entry.double[]minus(double[] arr1, double[] arr2)Subtract onedoublearray from another, entry-by-entry.double[]multiply(double[] arr1, double[] arr2)Multiply onedoublearray to another, entry-by-entry.double[]scaled(double[] arr, double c)Scale each entry of adoublearray.
-
-
-
Constructor Detail
-
CompositeDoubleArrayOperation
public CompositeDoubleArrayOperation(CompositeDoubleArrayOperation.ImplementationChooser chooser)
Construct aCompositeDoubleArrayOperationby supplying the multiplexing criterion and the multipleDoubleArrayOperations.- Parameters:
chooser- anCompositeDoubleArrayOperation.ImplementationChooser
-
CompositeDoubleArrayOperation
public CompositeDoubleArrayOperation(int arrayLengthThreshold, DoubleArrayOperation impl1, DoubleArrayOperation impl2)Construct aCompositeDoubleArrayOperationthat chooses an implementation by array length.- Parameters:
arrayLengthThreshold- the array length threshold to switch implementationimpl1- implementation 1impl2- implementation 2
-
-
Method Detail
-
add
public double[] add(double[] arr1, double[] arr2)Description copied from interface:DoubleArrayOperationAdd twodoublearrays, entry-by-entry.- Specified by:
addin interfaceDoubleArrayOperation- Parameters:
arr1- an arraydouble[]arr2- an arraydouble[]- Returns:
- the sum of the two arrays
-
minus
public double[] minus(double[] arr1, double[] arr2)Description copied from interface:DoubleArrayOperationSubtract onedoublearray from another, entry-by-entry.- Specified by:
minusin interfaceDoubleArrayOperation- Parameters:
arr1- an arraydouble[]arr2- an arraydouble[]- Returns:
- the difference of the two arrays
-
multiply
public double[] multiply(double[] arr1, double[] arr2)Description copied from interface:DoubleArrayOperationMultiply onedoublearray to another, entry-by-entry.- Specified by:
multiplyin interfaceDoubleArrayOperation- Parameters:
arr1- an arraydouble[]arr2- an arraydouble[]- Returns:
- the product of the two arrays
-
divide
public double[] divide(double[] arr1, double[] arr2)Description copied from interface:DoubleArrayOperationDivide onedoublearray by another, entry-by-entry.- Specified by:
dividein interfaceDoubleArrayOperation- Parameters:
arr1- an arraydouble[]arr2- an arraydouble[]- Returns:
- the quotient array
-
scaled
public double[] scaled(double[] arr, double c)Description copied from interface:DoubleArrayOperationScale each entry of adoublearray.- Specified by:
scaledin interfaceDoubleArrayOperation- Parameters:
arr- an arraydouble[]c- a scaling constant- Returns:
- the scaled array
-
-