Skip to content

Commit

Permalink
Refactoring (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
apete authored Nov 14, 2019
1 parent 246a450 commit 85f9013
Show file tree
Hide file tree
Showing 30 changed files with 937 additions and 739 deletions.
297 changes: 19 additions & 278 deletions src/org/ojalgo/array/Primitive32Array.java

Large diffs are not rendered by default.

297 changes: 19 additions & 278 deletions src/org/ojalgo/array/Primitive64Array.java

Large diffs are not rendered by default.

109 changes: 20 additions & 89 deletions src/org/ojalgo/array/ReferenceTypeArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@
import java.util.Spliterators;

import org.ojalgo.array.operation.COPY;
import org.ojalgo.array.operation.Exchange;
import org.ojalgo.array.operation.FillAll;
import org.ojalgo.array.operation.OperationBinary;
import org.ojalgo.array.operation.OperationParameter;
import org.ojalgo.array.operation.OperationUnary;
import org.ojalgo.array.operation.OperationVoid;
import org.ojalgo.function.BinaryFunction;
import org.ojalgo.function.NullaryFunction;
import org.ojalgo.function.ParameterFunction;
import org.ojalgo.function.UnaryFunction;
import org.ojalgo.function.VoidFunction;
import org.ojalgo.function.constant.PrimitiveMath;
import org.ojalgo.function.special.MissingMath;
import org.ojalgo.scalar.Scalar;
import org.ojalgo.structure.Access1D;
import org.ojalgo.structure.Mutate1D;

Expand All @@ -44,78 +49,6 @@
*/
public abstract class ReferenceTypeArray<N extends Comparable<N>> extends PlainArray<N> implements Mutate1D.Sortable {

protected static <N extends Comparable<N>> void exchange(final N[] data, final int firstA, final int firstB, final int step, final int aCount) {

int tmpIndexA = firstA;
int tmpIndexB = firstB;

N tmpVal;

for (int i = 0; i < aCount; i++) {

tmpVal = data[tmpIndexA];
data[tmpIndexA] = data[tmpIndexB];
data[tmpIndexB] = tmpVal;

tmpIndexA += step;
tmpIndexB += step;
}
}

protected static <N extends Comparable<N>> void fill(final N[] data, final int first, final int limit, final int step, final N value) {
for (int i = first; i < limit; i += step) {
data[i] = value;
}
}

protected static <N extends Comparable<N>> void fill(final N[] data, final int first, final int limit, final int step, final NullaryFunction<?> supplier,
Scalar.Factory<N> scalar) {
for (int i = first; i < limit; i += step) {
data[i] = scalar.cast(supplier.invoke());
}
}

protected static <N extends Comparable<N>> void invoke(final N[] data, final int first, final int limit, final int step, final Access1D<N> left,
final BinaryFunction<N> function, final Access1D<N> right) {
for (int i = first; i < limit; i += step) {
data[i] = function.invoke(left.get(i), right.get(i));
}
}

protected static <N extends Comparable<N>> void invoke(final N[] data, final int first, final int limit, final int step, final Access1D<N> left,
final BinaryFunction<N> function, final N right) {
for (int i = first; i < limit; i += step) {
data[i] = function.invoke(left.get(i), right);
}
}

protected static <N extends Comparable<N>> void invoke(final N[] data, final int first, final int limit, final int step, final Access1D<N> value,
final ParameterFunction<N> function, final int aParam) {
for (int i = first; i < limit; i += step) {
data[i] = function.invoke(value.get(i), aParam);
}
}

protected static <N extends Comparable<N>> void invoke(final N[] data, final int first, final int limit, final int step, final Access1D<N> value,
final UnaryFunction<N> function) {
for (int i = first; i < limit; i += step) {
data[i] = function.invoke(value.get(i));
}
}

protected static <N extends Comparable<N>> void invoke(final N[] data, final int first, final int limit, final int step, final N left,
final BinaryFunction<N> function, final Access1D<N> right) {
for (int i = first; i < limit; i += step) {
data[i] = function.invoke(left, right.get(i));
}
}

protected static <N extends Comparable<N>> void invoke(final N[] data, final int first, final int limit, final int step, final VoidFunction<N> aVisitor) {
for (int i = first; i < limit; i += step) {
aVisitor.invoke(data[i]);
}
}

public final N[] data;

ReferenceTypeArray(final DenseArray.Factory<N> factory, final int length) {
Expand Down Expand Up @@ -145,9 +78,7 @@ public boolean equals(final Object anObj) {

@Override
public void fillMatching(final Access1D<?> values) {
for (int i = 0, limit = (int) Math.min(this.count(), values.count()); i < limit; i++) {
data[i] = this.factory().scalar().cast(values.get(i));
}
FillAll.fill(data, values, this.factory().scalar());
}

@Override
Expand Down Expand Up @@ -191,32 +122,32 @@ protected final N[] copyOfData() {

@Override
protected final void exchange(final int firstA, final int firstB, final int step, final int count) {
ReferenceTypeArray.exchange(data, firstA, firstB, step, count);
Exchange.exchange(data, firstA, firstB, step, count);
}

@Override
protected final void fill(final int first, final int limit, final Access1D<N> left, final BinaryFunction<N> function, final Access1D<N> right) {
ReferenceTypeArray.invoke(data, first, limit, 1, left, function, right);
OperationBinary.invoke(data, first, limit, 1, left, function, right);
}

@Override
protected final void fill(final int first, final int limit, final Access1D<N> left, final BinaryFunction<N> function, final N right) {
ReferenceTypeArray.invoke(data, first, limit, 1, left, function, right);
OperationBinary.invoke(data, first, limit, 1, left, function, right);
}

@Override
protected final void fill(final int first, final int limit, final int step, final N value) {
ReferenceTypeArray.fill(data, first, limit, step, value);
FillAll.fill(data, first, limit, step, value);
}

@Override
protected final void fill(final int first, final int limit, final int step, final NullaryFunction<?> supplier) {
ReferenceTypeArray.fill(data, first, limit, step, supplier, this.factory().scalar());
FillAll.fill(data, first, limit, step, supplier, this.factory().scalar());
}

@Override
protected final void fill(final int first, final int limit, final N left, final BinaryFunction<N> function, final Access1D<N> right) {
ReferenceTypeArray.invoke(data, first, limit, 1, left, function, right);
OperationBinary.invoke(data, first, limit, 1, left, function, right);
}

@Override
Expand All @@ -237,32 +168,32 @@ protected final N get(final int index) {

@Override
protected final void modify(final int first, final int limit, final int step, final Access1D<N> left, final BinaryFunction<N> function) {
ReferenceTypeArray.invoke(data, first, limit, step, left, function, this);
OperationBinary.invoke(data, first, limit, step, left, function, this);
}

@Override
protected final void modify(final int first, final int limit, final int step, final BinaryFunction<N> function, final Access1D<N> right) {
ReferenceTypeArray.invoke(data, first, limit, step, this, function, right);
OperationBinary.invoke(data, first, limit, step, this, function, right);
}

@Override
protected final void modify(final int first, final int limit, final int step, final BinaryFunction<N> function, final N right) {
ReferenceTypeArray.invoke(data, first, limit, step, this, function, right);
OperationBinary.invoke(data, first, limit, step, this, function, right);
}

@Override
protected final void modify(final int first, final int limit, final int step, final N left, final BinaryFunction<N> function) {
ReferenceTypeArray.invoke(data, first, limit, step, left, function, this);
OperationBinary.invoke(data, first, limit, step, left, function, this);
}

@Override
protected final void modify(final int first, final int limit, final int step, final ParameterFunction<N> function, final int parameter) {
ReferenceTypeArray.invoke(data, first, limit, step, this, function, parameter);
OperationParameter.invoke(data, first, limit, step, data, function, parameter);
}

@Override
protected final void modify(final int first, final int limit, final int step, final UnaryFunction<N> function) {
ReferenceTypeArray.invoke(data, first, limit, step, this, function);
OperationUnary.invoke(data, first, limit, step, this, function);
}

@Override
Expand Down Expand Up @@ -292,7 +223,7 @@ protected final void set(final int index, final Comparable<?> value) {

@Override
protected final void visit(final int first, final int limit, final int step, final VoidFunction<N> visitor) {
ReferenceTypeArray.invoke(data, first, limit, step, visitor);
OperationVoid.invoke(data, first, limit, step, visitor);
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/org/ojalgo/array/operation/ArrayOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static void setThresholdsMaxValue(final int value) {
ApplyLU.THRESHOLD = Math.min(value, ApplyLU.THRESHOLD);
ASUM.THRESHOLD = Math.min(value, ASUM.THRESHOLD);
AXPY.THRESHOLD = Math.min(value, AXPY.THRESHOLD);
CorePrimitiveOperation.THRESHOLD = Math.min(value, CorePrimitiveOperation.THRESHOLD);
CABS1.THRESHOLD = Math.min(value, CABS1.THRESHOLD);
COPY.THRESHOLD = Math.min(value, COPY.THRESHOLD);
DOT.THRESHOLD = Math.min(value, DOT.THRESHOLD);
Expand All @@ -73,6 +74,10 @@ static void setThresholdsMaxValue(final int value) {
MultiplyNeither.THRESHOLD = Math.min(value, MultiplyNeither.THRESHOLD);
MultiplyRight.THRESHOLD = Math.min(value, MultiplyRight.THRESHOLD);
NRM2.THRESHOLD = Math.min(value, NRM2.THRESHOLD);
OperationBinary.THRESHOLD = Math.min(value, OperationBinary.THRESHOLD);
OperationParameter.THRESHOLD = Math.min(value, OperationParameter.THRESHOLD);
OperationUnary.THRESHOLD = Math.min(value, OperationUnary.THRESHOLD);
OperationVoid.THRESHOLD = Math.min(value, OperationVoid.THRESHOLD);
ROT.THRESHOLD = Math.min(value, ROT.THRESHOLD);
RotateLeft.THRESHOLD = Math.min(value, RotateLeft.THRESHOLD);
RotateRight.THRESHOLD = Math.min(value, RotateRight.THRESHOLD);
Expand Down Expand Up @@ -103,6 +108,7 @@ static void setThresholdsMinValue(final int value) {
ApplyLU.THRESHOLD = Math.max(value, ApplyLU.THRESHOLD);
ASUM.THRESHOLD = Math.max(value, ASUM.THRESHOLD);
AXPY.THRESHOLD = Math.max(value, AXPY.THRESHOLD);
CorePrimitiveOperation.THRESHOLD = Math.max(value, CorePrimitiveOperation.THRESHOLD);
CABS1.THRESHOLD = Math.max(value, CABS1.THRESHOLD);
COPY.THRESHOLD = Math.max(value, COPY.THRESHOLD);
DOT.THRESHOLD = Math.max(value, DOT.THRESHOLD);
Expand All @@ -125,6 +131,10 @@ static void setThresholdsMinValue(final int value) {
MultiplyNeither.THRESHOLD = Math.max(value, MultiplyNeither.THRESHOLD);
MultiplyRight.THRESHOLD = Math.max(value, MultiplyRight.THRESHOLD);
NRM2.THRESHOLD = Math.max(value, NRM2.THRESHOLD);
OperationBinary.THRESHOLD = Math.max(value, OperationBinary.THRESHOLD);
OperationParameter.THRESHOLD = Math.max(value, OperationParameter.THRESHOLD);
OperationUnary.THRESHOLD = Math.max(value, OperationUnary.THRESHOLD);
OperationVoid.THRESHOLD = Math.max(value, OperationVoid.THRESHOLD);
ROT.THRESHOLD = Math.max(value, ROT.THRESHOLD);
RotateLeft.THRESHOLD = Math.max(value, RotateLeft.THRESHOLD);
RotateRight.THRESHOLD = Math.max(value, RotateRight.THRESHOLD);
Expand Down
Loading

0 comments on commit 85f9013

Please sign in to comment.