Skip to content

Commit 64ba835

Browse files
committed
Remove multi-stage tasks
It's simpler and faster this way
1 parent 0d5c5f9 commit 64ba835

15 files changed

Lines changed: 138 additions & 203 deletions

File tree

scijava-ops-engine/pom.xml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -107,36 +107,36 @@
107107

108108
<build>
109109
<plugins>
110-
<!-- <plugin>-->
111-
<!-- <artifactId>maven-invoker-plugin</artifactId>-->
112-
<!-- <version>${maven-invoker-plugin.version}</version>-->
113-
<!-- <configuration>-->
114-
<!-- &lt;!&ndash; <debug>true</debug> &ndash;&gt;-->
115-
<!-- <showErrors>true</showErrors>-->
116-
<!-- <properties>-->
117-
<!-- <scijava-maven.version>${project.version}</scijava-maven.version>-->
118-
<!-- </properties>-->
119-
<!-- <projectsDirectory>src/it</projectsDirectory>-->
120-
<!-- <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>-->
121-
<!-- <pomIncludes>-->
122-
<!-- <pomInclude>*/pom.xml</pomInclude>-->
123-
<!-- </pomIncludes>-->
124-
<!-- <settingsFile>src/it/settings.xml</settingsFile>-->
125-
<!-- <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>-->
126-
<!-- <goals>-->
127-
<!-- <goal>install</goal>-->
128-
<!-- </goals>-->
129-
<!-- </configuration>-->
130-
<!-- <executions>-->
131-
<!-- <execution>-->
132-
<!-- <id>integration-test</id>-->
133-
<!-- <goals>-->
134-
<!-- <goal>install</goal>-->
135-
<!-- <goal>run</goal>-->
136-
<!-- </goals>-->
137-
<!-- </execution>-->
138-
<!-- </executions>-->
139-
<!-- </plugin>-->
110+
<plugin>
111+
<artifactId>maven-invoker-plugin</artifactId>
112+
<version>${maven-invoker-plugin.version}</version>
113+
<configuration>
114+
<!-- <debug>true</debug> -->
115+
<showErrors>true</showErrors>
116+
<properties>
117+
<scijava-maven.version>${project.version}</scijava-maven.version>
118+
</properties>
119+
<projectsDirectory>src/it</projectsDirectory>
120+
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
121+
<pomIncludes>
122+
<pomInclude>*/pom.xml</pomInclude>
123+
</pomIncludes>
124+
<settingsFile>src/it/settings.xml</settingsFile>
125+
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
126+
<goals>
127+
<goal>install</goal>
128+
</goals>
129+
</configuration>
130+
<executions>
131+
<execution>
132+
<id>integration-test</id>
133+
<goals>
134+
<goal>install</goal>
135+
<goal>run</goal>
136+
</goals>
137+
</execution>
138+
</executions>
139+
</plugin>
140140
</plugins>
141141
</build>
142142

