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
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
# Calling Ops with the `OpBuilder`
2
2
3
-
Use of the Ops framework centers on a process of matching Op requests are to function implementations based on the parameters provided. The easiest way to make these queries is to use the `OpBuilder` syntax, which follows the [builder pattern](https://refactoring.guru/design-patterns/builder) to assemble the required components of an Op matching request from a particular `OpEnvironment`.
3
+
Use of the Ops framework centers on a process of matching Op requests to algorithm implementations based on the parameters provided. The easiest way to make these queries is to use the `OpBuilder` syntax, which follows the [builder pattern](https://refactoring.guru/design-patterns/builder) to assemble the required components of an Op matching request from a particular `OpEnvironment`.
4
4
5
-
In this page we start after having [identified a Gaussian Blur Op](SearchingForOps) that we would like to use. We assume we already have created an `OpEnvironment`, named `ops`, as well as the input image to blur, and a pre-allocated output image for the result - `inImage` and `outImage`, respectively.
5
+
In this page, we start after having [identified a Gaussian Blur Op](SearchingForOps) that we would like to use. We assume we already have created an `OpEnvironment` named `ops`, as well as the input image to blur, and a pre-allocated output image for the result—`inImage` and `outImage`, respectively.
6
6
7
-
**Note:** we are incrementally building one line of code in this example. Running an intermediate step simply returns an appropriate builder that knows what has been set so far, and which step is next. If you're following along in an IDE or script editor, the code you actually *run* would be the last step, once our builder call is fully constructed.
7
+
**Note:** we are incrementally constructing one line of code in this example. Running an intermediate step simply returns an appropriate builder that knows what has been set so far, and which step is next. If you're following along in an IDE or script editor, the code you actually *run* would be the last step, once our builder call is fully constructed.
8
8
9
9
## Specifying the name with `.op()`
10
10
11
-
From the `OpEnvironment`, an `OpBuilder` chain is initialized with the `OpEnvironment.op(String)` method, which describes the name of the Op that we ultimately want to call:
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
13
```groovy
14
14
ops.op("filter.gauss")
@@ -18,49 +18,49 @@ ops.op("filter.gauss")
18
18
19
19
With the name established in the `OpBuilder` chain, we can then specify our input(s) with the `.input()` method.
20
20
21
-
For this Gaussian blur, we have two inputs: `inImage` is the image we want to blur, and a `double` as our sigma parameter:
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
23
```groovy
24
24
ops.op("filter.gauss").input(inImage, 2.0)
25
25
```
26
26
27
27
## Passing an output buffer with `.output()`
28
28
29
-
After specifying inputs, we provide preallocated outputs using the `.output()` method.
29
+
After specifying inputs, we provide a preallocated output container using the `.output()` method.
30
30
31
-
For our Gaussian blur, we will pass our output image `outImage` as a buffer for the result:
31
+
For our Gaussian blur, we will pass our output image `outImage` as a receptacle for the result:
In the call to `compute()`, the `OpEnvironment` will use the components of the `OpBuilder` syntax to:
46
-
* Match an Op based on the name provided, as well as the types of the provided input and output `Object`s
47
-
* Execute the Op on the provided input and output `Object`s.
45
+
In the call to `compute()`, the `OpEnvironment` will use all of the parameters provided to:
46
+
* Match an Op based on the name provided, as well as the types of the provided input and output objects
47
+
* Execute the Op on the provided input and output objects.
48
48
49
49
After this step, `outImage` will contain the results of the Gaussian blur on `inImage`.
50
50
51
51
## Variations on use
52
52
53
-
### Using `Function`or `InPlace`
53
+
### Using a *function*or *inplace* Op
54
54
55
-
Calling our Gaussian blur as a `Computer` above is great when we have pre-allocated output, but for other scenarios we can request Ops as `Functions` or `InPlaces`.
55
+
Calling our Gaussian blur as a *computer* above is great when we have pre-allocated output, but for other scenarios we can request Ops as *functions* or *inplaces*.
56
56
57
-
`Functions` are used when we want to *create* the final output, indicated by ending the builder with `.apply()`:
57
+
*Functions* are used when we want to *create* the final output, indicated by ending the builder with `.apply()`:
58
58
59
59
```groovy
60
60
var outImage = ops.op("filter.gauss").input(inImage, 2.0).apply()
61
61
```
62
62
63
-
`InPlaces` are used when we want to destructively modify one of the existing inputs (which is explicitly forbidden by `Computers`). We indicate this by the `mutate#()` method, where the `#` corresponds to the *parameter index* that will be modified:
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:
64
64
65
65
```
66
66
# Modify the first input in-place
@@ -74,11 +74,11 @@ Note that although the final method call changes for each mode of operation, *th
A key takeaway from this section is that how you **request** the Op does not necessarily need to match how the Op is **implemented**. `Functions` and `Computers` should be largely interchangeable. For the 1.0.0 release we do not have the necessary converters to go between `InPlaces` and the other paradigms, but it is on our [development roadmap](https://github.com/scijava/scijava/issues/47)!
77
+
A key takeaway from this section is that how you **request** the Op does not necessarily need to match how the Op is **implemented**. *Functions* and *computers* should be largely interchangeable, thanks to the Ops engine's adaptation subsystem. For the 1.0.0 release we do not have the necessary adapters to go between *inplaces* and the other paradigms, but it is on our [development roadmap](https://github.com/scijava/scijava/issues/47)!
78
78
79
79
### Repeating execution
80
80
81
-
When you want to call an Op many times on different inputs, the `OpBuilder`syntax can be modified 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()`, `.mutate#()`):
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
83
```groovy
84
84
var gaussOp = ops.op("filter.gauss").input(inImage, 2.0).output(outImage).computer()
@@ -131,7 +131,7 @@ Generally speaking, op requests are **cached**, meaning repeated OpBuilder calls
131
131
132
132
### Solution 2: Avoid using wildcards
133
133
134
-
If you *know* that your `Img` will always contain unsigned byte values, for example, define your variable as an `Img<UnsignedByteType>` rather than using `Img<?>`.
134
+
If you know that your `Img` will always contain unsigned byte values, for example, define your variable as an `Img<UnsignedByteType>` rather than using `Img<?>`.
0 commit comments