Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sot-dyninv
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Stack Of Tasks
sot-dyninv
Commits
05d59878
Commit
05d59878
authored
14 years ago
by
Nicolas Mansard
Browse files
Options
Downloads
Patches
Plain Diff
New working version for shortcuts and matlab style display.
parent
0bf681ae
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/matlab.py
+19
-19
19 additions, 19 deletions
python/matlab.py
python/script_shortcuts.py
+74
-0
74 additions, 0 deletions
python/script_shortcuts.py
with
93 additions
and
19 deletions
python/matlab.py
+
19
−
19
View file @
05d59878
def
prettyDisp
(
self
):
print
matlab
(
self
.
value
)
from
dynamic_graph.signal_base
import
*
setattr
(
SignalBase
,
'
m
'
,
property
(
prettyDisp
))
print
(
'
Pretty matlab print set
'
)
def
pseudozero
(
prec
):
...
...
@@ -20,7 +13,7 @@ def pseudozero(prec):
class
matlab
:
prec
=
12
space
=
2
fullPrec
=
0
fullPrec
=
1e-5
def
__init__
(
self
,
obj
):
try
:
...
...
@@ -31,6 +24,7 @@ class matlab:
return
self
.
matlabFromVector
(
obj
)
except
:
pass
self
.
resstr
=
str
(
obj
)
def
__str__
(
self
):
return
self
.
resstr
...
...
@@ -44,17 +38,20 @@ class matlab:
for
v
in
A
:
lnstr
=
()
for
x
in
v
:
if
(
abs
(
x
)
<
self
.
fullPrec
):
curr
=
pseudozero
(
self
.
prec
)
if
(
abs
(
x
)
<
self
.
fullPrec
*
self
.
fullPrec
):
curr
=
'
0
'
else
:
curr
=
'
'
+
(
fm
%
x
)
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
'
resstr
=
'
[
...
\n
'
first
=
True
for
v
in
mstr
:
if
first
:
...
...
@@ -80,13 +77,16 @@ class matlab:
maxstr
=
0
vstr
=
(())
for
x
in
v
:
if
(
abs
(
x
)
<
self
.
fullPrec
):
curr
=
pseudozero
(
prec
)
else
:
curr
=
'
'
+
(
fm
%
x
)
if
(
maxstr
<
len
(
curr
)):
maxstr
=
len
(
curr
)
vstr
+=
(
curr
,)
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
=
'
[
'
...
...
This diff is collapsed.
Click to expand it.
python/script_shortcuts.py
0 → 100644
+
74
−
0
View file @
05d59878
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