Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
is3-et-2a3-prognum-2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Francois Boulier
is3-et-2a3-prognum-2024
Commits
6069e871
Commit
6069e871
authored
5 months ago
by
Francois Boulier
Browse files
Options
Downloads
Patches
Plain Diff
Ajout de deux ressources
parent
2bd4ffaf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ressources/smoothing-splines.pdf
+0
-0
0 additions, 0 deletions
ressources/smoothing-splines.pdf
tp5-integration/code_generation.py
+93
-0
93 additions, 0 deletions
tp5-integration/code_generation.py
with
93 additions
and
0 deletions
ressources/smoothing-splines.pdf
0 → 100644
+
0
−
0
View file @
6069e871
File added
This diff is collapsed.
Click to expand it.
tp5-integration/code_generation.py
0 → 100755
+
93
−
0
View file @
6069e871
#!/bin/python3
# F. Boulier 2023
import
sympy
# Auxiliary function for Python code generation
# P : the expression for which code must be generated
# D0 : the dictionary of already computed expressions
# n0 : the number of the first free temporary variable
# tab : if True, generated expressions start with a four spaces tabulation
def
Python_aux
(
P
,
D0
,
n0
,
tab
,
mathlib
)
:
n
=
n0
D
=
D0
if
P
in
D
:
result
=
D
[
P
]
elif
isinstance
(
P
,
sympy
.
core
.
symbol
.
Symbol
)
:
result
=
P
elif
isinstance
(
P
,
sympy
.
core
.
Integer
)
or
\
isinstance
(
P
,
sympy
.
core
.
Rational
)
:
if
P
<
0
:
result
=
'
(%s)
'
%
str
(
P
)
else
:
result
=
P
elif
isinstance
(
P
,
sympy
.
core
.
Add
)
:
result
=
'
t%d
'
%
n
n
+=
1
L
=
[]
for
arg
in
P
.
args
:
tmp
,
D
,
n
=
Python_aux
(
arg
,
D
,
n
,
tab
,
mathlib
)
L
.
append
(
tmp
)
if
(
tab
)
:
print
(
'
'
*
4
,
end
=
''
)
print
(
result
,
'
=
'
,
end
=
'
'
)
for
i
in
range
(
0
,
len
(
L
)
-
1
)
:
print
(
L
[
i
],
'
+
'
,
end
=
'
'
)
print
(
L
[
-
1
])
elif
isinstance
(
P
,
sympy
.
core
.
Mul
)
:
result
=
'
t%d
'
%
n
n
+=
1
L
=
[]
for
arg
in
P
.
args
:
tmp
,
D
,
n
=
Python_aux
(
arg
,
D
,
n
,
tab
,
mathlib
)
L
.
append
(
tmp
)
if
(
tab
)
:
print
(
'
'
*
4
,
end
=
''
)
print
(
result
,
'
=
'
,
end
=
'
'
)
for
i
in
range
(
0
,
len
(
L
)
-
1
)
:
print
(
L
[
i
],
'
*
'
,
end
=
'
'
)
print
(
L
[
-
1
])
elif
isinstance
(
P
,
sympy
.
core
.
Pow
)
:
result
=
'
t%d
'
%
n
n
+=
1
tmp
,
D
,
n
=
Python_aux
(
P
.
args
[
0
],
D
,
n
,
tab
,
mathlib
)
if
(
tab
)
:
print
(
'
'
*
4
,
end
=
''
)
if
P
.
args
[
1
]
==
sympy
.
core
.
Rational
(
1
,
2
)
:
print
(
result
,
'
= %s.sqrt (
'
%
mathlib
,
tmp
,
'
)
'
,
sep
=
''
)
elif
P
.
args
[
1
]
==
sympy
.
core
.
Rational
(
-
1
,
2
)
:
print
(
result
,
'
= 1. / %s.sqrt (
'
%
mathlib
,
tmp
,
'
)
'
,
sep
=
''
)
elif
isinstance
(
P
.
args
[
1
],
sympy
.
core
.
Integer
)
and
P
.
args
[
1
]
>
0
:
print
(
result
,
'
=
'
,
tmp
,
'
**
'
,
P
.
args
[
1
],
sep
=
''
)
else
:
print
(
result
,
'
=
'
,
tmp
,
'
**(
'
,
P
.
args
[
1
],
'
)
'
,
sep
=
''
)
elif
isinstance
(
P
,
(
sympy
.
sin
,
sympy
.
asin
,
sympy
.
cos
,
sympy
.
acos
,
\
sympy
.
exp
,
sympy
.
log
,
sympy
.
tan
,
sympy
.
atan
,
\
sympy
.
sinh
,
sympy
.
asinh
,
sympy
.
cosh
,
sympy
.
acosh
,
\
sympy
.
tanh
,
sympy
.
atanh
,
sympy
.
sqrt
))
:
result
=
'
t%d
'
%
n
n
+=
1
tmp
,
D
,
n
=
Python_aux
(
P
.
args
[
0
],
D
,
n
,
tab
,
mathlib
)
if
(
tab
)
:
print
(
'
'
*
4
,
end
=
''
)
print
(
result
,
'
= %s.%s (
'
%
(
mathlib
,
P
.
func
.
__name__
),
tmp
,
'
)
'
,
sep
=
''
)
D
[
P
]
=
result
return
result
,
D
,
n
# Function for Python code generation in Python
# P : the expression for which code must be generated
# fname : if not None, the code is generated as a function with
# name fname and argument list argname (default None)
# argname : the argument list (default 'x')
# mathlib : the library name for functions such as sin, exp, atan, ...
def
Python
(
P
,
fname
=
None
,
argname
=
'
x
'
,
mathlib
=
'
math
'
)
:
if
not
fname
is
None
:
print
(
'
def %s (%s) :
'
%
(
str
(
fname
),
str
(
argname
)))
Python_aux
(
P
,
dict
(),
0
,
True
,
mathlib
)
print
(
'
'
*
4
,
'
return t0
'
,
sep
=
''
)
else
:
Python_aux
(
P
,
dict
(),
0
,
False
,
mathlib
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment