Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small auto type inference improvement #68

Merged
merged 3 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>org.micro-manager.acqengj</groupId>
<artifactId>AcqEngJ</artifactId>
<version>0.5.4</version>
<version>0.5.5</version>
</dependency>
<dependency>
<groupId>org.micro-manager.ndviewer</groupId>
Expand Down
17 changes: 12 additions & 5 deletions pycromanager/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,18 @@ def _check_single_method_spec(method_spec, fn_args):
"""
if len(method_spec['arguments']) != len(fn_args):
return False
for arg_type, arg_val in zip(method_spec['arguments'], fn_args):
for arg_java_type, arg_val in zip(method_spec['arguments'], fn_args):
if isinstance(arg_val, JavaObjectShadow):
if arg_type not in arg_val._interfaces:
if arg_java_type not in arg_val._interfaces:
# check that it shadows object of the correct type
return False
elif type(arg_val) == np.ndarray:
# For ND Arrays, need to make sure data types match
if _ARRAY_TYPE_TO_NUMPY_DTYPE[arg_type] != arg_val.dtype:
if _ARRAY_TYPE_TO_NUMPY_DTYPE[arg_java_type] != arg_val.dtype:
return False
elif not isinstance(arg_val, _JAVA_TYPE_NAME_TO_PYTHON_TYPE[arg_type]) and \
not (arg_val is None and arg_type in _JAVA_NON_PRIMITIVES): #could be null if its an object
elif not any([isinstance(arg_val, acceptable_type) for acceptable_type in
_JAVA_TYPE_NAME_TO_CASTABLE_PYTHON_TYPE[arg_java_type]]) and \
not (arg_val is None and arg_java_type in _JAVA_NON_PRIMITIVES): #could be null if its an object
# if a type that gets converted
return False
return True
Expand Down Expand Up @@ -520,6 +521,12 @@ def _camel_case_2_snake_case(name):
'int': int, 'int[]': np.ndarray, 'java.lang.String': str,
'long': int, 'short': int, 'char': int, 'byte': int, 'void': None,
'java.lang.Object': object}
#type conversions that allow for autocasting
_JAVA_TYPE_NAME_TO_CASTABLE_PYTHON_TYPE = {'boolean': {bool}, 'byte[]': {np.ndarray},
'double': {float, int}, 'double[]': {np.ndarray}, 'float': {float},
'int': {int}, 'int[]': {np.ndarray}, 'java.lang.String': {str},
'long': {int}, 'short': {int}, 'char': {int}, 'byte': {int}, 'void': {None},
'java.lang.Object': {object}}
_JAVA_NON_PRIMITIVES = {'byte[]', 'double[]', 'int[]', 'java.lang.String', 'java.lang.Object'}

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pycromanager",
version="0.3.6",
version="0.3.7",
author="Henry Pinkard",
author_email="henry.pinkard@gmail.com",
description="Open source microscope control using python",
Expand Down