---
title: "ClikaRT::graph::Transform"
sidebar_label: "Transform"
description: "A graph transform: one of ours, from its factory in transforms, or one you write (from_function). Cheap to copy."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--class">class</span>

**Header:** `ClikaRT/graph/transform.h`

`Transform`: a graph transform the runtime can run over a `ModelGraph`: one of ours, from its factory in `transforms` (`transforms::fusion_driver()`), or one you write (`Transform::from_function`, or `transforms::rewrite` for a rule over a `Pattern`, [rewrite.h](./RewriteMatch.md)).

A handle of ours names a transform and carries nothing else: the graph that runs it supplies the settings it depends on, so a factory takes no arguments. A handle you make carries your function. `kind()` is the typed key (`TransformKind::User` for yours); `name()` is the transform's name, the factory's own spelling or the name you gave, readable in every build. Two handles of ours compare equal when they name the same kind; a handle you made equals its copies only.

Compare and persist a transform by its NAME, never by the integer behind its `TransformKind`: the values follow the runtime's transform list and move whenever the list changes.

A list of handles is what `ModelGraph::optimize` runs (`OptimizeOptions::transforms`, [optimize.h](./transforms/index.md#optimize-h)); `ModelGraph::default_transforms` and `transforms::defaults` ([optimize.h](./transforms/index.md#optimize-h)) return the default lists.

## Macros

### \#define CLIKART\_DETAIL\_TRANSFORM\_KIND\_ENUMERATOR {#CLIKART_DETAIL_TRANSFORM_KIND_ENUMERATOR}

<div class="api-signature">

`#define` **`CLIKART_DETAIL_TRANSFORM_KIND_ENUMERATOR(kind, name)`** `kind,`

</div>

<div class="api-declared">

Declared in `ClikaRT/graph/transform.h`, line 46

</div>

### \#define CLIKART\_DETAIL\_TRANSFORM\_FACTORY {#CLIKART_DETAIL_TRANSFORM_FACTORY}

<div class="api-signature">

`#define` **`CLIKART_DETAIL_TRANSFORM_FACTORY(kind, name)`** `CLIKART_PUBLIC_EXPORT Transform name();`

</div>

<div class="api-declared">

Declared in `ClikaRT/graph/transform.h`, line 152

</div>

A graph transform: one of ours, from its factory in [`transforms`](./transforms/index.md), or one you write ([`from_function`](./Transform.md#from_function)). Cheap to copy.

## Static member functions

### from\_function() {#from_function}

<div class="api-signature">

`static` `Transform` **`from_function`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::string` `name`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`TransformFunction`](./index.md#TransformFunction) `fn`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::vector<Transform>` `runs_after` `=` `{}`<br />
)

</div>

A transform you write, which [`ModelGraph::optimize`](./ModelGraph.md#optimize) runs beside ours at its place in [`OptimizeOptions::transforms`](./OptimizeOptions.md#transforms), once per iteration.

- [`name`](./Transform.md#name): how the transform reads in the report and in errors. Not empty and never the name of one of ours. Within one list no two different transforms share a name; one handle may be listed more than once, as ours may.
- `fn`: edits the graph it is handed ([model\_graph.h](./index.md#model_graph-h) lists the edits and what a transform may not do) and returns a failure to stop the run; a throw it makes is caught on your side and read as that failure. The run counts it as changing the graph when one of its edits did.
- `runs_after`: the transforms, ours or yours, it must follow in any list that holds both: `optimize` refuses a list that places it ahead of one of them. One the list does not hold asks nothing.

Refuses `InvalidArgument` for an empty name, the name of one of ours, an empty `fn`, and a `runs_after` entry that is another transform of the same name.

<div class="api-declared">

Declared in `ClikaRT/graph/transform.h`, line 116

</div>

## Member functions

### kind() {#kind}

<div class="api-signature">

[`TransformKind`](./index.md#TransformKind) **`kind`**() `const noexcept`

</div>

Which transform this handle names: [`TransformKind::User`](./index.md#TransformKind) for one you made.

<div class="api-declared">

Declared in `ClikaRT/graph/transform.h`, line 124

</div>

### name() {#name}

<div class="api-signature">

`std::string` **`name`**() `const`

</div>

The transform's name: `"fusion_driver"` for `transforms::fusion_driver()`, the name you gave for one you made.

<div class="api-declared">

Declared in `ClikaRT/graph/transform.h`, line 128

</div>

## Friends

### operator== {#operator-eq}

<div class="api-signature">

`friend` `bool` **`operator==`**(`const Transform&` `a`, `const Transform&` `b`) `noexcept`

</div>

Two handles of ours naming the same kind compare equal; a handle you made equals its copies only.

<div class="api-declared">

Declared in `ClikaRT/graph/transform.h`, line 132

</div>
