lapspython.types
Implements types for parsed primitives and lambda expressions.
Classes
Abstract base class for program parsing. |
|
Abstract base class for python parsing. |
|
Abstract base class for R parsing. |
|
|
Class parsing primitives for translation to clean Python code. |
|
Class parsing primitives for translation to clean R code. |
|
Class parsing invented primitives for translation to Python. |
|
Class parsing invented primitives for translation to R. |
|
Class parsing synthesized programs. |
|
Class parsing synthesized programs. |
|
Class parsing synthesized programs. |
|
Data class containing parsed (invented) primitives. |
|
Data class containing the important specs of extracted frontiers. |
|
Class containing (compact) extracted frontiers. |
- class lapspython.types.ParsedType[source]
Abstract base class for program parsing.
- classmethod parse_argument_types(arg_types: dreamcoder.type.TypeConstructor) list[source]
Flatten inferred nested type structure of primitive.
- Parameters
arg_types (dreamcoder.type.TypeConstructor) – Inferred types.
- Returns
Flat list of inferred types.
- Return type
list
- class lapspython.types.ParsedPrimitive(primitive: dreamcoder.program.Primitive)[source]
Class parsing primitives for translation to clean Python code.
- parse_source(implementation) str[source]
Resolve lambdas and arguments to produce cleaner Python code.
- Parameters
implementation (callable) – The function referenced by primitive
- Returns
New source code
- Return type
string
- get_imports(implementation) set[source]
Find import modules that might be required by primitives.
- Parameters
implementation (function) – The function referenced by a primitive
- Returns
A set of module names as strings
- Return type
set
- get_dependencies(implementation) list[source]
Find functions called by primitives that are not built-ins.
- Parameters
implementation (function) – The function referenced by a primitive
- Returns
A list of (function name, source) tuples
- Return type
list
- resolve_lambdas() lapspython.types.ParsedPrimitive[source]
Remove lambda functions from source and extend list of arguments.
- Returns
New, cleaner parsed primitive
- Return type
- class lapspython.types.ParsedRPrimitive(primitive: dreamcoder.program.Primitive)[source]
Class parsing primitives for translation to clean R code.
- parse_source(name: str, path: str, is_dep=False) str[source]
Extract source code of primitive from R file.
- Parameters
handle (string) – Function name in source file.
- Returns
Source code of corresponding function.
- Return type
string
- get_imports(path) set[source]
Find import modules that might be required by primitives.
- Parameters
implementation (function) – The function referenced by a primitive
- Returns
A set of module names as strings
- Return type
set
- get_dependencies(implementation)[source]
Find functions called by primitives that are not built-ins.
- Parameters
implementation (function) – The function referenced by a primitive
- Returns
A list of (function name, source) tuples
- Return type
list
- get_args(header: str)[source]
Get list of arguments from function code.
- Parameters
source (string) – Function code
- resolve_lambdas() lapspython.types.ParsedRPrimitive[source]
No lambdas in R, but required for backwards compatibility.
- class lapspython.types.ParsedInvented(invented: dreamcoder.program.Invented, name: str)[source]
Class parsing invented primitives for translation to Python.
- class lapspython.types.ParsedRInvented(invented: dreamcoder.program.Invented, name: str)[source]
Class parsing invented primitives for translation to R.
- class lapspython.types.ParsedProgramBase(name: str, source: str, args: list, imports: set, dependencies: set)[source]
Class parsing synthesized programs.
- class lapspython.types.ParsedProgram(name: str, source: str, args: list, imports: set, dependencies: set)[source]
Class parsing synthesized programs.
- class lapspython.types.ParsedRProgram(name: str, source: str, args: list, imports: set, dependencies: set)[source]
Class parsing synthesized programs.
- class lapspython.types.ParsedGrammar(primitives: dict, invented: dict, mode: str = 'python')[source]
Data class containing parsed (invented) primitives.
- class lapspython.types.CompactFrontier(frontier: dreamcoder.frontier.Frontier, annotation: str = '')[source]
Data class containing the important specs of extracted frontiers.