scijava-ops-image/src/main/java/org/scijava/ops/image/coloc/saca/AdaptiveSmoothedKendallTau.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static <I extends RealType<I>> void execute(
9595

9696
LoopBuilder.setImages(oldsqrtN).multiThreaded().forEachPixel(t -> t
9797
.setOne());
98-
Progress.setStageMax(TU);
98+
Progress.defineTotal(TU);
9999
for (int s = 0; s < TU; s++) {
100100
intSize = (int) Math.floor(size);
101101
singleiteration(image1, image2, thres1, thres2, stop, oldtau, oldsqrtN,

scijava-ops-image/src/main/java/org/scijava/ops/image/coloc/saca/SACAHeatmapZScore.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public void compute(final RandomAccessibleInterval<I> image1,
102102
}
103103

104104
// set seed, compute thresholds and create empty result if necessary
105-
Progress.defineTotalProgress(1);
106105
if (seed == null) seed = 0xdeadbeefL;
107106
if (thres1 == null) thres1 = otsuOp.apply(histOp.apply(Views.iterable(
108107
image1)));

scijava-ops-image/src/main/java/org/scijava/ops/image/deconvolve/PadAndRichardsonLucy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public class PadAndRichardsonLucy<I extends RealType<I> & NativeType<I>, O exten
9393
@OpDependency(name = "filter.createFFTOutput")
9494
private Functions.Arity3<Dimensions, C, Boolean, RandomAccessibleInterval<C>> createOp;
9595

96-
@OpDependency(name = "deconvolve.richardsonLucy")
96+
@OpDependency(name = "deconvolve.richardsonLucy", hints= {"progress.TRACK"})
9797
private Computers.Arity12<RandomAccessibleInterval<I>, RandomAccessibleInterval<K>, //
9898
RandomAccessibleInterval<C>, RandomAccessibleInterval<C>, Boolean, //
9999
Boolean, C, Integer, Boolean, //
@@ -178,7 +178,7 @@ public RandomAccessibleInterval<O> apply(RandomAccessibleInterval<I> input,
178178
}
179179
}
180180

181-
Progress.defineTotalProgress(0, 3);
181+
Progress.defineTotal(0, 1);
182182
RandomAccessibleInterval<I> paddedInput = padOp.apply(input,
183183
new FinalDimensions(paddedSize), true, obfInput);
184184

scijava-ops-image/src/main/java/org/scijava/ops/image/deconvolve/PadAndRichardsonLucyTV.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.scijava.function.Inplaces;
5151
import org.scijava.ops.spi.Nullable;
5252
import org.scijava.ops.spi.OpDependency;
53+
import org.scijava.progress.Progress;
5354

5455
/**
5556
* Richardson Lucy with total variation function op that operates on (@link
@@ -216,6 +217,8 @@ public RandomAccessibleInterval<O> apply(RandomAccessibleInterval<I> input,
216217
this.nonCirculant = nonCirculant;
217218
}
218219

220+
Progress.defineTotal(0, 1);
221+
219222
// out of bounds factory will be different depending on if circulant or
220223
// non-circulant is used
221224
if (obfInput == null) {

scijava-ops-image/src/main/java/org/scijava/ops/image/deconvolve/RichardsonLucyC.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ public void compute(RandomAccessibleInterval<I> in, //
166166
AccelerationState<O> state = new AccelerationState<>(raiExtendedEstimate);
167167

168168
// -- perform iterations --
169-
Progress.defineTotalProgress(1);
170-
Progress.setStageMax(maxIterations);
169+
Progress.defineTotal(maxIterations);
171170
for (int i = 0; i < maxIterations; i++) {
172171
// create reblurred by convolving kernel with estimate
173172
// NOTE: the FFT of the PSF of the kernel has been passed in as a

scijava-ops-image/src/test/java/org/scijava/ops/image/AbstractOpTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import java.net.URL;
3333
import java.util.stream.StreamSupport;
3434

35+
import org.scijava.ops.api.Hints;
3536
import org.scijava.ops.api.OpEnvironment;
37+
import org.scijava.ops.engine.BaseOpHints;
3638
import org.scijava.ops.spi.Op;
3739

3840
import io.scif.img.IO;
@@ -64,6 +66,10 @@ public abstract class AbstractOpTest {
6466

6567
protected static final OpEnvironment ops = OpEnvironment.build();
6668

69+
static {
70+
ops.setDefaultHints(new Hints(BaseOpHints.Progress.TRACK));
71+
}
72+
6773
private int seed;
6874

6975
private int pseudoRandom() {

scijava-ops-tutorial/src/main/java/org/scijava/ops/tutorial/ReportingProgress.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,19 @@ public class ReportingProgress implements OpCollection {
7979
long val = 1, sqrt;
8080
boolean couldBePrime;
8181

82-
// Define the number of stages, and the number of subtasks
83-
// One stage - finding the primes
84-
// Zero subtasks - we call no other Ops
85-
Progress.defineTotalProgress(1, 0);
82+
// If you have N discrete packets of computation, you should call
83+
// Progress.defineTotalProgress(N)
84+
// If you have N discrete packets of computation and want to call Op dependencies M times, you should call
85+
// Progress.defineTotalProgress(N, M)
86+
87+
// Here, we want to update the progress every time we find a new prime.
88+
// We call no Op dependencies, thus the call looks like:
89+
Progress.defineTotal(numPrimes, 0);
90+
8691
// Progress is defined within the range [0, 1],
8792
// where 0 denotes an Op that has not yet started.
8893
// and 1 denotes completion.
8994

90-
// setStageMax is used to define the denominator for the Progress fraction.
91-
// If you have N discrete packets of computation, you should call
92-
// Progress.setStageMax(N)
93-
Progress.setStageMax(numPrimes);
9495
// Find each of our primes
9596
while (primes.size() < numPrimes) {
9697
sqrt = (long) Math.sqrt(++val);

scijava-progress/src/main/java/org/scijava/progress/Progress.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,29 +281,24 @@ public static void setStatus(String status) {
281281
/**
282282
* Defines the total progress of the current {@link Task}
283283
*
284-
* @see Task#defineTotalProgress(long)
284+
* @param elements the number of discrete "elements" in the computation
285+
* @see Task#define(long)
285286
*/
286-
public static void defineTotalProgress(long numStages) {
287-
currentTask().defineTotalProgress(numStages);
287+
public static void defineTotal(long elements) {
288+
currentTask().define(elements);
288289
}
289290

290291
/**
291292
* Defines the total progress of the current {@link Task}
292293
*
293-
* @see Task#defineTotalProgress(long, long)
294+
* @param elements the number of discrete "elements" in the computation
295+
* @param subTasks the number <b>of times</b> subtasks are called upon
296+
* within the task. This <b>is not</b> the same as the number of
297+
* subtasks used (as one subtask may run multiple times).
298+
* @see Task#define(long, long)
294299
*/
295-
public static void defineTotalProgress(long numStages, long numSubTasks) {
296-
currentTask().defineTotalProgress(numStages, numSubTasks);
297-
}
298-
299-
/**
300-
* Defines the number of updates expected by the end of the current stage of
301-
* the current {@link Task}
302-
*
303-
* @see Task#setStageMax(long)
304-
*/
305-
public static void setStageMax(long max) {
306-
currentTask().setStageMax(max);
300+
public static void defineTotal(long elements, long subTasks) {
301+
currentTask().define(elements, subTasks);
307302
}
308303

309304
/**
@@ -322,7 +317,7 @@ private NOPTask() {
322317

323318
@Override
324319
public boolean isComplete() {
325-
return true;
320+
return false;
326321
}
327322

328323
@Override
@@ -340,6 +335,11 @@ public double progress() {
340335
return NOP_PROGRESS;
341336
}
342337

338+
@Override
339+
public void define(final long elements, final long subTasks) {
340+
// NB: No-op
341+
}
342+
343343
}
344344

345345
private static final NOPTask IGNORED = new NOPTask();

0 commit comments

Comments
 (0)