MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Nodes::Network::RewriteOperator Class Referencefinal

Bounded parallel rewriting of a typed word in a RelationNetwork. More...

#include <RewriteOperator.hpp>

Inheritance diagram for MayaFlux::Nodes::Network::RewriteOperator:
Collaboration diagram for MayaFlux::Nodes::Network::RewriteOperator:

Classes

struct  Config
struct  Environment
 What a replacement sees: the caller's inputs, the word with the symbol's position in it, and the grammar's controls. More...
struct  Replacement
 One rewrite rule: left < predecessor > right, if predicate, with weight. More...
struct  Submission
class  SubmissionMailbox
struct  Symbol
struct  Word

Public Types

using EmitSymbol = std::function<bool(Symbol)>
 Append a symbol; false on a bound violation.
enum class  GrowResult : uint8_t {
  GROWN , BUSY , INVALID_CONFIG , GENERATION_LIMIT ,
  WORD_LIMIT , REPLACEMENT_FAILED , SUBMISSION_LIMIT
}
 What grow() did; the first failure of its rewrite or its submit. More...
using Predicate = std::function<bool(const Symbol&, Environment)>
enum class  RewriteResult : uint8_t {
  REWRITTEN , INVALID_CONFIG , GENERATION_LIMIT , WORD_LIMIT ,
  REPLACEMENT_FAILED
}
enum class  SubmitResult : uint8_t { SUBMITTED , INVALID_CONFIG , BUSY , SUBMISSION_LIMIT }
using Successor = std::function<void(const Symbol&, Environment, const EmitSymbol&)>
using SymbolId = uint32_t

Public Member Functions

uint64_t active_generation () const noexcept
std::span< const Symbol > active_symbols () const noexcept
 Read the active word on the RelationNetwork processing lane.
std::shared_ptr< const Word > active_word () const
 Return the latest active word on the producer lane.
void clear_replacements () noexcept
template<typename C>
C & declare ()
 Declare the struct of controls the grammar's rules read, and return it.
uint64_t draft_generation () const noexcept
std::shared_ptr< const Word > draft_word () const noexcept
 The draft word on the producer lane: the axiom, or what rewrite() last built.
Kinesis::Stochastic::Stochastic & generator () noexcept
 The generator behind weighted choices.
template<typename C>
C get () const
 The controls with the values the operator holds now.
std::string_view get_type_name () const override
 Type name for introspection.
GrowResult grow (uint64_t steps=1, std::span< const double > inputs={})
 Rewrite the draft word and submit it, on the producer lane.
void process (float frames) override
 Process for one batch cycle.
bool published () const noexcept
 True once the word last submitted is the draft and is the active word.
std::optional< double > query_state (std::string_view name) const override
 The number held by the control called name, or nullopt for an unknown name.
bool replace (Replacement replacement)
 Append a rule; false when the operator is invalid or the successor is empty.
bool replace (SymbolId predecessor, std::string_view successor, double weight=0.0)
 Append a rule whose successor is text.
bool replace (SymbolId predecessor, Successor successor, Predicate predicate={})
bool restore_axiom ()
 Restore the axiom as the draft word on the producer lane, without submitting it.
RewriteResult rewrite (uint64_t steps=1, std::span< const double > inputs={})
 Rewrite the draft word on the producer lane, without submitting it.
 RewriteOperator (Config config)
template<typename C>
void set (const C &incoming)
 Apply the members of incoming that hold a value; empty members are left alone.
void set_parameter (std::string_view name, double value) override
 Set the control called name; unknown names are logged and ignored.
SubmitResult submit ()
 Submit the draft word; it becomes the active word at the next RelationNetwork block.
bool valid () const noexcept
Public Member Functions inherited from MayaFlux::Nodes::Network::RelationOperator
void begin_block ()
 Apply mapped parameters at the start of a block.
virtual std::span< const double > get_output_block (size_t) const
virtual size_t get_output_count () const
void map (std::string parameter, Source source)
 Drive an operator parameter from a source.
virtual bool publishes_output () const
void set_slots (std::vector< RelationSlot > &slots) noexcept
 Supply the current slot storage.
void unmap (std::string_view parameter)
 Remove the mapping of a parameter.
Public Member Functions inherited from MayaFlux::Nodes::Network::NetworkOperator
virtual void apply_mapped_one_to_one (ParameterKey key, const std::shared_ptr< NodeNetwork > &source)
 Apply a cached per-element key, delegating to apply_one_to_one by default.
