Dictionary for storing values with respect to two keys.
More...
#include <variable.h>
|
| | PairDict ()=default |
| | Default constructor.
|
| |
| | PairDict (const PairDict &)=default |
| | Copy constructor.
|
| |
| PairDict & | operator= (const PairDict &)=default |
| | Copy assignment operator.
|
| |
| | PairDict (PairDict &&) noexcept=default |
| | Move constructor.
|
| |
| PairDict & | operator= (PairDict &&) noexcept=default |
| | Move assignment operator.
|
| |
| | ~PairDict () noexcept=default |
| | Destructor.
|
| |
| T & | operator() (const std::string &key1, const std::string &key2) |
| | Access/modify value using two keys.
|
| |
| const T & | operator() (const std::string &key1, const std::string &key2) const |
| | Access value using two keys (const version)
|
| |
| bool | contains (const std::string &key1, const std::string &key2) const noexcept |
| | Check if a key pair exists.
|
| |
| size_t | size () const noexcept |
| | Get the size of the dictionary.
|
| |
| bool | empty () const noexcept |
| | Check if the dictionary is empty.
|
| |
| void | clear () |
| | Clear all entries.
|
| |
| auto | begin () |
| | Get iterator to beginning.
|
| |
| auto | begin () const |
| |
| auto | end () |
| | Get iterator to end.
|
| |
| auto | end () const |
| |
template<typename T>
class philote::PairDict< T >
Dictionary for storing values with respect to two keys.
Provides a cleaner interface for accessing values using two string keys, similar to Philote-Python's PairDict class. This is particularly useful for storing Jacobian/partial derivative values.
- Template Parameters
-
- Example: Using PairDict for Gradients
gradients("f", "x")(0) = 2.5;
gradients("f", "y")(0) = 3.7;
double df_dx = gradients("f", "x")(0);
}
Dictionary for storing values with respect to two keys.
Definition variable.h:292
bool contains(const std::string &key1, const std::string &key2) const noexcept
Check if a key pair exists.
Definition variable.h:355
A class for storing continuous and discrete variables.
Definition variable.h:85
- Example: Traditional Partials vs PairDict
partials[std::make_pair("output", "input")](0) = 1.5;
pair_partials("output", "input")(0) = 1.5;
PairDict< philote::Variable > PartialsPairDict
Definition variable.h:406
std::map< std::pair< std::string, std::string >, philote::Variable > Partials
Definition variable.h:405
- Note
- Thread Safety: This class is NOT thread-safe. The underlying std::map does not provide thread safety for concurrent modifications. If multiple threads need to access the same PairDict, external synchronization is required.
◆ PairDict() [1/3]
◆ PairDict() [2/3]
◆ PairDict() [3/3]
◆ ~PairDict()
◆ begin() [1/2]
Get iterator to beginning.
◆ begin() [2/2]
◆ clear()
◆ contains()
template<typename T >
| bool philote::PairDict< T >::contains |
( |
const std::string & |
key1, |
|
|
const std::string & |
key2 |
|
) |
| const |
|
inlinenoexcept |
Check if a key pair exists.
- Parameters
-
| key1 | First key |
| key2 | Second key |
- Returns
- true if the key pair exists
◆ empty()
Check if the dictionary is empty.
- Returns
- true if empty
◆ end() [1/2]
◆ end() [2/2]
◆ operator()() [1/2]
template<typename T >
| T & philote::PairDict< T >::operator() |
( |
const std::string & |
key1, |
|
|
const std::string & |
key2 |
|
) |
| |
|
inline |
Access/modify value using two keys.
- Parameters
-
| key1 | First key |
| key2 | Second key |
- Returns
- Reference to the value
◆ operator()() [2/2]
template<typename T >
| const T & philote::PairDict< T >::operator() |
( |
const std::string & |
key1, |
|
|
const std::string & |
key2 |
|
) |
| const |
|
inline |
Access value using two keys (const version)
- Parameters
-
| key1 | First key |
| key2 | Second key |
- Returns
- Const reference to the value
◆ operator=() [1/2]
Copy assignment operator.
◆ operator=() [2/2]
Move assignment operator.
◆ size()
Get the size of the dictionary.
- Returns
- Number of key-value pairs
The documentation for this class was generated from the following file:
- /home/runner/work/Philote-Cpp/Philote-Cpp/include/variable.h