A user-defined operator, allowing the user to write Cog code that can't
be easily parallelized and must be executed on the CPU.
A user-defined operator, allowing the user to write Cog code that can't
be easily parallelized and must be executed on the CPU.
To define an Operator, create an object which extends this class and define
a 'compute' method in it. Here's an example:
/** An operator which flips a picture upside down. */object upsideDown extends Operator {
def compute(in: ScalarFieldReader, out: ScalarFieldWriter) {
out.setShape(in.fieldShape)
for (row <-0 until in.rows; col <-0 until in.columns) {
val pixel = in.read(row, col)
result.write(in.rows - row - 1, col, pixel)
}
}
}
To invoke this operator, use it like a function:
val graph = new ComputeGraph {
val field = ScalarField(...)
val flipped = upsideDown(field)
}
This class does the necessary reflective magic to connect up the compute
method, which is written using *FieldReader and *FieldWriter objects, to
Fields.
A user-defined operator, allowing the user to write Cog code that can't be easily parallelized and must be executed on the CPU.
To define an Operator, create an object which extends this class and define a 'compute' method in it. Here's an example:
To invoke this operator, use it like a function:
This class does the necessary reflective magic to connect up the
compute
method, which is written using *FieldReader and *FieldWriter objects, to Fields.