Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
46b19525
Commit
46b19525
authored
11 years ago
by
Joseph E. Gonzalez
Browse files
Options
Downloads
Patches
Plain Diff
Adding some additional graph generators to support unit testing of the analytics package.
parent
14a3329a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
graph/src/main/scala/org/apache/spark/graph/util/GraphGenerators.scala
+45
-1
45 additions, 1 deletion
...n/scala/org/apache/spark/graph/util/GraphGenerators.scala
with
45 additions
and
1 deletion
graph/src/main/scala/org/apache/spark/graph/util/GraphGenerators.scala
+
45
−
1
View file @
46b19525
...
...
@@ -236,7 +236,51 @@ object GraphGenerators {
}
}
}
/**
* Create `rows` by `cols` grid graph with each vertex connected to its
* row+1 and col+1 neighbors. Vertex ids are assigned in row major
* order.
*
* @param sc the spark context in which to construct the graph
* @param rows the number of rows
* @param cols the number of columns
*
* @return A graph containing vertices with the row and column ids
* as their attributes and edge values as 1.0.
*/
def
gridGraph
(
sc
:
SparkContext
,
rows
:
Int
,
cols
:
Int
)
:
Graph
[(
Int
,
Int
)
,
Double
]
=
{
// Convert row column address into vertex ids (row major order)
def
sub2ind
(
r
:
Int
,
c
:
Int
)
:
Vid
=
r
*
cols
+
c
val
vertices
:
RDD
[(
Vid
,
(
Int
,
Int
))]
=
sc
.
parallelize
(
0
until
rows
).
flatMap
(
r
=>
(
0
until
cols
).
map
(
c
=>
(
sub2ind
(
r
,
c
),
(
r
,
c
))
)
)
val
edges
:
RDD
[
Edge
[
Double
]]
=
vertices
.
flatMap
{
case
(
vid
,
(
r
,
c
))
=>
(
if
(
r
+
1
<
rows
)
{
Seq
(
(
sub2ind
(
r
,
c
),
sub2ind
(
r
+
1
,
c
)))
}
else
{
Seq
.
empty
})
++
(
if
(
c
+
1
<
cols
)
{
Seq
(
(
sub2ind
(
r
,
c
),
sub2ind
(
r
,
c
+
1
)))
}
else
{
Seq
.
empty
})
}.
map
{
case
(
src
,
dst
)
=>
Edge
(
src
,
dst
,
1.0
)
}
Graph
(
vertices
,
edges
)
}
// end of gridGraph
/**
* Create a star graph with vertex 0 being the center.
*
* @param sc the spark context in which to construct the graph
* @param the number of vertices in the star
*
* @return A star graph containing `nverts` vertices with vertex 0
* being the center vertex.
*/
def
starGraph
(
sc
:
SparkContext
,
nverts
:
Int
)
:
Graph
[
Int
,
Int
]
=
{
val
edges
:
RDD
[(
Vid
,
Vid
)]
=
sc
.
parallelize
(
1
until
nverts
).
map
(
vid
=>
(
vid
,
0
))
Graph
(
edges
,
false
)
}
// end of starGraph
}
// end of Graph Generators
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment