File: no-python.m2

package info (click to toggle)
macaulay2 1.21%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 133,096 kB
  • sloc: cpp: 110,377; ansic: 16,306; javascript: 4,193; makefile: 3,821; sh: 3,580; lisp: 764; yacc: 590; xml: 177; python: 140; perl: 114; lex: 65; awk: 3
file content (111 lines) | stat: -rw-r--r-- 2,361 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
-- definitions for when Macaulay2 is built w/o Python support

exportFrom_Core {"PythonObject"}
export {
    "addPyToM2Function",
    "getattr",
    "getitem",
    "hasattr",
    "import",
    "pythonValue",
    "setattr",
    "setitem",
    "toFunction",
    "toPython",
    "objectType",
    "runSimpleString"}

errmsg = "Macaulay2 was built without Python support"
err = x -> error errmsg

addPyToM2Function = method()
addPyToM2Function(String, Function, String) :=
addPyToM2Function(List, Function, String) := err

getattr = method()
getattr(PythonObject, String) := err

getitem = method()
getitem(PythonObject, Thing) := err

hasattr = method()
hasattr(PythonObject, String) := err

import = method()
import String := err

iterator PythonObject := err

next PythonObject := err

pythonValue = method(Dispatch => Thing)
pythonValue String :=
pythonValue Sequence := err

setattr = method()
setattr(PythonObject, String, Thing) := err

setitem = method()
setitem(PythonObject, Thing, Thing) := err

toFunction = method()
toFunction PythonObject := err

toPython = method()
for type in {
    Boolean,
    CC,
    Constant,
    Function,
    HashTable,
    Nothing,
    PythonObject,
    QQ,
    RR,
    Sequence,
    Set,
    String,
    VisibleList,
    ZZ
    } do installMethod(toPython, type, err)

for op in {symbol +, symbol -, symbol *, symbol /, symbol //, symbol %,
    symbol ^, symbol <<, symbol >>, symbol &, symbol |, symbol ^^, symbol and,
    symbol or, symbol xor, symbol ==, symbol ?, symbol @} do (
    installMethod(op, PythonObject, PythonObject, err);
    installMethod(op, PythonObject, Thing, err);
    installMethod(op, Thing, PythonObject, err))

-- unary methods
for m in {
    length,
    value,
    symbol +,
    symbol -,
    abs,
    symbol ~,
    round,
    truncate,
    floor,
    ceiling,
    help#0
    } do installMethod(m, PythonObject, err)

-- binary methods (PythonObject, Thing)
for m in {
    symbol SPACE,
    symbol @@,
    symbol_,
    quotientRemainder
    } do installMethod(m, PythonObject, Thing, err)

-- others
member(Thing, PythonObject) :=
member(PythonObject, PythonObject) :=
quotientRemainder(PythonObject, PythonObject) :=
quotientRemainder(Thing, PythonObject) :=
round(ZZ, PythonObject) :=
round(PythonObject, PythonObject) := err

objectType = x -> error errmsg
runSimpleString = x -> error errmsg