virtual void apply_one_to_one (std::string_view param, const std::shared_ptr< NodeNetwork > &source)
 Apply ONE_TO_ONE parameter mapping (per-point control).
virtual bool demands_full_vertex_restore () const
 Whether a downstream compute pass writes the network's vertex buffer in place each cycle, so the geometry producer must keep restoring the CPU-authoritative vertex data every frame.
template<typename Self>
Self::Controls get (this const Self &self)
 The controls with the values the operator holds now.
template<typename Self>
void set (this Self &self, const typename Self::Controls &incoming)
 Apply the members of this operator's Controls struct that hold a value.
virtual void set_mapped_parameter (ParameterKey key, double value)
 Apply a cached mapping key, delegating to set_parameter by default.
virtual ~NetworkOperator ()=default

Static Public Member Functions

template<typename C>
static const void * controls_tag () noexcept
 A tag that is the same for every use of one type C in a module, and differs between types.
static std::vector< Symbol > symbols_from_text (std::string_view text)
 One parameterless symbol per character, each character being its own id.
static Successor text_successor (std::string_view text)
 A successor that emits the text's characters as parameterless symbols.

Static Public Attributes

static constexpr size_t max_symbol_parameters = 8

Private Member Functions

void drain_retired ()
bool matches_context (const Replacement &replacement, const Environment &environment) const
const Replacement * select_replacement (const Symbol &symbol, const Environment &environment)

Private Attributes

Submission m_active
std::atomic< uint64_t > m_active_generation
std::atomic< uint64_t > m_active_submission_id
std::shared_ptr< const Word > m_active_word
std::shared_ptr< const Word > m_axiom
std::vector< const Replacement * > m_candidates
Submission m_deferred
std::shared_ptr< const Word > m_draft
Kinesis::Stochastic::Stochastic m_generator
const void * m_held_tag {}
std::function< std::shared_ptr< const void >()> m_hold
std::vector< SymbolId > m_ignore
uint64_t m_max_generations
size_t m_max_word_length
uint64_t m_next_submission_id {}
bool m_pending {}
std::function< std::optional< double >(std::string_view)> m_read
SubmissionMailbox m_ready
std::vector< Replacement > m_replacements
SubmissionMailbox m_retired
bool m_retirement_received {}
Submission m_submitted
bool m_valid
std::vector< double > m_weights

Additional Inherited Members

Protected Member Functions inherited from MayaFlux::Nodes::Network::RelationOperator
virtual std::optional< size_t > mapped_parameter_index (std::string_view) const
virtual std::shared_ptr< std::optional< double > > mapped_parameter_slot (std::string_view)
virtual void set_indexed_parameter (size_t, double)
std::span< RelationSlot > slots () const noexcept
Protected Member Functions inherited from MayaFlux::Nodes::Network::NetworkOperator
template<typename C>
C & declare_controls ()
 Create the operator's controls struct and keep it alive.
template<typename C>
void merge_controls (const C &incoming)
 Apply the members of incoming that hold a value, for an operator whose controls type is not fixed.
void refresh_controls ()
 Read node sources into their controls.
bool set_named_control (std::string_view name, double value)
 Sets the control called name, the way set() would.
bool settle_named_control (std::string_view name)
 Drops the pending typed value of the control called name.
template<typename C>
C snapshot_controls () const
 A copy of the declared struct, for an operator whose controls type is not fixed.

Detailed Description

Bounded parallel rewriting of a typed word in a RelationNetwork.

A symbol is an id plus up to eight numeric parameters. A character literal is its own id, so grammars read the way they are written on paper. Replacements may be conditional, context sensitive and stochastic.

Rewriting runs on one producer lane and builds a draft word. submit() hands the draft to the network, and process() makes it the active word at a block boundary without allocating or releasing word storage.

.max_word_length = 4096,
.max_generations = 5 });
rewrite->replace('F', "F[+F]F[-F]F");
rewrite->rewrite(4);
rewrite->submit();
RewriteResult rewrite(uint64_t steps=1, std::span< const double > inputs={})
Rewrite the draft word on the producer lane, without submitting it.
static std::vector< Symbol > symbols_from_text(std::string_view text)
One parameterless symbol per character, each character being its own id.

Definition at line 28 of file RewriteOperator.hpp.


The documentation for this class was generated from the following files: