User 1914 | 6/9/2015, 7:07:43 PM

I am trying to use g.triple_apply with externally declared global parameters and get the following error:

The code snippet is:

global n*components
global covars*
global means*
global cv*log*det*
global cv*chol*

def log*multivariate*normal*density*g (source*vertex, edge, target*vertex):
""" calculation of responsibilities for each edge in the graph
"""
n*dim = cv*chol*[c].shape[0]
X = source*vertex['features']
c = target_vertex['vertex*id']
cv*sol = linalg.solve*triangular(cv*chol*[c], (X - means*[c]).T, lower=True).T
edge['resp'] = - .5 * (np.sum(cv*sol ** 2) + n*dim * np.log(2 * np.pi) + cv*log*det*[c])
return (source*vertex, edge, target*vertex)
...
error occured at
217 g.triple*apply(log*multivariate*normal*density*g, mutated_fields=['resp'])

/usr/lib/python2.7/site-packages/graphlab/data*structures/sgraph.pyc in triple*apply(self, triple*apply*fn, mutated*fields, input*fields)
1018 else:
1019 with cython*context():
-> 1020 return SGraph(*proxy=g.**proxy**.lambda*triple*apply(triple*apply*fn, mutated_fields))

/usr/lib/python2.7/site-packages/graphlab/cython/context.pyc in **exit**(self, exc*type, exc*value, traceback)
29 def **exit**(self, exc*type, exc*value, traceback):
30 if not self.show*cython*trace and exc*type:
---> 31 raise exc*type(exc_value)

User 19 | 6/9/2015, 8:41:56 PM

Does it work when you remove the `cv_sol =...`

line and simply set `edge['resp']=1`

? After doing this, does it work when you don't set the other variables to be global?

User 1914 | 6/10/2015, 7:44:34 PM

Changed asa you suggested and no error anymore. However, I do need these global variables. The only other option would be to add them to all the vertices? They are fairly small 7 * 4 * 4 floats, compared to millions of vertices?

User 19 | 6/10/2015, 8:02:53 PM

The global variables should be fine to use. I wouldn't recommend adding them to the vertices. The global variable `a`

in this example works as expected:

```
`
import graphlab as gl
g = gl.SFrame({'i': range(10), 'j': [i+5 for i in range(10)]})
g = gl.SGraph().add_edges(g, 'i', 'j')
g.edges['sum'] = 0
```

global a a = [i for i in range(20)]

def fn(src, edge, dst): i = src['__id'] j = dst['__id']

```
edge['sum'] = i + j + a[i] + a[j]
return (src, edge, dst)
```

g2 = g.triple*apply(fn, ['sum'], ['sum'])
g2.edges
gives the following
Data:
+----------+----------+-----+
| __src*id | __dst_id | sum |
+----------+----------+-----+
| 5 | 10 | 30 |
| 8 | 13 | 42 |
| 7 | 12 | 38 |
| 0 | 5 | 10 |
| 2 | 7 | 18 |
| 9 | 14 | 46 |
| 6 | 11 | 34 |
| 3 | 8 | 22 |
| 1 | 6 | 14 |
| 4 | 9 | 26 |
+----------+----------+-----+
[10 rows x 3 columns]

```

So I would recommend working up from a small example like this. I suspect there are some inputs to `linalg.solve_triangular`

that are causing problems.