Skip to content

Commit 58b26ca

Browse files
author
Joao Rui Leal
committed
bumped version to 2.3.0;
improved CGPrettyPrinter and changed installation path; Operation node stores the name in a unique_ptr
1 parent b0146ee commit 58b26ca

File tree

6 files changed

+109
-74
lines changed

6 files changed

+109
-74
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
1818

1919
PROJECT(cppadcg CXX C)
2020

21-
SET(cppadcg_version "2.2.0" )
21+
SET(cppadcg_version "2.3.0" )
2222
SET(cppadcg_url "https://github.com/joaoleal/CppADCodeGen" )
2323
SET(cppadcg_description "A C++ Algorithmic Differentiation Package with Source Code Generation" )
2424

@@ -111,7 +111,7 @@ SET(install_cppadcg_include_location "${CMAKE_INSTALL_PREFIX}/include/cppad")
111111
SET(install_cppad_include_location "${CMAKE_INSTALL_PREFIX}/include/cppad")
112112
SET(install_library_pkg_location "${CMAKE_INSTALL_PREFIX}/share/pkgconfig")
113113
SET(install_doc_location "${CMAKE_INSTALL_PREFIX}/share/doc/cppadcg")
114-
SET(install_python_location "${CMAKE_INSTALL_PREFIX}/share/cppad/cg/")
114+
SET(install_python_location "${CMAKE_INSTALL_PREFIX}/share/cppadcg/python")
115115

116116
# ----------------------------------------------------------------------------
117117
# Define some optional compiler flags

debian/changelog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
cppadcodegen (2.3.0-1) unstable; urgency=low
2+
3+
* added support for Clang/LLVM 5.0
4+
* use unique_ptr internally in additional locations
5+
* pretty printers for GDB
6+
7+
-- Joao Leal <[email protected]> Wed, 24 Jan 2018 13:00:00 +0000
8+
19
cppadcodegen (2.2.0-1) unstable; urgency=low
210

311
* initial work for multithreaded evaluation of Jacobians and Hessians

debian/control

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Build-Depends: debhelper (>= 5),
99
libattr1 (>= 1 ),
1010
cmake (>= 2.8),
1111
doxygen,
12-
cppad-dev (>= 20170000.3)|cppad (>= 20170000.3),
12+
cppad-dev (>= 20170000.3)|cppad (>= 2017.00.00.3),
1313
libadolc-dev,
1414
libclang-dev (>= 3.2) | libclang-3.6-dev | libclang-3.8-dev | libclang-4.0-dev,
1515
libeigen3-dev,
@@ -20,7 +20,7 @@ Package: cppadcodegen-dev
2020
Section: libdevel
2121
Architecture: any
2222
Depends: ${misc:Depends},
23-
cppad-dev (>= 20170000.3)|cppad (>= 20170000.3)
23+
cppad-dev (>= 20170000.3)|cppad (>= 2017.00.00.3)
2424
Suggests: libclang-dev (>= 3.2),
2525
llvm-4.0-dev,
2626
libeigen3-dev
@@ -30,4 +30,4 @@ Package: cppadcodegen-doc
3030
Section: doc
3131
Architecture: all
3232
Description: Documentation for CppADCodeGen
33-
HTML Documentation for CppADCodeGen package.
33+
HTML Documentation for CppADCodeGen package.

debian/cppadcodegen-dev.install

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
debian/tmp/usr/include/
22
debian/tmp/usr/share/pkgconfig/
3-
debian/tmp/usr/share/cppad/cg/
3+
debian/tmp/usr/share/cppadcg/

include/cppad/cg/operation_node.hpp

