Skip to content

Commit

Permalink
clustering and r/w
Browse files Browse the repository at this point in the history
  • Loading branch information
apete committed Dec 19, 2024
1 parent 2381c5a commit aa55f22
Show file tree
Hide file tree
Showing 59 changed files with 1,805 additions and 740 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,43 @@ Added / Changed / Deprecated / Fixed / Removed / Security

> Corresponds to changes in the `develop` branch since the last release
### Added

#### org.ojalgo.data

- New package `org.ojalgo.data.cluster` with k-means and greedy clustering algorithms implemented, as well as generalisations, specialisations and combinations of those.
- `DataProcessors` now has a method `Transformation2D newRowsTransformer(Function<SampleSet, UnaryFunction>)` to complement the existing `newColumnsTransformer`.

#### org.ojalgo.random

- `SampleSet` gained a couple of methods; `getMidrange()` and `getRange()`.

### Changed

#### org.ojalgo.array

- Sorting is no longer parallel/multi-threaded. The previous implementations made use of the common `ForkJoinPool`.

#### org.ojalgo.netio

- The `FromFileReader` and `ToFileWriter` interfaces and their implementations used to extend and delegate to code in the `org.ojalgo.type.function` package. Much of what was in that package has been moved to and merged with stuff in the `org.ojalgo.netio` package.
- The `FromFileReader.Builder` and `ToFileWriter.Builder` builders now use generic "file" types. They used to be implemented in terms of Java's `File`, but can now be anything like `Path` or ojAlgo's own `SegmentedFile`, `ShardedFile` or `InMemoryFile`.
- The `DataInterpreter` gained some additional standard interpreters, as well as utilities to convert back and forth between `byte[]`.

#### org.ojalgo.random

- `SamleSet` no longer makes use of parallel/multi-threaded sorting – to avoid making use of the common `ForkJoinPool`.

#### org.ojalgo.type

- The `AutoSupplier` and `AutoConsumer` interfaces are removed. They used to provide abstract/generalised functionality for `FromFileReader` and `ToFileWriter` in the `org.ojalgo.netio` package. All features and functionality still exists, but in terms of the more specific/concrete `FromFileReader` and `ToFileWriter`. If you directly referenced any of the various utility methods in `AutoSupplier` or `AutoConsumer` they're now gone. They primarily existed so that `FromFileReader` and `ToFileWriter` could access them (from another package). The features and functionality they provided are now available through other classes in the `org.ojalgo.netio` package – like `FromFileReader.Builder` and `ToFileWriter.Builder`.

### Fixed

#### org.ojalgo.data

- In `DataProcessors`, the `CENTER_AND_SCALE` transformation didn't do exactly what the documentation said it. That's been fixed.

## [55.0.2] – 2024-11-30

### Added
Expand Down
145 changes: 2 additions & 143 deletions src/main/java/org/ojalgo/array/Array1D.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
import java.math.BigDecimal;
import java.util.AbstractList;
import java.util.RandomAccess;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;

import org.ojalgo.ProgrammingError;
import org.ojalgo.function.BinaryFunction;
Expand Down Expand Up @@ -124,132 +121,6 @@ public Array1D<N> wrap(final BasicArray<N> array) {

}

static final class QuickAscendingSorter extends RecursiveAction {

private static final long serialVersionUID = 1L;

private final long high;
private final long low;
private final Array1D<?> myArray;

private QuickAscendingSorter(final Array1D<?> array, final long low, final long high) {
super();
myArray = array;
this.low = low;
this.high = high;
}

QuickAscendingSorter(final Array1D<?> array) {
this(array, 0L, array.count() - 1L);
}

@Override
protected void compute() {

long i = low, j = high;

double pivot = myArray.doubleValue(low + (high - low) / 2);

while (i <= j) {

while (myArray.doubleValue(i) < pivot) {
i++;
}
while (myArray.doubleValue(j) > pivot) {
j--;
}

if (i <= j) {
myArray.exchange(i, j);
i++;
j--;
}
}

QuickAscendingSorter tmpPartL = null;
QuickAscendingSorter tmpPartH = null;

if (low < j) {
tmpPartL = new QuickAscendingSorter(myArray, low, j);
tmpPartL.fork();
}
if (i < high) {
tmpPartH = new QuickAscendingSorter(myArray, i, high);
tmpPartH.fork();
}
if (tmpPartL != null) {
tmpPartL.join();
}
if (tmpPartH != null) {
tmpPartH.join();
}
}

}

