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
8d021b42
Commit
8d021b42
authored
11 years ago
by
Pillis
Browse files
Options
Downloads
Patches
Plain Diff
SPARK-961. Add a Vector.random() method - update 1
parent
18147190
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/src/main/scala/org/apache/spark/util/Vector.scala
+5
-1
5 additions, 1 deletion
core/src/main/scala/org/apache/spark/util/Vector.scala
core/src/test/scala/org/apache/spark/util/VectorSuite.scala
+7
-9
7 additions, 9 deletions
core/src/test/scala/org/apache/spark/util/VectorSuite.scala
with
12 additions
and
10 deletions
core/src/main/scala/org/apache/spark/util/Vector.scala
+
5
−
1
View file @
8d021b42
...
@@ -126,7 +126,11 @@ object Vector {
...
@@ -126,7 +126,11 @@ object Vector {
def
ones
(
length
:
Int
)
=
Vector
(
length
,
_
=>
1
)
def
ones
(
length
:
Int
)
=
Vector
(
length
,
_
=>
1
)
def
random
(
length
:
Int
,
random
:
Random
=
new
Random
())
=
Vector
(
length
,
_
=>
random
.
nextDouble
());
/**
* Creates this [[org.apache.spark.util.Vector]] of given length containing random numbers
* between 0.0 and 1.0. Optional [[scala.util.Random]] number generator can be provided.
*/
def
random
(
length
:
Int
,
random
:
Random
=
new
XORShiftRandom
())
=
Vector
(
length
,
_
=>
random
.
nextDouble
())
class
Multiplier
(
num
:
Double
)
{
class
Multiplier
(
num
:
Double
)
{
def
*
(
vec
:
Vector
)
=
vec
*
num
def
*
(
vec
:
Vector
)
=
vec
*
num
...
...
This diff is collapsed.
Click to expand it.
core/src/test/scala/org/apache/spark/util/VectorSuite.scala
+
7
−
9
View file @
8d021b42
...
@@ -27,20 +27,18 @@ import org.scalatest.FunSuite
...
@@ -27,20 +27,18 @@ import org.scalatest.FunSuite
class
VectorSuite
extends
FunSuite
{
class
VectorSuite
extends
FunSuite
{
def
verifyVector
(
vector
:
Vector
,
expectedLength
:
Int
)
=
{
def
verifyVector
(
vector
:
Vector
,
expectedLength
:
Int
)
=
{
assert
(
vector
.
length
==
expectedLength
);
// Array must be of expected length
assert
(
vector
.
length
==
expectedLength
)
assert
(
vector
.
length
==
vector
.
elements
.
distinct
.
length
);
// Values should not repeat
assert
(
vector
.
elements
.
min
>
0.0
)
assert
(
vector
.
sum
>
0
);
// All values must not be 0
assert
(
vector
.
elements
.
max
<
1.0
)
assert
(
vector
.
sum
<
vector
.
length
);
// All values must not be 1
assert
(
vector
.
elements
.
product
>
0
);
// No value is 0
}
}
test
(
"random with default random number generator"
)
{
test
(
"random with default random number generator"
)
{
val
vector100
=
Vector
.
random
(
100
)
;
val
vector100
=
Vector
.
random
(
100
)
verifyVector
(
vector100
,
100
)
;
verifyVector
(
vector100
,
100
)
}
}
test
(
"random with given random number generator"
)
{
test
(
"random with given random number generator"
)
{
val
vector100
=
Vector
.
random
(
100
,
new
Random
(
100
))
;
val
vector100
=
Vector
.
random
(
100
,
new
Random
(
100
))
verifyVector
(
vector100
,
100
)
;
verifyVector
(
vector100
,
100
)
}
}
}
}
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