Skip to content

Commit

Permalink
Merging 'master' into 'wrap'
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Jul 11, 2021
2 parents 17842dc + 4c410fc commit 7b9928d
Show file tree
Hide file tree
Showing 37 changed files with 1,267 additions and 1,539 deletions.
2 changes: 1 addition & 1 deletion wrap/.github/workflows/linux-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion wrap/.github/workflows/macos-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion wrap/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ __pycache__/
# Files related to code coverage stats
**/.coverage

gtwrap/matlab_wrapper.tpl
gtwrap/matlab_wrapper/matlab_wrapper.tpl
2 changes: 1 addition & 1 deletion wrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if(NOT DEFINED GTWRAP_INCLUDE_NAME)
endif()

configure_file(${PROJECT_SOURCE_DIR}/templates/matlab_wrapper.tpl.in
${PROJECT_SOURCE_DIR}/gtwrap/matlab_wrapper.tpl)
${PROJECT_SOURCE_DIR}/gtwrap/matlab_wrapper/matlab_wrapper.tpl)

# Install the gtwrap python package as a directory so it can be found by CMake
# for wrapping.
Expand Down
8 changes: 5 additions & 3 deletions wrap/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ The python wrapper supports keyword arguments for functions/methods. Hence, the

- **DO NOT** re-define an overriden function already declared in the external (forward-declared) base class. This will cause an ambiguity problem in the Pybind header file.

- Splitting wrapper over multiple files
- The Pybind11 wrapper supports splitting the wrapping code over multiple files.
- To be able to use classes from another module, simply import the C++ header file in that wrapper file.
- Unfortunately, this means that aliases can no longer be used.
- Similarly, there can be multiple `preamble.h` and `specializations.h` files. Each of these should match the module file name.

