NREL/OpenStudio — pull request #552 by mbadams5 (2013-10-04 14:04:12+00:00)
Title: Fix Matrix python swig

This fixes an issue with "__setitem__" and "__getitem__" in python swig of Matrix. This
fixes…

for "__setitem__"
Traceback (most recent call last):
File "", line 1, in
File "openstudioutilitiesdata.py", line 4094, in __setitem__
return _openstudioutilitiesdata.Matrix___setitem__(self, *args)
TypeError: Matrix___setitem__() takes exactly 4 arguments (3 given)

and for "__getitem__"
Traceback (most recent call last):
File "", line 1, in
File "openstudioutilitiesdata.py", line 3608, in __getitem__
return _openstudioutilitiesdata.Matrix___getitem__(self, *args)
TypeError: Matrix___getitem__() takes exactly 3 arguments (2 given)

in the following python code (start python interpreter, copy and paste following code, and it should reproduce errors)

=====CODE======
import sys
import os

path_to_build = 'path/to/your/build/directory'
path_to_python_files = 'OpenStudioCore-prefix/src/OpenStudioCore-build/Products/python'
append_path = os.path.join(path_to_build, path_to_python_files)
sys.path.append(append_path)

from openstudioutilitiescore import *
from openstudioutilitiesdata import *
from openstudioutilitiesgeometry import *
from openstudioutilities import *

m = Matrix(4,4,0)
print m[0,0] # should be 0
m[0,0] = 1
print m[0,0] # should be 1

=====CODE======

this is due to the fact that in m[0,0] = 1 the [0,0] is a tuple (0,0) and gets passed to swig as a tuple argument. The C++ code expects (unsigned int, unsigned int, double) so this converts the tuple to the appropriate C++ input.

This code should only affect python swig and shouldn't have unexpected python behavior, at least none has shown up in my testing.

@axelstudios @lefticus @kbenne @macumber