+29-38
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace cg {
2020

2121
/**
2222
* An operation node.
23-
*
23+
*
2424
* @author Joao Leal
2525
*/
2626
template<class Base>
@@ -35,7 +35,7 @@ class OperationNode {
3535
static const std::set<CGOpCode> CUSTOM_NODE_CLASS;
3636
private:
3737
/**
38-
* the source code handler that own this node
38+
* the source code handler that own this node
3939
* (only null for temporary OperationNodes)
4040
*/
4141
CodeHandler<Base>* handler_;
@@ -48,7 +48,7 @@ class OperationNode {
4848
*/
4949
std::vector<size_t> info_;
5050
/**
51-
* arguments required by the operation
51+
* arguments required by the operation
5252
* (empty for independent variables and possibly for the 1st assignment
5353
* of a dependent variable)
5454
*/
@@ -60,7 +60,7 @@ class OperationNode {
6060
/**
6161
* name for the result of this operation
6262
*/
63-
std::string* name_;
63+
std::unique_ptr<std::string> name_;
6464
public:
6565
/**
6666
* Changes the current operation type into an Alias.
@@ -72,14 +72,13 @@ class OperationNode {
7272
operation_ = CGOpCode::Alias;
7373
arguments_.resize(1);
7474
arguments_[0] = other;
75-
delete name_;
76-
name_ = nullptr;
75+
name_.reset();
7776
}
78-
77+
7978
/**
8079
* Provides the source code handler that owns this node.
8180
* It can only be null for temporary nodes.
82-
*
81+
*
8382
* @return a CodeHandler which owns this nodes memory (possibly null)
8483
*/
8584
inline CodeHandler<Base>* getCodeHandler() const {
@@ -96,7 +95,7 @@ class OperationNode {
9695

9796
/**
9897
* Changes the current operation type.
99-
* The previous operation information/options might also have to be
98+
* The previous operation information/options might also have to be
10099
* changed, use getInfo() to change it if required.
101100
* @param op the new operation type
102101
* @param arguments the arguments for the new operation
@@ -149,7 +148,7 @@ class OperationNode {
149148
* no name was assigned to this node yet
150149
*/
151150
inline const std::string* getName() const {
152-
return name_;
151+
return name_.get();
153152
}
154153

155154
/**
@@ -160,29 +159,28 @@ class OperationNode {
160159
if (name_ != nullptr)
161160
*name_ = name;
162161
else
163-
name_ = new std::string(name);
162+
name_.reset(new std::string(name));
164163
}
165164

166165
/**
167166
* Clears any name assigned to this node.
168167
*/
169168
inline void clearName() {
170-
delete name_;
171-
name_ = nullptr;
169+
name_.reset();
172170
}
173-
171+
174172
/**
175173
* Provides the index in CodeHandler which owns this OperationNode.
176-
* A value of std::numeric_limits<size_t>::max() means that it is not
174+
* A value of std::numeric_limits<size_t>::max() means that it is not
177175
* managed by any CodeHandler.
178176
* This value can change if its position changes in the CodeHandler.
179-
*
180-
* @return the index in the CodeHandler's array of managed nodes
177+
*
178+
* @return the index in the CodeHandler's array of managed nodes
181179
*/
182180
inline size_t getHandlerPosition() const {
183181
return pos_;
184182
}
185-
183+
186184
// argument iterators
187185

188186
inline iterator begin() {
@@ -232,13 +230,11 @@ class OperationNode {
232230
inline const_reverse_iterator crend() const noexcept {
233231
return arguments_.crend();
234232
}
235-
236-
inline virtual ~OperationNode() {
237-
delete name_;
238-
}
239-
233+
234+
inline virtual ~OperationNode() = default;
235+
240236
protected:
241-
237+
242238
inline OperationNode(const OperationNode& orig) :
243239
handler_(orig.handler_),
244240
operation_(orig.operation_),
@@ -252,8 +248,7 @@ class OperationNode {
252248
CGOpCode op) :
253249
handler_(handler),
254250
operation_(op),
255-
pos_(std::numeric_limits<size_t>::max()),
256-
name_(nullptr) {
251+
pos_(std::numeric_limits<size_t>::max()) {
257252
}
258253

259254
inline OperationNode(CodeHandler<Base>* handler,
@@ -262,8 +257,7 @@ class OperationNode {
262257
handler_(handler),
263258
operation_(op),
264259
arguments_ {arg},
265-
pos_(std::numeric_limits<size_t>::max()),
266-
name_(nullptr) {
260+
pos_(std::numeric_limits<size_t>::max()) {
267261
}
268262

269263
inline OperationNode(CodeHandler<Base>* handler,
@@ -272,8 +266,7 @@ class OperationNode {
272266
handler_(handler),
273267
operation_(op),
274268
arguments_(std::move(args)),
275-
pos_(std::numeric_limits<size_t>::max()),
276-
name_(nullptr) {
269+
pos_(std::numeric_limits<size_t>::max()) {
277270
}
278271

279272
inline OperationNode(CodeHandler<Base>* handler,
@@ -284,8 +277,7 @@ class OperationNode {
284277
operation_(op),
285278
info_(std::move(info)),
286279
arguments_(std::move(args)),
287-
pos_(std::numeric_limits<size_t>::max()),
288-
name_(nullptr) {
280+
pos_(std::numeric_limits<size_t>::max()) {
289281
}
290282

291283
inline OperationNode(CodeHandler<Base>* handler,
@@ -296,10 +288,9 @@ class OperationNode {
296288
operation_(op),
297289
info_(info),
298290
arguments_(args),
299-
pos_(std::numeric_limits<size_t>::max()),
300-
name_(nullptr) {
291+
pos_(std::numeric_limits<size_t>::max()) {
301292
}
302-
293+
303294
inline void setHandlerPosition(size_t pos) {
304295
pos_ = pos;
305296
}
@@ -308,15 +299,15 @@ class OperationNode {
308299

309300
/**
310301
* Creates a temporary operation node.
311-
*
302+
*
312303
* @warning This node should never be provided to a CodeHandler.
313304
*/
314305
static std::unique_ptr<OperationNode<Base>> makeTemporaryNode(CGOpCode op,
315306
const std::vector<size_t>& info,
316307
const std::vector<Argument<Base> >& args) {
317308
return std::unique_ptr<OperationNode<Base>> (new OperationNode<Base>(nullptr, op, info, args));
318309
}
319-
310+
320311
protected:
321312
static inline std::set<CGOpCode> makeCustomNodeClassesSet();
322313

@@ -371,4 +362,4 @@ inline std::ostream& operator<<(
371362
} // END cg namespace
372363
} // END CppAD namespace
373364

374-
#endif
365+
#endif

python/gdb/cppadcg/CGPrettyPrinter.py

+66-30
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,88 @@
1-
'''
2-
* --------------------------------------------------------------------------
3-
* CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
4-
* Copyright (C) 2018 Ciengis
5-
*
6-
* CppADCodeGen is distributed under multiple licenses:
7-
*
8-
* - Eclipse Public License Version 1.0 (EPL1), and
9-
* - GNU General Public License Version 3 (GPL3).
10-
*
11-
* EPL1 terms and conditions can be found in the file "epl-v10.txt", while
12-
* terms and conditions for the GPL3 can be found in the file "gpl3.txt".
13-
* ----------------------------------------------------------------------------
14-
* Author: Joao Leal
15-
'''
1+
# * --------------------------------------------------------------------------
2+
# * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
3+
# * Copyright (C) 2018 Ciengis
4+
# *
5+
# * CppADCodeGen is distributed under multiple licenses:
6+
# *
7+
# * - Eclipse Public License Version 1.0 (EPL1), and
8+
# * - GNU General Public License Version 3 (GPL3).
9+
# *
10+
# * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
11+
# * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
12+
# * ----------------------------------------------------------------------------
13+
# * Author: Joao Leal
14+
1615
import gdb
1716

1817

18+
def is_null(value_ptr):
19+
if value_ptr.type.code == gdb.TYPE_CODE_PTR:
20+
value_str = str(value_ptr)
21+
return value_str == '0x0' or value_str == 'NULL'
22+
else:
23+
return False
24+
25+
26+
def get_smart_ptr_val(smart_ptr):
27+
pointer = smart_ptr['_M_t']['_M_t']['_M_head_impl']
28+
if is_null(pointer):
29+
return None
30+
else:
31+
return pointer.dereference()
32+
33+
1934
class CGPrettyPrinter:
2035
def __init__(self, val):
2136
self.val = val
2237

2338
def to_string(self):
24-
out = "CG:"
25-
2639
try:
2740
node_ptr = self.val['node_']
28-
if str(node_ptr) != 'NULL':
41+
if not is_null(node_ptr):
2942
node = node_ptr.dereference()
30-
if str(node['name_']) != '0x0' and str(node['name_']) != 'NULL':
31-
out += "\n name: " + str(node['name_'])
32-
out += "\n variable operation: " + str(node['operation_'])
33-
else:
34-
out += "\n <constant>"
3543

36-
# pointer to value
37-
pointer = self.val['value_']['_M_t']['_M_t']['_M_head_impl']
38-
if str(pointer) != 'NULL':
39-
out += "\n value: " + str(pointer.dereference())
44+
out = "variable CG ("
45+
46+
name = get_smart_ptr_val(node['name_'])
47+
if name is not None:
48+
out += "'" + str(name) + "', "
49+
out += str(node['operation_'])
50+
51+
value = get_smart_ptr_val(self.val['value_'])
52+
if value is not None:
53+
out += ", " + str(value)
54+
55+
out += ")"
56+
return out
57+
else:
58+
value = get_smart_ptr_val(self.val['value_'])
59+
return "constant CG (" + str(value) + ")"
4060

4161
except Exception as e:
4262
print('An exception occurred: {}'.format(e))
43-
except:
44-
print('An exception occurred')
4563

4664
return out
4765

4866
def children(self):
49-
return [('node', self.val['node_']), ('value', self.val['value_'])]
67+
c = []
68+
69+
# value
70+
value = get_smart_ptr_val(self.val['value_'])
71+
if value is not None:
72+
c.append(('value_', value))
73+
74+
# node
75+
node_ptr = self.val['node_']
76+
if not is_null(node_ptr):
77+
c.append(('node_', node_ptr.dereference()))
78+
79+
return c
80+
81+
def display_hint(self):
82+
if is_null(self.val['node_']):
83+
return 'string'
84+
else:
85+
return 'map'
5086

5187
###############################################################################
5288
#

0 commit comments

Comments
 (0)