Vertex data: arrays

User 1867 | 5/2/2015, 4:32:25 PM

Is there an easy way to associate an array of information with each vertex? In my case, I'd like to associate an array of floats with each vertex and have fast random access to elements of this array.

Comments

User 91 | 5/4/2015, 5:28:57 PM

You can store arrays in a single column of an SArray. It should work pretty seamlessly.

` sf = gl.SFrame({'vid': [1,2,3], 'vertexarrayside_data': [[1,2,3], [4,5,6], [7,8,9]]}) print sf

Columns: vertexarrayside_data array vid int

Rows: 3

Data: +------------------------+-----+ | vertexarrayside_data | vid | +------------------------+-----+ | [1.0, 2.0, 3.0] | 1 | | [4.0, 5.0, 6.0] | 2 | | [7.0, 8.0, 9.0] | 3 | +------------------------+-----+ [3 rows x 2 columns] `

Now you can create an SGraph as follows:

` sg = gl.SGraph(sf, vid_field='vid') print sg.vertices

Columns: __id int vertexarrayside_data array

Rows: 3

Data: +------+------------------------+ | __id | vertexarrayside_data | +------+------------------------+ | 2 | [4.0, 5.0, 6.0] | | 3 | [7.0, 8.0, 9.0] | | 1 | [1.0, 2.0, 3.0] | +------+------------------------+ [3 rows x 2 columns] `


User 1867 | 5/5/2015, 10:18:07 PM

Thanks for the helpful reply!

We're working with the GraphLab Create SDK, and we seem to be encountering a race condition when our triple_apply function makes edits to this vector. Are lists (not list pointers, but lists themselves) protected by locks too?


User 1867 | 5/6/2015, 5:28:17 AM

Yeah, is it possible that when you have a list as a column of an SFrame, the pointer to the list is what gets locked/protected/copied over when you do a triple_apply?


User 1867 | 5/6/2015, 3:26:01 PM

Distilled the issue into something simpler in a toy example: you can ignore this, but could we get advice on http://forum.dato.com/discussion/1015/bug-in-triple-apply-missing-edge-updates#latest?

Thanks!


User 1190 | 5/6/2015, 3:56:08 PM

When you hold a triple, vertex data on both sides are protected. There are no race on the edge data because one edge is touched only once per triple_apply.