### TODO
- Default values for arguments.
- WORKAROUND: make multiple versions of the same function for different configurations of default arguments.
- Handle `gtsam::Rot3M` conversions to quaternions.
- Parse return of const ref arguments.
- Parse `std::string` variants and convert directly to special string.
- Add enum support.
- Add generalized serialization support via `boost.serialization` with hooks to MATLAB save/load.
4 changes: 3 additions & 1 deletion wrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ Using `wrap` in your project is straightforward from here. In your `CMakeLists.t
```cmake
find_package(gtwrap)
set(interface_files ${PROJECT_SOURCE_DIR}/cpp/${PROJECT_NAME}.h)
pybind_wrap(${PROJECT_NAME}_py # target
${PROJECT_SOURCE_DIR}/cpp/${PROJECT_NAME}.h # interface header file
"${interface_files}" # list of interface header files
"${PROJECT_NAME}.cpp" # the generated cpp
"${PROJECT_NAME}" # module_name
"${PROJECT_MODULE_NAME}" # top namespace in the cpp file e.g. gtsam
Expand Down
2 changes: 1 addition & 1 deletion wrap/gtwrap/interface_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import sys

import pyparsing
import pyparsing # type: ignore

from .classes import *
from .declaration import *
Expand Down
12 changes: 6 additions & 6 deletions wrap/gtwrap/interface_parser/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from typing import Iterable, List, Union

from pyparsing import Literal, Optional, ZeroOrMore
from pyparsing import Literal, Optional, ZeroOrMore # type: ignore

from .enum import Enum
from .function import ArgumentList, ReturnType
Expand Down Expand Up @@ -233,7 +233,7 @@ def __init__(self,
self.static_methods = []
self.properties = []
self.operators = []
self.enums = []
self.enums: List[Enum] = []
for m in members:
if isinstance(m, Constructor):
self.ctors.append(m)
Expand Down Expand Up @@ -274,7 +274,7 @@ def __init__(self,

def __init__(
self,
template: Template,
template: Union[Template, None],
is_virtual: str,
name: str,
parent_class: list,
Expand All @@ -292,16 +292,16 @@ def __init__(
if parent_class:
# If it is in an iterable, extract the parent class.
if isinstance(parent_class, Iterable):
parent_class = parent_class[0]
parent_class = parent_class[0] # type: ignore

# If the base class is a TemplatedType,
# we want the instantiated Typename
if isinstance(parent_class, TemplatedType):
parent_class = parent_class.typename
parent_class = parent_class.typename # type: ignore

self.parent_class = parent_class
else:
self.parent_class = ''
self.parent_class = '' # type: ignore

self.ctors = ctors
self.methods = methods
Expand Down
2 changes: 1 addition & 1 deletion wrap/gtwrap/interface_parser/declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert
"""

from pyparsing import CharsNotIn, Optional
from pyparsing import CharsNotIn, Optional # type: ignore

from .tokens import (CLASS, COLON, INCLUDE, LOPBRACK, ROPBRACK, SEMI_COLON,
VIRTUAL)
Expand Down
2 changes: 1 addition & 1 deletion wrap/gtwrap/interface_parser/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Author: Varun Agrawal
"""

from pyparsing import delimitedList
from pyparsing import delimitedList # type: ignore

from .tokens import ENUM, IDENT, LBRACE, RBRACE, SEMI_COLON
from .type import Typename
Expand Down
12 changes: 6 additions & 6 deletions wrap/gtwrap/interface_parser/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert
"""

from typing import Iterable, List, Union
from typing import Any, Iterable, List, Union

from pyparsing import Optional, ParseResults, delimitedList
from pyparsing import Optional, ParseResults, delimitedList # type: ignore

from .template import Template
from .tokens import (COMMA, DEFAULT_ARG, EQUAL, IDENT, LOPBRACK, LPAREN, PAIR,
Expand Down Expand Up @@ -42,12 +42,12 @@ def __init__(self,
name: str,
default: ParseResults = None):
if isinstance(ctype, Iterable):
self.ctype = ctype[0]
self.ctype = ctype[0] # type: ignore
else:
self.ctype = ctype
self.name = name
self.default = default
self.parent = None # type: Union[ArgumentList, None]
self.parent: Union[ArgumentList, None] = None

def __repr__(self) -> str:
return self.to_cpp()
Expand All @@ -70,7 +70,7 @@ def __init__(self, args_list: List[Argument]):
arg.parent = self
# The parent object which contains the argument list
# E.g. Method, StaticMethod, Template, Constructor, GlobalFunction
self.parent = None
self.parent: Any = None

@staticmethod
def from_parse_result(parse_result: ParseResults):
Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(self, type1: Union[Type, TemplatedType], type2: Type):
self.type2 = type2
# The parent object which contains the return type
# E.g. Method, StaticMethod, Template, Constructor, GlobalFunction
self.parent = None
self.parent: Any = None

def is_void(self) -> bool:
"""
Expand Down
3 changes: 2 additions & 1 deletion wrap/gtwrap/interface_parser/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

# pylint: disable=unnecessary-lambda, unused-import, expression-not-assigned, no-else-return, protected-access, too-few-public-methods, too-many-arguments

from pyparsing import ParseResults, ZeroOrMore, cppStyleComment, stringEnd
from pyparsing import (ParseResults, ZeroOrMore, # type: ignore
cppStyleComment, stringEnd)

from .classes import Class
from .declaration import ForwardDeclaration, Include
Expand Down
6 changes: 3 additions & 3 deletions wrap/gtwrap/interface_parser/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from typing import List, Union

from pyparsing import Forward, ParseResults, ZeroOrMore
from pyparsing import Forward, ParseResults, ZeroOrMore # type: ignore

from .classes import Class, collect_namespaces
from .declaration import ForwardDeclaration, Include
Expand Down Expand Up @@ -93,7 +93,7 @@ def from_parse_result(t: ParseResults):
return Namespace(t.name, content)

def find_class_or_function(
self, typename: Typename) -> Union[Class, GlobalFunction]:
self, typename: Typename) -> Union[Class, GlobalFunction, ForwardDeclaration]:
"""
Find the Class or GlobalFunction object given its typename.
We have to traverse the tree of namespaces.
Expand All @@ -115,7 +115,7 @@ def find_class_or_function(
return res[0]

def top_level(self) -> "Namespace":
"""Return the top leve namespace."""
"""Return the top level namespace."""
if self.name == '' or self.parent == '':
return self
else:
Expand Down
4 changes: 2 additions & 2 deletions wrap/gtwrap/interface_parser/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

from typing import List

from pyparsing import Optional, ParseResults, delimitedList
from pyparsing import Optional, ParseResults, delimitedList # type: ignore

from .tokens import (EQUAL, IDENT, LBRACE, LOPBRACK, RBRACE, ROPBRACK,
SEMI_COLON, TEMPLATE, TYPEDEF)
from .type import Typename, TemplatedType
from .type import TemplatedType, Typename


class Template:
Expand Down
6 changes: 3 additions & 3 deletions wrap/gtwrap/interface_parser/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert
"""

from pyparsing import (Keyword, Literal, OneOrMore, Or, QuotedString, Suppress,
Word, alphanums, alphas, nestedExpr, nums,
originalTextFor, printables)
from pyparsing import (Keyword, Literal, OneOrMore, Or, # type: ignore
QuotedString, Suppress, Word, alphanums, alphas,
nestedExpr, nums, originalTextFor, printables)

# rule for identifiers (e.g. variable names)
IDENT = Word(alphas + '_', alphanums + '_') ^ Word(nums)
Expand Down
5 changes: 3 additions & 2 deletions wrap/gtwrap/interface_parser/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

from typing import Iterable, List, Union

from pyparsing import Forward, Optional, Or, ParseResults, delimitedList
from pyparsing import (Forward, Optional, Or, ParseResults, # type: ignore
delimitedList)

from .tokens import (BASIS_TYPES, CONST, IDENT, LOPBRACK, RAW_POINTER, REF,
ROPBRACK, SHARED_POINTER)
Expand Down Expand Up @@ -48,7 +49,7 @@ class Typename:

def __init__(self,
t: ParseResults,
instantiations: Union[tuple, list, str, ParseResults] = ()):
instantiations: Iterable[ParseResults] = ()):
self.name = t[-1] # the name is the last element in this list
self.namespaces = t[:-1]

Expand Down
6 changes: 4 additions & 2 deletions wrap/gtwrap/interface_parser/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
Author: Varun Agrawal, Gerry Chen
"""

from pyparsing import Optional, ParseResults
from typing import List

from pyparsing import Optional, ParseResults # type: ignore

from .tokens import DEFAULT_ARG, EQUAL, IDENT, SEMI_COLON
from .type import TemplatedType, Type
Expand Down Expand Up @@ -40,7 +42,7 @@ class Hello {
t.default[0] if isinstance(t.default, ParseResults) else None))

def __init__(self,
ctype: Type,
ctype: List[Type],
name: str,
default: ParseResults = None,
parent=''):
Expand Down
3 changes: 3 additions & 0 deletions wrap/gtwrap/matlab_wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Package to wrap C++ code to Matlab via MEX."""

from .wrapper import MatlabWrapper
Loading

0 comments on commit 7b9928d

Please sign in to comment.