-
Notifications
You must be signed in to change notification settings - Fork 201
module block proposal implementation #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KamikazeSquirrel
wants to merge
8
commits into
oracle:master
Choose a base branch
from
KamikazeSquirrel:moduleblock
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8088017
module block proposal implementation
KamikazeSquirrel 025617a
added performance testing
KamikazeSquirrel 48f99c3
first suggestion implementation
KamikazeSquirrel 823a95b
second suggestion implementation
KamikazeSquirrel 71c872c
added tests and contextOption for serialization api
KamikazeSquirrel e2e2500
api changes on deserialize
KamikazeSquirrel cd9e40b
serialization api String version and thread tests
KamikazeSquirrel 0eed18c
added node example
KamikazeSquirrel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...st/src/com/oracle/truffle/js/test/interop/resources/moduleblock/benchmark/kMeansModule.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. | ||
KamikazeSquirrel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* The Universal Permissive License (UPL), Version 1.0 | ||
* | ||
* Subject to the condition set forth below, permission is hereby granted to any | ||
* person obtaining a copy of this software, associated documentation and/or | ||
* data (collectively the "Software"), free of charge and under any and all | ||
* copyright rights in the Software, and any and all patent rights owned or | ||
* freely licensable by each licensor hereunder covering either (i) the | ||
* unmodified Software as contributed to or provided by such licensor, or (ii) | ||
* the Larger Works (as defined below), to deal in both | ||
* | ||
* (a) the Software, and | ||
* | ||
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if | ||
* one is included with the Software each a "Larger Work" to which the Software | ||
* is contributed by such licensors), | ||
* | ||
* without restriction, including without limitation the rights to copy, create | ||
* derivative works of, display, perform, and distribute the Software and make, | ||
* use, sell, offer for sale, import, export, have made, and have sold the | ||
* Software and the Larger Work(s), and to sublicense the foregoing rights on | ||
* either these or other terms. | ||
* | ||
* This license is subject to the following condition: | ||
* | ||
* The above copyright notice and either this complete permission notice or at a | ||
* minimum a reference to the UPL must be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
const N = 100000; // datapoints | ||
const K = 7; // cluster | ||
const SIZE = 600 // max data size | ||
|
||
const N_EXP = 20; // 20 runs | ||
|
||
const clusterX = new Array(K); | ||
const clusterY = new Array(K); | ||
|
||
const dataPointsX = new Array(N); | ||
const dataPointsY = new Array(N); | ||
const dataPointsCluster = new Array(N); | ||
|
||
function computeDist(x1, y1, x2, y2) { | ||
let dx = x1-x2; | ||
let dy = y1-y2; | ||
|
||
return dx * dx + dy * dy; | ||
} | ||
|
||
function getClosestCluster(x,y) { | ||
let minCluster=-1; | ||
let minDist = Number.MAX_VALUE; // set min to max dist | ||
|
||
for (let i = 0; i < K; i++) { | ||
let dist = computeDist(x,y,clusterX[i],clusterY[i]); | ||
|
||
if (dist < minDist) { | ||
minCluster=i; | ||
minDist = dist; | ||
} | ||
} | ||
|
||
return minCluster; | ||
} | ||
|
||
function computeCentroids() { | ||
let sumX = new Array(K); | ||
let sumY = new Array(K); | ||
let sumN = new Array(K); | ||
|
||
for (let i = 0; i < N; i++) { | ||
sumX[dataPointsCluster[i]] += dataPointsX[i]; | ||
sumY[dataPointsCluster[i]] += dataPointsY[i]; | ||
sumN[dataPointsCluster[i]]++; | ||
} | ||
|
||
for (let i = 0; i < K; i++) { | ||
if (sumN[i] != 0) { | ||
clusterX[i] = sumX[i] / sumN[i]; | ||
clusterY[i] = sumY[i] / sumN[i]; | ||
} | ||
} | ||
} | ||
|
||
function doNewClustering() { | ||
let stable = true; | ||
|
||
for (let i = 0; i < N; i++) { | ||
let closestCluster = getClosestCluster(dataPointsX[i],dataPointsY[i]); | ||
|
||
if (stable && dataPointsCluster[i] != closestCluster) { | ||
stable = false; | ||
} | ||
|
||
dataPointsCluster[i] = closestCluster; | ||
} | ||
|
||
return stable; | ||
} | ||
|
||
function doInitialClustering() { | ||
for (let i = 0; i < N; i++) { | ||
dataPointsCluster[i] = Math.floor(Math.random() * K); | ||
} | ||
} | ||
|
||
export function createRandomData() { | ||
for (let i = 0; i < N; i++) { | ||
dataPointsX[i] = Math.floor(Math.random() * SIZE); | ||
dataPointsY[i] = Math.floor(Math.random() * SIZE); | ||
} | ||
} | ||
|
||
export function cluster() { | ||
doInitialClustering(); | ||
|
||
computeCentroids(); | ||
|
||
let stable = false; | ||
|
||
while (!stable) { | ||
stable = doNewClustering(); | ||
computeCentroids(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.