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 interface
CompositeDoubleArrayOperation.ImplementationChooser
Specify which implementation to use.
-
Constructor Summary
Constructors Constructor Description CompositeDoubleArrayOperation(int arrayLengthThreshold, DoubleArrayOperation impl1, DoubleArrayOperation impl2)
Construct aCompositeDoubleArrayOperation
that chooses an implementation by array length.CompositeDoubleArrayOperation(CompositeDoubleArrayOperation.ImplementationChooser chooser)
Construct aCompositeDoubleArrayOperation
by supplying the multiplexing criterion and the multipleDoubleArrayOperation
s.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double[]
add(double[] arr1, double[] arr2)
Add twodouble
arrays, entry-by-entry.double[]
divide(double[] arr1, double[] arr2)
Divide onedouble
array by another, entry-by-entry.double[]
minus(double[] arr1, double[] arr2)
Subtract onedouble
array from another, entry-by-entry.double[]
multiply(double[] arr1, double[] arr2)
Multiply onedouble
array to another, entry-by-entry.double[]
scaled(double[] arr, double c)
Scale each entry of adouble
array.
-
-
-
Constructor Detail
-
CompositeDoubleArrayOperation
public CompositeDoubleArrayOperation(CompositeDoubleArrayOperation.ImplementationChooser chooser)
Construct aCompositeDoubleArrayOperation
by supplying the multiplexing criterion and the multipleDoubleArrayOperation
s.- Parameters:
chooser
- anCompositeDoubleArrayOperation.ImplementationChooser
-
CompositeDoubleArrayOperation
public CompositeDoubleArrayOperation(int arrayLengthThreshold, DoubleArrayOperation impl1, DoubleArrayOperation impl2)
Construct aCompositeDoubleArrayOperation
that 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:DoubleArrayOperation
Add twodouble
arrays, entry-by-entry.- Specified by:
add
in 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:DoubleArrayOperation
Subtract onedouble
array from another, entry-by-entry.- Specified by:
minus
in 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:DoubleArrayOperation
Multiply onedouble
array to another, entry-by-entry.- Specified by:
multiply
in 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:DoubleArrayOperation
Divide onedouble
array by another, entry-by-entry.- Specified by:
divide
in interfaceDoubleArrayOperation
- Parameters:
arr1
- an arraydouble[]
arr2
- an arraydouble[]
- Returns:
- the quotient array
-
scaled
public double[] scaled(double[] arr, double c)
Description copied from interface:DoubleArrayOperation
Scale each entry of adouble
array.- Specified by:
scaled
in interfaceDoubleArrayOperation
- Parameters:
arr
- an arraydouble[]
c
- a scaling constant- Returns:
- the scaled array
-
-