Skip to content

Commit 904ea30

Browse files
committed
Add inplace support for OpBuilders
1 parent a1b776a commit 904ea30

1 file changed

Lines changed: 104 additions & 1 deletion

File tree

src/main/java/org/scijava/ops/core/builder/OpBuilder.java

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.scijava.ops.function.Computers;
3939
import org.scijava.ops.function.Computers.Arity0;
4040
import org.scijava.ops.function.Functions;
41+
import org.scijava.ops.function.Inplaces;
4142
import org.scijava.ops.function.Producer;
4243
import org.scijava.ops.types.Nil;
4344
import org.scijava.ops.types.TypeService;
@@ -167,10 +168,15 @@ public Type getType() {
167168
public Computers.Arity0<O> computer() {
168169
return Computers.match(ops, opName, outType);
169170
}
171+
172+
public Inplaces.Arity1<O> inplace() {
173+
return Inplaces.match(ops, opName, outType);
174+
}
170175

171176
public O create() {
172177
return producer().create();
173178
}
179+
174180
}
175181

176182
/**
@@ -190,10 +196,18 @@ public Arity0_OV(final O out) {
190196
public Arity0<O> computer() {
191197
return Computers.match(ops, opName, type(out));
192198
}
193-
199+
194200
public void compute() {
195201
computer().compute(out.get());
196202
}
203+
204+
public Inplaces.Arity1<O> inplace(){
205+
return Inplaces.match(ops, opName, type(out));
206+
}
207+
208+
public void mutate() {
209+
inplace().mutate(out.get());
210+
}
197211
}
198212

199213
/**
@@ -220,6 +234,15 @@ public Function<I, O> function() {
220234
public Computers.Arity1<I, O> computer() {
221235
return Computers.match(ops, opName, inType, outType);
222236
}
237+
238+
public Inplaces.Arity2<I, O> inplace1(){
239+
return Inplaces.match1(ops, opName, inType, outType);
240+
}
241+
242+
public Inplaces.Arity2<I, O> inplace2(){
243+
return Inplaces.match2(ops, opName, inType, outType);
244+
}
245+
223246
}
224247

225248
/**
@@ -269,6 +292,18 @@ public Arity1_IV_OT(final I in, final Nil<O> outType) {
269292
public Function<I, O> function() {
270293
return Functions.match(ops, opName, type(in), outType);
271294
}
295+
296+
public Computers.Arity1<I, O> computer() {
297+
return Computers.match(ops, opName, type(in), outType);
298+
}
299+
300+
public Inplaces.Arity2<I, O> inplace1(){
301+
return Inplaces.match1(ops, opName, type(in), outType);
302+
}
303+
304+
public Inplaces.Arity2<I, O> inplace2(){
305+
return Inplaces.match2(ops, opName, type(in), outType);
306+
}
272307

273308
public O apply() {
274309
return function().apply(in.get());
@@ -329,10 +364,26 @@ public Arity1_IV_OV(final I in, final O out) {
329364
public Computers.Arity1<I, O> computer() {
330365
return Computers.match(ops, opName, type(in), type(out));
331366
}
367+
368+
public Inplaces.Arity2<I, O> inplace1(){
369+
return Inplaces.match1(ops, opName, type(in), type(out));
370+
}
371+
372+
public Inplaces.Arity2<I, O> inplace2(){
373+
return Inplaces.match2(ops, opName, type(in), type(out));
374+
}
332375

333376
public void compute() {
334377
computer().compute(in.get(), out.get());
335378
}
379+
380+
public void mutate1() {
381+
inplace1().mutate(in.get(), out.get());
382+
}
383+
384+
public void mutate2() {
385+
inplace2().mutate(in.get(), out.get());
386+
}
336387
}
337388

338389
/**
@@ -362,6 +413,18 @@ public BiFunction<I1, I2, O> function() {
362413
public Computers.Arity2<I1, I2, O> computer() {
363414
return Computers.match(ops, opName, in1Type, in2Type, outType);
364415
}
416+
417+
public Inplaces.Arity3_1<I1, I2, O> inplace1() {
418+
return Inplaces.match1(ops, opName, in1Type, in2Type, outType);
419+
}
420+
421+
public Inplaces.Arity3_2<I1, I2, O> inplace2() {
422+
return Inplaces.match2(ops, opName, in1Type, in2Type, outType);
423+
}
424+
425+
public Inplaces.Arity3_3<I1, I2, O> inplace3() {
426+
return Inplaces.match3(ops, opName, in1Type, in2Type, outType);
427+
}
365428
}
366429

367430
/**
@@ -417,6 +480,22 @@ public Arity2_IV_OT(final I1 in1, final I2 in2, final Nil<O> outType) {
417480
public BiFunction<I1, I2, O> function() {
418481
return Functions.match(ops, opName, type(in1), type(in2), outType);
419482
}
483+
484+
public Computers.Arity2<I1, I2, O> computer() {
485+
return Computers.match(ops, opName, type(in1), type(in2), outType);
486+
}
487+
488+
public Inplaces.Arity3_1<I1, I2, O> inplace1() {
489+
return Inplaces.match1(ops, opName, type(in1), type(in2), outType);
490+
}
491+
492+
public Inplaces.Arity3_2<I1, I2, O> inplace2() {
493+
return Inplaces.match2(ops, opName, type(in1), type(in2), outType);
494+
}
495+
496+
public Inplaces.Arity3_3<I1, I2, O> inplace3() {
497+
return Inplaces.match3(ops, opName, type(in1), type(in2), outType);
498+
}
420499

421500
public O apply() {
422501
return function().apply(in1.get(), in2.get());
@@ -484,9 +563,33 @@ public Arity2_IV_OV(final I1 in1, final I2 in2, final O out) {
484563
public Computers.Arity2<I1, I2, O> computer() {
485564
return Computers.match(ops, opName, type(in1), type(in2), type(out));
486565
}
566+
567+
public Inplaces.Arity3_1<I1, I2, O> inplace1() {
568+
return Inplaces.match1(ops, opName, type(in1), type(in2), type(out));
569+
}
570+
571+
public Inplaces.Arity3_2<I1, I2, O> inplace2() {
572+
return Inplaces.match2(ops, opName, type(in1), type(in2), type(out));
573+
}
574+
575+
public Inplaces.Arity3_3<I1, I2, O> inplace3() {
576+
return Inplaces.match3(ops, opName, type(in1), type(in2), type(out));
577+
}
487578

488579
public void compute() {
489580
computer().compute(in1.get(), in2.get(), out.get());
490581
}
582+
583+
public void mutate1() {
584+
inplace1().mutate(in1.get(), in2.get(), out.get());
585+
}
586+
587+
public void mutate2() {
588+
inplace2().mutate(in1.get(), in2.get(), out.get());
589+
}
590+
591+
public void mutate3() {
592+
inplace3().mutate(in1.get(), in2.get(), out.get());
593+
}
491594
}
492595
}

0 commit comments

Comments
 (0)