Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic-graph-python
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
Container Registry
Model registry
Operate
Environments
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
Guilhem Saurel
dynamic-graph-python
Commits
cd72626d
Commit
cd72626d
authored
14 years ago
by
Nicolas Mansard
Committed by
Nicolas Mansard
14 years ago
Browse files
Options
Downloads
Patches
Plain Diff
IVIGIT.
parent
330cb8db
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/CMakeLists.txt
+2
-0
2 additions, 0 deletions
src/CMakeLists.txt
src/dynamic_graph/matlab.py
+107
-0
107 additions, 0 deletions
src/dynamic_graph/matlab.py
src/dynamic_graph/script_shortcuts.py
+85
-0
85 additions, 0 deletions
src/dynamic_graph/script_shortcuts.py
with
194 additions
and
0 deletions
src/CMakeLists.txt
+
2
−
0
View file @
cd72626d
...
@@ -104,6 +104,8 @@ SET (PYTHON_SOURCES
...
@@ -104,6 +104,8 @@ SET (PYTHON_SOURCES
dynamic_graph/__init__.py
dynamic_graph/__init__.py
dynamic_graph/entity.py
dynamic_graph/entity.py
dynamic_graph/signal_base.py
dynamic_graph/signal_base.py
dynamic_graph/matlab.py
dynamic_graph/script_shortcuts.py
)
)
SET
(
PYTHON_SOURCES_FULLPATH
""
)
SET
(
PYTHON_SOURCES_FULLPATH
""
)
...
...
This diff is collapsed.
Click to expand it.
src/dynamic_graph/matlab.py
0 → 100644
+
107
−
0
View file @
cd72626d
# The matlab class is define to produce a nice rendering of vector and matrix
# signals. The class builds at construction a string from the display
# of the matrix/vector, and stores the string internally. The string can be recovered
# using the str() member.
# The statics prec, space and fullPrec can be used to modify the display.
def
pseudozero
(
prec
):
"""
Return a string with
'
0...
'
and enough space to fill prec cars.
"""
res
=
'
0...
'
for
i
in
range
(
2
,
prec
):
res
+=
'
'
return
res
class
matlab
:
prec
=
12
space
=
2
fullPrec
=
1e-5
def
__init__
(
self
,
obj
):
try
:
return
self
.
matlabFromMatrix
(
obj
)
except
:
pass
try
:
return
self
.
matlabFromVector
(
obj
)
except
:
pass
self
.
resstr
=
str
(
obj
)
def
__str__
(
self
):
return
self
.
resstr
def
matlabFromMatrix
(
self
,
A
):
nr
=
len
(
A
)
nc
=
len
(
A
[
0
]);
fm
=
'
%.
'
+
str
(
self
.
prec
)
+
'
f
'
maxstr
=
0
mstr
=
(())
for
v
in
A
:
lnstr
=
()
for
x
in
v
:
if
(
abs
(
x
)
<
self
.
fullPrec
*
self
.
fullPrec
):
curr
=
'
0
'
else
:
if
(
abs
(
x
)
<
self
.
fullPrec
):
curr
=
pseudozero
(
self
.
prec
)
else
:
curr
=
'
'
+
(
fm
%
x
)
if
(
maxstr
<
len
(
curr
)):
maxstr
=
len
(
curr
)
lnstr
+=
(
curr
,)
mstr
+=
(
lnstr
,)
maxstr
+=
self
.
space
resstr
=
'
[...
\n
'
first
=
True
for
v
in
mstr
:
if
first
:
first
=
False
;
else
:
resstr
+=
'
;
\n
'
firstC
=
True
for
x
in
v
:
if
firstC
:
firstC
=
False
else
:
resstr
+=
'
,
'
for
i
in
range
(
1
,
maxstr
-
len
(
x
)):
resstr
+=
'
'
resstr
+=
x
resstr
+=
'
];
'
self
.
resstr
=
resstr
def
matlabFromVector
(
self
,
v
):
nr
=
len
(
v
)
fm
=
'
%.
'
+
str
(
self
.
prec
)
+
'
f
'
maxstr
=
0
vstr
=
(())
for
x
in
v
:
if
(
abs
(
x
)
<
self
.
fullPrec
*
self
.
fullPrec
):
curr
=
'
0
'
else
:
if
(
abs
(
x
)
<
self
.
fullPrec
):
curr
=
pseudozero
(
self
.
prec
)
else
:
curr
=
'
'
+
(
fm
%
x
)
if
(
maxstr
<
len
(
curr
)):
maxstr
=
len
(
curr
)
vstr
+=
(
curr
,)
maxstr
+=
self
.
space
resstr
=
'
[
'
first
=
True
for
x
in
vstr
:
if
first
:
first
=
False
;
else
:
resstr
+=
'
,
'
for
i
in
range
(
1
,
maxstr
-
len
(
x
)):
resstr
+=
'
'
resstr
+=
x
resstr
+=
'
]
\'
;
'
self
.
resstr
=
resstr
This diff is collapsed.
Click to expand it.
src/dynamic_graph/script_shortcuts.py
0 → 100644
+
85
−
0
View file @
cd72626d
# Defines the following shortcuts:
# signal.name -> return the shortname
# signal -> display nicely the content of the signal
# signal(3) -> recompute the signal at time 3, and display nicely
# signal +1 -> increment the signal time of 1, recompute, and display.
# signal.deps -> display the graph dependancy up to the default value (3)
# signal.deps(6) -> same, but with depth = 6.
# entity -> same as print(entity)
# change the prompt to be '%'
from
dynamic_graph.signal_base
import
*
from
dynamic_graph.entity
import
*
from
matlab
import
matlab
# Enables shortcut "name"
def
sig_short_name
(
self
):
return
self
.
getName
().
split
(
'
:
'
)[
-
1
]
setattr
(
SignalBase
,
'
name
'
,
property
(
sig_short_name
))
# Enables shortcuts "m"
# This code implements a pseudo function 'm' in the class signal_base,
# with no args, or optional args. Three calls can be made:
# - sig.m : print the current value.
# - sig.m(time): recompute at given <time>, and display the current value
# - sig.m +time: recompute at <time> after current time, and display.
class
PrettySignalPrint
:
sig
=
None
def
__init__
(
self
,
sig
):
self
.
sig
=
sig
def
__repr__
(
self
):
return
str
(
matlab
(
self
.
sig
.
value
))
def
__call__
(
self
,
iter
):
self
.
sig
.
recompute
(
iter
)
return
self
def
__add__
(
self
,
iter
):
self
.
sig
.
recompute
(
self
.
sig
.
time
+
iter
)
return
self
def
sigMatPrint
(
sig
):
return
PrettySignalPrint
(
sig
)
setattr
(
SignalBase
,
'
m
'
,
property
(
PrettySignalPrint
))
print
(
'
Pretty matlab print set
'
)
# Enable the same as 'm', but directly on the signal object.
def
sigRepr
(
self
):
return
self
.
name
+
'
=
'
+
str
(
matlab
(
self
.
value
))
def
sigCall
(
sig
,
iter
):
sig
.
recompute
(
iter
)
print
sigRepr
(
sig
)
def
sigTimeIncr
(
sig
,
iter
):
sig
.
recompute
(
sig
.
time
+
iter
)
print
sigRepr
(
sig
)
setattr
(
SignalBase
,
'
__repr__
'
,
sigRepr
)
setattr
(
SignalBase
,
'
__call__
'
,
sigCall
)
setattr
(
SignalBase
,
'
__add__
'
,
sigTimeIncr
)
# Enables shortcut "deps"
# Implements the peudo function 'deps', that can be called without arg,
# or specifying a specific depth to be printed.
class
SignalDepPrint
:
defaultDepth
=
2
sig
=
None
def
__init__
(
self
,
sig
):
self
.
sig
=
sig
def
__repr__
(
self
):
return
self
.
sig
.
displayDependencies
(
self
.
defaultDepth
)
def
__call__
(
self
,
depth
):
self
.
defaultDepth
=
depth
return
self
setattr
(
SignalBase
,
'
deps
'
,
property
(
SignalDepPrint
))
setattr
(
Entity
,
'
__repr__
'
,
Entity
.
__str__
)
# Changing prompt
import
sys
sys
.
ps1
=
'
%
'
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