|
| 1 | +"""Projective coordinate operation declarations.""" |
| 2 | + |
| 3 | +from collections.abc import Callable |
| 4 | +from typing import Any |
| 5 | + |
| 6 | +from jacobian._models import StrictModel |
| 7 | +from jacobian.catalog._examples import example |
| 8 | +from jacobian.catalog.models import MathTool, OperationExample |
| 9 | +from jacobian.math.projective_coords_ops._models import ( |
| 10 | + ChartTransitionRequest, |
| 11 | + ChartTransitionResult, |
| 12 | + RationalPointConstructRequest, |
| 13 | + RationalPointConstructResult, |
| 14 | + StandardChartRequest, |
| 15 | + StandardChartResult, |
| 16 | +) |
| 17 | +from jacobian.math.projective_coords_ops._operations import ( |
| 18 | + compute_chart_transition, |
| 19 | + compute_rational_point_construct, |
| 20 | + compute_standard_chart, |
| 21 | +) |
| 22 | + |
| 23 | + |
| 24 | +def _op[RequestT: StrictModel, ResultT: StrictModel]( |
| 25 | + operation_id: str, |
| 26 | + title: str, |
| 27 | + description: str, |
| 28 | + request_model: type[RequestT], |
| 29 | + result_model: type[ResultT], |
| 30 | + operation: Callable[[RequestT], ResultT], |
| 31 | + *tags: str, |
| 32 | + examples: tuple[OperationExample, ...] = (), |
| 33 | + version: str = "1", |
| 34 | +) -> MathTool[RequestT, ResultT]: |
| 35 | + return MathTool( |
| 36 | + operation_id=operation_id, |
| 37 | + version=version, |
| 38 | + title=title, |
| 39 | + description=description, |
| 40 | + request_type=request_model, |
| 41 | + result_type=result_model, |
| 42 | + run=operation, |
| 43 | + tags=tags, |
| 44 | + examples=examples, |
| 45 | + ) |
| 46 | + |
| 47 | + |
| 48 | +TOOLS: tuple[MathTool[Any, Any], ...] = ( |
| 49 | + _op( |
| 50 | + "projective.rational_point.construct", |
| 51 | + "Construct a canonical rational projective point", |
| 52 | + "Canonicalize a rational projective point by scaling so the first " |
| 53 | + "nonzero coordinate is 1.", |
| 54 | + RationalPointConstructRequest, |
| 55 | + RationalPointConstructResult, |
| 56 | + compute_rational_point_construct, |
| 57 | + "projective", |
| 58 | + "rational", |
| 59 | + "exact", |
| 60 | + examples=( |
| 61 | + example( |
| 62 | + "p1_point", |
| 63 | + "Construct [2 : 4] in P^1(Q).", |
| 64 | + { |
| 65 | + "coordinates": [ |
| 66 | + {"num": "2", "den": "1"}, |
| 67 | + {"num": "4", "den": "1"}, |
| 68 | + ], |
| 69 | + }, |
| 70 | + ), |
| 71 | + ), |
| 72 | + ), |
| 73 | + _op( |
| 74 | + "projective.standard_chart.compute", |
| 75 | + "Dehomogenize at a standard affine chart", |
| 76 | + "Dehomogenize a projective point at the given chart index by " |
| 77 | + "dividing all coordinates by that coordinate.", |
| 78 | + StandardChartRequest, |
| 79 | + StandardChartResult, |
| 80 | + compute_standard_chart, |
| 81 | + "projective", |
| 82 | + "affine-chart", |
| 83 | + "exact", |
| 84 | + examples=( |
| 85 | + example( |
| 86 | + "chart_0", |
| 87 | + "Dehomogenize [1 : 2 : 3] at chart 0.", |
| 88 | + { |
| 89 | + "point": { |
| 90 | + "coordinates": [ |
| 91 | + {"num": "1", "den": "1"}, |
| 92 | + {"num": "2", "den": "1"}, |
| 93 | + {"num": "3", "den": "1"}, |
| 94 | + ], |
| 95 | + }, |
| 96 | + "chart_index": 0, |
| 97 | + }, |
| 98 | + ), |
| 99 | + ), |
| 100 | + ), |
| 101 | + _op( |
| 102 | + "projective.chart_transition.compute", |
| 103 | + "Compute the transition map between two charts", |
| 104 | + "Compute the transition map from chart_i to chart_j for a projective " |
| 105 | + "point.", |
| 106 | + ChartTransitionRequest, |
| 107 | + ChartTransitionResult, |
| 108 | + compute_chart_transition, |
| 109 | + "projective", |
| 110 | + "chart-transition", |
| 111 | + "exact", |
| 112 | + examples=( |
| 113 | + example( |
| 114 | + "transition_0_to_1", |
| 115 | + "Transition from chart 0 to chart 1 for [1 : 2 : 3].", |
| 116 | + { |
| 117 | + "point": { |
| 118 | + "coordinates": [ |
| 119 | + {"num": "1", "den": "1"}, |
| 120 | + {"num": "2", "den": "1"}, |
| 121 | + {"num": "3", "den": "1"}, |
| 122 | + ], |
| 123 | + }, |
| 124 | + "chart_i": 0, |
| 125 | + "chart_j": 1, |
| 126 | + }, |
| 127 | + ), |
| 128 | + ), |
| 129 | + ), |
| 130 | +) |
| 131 | + |
| 132 | +__all__ = ["TOOLS"] |
0 commit comments