Skip to content

Commit

Permalink
Fix arguments interface to respect pythonOperandOrder.
Browse files Browse the repository at this point in the history
  • Loading branch information
BowenBao committed Jul 20, 2018
1 parent fae5dc6 commit 1eb5183
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Documentation/current_iteration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ There is a breaking change in the **depth_to_space** and **space_to_depth** oper
the permutation for how the depth dimension is placed as blocks in the spatial dimensions, and vice-versa, has been changed. Please refer to the updated doc
examples for these two ops to see the change.

## Default arguments order
There is a breaking change in the **arguments** property in CNTK python API. The default behavior has been updated to return arguments in python order instead of in C++ order. This way it will return arguments in the same order as they are fed into ops. If you wish to still get arguments in C++ order, you can simply override the global option. This change should only affect the following ops: Times, TransposeTimes, and Gemm(internal).

## Bug fixes

Expand Down
28 changes: 25 additions & 3 deletions bindings/python/cntk/ops/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,31 @@ def type(self):
@typemap
def arguments(self):
'''
List of all input variables of the Function that are not of type Parameter or Constant
'''
return super(Function, self).arguments()
List of all input variables of the Function that are not of type Parameter or Constant.
Note that due to the different matrix storage format in C++(column major) and Python(row major),
the order of arguments for some ops(Times, TransposeTimes, and Gemm) in C++ and Python are not the same.
In previous CNTK versions, the default for this api was to return arguments in C++ order.
Now the default for this api is set to python order. This way it will return arguments in the same order as they are fed into ops.
If you wish to still get arguments in C++ order, you can simply override the global option.
Example:
>>> import cntk as C
>>> a = C.input_variable((3,4), name='a')
>>> b = C.input_variable((4,5), name='b')
>>> c = C.times(a, b)
>>> c.arguments # python order
(Input('a', [#], [3 x 4]), Input('b', [#], [4 x 5]))
>>> from cntk.default_options import set_global_option
>>> set_global_option('python_operand_order', False)
>>> c.arguments # C++ order
(Input('b', [#], [4 x 5]), Input('a', [#], [3 x 4]))
'''
from ..default_options import get_global_option
python_operand_order = get_global_option('python_operand_order', True)
return super(Function, self).arguments(python_operand_order)

@property
@typemap
Expand Down

0 comments on commit 1eb5183

Please sign in to comment.