static final class QuickDescendingSorter extends RecursiveAction {

private static final long serialVersionUID = 1L;

private final long high;
private final long low;
private final Array1D<?> myArray;

private QuickDescendingSorter(final Array1D<?> array, final long low, final long high) {
super();
myArray = array;
this.low = low;
this.high = high;
}

QuickDescendingSorter(final Array1D<?> array) {
this(array, 0L, array.count() - 1L);
}

@Override
protected void compute() {

long i = low, j = high;

double pivot = myArray.doubleValue(low + (high - low) / 2);

while (i <= j) {

while (myArray.doubleValue(i) > pivot) {
i++;
}
while (myArray.doubleValue(j) < pivot) {
j--;
}

if (i <= j) {
myArray.exchange(i, j);
i++;
j--;
}
}

QuickDescendingSorter tmpPartL = null;
QuickDescendingSorter tmpPartH = null;

if (low < j) {
tmpPartL = new QuickDescendingSorter(myArray, low, j);
tmpPartL.fork();
}
if (i < high) {
tmpPartH = new QuickDescendingSorter(myArray, i, high);
tmpPartH.fork();
}
if (tmpPartL != null) {
tmpPartL.join();
}
if (tmpPartH != null) {
tmpPartH.join();
}
}

}

public static final Factory<ComplexNumber> C128 = Array1D.factory(ArrayC128.FACTORY);
public static final Factory<Quaternion> H256 = Array1D.factory(ArrayH256.FACTORY);
public static final Factory<RationalNumber> Q128 = Array1D.factory(ArrayQ128.FACTORY);
Expand Down Expand Up @@ -674,13 +545,7 @@ public void sortAscending() {

} else {

//this.sortAscending(0L, this.count() - 1L);

try {
ForkJoinPool.commonPool().submit(new QuickAscendingSorter(this)).get();
} catch (InterruptedException | ExecutionException exception) {
exception.printStackTrace();
}
this.sortAscending(0L, this.count() - 1L);
}
}

Expand All @@ -693,13 +558,7 @@ public void sortDescending() {

} else {

//this.sortDescending(0L, this.count() - 1L);

try {
ForkJoinPool.commonPool().submit(new QuickDescendingSorter(this)).get();
} catch (InterruptedException | ExecutionException exception) {
exception.printStackTrace();
}
this.sortDescending(0L, this.count() - 1L);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ojalgo/array/ArrayR032.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ public short shortValue(final int index) {

@Override
public void sortAscending() {
Arrays.parallelSort(data);
Arrays.sort(data);
}

@Override
public void sortDescending() {
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
Arrays.parallelSort(data);
Arrays.sort(data);
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ojalgo/array/ArrayR064.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ public short shortValue(final int index) {

@Override
public void sortAscending() {
Arrays.parallelSort(data);
Arrays.sort(data);
}

@Override
public void sortDescending() {
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
Arrays.parallelSort(data);
Arrays.sort(data);
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ojalgo/array/ArrayR256.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ public short shortValue(final int index) {

@Override
public void sortAscending() {
Arrays.parallelSort(data);
Arrays.sort(data);
}

@Override
public void sortDescending() {
Arrays.parallelSort(data, Comparator.reverseOrder());
Arrays.sort(data, Comparator.reverseOrder());
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ojalgo/array/ArrayZ008.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ public void set(final int index, final long value) {

@Override
public void sortAscending() {
Arrays.parallelSort(data);
Arrays.sort(data);
}

@Override
public void sortDescending() {
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
Arrays.parallelSort(data);
Arrays.sort(data);
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ojalgo/array/ArrayZ016.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ public short shortValue(final int index) {

@Override
public void sortAscending() {
Arrays.parallelSort(data);
Arrays.sort(data);
}

@Override
public void sortDescending() {
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
Arrays.parallelSort(data);
Arrays.sort(data);
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ojalgo/array/ArrayZ032.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ public short shortValue(final int index) {

@Override
public void sortAscending() {
Arrays.parallelSort(data);
Arrays.sort(data);
}

@Override
public void sortDescending() {
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
Arrays.parallelSort(data);
Arrays.sort(data);
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ojalgo/array/ArrayZ064.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ public short shortValue(final int index) {

@Override
public void sortAscending() {
Arrays.parallelSort(data);
Arrays.sort(data);
}

@Override
public void sortDescending() {
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
Arrays.parallelSort(data);
Arrays.sort(data);
CorePrimitiveOperation.negate(data, 0, data.length, 1, data);
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/ojalgo/array/NumberList.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ public boolean add(final double element) {
return true;
}

public boolean add(final float element) {

this.ensureCapacity();

myStorage.set(myActualCount++, element);

return true;
}

@Override
public void add(final int index, final N element) {

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/ojalgo/array/ScalarArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public short shortValue(final int index) {

@Override
public final void sortAscending() {
Arrays.parallelSort(data);
Arrays.sort(data);
}

@Override
public final void sortDescending() {
Arrays.parallelSort(data, Comparator.reverseOrder());
Arrays.sort(data, Comparator.reverseOrder());
}

@Override
Expand Down
Loading

0 comments on commit aa55f22

Please sign in to comment.