You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ops/doc/CallingOps.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ In this page, we start after having [identified a Gaussian Blur Op](SearchingFor
10
10
11
11
From the `OpEnvironment`, an `OpBuilder` chain is initialized with the `op(String)` method, which describes the name of the Op that we ultimately want to call:
12
12
13
-
```groovy
13
+
```java
14
14
ops.op("filter.gauss")
15
15
```
16
16
@@ -20,7 +20,7 @@ With the name established in the `OpBuilder` chain, we can then specify our inpu
20
20
21
21
For this Gaussian blur, we have two inputs: `inImage` is the image we want to blur, and a `double` value as our sigma parameter:
22
22
23
-
```groovy
23
+
```java
24
24
ops.op("filter.gauss").input(inImage, 2.0)
25
25
```
26
26
@@ -30,15 +30,15 @@ After specifying inputs, we provide a preallocated output container using the `.
30
30
31
31
For our Gaussian blur, we will pass our output image `outImage` as a receptacle for the result:
@@ -56,21 +56,21 @@ Calling our Gaussian blur as a *computer* above is great when we have pre-alloca
56
56
57
57
*Functions* are used when we want to *create* the final output, indicated by ending the builder with `.apply()`:
58
58
59
-
```groovy
59
+
```java
60
60
var outImage = ops.op("filter.gauss").input(inImage, 2.0).apply()
61
61
```
62
62
63
63
*Inplaces* are used when we want to destructively modify one of the existing inputs (which is explicitly forbidden by *computers*; a *computer* Op's output should be a different object from all of its inputs). We indicate this by the `mutate#()` method, where the `#` corresponds to the *parameter index* that will be modified:
Note that although the final method call changes for each mode of operation, *this is based on the path taken through the `OpBuilder` chain*. For example, we cannot call the `compute()` method if we haven't provided an `.output()`:
@@ -80,10 +80,10 @@ A key takeaway from this section is that how you **request** the Op does not nec
80
80
81
81
When you want to call an Op many times on different inputs, the `OpBuilder` can be used to return the *Op* itself, instead of performing the computation. Instead of calling the `.compute()` function at the end of our `OpBuilder` chain, we can use the `.computer()` method (or `.inplace()` or `.function()`, as appropriate) to get back the matched Op, which can then be reused via its `.compute()` method (or `.apply()` or `.mutate#()`, respectively):
82
82
83
-
```groovy
84
-
var gaussOp = ops.op("filter.gauss").input(inImage, 2.0).output(outImage).computer()
85
-
gaussOp.compute(inImage, 2.0, outImage1)
86
-
gaussOp.compute(inImage, 5.0, outImage2)
83
+
```java
84
+
var gaussOp = ops.op("filter.gauss").input(inImage, 2.0).output(outImage).computer();
85
+
gaussOp.compute(inImage, 2.0, outImage1);
86
+
gaussOp.compute(inImage, 5.0, outImage2);
87
87
```
88
88
89
89
While we do pass concrete inputs and outputs in this example, they are essentially just being used to reason about the desired *types* - which we'll cover in the next section.
@@ -95,7 +95,7 @@ While we do pass concrete inputs and outputs in this example, they are essential
95
95
In addition to the `.input()` and `.output()` builder steps, there are parallel `.inType()` and `.outType()`
96
96
methods. These accept either a `Class` or a `Nil` - the latter allowing retention of generic types.
97
97
98
-
```groovy
98
+
```java
99
99
var computer = ops.op("filter.gauss").inType(ImgPlus.class, Double.class).outType(ImgPlus.class).computer()
100
100
```
101
101
@@ -106,7 +106,7 @@ not been concretely specified yet. This is very sensible when we want to re-use
106
106
We can also use the `.outType()` methods to add type safety to our `Function` calls:
Generally speaking, op requests are **cached**, meaning repeated OpBuilder calls that directly execute Ops will **not** significantly decrease performance.
0 commit comments