diff --git a/AirQuality_Taiwan_20180121/AirQualityTaiwan.js b/AirQuality_Taiwan_20180121/AirQualityTaiwan.js deleted file mode 100644 index 903936b720..0000000000 --- a/AirQuality_Taiwan_20180121/AirQualityTaiwan.js +++ /dev/null @@ -1,169 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var PM_data=""; - - function PM_gov_link(input_url_,input_format_) - { - if (input_format_=="JSON") - getJSON(input_url_); - else if (input_format_=="XML") - getXML(input_url_); - } - - function getXML(target) - { - if (window.XMLHttpRequest) - var xmlHttp = new XMLHttpRequest(); - else - var xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); - - xmlHttp.onreadystatechange = function() - { - if (this.readyState == 4 && this.status == 200) - { - var x = this.responseXML.getElementsByTagName("Data"); - PM_data = ""; - for (var i = 0; i - - JSON - - - https://opendata.epa.gov.tw/webapi/api/rest/datastore/355000000I-000259?sort=County - - - - - - - diff --git a/BlocklyduinoF2_LLM.gs b/BlocklyduinoF2_LLM.gs new file mode 100644 index 0000000000..202f727dad --- /dev/null +++ b/BlocklyduinoF2_LLM.gs @@ -0,0 +1,55 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2024/12/19 17:00 +https://www.facebook.com/francefu +Google Apps script & Custom Domain chat + +若傳訊無回應: +1. Custom Domain api額度已用盡或Key已失效。 +2. 不明原因,可能太久無人使用自動停用,重新佈署或重建Apps script專案並開放存取權限。 +3. Apps script程式碼有bug。 +4. 重新再傳訊一次。 +*/ + +function doPost(e) { + let response = ""; + if (e.postData) { + let domain = decodeURIComponent(e.parameter.domain)||""; + let path = decodeURIComponent(e.parameter.path)||""; + let model = decodeURIComponent(e.parameter.model)||""; + let key = decodeURIComponent(e.parameter.key)||""; + let role = decodeURIComponent(e.parameter.role)||""; + let message = decodeURIComponent(e.parameter.message)||""; + + response = sendMessageToOpenaiChat(domain, path, key, model, role, message); + } + return ContentService.createTextOutput(response); +} + +function sendMessageToOpenaiChat(domain, path, key, model, role, message){ + try { + let messages = [ + {"role": "system", "content": role}, + {"role": "user", "content": message} + ] + + let url = "https://"+domain+path; + + let data = { + "model": model, + "messages": messages + }; + + const authHeader = "Bearer "+key; + const options = { + headers: {Authorization: authHeader}, + method: 'POST', + contentType: 'application/json', + payload: JSON.stringify(data) + } + let response = UrlFetchApp.fetch(url, options); + let json = JSON.parse(response.getContentText()); + return json["choices"][0]["message"]["content"]; + } catch (error) { + return JSON.stringify(error); + } +} diff --git a/BlocklyduinoF2_dvcbot.gs b/BlocklyduinoF2_dvcbot.gs new file mode 100644 index 0000000000..2a27b7c22a --- /dev/null +++ b/BlocklyduinoF2_dvcbot.gs @@ -0,0 +1,208 @@ +/* + Author : ChungYi Fu (Kaohsiung, Taiwan) 2024/11/23 13:00 + https://www.facebook.com/francefu +*/ + +let dvcbot_apiKey = ""; +let dvcbot_assistantId = ""; + +let BASE_URL = "https://prod.dvcbot.net/api/assts/v1"; +let THREAD_URL = "https://prod.dvcbot.net/api/assts/v1/threads"; +let dvcbot_inputMsg = ""; + +function doPost(e) { + dvcbot_apiKey = decodeURIComponent(e.parameter.dvcbot_apiKey) || ""; + dvcbot_assistantId = decodeURIComponent(e.parameter.dvcbot_assistantId) || ""; + dvcbot_inputMsg = decodeURIComponent(e.parameter.dvcbot_inputMsg) || ""; + + var output = ContentService.createTextOutput(); + + const res = sendMessageToDvcbot(dvcbot_inputMsg) + .then(responseMsg => { + return responseMsg; + }) + .catch(error => { + return `Error: ${error}`; + }) + + res.then((promisedata) => { + output.append(promisedata); + }) + return output; +} + +async function sendMessageToDvcbot(inputMsg) { + return new Promise(async (resolve, reject) => { + const threadId = await createThread(); + const status = await addMessageToThread(threadId, inputMsg); + if (status == "completed") { + const runId = await runAssistant(threadId, dvcbot_assistantId); + const runUrl = `${BASE_URL}/threads/${threadId}/runs`; + await getRunResult(threadId, runUrl, runId); + const responseMsg = await listMessage(threadId); + resolve(responseMsg); + } else { + reject("Thread state is not completed"); + } + }); +} + +async function createThread() { + return new Promise((resolve, reject) => { + let res = UrlFetchApp.fetch(THREAD_URL, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post' + }); + let json = JSON.parse(res.getContentText()); + resolve(json.id); + }); +} + +async function addMessageToThread(threadId, inputMsg) { + return new Promise((resolve, reject) => { + const msgUrl = `${BASE_URL}/threads/${threadId}/messages`; + const createMsgData = { + role: "user", + content: inputMsg + }; + let res = UrlFetchApp.fetch(msgUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': JSON.stringify(createMsgData) + }); + + let json = JSON.parse(res.getContentText()); + resolve(json.status); + }); +} + +async function runAssistant(threadId, dvcbot_assistantId) { + return new Promise((resolve, reject) => { + const runUrl = `${BASE_URL}/threads/${threadId}/runs`; + let now = new Date(); + const createRunData = { + assistant_id: dvcbot_assistantId, + additional_instructions: `The current time is: ${Utilities.formatDate(now, 'GMT+8', 'yyyy-MM-dd HH:mm:ss')}` + }; + let res = UrlFetchApp.fetch(runUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': JSON.stringify(createRunData) + }); + let json = JSON.parse(res.getContentText()); + resolve(json.id); + }); +} + +async function getRunResult(threadId, runUrl, runId) { + return new Promise((resolve, reject) => { + let runStatus = ""; + while (true) { + let res = UrlFetchApp.fetch(`${runUrl}/${runId}`, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'get' + }); + + if (res.getResponseCode() === 200) { + let response = JSON.parse(res.getContentText()); + runStatus = response.status; + const requiredAction = response.required_action; + + if (runStatus === "requires_action" && requiredAction) { + let toolOutputs = []; + const toolCalls = requiredAction.submit_tool_outputs.tool_calls; + for (let i = 0; i < toolCalls.length; i++) { + const funcName = toolCalls[i].function.name; + let args = toolCalls[i].function.arguments; + args = args.replace(/\\"/g, '"'); + const pluginApiUrl = `${BASE_URL}/pluginapi?tid=${threadId}&aid=${dvcbot_assistantId}&pid=${funcName}`; + + let toolRes = UrlFetchApp.fetch(pluginApiUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': args + }); + + let output = toolRes.getContentText().substring(0, 8000).replace(/"/g, '\\"'); + try { + output = JSON.stringify(JSON.parse(output)); + } catch (error) { + } + const callId = toolCalls[i].id; + + toolOutputs.push({ + tool_call_id: callId, + output: output + }); + } + + const submitToolOutputRunUrl = `${BASE_URL}/threads/${threadId}/runs/${runId}/submit_tool_outputs`; + const toolOutputsData = { + tool_outputs: toolOutputs + }; + + UrlFetchApp.fetch(submitToolOutputRunUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': JSON.stringify(toolOutputsData) + }); + + Utilities.sleep(1000); + } else if (runStatus === "completed") { + resolve(); + break; + } else { + Utilities.sleep(1000); + } + } else { + reject(`Error: ${res.getResponseCode()}`); + break; + } + } + }); +} + +async function listMessage(threadId) { + return new Promise((resolve, reject) => { + const msgUrl = `${BASE_URL}/threads/${threadId}/messages`; + let res = UrlFetchApp.fetch(msgUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'get' + }); + + if (res.getResponseCode() === 200) { + let response = JSON.parse(res.getContentText()); + resolve(response.data[0].content[0].text.value); + } else { + reject(`Error: ${res.getResponseCode()}`); + } + }); +} diff --git a/BlocklyduinoF2_dvcbot_linebot.gs b/BlocklyduinoF2_dvcbot_linebot.gs new file mode 100644 index 0000000000..da8f53c92b --- /dev/null +++ b/BlocklyduinoF2_dvcbot_linebot.gs @@ -0,0 +1,256 @@ +/* + Author : ChungYi Fu (Kaohsiung, Taiwan) 2024/11/23 13:00 + https://www.facebook.com/francefu + Using Apps Script to create a Line Bot Webhook for integrating with the DvcBot Assistant API. +*/ + +// Line Bot TOKEN +let channel_access_TOKEN = "xxxxx"; + +// DvcBot +let dvcbot_apiKey = "xxxxx"; +let dvcbot_assistantId = "xxxxx"; + +let BASE_URL = "https://prod.dvcbot.net/api/assts/v1"; +let THREAD_URL = "https://prod.dvcbot.net/api/assts/v1/threads"; + +let getLinebotData = { + "type": "", + "userMessage": "", + "userId": "", + "groupId": "", + "roomId": "", + "eventType": "", + "replyToken": "" +} + +function doPost(e) { + if (e.postData) { + let msg = JSON.parse(e.postData.contents); + if (msg && msg.events && msg.events.length > 0) { + for (var i = 0; i < msg.events.length; i++) { + getLinebotData.userMessage = msg.events[i].message.text.trim(); + getLinebotData.type = msg.events[i].type; + getLinebotData.userId = msg.events[i].source.userId; + getLinebotData.groupId = msg.events[i].source.groupId; + getLinebotData.roomId = msg.events[i].source.roomId; + getLinebotData.eventType = msg.events[i].source.type; + getLinebotData.replyToken = msg.events[i].replyToken; + + if (getLinebotData.type=="message") { + const res = sendMessageToDvcbot(getLinebotData.userMessage) + .then(responseMsg => { + return responseMsg; + }) + .catch(error => { + return `Error: ${error}`; + }) + + res.then((promisedata) => { + replyMessageToLineBot(channel_access_TOKEN, getLinebotData.replyToken, promisedata); + }) + } + } + } + } + return ContentService.createTextOutput("OK"); +} + +function replyMessageToLineBot(accessToken, replyToken, message) { + let url = 'https://api.line.me/v2/bot/message/reply'; + let replyMessage = [{ + "type": "text", + "text": message + }] + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': replyMessage + }), + }); +} + +async function sendMessageToDvcbot(inputMsg) { + return new Promise(async (resolve, reject) => { + try { + const threadId = await createThread(); + const status = await addMessageToThread(threadId, inputMsg); + if (status == "completed") { + const runId = await runAssistant(threadId, dvcbot_assistantId); + const runUrl = `${BASE_URL}/threads/${threadId}/runs`; + await getRunResult(threadId, runUrl, runId); + const responseMsg = await listMessage(threadId); + resolve(responseMsg); + } else { + reject("Thread state is not completed"); + } + } catch (error) { + reject("The state is not completed"); + } + }); +} + +async function createThread() { + return new Promise((resolve, reject) => { + let res = UrlFetchApp.fetch(THREAD_URL, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post' + }); + let json = JSON.parse(res.getContentText()); + resolve(json.id); + }); +} + +async function addMessageToThread(threadId, inputMsg) { + return new Promise((resolve, reject) => { + const msgUrl = `${BASE_URL}/threads/${threadId}/messages`; + const createMsgData = { + role: "user", + content: inputMsg + }; + let res = UrlFetchApp.fetch(msgUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': JSON.stringify(createMsgData) + }); + + let json = JSON.parse(res.getContentText()); + resolve(json.status); + }); +} + +async function runAssistant(threadId, dvcbot_assistantId) { + return new Promise((resolve, reject) => { + const runUrl = `${BASE_URL}/threads/${threadId}/runs`; + let now = new Date(); + const createRunData = { + assistant_id: dvcbot_assistantId, + additional_instructions: `The current time is: ${Utilities.formatDate(now, 'GMT+8', 'yyyy-MM-dd HH:mm:ss')}` + }; + let res = UrlFetchApp.fetch(runUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': JSON.stringify(createRunData) + }); + let json = JSON.parse(res.getContentText()); + resolve(json.id); + }); +} + +async function getRunResult(threadId, runUrl, runId) { + return new Promise((resolve, reject) => { + let runStatus = ""; + while (true) { + let res = UrlFetchApp.fetch(`${runUrl}/${runId}`, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'get' + }); + + if (res.getResponseCode() === 200) { + let response = JSON.parse(res.getContentText()); + runStatus = response.status; + const requiredAction = response.required_action; + + if (runStatus === "requires_action" && requiredAction) { + let toolOutputs = []; + const toolCalls = requiredAction.submit_tool_outputs.tool_calls; + for (let i = 0; i < toolCalls.length; i++) { + const funcName = toolCalls[i].function.name; + let args = toolCalls[i].function.arguments; + args = args.replace(/\\"/g, '"'); + const pluginApiUrl = `${BASE_URL}/pluginapi?tid=${threadId}&aid=${dvcbot_assistantId}&pid=${funcName}`; + + let toolRes = UrlFetchApp.fetch(pluginApiUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': args + }); + + let output = toolRes.getContentText().substring(0, 8000).replace(/"/g, '\\"'); + try { + output = JSON.stringify(JSON.parse(output)); + } catch (error) { + } + const callId = toolCalls[i].id; + + toolOutputs.push({ + tool_call_id: callId, + output: output + }); + } + + const submitToolOutputRunUrl = `${BASE_URL}/threads/${threadId}/runs/${runId}/submit_tool_outputs`; + const toolOutputsData = { + tool_outputs: toolOutputs + }; + + UrlFetchApp.fetch(submitToolOutputRunUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': JSON.stringify(toolOutputsData) + }); + + Utilities.sleep(1000); + } else if (runStatus === "completed") { + resolve(); + break; + } else { + Utilities.sleep(1000); + } + } else { + reject(`Error: ${res.getResponseCode()}`); + break; + } + } + }); +} + +async function listMessage(threadId) { + return new Promise((resolve, reject) => { + const msgUrl = `${BASE_URL}/threads/${threadId}/messages`; + let res = UrlFetchApp.fetch(msgUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'get' + }); + + if (res.getResponseCode() === 200) { + let response = JSON.parse(res.getContentText()); + resolve(response.data[0].content[0].text.value); + } else { + reject(`Error: ${res.getResponseCode()}`); + } + }); +} diff --git a/BlocklyduinoF2_gemini.gs b/BlocklyduinoF2_gemini.gs new file mode 100644 index 0000000000..628e9aacdf --- /dev/null +++ b/BlocklyduinoF2_gemini.gs @@ -0,0 +1,65 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2024/12/16 17:00 +https://www.facebook.com/francefu +Google Apps script & Gemini chat + +若傳訊無回應: +1. Gemini api額度已用盡或Key已失效。 +2. 不明原因,可能太久無人使用自動停用,重新佈署或重建Apps script專案並開放存取權限。 +3. Apps script程式碼有bug。 +4. 重新再傳訊一次。 +*/ + +function doPost(e) { + if (e.postData) { + let key = decodeURIComponent(e.parameter.key)||""; + let model = decodeURIComponent(e.parameter.model)||""; + let role = decodeURIComponent(e.parameter.role)||""; + let message = decodeURIComponent(e.parameter.message)||""; + + response = sendMessageToGeminiChat(key, model, role, message); + } + return ContentService.createTextOutput(response); +} + +function sendMessageToGeminiChat(key, model, role, message){ + try { + let url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${key}`; + let data = { + "contents": [ + { + "role": "model", + "parts":[ + { + "text": role + } + ] + }, + { + "role": "user", + "parts":[ + { + "text": message + } + ] + } + ] + }; + + const options = { + method: 'POST', + contentType: 'application/json; charset=utf-8', + payload: JSON.stringify(data) + } + + let response = UrlFetchApp.fetch(url, options); + let json = JSON.parse(response.getContentText()); + response = json["candidates"][0]["content"]["parts"][0]["text"]; + if (response == "null") + response = json["error"]["message"]; + + return response; + } catch (error) { + return JSON.stringify(error); + } +} \ No newline at end of file diff --git a/BlocklyduinoF2_openAI.gs b/BlocklyduinoF2_openAI.gs new file mode 100644 index 0000000000..6ff35f7279 --- /dev/null +++ b/BlocklyduinoF2_openAI.gs @@ -0,0 +1,53 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2024/12/16 17:00 +https://www.facebook.com/francefu +Google Apps script & openAI chat + +若傳訊無回應: +1. openAI api額度已用盡或Key已失效。 +2. 不明原因,可能太久無人使用自動停用,重新佈署或重建Apps script專案並開放存取權限。 +3. Apps script程式碼有bug。 +4. 重新再傳訊一次。 +*/ + +function doPost(e) { + let response = ""; + if (e.postData) { + let key = decodeURIComponent(e.parameter.key)||""; + let model = decodeURIComponent(e.parameter.model)||"gpt-4o-mini"; + let role = decodeURIComponent(e.parameter.role)||""; + let message = decodeURIComponent(e.parameter.message)||""; + + response = sendMessageToOpenaiChat(key, model, role, message); + } + return ContentService.createTextOutput(response); +} + +function sendMessageToOpenaiChat(key, model, role, message){ + try { + let messages = [ + {"role": "system", "content": role}, + {"role": "user", "content": message} + ] + + let url = "https://api.openai.com/v1/chat/completions"; + + let data = { + "model": model, + "messages": messages + }; + + const authHeader = "Bearer "+key; + const options = { + headers: {Authorization: authHeader}, + method: 'POST', + contentType: 'application/json', + payload: JSON.stringify(data) + } + let response = UrlFetchApp.fetch(url, options); + let json = JSON.parse(response.getContentText()); + return json["choices"][0]["message"]["content"]; + } catch (error) { + return JSON.stringify(error); + } +} diff --git a/DHTchart-20180103/DHT_chart.js b/DHTchart-20180103/DHT_chart.js deleted file mode 100644 index 8765fe4236..0000000000 --- a/DHTchart-20180103/DHT_chart.js +++ /dev/null @@ -1,167 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function checkDHTdataset(input_dataset_,input_count_){ - if ((input_dataset_.split(';')).length > (input_count_ + 1)) { - var outputdataset = ''; - input_dataset_ = input_dataset_.split(';'); - var i_start = input_dataset_.length - input_count_; - var i_end = input_dataset_.length - 1; - for (var i = i_start;i <= i_end;i++) { - outputdataset = outputdataset + input_dataset_[i - 1] + ';'; - } - } else { - outputdataset = input_dataset_; - } - return outputdataset; - } - - function createDHTchart(input_type_,input_value_,input_WIDTH_,input_HEIGHT_,input_TITLE_X_,input_TITLE_Y_) { - - var margin = {top: 50, right: 50, bottom: 70, left: 50}; - var width = input_WIDTH_ - margin.left - margin.right; - var height = input_HEIGHT_ - margin.top - margin.bottom; - - if (document.getElementById('fustyles_DHTchart')) - { - d3.selectAll("svg > *").remove(); - var svg = d3.select('#fustyles_DHTchart') - .attr('width', width + margin.left + margin.right) - .attr('height', height + margin.top + margin.bottom) - .append('g') - .attr('transform', `translate(${margin.left}, ${margin.top})`); - } - else - { - var sheet = document.createElement('style'); - sheet.innerHTML = "body {font-size: 100%;}\n" - + ".area1 {fill: red;}\n" - + ".area2 {fill: blue;}\n" - + ".line1 {fill: none;stroke: red;stroke-width: 2px;}\n" - + ".line2 {fill: none;stroke: blue;stroke-width: 2px;}\n" - + ".point1 {fill:red;stroke:red;}\n" - + ".point2 {fill:blue;stroke:blue;}"; - - document.head.appendChild(sheet); - - var svg = d3.select('body').append('svg') - .attr('id','fustyles_DHTchart') - .attr('width', width + margin.left + margin.right) - .attr('height', height + margin.top + margin.bottom) - .append('g') - .attr('transform', `translate(${margin.left}, ${margin.top})`); - } - - var string = "time,temperature,humidity\n"+input_value_.replace(/;/ig,"\n"); - var data = d3.csvParse(string); - - var parseTime = d3.timeParse("%H:%M:%S"); - - data.forEach(function(d){ - d.time = parseTime(d.time); - d.temperature = d.temperature; - d.humidity = d.humidity; - }); - - var xScale = d3.scaleTime().range([0, width]); - var yScale = d3.scaleLinear().range([height, 0]); - - xScale.domain(d3.extent(data, d => d.time)); - yScale.domain([0, 100]); - - if (input_type_=='AreaChart') - { - var area2 = d3.area() - .x(d => xScale(d.time)) - .y0(height) - .y1(d => yScale(d.humidity)); - - svg.append("path") - .data([data]) - .attr("class", "area2") - .attr("d", area2); - } - - var line2 = d3.line() - .x(d => xScale(d.time)) - .y(d => yScale(d.humidity)); - - svg.append('path') - .data([data]) - .attr('class', 'line2') - .attr('d', line2); - - if (input_type_=='AreaChart') - { - var area1 = d3.area() - .x(d => xScale(d.time)) - .y0(height) - .y1(d => yScale(d.temperature)); - - svg.append("path") - .data([data]) - .attr("class", "area1") - .attr("d", area1); - } - - var line1 = d3.line() - .x(d => xScale(d.time)) - .y(d => yScale(d.temperature)); - - svg.append('path') - .data([data]) - .attr('class', 'line1') - .attr('d', line1); - - svg.append("g") - .attr("transform", "translate(0," + height + ")") - .call(d3.axisBottom(xScale).tickFormat(d3.timeFormat("%H:%M:%S"))) - .selectAll("text") - .style("text-anchor", "end") - .attr("dx", "-.8em") - .attr("dy", ".15em") - .attr("transform", "rotate(-65)"); - - svg.append("text") - .attr("transform", "translate(" + (width+25) + " ," + (height-10) + ")") - .style("text-anchor", "middle") - .text(input_TITLE_X_); - - svg.append("g") - .call(d3.axisLeft(yScale)); - - svg.append("text") - .attr("y", -30 ) - .attr("x", 40 ) - .attr("dy", "1em") - .style("text-anchor", "middle") - .text(input_TITLE_Y_); - - data.forEach(function(d){ - svg.append('circle') - .attr("cx",xScale(d.time)) - .attr("cy",yScale(d.temperature)) - .attr("r",2) - .attr("title",'test') - .attr("class", "point1") - .append("svg:title") - .text(d.temperature); - - svg.append('circle') - .attr("cx",xScale(d.time)) - .attr("cy",yScale(d.humidity)) - .attr("r",2) - .attr("class", "point2") - .append("svg:title") - .text(d.humidity); - }); - - } - - window.createDHTchart = createDHTchart; - window.checkDHTdataset = checkDHTdataset; - -}(window, window.document)); diff --git a/DHTchart-20180103/blockly.json b/DHTchart-20180103/blockly.json deleted file mode 100644 index 33c8a0c884..0000000000 --- a/DHTchart-20180103/blockly.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "types": ["DHT_chart","DHT_datasetcheck","variables_set"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "DHT_chart.js", - "https://d3js.org/d3.v4.min.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/DHTchart-20180103/blockly/blocks.js b/DHTchart-20180103/blockly/blocks.js deleted file mode 100644 index 023e538497..0000000000 --- a/DHTchart-20180103/blockly/blocks.js +++ /dev/null @@ -1,52 +0,0 @@ -Blockly.Blocks['DHT_chart'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.BLOCK1_SHOW) - .appendField(new Blockly.FieldDropdown([["LineChart","LineChart"], ["AreaChart","AreaChart"]]), "type_"); - this.appendValueInput("value_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.VALUE_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("title_x_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TITLE_X_SHOW); - this.appendValueInput("title_y_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TITLE_Y_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setTooltip(''); - this.setColour(65); - this.setHelpUrl(mainUrl + 'basic/blockly/blockly-information.html' + utmUrl); - } -}; - -Blockly.Blocks['DHT_datasetcheck'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.BLOCK2_SHOW); - this.appendValueInput("dataset_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DATASET_SHOW); - this.appendValueInput("count_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COUNT_SHOW); - this.setOutput(true, null); - this.setTooltip(""); - this.setColour(65); - this.setHelpUrl(mainUrl + 'basic/blockly/blockly-information.html' + utmUrl); - } -}; diff --git a/DHTchart-20180103/blockly/javascript.js b/DHTchart-20180103/blockly/javascript.js deleted file mode 100644 index a4e8223931..0000000000 --- a/DHTchart-20180103/blockly/javascript.js +++ /dev/null @@ -1,17 +0,0 @@ -Blockly.JavaScript['DHT_chart'] = function (block) { - var dropdown_type_ = block.getFieldValue('type_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_title_x_ = Blockly.JavaScript.valueToCode(block, 'title_x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_title_y_ = Blockly.JavaScript.valueToCode(block, 'title_y_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'createDHTchart("' + dropdown_type_ + '",' + value_value_ + ','+ value_width_ + ',' + value_height_ + ',' + value_title_x_ + ',' + value_title_y_ + ');\n'; - return code; -}; - -Blockly.JavaScript['DHT_datasetcheck'] = function(block) { - var value_dataset_ = Blockly.JavaScript.valueToCode(block, 'dataset_', Blockly.JavaScript.ORDER_ATOMIC); - var value_count_ = Blockly.JavaScript.valueToCode(block, 'count_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'checkDHTdataset(' + value_dataset_ + ',' + value_count_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; diff --git a/DHTchart-20180103/blockly/msg/blocks/en.js b/DHTchart-20180103/blockly/msg/blocks/en.js deleted file mode 100644 index 7492c4ec13..0000000000 --- a/DHTchart-20180103/blockly/msg/blocks/en.js +++ /dev/null @@ -1,9 +0,0 @@ -Blockly.Msg.BLOCK1_SHOW = " DHT"; -Blockly.Msg.VALUE_SHOW = "dataset"; -Blockly.Msg.WIDTH_SHOW = "width"; -Blockly.Msg.HEIGHT_SHOW = "height"; -Blockly.Msg.TITLE_X_SHOW = "title_x"; -Blockly.Msg.TITLE_Y_SHOW = "title_y"; -Blockly.Msg.BLOCK2_SHOW = " Get"; -Blockly.Msg.DATASET_SHOW = "dataset"; -Blockly.Msg.COUNT_SHOW = "latest data"; diff --git a/DHTchart-20180103/blockly/msg/blocks/zh-hans.js b/DHTchart-20180103/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 29c64fdd67..0000000000 --- a/DHTchart-20180103/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,9 +0,0 @@ -Blockly.Msg.BLOCK1_SHOW = "温湿度"; -Blockly.Msg.VALUE_SHOW = "数据"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.TITLE_X_SHOW = "X轴名称"; -Blockly.Msg.TITLE_Y_SHOW = "Y轴名称"; -Blockly.Msg.BLOCK2_SHOW = "取得"; -Blockly.Msg.DATASET_SHOW = "数据"; -Blockly.Msg.COUNT_SHOW = "最新笔数"; diff --git a/DHTchart-20180103/blockly/msg/blocks/zh-hant.js b/DHTchart-20180103/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 70933f1683..0000000000 --- a/DHTchart-20180103/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,9 +0,0 @@ -Blockly.Msg.BLOCK1_SHOW = "溫濕度"; -Blockly.Msg.VALUE_SHOW = "數據"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.TITLE_X_SHOW = "X軸名稱"; -Blockly.Msg.TITLE_Y_SHOW = "Y軸名稱"; -Blockly.Msg.BLOCK2_SHOW = "取得"; -Blockly.Msg.DATASET_SHOW = "數據"; -Blockly.Msg.COUNT_SHOW = "最新筆數"; diff --git a/DHTchart-20180103/blockly/msg/en.js b/DHTchart-20180103/blockly/msg/en.js deleted file mode 100644 index b82203a6ac..0000000000 --- a/DHTchart-20180103/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catDHTchart = " DHT Chart"; diff --git a/DHTchart-20180103/blockly/msg/zh-hans.js b/DHTchart-20180103/blockly/msg/zh-hans.js deleted file mode 100644 index e41618d781..0000000000 --- a/DHTchart-20180103/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catDHTchart = "温湿度关係图"; diff --git a/DHTchart-20180103/blockly/msg/zh-hant.js b/DHTchart-20180103/blockly/msg/zh-hant.js deleted file mode 100644 index 8c93e451f7..0000000000 --- a/DHTchart-20180103/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catDHTchart = "溫濕度關係圖"; diff --git a/DHTchart-20180103/blockly/toolbox.xml b/DHTchart-20180103/blockly/toolbox.xml deleted file mode 100644 index e5db9785a7..0000000000 --- a/DHTchart-20180103/blockly/toolbox.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - Dataset - - - - - 00:00:00,30,60;00:00:01,20,80; - - - - - 20 - - - - - - - - LineChart - - - 00:00:00,30,60;00:00:01,20,80; - - - - - 600 - - - - - 300 - - - - - time - - - - - value - - - - - - - diff --git a/GameElements_20180822/blockly.json b/GameElements_20180822/blockly.json deleted file mode 100644 index 67188f5c61..0000000000 --- a/GameElements_20180822/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["canvas_create", "canvas_line", "canvas_rect", "canvas_arc", "canvas_img", "canvas_text", "canvas_clear", "canvas_delete", "image_create","image_set","image_get","image_delete","image_collision","image_boundary","image_boundary_collision","image_sys_get","image_onclick","mouse_coordinate_get","document_timer","document_timer_once","document_timer_stop"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameelements.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameElements_20180822/blockly/blocks.js b/GameElements_20180822/blockly/blocks.js deleted file mode 100644 index 93f5dc4d37..0000000000 --- a/GameElements_20180822/blockly/blocks.js +++ /dev/null @@ -1,474 +0,0 @@ -Blockly.Blocks['canvas_create'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_CREATE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_line'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_LINE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("x1_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X1_SHOW); - this.appendValueInput("y1_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y1_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_rect'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_RECT_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_arc'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_ARC_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("r_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_R_SHOW); - this.appendValueInput("sAngle_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SANGLE_SHOW); - this.appendValueInput("eAngle_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_EANGLE_SHOW); - this.appendValueInput("counterclockwise_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_img'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_IMG_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("sx_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SX_SHOW); - this.appendValueInput("sy_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SY_SHOW); - this.appendValueInput("swidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SWIDTH_SHOW); - this.appendValueInput("sheight_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SHEIGHT_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_text'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_TEXT_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("text_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_CONTEXT_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("fontname_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FONTNAME_SHOW); - this.appendValueInput("fontsize_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FONTSIZE_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_TEXTALIGN_SHOW) - .appendField(new Blockly.FieldDropdown([["start","start"], ["end","end"], ["center","center"], ["left","left"], ["right","right"]]), "textalign_"); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_clear'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_CLEAR_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_delete'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_DELETE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.IMAGE_CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"], ["opacity","opacity"], ["rotate","rotate"], ["rotateX","rotateX"], ["rotateY","rotateY"], ["rotateZ","rotateZ"], ["moveX","moveX"], ["moveY","moveY"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["id","id"], ["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"], ["opacity","opacity"], ["rotate","rotate"], ["rotateX","rotateX"], ["rotateY","rotateY"], ["rotateZ","rotateZ"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_boundary'] = { - init: function() { - this.appendValueInput("left_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.BOUNDARY_SHOW) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("top_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary_collision'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.BOUNDARY_COLLISION_SHOW) - .appendField(new Blockly.FieldDropdown([["up","up"], ["down","down"], ["left","left"], ["right","right"], ["any","any"]]), "property_"); - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_sys_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SYS_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["width","screen_width"], ["height","screen_height"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_onclick_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ONCLICK_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['mouse_coordinate_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MOUSE_COORDINATE_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["X","x"], ["Y","y"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['document_timer'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_once'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimerOnce'), 'fuTimerOnce_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_stop'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW) - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_'); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; diff --git a/GameElements_20180822/blockly/javascript.js b/GameElements_20180822/blockly/javascript.js deleted file mode 100644 index f9ce279287..0000000000 --- a/GameElements_20180822/blockly/javascript.js +++ /dev/null @@ -1,186 +0,0 @@ -Blockly.JavaScript['canvas_create'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_create("' + variable_fuGameElements_ + '",'+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_line'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x1_ = Blockly.JavaScript.valueToCode(block, 'x1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y1_ = Blockly.JavaScript.valueToCode(block, 'y1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_line("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_x1_ + ',' + value_y1_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_rect'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_rect("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_width_ + ',' + value_height_ + ',' + value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_arc'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_r_ = Blockly.JavaScript.valueToCode(block, 'r_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sAngle_ = Blockly.JavaScript.valueToCode(block, 'sAngle_', Blockly.JavaScript.ORDER_ATOMIC); - var value_eAngle_ = Blockly.JavaScript.valueToCode(block, 'eAngle_', Blockly.JavaScript.ORDER_ATOMIC); - var value_counterclockwise_ = Blockly.JavaScript.valueToCode(block, 'counterclockwise_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_arc("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_r_ + ',' + value_sAngle_ + ',' + value_eAngle_ + ',' + value_counterclockwise_ + ',' + value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_img'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sx_ = Blockly.JavaScript.valueToCode(block, 'sx_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sy_ = Blockly.JavaScript.valueToCode(block, 'sy_', Blockly.JavaScript.ORDER_ATOMIC); - var value_swidth_ = Blockly.JavaScript.valueToCode(block, 'swidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sheight_ = Blockly.JavaScript.valueToCode(block, 'sheight_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_img("' + variable_fuGameElements_ + '",' + value_url_ + ',' + value_sx_ + ','+ value_sy_ + ',' + value_swidth_ + ','+ value_sheight_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_width_ + ',' + value_height_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_text'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_text_ = Blockly.JavaScript.valueToCode(block, 'text_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontname_ = Blockly.JavaScript.valueToCode(block, 'fontname_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontsize_ = Blockly.JavaScript.valueToCode(block, 'fontsize_', Blockly.JavaScript.ORDER_ATOMIC); - var value_textalign_ = block.getFieldValue('textalign_'); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_text("' + variable_fuGameElements_ + '",' + value_text_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_fontname_ + ','+ value_fontsize_ + ',"' + value_textalign_ + '",'+ value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_clear'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'canvas_clear("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['canvas_delete'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'canvas_delete("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_boundary'] = function (block) { - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary(' + value_left_ + ',' + value_top_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_boundary_collision'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_boundary_collision(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_sys_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'image_sys_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_onclick_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_onclick_get(' + value_id_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['mouse_coordinate_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'mouse_coordinate_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['document_timer'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimer_+' = setInterval(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_once'] = function (block) { - var variable_fuTimerOnce_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimerOnce_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimerOnce_+' = setTimeout(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_stop'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var code = 'clearInterval(' + variable_fuTimer_ + ');\n'; - return code; -}; diff --git a/GameElements_20180822/blockly/msg/blocks/en.js b/GameElements_20180822/blockly/msg/blocks/en.js deleted file mode 100644 index 71ba16af27..0000000000 --- a/GameElements_20180822/blockly/msg/blocks/en.js +++ /dev/null @@ -1,48 +0,0 @@ -Blockly.Msg.CANVAS_CREATE_SHOW = "Canvas Create"; -Blockly.Msg.CANVAS_LINE_SHOW = "Canvas Line"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "Line Width"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "Canvas Rect"; -Blockly.Msg.CANVAS_ARC_SHOW = "Canvas Arc"; -Blockly.Msg.CANVAS_R_SHOW = "Radius"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "Start Diameter"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "End Diameter"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "Counterclockwise"; -Blockly.Msg.CANVAS_FILL_SHOW = "F"; -Blockly.Msg.CANVAS_IMG_SHOW = "Canvas Image"; -Blockly.Msg.CANVAS_SX_SHOW = "Crop x0"; -Blockly.Msg.CANVAS_SY_SHOW = "Crop y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "Crop Width"; -Blockly.Msg.CANVAS_sHEIGHT_SHOW = "Crop Height"; -Blockly.Msg.CANVAS_TEXT_SHOW ="Canvas Text"; -Blockly.Msg.CANVAS_CONTEXT_SHOW ="Context"; -Blockly.Msg.CANVAS_FONTNAME_SHOW ="Fontname"; -Blockly.Msg.CANVAS_FONTSIZE_SHOW ="Fontsize"; -Blockly.Msg.CANVAS_TEXTALIGN_SHOW ="Align"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "Canvas Clear"; -Blockly.Msg.CANVAS_DELETE_SHOW = "Canvas Delete"; -Blockly.Msg.IMAGE_CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Get Collision ID"; -Blockly.Msg.AND_SHOW = " And "; -Blockly.Msg.BOUNDARY_SHOW = "Set Screen Boundary"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "Get Collision with sides of screen "; -Blockly.Msg.SYS_GET_SHOW = "Get Screen"; -Blockly.Msg.ONCLICK_SHOW = "Get onClick"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "Get Mouse Coordinate"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "Timer Intervals(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "Timer Intervals(ms) Once"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "Timer Stop"; diff --git a/GameElements_20180822/blockly/msg/blocks/zh-hans.js b/GameElements_20180822/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 39bfa1a680..0000000000 --- a/GameElements_20180822/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,48 +0,0 @@ -Blockly.Msg.CANVAS_CREATE_SHOW = "画布 建立"; -Blockly.Msg.CANVAS_LINE_SHOW = "画布 画直线"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "宽度"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "画布 画矩形"; -Blockly.Msg.CANVAS_ARC_SHOW = "画布 画圆"; -Blockly.Msg.CANVAS_R_SHOW = "半径"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "起始径度"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "终止径度"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "顺时钟方向"; -Blockly.Msg.CANVAS_FILL_SHOW = "填满"; -Blockly.Msg.CANVAS_IMG_SHOW = "画布 贴图"; -Blockly.Msg.CANVAS_SX_SHOW = "剪裁x0"; -Blockly.Msg.CANVAS_SY_SHOW = "剪裁y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "剪裁宽度"; -Blockly.Msg.CANVAS_sHEIGHT_SHOW = "剪裁高度"; -Blockly.Msg.CANVAS_TEXT_SHOW ="画布 贴文字"; -Blockly.Msg.CANVAS_CONTEXT_SHOW ="文字"; -Blockly.Msg.CANVAS_FONTNAME_SHOW ="字型"; -Blockly.Msg.CANVAS_FONTSIZE_SHOW ="字型大小"; -Blockly.Msg.CANVAS_TEXTALIGN_SHOW ="对齐方式"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "画布 清除"; -Blockly.Msg.CANVAS_DELETE_SHOW = "画布 删除"; -Blockly.Msg.IMAGE_CREATE_SHOW = "图片 建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "网址来源"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.SET_SHOW = "图片 设定 "; -Blockly.Msg.GET_SHOW = "图片 取得 "; -Blockly.Msg.DELETE_SHOW = "图片 删除"; -Blockly.Msg.COLLISION_SHOW = "图片 取得接触状态 代码"; -Blockly.Msg.AND_SHOW = " 与 "; -Blockly.Msg.BOUNDARY_SHOW = "视窗 设定大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得 图片边界状态"; -Blockly.Msg.SYS_GET_SHOW = "取得 视窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得 图片点选状态"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得 滑鼠座标"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "计时器 间隔时间(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "计时器 间隔时间(ms)后执行一次"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "计时器 停止"; diff --git a/GameElements_20180822/blockly/msg/blocks/zh-hant.js b/GameElements_20180822/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 3bcc5c1e0e..0000000000 --- a/GameElements_20180822/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,48 +0,0 @@ -Blockly.Msg.CANVAS_CREATE_SHOW = "畫布 建立"; -Blockly.Msg.CANVAS_LINE_SHOW = "畫布 畫直線"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "寬度"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "畫布 畫矩形"; -Blockly.Msg.CANVAS_ARC_SHOW = "畫布 畫圓"; -Blockly.Msg.CANVAS_R_SHOW = "半徑"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "起始徑度"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "終止徑度"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "順時鐘方向"; -Blockly.Msg.CANVAS_FILL_SHOW = "填滿"; -Blockly.Msg.CANVAS_IMG_SHOW = "畫布 貼圖"; -Blockly.Msg.CANVAS_SX_SHOW = "剪裁x0"; -Blockly.Msg.CANVAS_SY_SHOW = "剪裁y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "剪裁寬度"; -Blockly.Msg.CANVAS_sHEIGHT_SHOW = "剪裁高度"; -Blockly.Msg.CANVAS_TEXT_SHOW ="畫布 貼文字"; -Blockly.Msg.CANVAS_CONTEXT_SHOW ="文字"; -Blockly.Msg.CANVAS_FONTNAME_SHOW ="字型"; -Blockly.Msg.CANVAS_FONTSIZE_SHOW ="字型大小"; -Blockly.Msg.CANVAS_TEXTALIGN_SHOW ="對齊方式"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "畫布 清除"; -Blockly.Msg.CANVAS_DELETE_SHOW = "畫布 刪除"; -Blockly.Msg.IMAGE_CREATE_SHOW = "圖片 建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "網址來源"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.SET_SHOW = "圖片 設定 "; -Blockly.Msg.GET_SHOW = "圖片 取得 "; -Blockly.Msg.DELETE_SHOW = "圖片 刪除"; -Blockly.Msg.COLLISION_SHOW = "圖片 取得接觸狀態 代碼"; -Blockly.Msg.AND_SHOW = " 與 "; -Blockly.Msg.BOUNDARY_SHOW = "視窗 設定大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得 圖片邊界狀態"; -Blockly.Msg.SYS_GET_SHOW = "取得 視窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得 圖片點選狀態"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得 滑鼠座標"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "計時器 間隔時間(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "計時器 間隔時間(ms)後執行一次"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "計時器 停止"; diff --git a/GameElements_20180822/blockly/msg/en.js b/GameElements_20180822/blockly/msg/en.js deleted file mode 100644 index d91df621b7..0000000000 --- a/GameElements_20180822/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "Game Elements"; diff --git a/GameElements_20180822/blockly/msg/zh-hans.js b/GameElements_20180822/blockly/msg/zh-hans.js deleted file mode 100644 index e338c4eb2d..0000000000 --- a/GameElements_20180822/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "游戏元素"; diff --git a/GameElements_20180822/blockly/msg/zh-hant.js b/GameElements_20180822/blockly/msg/zh-hant.js deleted file mode 100644 index f40b768d28..0000000000 --- a/GameElements_20180822/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "遊戲元素"; diff --git a/GameElements_20180822/blockly/toolbox.xml b/GameElements_20180822/blockly/toolbox.xml deleted file mode 100644 index fdf253647f..0000000000 --- a/GameElements_20180822/blockly/toolbox.xml +++ /dev/null @@ -1,359 +0,0 @@ - - - - - 500 - - - - - 500 - - - - - 0 - - - - - 100 - - - - - 0 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 100 - - - - - #ff0000 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 100 - - - - - FALSE - - - - - #ff0000 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 0 - - - - - 6.284 - - - - - FALSE - - - - - FALSE - - - - - #ff0000 - - - - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - Hello World - - - - - 0 - - - - - 100 - - - - - Arial - - - - - 30 - - - - - TRUE - - - - - #ff0000 - - - - - - - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - 100 - - - - - - - 1000 - - - - - - diff --git a/GameElements_20180822/gameelements.js b/GameElements_20180822/gameelements.js deleted file mode 100644 index 17202660d1..0000000000 --- a/GameElements_20180822/gameelements.js +++ /dev/null @@ -1,365 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var screen_width = 0; - var screen_height = 0; - var onclickid = ""; - var onclicktime = 200; - var onclicktimerid; - var mouse_x,mouse_y; - - function canvas_create(input_id ,input_width,input_height,input_left,input_top,input_zindex) { - if (document.getElementById("gamecanvas_"+input_id)) - { - document.getElementById("gamecanvas_"+input_id).setAttribute("width",input_width + 'px'); - document.getElementById("gamecanvas_"+input_id).setAttribute("height",input_height + 'px'); - document.getElementById("gamecanvas_"+input_id).style.left = input_left + 'px'; - document.getElementById("gamecanvas_"+input_id).style.top = input_top + 'px'; - document.getElementById("gamecanvas_"+input_id).style.zIndex = input_zindex; - } - else - { - var can = document.createElement('canvas'); - can.style.position = "absolute"; - can.id = "gamecanvas_"+input_id; - can.setAttribute("width",input_width + 'px'); - can.setAttribute("height",input_height + 'px'); - can.style.left = input_left + 'px'; - can.style.top = input_top + 'px'; - can.style.zIndex = input_zindex; - document.body.appendChild(can); - - var img = document.createElement('img'); - img.id = "gamecanvasimg"; - img.style.display = "none"; - document.body.appendChild(img); - } - } - - function canvas_line(input_id,input_linewidth,input_x0,input_y0,input_x1,input_y1,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.moveTo(input_x0,input_y0); - context.lineTo(input_x1,input_y1); - context.stroke(); - } - } - - function canvas_rect(input_id,input_linewidth,input_x0,input_y0,input_width,input_height,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.rect(input_x0,input_y0,input_width,input_height); - if (input_fill==0) - context.stroke(); - else - context.fill(); - } - } - - function canvas_arc(input_id,input_linewidth,input_x0,input_y0,input_r,input_sAngle,input_eAngle,input_counterclockwise,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.arc(input_x0,input_y0,input_r,input_sAngle,input_eAngle,input_counterclockwise); - if (input_fill==0) - context.stroke(); - else - context.fill(); - } - } - - function canvas_img(input_id,input_url,input_sx,input_sy,input_swidth,input_sheight,input_x0,input_y0,input_width,input_height) { - if (document.getElementById("gamecanvas_"+input_id)) { - var img = document.getElementById("gamecanvasimg"); - img.src = input_url; - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - if ((input_swidth>0)&&(input_sheight>0)) - context.drawImage(img,input_sx,input_sy,input_swidth,input_sheight,input_x0,input_y0,input_width,input_height); - else if (((input_swidth==0)||(input_sheight==0))&&((input_width>0)&&(input_height>0))) - context.drawImage(img,input_x0,input_y0,input_width,input_height); - else - context.drawImage(img,input_x0,input_y0); - } - } - - function canvas_text(input_id,input_text,input_x0,input_y0,input_fontname,input_fontsize,input_textalign,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.font = input_fontsize + 'px ' + input_fontname; - context.textAlign = input_textalign; - if (input_fill==0) - context.strokeText(input_text,input_x0,input_y0); - else - context.fillText(input_text,input_x0,input_y0); - } - } - - function canvas_clear(input_id) { - if (document.getElementById("gamecanvas_"+input_id)) { - var canvas = document.getElementById("gamecanvas_"+input_id); - var context = canvas.getContext("2d"); - context.clearRect(0, 0, canvas.width, canvas.height); - } - } - - function canvas_delete(input_id) { - if (document.getElementById("gamecanvas_"+input_id)) { - document.body.removeChild(document.getElementById("gamecanvas_"+input_id)); - } - } - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("gameimg_"+input_id)) - { - document.getElementById("gameimg_"+input_id).src = input_url; - document.getElementById("gameimg_"+input_id).style.width = input_width + 'px'; - document.getElementById("gameimg_"+input_id).style.height = input_height + 'px'; - document.getElementById("gameimg_"+input_id).style.left = input_left + 'px'; - document.getElementById("gameimg_"+input_id).style.top = input_top + 'px'; - document.getElementById("gameimg_"+input_id).style.zIndex = input_zindex; - if (input_display==0) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else - { - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "gameimg_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==0) - img.style.display = "none"; - else - img.style.display = "block"; - img.setAttribute("onclick", "javascript:image_onclickid_set(this);"); - document.body.appendChild(img); - } - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - document.getElementById("gameimg_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("gameimg_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("gameimg_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("gameimg_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("gameimg_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("gameimg_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==0) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else if (input_property=='opacity') - document.getElementById("gameimg_"+input_id).style.opacity = input_value; - else if (input_property=='rotate') - document.getElementById("gameimg_"+input_id).style.transform = "rotate("+input_value+"deg)"; - else if (input_property=='rotateX') - document.getElementById("gameimg_"+input_id).style.transform = "rotateX("+input_value+"deg)"; - else if (input_property=='rotateY') - document.getElementById("gameimg_"+input_id).style.transform = "rotateY("+input_value+"deg)"; - else if (input_property=='rotateZ') - document.getElementById("gameimg_"+input_id).style.transform = "rotateZ("+input_value+"deg)"; - else if (input_property=='moveX') - document.getElementById("gameimg_"+input_id).style.left = (Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,""))+Number(input_value))+"px"; - else if (input_property=='moveY') - document.getElementById("gameimg_"+input_id).style.top = (Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,""))+Number(input_value))+"px"; - } - } - - function image_get(input_id,input_property) { - if (input_property=='id') - { - if (document.getElementById("gameimg_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - return document.getElementById("gameimg_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='left') - return Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("gameimg_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("gameimg_"+input_id).style.display=="block") - return 1; - else - return 0; - } - else if (input_property=='opacity') - return document.getElementById("gameimg_"+input_id).style.opacity; - else if (input_property=='rotate') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateX') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateY') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateZ') - return document.getElementById("gameimg_"+input_id).style.transform; - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("gameimg_"+input_id)) - { - document.body.removeChild(document.getElementById("gameimg_"+input_id)); - } - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("gameimg_"+input_id1))&&(document.getElementById("gameimg_"+input_id2))) - { - var img1 = document.getElementById("gameimg_"+input_id1).style; - var img2 = document.getElementById("gameimg_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - function image_boundary(input_left,input_top) { - if (input_left>=0) screen_width = input_left; - if (input_top>=0) screen_height = input_top; - } - - function image_boundary_collision(input_id,input_property) { - if ((screen_width>0)||(screen_height>0)) - { - var left = Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - var width = Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - var top = Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - var height = Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - if (screen_width>0) - { - if (((input_property=="left")||(input_property=="any"))&&(left<=0)) return 1 - if (((input_property=="right")||(input_property=="any"))&&(left+width>=screen_width)) return 1 - } - if (screen_height>0) - { - if (((input_property=="up")||(input_property=="any"))&&(top<=0)) return 1 - if (((input_property=="down")||(input_property=="any"))&&(top+height>=screen_height)) return 1 - } - return 0; - } - else - return 0; - } - - function image_sys_get(input_property) { - if (input_property=='screen_width') - return screen_width; - else if (input_property=='screen_height') - return screen_height; - else - return; - } - - function image_onclickid_set(obj) { - clearTimeout(onclicktimerid); - onclickid=obj.id; - onclicktimerid=setTimeout('image_onclickid_clear()',onclicktime); - } - - function image_onclickid_clear() { - onclickid=""; - } - - function image_onclick_get(input_id) { - if (onclickid==("gameimg_"+input_id)) - { - onclickid=""; - return 1; - } - else - return 0; - } - - function mouse_coordinate_get(input_property) { - document.onmousemove = function(e){ - e=e||window.event; - mouse_x = e.pageX; - mouse_y = e.pageY; - } - if (input_property=="x") - return mouse_x; - else if (input_property=="y") - return mouse_y; - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - window.image_boundary = image_boundary; - window.image_boundary_collision = image_boundary_collision; - window.image_sys_get = image_sys_get; - window.image_onclickid_set = image_onclickid_set; - window.image_onclickid_clear = image_onclickid_clear; - window.image_onclick_get = image_onclick_get; - window.mouse_coordinate_get = mouse_coordinate_get; - window.canvas_create = canvas_create; - window.canvas_line = canvas_line; - window.canvas_rect = canvas_rect; - window.canvas_arc = canvas_arc; - window.canvas_img = canvas_img; - window.canvas_text = canvas_text; - window.canvas_clear = canvas_clear; - window.canvas_delete = canvas_delete; - -}(window, window.document)); diff --git a/GameElements_20180824/blockly.json b/GameElements_20180824/blockly.json deleted file mode 100644 index 9918a8fbaa..0000000000 --- a/GameElements_20180824/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["canvas_create", "canvas_line", "canvas_rect", "canvas_arc", "canvas_img", "canvas_text", "canvas_clear", "canvas_delete", "music_create","music_delete", "image_create","image_set","image_get","image_delete","image_collision","image_boundary","image_boundary_collision","image_sys_get","image_onclick","mouse_coordinate_get","document_timer","document_timer_once","document_timer_stop"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameelements.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameElements_20180824/blockly/blocks.js b/GameElements_20180824/blockly/blocks.js deleted file mode 100644 index 2947966c5c..0000000000 --- a/GameElements_20180824/blockly/blocks.js +++ /dev/null @@ -1,506 +0,0 @@ -Blockly.Blocks['music_create'] = { - init: function() { - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MUSIC_CREATE_SHOW) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("length_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MUSIC_LENGTH_SHOW); - this.appendValueInput("loop_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MUSIC_LOOP_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['music_delete'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.MUSIC_DELETE_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_create'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_CREATE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_line'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_LINE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("x1_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X1_SHOW); - this.appendValueInput("y1_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y1_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_rect'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_RECT_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_arc'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_ARC_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("r_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_R_SHOW); - this.appendValueInput("sAngle_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SANGLE_SHOW); - this.appendValueInput("eAngle_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_EANGLE_SHOW); - this.appendValueInput("counterclockwise_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_img'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_IMG_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("sx_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SX_SHOW); - this.appendValueInput("sy_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SY_SHOW); - this.appendValueInput("swidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SWIDTH_SHOW); - this.appendValueInput("sheight_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SHEIGHT_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_text'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_TEXT_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.appendValueInput("text_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_CONTEXT_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("fontname_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FONTNAME_SHOW); - this.appendValueInput("fontsize_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FONTSIZE_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_TEXTALIGN_SHOW) - .appendField(new Blockly.FieldDropdown([["start","start"], ["end","end"], ["center","center"], ["left","left"], ["right","right"]]), "textalign_"); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_clear'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_CLEAR_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_delete'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_DELETE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameElements'), 'fuGameElements_'); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.IMAGE_CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"], ["opacity","opacity"], ["rotate","rotate"], ["rotateX","rotateX"], ["rotateY","rotateY"], ["rotateZ","rotateZ"], ["moveX","moveX"], ["moveY","moveY"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["id","id"], ["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"], ["opacity","opacity"], ["rotate","rotate"], ["rotateX","rotateX"], ["rotateY","rotateY"], ["rotateZ","rotateZ"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_boundary'] = { - init: function() { - this.appendValueInput("left_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.BOUNDARY_SHOW) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("top_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary_collision'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.BOUNDARY_COLLISION_SHOW) - .appendField(new Blockly.FieldDropdown([["up","up"], ["down","down"], ["left","left"], ["right","right"], ["any","any"]]), "property_"); - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_sys_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SYS_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["width","screen_width"], ["height","screen_height"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_onclick_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ONCLICK_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['mouse_coordinate_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MOUSE_COORDINATE_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["X","x"], ["Y","y"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['document_timer'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_once'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimerOnce'), 'fuTimerOnce_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_stop'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW) - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_'); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; diff --git a/GameElements_20180824/blockly/javascript.js b/GameElements_20180824/blockly/javascript.js deleted file mode 100644 index 19edd31de0..0000000000 --- a/GameElements_20180824/blockly/javascript.js +++ /dev/null @@ -1,204 +0,0 @@ -Blockly.JavaScript['music_create'] = function (block) { - var value_url = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_length = Blockly.JavaScript.valueToCode(block, 'length_', Blockly.JavaScript.ORDER_ATOMIC); - var value_loop = Blockly.JavaScript.valueToCode(block, 'loop_', Blockly.JavaScript.ORDER_ATOMIC); - if ((value_loop=="true")&&(value_length>0)) - var code = 'music_create(' + value_url + ');\nvar musicTimer = setInterval(function(){\nmusic_create(' + value_url + ');},' + value_length + ');\n'; - else if ((value_loop=="false")&&(value_length>0)) - var code = 'music_create(' + value_url + ');\nvar musicTimer = setTimeout(function(){\nmusic_delete();},' + value_length + ');\n'; - else - var code = 'music_create(' + value_url + ');\n'; - return code; -}; - -Blockly.JavaScript['music_delete'] = function (block) { - var code = 'clearInterval(musicTimer);\nmusic_delete();\n'; - return code; -}; - -Blockly.JavaScript['canvas_create'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_create("' + variable_fuGameElements_ + '",'+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_line'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x1_ = Blockly.JavaScript.valueToCode(block, 'x1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y1_ = Blockly.JavaScript.valueToCode(block, 'y1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_line("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_x1_ + ',' + value_y1_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_rect'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_rect("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_width_ + ',' + value_height_ + ',' + value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_arc'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_r_ = Blockly.JavaScript.valueToCode(block, 'r_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sAngle_ = Blockly.JavaScript.valueToCode(block, 'sAngle_', Blockly.JavaScript.ORDER_ATOMIC); - var value_eAngle_ = Blockly.JavaScript.valueToCode(block, 'eAngle_', Blockly.JavaScript.ORDER_ATOMIC); - var value_counterclockwise_ = Blockly.JavaScript.valueToCode(block, 'counterclockwise_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_arc("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_r_ + ',' + value_sAngle_ + ',' + value_eAngle_ + ',' + value_counterclockwise_ + ',' + value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_img'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sx_ = Blockly.JavaScript.valueToCode(block, 'sx_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sy_ = Blockly.JavaScript.valueToCode(block, 'sy_', Blockly.JavaScript.ORDER_ATOMIC); - var value_swidth_ = Blockly.JavaScript.valueToCode(block, 'swidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sheight_ = Blockly.JavaScript.valueToCode(block, 'sheight_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_img("' + variable_fuGameElements_ + '",' + value_url_ + ',' + value_sx_ + ','+ value_sy_ + ',' + value_swidth_ + ','+ value_sheight_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_width_ + ',' + value_height_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_text'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_text_ = Blockly.JavaScript.valueToCode(block, 'text_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontname_ = Blockly.JavaScript.valueToCode(block, 'fontname_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontsize_ = Blockly.JavaScript.valueToCode(block, 'fontsize_', Blockly.JavaScript.ORDER_ATOMIC); - var value_textalign_ = block.getFieldValue('textalign_'); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_text("' + variable_fuGameElements_ + '",' + value_text_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_fontname_ + ','+ value_fontsize_ + ',"' + value_textalign_ + '",'+ value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_clear'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'canvas_clear("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['canvas_delete'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'canvas_delete("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_boundary'] = function (block) { - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary(' + value_left_ + ',' + value_top_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_boundary_collision'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_boundary_collision(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_sys_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'image_sys_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_onclick_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_onclick_get(' + value_id_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['mouse_coordinate_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'mouse_coordinate_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['document_timer'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimer_+' = setInterval(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_once'] = function (block) { - var variable_fuTimerOnce_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimerOnce_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimerOnce_+' = setTimeout(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_stop'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var code = 'clearInterval(' + variable_fuTimer_ + ');\n'; - return code; -}; diff --git a/GameElements_20180824/blockly/msg/blocks/en.js b/GameElements_20180824/blockly/msg/blocks/en.js deleted file mode 100644 index 44ac198b12..0000000000 --- a/GameElements_20180824/blockly/msg/blocks/en.js +++ /dev/null @@ -1,52 +0,0 @@ -Blockly.Msg.MUSIC_CREATE_SHOW ="Background Music Play"; -Blockly.Msg.MUSIC_LENGTH_SHOW ="Length(ms)"; -Blockly.Msg.MUSIC_LOOP_SHOW ="Loop"; -Blockly.Msg.MUSIC_DELETE_SHOW ="Background Music Stop"; -Blockly.Msg.CANVAS_CREATE_SHOW = "Canvas Create"; -Blockly.Msg.CANVAS_LINE_SHOW = "Canvas Line"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "Line Width"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "Canvas Rect"; -Blockly.Msg.CANVAS_ARC_SHOW = "Canvas Arc"; -Blockly.Msg.CANVAS_R_SHOW = "Radius"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "Start Diameter"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "End Diameter"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "Counterclockwise"; -Blockly.Msg.CANVAS_FILL_SHOW = "F"; -Blockly.Msg.CANVAS_IMG_SHOW = "Canvas Image"; -Blockly.Msg.CANVAS_SX_SHOW = "Crop x0"; -Blockly.Msg.CANVAS_SY_SHOW = "Crop y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "Crop Width"; -Blockly.Msg.CANVAS_SHEIGHT_SHOW = "Crop Height"; -Blockly.Msg.CANVAS_TEXT_SHOW ="Canvas Text"; -Blockly.Msg.CANVAS_CONTEXT_SHOW ="Context"; -Blockly.Msg.CANVAS_FONTNAME_SHOW ="Fontname"; -Blockly.Msg.CANVAS_FONTSIZE_SHOW ="Fontsize"; -Blockly.Msg.CANVAS_TEXTALIGN_SHOW ="Align"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "Canvas Clear"; -Blockly.Msg.CANVAS_DELETE_SHOW = "Canvas Delete"; -Blockly.Msg.IMAGE_CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Get Collision ID"; -Blockly.Msg.AND_SHOW = " And "; -Blockly.Msg.BOUNDARY_SHOW = "Set Screen Boundary"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "Get Collision with sides of screen "; -Blockly.Msg.SYS_GET_SHOW = "Get Screen"; -Blockly.Msg.ONCLICK_SHOW = "Get onClick"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "Get Mouse Coordinate"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "Timer Intervals(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "Timer Intervals(ms) Once"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "Timer Stop"; diff --git a/GameElements_20180824/blockly/msg/blocks/zh-hans.js b/GameElements_20180824/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 5b1319afda..0000000000 --- a/GameElements_20180824/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,52 +0,0 @@ -Blockly.Msg.MUSIC_CREATE_SHOW ="背景音乐 播放"; -Blockly.Msg.MUSIC_LENGTH_SHOW ="长度(ms)"; -Blockly.Msg.MUSIC_LOOP_SHOW ="循环"; -Blockly.Msg.MUSIC_DELETE_SHOW ="背景音乐 停止"; -Blockly.Msg.CANVAS_CREATE_SHOW = "画布 建立"; -Blockly.Msg.CANVAS_LINE_SHOW = "画布 画直线"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "宽度"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "画布 画矩形"; -Blockly.Msg.CANVAS_ARC_SHOW = "画布 画圆"; -Blockly.Msg.CANVAS_R_SHOW = "半径"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "起始径度"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "终止径度"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "顺时钟方向"; -Blockly.Msg.CANVAS_FILL_SHOW = "填满"; -Blockly.Msg.CANVAS_IMG_SHOW = "画布 贴图"; -Blockly.Msg.CANVAS_SX_SHOW = "剪裁x0"; -Blockly.Msg.CANVAS_SY_SHOW = "剪裁y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "剪裁宽度"; -Blockly.Msg.CANVAS_SHEIGHT_SHOW = "剪裁高度"; -Blockly.Msg.CANVAS_TEXT_SHOW ="画布 贴文字"; -Blockly.Msg.CANVAS_CONTEXT_SHOW ="文字"; -Blockly.Msg.CANVAS_FONTNAME_SHOW ="字型"; -Blockly.Msg.CANVAS_FONTSIZE_SHOW ="字型大小"; -Blockly.Msg.CANVAS_TEXTALIGN_SHOW ="对齐方式"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "画布 清除"; -Blockly.Msg.CANVAS_DELETE_SHOW = "画布 删除"; -Blockly.Msg.IMAGE_CREATE_SHOW = "图片 建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "网址来源"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.SET_SHOW = "图片 设定 "; -Blockly.Msg.GET_SHOW = "图片 取得 "; -Blockly.Msg.DELETE_SHOW = "图片 删除"; -Blockly.Msg.COLLISION_SHOW = "图片 取得接触状态 代码"; -Blockly.Msg.AND_SHOW = " 与 "; -Blockly.Msg.BOUNDARY_SHOW = "视窗 设定大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得 图片边界状态"; -Blockly.Msg.SYS_GET_SHOW = "取得 视窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得 图片点选状态"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得 滑鼠座标"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "计时器 间隔时间(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "计时器 间隔时间(ms)后执行一次"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "计时器 停止"; diff --git a/GameElements_20180824/blockly/msg/blocks/zh-hant.js b/GameElements_20180824/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 3db0de7439..0000000000 --- a/GameElements_20180824/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,52 +0,0 @@ -Blockly.Msg.MUSIC_CREATE_SHOW ="背景音樂 播放"; -Blockly.Msg.MUSIC_LENGTH_SHOW ="長度(ms)"; -Blockly.Msg.MUSIC_LOOP_SHOW ="循環"; -Blockly.Msg.MUSIC_DELETE_SHOW ="背景音樂 停止"; -Blockly.Msg.CANVAS_CREATE_SHOW = "畫布 建立"; -Blockly.Msg.CANVAS_LINE_SHOW = "畫布 畫直線"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "寬度"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "畫布 畫矩形"; -Blockly.Msg.CANVAS_ARC_SHOW = "畫布 畫圓"; -Blockly.Msg.CANVAS_R_SHOW = "半徑"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "起始徑度"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "終止徑度"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "順時鐘方向"; -Blockly.Msg.CANVAS_FILL_SHOW = "填滿"; -Blockly.Msg.CANVAS_IMG_SHOW = "畫布 貼圖"; -Blockly.Msg.CANVAS_SX_SHOW = "剪裁x0"; -Blockly.Msg.CANVAS_SY_SHOW = "剪裁y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "剪裁寬度"; -Blockly.Msg.CANVAS_SHEIGHT_SHOW = "剪裁高度"; -Blockly.Msg.CANVAS_TEXT_SHOW ="畫布 貼文字"; -Blockly.Msg.CANVAS_CONTEXT_SHOW ="文字"; -Blockly.Msg.CANVAS_FONTNAME_SHOW ="字型"; -Blockly.Msg.CANVAS_FONTSIZE_SHOW ="字型大小"; -Blockly.Msg.CANVAS_TEXTALIGN_SHOW ="對齊方式"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "畫布 清除"; -Blockly.Msg.CANVAS_DELETE_SHOW = "畫布 刪除"; -Blockly.Msg.IMAGE_CREATE_SHOW = "圖片 建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "網址來源"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.SET_SHOW = "圖片 設定 "; -Blockly.Msg.GET_SHOW = "圖片 取得 "; -Blockly.Msg.DELETE_SHOW = "圖片 刪除"; -Blockly.Msg.COLLISION_SHOW = "圖片 取得接觸狀態 代碼"; -Blockly.Msg.AND_SHOW = " 與 "; -Blockly.Msg.BOUNDARY_SHOW = "視窗 設定大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得 圖片邊界狀態"; -Blockly.Msg.SYS_GET_SHOW = "取得 視窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得 圖片點選狀態"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得 滑鼠座標"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "計時器 間隔時間(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "計時器 間隔時間(ms)後執行一次"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "計時器 停止"; diff --git a/GameElements_20180824/blockly/msg/en.js b/GameElements_20180824/blockly/msg/en.js deleted file mode 100644 index d91df621b7..0000000000 --- a/GameElements_20180824/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "Game Elements"; diff --git a/GameElements_20180824/blockly/msg/zh-hans.js b/GameElements_20180824/blockly/msg/zh-hans.js deleted file mode 100644 index e338c4eb2d..0000000000 --- a/GameElements_20180824/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "游戏元素"; diff --git a/GameElements_20180824/blockly/msg/zh-hant.js b/GameElements_20180824/blockly/msg/zh-hant.js deleted file mode 100644 index f40b768d28..0000000000 --- a/GameElements_20180824/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "遊戲元素"; diff --git a/GameElements_20180824/blockly/toolbox.xml b/GameElements_20180824/blockly/toolbox.xml deleted file mode 100644 index 502a5ff514..0000000000 --- a/GameElements_20180824/blockly/toolbox.xml +++ /dev/null @@ -1,378 +0,0 @@ - - - - - 500 - - - - - 500 - - - - - 0 - - - - - 100 - - - - - 0 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 100 - - - - - #ff0000 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 100 - - - - - FALSE - - - - - #ff0000 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 0 - - - - - 6.284 - - - - - FALSE - - - - - FALSE - - - - - #ff0000 - - - - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - Hello World - - - - - 0 - - - - - 100 - - - - - Arial - - - - - 30 - - - - - TRUE - - - - - #ff0000 - - - - - - - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - 100 - - - - - - - 1000 - - - - - - - - - - - - - - 0 - - - - - TRUE - - - - - - diff --git a/GameElements_20180824/gameelements.js b/GameElements_20180824/gameelements.js deleted file mode 100644 index 463eb5efbb..0000000000 --- a/GameElements_20180824/gameelements.js +++ /dev/null @@ -1,403 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var screen_width = 0; - var screen_height = 0; - var onclickid = ""; - var onclicktime = 200; - var onclicktimerid; - var mouse_x,mouse_y; - - function music_create(input_url) { - var substr = input_url.toLowerCase().split('.'); - var extname_av = ".aac,.au,.aif,.aiff,.aiffc,.alac,.ape,.asf,.avi,.cda,.dat,.divx,.flac,.m2ts,.m4a,.mid,.mov,.mp2,.mp3,.mp4,.mpc,.mpg,.mpeg,.mv2,.ogg,.pdf,.ra,.ram,.raw,.rcp,.rm,.rmvb,.snd,.tak,.tta,.vob,.voc,.wma,.wav,.webm,.wmf,.wmv,.wv,.xmi,"; - var extname_flash = ".swf,.flv,"; - - if (input_url.toLowerCase().indexOf("http")!=0) - var src = input_url; - else if (extname_av.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else if (extname_flash.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else - var src = ''; - - if (document.getElementById("gamemusic_")) - document.getElementById("gamemusic_").innerHTML = src; - else - { - var div = document.createElement('div'); - div.id = "gamemusic_"; - div.style.position = 'absolute'; - div.style.left = '0px'; - div.style.top = '0px'; - div.style.zIndex = -1; - div.style.display = 'none'; - div.innerHTML = src; - document.body.appendChild(div); - } - } - - function music_delete() { - if (document.getElementById("gamemusic_")) { - document.body.removeChild(document.getElementById("gamemusic_")); - } - } - - function canvas_create(input_id ,input_width,input_height,input_left,input_top,input_zindex) { - if (document.getElementById("gamecanvas_"+input_id)) - { - document.getElementById("gamecanvas_"+input_id).setAttribute("width",input_width + 'px'); - document.getElementById("gamecanvas_"+input_id).setAttribute("height",input_height + 'px'); - document.getElementById("gamecanvas_"+input_id).style.left = input_left + 'px'; - document.getElementById("gamecanvas_"+input_id).style.top = input_top + 'px'; - document.getElementById("gamecanvas_"+input_id).style.zIndex = input_zindex; - } - else - { - var can = document.createElement('canvas'); - can.style.position = "absolute"; - can.id = "gamecanvas_"+input_id; - can.setAttribute("width",input_width + 'px'); - can.setAttribute("height",input_height + 'px'); - can.style.left = input_left + 'px'; - can.style.top = input_top + 'px'; - can.style.zIndex = input_zindex; - document.body.appendChild(can); - - var img = document.createElement('img'); - img.id = "gamecanvasimg"; - img.style.display = "none"; - document.body.appendChild(img); - } - } - - function canvas_line(input_id,input_linewidth,input_x0,input_y0,input_x1,input_y1,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.moveTo(input_x0,input_y0); - context.lineTo(input_x1,input_y1); - context.stroke(); - } - } - - function canvas_rect(input_id,input_linewidth,input_x0,input_y0,input_width,input_height,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.rect(input_x0,input_y0,input_width,input_height); - if (input_fill==0) - context.stroke(); - else - context.fill(); - } - } - - function canvas_arc(input_id,input_linewidth,input_x0,input_y0,input_r,input_sAngle,input_eAngle,input_counterclockwise,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.arc(input_x0,input_y0,input_r,input_sAngle,input_eAngle,input_counterclockwise); - if (input_fill==0) - context.stroke(); - else - context.fill(); - } - } - - function canvas_img(input_id,input_url,input_sx,input_sy,input_swidth,input_sheight,input_x0,input_y0,input_width,input_height) { - if (document.getElementById("gamecanvas_"+input_id)) { - var img = document.getElementById("gamecanvasimg"); - img.src = input_url; - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - if ((input_swidth>0)&&(input_sheight>0)) - context.drawImage(img,input_sx,input_sy,input_swidth,input_sheight,input_x0,input_y0,input_width,input_height); - else if (((input_swidth==0)||(input_sheight==0))&&((input_width>0)&&(input_height>0))) - context.drawImage(img,input_x0,input_y0,input_width,input_height); - else - context.drawImage(img,input_x0,input_y0); - } - } - - function canvas_text(input_id,input_text,input_x0,input_y0,input_fontname,input_fontsize,input_textalign,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.font = input_fontsize + 'px ' + input_fontname; - context.textAlign = input_textalign; - if (input_fill==0) - context.strokeText(input_text,input_x0,input_y0); - else - context.fillText(input_text,input_x0,input_y0); - } - } - - function canvas_clear(input_id) { - if (document.getElementById("gamecanvas_"+input_id)) { - var canvas = document.getElementById("gamecanvas_"+input_id); - var context = canvas.getContext("2d"); - context.clearRect(0, 0, canvas.width, canvas.height); - } - } - - function canvas_delete(input_id) { - if (document.getElementById("gamecanvas_"+input_id)) { - document.body.removeChild(document.getElementById("gamecanvas_"+input_id)); - } - } - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("gameimg_"+input_id)) - { - document.getElementById("gameimg_"+input_id).src = input_url; - document.getElementById("gameimg_"+input_id).style.width = input_width + 'px'; - document.getElementById("gameimg_"+input_id).style.height = input_height + 'px'; - document.getElementById("gameimg_"+input_id).style.left = input_left + 'px'; - document.getElementById("gameimg_"+input_id).style.top = input_top + 'px'; - document.getElementById("gameimg_"+input_id).style.zIndex = input_zindex; - if (input_display==0) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else - { - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "gameimg_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==0) - img.style.display = "none"; - else - img.style.display = "block"; - img.setAttribute("onclick", "javascript:image_onclickid_set(this);"); - document.body.appendChild(img); - } - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - document.getElementById("gameimg_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("gameimg_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("gameimg_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("gameimg_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("gameimg_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("gameimg_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==0) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else if (input_property=='opacity') - document.getElementById("gameimg_"+input_id).style.opacity = input_value; - else if (input_property=='rotate') - document.getElementById("gameimg_"+input_id).style.transform = "rotate("+input_value+"deg)"; - else if (input_property=='rotateX') - document.getElementById("gameimg_"+input_id).style.transform = "rotateX("+input_value+"deg)"; - else if (input_property=='rotateY') - document.getElementById("gameimg_"+input_id).style.transform = "rotateY("+input_value+"deg)"; - else if (input_property=='rotateZ') - document.getElementById("gameimg_"+input_id).style.transform = "rotateZ("+input_value+"deg)"; - else if (input_property=='moveX') - document.getElementById("gameimg_"+input_id).style.left = (Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,""))+Number(input_value))+"px"; - else if (input_property=='moveY') - document.getElementById("gameimg_"+input_id).style.top = (Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,""))+Number(input_value))+"px"; - } - } - - function image_get(input_id,input_property) { - if (input_property=='id') - { - if (document.getElementById("gameimg_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - return document.getElementById("gameimg_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='left') - return Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("gameimg_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("gameimg_"+input_id).style.display=="block") - return 1; - else - return 0; - } - else if (input_property=='opacity') - return document.getElementById("gameimg_"+input_id).style.opacity; - else if (input_property=='rotate') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateX') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateY') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateZ') - return document.getElementById("gameimg_"+input_id).style.transform; - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("gameimg_"+input_id)) - { - document.body.removeChild(document.getElementById("gameimg_"+input_id)); - } - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("gameimg_"+input_id1))&&(document.getElementById("gameimg_"+input_id2))) - { - var img1 = document.getElementById("gameimg_"+input_id1).style; - var img2 = document.getElementById("gameimg_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - function image_boundary(input_left,input_top) { - if (input_left>=0) screen_width = input_left; - if (input_top>=0) screen_height = input_top; - } - - function image_boundary_collision(input_id,input_property) { - if ((screen_width>0)||(screen_height>0)) - { - var left = Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - var width = Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - var top = Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - var height = Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - if (screen_width>0) - { - if (((input_property=="left")||(input_property=="any"))&&(left<=0)) return 1 - if (((input_property=="right")||(input_property=="any"))&&(left+width>=screen_width)) return 1 - } - if (screen_height>0) - { - if (((input_property=="up")||(input_property=="any"))&&(top<=0)) return 1 - if (((input_property=="down")||(input_property=="any"))&&(top+height>=screen_height)) return 1 - } - return 0; - } - else - return 0; - } - - function image_sys_get(input_property) { - if (input_property=='screen_width') - return screen_width; - else if (input_property=='screen_height') - return screen_height; - else - return; - } - - function image_onclickid_set(obj) { - clearTimeout(onclicktimerid); - onclickid=obj.id; - onclicktimerid=setTimeout('image_onclickid_clear()',onclicktime); - } - - function image_onclickid_clear() { - onclickid=""; - } - - function image_onclick_get(input_id) { - if (onclickid==("gameimg_"+input_id)) - { - onclickid=""; - return 1; - } - else - return 0; - } - - function mouse_coordinate_get(input_property) { - document.onmousemove = function(e){ - e=e||window.event; - mouse_x = e.pageX; - mouse_y = e.pageY; - } - if (input_property=="x") - return mouse_x; - else if (input_property=="y") - return mouse_y; - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - window.image_boundary = image_boundary; - window.image_boundary_collision = image_boundary_collision; - window.image_sys_get = image_sys_get; - window.image_onclickid_set = image_onclickid_set; - window.image_onclickid_clear = image_onclickid_clear; - window.image_onclick_get = image_onclick_get; - window.mouse_coordinate_get = mouse_coordinate_get; - window.canvas_create = canvas_create; - window.canvas_line = canvas_line; - window.canvas_rect = canvas_rect; - window.canvas_arc = canvas_arc; - window.canvas_img = canvas_img; - window.canvas_text = canvas_text; - window.canvas_clear = canvas_clear; - window.canvas_delete = canvas_delete; - window.music_create = music_create; - window.music_delete = music_delete; - -}(window, window.document)); diff --git a/GameElements_20180826/blockly.json b/GameElements_20180826/blockly.json deleted file mode 100644 index 3b1414839c..0000000000 --- a/GameElements_20180826/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["table_create", "table_set", "table_get", "table_clear", "table_delete", "table_td_insert_img", "table_td_img_get", "table_td_insert_text", "table_td_get", "table_td_set", "table_td_clear", "canvas_create", "canvas_line", "canvas_rect", "canvas_arc", "canvas_img", "canvas_text", "canvas_clear", "canvas_delete", "music_create","music_delete", "image_create","image_set","image_get","image_delete","image_collision","image_boundary","image_boundary_collision","image_sys_get","image_onclick","mouse_coordinate_get","document_timer","document_timer_once","document_timer_stop"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameelements.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameElements_20180826/blockly/blocks.js b/GameElements_20180826/blockly/blocks.js deleted file mode 100644 index cad976d7f5..0000000000 --- a/GameElements_20180826/blockly/blocks.js +++ /dev/null @@ -1,775 +0,0 @@ -Blockly.Blocks['table_create'] = { - init: function() { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_CREATE_SHOW) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_BORDERSTYLE_SHOW) - .appendField(new Blockly.FieldDropdown([["solid","solid"], ["dashed","dashed"], ["double","double"], ["dotted","dotted"], ["groove","groove"], ["ridge","ridge"], ["inset","inset"], ["outset","outset"], ["inherit","inherit"], ["none","none"], ["hidden","hidden"]]), "borderstyle_"); - this.appendValueInput("borderwidth_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_BORDERWIDTH_SHOW); - this.appendValueInput("bordercolor_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_BORDERCOLOR_SHOW); - this.appendValueInput("trcount_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TRCOUNT_SHOW); - this.appendValueInput("tdcount_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TDCOUNT_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_HEIGHT_SHOW); - this.appendValueInput("bgcolor_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_BGCOLOR_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setInputsInline(false); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_set'] = { - init: function() { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_SET_SHOW) - .appendField(new Blockly.FieldDropdown([["left","left"], ["top","top"], ["borderstyle","borderstyle"], ["borderwidth","borderwidth"], ["bordercolor","bordercolor"], ["cellwidth","cellwidth"], ["cellheight","cellheight"], ["cellcolor","cellcolor"], ["zindex","zindex"], ["display","display"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_get'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_GET_SHOW) - .appendField(Blockly.Msg.PROPERTY_SHOW) - .appendField(new Blockly.FieldDropdown([["onclick[Column,Row]","onclick[Column,Row]"], ["onclickImage","onclickImage"], ["columns","columns"], ["rows","rows"], ["left","left"], ["top","top"], ["borderstyle","borderstyle"], ["borderwidth","borderwidth"], ["bordercolor","bordercolor"], ["zindex","zindex"], ["display","display"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['table_clear'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_CLEAR_SHOW) - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_td_set'] = { - init: function() { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_SET_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.PROPERTY_SHOW) - .appendField(new Blockly.FieldDropdown([["width","width"], ["height","height"], ["background","background"], ["innerHTML","innerHTML"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_td_get'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_GET_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.PROPERTY_SHOW) - .appendField(new Blockly.FieldDropdown([["width","width"], ["height","height"], ["background","background"], ["innerHTML","innerHTML"], ["image","image"], ["tdid","tdid"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['table_td_insert_img'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_INSERT_IMAGE_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.appendValueInput("imgid_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_td_img_get'] = { - init: function () { - this.appendValueInput("imgid_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_IMAGE_GET_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.PROPERTY_SHOW) - .appendField(new Blockly.FieldDropdown([["column","column"], ["row","row"], ["width","width"], ["height","height"], ["naturalwidth","naturalwidth"], ["naturalheight","naturalheight"], ["imageid","imageid"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['table_td_insert_text'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_INSERT_TEXT_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.appendValueInput("text_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CONTEXT_SHOW); - this.appendValueInput("fontname_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.FONTNAME_SHOW); - this.appendValueInput("fontsize_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.FONTSIZE_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.FONTCOLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_td_clear'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_CLEAR_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_delete'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_DELETE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['music_create'] = { - init: function() { - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MUSIC_CREATE_SHOW) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("length_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MUSIC_LENGTH_SHOW); - this.appendValueInput("loop_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MUSIC_LOOP_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['music_delete'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.MUSIC_DELETE_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_create'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_CREATE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_line'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_LINE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("x1_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X1_SHOW); - this.appendValueInput("y1_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y1_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_rect'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_RECT_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_arc'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_ARC_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("r_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_R_SHOW); - this.appendValueInput("sAngle_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SANGLE_SHOW); - this.appendValueInput("eAngle_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_EANGLE_SHOW); - this.appendValueInput("counterclockwise_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_img'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_IMG_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("sx_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SX_SHOW); - this.appendValueInput("sy_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SY_SHOW); - this.appendValueInput("swidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SWIDTH_SHOW); - this.appendValueInput("sheight_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SHEIGHT_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_text'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_TEXT_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("text_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CONTEXT_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("fontname_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.FONTNAME_SHOW); - this.appendValueInput("fontsize_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.FONTSIZE_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.TEXTALIGN_SHOW) - .appendField(new Blockly.FieldDropdown([["start","start"], ["end","end"], ["center","center"], ["left","left"], ["right","right"]]), "textalign_"); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_clear'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_CLEAR_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_delete'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_DELETE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.IMAGE_CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"], ["opacity","opacity"], ["rotate","rotate"], ["rotateX","rotateX"], ["rotateY","rotateY"], ["rotateZ","rotateZ"], ["moveX","moveX"], ["moveY","moveY"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["onclickid","onclickid"], ["exist","exist"], ["url","url"], ["width","width"], ["height","height"], ["naturalwidth","naturalwidth"], ["naturalheight","naturalheight"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"], ["opacity","opacity"], ["rotate","rotate"], ["rotateX","rotateX"], ["rotateY","rotateY"], ["rotateZ","rotateZ"], ["id","id"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_boundary'] = { - init: function() { - this.appendValueInput("left_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.BOUNDARY_SHOW) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("top_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary_collision'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.BOUNDARY_COLLISION_SHOW) - .appendField(new Blockly.FieldDropdown([["up","up"], ["down","down"], ["left","left"], ["right","right"], ["any","any"]]), "property_"); - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_sys_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SYS_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["width","screen_width"], ["height","screen_height"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_onclick_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ONCLICK_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['mouse_coordinate_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MOUSE_COORDINATE_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["X","x"], ["Y","y"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['document_timer'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_once'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimerOnce'), 'fuTimerOnce_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_stop'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW) - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_'); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; diff --git a/GameElements_20180826/blockly/javascript.js b/GameElements_20180826/blockly/javascript.js deleted file mode 100644 index 122792cb74..0000000000 --- a/GameElements_20180826/blockly/javascript.js +++ /dev/null @@ -1,307 +0,0 @@ -Blockly.JavaScript['table_create'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_borderstyle_ = block.getFieldValue('borderstyle_'); - var value_borderwidth_ = Blockly.JavaScript.valueToCode(block, 'borderwidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_bordercolor_ = Blockly.JavaScript.valueToCode(block, 'bordercolor_', Blockly.JavaScript.ORDER_ATOMIC); - var value_trcount_ = Blockly.JavaScript.valueToCode(block, 'trcount_', Blockly.JavaScript.ORDER_ATOMIC); - var value_tdcount_ = Blockly.JavaScript.valueToCode(block, 'tdcount_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_bgcolor_ = Blockly.JavaScript.valueToCode(block, 'bgcolor_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_create("' + variable_fuGameElements_ + '",'+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_trcount_ + ',' + value_tdcount_ + ',"'+ value_borderstyle_ + '",' + value_borderwidth_ + ',' + value_bordercolor_ + ',' + value_bgcolor_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_set'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_set("' + variable_fuGameElements_ + '","' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_get'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_property_ = block.getFieldValue('property_'); - var code = 'table_get("' + variable_fuGameElements_ + '","' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['table_clear'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'table_clear("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['table_td_set'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_td_set("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_td_insert_img'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var value_imgid_ = Blockly.JavaScript.valueToCode(block, 'imgid_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_td_insert_img("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ',' + value_imgid_ + ',' + value_url_ + ',' + value_width_ + ',' + value_height_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_td_img_get'] = function (block) { - var value_imgid_ = Blockly.JavaScript.valueToCode(block, 'imgid_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'table_td_img_get('+ value_imgid_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['table_td_insert_text'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var value_text_ = Blockly.JavaScript.valueToCode(block, 'text_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontname_ = Blockly.JavaScript.valueToCode(block, 'fontname_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontsize_ = Blockly.JavaScript.valueToCode(block, 'fontsize_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_td_insert_text("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ',' + value_text_+ ',' + value_fontname_ + ',' + value_fontsize_ + ',' + value_color_+ ');\n'; - return code; -}; - -Blockly.JavaScript['table_td_get'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'table_td_get("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ',"' + value_property_+ '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['table_td_clear'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_td_clear("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_delete'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'table_delete("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['music_create'] = function (block) { - var value_url = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_length = Blockly.JavaScript.valueToCode(block, 'length_', Blockly.JavaScript.ORDER_ATOMIC); - var value_loop = Blockly.JavaScript.valueToCode(block, 'loop_', Blockly.JavaScript.ORDER_ATOMIC); - if ((value_loop=="true")&&(value_length>0)) - var code = 'music_create(' + value_url + ');\nvar musicTimer = setInterval(function(){\nmusic_create(' + value_url + ');},' + value_length + ');\n'; - else if ((value_loop=="false")&&(value_length>0)) - var code = 'music_create(' + value_url + ');\nvar musicTimer = setTimeout(function(){\nmusic_delete();},' + value_length + ');\n'; - else - var code = 'music_create(' + value_url + ');\n'; - return code; -}; - -Blockly.JavaScript['music_delete'] = function (block) { - var code = 'clearInterval(musicTimer);\nmusic_delete();\n'; - return code; -}; - -Blockly.JavaScript['canvas_create'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_create("' + variable_fuGameElements_ + '",'+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_line'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x1_ = Blockly.JavaScript.valueToCode(block, 'x1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y1_ = Blockly.JavaScript.valueToCode(block, 'y1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_line("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_x1_ + ',' + value_y1_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_rect'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_rect("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_width_ + ',' + value_height_ + ',' + value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_arc'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_r_ = Blockly.JavaScript.valueToCode(block, 'r_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sAngle_ = Blockly.JavaScript.valueToCode(block, 'sAngle_', Blockly.JavaScript.ORDER_ATOMIC); - var value_eAngle_ = Blockly.JavaScript.valueToCode(block, 'eAngle_', Blockly.JavaScript.ORDER_ATOMIC); - var value_counterclockwise_ = Blockly.JavaScript.valueToCode(block, 'counterclockwise_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_arc("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_r_ + ',' + value_sAngle_ + ',' + value_eAngle_ + ',' + value_counterclockwise_ + ',' + value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_img'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sx_ = Blockly.JavaScript.valueToCode(block, 'sx_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sy_ = Blockly.JavaScript.valueToCode(block, 'sy_', Blockly.JavaScript.ORDER_ATOMIC); - var value_swidth_ = Blockly.JavaScript.valueToCode(block, 'swidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sheight_ = Blockly.JavaScript.valueToCode(block, 'sheight_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_img("' + variable_fuGameElements_ + '",' + value_url_ + ',' + value_sx_ + ','+ value_sy_ + ',' + value_swidth_ + ','+ value_sheight_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_width_ + ',' + value_height_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_text'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_text_ = Blockly.JavaScript.valueToCode(block, 'text_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontname_ = Blockly.JavaScript.valueToCode(block, 'fontname_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontsize_ = Blockly.JavaScript.valueToCode(block, 'fontsize_', Blockly.JavaScript.ORDER_ATOMIC); - var value_textalign_ = block.getFieldValue('textalign_'); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_text("' + variable_fuGameElements_ + '",' + value_text_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_fontname_ + ','+ value_fontsize_ + ',"' + value_textalign_ + '",'+ value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_clear'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'canvas_clear("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['canvas_delete'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'canvas_delete("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_boundary'] = function (block) { - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary(' + value_left_ + ',' + value_top_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_boundary_collision'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_boundary_collision(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_sys_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'image_sys_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_onclick_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_onclick_get(' + value_id_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['mouse_coordinate_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'mouse_coordinate_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['document_timer'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimer_+' = setInterval(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_once'] = function (block) { - var variable_fuTimerOnce_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimerOnce_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimerOnce_+' = setTimeout(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_stop'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var code = 'clearInterval(' + variable_fuTimer_ + ');\n'; - return code; -}; diff --git a/GameElements_20180826/blockly/msg/blocks/en.js b/GameElements_20180826/blockly/msg/blocks/en.js deleted file mode 100644 index cf479f831b..0000000000 --- a/GameElements_20180826/blockly/msg/blocks/en.js +++ /dev/null @@ -1,77 +0,0 @@ -Blockly.Msg.TABLE_CREATE_SHOW = "Table Create"; -Blockly.Msg.TABLE_SET_SHOW = "Table Set"; -Blockly.Msg.TABLE_TD_WIDTH_SHOW = "Cell Width"; -Blockly.Msg.TABLE_TD_HEIGHT_SHOW = "Cell Height"; -Blockly.Msg.TABLE_TRCOUNT_SHOW = "Rows"; -Blockly.Msg.TABLE_TDCOUNT_SHOW = "Columns"; -Blockly.Msg.TABLE_BORDERSTYLE_SHOW = "Border Style"; -Blockly.Msg.TABLE_BORDERWIDTH_SHOW = "Border Width"; -Blockly.Msg.TABLE_BORDERCOLOR_SHOW = "Border Color"; -Blockly.Msg.TABLE_BGCOLOR_SHOW = "Cell Color"; -Blockly.Msg.TABLE_TD_INSERT_IMAGE_SHOW = "Cell Insert Image"; -Blockly.Msg.TABLE_TD_X_SHOW = "Column"; -Blockly.Msg.TABLE_TD_Y_SHOW = "Row"; -Blockly.Msg.TABLE_TD_IMAGE_GET_SHOW = "Get Cell Image"; -Blockly.Msg.TABLE_TD_TEXT_SHOW = "Text"; -Blockly.Msg.TABLE_TD_INSERT_TEXT_SHOW = "Cell Insert Text"; -Blockly.Msg.TABLE_TD_GET_SHOW = "Get Cell"; -Blockly.Msg.TABLE_TD_CLEAR_SHOW = "Cell Clear"; -Blockly.Msg.TABLE_DELETE_SHOW = "Table Delete"; -Blockly.Msg.TABLE_GET_SHOW = "Get Table"; -Blockly.Msg.TABLE_CLEAR_SHOW = "Table Clear"; -Blockly.Msg.TABLE_TD_SET_SHOW = "Cell Set"; -Blockly.Msg.MUSIC_CREATE_SHOW ="Background Music Play"; -Blockly.Msg.MUSIC_LENGTH_SHOW ="Length(ms)"; -Blockly.Msg.MUSIC_LOOP_SHOW ="Loop"; -Blockly.Msg.MUSIC_DELETE_SHOW ="Background Music Stop"; -Blockly.Msg.CANVAS_CREATE_SHOW = "Canvas Create"; -Blockly.Msg.CANVAS_LINE_SHOW = "Canvas Line"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "Line Width"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "Canvas Rect"; -Blockly.Msg.CANVAS_ARC_SHOW = "Canvas Arc"; -Blockly.Msg.CANVAS_R_SHOW = "Radius"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "Start Diameter"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "End Diameter"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "Counterclockwise"; -Blockly.Msg.CANVAS_FILL_SHOW = "F"; -Blockly.Msg.CANVAS_IMG_SHOW = "Canvas Image"; -Blockly.Msg.CANVAS_SX_SHOW = "Crop x0"; -Blockly.Msg.CANVAS_SY_SHOW = "Crop y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "Crop Width"; -Blockly.Msg.CANVAS_SHEIGHT_SHOW = "Crop Height"; -Blockly.Msg.CANVAS_TEXT_SHOW ="Canvas Text"; -Blockly.Msg.CONTEXT_SHOW ="Context"; -Blockly.Msg.FONTNAME_SHOW ="Fontname"; -Blockly.Msg.FONTSIZE_SHOW ="Fontsize"; -Blockly.Msg.FONTCOLOR_SHOW = "Fontcolor"; -Blockly.Msg.TEXTALIGN_SHOW ="Align"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "Canvas Clear"; -Blockly.Msg.CANVAS_DELETE_SHOW = "Canvas Delete"; -Blockly.Msg.IMAGE_CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.COLOR_SHOW = "Color"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Get Collision ID"; -Blockly.Msg.AND_SHOW = " And "; -Blockly.Msg.BOUNDARY_SHOW = "Set Screen Boundary"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "Get Collision with sides of screen "; -Blockly.Msg.SYS_GET_SHOW = "Get Screen"; -Blockly.Msg.ONCLICK_SHOW = "Get onClick"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "Get Mouse Coordinate"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "Timer Intervals(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "Timer Intervals(ms) Once"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "Timer Stop"; -Blockly.Msg.PROPERTY_SHOW = "Property"; diff --git a/GameElements_20180826/blockly/msg/blocks/zh-hans.js b/GameElements_20180826/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 2a360009b9..0000000000 --- a/GameElements_20180826/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,77 +0,0 @@ -Blockly.Msg.TABLE_CREATE_SHOW = "表格 新增"; -Blockly.Msg.TABLE_SET_SHOW = "表格 设定"; -Blockly.Msg.TABLE_TD_WIDTH_SHOW = "储存格宽度"; -Blockly.Msg.TABLE_TD_HEIGHT_SHOW = "储存格高度"; -Blockly.Msg.TABLE_TRCOUNT_SHOW = "列数"; -Blockly.Msg.TABLE_TDCOUNT_SHOW = "行数"; -Blockly.Msg.TABLE_BORDERSTYLE_SHOW = "边框样式"; -Blockly.Msg.TABLE_BORDERWIDTH_SHOW = "边框宽度"; -Blockly.Msg.TABLE_BORDERCOLOR_SHOW = "边框颜色"; -Blockly.Msg.TABLE_BGCOLOR_SHOW = "储存格颜色"; -Blockly.Msg.TABLE_TD_INSERT_IMAGE_SHOW = "储存格 插入图片"; -Blockly.Msg.TABLE_TD_X_SHOW = "纵行"; -Blockly.Msg.TABLE_TD_Y_SHOW = "横列"; -Blockly.Msg.TABLE_TD_IMAGE_GET_SHOW = "取得 储存格图片"; -Blockly.Msg.TABLE_TD_TEXT_SHOW = "文字"; -Blockly.Msg.TABLE_TD_INSERT_TEXT_SHOW = "储存格 插入文字"; -Blockly.Msg.TABLE_TD_GET_SHOW = "取得 储存格"; -Blockly.Msg.TABLE_TD_CLEAR_SHOW = "储存格 清除"; -Blockly.Msg.TABLE_DELETE_SHOW = "表格 删除"; -Blockly.Msg.TABLE_GET_SHOW = "取得 表格"; -Blockly.Msg.TABLE_CLEAR_SHOW = "表格 清除"; -Blockly.Msg.TABLE_TD_SET_SHOW = "储存格 设定"; -Blockly.Msg.MUSIC_CREATE_SHOW ="背景音乐 播放"; -Blockly.Msg.MUSIC_LENGTH_SHOW ="长度(ms)"; -Blockly.Msg.MUSIC_LOOP_SHOW ="循环"; -Blockly.Msg.MUSIC_DELETE_SHOW ="背景音乐 停止"; -Blockly.Msg.CANVAS_CREATE_SHOW = "画布 建立"; -Blockly.Msg.CANVAS_LINE_SHOW = "画布 画直线"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "宽度"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "画布 画矩形"; -Blockly.Msg.CANVAS_ARC_SHOW = "画布 画圆"; -Blockly.Msg.CANVAS_R_SHOW = "半径"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "起始径度"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "终止径度"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "顺时钟方向"; -Blockly.Msg.CANVAS_FILL_SHOW = "填满"; -Blockly.Msg.CANVAS_IMG_SHOW = "画布 贴图"; -Blockly.Msg.CANVAS_SX_SHOW = "剪裁x0"; -Blockly.Msg.CANVAS_SY_SHOW = "剪裁y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "剪裁宽度"; -Blockly.Msg.CANVAS_SHEIGHT_SHOW = "剪裁高度"; -Blockly.Msg.CANVAS_TEXT_SHOW ="画布 贴文字"; -Blockly.Msg.CONTEXT_SHOW ="文字"; -Blockly.Msg.FONTNAME_SHOW ="字型名称"; -Blockly.Msg.FONTSIZE_SHOW ="字型大小"; -Blockly.Msg.FONTCOLOR_SHOW = "字型颜色"; -Blockly.Msg.TEXTALIGN_SHOW ="对齐方式"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "画布 清除"; -Blockly.Msg.CANVAS_DELETE_SHOW = "画布 删除"; -Blockly.Msg.IMAGE_CREATE_SHOW = "图片 建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "网址来源"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.COLOR_SHOW = "颜色"; -Blockly.Msg.SET_SHOW = "图片 设定 "; -Blockly.Msg.GET_SHOW = "图片 取得 "; -Blockly.Msg.DELETE_SHOW = "图片 删除"; -Blockly.Msg.COLLISION_SHOW = "图片 取得接触状态 代码"; -Blockly.Msg.AND_SHOW = " 与 "; -Blockly.Msg.BOUNDARY_SHOW = "视窗 设定大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得 图片边界状态"; -Blockly.Msg.SYS_GET_SHOW = "取得 视窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得 图片点选状态"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得 滑鼠座标"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "计时器 间隔时间(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "计时器 间隔时间(ms)后执行一次"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "计时器 停止"; -Blockly.Msg.PROPERTY_SHOW = "属性"; diff --git a/GameElements_20180826/blockly/msg/blocks/zh-hant.js b/GameElements_20180826/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index e1096278b5..0000000000 --- a/GameElements_20180826/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,77 +0,0 @@ -Blockly.Msg.TABLE_CREATE_SHOW = "表格 新增"; -Blockly.Msg.TABLE_SET_SHOW = "表格 設定"; -Blockly.Msg.TABLE_TD_WIDTH_SHOW = "儲存格寬度"; -Blockly.Msg.TABLE_TD_HEIGHT_SHOW = "儲存格高度"; -Blockly.Msg.TABLE_TRCOUNT_SHOW = "列數"; -Blockly.Msg.TABLE_TDCOUNT_SHOW = "行數"; -Blockly.Msg.TABLE_BORDERSTYLE_SHOW = "邊框樣式"; -Blockly.Msg.TABLE_BORDERWIDTH_SHOW = "邊框寬度"; -Blockly.Msg.TABLE_BORDERCOLOR_SHOW = "邊框顏色"; -Blockly.Msg.TABLE_BGCOLOR_SHOW = "儲存格顏色"; -Blockly.Msg.TABLE_TD_INSERT_IMAGE_SHOW = "儲存格 插入圖片"; -Blockly.Msg.TABLE_TD_X_SHOW = "縱行"; -Blockly.Msg.TABLE_TD_Y_SHOW = "橫列"; -Blockly.Msg.TABLE_TD_IMAGE_GET_SHOW = "取得 儲存格圖片"; -Blockly.Msg.TABLE_TD_TEXT_SHOW = "文字"; -Blockly.Msg.TABLE_TD_INSERT_TEXT_SHOW = "儲存格 插入文字"; -Blockly.Msg.TABLE_TD_GET_SHOW = "取得 儲存格"; -Blockly.Msg.TABLE_TD_CLEAR_SHOW = "儲存格 清除"; -Blockly.Msg.TABLE_DELETE_SHOW = "表格 刪除"; -Blockly.Msg.TABLE_GET_SHOW = "取得 表格"; -Blockly.Msg.TABLE_CLEAR_SHOW = "表格 清除"; -Blockly.Msg.TABLE_TD_SET_SHOW = "儲存格 設定"; -Blockly.Msg.MUSIC_CREATE_SHOW ="背景音樂 播放"; -Blockly.Msg.MUSIC_LENGTH_SHOW ="長度(ms)"; -Blockly.Msg.MUSIC_LOOP_SHOW ="循環"; -Blockly.Msg.MUSIC_DELETE_SHOW ="背景音樂 停止"; -Blockly.Msg.CANVAS_CREATE_SHOW = "畫布 建立"; -Blockly.Msg.CANVAS_LINE_SHOW = "畫布 畫直線"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "寬度"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "畫布 畫矩形"; -Blockly.Msg.CANVAS_ARC_SHOW = "畫布 畫圓"; -Blockly.Msg.CANVAS_R_SHOW = "半徑"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "起始徑度"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "終止徑度"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "順時鐘方向"; -Blockly.Msg.CANVAS_FILL_SHOW = "填滿"; -Blockly.Msg.CANVAS_IMG_SHOW = "畫布 貼圖"; -Blockly.Msg.CANVAS_SX_SHOW = "剪裁x0"; -Blockly.Msg.CANVAS_SY_SHOW = "剪裁y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "剪裁寬度"; -Blockly.Msg.CANVAS_SHEIGHT_SHOW = "剪裁高度"; -Blockly.Msg.CANVAS_TEXT_SHOW ="畫布 貼文字"; -Blockly.Msg.CONTEXT_SHOW ="文字"; -Blockly.Msg.FONTNAME_SHOW ="字型名稱"; -Blockly.Msg.FONTSIZE_SHOW ="字型大小"; -Blockly.Msg.FONTCOLOR_SHOW = "字型顏色"; -Blockly.Msg.TEXTALIGN_SHOW ="對齊方式"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "畫布 清除"; -Blockly.Msg.CANVAS_DELETE_SHOW = "畫布 刪除"; -Blockly.Msg.IMAGE_CREATE_SHOW = "圖片 建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "網址來源"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.COLOR_SHOW = "顏色"; -Blockly.Msg.SET_SHOW = "圖片 設定 "; -Blockly.Msg.GET_SHOW = "圖片 取得 "; -Blockly.Msg.DELETE_SHOW = "圖片 刪除"; -Blockly.Msg.COLLISION_SHOW = "圖片 取得接觸狀態 代碼"; -Blockly.Msg.AND_SHOW = " 與 "; -Blockly.Msg.BOUNDARY_SHOW = "視窗 設定大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得 圖片邊界狀態"; -Blockly.Msg.SYS_GET_SHOW = "取得 視窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得 圖片點選狀態"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得 滑鼠座標"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "計時器 間隔時間(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "計時器 間隔時間(ms)後執行一次"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "計時器 停止"; -Blockly.Msg.PROPERTY_SHOW = "屬性"; diff --git a/GameElements_20180826/blockly/msg/en.js b/GameElements_20180826/blockly/msg/en.js deleted file mode 100644 index d91df621b7..0000000000 --- a/GameElements_20180826/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "Game Elements"; diff --git a/GameElements_20180826/blockly/msg/zh-hans.js b/GameElements_20180826/blockly/msg/zh-hans.js deleted file mode 100644 index e338c4eb2d..0000000000 --- a/GameElements_20180826/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "游戏元素"; diff --git a/GameElements_20180826/blockly/msg/zh-hant.js b/GameElements_20180826/blockly/msg/zh-hant.js deleted file mode 100644 index f40b768d28..0000000000 --- a/GameElements_20180826/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "遊戲元素"; diff --git a/GameElements_20180826/blockly/toolbox.xml b/GameElements_20180826/blockly/toolbox.xml deleted file mode 100644 index a575bedfa6..0000000000 --- a/GameElements_20180826/blockly/toolbox.xml +++ /dev/null @@ -1,560 +0,0 @@ - - - - - 0 - - - - - 100 - - - - - 1 - - - - - #000000 - - - - - 5 - - - - - 5 - - - - - 60 - - - - - 60 - - - - - #ff0000 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - 50 - - - - - 50 - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - Arial - - - - - 12 - - - - - #ff0000 - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 500 - - - - - 500 - - - - - 0 - - - - - 100 - - - - - 0 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 100 - - - - - #ff0000 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 100 - - - - - FALSE - - - - - #ff0000 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 0 - - - - - 6.284 - - - - - FALSE - - - - - FALSE - - - - - #ff0000 - - - - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - Hello World - - - - - 0 - - - - - 100 - - - - - Arial - - - - - 30 - - - - - TRUE - - - - - #ff0000 - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 20000 - - - - - TRUE - - - - - - - - - 100 - - - - - - - 1000 - - - - - - diff --git a/GameElements_20180826/gameelements.js b/GameElements_20180826/gameelements.js deleted file mode 100644 index e5a68fcea2..0000000000 --- a/GameElements_20180826/gameelements.js +++ /dev/null @@ -1,695 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) 2018-9-1 20:00 -// https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var screen_width = 0; - var screen_height = 0; - var onclickid = ""; - var onclicktime = 200; - var onclicktimerid; - var mouse_x,mouse_y; - var ImageWidth,ImageHeight; - - function table_create(input_id,input_width,input_height,input_left,input_top,input_trcount,input_tdcount,input_borderstyle,input_borderwidth,input_bordercolor,input_bgcolor,input_zindex,input_display) { - if (document.getElementById("gametable_"+input_id)) - document.getElementById("gametable_"+input_id).parentNode.removeChild(document.getElementById("gametable_"+input_id)); - if ((input_trcount>=1)&&(input_tdcount>=1)){ - var tbl = document.createElement('table'); - tbl.id = "gametable_"+input_id; - tbl.style.position = "absolute"; - tbl.style.left = input_left + 'px'; - tbl.style.top = input_top + 'px'; - tbl.style.zIndex = input_zindex; - tbl.style.border = input_borderwidth +'px ' + input_borderstyle + ' ' + input_bordercolor; - if (input_display==0) - tbl.style.display = "none"; - else - tbl.style.display = "block"; - var tr,td; - for (var i=0;i0){ - for (var i=0;i0){ - for (var j=0;j=5){ - var arr = onclickid.split("_"); - return Number(arr[arr.length-1]); - } - else - return ""; - } - else - return ""; - } - else if (input_property=="onclickRow"){ - if (onclickid.indexOf("gametable_td_"+input_id)==0){ - if (onclickid.split("_").length>=5){ - var arr = onclickid.split("_"); - return Number(arr[arr.length-2]); - } - else - return ""; - } - else - return ""; - } - else if (input_property=="onclick[Column,Row]"){ - if (onclickid.indexOf("gametable_td_"+input_id)==0){ - if (onclickid.split("_").length>=5){ - var arr = onclickid.split("_"); - onclickid=""; - arr = [arr[arr.length-1],arr[arr.length-2]]; - return arr; - } - else - return ""; - } - else - return ""; - } - else if (input_property=="onclickImage"){ - if (onclickid.indexOf("gametable_td_"+input_id)==0){ - if (document.getElementById(onclickid).hasChildNodes()) - return document.getElementById(onclickid).firstChild.id.replace(/gameimg_/ig,""); - else - return ""; - } - else - return ""; - } - else - return ""; - } - else - return ""; - } - - function table_clear(input_id){ - if (document.getElementById("gametable_"+input_id)) { - var obj = document.getElementById("gametable_"+input_id); - if (document.getElementById("gametable_"+input_id).rows.length>0){ - for (var i=0;i0){ - for (var j=0;j 0){ - if (td.childNodes[0].id.indexOf("gameimg_")==0) - return td.childNodes[0].id.substr(8); - else - return ""; - } - else - return ""; - } - else if (input_property=="tdid") - return "gametable_td_"+input_id+"_"+input_y+'_'+input_x; - } - else - return ""; - } - - - function table_td_insert_img(input_id,input_x,input_y,input_img_id,input_url,input_width,input_height){ - if (document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x)){ - var img = document.createElement('img'); - img.id = "gameimg_"+input_img_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.setAttribute("onclick", "javascript:image_onclickid_set(this);"); - document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x).appendChild(img); - } - } - - function table_td_img_get(input_img_id,input_property){ - if (document.getElementById("gameimg_"+input_img_id)){ - if (document.getElementById("gameimg_"+input_img_id).parentNode.id.split("_").length>=5){ - var arr = document.getElementById("gameimg_"+input_img_id).parentNode.id.split("_"); - if (input_property=="column") - return Number(arr[arr.length-1]); - else if (input_property=="row") - return Number(arr[arr.length-2]); - else if (input_property=="width") - return Number(document.getElementById("gameimg_"+input_img_id).style.width.replace(/px/ig,"")); - else if (input_property=="height") - return Number(document.getElementById("gameimg_"+input_img_id).style.height.replace(/px/ig,"")); - else if (input_property=='naturalwidth'){ - var naturl = image_Natural_get(document.getElementById("gameimg_"+input_img_id)); - return Number(naturl.width); - } - else if (input_property=='naturalheight'){ - var naturl = image_Natural_get(document.getElementById("gameimg_"+input_img_id)); - return Number(naturl.height); - } - else if (input_property=="imageid") - return "gameimg_"+input_img_id; - } - else - return -1; - } - else - return -1; - } - - function table_td_insert_text(input_id,input_x,input_y,input_text,input_fontname,input_fontsize,input_color){ - if (document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x)) - document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x).innerHTML = "" + input_text + ""; - } - - function table_td_clear(input_id,input_x,input_y){ - if (document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x)) - document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x).innerHTML = ""; - } - - function table_delete(input_id) { - if (document.getElementById("gametable_"+input_id)) - document.getElementById("gametable_"+input_id).parentNode.removeChild(document.getElementById("gametable_"+input_id)); - } - - function music_create(input_url) { - var substr = input_url.toLowerCase().split('.'); - var extname_av = ".aac,.au,.aif,.aiff,.aiffc,.alac,.ape,.asf,.avi,.cda,.dat,.divx,.flac,.m2ts,.m4a,.mid,.mov,.mp2,.mp3,.mp4,.mpc,.mpg,.mpeg,.mv2,.ogg,.pdf,.ra,.ram,.raw,.rcp,.rm,.rmvb,.snd,.tak,.tta,.vob,.voc,.wma,.wav,.webm,.wmf,.wmv,.wv,.xmi,"; - var extname_flash = ".swf,.flv,"; - - if (input_url.toLowerCase().indexOf("http")!=0) - var src = input_url; - else if (extname_av.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else if (extname_flash.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else - var src = ''; - - if (document.getElementById("gamemusic_")) - document.getElementById("gamemusic_").parentNode.removeChild(document.getElementById("gamemusic_")); - var div = document.createElement('div'); - div.id = "gamemusic_"; - div.style.position = 'absolute'; - div.style.left = '0px'; - div.style.top = '0px'; - div.style.zIndex = -1; - div.style.display = 'none'; - div.innerHTML = src; - document.body.appendChild(div); - } - - function music_delete() { - if (document.getElementById("gamemusic_")) - document.getElementById("gamemusic_").parentNode.removeChild(document.getElementById("gamemusic_")); - } - - function canvas_create(input_id ,input_width,input_height,input_left,input_top,input_zindex) { - if (document.getElementById("gamecanvas_"+input_id)) - document.getElementById("gamecanvas_"+input_id).parentNode.removeChild(document.getElementById("gamecanvas_"+input_id)); - var can = document.createElement('canvas'); - can.style.position = "absolute"; - can.id = "gamecanvas_"+input_id; - can.setAttribute("width",input_width + 'px'); - can.setAttribute("height",input_height + 'px'); - can.style.left = input_left + 'px'; - can.style.top = input_top + 'px'; - can.style.zIndex = input_zindex; - document.body.appendChild(can); - - var img = document.createElement('img'); - img.id = "gamecanvasimg"; - img.style.display = "none"; - document.body.appendChild(img); - } - - function canvas_line(input_id,input_linewidth,input_x0,input_y0,input_x1,input_y1,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.moveTo(input_x0,input_y0); - context.lineTo(input_x1,input_y1); - context.stroke(); - } - } - - function canvas_rect(input_id,input_linewidth,input_x0,input_y0,input_width,input_height,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.rect(input_x0,input_y0,input_width,input_height); - if (input_fill==0) - context.stroke(); - else - context.fill(); - } - } - - function canvas_arc(input_id,input_linewidth,input_x0,input_y0,input_r,input_sAngle,input_eAngle,input_counterclockwise,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.arc(input_x0,input_y0,input_r,input_sAngle,input_eAngle,input_counterclockwise); - if (input_fill==0) - context.stroke(); - else - context.fill(); - } - } - - function canvas_img(input_id,input_url,input_sx,input_sy,input_swidth,input_sheight,input_x0,input_y0,input_width,input_height) { - if (document.getElementById("gamecanvas_"+input_id)) { - var img = document.getElementById("gamecanvasimg"); - img.src = input_url; - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - if ((input_swidth>0)&&(input_sheight>0)) - context.drawImage(img,input_sx,input_sy,input_swidth,input_sheight,input_x0,input_y0,input_width,input_height); - else if (((input_swidth==0)||(input_sheight==0))&&((input_width>0)&&(input_height>0))) - context.drawImage(img,input_x0,input_y0,input_width,input_height); - else - context.drawImage(img,input_x0,input_y0); - } - } - - function canvas_text(input_id,input_text,input_x0,input_y0,input_fontname,input_fontsize,input_textalign,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.font = input_fontsize + 'px ' + input_fontname; - context.textAlign = input_textalign; - if (input_fill==0) - context.strokeText(input_text,input_x0,input_y0); - else - context.fillText(input_text,input_x0,input_y0); - } - } - - function canvas_clear(input_id) { - if (document.getElementById("gamecanvas_"+input_id)) { - var canvas = document.getElementById("gamecanvas_"+input_id); - var context = canvas.getContext("2d"); - context.clearRect(0, 0, canvas.width, canvas.height); - } - } - - function canvas_delete(input_id) { - if (document.getElementById("gamecanvas_"+input_id)) - document.getElementById("gamecanvas_"+input_id).parentNode.removeChild(document.getElementById("gamecanvas_"+input_id)); - } - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("gameimg_"+input_id)) - document.getElementById("gameimg_"+input_id).parentNode.removeChild(document.getElementById("gameimg_"+input_id)); - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "gameimg_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==0) - img.style.display = "none"; - else - img.style.display = "block"; - img.setAttribute("onclick", "javascript:image_onclickid_set(this);"); - document.body.appendChild(img); - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - document.getElementById("gameimg_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("gameimg_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("gameimg_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("gameimg_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("gameimg_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("gameimg_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==0) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else if (input_property=='opacity') - document.getElementById("gameimg_"+input_id).style.opacity = input_value; - else if (input_property=='rotate') - document.getElementById("gameimg_"+input_id).style.transform = "rotate("+input_value+"deg)"; - else if (input_property=='rotateX') - document.getElementById("gameimg_"+input_id).style.transform = "rotateX("+input_value+"deg)"; - else if (input_property=='rotateY') - document.getElementById("gameimg_"+input_id).style.transform = "rotateY("+input_value+"deg)"; - else if (input_property=='rotateZ') - document.getElementById("gameimg_"+input_id).style.transform = "rotateZ("+input_value+"deg)"; - else if (input_property=='moveX') - document.getElementById("gameimg_"+input_id).style.left = (Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,""))+Number(input_value))+"px"; - else if (input_property=='moveY') - document.getElementById("gameimg_"+input_id).style.top = (Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,""))+Number(input_value))+"px"; - } - } - - function image_get(input_id,input_property) { - if (input_property=="onclickid"){ - if (onclickid.indexOf("gameimg_")==0) - return onclickid.replace(/gameimg_/ig,""); - else if (onclickid.indexOf("gametable_td_")==0){ - if (document.getElementById(onclickid).hasChildNodes()) - return document.getElementById(onclickid).firstChild.id.replace(/gameimg_/ig,""); - else - return ""; - } - else - return ""; - } - else if (input_property=='exist') - { - if (document.getElementById("gameimg_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - return document.getElementById("gameimg_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='naturalwidth'){ - var naturl = image_Natural_get(document.getElementById("gameimg_"+input_id)); - return Number(naturl.width); - } - else if (input_property=='naturalheight'){ - var naturl = image_Natural_get(document.getElementById("gameimg_"+input_id)); - return Number(naturl.height); - } - else if (input_property=='left') - return Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("gameimg_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("gameimg_"+input_id).style.display=="block") - return 1; - else - return 0; - } - else if (input_property=='opacity') - return document.getElementById("gameimg_"+input_id).style.opacity; - else if (input_property=='rotate') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateX') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateY') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateZ') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='id') - return "gameimg_"+input_id; - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("gameimg_"+input_id)) - document.getElementById("gameimg_"+input_id).parentNode.removeChild(document.getElementById("gameimg_"+input_id)); - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("gameimg_"+input_id1))&&(document.getElementById("gameimg_"+input_id2))) - { - var img1 = document.getElementById("gameimg_"+input_id1).style; - var img2 = document.getElementById("gameimg_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - function image_boundary(input_left,input_top) { - if (input_left>=0) screen_width = input_left; - if (input_top>=0) screen_height = input_top; - } - - function image_boundary_collision(input_id,input_property) { - if ((screen_width>0)||(screen_height>0)) - { - var left = Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - var width = Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - var top = Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - var height = Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - if (screen_width>0) - { - if (((input_property=="left")||(input_property=="any"))&&(left<=0)) return 1 - if (((input_property=="right")||(input_property=="any"))&&(left+width>=screen_width)) return 1 - } - if (screen_height>0) - { - if (((input_property=="up")||(input_property=="any"))&&(top<=0)) return 1 - if (((input_property=="down")||(input_property=="any"))&&(top+height>=screen_height)) return 1 - } - return 0; - } - else - return 0; - } - - function image_sys_get(input_property) { - if (input_property=='screen_width') - return screen_width; - else if (input_property=='screen_height') - return screen_height; - else - return; - } - - function image_onclickid_set(obj) { - clearTimeout(onclicktimerid); - onclickid=obj.id; - onclicktimerid=setTimeout('image_onclickid_clear()',onclicktime); - } - - function image_onclickid_clear() { - onclickid=""; - } - - function image_onclick_get(input_id) { - if (onclickid==("gameimg_"+input_id)) - { - onclickid=""; - return 1; - } - else - return 0; - } - - function image_Natural_get (obj) { - var img = new Image(); - img.src = obj.src; - return {width: img.width, height: img.height}; - } - - function mouse_coordinate_get(input_property) { - if (!document.onmousemove) - { - document.onmousemove = function(e){ - e=e||window.event; - mouse_x = e.pageX; - mouse_y = e.pageY; - } - console.log("set"); - } - if (input_property=="x") - return mouse_x; - else if (input_property=="y") - return mouse_y; - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - window.image_boundary = image_boundary; - window.image_boundary_collision = image_boundary_collision; - window.image_sys_get = image_sys_get; - window.image_onclickid_set = image_onclickid_set; - window.image_onclickid_clear = image_onclickid_clear; - window.image_onclick_get = image_onclick_get; - window.image_Natural_get = image_Natural_get; - window.mouse_coordinate_get = mouse_coordinate_get; - window.canvas_create = canvas_create; - window.canvas_line = canvas_line; - window.canvas_rect = canvas_rect; - window.canvas_arc = canvas_arc; - window.canvas_img = canvas_img; - window.canvas_text = canvas_text; - window.canvas_clear = canvas_clear; - window.canvas_delete = canvas_delete; - window.music_create = music_create; - window.music_delete = music_delete; - window.table_create = table_create; - window.table_set = table_set; - window.table_delete = table_delete; - window.table_td_insert_img = table_td_insert_img; - window.table_td_img_get = table_td_img_get; - window.table_td_insert_text = table_td_insert_text; - window.table_td_get = table_td_get; - window.table_td_clear = table_td_clear; - window.table_get = table_get; - window.table_clear = table_clear; - window.table_td_set = table_td_set; - -}(window, window.document)); diff --git a/GameElements_20180910/blockly.json b/GameElements_20180910/blockly.json deleted file mode 100644 index 80a8471dcf..0000000000 --- a/GameElements_20180910/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["table_create", "table_set", "table_get", "table_clear", "table_delete", "table_td_insert_img", "table_td_img_get", "table_td_insert_text", "table_td_get", "table_td_set", "table_border_set", "table_td_border_set", "table_td_clear", "canvas_create", "canvas_line", "canvas_rect", "canvas_arc", "canvas_img", "canvas_text", "canvas_clear", "canvas_delete", "music_create","music_delete", "image_create","image_set","image_get","image_delete","image_collision","image_boundary","image_boundary_collision","image_sys_get","image_onclick","mouse_coordinate_get","document_timer","document_timer_once","document_timer_stop","text_to_number","loop_break","loop_continue","function_return"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameelements.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameElements_20180910/blockly/blocks.js b/GameElements_20180910/blockly/blocks.js deleted file mode 100644 index 7107af4324..0000000000 --- a/GameElements_20180910/blockly/blocks.js +++ /dev/null @@ -1,872 +0,0 @@ -Blockly.Blocks['table_create'] = { - init: function() { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_CREATE_SHOW) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_BORDERSTYLE_SHOW) - .appendField(new Blockly.FieldDropdown([["solid","solid"], ["dashed","dashed"], ["double","double"], ["dotted","dotted"], ["groove","groove"], ["ridge","ridge"], ["inset","inset"], ["outset","outset"], ["inherit","inherit"], ["none","none"], ["hidden","hidden"]]), "borderstyle_"); - this.appendValueInput("borderwidth_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_BORDERWIDTH_SHOW); - this.appendValueInput("bordercolor_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_BORDERCOLOR_SHOW); - this.appendValueInput("trcount_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TRCOUNT_SHOW); - this.appendValueInput("tdcount_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TDCOUNT_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_HEIGHT_SHOW); - this.appendValueInput("bgcolor_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_BGCOLOR_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setInputsInline(false); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_set'] = { - init: function() { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_SET_SHOW) - .appendField(new Blockly.FieldDropdown([["left","left"], ["top","top"], ["borderstyle","borderstyle"], ["borderwidth","borderwidth"], ["bordercolor","bordercolor"], ["cellwidth","cellwidth"], ["cellheight","cellheight"], ["cellcolor","cellcolor"], ["zindex","zindex"], ["display","display"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_get'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_GET_SHOW) - .appendField(Blockly.Msg.PROPERTY_SHOW) - .appendField(new Blockly.FieldDropdown([["onclick[Column,Row]","onclick[Column,Row]"], ["onclickImage","onclickImage"], ["columns","columns"], ["rows","rows"], ["left","left"], ["top","top"], ["borderstyle","borderstyle"], ["borderwidth","borderwidth"], ["bordercolor","bordercolor"], ["zindex","zindex"], ["display","display"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['table_clear'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_CLEAR_SHOW) - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_td_set'] = { - init: function() { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_SET_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.PROPERTY_SHOW) - .appendField(new Blockly.FieldDropdown([["width","width"], ["height","height"], ["textalign","textalign"], ["background","background"], ["innerHTML","innerHTML"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_border_set'] = { - init: function() { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_BORDER_SET_SHOW) - .appendField(Blockly.Msg.TABLE_BORDERSTYLE_SHOW) - .appendField(new Blockly.FieldDropdown([["solid","solid"], ["dashed","dashed"], ["double","double"], ["dotted","dotted"], ["groove","groove"], ["ridge","ridge"], ["inset","inset"], ["outset","outset"], ["inherit","inherit"], ["none","none"], ["hidden","hidden"]]), "borderstyle_"); - this.appendValueInput("borderwidth_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_BORDERWIDTH_SHOW); - this.appendValueInput("bordercolor_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_BORDERCOLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_td_border_set'] = { - init: function() { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_BORDER_SET_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_BORDERSTYLE_SHOW) - .appendField(new Blockly.FieldDropdown([["solid","solid"], ["dashed","dashed"], ["double","double"], ["dotted","dotted"], ["groove","groove"], ["ridge","ridge"], ["inset","inset"], ["outset","outset"], ["inherit","inherit"], ["none","none"], ["hidden","hidden"]]), "borderstyle_"); - this.appendValueInput("borderwidth_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_BORDERWIDTH_SHOW); - this.appendValueInput("bordercolor_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_BORDERCOLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_td_get'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_GET_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.PROPERTY_SHOW) - .appendField(new Blockly.FieldDropdown([["width","width"], ["height","height"], ["background","background"], ["innerHTML","innerHTML"], ["image","image"], ["tdid","tdid"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['table_td_insert_img'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_INSERT_IMAGE_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.appendValueInput("imgid_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_td_img_get'] = { - init: function () { - this.appendValueInput("imgid_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_IMAGE_GET_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.PROPERTY_SHOW) - .appendField(new Blockly.FieldDropdown([["column","column"], ["row","row"], ["width","width"], ["height","height"], ["naturalwidth","naturalwidth"], ["naturalheight","naturalheight"], ["imageid","imageid"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['table_td_insert_text'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_INSERT_TEXT_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.appendValueInput("text_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CONTEXT_SHOW); - this.appendValueInput("fontname_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.FONTNAME_SHOW); - this.appendValueInput("fontsize_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.FONTSIZE_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.FONTCOLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_td_clear'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.appendValueInput("x_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_CLEAR_SHOW) - .appendField(Blockly.Msg.TABLE_TD_X_SHOW); - this.appendValueInput("y_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TABLE_TD_Y_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['table_delete'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.TABLE_DELETE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameTable'), 'fuGameElements_'); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['music_create'] = { - init: function() { - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MUSIC_CREATE_SHOW) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("length_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MUSIC_LENGTH_SHOW); - this.appendValueInput("loop_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MUSIC_LOOP_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['music_delete'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.MUSIC_DELETE_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_create'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_CREATE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_line'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_LINE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("x1_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X1_SHOW); - this.appendValueInput("y1_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y1_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_rect'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_RECT_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_arc'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_ARC_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("linewidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_LINEWIDTH_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("r_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_R_SHOW); - this.appendValueInput("sAngle_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SANGLE_SHOW); - this.appendValueInput("eAngle_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_EANGLE_SHOW); - this.appendValueInput("counterclockwise_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_img'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_IMG_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("sx_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SX_SHOW); - this.appendValueInput("sy_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SY_SHOW); - this.appendValueInput("swidth_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SWIDTH_SHOW); - this.appendValueInput("sheight_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_SHEIGHT_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_text'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_TEXT_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.appendValueInput("text_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CONTEXT_SHOW); - this.appendValueInput("x0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_X0_SHOW); - this.appendValueInput("y0_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_Y0_SHOW); - this.appendValueInput("fontname_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.FONTNAME_SHOW); - this.appendValueInput("fontsize_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.FONTSIZE_SHOW); - this.appendDummyInput() - .appendField(Blockly.Msg.TEXTALIGN_SHOW) - .appendField(new Blockly.FieldDropdown([["start","start"], ["end","end"], ["center","center"], ["left","left"], ["right","right"]]), "textalign_"); - this.appendValueInput("fill_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CANVAS_FILL_SHOW); - this.appendValueInput("color_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.COLOR_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_clear'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_CLEAR_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['canvas_delete'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.CANVAS_DELETE_SHOW) - .appendField(new Blockly.FieldVariable('fuGameCanvas'), 'fuGameElements_'); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.IMAGE_CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"], ["opacity","opacity"], ["rotate","rotate"], ["rotateX","rotateX"], ["rotateY","rotateY"], ["rotateZ","rotateZ"], ["moveX","moveX"], ["moveY","moveY"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["onclickid","onclickid"], ["exist","exist"], ["url","url"], ["width","width"], ["height","height"], ["naturalwidth","naturalwidth"], ["naturalheight","naturalheight"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"], ["opacity","opacity"], ["rotate","rotate"], ["rotateX","rotateX"], ["rotateY","rotateY"], ["rotateZ","rotateZ"], ["id","id"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_boundary'] = { - init: function() { - this.appendValueInput("left_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.BOUNDARY_SHOW) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("top_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary_collision'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.BOUNDARY_COLLISION_SHOW) - .appendField(new Blockly.FieldDropdown([["up","up"], ["down","down"], ["left","left"], ["right","right"], ["any","any"]]), "property_"); - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_sys_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SYS_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["width","screen_width"], ["height","screen_height"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_onclick_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ONCLICK_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['mouse_coordinate_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MOUSE_COORDINATE_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["X","x"], ["Y","y"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['document_timer'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_once'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimerOnce'), 'fuTimerOnce_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_stop'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW) - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_'); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['text_to_number'] = { - init: function() { - this.appendValueInput("value_text_") - .setCheck(null) - .appendField(Blockly.Msg.TEXT_TO_NUMBER_SHOW); - this.setOutput(true); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['loop_break'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.LOOP_BREAK_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['loop_continue'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.LOOP_CONTINUE_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['function_return'] = { - init: function () { - this.appendValueInput("value_") - .setCheck(null) - .appendField(Blockly.Msg.FUNCTION_RETURN_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; diff --git a/GameElements_20180910/blockly/javascript.js b/GameElements_20180910/blockly/javascript.js deleted file mode 100644 index 31926371fb..0000000000 --- a/GameElements_20180910/blockly/javascript.js +++ /dev/null @@ -1,349 +0,0 @@ -Blockly.JavaScript['table_create'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_borderstyle_ = block.getFieldValue('borderstyle_'); - var value_borderwidth_ = Blockly.JavaScript.valueToCode(block, 'borderwidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_bordercolor_ = Blockly.JavaScript.valueToCode(block, 'bordercolor_', Blockly.JavaScript.ORDER_ATOMIC); - var value_trcount_ = Blockly.JavaScript.valueToCode(block, 'trcount_', Blockly.JavaScript.ORDER_ATOMIC); - var value_tdcount_ = Blockly.JavaScript.valueToCode(block, 'tdcount_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_bgcolor_ = Blockly.JavaScript.valueToCode(block, 'bgcolor_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_create("' + variable_fuGameElements_ + '",'+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_trcount_ + ',' + value_tdcount_ + ',"'+ value_borderstyle_ + '",' + value_borderwidth_ + ',' + value_bordercolor_ + ',' + value_bgcolor_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_set'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_set("' + variable_fuGameElements_ + '","' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_get'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_property_ = block.getFieldValue('property_'); - var code = 'table_get("' + variable_fuGameElements_ + '","' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['table_clear'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'table_clear("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['table_td_set'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_td_set("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_border_set'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_borderstyle_ = block.getFieldValue('borderstyle_'); - var value_borderwidth_ = Blockly.JavaScript.valueToCode(block, 'borderwidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_bordercolor_ = Blockly.JavaScript.valueToCode(block, 'bordercolor_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_border_set("' + variable_fuGameElements_ + '","'+ value_borderstyle_ + '",' + value_borderwidth_ + ',' + value_bordercolor_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_td_border_set'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var value_borderstyle_ = block.getFieldValue('borderstyle_'); - var value_borderwidth_ = Blockly.JavaScript.valueToCode(block, 'borderwidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_bordercolor_ = Blockly.JavaScript.valueToCode(block, 'bordercolor_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_td_border_set("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ',"'+ value_borderstyle_ + '",' + value_borderwidth_ + ',' + value_bordercolor_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_td_insert_img'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var value_imgid_ = Blockly.JavaScript.valueToCode(block, 'imgid_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_td_insert_img("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ',' + value_imgid_ + ',' + value_url_ + ',' + value_width_ + ',' + value_height_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_td_img_get'] = function (block) { - var value_imgid_ = Blockly.JavaScript.valueToCode(block, 'imgid_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'table_td_img_get('+ value_imgid_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['table_td_insert_text'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var value_text_ = Blockly.JavaScript.valueToCode(block, 'text_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontname_ = Blockly.JavaScript.valueToCode(block, 'fontname_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontsize_ = Blockly.JavaScript.valueToCode(block, 'fontsize_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_td_insert_text("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ',' + value_text_+ ',' + value_fontname_ + ',' + value_fontsize_ + ',' + value_color_+ ');\n'; - return code; -}; - -Blockly.JavaScript['table_td_get'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'table_td_get("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ',"' + value_property_+ '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['table_td_clear'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_x_ = Blockly.JavaScript.valueToCode(block, 'x_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_ = Blockly.JavaScript.valueToCode(block, 'y_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'table_td_clear("' + variable_fuGameElements_ + '",'+ value_x_ + ',' + value_y_ + ');\n'; - return code; -}; - -Blockly.JavaScript['table_delete'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'table_delete("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['music_create'] = function (block) { - var value_url = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_length = Blockly.JavaScript.valueToCode(block, 'length_', Blockly.JavaScript.ORDER_ATOMIC); - var value_loop = Blockly.JavaScript.valueToCode(block, 'loop_', Blockly.JavaScript.ORDER_ATOMIC); - if ((value_loop=="true")&&(value_length>0)) - var code = 'music_create(' + value_url + ');\nvar musicTimer = setInterval(function(){\nmusic_create(' + value_url + ');},' + value_length + ');\n'; - else if ((value_loop=="false")&&(value_length>0)) - var code = 'music_create(' + value_url + ');\nvar musicTimer = setTimeout(function(){\nmusic_delete();},' + value_length + ');\n'; - else - var code = 'music_create(' + value_url + ');\n'; - return code; -}; - -Blockly.JavaScript['music_delete'] = function (block) { - var code = 'clearInterval(musicTimer);\nmusic_delete();\n'; - return code; -}; - -Blockly.JavaScript['canvas_create'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_create("' + variable_fuGameElements_ + '",'+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_line'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x1_ = Blockly.JavaScript.valueToCode(block, 'x1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y1_ = Blockly.JavaScript.valueToCode(block, 'y1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_line("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_x1_ + ',' + value_y1_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_rect'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_rect("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_width_ + ',' + value_height_ + ',' + value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_arc'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_linewidth_ = Blockly.JavaScript.valueToCode(block, 'linewidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_r_ = Blockly.JavaScript.valueToCode(block, 'r_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sAngle_ = Blockly.JavaScript.valueToCode(block, 'sAngle_', Blockly.JavaScript.ORDER_ATOMIC); - var value_eAngle_ = Blockly.JavaScript.valueToCode(block, 'eAngle_', Blockly.JavaScript.ORDER_ATOMIC); - var value_counterclockwise_ = Blockly.JavaScript.valueToCode(block, 'counterclockwise_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_arc("' + variable_fuGameElements_ + '",' + value_linewidth_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_r_ + ',' + value_sAngle_ + ',' + value_eAngle_ + ',' + value_counterclockwise_ + ',' + value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_img'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sx_ = Blockly.JavaScript.valueToCode(block, 'sx_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sy_ = Blockly.JavaScript.valueToCode(block, 'sy_', Blockly.JavaScript.ORDER_ATOMIC); - var value_swidth_ = Blockly.JavaScript.valueToCode(block, 'swidth_', Blockly.JavaScript.ORDER_ATOMIC); - var value_sheight_ = Blockly.JavaScript.valueToCode(block, 'sheight_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_img("' + variable_fuGameElements_ + '",' + value_url_ + ',' + value_sx_ + ','+ value_sy_ + ',' + value_swidth_ + ','+ value_sheight_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_width_ + ',' + value_height_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_text'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var value_text_ = Blockly.JavaScript.valueToCode(block, 'text_', Blockly.JavaScript.ORDER_ATOMIC); - var value_x0_ = Blockly.JavaScript.valueToCode(block, 'x0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y0_ = Blockly.JavaScript.valueToCode(block, 'y0_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontname_ = Blockly.JavaScript.valueToCode(block, 'fontname_', Blockly.JavaScript.ORDER_ATOMIC); - var value_fontsize_ = Blockly.JavaScript.valueToCode(block, 'fontsize_', Blockly.JavaScript.ORDER_ATOMIC); - var value_textalign_ = block.getFieldValue('textalign_'); - var value_fill_ = Blockly.JavaScript.valueToCode(block, 'fill_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_ = Blockly.JavaScript.valueToCode(block, 'color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'canvas_text("' + variable_fuGameElements_ + '",' + value_text_ + ',' + value_x0_ + ','+ value_y0_ + ',' + value_fontname_ + ','+ value_fontsize_ + ',"' + value_textalign_ + '",'+ value_fill_ + ',' + value_color_ + ');\n'; - return code; -}; - -Blockly.JavaScript['canvas_clear'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'canvas_clear("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['canvas_delete'] = function (block) { - var variable_fuGameElements_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuGameElements_'), Blockly.Variables.NAME_TYPE); - var code = 'canvas_delete("' + variable_fuGameElements_ + '");\n'; - return code; -}; - -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_boundary'] = function (block) { - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary(' + value_left_ + ',' + value_top_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_boundary_collision'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_boundary_collision(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_sys_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'image_sys_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_onclick_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_onclick_get(' + value_id_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['mouse_coordinate_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'mouse_coordinate_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['document_timer'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimer_+' = setInterval(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_once'] = function (block) { - var variable_fuTimerOnce_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimerOnce_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimerOnce_+' = setTimeout(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_stop'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var code = 'clearInterval(' + variable_fuTimer_ + ');\n'; - return code; -}; - -Blockly.JavaScript['text_to_number'] = function (block) { - var value_text = Blockly.JavaScript.valueToCode(block, 'value_text_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'text_to_number(' + value_text + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['loop_break'] = function (block) { - var code = 'break;\n'; - return code; -}; - -Blockly.JavaScript['loop_continue'] = function (block) { - var code = 'continue;\n'; - return code; -}; - -Blockly.JavaScript['function_return'] = function (block) { - var value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'return ' + value_ + ';\n'; - return code; -}; diff --git a/GameElements_20180910/blockly/msg/blocks/en.js b/GameElements_20180910/blockly/msg/blocks/en.js deleted file mode 100644 index a27e8e6719..0000000000 --- a/GameElements_20180910/blockly/msg/blocks/en.js +++ /dev/null @@ -1,83 +0,0 @@ -Blockly.Msg.TABLE_CREATE_SHOW = "Table Create"; -Blockly.Msg.TABLE_SET_SHOW = "Table Set"; -Blockly.Msg.TABLE_TD_WIDTH_SHOW = "Cell Width"; -Blockly.Msg.TABLE_TD_HEIGHT_SHOW = "Cell Height"; -Blockly.Msg.TABLE_TRCOUNT_SHOW = "Rows"; -Blockly.Msg.TABLE_TDCOUNT_SHOW = "Columns"; -Blockly.Msg.TABLE_BORDERSTYLE_SHOW = "Border Style"; -Blockly.Msg.TABLE_BORDERWIDTH_SHOW = "Border Width"; -Blockly.Msg.TABLE_BORDERCOLOR_SHOW = "Border Color"; -Blockly.Msg.TABLE_BGCOLOR_SHOW = "Cell Color"; -Blockly.Msg.TABLE_TD_INSERT_IMAGE_SHOW = "Cell Insert Image"; -Blockly.Msg.TABLE_TD_X_SHOW = "Column"; -Blockly.Msg.TABLE_TD_Y_SHOW = "Row"; -Blockly.Msg.TABLE_TD_IMAGE_GET_SHOW = "Get Cell Image"; -Blockly.Msg.TABLE_TD_TEXT_SHOW = "Text"; -Blockly.Msg.TABLE_TD_INSERT_TEXT_SHOW = "Cell Insert Text"; -Blockly.Msg.TABLE_TD_GET_SHOW = "Get Cell"; -Blockly.Msg.TABLE_TD_CLEAR_SHOW = "Cell Clear"; -Blockly.Msg.TABLE_DELETE_SHOW = "Table Delete"; -Blockly.Msg.TABLE_GET_SHOW = "Get Table"; -Blockly.Msg.TABLE_CLEAR_SHOW = "Table Clear"; -Blockly.Msg.TABLE_TD_SET_SHOW = "Cell Set"; -Blockly.Msg.TABLE_BORDER_SET_SHOW = "Table Border Set"; -Blockly.Msg.TABLE_TD_BORDER_SET_SHOW = "Cell Border Set"; -Blockly.Msg.MUSIC_CREATE_SHOW ="Background Music Play"; -Blockly.Msg.MUSIC_LENGTH_SHOW ="Length(ms)"; -Blockly.Msg.MUSIC_LOOP_SHOW ="Loop"; -Blockly.Msg.MUSIC_DELETE_SHOW ="Background Music Stop"; -Blockly.Msg.CANVAS_CREATE_SHOW = "Canvas Create"; -Blockly.Msg.CANVAS_LINE_SHOW = "Canvas Line"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "Line Width"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "Canvas Rect"; -Blockly.Msg.CANVAS_ARC_SHOW = "Canvas Arc"; -Blockly.Msg.CANVAS_R_SHOW = "Radius"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "Start Diameter"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "End Diameter"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "Counterclockwise"; -Blockly.Msg.CANVAS_FILL_SHOW = "F"; -Blockly.Msg.CANVAS_IMG_SHOW = "Canvas Image"; -Blockly.Msg.CANVAS_SX_SHOW = "Crop x0"; -Blockly.Msg.CANVAS_SY_SHOW = "Crop y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "Crop Width"; -Blockly.Msg.CANVAS_SHEIGHT_SHOW = "Crop Height"; -Blockly.Msg.CANVAS_TEXT_SHOW ="Canvas Text"; -Blockly.Msg.CONTEXT_SHOW ="Context"; -Blockly.Msg.FONTNAME_SHOW ="Fontname"; -Blockly.Msg.FONTSIZE_SHOW ="Fontsize"; -Blockly.Msg.FONTCOLOR_SHOW = "Fontcolor"; -Blockly.Msg.TEXTALIGN_SHOW ="Align"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "Canvas Clear"; -Blockly.Msg.CANVAS_DELETE_SHOW = "Canvas Delete"; -Blockly.Msg.IMAGE_CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.COLOR_SHOW = "Color"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Get Collision ID"; -Blockly.Msg.AND_SHOW = " And "; -Blockly.Msg.BOUNDARY_SHOW = "Set Screen Boundary"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "Get Collision with sides of screen "; -Blockly.Msg.SYS_GET_SHOW = "Get Screen"; -Blockly.Msg.ONCLICK_SHOW = "Get onClick"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "Get Mouse Coordinate"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "Timer Intervals(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "Timer Intervals(ms) Once"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "Timer Stop"; -Blockly.Msg.PROPERTY_SHOW = "Property"; -Blockly.Msg.TEXT_TO_NUMBER_SHOW = "TEXT TO NUMBER"; -Blockly.Msg.LOOP_BREAK_SHOW = "LOOP BREAK"; -Blockly.Msg.LOOP_CONTINUE_SHOW = "LOOP CONTINUE"; -Blockly.Msg.FUNCTION_RETURN_SHOW = "FUNCTION RETURN"; diff --git a/GameElements_20180910/blockly/msg/blocks/zh-hans.js b/GameElements_20180910/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 482eaae94d..0000000000 --- a/GameElements_20180910/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,83 +0,0 @@ -Blockly.Msg.TABLE_CREATE_SHOW = "表格 新增"; -Blockly.Msg.TABLE_SET_SHOW = "表格 设定"; -Blockly.Msg.TABLE_TD_WIDTH_SHOW = "储存格宽度"; -Blockly.Msg.TABLE_TD_HEIGHT_SHOW = "储存格高度"; -Blockly.Msg.TABLE_TRCOUNT_SHOW = "列数"; -Blockly.Msg.TABLE_TDCOUNT_SHOW = "行数"; -Blockly.Msg.TABLE_BORDERSTYLE_SHOW = "边框样式"; -Blockly.Msg.TABLE_BORDERWIDTH_SHOW = "边框宽度"; -Blockly.Msg.TABLE_BORDERCOLOR_SHOW = "边框颜色"; -Blockly.Msg.TABLE_BGCOLOR_SHOW = "储存格颜色"; -Blockly.Msg.TABLE_TD_INSERT_IMAGE_SHOW = "储存格 插入图片"; -Blockly.Msg.TABLE_TD_X_SHOW = "纵行"; -Blockly.Msg.TABLE_TD_Y_SHOW = "横列"; -Blockly.Msg.TABLE_TD_IMAGE_GET_SHOW = "取得 储存格图片"; -Blockly.Msg.TABLE_TD_TEXT_SHOW = "文字"; -Blockly.Msg.TABLE_TD_INSERT_TEXT_SHOW = "储存格 插入文字"; -Blockly.Msg.TABLE_TD_GET_SHOW = "取得 储存格"; -Blockly.Msg.TABLE_TD_CLEAR_SHOW = "储存格 清除"; -Blockly.Msg.TABLE_DELETE_SHOW = "表格 删除"; -Blockly.Msg.TABLE_GET_SHOW = "取得 表格"; -Blockly.Msg.TABLE_CLEAR_SHOW = "表格 清除"; -Blockly.Msg.TABLE_TD_SET_SHOW = "储存格 设定"; -Blockly.Msg.TABLE_BORDER_SET_SHOW = "表格 框线设定"; -Blockly.Msg.TABLE_TD_BORDER_SET_SHOW = "储存格 框线设定"; -Blockly.Msg.MUSIC_CREATE_SHOW ="背景音乐 播放"; -Blockly.Msg.MUSIC_LENGTH_SHOW ="长度(ms)"; -Blockly.Msg.MUSIC_LOOP_SHOW ="循环"; -Blockly.Msg.MUSIC_DELETE_SHOW ="背景音乐 停止"; -Blockly.Msg.CANVAS_CREATE_SHOW = "画布 建立"; -Blockly.Msg.CANVAS_LINE_SHOW = "画布 画直线"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "宽度"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "画布 画矩形"; -Blockly.Msg.CANVAS_ARC_SHOW = "画布 画圆"; -Blockly.Msg.CANVAS_R_SHOW = "半径"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "起始径度"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "终止径度"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "顺时钟方向"; -Blockly.Msg.CANVAS_FILL_SHOW = "填满"; -Blockly.Msg.CANVAS_IMG_SHOW = "画布 贴图"; -Blockly.Msg.CANVAS_SX_SHOW = "剪裁x0"; -Blockly.Msg.CANVAS_SY_SHOW = "剪裁y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "剪裁宽度"; -Blockly.Msg.CANVAS_SHEIGHT_SHOW = "剪裁高度"; -Blockly.Msg.CANVAS_TEXT_SHOW ="画布 贴文字"; -Blockly.Msg.CONTEXT_SHOW ="文字"; -Blockly.Msg.FONTNAME_SHOW ="字型名称"; -Blockly.Msg.FONTSIZE_SHOW ="字型大小"; -Blockly.Msg.FONTCOLOR_SHOW = "字型颜色"; -Blockly.Msg.TEXTALIGN_SHOW ="对齐方式"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "画布 清除"; -Blockly.Msg.CANVAS_DELETE_SHOW = "画布 删除"; -Blockly.Msg.IMAGE_CREATE_SHOW = "图片 建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "网址来源"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.COLOR_SHOW = "颜色"; -Blockly.Msg.SET_SHOW = "图片 设定 "; -Blockly.Msg.GET_SHOW = "图片 取得 "; -Blockly.Msg.DELETE_SHOW = "图片 删除"; -Blockly.Msg.COLLISION_SHOW = "图片 取得接触状态 代码"; -Blockly.Msg.AND_SHOW = " 与 "; -Blockly.Msg.BOUNDARY_SHOW = "视窗 设定大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得 图片边界状态"; -Blockly.Msg.SYS_GET_SHOW = "取得 视窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得 图片点选状态"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得 滑鼠座标"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "计时器 间隔时间(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "计时器 间隔时间(ms)后执行一次"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "计时器 停止"; -Blockly.Msg.PROPERTY_SHOW = "属性"; -Blockly.Msg.TEXT_TO_NUMBER_SHOW = "文字转数字"; -Blockly.Msg.LOOP_BREAK_SHOW = "迴圈 中断"; -Blockly.Msg.LOOP_CONTINUE_SHOW = "迴圈 继续"; -Blockly.Msg.FUNCTION_RETURN_SHOW = "函数 回传"; diff --git a/GameElements_20180910/blockly/msg/blocks/zh-hant.js b/GameElements_20180910/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index f0ce001148..0000000000 --- a/GameElements_20180910/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,83 +0,0 @@ -Blockly.Msg.TABLE_CREATE_SHOW = "表格 新增"; -Blockly.Msg.TABLE_SET_SHOW = "表格 設定"; -Blockly.Msg.TABLE_TD_WIDTH_SHOW = "儲存格寬度"; -Blockly.Msg.TABLE_TD_HEIGHT_SHOW = "儲存格高度"; -Blockly.Msg.TABLE_TRCOUNT_SHOW = "列數"; -Blockly.Msg.TABLE_TDCOUNT_SHOW = "行數"; -Blockly.Msg.TABLE_BORDERSTYLE_SHOW = "邊框樣式"; -Blockly.Msg.TABLE_BORDERWIDTH_SHOW = "邊框寬度"; -Blockly.Msg.TABLE_BORDERCOLOR_SHOW = "邊框顏色"; -Blockly.Msg.TABLE_BGCOLOR_SHOW = "儲存格顏色"; -Blockly.Msg.TABLE_TD_INSERT_IMAGE_SHOW = "儲存格 插入圖片"; -Blockly.Msg.TABLE_TD_X_SHOW = "縱行"; -Blockly.Msg.TABLE_TD_Y_SHOW = "橫列"; -Blockly.Msg.TABLE_TD_IMAGE_GET_SHOW = "取得 儲存格圖片"; -Blockly.Msg.TABLE_TD_TEXT_SHOW = "文字"; -Blockly.Msg.TABLE_TD_INSERT_TEXT_SHOW = "儲存格 插入文字"; -Blockly.Msg.TABLE_TD_GET_SHOW = "取得 儲存格"; -Blockly.Msg.TABLE_TD_CLEAR_SHOW = "儲存格 清除"; -Blockly.Msg.TABLE_DELETE_SHOW = "表格 刪除"; -Blockly.Msg.TABLE_GET_SHOW = "取得 表格"; -Blockly.Msg.TABLE_CLEAR_SHOW = "表格 清除"; -Blockly.Msg.TABLE_TD_SET_SHOW = "儲存格 設定"; -Blockly.Msg.TABLE_BORDER_SET_SHOW = "表格 框線設定"; -Blockly.Msg.TABLE_TD_BORDER_SET_SHOW = "儲存格 框線設定"; -Blockly.Msg.MUSIC_CREATE_SHOW ="背景音樂 播放"; -Blockly.Msg.MUSIC_LENGTH_SHOW ="長度(ms)"; -Blockly.Msg.MUSIC_LOOP_SHOW ="循環"; -Blockly.Msg.MUSIC_DELETE_SHOW ="背景音樂 停止"; -Blockly.Msg.CANVAS_CREATE_SHOW = "畫布 建立"; -Blockly.Msg.CANVAS_LINE_SHOW = "畫布 畫直線"; -Blockly.Msg.CANVAS_LINEWIDTH_SHOW = "寬度"; -Blockly.Msg.CANVAS_X0_SHOW = "x0"; -Blockly.Msg.CANVAS_Y0_SHOW = "y0"; -Blockly.Msg.CANVAS_X1_SHOW = "x1"; -Blockly.Msg.CANVAS_Y1_SHOW = "y1"; -Blockly.Msg.CANVAS_RECT_SHOW = "畫布 畫矩形"; -Blockly.Msg.CANVAS_ARC_SHOW = "畫布 畫圓"; -Blockly.Msg.CANVAS_R_SHOW = "半徑"; -Blockly.Msg.CANVAS_SANGLE_SHOW = "起始徑度"; -Blockly.Msg.CANVAS_EANGLE_SHOW = "終止徑度"; -Blockly.Msg.CANVAS_COUNTERCLOCKWISE_SHOW = "順時鐘方向"; -Blockly.Msg.CANVAS_FILL_SHOW = "填滿"; -Blockly.Msg.CANVAS_IMG_SHOW = "畫布 貼圖"; -Blockly.Msg.CANVAS_SX_SHOW = "剪裁x0"; -Blockly.Msg.CANVAS_SY_SHOW = "剪裁y0"; -Blockly.Msg.CANVAS_SWIDTH_SHOW = "剪裁寬度"; -Blockly.Msg.CANVAS_SHEIGHT_SHOW = "剪裁高度"; -Blockly.Msg.CANVAS_TEXT_SHOW ="畫布 貼文字"; -Blockly.Msg.CONTEXT_SHOW ="文字"; -Blockly.Msg.FONTNAME_SHOW ="字型名稱"; -Blockly.Msg.FONTSIZE_SHOW ="字型大小"; -Blockly.Msg.FONTCOLOR_SHOW = "字型顏色"; -Blockly.Msg.TEXTALIGN_SHOW ="對齊方式"; -Blockly.Msg.CANVAS_CLEAR_SHOW = "畫布 清除"; -Blockly.Msg.CANVAS_DELETE_SHOW = "畫布 刪除"; -Blockly.Msg.IMAGE_CREATE_SHOW = "圖片 建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "網址來源"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.COLOR_SHOW = "顏色"; -Blockly.Msg.SET_SHOW = "圖片 設定 "; -Blockly.Msg.GET_SHOW = "圖片 取得 "; -Blockly.Msg.DELETE_SHOW = "圖片 刪除"; -Blockly.Msg.COLLISION_SHOW = "圖片 取得接觸狀態 代碼"; -Blockly.Msg.AND_SHOW = " 與 "; -Blockly.Msg.BOUNDARY_SHOW = "視窗 設定大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得 圖片邊界狀態"; -Blockly.Msg.SYS_GET_SHOW = "取得 視窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得 圖片點選狀態"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得 滑鼠座標"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "計時器 間隔時間(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "計時器 間隔時間(ms)後執行一次"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "計時器 停止"; -Blockly.Msg.PROPERTY_SHOW = "屬性"; -Blockly.Msg.TEXT_TO_NUMBER_SHOW = "文字轉數字"; -Blockly.Msg.LOOP_BREAK_SHOW = "迴圈 中斷"; -Blockly.Msg.LOOP_CONTINUE_SHOW = "迴圈 繼續"; -Blockly.Msg.FUNCTION_RETURN_SHOW = "函數 回傳"; diff --git a/GameElements_20180910/blockly/msg/en.js b/GameElements_20180910/blockly/msg/en.js deleted file mode 100644 index d91df621b7..0000000000 --- a/GameElements_20180910/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "Game Elements"; diff --git a/GameElements_20180910/blockly/msg/zh-hans.js b/GameElements_20180910/blockly/msg/zh-hans.js deleted file mode 100644 index e338c4eb2d..0000000000 --- a/GameElements_20180910/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "游戏元素"; diff --git a/GameElements_20180910/blockly/msg/zh-hant.js b/GameElements_20180910/blockly/msg/zh-hant.js deleted file mode 100644 index f40b768d28..0000000000 --- a/GameElements_20180910/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catGameElements = "遊戲元素"; diff --git a/GameElements_20180910/blockly/toolbox.xml b/GameElements_20180910/blockly/toolbox.xml deleted file mode 100644 index e68120c2db..0000000000 --- a/GameElements_20180910/blockly/toolbox.xml +++ /dev/null @@ -1,609 +0,0 @@ - - - - - 100 - - - - - - - 1000 - - - - - - - - - - - - - - - - - 0 - - - - - - - 0 - - - - - 100 - - - - - 1 - - - - - #000000 - - - - - 5 - - - - - 5 - - - - - 60 - - - - - 60 - - - - - #ff0000 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - 50 - - - - - 50 - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - Arial - - - - - 12 - - - - - #ff0000 - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - 1 - - - - - #000000 - - - - - - - 0 - - - - - 0 - - - - - 1 - - - - - #000000 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 500 - - - - - 500 - - - - - 0 - - - - - 100 - - - - - 0 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 100 - - - - - #ff0000 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 100 - - - - - FALSE - - - - - #ff0000 - - - - - - - 5 - - - - - 0 - - - - - 0 - - - - - 100 - - - - - 0 - - - - - 6.284 - - - - - FALSE - - - - - FALSE - - - - - #ff0000 - - - - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - Hello World - - - - - 0 - - - - - 100 - - - - - Arial - - - - - 30 - - - - - TRUE - - - - - #ff0000 - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 20000 - - - - - TRUE - - - - - - diff --git a/GameElements_20180910/gameelements.js b/GameElements_20180910/gameelements.js deleted file mode 100644 index dc597116fb..0000000000 --- a/GameElements_20180910/gameelements.js +++ /dev/null @@ -1,718 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) 2018-9-15 23:00 -// https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var screen_width = 0; - var screen_height = 0; - var onclickid = ""; - var onclicktime = 200; - var onclicktimerid; - var mouse_x,mouse_y; - var ImageWidth,ImageHeight; - - function table_create(input_id,input_width,input_height,input_left,input_top,input_trcount,input_tdcount,input_borderstyle,input_borderwidth,input_bordercolor,input_bgcolor,input_zindex,input_display) { - if (document.getElementById("gametable_"+input_id)) - document.getElementById("gametable_"+input_id).parentNode.removeChild(document.getElementById("gametable_"+input_id)); - if ((input_trcount>=1)&&(input_tdcount>=1)){ - var tbl = document.createElement('table'); - tbl.id = "gametable_"+input_id; - tbl.style.position = "absolute"; - tbl.style.left = input_left + 'px'; - tbl.style.top = input_top + 'px'; - tbl.style.zIndex = input_zindex; - tbl.style.border = input_borderwidth +'px ' + input_borderstyle + ' ' + input_bordercolor; - if (input_display==0) - tbl.style.display = "none"; - else - tbl.style.display = "block"; - var tr,td; - for (var i=0;i0){ - for (var i=0;i0){ - for (var j=0;j=5){ - var arr = onclickid.split("_"); - return Number(arr[arr.length-1]); - } - else - return ""; - } - else - return ""; - } - else if (input_property=="onclickRow"){ - if (onclickid.indexOf("gametable_td_"+input_id)==0){ - if (onclickid.split("_").length>=5){ - var arr = onclickid.split("_"); - return Number(arr[arr.length-2]); - } - else - return ""; - } - else - return ""; - } - else if (input_property=="onclick[Column,Row]"){ - if (onclickid.indexOf("gametable_td_"+input_id)==0){ - if (onclickid.split("_").length>=5){ - var arr = onclickid.split("_"); - onclickid=""; - arr = [arr[arr.length-1],arr[arr.length-2]]; - return arr; - } - else - return ""; - } - else - return ""; - } - else if (input_property=="onclickImage"){ - if (onclickid.indexOf("gametable_td_"+input_id)==0){ - if (document.getElementById(onclickid).hasChildNodes()) - return document.getElementById(onclickid).firstChild.id.replace(/gameimg_/ig,""); - else - return ""; - } - else - return ""; - } - else - return ""; - } - else - return ""; - } - - function table_clear(input_id){ - if (document.getElementById("gametable_"+input_id)) { - var obj = document.getElementById("gametable_"+input_id); - if (document.getElementById("gametable_"+input_id).rows.length>0){ - for (var i=0;i0){ - for (var j=0;j 0){ - if (td.childNodes[0].id.indexOf("gameimg_")==0) - return td.childNodes[0].id.substr(8); - else - return ""; - } - else - return ""; - } - else if (input_property=="tdid") - return "gametable_td_"+input_id+"_"+input_y+'_'+input_x; - } - else - return ""; - } - - - function table_td_insert_img(input_id,input_x,input_y,input_img_id,input_url,input_width,input_height){ - if (document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x)){ - var img = document.createElement('img'); - img.id = "gameimg_"+input_img_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.setAttribute("onclick", "javascript:image_onclickid_set(this);"); - document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x).appendChild(img); - } - } - - function table_td_img_get(input_img_id,input_property){ - if (document.getElementById("gameimg_"+input_img_id)){ - if (document.getElementById("gameimg_"+input_img_id).parentNode.id.split("_").length>=5){ - var arr = document.getElementById("gameimg_"+input_img_id).parentNode.id.split("_"); - if (input_property=="column") - return Number(arr[arr.length-1]); - else if (input_property=="row") - return Number(arr[arr.length-2]); - else if (input_property=="width") - return Number(document.getElementById("gameimg_"+input_img_id).style.width.replace(/px/ig,"")); - else if (input_property=="height") - return Number(document.getElementById("gameimg_"+input_img_id).style.height.replace(/px/ig,"")); - else if (input_property=='naturalwidth'){ - var naturl = image_Natural_get(document.getElementById("gameimg_"+input_img_id)); - return Number(naturl.width); - } - else if (input_property=='naturalheight'){ - var naturl = image_Natural_get(document.getElementById("gameimg_"+input_img_id)); - return Number(naturl.height); - } - else if (input_property=="imageid") - return "gameimg_"+input_img_id; - } - else - return -1; - } - else - return -1; - } - - function table_td_insert_text(input_id,input_x,input_y,input_text,input_fontname,input_fontsize,input_color){ - if (document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x)) - document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x).innerHTML = "" + input_text + ""; - } - - function table_td_clear(input_id,input_x,input_y){ - if (document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x)) - document.getElementById("gametable_td_"+input_id+"_"+input_y+"_"+input_x).innerHTML = ""; - } - - function table_delete(input_id) { - if (document.getElementById("gametable_"+input_id)) - document.getElementById("gametable_"+input_id).parentNode.removeChild(document.getElementById("gametable_"+input_id)); - } - - function music_create(input_url) { - var substr = input_url.toLowerCase().split('.'); - var extname_av = ".aac,.au,.aif,.aiff,.aiffc,.alac,.ape,.asf,.avi,.cda,.dat,.divx,.flac,.m2ts,.m4a,.mid,.mov,.mp2,.mp3,.mp4,.mpc,.mpg,.mpeg,.mv2,.ogg,.pdf,.ra,.ram,.raw,.rcp,.rm,.rmvb,.snd,.tak,.tta,.vob,.voc,.wma,.wav,.webm,.wmf,.wmv,.wv,.xmi,"; - var extname_flash = ".swf,.flv,"; - - if (input_url.toLowerCase().indexOf("http")!=0) - var src = input_url; - else if (extname_av.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else if (extname_flash.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else - var src = ''; - - if (document.getElementById("gamemusic_")) - document.getElementById("gamemusic_").parentNode.removeChild(document.getElementById("gamemusic_")); - var div = document.createElement('div'); - div.id = "gamemusic_"; - div.style.position = 'absolute'; - div.style.left = '0px'; - div.style.top = '0px'; - div.style.zIndex = -1; - div.style.display = 'none'; - div.innerHTML = src; - document.body.appendChild(div); - } - - function music_delete() { - if (document.getElementById("gamemusic_")) - document.getElementById("gamemusic_").parentNode.removeChild(document.getElementById("gamemusic_")); - } - - function canvas_create(input_id ,input_width,input_height,input_left,input_top,input_zindex) { - if (document.getElementById("gamecanvas_"+input_id)) - document.getElementById("gamecanvas_"+input_id).parentNode.removeChild(document.getElementById("gamecanvas_"+input_id)); - var can = document.createElement('canvas'); - can.style.position = "absolute"; - can.id = "gamecanvas_"+input_id; - can.setAttribute("width",input_width + 'px'); - can.setAttribute("height",input_height + 'px'); - can.style.left = input_left + 'px'; - can.style.top = input_top + 'px'; - can.style.zIndex = input_zindex; - document.body.appendChild(can); - - var img = document.createElement('img'); - img.id = "gamecanvasimg"; - img.style.display = "none"; - document.body.appendChild(img); - } - - function canvas_line(input_id,input_linewidth,input_x0,input_y0,input_x1,input_y1,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.moveTo(input_x0,input_y0); - context.lineTo(input_x1,input_y1); - context.stroke(); - } - } - - function canvas_rect(input_id,input_linewidth,input_x0,input_y0,input_width,input_height,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.rect(input_x0,input_y0,input_width,input_height); - if (input_fill==0) - context.stroke(); - else - context.fill(); - } - } - - function canvas_arc(input_id,input_linewidth,input_x0,input_y0,input_r,input_sAngle,input_eAngle,input_counterclockwise,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.lineWidth = input_linewidth; - context.beginPath(); - context.arc(input_x0,input_y0,input_r,input_sAngle,input_eAngle,input_counterclockwise); - if (input_fill==0) - context.stroke(); - else - context.fill(); - } - } - - function canvas_img(input_id,input_url,input_sx,input_sy,input_swidth,input_sheight,input_x0,input_y0,input_width,input_height) { - if (document.getElementById("gamecanvas_"+input_id)) { - var img = document.getElementById("gamecanvasimg"); - img.src = input_url; - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - if ((input_swidth>0)&&(input_sheight>0)) - context.drawImage(img,input_sx,input_sy,input_swidth,input_sheight,input_x0,input_y0,input_width,input_height); - else if (((input_swidth==0)||(input_sheight==0))&&((input_width>0)&&(input_height>0))) - context.drawImage(img,input_x0,input_y0,input_width,input_height); - else - context.drawImage(img,input_x0,input_y0); - } - } - - function canvas_text(input_id,input_text,input_x0,input_y0,input_fontname,input_fontsize,input_textalign,input_fill,input_color) { - if (document.getElementById("gamecanvas_"+input_id)) { - var context = document.getElementById("gamecanvas_"+input_id).getContext("2d"); - context.strokeStyle = input_color; - context.fillStyle = input_color; - context.font = input_fontsize + 'px ' + input_fontname; - context.textAlign = input_textalign; - if (input_fill==0) - context.strokeText(input_text,input_x0,input_y0); - else - context.fillText(input_text,input_x0,input_y0); - } - } - - function canvas_clear(input_id) { - if (document.getElementById("gamecanvas_"+input_id)) { - var canvas = document.getElementById("gamecanvas_"+input_id); - var context = canvas.getContext("2d"); - context.clearRect(0, 0, canvas.width, canvas.height); - } - } - - function canvas_delete(input_id) { - if (document.getElementById("gamecanvas_"+input_id)) - document.getElementById("gamecanvas_"+input_id).parentNode.removeChild(document.getElementById("gamecanvas_"+input_id)); - } - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("gameimg_"+input_id)) - document.getElementById("gameimg_"+input_id).parentNode.removeChild(document.getElementById("gameimg_"+input_id)); - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "gameimg_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==0) - img.style.display = "none"; - else - img.style.display = "block"; - img.setAttribute("onclick", "javascript:image_onclickid_set(this);"); - document.body.appendChild(img); - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - document.getElementById("gameimg_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("gameimg_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("gameimg_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("gameimg_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("gameimg_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("gameimg_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==0) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else if (input_property=='opacity') - document.getElementById("gameimg_"+input_id).style.opacity = input_value; - else if (input_property=='rotate') - document.getElementById("gameimg_"+input_id).style.transform = "rotate("+input_value+"deg)"; - else if (input_property=='rotateX') - document.getElementById("gameimg_"+input_id).style.transform = "rotateX("+input_value+"deg)"; - else if (input_property=='rotateY') - document.getElementById("gameimg_"+input_id).style.transform = "rotateY("+input_value+"deg)"; - else if (input_property=='rotateZ') - document.getElementById("gameimg_"+input_id).style.transform = "rotateZ("+input_value+"deg)"; - else if (input_property=='moveX') - document.getElementById("gameimg_"+input_id).style.left = (Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,""))+Number(input_value))+"px"; - else if (input_property=='moveY') - document.getElementById("gameimg_"+input_id).style.top = (Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,""))+Number(input_value))+"px"; - } - } - - function image_get(input_id,input_property) { - if (input_property=="onclickid"){ - if (onclickid.indexOf("gameimg_")==0) - return onclickid.replace(/gameimg_/ig,""); - else if (onclickid.indexOf("gametable_td_")==0){ - if (document.getElementById(onclickid).hasChildNodes()) - return document.getElementById(onclickid).firstChild.id.replace(/gameimg_/ig,""); - else - return ""; - } - else - return ""; - } - else if (input_property=='exist') - { - if (document.getElementById("gameimg_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - return document.getElementById("gameimg_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='naturalwidth'){ - var naturl = image_Natural_get(document.getElementById("gameimg_"+input_id)); - return Number(naturl.width); - } - else if (input_property=='naturalheight'){ - var naturl = image_Natural_get(document.getElementById("gameimg_"+input_id)); - return Number(naturl.height); - } - else if (input_property=='left') - return Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("gameimg_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("gameimg_"+input_id).style.display=="block") - return 1; - else - return 0; - } - else if (input_property=='opacity') - return document.getElementById("gameimg_"+input_id).style.opacity; - else if (input_property=='rotate') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateX') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateY') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateZ') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='id') - return "gameimg_"+input_id; - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("gameimg_"+input_id)) - document.getElementById("gameimg_"+input_id).parentNode.removeChild(document.getElementById("gameimg_"+input_id)); - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("gameimg_"+input_id1))&&(document.getElementById("gameimg_"+input_id2))) - { - var img1 = document.getElementById("gameimg_"+input_id1).style; - var img2 = document.getElementById("gameimg_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - function image_boundary(input_left,input_top) { - if (input_left>=0) screen_width = input_left; - if (input_top>=0) screen_height = input_top; - } - - function image_boundary_collision(input_id,input_property) { - if ((screen_width>0)||(screen_height>0)) - { - var left = Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - var width = Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - var top = Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - var height = Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - if (screen_width>0) - { - if (((input_property=="left")||(input_property=="any"))&&(left<=0)) return 1 - if (((input_property=="right")||(input_property=="any"))&&(left+width>=screen_width)) return 1 - } - if (screen_height>0) - { - if (((input_property=="up")||(input_property=="any"))&&(top<=0)) return 1 - if (((input_property=="down")||(input_property=="any"))&&(top+height>=screen_height)) return 1 - } - return 0; - } - else - return 0; - } - - function image_sys_get(input_property) { - if (input_property=='screen_width') - return screen_width; - else if (input_property=='screen_height') - return screen_height; - else - return; - } - - function image_onclickid_set(obj) { - clearTimeout(onclicktimerid); - onclickid=obj.id; - onclicktimerid=setTimeout('image_onclickid_clear()',onclicktime); - } - - function image_onclickid_clear() { - onclickid=""; - } - - function image_onclick_get(input_id) { - if (onclickid==("gameimg_"+input_id)) - { - onclickid=""; - return 1; - } - else - return 0; - } - - function image_Natural_get (obj) { - var img = new Image(); - img.src = obj.src; - return {width: img.width, height: img.height}; - } - - function mouse_coordinate_get(input_property) { - if (!document.onmousemove) - { - document.onmousemove = function(e){ - e=e||window.event; - mouse_x = e.pageX; - mouse_y = e.pageY; - } - console.log("set"); - } - if (input_property=="x") - return mouse_x; - else if (input_property=="y") - return mouse_y; - } - - function text_to_number(input_text) { - return Number(input_text); - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - window.image_boundary = image_boundary; - window.image_boundary_collision = image_boundary_collision; - window.image_sys_get = image_sys_get; - window.image_onclickid_set = image_onclickid_set; - window.image_onclickid_clear = image_onclickid_clear; - window.image_onclick_get = image_onclick_get; - window.image_Natural_get = image_Natural_get; - window.mouse_coordinate_get = mouse_coordinate_get; - window.canvas_create = canvas_create; - window.canvas_line = canvas_line; - window.canvas_rect = canvas_rect; - window.canvas_arc = canvas_arc; - window.canvas_img = canvas_img; - window.canvas_text = canvas_text; - window.canvas_clear = canvas_clear; - window.canvas_delete = canvas_delete; - window.music_create = music_create; - window.music_delete = music_delete; - window.table_create = table_create; - window.table_set = table_set; - window.table_delete = table_delete; - window.table_td_insert_img = table_td_insert_img; - window.table_td_img_get = table_td_img_get; - window.table_td_insert_text = table_td_insert_text; - window.table_td_get = table_td_get; - window.table_td_clear = table_td_clear; - window.table_get = table_get; - window.table_clear = table_clear; - window.table_td_set = table_td_set; - window.table_border_set = table_border_set; - window.table_td_border_set = table_td_border_set; - window.text_to_number = text_to_number; - -}(window, window.document)); diff --git a/GameImage_20180727/blockly.json b/GameImage_20180727/blockly.json deleted file mode 100644 index ed2d8d505e..0000000000 --- a/GameImage_20180727/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["image_create","image_set","image_get","image_delete","image_collision"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameimage.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameImage_20180727/blockly/blocks.js b/GameImage_20180727/blockly/blocks.js deleted file mode 100644 index 3044c6cb49..0000000000 --- a/GameImage_20180727/blockly/blocks.js +++ /dev/null @@ -1,99 +0,0 @@ -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck("Boolean") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["id","id"], ["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; diff --git a/GameImage_20180727/blockly/javascript.js b/GameImage_20180727/blockly/javascript.js deleted file mode 100644 index fb18e77fad..0000000000 --- a/GameImage_20180727/blockly/javascript.js +++ /dev/null @@ -1,40 +0,0 @@ -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; diff --git a/GameImage_20180727/blockly/msg/blocks/en.js b/GameImage_20180727/blockly/msg/blocks/en.js deleted file mode 100644 index b587f00c77..0000000000 --- a/GameImage_20180727/blockly/msg/blocks/en.js +++ /dev/null @@ -1,14 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Image Collision ID"; -Blockly.Msg.AND_SHOW = " And "; diff --git a/GameImage_20180727/blockly/msg/blocks/zh-hans.js b/GameImage_20180727/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index f81597a323..0000000000 --- a/GameImage_20180727/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,14 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "图片建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "来源网址"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.SET_SHOW = "设定图片 "; -Blockly.Msg.GET_SHOW = "取得图片 "; -Blockly.Msg.DELETE_SHOW = "删除图片"; -Blockly.Msg.COLLISION_SHOW = "取得图片 接触状态 代码 "; -Blockly.Msg.AND_SHOW = " 与 "; diff --git a/GameImage_20180727/blockly/msg/blocks/zh-hant.js b/GameImage_20180727/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index c8e4cfb283..0000000000 --- a/GameImage_20180727/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,14 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "圖片建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "來源網址"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.SET_SHOW = "設定圖片 "; -Blockly.Msg.GET_SHOW = "取得圖片 "; -Blockly.Msg.DELETE_SHOW = "刪除圖片"; -Blockly.Msg.COLLISION_SHOW = "取得圖片 接觸狀態 代碼 "; -Blockly.Msg.AND_SHOW = " 與 "; diff --git a/GameImage_20180727/blockly/msg/en.js b/GameImage_20180727/blockly/msg/en.js deleted file mode 100644 index 0adb114735..0000000000 --- a/GameImage_20180727/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "Game Image"; diff --git a/GameImage_20180727/blockly/msg/zh-hans.js b/GameImage_20180727/blockly/msg/zh-hans.js deleted file mode 100644 index b6c170092c..0000000000 --- a/GameImage_20180727/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "游戏图片"; diff --git a/GameImage_20180727/blockly/msg/zh-hant.js b/GameImage_20180727/blockly/msg/zh-hant.js deleted file mode 100644 index 66af270c69..0000000000 --- a/GameImage_20180727/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "遊戲圖片"; diff --git a/GameImage_20180727/blockly/toolbox.xml b/GameImage_20180727/blockly/toolbox.xml deleted file mode 100644 index 568f03ed9c..0000000000 --- a/GameImage_20180727/blockly/toolbox.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/GameImage_20180727/gameimage.js b/GameImage_20180727/gameimage.js deleted file mode 100644 index 09129f440e..0000000000 --- a/GameImage_20180727/gameimage.js +++ /dev/null @@ -1,138 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("img_"+input_id)) - { - document.getElementById("img_"+input_id).src = input_url; - document.getElementById("img_"+input_id).style.width = input_width + 'px'; - document.getElementById("img_"+input_id).style.height = input_height + 'px'; - document.getElementById("img_"+input_id).style.left = input_left + 'px'; - document.getElementById("img_"+input_id).style.top = input_top + 'px'; - document.getElementById("img_"+input_id).style.zIndex = input_zindex; - if (input_display==false) - document.getElementById("img_"+input_id).style.display = "none"; - else - document.getElementById("img_"+input_id).style.display = "block"; - } - else - { - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "img_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==false) - img.style.display = "none"; - else - img.style.display = "block"; - - document.body.appendChild(img); - } - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("img_"+input_id)) - { - if (input_property=='url') - document.getElementById("img_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("img_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("img_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("img_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("img_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("img_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==false) - document.getElementById("img_"+input_id).style.display = "none"; - else - document.getElementById("img_"+input_id).style.display = "block"; - } - } - } - - function image_get(input_id,input_property) { - if (input_property=='id') - { - if (document.getElementById("img_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("img_"+input_id)) - { - if (input_property=='url') - return document.getElementById("img_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("img_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("img_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='left') - return Number(document.getElementById("img_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("img_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("img_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("img_"+input_id).style.display=="block") - return 1; - else - return 0; - } - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("img_"+input_id)) - { - document.body.removeChild(document.getElementById("img_"+input_id)); - } - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("img_"+input_id1))&&(document.getElementById("img_"+input_id2))) - { - var img1 = document.getElementById("img_"+input_id1).style; - var img2 = document.getElementById("img_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - -}(window, window.document)); diff --git a/GameImage_20180729/blockly.json b/GameImage_20180729/blockly.json deleted file mode 100644 index ae57dea6fb..0000000000 --- a/GameImage_20180729/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["image_create","image_set","image_get","image_delete","image_collision","image_boundary","image_boundary_collision","image_sys_get"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameimage.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameImage_20180729/blockly/blocks.js b/GameImage_20180729/blockly/blocks.js deleted file mode 100644 index b430825545..0000000000 --- a/GameImage_20180729/blockly/blocks.js +++ /dev/null @@ -1,139 +0,0 @@ -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck("Boolean") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["id","id"], ["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary'] = { - init: function() { - this.appendValueInput("left_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.BOUNDARY_SHOW) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("top_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary_collision'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.BOUNDARY_COLLISION_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_sys_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SYS_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["screen_width","screen_width"], ["screen_height","screen_height"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; diff --git a/GameImage_20180729/blockly/javascript.js b/GameImage_20180729/blockly/javascript.js deleted file mode 100644 index 40c0a1da48..0000000000 --- a/GameImage_20180729/blockly/javascript.js +++ /dev/null @@ -1,59 +0,0 @@ -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_boundary'] = function (block) { - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary(' + value_left_ + ',' + value_top_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_boundary_collision'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary_collision(' + value_id_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_sys_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'image_sys_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; diff --git a/GameImage_20180729/blockly/msg/blocks/en.js b/GameImage_20180729/blockly/msg/blocks/en.js deleted file mode 100644 index 0367f20858..0000000000 --- a/GameImage_20180729/blockly/msg/blocks/en.js +++ /dev/null @@ -1,17 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Image Collision ID"; -Blockly.Msg.AND_SHOW = " And "; -Blockly.Msg.BOUNDARY_SHOW = "Set Screen Boundary"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "Image Screen Boundary Collision ID"; -Blockly.Msg.SYS_GET_SHOW = "Get Screen"; diff --git a/GameImage_20180729/blockly/msg/blocks/zh-hans.js b/GameImage_20180729/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 4acdf1ec14..0000000000 --- a/GameImage_20180729/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,17 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "图片建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "来源网址"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.SET_SHOW = "设定图片 "; -Blockly.Msg.GET_SHOW = "取得图片 "; -Blockly.Msg.DELETE_SHOW = "删除图片"; -Blockly.Msg.COLLISION_SHOW = "取得图片 接触状态 代码"; -Blockly.Msg.AND_SHOW = " 与 "; -Blockly.Msg.BOUNDARY_SHOW = "设定视窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得图片 边界状态 代码"; -Blockly.Msg.SYS_GET_SHOW = "取得视窗"; diff --git a/GameImage_20180729/blockly/msg/blocks/zh-hant.js b/GameImage_20180729/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 88eab66ee9..0000000000 --- a/GameImage_20180729/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,17 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "圖片建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "來源網址"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.SET_SHOW = "設定圖片 "; -Blockly.Msg.GET_SHOW = "取得圖片 "; -Blockly.Msg.DELETE_SHOW = "刪除圖片"; -Blockly.Msg.COLLISION_SHOW = "取得圖片 接觸狀態 代碼"; -Blockly.Msg.AND_SHOW = " 與 "; -Blockly.Msg.BOUNDARY_SHOW = "設定視窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得圖片 邊界狀態 代碼"; -Blockly.Msg.SYS_GET_SHOW = "取得視窗 "; diff --git a/GameImage_20180729/blockly/msg/en.js b/GameImage_20180729/blockly/msg/en.js deleted file mode 100644 index 0adb114735..0000000000 --- a/GameImage_20180729/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "Game Image"; diff --git a/GameImage_20180729/blockly/msg/zh-hans.js b/GameImage_20180729/blockly/msg/zh-hans.js deleted file mode 100644 index b6c170092c..0000000000 --- a/GameImage_20180729/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "游戏图片"; diff --git a/GameImage_20180729/blockly/msg/zh-hant.js b/GameImage_20180729/blockly/msg/zh-hant.js deleted file mode 100644 index 66af270c69..0000000000 --- a/GameImage_20180729/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "遊戲圖片"; diff --git a/GameImage_20180729/blockly/toolbox.xml b/GameImage_20180729/blockly/toolbox.xml deleted file mode 100644 index 1d223c6c70..0000000000 --- a/GameImage_20180729/blockly/toolbox.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - diff --git a/GameImage_20180729/gameimage.js b/GameImage_20180729/gameimage.js deleted file mode 100644 index 2d30881586..0000000000 --- a/GameImage_20180729/gameimage.js +++ /dev/null @@ -1,175 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var screen_width = 0; - var screen_height = 0; - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("img_"+input_id)) - { - document.getElementById("img_"+input_id).src = input_url; - document.getElementById("img_"+input_id).style.width = input_width + 'px'; - document.getElementById("img_"+input_id).style.height = input_height + 'px'; - document.getElementById("img_"+input_id).style.left = input_left + 'px'; - document.getElementById("img_"+input_id).style.top = input_top + 'px'; - document.getElementById("img_"+input_id).style.zIndex = input_zindex; - if (input_display==false) - document.getElementById("img_"+input_id).style.display = "none"; - else - document.getElementById("img_"+input_id).style.display = "block"; - } - else - { - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "img_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==false) - img.style.display = "none"; - else - img.style.display = "block"; - - document.body.appendChild(img); - } - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("img_"+input_id)) - { - if (input_property=='url') - document.getElementById("img_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("img_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("img_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("img_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("img_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("img_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==false) - document.getElementById("img_"+input_id).style.display = "none"; - else - document.getElementById("img_"+input_id).style.display = "block"; - } - } - } - - function image_get(input_id,input_property) { - if (input_property=='id') - { - if (document.getElementById("img_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("img_"+input_id)) - { - if (input_property=='url') - return document.getElementById("img_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("img_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("img_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='left') - return Number(document.getElementById("img_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("img_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("img_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("img_"+input_id).style.display=="block") - return 1; - else - return 0; - } - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("img_"+input_id)) - { - document.body.removeChild(document.getElementById("img_"+input_id)); - } - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("img_"+input_id1))&&(document.getElementById("img_"+input_id2))) - { - var img1 = document.getElementById("img_"+input_id1).style; - var img2 = document.getElementById("img_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - function image_boundary(input_left,input_top) { - if (input_left>=0) screen_width = input_left; - if (input_top>=0) screen_height = input_top; - } - - function image_boundary_collision(input_id) { - if ((screen_width>0)||(screen_height>0)) - { - var left = Number(document.getElementById("img_"+input_id).style.left.replace(/px/ig,"")); - var width = Number(document.getElementById("img_"+input_id).style.width.replace(/px/ig,"")); - var top = Number(document.getElementById("img_"+input_id).style.top.replace(/px/ig,"")); - var height = Number(document.getElementById("img_"+input_id).style.height.replace(/px/ig,"")); - if (screen_width>0) - if ((left<=0)||(left+width>=screen_width)) return 1 - if (screen_height>0) - if ((top<=0)||(top+height>=screen_height)) return 1 - return 0; - } - else - return 0; - } - - function image_sys_get(input_property) { - if (input_property=='screen_width') - return screen_width; - else if (input_property=='screen_height') - return screen_height; - else - return; - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - window.image_boundary = image_boundary; - window.image_boundary_collision = image_boundary_collision; - window.image_sys_get = image_sys_get; - -}(window, window.document)); diff --git a/GameImage_20180730/blockly.json b/GameImage_20180730/blockly.json deleted file mode 100644 index ae57dea6fb..0000000000 --- a/GameImage_20180730/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["image_create","image_set","image_get","image_delete","image_collision","image_boundary","image_boundary_collision","image_sys_get"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameimage.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameImage_20180730/blockly/blocks.js b/GameImage_20180730/blockly/blocks.js deleted file mode 100644 index f0989cb1aa..0000000000 --- a/GameImage_20180730/blockly/blocks.js +++ /dev/null @@ -1,142 +0,0 @@ -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck("Boolean") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["id","id"], ["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary'] = { - init: function() { - this.appendValueInput("left_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.BOUNDARY_SHOW) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("top_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary_collision'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.BOUNDARY_COLLISION_SHOW) - .appendField(new Blockly.FieldDropdown([["up","up"], ["down","down"], ["left","left"], ["right","right"], ["any","any"]]), "property_"); - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_sys_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SYS_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["screen_width","screen_width"], ["screen_height","screen_height"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; diff --git a/GameImage_20180730/blockly/javascript.js b/GameImage_20180730/blockly/javascript.js deleted file mode 100644 index b6d4118aa6..0000000000 --- a/GameImage_20180730/blockly/javascript.js +++ /dev/null @@ -1,60 +0,0 @@ -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_boundary'] = function (block) { - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary(' + value_left_ + ',' + value_top_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_boundary_collision'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_boundary_collision(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_sys_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'image_sys_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; diff --git a/GameImage_20180730/blockly/msg/blocks/en.js b/GameImage_20180730/blockly/msg/blocks/en.js deleted file mode 100644 index e7e9ad8007..0000000000 --- a/GameImage_20180730/blockly/msg/blocks/en.js +++ /dev/null @@ -1,17 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Image Collision ID"; -Blockly.Msg.AND_SHOW = " And "; -Blockly.Msg.BOUNDARY_SHOW = "Set Screen Boundary"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "Image Screen Boundary Collision"; -Blockly.Msg.SYS_GET_SHOW = "Get Screen"; diff --git a/GameImage_20180730/blockly/msg/blocks/zh-hans.js b/GameImage_20180730/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 86beb8a559..0000000000 --- a/GameImage_20180730/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,17 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "图片建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "来源网址"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.SET_SHOW = "设定图片 "; -Blockly.Msg.GET_SHOW = "取得图片 "; -Blockly.Msg.DELETE_SHOW = "删除图片"; -Blockly.Msg.COLLISION_SHOW = "取得图片 接触状态 代码"; -Blockly.Msg.AND_SHOW = " 与 "; -Blockly.Msg.BOUNDARY_SHOW = "设定视窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得图片 边界状态"; -Blockly.Msg.SYS_GET_SHOW = "取得视窗"; diff --git a/GameImage_20180730/blockly/msg/blocks/zh-hant.js b/GameImage_20180730/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index e1a4212b34..0000000000 --- a/GameImage_20180730/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,17 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "圖片建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "來源網址"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.SET_SHOW = "設定圖片 "; -Blockly.Msg.GET_SHOW = "取得圖片 "; -Blockly.Msg.DELETE_SHOW = "刪除圖片"; -Blockly.Msg.COLLISION_SHOW = "取得圖片 接觸狀態 代碼"; -Blockly.Msg.AND_SHOW = " 與 "; -Blockly.Msg.BOUNDARY_SHOW = "設定視窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得圖片 邊界狀態"; -Blockly.Msg.SYS_GET_SHOW = "取得視窗 "; diff --git a/GameImage_20180730/blockly/msg/en.js b/GameImage_20180730/blockly/msg/en.js deleted file mode 100644 index 0adb114735..0000000000 --- a/GameImage_20180730/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "Game Image"; diff --git a/GameImage_20180730/blockly/msg/zh-hans.js b/GameImage_20180730/blockly/msg/zh-hans.js deleted file mode 100644 index b6c170092c..0000000000 --- a/GameImage_20180730/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "游戏图片"; diff --git a/GameImage_20180730/blockly/msg/zh-hant.js b/GameImage_20180730/blockly/msg/zh-hant.js deleted file mode 100644 index 66af270c69..0000000000 --- a/GameImage_20180730/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "遊戲圖片"; diff --git a/GameImage_20180730/blockly/toolbox.xml b/GameImage_20180730/blockly/toolbox.xml deleted file mode 100644 index 1d223c6c70..0000000000 --- a/GameImage_20180730/blockly/toolbox.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - diff --git a/GameImage_20180730/gameimage.js b/GameImage_20180730/gameimage.js deleted file mode 100644 index 0e54ef08fd..0000000000 --- a/GameImage_20180730/gameimage.js +++ /dev/null @@ -1,181 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var screen_width = 0; - var screen_height = 0; - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("img_"+input_id)) - { - document.getElementById("img_"+input_id).src = input_url; - document.getElementById("img_"+input_id).style.width = input_width + 'px'; - document.getElementById("img_"+input_id).style.height = input_height + 'px'; - document.getElementById("img_"+input_id).style.left = input_left + 'px'; - document.getElementById("img_"+input_id).style.top = input_top + 'px'; - document.getElementById("img_"+input_id).style.zIndex = input_zindex; - if (input_display==false) - document.getElementById("img_"+input_id).style.display = "none"; - else - document.getElementById("img_"+input_id).style.display = "block"; - } - else - { - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "img_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==false) - img.style.display = "none"; - else - img.style.display = "block"; - - document.body.appendChild(img); - } - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("img_"+input_id)) - { - if (input_property=='url') - document.getElementById("img_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("img_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("img_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("img_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("img_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("img_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==false) - document.getElementById("img_"+input_id).style.display = "none"; - else - document.getElementById("img_"+input_id).style.display = "block"; - } - } - } - - function image_get(input_id,input_property) { - if (input_property=='id') - { - if (document.getElementById("img_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("img_"+input_id)) - { - if (input_property=='url') - return document.getElementById("img_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("img_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("img_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='left') - return Number(document.getElementById("img_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("img_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("img_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("img_"+input_id).style.display=="block") - return 1; - else - return 0; - } - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("img_"+input_id)) - { - document.body.removeChild(document.getElementById("img_"+input_id)); - } - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("img_"+input_id1))&&(document.getElementById("img_"+input_id2))) - { - var img1 = document.getElementById("img_"+input_id1).style; - var img2 = document.getElementById("img_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - function image_boundary(input_left,input_top) { - if (input_left>=0) screen_width = input_left; - if (input_top>=0) screen_height = input_top; - } - - function image_boundary_collision(input_id,input_property) { - if ((screen_width>0)||(screen_height>0)) - { - var left = Number(document.getElementById("img_"+input_id).style.left.replace(/px/ig,"")); - var width = Number(document.getElementById("img_"+input_id).style.width.replace(/px/ig,"")); - var top = Number(document.getElementById("img_"+input_id).style.top.replace(/px/ig,"")); - var height = Number(document.getElementById("img_"+input_id).style.height.replace(/px/ig,"")); - if (screen_width>0) - { - if (((input_property=="left")||(input_property=="any"))&&(left<=0)) return 1 - if (((input_property=="right")||(input_property=="any"))&&(left+width>=screen_width)) return 1 - } - if (screen_height>0) - { - if (((input_property=="up")||(input_property=="any"))&&(top<=0)) return 1 - if (((input_property=="down")||(input_property=="any"))&&(top+height>=screen_height)) return 1 - } - return 0; - } - else - return 0; - } - - function image_sys_get(input_property) { - if (input_property=='screen_width') - return screen_width; - else if (input_property=='screen_height') - return screen_height; - else - return; - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - window.image_boundary = image_boundary; - window.image_boundary_collision = image_boundary_collision; - window.image_sys_get = image_sys_get; - -}(window, window.document)); diff --git a/GameImage_20180802/blockly.json b/GameImage_20180802/blockly.json deleted file mode 100644 index 4f2f9ec467..0000000000 --- a/GameImage_20180802/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["image_create","image_set","image_get","image_delete","image_collision","image_boundary","image_boundary_collision","image_sys_get","image_onclick_get"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameimage.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameImage_20180802/blockly/blocks.js b/GameImage_20180802/blockly/blocks.js deleted file mode 100644 index d6869982ea..0000000000 --- a/GameImage_20180802/blockly/blocks.js +++ /dev/null @@ -1,154 +0,0 @@ -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck("Boolean") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["id","id"], ["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary'] = { - init: function() { - this.appendValueInput("left_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.BOUNDARY_SHOW) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("top_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary_collision'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.BOUNDARY_COLLISION_SHOW) - .appendField(new Blockly.FieldDropdown([["up","up"], ["down","down"], ["left","left"], ["right","right"], ["any","any"]]), "property_"); - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_sys_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SYS_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["width","screen_width"], ["height","screen_height"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_onclick_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ONCLICK_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(60); - } -}; diff --git a/GameImage_20180802/blockly/javascript.js b/GameImage_20180802/blockly/javascript.js deleted file mode 100644 index 2fc4cad5a8..0000000000 --- a/GameImage_20180802/blockly/javascript.js +++ /dev/null @@ -1,66 +0,0 @@ -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_boundary'] = function (block) { - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary(' + value_left_ + ',' + value_top_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_boundary_collision'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_boundary_collision(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_sys_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'image_sys_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_onclick_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_onclick_get(' + value_id_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; diff --git a/GameImage_20180802/blockly/msg/blocks/en.js b/GameImage_20180802/blockly/msg/blocks/en.js deleted file mode 100644 index 87188b4aa0..0000000000 --- a/GameImage_20180802/blockly/msg/blocks/en.js +++ /dev/null @@ -1,18 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Get Collision ID"; -Blockly.Msg.AND_SHOW = " And "; -Blockly.Msg.BOUNDARY_SHOW = "Set Screen Boundary"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "Get Collision with sides of screen "; -Blockly.Msg.SYS_GET_SHOW = "Get Screen"; -Blockly.Msg.ONCLICK_SHOW = "Get onClick"; diff --git a/GameImage_20180802/blockly/msg/blocks/zh-hans.js b/GameImage_20180802/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index d533fdf38d..0000000000 --- a/GameImage_20180802/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,18 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "图片建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "来源网址"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.SET_SHOW = "设定图片 "; -Blockly.Msg.GET_SHOW = "取得图片 "; -Blockly.Msg.DELETE_SHOW = "删除图片"; -Blockly.Msg.COLLISION_SHOW = "取得图片 接触状态 代码"; -Blockly.Msg.AND_SHOW = " 与 "; -Blockly.Msg.BOUNDARY_SHOW = "设定视窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得图片 边界状态"; -Blockly.Msg.SYS_GET_SHOW = "取得视窗"; -Blockly.Msg.ONCLICK_SHOW = "取得图片 点选状态"; diff --git a/GameImage_20180802/blockly/msg/blocks/zh-hant.js b/GameImage_20180802/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index aee567e6da..0000000000 --- a/GameImage_20180802/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,18 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "圖片建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "來源網址"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.SET_SHOW = "設定圖片 "; -Blockly.Msg.GET_SHOW = "取得圖片 "; -Blockly.Msg.DELETE_SHOW = "刪除圖片"; -Blockly.Msg.COLLISION_SHOW = "取得圖片 接觸狀態 代碼"; -Blockly.Msg.AND_SHOW = " 與 "; -Blockly.Msg.BOUNDARY_SHOW = "設定視窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得圖片 邊界狀態"; -Blockly.Msg.SYS_GET_SHOW = "取得視窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得圖片 點選狀態"; diff --git a/GameImage_20180802/blockly/msg/en.js b/GameImage_20180802/blockly/msg/en.js deleted file mode 100644 index 0adb114735..0000000000 --- a/GameImage_20180802/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "Game Image"; diff --git a/GameImage_20180802/blockly/msg/zh-hans.js b/GameImage_20180802/blockly/msg/zh-hans.js deleted file mode 100644 index b6c170092c..0000000000 --- a/GameImage_20180802/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "游戏图片"; diff --git a/GameImage_20180802/blockly/msg/zh-hant.js b/GameImage_20180802/blockly/msg/zh-hant.js deleted file mode 100644 index 66af270c69..0000000000 --- a/GameImage_20180802/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "遊戲圖片"; diff --git a/GameImage_20180802/blockly/toolbox.xml b/GameImage_20180802/blockly/toolbox.xml deleted file mode 100644 index 5a7146558a..0000000000 --- a/GameImage_20180802/blockly/toolbox.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - diff --git a/GameImage_20180802/gameimage.js b/GameImage_20180802/gameimage.js deleted file mode 100644 index 4793449929..0000000000 --- a/GameImage_20180802/gameimage.js +++ /dev/null @@ -1,207 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var screen_width = 0; - var screen_height = 0; - var onclickid = ""; - var onclicktime = 200; - var onclicktimerid; - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("gameimg_"+input_id)) - { - document.getElementById("gameimg_"+input_id).src = input_url; - document.getElementById("gameimg_"+input_id).style.width = input_width + 'px'; - document.getElementById("gameimg_"+input_id).style.height = input_height + 'px'; - document.getElementById("gameimg_"+input_id).style.left = input_left + 'px'; - document.getElementById("gameimg_"+input_id).style.top = input_top + 'px'; - document.getElementById("gameimg_"+input_id).style.zIndex = input_zindex; - if (input_display==false) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else - { - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "gameimg_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==false) - img.style.display = "none"; - else - img.style.display = "block"; - img.setAttribute("onclick", "javascript:image_onclickid_set(this);"); - document.body.appendChild(img); - } - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - document.getElementById("gameimg_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("gameimg_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("gameimg_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("gameimg_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("gameimg_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("gameimg_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==false) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - } - } - - function image_get(input_id,input_property) { - if (input_property=='id') - { - if (document.getElementById("gameimg_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - return document.getElementById("gameimg_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='left') - return Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("gameimg_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("gameimg_"+input_id).style.display=="block") - return 1; - else - return 0; - } - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("gameimg_"+input_id)) - { - document.body.removeChild(document.getElementById("gameimg_"+input_id)); - } - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("gameimg_"+input_id1))&&(document.getElementById("gameimg_"+input_id2))) - { - var img1 = document.getElementById("gameimg_"+input_id1).style; - var img2 = document.getElementById("gameimg_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - function image_boundary(input_left,input_top) { - if (input_left>=0) screen_width = input_left; - if (input_top>=0) screen_height = input_top; - } - - function image_boundary_collision(input_id,input_property) { - if ((screen_width>0)||(screen_height>0)) - { - var left = Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - var width = Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - var top = Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - var height = Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - if (screen_width>0) - { - if (((input_property=="left")||(input_property=="any"))&&(left<=0)) return 1 - if (((input_property=="right")||(input_property=="any"))&&(left+width>=screen_width)) return 1 - } - if (screen_height>0) - { - if (((input_property=="up")||(input_property=="any"))&&(top<=0)) return 1 - if (((input_property=="down")||(input_property=="any"))&&(top+height>=screen_height)) return 1 - } - return 0; - } - else - return 0; - } - - function image_sys_get(input_property) { - if (input_property=='screen_width') - return screen_width; - else if (input_property=='screen_height') - return screen_height; - else - return; - } - - function image_onclickid_set(obj) { - clearTimeout(onclicktimerid); - onclickid=obj.id; - onclicktimerid=setTimeout('image_onclickid_clear()',onclicktime); - } - - function image_onclickid_clear() { - onclickid=""; - } - - function image_onclick_get(input_id) { - if (onclickid==("gameimg_"+input_id)) - { - onclickid=""; - return 1; - } - else - return 0; - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - window.image_boundary = image_boundary; - window.image_boundary_collision = image_boundary_collision; - window.image_sys_get = image_sys_get; - window.image_onclickid_set = image_onclickid_set; - window.image_onclickid_clear = image_onclickid_clear; - window.image_onclick_get = image_onclick_get; - -}(window, window.document)); diff --git a/GameImage_20180812/blockly.json b/GameImage_20180812/blockly.json deleted file mode 100644 index 13a0174f49..0000000000 --- a/GameImage_20180812/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["image_create","image_set","image_get","image_delete","image_collision","image_boundary","image_boundary_collision","image_sys_get","image_onclick_get","mouse_coordinate_get"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameimage.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameImage_20180812/blockly/blocks.js b/GameImage_20180812/blockly/blocks.js deleted file mode 100644 index d0e6feed53..0000000000 --- a/GameImage_20180812/blockly/blocks.js +++ /dev/null @@ -1,165 +0,0 @@ -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck("Boolean") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["id","id"], ["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_boundary'] = { - init: function() { - this.appendValueInput("left_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.BOUNDARY_SHOW) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("top_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary_collision'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.BOUNDARY_COLLISION_SHOW) - .appendField(new Blockly.FieldDropdown([["up","up"], ["down","down"], ["left","left"], ["right","right"], ["any","any"]]), "property_"); - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_sys_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SYS_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["width","screen_width"], ["height","screen_height"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_onclick_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ONCLICK_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['mouse_coordinate_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MOUSE_COORDINATE_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["X","x"], ["Y","y"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; diff --git a/GameImage_20180812/blockly/javascript.js b/GameImage_20180812/blockly/javascript.js deleted file mode 100644 index 8b4a7777fb..0000000000 --- a/GameImage_20180812/blockly/javascript.js +++ /dev/null @@ -1,72 +0,0 @@ -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_boundary'] = function (block) { - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary(' + value_left_ + ',' + value_top_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_boundary_collision'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_boundary_collision(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_sys_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'image_sys_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_onclick_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_onclick_get(' + value_id_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['mouse_coordinate_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'mouse_coordinate_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; diff --git a/GameImage_20180812/blockly/msg/blocks/en.js b/GameImage_20180812/blockly/msg/blocks/en.js deleted file mode 100644 index e4ad3fdb1f..0000000000 --- a/GameImage_20180812/blockly/msg/blocks/en.js +++ /dev/null @@ -1,19 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Get Collision ID"; -Blockly.Msg.AND_SHOW = " And "; -Blockly.Msg.BOUNDARY_SHOW = "Set Screen Boundary"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "Get Collision with sides of screen "; -Blockly.Msg.SYS_GET_SHOW = "Get Screen"; -Blockly.Msg.ONCLICK_SHOW = "Get onClick"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "Get Mouse Coordinate"; diff --git a/GameImage_20180812/blockly/msg/blocks/zh-hans.js b/GameImage_20180812/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 202e14db55..0000000000 --- a/GameImage_20180812/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,19 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "图片建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "来源网址"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.SET_SHOW = "设定图片 "; -Blockly.Msg.GET_SHOW = "取得图片 "; -Blockly.Msg.DELETE_SHOW = "删除图片"; -Blockly.Msg.COLLISION_SHOW = "取得图片 接触状态 代码"; -Blockly.Msg.AND_SHOW = " 与 "; -Blockly.Msg.BOUNDARY_SHOW = "设定视窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得图片 边界状态"; -Blockly.Msg.SYS_GET_SHOW = "取得视窗"; -Blockly.Msg.ONCLICK_SHOW = "取得图片 点选状态"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得滑鼠 座标"; diff --git a/GameImage_20180812/blockly/msg/blocks/zh-hant.js b/GameImage_20180812/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index d38bd94857..0000000000 --- a/GameImage_20180812/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,19 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "圖片建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "來源網址"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.SET_SHOW = "設定圖片 "; -Blockly.Msg.GET_SHOW = "取得圖片 "; -Blockly.Msg.DELETE_SHOW = "刪除圖片"; -Blockly.Msg.COLLISION_SHOW = "取得圖片 接觸狀態 代碼"; -Blockly.Msg.AND_SHOW = " 與 "; -Blockly.Msg.BOUNDARY_SHOW = "設定視窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得圖片 邊界狀態"; -Blockly.Msg.SYS_GET_SHOW = "取得視窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得圖片 點選狀態"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得滑鼠 座標"; diff --git a/GameImage_20180812/blockly/msg/en.js b/GameImage_20180812/blockly/msg/en.js deleted file mode 100644 index a1d845e10d..0000000000 --- a/GameImage_20180812/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "Game E"; diff --git a/GameImage_20180812/blockly/msg/zh-hans.js b/GameImage_20180812/blockly/msg/zh-hans.js deleted file mode 100644 index 9d4558ef80..0000000000 --- a/GameImage_20180812/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "游戏元素"; diff --git a/GameImage_20180812/blockly/msg/zh-hant.js b/GameImage_20180812/blockly/msg/zh-hant.js deleted file mode 100644 index 92225ca351..0000000000 --- a/GameImage_20180812/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "遊戲元素"; diff --git a/GameImage_20180812/blockly/toolbox.xml b/GameImage_20180812/blockly/toolbox.xml deleted file mode 100644 index 1f1d2bec9c..0000000000 --- a/GameImage_20180812/blockly/toolbox.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - diff --git a/GameImage_20180812/gameimage.js b/GameImage_20180812/gameimage.js deleted file mode 100644 index d80dd367dc..0000000000 --- a/GameImage_20180812/gameimage.js +++ /dev/null @@ -1,221 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var screen_width = 0; - var screen_height = 0; - var onclickid = ""; - var onclicktime = 200; - var onclicktimerid; - var mouse_x,mouse_y; - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("gameimg_"+input_id)) - { - document.getElementById("gameimg_"+input_id).src = input_url; - document.getElementById("gameimg_"+input_id).style.width = input_width + 'px'; - document.getElementById("gameimg_"+input_id).style.height = input_height + 'px'; - document.getElementById("gameimg_"+input_id).style.left = input_left + 'px'; - document.getElementById("gameimg_"+input_id).style.top = input_top + 'px'; - document.getElementById("gameimg_"+input_id).style.zIndex = input_zindex; - if (input_display==false) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else - { - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "gameimg_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==false) - img.style.display = "none"; - else - img.style.display = "block"; - img.setAttribute("onclick", "javascript:image_onclickid_set(this);"); - document.body.appendChild(img); - } - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - document.getElementById("gameimg_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("gameimg_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("gameimg_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("gameimg_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("gameimg_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("gameimg_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==false) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - } - } - - function image_get(input_id,input_property) { - if (input_property=='id') - { - if (document.getElementById("gameimg_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - return document.getElementById("gameimg_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='left') - return Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("gameimg_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("gameimg_"+input_id).style.display=="block") - return 1; - else - return 0; - } - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("gameimg_"+input_id)) - { - document.body.removeChild(document.getElementById("gameimg_"+input_id)); - } - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("gameimg_"+input_id1))&&(document.getElementById("gameimg_"+input_id2))) - { - var img1 = document.getElementById("gameimg_"+input_id1).style; - var img2 = document.getElementById("gameimg_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - function image_boundary(input_left,input_top) { - if (input_left>=0) screen_width = input_left; - if (input_top>=0) screen_height = input_top; - } - - function image_boundary_collision(input_id,input_property) { - if ((screen_width>0)||(screen_height>0)) - { - var left = Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - var width = Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - var top = Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - var height = Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - if (screen_width>0) - { - if (((input_property=="left")||(input_property=="any"))&&(left<=0)) return 1 - if (((input_property=="right")||(input_property=="any"))&&(left+width>=screen_width)) return 1 - } - if (screen_height>0) - { - if (((input_property=="up")||(input_property=="any"))&&(top<=0)) return 1 - if (((input_property=="down")||(input_property=="any"))&&(top+height>=screen_height)) return 1 - } - return 0; - } - else - return 0; - } - - function image_sys_get(input_property) { - if (input_property=='screen_width') - return screen_width; - else if (input_property=='screen_height') - return screen_height; - else - return; - } - - function image_onclickid_set(obj) { - clearTimeout(onclicktimerid); - onclickid=obj.id; - onclicktimerid=setTimeout('image_onclickid_clear()',onclicktime); - } - - function image_onclickid_clear() { - onclickid=""; - } - - function image_onclick_get(input_id) { - if (onclickid==("gameimg_"+input_id)) - { - onclickid=""; - return 1; - } - else - return 0; - } - - function mouse_coordinate_get(input_property) { - document.onmousemove = function(e){ - e=e||window.event; - mouse_x = e.pageX; - mouse_y = e.pageY; - } - if (input_property=="x") - return mouse_x; - else if (input_property=="y") - return mouse_y; - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - window.image_boundary = image_boundary; - window.image_boundary_collision = image_boundary_collision; - window.image_sys_get = image_sys_get; - window.image_onclickid_set = image_onclickid_set; - window.image_onclickid_clear = image_onclickid_clear; - window.image_onclick_get = image_onclick_get; - window.mouse_coordinate_get = mouse_coordinate_get; - -}(window, window.document)); diff --git a/GameImage_20180813/blockly.json b/GameImage_20180813/blockly.json deleted file mode 100644 index 6aa44cc60b..0000000000 --- a/GameImage_20180813/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["image_create","image_set","image_get","image_delete","image_collision","image_boundary","image_boundary_collision","image_sys_get","image_onclick","mouse_coordinate_get","document_timer","document_timer_stop"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameimage.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameImage_20180813/blockly/blocks.js b/GameImage_20180813/blockly/blocks.js deleted file mode 100644 index 2788614311..0000000000 --- a/GameImage_20180813/blockly/blocks.js +++ /dev/null @@ -1,190 +0,0 @@ -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck("Boolean") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["id","id"], ["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_boundary'] = { - init: function() { - this.appendValueInput("left_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.BOUNDARY_SHOW) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("top_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary_collision'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.BOUNDARY_COLLISION_SHOW) - .appendField(new Blockly.FieldDropdown([["up","up"], ["down","down"], ["left","left"], ["right","right"], ["any","any"]]), "property_"); - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_sys_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SYS_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["width","screen_width"], ["height","screen_height"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_onclick_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ONCLICK_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['mouse_coordinate_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MOUSE_COORDINATE_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["X","x"], ["Y","y"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['document_timer'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_stop'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW) - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_'); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; diff --git a/GameImage_20180813/blockly/javascript.js b/GameImage_20180813/blockly/javascript.js deleted file mode 100644 index b20bf39cda..0000000000 --- a/GameImage_20180813/blockly/javascript.js +++ /dev/null @@ -1,86 +0,0 @@ -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_boundary'] = function (block) { - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary(' + value_left_ + ',' + value_top_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_boundary_collision'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_boundary_collision(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_sys_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'image_sys_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_onclick_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_onclick_get(' + value_id_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['mouse_coordinate_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'mouse_coordinate_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['document_timer'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimer_+' = setInterval(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_stop'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var code = 'clearInterval(' + variable_fuTimer_ + ');\n'; - return code; -}; diff --git a/GameImage_20180813/blockly/msg/blocks/en.js b/GameImage_20180813/blockly/msg/blocks/en.js deleted file mode 100644 index e9755d5411..0000000000 --- a/GameImage_20180813/blockly/msg/blocks/en.js +++ /dev/null @@ -1,21 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Get Collision ID"; -Blockly.Msg.AND_SHOW = " And "; -Blockly.Msg.BOUNDARY_SHOW = "Set Screen Boundary"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "Get Collision with sides of screen "; -Blockly.Msg.SYS_GET_SHOW = "Get Screen"; -Blockly.Msg.ONCLICK_SHOW = "Get onClick"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "Get Mouse Coordinate"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "Timer Intervals(ms)"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "Stop Timer"; diff --git a/GameImage_20180813/blockly/msg/blocks/zh-hans.js b/GameImage_20180813/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 92509fbcdc..0000000000 --- a/GameImage_20180813/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,21 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "图片建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "来源网址"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.SET_SHOW = "设定图片 "; -Blockly.Msg.GET_SHOW = "取得图片 "; -Blockly.Msg.DELETE_SHOW = "删除图片"; -Blockly.Msg.COLLISION_SHOW = "取得图片 接触状态 代码"; -Blockly.Msg.AND_SHOW = " 与 "; -Blockly.Msg.BOUNDARY_SHOW = "设定视窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得图片 边界状态"; -Blockly.Msg.SYS_GET_SHOW = "取得视窗"; -Blockly.Msg.ONCLICK_SHOW = "取得图片 点选状态"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得滑鼠 座标"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "计时器 间隔时间(ms)"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "停止计时器"; diff --git a/GameImage_20180813/blockly/msg/blocks/zh-hant.js b/GameImage_20180813/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index f6f9b05a82..0000000000 --- a/GameImage_20180813/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,21 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "圖片建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "來源網址"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.SET_SHOW = "設定圖片 "; -Blockly.Msg.GET_SHOW = "取得圖片 "; -Blockly.Msg.DELETE_SHOW = "刪除圖片"; -Blockly.Msg.COLLISION_SHOW = "取得圖片 接觸狀態 代碼"; -Blockly.Msg.AND_SHOW = " 與 "; -Blockly.Msg.BOUNDARY_SHOW = "設定視窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得圖片 邊界狀態"; -Blockly.Msg.SYS_GET_SHOW = "取得視窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得圖片 點選狀態"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得滑鼠 座標"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "計時器 間隔時間(ms)"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "停止計時器"; diff --git a/GameImage_20180813/blockly/msg/en.js b/GameImage_20180813/blockly/msg/en.js deleted file mode 100644 index a1d845e10d..0000000000 --- a/GameImage_20180813/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "Game E"; diff --git a/GameImage_20180813/blockly/msg/zh-hans.js b/GameImage_20180813/blockly/msg/zh-hans.js deleted file mode 100644 index 9d4558ef80..0000000000 --- a/GameImage_20180813/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "游戏元素"; diff --git a/GameImage_20180813/blockly/msg/zh-hant.js b/GameImage_20180813/blockly/msg/zh-hant.js deleted file mode 100644 index 92225ca351..0000000000 --- a/GameImage_20180813/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "遊戲元素"; diff --git a/GameImage_20180813/blockly/toolbox.xml b/GameImage_20180813/blockly/toolbox.xml deleted file mode 100644 index 4e5540227e..0000000000 --- a/GameImage_20180813/blockly/toolbox.xml +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - 100 - - - - - - diff --git a/GameImage_20180813/gameimage.js b/GameImage_20180813/gameimage.js deleted file mode 100644 index d80dd367dc..0000000000 --- a/GameImage_20180813/gameimage.js +++ /dev/null @@ -1,221 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var screen_width = 0; - var screen_height = 0; - var onclickid = ""; - var onclicktime = 200; - var onclicktimerid; - var mouse_x,mouse_y; - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("gameimg_"+input_id)) - { - document.getElementById("gameimg_"+input_id).src = input_url; - document.getElementById("gameimg_"+input_id).style.width = input_width + 'px'; - document.getElementById("gameimg_"+input_id).style.height = input_height + 'px'; - document.getElementById("gameimg_"+input_id).style.left = input_left + 'px'; - document.getElementById("gameimg_"+input_id).style.top = input_top + 'px'; - document.getElementById("gameimg_"+input_id).style.zIndex = input_zindex; - if (input_display==false) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else - { - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "gameimg_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==false) - img.style.display = "none"; - else - img.style.display = "block"; - img.setAttribute("onclick", "javascript:image_onclickid_set(this);"); - document.body.appendChild(img); - } - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - document.getElementById("gameimg_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("gameimg_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("gameimg_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("gameimg_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("gameimg_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("gameimg_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==false) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - } - } - - function image_get(input_id,input_property) { - if (input_property=='id') - { - if (document.getElementById("gameimg_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - return document.getElementById("gameimg_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='left') - return Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("gameimg_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("gameimg_"+input_id).style.display=="block") - return 1; - else - return 0; - } - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("gameimg_"+input_id)) - { - document.body.removeChild(document.getElementById("gameimg_"+input_id)); - } - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("gameimg_"+input_id1))&&(document.getElementById("gameimg_"+input_id2))) - { - var img1 = document.getElementById("gameimg_"+input_id1).style; - var img2 = document.getElementById("gameimg_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - function image_boundary(input_left,input_top) { - if (input_left>=0) screen_width = input_left; - if (input_top>=0) screen_height = input_top; - } - - function image_boundary_collision(input_id,input_property) { - if ((screen_width>0)||(screen_height>0)) - { - var left = Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - var width = Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - var top = Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - var height = Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - if (screen_width>0) - { - if (((input_property=="left")||(input_property=="any"))&&(left<=0)) return 1 - if (((input_property=="right")||(input_property=="any"))&&(left+width>=screen_width)) return 1 - } - if (screen_height>0) - { - if (((input_property=="up")||(input_property=="any"))&&(top<=0)) return 1 - if (((input_property=="down")||(input_property=="any"))&&(top+height>=screen_height)) return 1 - } - return 0; - } - else - return 0; - } - - function image_sys_get(input_property) { - if (input_property=='screen_width') - return screen_width; - else if (input_property=='screen_height') - return screen_height; - else - return; - } - - function image_onclickid_set(obj) { - clearTimeout(onclicktimerid); - onclickid=obj.id; - onclicktimerid=setTimeout('image_onclickid_clear()',onclicktime); - } - - function image_onclickid_clear() { - onclickid=""; - } - - function image_onclick_get(input_id) { - if (onclickid==("gameimg_"+input_id)) - { - onclickid=""; - return 1; - } - else - return 0; - } - - function mouse_coordinate_get(input_property) { - document.onmousemove = function(e){ - e=e||window.event; - mouse_x = e.pageX; - mouse_y = e.pageY; - } - if (input_property=="x") - return mouse_x; - else if (input_property=="y") - return mouse_y; - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - window.image_boundary = image_boundary; - window.image_boundary_collision = image_boundary_collision; - window.image_sys_get = image_sys_get; - window.image_onclickid_set = image_onclickid_set; - window.image_onclickid_clear = image_onclickid_clear; - window.image_onclick_get = image_onclick_get; - window.mouse_coordinate_get = mouse_coordinate_get; - -}(window, window.document)); diff --git a/GameImage_20180815/blockly.json b/GameImage_20180815/blockly.json deleted file mode 100644 index 7e9cd4d1be..0000000000 --- a/GameImage_20180815/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["image_create","image_set","image_get","image_delete","image_collision","image_boundary","image_boundary_collision","image_sys_get","image_onclick","mouse_coordinate_get","document_timer","document_timer_once","document_timer_stop"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "gameimage.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/GameImage_20180815/blockly/blocks.js b/GameImage_20180815/blockly/blocks.js deleted file mode 100644 index 288de3ae29..0000000000 --- a/GameImage_20180815/blockly/blocks.js +++ /dev/null @@ -1,204 +0,0 @@ -Blockly.Blocks['image_create'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CREATE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW); - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.appendValueInput("display_") - .setCheck("Boolean") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DISPLAY_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_set'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SET_SHOW) - .appendField(new Blockly.FieldDropdown([["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"], ["opacity","opacity"], ["rotate","rotate"], ["rotateX","rotateX"], ["rotateY","rotateY"], ["rotateZ","rotateZ"], ["moveX","moveX"], ["moveY","moveY"]]), "property_"); - this.appendValueInput("value_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null); - this.appendValueInput("id_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.GET_SHOW) - .appendField(new Blockly.FieldDropdown([["id","id"], ["url","url"], ["width","width"], ["height","height"], ["left","left"], ["top","top"], ["zindex","zindex"], ["display","display"], ["opacity","opacity"], ["rotate","rotate"], ["rotateX","rotateX"], ["rotateY","rotateY"], ["rotateZ","rotateZ"]]), "property_") - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_delete'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.DELETE_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(60); - } -}; - -Blockly.Blocks['image_collision'] = { - init: function() { - this.appendValueInput("id1_") - .setCheck(null) - .appendField(Blockly.Msg.COLLISION_SHOW); - this.appendValueInput("id2_") - .setCheck(null) - .appendField(Blockly.Msg.AND_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_boundary'] = { - init: function() { - this.appendValueInput("left_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.BOUNDARY_SHOW) - .appendField(Blockly.Msg.WIDTH_SHOW); - this.appendValueInput("top_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.setInputsInline(true); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['image_boundary_collision'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.BOUNDARY_COLLISION_SHOW) - .appendField(new Blockly.FieldDropdown([["up","up"], ["down","down"], ["left","left"], ["right","right"], ["any","any"]]), "property_"); - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_sys_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.SYS_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["width","screen_width"], ["height","screen_height"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['image_onclick_get'] = { - init: function() { - this.appendValueInput("id_") - .setCheck(null) - .appendField(Blockly.Msg.ONCLICK_SHOW) - .appendField(Blockly.Msg.ID_SHOW); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['mouse_coordinate_get'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MOUSE_COORDINATE_GET_SHOW) - .appendField(new Blockly.FieldDropdown([["X","x"], ["Y","y"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(200); - } -}; - -Blockly.Blocks['document_timer'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_once'] = { - init: function () { - this.appendValueInput("intervals_") - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck("Number") - .appendField(new Blockly.FieldVariable('fuTimerOnce'), 'fuTimerOnce_') - .appendField(Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW); - this.appendStatementInput("do_"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; - -Blockly.Blocks['document_timer_stop'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW) - .appendField(new Blockly.FieldVariable('fuTimer'), 'fuTimer_'); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(60); - } -}; diff --git a/GameImage_20180815/blockly/javascript.js b/GameImage_20180815/blockly/javascript.js deleted file mode 100644 index 4b9f24b81a..0000000000 --- a/GameImage_20180815/blockly/javascript.js +++ /dev/null @@ -1,94 +0,0 @@ -Blockly.JavaScript['image_create'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var value_display_ = Blockly.JavaScript.valueToCode(block, 'display_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_create(' + value_id_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ',' + value_display_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_set'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_set(' + value_id_ + ',"' + value_property_ + '",' + value_value_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_get(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_delete'] = function(block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_delete(' + value_id_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_collision'] = function (block) { - var value_id1_ = Blockly.JavaScript.valueToCode(block, 'id1_', Blockly.JavaScript.ORDER_ATOMIC); - var value_id2_ = Blockly.JavaScript.valueToCode(block, 'id2_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_collision(' + value_id1_ + ',' + value_id2_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_boundary'] = function (block) { - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_boundary(' + value_left_ + ',' + value_top_ + ');\n'; - return code; -}; - -Blockly.JavaScript['image_boundary_collision'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var value_property_ = block.getFieldValue('property_'); - var code = 'image_boundary_collision(' + value_id_ + ',"' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_sys_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'image_sys_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['image_onclick_get'] = function (block) { - var value_id_ = Blockly.JavaScript.valueToCode(block, 'id_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'image_onclick_get(' + value_id_ + ')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['mouse_coordinate_get'] = function (block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'mouse_coordinate_get("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['document_timer'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimer_+' = setInterval(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_once'] = function (block) { - var variable_fuTimerOnce_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimerOnce_'), Blockly.Variables.NAME_TYPE); - var statements_do_ = Blockly.JavaScript.statementToCode(block, 'do_'); - var value_intervals_ = Blockly.JavaScript.valueToCode(block, 'intervals_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuTimerOnce_+' = setTimeout(function(){\n' + statements_do_ + '},' + value_intervals_ + ');\n'; - return code; -}; - -Blockly.JavaScript['document_timer_stop'] = function (block) { - var variable_fuTimer_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuTimer_'), Blockly.Variables.NAME_TYPE); - var code = 'clearInterval(' + variable_fuTimer_ + ');\n'; - return code; -}; diff --git a/GameImage_20180815/blockly/msg/blocks/en.js b/GameImage_20180815/blockly/msg/blocks/en.js deleted file mode 100644 index 28c4b7d6d1..0000000000 --- a/GameImage_20180815/blockly/msg/blocks/en.js +++ /dev/null @@ -1,22 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "Create Image"; -Blockly.Msg.ID_SHOW = " ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.HEIGHT_SHOW = "Height"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; -Blockly.Msg.DISPLAY_SHOW = "Display"; -Blockly.Msg.SET_SHOW = "Set Image"; -Blockly.Msg.GET_SHOW = "Get Image"; -Blockly.Msg.DELETE_SHOW = "Delete Image"; -Blockly.Msg.COLLISION_SHOW = "Get Collision ID"; -Blockly.Msg.AND_SHOW = " And "; -Blockly.Msg.BOUNDARY_SHOW = "Set Screen Boundary"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "Get Collision with sides of screen "; -Blockly.Msg.SYS_GET_SHOW = "Get Screen"; -Blockly.Msg.ONCLICK_SHOW = "Get onClick"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "Get Mouse Coordinate"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "Timer Intervals(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "Timer Intervals(ms) Once"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "Stop Timer"; diff --git a/GameImage_20180815/blockly/msg/blocks/zh-hans.js b/GameImage_20180815/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 28afcee35a..0000000000 --- a/GameImage_20180815/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,22 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "图片建立"; -Blockly.Msg.ID_SHOW = " 代码"; -Blockly.Msg.URL_SHOW = "来源网址"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; -Blockly.Msg.DISPLAY_SHOW = "显示"; -Blockly.Msg.SET_SHOW = "设定图片 "; -Blockly.Msg.GET_SHOW = "取得图片 "; -Blockly.Msg.DELETE_SHOW = "删除图片"; -Blockly.Msg.COLLISION_SHOW = "取得图片 接触状态 代码"; -Blockly.Msg.AND_SHOW = " 与 "; -Blockly.Msg.BOUNDARY_SHOW = "设定视窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得图片 边界状态"; -Blockly.Msg.SYS_GET_SHOW = "取得视窗"; -Blockly.Msg.ONCLICK_SHOW = "取得图片 点选状态"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得滑鼠 座标"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "计时器 间隔时间(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "计时器 间隔时间(ms)后执行一次"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "停止计时器"; diff --git a/GameImage_20180815/blockly/msg/blocks/zh-hant.js b/GameImage_20180815/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 0f19d5dba1..0000000000 --- a/GameImage_20180815/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,22 +0,0 @@ -Blockly.Msg.CREATE_SHOW = "圖片建立"; -Blockly.Msg.ID_SHOW = " 代碼"; -Blockly.Msg.URL_SHOW = "來源網址"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; -Blockly.Msg.DISPLAY_SHOW = "顯示"; -Blockly.Msg.SET_SHOW = "設定圖片 "; -Blockly.Msg.GET_SHOW = "取得圖片 "; -Blockly.Msg.DELETE_SHOW = "刪除圖片"; -Blockly.Msg.COLLISION_SHOW = "取得圖片 接觸狀態 代碼"; -Blockly.Msg.AND_SHOW = " 與 "; -Blockly.Msg.BOUNDARY_SHOW = "設定視窗大小"; -Blockly.Msg.BOUNDARY_COLLISION_SHOW = "取得圖片 邊界狀態"; -Blockly.Msg.SYS_GET_SHOW = "取得視窗 "; -Blockly.Msg.ONCLICK_SHOW = "取得圖片 點選狀態"; -Blockly.Msg.MOUSE_COORDINATE_GET_SHOW = "取得滑鼠 座標"; -Blockly.Msg.DOCUMENT_TIMER_SHOW = "計時器 間隔時間(ms)"; -Blockly.Msg.DOCUMENT_TIMER_ONCE_SHOW = "計時器 間隔時間(ms)後執行一次"; -Blockly.Msg.DOCUMENT_TIMER_STOP_SHOW = "停止計時器"; diff --git a/GameImage_20180815/blockly/msg/en.js b/GameImage_20180815/blockly/msg/en.js deleted file mode 100644 index 765217e8f7..0000000000 --- a/GameImage_20180815/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "Game Elements"; diff --git a/GameImage_20180815/blockly/msg/zh-hans.js b/GameImage_20180815/blockly/msg/zh-hans.js deleted file mode 100644 index 9d4558ef80..0000000000 --- a/GameImage_20180815/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "游戏元素"; diff --git a/GameImage_20180815/blockly/msg/zh-hant.js b/GameImage_20180815/blockly/msg/zh-hant.js deleted file mode 100644 index 92225ca351..0000000000 --- a/GameImage_20180815/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catImage = "遊戲元素"; diff --git a/GameImage_20180815/blockly/toolbox.xml b/GameImage_20180815/blockly/toolbox.xml deleted file mode 100644 index c6c0f08cac..0000000000 --- a/GameImage_20180815/blockly/toolbox.xml +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - - - - - - - - 200 - - - - - 300 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - TRUE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - 100 - - - - - - - 1000 - - - - - - diff --git a/GameImage_20180815/gameimage.js b/GameImage_20180815/gameimage.js deleted file mode 100644 index 32a632ddb3..0000000000 --- a/GameImage_20180815/gameimage.js +++ /dev/null @@ -1,245 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - var screen_width = 0; - var screen_height = 0; - var onclickid = ""; - var onclicktime = 200; - var onclicktimerid; - var mouse_x,mouse_y; - - function image_create(input_id,input_url,input_width,input_height,input_left,input_top,input_zindex,input_display) { - if (document.getElementById("gameimg_"+input_id)) - { - document.getElementById("gameimg_"+input_id).src = input_url; - document.getElementById("gameimg_"+input_id).style.width = input_width + 'px'; - document.getElementById("gameimg_"+input_id).style.height = input_height + 'px'; - document.getElementById("gameimg_"+input_id).style.left = input_left + 'px'; - document.getElementById("gameimg_"+input_id).style.top = input_top + 'px'; - document.getElementById("gameimg_"+input_id).style.zIndex = input_zindex; - if (input_display==false) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else - { - var img = document.createElement('img'); - img.style.position = "absolute"; - img.id = "gameimg_"+input_id; - img.src = input_url; - img.style.width = input_width + 'px'; - img.style.height = input_height + 'px'; - img.style.left = input_left + 'px'; - img.style.top = input_top + 'px'; - img.style.zIndex = input_zindex; - if (input_display==false) - img.style.display = "none"; - else - img.style.display = "block"; - img.setAttribute("onclick", "javascript:image_onclickid_set(this);"); - document.body.appendChild(img); - } - } - - function image_set(input_id,input_property,input_value) { - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - document.getElementById("gameimg_"+input_id).src = input_value; - else if (input_property=='width') - document.getElementById("gameimg_"+input_id).style.width = input_value + 'px'; - else if (input_property=='height') - document.getElementById("gameimg_"+input_id).style.height = input_value + 'px'; - else if (input_property=='left') - document.getElementById("gameimg_"+input_id).style.left = input_value + 'px'; - else if (input_property=='top') - document.getElementById("gameimg_"+input_id).style.top = input_value + 'px'; - else if (input_property=='zindex') - document.getElementById("gameimg_"+input_id).style.zIndex = input_value; - else if (input_property=='display') - { - if (input_value==0) - document.getElementById("gameimg_"+input_id).style.display = "none"; - else - document.getElementById("gameimg_"+input_id).style.display = "block"; - } - else if (input_property=='opacity') - document.getElementById("gameimg_"+input_id).style.opacity = input_value; - else if (input_property=='rotate') - document.getElementById("gameimg_"+input_id).style.transform = "rotate("+input_value+"deg)"; - else if (input_property=='rotateX') - document.getElementById("gameimg_"+input_id).style.transform = "rotateX("+input_value+"deg)"; - else if (input_property=='rotateY') - document.getElementById("gameimg_"+input_id).style.transform = "rotateY("+input_value+"deg)"; - else if (input_property=='rotateZ') - document.getElementById("gameimg_"+input_id).style.transform = "rotateZ("+input_value+"deg)"; - else if (input_property=='moveX') - document.getElementById("gameimg_"+input_id).style.left = (Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,""))+Number(input_value))+"px"; - else if (input_property=='moveY') - document.getElementById("gameimg_"+input_id).style.top = (Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,""))+Number(input_value))+"px"; - } - } - - function image_get(input_id,input_property) { - if (input_property=='id') - { - if (document.getElementById("gameimg_"+input_id)) - return 1; - else - return 0; - } - if (document.getElementById("gameimg_"+input_id)) - { - if (input_property=='url') - return document.getElementById("gameimg_"+input_id).src; - else if (input_property=='width') - return Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - else if (input_property=='height') - return Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - else if (input_property=='left') - return Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - else if (input_property=='top') - return Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - else if (input_property=='zindex') - return Number(document.getElementById("gameimg_"+input_id).style.zIndex); - else if (input_property=='display') - { - if (document.getElementById("gameimg_"+input_id).style.display=="block") - return 1; - else - return 0; - } - else if (input_property=='opacity') - return document.getElementById("gameimg_"+input_id).style.opacity; - else if (input_property=='rotate') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateX') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateY') - return document.getElementById("gameimg_"+input_id).style.transform; - else if (input_property=='rotateZ') - return document.getElementById("gameimg_"+input_id).style.transform; - } - else - return ""; - } - - function image_delete(input_id) { - if (document.getElementById("gameimg_"+input_id)) - { - document.body.removeChild(document.getElementById("gameimg_"+input_id)); - } - } - - function image_collision(input_id1,input_id2) { - if ((document.getElementById("gameimg_"+input_id1))&&(document.getElementById("gameimg_"+input_id2))) - { - var img1 = document.getElementById("gameimg_"+input_id1).style; - var img2 = document.getElementById("gameimg_"+input_id2).style; - var x1 = Number(img1.left.replace(/px/ig,"")); - var x1_w = Number(img1.left.replace(/px/ig,"")) + Number(img1.width.replace(/px/ig,"")); - var y1 = Number(img1.top.replace(/px/ig,"")); - var y1_h = Number(img1.top.replace(/px/ig,"")) + Number(img1.height.replace(/px/ig,"")); - var x2 = Number(img2.left.replace(/px/ig,"")); - var x2_w = Number(img2.left.replace(/px/ig,"")) + Number(img2.width.replace(/px/ig,"")); - var y2 = Number(img2.top.replace(/px/ig,"")); - var y2_h = Number(img2.top.replace(/px/ig,"")) + Number(img2.height.replace(/px/ig,"")); - - if ((((x2>=x1)&&(x2<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2>=x1)&&(x2<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2>=y1)&&(y2<=y1_h)))||(((x2_w>=x1)&&(x2_w<=x1_w))&&((y2_h>=y1)&&(y2_h<=y1_h)))) - return 1; - else if ((((x1>=x2)&&(x1<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1>=x2)&&(x1<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1>=y2)&&(y1<=y2_h)))||(((x1_w>=x2)&&(x1_w<=x2_w))&&((y1_h>=y2)&&(y1_h<=y2_h)))) - return 1; - else - return 0; - } - else - return 0; - } - - function image_boundary(input_left,input_top) { - if (input_left>=0) screen_width = input_left; - if (input_top>=0) screen_height = input_top; - } - - function image_boundary_collision(input_id,input_property) { - if ((screen_width>0)||(screen_height>0)) - { - var left = Number(document.getElementById("gameimg_"+input_id).style.left.replace(/px/ig,"")); - var width = Number(document.getElementById("gameimg_"+input_id).style.width.replace(/px/ig,"")); - var top = Number(document.getElementById("gameimg_"+input_id).style.top.replace(/px/ig,"")); - var height = Number(document.getElementById("gameimg_"+input_id).style.height.replace(/px/ig,"")); - if (screen_width>0) - { - if (((input_property=="left")||(input_property=="any"))&&(left<=0)) return 1 - if (((input_property=="right")||(input_property=="any"))&&(left+width>=screen_width)) return 1 - } - if (screen_height>0) - { - if (((input_property=="up")||(input_property=="any"))&&(top<=0)) return 1 - if (((input_property=="down")||(input_property=="any"))&&(top+height>=screen_height)) return 1 - } - return 0; - } - else - return 0; - } - - function image_sys_get(input_property) { - if (input_property=='screen_width') - return screen_width; - else if (input_property=='screen_height') - return screen_height; - else - return; - } - - function image_onclickid_set(obj) { - clearTimeout(onclicktimerid); - onclickid=obj.id; - onclicktimerid=setTimeout('image_onclickid_clear()',onclicktime); - } - - function image_onclickid_clear() { - onclickid=""; - } - - function image_onclick_get(input_id) { - if (onclickid==("gameimg_"+input_id)) - { - onclickid=""; - return 1; - } - else - return 0; - } - - function mouse_coordinate_get(input_property) { - document.onmousemove = function(e){ - e=e||window.event; - mouse_x = e.pageX; - mouse_y = e.pageY; - } - if (input_property=="x") - return mouse_x; - else if (input_property=="y") - return mouse_y; - } - - window.image_create = image_create; - window.image_set = image_set; - window.image_get = image_get; - window.image_delete = image_delete; - window.image_collision = image_collision; - window.image_boundary = image_boundary; - window.image_boundary_collision = image_boundary_collision; - window.image_sys_get = image_sys_get; - window.image_onclickid_set = image_onclickid_set; - window.image_onclickid_clear = image_onclickid_clear; - window.image_onclick_get = image_onclick_get; - window.mouse_coordinate_get = mouse_coordinate_get; - -}(window, window.document)); diff --git a/IFTTT_20180312/blockly.json b/IFTTT_20180312/blockly.json deleted file mode 100644 index 78b2f67467..0000000000 --- a/IFTTT_20180312/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["ifttt_open"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "ifttt.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/IFTTT_20180312/blockly/blocks.js b/IFTTT_20180312/blockly/blocks.js deleted file mode 100644 index da13cc2f90..0000000000 --- a/IFTTT_20180312/blockly/blocks.js +++ /dev/null @@ -1,30 +0,0 @@ -Blockly.Blocks['ifttt_open'] = { - init: function() { - this.appendValueInput("ifttt_event") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("IFTTT ") - .appendField("Event"); - this.appendValueInput("ifttt_key") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("Key"); - this.appendValueInput("ifttt_value1") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("Value1"); - this.appendValueInput("ifttt_value2") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("Value2"); - this.appendValueInput("ifttt_value3") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("Value3"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setTooltip(''); - this.setColour(65); - this.setHelpUrl(mainUrl + 'basic/blockly/blockly-information.html' + utmUrl); - } -}; diff --git a/IFTTT_20180312/blockly/javascript.js b/IFTTT_20180312/blockly/javascript.js deleted file mode 100644 index c06bd803b2..0000000000 --- a/IFTTT_20180312/blockly/javascript.js +++ /dev/null @@ -1,9 +0,0 @@ -Blockly.JavaScript['ifttt_open'] = function (block) { - var ifttt_event = Blockly.JavaScript.valueToCode(block, 'ifttt_event', Blockly.JavaScript.ORDER_ATOMIC); - var ifttt_key = Blockly.JavaScript.valueToCode(block, 'ifttt_key', Blockly.JavaScript.ORDER_ATOMIC); - var ifttt_value1 = Blockly.JavaScript.valueToCode(block, 'ifttt_value1', Blockly.JavaScript.ORDER_ATOMIC); - var ifttt_value2 = Blockly.JavaScript.valueToCode(block, 'ifttt_value2', Blockly.JavaScript.ORDER_ATOMIC); - var ifttt_value3 = Blockly.JavaScript.valueToCode(block, 'ifttt_value3', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'createIframe('+ifttt_event+','+ifttt_key+','+ifttt_value1+','+ifttt_value2+','+ifttt_value3+');\n'; - return code; -}; diff --git a/IFTTT_20180312/blockly/msg/blocks/en.js b/IFTTT_20180312/blockly/msg/blocks/en.js deleted file mode 100644 index 8b13789179..0000000000 --- a/IFTTT_20180312/blockly/msg/blocks/en.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/IFTTT_20180312/blockly/msg/blocks/zh-hans.js b/IFTTT_20180312/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 8b13789179..0000000000 --- a/IFTTT_20180312/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/IFTTT_20180312/blockly/msg/blocks/zh-hant.js b/IFTTT_20180312/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index d3f5a12faa..0000000000 --- a/IFTTT_20180312/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/IFTTT_20180312/blockly/msg/en.js b/IFTTT_20180312/blockly/msg/en.js deleted file mode 100644 index caee9f08bd..0000000000 --- a/IFTTT_20180312/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catifttt = "IFTTT"; diff --git a/IFTTT_20180312/blockly/msg/zh-hans.js b/IFTTT_20180312/blockly/msg/zh-hans.js deleted file mode 100644 index caee9f08bd..0000000000 --- a/IFTTT_20180312/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catifttt = "IFTTT"; diff --git a/IFTTT_20180312/blockly/msg/zh-hant.js b/IFTTT_20180312/blockly/msg/zh-hant.js deleted file mode 100644 index caee9f08bd..0000000000 --- a/IFTTT_20180312/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catifttt = "IFTTT"; diff --git a/IFTTT_20180312/blockly/toolbox.xml b/IFTTT_20180312/blockly/toolbox.xml deleted file mode 100644 index c6bc981fa5..0000000000 --- a/IFTTT_20180312/blockly/toolbox.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/IFTTT_20180312/ifttt.js b/IFTTT_20180312/ifttt.js deleted file mode 100644 index 71ce7e465e..0000000000 --- a/IFTTT_20180312/ifttt.js +++ /dev/null @@ -1,34 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function createIframe(ifttt_event,ifttt_key,ifttt_value1,ifttt_value2,ifttt_value3) { - - var input_url="https://maker.ifttt.com/trigger/"+ifttt_event+"/with/key/"+ifttt_key+"?value1="+ifttt_value1+"&value2="+ifttt_value2+"&value3="+ifttt_value3; - var src = ''; - - if (document.getElementById("ifttt_iframe")) - { - document.getElementById("ifttt_iframe").style.left = '0px'; - document.getElementById("ifttt_iframe").style.top = '0px'; - document.getElementById("ifttt_iframe").style.display = 'block'; - document.getElementById("ifttt_iframe").innerHTML = src; - } - else - { - var div = document.createElement('div'); - div.id = "ifttt_iframe"; - div.style.position = 'absolute'; - div.style.left = '0px'; - div.style.top = '0px'; - div.style.zindex='9999'; - div.innerHTML = src; - document.body.appendChild(div); - } - } - - window.createIframe = createIframe; - -}(window, window.document)); diff --git a/LineBot_20181014/blockly.json b/LineBot_20181014/blockly.json deleted file mode 100644 index 8351e02f22..0000000000 --- a/LineBot_20181014/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["linebot_notify"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "linebot.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/LineBot_20181014/blockly/blocks.js b/LineBot_20181014/blockly/blocks.js deleted file mode 100644 index d095790d2e..0000000000 --- a/LineBot_20181014/blockly/blocks.js +++ /dev/null @@ -1,21 +0,0 @@ -Blockly.Blocks['linebot_notify'] = { - init: function() { - this.appendValueInput("bot_token") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("Line Bot ") - .appendField("CHANNEL ACCESS TOKEN"); - this.appendValueInput("bot_userid") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("USERID"); - this.appendValueInput("bot_msg") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("MESSAGE"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setTooltip(''); - this.setColour(65); - } -}; diff --git a/LineBot_20181014/blockly/javascript.js b/LineBot_20181014/blockly/javascript.js deleted file mode 100644 index 4bb5f9e195..0000000000 --- a/LineBot_20181014/blockly/javascript.js +++ /dev/null @@ -1,7 +0,0 @@ -Blockly.JavaScript['linebot_notify'] = function (block) { - var bot_token = Blockly.JavaScript.valueToCode(block, 'bot_token', Blockly.JavaScript.ORDER_ATOMIC); - var bot_userid = Blockly.JavaScript.valueToCode(block, 'bot_userid', Blockly.JavaScript.ORDER_ATOMIC); - var bot_msg = Blockly.JavaScript.valueToCode(block, 'bot_msg', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'createIframe('+bot_token+','+bot_userid+','+bot_msg+');\n'; - return code; -}; diff --git a/LineBot_20181014/blockly/msg/blocks/en.js b/LineBot_20181014/blockly/msg/blocks/en.js deleted file mode 100644 index 8b13789179..0000000000 --- a/LineBot_20181014/blockly/msg/blocks/en.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/LineBot_20181014/blockly/msg/blocks/zh-hans.js b/LineBot_20181014/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 8b13789179..0000000000 --- a/LineBot_20181014/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/LineBot_20181014/blockly/msg/blocks/zh-hant.js b/LineBot_20181014/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index d3f5a12faa..0000000000 --- a/LineBot_20181014/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/LineBot_20181014/blockly/msg/en.js b/LineBot_20181014/blockly/msg/en.js deleted file mode 100644 index 173961dfbf..0000000000 --- a/LineBot_20181014/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catlinebot = "Line Bot"; diff --git a/LineBot_20181014/blockly/msg/zh-hans.js b/LineBot_20181014/blockly/msg/zh-hans.js deleted file mode 100644 index 173961dfbf..0000000000 --- a/LineBot_20181014/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catlinebot = "Line Bot"; diff --git a/LineBot_20181014/blockly/msg/zh-hant.js b/LineBot_20181014/blockly/msg/zh-hant.js deleted file mode 100644 index 173961dfbf..0000000000 --- a/LineBot_20181014/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catlinebot = "Line Bot"; diff --git a/LineBot_20181014/blockly/toolbox.xml b/LineBot_20181014/blockly/toolbox.xml deleted file mode 100644 index f92443c68c..0000000000 --- a/LineBot_20181014/blockly/toolbox.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/LineBot_20181014/linebot.js b/LineBot_20181014/linebot.js deleted file mode 100644 index e1ebaa6441..0000000000 --- a/LineBot_20181014/linebot.js +++ /dev/null @@ -1,67 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function createIframe(bot_token,bot_userid,bot_msg) { - - var input_url="https://script.google.com/macros/s/AKfycbwNu63z3ZFHo38wp9LBAwDGyG8tI46-5d-TpFLYFiOHDVOvmgN0/exec?token="+bot_token+"&userid="+bot_userid+"&type=text&text="+bot_msg; - var src = ''; - - if (document.getElementById("bot_iframe")) - { - document.getElementById("bot_iframe").style.left = '0px'; - document.getElementById("bot_iframe").style.top = '0px'; - document.getElementById("bot_iframe").style.display = 'block'; - document.getElementById("bot_iframe").innerHTML = src; - } - else - { - var div = document.createElement('div'); - div.id = "bot_iframe"; - div.style.position = 'absolute'; - div.style.left = '0px'; - div.style.top = '0px'; - div.style.zindex='9999'; - div.innerHTML = src; - document.body.appendChild(div); - } - } - - window.createIframe = createIframe; - -}(window, window.document)); - -/* -// Google Apps Script - -function doGet(e) { - var token = e.parameter.token.replace(/\s+/g,"+"); - var userid = e.parameter.userid; - var text = e.parameter.text; - - //console.log("token="+token); - //console.log("userid="+userid); - //console.log("text="+text); - - var url = 'https://api.line.me/v2/bot/message/push'; - UrlFetchApp.fetch(url, { - 'headers': { - 'Content-Type': 'application/json; charset=UTF-8', - 'Authorization': 'Bearer ' + token, - }, - 'method': 'post', - 'payload': JSON.stringify({ - 'to': userid, - 'messages': [{ - type:'text', - text: text - }] - }), - }); - - var textOutput = ContentService.createTextOutput(text) - return textOutput -} -*/ diff --git a/LineBot_20181015/blockly.json b/LineBot_20181015/blockly.json deleted file mode 100644 index 84081a369d..0000000000 --- a/LineBot_20181015/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["linebot_notify","linebot_type","linenotify"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "linebot.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/LineBot_20181015/blockly/blocks.js b/LineBot_20181015/blockly/blocks.js deleted file mode 100644 index 052e4296f3..0000000000 --- a/LineBot_20181015/blockly/blocks.js +++ /dev/null @@ -1,65 +0,0 @@ -Blockly.Blocks['linebot_notify'] = { - init: function() { - this.appendValueInput("bot_token") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("Line Bot ") - .appendField("CHANNEL ACCESS TOKEN"); - this.appendValueInput("bot_userid") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("USERID"); - this.appendValueInput("bot_msg") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("MESSAGE"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setTooltip(''); - this.setColour(65); - } -}; - -Blockly.Blocks['linebot_type'] = { - init: function() { - this.appendDummyInput() - .appendField("Message (bot)"); - this.appendDummyInput() - .appendField("Type") - .appendField(new Blockly.FieldDropdown([["text (text)","text"], ["sticker (packageId, stickerId)","sticker"], ["image (originalContentUrl, previewImageUrl)","image"], ["video (originalContentUrl, previewImageUrl)","video"], ["audio (originalContentUrl, duration)","audio"], ["location (title, address, latitude, longitude)","location"]]), "value_type"); - this.appendValueInput("value_parameter1") - .setCheck("String") - .appendField("Parameter1"); - this.appendValueInput("value_parameter2") - .setCheck("String") - .appendField("Parameter2"); - this.appendValueInput("value_parameter3") - .setCheck("String") - .appendField("Parameter3"); - this.appendValueInput("value_parameter4") - .setCheck("String") - .appendField("Parameter4"); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['linenotify'] = { - init: function() { - this.appendValueInput("notify_token") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("Line Notify ") - .appendField("CHANNEL ACCESS TOKEN"); - this.appendValueInput("notify_msg") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("MESSAGE"); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setTooltip(''); - this.setColour(65); - } -}; diff --git a/LineBot_20181015/blockly/javascript.js b/LineBot_20181015/blockly/javascript.js deleted file mode 100644 index 9a3e218354..0000000000 --- a/LineBot_20181015/blockly/javascript.js +++ /dev/null @@ -1,45 +0,0 @@ -Blockly.JavaScript['linebot_notify'] = function (block) { - var bot_token = Blockly.JavaScript.valueToCode(block, 'bot_token', Blockly.JavaScript.ORDER_ATOMIC); - var bot_userid = Blockly.JavaScript.valueToCode(block, 'bot_userid', Blockly.JavaScript.ORDER_ATOMIC); - var bot_msg = Blockly.JavaScript.valueToCode(block, 'bot_msg', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'linebot_notify('+bot_token+','+bot_userid+','+bot_msg.replace(/\'/g,"")+');\n'; - return code; -}; - -Blockly.JavaScript['linebot_type'] = function(block) { - var value_type = block.getFieldValue('value_type'); - var value_parameter1 = Blockly.JavaScript.valueToCode(block, 'value_parameter1', Blockly.JavaScript.ORDER_ATOMIC); - var value_parameter2 = Blockly.JavaScript.valueToCode(block, 'value_parameter2', Blockly.JavaScript.ORDER_ATOMIC); - var value_parameter3 = Blockly.JavaScript.valueToCode(block, 'value_parameter3', Blockly.JavaScript.ORDER_ATOMIC); - var value_parameter4 = Blockly.JavaScript.valueToCode(block, 'value_parameter4', Blockly.JavaScript.ORDER_ATOMIC); - - if ((value_parameter1.indexOf(":")!=-1)||(value_parameter1.indexOf("/")!=-1)||(value_parameter1.indexOf("+")!=-1)) - value_parameter1 = '"'+value_parameter1+'"'; - if ((value_parameter2.indexOf(":")!=-1)||(value_parameter2.indexOf("/")!=-1)||(value_parameter2.indexOf("+")!=-1)) - value_parameter2 = '"'+value_parameter2+'"'; - if ((value_parameter3.indexOf(":")!=-1)||(value_parameter3.indexOf("/")!=-1)||(value_parameter3.indexOf("+")!=-1)) - value_parameter3 = '"'+value_parameter3+'"'; - if ((value_parameter4.indexOf(":")!=-1)||(value_parameter4.indexOf("/")!=-1)||(value_parameter4.indexOf("+")!=-1)) - value_parameter4 = '"'+value_parameter4+'"'; - - if (value_type=='text') - var code = '"&type='+value_type+'&text="+'+value_parameter1; - else if (value_type=='sticker') - var code = '"&type='+value_type+'&packageId="+'+value_parameter1+'+"&stickerId="+'+value_parameter2; - else if (value_type=='image') - var code = '"&type='+value_type+'&originalContentUrl="+'+value_parameter1+'+"&previewImageUrl="+'+value_parameter2; - else if (value_type=='video') - var code = '"&type='+value_type+'&originalContentUrl="+'+value_parameter1+'+"&previewImageUrl="+'+value_parameter2; - else if (value_type=='audio') - var code = '"&type='+value_type+'&originalContentUrl="+'+value_parameter1+'+"&duration="+'+value_parameter2; - else if (value_type=='location') - var code = '"&type='+value_type+'&title="+'+value_parameter1+'+"&address="+'+value_parameter2+'+"&latitude="+'+value_parameter3+'+"&longitude="+'+value_parameter4; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['linenotify'] = function (block) { - var notify_token = Blockly.JavaScript.valueToCode(block, 'notify_token', Blockly.JavaScript.ORDER_ATOMIC); - var notify_msg = Blockly.JavaScript.valueToCode(block, 'notify_msg', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'linenotify('+notify_token+','+notify_msg+');\n'; - return code; -}; diff --git a/LineBot_20181015/blockly/msg/blocks/en.js b/LineBot_20181015/blockly/msg/blocks/en.js deleted file mode 100644 index 8b13789179..0000000000 --- a/LineBot_20181015/blockly/msg/blocks/en.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/LineBot_20181015/blockly/msg/blocks/zh-hans.js b/LineBot_20181015/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 8b13789179..0000000000 --- a/LineBot_20181015/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/LineBot_20181015/blockly/msg/blocks/zh-hant.js b/LineBot_20181015/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index d3f5a12faa..0000000000 --- a/LineBot_20181015/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/LineBot_20181015/blockly/msg/en.js b/LineBot_20181015/blockly/msg/en.js deleted file mode 100644 index 173961dfbf..0000000000 --- a/LineBot_20181015/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catlinebot = "Line Bot"; diff --git a/LineBot_20181015/blockly/msg/zh-hans.js b/LineBot_20181015/blockly/msg/zh-hans.js deleted file mode 100644 index 173961dfbf..0000000000 --- a/LineBot_20181015/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catlinebot = "Line Bot"; diff --git a/LineBot_20181015/blockly/msg/zh-hant.js b/LineBot_20181015/blockly/msg/zh-hant.js deleted file mode 100644 index 173961dfbf..0000000000 --- a/LineBot_20181015/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catlinebot = "Line Bot"; diff --git a/LineBot_20181015/blockly/toolbox.xml b/LineBot_20181015/blockly/toolbox.xml deleted file mode 100644 index 2327c5d26d..0000000000 --- a/LineBot_20181015/blockly/toolbox.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/LineBot_20181015/linebot.js b/LineBot_20181015/linebot.js deleted file mode 100644 index 13da598456..0000000000 --- a/LineBot_20181015/linebot.js +++ /dev/null @@ -1,39 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function linebot_notify(bot_token,bot_userid,bot_msg) { - - console.log(bot_msg); - var input_url="https://script.google.com/macros/s/AKfycbwNu63z3ZFHo38wp9LBAwDGyG8tI46-5d-TpFLYFiOHDVOvmgN0/exec?token="+bot_token+"&userid="+bot_userid+bot_msg; - var src = ''; - - if (document.getElementById("bot_iframe")) - { - document.getElementById("bot_iframe").style.left = '0px'; - document.getElementById("bot_iframe").style.top = '0px'; - document.getElementById("bot_iframe").style.display = 'block'; - document.getElementById("bot_iframe").innerHTML = src; - } - else - { - var div = document.createElement('div'); - div.id = "bot_iframe"; - div.style.position = 'absolute'; - div.style.left = '0px'; - div.style.top = '0px'; - div.style.zindex='9999'; - div.innerHTML = src; - document.body.appendChild(div); - } - } - - function linenotify(notify_token,notify_msg) { - } - - window.linebot_notify = linebot_notify; - window.linenotify = linenotify; - -}(window, window.document)); diff --git a/LineBot_userId.gs b/LineBot_userId.gs new file mode 100644 index 0000000000..47fd1dbdea --- /dev/null +++ b/LineBot_userId.gs @@ -0,0 +1,53 @@ +// Line Bot TOKEN +let channel_access_TOKEN = ""; + +let getLinebotData = { + "userMessage": "", + "userId": "", + "groupId": "", + "roomId": "", + "eventType": "", + "replyToken": "" +} + +function doPost(e) { + let linebot_response = ""; + if (e.postData) { + let msg = JSON.parse(e.postData.contents); + getLinebotData.userMessage = msg.events[0].message.text.trim(); + getLinebotData.userId = msg.events[0].source.userId; + getLinebotData.groupId = msg.events[0].source.groupId; + getLinebotData.roomId = msg.events[0].source.roomId; + getLinebotData.eventType = msg.events[0].source.type; + getLinebotData.replyToken = msg.events[0].replyToken; + + if (getLinebotData.userMessage=="id") { + linebot_response = getLinebotData.userId; + } else if (getLinebotData.userMessage=="gid") { + linebot_response = getLinebotData.groupId; + } else if (getLinebotData.userMessage=="rid") { + linebot_response = getLinebotData.roomId; + } + replyMessageToLineBot(channel_access_TOKEN, getLinebotData.replyToken, linebot_response); + } + return ContentService.createTextOutput("ok"); +} + +function replyMessageToLineBot(accessToken, replyToken, message) { + let url = 'https://api.line.me/v2/bot/message/reply'; + let replyMessage = [{ + "type": "text", + "text": message + }] + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': replyMessage + }), + }); +} diff --git a/Linebot_ChatGPT_ThingspeakMQTT.gs b/Linebot_ChatGPT_ThingspeakMQTT.gs new file mode 100644 index 0000000000..8aa6ca3e08 --- /dev/null +++ b/Linebot_ChatGPT_ThingspeakMQTT.gs @@ -0,0 +1,275 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2023/7/29 23:00 +https://www.facebook.com/francefu +Line Bot Webhook & Google Apps script & ChatGTP API + +若傳訊無回應: +1. openAI api額度已用盡或Key已失效。 +2. 指令碼屬性值暫存歷史對話紀錄字串長度已達上限,請輸入"清除對話"清除歷史紀錄重新對話,或在Apps script專案設定裡刪除對應指令碼屬性。 +3. 指令碼屬性數超過上限,新增的Line bot使用者將無法記錄歷史對話,可付費升級為Google付費會員。 +4. 不明原因,重新佈署或重建Apps script專案並開放存取權限。 + +圖片生成並存入Google雲端硬碟: +格式: +image:你的prompts +例如: +image:美麗的台灣 + +教學影片清單 +https://www.youtube.com/playlist?list=PLxVtiYga8ehvi3lY9QYlEOL0tDLQFNfdM +*/ + +// ThingSpeak +let thingspeak_key = ""; + +// Line bot +let channel_access_TOKEN = ""; + +// chatGPT +let openAI_api_KEY = ""; // openAI + +let openAI_model = "gpt-3.5-turbo"; // gpt-3.5-turbo, gpt-3.5-turbo-0301, gpt-4 (gpt-4限已升級plus帳號或已有試用資格帳號) +let openAI_assistant_behavior = "你是使用繁體中文語言的專業助理"; +let reset_command = "reset"; //因對話紀錄會累計送出查詢,造成額度消費倍數增長,因此Line bot要在適當時候執行清除輸入文字"清除對話"。 +let reset_response = "您好,已為您清除歷史對話紀錄,讓我們重新聊天吧!"; + +// Image generator +let imageSize = "256x256"; // 256x256, 512x512, 1024x1024 +let driveFolderName = "openAI_image"; //建立Google雲端硬碟資料夾名稱,若無需存入可空白不填 + +// 可記錄對話內容於Google試算表,若無需紀錄可空白不填 +let spreadsheet_ID = ""; // 試算表ID (非網址) +let sheet_Name_sensor = "工作表1"; // 感測器工作表名稱 +let sheet_Name_chatgpt = "工作表2"; // chatgpt工作表名稱 + +// 感測值分析 +let sensor_command = "sensor"; + +// 查詢userId用於單晶片向Line bot回傳通知 +let userId_command = "id"; + +// 系統變數(無須填寫資料) +let userMessage = ""; +let userId = ""; +let eventType = ""; +let replyToken = ""; +let openAI_response; +let openAI_historical_messages; + +function doPost(e) { + + let scriptProperties = PropertiesService.getScriptProperties(); + + if (e.postData) { + + let msg = JSON.parse(e.postData.contents); + userMessage = msg.events[0].message.text.trim(); + userId = msg.events[0].source.userId; + eventType = msg.events[0].source.type; + replyToken = msg.events[0].replyToken; + + if (userMessage == sensor_command) { + var data = getRowsDataFromSpreadsheet(spreadsheet_ID, sheet_Name_sensor, 11); + userMessage = data.toString() + "\n請將感測器數據以此規則換行排列:日期, 時間, 溫度, 濕度, 亮度。並從欄位中找出各欄位的最大值與最小值。"; + } + + if (userMessage.toLowerCase()=="help") { + openAI_response = "開門:on\n關門:off\n重設聊天:"+reset_command+"\n生成圖片: image:提示詞\n感測值分析:"+sensor_command+"\n查詢userId:"+userId_command+"\n"; + } else if (userMessage.toLowerCase()==userId_command) { + openAI_response = userId; + } else if (userMessage.toLowerCase()=="on") { + let thingspeak_response = sendCommandToThingSpeak(thingspeak_key, 180, 0, 0, 0, 0, 0, 0, 0); + if (thingspeak_response!=0) + openAI_response = "正為您開門!"; + else + openAI_response = "請距離前次指令間隔15秒後再下指令!"; + } + else if (userMessage.toLowerCase()=="off") { + let thingspeak_response = sendCommandToThingSpeak(thingspeak_key, 90, 0, 0, 0, 0, 0, 0, 0); + if (thingspeak_response!=0) + openAI_response = "正為您關門!"; + else + openAI_response = "請距離前次指令間隔15秒後再下指令!"; + } + else if (userMessage != reset_command) { + + if (userMessage.indexOf("image:")!=-1) { + + if (spreadsheet_ID&&sheet_Name_chatgpt) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name_chatgpt, userId, "user", userMessage); + + let url = "https://api.openai.com/v1/images/generations"; + let data = { + "prompt": userMessage.substring(6), + "n": 1, + "size": imageSize + }; + + const authHeader = "Bearer " + openAI_api_KEY; + const options = { + headers: {Authorization: authHeader}, + method: 'POST', + contentType: 'application/json', + payload: JSON.stringify(data) + } + let response = UrlFetchApp.fetch(url, options); + let json = JSON.parse(response.getContentText()); + let openAI_response = json["data"][0]["url"]; + + let replyMessage = [{ + "type": "image", + "originalContentUrl": openAI_response, + "previewImageUrl": openAI_response + }] + sendMessageToLineBot(channel_access_TOKEN, replyToken, replyMessage); + + if (driveFolderName) { + var imageFilename = "openAI"+'_'+Utilities.formatDate(new Date(), "GMT", "yyyyMMddHHmmss"); + var imageBlob = UrlFetchApp.fetch(openAI_response).getBlob(); + + var folder, folders = DriveApp.getFoldersByName(driveFolderName); + if (folders.hasNext()) { + folder = folders.next(); + } else { + folder = DriveApp.createFolder(driveFolderName); + } + var file = folder.createFile(imageBlob).setName(imageFilename); + file.setDescription("Uploaded by line Bot"); + + var imageID = file.getUrl().substring(file.getUrl().indexOf("/d/")+3,file.getUrl().indexOf("view")-1); + var imageUrl = "https://drive.google.com/uc?authuser=0&id="+imageID; + + if (spreadsheet_ID&&sheet_Name_chatgpt) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name_chatgpt, userId, "assistant", imageUrl); + } else { + if (spreadsheet_ID&&sheet_Name_chatgpt) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name_chatgpt, userId, "assistant", openAI_response); + } + + } else { + + if (scriptProperties.getProperty(userId)==""||scriptProperties.getProperty(userId)==null) { + openAI_historical_messages = [{"role": "system", "content": openAI_assistant_behavior}]; + + if (spreadsheet_ID&&sheet_Name_chatgpt) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name_chatgpt, userId, "system", openAI_assistant_behavior); + } + else + openAI_historical_messages = JSON.parse(scriptProperties.getProperty(userId)); + + let chat_message = {}; + chat_message.role = "user"; + chat_message.content = userMessage; + openAI_historical_messages.push(chat_message); + + if (spreadsheet_ID&&sheet_Name_chatgpt) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name_chatgpt, userId, "user", userMessage); + + let url = "https://api.openAI.com/v1/chat/completions"; + + let data = { + "model": openAI_model, + "messages": openAI_historical_messages + }; + + const authHeader = "Bearer "+openAI_api_KEY; + const options = { + headers: {Authorization: authHeader}, + method: 'POST', + contentType: 'application/json', + payload: JSON.stringify(data) + } + + let response = UrlFetchApp.fetch(url, options); + let json = JSON.parse(response.getContentText()); + openAI_response = json["choices"][0]["message"]["content"].replace("?\n\n","").replace("?\n","").replace(/?\n/g,""); + + chat_message = {}; + chat_message.role = "assistant"; + chat_message.content = json["choices"][0]["message"]["content"]; + openAI_historical_messages.push(chat_message); + + scriptProperties.setProperty(userId, JSON.stringify(openAI_historical_messages)); + + if (spreadsheet_ID&&sheet_Name_chatgpt) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name_chatgpt, userId, "assistant", openAI_response); + } + + } else { + + scriptProperties.setProperty(userId, ''); + openAI_response = reset_response; + + if (spreadsheet_ID&&sheet_Name_chatgpt) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name_chatgpt, userId, "user", reset_command); + } + + let replyMessage = [{ + "type":"text", + "text": openAI_response + }] + sendMessageToLineBot(channel_access_TOKEN, replyToken, replyMessage); + } + + return ContentService.createTextOutput("Return = Finish"); +} + +function sendMessageToLineBot(accessToken, replyToken, reply_message) { + + let url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); + +} + +function getRowsDataFromSpreadsheet(spreadsheetId, sheetName, rows) { + var spreadsheet = SpreadsheetApp.openById(spreadsheetId); + var sheet = spreadsheet.getSheetByName(sheetName); + var dataRange = sheet.getRange("B1:F"+rows); + return dataRange.getValues(); +} + +function addDataToSpreadsheet(spreadsheetId, sheetName, chatId, chatType, chatContent) { + var dataDate = Utilities.formatDate(new Date(), "GMT+8", "yyyy-MM-dd"); + var dataTime = Utilities.formatDate(new Date(), "GMT+8", "HH:mm:ss"); + var data = [dataDate, dataTime, chatId, chatType, chatContent]; + + var spreadsheet = SpreadsheetApp.openById(spreadsheetId); + var sheet = spreadsheet.getSheetByName(sheetName); + + sheet.insertRowBefore(1); + sheet.getRange(1, 1, 1, data.length).setValues([data]); +} + +function sendCommandToThingSpeak(key,field1,field2,field3,field4,field5,field6,field7,field8) { + + let url = 'https://api.thingspeak.com/update'; + let response = UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8' + }, + 'method': 'post', + 'payload': JSON.stringify({ + "api_key": key, + "created_at": "DATETIME_STAMP", + "field1": field1, + "field2": field2, + "field3": field3, + "field4": field4, + "field5": field5, + "field6": field6, + "field7": field7, + "field8": field8 + }), + }); + return response.getContentText(); +} diff --git a/Linebot_Chatgpt_linenotify.gs b/Linebot_Chatgpt_linenotify.gs new file mode 100644 index 0000000000..3d9037aa26 --- /dev/null +++ b/Linebot_Chatgpt_linenotify.gs @@ -0,0 +1,314 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2024/8/15 18:00 +https://www.facebook.com/francefu +Line Bot Webhook & Google Apps script & ChatGTP API & Line Notify + +若傳訊無回應: +1. openAI api額度已用盡或Key已失效。 +2. 指令碼屬性數超過上限,新增的Line bot使用者將無法正常運作,可付費升級為Google付費會員。 +3. 不明原因,可能太久無人使用自動停用,重新佈署或重建Apps script專案並開放存取權限。 +4. Apps script程式碼有bug。 +5. Google試算表設定不正確。 +6. 重新再傳訊一次。 +*/ + +// Line bot +let channel_access_TOKEN = ""; + +// ChatGPT +let openAI_api_KEY = ""; + +// Google試算表 +let spreadsheet_ID = ""; // 試算表ID +let spreadsheet_Name_list = ""; // 工作表名稱 ( 行政人員名單:["編號","姓名","處室","職稱","權杖","訊息"] ) +let spreadsheet_Name_record = ""; // 工作表名稱 ( 訊息歷史紀錄:["日期","時間","userId","訊息","狀態"] ) + +// openAI設定 +let openAI_model = "gpt-4o"; // 限已升級plus帳號或已有刷卡儲值帳號,最好使用gpt-4o但很貴,因使用gpt-4o-mini或gpt-3.5錯誤率高 +let openAI_assistant_behavior = ` +請回覆陣列格式資料符合以下規範: +(1)請分析使用者對話內容,區分要傳送的訊息內容與傳送對象(陣列格式資料中與欄位「編號」、「姓名」、「處室」、「職稱」任一相同或相關聯,或所有對象皆傳送) +(2)對話內容中提及對象與欄位「編號」、「姓名」、「處室」、「職稱」任一相同或相關連,視為同一對象。 +(3)若同一對象的訊息內容可能有數則,以流水編號區表示不同則訊息。單一訊息資料格式如:請回電。多則訊息資料格式如:(1)請回電 (2)請離開 +(4)將傳送的訊息內容填入提供的陣列格式資料「訊息」欄位的值,保留欄位名稱首列。 +(5)若非傳送對象或傳送訊息內容為空白則不列入回傳陣列資料裡。 +(6)若無關任何傳送對象請回傳'請輸入要傳送的對象與訊息或者重試一次!',不須參照回傳陣列格式資料。 +(7)回覆對話的陣列資料列需根據「編號」欄位排序。 +(8)只回覆陣列格式資料,不要多作解釋。 +(9)陣列格式資料範本: +`; + +// 陣列資料格式範本: [["編號","姓名","處室","職稱","權杖","訊息"],["1", "林志玲", "校長室", "校長", "Line token1", "(1)message 1 (2)message 2 (3)..."],["2", "法蘭斯", "警衛室", "警衛", "Line token2", "(1)message 1 (2)message 2 (3)..."]] + +let Command = { + "help" : ["help", "list", "清單", "名單"], + "confirm" : ["confirm", "yes", "確定"], + "cancel" : ["cancel", "no", "取消"], + "search" : ["search", "查詢", "關鍵字"], // search 林志玲, 查詢 林志玲, 關鍵字 林志玲 + "sql" : "sql" // sql select * limit 2 +} + +let Msg = { + "success_send": "傳送完成", + "success": "成功:", + "failure_send": "傳送失敗", + "failure": "失敗:", + "cancel": "傳送取消", + "query": "請輸入[確定],或輸入[取消]", + "warn": "請先輸入要傳送的對象與訊息!", + "message_template": '(1)message 1 (2)message 2 (3)...' +} + +// Line bot參數 +let getLinebotData = { + "userMessage": "", + "userId": "", + "eventType": "", + "replyToken": "" +} + +let scriptProperties = PropertiesService.getScriptProperties(); + +function doPost(e) { + let linebot_response = ""; + + if (e.postData) { + let msg = JSON.parse(e.postData.contents); + getLinebotData.userMessage = msg.events[0].message.text.trim(); + getLinebotData.userId = msg.events[0].source.userId; + getLinebotData.eventType = msg.events[0].source.type; + getLinebotData.replyToken = msg.events[0].replyToken; + + if (Command.help.includes(getLinebotData.userMessage.toLowerCase())) { + let sqlDataArray = getSheetsQueryResult(spreadsheet_ID, spreadsheet_Name_list, "A:D", "select *"); + linebot_response = resultToListString(sqlDataArray); + } else if (Command.cancel.includes(getLinebotData.userMessage.toLowerCase())) { + scriptProperties.setProperty(getLinebotData.userId, ''); + linebot_response = Msg.cancel; + } else if (Command.confirm.includes(getLinebotData.userMessage.toLowerCase())) { + linebot_response = scriptProperties.getProperty(getLinebotData.userId); + if (!linebot_response) + linebot_response = Msg.warn; + else { + scriptProperties.setProperty(getLinebotData.userId, ''); + linebot_response = confirmSendMessage(linebot_response); + } + } else if (checkStartWithSearch(getLinebotData.userMessage, Command.search)!="") { + try { + let keyword = checkStartWithSearch(getLinebotData.userMessage, Command.search); + let sqlText = `select * where A contains '${keyword}' or B contains '${keyword}' or C contains '${keyword}' or D contains '${keyword}'`; + let sqlDataArray = getSheetsQueryResult(spreadsheet_ID, spreadsheet_Name_list, "A:D",sqlText ); + linebot_response = resultToListString(sqlDataArray); + } catch (error) { + linebot_response = error; + } + } else if (getLinebotData.userMessage.toLowerCase().indexOf(Command.sql)==0) { + try { + let sqlText = getLinebotData.userMessage.toLowerCase().substring(getLinebotData.userMessage.toLowerCase().indexOf(Command.sql) + Command.sql.length).trim(); + let sqlDataArray = getSheetsQueryResult(spreadsheet_ID, spreadsheet_Name_list, "A:D",sqlText ); + linebot_response = resultToListString(sqlDataArray); + } catch (error) { + linebot_response = error; + } + } else { + let sqlDataArray = getSheetsQueryResult(spreadsheet_ID, spreadsheet_Name_list, "A:E", "select *"); + let spreadsheet_list = resultToArrayString(sqlDataArray); + openAI_assistant_behavior = openAI_assistant_behavior + spreadsheet_list; + linebot_response = getSendMessageList(); + } + sendMessageToLineBot(channel_access_TOKEN, getLinebotData.replyToken, linebot_response); + } + return ContentService.createTextOutput("ok"); +} + +function checkStartWithSearch(message, search) { + for (var i = 0; i < search.length; i++) { + if (message.toLowerCase().indexOf(search[i].toLowerCase())==0) { + return message.substring(message.toLowerCase().indexOf(search[i].toLowerCase()) + search[i].length).trim(); + break; + } + } + return ""; +} + +function getSendMessageList() { + let response = sendMessageToChatGPT(openAI_assistant_behavior, getLinebotData.userMessage); + scriptProperties.setProperty(getLinebotData.userId, response); + let dataString = ""; + try { + let dataArray = eval(response); + for (let i = 1; i < dataArray.length; i++) { + let row = dataArray[i]; + dataString += `${row[0]} ${row[3]}-${row[1]}:${row[5]}\n`; + } + dataString += `\n${Msg.query}`; + } catch (error) { + dataString = `${response}\n\n${error}`; + } + return dataString; +} + +function confirmSendMessage(response) { + let count_ok = 0; + let row; + let err = ''; + try { + let dataArray = eval(response); + for (let i = 1; i < dataArray.length; i++) { + row = dataArray[i]; + if (row[5] != '') { + if (sendMessageToLineNotify(row[4], `\n${row[5]}`)) + count_ok++; + else { + err = `\n\nUnexpected token\n\n${row}`; + break; + } + } + } + recordMessageToSpreadsheet(response, (dataArray.length - 1 == count_ok)?"ok":err); + return `${Msg.success_send}\n${Msg.success}${count_ok}\n${Msg.failure}${dataArray.length - count_ok - 1}${err}`; + } catch (error) { + recordMessageToSpreadsheet(response, "error"); + return `${Msg.failure_send}\n\n${row}\n\n${Msg.success}${count_ok}\n${Msg.failure}${dataArray.length - count_ok - 1}\n\n${error}`; + } +} + +function recordMessageToSpreadsheet(message, status) { + var dataDate = Utilities.formatDate(new Date(), "GMT+8", "yyyy-MM-dd"); + var dataTime = Utilities.formatDate(new Date(), "GMT+8", "HH:mm:ss"); + var data = [dataDate, dataTime, getLinebotData.userId, message, status]; + + var spreadsheet = SpreadsheetApp.openById(spreadsheet_ID); + var sheet = spreadsheet.getSheetByName(spreadsheet_Name_record); + + sheet.insertRowAfter(1); + sheet.getRange(2, 1, 1, data.length).setValues([data]); +} + +function sendMessageToLineNotify(replyToken, replyMessage) { + try { + url = 'https://notify-api.line.me/api/notify'; + let response = UrlFetchApp.fetch(url, { + 'headers': { + 'Authorization': 'Bearer ' + replyToken, + }, + 'method': 'post', + 'payload': { + 'message': replyMessage + } + }); + if (JSON.parse(response).message == "ok") + return true; + else + return false; + } catch (error) { + return false; + } +} + +function sendMessageToLineBot(accessToken, replyToken, message) { + let url = 'https://api.line.me/v2/bot/message/reply'; + let replyMessage = [{ + "type": "text", + "text": message + }] + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': replyMessage + }), + }); +} + +function sendMessageToChatGPT(assistant_behavior, user_message){ + try { + let openAI_messages = [{ + "role": "system", + "content": assistant_behavior + }]; + + let chat_message = {}; + chat_message.role = "user"; + chat_message.content = user_message; + openAI_messages.push(chat_message); + + let url = "https://api.openAI.com/v1/chat/completions"; + let data = { + "model": openAI_model, + "messages": openAI_messages + }; + + const authHeader = "Bearer " + openAI_api_KEY; + const options = { + headers: { + Authorization: authHeader + }, + method: 'POST', + contentType: 'application/json', + payload: JSON.stringify(data) + } + + let response = UrlFetchApp.fetch(url, options); + let json = JSON.parse(response.getContentText()); + return json["choices"][0]["message"]["content"]; + } catch (error) { + return '[["", "", "", "", "", ""], ["", "Message", "", "Error", "", "Incorrect API key provided."]]'; + } +} + +function getSheetsQueryResult(fileId, sheetName, range, sqlText) { + let file = SpreadsheetApp.openById(fileId); + let sheetId = file.getSheetByName(sheetName).getSheetId(); + let sqlURL = `https://docs.google.com/spreadsheets/d/${fileId}/gviz/tq?gid=${sheetId}&range=${range}&tq=${encodeURIComponent(sqlText)}`; + let result = UrlFetchApp.fetch(sqlURL).getContentText(); + let jsonData = result.match(/\(.*?\)/)[0].replace(/[()]/g, ''); + jsonData = JSON.parse(jsonData); + if ('errors' in jsonData) { + let errorMessage = jsonData.errors[0].detailed_message; + return [[errorMessage]]; + } else { + let table_rows = jsonData.table.rows; + let labels = jsonData.table.cols.map(item => item.label); + let types = jsonData.table.cols.map(item => item.type); + let resultArray = []; + resultArray.push(labels); + for (let i = 0, l = table_rows.length; i < l; i++) { + let row = table_rows[i].c; + let items = []; + for (let j = 0; j < row.length; j++) { + let type = types[j]; + if (type === 'number'||type === 'boolean') { + items.push(row[j]==null?null:row[j].f); + } else { + items.push(row[j]==null?null:row[j].v); + } + } + resultArray.push(items); + } + return resultArray; + } +} + +function resultToArrayString(result) { + var output = '['; + for (var i = 0; i < result.length; i++) { + output += `["${result[i][0]}", "${result[i][1]}", "${result[i][2]}", "${result[i][3]}", "${result[i][4]}", "${Msg.message_template}"]`; + output += (i!=result.length-1)?",":""; + } + output += ']'; + return output; +} + +function resultToListString(result) { + var output = ''; + for (var i = 0; i < result.length; i++) { + output += result[i].slice(0, 4).join(', '); + output += (i!=result.length-1)?"\n":""; + } + return output; +} diff --git a/Linebot_Chatgpt_teacher.gs b/Linebot_Chatgpt_teacher.gs new file mode 100644 index 0000000000..fece66d7b4 --- /dev/null +++ b/Linebot_Chatgpt_teacher.gs @@ -0,0 +1,217 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2023/8/25 00:00 +https://www.facebook.com/francefu +Line Bot Webhook & Google Apps script & ChatGTP API + +若傳訊無回應: +1. openAI api額度已用盡或Key已失效。 +2. 指令碼屬性值暫存歷史對話紀錄字串長度已達上限,請輸入"清除對話"清除歷史紀錄重新對話。 +3. 指令碼屬性數超過上限,新增的Line bot使用者將無法記錄歷史對話,可付費升級為Google付費會員。 +4. 不明原因,重新佈署或重建Apps script專案並開放存取權限。 +*/ + +// Line bot +let channel_access_TOKEN = ""; + +// chatGPT +let openAI_api_KEY = ""; // openAI + +// 可記錄對話內容於試算表,若無需紀錄可空白不填 +let spreadsheet_ID = ""; // 試算表ID +let sheet_Name = "對話紀錄"; // 工作表名稱 +let sheet_Name1 = "聯絡簿事項"; // 聯絡簿作業、物品 +let sheet_Name2 = "個人事項"; // 聯絡簿私人事項 + +let openAI_model = "gpt-3.5-turbo"; // gpt-3.5-turbo, gpt-3.5-turbo-0301, gpt-4 (gpt-4限已升級plus帳號或已有試用資格帳號) +let openAI_assistant_behavior = "你是班級導師,回答家長有關班級管理與教育子女的問題,且符合以下規範:\n- 分析家長提問內容是否與教育有關或為問候語,若不是則果斷回覆「很抱歉,無法回答非教育問題!」,不要多做解釋。\n- 回覆的內容開頭要加上「我是ChatGPT導師助手」。"; +let openAI_queryTitle = "家長提問:"; +let reset_command = "reset"; +let reset_response = "您好,已為您清除歷史對話紀錄,讓我們重新聊天吧!"; +let userId_command = "id"; +let contactbook_command = "book"; +let private_command = "self"; + +// 系統變數 +let userMessage = ""; +let userId = ""; +let eventType = ""; +let replyToken = ""; +let openAI_response; +let openAI_historical_messages; +let openAI_request_title = ""; + +function doPost(e) { + + let scriptProperties = PropertiesService.getScriptProperties(); + + if (e.postData) { + + let msg = JSON.parse(e.postData.contents); + userMessage = msg.events[0].message.text.trim(); + userId = msg.events[0].source.userId; + eventType = msg.events[0].source.type; + replyToken = msg.events[0].replyToken; + + if (userMessage.toLowerCase()=="help"||userMessage=="導師") { + openAI_response = "查詢聯絡簿:"+contactbook_command+"\n個人事項:"+private_command+"\n重設聊天:"+reset_command+"\n查詢userId:"+userId_command+"\n"; + } + else if (userMessage == contactbook_command) { + var myDate = Utilities.formatDate(new Date(), "GMT+8", "yyyy-MM-dd"); + openAI_response = getSheetsQueryResult_(spreadsheet_ID, sheet_Name1, 'B:D', "select * where B >= date '" +myDate+ "'"); + openAI_response = openAI_response.join("\n"); + } + else if (userMessage == private_command) { + var myDate = Utilities.formatDate(new Date(), "GMT+8", "yyyy-MM-dd"); + openAI_response = getSheetsQueryResult_(spreadsheet_ID, sheet_Name2, 'B:E', "select C, D, E where C >= date '" +myDate+ "' and B = '" +userId+ "'"); + openAI_response = openAI_response.join("\n"); + } + else if (userMessage == reset_command) { + scriptProperties.setProperty(userId, ''); + openAI_response = reset_response; + + if (spreadsheet_ID&&sheet_Name) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name, userId, "user", reset_command); + } + else if (userMessage == userId_command) { + openAI_response = userId; + } + else { + + userMessage = scriptProperties.getProperty(userId+"_querytitle") + "[ "+ userMessage + " ]"; + + if (scriptProperties.getProperty(userId)==""||scriptProperties.getProperty(userId)==null) { + openAI_historical_messages = [{"role": "system", "content": openAI_assistant_behavior}]; + scriptProperties.setProperty(userId+"_querytitle", openAI_queryTitle); + + if (spreadsheet_ID&&sheet_Name) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name, userId, "system", openAI_assistant_behavior); + } + else + openAI_historical_messages = JSON.parse(scriptProperties.getProperty(userId)); + + let chat_message = {}; + chat_message.role = "user"; + chat_message.content = userMessage; + openAI_historical_messages.push(chat_message); + + if (spreadsheet_ID&&sheet_Name) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name, userId, "user", userMessage); + + let url = "https://api.openAI.com/v1/chat/completions"; + + let data = { + "model": openAI_model, + "messages": openAI_historical_messages + }; + + const authHeader = "Bearer "+openAI_api_KEY; + const options = { + headers: {Authorization: authHeader}, + method: 'POST', + contentType: 'application/json', + payload: JSON.stringify(data) + } + + let response = UrlFetchApp.fetch(url, options); + let json = JSON.parse(response.getContentText()); + openAI_response = json["choices"][0]["message"]["content"].replace("?\n\n","").replace("?\n","").replace(/?\n/g,""); + + chat_message = {}; + chat_message.role = "assistant"; + chat_message.content = json["choices"][0]["message"]["content"]; + openAI_historical_messages.push(chat_message); + + scriptProperties.setProperty(userId, JSON.stringify(openAI_historical_messages)); + + if (spreadsheet_ID&&sheet_Name) + addDataToSpreadsheet(spreadsheet_ID, sheet_Name, userId, "assistant", openAI_response); + } + + let replyMessage = [{ + "type":"text", + "text": openAI_response + }] + sendMessageToLineBot(channel_access_TOKEN, replyToken, replyMessage); + } + + return ContentService.createTextOutput("Return = Finish"); +} + +function sendMessageToLineBot(accessToken, replyToken, reply_message) { + + let url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); + +} + +function addDataToSpreadsheet(spreadsheetId, sheetName, chatId, chatType, chatContent) { + var dataDate = Utilities.formatDate(new Date(), "GMT+8", "yyyy-MM-dd"); + var dataTime = Utilities.formatDate(new Date(), "GMT+8", "HH:mm:ss"); + var data = [dataDate, dataTime, chatId, chatType, chatContent]; + + var spreadsheet = SpreadsheetApp.openById(spreadsheetId); + var sheet = spreadsheet.getSheetByName(sheetName); + + sheet.insertRowBefore(1); + sheet.getRange(1, 1, 1, data.length).setValues([data]); +} + +//https://stackoverflow.com/questions/22330542/can-i-use-google-visualization-api-to-query-a-spreadsheet-in-apps-script +function getSheetsQueryResult_(fileId, sheetName, rangeA1, sqlText) +{ + var file = SpreadsheetApp.openById(fileId); + var sheetId = file.getSheetByName(sheetName).getSheetId(); + + var request = 'https://docs.google.com/spreadsheets/d/' + fileId + '/gviz/tq?gid=' + sheetId + '&range=' + rangeA1 + '&tq=' + encodeURIComponent(sqlText); + var result = UrlFetchApp.fetch(request).getContentText(); + // get json object + var from = result.indexOf("{"); + var to = result.lastIndexOf("}")+1; + var jsonText = result.slice(from, to); + var parsedText = JSON.parse(jsonText); + + // get types + var types = []; + var addType_ = function(col) { types.push(col.type); } + var cols = parsedText.table.cols; + cols.forEach(addType_); + + // loop rows + var rows = parsedText.table.rows; + var result = []; + var rowQuery = []; + var eltQuery = {}; + var row = []; + var nRows = rows[0].c.length; + var type = ''; + for (var i = 0, l = rows.length; i < l; i++) + { + rowQuery = rows[i].c; + row = []; + // loop values + for (var k = 0; k < nRows; k++) + { + eltQuery = rowQuery[k]; + type = types[k]; + if (type === 'number') { + row.push(parseInt(eltQuery.v)); + } else if (type === 'boolean' || type === 'string') { + row.push(eltQuery.v); + } else { + row.push(eltQuery.f); + } + } + result.push(row); + } + return result; +} diff --git a/Linebot_Gemini_Vision.gs b/Linebot_Gemini_Vision.gs new file mode 100644 index 0000000000..2b597761f4 --- /dev/null +++ b/Linebot_Gemini_Vision.gs @@ -0,0 +1,234 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2024/8/23 00:00 +https://www.facebook.com/francefu +Line Bot Webhook & Google Apps script & Gemini Vision + +若傳訊無回應: +1. Gemini api額度已用盡或Key已失效。 +2. 不明原因,可能太久無人使用自動停用,重新佈署或重建Apps script專案並開放存取權限。 +3. Apps script程式碼有bug。 +4. 重新再傳訊一次。 +*/ + +// Line bot +let channel_access_TOKEN = ""; + +// Gemini設定 +let Gemini_api_key = ""; + +// Line bot參數 +let getLinebotData = { + "userId": "", + "eventType": "", + "replyToken": "", + "userType": "", + "userMessage": "", + "userImage": "", + "userMessageId": "", + "quotedMessageId": "" +} + +let scriptProperties = PropertiesService.getScriptProperties(); + +function doPost(e) { + if (e.postData) { + let linebot_response = "請先上傳圖片或輸入圖片網址,再引用圖片或輸入網址回覆並輸入對話內容!"; + let linebot_imageURL = ""; + let chat_message = "請分析圖片中的場景與情境,若有文字資料請將內容進行重點摘要。"; + + let msg = JSON.parse(e.postData.contents); + getLinebotData.userId = msg.events[0].source.userId; + getLinebotData.eventType = msg.events[0].source.type; + getLinebotData.replyToken = msg.events[0].replyToken; + getLinebotData.userType = msg.events[0].message.type; + getLinebotData.userMessageId = msg.events[0].message.id; + + if (getLinebotData.userType=="text") { + getLinebotData.userMessage = msg.events[0].message.text.trim(); + getLinebotData.quotedMessageId = msg.events[0].message.quotedMessageId; + + if (getLinebotData.userMessage.toLowerCase().trim().indexOf("https://")==0) { + let urlData = getLinebotData.userMessage.split("\n"); + getLinebotData.userImage = getImageUrlBase64(urlData[0].trim()); + if (urlData.length>1) + chat_message = getLinebotData.userMessage.replace(urlData[0], "").trim(); + linebot_imageURL = urlData[0].trim(); + saveHistoricalURL(getLinebotData.userId, getLinebotData.userMessageId, urlData[0].trim()); + } else if (getLinebotData.quotedMessageId) { + chat_message = getLinebotData.userMessage; + let imageURL = getHistoricalURL(getLinebotData.userId, getLinebotData.quotedMessageId); + getLinebotData.userImage = getImageUrlBase64(imageURL); + if (!getLinebotData.userImage) + getLinebotData.userImage = getImageBase64(channel_access_TOKEN, getLinebotData.quotedMessageId); + } else + linebot_response = sendMessageToGeminiChat(Gemini_api_key, getLinebotData.userMessage); + } + else if (getLinebotData.userType=="image") + getLinebotData.userImage = getImageBase64(channel_access_TOKEN, getLinebotData.userMessageId); + + if (getLinebotData.userImage) + linebot_response = sendImageToGeminiVision(Gemini_api_key, chat_message, getLinebotData.userImage); + + sendMessageToLineBot(channel_access_TOKEN, getLinebotData.replyToken, linebot_response, linebot_imageURL); + } + return ContentService.createTextOutput("OK"); +} + +function saveHistoricalURL(userId, messageId, messageURL) { + let list = scriptProperties.getProperty(userId)||"[]"; + list = JSON.parse(list); + if (list.length>=20) + list.splice(0, 1); + message = {}; + message.messageId = messageId; + message.messageURL = messageURL; + list.push(message); + scriptProperties.setProperty(userId, JSON.stringify(list)); +} + +function getHistoricalURL(userId, messageId) { + let list = scriptProperties.getProperty(userId); + if (list) { + list = JSON.parse(list); + for (let i=0;i 0 && json.candidates[0].content && json.candidates[0].content.parts && json.candidates[0].content.parts.length > 0) { + return json.candidates[0].content.parts[0].text; + } else { + return 'JSON.stringify(response)'; + } + + } catch (error) { + return 'error'; + } +} + +function sendMessageToLineBot(replyToken, reply_message) { + let url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); +} + +function replyErrorMessage(replyToken) { + let replyMessage = [{ + "type":"text", + "text": ERROR_MESSAGE + }]; + sendMessageToLineBot(replyToken, replyMessage); +} diff --git a/Linebot_Gemini_googleCalendar_advanced.gs b/Linebot_Gemini_googleCalendar_advanced.gs new file mode 100644 index 0000000000..3df4db803b --- /dev/null +++ b/Linebot_Gemini_googleCalendar_advanced.gs @@ -0,0 +1,316 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2025/5/4 23:30 +https://www.facebook.com/francefu +*/ + +const CHANNEL_ACCESS_TOKEN = "xxxxx"; +const GEMINI_API_KEY = "xxxxx"; +const GOOGLE_SPREADSHEET_ID = "xxxxx"; +const GOOGLE_SPREADSHEET_NAME = "xxxxx"; + +const GEMINI_ASSISTANT_BEHAVIOR = ` +請依照以下規範:\n +1. 請判別使用者對話內容屬於以下哪一種類別:【行事曆新增、記帳、查帳、聊天】,回傳陣列資料。\n +2. \n +(1) 如果類別為"行事曆新增(type:calendar)"且對話內容包含日期、時間、持續時間、事項,請回傳json陣列資料,格式如下:\n +[{"type":"calendar", "date":"填入日期轉換為 'YYYY-MM-DD' 格式", "time":"填入時間轉換為 'HH:MM:00' 格式", "duration":"持續幾小時,預設為1","workMatter":"事項內容"}, ...]\n +資料格式示範: [{"type":"calendar", "date":"2025-05-01", "time":"12:00:00", "duration":1, "workMatter":"吃海鮮大餐!"}, {"type":"calendar", "date":"2025-05-02", "time":"10:30:00", "duration":1, "workMatter":"去打球!"}, ...]\n +(2) 如果類別為"記帳(type:accounting)"且對話內容包含時間、分類、金額,請回傳json陣列資料,格式如下:\n +[{"type":"accounting", "time":"轉換為 'YYYY-MM-DD HH:MM:00' 格式","money":"消費金額","summary":"消費摘要"}, ...]\n +資料格式示範: [{"type":"accounting", "class":"餐飲", "time":"2025-05-01 12:00:00", "money":1000, "summary":"吃海鮮大餐!"}, {"type":"accounting", "class":"交通", "time":"2025-05-02 10:30:00", "money":200, "summary":"搭計程車"}, ...]\n +依對話內容判別分類為以下類別之一:餐飲, 交通, 居住, 娛樂, 健康與醫療, 個人用品, 設備、教育、其他。\n +(3) 如果類別為"查帳(type:audit)"且對話內容包含起訖日期,請回傳json陣列資料,格式如下:\n +[{"type":"audit", "startDate":"轉換為 'YYYY-MM-DD' 格式", "endDate":"轉換為 'YYYY-MM-DD' 格式"}]\n +資料格式示範: [{"type":"audit", "startDate":"2025-05-01", "endDate":"2025-05-02"}]\n +(4) 如果類別判斷屬於"聊天(type:chat)",請回傳json陣列資料,格式如下:\n +[{"type":"chat", "response":"依據使用者的對話內容詳細回覆。"}]\n +3. 若沒有提及年份,則表示今年。\n +4. 若沒有提及月份,則表示本月。\n +5. 若沒有提及時間,則表示00:00:00。\n +6. 若沒有提及持續幾小時,則預設為1小時。\n +7. 若提到持續一天或全天,時間由當日00:00:00算起。\n +8. 不可使用Markdown語法。\n +`; + +const HELP_MESSAGE = "\n\n您可以在此進行【行事曆新增、記帳、查帳、聊天】的功能!"; +const ERROR_MESSAGE = "請傳送文字或語音訊息,進行【行事曆新增、記帳、查帳、聊天】並提供所需資料,或者可能發生提供的 Gemini Key 無法使用!"; + +function doPost(e) { + if (e.postData) { + let msg = JSON.parse(e.postData.contents); + let userType = msg.events[0].message.type; + let replyToken = msg.events[0].replyToken; + + if (userType=="text"||userType=="audio") { + let userMessage = ""; + if (userType=="text") + userMessage = msg.events[0].message.text.trim(); + else { + let messageId = msg.events[0].message.id; + userMessage = sendAudioToGeminiSTT(getAudioFromLinebot(messageId), "audio/aac", "請將音訊轉換為文字"); + } + + let geminiMessages = [{ "role": "user", "parts": [{ "text": GEMINI_ASSISTANT_BEHAVIOR + "9. 現在時間為" + Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd HH:mm:ss") + "\n\n\n\n使用者訊息:" + userMessage }] }]; + + let jsonData = sendMessageToGeminiChat(GEMINI_API_KEY, geminiMessages).replace(/```json|```/g, "").trim(); + if (jsonData!="error"&&jsonData.indexOf('[')!=-1) { + try { + jsonData = jsonData.substring(jsonData.indexOf('['), jsonData.indexOf(']')+1); + let data = JSON.parse(jsonData.replace(/\r\n/g, '\\r\\n').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, ' ')); + let response = ""; + if (data.length>0) { + for (let i=0;i 0 && json.candidates[0].content && json.candidates[0].content.parts && json.candidates[0].content.parts.length > 0) { + return json.candidates[0].content.parts[0].text; + } else { + return JSON.stringify(response); + } + + } catch (error) { + return 'error'; + } +} + +function getAudioFromLinebot(messageId) { + var url = `https://api-data.line.me/v2/bot/message/${messageId}/content`; + + var options = { + 'headers': { + 'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN, + }, + 'method': 'get', + 'muteHttpExceptions': true + }; + + try { + var response = UrlFetchApp.fetch(url, options); + var responseCode = response.getResponseCode(); + if (responseCode === 200) { + var audioBlob = response.getBlob(); + var audioBase64Data = Utilities.base64Encode(audioBlob.getBytes()); + return audioBase64Data; + } else { + throw new Error('Failed to fetch audio content: ' + responseCode); + } + } catch (e) { + return null; + } +} + +function sendAudioToGeminiSTT(audioBase64Data, mimeType, prompt) { + var url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=${GEMINI_API_KEY}`; + + var filePart = { + "inline_data": { + "data": audioBase64Data, + "mime_type": mimeType + } + }; + + var textPart = { + "text": prompt + }; + + var requestBody = { + "contents": [ + { + "role": "user", + "parts": [filePart, textPart] + } + ] + }; + + var options = { + 'method': 'post', + 'contentType': 'application/json; charset=utf-8', + 'payload': JSON.stringify(requestBody), + 'muteHttpExceptions': true + }; + + try { + var response = UrlFetchApp.fetch(url, options); + var responseCode = response.getResponseCode(); + if (responseCode === 200) { + var responseData = JSON.parse(response.getContentText()); + var getText = responseData.candidates[0].content.parts[0].text; + if (getText === null) { + getText = responseData.error.message; + } + return getText.replace(/\n/g, ''); + } else { + return 'Error: ' + responseCode + ' ' + response.getContentText(); + } + } catch (e) { + return 'Request failed: ' + e.toString(); + } +} + +function sendMessageToLineBot(replyToken, reply_message) { + let url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); +} + +function spreadsheetsql_executeSql(spreadsheet_sql, spreadsheet_id, spreadsheet_name) { + try { + let file = SpreadsheetApp.openById(spreadsheet_id); + let sheet = file.getSheetByName(spreadsheet_name); + if (!sheet) { + return 'Error: Sheet "' + spreadsheet_name + '" not found in spreadsheet ID "' + spreadsheet_id + '".'; + } + let sheetId = sheet.getSheetId(); + let range = sheet.getDataRange().getA1Notation(); + + let request = 'https://docs.google.com/spreadsheets/d/' + spreadsheet_id + '/gviz/tq?gid=' + sheetId + '&range=' + range + '&tq=' + encodeURIComponent(spreadsheet_sql); + let result = UrlFetchApp.fetch(request).getContentText(); + + while (result.indexOf("table")!=-1) { + let dataFrom = result.indexOf("{"); + let dataTo = result.lastIndexOf("}"); + result = result.slice(dataFrom+1, dataTo); + } + let jsonText = "{"+result+"}"; + return spreadsheetsql_convertResponse(jsonText); + } catch (error) { + return 'Error executing SQL: ' + error; + } +} + +function spreadsheetsql_convertResponse(data) { + let response = []; + let res = JSON.parse(data.replace(/\r\n/g, '\\r\\n').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, ' ')); + + try { + response.push(""); + + let cols = res.cols; + if (cols) { + response.push(""); + else + response.push(""); + } + response.push(""); + } + + let rows = res.rows; + if (rows) { + for (let i = 0; i < rows.length; i++) { + response.push(""); + for (let j = 0; j < rows[i].c.length; j++) { + if (rows[i].c[j]) { + if (rows[i].c[j].v !== undefined) { + response.push((rows[i].c[j].f !== undefined) ? "" : ""); + } else + response.push(""); + } else + response.push(""); + } + response.push(""); + } + } + response.push("
"); + for (let i = 0; i < cols.length; i++) { + if (cols[i].label) + response.push("" + cols[i].label + "" + cols[i].id + "
"+rows[i].c[j].f+""+rows[i].c[j].v+"
"); + } catch (error) { + return 'Error getting SQL data: ' + error; + } + + return response.join(""); +} diff --git a/Linebot_Spreadsheet.gs b/Linebot_Spreadsheet.gs new file mode 100644 index 0000000000..097864c320 --- /dev/null +++ b/Linebot_Spreadsheet.gs @@ -0,0 +1,100 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2022/8/4 12:20 +https://www.facebook.com/francefu +*/ + +var BOT_ACCESS_TOKEN = '*****'; +var SPREADSHEET_ID = '*****'; +var userProperties = PropertiesService.getUserProperties(); + +function doPost(e) { + + var SpreadSheet = SpreadsheetApp.openById(SPREADSHEET_ID); + var Sheet = SpreadSheet.getSheets()[0]; + var reply_message; + + if (e.postData) { + + var msg = JSON.parse(e.postData.contents); + const userMessage = msg.events[0].message.text.trim(); + const user_id = msg.events[0].source.userId; + const event_type = msg.events[0].source.type; + const replyToken = msg.events[0].replyToken; + + try { + userProperties.setProperty('replyToken', replyToken); + } catch (err) { + Logger.log('Failed with error %s', err.message); + } + + if (userMessage=="help") { + + reply_message = [{ + "type": "text", + "text": "Command list", + "quickReply": { + "items": [ + { + "type": "action", + "action": { + "type": "message", + "label": "on", + "text": "on" + } + }, + { + "type": "action", + "action": { + "type": "message", + "label": "off", + "text": "off" + } + } + ] + } + }] + + sendMessageToLineBot(BOT_ACCESS_TOKEN,replyToken,reply_message); + } + else { + Sheet.getRange(1,1).setValue(userMessage); + Sheet.getRange(1,2).setValue(replyToken); + } + + } + else if (e.parameter.response) { + + if (e.parameter.token == userProperties.getProperty('replyToken')) { + Sheet.getRange(1,1).setValue(""); + Sheet.getRange(1,2).setValue(""); + + if (e.parameter.response!="") { + reply_message = [{ + "type":"text", + "text": e.parameter.response + }] + sendMessageToLineBot(BOT_ACCESS_TOKEN, e.parameter.token, reply_message); + } + } + + } + + return ContentService.createTextOutput("Return = Finish"); +} + +function sendMessageToLineBot(accessToken, replyToken, reply_message) { + + var url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); + +} diff --git a/Linebot_Spreadsheet_googledrive.gs b/Linebot_Spreadsheet_googledrive.gs new file mode 100644 index 0000000000..e89922e1d1 --- /dev/null +++ b/Linebot_Spreadsheet_googledrive.gs @@ -0,0 +1,138 @@ +var BOT_ACCESS_TOKEN = '*****'; +var SPREADSHEET_ID = '*****'; +var userProperties = PropertiesService.getUserProperties(); + +function doPost(e) { + + var SpreadSheet = SpreadsheetApp.openById(SPREADSHEET_ID); + var Sheet = SpreadSheet.getSheets()[0]; + var reply_message; + + if (e.parameter.myFile) { + Sheet.getRange(1,1).setValue(""); + Sheet.getRange(1,2).setValue(""); + + var myFile = e.parameter.myFile; + + var myFoldername = "esp32-cam"; + var myFilename = Utilities.formatDate(new Date(), "GMT", "yyyyMMddHHmmss")+"_esp32-cam.jpg"; + var myToken = e.parameter.token; + + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, myFilename); + + // Save a captured image to Google Drive. + var folder, folders = DriveApp.getFoldersByName(myFoldername); + if (folders.hasNext()) { + folder = folders.next(); + } else { + folder = DriveApp.createFolder(myFoldername); + } + var file = folder.createFile(blob); + file.setDescription("Uploaded by " + myFilename); + + var imageID = file.getUrl().substring(file.getUrl().indexOf("/d/")+3,file.getUrl().indexOf("view")-1); + var imageUrl = "https://drive.google.com/uc?authuser=0&id="+encodeURIComponent(imageID); + + reply_message = [{ + "type":"text", + "text": imageUrl + }] + sendMessageToLineBot(BOT_ACCESS_TOKEN, myToken, reply_message); + + } + else if (e.postData) { + + var msg = JSON.parse(e.postData.contents); + const userMessage = msg.events[0].message.text.trim(); + const user_id = msg.events[0].source.userId; + const event_type = msg.events[0].source.type; + const replyToken = msg.events[0].replyToken; + + try { + userProperties.setProperty('replyToken', replyToken); + } catch (err) { + Logger.log('Failed with error %s', err.message); + } + + if (userMessage=="help") { + + reply_message = [{ + "type": "text", + "text": "Command list", + "quickReply": { + "items": [ + { + "type": "action", + "action": { + "type": "message", + "label": "on", + "text": "on" + } + }, + { + "type": "action", + "action": { + "type": "message", + "label": "off", + "text": "off" + } + }, + { + "type": "action", + "action": { + "type": "message", + "label": "getstill", + "text": "getstill" + } + } + ] + } + }] + + sendMessageToLineBot(BOT_ACCESS_TOKEN,replyToken,reply_message); + } + else { + Sheet.getRange(1,1).setValue(userMessage); + Sheet.getRange(1,2).setValue(replyToken); + } + + } + else if (e.parameter.response) { + + if (e.parameter.token == userProperties.getProperty('replyToken')) { + Sheet.getRange(1,1).setValue(""); + Sheet.getRange(1,2).setValue(""); + + if (e.parameter.response!="") { + reply_message = [{ + "type":"text", + "text": e.parameter.response + }] + sendMessageToLineBot(BOT_ACCESS_TOKEN, e.parameter.token, reply_message); + } + } + + } + + return ContentService.createTextOutput("Return = Finish"); +} + +function sendMessageToLineBot(accessToken, replyToken, reply_message) { + + var url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); + +} \ No newline at end of file diff --git a/Linebot_openAI.gs b/Linebot_openAI.gs new file mode 100644 index 0000000000..645d575163 --- /dev/null +++ b/Linebot_openAI.gs @@ -0,0 +1,79 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2022/12/29 01:55 +https://www.facebook.com/francefu +Text completion (openAI) +*/ + +let channel_access_TOKEN = ""; //Line Bot Token +let openAI_api_KEY = ""; //openAI API Key +let maxTokens = 1024; + +let userMessage = ""; +let userId = ""; +let eventType = ""; +let replyToken = ""; + +function doPost(e) { + + if (e.postData) { + + let msg = JSON.parse(e.postData.contents); + userMessage = msg.events[0].message.text.trim(); + //userMessage = "請使用繁體中文回覆以下對話:\n\n" + userMessage; + userId = msg.events[0].source.userId; + eventType = msg.events[0].source.type; + replyToken = msg.events[0].replyToken; + + let url = "https://api.openai.com/v1/completions"; + + let data = { + "model": "text-davinci-003", + "prompt": userMessage, + "temperature": 0, + "max_tokens": maxTokens, + "frequency_penalty": 0, + "presence_penalty": 0.6, + "top_p": 1.0, + "n": 1, + //"stream": false, + //"logprobs": null, + //"stop": "\n" + }; + + const authHeader = "Bearer "+openAI_api_KEY; + const options = { + headers: {Authorization: authHeader}, + method: 'POST', + contentType: 'application/json', + payload: JSON.stringify(data) + } + let response = UrlFetchApp.fetch(url, options); + let json = JSON.parse(response.getContentText()); + let openAI_response = json["choices"][0]["text"].replace("?\n\n","").replace("?\n","").replace(/?\n/g,""); + + let replyMessage = [{ + "type":"text", + "text": openAI_response + }] + sendMessageToLineBot(channel_access_TOKEN, replyToken, replyMessage); + } + + return ContentService.createTextOutput("Return = Finish"); +} + +function sendMessageToLineBot(accessToken, replyToken, reply_message) { + + let url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); + +} diff --git a/Linebot_openAI_Vision.gs b/Linebot_openAI_Vision.gs new file mode 100644 index 0000000000..fa668c3453 --- /dev/null +++ b/Linebot_openAI_Vision.gs @@ -0,0 +1,236 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2024/8/23 00:00 +https://www.facebook.com/francefu +Line Bot Webhook & Google Apps script & openAI Vision + +若傳訊無回應: +1. openAI api額度已用盡或Key已失效。 +2. 不明原因,可能太久無人使用自動停用,重新佈署或重建Apps script專案並開放存取權限。 +3. Apps script程式碼有bug。 +4. 重新再傳訊一次。 +*/ + +// Line bot +let channel_access_TOKEN = ""; + +// openAI設定 +let openAI_api_key = "sk-proj-xxx-xxx-xxx"; + +// Line bot參數 +let getLinebotData = { + "userId": "", + "eventType": "", + "replyToken": "", + "userType": "", + "userMessage": "", + "userImage": "", + "userMessageId": "", + "quotedMessageId": "" +} + +let scriptProperties = PropertiesService.getScriptProperties(); + +function doPost(e) { + if (e.postData) { + let linebot_response = "請先上傳圖片或輸入圖片網址,再引用圖片或輸入網址回覆並輸入對話內容!"; + let linebot_imageURL = ""; + let chat_message = "請分析圖片中的場景與情境,若有文字資料請將內容進行重點摘要。"; + + let msg = JSON.parse(e.postData.contents); + getLinebotData.userId = msg.events[0].source.userId; + getLinebotData.eventType = msg.events[0].source.type; + getLinebotData.replyToken = msg.events[0].replyToken; + getLinebotData.userType = msg.events[0].message.type; + getLinebotData.userMessageId = msg.events[0].message.id; + + if (getLinebotData.userType=="text") { + getLinebotData.userMessage = msg.events[0].message.text.trim(); + getLinebotData.quotedMessageId = msg.events[0].message.quotedMessageId; + + if (getLinebotData.userMessage.toLowerCase().trim().indexOf("https://")==0) { + let urlData = getLinebotData.userMessage.split("\n"); + getLinebotData.userImage = urlData[0].trim(); + if (urlData.length>1) + chat_message = getLinebotData.userMessage.replace(urlData[0], "").trim(); + linebot_imageURL = urlData[0].trim(); + saveHistoricalURL(getLinebotData.userId, getLinebotData.userMessageId, urlData[0].trim()); + } else if (getLinebotData.quotedMessageId) { + chat_message = getLinebotData.userMessage; + getLinebotData.userImage = getHistoricalURL(getLinebotData.userId, getLinebotData.quotedMessageId); + if (!getLinebotData.userImage) + getLinebotData.userImage = getImageBase64(channel_access_TOKEN, getLinebotData.quotedMessageId); + } else + linebot_response = sendMessageToOpenaiChat(openAI_api_key, getLinebotData.userMessage); + } + else if (getLinebotData.userType=="image") + getLinebotData.userImage = getImageBase64(channel_access_TOKEN, getLinebotData.userMessageId); + + if (getLinebotData.userImage) + linebot_response = sendImageToOpenaiVision(openAI_api_key, chat_message, getLinebotData.userImage); + + sendMessageToLineBot(channel_access_TOKEN, getLinebotData.replyToken, linebot_response, linebot_imageURL); + } + return ContentService.createTextOutput("OK"); +} + +function saveHistoricalURL(userId, messageId, messageURL) { + let list = scriptProperties.getProperty(userId)||"[]"; + list = JSON.parse(list); + if (list.length>=20) + list.splice(0, 1); + message = {}; + message.messageId = messageId; + message.messageURL = messageURL; + list.push(message); + scriptProperties.setProperty(userId, JSON.stringify(list)); +} + +function getHistoricalURL(userId, messageId) { + let list = scriptProperties.getProperty(userId); + if (list) { + list = JSON.parse(list); + for (let i=0;i - - - - #ffffff - - - - - - - #ff0000 - - - - - - - 250 - - - - - - - 250 - - - - - 1 - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - #ff0000 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 500 - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - - - - - - - - - - - 0110011110011111111001100 - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - diff --git a/MatrixLed_20180621/matrixled.js b/MatrixLed_20180621/matrixled.js deleted file mode 100644 index 4cef56d06f..0000000000 --- a/MatrixLed_20180621/matrixled.js +++ /dev/null @@ -1,687 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - const charA = "0111110010100101001001111"; - const charB = "1111110101101011010101010"; - const charC = "0111010001100011000110001"; - const charD = "1111110001100011000101110"; - const charE = "1111110101101011010110101"; - const charF = "1111110100101001010010100"; - const charG = "0111010001101011010110111"; - const charH = "1111100100001000010011111"; - const charI = "1000110001111111000110001"; - const charJ = "1001110001111111000010000"; - const charK = "1111100010001000101010001"; - const charL = "1111100001000010000100001"; - const charM = "1111101000001000100011111"; - const charN = "1111101000001000001011111"; - const charO = "0111010001100011000101110"; - const charP = "1111110010100101001001100"; - const charQ = "0111010001101011001001101"; - const charR = "1111110100101001010001011"; - const charS = "0100110101101011010110010"; - const charT = "1000010000111111000010000"; - const charU = "1111000001000010000111110"; - const charV = "1110000010000010001011100"; - const charW = "1111000001111100000111110"; - const charX = "1000101010001000101010001"; - const charY = "1000001000001110100010000"; - const charZ = "1000110011101011100110001"; - const chara = "0000000110010010011000001"; - const charb = "0000011111001010001000000"; - const charc = "0000000110010010100100000"; - const chard = "0000000010001011111100000"; - const chare = "0000000110010110010100000"; - const charf = "0000000100111111010000000"; - const charg = "0000000101010110011000000"; - const charh = "0000011111001000001100000"; - const chari = "0000000000101110000000000"; - const charj = "0000000001101110000000000"; - const chark = "0000011111000100010100000"; - const charl = "0000000000111110000000000"; - const charm = "0011100100000110010000011"; - const charn = "0000000111001000001100000"; - const charo = "0000000010001010001000000"; - const charp = "0000001111010100010000000"; - const charq = "0000000100010100111100000"; - const charr = "0000000111000100010000000"; - const chars = "0000001001101011001000000"; - const chart = "0000000100011110010100000"; - const charu = "0000000110000010011000001"; - const charv = "0000000110000010011000000"; - const charw = "0011000001001100000100110"; - const charx = "0000000101000100010100000"; - const chary = "0000000101000100010000000"; - const charz = "0000101011011010100000000"; - const char0 = "0000011111100011111100000"; - const char1 = "0000001001111110000100000"; - const char2 = "0000010111101011110100000"; - const char3 = "0000010101101011111100000"; - const char4 = "0000011100001001111100000"; - const char5 = "0000011101101011011100000"; - const char6 = "0000011111101011011100000"; - const char7 = "0000011000100001111100000"; - const char8 = "0000011111101011111100000"; - const char9 = "0000011101101011111100000"; - const comma = "0000000001000100000000000"; - const period = "0000000001000000000000000"; - const questionmark = "0100010000100111010001000"; - const exclamationmark = "0000000000111010000000000"; - const semicolon = "0000000001010100000000000"; - const colon = "0000000000010100000000000"; - const parenthesesleft = "0000001110100010000000000"; - const parenthesesright = "0000000000100010111000000"; - const squarebracketsleft = "0000011111100010000000000"; - const squarebracketsright = "0000000000100011111100000"; - const curlybracketsleft = "0000000100111111000100000"; - const curlybracketsright = "0000010001111110010000000"; - const Quotationmarkssingle = "0000000000110000010000000"; - const Quotationmarksdouble = "1100000100110000010000000"; - const hyphen = "0000000100001000010000000"; - const heart = "0110010010010011001001100"; - const heartfill = "0110011110011111111001100"; - const arrowup = "0010001000111110100000100"; - const arrowdown = "0010000010111110001000100"; - const arrowleft = "0010001110101010010000100"; - const arrowright = "0010000100101010111000100"; - const arrowleftup = "1111011000101001001000001"; - const arrowleftdown = "0111100011001010100110000"; - const arrowrightup = "0000110010101001100011110"; - const arrowrightdown = "1000001001001010001101111"; - const arrowupfill = "0000100111111110011100001"; - const arrowdownfill = "1000011100111111110010000"; - const arrowleftfill = "0010000100011100111011111"; - const arrowrightfill = "1111101110011100010000100"; - const noexist = "0000000000000000000000000"; - - var L = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var MatrixLedcolor = "#ff0000"; - var MatrixLedbackcolor = "#ffffff"; - var MatrixLedwidth = 250; - var MatrixLedheight = 250; - var MatrixLedmarqueecode = ""; - var MatrixLedmarqueetime = 500; - var MatrixLedmarqueereverse = 1; - var MatrixLedshowstate = 1; - var marqueetimeid; - - function MatrixLed_color(input_color_) { - MatrixLedcolor = input_color_; - } - - function MatrixLed_width(input_width_) { - MatrixLedwidth = input_width_; - } - - function MatrixLed_height(input_height_) { - MatrixLedheight = input_height_; - } - - function MatrixLed_showstate(input_showstate_) { - MatrixLedshowstate = input_showstate_; - MatrixLed_show(); - } - - function MatrixLed_indentcode(input_indentcode_) { - var indentcode = input_indentcode_; - while (indentcode.search(/0000000000/)!=-1) - indentcode = indentcode.replace(/0000000000/g,"00000"); - return indentcode; - } - - function MatrixLed_marquee(input_marquee_) { - if ((input_marquee_.length==25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLed_matrix(input_marquee_); - return; - } - else if ((input_marquee_.length%5==0)&&(input_marquee_.length>25)&&(input_marquee_.search(/[^0-1]/)==-1)) - MatrixLedmarqueecode = input_marquee_; - else if (input_marquee_.length==1) - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - } - - function MatrixLed_marquee_time(input_time_) { - MatrixLedmarqueetime = input_time_; - } - - function MatrixLed_marquee_stop() { - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_resume() { - window.clearInterval(marqueetimeid); - marqueetimeid = window.setInterval("MatrixLed_marquee_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_reverse() { - if (MatrixLedmarqueereverse==1) - MatrixLedmarqueereverse=2; - else if (MatrixLedmarqueereverse==2) - MatrixLedmarqueereverse=1; - } - - function MatrixLed_char(input_char_) { - if (input_char_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_char_)); - } - } - - function MatrixLed_texttocode(input_text_) { - if (input_text_.length>0) - { - var textcode=""; - for (var i=0;i" - + "" - + "" - + "" - + "" - + "" - + ""; - else - var ledtable ="" - + "" - + "" - + "" - + "" - + "" - + "
"; - - if (document.getElementById("fustyles_matrixled")) - { - document.getElementById("fustyles_matrixled").innerHTML = ledtable; - } - else - { - var div = document.createElement('div'); - div.id = "fustyles_matrixled"; - div.innerHTML = ledtable; - document.body.appendChild(div); - } - } - - function MatrixLed_conversion(input_char_) { - if (input_char_=="A") - return charA; - else if (input_char_=="B") - return charB; - else if (input_char_=="C") - return charC; - else if (input_char_=="D") - return charD; - else if (input_char_=="E") - return charE; - else if (input_char_=="F") - return charF; - else if (input_char_=="G") - return charG; - else if (input_char_=="H") - return charH; - else if (input_char_=="I") - return charI; - else if (input_char_=="J") - return charJ; - else if (input_char_=="K") - return charK; - else if (input_char_=="L") - return charL; - else if (input_char_=="M") - return charM; - else if (input_char_=="N") - return charN; - else if (input_char_=="O") - return charO; - else if (input_char_=="P") - return charP; - else if (input_char_=="Q") - return charQ; - else if (input_char_=="R") - return charR; - else if (input_char_=="S") - return charS; - else if (input_char_=="T") - return charT; - else if (input_char_=="U") - return charU; - else if (input_char_=="V") - return charV; - else if (input_char_=="W") - return charW; - else if (input_char_=="X") - return charX; - else if (input_char_=="Y") - return charY; - else if (input_char_=="Z") - return charZ; - else if (input_char_=="a") - return chara; - else if (input_char_=="b") - return charb; - else if (input_char_=="c") - return charc; - else if (input_char_=="d") - return chard; - else if (input_char_=="e") - return chare; - else if (input_char_=="f") - return charf; - else if (input_char_=="g") - return charg; - else if (input_char_=="h") - return charh; - else if (input_char_=="i") - return chari; - else if (input_char_=="j") - return charj; - else if (input_char_=="k") - return chark; - else if (input_char_=="l") - return charl; - else if (input_char_=="m") - return charm; - else if (input_char_=="n") - return charn; - else if (input_char_=="o") - return charo; - else if (input_char_=="p") - return charp; - else if (input_char_=="q") - return charq; - else if (input_char_=="r") - return charr; - else if (input_char_=="s") - return chars; - else if (input_char_=="t") - return chart; - else if (input_char_=="u") - return charu; - else if (input_char_=="v") - return charv; - else if (input_char_=="w") - return charw; - else if (input_char_=="x") - return charx; - else if (input_char_=="y") - return chary; - else if (input_char_=="z") - return charz; - else if (input_char_=="0") - return char0; - else if (input_char_=="1") - return char1; - else if (input_char_=="2") - return char2; - else if (input_char_=="3") - return char3; - else if (input_char_=="4") - return char4; - else if (input_char_=="5") - return char5; - else if (input_char_=="6") - return char6; - else if (input_char_=="7") - return char7; - else if (input_char_=="8") - return char8; - else if (input_char_=="9") - return char9; - else if (input_char_==",") - return comma; - else if (input_char_==".") - return period; - else if (input_char_=="?") - return questionmark; - else if (input_char_=="!") - return exclamationmark; - else if (input_char_==";") - return semicolon; - else if (input_char_==":") - return colon; - else if (input_char_=="(") - return parenthesesleft; - else if (input_char_==")") - return parenthesesright; - else if (input_char_=="[") - return squarebracketsleft; - else if (input_char_=="]") - return squarebracketsright; - else if (input_char_=="{") - return curlybracketsleft; - else if (input_char_=="}") - return curlybracketsright; - else if (input_char_=="'") - return Quotationmarkssingle; - else if (input_char_=="\"") - return Quotationmarksdouble; - else if (input_char_=="♡") - return heart; - else if (input_char_=="♥") - return heartfill; - else if (input_char_=="↑") - return arrowup; - else if (input_char_=="↓") - return arrowdown; - else if (input_char_=="←") - return arrowleft; - else if (input_char_=="→") - return arrowright; - else if (input_char_=="↖") - return arrowleftup; - else if (input_char_=="↙") - return arrowleftdown; - else if (input_char_=="↗") - return arrowrightup; - else if (input_char_=="↘") - return arrowrightdown; - else if (input_char_=="▲") - return arrowupfill; - else if (input_char_=="▼") - return arrowdownfill; - else if (input_char_=="◄") - return arrowleftfill; - else if (input_char_=="►") - return arrowrightfill; - else - return noexist; - } - - function MatrixLed_barchart(value1,value2,value3,value4,value5){ - var input_value=[value1,value2,value3,value4,value5]; - var k=0; - for (var i=0;i<=4;i++) - { - for (var J=0;J<=4;J++) - { - if (J>=(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function Matrixled_clockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_counterclockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_verticalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[j+5*i]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_horizontalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[j+i*5]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_invert(){ - for (var i=0;i<25;i++) - { - if ((L[i]=="")||(L[i]==MatrixLedbackcolor)) - L[i]=MatrixLedcolor; - else - L[i]=MatrixLedbackcolor; - } - MatrixLed_show(); - } - - function MatrixLed_getcolor(input_x_,input_y_) { - return L[input_x_*5+input_y_]; - } - - function MatrixLed_backcolor(input_color_) { - MatrixLedbackcolor=input_color_; - } - - window.MatrixLed_clear = MatrixLed_clear; - window.MatrixLed_matrix = MatrixLed_matrix; - window.MatrixLed_matrix_color = MatrixLed_matrix_color; - window.MatrixLed_show = MatrixLed_show; - window.MatrixLed_on = MatrixLed_on; - window.MatrixLed_color_on = MatrixLed_color_on; - window.MatrixLed_off = MatrixLed_off; - window.MatrixLed_reverse = MatrixLed_reverse; - window.MatrixLed_state = MatrixLed_state; - window.MatrixLed_color = MatrixLed_color; - window.MatrixLed_width = MatrixLed_width; - window.MatrixLed_height = MatrixLed_height; - window.MatrixLed_sample = MatrixLed_sample; - window.MatrixLed_code = MatrixLed_code; - window.MatrixLed_marquee = MatrixLed_marquee; - window.MatrixLed_marquee_play = MatrixLed_marquee_play; - window.MatrixLed_marquee_stop = MatrixLed_marquee_stop; - window.MatrixLed_marquee_resume = MatrixLed_marquee_resume; - window.MatrixLed_marquee_reverse = MatrixLed_marquee_reverse; - window.MatrixLed_marquee_time = MatrixLed_marquee_time; - window.MatrixLed_char = MatrixLed_char; - window.MatrixLed_conversion = MatrixLed_conversion; - window.MatrixLed_texttocode = MatrixLed_texttocode; - window.MatrixLed_showstate = MatrixLed_showstate; - window.MatrixLed_indentcode = MatrixLed_indentcode; - window.MatrixLed_barchart = MatrixLed_barchart; - window.Matrixled_clockwise = Matrixled_clockwise; - window.Matrixled_counterclockwise = Matrixled_counterclockwise; - window.Matrixled_verticalflip = Matrixled_verticalflip; - window.Matrixled_horizontalflip = Matrixled_horizontalflip; - window.Matrixled_invert = Matrixled_invert; - window.MatrixLed_getcolor = MatrixLed_getcolor; - window.MatrixLed_backcolor = MatrixLed_backcolor; - -}(window, window.document)); diff --git a/MatrixLed_20180627/blockly.json b/MatrixLed_20180627/blockly.json deleted file mode 100644 index 58c45ded35..0000000000 --- a/MatrixLed_20180627/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["matrix_led_backcolor","matrix_led_verticalflip","matrix_led_horizontalflip","matrix_led_invert","matrix_led_getcolor","matrix_led_color","matrix_led_width","matrix_led_height","matrix_led_code","matrix_led_texttocode","matrix_led_indentcode","matrix_led_showstate","matrix_led_sample","matrix_led_matrix","matrix_led_matrix_color","matrix_led_matrixcode","matrix_led_clear","matrix_led_on","matrix_led_color_on","matrix_led_off","matrix_led_reverse","matrix_led_state","matrix_led_marquee","matrix_led_marquee_time","matrix_led_marquee_stop","matrix_led_marquee_reverse","matrix_led_marquee_resume","matrix_led_char","matrix_led_linechart","matrix_led_barchart","matrix_led_clockwise","matrix_led_counterclockwise"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "matrixled.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/MatrixLed_20180627/blockly/blocks.js b/MatrixLed_20180627/blockly/blocks.js deleted file mode 100644 index 9ff6c35b73..0000000000 --- a/MatrixLed_20180627/blockly/blocks.js +++ /dev/null @@ -1,566 +0,0 @@ -Blockly.Blocks['matrix_led_char'] = { - init: function() { - this.appendValueInput("value_char_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_CHAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - - -Blockly.Blocks['matrix_led_texttocode'] = { - init: function() { - this.appendValueInput("value_text_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_indentcode'] = { - init: function() { - this.appendValueInput("value_indentcode_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_INDENTCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_showstate'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW) - .appendField(new Blockly.FieldDropdown([["on","1"], ["off","0"]]), "value_showstate_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_stop'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_resume'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_time'] = { - init: function() { - this.appendValueInput("value_marquee_time_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_sample'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SAMPLE_SHOW) - .appendField(new Blockly.FieldDropdown([["♥","♥"], ["♡","♡"], ["↑","↑"], ["↓","↓"], ["←","←"], ["→","→"], ["↖","↖"], ["↙","↙"], ["↗","↗"], ["↘","↘"], ["▲","▲"], ["▼","▼"], ["◄","◄"], ["►","►"], ["O","O"], ["X","X"], ["V","V"]]), "value_sample_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setTooltip(''); - this.setColour(300); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_code'] = { - init: function() { - this.appendValueInput("value_code_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_CODE_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_width'] = { - init: function() { - this.appendValueInput("value_width_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_WIDTH_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_height'] = { - init: function() { - this.appendValueInput("value_height_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_HEIGHT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L01') - .appendField(new Blockly.FieldColour("#ffffff"), 'L06') - .appendField(new Blockly.FieldColour("#ffffff"), 'L11') - .appendField(new Blockly.FieldColour("#ffffff"), 'L16') - .appendField(new Blockly.FieldColour("#ffffff"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L02') - .appendField(new Blockly.FieldColour("#ffffff"), 'L07') - .appendField(new Blockly.FieldColour("#ffffff"), 'L12') - .appendField(new Blockly.FieldColour("#ffffff"), 'L17') - .appendField(new Blockly.FieldColour("#ffffff"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L03') - .appendField(new Blockly.FieldColour("#ffffff"), 'L08') - .appendField(new Blockly.FieldColour("#ffffff"), 'L13') - .appendField(new Blockly.FieldColour("#ffffff"), 'L18') - .appendField(new Blockly.FieldColour("#ffffff"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L04') - .appendField(new Blockly.FieldColour("#ffffff"), 'L09') - .appendField(new Blockly.FieldColour("#ffffff"), 'L14') - .appendField(new Blockly.FieldColour("#ffffff"), 'L19') - .appendField(new Blockly.FieldColour("#ffffff"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L05') - .appendField(new Blockly.FieldColour("#ffffff"), 'L10') - .appendField(new Blockly.FieldColour("#ffffff"), 'L15') - .appendField(new Blockly.FieldColour("#ffffff"), 'L20') - .appendField(new Blockly.FieldColour("#ffffff"), 'L25') - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; -Blockly.Blocks['matrix_led_matrixcode'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_clear'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLEAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COLOR_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.appendValueInput("value_color_on_") - .setCheck("Colour") - .appendField("color"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_off'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_OFF_SHOW); - this.appendValueInput("value_x_off_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_off_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_REVERSE_SHOW); - this.appendValueInput("value_x_reverse_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_reverse_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_state'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_STATE_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_linechart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_LINECHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_barchart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_BARCHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_clockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_counterclockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_verticalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_horizontalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_invert'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_INVERT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_getcolor'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_GETCOLOR_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_backcolor'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/MatrixLed_20180627/blockly/javascript.js b/MatrixLed_20180627/blockly/javascript.js deleted file mode 100644 index 65d9c0cd3e..0000000000 --- a/MatrixLed_20180627/blockly/javascript.js +++ /dev/null @@ -1,269 +0,0 @@ -Blockly.JavaScript['matrix_led_char'] = function(block) { - var value_char_ = Blockly.JavaScript.valueToCode(block, 'value_char_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_char('+ value_char_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_time'] = function(block) { - var value_marquee_time_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_time_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_time('+ value_marquee_time_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee('+ value_marquee_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_stop'] = function(block) { - var code = 'MatrixLed_marquee_stop();'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_resume'] = function(block) { - var code = 'MatrixLed_marquee_resume();'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_reverse'] = function(block) { - var code = 'MatrixLed_marquee_reverse();'; - return code; -}; - -Blockly.JavaScript['matrix_led_color'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color('+ value_color_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_texttocode'] = function(block) { - var value_text_ = Blockly.JavaScript.valueToCode(block, 'value_text_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_texttocode('+value_text_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_width'] = function(block) { - var value_width_ = Blockly.JavaScript.valueToCode(block, 'value_width_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_width('+ value_width_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_height'] = function(block) { - var value_height_ = Blockly.JavaScript.valueToCode(block, 'value_height_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_height('+ value_height_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_sample'] = function(block) { - var value_sample_ = block.getFieldValue('value_sample_'); - var code = 'MatrixLed_sample("'+ value_sample_ +'");'; - return code; -}; - -Blockly.JavaScript['matrix_led_code'] = function(block) { - var value_code_ = Blockly.JavaScript.valueToCode(block, 'value_code_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_code('+ value_code_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = 'MatrixLed_matrix("'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'");'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = 'MatrixLed_matrix_color("'+L01+'","'+L02+'","'+L03+'","'+L04+'","'+L05+'","'+L06+'","'+L07+'","'+L08+'","'+L09+'","'+L10+'","'+L11+'","'+L12+'","'+L13+'","'+L14+'","'+L15+'","'+L16+'","'+L17+'","'+L18+'","'+L19+'","'+L20+'","'+L21+'","'+L22+'","'+L23+'","'+L24+'","'+L25+'");'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrixcode'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_clear'] = function(block) { - var code = 'MatrixLed_clear();'; - return code; -}; - -Blockly.JavaScript['matrix_led_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_on('+value_x_on_+','+value_y_on_+');'; - return code; -}; - -Blockly.JavaScript['matrix_led_color_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_on_ = Blockly.JavaScript.valueToCode(block, 'value_color_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color_on('+value_x_on_+','+value_y_on_+','+value_color_on_+');'; - return code; -}; - -Blockly.JavaScript['matrix_led_off'] = function(block) { - var value_x_off_ = Blockly.JavaScript.valueToCode(block, 'value_x_off_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_off_ = Blockly.JavaScript.valueToCode(block, 'value_y_off_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_off('+value_x_off_+','+value_y_off_+');'; - return code; -}; - -Blockly.JavaScript['matrix_led_reverse'] = function(block) { - var value_x_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_x_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_y_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_reverse('+value_x_reverse_+','+value_y_reverse_+');'; - return code; -}; - -Blockly.JavaScript['matrix_led_state'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_state('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_showstate'] = function(block) { - var value_showstate_ = block.getFieldValue('value_showstate_'); - var code = 'MatrixLed_showstate('+value_showstate_+');'; - return code; -}; - -Blockly.JavaScript['matrix_led_indentcode'] = function(block) { - var value_indentcode_ = Blockly.JavaScript.valueToCode(block, 'value_indentcode_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_indentcode('+value_indentcode_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_linechart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_linechart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');'; - return code; -}; - -Blockly.JavaScript['matrix_led_barchart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_barchart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');'; - return code; -}; - -Blockly.JavaScript['matrix_led_clockwise'] = function(block) { - var code = 'Matrixled_clockwise();'; - return code; -}; - -Blockly.JavaScript['matrix_led_counterclockwise'] = function(block) { - var code = 'Matrixled_counterclockwise();'; - return code; -}; - -Blockly.JavaScript['matrix_led_verticalflip'] = function(block) { - var code = 'Matrixled_verticalflip();'; - return code; -}; - -Blockly.JavaScript['matrix_led_horizontalflip'] = function(block) { - var code = 'Matrixled_horizontalflip();'; - return code; -}; - -Blockly.JavaScript['matrix_led_invert'] = function(block) { - var code = 'Matrixled_invert();'; - return code; -}; - -Blockly.JavaScript['matrix_led_getcolor'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_getcolor('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_backcolor'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_backcolor('+ value_color_ +');'; - return code; -}; diff --git a/MatrixLed_20180627/blockly/msg/blocks/en.js b/MatrixLed_20180627/blockly/msg/blocks/en.js deleted file mode 100644 index 329cf66817..0000000000 --- a/MatrixLed_20180627/blockly/msg/blocks/en.js +++ /dev/null @@ -1,36 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "SHOW MATRIX LED"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "SHOW MATRIX LED"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "CLEAR SCREEN"; -Blockly.Msg.MATRIXLED_ON_SHOW = "TURN ON"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "TURN ON"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "TURN OFF"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "SWITCH"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "GET LED STATE"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "LED COLOR"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "SCREEN WIDTH"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "SCREEN HEIGHT"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "SHOW SAMPLE"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "SHOW SAMPLE BY CODE"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "SHOW MARQUEE"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "STOP MARQUEE"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "RESUME MARQUEE"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "MARQUEE TIME (ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "MARQUEE REVERSE"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "SHOW CHARACTER"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "CONVERT TEXT TO CODE"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "SHOW SCREEN"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "INDENT CODE"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "LINE CHART "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "BAR CHART "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "VALUE1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "VALUE2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "VALUE3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "VALUE4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "VALUE5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "Rotate 90 degrees clockwise"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "Rotate 90 degrees counter clockwise"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "VERTICAL FLIP"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "HORIZONTAL FLIP"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "INVERT"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "GET COLOR CODE"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "BACK COLOR"; diff --git a/MatrixLed_20180627/blockly/msg/blocks/zh-hans.js b/MatrixLed_20180627/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 2c63c772e7..0000000000 --- a/MatrixLed_20180627/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,36 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示灯 显示"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示灯 显示"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示灯 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗灯"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示灯 开关切换"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示灯 状态"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "灯光颜色"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "指示灯 宽度"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "指示灯 高度"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "显示 图案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "显示 图案(编码)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑马灯(英数) 显示"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑马灯 暂停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑马灯 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑马灯 间隔时间(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑马灯 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "显示 字元(英数)"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "转换文字为编码"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示灯 显示"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "缩排编码"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折线图 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "长条图 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "数值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "数值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "数值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "数值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "数值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示灯 顺时钟旋转90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示灯 逆时钟旋转90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示灯 垂直翻转"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示灯 水平翻转"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示灯 反转"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "灯光色码值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示灯 背景颜色"; diff --git a/MatrixLed_20180627/blockly/msg/blocks/zh-hant.js b/MatrixLed_20180627/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index f820033d6e..0000000000 --- a/MatrixLed_20180627/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,36 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示燈 顯示"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示燈 顯示"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示燈 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗燈"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示燈 開關切換"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示燈 狀態"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "燈光顏色"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "指示燈 寬度"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "指示燈 高度"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "顯示 圖案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "顯示 圖案(編碼)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑馬燈(英數) 顯示"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑馬燈 暫停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑馬燈 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑馬燈 間隔時間(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑馬燈 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "顯示 字元(英數)"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "轉換文字為編碼"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示燈 顯示"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "縮排編碼"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折線圖 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "長條圖 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "數值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "數值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "數值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "數值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "數值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示燈 順時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示燈 逆時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示燈 垂直翻轉"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示燈 水平翻轉"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示燈 反轉"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "燈光色碼值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示燈 背景顏色"; diff --git a/MatrixLed_20180627/blockly/msg/en.js b/MatrixLed_20180627/blockly/msg/en.js deleted file mode 100644 index 2881fb018f..0000000000 --- a/MatrixLed_20180627/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "Simulation Indicator Light"; diff --git a/MatrixLed_20180627/blockly/msg/zh-hans.js b/MatrixLed_20180627/blockly/msg/zh-hans.js deleted file mode 100644 index 774b699179..0000000000 --- a/MatrixLed_20180627/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "模拟指示灯"; diff --git a/MatrixLed_20180627/blockly/msg/zh-hant.js b/MatrixLed_20180627/blockly/msg/zh-hant.js deleted file mode 100644 index 8e299c4a7c..0000000000 --- a/MatrixLed_20180627/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "模擬指示燈"; diff --git a/MatrixLed_20180627/blockly/toolbox.xml b/MatrixLed_20180627/blockly/toolbox.xml deleted file mode 100644 index e2e003d817..0000000000 --- a/MatrixLed_20180627/blockly/toolbox.xml +++ /dev/null @@ -1,303 +0,0 @@ - - - - - #ffffff - - - - - - - #ff0000 - - - - - - - 250 - - - - - - - 250 - - - - - 1 - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - #ff0000 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 500 - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - - - - - - - - - - - 0110011110011111111001100 - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - diff --git a/MatrixLed_20180627/matrixled.js b/MatrixLed_20180627/matrixled.js deleted file mode 100644 index 474bebedd8..0000000000 --- a/MatrixLed_20180627/matrixled.js +++ /dev/null @@ -1,597 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - const charA = "0111110010100101001001111"; - const charB = "1111110101101011010101010"; - const charC = "0111010001100011000110001"; - const charD = "1111110001100011000101110"; - const charE = "1111110101101011010110101"; - const charF = "1111110100101001010010100"; - const charG = "0111010001101011010110111"; - const charH = "1111100100001000010011111"; - const charI = "1000110001111111000110001"; - const charJ = "1001110001111111000010000"; - const charK = "1111100010001000101010001"; - const charL = "1111100001000010000100001"; - const charM = "1111101000001000100011111"; - const charN = "1111101000001000001011111"; - const charO = "0111010001100011000101110"; - const charP = "1111110010100101001001100"; - const charQ = "0111010001101011001001101"; - const charR = "1111110100101001010001011"; - const charS = "0100110101101011010110010"; - const charT = "1000010000111111000010000"; - const charU = "1111000001000010000111110"; - const charV = "1110000010000010001011100"; - const charW = "1111000001111100000111110"; - const charX = "1000101010001000101010001"; - const charY = "1000001000001110100010000"; - const charZ = "1000110011101011100110001"; - const chara = "0000000110010010011000001"; - const charb = "0000011111001010001000000"; - const charc = "0000000110010010100100000"; - const chard = "0000000010001011111100000"; - const chare = "0000000110010110010100000"; - const charf = "0000000100111111010000000"; - const charg = "0000000101010110011000000"; - const charh = "0000011111001000001100000"; - const chari = "0000000000101110000000000"; - const charj = "0000000001101110000000000"; - const chark = "0000011111000100010100000"; - const charl = "0000000000111110000000000"; - const charm = "0011100100000110010000011"; - const charn = "0000000111001000001100000"; - const charo = "0000000010001010001000000"; - const charp = "0000001111010100010000000"; - const charq = "0000000100010100111100000"; - const charr = "0000000111000100010000000"; - const chars = "0000001001101011001000000"; - const chart = "0000000100011110010100000"; - const charu = "0000000110000010011000001"; - const charv = "0000000110000010011000000"; - const charw = "0011000001001100000100110"; - const charx = "0000000101000100010100000"; - const chary = "0000000101000100010000000"; - const charz = "0000101011011010100000000"; - const char0 = "0000011111100011111100000"; - const char1 = "0000001001111110000100000"; - const char2 = "0000010111101011110100000"; - const char3 = "0000010101101011111100000"; - const char4 = "0000011100001001111100000"; - const char5 = "0000011101101011011100000"; - const char6 = "0000011111101011011100000"; - const char7 = "0000011000100001111100000"; - const char8 = "0000011111101011111100000"; - const char9 = "0000011101101011111100000"; - const comma = "0000000001000100000000000"; - const period = "0000000001000000000000000"; - const questionmark = "0100010000100111010001000"; - const exclamationmark = "0000000000111010000000000"; - const semicolon = "0000000001010100000000000"; - const colon = "0000000000010100000000000"; - const parenthesesleft = "0000001110100010000000000"; - const parenthesesright = "0000000000100010111000000"; - const squarebracketsleft = "0000011111100010000000000"; - const squarebracketsright = "0000000000100011111100000"; - const curlybracketsleft = "0000000100111111000100000"; - const curlybracketsright = "0000010001111110010000000"; - const Quotationmarkssingle = "0000000000110000010000000"; - const Quotationmarksdouble = "1100000100110000010000000"; - const hyphen = "0000000100001000010000000"; - const heart = "0110010010010011001001100"; - const heartfill = "0110011110011111111001100"; - const arrowup = "0010001000111110100000100"; - const arrowdown = "0010000010111110001000100"; - const arrowleft = "0010001110101010010000100"; - const arrowright = "0010000100101010111000100"; - const arrowleftup = "1111011000101001001000001"; - const arrowleftdown = "0111100011001010100110000"; - const arrowrightup = "0000110010101001100011110"; - const arrowrightdown = "1000001001001010001101111"; - const arrowupfill = "0000100111111110011100001"; - const arrowdownfill = "1000011100111111110010000"; - const arrowleftfill = "0010000100011100111011111"; - const arrowrightfill = "1111101110011100010000100"; - const noexist = "0000000000000000000000000"; - - var L = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var MatrixLedcolor = "#ff0000"; - var MatrixLedbackcolor = "#ffffff"; - var MatrixLedwidth = 250; - var MatrixLedheight = 250; - var MatrixLedmarqueecode = ""; - var MatrixLedmarqueetime = 500; - var MatrixLedmarqueereverse = 1; - var MatrixLedshowstate = 1; - var marqueetimeid; - - function MatrixLed_color(input_color_) { - MatrixLedcolor = input_color_; - } - - function MatrixLed_width(input_width_) { - MatrixLedwidth = input_width_; - } - - function MatrixLed_height(input_height_) { - MatrixLedheight = input_height_; - } - - function MatrixLed_showstate(input_showstate_) { - MatrixLedshowstate = input_showstate_; - MatrixLed_show(); - } - - function MatrixLed_indentcode(input_indentcode_) { - var indentcode = input_indentcode_; - while (indentcode.search(/0000000000/)!=-1) - indentcode = indentcode.replace(/0000000000/g,"00000"); - return indentcode; - } - - function MatrixLed_marquee(input_marquee_) { - if ((input_marquee_.length==25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLed_matrix(input_marquee_); - return; - } - else if ((input_marquee_.length%5==0)&&(input_marquee_.length>25)&&(input_marquee_.search(/[^0-1]/)==-1)) - MatrixLedmarqueecode = input_marquee_; - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - } - - function MatrixLed_marquee_time(input_time_) { - MatrixLedmarqueetime = input_time_; - } - - function MatrixLed_marquee_stop() { - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_resume() { - window.clearInterval(marqueetimeid); - marqueetimeid = window.setInterval("MatrixLed_marquee_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_reverse() { - if (MatrixLedmarqueereverse==1) - MatrixLedmarqueereverse=2; - else if (MatrixLedmarqueereverse==2) - MatrixLedmarqueereverse=1; - } - - function MatrixLed_char(input_char_) { - if (input_char_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_char_)); - } - } - - function MatrixLed_texttocode(input_text_) { - if (input_text_.length>0) - { - var textcode=""; - for (var i=0;i" - + "" - + "" - + "" - + "" - + "" - + ""; - else - var ledtable ="" - + "" - + "" - + "" - + "" - + "" - + "
"; - - if (document.getElementById("fustyles_matrixled")) - { - document.getElementById("fustyles_matrixled").innerHTML = ledtable; - } - else - { - var div = document.createElement('div'); - div.id = "fustyles_matrixled"; - div.innerHTML = ledtable; - document.body.appendChild(div); - } - } - - function MatrixLed_conversion(input_char_) { - if (input_char_=="A") return charA; - else if (input_char_=="B") return charB; - else if (input_char_=="C") return charC; - else if (input_char_=="D") return charD; - else if (input_char_=="E") return charE; - else if (input_char_=="F") return charF; - else if (input_char_=="G") return charG; - else if (input_char_=="H") return charH; - else if (input_char_=="I") return charI; - else if (input_char_=="J") return charJ; - else if (input_char_=="K") return charK; - else if (input_char_=="L") return charL; - else if (input_char_=="M") return charM; - else if (input_char_=="N") return charN; - else if (input_char_=="O") return charO; - else if (input_char_=="P") return charP; - else if (input_char_=="Q") return charQ; - else if (input_char_=="R") return charR; - else if (input_char_=="S") return charS; - else if (input_char_=="T") return charT; - else if (input_char_=="U") return charU; - else if (input_char_=="V") return charV; - else if (input_char_=="W") return charW; - else if (input_char_=="X") return charX; - else if (input_char_=="Y") return charY; - else if (input_char_=="Z") return charZ; - else if (input_char_=="a") return chara; - else if (input_char_=="b") return charb; - else if (input_char_=="c") return charc; - else if (input_char_=="d") return chard; - else if (input_char_=="e") return chare; - else if (input_char_=="f") return charf; - else if (input_char_=="g") return charg; - else if (input_char_=="h") return charh; - else if (input_char_=="i") return chari; - else if (input_char_=="j") return charj; - else if (input_char_=="k") return chark; - else if (input_char_=="l") return charl; - else if (input_char_=="m") return charm; - else if (input_char_=="n") return charn; - else if (input_char_=="o") return charo; - else if (input_char_=="p") return charp; - else if (input_char_=="q") return charq; - else if (input_char_=="r") return charr; - else if (input_char_=="s") return chars; - else if (input_char_=="t") return chart; - else if (input_char_=="u") return charu; - else if (input_char_=="v") return charv; - else if (input_char_=="w") return charw; - else if (input_char_=="x") return charx; - else if (input_char_=="y") return chary; - else if (input_char_=="z") return charz; - else if (input_char_=="0") return char0; - else if (input_char_=="1") return char1; - else if (input_char_=="2") return char2; - else if (input_char_=="3") return char3; - else if (input_char_=="4") return char4; - else if (input_char_=="5") return char5; - else if (input_char_=="6") return char6; - else if (input_char_=="7") return char7; - else if (input_char_=="8") return char8; - else if (input_char_=="9") return char9; - else if (input_char_==",") return comma; - else if (input_char_==".") return period; - else if (input_char_=="?") return questionmark; - else if (input_char_=="!") return exclamationmark; - else if (input_char_==";") return semicolon; - else if (input_char_==":") return colon; - else if (input_char_=="(") return parenthesesleft; - else if (input_char_==")") return parenthesesright; - else if (input_char_=="[") return squarebracketsleft; - else if (input_char_=="]") return squarebracketsright; - else if (input_char_=="{") return curlybracketsleft; - else if (input_char_=="}") return curlybracketsright; - else if (input_char_=="'") return Quotationmarkssingle; - else if (input_char_=="\"") return Quotationmarksdouble; - else if (input_char_=="♡") return heart; - else if (input_char_=="♥") return heartfill; - else if (input_char_=="↑") return arrowup; - else if (input_char_=="↓") return arrowdown; - else if (input_char_=="←") return arrowleft; - else if (input_char_=="→") return arrowright; - else if (input_char_=="↖") return arrowleftup; - else if (input_char_=="↙") return arrowleftdown; - else if (input_char_=="↗") return arrowrightup; - else if (input_char_=="↘") return arrowrightdown; - else if (input_char_=="▲") return arrowupfill; - else if (input_char_=="▼") return arrowdownfill; - else if (input_char_=="◄") return arrowleftfill; - else if (input_char_=="►") return arrowrightfill; - else return noexist; - } - - function MatrixLed_linechart(value1,value2,value3,value4,value5){ - var input_value=[value1,value2,value3,value4,value5]; - var k=0; - for (var i=0;i<=4;i++) - { - for (var j=0;j<=4;j++) - { - if (j==(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function MatrixLed_barchart(value1,value2,value3,value4,value5){ - var input_value=[value1,value2,value3,value4,value5]; - var k=0; - for (var i=0;i<=4;i++) - { - for (var j=0;j<=4;j++) - { - if (j>=(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function Matrixled_clockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_counterclockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_verticalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[j+5*i]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_horizontalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[j+i*5]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_invert(){ - for (var i=0;i<25;i++) - { - if ((L[i]=="")||(L[i]==MatrixLedbackcolor)) - L[i]=MatrixLedcolor; - else - L[i]=MatrixLedbackcolor; - } - MatrixLed_show(); - } - - function MatrixLed_getcolor(input_x_,input_y_) { - return L[input_x_*5+input_y_]; - } - - function MatrixLed_backcolor(input_color_) { - MatrixLedbackcolor=input_color_; - } - - window.MatrixLed_clear = MatrixLed_clear; - window.MatrixLed_matrix = MatrixLed_matrix; - window.MatrixLed_matrix_color = MatrixLed_matrix_color; - window.MatrixLed_show = MatrixLed_show; - window.MatrixLed_on = MatrixLed_on; - window.MatrixLed_color_on = MatrixLed_color_on; - window.MatrixLed_off = MatrixLed_off; - window.MatrixLed_reverse = MatrixLed_reverse; - window.MatrixLed_state = MatrixLed_state; - window.MatrixLed_color = MatrixLed_color; - window.MatrixLed_width = MatrixLed_width; - window.MatrixLed_height = MatrixLed_height; - window.MatrixLed_sample = MatrixLed_sample; - window.MatrixLed_code = MatrixLed_code; - window.MatrixLed_marquee = MatrixLed_marquee; - window.MatrixLed_marquee_play = MatrixLed_marquee_play; - window.MatrixLed_marquee_stop = MatrixLed_marquee_stop; - window.MatrixLed_marquee_resume = MatrixLed_marquee_resume; - window.MatrixLed_marquee_reverse = MatrixLed_marquee_reverse; - window.MatrixLed_marquee_time = MatrixLed_marquee_time; - window.MatrixLed_char = MatrixLed_char; - window.MatrixLed_conversion = MatrixLed_conversion; - window.MatrixLed_texttocode = MatrixLed_texttocode; - window.MatrixLed_showstate = MatrixLed_showstate; - window.MatrixLed_indentcode = MatrixLed_indentcode; - window.MatrixLed_linechart = MatrixLed_linechart; - window.MatrixLed_barchart = MatrixLed_barchart; - window.Matrixled_clockwise = Matrixled_clockwise; - window.Matrixled_counterclockwise = Matrixled_counterclockwise; - window.Matrixled_verticalflip = Matrixled_verticalflip; - window.Matrixled_horizontalflip = Matrixled_horizontalflip; - window.Matrixled_invert = Matrixled_invert; - window.MatrixLed_getcolor = MatrixLed_getcolor; - window.MatrixLed_backcolor = MatrixLed_backcolor; - -}(window, window.document)); diff --git a/MatrixLed_20180720/blockly.json b/MatrixLed_20180720/blockly.json deleted file mode 100644 index 455a4fda60..0000000000 --- a/MatrixLed_20180720/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["matrix_led_backcolor","matrix_led_verticalflip","matrix_led_horizontalflip","matrix_led_invert","matrix_led_getcolor","matrix_led_color","matrix_led_width","matrix_led_height","matrix_led_code","matrix_led_texttocode","matrix_led_indentcode","matrix_led_showstate","matrix_led_sample","matrix_led_matrix","matrix_led_matrix_color","matrix_led_matrixcode","matrix_led_clear","matrix_led_on","matrix_led_color_on","matrix_led_off","matrix_led_reverse","matrix_led_state","matrix_led_marquee","matrix_led_marquee_once","matrix_led_marquee_degree","matrix_led_marquee_time","matrix_led_marquee_stop","matrix_led_marquee_reverse","matrix_led_marquee_resume","matrix_led_char","matrix_led_linechart","matrix_led_barchart","matrix_led_clockwise","matrix_led_counterclockwise"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "matrixled.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/MatrixLed_20180720/blockly/blocks.js b/MatrixLed_20180720/blockly/blocks.js deleted file mode 100644 index 3b8ddbdcfb..0000000000 --- a/MatrixLed_20180720/blockly/blocks.js +++ /dev/null @@ -1,594 +0,0 @@ -Blockly.Blocks['matrix_led_char'] = { - init: function() { - this.appendValueInput("value_char_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_CHAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - - -Blockly.Blocks['matrix_led_texttocode'] = { - init: function() { - this.appendValueInput("value_text_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_indentcode'] = { - init: function() { - this.appendValueInput("value_indentcode_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_INDENTCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_showstate'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW) - .appendField(new Blockly.FieldDropdown([["on","1"], ["off","0"]]), "value_showstate_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_stop'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_resume'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_time'] = { - init: function() { - this.appendValueInput("value_marquee_time_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_sample'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SAMPLE_SHOW) - .appendField(new Blockly.FieldDropdown([["♥","♥"], ["♡","♡"], ["↑","↑"], ["↓","↓"], ["←","←"], ["→","→"], ["↖","↖"], ["↙","↙"], ["↗","↗"], ["↘","↘"], ["▲","▲"], ["▼","▼"], ["◄","◄"], ["►","►"], ["O","O"], ["X","X"], ["V","V"]]), "value_sample_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setTooltip(''); - this.setColour(300); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_code'] = { - init: function() { - this.appendValueInput("value_code_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_CODE_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_width'] = { - init: function() { - this.appendValueInput("value_width_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_WIDTH_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_height'] = { - init: function() { - this.appendValueInput("value_height_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_HEIGHT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L01') - .appendField(new Blockly.FieldColour("#ffffff"), 'L06') - .appendField(new Blockly.FieldColour("#ffffff"), 'L11') - .appendField(new Blockly.FieldColour("#ffffff"), 'L16') - .appendField(new Blockly.FieldColour("#ffffff"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L02') - .appendField(new Blockly.FieldColour("#ffffff"), 'L07') - .appendField(new Blockly.FieldColour("#ffffff"), 'L12') - .appendField(new Blockly.FieldColour("#ffffff"), 'L17') - .appendField(new Blockly.FieldColour("#ffffff"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L03') - .appendField(new Blockly.FieldColour("#ffffff"), 'L08') - .appendField(new Blockly.FieldColour("#ffffff"), 'L13') - .appendField(new Blockly.FieldColour("#ffffff"), 'L18') - .appendField(new Blockly.FieldColour("#ffffff"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L04') - .appendField(new Blockly.FieldColour("#ffffff"), 'L09') - .appendField(new Blockly.FieldColour("#ffffff"), 'L14') - .appendField(new Blockly.FieldColour("#ffffff"), 'L19') - .appendField(new Blockly.FieldColour("#ffffff"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L05') - .appendField(new Blockly.FieldColour("#ffffff"), 'L10') - .appendField(new Blockly.FieldColour("#ffffff"), 'L15') - .appendField(new Blockly.FieldColour("#ffffff"), 'L20') - .appendField(new Blockly.FieldColour("#ffffff"), 'L25') - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; -Blockly.Blocks['matrix_led_matrixcode'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_clear'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLEAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COLOR_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.appendValueInput("value_color_on_") - .setCheck("Colour") - .appendField("color"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_off'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_OFF_SHOW); - this.appendValueInput("value_x_off_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_off_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_REVERSE_SHOW); - this.appendValueInput("value_x_reverse_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_reverse_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_state'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_STATE_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_linechart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_LINECHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_barchart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_BARCHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_clockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_counterclockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_verticalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_horizontalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_invert'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_INVERT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_getcolor'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_GETCOLOR_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_backcolor'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/MatrixLed_20180720/blockly/javascript.js b/MatrixLed_20180720/blockly/javascript.js deleted file mode 100644 index 2c86decfea..0000000000 --- a/MatrixLed_20180720/blockly/javascript.js +++ /dev/null @@ -1,282 +0,0 @@ -Blockly.JavaScript['matrix_led_char'] = function(block) { - var value_char_ = Blockly.JavaScript.valueToCode(block, 'value_char_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_char('+ value_char_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_time'] = function(block) { - var value_marquee_time_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_time_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_time('+ value_marquee_time_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_stop'] = function(block) { - var code = 'MatrixLed_marquee_stop();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_resume'] = function(block) { - var code = 'MatrixLed_marquee_resume();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_reverse'] = function(block) { - var code = 'MatrixLed_marquee_reverse();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color('+ value_color_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_texttocode'] = function(block) { - var value_text_ = Blockly.JavaScript.valueToCode(block, 'value_text_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_texttocode('+value_text_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_width'] = function(block) { - var value_width_ = Blockly.JavaScript.valueToCode(block, 'value_width_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_width('+ value_width_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_height'] = function(block) { - var value_height_ = Blockly.JavaScript.valueToCode(block, 'value_height_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_height('+ value_height_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_sample'] = function(block) { - var value_sample_ = block.getFieldValue('value_sample_'); - var code = 'MatrixLed_sample("'+ value_sample_ +'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_code'] = function(block) { - var value_code_ = Blockly.JavaScript.valueToCode(block, 'value_code_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_code('+ value_code_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = 'MatrixLed_matrix("'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = 'MatrixLed_matrix_color(["'+L01+'","'+L02+'","'+L03+'","'+L04+'","'+L05+'","'+L06+'","'+L07+'","'+L08+'","'+L09+'","'+L10+'","'+L11+'","'+L12+'","'+L13+'","'+L14+'","'+L15+'","'+L16+'","'+L17+'","'+L18+'","'+L19+'","'+L20+'","'+L21+'","'+L22+'","'+L23+'","'+L24+'","'+L25+'"]);\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrixcode'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_clear'] = function(block) { - var code = 'MatrixLed_clear();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_on('+value_x_on_+','+value_y_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_on_ = Blockly.JavaScript.valueToCode(block, 'value_color_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color_on('+value_x_on_+','+value_y_on_+','+value_color_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_off'] = function(block) { - var value_x_off_ = Blockly.JavaScript.valueToCode(block, 'value_x_off_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_off_ = Blockly.JavaScript.valueToCode(block, 'value_y_off_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_off('+value_x_off_+','+value_y_off_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_reverse'] = function(block) { - var value_x_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_x_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_y_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_reverse('+value_x_reverse_+','+value_y_reverse_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_state'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_state('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_showstate'] = function(block) { - var value_showstate_ = block.getFieldValue('value_showstate_'); - var code = 'MatrixLed_showstate('+value_showstate_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_indentcode'] = function(block) { - var value_indentcode_ = Blockly.JavaScript.valueToCode(block, 'value_indentcode_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_indentcode('+value_indentcode_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_linechart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_linechart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_barchart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_barchart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_clockwise'] = function(block) { - var code = 'Matrixled_clockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_counterclockwise'] = function(block) { - var code = 'Matrixled_counterclockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_verticalflip'] = function(block) { - var code = 'Matrixled_verticalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_horizontalflip'] = function(block) { - var code = 'Matrixled_horizontalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_invert'] = function(block) { - var code = 'Matrixled_invert();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_getcolor'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_getcolor('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_backcolor'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_backcolor('+ value_color_ +');\n'; - return code; -}; diff --git a/MatrixLed_20180720/blockly/msg/blocks/en.js b/MatrixLed_20180720/blockly/msg/blocks/en.js deleted file mode 100644 index ec80b92e2a..0000000000 --- a/MatrixLed_20180720/blockly/msg/blocks/en.js +++ /dev/null @@ -1,40 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "Matrix Led"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "Matrix Led (COLOR)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "Matrix Led Code"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "Clean Screen"; -Blockly.Msg.MATRIXLED_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "Turn Off"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "Switch"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "Get Led State"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "Led Color"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "SCREEN WIDTH"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "SCREEN HEIGHT"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "Show Sample"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "Show Sample By Code"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "Show Marguee(CYCLE)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "Show Marguee(ONCE)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "Marguee Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " Degree"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "Stop Marguee"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "Resume Marguee(CYCLE)"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "Marguee Time (ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "Marguee(CYCLE) Reverse"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "Show Character"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "Convert Text To Code"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "Show Screen"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "Indent Code"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "Line Chart "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "Bar Chart "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "Value1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "Value2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "Value3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "Value4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "Value5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "Rotate 90 Degrees Clockwise"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "Rotate 90 Degrees Counter Clockwise"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "Vertical Flip"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "Horizontal Flip"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "Invert"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "Get Color Code"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "Back Color"; diff --git a/MatrixLed_20180720/blockly/msg/blocks/zh-hans.js b/MatrixLed_20180720/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 9b0a11f513..0000000000 --- a/MatrixLed_20180720/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,40 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示灯(单色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示灯(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示灯(单色) 编码"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示灯 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗灯"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示灯 开关反转"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示灯 亮暗状态"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示灯 颜色"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "指示灯 宽度"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "指示灯 高度"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "显示 图案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "显示 图案(编码)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑马灯(循环)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑马灯(单次)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑马灯 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格数"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑马灯 暂停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑马灯(循环) 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑马灯 间隔时间(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑马灯(循环) 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "显示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "转换文字为编码"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示灯 显示"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "缩排编码"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折线图 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "长条图 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "数值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "数值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "数值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "数值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "数值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示灯 顺时钟旋转90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示灯 逆时钟旋转90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示灯 垂直翻转"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示灯 水平翻转"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示灯 开关反转"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示灯 色码值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示灯 背景颜色"; diff --git a/MatrixLed_20180720/blockly/msg/blocks/zh-hant.js b/MatrixLed_20180720/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index af6d1b4692..0000000000 --- a/MatrixLed_20180720/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,40 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示燈(單色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示燈(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示燈(單色) 編碼"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示燈 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗燈"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示燈 開關反轉"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示燈 亮暗狀態"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示燈 顏色"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "指示燈 寬度"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "指示燈 高度"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "顯示 圖案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "顯示 圖案(編碼)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑馬燈(循環)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑馬燈(單次)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑馬燈 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格數"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑馬燈 暫停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑馬燈(循環) 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑馬燈 間隔時間(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑馬燈(循環) 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "顯示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "轉換文字為編碼"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示燈 顯示"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "縮排編碼"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折線圖 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "長條圖 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "數值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "數值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "數值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "數值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "數值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示燈 順時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示燈 逆時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示燈 垂直翻轉"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示燈 水平翻轉"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示燈 開關反轉"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示燈 色碼值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示燈 背景顏色"; diff --git a/MatrixLed_20180720/blockly/msg/en.js b/MatrixLed_20180720/blockly/msg/en.js deleted file mode 100644 index b8a0f1f7a2..0000000000 --- a/MatrixLed_20180720/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "Matrix Led"; diff --git a/MatrixLed_20180720/blockly/msg/zh-hans.js b/MatrixLed_20180720/blockly/msg/zh-hans.js deleted file mode 100644 index 774b699179..0000000000 --- a/MatrixLed_20180720/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "模拟指示灯"; diff --git a/MatrixLed_20180720/blockly/msg/zh-hant.js b/MatrixLed_20180720/blockly/msg/zh-hant.js deleted file mode 100644 index 8e299c4a7c..0000000000 --- a/MatrixLed_20180720/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "模擬指示燈"; diff --git a/MatrixLed_20180720/blockly/toolbox.xml b/MatrixLed_20180720/blockly/toolbox.xml deleted file mode 100644 index 4565032e5f..0000000000 --- a/MatrixLed_20180720/blockly/toolbox.xml +++ /dev/null @@ -1,333 +0,0 @@ - - - 1 - - - - - 250 - - - - - - - 250 - - - - - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - - - - - 0 - - - - - 0 - - - - - #ff0000 - - - - - - - #ffffff - - - - - - - #ff0000 - - - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - - - - - - - - - - - - - 0110011110011111111001100 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - 500 - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - 1 - - - 1 - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - diff --git a/MatrixLed_20180720/matrixled.js b/MatrixLed_20180720/matrixled.js deleted file mode 100644 index 5e64a5dbee..0000000000 --- a/MatrixLed_20180720/matrixled.js +++ /dev/null @@ -1,677 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - const charA = "0111110010100101001001111"; - const charB = "1111110101101011010101010"; - const charC = "0111010001100011000110001"; - const charD = "1111110001100011000101110"; - const charE = "1111110101101011010110101"; - const charF = "1111110100101001010010100"; - const charG = "0111010001101011010110111"; - const charH = "1111100100001000010011111"; - const charI = "1000110001111111000110001"; - const charJ = "1001110001111111000010000"; - const charK = "1111100010001000101010001"; - const charL = "1111100001000010000100001"; - const charM = "1111101000001000100011111"; - const charN = "1111101000001000001011111"; - const charO = "0111010001100011000101110"; - const charP = "1111110010100101001001100"; - const charQ = "0111010001101011001001101"; - const charR = "1111110100101001010001011"; - const charS = "0100110101101011010110010"; - const charT = "1000010000111111000010000"; - const charU = "1111000001000010000111110"; - const charV = "1110000010000010001011100"; - const charW = "1111000001111100000111110"; - const charX = "1000101010001000101010001"; - const charY = "1000001000001110100010000"; - const charZ = "1000110011101011100110001"; - const chara = "0000000110010010011000001"; - const charb = "0000011111001010001000000"; - const charc = "0000000110010010100100000"; - const chard = "0000000010001011111100000"; - const chare = "0000000110010110010100000"; - const charf = "0000000100111111010000000"; - const charg = "0000000101010110011000000"; - const charh = "0000011111001000001100000"; - const chari = "0000000000101110000000000"; - const charj = "0000000001101110000000000"; - const chark = "0000011111000100010100000"; - const charl = "0000000000111110000000000"; - const charm = "0011100100000110010000011"; - const charn = "0000000111001000001100000"; - const charo = "0000000010001010001000000"; - const charp = "0000001111010100010000000"; - const charq = "0000000100010100111100000"; - const charr = "0000000111000100010000000"; - const chars = "0000001001101011001000000"; - const chart = "0000000100011110010100000"; - const charu = "0000000110000010011000001"; - const charv = "0000000110000010011000000"; - const charw = "0011000001001100000100110"; - const charx = "0000000101000100010100000"; - const chary = "0000000101000100010000000"; - const charz = "0000101011011010100000000"; - const char0 = "0000011111100011111100000"; - const char1 = "0000001001111110000100000"; - const char2 = "0000010111101011110100000"; - const char3 = "0000010101101011111100000"; - const char4 = "0000011100001001111100000"; - const char5 = "0000011101101011011100000"; - const char6 = "0000011111101011011100000"; - const char7 = "0000011000100001111100000"; - const char8 = "0000011111101011111100000"; - const char9 = "0000011101101011111100000"; - const comma = "0000000001000100000000000"; - const period = "0000000001000000000000000"; - const questionmark = "0100010000100111010001000"; - const exclamationmark = "0000000000111010000000000"; - const semicolon = "0000000001010100000000000"; - const colon = "0000000000010100000000000"; - const parenthesesleft = "0000001110100010000000000"; - const parenthesesright = "0000000000100010111000000"; - const squarebracketsleft = "0000011111100010000000000"; - const squarebracketsright = "0000000000100011111100000"; - const curlybracketsleft = "0000000100111111000100000"; - const curlybracketsright = "0000010001111110010000000"; - const Quotationmarkssingle = "0000000000110000010000000"; - const Quotationmarksdouble = "1100000100110000010000000"; - const hyphen = "0000000100001000010000000"; - const heart = "0110010010010011001001100"; - const heartfill = "0110011110011111111001100"; - const arrowup = "0010001000111110100000100"; - const arrowdown = "0010000010111110001000100"; - const arrowleft = "0010001110101010010000100"; - const arrowright = "0010000100101010111000100"; - const arrowleftup = "1111011000101001001000001"; - const arrowleftdown = "0111100011001010100110000"; - const arrowrightup = "0000110010101001100011110"; - const arrowrightdown = "1000001001001010001101111"; - const arrowupfill = "0000100111111110011100001"; - const arrowdownfill = "1000011100111111110010000"; - const arrowleftfill = "0010000100011100111011111"; - const arrowrightfill = "1111101110011100010000100"; - const noexist = "0000000000000000000000000"; - - var L = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var MatrixLedcolor = "#ff0000"; - var MatrixLedbackcolor = "#ffffff"; - var MatrixLedwidth = 250; - var MatrixLedheight = 250; - var MatrixLedmarqueecode = ""; - var MatrixLedmarqueecodeonce = ""; - var MatrixLedmarqueetime = 500; - var MatrixLedmarqueereverse = 1; - var MatrixLedshowstate = 1; - var marqueetimeid,marqueetimeid1; - - function MatrixLed_color(input_color_) { - MatrixLedcolor = input_color_; - } - - function MatrixLed_width(input_width_) { - MatrixLedwidth = input_width_; - } - - function MatrixLed_height(input_height_) { - MatrixLedheight = input_height_; - } - - function MatrixLed_showstate(input_showstate_) { - MatrixLedshowstate = input_showstate_; - } - - function MatrixLed_indentcode(input_indentcode_) { - var indentcode = input_indentcode_; - while (indentcode.search(/0000000000/)!=-1) - indentcode = indentcode.replace(/0000000000/g,"00000"); - return indentcode; - } - - function MatrixLed_marquee(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecodeonce = ""; - window.clearInterval(marqueetimeid); - window.clearInterval(marqueetimeid1); - if ((input_marquee_.length==25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLed_matrix(input_marquee_); - return; - } - else if ((input_marquee_.length%5==0)&&(input_marquee_.length>25)&&(input_marquee_.search(/[^0-1]/)==-1)) - MatrixLedmarqueecode = input_marquee_; - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLedmarqueecode = input_marquee_+"0000000000000000000000000"; - MatrixLedmarqueecodeonce = input_marquee_+"0000000000000000000000000"; - } - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_once_play() { - if (MatrixLedmarqueecode.length>25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(5,MatrixLedmarqueecodeonce.length-5)+MatrixLedmarqueecodeonce.substr(0,5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(MatrixLedmarqueecodeonce.length-5,5)+MatrixLedmarqueecodeonce.substr(0,MatrixLedmarqueecodeonce.length-5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5); - } - } - else - window.clearInterval(marqueetimeid1); - } - - function MatrixLed_marquee_degree(direction,degree) { - window.clearInterval(marqueetimeid); - window.clearInterval(marqueetimeid1); - if (MatrixLedmarqueecode.length25) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - } - } - - function MatrixLed_marquee_time(input_time_) { - MatrixLedmarqueetime = input_time_; - } - - function MatrixLed_marquee_stop() { - window.clearInterval(marqueetimeid); - window.clearInterval(marqueetimeid1); - } - - function MatrixLed_marquee_resume() { - window.clearInterval(marqueetimeid); - marqueetimeid = window.setInterval("MatrixLed_marquee_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_reverse() { - if (MatrixLedmarqueereverse==1) - MatrixLedmarqueereverse=2; - else if (MatrixLedmarqueereverse==2) - MatrixLedmarqueereverse=1; - } - - function MatrixLed_char(input_char_) { - input_char_=input_char_.toString(); - if (input_char_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_char_)); - } - } - - function MatrixLed_texttocode(input_text_) { - input_text_=input_text_.toString(); - if (input_text_.length>0) - { - var textcode=""; - for (var i=0;i" - + "" - + "" - + "" - + "" - + "" - + ""; - else - var ledtable ="" - + "" - + "" - + "" - + "" - + "" - + "
"; - - if (document.getElementById("fustyles_matrixled")) - { - document.getElementById("fustyles_matrixled").innerHTML = ledtable; - } - else - { - var div = document.createElement('div'); - div.id = "fustyles_matrixled"; - div.innerHTML = ledtable; - document.body.appendChild(div); - } - } - - function MatrixLed_conversion(input_char_) { - if (input_char_=="A") return charA; - else if (input_char_=="B") return charB; - else if (input_char_=="C") return charC; - else if (input_char_=="D") return charD; - else if (input_char_=="E") return charE; - else if (input_char_=="F") return charF; - else if (input_char_=="G") return charG; - else if (input_char_=="H") return charH; - else if (input_char_=="I") return charI; - else if (input_char_=="J") return charJ; - else if (input_char_=="K") return charK; - else if (input_char_=="L") return charL; - else if (input_char_=="M") return charM; - else if (input_char_=="N") return charN; - else if (input_char_=="O") return charO; - else if (input_char_=="P") return charP; - else if (input_char_=="Q") return charQ; - else if (input_char_=="R") return charR; - else if (input_char_=="S") return charS; - else if (input_char_=="T") return charT; - else if (input_char_=="U") return charU; - else if (input_char_=="V") return charV; - else if (input_char_=="W") return charW; - else if (input_char_=="X") return charX; - else if (input_char_=="Y") return charY; - else if (input_char_=="Z") return charZ; - else if (input_char_=="a") return chara; - else if (input_char_=="b") return charb; - else if (input_char_=="c") return charc; - else if (input_char_=="d") return chard; - else if (input_char_=="e") return chare; - else if (input_char_=="f") return charf; - else if (input_char_=="g") return charg; - else if (input_char_=="h") return charh; - else if (input_char_=="i") return chari; - else if (input_char_=="j") return charj; - else if (input_char_=="k") return chark; - else if (input_char_=="l") return charl; - else if (input_char_=="m") return charm; - else if (input_char_=="n") return charn; - else if (input_char_=="o") return charo; - else if (input_char_=="p") return charp; - else if (input_char_=="q") return charq; - else if (input_char_=="r") return charr; - else if (input_char_=="s") return chars; - else if (input_char_=="t") return chart; - else if (input_char_=="u") return charu; - else if (input_char_=="v") return charv; - else if (input_char_=="w") return charw; - else if (input_char_=="x") return charx; - else if (input_char_=="y") return chary; - else if (input_char_=="z") return charz; - else if (input_char_=="0") return char0; - else if (input_char_=="1") return char1; - else if (input_char_=="2") return char2; - else if (input_char_=="3") return char3; - else if (input_char_=="4") return char4; - else if (input_char_=="5") return char5; - else if (input_char_=="6") return char6; - else if (input_char_=="7") return char7; - else if (input_char_=="8") return char8; - else if (input_char_=="9") return char9; - else if (input_char_==",") return comma; - else if (input_char_==".") return period; - else if (input_char_=="?") return questionmark; - else if (input_char_=="!") return exclamationmark; - else if (input_char_==";") return semicolon; - else if (input_char_==":") return colon; - else if (input_char_=="(") return parenthesesleft; - else if (input_char_==")") return parenthesesright; - else if (input_char_=="[") return squarebracketsleft; - else if (input_char_=="]") return squarebracketsright; - else if (input_char_=="{") return curlybracketsleft; - else if (input_char_=="}") return curlybracketsright; - else if (input_char_=="'") return Quotationmarkssingle; - else if (input_char_=="\"") return Quotationmarksdouble; - else if (input_char_=="♡") return heart; - else if (input_char_=="♥") return heartfill; - else if (input_char_=="↑") return arrowup; - else if (input_char_=="↓") return arrowdown; - else if (input_char_=="←") return arrowleft; - else if (input_char_=="→") return arrowright; - else if (input_char_=="↖") return arrowleftup; - else if (input_char_=="↙") return arrowleftdown; - else if (input_char_=="↗") return arrowrightup; - else if (input_char_=="↘") return arrowrightdown; - else if (input_char_=="▲") return arrowupfill; - else if (input_char_=="▼") return arrowdownfill; - else if (input_char_=="◄") return arrowleftfill; - else if (input_char_=="►") return arrowrightfill; - else return noexist; - } - - function MatrixLed_linechart(value1,value2,value3,value4,value5){ - var input_value=[value1,value2,value3,value4,value5]; - var k=0; - for (var i=0;i<=4;i++) - { - for (var j=0;j<=4;j++) - { - if (j==(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function MatrixLed_barchart(value1,value2,value3,value4,value5){ - var input_value=[value1,value2,value3,value4,value5]; - var k=0; - for (var i=0;i<=4;i++) - { - for (var j=0;j<=4;j++) - { - if (j>=(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function Matrixled_clockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_counterclockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_verticalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[j+5*i]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_horizontalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[j+i*5]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_invert(){ - for (var i=0;i<25;i++) - { - if ((L[i]=="")||(L[i]==MatrixLedbackcolor)) - L[i]=MatrixLedcolor; - else - L[i]=MatrixLedbackcolor; - } - MatrixLed_show(); - } - - function MatrixLed_getcolor(input_x_,input_y_) { - return L[input_x_*5+input_y_]; - } - - function MatrixLed_backcolor(input_color_) { - MatrixLedbackcolor=input_color_; - } - - window.MatrixLed_clear = MatrixLed_clear; - window.MatrixLed_matrix = MatrixLed_matrix; - window.MatrixLed_matrix_color = MatrixLed_matrix_color; - window.MatrixLed_show = MatrixLed_show; - window.MatrixLed_on = MatrixLed_on; - window.MatrixLed_color_on = MatrixLed_color_on; - window.MatrixLed_off = MatrixLed_off; - window.MatrixLed_reverse = MatrixLed_reverse; - window.MatrixLed_state = MatrixLed_state; - window.MatrixLed_color = MatrixLed_color; - window.MatrixLed_width = MatrixLed_width; - window.MatrixLed_height = MatrixLed_height; - window.MatrixLed_sample = MatrixLed_sample; - window.MatrixLed_code = MatrixLed_code; - window.MatrixLed_marquee = MatrixLed_marquee; - window.MatrixLed_marquee_once = MatrixLed_marquee_once; - window.MatrixLed_marquee_play = MatrixLed_marquee_play; - window.MatrixLed_marquee_once_play = MatrixLed_marquee_once_play; - window.MatrixLed_marquee_degree = MatrixLed_marquee_degree; - window.MatrixLed_marquee_stop = MatrixLed_marquee_stop; - window.MatrixLed_marquee_resume = MatrixLed_marquee_resume; - window.MatrixLed_marquee_reverse = MatrixLed_marquee_reverse; - window.MatrixLed_marquee_time = MatrixLed_marquee_time; - window.MatrixLed_char = MatrixLed_char; - window.MatrixLed_conversion = MatrixLed_conversion; - window.MatrixLed_texttocode = MatrixLed_texttocode; - window.MatrixLed_showstate = MatrixLed_showstate; - window.MatrixLed_indentcode = MatrixLed_indentcode; - window.MatrixLed_linechart = MatrixLed_linechart; - window.MatrixLed_barchart = MatrixLed_barchart; - window.Matrixled_clockwise = Matrixled_clockwise; - window.Matrixled_counterclockwise = Matrixled_counterclockwise; - window.Matrixled_verticalflip = Matrixled_verticalflip; - window.Matrixled_horizontalflip = Matrixled_horizontalflip; - window.Matrixled_invert = Matrixled_invert; - window.MatrixLed_getcolor = MatrixLed_getcolor; - window.MatrixLed_backcolor = MatrixLed_backcolor; - -}(window, window.document)); diff --git a/MatrixLed_20180723/blockly.json b/MatrixLed_20180723/blockly.json deleted file mode 100644 index f2c791c28a..0000000000 --- a/MatrixLed_20180723/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["matrix_led_backcolor","matrix_led_verticalflip","matrix_led_horizontalflip","matrix_led_invert","matrix_led_getcolor","matrix_led_color","matrix_led_width","matrix_led_height","matrix_led_code","matrix_led_texttocode","matrix_led_indentcode","matrix_led_showstate","matrix_led_sample","matrix_led_matrix","matrix_led_matrix_color","matrix_led_matrixcode","matrix_led_matrixcode_color","matrix_led_clear","matrix_led_on","matrix_led_color_on","matrix_led_off","matrix_led_reverse","matrix_led_state","matrix_led_marquee","matrix_led_marquee_once","matrix_led_marquee_color","matrix_led_marquee_color_once","matrix_led_marquee_degree","matrix_led_marquee_color_degree","matrix_led_marquee_time","matrix_led_marquee_stop","matrix_led_marquee_reverse","matrix_led_marquee_resume","matrix_led_char","matrix_led_linechart","matrix_led_barchart","matrix_led_clockwise","matrix_led_counterclockwise"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "matrixled.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/MatrixLed_20180723/blockly/blocks.js b/MatrixLed_20180723/blockly/blocks.js deleted file mode 100644 index dcc7730b22..0000000000 --- a/MatrixLed_20180723/blockly/blocks.js +++ /dev/null @@ -1,678 +0,0 @@ -Blockly.Blocks['matrix_led_char'] = { - init: function() { - this.appendValueInput("value_char_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_CHAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - - -Blockly.Blocks['matrix_led_texttocode'] = { - init: function() { - this.appendValueInput("value_text_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_indentcode'] = { - init: function() { - this.appendValueInput("value_indentcode_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_INDENTCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_showstate'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW) - .appendField(new Blockly.FieldDropdown([["on","1"], ["off","0"]]), "value_showstate_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_stop'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_resume'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_time'] = { - init: function() { - this.appendValueInput("value_marquee_time_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_sample'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SAMPLE_SHOW) - .appendField(new Blockly.FieldDropdown([["♥","♥"], ["♡","♡"], ["↑","↑"], ["↓","↓"], ["←","←"], ["→","→"], ["↖","↖"], ["↙","↙"], ["↗","↗"], ["↘","↘"], ["▲","▲"], ["▼","▼"], ["◄","◄"], ["►","►"], ["O","O"], ["X","X"], ["V","V"]]), "value_sample_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setTooltip(''); - this.setColour(300); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_code'] = { - init: function() { - this.appendValueInput("value_code_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_CODE_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_width'] = { - init: function() { - this.appendValueInput("value_width_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_WIDTH_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_height'] = { - init: function() { - this.appendValueInput("value_height_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_HEIGHT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L01') - .appendField(new Blockly.FieldColour("#ffffff"), 'L06') - .appendField(new Blockly.FieldColour("#ffffff"), 'L11') - .appendField(new Blockly.FieldColour("#ffffff"), 'L16') - .appendField(new Blockly.FieldColour("#ffffff"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L02') - .appendField(new Blockly.FieldColour("#ffffff"), 'L07') - .appendField(new Blockly.FieldColour("#ffffff"), 'L12') - .appendField(new Blockly.FieldColour("#ffffff"), 'L17') - .appendField(new Blockly.FieldColour("#ffffff"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L03') - .appendField(new Blockly.FieldColour("#ffffff"), 'L08') - .appendField(new Blockly.FieldColour("#ffffff"), 'L13') - .appendField(new Blockly.FieldColour("#ffffff"), 'L18') - .appendField(new Blockly.FieldColour("#ffffff"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L04') - .appendField(new Blockly.FieldColour("#ffffff"), 'L09') - .appendField(new Blockly.FieldColour("#ffffff"), 'L14') - .appendField(new Blockly.FieldColour("#ffffff"), 'L19') - .appendField(new Blockly.FieldColour("#ffffff"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L05') - .appendField(new Blockly.FieldColour("#ffffff"), 'L10') - .appendField(new Blockly.FieldColour("#ffffff"), 'L15') - .appendField(new Blockly.FieldColour("#ffffff"), 'L20') - .appendField(new Blockly.FieldColour("#ffffff"), 'L25') - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; - -Blockly.Blocks['matrix_led_matrixcode'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrixcode_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L01') - .appendField(new Blockly.FieldColour("#ffffff"), 'L06') - .appendField(new Blockly.FieldColour("#ffffff"), 'L11') - .appendField(new Blockly.FieldColour("#ffffff"), 'L16') - .appendField(new Blockly.FieldColour("#ffffff"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L02') - .appendField(new Blockly.FieldColour("#ffffff"), 'L07') - .appendField(new Blockly.FieldColour("#ffffff"), 'L12') - .appendField(new Blockly.FieldColour("#ffffff"), 'L17') - .appendField(new Blockly.FieldColour("#ffffff"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L03') - .appendField(new Blockly.FieldColour("#ffffff"), 'L08') - .appendField(new Blockly.FieldColour("#ffffff"), 'L13') - .appendField(new Blockly.FieldColour("#ffffff"), 'L18') - .appendField(new Blockly.FieldColour("#ffffff"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L04') - .appendField(new Blockly.FieldColour("#ffffff"), 'L09') - .appendField(new Blockly.FieldColour("#ffffff"), 'L14') - .appendField(new Blockly.FieldColour("#ffffff"), 'L19') - .appendField(new Blockly.FieldColour("#ffffff"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L05') - .appendField(new Blockly.FieldColour("#ffffff"), 'L10') - .appendField(new Blockly.FieldColour("#ffffff"), 'L15') - .appendField(new Blockly.FieldColour("#ffffff"), 'L20') - .appendField(new Blockly.FieldColour("#ffffff"), 'L25') - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; - -Blockly.Blocks['matrix_led_clear'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLEAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COLOR_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.appendValueInput("value_color_on_") - .setCheck("Colour") - .appendField("color"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_off'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_OFF_SHOW); - this.appendValueInput("value_x_off_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_off_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_REVERSE_SHOW); - this.appendValueInput("value_x_reverse_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_reverse_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_state'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_STATE_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_linechart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_LINECHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_barchart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_BARCHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_clockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_counterclockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_verticalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_horizontalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_invert'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_INVERT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_getcolor'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_GETCOLOR_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_backcolor'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/MatrixLed_20180723/blockly/javascript.js b/MatrixLed_20180723/blockly/javascript.js deleted file mode 100644 index 7e2446654a..0000000000 --- a/MatrixLed_20180723/blockly/javascript.js +++ /dev/null @@ -1,331 +0,0 @@ -Blockly.JavaScript['matrix_led_char'] = function(block) { - var value_char_ = Blockly.JavaScript.valueToCode(block, 'value_char_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_char('+ value_char_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_time'] = function(block) { - var value_marquee_time_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_time_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_time('+ value_marquee_time_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_stop'] = function(block) { - var code = 'MatrixLed_marquee_stop();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_resume'] = function(block) { - var code = 'MatrixLed_marquee_resume();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_reverse'] = function(block) { - var code = 'MatrixLed_marquee_reverse();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color('+ value_color_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_texttocode'] = function(block) { - var value_text_ = Blockly.JavaScript.valueToCode(block, 'value_text_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_texttocode('+value_text_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_width'] = function(block) { - var value_width_ = Blockly.JavaScript.valueToCode(block, 'value_width_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_width('+ value_width_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_height'] = function(block) { - var value_height_ = Blockly.JavaScript.valueToCode(block, 'value_height_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_height('+ value_height_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_sample'] = function(block) { - var value_sample_ = block.getFieldValue('value_sample_'); - var code = 'MatrixLed_sample("'+ value_sample_ +'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_code'] = function(block) { - var value_code_ = Blockly.JavaScript.valueToCode(block, 'value_code_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_code('+ value_code_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = 'MatrixLed_matrix("'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = 'MatrixLed_matrix_color(["'+L01+'","'+L02+'","'+L03+'","'+L04+'","'+L05+'","'+L06+'","'+L07+'","'+L08+'","'+L09+'","'+L10+'","'+L11+'","'+L12+'","'+L13+'","'+L14+'","'+L15+'","'+L16+'","'+L17+'","'+L18+'","'+L19+'","'+L20+'","'+L21+'","'+L22+'","'+L23+'","'+L24+'","'+L25+'"]);\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrixcode'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_matrixcode_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_clear'] = function(block) { - var code = 'MatrixLed_clear();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_on('+value_x_on_+','+value_y_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_on_ = Blockly.JavaScript.valueToCode(block, 'value_color_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color_on('+value_x_on_+','+value_y_on_+','+value_color_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_off'] = function(block) { - var value_x_off_ = Blockly.JavaScript.valueToCode(block, 'value_x_off_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_off_ = Blockly.JavaScript.valueToCode(block, 'value_y_off_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_off('+value_x_off_+','+value_y_off_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_reverse'] = function(block) { - var value_x_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_x_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_y_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_reverse('+value_x_reverse_+','+value_y_reverse_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_state'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_state('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_showstate'] = function(block) { - var value_showstate_ = block.getFieldValue('value_showstate_'); - var code = 'MatrixLed_showstate('+value_showstate_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_indentcode'] = function(block) { - var value_indentcode_ = Blockly.JavaScript.valueToCode(block, 'value_indentcode_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_indentcode('+value_indentcode_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_linechart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_linechart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_barchart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_barchart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_clockwise'] = function(block) { - var code = 'Matrixled_clockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_counterclockwise'] = function(block) { - var code = 'Matrixled_counterclockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_verticalflip'] = function(block) { - var code = 'Matrixled_verticalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_horizontalflip'] = function(block) { - var code = 'Matrixled_horizontalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_invert'] = function(block) { - var code = 'Matrixled_invert();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_getcolor'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_getcolor('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_backcolor'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_backcolor('+ value_color_ +');\n'; - return code; -}; diff --git a/MatrixLed_20180723/blockly/msg/blocks/en.js b/MatrixLed_20180723/blockly/msg/blocks/en.js deleted file mode 100644 index fdbf0209cd..0000000000 --- a/MatrixLed_20180723/blockly/msg/blocks/en.js +++ /dev/null @@ -1,44 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "Matrix Led"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "Matrix Led (Full Color)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "Matrix Led Code"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "Clean Screen"; -Blockly.Msg.MATRIXLED_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "Turn Off"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "Switch"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "Get Led State"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "Led Color"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "Screen Width"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "Screen Height"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "Show Sample"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "Show Sample By Code"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "Show Marguee(CYCLE)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "Show Marguee(ONCE)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "Marguee Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "Marguee(Full Color) Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " Degree"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "Stop Marguee"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "Resume Marguee"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "Marguee Time (ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "Marguee Reverse"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "Show Character"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "Convert Text To Code"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "Show Screen"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "Indent Code"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "Line Chart "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "Bar Chart "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "Value1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "Value2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "Value3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "Value4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "Value5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "Rotate 90 Degrees Clockwise"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "Rotate 90 Degrees Counter Clockwise"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "Vertical Flip"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "Horizontal Flip"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "Invert"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "Get Color Code"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "Back Color"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "Matrix Led(Full Color) Code"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "Show Marguee(Full Color) CYCLE"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "Show Marguee(Full Color) ONCE"; diff --git a/MatrixLed_20180723/blockly/msg/blocks/zh-hans.js b/MatrixLed_20180723/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 7c7699a975..0000000000 --- a/MatrixLed_20180723/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,44 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示灯(单色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示灯(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示灯(单色) 编码"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示灯 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗灯"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示灯 亮暗反转"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示灯 亮暗状态"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示灯(单色) 颜色"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "指示灯 宽度"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "指示灯 高度"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "显示 图案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "显示 图案(编码)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑马灯(单色) 循环"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑马灯(单色) 单次"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑马灯(单色) 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "跑马灯(全彩) 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格数"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑马灯 暂停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑马灯 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑马灯 间隔时间(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑马灯 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "显示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "转换文字为编码"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示灯 显示"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "缩排编码"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折线图 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "长条图 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "数值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "数值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "数值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "数值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "数值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示灯 顺时钟旋转90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示灯 逆时钟旋转90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示灯 垂直翻转"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示灯 水平翻转"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示灯 开关反转"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示灯 色码值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示灯(单色) 背景颜色"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "指示灯(全彩) 编码"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "跑马灯(全彩) 循环"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "跑马灯(全彩) 单次"; diff --git a/MatrixLed_20180723/blockly/msg/blocks/zh-hant.js b/MatrixLed_20180723/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 805d449976..0000000000 --- a/MatrixLed_20180723/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,44 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示燈(單色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示燈(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示燈(單色) 編碼"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示燈 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗燈"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示燈 亮暗反轉"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示燈 亮暗狀態"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示燈(單色) 顏色"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "指示燈 寬度"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "指示燈 高度"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "顯示 圖案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "顯示 圖案(編碼)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑馬燈(單色) 循環"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑馬燈(單色) 單次"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑馬燈(單色) 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "跑馬燈(全彩) 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格數"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑馬燈 暫停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑馬燈 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑馬燈 間隔時間(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑馬燈 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "顯示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "轉換文字為編碼"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示燈 顯示"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "縮排編碼"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折線圖 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "長條圖 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "數值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "數值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "數值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "數值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "數值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示燈 順時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示燈 逆時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示燈 垂直翻轉"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示燈 水平翻轉"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示燈 開關反轉"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示燈 色碼值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示燈(單色) 背景顏色"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "指示燈(全彩) 編碼"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "跑馬燈(全彩) 循環"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "跑馬燈(全彩) 單次"; diff --git a/MatrixLed_20180723/blockly/msg/en.js b/MatrixLed_20180723/blockly/msg/en.js deleted file mode 100644 index 6339d1dd92..0000000000 --- a/MatrixLed_20180723/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "Simulation Matrix Led"; diff --git a/MatrixLed_20180723/blockly/msg/zh-hans.js b/MatrixLed_20180723/blockly/msg/zh-hans.js deleted file mode 100644 index f14896b249..0000000000 --- a/MatrixLed_20180723/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "模拟点矩阵"; diff --git a/MatrixLed_20180723/blockly/msg/zh-hant.js b/MatrixLed_20180723/blockly/msg/zh-hant.js deleted file mode 100644 index 42ab3e44a3..0000000000 --- a/MatrixLed_20180723/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "模擬點矩陣"; diff --git a/MatrixLed_20180723/blockly/toolbox.xml b/MatrixLed_20180723/blockly/toolbox.xml deleted file mode 100644 index a1996be62d..0000000000 --- a/MatrixLed_20180723/blockly/toolbox.xml +++ /dev/null @@ -1,498 +0,0 @@ - - - 1 - - - - - 250 - - - - - - - 250 - - - - - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - - - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - - - - - 0 - - - - - 0 - - - - - #ff0000 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - 500 - - - - - - - - - - - - - - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - - - - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - - - 1 - - - 1 - - - - - - - - - - - - - #ffffff - - - - - - - #ff0000 - - - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - - - - - - - - - - - - - 0110011110011111111001100 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - 1 - - - 1 - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - diff --git a/MatrixLed_20180723/matrixled.js b/MatrixLed_20180723/matrixled.js deleted file mode 100644 index 16cdb2bff2..0000000000 --- a/MatrixLed_20180723/matrixled.js +++ /dev/null @@ -1,808 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - const charA = "0111110010100101001001111"; - const charB = "1111110101101011010101010"; - const charC = "0111010001100011000110001"; - const charD = "1111110001100011000101110"; - const charE = "1111110101101011010110101"; - const charF = "1111110100101001010010100"; - const charG = "0111010001101011010110111"; - const charH = "1111100100001000010011111"; - const charI = "1000110001111111000110001"; - const charJ = "1001110001111111000010000"; - const charK = "1111100010001000101010001"; - const charL = "1111100001000010000100001"; - const charM = "1111101000001000100011111"; - const charN = "1111101000001000001011111"; - const charO = "0111010001100011000101110"; - const charP = "1111110010100101001001100"; - const charQ = "0111010001101011001001101"; - const charR = "1111110100101001010001011"; - const charS = "0100110101101011010110010"; - const charT = "1000010000111111000010000"; - const charU = "1111000001000010000111110"; - const charV = "1110000010000010001011100"; - const charW = "1111000001111100000111110"; - const charX = "1000101010001000101010001"; - const charY = "1000001000001110100010000"; - const charZ = "1000110011101011100110001"; - const chara = "0000000110010010011000001"; - const charb = "0000011111001010001000000"; - const charc = "0000000110010010100100000"; - const chard = "0000000010001011111100000"; - const chare = "0000000110010110010100000"; - const charf = "0000000100111111010000000"; - const charg = "0000000101010110011000000"; - const charh = "0000011111001000001100000"; - const chari = "0000000000101110000000000"; - const charj = "0000000001101110000000000"; - const chark = "0000011111000100010100000"; - const charl = "0000000000111110000000000"; - const charm = "0011100100000110010000011"; - const charn = "0000000111001000001100000"; - const charo = "0000000010001010001000000"; - const charp = "0000001111010100010000000"; - const charq = "0000000100010100111100000"; - const charr = "0000000111000100010000000"; - const chars = "0000001001101011001000000"; - const chart = "0000000100011110010100000"; - const charu = "0000000110000010011000001"; - const charv = "0000000110000010011000000"; - const charw = "0011000001001100000100110"; - const charx = "0000000101000100010100000"; - const chary = "0000000101000100010000000"; - const charz = "0000101011011010100000000"; - const char0 = "0000011111100011111100000"; - const char1 = "0000001001111110000100000"; - const char2 = "0000010111101011110100000"; - const char3 = "0000010101101011111100000"; - const char4 = "0000011100001001111100000"; - const char5 = "0000011101101011011100000"; - const char6 = "0000011111101011011100000"; - const char7 = "0000011000100001111100000"; - const char8 = "0000011111101011111100000"; - const char9 = "0000011101101011111100000"; - const comma = "0000000001000100000000000"; - const period = "0000000001000000000000000"; - const questionmark = "0100010000100111010001000"; - const exclamationmark = "0000000000111010000000000"; - const semicolon = "0000000001010100000000000"; - const colon = "0000000000010100000000000"; - const parenthesesleft = "0000001110100010000000000"; - const parenthesesright = "0000000000100010111000000"; - const squarebracketsleft = "0000011111100010000000000"; - const squarebracketsright = "0000000000100011111100000"; - const curlybracketsleft = "0000000100111111000100000"; - const curlybracketsright = "0000010001111110010000000"; - const Quotationmarkssingle = "0000000000110000010000000"; - const Quotationmarksdouble = "1100000100110000010000000"; - const hyphen = "0000000100001000010000000"; - const heart = "0110010010010011001001100"; - const heartfill = "0110011110011111111001100"; - const arrowup = "0010001000111110100000100"; - const arrowdown = "0010000010111110001000100"; - const arrowleft = "0010001110101010010000100"; - const arrowright = "0010000100101010111000100"; - const arrowleftup = "1111011000101001001000001"; - const arrowleftdown = "0111100011001010100110000"; - const arrowrightup = "0000110010101001100011110"; - const arrowrightdown = "1000001001001010001101111"; - const arrowupfill = "0000100111111110011100001"; - const arrowdownfill = "1000011100111111110010000"; - const arrowleftfill = "0010000100011100111011111"; - const arrowrightfill = "1111101110011100010000100"; - const noexist = "0000000000000000000000000"; - - var L = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var MatrixLedcolor = "#ff0000"; - var MatrixLedbackcolor = "#ffffff"; - var MatrixLedwidth = 250; - var MatrixLedheight = 250; - var MatrixLedmarqueeinitial = "",MatrixLedmarqueecode = "",MatrixLedmarqueecodeonce = "",MatrixLedmarqueecolorcode = "",MatrixLedmarqueecolorcodeonce = ""; - var MatrixLedmarqueetime = 500; - var MatrixLedmarqueereverse = 1; - var MatrixLedshowstate = 1; - var marqueetimeid; - var marqueeactive; - - function MatrixLed_color(input_color_) { - MatrixLedcolor = input_color_; - } - - function MatrixLed_width(input_width_) { - MatrixLedwidth = input_width_; - } - - function MatrixLed_height(input_height_) { - MatrixLedheight = input_height_; - } - - function MatrixLed_showstate(input_showstate_) { - MatrixLedshowstate = input_showstate_; - } - - function MatrixLed_indentcode(input_indentcode_) { - var indentcode = input_indentcode_; - while (indentcode.search(/0000000000/)!=-1) - indentcode = indentcode.replace(/0000000000/g,"00000"); - return indentcode; - } - - function MatrixLed_marquee(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecodeonce = ""; - window.clearInterval(marqueetimeid); - if ((input_marquee_.length==25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLed_matrix(input_marquee_); - return; - } - else if ((input_marquee_.length%5==0)&&(input_marquee_.length>25)&&(input_marquee_.search(/[^0-1]/)==-1)) - MatrixLedmarqueecode = input_marquee_; - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLedmarqueecode = input_marquee_; - MatrixLedmarqueecodeonce = input_marquee_; - } - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_once_play() { - if (MatrixLedmarqueecode.length>=25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(5,MatrixLedmarqueecodeonce.length-5)+MatrixLedmarqueecodeonce.substr(0,5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(MatrixLedmarqueecodeonce.length-5,5)+MatrixLedmarqueecodeonce.substr(0,MatrixLedmarqueecodeonce.length-5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_degree(direction,degree) { - window.clearInterval(marqueetimeid); - if (MatrixLedmarqueecode.length25) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - } - } - - function MatrixLed_marquee_color(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecolorcodeonce = ""; - window.clearInterval(marqueetimeid); - if (input_marquee_.length==175) - { - MatrixLed_matrix_codetocolor(input_marquee_); - return; - } - else if ((input_marquee_.length%35==0)&&(input_marquee_.length>175)) - MatrixLedmarqueecolorcode = input_marquee_; - MatrixLedmarqueeinitial=MatrixLedmarqueecolorcode; - marqueeactive=3; - marqueetimeid = window.setInterval("MatrixLed_marquee_color_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_color_once(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueeinitial=input_marquee_; - window.clearInterval(marqueetimeid); - if (input_marquee_.length==175) - { - MatrixLed_matrix_codetocolor(input_marquee_); - return; - } - else if ((input_marquee_.length%35==0)&&(input_marquee_.length>175)) - { - MatrixLedmarqueecolorcode = input_marquee_; - MatrixLedmarqueecolorcodeonce = input_marquee_; - } - MatrixLedmarqueeinitial=MatrixLedmarqueecolorcode; - marqueeactive=4; - marqueetimeid = window.setInterval("MatrixLed_marquee_color_once_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_color_play() { - if (MatrixLedmarqueecolorcode.length>175) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35)+MatrixLedmarqueecolorcode.substr(0,35); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-175,175)); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-35,35)+MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_color_once_play() { - if (MatrixLedmarqueecolorcode.length>=175) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueecolorcodeonce.substr(35,MatrixLedmarqueecolorcodeonce.length-35)+MatrixLedmarqueecolorcodeonce.substr(0,35); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-175,175)); - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueecolorcodeonce.substr(MatrixLedmarqueecolorcodeonce.length-35,35)+MatrixLedmarqueecolorcodeonce.substr(0,MatrixLedmarqueecolorcodeonce.length-35); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_color_degree(direction,degree) { - window.clearInterval(marqueetimeid); - if (MatrixLedmarqueecolorcode.length175) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35)+MatrixLedmarqueecolorcode.substr(0,35); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-35,35)+MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - } - } - - function MatrixLed_marquee_time(input_time_) { - MatrixLedmarqueetime = input_time_; - } - - function MatrixLed_marquee_stop() { - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_resume() { - window.clearInterval(marqueetimeid); - if (marqueeactive==1) - marqueetimeid = window.setInterval("MatrixLed_marquee_play()",MatrixLedmarqueetime); - else if (marqueeactive==2) - marqueetimeid = window.setInterval("MatrixLed_marquee_once_play()",MatrixLedmarqueetime); - else if (marqueeactive==3) - marqueetimeid= window.setInterval("MatrixLed_marquee_color_play()",MatrixLedmarqueetime); - else if (marqueeactive==4) - marqueetimeid = window.setInterval("MatrixLed_marquee_color_once_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_reverse() { - MatrixLedmarqueecode = MatrixLedmarqueeinitial; - MatrixLedmarqueecodeonce = MatrixLedmarqueeinitial; - MatrixLedmarqueecolorcode = MatrixLedmarqueeinitial; - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueeinitial; - if (MatrixLedmarqueereverse==1) - MatrixLedmarqueereverse=2; - else if (MatrixLedmarqueereverse==2) - MatrixLedmarqueereverse=1; - } - - function MatrixLed_char(input_char_) { - input_char_=input_char_.toString(); - if (input_char_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_char_)); - } - } - - function MatrixLed_texttocode(input_text_) { - input_text_=input_text_.toString(); - if (input_text_.length>0) - { - var textcode=""; - for (var i=0;i=(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function Matrixled_clockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_counterclockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_verticalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[j+5*i]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_horizontalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[j+i*5]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_invert(){ - for (var i=0;i<25;i++) - { - if ((L[i]=="")||(L[i]==MatrixLedbackcolor)) - L[i]=MatrixLedcolor; - else - L[i]=MatrixLedbackcolor; - } - MatrixLed_show(); - } - - function MatrixLed_getcolor(input_x_,input_y_) { - return L[input_x_*5+input_y_]; - } - - function MatrixLed_backcolor(input_color_) { - MatrixLedbackcolor=input_color_; - } - - function MatrixLed_show() { - if (MatrixLedshowstate==1) - var ledtable ="" - + "" - + "" - + "" - + "" - + "" - + "
"; - else - var ledtable ="" - + "" - + "" - + "" - + "" - + "" - + "
"; - - if (document.getElementById("fustyles_matrixled")) - { - document.getElementById("fustyles_matrixled").innerHTML = ledtable; - } - else - { - var div = document.createElement('div'); - div.id = "fustyles_matrixled"; - div.innerHTML = ledtable; - document.body.appendChild(div); - } - } - - window.MatrixLed_clear = MatrixLed_clear; - window.MatrixLed_matrix = MatrixLed_matrix; - window.MatrixLed_matrix_color = MatrixLed_matrix_color; - window.MatrixLed_show = MatrixLed_show; - window.MatrixLed_on = MatrixLed_on; - window.MatrixLed_color_on = MatrixLed_color_on; - window.MatrixLed_off = MatrixLed_off; - window.MatrixLed_reverse = MatrixLed_reverse; - window.MatrixLed_state = MatrixLed_state; - window.MatrixLed_color = MatrixLed_color; - window.MatrixLed_width = MatrixLed_width; - window.MatrixLed_height = MatrixLed_height; - window.MatrixLed_sample = MatrixLed_sample; - window.MatrixLed_code = MatrixLed_code; - window.MatrixLed_marquee = MatrixLed_marquee; - window.MatrixLed_marquee_play = MatrixLed_marquee_play; - window.MatrixLed_marquee_once = MatrixLed_marquee_once; - window.MatrixLed_marquee_once_play = MatrixLed_marquee_once_play; - window.MatrixLed_marquee_color = MatrixLed_marquee_color; - window.MatrixLed_marquee_color_play = MatrixLed_marquee_color_play; - window.MatrixLed_marquee_color_once = MatrixLed_marquee_color_once; - window.MatrixLed_marquee_color_once_play = MatrixLed_marquee_color_once_play; - window.MatrixLed_matrix_codetocolor = MatrixLed_matrix_codetocolor; - window.MatrixLed_marquee_degree = MatrixLed_marquee_degree; - window.MatrixLed_marquee_color_degree = MatrixLed_marquee_color_degree; - window.MatrixLed_marquee_stop = MatrixLed_marquee_stop; - window.MatrixLed_marquee_resume = MatrixLed_marquee_resume; - window.MatrixLed_marquee_reverse = MatrixLed_marquee_reverse; - window.MatrixLed_marquee_time = MatrixLed_marquee_time; - window.MatrixLed_char = MatrixLed_char; - window.MatrixLed_conversion = MatrixLed_conversion; - window.MatrixLed_texttocode = MatrixLed_texttocode; - window.MatrixLed_showstate = MatrixLed_showstate; - window.MatrixLed_indentcode = MatrixLed_indentcode; - window.MatrixLed_linechart = MatrixLed_linechart; - window.MatrixLed_barchart = MatrixLed_barchart; - window.Matrixled_clockwise = Matrixled_clockwise; - window.Matrixled_counterclockwise = Matrixled_counterclockwise; - window.Matrixled_verticalflip = Matrixled_verticalflip; - window.Matrixled_horizontalflip = Matrixled_horizontalflip; - window.Matrixled_invert = Matrixled_invert; - window.MatrixLed_getcolor = MatrixLed_getcolor; - window.MatrixLed_backcolor = MatrixLed_backcolor; - -}(window, window.document)); diff --git a/MatrixLed_20180810/blockly.json b/MatrixLed_20180810/blockly.json deleted file mode 100644 index 080f96b2db..0000000000 --- a/MatrixLed_20180810/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["matrix_led_backcolor","matrix_led_verticalflip","matrix_led_horizontalflip","matrix_led_invert","matrix_led_getcolor","matrix_led_color","matrix_led_width","matrix_led_height","matrix_led_code","matrix_led_texttocode","matrix_led_indentcode","matrix_led_showstate","matrix_led_sample","matrix_led_matrix","matrix_led_matrix_color","matrix_led_matrixcode","matrix_led_matrixcode_line","matrix_led_matrixcode_color","matrix_led_matrixcode_line_color","matrix_led_clear","matrix_led_on","matrix_led_color_on","matrix_led_off","matrix_led_reverse","matrix_led_state","matrix_led_marquee","matrix_led_marquee_once","matrix_led_marquee_color","matrix_led_marquee_color_once","matrix_led_marquee_degree","matrix_led_marquee_color_degree","matrix_led_marquee_time","matrix_led_marquee_stop","matrix_led_marquee_reverse","matrix_led_marquee_resume","matrix_led_char","matrix_led_linechart","matrix_led_barchart","matrix_led_clockwise","matrix_led_counterclockwise"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "matrixled.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/MatrixLed_20180810/blockly/blocks.js b/MatrixLed_20180810/blockly/blocks.js deleted file mode 100644 index 8e2060f04e..0000000000 --- a/MatrixLed_20180810/blockly/blocks.js +++ /dev/null @@ -1,710 +0,0 @@ -Blockly.Blocks['matrix_led_char'] = { - init: function() { - this.appendValueInput("value_char_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_CHAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - - -Blockly.Blocks['matrix_led_texttocode'] = { - init: function() { - this.appendValueInput("value_text_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_indentcode'] = { - init: function() { - this.appendValueInput("value_indentcode_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_INDENTCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_showstate'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW) - .appendField(new Blockly.FieldDropdown([["on","1"], ["off","0"]]), "value_showstate_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_stop'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_resume'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_time'] = { - init: function() { - this.appendValueInput("value_marquee_time_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_sample'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SAMPLE_SHOW) - .appendField(new Blockly.FieldDropdown([["♥","♥"], ["♡","♡"], ["↑","↑"], ["↓","↓"], ["←","←"], ["→","→"], ["↖","↖"], ["↙","↙"], ["↗","↗"], ["↘","↘"], ["▲","▲"], ["▼","▼"], ["◄","◄"], ["►","►"], ["O","O"], ["X","X"], ["V","V"]]), "value_sample_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setTooltip(''); - this.setColour(300); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_code'] = { - init: function() { - this.appendValueInput("value_code_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_CODE_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_width'] = { - init: function() { - this.appendValueInput("value_width_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_WIDTH_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_height'] = { - init: function() { - this.appendValueInput("value_height_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_HEIGHT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L01') - .appendField(new Blockly.FieldColour("#ffffff"), 'L06') - .appendField(new Blockly.FieldColour("#ffffff"), 'L11') - .appendField(new Blockly.FieldColour("#ffffff"), 'L16') - .appendField(new Blockly.FieldColour("#ffffff"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L02') - .appendField(new Blockly.FieldColour("#ffffff"), 'L07') - .appendField(new Blockly.FieldColour("#ffffff"), 'L12') - .appendField(new Blockly.FieldColour("#ffffff"), 'L17') - .appendField(new Blockly.FieldColour("#ffffff"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L03') - .appendField(new Blockly.FieldColour("#ffffff"), 'L08') - .appendField(new Blockly.FieldColour("#ffffff"), 'L13') - .appendField(new Blockly.FieldColour("#ffffff"), 'L18') - .appendField(new Blockly.FieldColour("#ffffff"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L04') - .appendField(new Blockly.FieldColour("#ffffff"), 'L09') - .appendField(new Blockly.FieldColour("#ffffff"), 'L14') - .appendField(new Blockly.FieldColour("#ffffff"), 'L19') - .appendField(new Blockly.FieldColour("#ffffff"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L05') - .appendField(new Blockly.FieldColour("#ffffff"), 'L10') - .appendField(new Blockly.FieldColour("#ffffff"), 'L15') - .appendField(new Blockly.FieldColour("#ffffff"), 'L20') - .appendField(new Blockly.FieldColour("#ffffff"), 'L25') - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; - -Blockly.Blocks['matrix_led_matrixcode'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrixcode_line'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05"); - this.setOutput(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_matrixcode_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L01') - .appendField(new Blockly.FieldColour("#ffffff"), 'L06') - .appendField(new Blockly.FieldColour("#ffffff"), 'L11') - .appendField(new Blockly.FieldColour("#ffffff"), 'L16') - .appendField(new Blockly.FieldColour("#ffffff"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L02') - .appendField(new Blockly.FieldColour("#ffffff"), 'L07') - .appendField(new Blockly.FieldColour("#ffffff"), 'L12') - .appendField(new Blockly.FieldColour("#ffffff"), 'L17') - .appendField(new Blockly.FieldColour("#ffffff"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L03') - .appendField(new Blockly.FieldColour("#ffffff"), 'L08') - .appendField(new Blockly.FieldColour("#ffffff"), 'L13') - .appendField(new Blockly.FieldColour("#ffffff"), 'L18') - .appendField(new Blockly.FieldColour("#ffffff"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L04') - .appendField(new Blockly.FieldColour("#ffffff"), 'L09') - .appendField(new Blockly.FieldColour("#ffffff"), 'L14') - .appendField(new Blockly.FieldColour("#ffffff"), 'L19') - .appendField(new Blockly.FieldColour("#ffffff"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#ffffff"), 'L05') - .appendField(new Blockly.FieldColour("#ffffff"), 'L10') - .appendField(new Blockly.FieldColour("#ffffff"), 'L15') - .appendField(new Blockly.FieldColour("#ffffff"), 'L20') - .appendField(new Blockly.FieldColour("#ffffff"), 'L25') - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; - -Blockly.Blocks['matrix_led_matrixcode_line_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L01') - .appendField(new Blockly.FieldColour("#000000"), 'L02') - .appendField(new Blockly.FieldColour("#000000"), 'L03') - .appendField(new Blockly.FieldColour("#000000"), 'L04') - .appendField(new Blockly.FieldColour("#000000"), 'L05'); - this.setOutput(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_clear'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLEAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COLOR_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.appendValueInput("value_color_on_") - .setCheck("Colour") - .appendField("color"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_off'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_OFF_SHOW); - this.appendValueInput("value_x_off_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_off_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_REVERSE_SHOW); - this.appendValueInput("value_x_reverse_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_reverse_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_state'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_STATE_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_linechart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_LINECHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_barchart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_BARCHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_clockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_counterclockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_verticalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_horizontalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_invert'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_INVERT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_getcolor'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_GETCOLOR_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_backcolor'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/MatrixLed_20180810/blockly/javascript.js b/MatrixLed_20180810/blockly/javascript.js deleted file mode 100644 index 6861e1b352..0000000000 --- a/MatrixLed_20180810/blockly/javascript.js +++ /dev/null @@ -1,351 +0,0 @@ -Blockly.JavaScript['matrix_led_char'] = function(block) { - var value_char_ = Blockly.JavaScript.valueToCode(block, 'value_char_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_char('+ value_char_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_time'] = function(block) { - var value_marquee_time_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_time_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_time('+ value_marquee_time_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_stop'] = function(block) { - var code = 'MatrixLed_marquee_stop();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_resume'] = function(block) { - var code = 'MatrixLed_marquee_resume();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_reverse'] = function(block) { - var code = 'MatrixLed_marquee_reverse();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color('+ value_color_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_texttocode'] = function(block) { - var value_text_ = Blockly.JavaScript.valueToCode(block, 'value_text_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_texttocode('+value_text_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_width'] = function(block) { - var value_width_ = Blockly.JavaScript.valueToCode(block, 'value_width_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_width('+ value_width_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_height'] = function(block) { - var value_height_ = Blockly.JavaScript.valueToCode(block, 'value_height_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_height('+ value_height_ +');'; - return code; -}; - -Blockly.JavaScript['matrix_led_sample'] = function(block) { - var value_sample_ = block.getFieldValue('value_sample_'); - var code = 'MatrixLed_sample("'+ value_sample_ +'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_code'] = function(block) { - var value_code_ = Blockly.JavaScript.valueToCode(block, 'value_code_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_code('+ value_code_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = 'MatrixLed_matrix("'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = 'MatrixLed_matrix_color(["'+L01+'","'+L02+'","'+L03+'","'+L04+'","'+L05+'","'+L06+'","'+L07+'","'+L08+'","'+L09+'","'+L10+'","'+L11+'","'+L12+'","'+L13+'","'+L14+'","'+L15+'","'+L16+'","'+L17+'","'+L18+'","'+L19+'","'+L20+'","'+L21+'","'+L22+'","'+L23+'","'+L24+'","'+L25+'"]);\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrixcode'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_matrixcode_line'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var code = '"'+L01+L02+L03+L04+L05+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_matrixcode_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_matrixcode_line_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var code = '"'+L01+L02+L03+L04+L05+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_clear'] = function(block) { - var code = 'MatrixLed_clear();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_on('+value_x_on_+','+value_y_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_on_ = Blockly.JavaScript.valueToCode(block, 'value_color_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color_on('+value_x_on_+','+value_y_on_+','+value_color_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_off'] = function(block) { - var value_x_off_ = Blockly.JavaScript.valueToCode(block, 'value_x_off_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_off_ = Blockly.JavaScript.valueToCode(block, 'value_y_off_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_off('+value_x_off_+','+value_y_off_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_reverse'] = function(block) { - var value_x_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_x_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_y_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_reverse('+value_x_reverse_+','+value_y_reverse_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_state'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_state('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_showstate'] = function(block) { - var value_showstate_ = block.getFieldValue('value_showstate_'); - var code = 'MatrixLed_showstate('+value_showstate_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_indentcode'] = function(block) { - var value_indentcode_ = Blockly.JavaScript.valueToCode(block, 'value_indentcode_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_indentcode('+value_indentcode_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_linechart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_linechart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_barchart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_barchart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_clockwise'] = function(block) { - var code = 'Matrixled_clockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_counterclockwise'] = function(block) { - var code = 'Matrixled_counterclockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_verticalflip'] = function(block) { - var code = 'Matrixled_verticalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_horizontalflip'] = function(block) { - var code = 'Matrixled_horizontalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_invert'] = function(block) { - var code = 'Matrixled_invert();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_getcolor'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_getcolor('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_backcolor'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_backcolor('+ value_color_ +');\n'; - return code; -}; diff --git a/MatrixLed_20180810/blockly/msg/blocks/en.js b/MatrixLed_20180810/blockly/msg/blocks/en.js deleted file mode 100644 index 5819f698b6..0000000000 --- a/MatrixLed_20180810/blockly/msg/blocks/en.js +++ /dev/null @@ -1,46 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "Matrix Led"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "Matrix Led (Full Color)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "Matrix Led Code"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "Clean Screen"; -Blockly.Msg.MATRIXLED_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "Turn Off"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "Reverse"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "Get Led State"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "Led Color"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "Screen Width"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "Screen Height"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "Show Sample"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "Show Sample By Code"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "Show Marguee(CYCLE)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "Show Marguee(ONCE)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "Marguee Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "Marguee(Full Color) Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " Degree"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "Stop Marguee"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "Resume Marguee"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "Marguee Time (ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "Marguee Reverse"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "Show Character"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "Convert Text To Code"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "Screen Switch"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "Indent Code"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "Line Chart "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "Bar Chart "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "Value1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "Value2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "Value3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "Value4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "Value5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "Rotate 90 Degrees Clockwise"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "Rotate 90 Degrees Counter Clockwise"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "Vertical Flip"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "Horizontal Flip"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "Reverse"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "Get Color Code"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "Back Color"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "Matrix Led(Full Color) Code"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "Show Marguee(Full Color) CYCLE"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "Show Marguee(Full Color) ONCE"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_SHOW = "Matrix Led Add Up A Long Column"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_COLOR_SHOW = "Matrix Led(Full Color) Add Up A Long Column"; diff --git a/MatrixLed_20180810/blockly/msg/blocks/zh-hans.js b/MatrixLed_20180810/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 5e1988fbc2..0000000000 --- a/MatrixLed_20180810/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,46 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示灯(单色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示灯(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示灯(单色) 编码"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示灯 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗灯"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示灯 亮暗反转"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示灯 亮暗状态"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示灯(单色) 颜色"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "指示灯 宽度"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "指示灯 高度"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "显示 图案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "显示 图案(编码)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑马灯(单色) 循环"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑马灯(单色) 单次"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑马灯(单色) 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "跑马灯(全彩) 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格数"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑马灯 暂停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑马灯 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑马灯 间隔时间(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑马灯 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "显示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "转换文字为编码"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示灯 开关"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "缩排编码"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折线图 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "长条图 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "数值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "数值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "数值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "数值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "数值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示灯 顺时钟旋转90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示灯 逆时钟旋转90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示灯 垂直翻转"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示灯 水平翻转"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示灯 亮暗反转"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示灯 色码值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示灯(单色) 背景颜色"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "指示灯(全彩) 编码"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "跑马灯(全彩) 循环"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "跑马灯(全彩) 单次"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_SHOW = "指示灯(单色) 新增纵行"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_COLOR_SHOW = "指示灯(全彩) 新增纵行"; diff --git a/MatrixLed_20180810/blockly/msg/blocks/zh-hant.js b/MatrixLed_20180810/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 05723cd112..0000000000 --- a/MatrixLed_20180810/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,46 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示燈(單色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示燈(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示燈(單色) 編碼"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示燈 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗燈"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示燈 亮暗反轉"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示燈 亮暗狀態"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示燈(單色) 顏色"; -Blockly.Msg.MATRIXLED_WIDTH_SHOW = "指示燈 寬度"; -Blockly.Msg.MATRIXLED_HEIGHT_SHOW = "指示燈 高度"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "顯示 圖案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "顯示 圖案(編碼)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑馬燈(單色) 循環"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑馬燈(單色) 單次"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑馬燈(單色) 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "跑馬燈(全彩) 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格數"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑馬燈 暫停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑馬燈 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑馬燈 間隔時間(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑馬燈 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "顯示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "轉換文字為編碼"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示燈 開關"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "縮排編碼"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折線圖 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "長條圖 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "數值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "數值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "數值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "數值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "數值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示燈 順時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示燈 逆時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示燈 垂直翻轉"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示燈 水平翻轉"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示燈 亮暗反轉"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示燈 色碼值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示燈(單色) 背景顏色"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "指示燈(全彩) 編碼"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "跑馬燈(全彩) 循環"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "跑馬燈(全彩) 單次"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_SHOW = "指示燈(單色) 新增縱行"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_COLOR_SHOW = "指示燈(全彩) 新增縱行"; diff --git a/MatrixLed_20180810/blockly/msg/en.js b/MatrixLed_20180810/blockly/msg/en.js deleted file mode 100644 index 6339d1dd92..0000000000 --- a/MatrixLed_20180810/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "Simulation Matrix Led"; diff --git a/MatrixLed_20180810/blockly/msg/zh-hans.js b/MatrixLed_20180810/blockly/msg/zh-hans.js deleted file mode 100644 index f14896b249..0000000000 --- a/MatrixLed_20180810/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "模拟点矩阵"; diff --git a/MatrixLed_20180810/blockly/msg/zh-hant.js b/MatrixLed_20180810/blockly/msg/zh-hant.js deleted file mode 100644 index 42ab3e44a3..0000000000 --- a/MatrixLed_20180810/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "模擬點矩陣"; diff --git a/MatrixLed_20180810/blockly/toolbox.xml b/MatrixLed_20180810/blockly/toolbox.xml deleted file mode 100644 index 644d6c8b9a..0000000000 --- a/MatrixLed_20180810/blockly/toolbox.xml +++ /dev/null @@ -1,512 +0,0 @@ - - - 1 - - - - - 250 - - - - - - - 250 - - - - - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - - - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - - - #ffffff - #ffffff - #ffffff - #ffffff - #ffffff - - - - - 0 - - - - - 0 - - - - - #ff0000 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - 500 - - - - - - - - - - - - - - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - - - - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - - - 1 - - - 1 - - - - - - - - - - - - - #ffffff - - - - - - - #ff0000 - - - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - FALSE - FALSE - FALSE - FALSE - FALSE - - - - - - - - - - - - - - - 0110011110011111111001100 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - 1 - - - 1 - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - diff --git a/MatrixLed_20180810/matrixled.js b/MatrixLed_20180810/matrixled.js deleted file mode 100644 index 16cdb2bff2..0000000000 --- a/MatrixLed_20180810/matrixled.js +++ /dev/null @@ -1,808 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - const charA = "0111110010100101001001111"; - const charB = "1111110101101011010101010"; - const charC = "0111010001100011000110001"; - const charD = "1111110001100011000101110"; - const charE = "1111110101101011010110101"; - const charF = "1111110100101001010010100"; - const charG = "0111010001101011010110111"; - const charH = "1111100100001000010011111"; - const charI = "1000110001111111000110001"; - const charJ = "1001110001111111000010000"; - const charK = "1111100010001000101010001"; - const charL = "1111100001000010000100001"; - const charM = "1111101000001000100011111"; - const charN = "1111101000001000001011111"; - const charO = "0111010001100011000101110"; - const charP = "1111110010100101001001100"; - const charQ = "0111010001101011001001101"; - const charR = "1111110100101001010001011"; - const charS = "0100110101101011010110010"; - const charT = "1000010000111111000010000"; - const charU = "1111000001000010000111110"; - const charV = "1110000010000010001011100"; - const charW = "1111000001111100000111110"; - const charX = "1000101010001000101010001"; - const charY = "1000001000001110100010000"; - const charZ = "1000110011101011100110001"; - const chara = "0000000110010010011000001"; - const charb = "0000011111001010001000000"; - const charc = "0000000110010010100100000"; - const chard = "0000000010001011111100000"; - const chare = "0000000110010110010100000"; - const charf = "0000000100111111010000000"; - const charg = "0000000101010110011000000"; - const charh = "0000011111001000001100000"; - const chari = "0000000000101110000000000"; - const charj = "0000000001101110000000000"; - const chark = "0000011111000100010100000"; - const charl = "0000000000111110000000000"; - const charm = "0011100100000110010000011"; - const charn = "0000000111001000001100000"; - const charo = "0000000010001010001000000"; - const charp = "0000001111010100010000000"; - const charq = "0000000100010100111100000"; - const charr = "0000000111000100010000000"; - const chars = "0000001001101011001000000"; - const chart = "0000000100011110010100000"; - const charu = "0000000110000010011000001"; - const charv = "0000000110000010011000000"; - const charw = "0011000001001100000100110"; - const charx = "0000000101000100010100000"; - const chary = "0000000101000100010000000"; - const charz = "0000101011011010100000000"; - const char0 = "0000011111100011111100000"; - const char1 = "0000001001111110000100000"; - const char2 = "0000010111101011110100000"; - const char3 = "0000010101101011111100000"; - const char4 = "0000011100001001111100000"; - const char5 = "0000011101101011011100000"; - const char6 = "0000011111101011011100000"; - const char7 = "0000011000100001111100000"; - const char8 = "0000011111101011111100000"; - const char9 = "0000011101101011111100000"; - const comma = "0000000001000100000000000"; - const period = "0000000001000000000000000"; - const questionmark = "0100010000100111010001000"; - const exclamationmark = "0000000000111010000000000"; - const semicolon = "0000000001010100000000000"; - const colon = "0000000000010100000000000"; - const parenthesesleft = "0000001110100010000000000"; - const parenthesesright = "0000000000100010111000000"; - const squarebracketsleft = "0000011111100010000000000"; - const squarebracketsright = "0000000000100011111100000"; - const curlybracketsleft = "0000000100111111000100000"; - const curlybracketsright = "0000010001111110010000000"; - const Quotationmarkssingle = "0000000000110000010000000"; - const Quotationmarksdouble = "1100000100110000010000000"; - const hyphen = "0000000100001000010000000"; - const heart = "0110010010010011001001100"; - const heartfill = "0110011110011111111001100"; - const arrowup = "0010001000111110100000100"; - const arrowdown = "0010000010111110001000100"; - const arrowleft = "0010001110101010010000100"; - const arrowright = "0010000100101010111000100"; - const arrowleftup = "1111011000101001001000001"; - const arrowleftdown = "0111100011001010100110000"; - const arrowrightup = "0000110010101001100011110"; - const arrowrightdown = "1000001001001010001101111"; - const arrowupfill = "0000100111111110011100001"; - const arrowdownfill = "1000011100111111110010000"; - const arrowleftfill = "0010000100011100111011111"; - const arrowrightfill = "1111101110011100010000100"; - const noexist = "0000000000000000000000000"; - - var L = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var MatrixLedcolor = "#ff0000"; - var MatrixLedbackcolor = "#ffffff"; - var MatrixLedwidth = 250; - var MatrixLedheight = 250; - var MatrixLedmarqueeinitial = "",MatrixLedmarqueecode = "",MatrixLedmarqueecodeonce = "",MatrixLedmarqueecolorcode = "",MatrixLedmarqueecolorcodeonce = ""; - var MatrixLedmarqueetime = 500; - var MatrixLedmarqueereverse = 1; - var MatrixLedshowstate = 1; - var marqueetimeid; - var marqueeactive; - - function MatrixLed_color(input_color_) { - MatrixLedcolor = input_color_; - } - - function MatrixLed_width(input_width_) { - MatrixLedwidth = input_width_; - } - - function MatrixLed_height(input_height_) { - MatrixLedheight = input_height_; - } - - function MatrixLed_showstate(input_showstate_) { - MatrixLedshowstate = input_showstate_; - } - - function MatrixLed_indentcode(input_indentcode_) { - var indentcode = input_indentcode_; - while (indentcode.search(/0000000000/)!=-1) - indentcode = indentcode.replace(/0000000000/g,"00000"); - return indentcode; - } - - function MatrixLed_marquee(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecodeonce = ""; - window.clearInterval(marqueetimeid); - if ((input_marquee_.length==25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLed_matrix(input_marquee_); - return; - } - else if ((input_marquee_.length%5==0)&&(input_marquee_.length>25)&&(input_marquee_.search(/[^0-1]/)==-1)) - MatrixLedmarqueecode = input_marquee_; - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLedmarqueecode = input_marquee_; - MatrixLedmarqueecodeonce = input_marquee_; - } - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_once_play() { - if (MatrixLedmarqueecode.length>=25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(5,MatrixLedmarqueecodeonce.length-5)+MatrixLedmarqueecodeonce.substr(0,5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(MatrixLedmarqueecodeonce.length-5,5)+MatrixLedmarqueecodeonce.substr(0,MatrixLedmarqueecodeonce.length-5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_degree(direction,degree) { - window.clearInterval(marqueetimeid); - if (MatrixLedmarqueecode.length25) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - } - } - - function MatrixLed_marquee_color(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecolorcodeonce = ""; - window.clearInterval(marqueetimeid); - if (input_marquee_.length==175) - { - MatrixLed_matrix_codetocolor(input_marquee_); - return; - } - else if ((input_marquee_.length%35==0)&&(input_marquee_.length>175)) - MatrixLedmarqueecolorcode = input_marquee_; - MatrixLedmarqueeinitial=MatrixLedmarqueecolorcode; - marqueeactive=3; - marqueetimeid = window.setInterval("MatrixLed_marquee_color_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_color_once(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueeinitial=input_marquee_; - window.clearInterval(marqueetimeid); - if (input_marquee_.length==175) - { - MatrixLed_matrix_codetocolor(input_marquee_); - return; - } - else if ((input_marquee_.length%35==0)&&(input_marquee_.length>175)) - { - MatrixLedmarqueecolorcode = input_marquee_; - MatrixLedmarqueecolorcodeonce = input_marquee_; - } - MatrixLedmarqueeinitial=MatrixLedmarqueecolorcode; - marqueeactive=4; - marqueetimeid = window.setInterval("MatrixLed_marquee_color_once_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_color_play() { - if (MatrixLedmarqueecolorcode.length>175) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35)+MatrixLedmarqueecolorcode.substr(0,35); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-175,175)); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-35,35)+MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_color_once_play() { - if (MatrixLedmarqueecolorcode.length>=175) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueecolorcodeonce.substr(35,MatrixLedmarqueecolorcodeonce.length-35)+MatrixLedmarqueecolorcodeonce.substr(0,35); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-175,175)); - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueecolorcodeonce.substr(MatrixLedmarqueecolorcodeonce.length-35,35)+MatrixLedmarqueecolorcodeonce.substr(0,MatrixLedmarqueecolorcodeonce.length-35); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_color_degree(direction,degree) { - window.clearInterval(marqueetimeid); - if (MatrixLedmarqueecolorcode.length175) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35)+MatrixLedmarqueecolorcode.substr(0,35); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-35,35)+MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - } - } - - function MatrixLed_marquee_time(input_time_) { - MatrixLedmarqueetime = input_time_; - } - - function MatrixLed_marquee_stop() { - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_resume() { - window.clearInterval(marqueetimeid); - if (marqueeactive==1) - marqueetimeid = window.setInterval("MatrixLed_marquee_play()",MatrixLedmarqueetime); - else if (marqueeactive==2) - marqueetimeid = window.setInterval("MatrixLed_marquee_once_play()",MatrixLedmarqueetime); - else if (marqueeactive==3) - marqueetimeid= window.setInterval("MatrixLed_marquee_color_play()",MatrixLedmarqueetime); - else if (marqueeactive==4) - marqueetimeid = window.setInterval("MatrixLed_marquee_color_once_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_reverse() { - MatrixLedmarqueecode = MatrixLedmarqueeinitial; - MatrixLedmarqueecodeonce = MatrixLedmarqueeinitial; - MatrixLedmarqueecolorcode = MatrixLedmarqueeinitial; - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueeinitial; - if (MatrixLedmarqueereverse==1) - MatrixLedmarqueereverse=2; - else if (MatrixLedmarqueereverse==2) - MatrixLedmarqueereverse=1; - } - - function MatrixLed_char(input_char_) { - input_char_=input_char_.toString(); - if (input_char_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_char_)); - } - } - - function MatrixLed_texttocode(input_text_) { - input_text_=input_text_.toString(); - if (input_text_.length>0) - { - var textcode=""; - for (var i=0;i=(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function Matrixled_clockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_counterclockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_verticalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[j+5*i]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_horizontalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[j+i*5]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_invert(){ - for (var i=0;i<25;i++) - { - if ((L[i]=="")||(L[i]==MatrixLedbackcolor)) - L[i]=MatrixLedcolor; - else - L[i]=MatrixLedbackcolor; - } - MatrixLed_show(); - } - - function MatrixLed_getcolor(input_x_,input_y_) { - return L[input_x_*5+input_y_]; - } - - function MatrixLed_backcolor(input_color_) { - MatrixLedbackcolor=input_color_; - } - - function MatrixLed_show() { - if (MatrixLedshowstate==1) - var ledtable ="" - + "" - + "" - + "" - + "" - + "" - + "
"; - else - var ledtable ="" - + "" - + "" - + "" - + "" - + "" - + "
"; - - if (document.getElementById("fustyles_matrixled")) - { - document.getElementById("fustyles_matrixled").innerHTML = ledtable; - } - else - { - var div = document.createElement('div'); - div.id = "fustyles_matrixled"; - div.innerHTML = ledtable; - document.body.appendChild(div); - } - } - - window.MatrixLed_clear = MatrixLed_clear; - window.MatrixLed_matrix = MatrixLed_matrix; - window.MatrixLed_matrix_color = MatrixLed_matrix_color; - window.MatrixLed_show = MatrixLed_show; - window.MatrixLed_on = MatrixLed_on; - window.MatrixLed_color_on = MatrixLed_color_on; - window.MatrixLed_off = MatrixLed_off; - window.MatrixLed_reverse = MatrixLed_reverse; - window.MatrixLed_state = MatrixLed_state; - window.MatrixLed_color = MatrixLed_color; - window.MatrixLed_width = MatrixLed_width; - window.MatrixLed_height = MatrixLed_height; - window.MatrixLed_sample = MatrixLed_sample; - window.MatrixLed_code = MatrixLed_code; - window.MatrixLed_marquee = MatrixLed_marquee; - window.MatrixLed_marquee_play = MatrixLed_marquee_play; - window.MatrixLed_marquee_once = MatrixLed_marquee_once; - window.MatrixLed_marquee_once_play = MatrixLed_marquee_once_play; - window.MatrixLed_marquee_color = MatrixLed_marquee_color; - window.MatrixLed_marquee_color_play = MatrixLed_marquee_color_play; - window.MatrixLed_marquee_color_once = MatrixLed_marquee_color_once; - window.MatrixLed_marquee_color_once_play = MatrixLed_marquee_color_once_play; - window.MatrixLed_matrix_codetocolor = MatrixLed_matrix_codetocolor; - window.MatrixLed_marquee_degree = MatrixLed_marquee_degree; - window.MatrixLed_marquee_color_degree = MatrixLed_marquee_color_degree; - window.MatrixLed_marquee_stop = MatrixLed_marquee_stop; - window.MatrixLed_marquee_resume = MatrixLed_marquee_resume; - window.MatrixLed_marquee_reverse = MatrixLed_marquee_reverse; - window.MatrixLed_marquee_time = MatrixLed_marquee_time; - window.MatrixLed_char = MatrixLed_char; - window.MatrixLed_conversion = MatrixLed_conversion; - window.MatrixLed_texttocode = MatrixLed_texttocode; - window.MatrixLed_showstate = MatrixLed_showstate; - window.MatrixLed_indentcode = MatrixLed_indentcode; - window.MatrixLed_linechart = MatrixLed_linechart; - window.MatrixLed_barchart = MatrixLed_barchart; - window.Matrixled_clockwise = Matrixled_clockwise; - window.Matrixled_counterclockwise = Matrixled_counterclockwise; - window.Matrixled_verticalflip = Matrixled_verticalflip; - window.Matrixled_horizontalflip = Matrixled_horizontalflip; - window.Matrixled_invert = Matrixled_invert; - window.MatrixLed_getcolor = MatrixLed_getcolor; - window.MatrixLed_backcolor = MatrixLed_backcolor; - -}(window, window.document)); diff --git a/README.md b/README.md deleted file mode 100644 index 1835dc36b5..0000000000 --- a/README.md +++ /dev/null @@ -1,37 +0,0 @@ -## Welcome to GitHub Pages - -You can use the [editor on GitHub](https://github.com/fustyles/webduino/edit/master/README.md) to maintain and preview the content for your website in Markdown files. - -Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files. - -### Markdown - -Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for - -```markdown -Syntax highlighted code block - -# Header 1 -## Header 2 -### Header 3 - -- Bulleted -- List - -1. Numbered -2. List - -**Bold** and _Italic_ and `Code` text - -[Link](url) and ![Image](src) -``` - -For more details see [GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/). - -### Jekyll Themes - -Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/fustyles/webduino/settings). The name of this theme is saved in the Jekyll `_config.yml` configuration file. - -### Support or Contact - -Having trouble with Pages? Check out our [documentation](https://help.github.com/categories/github-pages-basics/) or [contact support](https://github.com/contact) and we’ll help you sort it out. diff --git a/RGB_LED_20180219/blockly.json b/RGB_LED_20180219/blockly.json deleted file mode 100644 index 59a58de196..0000000000 --- a/RGB_LED_20180219/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["rgb_led"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "rgb_led.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/RGB_LED_20180219/blockly/blocks.js b/RGB_LED_20180219/blockly/blocks.js deleted file mode 100644 index 49f2c60f7d..0000000000 --- a/RGB_LED_20180219/blockly/blocks.js +++ /dev/null @@ -1,28 +0,0 @@ -Blockly.Blocks['rgb_led'] = { - init: function() { - this.appendValueInput("VALUE_RED") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TITLE_SHOW) - .appendField(Blockly.Msg.RED_SHOW) - .appendField(new Blockly.FieldDropdown([["3","3"], ["5","5"], ["6","6"], ["9","9"], ["10","10"], ["11","11"], ["12","12"], ["13","13"], ["15","15"]]), "PIN_RED") - .appendField(Blockly.Msg.VALE_RED_SHOW); - this.appendValueInput("VALUE_GREEN") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.GREEN_SHOW) - .appendField(new Blockly.FieldDropdown([["3","3"], ["5","5"], ["6","6"], ["9","9"], ["10","10"], ["11","11"], ["12","12"], ["13","13"], ["15","15"]]), "PIN_GREEN") - .appendField(Blockly.Msg.VALUE_GREEN_SHOW); - this.appendValueInput("VALUE_BLUE") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.BLUE_SHOW) - .appendField(new Blockly.FieldDropdown([["3","3"], ["5","5"], ["6","6"], ["9","9"], ["10","10"], ["11","11"], ["12","12"], ["13","13"], ["15","15"]]), "PIN_BLUE") - .appendField(Blockly.Msg.VALUE_BLUE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(330); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/RGB_LED_20180219/blockly/javascript.js b/RGB_LED_20180219/blockly/javascript.js deleted file mode 100644 index 42627bcbc1..0000000000 --- a/RGB_LED_20180219/blockly/javascript.js +++ /dev/null @@ -1,22 +0,0 @@ -Blockly.JavaScript['rgb_led'] = function(block) { - var pin_red = block.getFieldValue('PIN_RED'); - var value_red = Blockly.JavaScript.valueToCode(block, 'VALUE_RED', Blockly.JavaScript.ORDER_ATOMIC); - var pin_green = block.getFieldValue('PIN_GREEN'); - var value_green = Blockly.JavaScript.valueToCode(block, 'VALUE_GREEN', Blockly.JavaScript.ORDER_ATOMIC); - var pin_blue = block.getFieldValue('PIN_BLUE'); - var value_blue = Blockly.JavaScript.valueToCode(block, 'VALUE_BLUE', Blockly.JavaScript.ORDER_ATOMIC); - - Blockly.JavaScript.definitions_['var_rgbled_pin'] = 'var ledred,ledgreen,ledblue;'; - - var code = 'ledred = getPin(board, '+pin_red+');\n'+ - 'ledred.setMode(3);\n'+ - 'ledred.write('+value_red+');\n'+ - 'ledgreen = getPin(board, '+pin_green+');\n'+ - 'ledgreen.setMode(3);\n'+ - 'ledgreen.write('+value_green+');\n'+ - 'ledblue = getPin(board, '+pin_blue+');\n'+ - 'ledblue.setMode(3);\n'+ - 'ledblue.write('+value_blue+');\n'+ - 'funRGB_LED('+pin_red+','+value_red+','+pin_green+','+value_green+','+pin_blue+','+value_blue+');\n'; - return code; -}; diff --git a/RGB_LED_20180219/blockly/msg/blocks/en.js b/RGB_LED_20180219/blockly/msg/blocks/en.js deleted file mode 100644 index ac516d4223..0000000000 --- a/RGB_LED_20180219/blockly/msg/blocks/en.js +++ /dev/null @@ -1,7 +0,0 @@ -Blockly.Msg.TITLE_SHOW = "RGB LED "; -Blockly.Msg.RED_SHOW = "RED"; -Blockly.Msg.VALE_RED_SHOW = "VALUE"; -Blockly.Msg.GREEN_SHOW = "GREEN"; -Blockly.Msg.VALUE_GREEN_SHOW = "VALUE"; -Blockly.Msg.BLUE_SHOW = "BLUE"; -Blockly.Msg.VALUE_BLUE_SHOW = "VALUE"; diff --git a/RGB_LED_20180219/blockly/msg/blocks/zh-hans.js b/RGB_LED_20180219/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 3b25e93094..0000000000 --- a/RGB_LED_20180219/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,7 +0,0 @@ -Blockly.Msg.TITLE_SHOW = "RGB LED "; -Blockly.Msg.RED_SHOW = "红"; -Blockly.Msg.VALE_RED_SHOW = "数值"; -Blockly.Msg.GREEN_SHOW = "绿"; -Blockly.Msg.VALUE_GREEN_SHOW = "数值"; -Blockly.Msg.BLUE_SHOW = "蓝"; -Blockly.Msg.VALUE_BLUE_SHOW = "数值"; diff --git a/RGB_LED_20180219/blockly/msg/blocks/zh-hant.js b/RGB_LED_20180219/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 5bbb00034c..0000000000 --- a/RGB_LED_20180219/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,7 +0,0 @@ -Blockly.Msg.TITLE_SHOW = "RGB LED "; -Blockly.Msg.RED_SHOW = "紅"; -Blockly.Msg.VALE_RED_SHOW = "數值"; -Blockly.Msg.GREEN_SHOW = "綠"; -Blockly.Msg.VALUE_GREEN_SHOW = "數值"; -Blockly.Msg.BLUE_SHOW = "藍"; -Blockly.Msg.VALUE_BLUE_SHOW = "數值"; diff --git a/RGB_LED_20180219/blockly/msg/en.js b/RGB_LED_20180219/blockly/msg/en.js deleted file mode 100644 index 193dbf795b..0000000000 --- a/RGB_LED_20180219/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catrgbled = "RGB LED"; diff --git a/RGB_LED_20180219/blockly/msg/zh-hans.js b/RGB_LED_20180219/blockly/msg/zh-hans.js deleted file mode 100644 index 193dbf795b..0000000000 --- a/RGB_LED_20180219/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catrgbled = "RGB LED"; diff --git a/RGB_LED_20180219/blockly/msg/zh-hant.js b/RGB_LED_20180219/blockly/msg/zh-hant.js deleted file mode 100644 index 193dbf795b..0000000000 --- a/RGB_LED_20180219/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catrgbled = "RGB LED"; diff --git a/RGB_LED_20180219/blockly/toolbox.xml b/RGB_LED_20180219/blockly/toolbox.xml deleted file mode 100644 index 241a2073f4..0000000000 --- a/RGB_LED_20180219/blockly/toolbox.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - 3 - 5 - 6 - - - 0 - - - - - 0 - - - - - 0 - - - - diff --git a/RGB_LED_20180219/rgb_led.js b/RGB_LED_20180219/rgb_led.js deleted file mode 100644 index 8e8f614b97..0000000000 --- a/RGB_LED_20180219/rgb_led.js +++ /dev/null @@ -1,15 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - - function funRGB_LED(pin_red,value_red,pin_green,value_green,pin_blue,value_blue) - { - console.log(pin_red+','+value_red+','+pin_green+','+value_green+','+pin_blue+','+value_blue); - } - - window.funRGB_LED = funRGB_LED; - -}(window, window.document)); diff --git a/SendCapturedImageByGmail_doPost.gs b/SendCapturedImageByGmail_doPost.gs new file mode 100644 index 0000000000..5fec08bd64 --- /dev/null +++ b/SendCapturedImageByGmail_doPost.gs @@ -0,0 +1,35 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2019/9/28 12:00 +https://www.facebook.com/francefu +*/ + +function doPost(e) { + var myRecipient = decodeURIComponent(e.parameter.myRecipient); + var mySubject = decodeURIComponent(e.parameter.mySubject); + var myBody = new Date().toString(); + var myFile = e.parameter.myFile; + + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, "esp32-cam.jpg"); + + // Send a photo as an attachment by using Gmail + var response = GmailApp.sendEmail(myRecipient, mySubject, myBody,{ + attachments: [blob], + name: 'Automatic Emailer Script' + } + ); + + // Save the photo to Google Drive + var folder, folders = DriveApp.getFoldersByName("ESP32-CAM"); + if (folders.hasNext()) { + folder = folders.next(); + } else { + folder = DriveApp.createFolder("ESP32-CAM"); + } + var file = folder.createFile(blob); + file.setDescription("Uploaded by ESP32-CAM"); + + return ContentService.createTextOutput(response); +} diff --git a/SendCapturedImageToGoogleDriveAndLinenotify_doGet.gs b/SendCapturedImageToGoogleDriveAndLinenotify_doGet.gs new file mode 100644 index 0000000000..9677526f4b --- /dev/null +++ b/SendCapturedImageToGoogleDriveAndLinenotify_doGet.gs @@ -0,0 +1,50 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2019/6/22 15:30 +https://www.facebook.com/francefu +*/ + +function doGet(e) { + var myFoldername = e.parameter.myFoldername; + var myFile = e.parameter.myFile; + //var myFilename = e.parameter.myFilename; + var myFilename = Utilities.formatDate(new Date(), "GMT", "yyyyMMddHHmmss")+"-"+e.parameter.myFilename; + var myToken = e.parameter.myToken; + + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, myFilename); + + // Save a captured image to Google Drive. + var folder, folders = DriveApp.getFoldersByName(myFoldername); + if (folders.hasNext()) { + folder = folders.next(); + } else { + folder = DriveApp.createFolder(myFoldername); + } + var file = folder.createFile(blob); + file.setDescription("Uploaded by " + myFilename); + + var imageID = file.getUrl().substring(file.getUrl().indexOf("/d/")+3,file.getUrl().indexOf("view")-1); + var imageUrl = "https://drive.google.com/uc?authuser=0&id="+imageID; + + // Send a link message to Line Notify. + var res = "Line Notify: "; + try { + var url = 'https://notify-api.line.me/api/notify'; + var response = UrlFetchApp.fetch(url, { + 'headers': { + 'Authorization': 'Bearer ' + myToken, + }, + 'method': 'post', + 'payload': { + 'message': imageUrl + } + }); + res += response.getContentText(); + } catch(error) { + res += error; + } + + return ContentService.createTextOutput(myFoldername+"/"+myFilename+"\n"+imageUrl+"\n"+res); +} diff --git a/SendCapturedImageToGoogleDriveAndLinenotify_doPost.gs b/SendCapturedImageToGoogleDriveAndLinenotify_doPost.gs new file mode 100644 index 0000000000..f83333bbcf --- /dev/null +++ b/SendCapturedImageToGoogleDriveAndLinenotify_doPost.gs @@ -0,0 +1,95 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2024/11/10 22:30 +https://www.facebook.com/francefu +*/ + +function doPost(e) { + //Taiwan is in the GMT+8 time zone. You need to modify the parameter value from "GMT" to "GMT+8". + var currentTime = Utilities.formatDate(new Date(), "GMT", "yyyy/MM/dd HH:mm:ss"); + var myFoldername = decodeURIComponent(e.parameter.myFoldername)||Utilities.formatDate(new Date(), "GMT", "yyyyMMdd"); + var myFilename = decodeURIComponent(e.parameter.myFilename) + "_" + Utilities.formatDate(new Date(), "GMT", "yyyyMMddHHmmss"); + var myFile = e.parameter.myFile; + var myLineType = e.parameter.myLineType||""; + var myToken = decodeURIComponent(e.parameter.myToken)||""; + var myUserID = decodeURIComponent(e.parameter.myUserID)||""; + + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, myFilename); + + var folder, folders = DriveApp.getFoldersByName(myFoldername); + if (folders.hasNext()) { + folder = folders.next(); + } else { + folder = DriveApp.createFolder(myFoldername); + } + var file = folder.createFile(blob); + file.setDescription("Uploaded by " + myFilename); + + var imageID = file.getUrl().substring(file.getUrl().indexOf("/d/")+3,file.getUrl().indexOf("view")-1); + var imageUrl = "https://drive.google.com/uc?authuser=0&id="+imageID; + var imageThumbnailUrl = "https://drive.google.com/thumbnail?id="+imageID; + var message = currentTime+'\n'+imageUrl; + + if (myLineType=="bot") + LineBotMessageImage(myToken, myUserID, message, imageThumbnailUrl, imageUrl); + else if (myLineType=="notify"||myToken) + LineNotifyMessageImage(myToken, message, imageThumbnailUrl, imageUrl); + + return ContentService.createTextOutput(imageUrl); +} + +function LineNotifyMessageImage(token, message, imageThumbnail, imageFullsize) { + var res = "Line Notify: "; + try { + var url = 'https://notify-api.line.me/api/notify'; + var response = UrlFetchApp.fetch(url, { + 'headers': { + 'Authorization': 'Bearer ' + token, + }, + 'method': 'post', + 'payload': { + 'message': message, + 'imageThumbnail': imageThumbnail, + 'imageFullsize': imageFullsize + } + }); + res += response.getContentText(); + } catch(error) { + res += error; + } + return res; +} + +function LineBotMessageImage(token, userID, message, imageThumbnail, imageFullsize) { + var res = "Line Bot: "; + try { + var url = 'https://api.line.me/v2/bot/message/push'; + var response = UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + token, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'to': userID, + 'messages': [ + { + type:'text', + text: message + }, + { + type:'image', + originalContentUrl: imageFullsize, + previewImageUrl: imageThumbnail + } + ] + }) + }); + res += response.getContentText(); + } catch(error) { + res += error; + } + return res; +} diff --git a/SendCapturedImageToGoogleSpreadsheet_base64_doPost.gs b/SendCapturedImageToGoogleSpreadsheet_base64_doPost.gs new file mode 100644 index 0000000000..9b7e935ccc --- /dev/null +++ b/SendCapturedImageToGoogleSpreadsheet_base64_doPost.gs @@ -0,0 +1,54 @@ +/* + Author : ChungYi Fu (Kaohsiung, Taiwan) 2022/7/22 20:00 + https://www.facebook.com/francefu +*/ + +function doPost(e) { + var myFile = e.parameter.file; + var mySpreadsheeturl = decodeURIComponent(e.parameter.spreadsheeturl); + var mySpreadsheetname = decodeURIComponent(e.parameter.spreadsheetname); + var myDatetime = e.parameter.datetime; + var myPosition = e.parameter.position; + var myColumn = e.parameter.column; + var myRow = e.parameter.row; + var myDate = Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd"); + var myTime = Utilities.formatDate(new Date(), "GMT+8", "HH:mm:ss"); + var myDatetimeRow = 1; + + var ss = SpreadsheetApp.openByUrl(mySpreadsheeturl) + var sheet = ss.getSheetByName(mySpreadsheetname); + var lastRow = sheet.getLastRow(); + + if (myPosition=="custom") { + myDatetimeRow = myRow; + sheet.getRange(myRow, myColumn).setValue(myFile); + } else if (myPosition=="first") { + myDatetimeRow = 1; + sheet.getRange(1, myColumn).setValue(myFile); + } else if (myPosition=="second") { + myDatetimeRow = 2; + sheet.getRange(2, myColumn).setValue(myFile); + } else if (myPosition=="insertfirst") { + sheet.insertRowsBefore(1, 1); + myDatetimeRow = 1; + sheet.getRange(1, myColumn).setValue(myFile); + } else if (myPosition=="last") { + myDatetimeRow = lastRow; + sheet.getRange(lastRow, myColumn).setValue(myFile); + } else if (myPosition=="insertlast") { + myDatetimeRow = lastRow+1; + sheet.getRange(lastRow+1, myColumn).setValue(myFile); + } + + if (myDatetime=="gmt_datetime") { + sheet.getRange(myDatetimeRow, 1).setValue(myDate); + sheet.getRange(myDatetimeRow, 2).setValue(myTime); + } + else if (myDatetime=="gmt_date") { + sheet.getRange(myDatetimeRow, 1).setValue(myDate); + } + else if (myDatetime=="gmt_time") { + sheet.getRange(myDatetimeRow, 1).setValue(myTime); + } + return ContentService.createTextOutput("ok"); +} diff --git a/SendCapturedImageToGoogleSpreadsheet_doPost.gs b/SendCapturedImageToGoogleSpreadsheet_doPost.gs new file mode 100644 index 0000000000..730d9a0f69 --- /dev/null +++ b/SendCapturedImageToGoogleSpreadsheet_doPost.gs @@ -0,0 +1,29 @@ +/* + Author : ChungYi Fu (Kaohsiung, Taiwan) 2020/5/17 11:00 + https://www.facebook.com/francefu +*/ + +function doPost(e) { + var myFile = e.parameter.myFile; + var myFilename = Utilities.formatDate(new Date(), "GMT", "yyyyMMddHHmmss")+"_"+e.parameter.myFilename; + var mySpreadsheet = e.parameter.mySpreadsheet; + var myCellRow = e.parameter.myCellRow; + var myCellCol = e.parameter.myCellCol; + + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, myFilename); + + var ss = SpreadsheetApp.openByUrl('https://docs.google.com'+mySpreadsheet) + ss.getActiveSheet().setHiddenGridlines(true); + var sheet = ss.getSheets()[0]; + sheet.insertImage(blob, myCellRow, myCellCol); + + var images = sheet.getImages(); + while (images.length>2) { + images[0].remove(); + } + + return ContentService.createTextOutput("ok"); +} diff --git a/SendCapturedImageToLineNotify.gs b/SendCapturedImageToLineNotify.gs new file mode 100644 index 0000000000..64de56d795 --- /dev/null +++ b/SendCapturedImageToLineNotify.gs @@ -0,0 +1,36 @@ +function doPost(e) { + var myFile = e.parameter.myFile; + var myFilename = e.parameter.myFilename; + var myToken = e.parameter.myToken; + + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, myFilename); + + var message = myFilename; + var boundary = "------------------------------"; + var imageData = Utilities.newBlob( + "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"message\"; \r\n\r\n" + message + "\r\n" + + "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"imageFile\"; filename=\"" + myFilename + "\"\r\n" + + "Content-Type: " + 'image/jpeg' +"\r\n\r\n" + ).getBytes(); + imageData = imageData.concat(blob.getBytes()); + imageData = imageData.concat(Utilities.newBlob("\r\n--" + boundary + "--\r\n").getBytes()); + + sendImagetoLineNotify(imageData, myToken, boundary); + + return ContentService.createTextOutput("Return = OK"); +} + +function sendImagetoLineNotify(imageData, token, boundary){ + var options = { + "method" : "post", + "contentType" : "multipart/form-data; boundary=" + boundary, + "payload" : imageData, + "headers" : {"Authorization" : "Bearer " + token} + }; + UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options); +} \ No newline at end of file diff --git a/SendCapturedImageToMySQL_doPost.gs b/SendCapturedImageToMySQL_doPost.gs new file mode 100644 index 0000000000..a7cd4cb9aa --- /dev/null +++ b/SendCapturedImageToMySQL_doPost.gs @@ -0,0 +1,39 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2019/9/29 23:00 +https://www.facebook.com/francefu +*/ + +function doPost(e) { + + var dbHost = decodeURIComponent(e.parameter.dbHost); + var dbPort = decodeURIComponent(e.parameter.dbPort); + var dbUser = decodeURIComponent(e.parameter.dbUser); + var dbPassword = decodeURIComponent(e.parameter.dbPassword); + var databaseName = decodeURIComponent(e.parameter.databaseName); + var tableName = decodeURIComponent(e.parameter.tableName); + var columnName = decodeURIComponent(e.parameter.columnName); + var myFile = e.parameter.myFile; + + // Save the photo to MySQL + var conn = Jdbc.getConnection("jdbc:mysql://"+dbHost+":"+dbPort+"/"+databaseName, dbUser, dbPassword); + var insert_sql = "INSERT INTO "+tableName+" ("+columnName+") VALUES ('"+myFile+"')"; + conn.createStatement().execute(insert_sql); + if (conn!=null) conn.close(); + + // Save the photo to Google Drive + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, "esp32-cam.jpg"); + + var folder, folders = DriveApp.getFoldersByName("ESP32-CAM"); + if (folders.hasNext()) { + folder = folders.next(); + } else { + folder = DriveApp.createFolder("ESP32-CAM"); + } + var file = folder.createFile(blob); + file.setDescription("Uploaded by ESP32-CAM"); + + return ContentService.createTextOutput("ok"); +} \ No newline at end of file diff --git a/SendCapturedImageToSpreadsheet_base64_doPost.gs b/SendCapturedImageToSpreadsheet_base64_doPost.gs new file mode 100644 index 0000000000..90f3335b9d --- /dev/null +++ b/SendCapturedImageToSpreadsheet_base64_doPost.gs @@ -0,0 +1,156 @@ +/* + Author : ChungYi Fu (Kaohsiung, Taiwan) 2025/4/1 11:30 + https://www.facebook.com/francefu +*/ + +var cellWidth = 160; //預設插入影像儲存格寬度 +var cellHeight = 120; //預設插入影像儲存格高度 +var myFoldername = "spreadsheet_images"; //預設Google雲端硬碟建立資料夾名稱,須設定"知道連結者有檢視權限"才能在試算表連結顯示影像。 +var linebotToken = ""; //可不填 +var linebotUserId = ""; //可不填 + +function doPost(e) { + var myFile = e.parameter.file; + var mySpreadsheeturl = e.parameter.spreadsheeturl; + var mySpreadsheetname = decodeURIComponent(e.parameter.spreadsheetname); + var myDatetime = e.parameter.datetime; + var myPosition = e.parameter.position; + var myColumn = e.parameter.column; + var myRow = e.parameter.row; + var myFormat = e.parameter.format||"base64"; + var myDate = Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd"); + var myTime = Utilities.formatDate(new Date(), "GMT+8", "HH:mm:ss"); + cellWidth = e.parameter.cellwidth||cellWidth; + cellHeight = e.parameter.cellheight||cellHeight; + myFoldername = e.parameter.foldername||myFoldername; + linebotToken = e.parameter.linetoken||linebotToken; + + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, myDate+" "+myTime+".jpg"); + + var ss = SpreadsheetApp.openByUrl(mySpreadsheeturl) + var sheet = ss.getSheetByName(mySpreadsheetname); + var lastRow = sheet.getLastRow(); + + if (myPosition=="insertfirst") { + sheet.insertRowsBefore(1, 1); + myRow = 1; + } else if (myPosition=="insertsecond") { + sheet.insertRowsBefore(2, 1); + myRow = 2; + } else if (myPosition=="insertlast") { + myRow = lastRow+1; + } + + if (myDatetime=="gmt_datetime") { + sheet.getRange(myRow, 1).setValue(myDate); + sheet.getRange(myRow, 2).setValue(myTime); + } else if (myDatetime=="gmt_date") { + sheet.getRange(myRow, 1).setValue(myDate); + } else if (myDatetime=="gmt_time") { + sheet.getRange(myRow, 1).setValue(myTime); + } + + if (myFormat=="base64") { + sheet.getRange(myRow, myColumn).setValue(myFile); + } else if (myFormat=="link") { + var folder, folders = DriveApp.getFoldersByName(myFoldername); + if (folders.hasNext()) { + folder = folders.next(); + } else { + folder = DriveApp.createFolder(myFoldername); + } + + var file = folder.createFile(blob); + var imageUrl = file.getUrl(); + var imageID = imageUrl.substring(imageUrl.indexOf("/d/")+3,imageUrl.indexOf("view")-1); + imageUrl = "https://drive.google.com/file/d/"+imageID+"/view?usp=sharing"; + var imageThumbnailUrl = "https://drive.google.com/thumbnail?id="+imageID; + var formula = '=HYPERLINK("' + imageUrl + '","'+ myDate+" "+myTime +'")'; + sheet.getRange(myRow, myColumn).setFormula(formula); + + lineBotPhoto(myDate+" "+myTime, imageThumbnailUrl, imageUrl); + } else if (myFormat=="jpg") { + var folder, folders = DriveApp.getFoldersByName(myFoldername); + if (folders.hasNext()) { + folder = folders.next(); + } else { + folder = DriveApp.createFolder(myFoldername); + } + + var file = folder.createFile(blob); + var imageUrl = file.getUrl(); + var imageID = imageUrl.substring(imageUrl.indexOf("/d/")+3,imageUrl.indexOf("view")-1); + imageUrl = "https://drive.google.com/file/d/"+imageID+"/view?usp=sharing"; + var imageThumbnailUrl = "https://drive.google.com/thumbnail?id="+imageID; + sheet.setRowHeight(myRow, cellHeight); + sheet.setColumnWidth(myColumn, cellWidth); + var formula = 'IMAGE("' + imageThumbnailUrl + '", 1)'; + sheet.getRange(myRow, myColumn).setFormula('=HYPERLINK("' + imageUrl + '", '+formula+')'); + + lineBotPhoto(myDate+" "+myTime, imageThumbnailUrl, imageUrl); + } + return ContentService.createTextOutput("OK"); +} + +function lineBotMessage(message) { + try { + var url = 'https://api.line.me/v2/bot/message/push'; + + var payload = JSON.stringify({ + 'to': linebotUserId, + 'messages': [{ + type:'text', + text: message + }] + }); + + var response = UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + linebotToken, + }, + 'method': 'post', + 'payload': payload + }); + + return response.getContentText(); + } catch(error) { + return 'Error: ' + error.message; + } +} + +function lineBotPhoto(message, imageThumbnail, imageFullsize) { + try { + var url = 'https://api.line.me/v2/bot/message/push'; + + var payload = JSON.stringify({ + 'to': linebotUserId, + 'messages': [ + { + type:'text', + text: message + }, + { + type:'image', + originalContentUrl: imageFullsize, + previewImageUrl: imageThumbnail + } + ] + }); + + var response = UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + linebotToken, + }, + 'method': 'post', + 'payload': payload + }); + return response.getContentText(); + } catch(error) { + return 'Error: ' + error.message; + } +} diff --git a/SendCapturedImageToTelegram.gs b/SendCapturedImageToTelegram.gs new file mode 100644 index 0000000000..1e69d0ef24 --- /dev/null +++ b/SendCapturedImageToTelegram.gs @@ -0,0 +1,35 @@ +function doPost(e) { + var myFilename = e.parameter.myFilename; + var myFile = e.parameter.myFile; + var myToken = e.parameter.myToken; + var myChatID = e.parameter.myChatID; + + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, myFilename); + + var boundary = "------------------------------"; + var imageData = Utilities.newBlob( + "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"chat_id\"; \r\n\r\n" + myChatID + "\r\n" + + "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"photo\"; filename=\"" + myFilename + "\"\r\n" + + "Content-Type: " + 'image/jpeg' +"\r\n\r\n" + ).getBytes(); + imageData = imageData.concat(blob.getBytes()); + imageData = imageData.concat(Utilities.newBlob("\r\n--" + boundary + "--\r\n").getBytes()); + + sendImagetoTelegram(imageData, myToken, boundary); + + return ContentService.createTextOutput("Return = OK"); +} + +function sendImagetoTelegram(imageData, token, boundary){ + var options = { + "method" : "post", + "contentType" : "multipart/form-data; boundary=" + boundary, + "payload" : imageData + }; + UrlFetchApp.fetch("https://api.telegram.org/bot"+token+"/sendPhoto", options); +} \ No newline at end of file diff --git a/Spreadsheet_function.gs b/Spreadsheet_function.gs new file mode 100644 index 0000000000..193b3b991d --- /dev/null +++ b/Spreadsheet_function.gs @@ -0,0 +1,117 @@ +/* + Author : ChungYi Fu (Kaohsiung, Taiwan) 2022/7/22 00:00 + https://www.facebook.com/francefu +*/ + +function doPost(e) { + var mySpreadsheeturl = decodeURIComponent(e.parameter.spreadsheeturl); + var mySpreadsheetname = decodeURIComponent(e.parameter.spreadsheetname); + var myFunction = e.parameter.func; + var myData = decodeURIComponent(e.parameter.data); + var myRow = e.parameter.row; + var myCol = e.parameter.col; + var myText = decodeURIComponent(e.parameter.text); + myData = myData.replace(/gmt_datetime/g, Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd HH:mm:ss")); + myData = myData.replace(/gmt_date/g, Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd")); + myData = myData.replace(/gmt_time/g, Utilities.formatDate(new Date(), "GMT+8", "HH:mm:ss")); + myData = myData.split("|"); + myText = myText.replace(/gmt_datetime/g, Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd HH:mm:ss")); + myText = myText.replace(/gmt_date/g, Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd")); + myText = myText.replace(/gmt_time/g, Utilities.formatDate(new Date(), "GMT+8", "HH:mm:ss")); + + var spreadsheet = SpreadsheetApp.openByUrl(mySpreadsheeturl) + var sheet = spreadsheet.getSheetByName(mySpreadsheetname); + var lastRow = sheet.getLastRow(); + + if (myFunction=="insertfirst") { + sheet.insertRowsBefore(1, 1); + for (var i=0;i - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - diff --git a/ThingSpeak_20180401/thingspeak.js b/ThingSpeak_20180401/thingspeak.js deleted file mode 100644 index 537e5fb2b9..0000000000 --- a/ThingSpeak_20180401/thingspeak.js +++ /dev/null @@ -1,34 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function createIframe(key,field1,field2,field3,field4,field5,field6,field7,field8) { - - var input_url="https://api.thingspeak.com/update?api_key="+key+"&field1="+field1+"&field2="+field2+"&field3="+field3+"&field4="+field4+"&field5="+field5+"&field6="+field6+"&field7="+field7+"&field8="+field8; - var src = ''; - - if (document.getElementById("thingspeak_iframe")) - { - document.getElementById("thingspeak_iframe").style.left = '0px'; - document.getElementById("thingspeak_iframe").style.top = '0px'; - document.getElementById("thingspeak_iframe").style.display = 'block'; - document.getElementById("thingspeak_iframe").innerHTML = src; - } - else - { - var div = document.createElement('div'); - div.id = "thingspeak_iframe"; - div.style.position = 'absolute'; - div.style.left = '0px'; - div.style.top = '0px'; - div.style.zindex='9999'; - div.innerHTML = src; - document.body.appendChild(div); - } - } - - window.createIframe = createIframe; - -}(window, window.document)); diff --git a/WebduinoDrive.gs b/WebduinoDrive.gs new file mode 100644 index 0000000000..15b8ac3712 --- /dev/null +++ b/WebduinoDrive.gs @@ -0,0 +1,96 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2025/4/1 12:00 +https://www.facebook.com/francefu +*/ + +var linebotToken = ""; //可不填 +var linebotUserId = ""; //可不填 + +function doPost(e) { + var myFoldername = e.parameter.myFoldername; + var myFile = e.parameter.myFile; + //var myFilename = e.parameter.myFilename; + var myFilename = Utilities.formatDate(new Date(), "GMT", "yyyyMMddHHmmss")+"-"+e.parameter.myFilename; + + // Save a captured image to Google Drive. + var folder, folders = DriveApp.getFoldersByName(myFoldername); + if (folders.hasNext()) { + folder = folders.next(); + } else { + folder = DriveApp.createFolder(myFoldername); + } + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, myFilename); + var file = folder.createFile(blob); + file.setDescription("Uploaded by " + myFilename); + + var imageID = file.getUrl().substring(file.getUrl().indexOf("/d/")+3,file.getUrl().indexOf("view")-1); + var imageUrl = "https://drive.google.com/uc?authuser=0&id="+imageID; + var imageThumbnailUrl = "https://drive.google.com/thumbnail?id="+imageID; + + // lineBotPhoto(myFilename, imageThumbnailUrl, imageUrl); + + return ContentService.createTextOutput(myFoldername+"/"+myFilename+"\n"+imageUrl); +} + +function lineBotMessage(message) { + try { + var url = 'https://api.line.me/v2/bot/message/push'; + + var payload = JSON.stringify({ + 'to': linebotUserId, + 'messages': [{ + type:'text', + text: message + }] + }); + + var response = UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + linebotToken, + }, + 'method': 'post', + 'payload': payload + }); + + return response.getContentText(); + } catch(error) { + return 'Error: ' + error.message; + } +} + +function lineBotPhoto(message, imageThumbnail, imageFullsize) { + try { + var url = 'https://api.line.me/v2/bot/message/push'; + + var payload = JSON.stringify({ + 'to': linebotUserId, + 'messages': [ + { + type:'text', + text: message + }, + { + type:'image', + originalContentUrl: imageFullsize, + previewImageUrl: imageThumbnail + } + ] + }); + + var response = UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + linebotToken, + }, + 'method': 'post', + 'payload': payload + }); + return response.getContentText(); + } catch(error) { + return 'Error: ' + error.message; + } +} diff --git a/WebduinoSpreadsheet.gs b/WebduinoSpreadsheet.gs new file mode 100644 index 0000000000..1ced341eee --- /dev/null +++ b/WebduinoSpreadsheet.gs @@ -0,0 +1,34 @@ +/* + Author : ChungYi Fu (Kaohsiung, Taiwan) 2022/6/27 06:00 + https://www.facebook.com/francefu +*/ + +function doPost(e) { + + var myFile = e.parameter.myFile; + var myFileFormat = e.parameter.myFileFormat; + var myFilename = Utilities.formatDate(new Date(), "GMT+8", "yyyyMMddHHmmss"); + var mySpreadsheet = e.parameter.mySpreadsheet; + var mySpreadsheetName = e.parameter.mySpreadsheetName; + var myCellRow = e.parameter.myCellRow; + var myCellCol = e.parameter.myCellCol; + var myCellColHeight = e.parameter.myCellColHeight; + + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var data = myFile.substring(myFile.indexOf(",")+1); + data = Utilities.base64Decode(data); + var blob = Utilities.newBlob(data, contentType, myFilename); + + var ss = SpreadsheetApp.openByUrl(mySpreadsheet) + ss.getActiveSheet().setHiddenGridlines(true); + var sheet = ss.getSheetByName(mySpreadsheetName); + sheet.insertRowsBefore(myCellRow, 1); + if (myFileFormat=="string") + sheet.getRange(myCellRow, myCellCol).setValue(myFile); + else { + sheet.setRowHeight(myCellRow, myCellColHeight); + sheet.insertImage(blob, myCellCol, myCellRow); + } + + return ContentService.createTextOutput("ok"); +} diff --git a/_config.yml b/_config.yml deleted file mode 100644 index c4192631f2..0000000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-cayman \ No newline at end of file diff --git a/bit_MatrixLed_20180719/blockly.json b/bit_MatrixLed_20180719/blockly.json deleted file mode 100644 index 24ee36e792..0000000000 --- a/bit_MatrixLed_20180719/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["matrix_led_backcolor","matrix_led_verticalflip","matrix_led_horizontalflip","matrix_led_invert","matrix_led_getcolor","matrix_led_color","matrix_led_code","matrix_led_texttocode","matrix_led_indentcode","matrix_led_showstate","matrix_led_sample","matrix_led_matrix","matrix_led_matrix_color","matrix_led_matrixcode","matrix_led_clear","matrix_led_on","matrix_led_color_on","matrix_led_off","matrix_led_reverse","matrix_led_state","matrix_led_marquee","matrix_led_marquee_once","matrix_led_marquee_degree","matrix_led_marquee_time","matrix_led_marquee_stop","matrix_led_marquee_reverse","matrix_led_marquee_resume","matrix_led_char","matrix_led_linechart","matrix_led_barchart","matrix_led_clockwise","matrix_led_counterclockwise"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "matrixled.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/bit_MatrixLed_20180719/blockly/blocks.js b/bit_MatrixLed_20180719/blockly/blocks.js deleted file mode 100644 index 983b785761..0000000000 --- a/bit_MatrixLed_20180719/blockly/blocks.js +++ /dev/null @@ -1,568 +0,0 @@ -Blockly.Blocks['matrix_led_char'] = { - init: function() { - this.appendValueInput("value_char_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_CHAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - - -Blockly.Blocks['matrix_led_texttocode'] = { - init: function() { - this.appendValueInput("value_text_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_indentcode'] = { - init: function() { - this.appendValueInput("value_indentcode_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_INDENTCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_showstate'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW) - .appendField(new Blockly.FieldDropdown([["on","1"], ["off","0"]]), "value_showstate_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_stop'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_resume'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_time'] = { - init: function() { - this.appendValueInput("value_marquee_time_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_sample'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SAMPLE_SHOW) - .appendField(new Blockly.FieldDropdown([["♥","♥"], ["♡","♡"], ["↑","↑"], ["↓","↓"], ["←","←"], ["→","→"], ["↖","↖"], ["↙","↙"], ["↗","↗"], ["↘","↘"], ["▲","▲"], ["▼","▼"], ["◄","◄"], ["►","►"], ["O","O"], ["X","X"], ["V","V"]]), "value_sample_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setTooltip(''); - this.setColour(300); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_code'] = { - init: function() { - this.appendValueInput("value_code_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_CODE_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L01') - .appendField(new Blockly.FieldColour("#000000"), 'L06') - .appendField(new Blockly.FieldColour("#000000"), 'L11') - .appendField(new Blockly.FieldColour("#000000"), 'L16') - .appendField(new Blockly.FieldColour("#000000"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L02') - .appendField(new Blockly.FieldColour("#000000"), 'L07') - .appendField(new Blockly.FieldColour("#000000"), 'L12') - .appendField(new Blockly.FieldColour("#000000"), 'L17') - .appendField(new Blockly.FieldColour("#000000"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L03') - .appendField(new Blockly.FieldColour("#000000"), 'L08') - .appendField(new Blockly.FieldColour("#000000"), 'L13') - .appendField(new Blockly.FieldColour("#000000"), 'L18') - .appendField(new Blockly.FieldColour("#000000"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L04') - .appendField(new Blockly.FieldColour("#000000"), 'L09') - .appendField(new Blockly.FieldColour("#000000"), 'L14') - .appendField(new Blockly.FieldColour("#000000"), 'L19') - .appendField(new Blockly.FieldColour("#000000"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L05') - .appendField(new Blockly.FieldColour("#000000"), 'L10') - .appendField(new Blockly.FieldColour("#000000"), 'L15') - .appendField(new Blockly.FieldColour("#000000"), 'L20') - .appendField(new Blockly.FieldColour("#000000"), 'L25') - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; -Blockly.Blocks['matrix_led_matrixcode'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_clear'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLEAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COLOR_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.appendValueInput("value_color_on_") - .setCheck("Colour") - .appendField("color"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_off'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_OFF_SHOW); - this.appendValueInput("value_x_off_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_off_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_REVERSE_SHOW); - this.appendValueInput("value_x_reverse_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_reverse_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_state'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_STATE_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_linechart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_LINECHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_barchart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_BARCHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_clockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_counterclockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_verticalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_horizontalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_invert'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_INVERT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_getcolor'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_GETCOLOR_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_backcolor'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/bit_MatrixLed_20180719/blockly/javascript.js b/bit_MatrixLed_20180719/blockly/javascript.js deleted file mode 100644 index 6695b61e4e..0000000000 --- a/bit_MatrixLed_20180719/blockly/javascript.js +++ /dev/null @@ -1,270 +0,0 @@ -Blockly.JavaScript['matrix_led_char'] = function(block) { - var value_char_ = Blockly.JavaScript.valueToCode(block, 'value_char_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_char('+ value_char_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_time'] = function(block) { - var value_marquee_time_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_time_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_time('+ value_marquee_time_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_stop'] = function(block) { - var code = 'MatrixLed_marquee_stop();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_resume'] = function(block) { - var code = 'MatrixLed_marquee_resume();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_reverse'] = function(block) { - var code = 'MatrixLed_marquee_reverse();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color('+ value_color_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_texttocode'] = function(block) { - var value_text_ = Blockly.JavaScript.valueToCode(block, 'value_text_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_texttocode('+value_text_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_sample'] = function(block) { - var value_sample_ = block.getFieldValue('value_sample_'); - var code = 'MatrixLed_sample("'+ value_sample_ +'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_code'] = function(block) { - var value_code_ = Blockly.JavaScript.valueToCode(block, 'value_code_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_code('+ value_code_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = 'MatrixLed_matrix("'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = 'MatrixLed_matrix_color(["'+L01+'","'+L02+'","'+L03+'","'+L04+'","'+L05+'","'+L06+'","'+L07+'","'+L08+'","'+L09+'","'+L10+'","'+L11+'","'+L12+'","'+L13+'","'+L14+'","'+L15+'","'+L16+'","'+L17+'","'+L18+'","'+L19+'","'+L20+'","'+L21+'","'+L22+'","'+L23+'","'+L24+'","'+L25+'"]);\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrixcode'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_clear'] = function(block) { - var code = 'MatrixLed_clear();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_on('+value_x_on_+','+value_y_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_on_ = Blockly.JavaScript.valueToCode(block, 'value_color_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color_on('+value_x_on_+','+value_y_on_+','+value_color_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_off'] = function(block) { - var value_x_off_ = Blockly.JavaScript.valueToCode(block, 'value_x_off_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_off_ = Blockly.JavaScript.valueToCode(block, 'value_y_off_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_off('+value_x_off_+','+value_y_off_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_reverse'] = function(block) { - var value_x_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_x_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_y_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_reverse('+value_x_reverse_+','+value_y_reverse_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_state'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_state('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_showstate'] = function(block) { - var value_showstate_ = block.getFieldValue('value_showstate_'); - var code = 'MatrixLed_showstate(fuMatrixLed,'+value_showstate_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_indentcode'] = function(block) { - var value_indentcode_ = Blockly.JavaScript.valueToCode(block, 'value_indentcode_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_indentcode('+value_indentcode_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_linechart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_linechart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_barchart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_barchart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_clockwise'] = function(block) { - var code = 'Matrixled_clockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_counterclockwise'] = function(block) { - var code = 'Matrixled_counterclockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_verticalflip'] = function(block) { - var code = 'Matrixled_verticalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_horizontalflip'] = function(block) { - var code = 'Matrixled_horizontalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_invert'] = function(block) { - var code = 'Matrixled_invert();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_getcolor'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_getcolor('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_backcolor'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_backcolor('+ value_color_ +');\n'; - return code; -}; diff --git a/bit_MatrixLed_20180719/blockly/msg/blocks/en.js b/bit_MatrixLed_20180719/blockly/msg/blocks/en.js deleted file mode 100644 index a5e45705f3..0000000000 --- a/bit_MatrixLed_20180719/blockly/msg/blocks/en.js +++ /dev/null @@ -1,38 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "Matrix Led"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "Matrix Led (COLOR)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "Matrix Led Code"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "Clean Screen"; -Blockly.Msg.MATRIXLED_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "Turn Off"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "Switch"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "Get Led State"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "Led Color"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "Show Sample"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "Show Sample By Code"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "Show Marguee(CYCLE)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "Show Marguee(ONCE)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "Marguee Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " Degree"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "Stop Marguee"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "Resume Marguee(CYCLE)"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "Marguee Time (ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "Marguee(CYCLE) Reverse"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "Show Character"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "Convert Text To Code"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "Show Screen"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "Indent Code"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "Line Chart "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "Bar Chart "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "Value1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "Value2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "Value3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "Value4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "Value5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "Rotate 90 Degrees Clockwise"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "Rotate 90 Degrees Counter Clockwise"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "Vertical Flip"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "Horizontal Flip"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "Invert"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "Get Color Code"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "Back Color"; diff --git a/bit_MatrixLed_20180719/blockly/msg/blocks/zh-hans.js b/bit_MatrixLed_20180719/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index d902e7f9af..0000000000 --- a/bit_MatrixLed_20180719/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,38 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示灯(单色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示灯(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示灯(单色) 编码"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示灯 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗灯"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示灯 亮暗反转"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示灯 亮暗状态"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示灯(单色) 颜色"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "显示 图案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "显示 图案(编码)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑马灯(循环)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑马灯(单次)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑马灯 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格数"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑马灯 暂停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑马灯(循环) 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑马灯 间隔时间(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑马灯(循环) 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "显示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "转换文字为编码"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示灯 显示"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "缩排编码"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折线图 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "长条图 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "数值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "数值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "数值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "数值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "数值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示灯 顺时钟旋转90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示灯 逆时钟旋转90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示灯 垂直翻转"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示灯 水平翻转"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示灯 开关反转"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示灯 色码值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示灯(单色) 背景颜色"; diff --git a/bit_MatrixLed_20180719/blockly/msg/blocks/zh-hant.js b/bit_MatrixLed_20180719/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 97163c1935..0000000000 --- a/bit_MatrixLed_20180719/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,38 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示燈(單色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示燈(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示燈(單色) 編碼"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示燈 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗燈"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示燈 亮暗反轉"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示燈 亮暗狀態"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示燈(單色) 顏色"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "顯示 圖案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "顯示 圖案(編碼)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑馬燈(循環)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑馬燈(單次)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑馬燈 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格數"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑馬燈 暫停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑馬燈(循環) 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑馬燈 間隔時間(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑馬燈(循環) 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "顯示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "轉換文字為編碼"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示燈 顯示"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "縮排編碼"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折線圖 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "長條圖 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "數值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "數值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "數值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "數值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "數值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示燈 順時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示燈 逆時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示燈 垂直翻轉"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示燈 水平翻轉"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示燈 開關反轉"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示燈 色碼值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示燈(單色) 背景顏色"; diff --git a/bit_MatrixLed_20180719/blockly/msg/en.js b/bit_MatrixLed_20180719/blockly/msg/en.js deleted file mode 100644 index 883a7b3522..0000000000 --- a/bit_MatrixLed_20180719/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "FuMatrixLed"; diff --git a/bit_MatrixLed_20180719/blockly/msg/zh-hans.js b/bit_MatrixLed_20180719/blockly/msg/zh-hans.js deleted file mode 100644 index 7d969d936c..0000000000 --- a/bit_MatrixLed_20180719/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "法兰斯点矩阵"; diff --git a/bit_MatrixLed_20180719/blockly/msg/zh-hant.js b/bit_MatrixLed_20180719/blockly/msg/zh-hant.js deleted file mode 100644 index e008529bf5..0000000000 --- a/bit_MatrixLed_20180719/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "法蘭斯點矩陣"; diff --git a/bit_MatrixLed_20180719/blockly/toolbox.xml b/bit_MatrixLed_20180719/blockly/toolbox.xml deleted file mode 100644 index 535c41908f..0000000000 --- a/bit_MatrixLed_20180719/blockly/toolbox.xml +++ /dev/null @@ -1,332 +0,0 @@ - - - fuMatrixLed - - - - - - 1 - - - - - 10 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - 0 - - - - - 0 - - - - - #ff0000 - - - - - - - #000000 - - - - - - - #ff0000 - - - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - - - - - - - - - - - - - 0110011110011111111001100 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - 500 - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - 1 - - - 1 - - - - - - - - - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - diff --git a/bit_MatrixLed_20180719/matrixled.js b/bit_MatrixLed_20180719/matrixled.js deleted file mode 100644 index ca3bd66158..0000000000 --- a/bit_MatrixLed_20180719/matrixled.js +++ /dev/null @@ -1,651 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - const charA = "0111110010100101001001111"; - const charB = "1111110101101011010101010"; - const charC = "0111010001100011000110001"; - const charD = "1111110001100011000101110"; - const charE = "1111110101101011010110101"; - const charF = "1111110100101001010010100"; - const charG = "0111010001101011010110111"; - const charH = "1111100100001000010011111"; - const charI = "1000110001111111000110001"; - const charJ = "1001110001111111000010000"; - const charK = "1111100010001000101010001"; - const charL = "1111100001000010000100001"; - const charM = "1111101000001000100011111"; - const charN = "1111101000001000001011111"; - const charO = "0111010001100011000101110"; - const charP = "1111110010100101001001100"; - const charQ = "0111010001101011001001101"; - const charR = "1111110100101001010001011"; - const charS = "0100110101101011010110010"; - const charT = "1000010000111111000010000"; - const charU = "1111000001000010000111110"; - const charV = "1110000010000010001011100"; - const charW = "1111000001111100000111110"; - const charX = "1000101010001000101010001"; - const charY = "1000001000001110100010000"; - const charZ = "1000110011101011100110001"; - const chara = "0000000110010010011000001"; - const charb = "0000011111001010001000000"; - const charc = "0000000110010010100100000"; - const chard = "0000000010001011111100000"; - const chare = "0000000110010110010100000"; - const charf = "0000000100111111010000000"; - const charg = "0000000101010110011000000"; - const charh = "0000011111001000001100000"; - const chari = "0000000000101110000000000"; - const charj = "0000000001101110000000000"; - const chark = "0000011111000100010100000"; - const charl = "0000000000111110000000000"; - const charm = "0011100100000110010000011"; - const charn = "0000000111001000001100000"; - const charo = "0000000010001010001000000"; - const charp = "0000001111010100010000000"; - const charq = "0000000100010100111100000"; - const charr = "0000000111000100010000000"; - const chars = "0000001001101011001000000"; - const chart = "0000000100011110010100000"; - const charu = "0000000110000010011000001"; - const charv = "0000000110000010011000000"; - const charw = "0011000001001100000100110"; - const charx = "0000000101000100010100000"; - const chary = "0000000101000100010000000"; - const charz = "0000101011011010100000000"; - const char0 = "0000011111100011111100000"; - const char1 = "0000001001111110000100000"; - const char2 = "0000010111101011110100000"; - const char3 = "0000010101101011111100000"; - const char4 = "0000011100001001111100000"; - const char5 = "0000011101101011011100000"; - const char6 = "0000011111101011011100000"; - const char7 = "0000011000100001111100000"; - const char8 = "0000011111101011111100000"; - const char9 = "0000011101101011111100000"; - const comma = "0000000001000100000000000"; - const period = "0000000001000000000000000"; - const questionmark = "0100010000100111010001000"; - const exclamationmark = "0000000000111010000000000"; - const semicolon = "0000000001010100000000000"; - const colon = "0000000000010100000000000"; - const parenthesesleft = "0000001110100010000000000"; - const parenthesesright = "0000000000100010111000000"; - const squarebracketsleft = "0000011111100010000000000"; - const squarebracketsright = "0000000000100011111100000"; - const curlybracketsleft = "0000000100111111000100000"; - const curlybracketsright = "0000010001111110010000000"; - const Quotationmarkssingle = "0000000000110000010000000"; - const Quotationmarksdouble = "1100000100110000010000000"; - const hyphen = "0000000100001000010000000"; - const heart = "0110010010010011001001100"; - const heartfill = "0110011110011111111001100"; - const arrowup = "0010001000111110100000100"; - const arrowdown = "0010000010111110001000100"; - const arrowleft = "0010001110101010010000100"; - const arrowright = "0010000100101010111000100"; - const arrowleftup = "1111011000101001001000001"; - const arrowleftdown = "0111100011001010100110000"; - const arrowrightup = "0000110010101001100011110"; - const arrowrightdown = "1000001001001010001101111"; - const arrowupfill = "0000100111111110011100001"; - const arrowdownfill = "1000011100111111110010000"; - const arrowleftfill = "0010000100011100111011111"; - const arrowrightfill = "1111101110011100010000100"; - const noexist = "0000000000000000000000000"; - - var L = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var MatrixLedcolor = "#ff0000"; - var MatrixLedbackcolor = "#000000"; - var MatrixLedmarqueecode = ""; - var MatrixLedmarqueecodeonce = ""; - var MatrixLedmarqueetime = 500; - var MatrixLedmarqueereverse = 1; - var MatrixLedshowstate = 1; - var marqueetimeid,marqueetimeid1; - var objMatrixLed; - - function MatrixLed_color(input_color_) { - MatrixLedcolor = input_color_; - } - - function MatrixLed_showstate(obj,input_showstate_) { - objMatrixLed=obj; - MatrixLedshowstate = input_showstate_; - } - - function MatrixLed_indentcode(input_indentcode_) { - var indentcode = input_indentcode_; - while (indentcode.search(/0000000000/)!=-1) - indentcode = indentcode.replace(/0000000000/g,"00000"); - return indentcode; - } - - function MatrixLed_marquee(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecodeonce = ""; - window.clearInterval(marqueetimeid); - window.clearInterval(marqueetimeid1); - if ((input_marquee_.length==25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLed_matrix(input_marquee_); - return; - } - else if ((input_marquee_.length%5==0)&&(input_marquee_.length>25)&&(input_marquee_.search(/[^0-1]/)==-1)) - MatrixLedmarqueecode = input_marquee_; - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLedmarqueecode = input_marquee_+"0000000000000000000000000"; - MatrixLedmarqueecodeonce = input_marquee_+"0000000000000000000000000"; - } - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - } - - function MatrixLed_marquee_once_play() { - if (MatrixLedmarqueecode.length>25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(5,MatrixLedmarqueecodeonce.length-5)+MatrixLedmarqueecodeonce.substr(0,5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(MatrixLedmarqueecodeonce.length-5,5)+MatrixLedmarqueecodeonce.substr(0,MatrixLedmarqueecodeonce.length-5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5); - } - } - else - window.clearInterval(marqueetimeid1); - } - - function MatrixLed_marquee_degree(direction,degree) { - window.clearInterval(marqueetimeid); - window.clearInterval(marqueetimeid1); - if (MatrixLedmarqueecode.length25) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - } - } - - function MatrixLed_marquee_time(input_time_) { - MatrixLedmarqueetime = input_time_; - } - - function MatrixLed_marquee_stop() { - window.clearInterval(marqueetimeid); - window.clearInterval(marqueetimeid1); - } - - function MatrixLed_marquee_resume() { - window.clearInterval(marqueetimeid); - marqueetimeid = window.setInterval("MatrixLed_marquee_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_reverse() { - if (MatrixLedmarqueereverse==1) - MatrixLedmarqueereverse=2; - else if (MatrixLedmarqueereverse==2) - MatrixLedmarqueereverse=1; - } - - function MatrixLed_char(input_char_) { - input_char_=input_char_.toString(); - if (input_char_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_char_)); - } - } - - function MatrixLed_texttocode(input_text_) { - input_text_=input_text_.toString(); - if (input_text_.length>0) - { - var textcode=""; - for (var i=0;i=(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function Matrixled_clockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_counterclockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_verticalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[j+5*i]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_horizontalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[j+i*5]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_invert(){ - for (var i=0;i<25;i++) - { - if ((L[i]=="")||(L[i]==MatrixLedbackcolor)) - L[i]=MatrixLedcolor; - else - L[i]=MatrixLedbackcolor; - } - MatrixLed_show(); - } - - function MatrixLed_getcolor(input_x_,input_y_) { - return L[input_x_*5+input_y_]; - } - - function MatrixLed_backcolor(input_color_) { - MatrixLedbackcolor=input_color_; - } - - window.MatrixLed_clear = MatrixLed_clear; - window.MatrixLed_matrix = MatrixLed_matrix; - window.MatrixLed_matrix_color = MatrixLed_matrix_color; - window.MatrixLed_show = MatrixLed_show; - window.MatrixLed_on = MatrixLed_on; - window.MatrixLed_color_on = MatrixLed_color_on; - window.MatrixLed_off = MatrixLed_off; - window.MatrixLed_reverse = MatrixLed_reverse; - window.MatrixLed_state = MatrixLed_state; - window.MatrixLed_color = MatrixLed_color; - window.MatrixLed_sample = MatrixLed_sample; - window.MatrixLed_code = MatrixLed_code; - window.MatrixLed_marquee = MatrixLed_marquee; - window.MatrixLed_marquee_once = MatrixLed_marquee_once; - window.MatrixLed_marquee_play = MatrixLed_marquee_play; - window.MatrixLed_marquee_once_play = MatrixLed_marquee_once_play; - window.MatrixLed_marquee_degree = MatrixLed_marquee_degree; - window.MatrixLed_marquee_stop = MatrixLed_marquee_stop; - window.MatrixLed_marquee_resume = MatrixLed_marquee_resume; - window.MatrixLed_marquee_reverse = MatrixLed_marquee_reverse; - window.MatrixLed_marquee_time = MatrixLed_marquee_time; - window.MatrixLed_char = MatrixLed_char; - window.MatrixLed_conversion = MatrixLed_conversion; - window.MatrixLed_texttocode = MatrixLed_texttocode; - window.MatrixLed_showstate = MatrixLed_showstate; - window.MatrixLed_indentcode = MatrixLed_indentcode; - window.MatrixLed_linechart = MatrixLed_linechart; - window.MatrixLed_barchart = MatrixLed_barchart; - window.Matrixled_clockwise = Matrixled_clockwise; - window.Matrixled_counterclockwise = Matrixled_counterclockwise; - window.Matrixled_verticalflip = Matrixled_verticalflip; - window.Matrixled_horizontalflip = Matrixled_horizontalflip; - window.Matrixled_invert = Matrixled_invert; - window.MatrixLed_getcolor = MatrixLed_getcolor; - window.MatrixLed_backcolor = MatrixLed_backcolor; - -}(window, window.document)); diff --git a/bit_MatrixLed_20180722/blockly.json b/bit_MatrixLed_20180722/blockly.json deleted file mode 100644 index f15297d039..0000000000 --- a/bit_MatrixLed_20180722/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["matrix_led_backcolor","matrix_led_verticalflip","matrix_led_horizontalflip","matrix_led_invert","matrix_led_getcolor","matrix_led_color","matrix_led_code","matrix_led_texttocode","matrix_led_indentcode","matrix_led_showstate","matrix_led_sample","matrix_led_matrix","matrix_led_matrix_color","matrix_led_matrixcode","matrix_led_matrixcode_color","matrix_led_clear","matrix_led_on","matrix_led_color_on","matrix_led_off","matrix_led_reverse","matrix_led_state","matrix_led_marquee","matrix_led_marquee_once","matrix_led_marquee_color","matrix_led_marquee_color_once","matrix_led_marquee_degree","matrix_led_marquee_color_degree","matrix_led_marquee_time","matrix_led_marquee_stop","matrix_led_marquee_reverse","matrix_led_marquee_resume","matrix_led_char","matrix_led_linechart","matrix_led_barchart","matrix_led_clockwise","matrix_led_counterclockwise"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "matrixled.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/bit_MatrixLed_20180722/blockly/blocks.js b/bit_MatrixLed_20180722/blockly/blocks.js deleted file mode 100644 index 2e3d65f7e3..0000000000 --- a/bit_MatrixLed_20180722/blockly/blocks.js +++ /dev/null @@ -1,652 +0,0 @@ -Blockly.Blocks['matrix_led_char'] = { - init: function() { - this.appendValueInput("value_char_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_CHAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - - -Blockly.Blocks['matrix_led_texttocode'] = { - init: function() { - this.appendValueInput("value_text_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_indentcode'] = { - init: function() { - this.appendValueInput("value_indentcode_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_INDENTCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_showstate'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW) - .appendField(new Blockly.FieldDropdown([["on","1"], ["off","0"]]), "value_showstate_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_stop'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_resume'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_time'] = { - init: function() { - this.appendValueInput("value_marquee_time_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_sample'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SAMPLE_SHOW) - .appendField(new Blockly.FieldDropdown([["♥","♥"], ["♡","♡"], ["↑","↑"], ["↓","↓"], ["←","←"], ["→","→"], ["↖","↖"], ["↙","↙"], ["↗","↗"], ["↘","↘"], ["▲","▲"], ["▼","▼"], ["◄","◄"], ["►","►"], ["O","O"], ["X","X"], ["V","V"]]), "value_sample_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setTooltip(''); - this.setColour(300); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_code'] = { - init: function() { - this.appendValueInput("value_code_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_CODE_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L01') - .appendField(new Blockly.FieldColour("#000000"), 'L06') - .appendField(new Blockly.FieldColour("#000000"), 'L11') - .appendField(new Blockly.FieldColour("#000000"), 'L16') - .appendField(new Blockly.FieldColour("#000000"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L02') - .appendField(new Blockly.FieldColour("#000000"), 'L07') - .appendField(new Blockly.FieldColour("#000000"), 'L12') - .appendField(new Blockly.FieldColour("#000000"), 'L17') - .appendField(new Blockly.FieldColour("#000000"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L03') - .appendField(new Blockly.FieldColour("#000000"), 'L08') - .appendField(new Blockly.FieldColour("#000000"), 'L13') - .appendField(new Blockly.FieldColour("#000000"), 'L18') - .appendField(new Blockly.FieldColour("#000000"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L04') - .appendField(new Blockly.FieldColour("#000000"), 'L09') - .appendField(new Blockly.FieldColour("#000000"), 'L14') - .appendField(new Blockly.FieldColour("#000000"), 'L19') - .appendField(new Blockly.FieldColour("#000000"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L05') - .appendField(new Blockly.FieldColour("#000000"), 'L10') - .appendField(new Blockly.FieldColour("#000000"), 'L15') - .appendField(new Blockly.FieldColour("#000000"), 'L20') - .appendField(new Blockly.FieldColour("#000000"), 'L25') - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; - -Blockly.Blocks['matrix_led_matrixcode'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrixcode_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L01') - .appendField(new Blockly.FieldColour("#000000"), 'L06') - .appendField(new Blockly.FieldColour("#000000"), 'L11') - .appendField(new Blockly.FieldColour("#000000"), 'L16') - .appendField(new Blockly.FieldColour("#000000"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L02') - .appendField(new Blockly.FieldColour("#000000"), 'L07') - .appendField(new Blockly.FieldColour("#000000"), 'L12') - .appendField(new Blockly.FieldColour("#000000"), 'L17') - .appendField(new Blockly.FieldColour("#000000"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L03') - .appendField(new Blockly.FieldColour("#000000"), 'L08') - .appendField(new Blockly.FieldColour("#000000"), 'L13') - .appendField(new Blockly.FieldColour("#000000"), 'L18') - .appendField(new Blockly.FieldColour("#000000"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L04') - .appendField(new Blockly.FieldColour("#000000"), 'L09') - .appendField(new Blockly.FieldColour("#000000"), 'L14') - .appendField(new Blockly.FieldColour("#000000"), 'L19') - .appendField(new Blockly.FieldColour("#000000"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L05') - .appendField(new Blockly.FieldColour("#000000"), 'L10') - .appendField(new Blockly.FieldColour("#000000"), 'L15') - .appendField(new Blockly.FieldColour("#000000"), 'L20') - .appendField(new Blockly.FieldColour("#000000"), 'L25') - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; - -Blockly.Blocks['matrix_led_clear'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLEAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COLOR_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.appendValueInput("value_color_on_") - .setCheck("Colour") - .appendField("color"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_off'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_OFF_SHOW); - this.appendValueInput("value_x_off_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_off_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_REVERSE_SHOW); - this.appendValueInput("value_x_reverse_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_reverse_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_state'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_STATE_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_linechart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_LINECHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_barchart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_BARCHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_clockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_counterclockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_verticalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_horizontalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_invert'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_INVERT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_getcolor'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_GETCOLOR_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_backcolor'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/bit_MatrixLed_20180722/blockly/javascript.js b/bit_MatrixLed_20180722/blockly/javascript.js deleted file mode 100644 index 76a4f3d112..0000000000 --- a/bit_MatrixLed_20180722/blockly/javascript.js +++ /dev/null @@ -1,319 +0,0 @@ -Blockly.JavaScript['matrix_led_char'] = function(block) { - var value_char_ = Blockly.JavaScript.valueToCode(block, 'value_char_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_char('+ value_char_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_time'] = function(block) { - var value_marquee_time_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_time_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_time('+ value_marquee_time_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_stop'] = function(block) { - var code = 'MatrixLed_marquee_stop();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_resume'] = function(block) { - var code = 'MatrixLed_marquee_resume();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_reverse'] = function(block) { - var code = 'MatrixLed_marquee_reverse();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color('+ value_color_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_texttocode'] = function(block) { - var value_text_ = Blockly.JavaScript.valueToCode(block, 'value_text_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_texttocode('+value_text_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_sample'] = function(block) { - var value_sample_ = block.getFieldValue('value_sample_'); - var code = 'MatrixLed_sample("'+ value_sample_ +'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_code'] = function(block) { - var value_code_ = Blockly.JavaScript.valueToCode(block, 'value_code_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_code('+ value_code_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = 'MatrixLed_matrix("'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = 'MatrixLed_matrix_color(["'+L01+'","'+L02+'","'+L03+'","'+L04+'","'+L05+'","'+L06+'","'+L07+'","'+L08+'","'+L09+'","'+L10+'","'+L11+'","'+L12+'","'+L13+'","'+L14+'","'+L15+'","'+L16+'","'+L17+'","'+L18+'","'+L19+'","'+L20+'","'+L21+'","'+L22+'","'+L23+'","'+L24+'","'+L25+'"]);\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrixcode'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_matrixcode_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_clear'] = function(block) { - var code = 'MatrixLed_clear();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_on('+value_x_on_+','+value_y_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_on_ = Blockly.JavaScript.valueToCode(block, 'value_color_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color_on('+value_x_on_+','+value_y_on_+','+value_color_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_off'] = function(block) { - var value_x_off_ = Blockly.JavaScript.valueToCode(block, 'value_x_off_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_off_ = Blockly.JavaScript.valueToCode(block, 'value_y_off_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_off('+value_x_off_+','+value_y_off_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_reverse'] = function(block) { - var value_x_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_x_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_y_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_reverse('+value_x_reverse_+','+value_y_reverse_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_state'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_state('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_showstate'] = function(block) { - var value_showstate_ = block.getFieldValue('value_showstate_'); - var code = 'MatrixLed_showstate(fuMatrixLed,'+value_showstate_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_indentcode'] = function(block) { - var value_indentcode_ = Blockly.JavaScript.valueToCode(block, 'value_indentcode_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_indentcode('+value_indentcode_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_linechart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_linechart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_barchart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_barchart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_clockwise'] = function(block) { - var code = 'Matrixled_clockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_counterclockwise'] = function(block) { - var code = 'Matrixled_counterclockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_verticalflip'] = function(block) { - var code = 'Matrixled_verticalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_horizontalflip'] = function(block) { - var code = 'Matrixled_horizontalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_invert'] = function(block) { - var code = 'Matrixled_invert();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_getcolor'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_getcolor('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_backcolor'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_backcolor('+ value_color_ +');\n'; - return code; -}; diff --git a/bit_MatrixLed_20180722/blockly/msg/blocks/en.js b/bit_MatrixLed_20180722/blockly/msg/blocks/en.js deleted file mode 100644 index 2f75de45f8..0000000000 --- a/bit_MatrixLed_20180722/blockly/msg/blocks/en.js +++ /dev/null @@ -1,42 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "Matrix Led"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "Matrix Led (Full Color)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "Matrix Led Code"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "Clean Screen"; -Blockly.Msg.MATRIXLED_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "Turn Off"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "Switch"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "Get Led State"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "Led Color"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "Show Sample"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "Show Sample By Code"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "Show Marguee(CYCLE)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "Show Marguee(ONCE)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "Marguee Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "Marguee(Full Color) Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " Degree"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "Marguee Stop"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "Marguee Resume"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "Marguee Time (ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "Marguee Reverse"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "Show Character"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "Convert Text To Code"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "Show Screen"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "Indent Code"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "Line Chart "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "Bar Chart "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "Value1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "Value2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "Value3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "Value4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "Value5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "Rotate 90 Degrees Clockwise"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "Rotate 90 Degrees Counter Clockwise"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "Vertical Flip"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "Horizontal Flip"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "Invert"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "Get Color Code"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "Back Color"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "Matrix Led(Full Color) Code"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "Show Marguee(Full Color) CYCLE"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "Show Marguee(Full Color) ONCE"; diff --git a/bit_MatrixLed_20180722/blockly/msg/blocks/zh-hans.js b/bit_MatrixLed_20180722/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index f8d63fd79b..0000000000 --- a/bit_MatrixLed_20180722/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,42 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示灯(单色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示灯(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示灯(单色) 编码"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示灯 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗灯"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示灯 亮暗反转"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示灯 亮暗状态"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示灯(单色) 颜色"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "显示 图案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "显示 图案(编码)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑马灯(单色) 循环"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑马灯(单色) 单次"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑马灯(单色) 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "跑马灯(全彩) 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格数"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑马灯 暂停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑马灯 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑马灯 间隔时间(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑马灯 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "显示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "转换文字为编码"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示灯 显示"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "缩排编码"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折线图 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "长条图 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "数值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "数值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "数值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "数值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "数值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示灯 顺时钟旋转90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示灯 逆时钟旋转90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示灯 垂直翻转"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示灯 水平翻转"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示灯 开关反转"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示灯 色码值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示灯(单色) 背景颜色"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "指示灯(全彩) 编码"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "跑马灯(全彩) 循环"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "跑马灯(全彩) 单次"; diff --git a/bit_MatrixLed_20180722/blockly/msg/blocks/zh-hant.js b/bit_MatrixLed_20180722/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index addf734482..0000000000 --- a/bit_MatrixLed_20180722/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,42 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示燈(單色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示燈(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示燈(單色) 編碼"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示燈 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗燈"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示燈 亮暗反轉"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示燈 亮暗狀態"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示燈(單色) 顏色"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "顯示 圖案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "顯示 圖案(編碼)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑馬燈(單色) 循環"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑馬燈(單色) 單次"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑馬燈(單色) 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "跑馬燈(全彩) 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格數"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑馬燈 暫停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑馬燈 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑馬燈 間隔時間(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑馬燈 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "顯示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "轉換文字為編碼"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示燈 顯示"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "縮排編碼"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折線圖 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "長條圖 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "數值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "數值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "數值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "數值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "數值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示燈 順時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示燈 逆時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示燈 垂直翻轉"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示燈 水平翻轉"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示燈 開關反轉"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示燈 色碼值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示燈(單色) 背景顏色"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "指示燈(全彩) 編碼"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "跑馬燈(全彩) 循環"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "跑馬燈(全彩) 單次"; diff --git a/bit_MatrixLed_20180722/blockly/msg/en.js b/bit_MatrixLed_20180722/blockly/msg/en.js deleted file mode 100644 index 883a7b3522..0000000000 --- a/bit_MatrixLed_20180722/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "FuMatrixLed"; diff --git a/bit_MatrixLed_20180722/blockly/msg/zh-hans.js b/bit_MatrixLed_20180722/blockly/msg/zh-hans.js deleted file mode 100644 index 7d969d936c..0000000000 --- a/bit_MatrixLed_20180722/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "法兰斯点矩阵"; diff --git a/bit_MatrixLed_20180722/blockly/msg/zh-hant.js b/bit_MatrixLed_20180722/blockly/msg/zh-hant.js deleted file mode 100644 index e008529bf5..0000000000 --- a/bit_MatrixLed_20180722/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "法蘭斯點矩陣"; diff --git a/bit_MatrixLed_20180722/blockly/toolbox.xml b/bit_MatrixLed_20180722/blockly/toolbox.xml deleted file mode 100644 index eab18e3650..0000000000 --- a/bit_MatrixLed_20180722/blockly/toolbox.xml +++ /dev/null @@ -1,497 +0,0 @@ - - - fuMatrixLed - - - - - - 1 - - - - - 10 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - 0 - - - - - 0 - - - - - #ff0000 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - 500 - - - - - - - - - - - - - - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - - - - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - - - 1 - - - 1 - - - - - - - - - - - - - #000000 - - - - - - - #ff0000 - - - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - - - - - - - - - - - - - 0110011110011111111001100 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - 1 - - - 1 - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - diff --git a/bit_MatrixLed_20180722/matrixled.js b/bit_MatrixLed_20180722/matrixled.js deleted file mode 100644 index 1796f7dfa7..0000000000 --- a/bit_MatrixLed_20180722/matrixled.js +++ /dev/null @@ -1,784 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - const charA = "0111110010100101001001111"; - const charB = "1111110101101011010101010"; - const charC = "0111010001100011000110001"; - const charD = "1111110001100011000101110"; - const charE = "1111110101101011010110101"; - const charF = "1111110100101001010010100"; - const charG = "0111010001101011010110111"; - const charH = "1111100100001000010011111"; - const charI = "1000110001111111000110001"; - const charJ = "1001110001111111000010000"; - const charK = "1111100010001000101010001"; - const charL = "1111100001000010000100001"; - const charM = "1111101000001000100011111"; - const charN = "1111101000001000001011111"; - const charO = "0111010001100011000101110"; - const charP = "1111110010100101001001100"; - const charQ = "0111010001101011001001101"; - const charR = "1111110100101001010001011"; - const charS = "0100110101101011010110010"; - const charT = "1000010000111111000010000"; - const charU = "1111000001000010000111110"; - const charV = "1110000010000010001011100"; - const charW = "1111000001111100000111110"; - const charX = "1000101010001000101010001"; - const charY = "1000001000001110100010000"; - const charZ = "1000110011101011100110001"; - const chara = "0000000110010010011000001"; - const charb = "0000011111001010001000000"; - const charc = "0000000110010010100100000"; - const chard = "0000000010001011111100000"; - const chare = "0000000110010110010100000"; - const charf = "0000000100111111010000000"; - const charg = "0000000101010110011000000"; - const charh = "0000011111001000001100000"; - const chari = "0000000000101110000000000"; - const charj = "0000000001101110000000000"; - const chark = "0000011111000100010100000"; - const charl = "0000000000111110000000000"; - const charm = "0011100100000110010000011"; - const charn = "0000000111001000001100000"; - const charo = "0000000010001010001000000"; - const charp = "0000001111010100010000000"; - const charq = "0000000100010100111100000"; - const charr = "0000000111000100010000000"; - const chars = "0000001001101011001000000"; - const chart = "0000000100011110010100000"; - const charu = "0000000110000010011000001"; - const charv = "0000000110000010011000000"; - const charw = "0011000001001100000100110"; - const charx = "0000000101000100010100000"; - const chary = "0000000101000100010000000"; - const charz = "0000101011011010100000000"; - const char0 = "0000011111100011111100000"; - const char1 = "0000001001111110000100000"; - const char2 = "0000010111101011110100000"; - const char3 = "0000010101101011111100000"; - const char4 = "0000011100001001111100000"; - const char5 = "0000011101101011011100000"; - const char6 = "0000011111101011011100000"; - const char7 = "0000011000100001111100000"; - const char8 = "0000011111101011111100000"; - const char9 = "0000011101101011111100000"; - const comma = "0000000001000100000000000"; - const period = "0000000001000000000000000"; - const questionmark = "0100010000100111010001000"; - const exclamationmark = "0000000000111010000000000"; - const semicolon = "0000000001010100000000000"; - const colon = "0000000000010100000000000"; - const parenthesesleft = "0000001110100010000000000"; - const parenthesesright = "0000000000100010111000000"; - const squarebracketsleft = "0000011111100010000000000"; - const squarebracketsright = "0000000000100011111100000"; - const curlybracketsleft = "0000000100111111000100000"; - const curlybracketsright = "0000010001111110010000000"; - const Quotationmarkssingle = "0000000000110000010000000"; - const Quotationmarksdouble = "1100000100110000010000000"; - const hyphen = "0000000100001000010000000"; - const heart = "0110010010010011001001100"; - const heartfill = "0110011110011111111001100"; - const arrowup = "0010001000111110100000100"; - const arrowdown = "0010000010111110001000100"; - const arrowleft = "0010001110101010010000100"; - const arrowright = "0010000100101010111000100"; - const arrowleftup = "1111011000101001001000001"; - const arrowleftdown = "0111100011001010100110000"; - const arrowrightup = "0000110010101001100011110"; - const arrowrightdown = "1000001001001010001101111"; - const arrowupfill = "0000100111111110011100001"; - const arrowdownfill = "1000011100111111110010000"; - const arrowleftfill = "0010000100011100111011111"; - const arrowrightfill = "1111101110011100010000100"; - const noexist = "0000000000000000000000000"; - - var L = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var MatrixLedcolor = "#ff0000"; - var MatrixLedbackcolor = "#000000"; - var MatrixLedmarqueeinitial = "",MatrixLedmarqueecode = "",MatrixLedmarqueecodeonce = "",MatrixLedmarqueecolorcode = "",MatrixLedmarqueecolorcodeonce = ""; - var MatrixLedmarqueetime = 500; - var MatrixLedmarqueereverse = 1; - var MatrixLedshowstate = 1; - var marqueetimeid; - var marqueeactive; - var objMatrixLed; - - function MatrixLed_color(input_color_) { - MatrixLedcolor = input_color_; - } - - function MatrixLed_showstate(obj,input_showstate_) { - objMatrixLed=obj; - MatrixLedshowstate = input_showstate_; - } - - function MatrixLed_indentcode(input_indentcode_) { - var indentcode = input_indentcode_; - while (indentcode.search(/0000000000/)!=-1) - indentcode = indentcode.replace(/0000000000/g,"00000"); - return indentcode; - } - - function MatrixLed_marquee(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecodeonce = ""; - window.clearInterval(marqueetimeid); - if ((input_marquee_.length==25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLed_matrix(input_marquee_); - return; - } - else if ((input_marquee_.length%5==0)&&(input_marquee_.length>25)&&(input_marquee_.search(/[^0-1]/)==-1)) - MatrixLedmarqueecode = input_marquee_; - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLedmarqueecode = input_marquee_; - MatrixLedmarqueecodeonce = input_marquee_; - } - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_once_play() { - if (MatrixLedmarqueecode.length>=25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(5,MatrixLedmarqueecodeonce.length-5)+MatrixLedmarqueecodeonce.substr(0,5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(MatrixLedmarqueecodeonce.length-5,5)+MatrixLedmarqueecodeonce.substr(0,MatrixLedmarqueecodeonce.length-5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_degree(direction,degree) { - window.clearInterval(marqueetimeid); - if (MatrixLedmarqueecode.length25) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - } - } - - function MatrixLed_marquee_color(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecolorcodeonce = ""; - window.clearInterval(marqueetimeid); - if (input_marquee_.length==175) - { - MatrixLed_matrix_codetocolor(input_marquee_); - return; - } - else if ((input_marquee_.length%35==0)&&(input_marquee_.length>175)) - MatrixLedmarqueecolorcode = input_marquee_; - MatrixLedmarqueeinitial=MatrixLedmarqueecolorcode; - marqueeactive=3; - marqueetimeid = window.setInterval("MatrixLed_marquee_color_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_color_once(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueeinitial=input_marquee_; - window.clearInterval(marqueetimeid); - if (input_marquee_.length==175) - { - MatrixLed_matrix_codetocolor(input_marquee_); - return; - } - else if ((input_marquee_.length%35==0)&&(input_marquee_.length>175)) - { - MatrixLedmarqueecolorcode = input_marquee_; - MatrixLedmarqueecolorcodeonce = input_marquee_; - } - MatrixLedmarqueeinitial=MatrixLedmarqueecolorcode; - marqueeactive=4; - marqueetimeid = window.setInterval("MatrixLed_marquee_color_once_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_color_play() { - if (MatrixLedmarqueecolorcode.length>175) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35)+MatrixLedmarqueecolorcode.substr(0,35); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-175,175)); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-35,35)+MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_color_once_play() { - if (MatrixLedmarqueecolorcode.length>=175) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueecolorcodeonce.substr(35,MatrixLedmarqueecolorcodeonce.length-35)+MatrixLedmarqueecolorcodeonce.substr(0,35); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-175,175)); - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueecolorcodeonce.substr(MatrixLedmarqueecolorcodeonce.length-35,35)+MatrixLedmarqueecolorcodeonce.substr(0,MatrixLedmarqueecolorcodeonce.length-35); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_color_degree(direction,degree) { - window.clearInterval(marqueetimeid); - if (MatrixLedmarqueecolorcode.length175) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35)+MatrixLedmarqueecolorcode.substr(0,35); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-35,35)+MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - } - } - - function MatrixLed_marquee_time(input_time_) { - MatrixLedmarqueetime = input_time_; - } - - function MatrixLed_marquee_stop() { - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_resume() { - window.clearInterval(marqueetimeid); - if (marqueeactive==1) - marqueetimeid = window.setInterval("MatrixLed_marquee_play()",MatrixLedmarqueetime); - else if (marqueeactive==2) - marqueetimeid = window.setInterval("MatrixLed_marquee_once_play()",MatrixLedmarqueetime); - else if (marqueeactive==3) - marqueetimeid= window.setInterval("MatrixLed_marquee_color_play()",MatrixLedmarqueetime); - else if (marqueeactive==4) - marqueetimeid = window.setInterval("MatrixLed_marquee_color_once_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_reverse() { - MatrixLedmarqueecode = MatrixLedmarqueeinitial; - MatrixLedmarqueecodeonce = MatrixLedmarqueeinitial; - MatrixLedmarqueecolorcode = MatrixLedmarqueeinitial; - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueeinitial; - if (MatrixLedmarqueereverse==1) - MatrixLedmarqueereverse=2; - else if (MatrixLedmarqueereverse==2) - MatrixLedmarqueereverse=1; - } - - function MatrixLed_char(input_char_) { - input_char_=input_char_.toString(); - if (input_char_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_char_)); - } - } - - function MatrixLed_texttocode(input_text_) { - input_text_=input_text_.toString(); - if (input_text_.length>0) - { - var textcode=""; - for (var i=0;i=(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function Matrixled_clockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_counterclockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_verticalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[j+5*i]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_horizontalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[j+i*5]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_invert(){ - for (var i=0;i<25;i++) - { - if ((L[i]=="")||(L[i]==MatrixLedbackcolor)) - L[i]=MatrixLedcolor; - else - L[i]=MatrixLedbackcolor; - } - MatrixLed_show(); - } - - function MatrixLed_getcolor(input_x_,input_y_) { - return L[input_x_*5+input_y_]; - } - - function MatrixLed_backcolor(input_color_) { - MatrixLedbackcolor=input_color_; - } - - function MatrixLed_show() { - if (MatrixLedshowstate==1) - var ledtable ="00"+L[0].replace(/\#/ig, "")+"01"+L[5].replace(/\#/ig, "")+"02"+L[10].replace(/\#/ig, "")+"03"+L[15].replace(/\#/ig, "")+"04"+L[20].replace(/\#/ig, "") - + "05"+L[1].replace(/\#/ig, "")+"06"+L[6].replace(/\#/ig, "")+"07"+L[11].replace(/\#/ig, "")+"08"+L[16].replace(/\#/ig, "")+"09"+L[21].replace(/\#/ig, "") - + "0a"+L[2].replace(/\#/ig, "")+"0b"+L[7].replace(/\#/ig, "")+"0c"+L[12].replace(/\#/ig, "")+"0d"+L[17].replace(/\#/ig, "")+"0e"+L[22].replace(/\#/ig, "") - + "0f"+L[3].replace(/\#/ig, "")+"10"+L[8].replace(/\#/ig, "")+"11"+L[13].replace(/\#/ig, "")+"12"+L[18].replace(/\#/ig, "")+"13"+L[23].replace(/\#/ig, "") - + "14"+L[4].replace(/\#/ig, "")+"15"+L[9].replace(/\#/ig, "")+"16"+L[14].replace(/\#/ig, "")+"17"+L[19].replace(/\#/ig, "")+"18"+L[24].replace(/\#/ig, ""); - else - var ledtable ="00"+MatrixLedbackcolor.replace(/\#/ig, "")+"01"+MatrixLedbackcolor.replace(/\#/ig, "")+"02"+MatrixLedbackcolor.replace(/\#/ig, "")+"03"+MatrixLedbackcolor.replace(/\#/ig, "")+"04"+MatrixLedbackcolor.replace(/\#/ig, "") - + "05"+MatrixLedbackcolor.replace(/\#/ig, "")+"06"+MatrixLedbackcolor.replace(/\#/ig, "")+"07"+MatrixLedbackcolor.replace(/\#/ig, "")+"08"+MatrixLedbackcolor.replace(/\#/ig, "")+"09"+MatrixLedbackcolor.replace(/\#/ig, "") - + "0a"+MatrixLedbackcolor.replace(/\#/ig, "")+"0b"+MatrixLedbackcolor.replace(/\#/ig, "")+"0c"+MatrixLedbackcolor.replace(/\#/ig, "")+"0d"+MatrixLedbackcolor.replace(/\#/ig, "")+"0e"+MatrixLedbackcolor.replace(/\#/ig, "") - + "0f"+MatrixLedbackcolor.replace(/\#/ig, "")+"10"+MatrixLedbackcolor.replace(/\#/ig, "")+"11"+MatrixLedbackcolor.replace(/\#/ig, "")+"12"+MatrixLedbackcolor.replace(/\#/ig, "")+"13"+MatrixLedbackcolor.replace(/\#/ig, "") - + "14"+MatrixLedbackcolor.replace(/\#/ig, "")+"15"+MatrixLedbackcolor.replace(/\#/ig, "")+"16"+MatrixLedbackcolor.replace(/\#/ig, "")+"17"+MatrixLedbackcolor.replace(/\#/ig, "")+"18"+MatrixLedbackcolor.replace(/\#/ig, ""); - - objMatrixLed.setColor(ledtable); - } - - window.MatrixLed_clear = MatrixLed_clear; - window.MatrixLed_matrix = MatrixLed_matrix; - window.MatrixLed_matrix_color = MatrixLed_matrix_color; - window.MatrixLed_show = MatrixLed_show; - window.MatrixLed_on = MatrixLed_on; - window.MatrixLed_color_on = MatrixLed_color_on; - window.MatrixLed_off = MatrixLed_off; - window.MatrixLed_reverse = MatrixLed_reverse; - window.MatrixLed_state = MatrixLed_state; - window.MatrixLed_color = MatrixLed_color; - window.MatrixLed_sample = MatrixLed_sample; - window.MatrixLed_code = MatrixLed_code; - window.MatrixLed_marquee = MatrixLed_marquee; - window.MatrixLed_marquee_play = MatrixLed_marquee_play; - window.MatrixLed_marquee_once = MatrixLed_marquee_once; - window.MatrixLed_marquee_once_play = MatrixLed_marquee_once_play; - window.MatrixLed_marquee_color = MatrixLed_marquee_color; - window.MatrixLed_marquee_color_play = MatrixLed_marquee_color_play; - window.MatrixLed_marquee_color_once = MatrixLed_marquee_color_once; - window.MatrixLed_marquee_color_once_play = MatrixLed_marquee_color_once_play; - window.MatrixLed_matrix_codetocolor = MatrixLed_matrix_codetocolor; - window.MatrixLed_marquee_degree = MatrixLed_marquee_degree; - window.MatrixLed_marquee_color_degree = MatrixLed_marquee_color_degree; - window.MatrixLed_marquee_stop = MatrixLed_marquee_stop; - window.MatrixLed_marquee_resume = MatrixLed_marquee_resume; - window.MatrixLed_marquee_reverse = MatrixLed_marquee_reverse; - window.MatrixLed_marquee_time = MatrixLed_marquee_time; - window.MatrixLed_char = MatrixLed_char; - window.MatrixLed_conversion = MatrixLed_conversion; - window.MatrixLed_texttocode = MatrixLed_texttocode; - window.MatrixLed_showstate = MatrixLed_showstate; - window.MatrixLed_indentcode = MatrixLed_indentcode; - window.MatrixLed_linechart = MatrixLed_linechart; - window.MatrixLed_barchart = MatrixLed_barchart; - window.Matrixled_clockwise = Matrixled_clockwise; - window.Matrixled_counterclockwise = Matrixled_counterclockwise; - window.Matrixled_verticalflip = Matrixled_verticalflip; - window.Matrixled_horizontalflip = Matrixled_horizontalflip; - window.Matrixled_invert = Matrixled_invert; - window.MatrixLed_getcolor = MatrixLed_getcolor; - window.MatrixLed_backcolor = MatrixLed_backcolor; - -}(window, window.document)); diff --git a/bit_MatrixLed_20180809/blockly.json b/bit_MatrixLed_20180809/blockly.json deleted file mode 100644 index fb4e2836aa..0000000000 --- a/bit_MatrixLed_20180809/blockly.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "types": ["matrix_led_backcolor","matrix_led_verticalflip","matrix_led_horizontalflip","matrix_led_invert","matrix_led_getcolor","matrix_led_color","matrix_led_code","matrix_led_texttocode","matrix_led_indentcode","matrix_led_showstate","matrix_led_sample","matrix_led_matrix","matrix_led_matrix_color","matrix_led_matrixcode","matrix_led_matrixcode_color","matrix_led_clear","matrix_led_on","matrix_led_color_on","matrix_led_off","matrix_led_reverse","matrix_led_state","matrix_led_marquee","matrix_led_marquee_once","matrix_led_marquee_color","matrix_led_marquee_color_once","matrix_led_marquee_degree","matrix_led_marquee_color_degree","matrix_led_marquee_time","matrix_led_marquee_stop","matrix_led_marquee_reverse","matrix_led_marquee_resume","matrix_led_char","matrix_led_linechart","matrix_led_barchart","matrix_led_clockwise","matrix_led_counterclockwise"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "matrixled.js", - "fuLedMatrix.js", - "fuLedMatrix-blockly.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/bit_MatrixLed_20180809/blockly/blocks.js b/bit_MatrixLed_20180809/blockly/blocks.js deleted file mode 100644 index 690e0712fb..0000000000 --- a/bit_MatrixLed_20180809/blockly/blocks.js +++ /dev/null @@ -1,663 +0,0 @@ -Blockly.Blocks['matrix_led_brightness'] = { - init: function () { - this.appendValueInput('brightness_') - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_BRIGHTNESS_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_char'] = { - init: function() { - this.appendValueInput("value_char_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_CHAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - - -Blockly.Blocks['matrix_led_texttocode'] = { - init: function() { - this.appendValueInput("value_text_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_indentcode'] = { - init: function() { - this.appendValueInput("value_indentcode_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_INDENTCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_showstate'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW) - .appendField(new Blockly.FieldDropdown([["on","1"], ["off","0"]]), "value_showstate_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_color_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_stop'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_resume'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_marquee_time'] = { - init: function() { - this.appendValueInput("value_marquee_time_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_sample'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SAMPLE_SHOW) - .appendField(new Blockly.FieldDropdown([["♥","♥"], ["♡","♡"], ["↑","↑"], ["↓","↓"], ["←","←"], ["→","→"], ["↖","↖"], ["↙","↙"], ["↗","↗"], ["↘","↘"], ["▲","▲"], ["▼","▼"], ["◄","◄"], ["►","►"], ["O","O"], ["X","X"], ["V","V"]]), "value_sample_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setTooltip(''); - this.setColour(300); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_code'] = { - init: function() { - this.appendValueInput("value_code_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_CODE_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrix_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L01') - .appendField(new Blockly.FieldColour("#000000"), 'L06') - .appendField(new Blockly.FieldColour("#000000"), 'L11') - .appendField(new Blockly.FieldColour("#000000"), 'L16') - .appendField(new Blockly.FieldColour("#000000"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L02') - .appendField(new Blockly.FieldColour("#000000"), 'L07') - .appendField(new Blockly.FieldColour("#000000"), 'L12') - .appendField(new Blockly.FieldColour("#000000"), 'L17') - .appendField(new Blockly.FieldColour("#000000"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L03') - .appendField(new Blockly.FieldColour("#000000"), 'L08') - .appendField(new Blockly.FieldColour("#000000"), 'L13') - .appendField(new Blockly.FieldColour("#000000"), 'L18') - .appendField(new Blockly.FieldColour("#000000"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L04') - .appendField(new Blockly.FieldColour("#000000"), 'L09') - .appendField(new Blockly.FieldColour("#000000"), 'L14') - .appendField(new Blockly.FieldColour("#000000"), 'L19') - .appendField(new Blockly.FieldColour("#000000"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L05') - .appendField(new Blockly.FieldColour("#000000"), 'L10') - .appendField(new Blockly.FieldColour("#000000"), 'L15') - .appendField(new Blockly.FieldColour("#000000"), 'L20') - .appendField(new Blockly.FieldColour("#000000"), 'L25') - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; - -Blockly.Blocks['matrix_led_matrixcode'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_matrixcode_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L01') - .appendField(new Blockly.FieldColour("#000000"), 'L06') - .appendField(new Blockly.FieldColour("#000000"), 'L11') - .appendField(new Blockly.FieldColour("#000000"), 'L16') - .appendField(new Blockly.FieldColour("#000000"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L02') - .appendField(new Blockly.FieldColour("#000000"), 'L07') - .appendField(new Blockly.FieldColour("#000000"), 'L12') - .appendField(new Blockly.FieldColour("#000000"), 'L17') - .appendField(new Blockly.FieldColour("#000000"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L03') - .appendField(new Blockly.FieldColour("#000000"), 'L08') - .appendField(new Blockly.FieldColour("#000000"), 'L13') - .appendField(new Blockly.FieldColour("#000000"), 'L18') - .appendField(new Blockly.FieldColour("#000000"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L04') - .appendField(new Blockly.FieldColour("#000000"), 'L09') - .appendField(new Blockly.FieldColour("#000000"), 'L14') - .appendField(new Blockly.FieldColour("#000000"), 'L19') - .appendField(new Blockly.FieldColour("#000000"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L05') - .appendField(new Blockly.FieldColour("#000000"), 'L10') - .appendField(new Blockly.FieldColour("#000000"), 'L15') - .appendField(new Blockly.FieldColour("#000000"), 'L20') - .appendField(new Blockly.FieldColour("#000000"), 'L25') - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(''); - this.setHelpUrl(''); - } -}; - -Blockly.Blocks['matrix_led_clear'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLEAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_color_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COLOR_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.appendValueInput("value_color_on_") - .setCheck("Colour") - .appendField("color"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_off'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_OFF_SHOW); - this.appendValueInput("value_x_off_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_off_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_REVERSE_SHOW); - this.appendValueInput("value_x_reverse_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_reverse_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_state'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_STATE_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_linechart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_LINECHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_barchart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_BARCHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_clockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_counterclockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_verticalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_horizontalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_invert'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_INVERT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_getcolor'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_GETCOLOR_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['matrix_led_backcolor'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/bit_MatrixLed_20180809/blockly/javascript.js b/bit_MatrixLed_20180809/blockly/javascript.js deleted file mode 100644 index 6e3b85bd86..0000000000 --- a/bit_MatrixLed_20180809/blockly/javascript.js +++ /dev/null @@ -1,327 +0,0 @@ -Blockly.JavaScript['matrix_led_brightness'] = function (block) { - var value_brightness_ = Blockly.JavaScript.valueToCode(block, 'brightness_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'fuMatrixLed.brightness(' + value_brightness_ + ');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_showstate'] = function(block) { - Blockly.JavaScript.definitions_['var_fuMatrixLed'] = 'var fuMatrixLed;'; - - var value_showstate_ = block.getFieldValue('value_showstate_'); - var code = 'fuMatrixLed = getMatrix(board, 4, 25);\nMatrixLed_showstate(fuMatrixLed,'+value_showstate_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_char'] = function(block) { - var value_char_ = Blockly.JavaScript.valueToCode(block, 'value_char_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_char('+ value_char_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_time'] = function(block) { - var value_marquee_time_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_time_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_time('+ value_marquee_time_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_stop'] = function(block) { - var code = 'MatrixLed_marquee_stop();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_resume'] = function(block) { - var code = 'MatrixLed_marquee_resume();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_reverse'] = function(block) { - var code = 'MatrixLed_marquee_reverse();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color('+ value_color_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_texttocode'] = function(block) { - var value_text_ = Blockly.JavaScript.valueToCode(block, 'value_text_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_texttocode('+value_text_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_sample'] = function(block) { - var value_sample_ = block.getFieldValue('value_sample_'); - var code = 'MatrixLed_sample("'+ value_sample_ +'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_code'] = function(block) { - var value_code_ = Blockly.JavaScript.valueToCode(block, 'value_code_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_code('+ value_code_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = 'MatrixLed_matrix("'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = 'MatrixLed_matrix_color(["'+L01+'","'+L02+'","'+L03+'","'+L04+'","'+L05+'","'+L06+'","'+L07+'","'+L08+'","'+L09+'","'+L10+'","'+L11+'","'+L12+'","'+L13+'","'+L14+'","'+L15+'","'+L16+'","'+L17+'","'+L18+'","'+L19+'","'+L20+'","'+L21+'","'+L22+'","'+L23+'","'+L24+'","'+L25+'"]);\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrixcode'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_matrixcode_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_clear'] = function(block) { - var code = 'MatrixLed_clear();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_on('+value_x_on_+','+value_y_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_on_ = Blockly.JavaScript.valueToCode(block, 'value_color_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color_on('+value_x_on_+','+value_y_on_+','+value_color_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_off'] = function(block) { - var value_x_off_ = Blockly.JavaScript.valueToCode(block, 'value_x_off_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_off_ = Blockly.JavaScript.valueToCode(block, 'value_y_off_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_off('+value_x_off_+','+value_y_off_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_reverse'] = function(block) { - var value_x_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_x_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_y_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_reverse('+value_x_reverse_+','+value_y_reverse_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_state'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_state('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_indentcode'] = function(block) { - var value_indentcode_ = Blockly.JavaScript.valueToCode(block, 'value_indentcode_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_indentcode('+value_indentcode_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_linechart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_linechart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_barchart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_barchart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_clockwise'] = function(block) { - var code = 'Matrixled_clockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_counterclockwise'] = function(block) { - var code = 'Matrixled_counterclockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_verticalflip'] = function(block) { - var code = 'Matrixled_verticalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_horizontalflip'] = function(block) { - var code = 'Matrixled_horizontalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_invert'] = function(block) { - var code = 'Matrixled_invert();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_getcolor'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_getcolor('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_backcolor'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_backcolor('+ value_color_ +');\n'; - return code; -}; diff --git a/bit_MatrixLed_20180809/blockly/msg/blocks/en.js b/bit_MatrixLed_20180809/blockly/msg/blocks/en.js deleted file mode 100644 index 1f3caedf95..0000000000 --- a/bit_MatrixLed_20180809/blockly/msg/blocks/en.js +++ /dev/null @@ -1,43 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "Matrix Led"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "Matrix Led (Full Color)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "Matrix Led Code"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "Clean Screen"; -Blockly.Msg.MATRIXLED_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "Turn Off"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "Switch"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "Get Led State"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "Led Color"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "Show Sample"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "Show Sample By Code"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "Show Marguee(CYCLE)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "Show Marguee(ONCE)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "Marguee Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "Marguee(Full Color) Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " Degree"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "Marguee Stop"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "Marguee Resume"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "Marguee Time (ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "Marguee Reverse"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "Show Character"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "Convert Text To Code"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "Show Screen (Initalize)"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "Indent Code"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "Line Chart "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "Bar Chart "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "Value1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "Value2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "Value3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "Value4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "Value5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "Rotate 90 Degrees Clockwise"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "Rotate 90 Degrees Counter Clockwise"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "Vertical Flip"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "Horizontal Flip"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "Invert"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "Get Color Code"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "Back Color"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "Matrix Led(Full Color) Code"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "Show Marguee(Full Color) CYCLE"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "Show Marguee(Full Color) ONCE"; -Blockly.Msg.MATRIXLED_BRIGHTNESS_SHOW = "Set Brightness (0~20)"; diff --git a/bit_MatrixLed_20180809/blockly/msg/blocks/zh-hans.js b/bit_MatrixLed_20180809/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 47f83a6bf9..0000000000 --- a/bit_MatrixLed_20180809/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,43 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示灯(单色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示灯(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示灯(单色) 编码"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示灯 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗灯"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示灯 亮暗反转"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示灯 亮暗状态"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示灯(单色) 颜色"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "显示 图案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "显示 图案(编码)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑马灯(单色) 循环"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑马灯(单色) 单次"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑马灯(单色) 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "跑马灯(全彩) 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格数"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑马灯 暂停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑马灯 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑马灯 间隔时间(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑马灯 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "显示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "转换文字为编码"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示灯 显示(初始化)"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "缩排编码"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折线图 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "长条图 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "数值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "数值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "数值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "数值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "数值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示灯 顺时钟旋转90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示灯 逆时钟旋转90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示灯 垂直翻转"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示灯 水平翻转"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示灯 开关反转"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示灯 色码值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示灯(单色) 背景颜色"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "指示灯(全彩) 编码"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "跑马灯(全彩) 循环"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "跑马灯(全彩) 单次"; -Blockly.Msg.MATRIXLED_BRIGHTNESS_SHOW = "指示灯 亮度 (0~20)"; diff --git a/bit_MatrixLed_20180809/blockly/msg/blocks/zh-hant.js b/bit_MatrixLed_20180809/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 99d71d1e15..0000000000 --- a/bit_MatrixLed_20180809/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,43 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示燈(單色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示燈(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示燈(單色) 編碼"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示燈 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗燈"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示燈 亮暗反轉"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示燈 亮暗狀態"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示燈(單色) 顏色"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "顯示 圖案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "顯示 圖案(編碼)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑馬燈(單色) 循環"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑馬燈(單色) 單次"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑馬燈(單色) 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "跑馬燈(全彩) 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格數"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑馬燈 暫停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑馬燈 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑馬燈 間隔時間(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑馬燈 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "顯示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "轉換文字為編碼"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示燈 顯示(初始化)"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "縮排編碼"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折線圖 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "長條圖 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "數值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "數值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "數值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "數值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "數值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示燈 順時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示燈 逆時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示燈 垂直翻轉"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示燈 水平翻轉"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示燈 開關反轉"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示燈 色碼值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示燈(單色) 背景顏色"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "指示燈(全彩) 編碼"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "跑馬燈(全彩) 循環"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "跑馬燈(全彩) 單次"; -Blockly.Msg.MATRIXLED_BRIGHTNESS_SHOW = "指示燈 亮度 (0~20)"; diff --git a/bit_MatrixLed_20180809/blockly/msg/en.js b/bit_MatrixLed_20180809/blockly/msg/en.js deleted file mode 100644 index 883a7b3522..0000000000 --- a/bit_MatrixLed_20180809/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "FuMatrixLed"; diff --git a/bit_MatrixLed_20180809/blockly/msg/zh-hans.js b/bit_MatrixLed_20180809/blockly/msg/zh-hans.js deleted file mode 100644 index 7d969d936c..0000000000 --- a/bit_MatrixLed_20180809/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "法兰斯点矩阵"; diff --git a/bit_MatrixLed_20180809/blockly/msg/zh-hant.js b/bit_MatrixLed_20180809/blockly/msg/zh-hant.js deleted file mode 100644 index e008529bf5..0000000000 --- a/bit_MatrixLed_20180809/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "法蘭斯點矩陣"; diff --git a/bit_MatrixLed_20180809/blockly/toolbox.xml b/bit_MatrixLed_20180809/blockly/toolbox.xml deleted file mode 100644 index d6eb1707d4..0000000000 --- a/bit_MatrixLed_20180809/blockly/toolbox.xml +++ /dev/null @@ -1,491 +0,0 @@ - - - 1 - - - - - 10 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - 0 - - - - - 0 - - - - - #ff0000 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - 500 - - - - - - - - - - - - - - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - - - - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - - - 1 - - - 1 - - - - - - - - - - - - - #000000 - - - - - - - #ff0000 - - - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - - - - - - - - - - - - - 0110011110011111111001100 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - 1 - - - 1 - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - diff --git a/bit_MatrixLed_20180809/fuLedMatrix-blockly.js b/bit_MatrixLed_20180809/fuLedMatrix-blockly.js deleted file mode 100644 index 08f6173302..0000000000 --- a/bit_MatrixLed_20180809/fuLedMatrix-blockly.js +++ /dev/null @@ -1,14 +0,0 @@ -+(function (factory) { - if (typeof exports === 'undefined') { - factory(window, window.webduino); - } else { - module.exports = factory; - } -}(function (scope, webduino) { - - 'use strict'; - - scope.getMatrix = function (board, pin, leds) { - return new webduino.module.Matrix(board, pin, leds); - }; -})); \ No newline at end of file diff --git a/bit_MatrixLed_20180809/fuLedMatrix.js b/bit_MatrixLed_20180809/fuLedMatrix.js deleted file mode 100644 index 0b235ec823..0000000000 --- a/bit_MatrixLed_20180809/fuLedMatrix.js +++ /dev/null @@ -1,275 +0,0 @@ -+(function (factory) { - if (typeof exports === 'undefined') { - factory(webduino || {}); - } else { - module.exports = factory; - } -}(function (scope) { - 'use strict'; - - var self; - var proto; - var sendLength = 50; - var sendArray = []; - var sendAck = ''; - var sendCallback; - var Module = scope.Module; - var BoardEvent = scope.BoardEvent; - var _backlight; - - function Matrix(board, pin, leds) { - Module.call(this); - this._board = board; - self = this; - self._pin = pin; - self._leds = leds; - var cmd = ''; - if (leds <= 64) { - cmd = [0xF0, 0x04, 0x21, 0x0 /*init*/ , leds, pin, 0xF7]; - } else { - var h6bit = leds >>> 6; - var l6bit = leds & 0x3F; - cmd = [0xF0, 0x04, 0x21, 0x4 /*init*/ , h6bit, l6bit, pin, 0xF7]; - } - board.send(cmd); - board.on(BoardEvent.SYSEX_MESSAGE, - function (event) { - var m = event.message; - }); - } - - Matrix.prototype = proto = Object.create(Module.prototype, { - constructor: { - value: Matrix - }, - backlight: { - get: function () { - return _backlight; - }, - set: function (val) { - _backlight = val; - } - } - }); - - proto.setColorByString = function (led, color) { - if (led > 64) { - this.setColor64(led, color); - return; - } - var data = ''; - var cmd = [0xF0, 0x04, 0x21, 0x03]; - if (arguments.length == 1) { - data = led; - this.setColorByPiece(data); - return; - } else { - var R = color.substring(1,3); - var G = color.substring(3,5); - var B = color.substring(5,7); - - var RG24 = (((parseInt(R,16)>>6)&0x3)<<4) | (parseInt(G,16)>>4); - var RB24 = (((parseInt(R,16)>>4)&0x3)<<4) | (parseInt(B,16)>>4); - - cmd.push(led); - cmd.push(RG24); - cmd.push(RB24); - } -/* - data = data.concat(toHex(led)); - data = data.concat(color.substring(1)); - } - for (var i = 0; i < data.length; i++) { - cmd.push(data.charCodeAt(i)) - } -*/ - cmd.push(0xF7); - this._board.send(cmd); - this._board.flush(); - } - - proto.setColorByPiece = function (allData) { - var self = this; - - function sendPiece(data) { - var cmd = [0xF0, 0x04, 0x21, 0x03]; - cmd.push(0x40); - for (var i = 0; i < data.length; i+=8) { - var led = data.substring(i,i+2); - var R = data.substring(i+2,i+4); - var G = data.substring(i+4,i+6); - var B = data.substring(i+6,i+8); - - var RG24 = (((parseInt(R,16)>>6)&0x3)<<4) | (parseInt(G,16)>>4); - var RB24 = (((parseInt(R,16)>>4)&0x3)<<4) | (parseInt(B,16)>>4); - - cmd.push(RG24); - cmd.push(RB24); - } - cmd.push(0xF7); - self._board.send(cmd); - self._board.flush(); - } - - // the maximum packet size is 64 bytes - sendPiece(allData); -/* - function sendPiece(data) { - var cmd = [0xF0, 0x04, 0x21, 0x03]; - for (var i = 0; i < data.length; i++) { - cmd.push(data.charCodeAt(i)); - } - cmd.push(0xF7); - self._board.send(cmd); - self._board.flush(); - } - // the maximum packet size is 64 bytes - sendPiece(allData.substring(0, 56)); - sendPiece(allData.substring(56, 112)); - sendPiece(allData.substring(112, 168)); - sendPiece(allData.substring(168)); -*/ - } - - proto.setColor64 = function (led, color) { - var data = ''; - var cmd = [0xF0, 0x04, 0x21, 0x05]; - - cmd.push(led >>> 6); - cmd.push(led & 0x3F); - data = data.concat(color.substring(1)); - for (var i = 0; i < data.length; i++) { - cmd.push(data.charCodeAt(i)) - } - cmd.push(0xF7); - this._board.send(cmd); - this._board.flush(); - } - - proto.off = function () { - this._board.send([0xF0, 0x04, 0x21, 0x02, 0xF7]); - } - - proto.brightness = function (b) { - var data = toHex(b); - this._board.send([0xF0, 0x04, 0x21, 0x01, b, 0xF7]); - this._board.flush(); - } - - function toHex(num) { - var str = num.toString(16); - if (parseInt(num) < 16) { - str = '0' + str; - } - return str; - } - - proto.setCharacter = function (character, color) { - var charMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!=~@abcdefghijklmnopqrstuvwxyz+/-*\",\'<>.0123456789"; // ~ = :) , @ = (heart) - var data = ''; - var cmd = [0xF0, 0x04, 0x21, 0x04]; - var ch = ''; - - if (character) { - ch = String(character); - ch = Array.from(ch).shift(); - } - - if (charMap.indexOf(ch) === -1 || !color) { - return; - } - - data = data.concat(color.substring(1)); - for (var i = 0; i < data.length && i < 54; i++) { - cmd.push(data.charCodeAt(i)); - } - cmd.push(ch.charCodeAt(0)); - cmd.push(0xF7); - this._board.send(cmd); - this._board.flush(); - } - - proto.setString = function (str, color, speed) { - var data = ''; - var cmd = [0xF0, 0x04, 0x21, 0x05]; - - data = data.concat(color.substring(1)); - for (var i = 0; i < data.length; i++) { - cmd.push(data.charCodeAt(i)); - } - cmd.push(speed); - str = String(str); - for (var i = 0; i < str.length && i < 54; i++) { - cmd.push(str.charCodeAt(i)); - } - cmd.push(0xF7); - this._board.send(cmd); - this._board.flush(); - } - - proto.setColor = function(data, color){ - if (arguments.length == 2) { - this.setColorByString(data, color); - } else { - let markup = (m) =>{ - let a = m; - if(m.length < 6){ - if(m.length == 3){ - let b = a.split(''); - let long = ''; - b.map((t)=>{ - long = long + t + t; - }); - a = long; - }else{ - for(let j=0; j<(6-m.length); j++){ - a = a + '0'; - } - } - }else if(m.length > 6){ - a = m.slice(0, 6); - } - return a; - } - let draw = (e,c) =>{ - let colorArray = []; - for(let i=0; i<25; i++){ - let index; - if (i < 16) { - index = '0' + i.toString(16); - } else { - index = i.toString(16); - } - if(e[i]){ - colorArray[i] = index + markup(e[i]); - }else{ - colorArray[i] = index + markup(c[0]);; - } - } - return colorArray.join().replace(/,/g,''); - } - let colorCodeGen = (data) => { - if(Array.isArray(data)){ - data = data.join(); - } - let colorArr = data.replace(/\[|\]|\'|\"| |#|/g,'').split(','); - let outputData; - if(colorArr.length>1){ - outputData = draw(colorArr,['000000']); - }else{ - if(colorArr[0].length==200 && colorArr[0].indexOf('0f')!=-1){ - outputData = colorArr[0]; - }else{ - outputData = draw(colorArr,colorArr); - } - } - outputData = outputData.slice(0, 200); - return outputData; - } - - this.setColorByString(colorCodeGen(data)); - } - } - - scope.module.Matrix = Matrix; -})); diff --git a/bit_MatrixLed_20180809/matrixled.js b/bit_MatrixLed_20180809/matrixled.js deleted file mode 100644 index 1796f7dfa7..0000000000 --- a/bit_MatrixLed_20180809/matrixled.js +++ /dev/null @@ -1,784 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - const charA = "0111110010100101001001111"; - const charB = "1111110101101011010101010"; - const charC = "0111010001100011000110001"; - const charD = "1111110001100011000101110"; - const charE = "1111110101101011010110101"; - const charF = "1111110100101001010010100"; - const charG = "0111010001101011010110111"; - const charH = "1111100100001000010011111"; - const charI = "1000110001111111000110001"; - const charJ = "1001110001111111000010000"; - const charK = "1111100010001000101010001"; - const charL = "1111100001000010000100001"; - const charM = "1111101000001000100011111"; - const charN = "1111101000001000001011111"; - const charO = "0111010001100011000101110"; - const charP = "1111110010100101001001100"; - const charQ = "0111010001101011001001101"; - const charR = "1111110100101001010001011"; - const charS = "0100110101101011010110010"; - const charT = "1000010000111111000010000"; - const charU = "1111000001000010000111110"; - const charV = "1110000010000010001011100"; - const charW = "1111000001111100000111110"; - const charX = "1000101010001000101010001"; - const charY = "1000001000001110100010000"; - const charZ = "1000110011101011100110001"; - const chara = "0000000110010010011000001"; - const charb = "0000011111001010001000000"; - const charc = "0000000110010010100100000"; - const chard = "0000000010001011111100000"; - const chare = "0000000110010110010100000"; - const charf = "0000000100111111010000000"; - const charg = "0000000101010110011000000"; - const charh = "0000011111001000001100000"; - const chari = "0000000000101110000000000"; - const charj = "0000000001101110000000000"; - const chark = "0000011111000100010100000"; - const charl = "0000000000111110000000000"; - const charm = "0011100100000110010000011"; - const charn = "0000000111001000001100000"; - const charo = "0000000010001010001000000"; - const charp = "0000001111010100010000000"; - const charq = "0000000100010100111100000"; - const charr = "0000000111000100010000000"; - const chars = "0000001001101011001000000"; - const chart = "0000000100011110010100000"; - const charu = "0000000110000010011000001"; - const charv = "0000000110000010011000000"; - const charw = "0011000001001100000100110"; - const charx = "0000000101000100010100000"; - const chary = "0000000101000100010000000"; - const charz = "0000101011011010100000000"; - const char0 = "0000011111100011111100000"; - const char1 = "0000001001111110000100000"; - const char2 = "0000010111101011110100000"; - const char3 = "0000010101101011111100000"; - const char4 = "0000011100001001111100000"; - const char5 = "0000011101101011011100000"; - const char6 = "0000011111101011011100000"; - const char7 = "0000011000100001111100000"; - const char8 = "0000011111101011111100000"; - const char9 = "0000011101101011111100000"; - const comma = "0000000001000100000000000"; - const period = "0000000001000000000000000"; - const questionmark = "0100010000100111010001000"; - const exclamationmark = "0000000000111010000000000"; - const semicolon = "0000000001010100000000000"; - const colon = "0000000000010100000000000"; - const parenthesesleft = "0000001110100010000000000"; - const parenthesesright = "0000000000100010111000000"; - const squarebracketsleft = "0000011111100010000000000"; - const squarebracketsright = "0000000000100011111100000"; - const curlybracketsleft = "0000000100111111000100000"; - const curlybracketsright = "0000010001111110010000000"; - const Quotationmarkssingle = "0000000000110000010000000"; - const Quotationmarksdouble = "1100000100110000010000000"; - const hyphen = "0000000100001000010000000"; - const heart = "0110010010010011001001100"; - const heartfill = "0110011110011111111001100"; - const arrowup = "0010001000111110100000100"; - const arrowdown = "0010000010111110001000100"; - const arrowleft = "0010001110101010010000100"; - const arrowright = "0010000100101010111000100"; - const arrowleftup = "1111011000101001001000001"; - const arrowleftdown = "0111100011001010100110000"; - const arrowrightup = "0000110010101001100011110"; - const arrowrightdown = "1000001001001010001101111"; - const arrowupfill = "0000100111111110011100001"; - const arrowdownfill = "1000011100111111110010000"; - const arrowleftfill = "0010000100011100111011111"; - const arrowrightfill = "1111101110011100010000100"; - const noexist = "0000000000000000000000000"; - - var L = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var MatrixLedcolor = "#ff0000"; - var MatrixLedbackcolor = "#000000"; - var MatrixLedmarqueeinitial = "",MatrixLedmarqueecode = "",MatrixLedmarqueecodeonce = "",MatrixLedmarqueecolorcode = "",MatrixLedmarqueecolorcodeonce = ""; - var MatrixLedmarqueetime = 500; - var MatrixLedmarqueereverse = 1; - var MatrixLedshowstate = 1; - var marqueetimeid; - var marqueeactive; - var objMatrixLed; - - function MatrixLed_color(input_color_) { - MatrixLedcolor = input_color_; - } - - function MatrixLed_showstate(obj,input_showstate_) { - objMatrixLed=obj; - MatrixLedshowstate = input_showstate_; - } - - function MatrixLed_indentcode(input_indentcode_) { - var indentcode = input_indentcode_; - while (indentcode.search(/0000000000/)!=-1) - indentcode = indentcode.replace(/0000000000/g,"00000"); - return indentcode; - } - - function MatrixLed_marquee(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecodeonce = ""; - window.clearInterval(marqueetimeid); - if ((input_marquee_.length==25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLed_matrix(input_marquee_); - return; - } - else if ((input_marquee_.length%5==0)&&(input_marquee_.length>25)&&(input_marquee_.search(/[^0-1]/)==-1)) - MatrixLedmarqueecode = input_marquee_; - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLedmarqueecode = input_marquee_; - MatrixLedmarqueecodeonce = input_marquee_; - } - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_once_play() { - if (MatrixLedmarqueecode.length>=25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(5,MatrixLedmarqueecodeonce.length-5)+MatrixLedmarqueecodeonce.substr(0,5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(MatrixLedmarqueecodeonce.length-5,5)+MatrixLedmarqueecodeonce.substr(0,MatrixLedmarqueecodeonce.length-5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_degree(direction,degree) { - window.clearInterval(marqueetimeid); - if (MatrixLedmarqueecode.length25) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - } - } - - function MatrixLed_marquee_color(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecolorcodeonce = ""; - window.clearInterval(marqueetimeid); - if (input_marquee_.length==175) - { - MatrixLed_matrix_codetocolor(input_marquee_); - return; - } - else if ((input_marquee_.length%35==0)&&(input_marquee_.length>175)) - MatrixLedmarqueecolorcode = input_marquee_; - MatrixLedmarqueeinitial=MatrixLedmarqueecolorcode; - marqueeactive=3; - marqueetimeid = window.setInterval("MatrixLed_marquee_color_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_color_once(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueeinitial=input_marquee_; - window.clearInterval(marqueetimeid); - if (input_marquee_.length==175) - { - MatrixLed_matrix_codetocolor(input_marquee_); - return; - } - else if ((input_marquee_.length%35==0)&&(input_marquee_.length>175)) - { - MatrixLedmarqueecolorcode = input_marquee_; - MatrixLedmarqueecolorcodeonce = input_marquee_; - } - MatrixLedmarqueeinitial=MatrixLedmarqueecolorcode; - marqueeactive=4; - marqueetimeid = window.setInterval("MatrixLed_marquee_color_once_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_color_play() { - if (MatrixLedmarqueecolorcode.length>175) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35)+MatrixLedmarqueecolorcode.substr(0,35); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-175,175)); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-35,35)+MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_color_once_play() { - if (MatrixLedmarqueecolorcode.length>=175) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueecolorcodeonce.substr(35,MatrixLedmarqueecolorcodeonce.length-35)+MatrixLedmarqueecolorcodeonce.substr(0,35); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-175,175)); - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueecolorcodeonce.substr(MatrixLedmarqueecolorcodeonce.length-35,35)+MatrixLedmarqueecolorcodeonce.substr(0,MatrixLedmarqueecolorcodeonce.length-35); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_color_degree(direction,degree) { - window.clearInterval(marqueetimeid); - if (MatrixLedmarqueecolorcode.length175) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35)+MatrixLedmarqueecolorcode.substr(0,35); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-35,35)+MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - } - } - - function MatrixLed_marquee_time(input_time_) { - MatrixLedmarqueetime = input_time_; - } - - function MatrixLed_marquee_stop() { - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_resume() { - window.clearInterval(marqueetimeid); - if (marqueeactive==1) - marqueetimeid = window.setInterval("MatrixLed_marquee_play()",MatrixLedmarqueetime); - else if (marqueeactive==2) - marqueetimeid = window.setInterval("MatrixLed_marquee_once_play()",MatrixLedmarqueetime); - else if (marqueeactive==3) - marqueetimeid= window.setInterval("MatrixLed_marquee_color_play()",MatrixLedmarqueetime); - else if (marqueeactive==4) - marqueetimeid = window.setInterval("MatrixLed_marquee_color_once_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_reverse() { - MatrixLedmarqueecode = MatrixLedmarqueeinitial; - MatrixLedmarqueecodeonce = MatrixLedmarqueeinitial; - MatrixLedmarqueecolorcode = MatrixLedmarqueeinitial; - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueeinitial; - if (MatrixLedmarqueereverse==1) - MatrixLedmarqueereverse=2; - else if (MatrixLedmarqueereverse==2) - MatrixLedmarqueereverse=1; - } - - function MatrixLed_char(input_char_) { - input_char_=input_char_.toString(); - if (input_char_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_char_)); - } - } - - function MatrixLed_texttocode(input_text_) { - input_text_=input_text_.toString(); - if (input_text_.length>0) - { - var textcode=""; - for (var i=0;i=(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function Matrixled_clockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_counterclockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_verticalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[j+5*i]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_horizontalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[j+i*5]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_invert(){ - for (var i=0;i<25;i++) - { - if ((L[i]=="")||(L[i]==MatrixLedbackcolor)) - L[i]=MatrixLedcolor; - else - L[i]=MatrixLedbackcolor; - } - MatrixLed_show(); - } - - function MatrixLed_getcolor(input_x_,input_y_) { - return L[input_x_*5+input_y_]; - } - - function MatrixLed_backcolor(input_color_) { - MatrixLedbackcolor=input_color_; - } - - function MatrixLed_show() { - if (MatrixLedshowstate==1) - var ledtable ="00"+L[0].replace(/\#/ig, "")+"01"+L[5].replace(/\#/ig, "")+"02"+L[10].replace(/\#/ig, "")+"03"+L[15].replace(/\#/ig, "")+"04"+L[20].replace(/\#/ig, "") - + "05"+L[1].replace(/\#/ig, "")+"06"+L[6].replace(/\#/ig, "")+"07"+L[11].replace(/\#/ig, "")+"08"+L[16].replace(/\#/ig, "")+"09"+L[21].replace(/\#/ig, "") - + "0a"+L[2].replace(/\#/ig, "")+"0b"+L[7].replace(/\#/ig, "")+"0c"+L[12].replace(/\#/ig, "")+"0d"+L[17].replace(/\#/ig, "")+"0e"+L[22].replace(/\#/ig, "") - + "0f"+L[3].replace(/\#/ig, "")+"10"+L[8].replace(/\#/ig, "")+"11"+L[13].replace(/\#/ig, "")+"12"+L[18].replace(/\#/ig, "")+"13"+L[23].replace(/\#/ig, "") - + "14"+L[4].replace(/\#/ig, "")+"15"+L[9].replace(/\#/ig, "")+"16"+L[14].replace(/\#/ig, "")+"17"+L[19].replace(/\#/ig, "")+"18"+L[24].replace(/\#/ig, ""); - else - var ledtable ="00"+MatrixLedbackcolor.replace(/\#/ig, "")+"01"+MatrixLedbackcolor.replace(/\#/ig, "")+"02"+MatrixLedbackcolor.replace(/\#/ig, "")+"03"+MatrixLedbackcolor.replace(/\#/ig, "")+"04"+MatrixLedbackcolor.replace(/\#/ig, "") - + "05"+MatrixLedbackcolor.replace(/\#/ig, "")+"06"+MatrixLedbackcolor.replace(/\#/ig, "")+"07"+MatrixLedbackcolor.replace(/\#/ig, "")+"08"+MatrixLedbackcolor.replace(/\#/ig, "")+"09"+MatrixLedbackcolor.replace(/\#/ig, "") - + "0a"+MatrixLedbackcolor.replace(/\#/ig, "")+"0b"+MatrixLedbackcolor.replace(/\#/ig, "")+"0c"+MatrixLedbackcolor.replace(/\#/ig, "")+"0d"+MatrixLedbackcolor.replace(/\#/ig, "")+"0e"+MatrixLedbackcolor.replace(/\#/ig, "") - + "0f"+MatrixLedbackcolor.replace(/\#/ig, "")+"10"+MatrixLedbackcolor.replace(/\#/ig, "")+"11"+MatrixLedbackcolor.replace(/\#/ig, "")+"12"+MatrixLedbackcolor.replace(/\#/ig, "")+"13"+MatrixLedbackcolor.replace(/\#/ig, "") - + "14"+MatrixLedbackcolor.replace(/\#/ig, "")+"15"+MatrixLedbackcolor.replace(/\#/ig, "")+"16"+MatrixLedbackcolor.replace(/\#/ig, "")+"17"+MatrixLedbackcolor.replace(/\#/ig, "")+"18"+MatrixLedbackcolor.replace(/\#/ig, ""); - - objMatrixLed.setColor(ledtable); - } - - window.MatrixLed_clear = MatrixLed_clear; - window.MatrixLed_matrix = MatrixLed_matrix; - window.MatrixLed_matrix_color = MatrixLed_matrix_color; - window.MatrixLed_show = MatrixLed_show; - window.MatrixLed_on = MatrixLed_on; - window.MatrixLed_color_on = MatrixLed_color_on; - window.MatrixLed_off = MatrixLed_off; - window.MatrixLed_reverse = MatrixLed_reverse; - window.MatrixLed_state = MatrixLed_state; - window.MatrixLed_color = MatrixLed_color; - window.MatrixLed_sample = MatrixLed_sample; - window.MatrixLed_code = MatrixLed_code; - window.MatrixLed_marquee = MatrixLed_marquee; - window.MatrixLed_marquee_play = MatrixLed_marquee_play; - window.MatrixLed_marquee_once = MatrixLed_marquee_once; - window.MatrixLed_marquee_once_play = MatrixLed_marquee_once_play; - window.MatrixLed_marquee_color = MatrixLed_marquee_color; - window.MatrixLed_marquee_color_play = MatrixLed_marquee_color_play; - window.MatrixLed_marquee_color_once = MatrixLed_marquee_color_once; - window.MatrixLed_marquee_color_once_play = MatrixLed_marquee_color_once_play; - window.MatrixLed_matrix_codetocolor = MatrixLed_matrix_codetocolor; - window.MatrixLed_marquee_degree = MatrixLed_marquee_degree; - window.MatrixLed_marquee_color_degree = MatrixLed_marquee_color_degree; - window.MatrixLed_marquee_stop = MatrixLed_marquee_stop; - window.MatrixLed_marquee_resume = MatrixLed_marquee_resume; - window.MatrixLed_marquee_reverse = MatrixLed_marquee_reverse; - window.MatrixLed_marquee_time = MatrixLed_marquee_time; - window.MatrixLed_char = MatrixLed_char; - window.MatrixLed_conversion = MatrixLed_conversion; - window.MatrixLed_texttocode = MatrixLed_texttocode; - window.MatrixLed_showstate = MatrixLed_showstate; - window.MatrixLed_indentcode = MatrixLed_indentcode; - window.MatrixLed_linechart = MatrixLed_linechart; - window.MatrixLed_barchart = MatrixLed_barchart; - window.Matrixled_clockwise = Matrixled_clockwise; - window.Matrixled_counterclockwise = Matrixled_counterclockwise; - window.Matrixled_verticalflip = Matrixled_verticalflip; - window.Matrixled_horizontalflip = Matrixled_horizontalflip; - window.Matrixled_invert = Matrixled_invert; - window.MatrixLed_getcolor = MatrixLed_getcolor; - window.MatrixLed_backcolor = MatrixLed_backcolor; - -}(window, window.document)); diff --git a/bit_MatrixLed_20180810/blockly.json b/bit_MatrixLed_20180810/blockly.json deleted file mode 100644 index 2eb2f29122..0000000000 --- a/bit_MatrixLed_20180810/blockly.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "types": ["matrix_led_backcolor","matrix_led_verticalflip","matrix_led_horizontalflip","matrix_led_invert","matrix_led_getcolor","matrix_led_color","matrix_led_code","matrix_led_texttocode","matrix_led_indentcode","matrix_led_showstate","matrix_led_sample","matrix_led_matrix","matrix_led_matrix_color","matrix_led_matrixcode","matrix_led_matrixcode_line","matrix_led_matrixcode_color","matrix_led_matrixcode_line_color","matrix_led_clear","matrix_led_on","matrix_led_color_on","matrix_led_off","matrix_led_reverse","matrix_led_state","matrix_led_marquee","matrix_led_marquee_once","matrix_led_marquee_color","matrix_led_marquee_color_once","matrix_led_marquee_degree","matrix_led_marquee_color_degree","matrix_led_marquee_time","matrix_led_marquee_stop","matrix_led_marquee_reverse","matrix_led_marquee_resume","matrix_led_char","matrix_led_linechart","matrix_led_barchart","matrix_led_clockwise","matrix_led_counterclockwise"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "matrixled.js", - "fuLedMatrix.js", - "fuLedMatrix-blockly.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/bit_MatrixLed_20180810/blockly/blocks.js b/bit_MatrixLed_20180810/blockly/blocks.js deleted file mode 100644 index 9477447903..0000000000 --- a/bit_MatrixLed_20180810/blockly/blocks.js +++ /dev/null @@ -1,625 +0,0 @@ -Blockly.Blocks['matrix_led_showstate'] = { - init: function() { - this.appendDummyInput() - .appendField(new Blockly.FieldVariable('fuMatrixLed'), 'fuMatrixLed_') - .appendField(Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW) - .appendField(new Blockly.FieldDropdown([["on","1"], ["off","0"]]), "value_showstate_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_brightness'] = { - init: function () { - this.appendValueInput('brightness_') - .setCheck(null) - .appendField(new Blockly.FieldVariable('fuMatrixLed'), 'fuMatrixLed_') - .appendField(Blockly.Msg.MATRIXLED_BRIGHTNESS_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_char'] = { - init: function() { - this.appendValueInput("value_char_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_CHAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - - -Blockly.Blocks['matrix_led_texttocode'] = { - init: function() { - this.appendValueInput("value_text_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_indentcode'] = { - init: function() { - this.appendValueInput("value_indentcode_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_INDENTCODE_SHOW); - this.setOutput(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_marquee'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_marquee_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_marquee_color'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_marquee_color_once'] = { - init: function() { - this.appendValueInput("value_marquee_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_marquee_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_marquee_color_degree'] = { - init: function() { - this.appendValueInput("value_marquee_degree_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW) - .appendField(new Blockly.FieldDropdown([["left","1"], ["right","2"]]), "value_marquee_direction_") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_marquee_stop'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_marquee_resume'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_marquee_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_marquee_time'] = { - init: function() { - this.appendValueInput("value_marquee_time_") - .setCheck("Number") - .appendField(Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_sample'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_SAMPLE_SHOW) - .appendField(new Blockly.FieldDropdown([["♥","♥"], ["♡","♡"], ["↑","↑"], ["↓","↓"], ["←","←"], ["→","→"], ["↖","↖"], ["↙","↙"], ["↗","↗"], ["↘","↘"], ["▲","▲"], ["▼","▼"], ["◄","◄"], ["►","►"], ["O","O"], ["X","X"], ["V","V"]]), "value_sample_"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_code'] = { - init: function() { - this.appendValueInput("value_code_") - .setCheck("String") - .appendField(Blockly.Msg.MATRIXLED_CODE_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_color'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_COLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_matrix'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_matrix_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L01') - .appendField(new Blockly.FieldColour("#000000"), 'L06') - .appendField(new Blockly.FieldColour("#000000"), 'L11') - .appendField(new Blockly.FieldColour("#000000"), 'L16') - .appendField(new Blockly.FieldColour("#000000"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L02') - .appendField(new Blockly.FieldColour("#000000"), 'L07') - .appendField(new Blockly.FieldColour("#000000"), 'L12') - .appendField(new Blockly.FieldColour("#000000"), 'L17') - .appendField(new Blockly.FieldColour("#000000"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L03') - .appendField(new Blockly.FieldColour("#000000"), 'L08') - .appendField(new Blockly.FieldColour("#000000"), 'L13') - .appendField(new Blockly.FieldColour("#000000"), 'L18') - .appendField(new Blockly.FieldColour("#000000"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L04') - .appendField(new Blockly.FieldColour("#000000"), 'L09') - .appendField(new Blockly.FieldColour("#000000"), 'L14') - .appendField(new Blockly.FieldColour("#000000"), 'L19') - .appendField(new Blockly.FieldColour("#000000"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L05') - .appendField(new Blockly.FieldColour("#000000"), 'L10') - .appendField(new Blockly.FieldColour("#000000"), 'L15') - .appendField(new Blockly.FieldColour("#000000"), 'L20') - .appendField(new Blockly.FieldColour("#000000"), 'L25') - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_matrixcode'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L06") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L11") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L16") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L21"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L07") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L12") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L17") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L22"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L08") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L13") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L18") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L23"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L09") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L14") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L19") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L24"); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L10") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L15") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L20") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L25"); - this.setOutput(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_matrixcode_line'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldCheckbox("FALSE"), "L01") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L02") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L03") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L04") - .appendField(new Blockly.FieldCheckbox("FALSE"), "L05"); - this.setOutput(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_matrixcode_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L01') - .appendField(new Blockly.FieldColour("#000000"), 'L06') - .appendField(new Blockly.FieldColour("#000000"), 'L11') - .appendField(new Blockly.FieldColour("#000000"), 'L16') - .appendField(new Blockly.FieldColour("#000000"), 'L21') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L02') - .appendField(new Blockly.FieldColour("#000000"), 'L07') - .appendField(new Blockly.FieldColour("#000000"), 'L12') - .appendField(new Blockly.FieldColour("#000000"), 'L17') - .appendField(new Blockly.FieldColour("#000000"), 'L22') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L03') - .appendField(new Blockly.FieldColour("#000000"), 'L08') - .appendField(new Blockly.FieldColour("#000000"), 'L13') - .appendField(new Blockly.FieldColour("#000000"), 'L18') - .appendField(new Blockly.FieldColour("#000000"), 'L23') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L04') - .appendField(new Blockly.FieldColour("#000000"), 'L09') - .appendField(new Blockly.FieldColour("#000000"), 'L14') - .appendField(new Blockly.FieldColour("#000000"), 'L19') - .appendField(new Blockly.FieldColour("#000000"), 'L24') - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L05') - .appendField(new Blockly.FieldColour("#000000"), 'L10') - .appendField(new Blockly.FieldColour("#000000"), 'L15') - .appendField(new Blockly.FieldColour("#000000"), 'L20') - .appendField(new Blockly.FieldColour("#000000"), 'L25') - this.setOutput(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_matrixcode_line_color'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField(Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_COLOR_SHOW); - this.appendDummyInput() - .appendField(new Blockly.FieldColour("#000000"), 'L01') - .appendField(new Blockly.FieldColour("#000000"), 'L02') - .appendField(new Blockly.FieldColour("#000000"), 'L03') - .appendField(new Blockly.FieldColour("#000000"), 'L04') - .appendField(new Blockly.FieldColour("#000000"), 'L05'); - this.setOutput(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_clear'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLEAR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_color_on'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COLOR_ON_SHOW); - this.appendValueInput("value_x_on_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_on_") - .setCheck("Number") - .appendField("y"); - this.appendValueInput("value_color_on_") - .setCheck("Colour") - .appendField("color"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_off'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_OFF_SHOW); - this.appendValueInput("value_x_off_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_off_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_reverse'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_REVERSE_SHOW); - this.appendValueInput("value_x_reverse_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_reverse_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_state'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_STATE_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_linechart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_LINECHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_barchart'] = { - init: function() { - this.appendValueInput("value_value1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_BARCHART_SHOW) - .appendField(Blockly.Msg.MATRIXLED_VALUE1_SHOW); - this.appendValueInput("value_value2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE2_SHOW); - this.appendValueInput("value_value3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE3_SHOW); - this.appendValueInput("value_value4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE4_SHOW); - this.appendValueInput("value_value5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.MATRIXLED_VALUE5_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_clockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_counterclockwise'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_verticalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_horizontalflip'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_invert'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_INVERT_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_getcolor'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.MATRIXLED_GETCOLOR_SHOW); - this.appendValueInput("value_x_state_") - .setCheck("Number") - .appendField("x"); - this.appendValueInput("value_y_state_") - .setCheck("Number") - .appendField("y"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - } -}; - -Blockly.Blocks['matrix_led_backcolor'] = { - init: function() { - this.appendValueInput("value_color_") - .setCheck(null) - .appendField(Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(300); - } -}; diff --git a/bit_MatrixLed_20180810/blockly/javascript.js b/bit_MatrixLed_20180810/blockly/javascript.js deleted file mode 100644 index a10fbbee9d..0000000000 --- a/bit_MatrixLed_20180810/blockly/javascript.js +++ /dev/null @@ -1,347 +0,0 @@ -Blockly.JavaScript['matrix_led_brightness'] = function (block) { - var variable_fuMatrixLed_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuMatrixLed_'), Blockly.Variables.NAME_TYPE); - var value_brightness_ = Blockly.JavaScript.valueToCode(block, 'brightness_', Blockly.JavaScript.ORDER_ATOMIC); - var code = variable_fuMatrixLed_+'.brightness(' + value_brightness_ + ');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_showstate'] = function(block) { - var variable_fuMatrixLed_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('fuMatrixLed_'), Blockly.Variables.NAME_TYPE); - var value_showstate_ = block.getFieldValue('value_showstate_'); - var code = variable_fuMatrixLed_+' = getMatrix(board, 4, 25);\nMatrixLed_showstate('+variable_fuMatrixLed_+','+value_showstate_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_char'] = function(block) { - var value_char_ = Blockly.JavaScript.valueToCode(block, 'value_char_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_char('+ value_char_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_time'] = function(block) { - var value_marquee_time_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_time_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_time('+ value_marquee_time_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color_once'] = function(block) { - var value_marquee_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color_once('+ value_marquee_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_color_degree'] = function(block) { - var value_marquee_direction_ = block.getFieldValue('value_marquee_direction_'); - var value_marquee_degree_ = Blockly.JavaScript.valueToCode(block, 'value_marquee_degree_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_marquee_color_degree('+ value_marquee_direction_ +','+ value_marquee_degree_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_stop'] = function(block) { - var code = 'MatrixLed_marquee_stop();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_resume'] = function(block) { - var code = 'MatrixLed_marquee_resume();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_marquee_reverse'] = function(block) { - var code = 'MatrixLed_marquee_reverse();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color('+ value_color_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_texttocode'] = function(block) { - var value_text_ = Blockly.JavaScript.valueToCode(block, 'value_text_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_texttocode('+value_text_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_sample'] = function(block) { - var value_sample_ = block.getFieldValue('value_sample_'); - var code = 'MatrixLed_sample("'+ value_sample_ +'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_code'] = function(block) { - var value_code_ = Blockly.JavaScript.valueToCode(block, 'value_code_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_code('+ value_code_ +');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = 'MatrixLed_matrix("'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'");\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrix_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = 'MatrixLed_matrix_color(["'+L01+'","'+L02+'","'+L03+'","'+L04+'","'+L05+'","'+L06+'","'+L07+'","'+L08+'","'+L09+'","'+L10+'","'+L11+'","'+L12+'","'+L13+'","'+L14+'","'+L15+'","'+L16+'","'+L17+'","'+L18+'","'+L19+'","'+L20+'","'+L21+'","'+L22+'","'+L23+'","'+L24+'","'+L25+'"]);\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_matrixcode'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var L06 = (block.getFieldValue('L06') == 'TRUE')?"1":"0"; - var L07 = (block.getFieldValue('L07') == 'TRUE')?"1":"0"; - var L08 = (block.getFieldValue('L08') == 'TRUE')?"1":"0"; - var L09 = (block.getFieldValue('L09') == 'TRUE')?"1":"0"; - var L10 = (block.getFieldValue('L10') == 'TRUE')?"1":"0"; - var L11 = (block.getFieldValue('L11') == 'TRUE')?"1":"0"; - var L12 = (block.getFieldValue('L12') == 'TRUE')?"1":"0"; - var L13 = (block.getFieldValue('L13') == 'TRUE')?"1":"0"; - var L14 = (block.getFieldValue('L14') == 'TRUE')?"1":"0"; - var L15 = (block.getFieldValue('L15') == 'TRUE')?"1":"0"; - var L16 = (block.getFieldValue('L16') == 'TRUE')?"1":"0"; - var L17 = (block.getFieldValue('L17') == 'TRUE')?"1":"0"; - var L18 = (block.getFieldValue('L18') == 'TRUE')?"1":"0"; - var L19 = (block.getFieldValue('L19') == 'TRUE')?"1":"0"; - var L20 = (block.getFieldValue('L20') == 'TRUE')?"1":"0"; - var L21 = (block.getFieldValue('L21') == 'TRUE')?"1":"0"; - var L22 = (block.getFieldValue('L22') == 'TRUE')?"1":"0"; - var L23 = (block.getFieldValue('L23') == 'TRUE')?"1":"0"; - var L24 = (block.getFieldValue('L24') == 'TRUE')?"1":"0"; - var L25 = (block.getFieldValue('L25') == 'TRUE')?"1":"0"; - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_matrixcode_line'] = function(block) { - var L01 = (block.getFieldValue('L01') == 'TRUE')?"1":"0"; - var L02 = (block.getFieldValue('L02') == 'TRUE')?"1":"0"; - var L03 = (block.getFieldValue('L03') == 'TRUE')?"1":"0"; - var L04 = (block.getFieldValue('L04') == 'TRUE')?"1":"0"; - var L05 = (block.getFieldValue('L05') == 'TRUE')?"1":"0"; - var code = '"'+L01+L02+L03+L04+L05+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_matrixcode_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var L06 = block.getFieldValue('L06'); - var L07 = block.getFieldValue('L07'); - var L08 = block.getFieldValue('L08'); - var L09 = block.getFieldValue('L09'); - var L10 = block.getFieldValue('L10'); - var L11 = block.getFieldValue('L11'); - var L12 = block.getFieldValue('L12'); - var L13 = block.getFieldValue('L13'); - var L14 = block.getFieldValue('L14'); - var L15 = block.getFieldValue('L15'); - var L16 = block.getFieldValue('L16'); - var L17 = block.getFieldValue('L17'); - var L18 = block.getFieldValue('L18'); - var L19 = block.getFieldValue('L19'); - var L20 = block.getFieldValue('L20'); - var L21 = block.getFieldValue('L21'); - var L22 = block.getFieldValue('L22'); - var L23 = block.getFieldValue('L23'); - var L24 = block.getFieldValue('L24'); - var L25 = block.getFieldValue('L25'); - var code = '"'+L01+L02+L03+L04+L05+L06+L07+L08+L09+L10+L11+L12+L13+L14+L15+L16+L17+L18+L19+L20+L21+L22+L23+L24+L25+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_matrixcode_line_color'] = function(block) { - var L01 = block.getFieldValue('L01'); - var L02 = block.getFieldValue('L02'); - var L03 = block.getFieldValue('L03'); - var L04 = block.getFieldValue('L04'); - var L05 = block.getFieldValue('L05'); - var code = '"'+L01+L02+L03+L04+L05+'"'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_clear'] = function(block) { - var code = 'MatrixLed_clear();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_on('+value_x_on_+','+value_y_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_color_on'] = function(block) { - var value_x_on_ = Blockly.JavaScript.valueToCode(block, 'value_x_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_on_ = Blockly.JavaScript.valueToCode(block, 'value_y_on_', Blockly.JavaScript.ORDER_ATOMIC); - var value_color_on_ = Blockly.JavaScript.valueToCode(block, 'value_color_on_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_color_on('+value_x_on_+','+value_y_on_+','+value_color_on_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_off'] = function(block) { - var value_x_off_ = Blockly.JavaScript.valueToCode(block, 'value_x_off_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_off_ = Blockly.JavaScript.valueToCode(block, 'value_y_off_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_off('+value_x_off_+','+value_y_off_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_reverse'] = function(block) { - var value_x_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_x_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_reverse_ = Blockly.JavaScript.valueToCode(block, 'value_y_reverse_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_reverse('+value_x_reverse_+','+value_y_reverse_+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_state'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_state('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_indentcode'] = function(block) { - var value_indentcode_ = Blockly.JavaScript.valueToCode(block, 'value_indentcode_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_indentcode('+value_indentcode_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_linechart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_linechart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_barchart'] = function(block) { - var value_value1 = Blockly.JavaScript.valueToCode(block, 'value_value1', Blockly.JavaScript.ORDER_ATOMIC); - var value_value2 = Blockly.JavaScript.valueToCode(block, 'value_value2', Blockly.JavaScript.ORDER_ATOMIC); - var value_value3 = Blockly.JavaScript.valueToCode(block, 'value_value3', Blockly.JavaScript.ORDER_ATOMIC); - var value_value4 = Blockly.JavaScript.valueToCode(block, 'value_value4', Blockly.JavaScript.ORDER_ATOMIC); - var value_value5 = Blockly.JavaScript.valueToCode(block, 'value_value5', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_barchart('+value_value1+','+value_value2+','+value_value3+','+value_value4+','+value_value5+');\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_clockwise'] = function(block) { - var code = 'Matrixled_clockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_counterclockwise'] = function(block) { - var code = 'Matrixled_counterclockwise();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_verticalflip'] = function(block) { - var code = 'Matrixled_verticalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_horizontalflip'] = function(block) { - var code = 'Matrixled_horizontalflip();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_invert'] = function(block) { - var code = 'Matrixled_invert();\n'; - return code; -}; - -Blockly.JavaScript['matrix_led_getcolor'] = function(block) { - var value_x_state_ = Blockly.JavaScript.valueToCode(block, 'value_x_state_', Blockly.JavaScript.ORDER_ATOMIC); - var value_y_state_ = Blockly.JavaScript.valueToCode(block, 'value_y_state_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_getcolor('+value_x_state_+','+value_y_state_+')'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['matrix_led_backcolor'] = function(block) { - var value_color_ = Blockly.JavaScript.valueToCode(block, 'value_color_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'MatrixLed_backcolor('+ value_color_ +');\n'; - return code; -}; diff --git a/bit_MatrixLed_20180810/blockly/msg/blocks/en.js b/bit_MatrixLed_20180810/blockly/msg/blocks/en.js deleted file mode 100644 index e277057c0a..0000000000 --- a/bit_MatrixLed_20180810/blockly/msg/blocks/en.js +++ /dev/null @@ -1,45 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "Matrix Led"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "Matrix Led (Full Color)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "Matrix Led Code"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "Clean Screen"; -Blockly.Msg.MATRIXLED_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "Turn On"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "Turn Off"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "Reverse"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "Get Led State"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "Led Color"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "Show Sample"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "Show Sample By Code"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "Show Marguee(CYCLE)"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "Show Marguee(ONCE)"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "Marguee Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "Marguee(Full Color) Direction Of Movement"; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " Degree"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "Marguee Stop"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "Marguee Resume"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "Marguee Time (ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "Marguee Reverse"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "Show Character"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "Convert Text To Code"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "Matrix Led Switch"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "Indent Code"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "Line Chart "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "Bar Chart "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "Value1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "Value2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "Value3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "Value4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "Value5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "Rotate 90 Degrees Clockwise"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "Rotate 90 Degrees Counter Clockwise"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "Vertical Flip"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "Horizontal Flip"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "Reverse"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "Get Color Code"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "Back Color"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "Matrix Led(Full Color) Code"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "Show Marguee(Full Color) CYCLE"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "Show Marguee(Full Color) ONCE"; -Blockly.Msg.MATRIXLED_BRIGHTNESS_SHOW = "Set Brightness (0~20)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_SHOW = "Matrix Led Add Up A Long Column"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_COLOR_SHOW = "Matrix Led(Full Color) Add Up A Long Column"; diff --git a/bit_MatrixLed_20180810/blockly/msg/blocks/zh-hans.js b/bit_MatrixLed_20180810/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index ea3a521b7f..0000000000 --- a/bit_MatrixLed_20180810/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,45 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示灯(单色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示灯(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示灯(单色) 编码"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示灯 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮灯"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗灯"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示灯 亮暗反转"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示灯 亮暗状态"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示灯(单色) 颜色"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "显示 图案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "显示 图案(编码)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑马灯(单色) 循环"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑马灯(单色) 单次"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑马灯(单色) 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "跑马灯(全彩) 移动方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格数"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑马灯 暂停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑马灯 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑马灯 间隔时间(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑马灯 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "显示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "转换文字为编码"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示灯 开关"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "缩排编码"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折线图 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "长条图 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "数值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "数值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "数值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "数值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "数值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示灯 顺时钟旋转90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示灯 逆时钟旋转90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示灯 垂直翻转"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示灯 水平翻转"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示灯 亮暗反转"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示灯 色码值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示灯(单色) 背景颜色"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "指示灯(全彩) 编码"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "跑马灯(全彩) 循环"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "跑马灯(全彩) 单次"; -Blockly.Msg.MATRIXLED_BRIGHTNESS_SHOW = "指示灯 亮度 (0~20)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_SHOW = "指示灯(单色) 新增纵行"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_COLOR_SHOW = "指示灯(全彩) 新增纵行"; diff --git a/bit_MatrixLed_20180810/blockly/msg/blocks/zh-hant.js b/bit_MatrixLed_20180810/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 3449f6f40a..0000000000 --- a/bit_MatrixLed_20180810/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,45 +0,0 @@ -Blockly.Msg.MATRIXLED_MATRIX_SHOW = "指示燈(單色)"; -Blockly.Msg.MATRIXLED_MATRIX_COLOR_SHOW = "指示燈(全彩)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_SHOW = "指示燈(單色) 編碼"; -Blockly.Msg.MATRIXLED_CLEAR_SHOW = "指示燈 清除"; -Blockly.Msg.MATRIXLED_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_COLOR_ON_SHOW = "亮燈"; -Blockly.Msg.MATRIXLED_OFF_SHOW = "暗燈"; -Blockly.Msg.MATRIXLED_REVERSE_SHOW = "指示燈 亮暗反轉"; -Blockly.Msg.MATRIXLED_STATE_SHOW = "指示燈 亮暗狀態"; -Blockly.Msg.MATRIXLED_COLOR_SHOW = "指示燈(單色) 顏色"; -Blockly.Msg.MATRIXLED_SAMPLE_SHOW = "顯示 圖案"; -Blockly.Msg.MATRIXLED_CODE_SHOW = "顯示 圖案(編碼)"; -Blockly.Msg.MATRIXLED_MARQUEE_SHOW = "跑馬燈(單色) 循環"; -Blockly.Msg.MATRIXLED_MARQUEE_ONCE_SHOW = "跑馬燈(單色) 單次"; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_SHOW = "跑馬燈(單色) 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DIRECTION_COLOR_SHOW = "跑馬燈(全彩) 移動方向 "; -Blockly.Msg.MATRIXLED_MARQUEE_DEGREE_SHOW = " 格數"; -Blockly.Msg.MATRIXLED_MARQUEE_STOP_SHOW = "跑馬燈 暫停"; -Blockly.Msg.MATRIXLED_MARQUEE_RESUME_SHOW = "跑馬燈 恢復"; -Blockly.Msg.MATRIXLED_MARQUEE_TIME_SHOW = "跑馬燈 間隔時間(ms)"; -Blockly.Msg.MATRIXLED_MARQUEE_REVERSE_SHOW = "跑馬燈 反向"; -Blockly.Msg.MATRIXLED_CHAR_SHOW = "顯示 字元"; -Blockly.Msg.MATRIXLED_TEXTTOCODE_SHOW = "轉換文字為編碼"; -Blockly.Msg.MATRIXLED_SHOWSTATE_SHOW = "指示燈 開關"; -Blockly.Msg.MATRIXLED_INDENTCODE_SHOW = "縮排編碼"; -Blockly.Msg.MATRIXLED_LINECHART_SHOW = "折線圖 "; -Blockly.Msg.MATRIXLED_BARCHART_SHOW = "長條圖 "; -Blockly.Msg.MATRIXLED_VALUE1_SHOW = "數值1"; -Blockly.Msg.MATRIXLED_VALUE2_SHOW = "數值2"; -Blockly.Msg.MATRIXLED_VALUE3_SHOW = "數值3"; -Blockly.Msg.MATRIXLED_VALUE4_SHOW = "數值4"; -Blockly.Msg.MATRIXLED_VALUE5_SHOW = "數值5"; -Blockly.Msg.MATRIXLED_CLOCKWISE_SHOW = "指示燈 順時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_COUNTERCLOCKWISE_SHOW = "指示燈 逆時鐘旋轉90度"; -Blockly.Msg.MATRIXLED_VERTICALFLIP_SHOW = "指示燈 垂直翻轉"; -Blockly.Msg.MATRIXLED_HORIZONTALFLIP_SHOW = "指示燈 水平翻轉"; -Blockly.Msg.MATRIXLED_INVERT_SHOW = "指示燈 亮暗反轉"; -Blockly.Msg.MATRIXLED_GETCOLOR_SHOW = "指示燈 色碼值"; -Blockly.Msg.MATRIXLED_BACKCOLOR_SHOW = "指示燈(單色) 背景顏色"; -Blockly.Msg.MATRIXLED_MATRIXCODE_COLOR_SHOW = "指示燈(全彩) 編碼"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_SHOW = "跑馬燈(全彩) 循環"; -Blockly.Msg.MATRIXLED_MARQUEE_COLOR_ONCE_SHOW = "跑馬燈(全彩) 單次"; -Blockly.Msg.MATRIXLED_BRIGHTNESS_SHOW = "指示燈 亮度 (0~20)"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_SHOW = "指示燈(單色) 新增縱行"; -Blockly.Msg.MATRIXLED_MATRIXCODE_LINE_COLOR_SHOW = "指示燈(全彩) 新增縱行"; diff --git a/bit_MatrixLed_20180810/blockly/msg/en.js b/bit_MatrixLed_20180810/blockly/msg/en.js deleted file mode 100644 index 883a7b3522..0000000000 --- a/bit_MatrixLed_20180810/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "FuMatrixLed"; diff --git a/bit_MatrixLed_20180810/blockly/msg/zh-hans.js b/bit_MatrixLed_20180810/blockly/msg/zh-hans.js deleted file mode 100644 index 7d969d936c..0000000000 --- a/bit_MatrixLed_20180810/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "法兰斯点矩阵"; diff --git a/bit_MatrixLed_20180810/blockly/msg/zh-hant.js b/bit_MatrixLed_20180810/blockly/msg/zh-hant.js deleted file mode 100644 index e008529bf5..0000000000 --- a/bit_MatrixLed_20180810/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catMatrixLed = "法蘭斯點矩陣"; diff --git a/bit_MatrixLed_20180810/blockly/toolbox.xml b/bit_MatrixLed_20180810/blockly/toolbox.xml deleted file mode 100644 index 6a03d43d6a..0000000000 --- a/bit_MatrixLed_20180810/blockly/toolbox.xml +++ /dev/null @@ -1,505 +0,0 @@ - - - 1 - - - - - 10 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - 0 - - - - - 0 - - - - - #ff0000 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - 500 - - - - - - - - - - - - - - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - - - - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - #000000 - - - - - - - 1 - - - 1 - - - - - - - - - - - - - #000000 - - - - - - - #ff0000 - - - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - FALSE - - - FALSE - FALSE - FALSE - FALSE - FALSE - - - - - - - - - - - - - - - 0110011110011111111001100 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - - - - - - - ♥ webduino ♡ - - - - - - - - - 1 - - - 1 - - - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - - diff --git a/bit_MatrixLed_20180810/fuLedMatrix-blockly.js b/bit_MatrixLed_20180810/fuLedMatrix-blockly.js deleted file mode 100644 index 08f6173302..0000000000 --- a/bit_MatrixLed_20180810/fuLedMatrix-blockly.js +++ /dev/null @@ -1,14 +0,0 @@ -+(function (factory) { - if (typeof exports === 'undefined') { - factory(window, window.webduino); - } else { - module.exports = factory; - } -}(function (scope, webduino) { - - 'use strict'; - - scope.getMatrix = function (board, pin, leds) { - return new webduino.module.Matrix(board, pin, leds); - }; -})); \ No newline at end of file diff --git a/bit_MatrixLed_20180810/fuLedMatrix.js b/bit_MatrixLed_20180810/fuLedMatrix.js deleted file mode 100644 index 0b235ec823..0000000000 --- a/bit_MatrixLed_20180810/fuLedMatrix.js +++ /dev/null @@ -1,275 +0,0 @@ -+(function (factory) { - if (typeof exports === 'undefined') { - factory(webduino || {}); - } else { - module.exports = factory; - } -}(function (scope) { - 'use strict'; - - var self; - var proto; - var sendLength = 50; - var sendArray = []; - var sendAck = ''; - var sendCallback; - var Module = scope.Module; - var BoardEvent = scope.BoardEvent; - var _backlight; - - function Matrix(board, pin, leds) { - Module.call(this); - this._board = board; - self = this; - self._pin = pin; - self._leds = leds; - var cmd = ''; - if (leds <= 64) { - cmd = [0xF0, 0x04, 0x21, 0x0 /*init*/ , leds, pin, 0xF7]; - } else { - var h6bit = leds >>> 6; - var l6bit = leds & 0x3F; - cmd = [0xF0, 0x04, 0x21, 0x4 /*init*/ , h6bit, l6bit, pin, 0xF7]; - } - board.send(cmd); - board.on(BoardEvent.SYSEX_MESSAGE, - function (event) { - var m = event.message; - }); - } - - Matrix.prototype = proto = Object.create(Module.prototype, { - constructor: { - value: Matrix - }, - backlight: { - get: function () { - return _backlight; - }, - set: function (val) { - _backlight = val; - } - } - }); - - proto.setColorByString = function (led, color) { - if (led > 64) { - this.setColor64(led, color); - return; - } - var data = ''; - var cmd = [0xF0, 0x04, 0x21, 0x03]; - if (arguments.length == 1) { - data = led; - this.setColorByPiece(data); - return; - } else { - var R = color.substring(1,3); - var G = color.substring(3,5); - var B = color.substring(5,7); - - var RG24 = (((parseInt(R,16)>>6)&0x3)<<4) | (parseInt(G,16)>>4); - var RB24 = (((parseInt(R,16)>>4)&0x3)<<4) | (parseInt(B,16)>>4); - - cmd.push(led); - cmd.push(RG24); - cmd.push(RB24); - } -/* - data = data.concat(toHex(led)); - data = data.concat(color.substring(1)); - } - for (var i = 0; i < data.length; i++) { - cmd.push(data.charCodeAt(i)) - } -*/ - cmd.push(0xF7); - this._board.send(cmd); - this._board.flush(); - } - - proto.setColorByPiece = function (allData) { - var self = this; - - function sendPiece(data) { - var cmd = [0xF0, 0x04, 0x21, 0x03]; - cmd.push(0x40); - for (var i = 0; i < data.length; i+=8) { - var led = data.substring(i,i+2); - var R = data.substring(i+2,i+4); - var G = data.substring(i+4,i+6); - var B = data.substring(i+6,i+8); - - var RG24 = (((parseInt(R,16)>>6)&0x3)<<4) | (parseInt(G,16)>>4); - var RB24 = (((parseInt(R,16)>>4)&0x3)<<4) | (parseInt(B,16)>>4); - - cmd.push(RG24); - cmd.push(RB24); - } - cmd.push(0xF7); - self._board.send(cmd); - self._board.flush(); - } - - // the maximum packet size is 64 bytes - sendPiece(allData); -/* - function sendPiece(data) { - var cmd = [0xF0, 0x04, 0x21, 0x03]; - for (var i = 0; i < data.length; i++) { - cmd.push(data.charCodeAt(i)); - } - cmd.push(0xF7); - self._board.send(cmd); - self._board.flush(); - } - // the maximum packet size is 64 bytes - sendPiece(allData.substring(0, 56)); - sendPiece(allData.substring(56, 112)); - sendPiece(allData.substring(112, 168)); - sendPiece(allData.substring(168)); -*/ - } - - proto.setColor64 = function (led, color) { - var data = ''; - var cmd = [0xF0, 0x04, 0x21, 0x05]; - - cmd.push(led >>> 6); - cmd.push(led & 0x3F); - data = data.concat(color.substring(1)); - for (var i = 0; i < data.length; i++) { - cmd.push(data.charCodeAt(i)) - } - cmd.push(0xF7); - this._board.send(cmd); - this._board.flush(); - } - - proto.off = function () { - this._board.send([0xF0, 0x04, 0x21, 0x02, 0xF7]); - } - - proto.brightness = function (b) { - var data = toHex(b); - this._board.send([0xF0, 0x04, 0x21, 0x01, b, 0xF7]); - this._board.flush(); - } - - function toHex(num) { - var str = num.toString(16); - if (parseInt(num) < 16) { - str = '0' + str; - } - return str; - } - - proto.setCharacter = function (character, color) { - var charMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!=~@abcdefghijklmnopqrstuvwxyz+/-*\",\'<>.0123456789"; // ~ = :) , @ = (heart) - var data = ''; - var cmd = [0xF0, 0x04, 0x21, 0x04]; - var ch = ''; - - if (character) { - ch = String(character); - ch = Array.from(ch).shift(); - } - - if (charMap.indexOf(ch) === -1 || !color) { - return; - } - - data = data.concat(color.substring(1)); - for (var i = 0; i < data.length && i < 54; i++) { - cmd.push(data.charCodeAt(i)); - } - cmd.push(ch.charCodeAt(0)); - cmd.push(0xF7); - this._board.send(cmd); - this._board.flush(); - } - - proto.setString = function (str, color, speed) { - var data = ''; - var cmd = [0xF0, 0x04, 0x21, 0x05]; - - data = data.concat(color.substring(1)); - for (var i = 0; i < data.length; i++) { - cmd.push(data.charCodeAt(i)); - } - cmd.push(speed); - str = String(str); - for (var i = 0; i < str.length && i < 54; i++) { - cmd.push(str.charCodeAt(i)); - } - cmd.push(0xF7); - this._board.send(cmd); - this._board.flush(); - } - - proto.setColor = function(data, color){ - if (arguments.length == 2) { - this.setColorByString(data, color); - } else { - let markup = (m) =>{ - let a = m; - if(m.length < 6){ - if(m.length == 3){ - let b = a.split(''); - let long = ''; - b.map((t)=>{ - long = long + t + t; - }); - a = long; - }else{ - for(let j=0; j<(6-m.length); j++){ - a = a + '0'; - } - } - }else if(m.length > 6){ - a = m.slice(0, 6); - } - return a; - } - let draw = (e,c) =>{ - let colorArray = []; - for(let i=0; i<25; i++){ - let index; - if (i < 16) { - index = '0' + i.toString(16); - } else { - index = i.toString(16); - } - if(e[i]){ - colorArray[i] = index + markup(e[i]); - }else{ - colorArray[i] = index + markup(c[0]);; - } - } - return colorArray.join().replace(/,/g,''); - } - let colorCodeGen = (data) => { - if(Array.isArray(data)){ - data = data.join(); - } - let colorArr = data.replace(/\[|\]|\'|\"| |#|/g,'').split(','); - let outputData; - if(colorArr.length>1){ - outputData = draw(colorArr,['000000']); - }else{ - if(colorArr[0].length==200 && colorArr[0].indexOf('0f')!=-1){ - outputData = colorArr[0]; - }else{ - outputData = draw(colorArr,colorArr); - } - } - outputData = outputData.slice(0, 200); - return outputData; - } - - this.setColorByString(colorCodeGen(data)); - } - } - - scope.module.Matrix = Matrix; -})); diff --git a/bit_MatrixLed_20180810/matrixled.js b/bit_MatrixLed_20180810/matrixled.js deleted file mode 100644 index 1796f7dfa7..0000000000 --- a/bit_MatrixLed_20180810/matrixled.js +++ /dev/null @@ -1,784 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - const charA = "0111110010100101001001111"; - const charB = "1111110101101011010101010"; - const charC = "0111010001100011000110001"; - const charD = "1111110001100011000101110"; - const charE = "1111110101101011010110101"; - const charF = "1111110100101001010010100"; - const charG = "0111010001101011010110111"; - const charH = "1111100100001000010011111"; - const charI = "1000110001111111000110001"; - const charJ = "1001110001111111000010000"; - const charK = "1111100010001000101010001"; - const charL = "1111100001000010000100001"; - const charM = "1111101000001000100011111"; - const charN = "1111101000001000001011111"; - const charO = "0111010001100011000101110"; - const charP = "1111110010100101001001100"; - const charQ = "0111010001101011001001101"; - const charR = "1111110100101001010001011"; - const charS = "0100110101101011010110010"; - const charT = "1000010000111111000010000"; - const charU = "1111000001000010000111110"; - const charV = "1110000010000010001011100"; - const charW = "1111000001111100000111110"; - const charX = "1000101010001000101010001"; - const charY = "1000001000001110100010000"; - const charZ = "1000110011101011100110001"; - const chara = "0000000110010010011000001"; - const charb = "0000011111001010001000000"; - const charc = "0000000110010010100100000"; - const chard = "0000000010001011111100000"; - const chare = "0000000110010110010100000"; - const charf = "0000000100111111010000000"; - const charg = "0000000101010110011000000"; - const charh = "0000011111001000001100000"; - const chari = "0000000000101110000000000"; - const charj = "0000000001101110000000000"; - const chark = "0000011111000100010100000"; - const charl = "0000000000111110000000000"; - const charm = "0011100100000110010000011"; - const charn = "0000000111001000001100000"; - const charo = "0000000010001010001000000"; - const charp = "0000001111010100010000000"; - const charq = "0000000100010100111100000"; - const charr = "0000000111000100010000000"; - const chars = "0000001001101011001000000"; - const chart = "0000000100011110010100000"; - const charu = "0000000110000010011000001"; - const charv = "0000000110000010011000000"; - const charw = "0011000001001100000100110"; - const charx = "0000000101000100010100000"; - const chary = "0000000101000100010000000"; - const charz = "0000101011011010100000000"; - const char0 = "0000011111100011111100000"; - const char1 = "0000001001111110000100000"; - const char2 = "0000010111101011110100000"; - const char3 = "0000010101101011111100000"; - const char4 = "0000011100001001111100000"; - const char5 = "0000011101101011011100000"; - const char6 = "0000011111101011011100000"; - const char7 = "0000011000100001111100000"; - const char8 = "0000011111101011111100000"; - const char9 = "0000011101101011111100000"; - const comma = "0000000001000100000000000"; - const period = "0000000001000000000000000"; - const questionmark = "0100010000100111010001000"; - const exclamationmark = "0000000000111010000000000"; - const semicolon = "0000000001010100000000000"; - const colon = "0000000000010100000000000"; - const parenthesesleft = "0000001110100010000000000"; - const parenthesesright = "0000000000100010111000000"; - const squarebracketsleft = "0000011111100010000000000"; - const squarebracketsright = "0000000000100011111100000"; - const curlybracketsleft = "0000000100111111000100000"; - const curlybracketsright = "0000010001111110010000000"; - const Quotationmarkssingle = "0000000000110000010000000"; - const Quotationmarksdouble = "1100000100110000010000000"; - const hyphen = "0000000100001000010000000"; - const heart = "0110010010010011001001100"; - const heartfill = "0110011110011111111001100"; - const arrowup = "0010001000111110100000100"; - const arrowdown = "0010000010111110001000100"; - const arrowleft = "0010001110101010010000100"; - const arrowright = "0010000100101010111000100"; - const arrowleftup = "1111011000101001001000001"; - const arrowleftdown = "0111100011001010100110000"; - const arrowrightup = "0000110010101001100011110"; - const arrowrightdown = "1000001001001010001101111"; - const arrowupfill = "0000100111111110011100001"; - const arrowdownfill = "1000011100111111110010000"; - const arrowleftfill = "0010000100011100111011111"; - const arrowrightfill = "1111101110011100010000100"; - const noexist = "0000000000000000000000000"; - - var L = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var MatrixLedcolor = "#ff0000"; - var MatrixLedbackcolor = "#000000"; - var MatrixLedmarqueeinitial = "",MatrixLedmarqueecode = "",MatrixLedmarqueecodeonce = "",MatrixLedmarqueecolorcode = "",MatrixLedmarqueecolorcodeonce = ""; - var MatrixLedmarqueetime = 500; - var MatrixLedmarqueereverse = 1; - var MatrixLedshowstate = 1; - var marqueetimeid; - var marqueeactive; - var objMatrixLed; - - function MatrixLed_color(input_color_) { - MatrixLedcolor = input_color_; - } - - function MatrixLed_showstate(obj,input_showstate_) { - objMatrixLed=obj; - MatrixLedshowstate = input_showstate_; - } - - function MatrixLed_indentcode(input_indentcode_) { - var indentcode = input_indentcode_; - while (indentcode.search(/0000000000/)!=-1) - indentcode = indentcode.replace(/0000000000/g,"00000"); - return indentcode; - } - - function MatrixLed_marquee(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecodeonce = ""; - window.clearInterval(marqueetimeid); - if ((input_marquee_.length==25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLed_matrix(input_marquee_); - return; - } - else if ((input_marquee_.length%5==0)&&(input_marquee_.length>25)&&(input_marquee_.search(/[^0-1]/)==-1)) - MatrixLedmarqueecode = input_marquee_; - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25)&&(input_marquee_.search(/[^0-1]/)==-1)) - { - MatrixLedmarqueecode = input_marquee_; - MatrixLedmarqueecodeonce = input_marquee_; - } - else if (input_marquee_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_marquee_)); - return; - } - else if (input_marquee_.length>1) - { - MatrixLedmarqueecode=""; - for (var i=0;i25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_once_play() { - if (MatrixLedmarqueecode.length>=25) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(5,MatrixLedmarqueecodeonce.length-5)+MatrixLedmarqueecodeonce.substr(0,5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix(MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-25,25)); - MatrixLedmarqueecodeonce = MatrixLedmarqueecodeonce.substr(MatrixLedmarqueecodeonce.length-5,5)+MatrixLedmarqueecodeonce.substr(0,MatrixLedmarqueecodeonce.length-5); - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_degree(direction,degree) { - window.clearInterval(marqueetimeid); - if (MatrixLedmarqueecode.length25) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(5,MatrixLedmarqueecode.length-5)+MatrixLedmarqueecode.substr(0,5); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecode = MatrixLedmarqueecode.substr(MatrixLedmarqueecode.length-5,5)+MatrixLedmarqueecode.substr(0,MatrixLedmarqueecode.length-5); - } - MatrixLed_matrix(MatrixLedmarqueecode.substr(0,25)); - } - } - - function MatrixLed_marquee_color(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueecolorcodeonce = ""; - window.clearInterval(marqueetimeid); - if (input_marquee_.length==175) - { - MatrixLed_matrix_codetocolor(input_marquee_); - return; - } - else if ((input_marquee_.length%35==0)&&(input_marquee_.length>175)) - MatrixLedmarqueecolorcode = input_marquee_; - MatrixLedmarqueeinitial=MatrixLedmarqueecolorcode; - marqueeactive=3; - marqueetimeid = window.setInterval("MatrixLed_marquee_color_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_color_once(input_marquee_) { - input_marquee_=input_marquee_.toString(); - MatrixLedmarqueeinitial=input_marquee_; - window.clearInterval(marqueetimeid); - if (input_marquee_.length==175) - { - MatrixLed_matrix_codetocolor(input_marquee_); - return; - } - else if ((input_marquee_.length%35==0)&&(input_marquee_.length>175)) - { - MatrixLedmarqueecolorcode = input_marquee_; - MatrixLedmarqueecolorcodeonce = input_marquee_; - } - MatrixLedmarqueeinitial=MatrixLedmarqueecolorcode; - marqueeactive=4; - marqueetimeid = window.setInterval("MatrixLed_marquee_color_once_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_color_play() { - if (MatrixLedmarqueecolorcode.length>175) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35)+MatrixLedmarqueecolorcode.substr(0,35); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-175,175)); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-35,35)+MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_color_once_play() { - if (MatrixLedmarqueecolorcode.length>=175) - { - if (MatrixLedmarqueereverse==1) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueecolorcodeonce.substr(35,MatrixLedmarqueecolorcodeonce.length-35)+MatrixLedmarqueecolorcodeonce.substr(0,35); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35); - } - else if (MatrixLedmarqueereverse==2) - { - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-175,175)); - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueecolorcodeonce.substr(MatrixLedmarqueecolorcodeonce.length-35,35)+MatrixLedmarqueecolorcodeonce.substr(0,MatrixLedmarqueecolorcodeonce.length-35); - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - } - else - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_color_degree(direction,degree) { - window.clearInterval(marqueetimeid); - if (MatrixLedmarqueecolorcode.length175) - { - if (direction==1) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(35,MatrixLedmarqueecolorcode.length-35)+MatrixLedmarqueecolorcode.substr(0,35); - } - else if (direction==2) - { - for (var i=1;i<=degree;i++) - MatrixLedmarqueecolorcode = MatrixLedmarqueecolorcode.substr(MatrixLedmarqueecolorcode.length-35,35)+MatrixLedmarqueecolorcode.substr(0,MatrixLedmarqueecolorcode.length-35); - } - MatrixLed_matrix_codetocolor(MatrixLedmarqueecolorcode.substr(0,175)); - } - } - - function MatrixLed_marquee_time(input_time_) { - MatrixLedmarqueetime = input_time_; - } - - function MatrixLed_marquee_stop() { - window.clearInterval(marqueetimeid); - } - - function MatrixLed_marquee_resume() { - window.clearInterval(marqueetimeid); - if (marqueeactive==1) - marqueetimeid = window.setInterval("MatrixLed_marquee_play()",MatrixLedmarqueetime); - else if (marqueeactive==2) - marqueetimeid = window.setInterval("MatrixLed_marquee_once_play()",MatrixLedmarqueetime); - else if (marqueeactive==3) - marqueetimeid= window.setInterval("MatrixLed_marquee_color_play()",MatrixLedmarqueetime); - else if (marqueeactive==4) - marqueetimeid = window.setInterval("MatrixLed_marquee_color_once_play()",MatrixLedmarqueetime); - } - - function MatrixLed_marquee_reverse() { - MatrixLedmarqueecode = MatrixLedmarqueeinitial; - MatrixLedmarqueecodeonce = MatrixLedmarqueeinitial; - MatrixLedmarqueecolorcode = MatrixLedmarqueeinitial; - MatrixLedmarqueecolorcodeonce = MatrixLedmarqueeinitial; - if (MatrixLedmarqueereverse==1) - MatrixLedmarqueereverse=2; - else if (MatrixLedmarqueereverse==2) - MatrixLedmarqueereverse=1; - } - - function MatrixLed_char(input_char_) { - input_char_=input_char_.toString(); - if (input_char_.length==1) - { - MatrixLed_matrix(MatrixLed_conversion(input_char_)); - } - } - - function MatrixLed_texttocode(input_text_) { - input_text_=input_text_.toString(); - if (input_text_.length>0) - { - var textcode=""; - for (var i=0;i=(5-input_value[i])) - L[k]=MatrixLedcolor; - else - L[k]=MatrixLedbackcolor; - k++; - } - } - MatrixLed_show(); - } - - function Matrixled_clockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_counterclockwise(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[i+5*j]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_verticalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=0;i<=4;i++) - { - for (var j=4;j>=0;j--) - { - L[n]=Tmp[j+5*i]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_horizontalflip(){ - var Tmp = new Array("","","","","","","","","","","","","","","","","","","","","","","","",""); - var n; - for (n=0;n<25;n++) - { - Tmp[n]=L[n]; - } - n=0; - for (var i=4;i>=0;i--) - { - for (var j=0;j<=4;j++) - { - L[n]=Tmp[j+i*5]; - n++; - } - } - MatrixLed_show(); - } - - function Matrixled_invert(){ - for (var i=0;i<25;i++) - { - if ((L[i]=="")||(L[i]==MatrixLedbackcolor)) - L[i]=MatrixLedcolor; - else - L[i]=MatrixLedbackcolor; - } - MatrixLed_show(); - } - - function MatrixLed_getcolor(input_x_,input_y_) { - return L[input_x_*5+input_y_]; - } - - function MatrixLed_backcolor(input_color_) { - MatrixLedbackcolor=input_color_; - } - - function MatrixLed_show() { - if (MatrixLedshowstate==1) - var ledtable ="00"+L[0].replace(/\#/ig, "")+"01"+L[5].replace(/\#/ig, "")+"02"+L[10].replace(/\#/ig, "")+"03"+L[15].replace(/\#/ig, "")+"04"+L[20].replace(/\#/ig, "") - + "05"+L[1].replace(/\#/ig, "")+"06"+L[6].replace(/\#/ig, "")+"07"+L[11].replace(/\#/ig, "")+"08"+L[16].replace(/\#/ig, "")+"09"+L[21].replace(/\#/ig, "") - + "0a"+L[2].replace(/\#/ig, "")+"0b"+L[7].replace(/\#/ig, "")+"0c"+L[12].replace(/\#/ig, "")+"0d"+L[17].replace(/\#/ig, "")+"0e"+L[22].replace(/\#/ig, "") - + "0f"+L[3].replace(/\#/ig, "")+"10"+L[8].replace(/\#/ig, "")+"11"+L[13].replace(/\#/ig, "")+"12"+L[18].replace(/\#/ig, "")+"13"+L[23].replace(/\#/ig, "") - + "14"+L[4].replace(/\#/ig, "")+"15"+L[9].replace(/\#/ig, "")+"16"+L[14].replace(/\#/ig, "")+"17"+L[19].replace(/\#/ig, "")+"18"+L[24].replace(/\#/ig, ""); - else - var ledtable ="00"+MatrixLedbackcolor.replace(/\#/ig, "")+"01"+MatrixLedbackcolor.replace(/\#/ig, "")+"02"+MatrixLedbackcolor.replace(/\#/ig, "")+"03"+MatrixLedbackcolor.replace(/\#/ig, "")+"04"+MatrixLedbackcolor.replace(/\#/ig, "") - + "05"+MatrixLedbackcolor.replace(/\#/ig, "")+"06"+MatrixLedbackcolor.replace(/\#/ig, "")+"07"+MatrixLedbackcolor.replace(/\#/ig, "")+"08"+MatrixLedbackcolor.replace(/\#/ig, "")+"09"+MatrixLedbackcolor.replace(/\#/ig, "") - + "0a"+MatrixLedbackcolor.replace(/\#/ig, "")+"0b"+MatrixLedbackcolor.replace(/\#/ig, "")+"0c"+MatrixLedbackcolor.replace(/\#/ig, "")+"0d"+MatrixLedbackcolor.replace(/\#/ig, "")+"0e"+MatrixLedbackcolor.replace(/\#/ig, "") - + "0f"+MatrixLedbackcolor.replace(/\#/ig, "")+"10"+MatrixLedbackcolor.replace(/\#/ig, "")+"11"+MatrixLedbackcolor.replace(/\#/ig, "")+"12"+MatrixLedbackcolor.replace(/\#/ig, "")+"13"+MatrixLedbackcolor.replace(/\#/ig, "") - + "14"+MatrixLedbackcolor.replace(/\#/ig, "")+"15"+MatrixLedbackcolor.replace(/\#/ig, "")+"16"+MatrixLedbackcolor.replace(/\#/ig, "")+"17"+MatrixLedbackcolor.replace(/\#/ig, "")+"18"+MatrixLedbackcolor.replace(/\#/ig, ""); - - objMatrixLed.setColor(ledtable); - } - - window.MatrixLed_clear = MatrixLed_clear; - window.MatrixLed_matrix = MatrixLed_matrix; - window.MatrixLed_matrix_color = MatrixLed_matrix_color; - window.MatrixLed_show = MatrixLed_show; - window.MatrixLed_on = MatrixLed_on; - window.MatrixLed_color_on = MatrixLed_color_on; - window.MatrixLed_off = MatrixLed_off; - window.MatrixLed_reverse = MatrixLed_reverse; - window.MatrixLed_state = MatrixLed_state; - window.MatrixLed_color = MatrixLed_color; - window.MatrixLed_sample = MatrixLed_sample; - window.MatrixLed_code = MatrixLed_code; - window.MatrixLed_marquee = MatrixLed_marquee; - window.MatrixLed_marquee_play = MatrixLed_marquee_play; - window.MatrixLed_marquee_once = MatrixLed_marquee_once; - window.MatrixLed_marquee_once_play = MatrixLed_marquee_once_play; - window.MatrixLed_marquee_color = MatrixLed_marquee_color; - window.MatrixLed_marquee_color_play = MatrixLed_marquee_color_play; - window.MatrixLed_marquee_color_once = MatrixLed_marquee_color_once; - window.MatrixLed_marquee_color_once_play = MatrixLed_marquee_color_once_play; - window.MatrixLed_matrix_codetocolor = MatrixLed_matrix_codetocolor; - window.MatrixLed_marquee_degree = MatrixLed_marquee_degree; - window.MatrixLed_marquee_color_degree = MatrixLed_marquee_color_degree; - window.MatrixLed_marquee_stop = MatrixLed_marquee_stop; - window.MatrixLed_marquee_resume = MatrixLed_marquee_resume; - window.MatrixLed_marquee_reverse = MatrixLed_marquee_reverse; - window.MatrixLed_marquee_time = MatrixLed_marquee_time; - window.MatrixLed_char = MatrixLed_char; - window.MatrixLed_conversion = MatrixLed_conversion; - window.MatrixLed_texttocode = MatrixLed_texttocode; - window.MatrixLed_showstate = MatrixLed_showstate; - window.MatrixLed_indentcode = MatrixLed_indentcode; - window.MatrixLed_linechart = MatrixLed_linechart; - window.MatrixLed_barchart = MatrixLed_barchart; - window.Matrixled_clockwise = Matrixled_clockwise; - window.Matrixled_counterclockwise = Matrixled_counterclockwise; - window.Matrixled_verticalflip = Matrixled_verticalflip; - window.Matrixled_horizontalflip = Matrixled_horizontalflip; - window.Matrixled_invert = Matrixled_invert; - window.MatrixLed_getcolor = MatrixLed_getcolor; - window.MatrixLed_backcolor = MatrixLed_backcolor; - -}(window, window.document)); diff --git a/demo_text_20180811/blockly.json b/demo_text_20180811/blockly.json deleted file mode 100644 index 1753846ac0..0000000000 --- a/demo_text_20180811/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["demo_text_add"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "demotext.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/demo_text_20180811/blockly/blocks.js b/demo_text_20180811/blockly/blocks.js deleted file mode 100644 index d15e297134..0000000000 --- a/demo_text_20180811/blockly/blocks.js +++ /dev/null @@ -1,10 +0,0 @@ -Blockly.Blocks['demo_text_add'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.DEMO_TEXT_ADD_SHOW); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(65); - } -}; diff --git a/demo_text_20180811/blockly/javascript.js b/demo_text_20180811/blockly/javascript.js deleted file mode 100644 index 723a802b5f..0000000000 --- a/demo_text_20180811/blockly/javascript.js +++ /dev/null @@ -1,4 +0,0 @@ -Blockly.JavaScript['demo_text_add'] = function(block) { - var code = 'createDemoText();\n'; - return code; -}; diff --git a/demo_text_20180811/blockly/msg/blocks/en.js b/demo_text_20180811/blockly/msg/blocks/en.js deleted file mode 100644 index 91116eb12e..0000000000 --- a/demo_text_20180811/blockly/msg/blocks/en.js +++ /dev/null @@ -1 +0,0 @@ -Blockly.Msg.DEMO_TEXT_ADD_SHOW = "Demo Text Add"; diff --git a/demo_text_20180811/blockly/msg/blocks/zh-hans.js b/demo_text_20180811/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 7df0a7aede..0000000000 --- a/demo_text_20180811/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -Blockly.Msg.DEMO_TEXT_ADD_SHOW = "显示文字附加"; diff --git a/demo_text_20180811/blockly/msg/blocks/zh-hant.js b/demo_text_20180811/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 7f56e32525..0000000000 --- a/demo_text_20180811/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -Blockly.Msg.DEMO_TEXT_ADD_SHOW = "顯示文字附加"; diff --git a/demo_text_20180811/blockly/msg/en.js b/demo_text_20180811/blockly/msg/en.js deleted file mode 100644 index 3a2fc11ef8..0000000000 --- a/demo_text_20180811/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catDemoText = "Show Text"; diff --git a/demo_text_20180811/blockly/msg/zh-hans.js b/demo_text_20180811/blockly/msg/zh-hans.js deleted file mode 100644 index bdb8ce416b..0000000000 --- a/demo_text_20180811/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catDemoText = "显示文字"; diff --git a/demo_text_20180811/blockly/msg/zh-hant.js b/demo_text_20180811/blockly/msg/zh-hant.js deleted file mode 100644 index ed5170677a..0000000000 --- a/demo_text_20180811/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catDemoText = "顯示文字"; diff --git a/demo_text_20180811/blockly/toolbox.xml b/demo_text_20180811/blockly/toolbox.xml deleted file mode 100644 index 67ddf434c3..0000000000 --- a/demo_text_20180811/blockly/toolbox.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - 20 - - - - - - - 20 - - - - - - - #ff0000 - - - - diff --git a/demo_text_20180811/demotext.js b/demo_text_20180811/demotext.js deleted file mode 100644 index 84fdf3a5e4..0000000000 --- a/demo_text_20180811/demotext.js +++ /dev/null @@ -1,21 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function createDemoText() { - if (!document.getElementById("demo-area-01-show")) - { - var div = document.createElement('div'); - div.id = "demo-area-01-show"; - div.style.zIndex = 999; - div.style.display = 'block'; - div.innerHTML = "123"; - document.body.insertBefore(div, document.body.firstChild); - } - } - - window.createDemoText = createDemoText; - -}(window, window.document)); diff --git a/dvcbot_assistant.gs b/dvcbot_assistant.gs new file mode 100644 index 0000000000..ca57dddd14 --- /dev/null +++ b/dvcbot_assistant.gs @@ -0,0 +1,207 @@ +/* + Author : ChungYi Fu (Kaohsiung, Taiwan) 2024/11/17 01:30 + https://www.facebook.com/francefu +*/ + + +let dvcbot_apiKey = ""; +let dvcbot_assistantId = ""; +let dvcbot_inputMsg = ""; +let dvcbot_response = ""; +let BASE_URL = "https://prod.dvcbot.net/api/assts/v1"; +let THREAD_URL = "https://prod.dvcbot.net/api/assts/v1/threads"; + +function doPost(e) { + dvcbot_apiKey = decodeURIComponent(e.parameter.dvcbot_apiKey) || ""; + dvcbot_assistantId = decodeURIComponent(e.parameter.dvcbot_assistantId) || ""; + dvcbot_inputMsg = decodeURIComponent(e.parameter.dvcbot_inputMsg) || ""; + + var output = ContentService.createTextOutput(); + + const res = sendMessageToDvcbot(dvcbot_inputMsg) + .then(responseMsg => { + return responseMsg; + }) + .catch(error => { + return `Error: ${error}`; + }) + + res.then((promisedata) => { + output.append(promisedata); + }) + return output; +} + +async function sendMessageToDvcbot(inputMsg) { + return new Promise(async (resolve, reject) => { + dvcbot_response = ""; + + const threadId = await createThread(); + const status = await addMessageToThread(threadId, inputMsg); + if (status == "completed") { + const runId = await runAssistant(threadId, dvcbot_assistantId); + const runUrl = `${BASE_URL}/threads/${threadId}/runs`; + await getRunResult(threadId, runUrl, runId); + const responseMsg = await listMessage(threadId); + resolve(responseMsg); + } else { + reject("Thread state is not completed"); + } + }); +} + +async function createThread() { + return new Promise((resolve, reject) => { + let res = UrlFetchApp.fetch(THREAD_URL, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post' + }); + let json = JSON.parse(res.getContentText()); + resolve(json.id); + }); +} + +async function addMessageToThread(threadId, inputMsg) { + return new Promise((resolve, reject) => { + const msgUrl = `${BASE_URL}/threads/${threadId}/messages`; + const createMsgData = { + role: "user", + content: inputMsg + }; + let res = UrlFetchApp.fetch(msgUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': JSON.stringify(createMsgData) + }); + + let json = JSON.parse(res.getContentText()); + resolve(json.status); + }); +} + +async function runAssistant(threadId, dvcbot_assistantId) { + return new Promise((resolve, reject) => { + const runUrl = `${BASE_URL}/threads/${threadId}/runs`; + let now = new Date(); + const createRunData = { + assistant_id: dvcbot_assistantId, + additional_instructions: `The current time is: ${Utilities.formatDate(now, 'GMT+8', 'yyyy-MM-dd HH:mm:ss')}` + }; + let res = UrlFetchApp.fetch(runUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': JSON.stringify(createRunData) + }); + let json = JSON.parse(res.getContentText()); + resolve(json.id); + }); +} + +async function getRunResult(threadId, runUrl, runId) { + return new Promise((resolve, reject) => { + let runStatus = ""; + while (true) { + let res = UrlFetchApp.fetch(`${runUrl}/${runId}`, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'get' + }); + + if (res.getResponseCode() === 200) { + let response = JSON.parse(res.getContentText()); + runStatus = response.status; + const requiredAction = response.required_action; + + if (runStatus === "requires_action" && requiredAction) { + let toolOutputs = []; + const toolCalls = requiredAction.submit_tool_outputs.tool_calls; + for (let i = 0; i < toolCalls.length; i++) { + const funcName = toolCalls[i].function.name; + let args = toolCalls[i].function.arguments; + args = args.replace(/\\"/g, '"'); + const pluginApiUrl = `${BASE_URL}/pluginapi?tid=${threadId}&aid=${dvcbot_assistantId}&pid=${funcName}`; + + let toolRes = UrlFetchApp.fetch(pluginApiUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': JSON.stringify(JSON.parse(args)) + }); + + const output = JSON.parse(toolRes.getContentText()); + const callId = toolCalls[i].id; + dvcbot_response = JSON.stringify(JSON.parse(output.text)); + toolOutputs.push({ + tool_call_id: callId, + output: output.text + }); + } + + const submitToolOutputRunUrl = `${BASE_URL}/threads/${threadId}/runs/${runId}/submit_tool_outputs`; + const toolOutputsData = { + tool_outputs: toolOutputs + }; + + UrlFetchApp.fetch(submitToolOutputRunUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'post', + 'payload': JSON.stringify(toolOutputsData) + }); + + Utilities.sleep(1000); + } else if (runStatus === "completed") { + resolve(); + break; + } else { + Utilities.sleep(1000); + } + } else { + reject(`Error: ${res.getResponseCode()}`); + break; + } + } + }); +} + +async function listMessage(threadId) { + return new Promise((resolve, reject) => { + const msgUrl = `${BASE_URL}/threads/${threadId}/messages`; + let res = UrlFetchApp.fetch(msgUrl, { + 'headers': { + 'OpenAI-Beta': 'assistants=v2', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${dvcbot_apiKey}` + }, + 'method': 'get' + }); + + if (res.getResponseCode() === 200) { + let response = JSON.parse(res.getContentText()); + resolve(response.data[0].content[0].text.value); + } else { + reject(`Error: ${res.getResponseCode()}`); + } + }); +} \ No newline at end of file diff --git a/esp32-cam_linebot_dht.gs b/esp32-cam_linebot_dht.gs new file mode 100644 index 0000000000..9d08acbd12 --- /dev/null +++ b/esp32-cam_linebot_dht.gs @@ -0,0 +1,129 @@ +function doPost(e) { + var BOT_ACCESS_TOKEN = 'Nwyfihc0pKey868MefCc9Er028u7E33OPJuRwdLEi/mmyjBSh0jFOJKvS3AMaFvKUKAp1k7JKdj2tpd8nr8/aJVF45aQajMY0anwVABxPkvJk3oPUeGlmdDWBiQt6qKBLzGhYimXU377SkcT03hhBwdB04t89/1O/w1cDnyilFU=123'; + var NOTIFY_ACCESS_TOKEN = 'RXDcVAhLhvVJjX0fxarGLcrbjqyWWIJPKPu0QdpomFE123'; + var SPREADSHEET_ID = '1VVONSSJSNY8Xj2-hO3swD7EEfky6vA99jp5CzZkxDKM123'; + + var SpreadSheet = SpreadsheetApp.openById(SPREADSHEET_ID); + var Sheet = SpreadSheet.getSheets()[0]; + var lastRow = Sheet.getLastRow(); + + if (e.parameter.myFile) { + var humidity = e.parameter.humidity; + var temperature = e.parameter.temperature; + var myFile = e.parameter.myFile; + var filename = e.parameter.myFilename; + + Sheet.getRange(lastRow+1,1).setValue("'"+Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd HH:mm:ss")); + Sheet.getRange(lastRow+1,2).setValue(humidity); + Sheet.getRange(lastRow+1,3).setValue(temperature); + Sheet.getRange(lastRow+1,4).setValue(filename); + Sheet.getRange(lastRow+1,5).setValue(myFile); + + } else { + + var msg = JSON.parse(e.postData.contents); + const userMessage = msg.events[0].message.text.trim(); + const user_id = msg.events[0].source.userId; + const event_type = msg.events[0].source.type; + const replyToken = msg.events[0].replyToken; + + var reply_message; + var Time = Sheet.getRange(lastRow,1).getValue(); + + if (userMessage=="image") { + var myFile = Sheet.getRange(lastRow,5).getValue(); + var imageData = myFile.substring(myFile.indexOf(",")+1); + imageData = Utilities.base64Decode(imageData); + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var filename = Sheet.getRange(lastRow,4).getValue(); + var message = filename; + + var blob = Utilities.newBlob(imageData, contentType, filename); + var boundary = "------------------------------"; + var imageData = Utilities.newBlob( + "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"message\"; \r\n\r\n" + message + "\r\n" + + "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"imageFile\"; filename=\"" + filename + "\"\r\n" + + "Content-Type: " + 'image/jpeg' +"\r\n\r\n" + ).getBytes(); + imageData = imageData.concat(blob.getBytes()); + imageData = imageData.concat(Utilities.newBlob("\r\n--" + boundary + "--\r\n").getBytes()); + + var options = { + "method" : "post", + "contentType" : "multipart/form-data; boundary=" + boundary, + "payload" : imageData, + "headers" : {"Authorization" : "Bearer " + NOTIFY_ACCESS_TOKEN} + }; + UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options); + } + else if (userMessage=="humidity") { + var humidity = Time+"\nhumidity = "+Sheet.getRange(lastRow,2).getValue()+" %"; + reply_message = [{ + "type":"text", + "text": humidity + }] + sendMessageToLineBot(BOT_ACCESS_TOKEN,replyToken,reply_message); + } + else if (userMessage=="temperature") { + var temperature = Time+"\ntemperature = "+Sheet.getRange(lastRow,3).getValue()+" °C"; + reply_message = [{ + "type":"text", + "text": temperature + }] + sendMessageToLineBot(BOT_ACCESS_TOKEN,replyToken,reply_message); + } + else if (userMessage=="help") { + reply_message = [{ + "type": "text", + "text": "Command list", + "quickReply": { + "items": [ + { + "type": "action", + "action": { + "type": "message", + "label": "humidity", + "text": "humidity" + } + }, + { + "type": "action", + "action": { + "type": "message", + "label": "temperature", + "text": "temperature" + } + }, + { + "type": "action", + "action": { + "type": "message", + "label": "image", + "text": "image" + } + } + ] + } + }] + sendMessageToLineBot(BOT_ACCESS_TOKEN,replyToken,reply_message); + } + } + return ContentService.createTextOutput("Return = OK"); +} + +function sendMessageToLineBot(accessToken, replyToken, reply_message) { + var url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); +} diff --git a/esp32-cam_linebot_dht_mqtt.txt b/esp32-cam_linebot_dht_mqtt.txt new file mode 100644 index 0000000000..9d65077c0f --- /dev/null +++ b/esp32-cam_linebot_dht_mqtt.txt @@ -0,0 +1,253 @@ +function doPost(e) { + + var BOT_ACCESS_TOKEN = 'Nwyfihc0pKey868MefCc9Er028u7E33OPJuRwdLEi/mmyjBSh0jFOJKvS3AMaFvKUKAp1k7JKdj2tpd8nr8/aJVF45aQajMY0anwVABxPkvJk3oPUeGlmdDWBiQt6qKBLzGhYimXU377SkcT03hhBwdB04t89/1O/w1cDnyilFU=123'; + var NOTIFY_ACCESS_TOKEN = 'RXDcVAhLhvVJjX0fxarGLcrbjqyWWIJPKPu0QdpomFE123'; + var SPREADSHEET_ID = '1VVONSSJSNY8Xj2-hO3swD7EEfky6vA99jp5CzZkxDKM123'; + var APPS_SCRIPT_ID = "AKfycbwjXH4ahYN8xiVGcU5k4Dbu-Fjx95Q9O4gCvLMU19OghCfD6dd2DEDKGPpqT8pxYjh-123"; + + var scriptProperties = PropertiesService.getScriptProperties(); + var SpreadSheet = SpreadsheetApp.openById(SPREADSHEET_ID); + var Sheet = SpreadSheet.getSheets()[0]; + var lastRow = Sheet.getLastRow(); + + if (e.parameter.myFile) { + + var humidity = e.parameter.humidity; + var temperature = e.parameter.temperature; + var myFile = e.parameter.myFile; + var filename = e.parameter.myFilename; + + Sheet.getRange(lastRow+1,1).setValue("'"+Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd HH:mm:ss")); + Sheet.getRange(lastRow+1,2).setValue(humidity); + Sheet.getRange(lastRow+1,3).setValue(temperature); + Sheet.getRange(lastRow+1,4).setValue(filename); + Sheet.getRange(lastRow+1,5).setValue(myFile); + + } else if (e.postData) { + + var msg = JSON.parse(e.postData.contents); + const userMessage = msg.events[0].message.text.trim(); + const user_id = msg.events[0].source.userId; + const event_type = msg.events[0].source.type; + const replyToken = msg.events[0].replyToken; + + var reply_message; + var Time = Sheet.getRange(lastRow,1).getValue(); + + + if (userMessage=="image") { + + var myFile = Sheet.getRange(lastRow,5).getValue(); + var imageData = myFile.substring(myFile.indexOf(",")+1); + imageData = Utilities.base64Decode(imageData); + var contentType = myFile.substring(myFile.indexOf(":")+1, myFile.indexOf(";")); + var filename = Sheet.getRange(lastRow,4).getValue(); + var message = filename; + + var blob = Utilities.newBlob(imageData, contentType, filename); + var boundary = "------------------------------"; + var imageData = Utilities.newBlob( + "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"message\"; \r\n\r\n" + message + "\r\n" + + "--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\"imageFile\"; filename=\"" + filename + "\"\r\n" + + "Content-Type: " + 'image/jpeg' +"\r\n\r\n" + ).getBytes(); + imageData = imageData.concat(blob.getBytes()); + imageData = imageData.concat(Utilities.newBlob("\r\n--" + boundary + "--\r\n").getBytes()); + + var options = { + "method" : "post", + "contentType" : "multipart/form-data; boundary=" + boundary, + "payload" : imageData, + "headers" : {"Authorization" : "Bearer " + NOTIFY_ACCESS_TOKEN} + }; + UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options); + + } else if (userMessage=="humidity") { + var humidity = Time+"\nhumidity = "+Sheet.getRange(lastRow,2).getValue()+" %"; + reply_message = [{ + "type":"text", + "text": humidity + }] + sendMessageToLineBot(BOT_ACCESS_TOKEN,replyToken,reply_message); + + } else if (userMessage=="temperature") { + var temperature = Time+"\ntemperature = "+Sheet.getRange(lastRow,3).getValue()+" °C"; + reply_message = [{ + "type":"text", + "text": temperature + }] + sendMessageToLineBot(BOT_ACCESS_TOKEN,replyToken,reply_message); + + } else if (userMessage=="help") { + + reply_message = [{ + "type": "text", + "text": "Command list", + "quickReply": { + "items": [ + { + "type": "action", + "action": { + "type": "message", + "label": "humidity", + "text": "humidity" + } + }, + { + "type": "action", + "action": { + "type": "message", + "label": "temperature", + "text": "temperature" + } + }, + { + "type": "action", + "action": { + "type": "message", + "label": "image", + "text": "image" + } + } + ] + } + }] + + sendMessageToLineBot(BOT_ACCESS_TOKEN,replyToken,reply_message); + + } else if (userMessage=="mqtt") { + reply_message = [{ + "type": "text", + "text": "MQTT", + "quickReply": { + "items": [ + { + "type": "action", + "action": { + "type": "uri", + "label": "on", + "uri": "https://script.google.com/macros/s/"+APPS_SCRIPT_ID+"/exec?command=on" + } + }, + { + "type": "action", + "action": { + "type": "uri", + "label": "off", + "uri": "https://script.google.com/macros/s/"+APPS_SCRIPT_ID+"/exec?command=off" + } + } + ] + } + }] + + sendMessageToLineBot(BOT_ACCESS_TOKEN,replyToken,reply_message); + } + } + + scriptProperties.setProperty('command', userMessage); + //return HtmlService.createHtmlOutputFromFile('linebot'); + return ContentService.createTextOutput("Return = OK"); + +} + +function sendMessageToLineBot(accessToken, replyToken, reply_message) { + var url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); +} + +function doGet(e) { + var command = e.parameter.command; + var scriptProperties = PropertiesService.getScriptProperties(); + scriptProperties.setProperty('command', command); + return HtmlService.createHtmlOutputFromFile('linebot'); +} + +function getCommand() { + var scriptProperties = PropertiesService.getScriptProperties(); + var command = scriptProperties.getProperty('command'); + scriptProperties.setProperty('command', ''); + return command; +} + + + + + + + + + + + + + + + + +
+ + + + + + + diff --git a/esp32_linebot_mqtt.txt b/esp32_linebot_mqtt.txt new file mode 100644 index 0000000000..5c80d37330 --- /dev/null +++ b/esp32_linebot_mqtt.txt @@ -0,0 +1,155 @@ +function doPost(e) { + + var BOT_ACCESS_TOKEN = 'Nwyfihc0pKey868MefCc9Er028u7E33OPJuRwdLEi/mmyjBSh0jFOJKvS3AMaFvKUKAp1k7JKdj2tpd8nr8/aJVF45aQajMY0anwVABxPkvJk3oPUeGlmdDWBiQt6qKBLzGhYimXU377SkcT03hhBwdB04t89/1O/w1cDnyilFU=123'; + var APPS_SCRIPT_ID = "AKfycbwjXH4ahYN8xiVGcU5k4Dbu-Fjx95Q9O4gCvLMU19OghCfD6dd2DEDKGPpqT8pxYjh-123"; + + var scriptProperties = PropertiesService.getScriptProperties(); + + if (e.postData) { + + var msg = JSON.parse(e.postData.contents); + const userMessage = msg.events[0].message.text.trim(); + const user_id = msg.events[0].source.userId; + const event_type = msg.events[0].source.type; + const replyToken = msg.events[0].replyToken; + + var reply_message; + + if (userMessage=="mqtt") { + reply_message = [{ + "type": "text", + "text": "MQTT", + "quickReply": { + "items": [ + { + "type": "action", + "action": { + "type": "uri", + "label": "on", + "uri": "https://script.google.com/macros/s/"+APPS_SCRIPT_ID+"/exec?command=on" + } + }, + { + "type": "action", + "action": { + "type": "uri", + "label": "off", + "uri": "https://script.google.com/macros/s/"+APPS_SCRIPT_ID+"/exec?command=off" + } + } + ] + } + }] + + sendMessageToLineBot(BOT_ACCESS_TOKEN,replyToken,reply_message); + } + } + + scriptProperties.setProperty('command', userMessage); + //return HtmlService.createHtmlOutputFromFile('linebot'); + return ContentService.createTextOutput("Return = OK"); + +} + +function sendMessageToLineBot(accessToken, replyToken, reply_message) { + var url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + accessToken, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); +} + +function doGet(e) { + var command = e.parameter.command; + var scriptProperties = PropertiesService.getScriptProperties(); + scriptProperties.setProperty('command', command); + return HtmlService.createHtmlOutputFromFile('linebot'); +} + +function getCommand() { + var scriptProperties = PropertiesService.getScriptProperties(); + var command = scriptProperties.getProperty('command'); + scriptProperties.setProperty('command', ''); + return command; +} + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + diff --git a/groq_LLaMA_googleCalendar.gs b/groq_LLaMA_googleCalendar.gs new file mode 100644 index 0000000000..a9a6c4fbcb --- /dev/null +++ b/groq_LLaMA_googleCalendar.gs @@ -0,0 +1,130 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2025/4/30 08:00 +https://www.facebook.com/francefu +*/ + +let channel_access_TOKEN = "xxxxx"; +let groq_api_KEY = "xxxxx"; + +let openAI_assistant_behavior = ` +請依照以下規範:\n +1. 如果對話內容並未能包含完整日期、時間、持續時間、工作事項,請回傳'error'。\n +2. 如果對話內容包含日期、時間、持續時間、工作事項,請回傳json格式資料,格式如下:\n +{"date":"填入日期轉換為 'YYYY-MM-DD' 格式", "time":"填入時間轉換為 'HH:MM:00' 格式", "duration":"持續幾小時,預設為1","workMatter":"工作事項內容"}\n +3. 資料格式示範: {"date":"2025-05-01", "time":"12:00:00", "duration":1, "workMatter":"相約吃海鮮大餐!"}\n +4. 若沒有提及年份,則表示今年。\n +5. 若沒有提及月份,則表示本月。\n +6. 若沒有提及持續幾小時,則duration值為1。\n +7. 若提到持續一天或全天,時間由當日00:00:00算起。\n +8. 請不要多做解釋。\n +9. 請不要使用Markdown語法。\n +`; + +const error_message = "請傳送文字訊息包含行事曆所需資料:日期、時間、持續時間(可無)、事項描述並聲明要新增行事曆,或者發生提供的openAI Key無法使用!"; + +function doPost(e) { + if (e.postData) { + + let msg = JSON.parse(e.postData.contents); + let userType = msg.events[0].message.type; + let replyToken = msg.events[0].replyToken; + + if (userType=="text") { + let userMessage = msg.events[0].message.text.trim(); + + let openAI_messages = [{"role": "system", "content": openAI_assistant_behavior + "9. 現在時間為" + Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd HH:mm:ss")}]; + let chat_message = {}; + chat_message.role = "user"; + chat_message.content = userMessage; + openAI_messages.push(chat_message); + + let jsonData = sendMessageToOpenaiChat(groq_api_KEY, openAI_messages).replace(/```json|```/g, "").trim(); + if (jsonData!="error") { + try { + let data = JSON.parse(jsonData); + let date = data.date; // 預期格式:'YYYY-MM-DD' + let time = data.time; // 預期格式:'HH:MM:00' + let duration = data.duration; // 預期格式:1 + let workMatter = data.workMatter; // 預期格式:文字敘述 + let response = `行程:${workMatter}\n時間:${date} ${time}\n時數:${duration}\n\n`; + + let eventDateTime = new Date(date + 'T' + time); + let calendar = CalendarApp.getDefaultCalendar(); + try { + calendar.createEvent(workMatter, eventDateTime, new Date(eventDateTime.getTime() + Number(duration) * 60 * 60 * 1000)); + let replyMessage = [{ + "type":"text", + "text": response + "行事曆建立成功!" + }]; + sendMessageToLineBot(replyToken, replyMessage); + } catch (calendarError) { + let replyMessage = [{ + "type":"text", + "text": jsonData + "\n\n行事曆建立失敗,請檢查日期時間格式或權限設定!\n錯誤訊息:" + calendarError + }]; + sendMessageToLineBot(replyToken, replyMessage); + } + } catch (error) { + let replyMessage = [{ + "type":"text", + "text": error_message + }] + sendMessageToLineBot(replyToken, replyMessage); + } + } else { + let replyMessage = [{ + "type":"text", + "text": error_message + }] + sendMessageToLineBot(replyToken, replyMessage); + } + } + } + + return ContentService.createTextOutput("OK"); +} + +function sendMessageToOpenaiChat(key, messages) { + try { + let url = "https://api.groq.com/openai/v1/chat/completions"; + let data = { + "model": "meta-llama/llama-4-scout-17b-16e-instruct", // "model": "deepseek-r1-distill-qwen-32b", + "messages": messages + }; + + const authHeader = "Bearer " + key; + const options = { + headers: { + Authorization: authHeader + }, + method: 'POST', + contentType: 'application/json', + payload: JSON.stringify(data) + } + + let response = UrlFetchApp.fetch(url, options); + let json = JSON.parse(response.getContentText()); + response = json["choices"][0]["message"]["content"]; + if (response == "null") + response = json["error"]["message"]; + + return response; + } catch (error) { + return error; + } +} + +function sendMessageToLineBot(replyToken, reply_message) { + let url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + channel_access_TOKEN, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); +} diff --git a/iframe_20180103/blockly.json b/iframe_20180103/blockly.json deleted file mode 100644 index 000901f8db..0000000000 --- a/iframe_20180103/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["iframe_open","iframe_close"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "iframe.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/iframe_20180103/blockly/blocks.js b/iframe_20180103/blockly/blocks.js deleted file mode 100644 index c56d676f92..0000000000 --- a/iframe_20180103/blockly/blocks.js +++ /dev/null @@ -1,41 +0,0 @@ -Blockly.Blocks['iframe_open'] = { - init: function() { - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TEXT_SHOW) - .appendField(Blockly.Msg.URL_SHOW) - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW) - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setTooltip(''); - this.setColour(65); - this.setHelpUrl(mainUrl + 'basic/blockly/blockly-information.html' + utmUrl); - } -}; -Blockly.Blocks['iframe_close'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.CLOSE_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(65); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/iframe_20180103/blockly/javascript.js b/iframe_20180103/blockly/javascript.js deleted file mode 100644 index 709ef601a8..0000000000 --- a/iframe_20180103/blockly/javascript.js +++ /dev/null @@ -1,13 +0,0 @@ -Blockly.JavaScript['iframe_open'] = function (block) { - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'createIframe(' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ');'; - return code; -}; -Blockly.JavaScript['iframe_close'] = function(block) { - var code = 'createIframe(\'about:blank\',0,0,0,0);'; - return code; -}; diff --git a/iframe_20180103/blockly/msg/blocks/en.js b/iframe_20180103/blockly/msg/blocks/en.js deleted file mode 100644 index 045d836e7f..0000000000 --- a/iframe_20180103/blockly/msg/blocks/en.js +++ /dev/null @@ -1,6 +0,0 @@ -Blockly.Msg.TEXT_SHOW = "Web Page"; -Blockly.Msg.URL_SHOW = "url"; -Blockly.Msg.WIDTH_SHOW = "width"; -Blockly.Msg.LEFT_SHOW = "LEFT"; -Blockly.Msg.TOP_SHOW = "TOP"; -Blockly.Msg.CLOSE_SHOW = "Close Web Page"; diff --git a/iframe_20180103/blockly/msg/blocks/zh-hans.js b/iframe_20180103/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index af289989a2..0000000000 --- a/iframe_20180103/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,7 +0,0 @@ -Blockly.Msg.TEXT_SHOW = "显示网页"; -Blockly.Msg.URL_SHOW = "网址"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "右移距离"; -Blockly.Msg.TOP_SHOW = "下移距离"; -Blockly.Msg.CLOSE_SHOW = "关闭 显示网页"; diff --git a/iframe_20180103/blockly/msg/blocks/zh-hant.js b/iframe_20180103/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 3caaea8def..0000000000 --- a/iframe_20180103/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,7 +0,0 @@ -Blockly.Msg.TEXT_SHOW = "顯示網頁"; -Blockly.Msg.URL_SHOW = "網址"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "右移距離"; -Blockly.Msg.TOP_SHOW = "下移距離"; -Blockly.Msg.CLOSE_SHOW = "關閉 顯示網頁"; diff --git a/iframe_20180103/blockly/msg/en.js b/iframe_20180103/blockly/msg/en.js deleted file mode 100644 index 4d02a868f1..0000000000 --- a/iframe_20180103/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catIframe = "Web Page"; diff --git a/iframe_20180103/blockly/msg/zh-hans.js b/iframe_20180103/blockly/msg/zh-hans.js deleted file mode 100644 index 428ded3477..0000000000 --- a/iframe_20180103/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catIframe = "显示网页"; diff --git a/iframe_20180103/blockly/msg/zh-hant.js b/iframe_20180103/blockly/msg/zh-hant.js deleted file mode 100644 index f923e468b4..0000000000 --- a/iframe_20180103/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catIframe = "顯示網頁"; diff --git a/iframe_20180103/blockly/toolbox.xml b/iframe_20180103/blockly/toolbox.xml deleted file mode 100644 index 81d79edc2d..0000000000 --- a/iframe_20180103/blockly/toolbox.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - about:blank - - - - - 500 - - - - - 400 - - - - - 0 - - - - - 100 - - - - - diff --git a/iframe_20180103/iframe.js b/iframe_20180103/iframe.js deleted file mode 100644 index 3b27f1ff1e..0000000000 --- a/iframe_20180103/iframe.js +++ /dev/null @@ -1,42 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function createIframe(input_url_,input_WIDTH_,input_HEIGHT_,input_LEFT_,input_TOP_) { - - var substr = input_url_.toLowerCase().split('.'); - var extname_av = ".aac,.au,.aif,.aiff,.aiffc,.alac,.ape,.asf,.avi,.cda,.dat,.divx,.flac,.m2ts,.m4a,.mid,.mov,.mp2,.mp3,.mp4,.mpc,.mpg,.mpeg,.mv2,.ogg,.pdf,.ra,.ram,.raw,.rcp,.rm,.rmvb,.snd,.tak,.tta,.vob,.voc,.wma,.wav,.webm,.wmf,.wmv,.wv,.xmi,"; - var extname_flash = ".swf,.flv,"; - - if (extname_av.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else if (extname_flash.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else - var src = ''; - - if (document.getElementById('fustyles')) - { - document.getElementById('fustyles').style.left = input_LEFT_ + 'px'; - document.getElementById('fustyles').style.top = input_TOP_ + 'px'; - document.getElementById('fustyles').style.display = 'block'; - document.getElementById('fustyles').innerHTML = src; - } - else - { - var div = document.createElement('div'); - div.id = 'fustyles'; - div.style.position = 'absolute'; - div.style.left = input_LEFT_ + 'px'; - div.style.top = input_TOP_ + 'px'; - div.style.zIndex='9999'; - div.innerHTML = src; - document.body.appendChild(div); - } - } - - window.createIframe = createIframe; - -}(window, window.document)); diff --git a/iframe_20180107/blockly.json b/iframe_20180107/blockly.json deleted file mode 100644 index 000901f8db..0000000000 --- a/iframe_20180107/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["iframe_open","iframe_close"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "iframe.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/iframe_20180107/blockly/blocks.js b/iframe_20180107/blockly/blocks.js deleted file mode 100644 index 28570aece1..0000000000 --- a/iframe_20180107/blockly/blocks.js +++ /dev/null @@ -1,48 +0,0 @@ -Blockly.Blocks['iframe_open'] = { - init: function() { - this.appendValueInput("openid_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.OPEN_SHOW) - .appendField(Blockly.Msg.OPENID_SHOW) - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW) - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW) - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setTooltip(''); - this.setColour(65); - this.setHelpUrl(mainUrl + 'basic/blockly/blockly-information.html' + utmUrl); - } -}; -Blockly.Blocks['iframe_close'] = { - init: function() { - this.appendValueInput("closeid_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CLOSE_SHOW) - .appendField(Blockly.Msg.CLOSEID_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(65); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/iframe_20180107/blockly/javascript.js b/iframe_20180107/blockly/javascript.js deleted file mode 100644 index 5502f3dfe7..0000000000 --- a/iframe_20180107/blockly/javascript.js +++ /dev/null @@ -1,16 +0,0 @@ -Blockly.JavaScript['iframe_open'] = function (block) { - var value_openid_ = Blockly.JavaScript.valueToCode(block, 'openid_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'createIframe(' + value_openid_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ');'; - return code; -}; - -Blockly.JavaScript['iframe_close'] = function(block) { - var value_closeid_ = Blockly.JavaScript.valueToCode(block, 'closeid_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'deleteIframe(' + value_closeid_ + ');'; - return code; -}; diff --git a/iframe_20180107/blockly/msg/blocks/en.js b/iframe_20180107/blockly/msg/blocks/en.js deleted file mode 100644 index 475f511e73..0000000000 --- a/iframe_20180107/blockly/msg/blocks/en.js +++ /dev/null @@ -1,8 +0,0 @@ -Blockly.Msg.OPEN_SHOW = "Web Page"; -Blockly.Msg.CLOSE_SHOW = "Close Web Page"; -Blockly.Msg.OPENID_SHOW = "ID"; -Blockly.Msg.CLOSEID_SHOW = "ID"; -Blockly.Msg.URL_SHOW = "URL"; -Blockly.Msg.WIDTH_SHOW = "WIDTH"; -Blockly.Msg.LEFT_SHOW = "LEFT"; -Blockly.Msg.TOP_SHOW = "TOP"; diff --git a/iframe_20180107/blockly/msg/blocks/zh-hans.js b/iframe_20180107/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 1d3ff59447..0000000000 --- a/iframe_20180107/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,9 +0,0 @@ -Blockly.Msg.OPEN_SHOW = "网页显示"; -Blockly.Msg.CLOSE_SHOW = "关闭 网页"; -Blockly.Msg.OPENID_SHOW = "代码"; -Blockly.Msg.CLOSEID_SHOW = "代码"; -Blockly.Msg.URL_SHOW = "来源网址"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; diff --git a/iframe_20180107/blockly/msg/blocks/zh-hant.js b/iframe_20180107/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 29e9f5c80f..0000000000 --- a/iframe_20180107/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,9 +0,0 @@ -Blockly.Msg.OPEN_SHOW = "網頁顯示"; -Blockly.Msg.CLOSE_SHOW = "關閉 網頁"; -Blockly.Msg.OPENID_SHOW = "代碼"; -Blockly.Msg.CLOSEID_SHOW = "代碼"; -Blockly.Msg.URL_SHOW = "來源網址"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; diff --git a/iframe_20180107/blockly/msg/en.js b/iframe_20180107/blockly/msg/en.js deleted file mode 100644 index 4d02a868f1..0000000000 --- a/iframe_20180107/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catIframe = "Web Page"; diff --git a/iframe_20180107/blockly/msg/zh-hans.js b/iframe_20180107/blockly/msg/zh-hans.js deleted file mode 100644 index 428ded3477..0000000000 --- a/iframe_20180107/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catIframe = "显示网页"; diff --git a/iframe_20180107/blockly/msg/zh-hant.js b/iframe_20180107/blockly/msg/zh-hant.js deleted file mode 100644 index f923e468b4..0000000000 --- a/iframe_20180107/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catIframe = "顯示網頁"; diff --git a/iframe_20180107/blockly/toolbox.xml b/iframe_20180107/blockly/toolbox.xml deleted file mode 100644 index 1e1aa49d99..0000000000 --- a/iframe_20180107/blockly/toolbox.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - about:blank - - - - - 500 - - - - - 400 - - - - - 0 - - - - - 100 - - - - - - - - - - - diff --git a/iframe_20180107/iframe.js b/iframe_20180107/iframe.js deleted file mode 100644 index 7cbfb739ed..0000000000 --- a/iframe_20180107/iframe.js +++ /dev/null @@ -1,50 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function createIframe(input_id_,input_url_,input_WIDTH_,input_HEIGHT_,input_LEFT_,input_TOP_) { - - var substr = input_url_.toLowerCase().split('.'); - var extname_av = ".aac,.au,.aif,.aiff,.aiffc,.alac,.ape,.asf,.avi,.cda,.dat,.divx,.flac,.m2ts,.m4a,.mid,.mov,.mp2,.mp3,.mp4,.mpc,.mpg,.mpeg,.mv2,.ogg,.pdf,.ra,.ram,.raw,.rcp,.rm,.rmvb,.snd,.tak,.tta,.vob,.voc,.wma,.wav,.webm,.wmf,.wmv,.wv,.xmi,"; - var extname_flash = ".swf,.flv,"; - - if (input_url_.toLowerCase().indexOf("http")!=0) - var src = input_url_; - else if (extname_av.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else if (extname_flash.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else - var src = ''; - - if (document.getElementById("fustyles_iframe"+input_id_)) - { - document.getElementById("fustyles_iframe"+input_id_).style.left = input_LEFT_ + 'px'; - document.getElementById("fustyles_iframe"+input_id_).style.top = input_TOP_ + 'px'; - document.getElementById("fustyles_iframe"+input_id_).style.display = 'block'; - document.getElementById("fustyles_iframe"+input_id_).innerHTML = src; - } - else - { - var div = document.createElement('div'); - div.id = "fustyles_iframe"+input_id_; - div.style.position = 'absolute'; - div.style.left = input_LEFT_ + 'px'; - div.style.top = input_TOP_ + 'px'; - div.style.zIndex='9999'; - div.innerHTML = src; - document.body.appendChild(div); - } - } - - function deleteIframe(input_id_){ - if (document.getElementById("fustyles_iframe"+input_id_)) - document.getElementById("fustyles_iframe"+input_id_).remove(); - } - - window.createIframe = createIframe; - window.deleteIframe = deleteIframe; - -}(window, window.document)); diff --git a/iframe_20180802/blockly.json b/iframe_20180802/blockly.json deleted file mode 100644 index 000901f8db..0000000000 --- a/iframe_20180802/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["iframe_open","iframe_close"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "iframe.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/iframe_20180802/blockly/blocks.js b/iframe_20180802/blockly/blocks.js deleted file mode 100644 index d9ffeaded9..0000000000 --- a/iframe_20180802/blockly/blocks.js +++ /dev/null @@ -1,52 +0,0 @@ -Blockly.Blocks['iframe_open'] = { - init: function() { - this.appendValueInput("openid_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.OPEN_SHOW) - .appendField(Blockly.Msg.OPENID_SHOW) - this.appendValueInput("url_") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.URL_SHOW) - this.appendValueInput("width_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.WIDTH_SHOW) - this.appendValueInput("height_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.HEIGHT_SHOW); - this.appendValueInput("left_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.LEFT_SHOW); - this.appendValueInput("top_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.TOP_SHOW); - this.appendValueInput("zindex_") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.ZINDEX_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setTooltip(''); - this.setColour(65); - this.setHelpUrl(mainUrl + 'basic/blockly/blockly-information.html' + utmUrl); - } -}; -Blockly.Blocks['iframe_close'] = { - init: function() { - this.appendValueInput("closeid_") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(Blockly.Msg.CLOSE_SHOW) - .appendField(Blockly.Msg.CLOSEID_SHOW) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(65); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/iframe_20180802/blockly/javascript.js b/iframe_20180802/blockly/javascript.js deleted file mode 100644 index b225c1afb7..0000000000 --- a/iframe_20180802/blockly/javascript.js +++ /dev/null @@ -1,17 +0,0 @@ -Blockly.JavaScript['iframe_open'] = function (block) { - var value_openid_ = Blockly.JavaScript.valueToCode(block, 'openid_', Blockly.JavaScript.ORDER_ATOMIC); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'url_', Blockly.JavaScript.ORDER_ATOMIC); - var value_width_ = Blockly.JavaScript.valueToCode(block, 'width_', Blockly.JavaScript.ORDER_ATOMIC); - var value_height_ = Blockly.JavaScript.valueToCode(block, 'height_', Blockly.JavaScript.ORDER_ATOMIC); - var value_left_ = Blockly.JavaScript.valueToCode(block, 'left_', Blockly.JavaScript.ORDER_ATOMIC); - var value_top_ = Blockly.JavaScript.valueToCode(block, 'top_', Blockly.JavaScript.ORDER_ATOMIC); - var value_zindex_ = Blockly.JavaScript.valueToCode(block, 'zindex_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'createIframe(' + value_openid_ + ',' + value_url_ + ','+ value_width_ + ',' + value_height_ + ',' + value_left_ + ',' + value_top_ + ',' + value_zindex_ + ');\n'; - return code; -}; - -Blockly.JavaScript['iframe_close'] = function(block) { - var value_closeid_ = Blockly.JavaScript.valueToCode(block, 'closeid_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'deleteIframe(' + value_closeid_ + ');\n'; - return code; -}; diff --git a/iframe_20180802/blockly/msg/blocks/en.js b/iframe_20180802/blockly/msg/blocks/en.js deleted file mode 100644 index 11e7c6ee40..0000000000 --- a/iframe_20180802/blockly/msg/blocks/en.js +++ /dev/null @@ -1,9 +0,0 @@ -Blockly.Msg.OPEN_SHOW = "Web Page"; -Blockly.Msg.CLOSE_SHOW = "Close Web Page"; -Blockly.Msg.OPENID_SHOW = "ID"; -Blockly.Msg.CLOSEID_SHOW = "ID"; -Blockly.Msg.URL_SHOW = "Url"; -Blockly.Msg.WIDTH_SHOW = "Width"; -Blockly.Msg.LEFT_SHOW = "Left"; -Blockly.Msg.TOP_SHOW = "Top"; -Blockly.Msg.ZINDEX_SHOW = "Z-index"; diff --git a/iframe_20180802/blockly/msg/blocks/zh-hans.js b/iframe_20180802/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 1c6964503a..0000000000 --- a/iframe_20180802/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,10 +0,0 @@ -Blockly.Msg.OPEN_SHOW = "网页显示"; -Blockly.Msg.CLOSE_SHOW = "关闭 网页"; -Blockly.Msg.OPENID_SHOW = "代码"; -Blockly.Msg.CLOSEID_SHOW = "代码"; -Blockly.Msg.URL_SHOW = "来源网址"; -Blockly.Msg.WIDTH_SHOW = "宽度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距离"; -Blockly.Msg.TOP_SHOW = "靠上距离"; -Blockly.Msg.ZINDEX_SHOW = "层次"; diff --git a/iframe_20180802/blockly/msg/blocks/zh-hant.js b/iframe_20180802/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index ae2b618006..0000000000 --- a/iframe_20180802/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,10 +0,0 @@ -Blockly.Msg.OPEN_SHOW = "網頁顯示"; -Blockly.Msg.CLOSE_SHOW = "關閉 網頁"; -Blockly.Msg.OPENID_SHOW = "代碼"; -Blockly.Msg.CLOSEID_SHOW = "代碼"; -Blockly.Msg.URL_SHOW = "來源網址"; -Blockly.Msg.WIDTH_SHOW = "寬度"; -Blockly.Msg.HEIGHT_SHOW = "高度"; -Blockly.Msg.LEFT_SHOW = "靠左距離"; -Blockly.Msg.TOP_SHOW = "靠上距離"; -Blockly.Msg.ZINDEX_SHOW = "層次"; diff --git a/iframe_20180802/blockly/msg/en.js b/iframe_20180802/blockly/msg/en.js deleted file mode 100644 index 4d02a868f1..0000000000 --- a/iframe_20180802/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catIframe = "Web Page"; diff --git a/iframe_20180802/blockly/msg/zh-hans.js b/iframe_20180802/blockly/msg/zh-hans.js deleted file mode 100644 index 428ded3477..0000000000 --- a/iframe_20180802/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catIframe = "显示网页"; diff --git a/iframe_20180802/blockly/msg/zh-hant.js b/iframe_20180802/blockly/msg/zh-hant.js deleted file mode 100644 index f923e468b4..0000000000 --- a/iframe_20180802/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catIframe = "顯示網頁"; diff --git a/iframe_20180802/blockly/toolbox.xml b/iframe_20180802/blockly/toolbox.xml deleted file mode 100644 index c461f7035e..0000000000 --- a/iframe_20180802/blockly/toolbox.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - about:blank - - - - - 500 - - - - - 400 - - - - - 0 - - - - - 100 - - - - - 0 - - - - - - - - - - - diff --git a/iframe_20180802/iframe.js b/iframe_20180802/iframe.js deleted file mode 100644 index 73aeee6e4a..0000000000 --- a/iframe_20180802/iframe.js +++ /dev/null @@ -1,51 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function createIframe(input_id_,input_url_,input_width_,input_height_,input_left_,input_top_,input_zindex_) { - - var substr = input_url_.toLowerCase().split('.'); - var extname_av = ".aac,.au,.aif,.aiff,.aiffc,.alac,.ape,.asf,.avi,.cda,.dat,.divx,.flac,.m2ts,.m4a,.mid,.mov,.mp2,.mp3,.mp4,.mpc,.mpg,.mpeg,.mv2,.ogg,.pdf,.ra,.ram,.raw,.rcp,.rm,.rmvb,.snd,.tak,.tta,.vob,.voc,.wma,.wav,.webm,.wmf,.wmv,.wv,.xmi,"; - var extname_flash = ".swf,.flv,"; - - if (input_url_.toLowerCase().indexOf("http")!=0) - var src = input_url_; - else if (extname_av.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else if (extname_flash.indexOf("."+substr[substr.length-1]+",")!=-1) - var src = ''; - else - var src = ''; - - if (document.getElementById("iframe"+input_id_)) - { - document.getElementById("iframe"+input_id_).style.left = input_left_ + 'px'; - document.getElementById("iframe"+input_id_).style.top = input_top_ + 'px'; - document.getElementById("iframe"+input_id_).style.zIndex = input_zindex_; - document.getElementById("iframe"+input_id_).innerHTML = src; - } - else - { - var div = document.createElement('div'); - div.id = "iframe"+input_id_; - div.style.position = 'absolute'; - div.style.left = input_left_ + 'px'; - div.style.top = input_top_ + 'px'; - div.style.zIndex = input_zindex_; - div.style.display = 'block'; - div.innerHTML = src; - document.body.appendChild(div); - } - } - - function deleteIframe(input_id_){ - if (document.getElementById("iframe"+input_id_)) - document.getElementById("iframe"+input_id_).remove(); - } - - window.createIframe = createIframe; - window.deleteIframe = deleteIframe; - -}(window, window.document)); diff --git a/linebot_push_message.gs b/linebot_push_message.gs new file mode 100644 index 0000000000..7de7c3b5cb --- /dev/null +++ b/linebot_push_message.gs @@ -0,0 +1,129 @@ +function doGet(e) { + var token = ((!e.parameter.token)?"":e.parameter.token); + var userid = ((!e.parameter.userid)?"":e.parameter.userid); + var type = ((!e.parameter.type)?"":e.parameter.type); + var text = ((!e.parameter.text)?"":e.parameter.text); + var packageId = ((!e.parameter.packageId)?"":e.parameter.packageId); + var stickerId = ((!e.parameter.stickerId)?"":e.parameter.stickerId); + var originalContentUrl = ((!e.parameter.originalContentUrl)?"":e.parameter.originalContentUrl); + var previewImageUrl = ((!e.parameter.previewImageUrl)?"":e.parameter.previewImageUrl); + var duration = ((!e.parameter.duration)?"":e.parameter.duration); + var title = ((!e.parameter.title)?"":e.parameter.title); + var address = ((!e.parameter.address)?"":e.parameter.address); + var latitude = ((!e.parameter.latitude)?"":e.parameter.latitude); + var longitude = ((!e.parameter.longitude)?"":e.parameter.longitude); + + token = token.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + userid = userid.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + type = type.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + text = text.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + packageId = packageId.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + stickerId = stickerId.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + originalContentUrl = originalContentUrl.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + previewImageUrl = previewImageUrl.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + duration = duration.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + title = title.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + address = address.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + latitude = latitude.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + longitude = longitude.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + + text = text.replace(/\/g,"\n").replace(/\/g,"\n").replace(/\
/g,"\n").replace(/\/g,"\n").replace(/\/g,"\n").replace(/\
/g,"\n"); + + //console.log("token="+token); + //console.log("userid="+userid); + //console.log("type="+type); + //console.log("text="+text); + //console.log("packageId="+packageId); + //console.log("stickerId="+stickerId); + //console.log("originalContentUrl="+originalContentUrl); + //console.log("previewImageUrl="+previewImageUrl); + //console.log("duration="+duration); + //console.log("title="+title); + //console.log("address="+address); + //console.log("latitude="+latitude); + //console.log("longitude="+longitude); + + if (type=="text") { + var payload= JSON.stringify({ + 'to': userid, + 'messages': [{ + type:'text', + text:text + }] + }); + } + else if (type=="sticker") { + var payload= JSON.stringify({ + 'to': userid, + 'messages': [{ + type:'sticker', + packageId:packageId, + stickerId:stickerId + }] + }); + } + else if (type=="image") { + var payload= JSON.stringify({ + 'to': userid, + 'messages': [{ + type:'image', + originalContentUrl:originalContentUrl, + previewImageUrl:previewImageUrl + }] + }); + } + else if (type=="video") { + var payload= JSON.stringify({ + 'to': userid, + 'messages': [{ + type:'video', + originalContentUrl:originalContentUrl, + previewImageUrl:previewImageUrl + }] + }); + } + else if (type=="audio") { + var payload= JSON.stringify({ + 'to': userid, + 'messages': [{ + type:'audio', + originalContentUrl:originalContentUrl, + duration:duration + }] + }); + } + else if (type=="location") { + var payload= JSON.stringify({ + 'to': userid, + 'messages': [{ + type:'location', + title:title, + address:address, + latitude:latitude, + longitude:longitude + }] + }); + } + + // Send a push message + var res = ""; + try { + var url = 'https://api.line.me/v2/bot/message/push'; + var response = UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + token, + }, + 'method': 'post', + 'payload': payload + }); + } catch(error) { + res = error; + } + + if (res=="") res = type + " OK"; + var result = JSON.stringify({ + "LineBot": res + }); + return ContentService.createTextOutput("console.log(" + result + ")").setMimeType(ContentService.MimeType.JAVASCRIPT); +} diff --git a/linenotify_push_message.gs b/linenotify_push_message.gs new file mode 100644 index 0000000000..a433358e90 --- /dev/null +++ b/linenotify_push_message.gs @@ -0,0 +1,53 @@ +function doGet(e) { + var token = ((!e.parameter.token)?"":e.parameter.token); + var type = ((!e.parameter.type)?"":e.parameter.type); + var text = ((!e.parameter.text)?"":e.parameter.text); + var packageId = ((!e.parameter.packageId)?"":e.parameter.packageId); + var stickerId = ((!e.parameter.stickerId)?"":e.parameter.stickerId); + var originalContentUrl = ((!e.parameter.originalContentUrl)?"":e.parameter.originalContentUrl); + var previewImageUrl = ((!e.parameter.previewImageUrl)?"":e.parameter.previewImageUrl); + + type = type.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + text = text.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + packageId = packageId.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + stickerId = stickerId.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + originalContentUrl = originalContentUrl.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + previewImageUrl = previewImageUrl.replace(/\%27/g,"\'").replace(/\%22/g,"\""); + + text = text.replace(/\/g,"\n").replace(/\/g,"\n").replace(/\
/g,"\n").replace(/\/g,"\n").replace(/\/g,"\n").replace(/\
/g,"\n"); + + //console.log("token="+token); + //console.log("type="+type); + //console.log("text="+text); + //console.log("packageId="+packageId); + //console.log("stickerId="+stickerId); + //console.log("originalContentUrl="+originalContentUrl); + //console.log("previewImageUrl="+previewImageUrl); + + // Send a push message + var res = ""; + try { + var url = 'https://notify-api.line.me/api/notify'; + var response = UrlFetchApp.fetch(url, { + 'headers': { + 'Authorization': 'Bearer ' + token, + }, + 'method': 'post', + 'payload': { + 'message':text + ' ', + 'imageThumbnail':previewImageUrl, + 'imageFullsize':originalContentUrl, + 'stickerPackageId':packageId, + 'stickerId':stickerId + } + }); + } catch(error) { + res = error; + } + + if (res=="") res = response.getContentText(); + var result = JSON.stringify({ + "LineNotify": res + }); + return ContentService.createTextOutput("console.log(" + result + ")").setMimeType(ContentService.MimeType.JAVASCRIPT); +} diff --git a/modifyWebDemo_20180526/blockly.json b/modifyWebDemo_20180526/blockly.json deleted file mode 100644 index 17cc53b3c6..0000000000 --- a/modifyWebDemo_20180526/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["create_button"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "createbutton.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/modifyWebDemo_20180526/blockly/blocks.js b/modifyWebDemo_20180526/blockly/blocks.js deleted file mode 100644 index be34690ce4..0000000000 --- a/modifyWebDemo_20180526/blockly/blocks.js +++ /dev/null @@ -1,11 +0,0 @@ -Blockly.Blocks['create_button'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.create_button) - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setColour(65); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/modifyWebDemo_20180526/blockly/javascript.js b/modifyWebDemo_20180526/blockly/javascript.js deleted file mode 100644 index 9fc19a0b4e..0000000000 --- a/modifyWebDemo_20180526/blockly/javascript.js +++ /dev/null @@ -1,4 +0,0 @@ -Blockly.JavaScript['create_button'] = function(block) { - var code = 'createButton();\n'; - return code; -}; diff --git a/modifyWebDemo_20180526/blockly/msg/blocks/en.js b/modifyWebDemo_20180526/blockly/msg/blocks/en.js deleted file mode 100644 index fde7cbd005..0000000000 --- a/modifyWebDemo_20180526/blockly/msg/blocks/en.js +++ /dev/null @@ -1 +0,0 @@ -Blockly.Msg.create_button = "Modify Web Demo"; diff --git a/modifyWebDemo_20180526/blockly/msg/blocks/zh-hans.js b/modifyWebDemo_20180526/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index fde7cbd005..0000000000 --- a/modifyWebDemo_20180526/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -Blockly.Msg.create_button = "Modify Web Demo"; diff --git a/modifyWebDemo_20180526/blockly/msg/blocks/zh-hant.js b/modifyWebDemo_20180526/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index aa2240adeb..0000000000 --- a/modifyWebDemo_20180526/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -Blockly.Msg.create_button = "修改網頁互動區域"; diff --git a/modifyWebDemo_20180526/blockly/msg/en.js b/modifyWebDemo_20180526/blockly/msg/en.js deleted file mode 100644 index 221ffcc7c0..0000000000 --- a/modifyWebDemo_20180526/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catCreateButton = "WeDemo"; diff --git a/modifyWebDemo_20180526/blockly/msg/zh-hans.js b/modifyWebDemo_20180526/blockly/msg/zh-hans.js deleted file mode 100644 index d9bff8c2cd..0000000000 --- a/modifyWebDemo_20180526/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catCreateButton = "Web Demo"; diff --git a/modifyWebDemo_20180526/blockly/msg/zh-hant.js b/modifyWebDemo_20180526/blockly/msg/zh-hant.js deleted file mode 100644 index d9bff8c2cd..0000000000 --- a/modifyWebDemo_20180526/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catCreateButton = "Web Demo"; diff --git a/modifyWebDemo_20180526/blockly/toolbox.xml b/modifyWebDemo_20180526/blockly/toolbox.xml deleted file mode 100644 index d62fe5d87b..0000000000 --- a/modifyWebDemo_20180526/blockly/toolbox.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/modifyWebDemo_20180526/createbutton.js b/modifyWebDemo_20180526/createbutton.js deleted file mode 100644 index 116c5afeae..0000000000 --- a/modifyWebDemo_20180526/createbutton.js +++ /dev/null @@ -1,37 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function createButton() { - - if (!document.getElementById('fustyles')) - { - var list = document.getElementsByClassName("db5"); - for(var i = list.length-1;i>=0; i--) - if(list[i] && list[i].parentElement) list[i].parentElement.removeChild(list[i]); - - var Html="
"; - - var div = document.createElement('div'); - div.id = 'fustyles'; - //div.style.position = 'absolute'; - //div.style.left = '50px'; - //div.style.top = '100px'; - //div.style.zindex='9999'; - div.innerHTML = Html; - document.body.appendChild(div); - } - - if (!document.getElementById('demo-area-01-show')) - { - var div = document.createElement('div'); - div.id = 'demo-area-01-show'; - document.body.appendChild(div); - } - } - - window.createButton = createButton; - -}(window, window.document)); diff --git a/smart_uart_myfirmata_20180309/blockly.json b/smart_uart_myfirmata_20180309/blockly.json deleted file mode 100644 index f923ffcb4a..0000000000 --- a/smart_uart_myfirmata_20180309/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["uart_car","uart_system","uart_custom"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "uartmyfirmata.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/smart_uart_myfirmata_20180309/blockly/blocks.js b/smart_uart_myfirmata_20180309/blockly/blocks.js deleted file mode 100644 index 297a459dbe..0000000000 --- a/smart_uart_myfirmata_20180309/blockly/blocks.js +++ /dev/null @@ -1,124 +0,0 @@ -Blockly.Blocks['uart_car'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_LEFT) - .appendField("Uart Car"); - this.appendValueInput("cmd") - .setCheck("String") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("cmd"); - this.appendValueInput("str1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("pinL1"); - this.appendValueInput("str2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("pinL2"); - this.appendValueInput("str3") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("pinR1"); - this.appendValueInput("str4") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("pinR2"); - this.appendValueInput("str5") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("L speed"); - this.appendValueInput("str6") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("R speed"); - this.appendValueInput("str7") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("Delay(ms)"); - this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("State") - .appendField(new Blockly.FieldDropdown([["FORWARD","F"], ["BACKWARD","B"], ["LEFT","L"], ["RIGHT","R"], ["STOP","S"]]), "str8"); - this.setInputsInline(false); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['uart_system'] = { - init: function() { - this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("Uart System cmd") - .appendField(new Blockly.FieldDropdown([["inputPullup","inputpullup"], ["pinMode","pinmode"], ["digitalWrite","digitalwrite"], ["digitalRead","digitalread"], ["analogWrite","analogwrite"], ["analogRead","analogread"]]), "cmd"); - this.appendValueInput("str1") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("pin"); - this.appendValueInput("str2") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("value"); - this.appendValueInput("str3") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("str3~str9"); - this.setInputsInline(false); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - -Blockly.Blocks['uart_custom'] = { - init: function() { - this.appendValueInput("cmd") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("Uart Custom cmd"); - this.appendValueInput("str1") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("str1"); - this.appendValueInput("str2") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("str2"); - this.appendValueInput("str3") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("str3"); - this.appendValueInput("str4") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("str4"); - this.appendValueInput("str5") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("str5"); - this.appendValueInput("str6") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("str6"); - this.appendValueInput("str7") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("str7"); - this.appendValueInput("str8") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("str8"); - this.appendValueInput("str9") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("str9"); - this.setInputsInline(false); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; diff --git a/smart_uart_myfirmata_20180309/blockly/javascript.js b/smart_uart_myfirmata_20180309/blockly/javascript.js deleted file mode 100644 index e8f720f051..0000000000 --- a/smart_uart_myfirmata_20180309/blockly/javascript.js +++ /dev/null @@ -1,37 +0,0 @@ -Blockly.JavaScript['uart_car'] = function(block) { - var value_cmd = Blockly.JavaScript.valueToCode(block, 'cmd', Blockly.JavaScript.ORDER_ATOMIC); - var value_str1 = Blockly.JavaScript.valueToCode(block, 'str1', Blockly.JavaScript.ORDER_ATOMIC); - var value_str2 = Blockly.JavaScript.valueToCode(block, 'str2', Blockly.JavaScript.ORDER_ATOMIC); - var value_str3 = Blockly.JavaScript.valueToCode(block, 'str3', Blockly.JavaScript.ORDER_ATOMIC); - var value_str4 = Blockly.JavaScript.valueToCode(block, 'str4', Blockly.JavaScript.ORDER_ATOMIC); - var value_str5 = Blockly.JavaScript.valueToCode(block, 'str5', Blockly.JavaScript.ORDER_ATOMIC); - var value_str6 = Blockly.JavaScript.valueToCode(block, 'str6', Blockly.JavaScript.ORDER_ATOMIC); - var value_str7 = Blockly.JavaScript.valueToCode(block, 'str7', Blockly.JavaScript.ORDER_ATOMIC); - var dropdown_str8 = block.getFieldValue('str8'); - var code = "uartcar("+value_cmd+","+value_str1+","+value_str2+","+value_str3+","+value_str4+","+value_str5+","+value_str6+","+value_str7+",'"+dropdown_str8+"')"; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['uart_system'] = function(block) { - var dropdown_cmd = block.getFieldValue('cmd'); - var value_str1 = Blockly.JavaScript.valueToCode(block, 'str1', Blockly.JavaScript.ORDER_ATOMIC); - var value_str2 = Blockly.JavaScript.valueToCode(block, 'str2', Blockly.JavaScript.ORDER_ATOMIC); - var value_str3 = Blockly.JavaScript.valueToCode(block, 'str3', Blockly.JavaScript.ORDER_ATOMIC); - var code = "uartsystem('"+dropdown_cmd+"',"+value_str1+","+value_str2+","+value_str3+")"; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; - -Blockly.JavaScript['uart_custom'] = function(block) { - var value_cmd = Blockly.JavaScript.valueToCode(block, 'cmd', Blockly.JavaScript.ORDER_ATOMIC); - var value_str1 = Blockly.JavaScript.valueToCode(block, 'str1', Blockly.JavaScript.ORDER_ATOMIC); - var value_str2 = Blockly.JavaScript.valueToCode(block, 'str2', Blockly.JavaScript.ORDER_ATOMIC); - var value_str3 = Blockly.JavaScript.valueToCode(block, 'str3', Blockly.JavaScript.ORDER_ATOMIC); - var value_str4 = Blockly.JavaScript.valueToCode(block, 'str4', Blockly.JavaScript.ORDER_ATOMIC); - var value_str5 = Blockly.JavaScript.valueToCode(block, 'str5', Blockly.JavaScript.ORDER_ATOMIC); - var value_str6 = Blockly.JavaScript.valueToCode(block, 'str6', Blockly.JavaScript.ORDER_ATOMIC); - var value_str7 = Blockly.JavaScript.valueToCode(block, 'str7', Blockly.JavaScript.ORDER_ATOMIC); - var value_str8 = Blockly.JavaScript.valueToCode(block, 'str8', Blockly.JavaScript.ORDER_ATOMIC); - var value_str9 = Blockly.JavaScript.valueToCode(block, 'str9', Blockly.JavaScript.ORDER_ATOMIC); - var code = "uartcustom("+value_cmd+","+value_str1+","+value_str2+","+value_str3+","+value_str4+","+value_str5+","+value_str6+","+value_str7+","+value_str8+","+value_str9+")"; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; diff --git a/smart_uart_myfirmata_20180309/blockly/msg/blocks/en.js b/smart_uart_myfirmata_20180309/blockly/msg/blocks/en.js deleted file mode 100644 index 8b13789179..0000000000 --- a/smart_uart_myfirmata_20180309/blockly/msg/blocks/en.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/smart_uart_myfirmata_20180309/blockly/msg/blocks/zh-hans.js b/smart_uart_myfirmata_20180309/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 8b13789179..0000000000 --- a/smart_uart_myfirmata_20180309/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/smart_uart_myfirmata_20180309/blockly/msg/blocks/zh-hant.js b/smart_uart_myfirmata_20180309/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 8b13789179..0000000000 --- a/smart_uart_myfirmata_20180309/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/smart_uart_myfirmata_20180309/blockly/msg/en.js b/smart_uart_myfirmata_20180309/blockly/msg/en.js deleted file mode 100644 index 697c6ab54b..0000000000 --- a/smart_uart_myfirmata_20180309/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catUARTMYFIRMATA = "UART MYFIRMATA"; diff --git a/smart_uart_myfirmata_20180309/blockly/msg/zh-hans.js b/smart_uart_myfirmata_20180309/blockly/msg/zh-hans.js deleted file mode 100644 index 697c6ab54b..0000000000 --- a/smart_uart_myfirmata_20180309/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catUARTMYFIRMATA = "UART MYFIRMATA"; diff --git a/smart_uart_myfirmata_20180309/blockly/msg/zh-hant.js b/smart_uart_myfirmata_20180309/blockly/msg/zh-hant.js deleted file mode 100644 index 697c6ab54b..0000000000 --- a/smart_uart_myfirmata_20180309/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catUARTMYFIRMATA = "UART MYFIRMATA"; diff --git a/smart_uart_myfirmata_20180309/blockly/toolbox.xml b/smart_uart_myfirmata_20180309/blockly/toolbox.xml deleted file mode 100644 index cfba64bb6b..0000000000 --- a/smart_uart_myfirmata_20180309/blockly/toolbox.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - F - - - car - - - - - 3 - - - - - 5 - - - - - 6 - - - - - 9 - - - - - 200 - - - - - 200 - - - - - 200 - - - - - inputpullup - - - 3 - - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/smart_uart_myfirmata_20180309/uartmyfirmata.js b/smart_uart_myfirmata_20180309/uartmyfirmata.js deleted file mode 100644 index 1f8e83deb9..0000000000 --- a/smart_uart_myfirmata_20180309/uartmyfirmata.js +++ /dev/null @@ -1,26 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function uartcar(cmd,str1,str2,str3,str4,str5,str6,str7,str8) - { - return "?"+cmd+"="+str1+";"+str2+";"+str3+";"+str4+";"+str5+";"+str6+";"+str7+";"+str8; - } - - function uartsystem(cmd,str1,str2,str3) - { - return "?"+cmd+"="+str1+";"+str2+";"+str3; - } - - function uartcustom(cmd,str1,str2,str3,str4,str5,str6,str7,str8,str9) - { - return "?"+cmd+"="+str1+";"+str2+";"+str3+";"+str4+";"+str5+";"+str6+";"+str7+";"+str8+";"+str9; - } - - window.uartcar = uartcar; - window.uartsystem = uartsystem; - window.uartcustom = uartcustom; - -}(window, window.document)); diff --git a/speak_setting_sample_fustyles/blockly.json b/speak_setting_sample_fustyles/blockly.json deleted file mode 100644 index e3e194050e..0000000000 --- a/speak_setting_sample_fustyles/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["speak_setting_sample_fustyles","speak_setting_sample1_fustyles"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "speak_setting_sample.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/speak_setting_sample_fustyles/blockly/blocks.js b/speak_setting_sample_fustyles/blockly/blocks.js deleted file mode 100644 index 8e3d147b81..0000000000 --- a/speak_setting_sample_fustyles/blockly/blocks.js +++ /dev/null @@ -1,206 +0,0 @@ -Blockly.Blocks['speak_setting_sample_fustyles'] = { - init: function () { - this.appendDummyInput() - .appendField(Blockly.Msg.WEBDUINO_SPEAK_LANG) - .appendField(new Blockly.FieldDropdown([ - [Blockly.Msg.WEBDUINO_SPEAK_TW, "cmn-Hant-TW"], - [Blockly.Msg.WEBDUINO_SPEAK_US, "en-US"], - [Blockly.Msg.WEBDUINO_SPEAK_JP, "ja-JP"], - [Blockly.Msg.WEBDUINO_SPEAK_KR, "ko-KR"], - [Blockly.Msg.WEBDUINO_SPEAK_ES, "es-ES"], - [Blockly.Msg.WEBDUINO_SPEAK_FR, "fr-FR"], - [Blockly.Msg.WEBDUINO_SPEAK_IT, "it-IT"], - [Blockly.Msg.WEBDUINO_SPEAK_yue_Hant_HK,"yue-Hant-HK"], - [Blockly.Msg.WEBDUINO_SPEAK_cmn_Hans_HK,"cmn-Hans-HK"], - [Blockly.Msg.WEBDUINO_SPEAK_cmn_Hans_CN,"cmn-Hans-CN"], - [Blockly.Msg.WEBDUINO_SPEAK_vi_VN,"vi-VN"], - [Blockly.Msg.WEBDUINO_SPEAK_af_ZA,"af-ZA"], - [Blockly.Msg.WEBDUINO_SPEAK_am_ET,"am-ET"], - [Blockly.Msg.WEBDUINO_SPEAK_hy_AM,"hy-AM"], - [Blockly.Msg.WEBDUINO_SPEAK_az_AZ,"az-AZ"], - [Blockly.Msg.WEBDUINO_SPEAK_id_ID,"id-ID"], - [Blockly.Msg.WEBDUINO_SPEAK_ms_MY,"ms-MY"], - [Blockly.Msg.WEBDUINO_SPEAK_bn_BD,"bn-BD"], - [Blockly.Msg.WEBDUINO_SPEAK_bn_IN,"bn-IN"], - [Blockly.Msg.WEBDUINO_SPEAK_ca_ES,"ca-ES"], - [Blockly.Msg.WEBDUINO_SPEAK_cs_CZ,"cs-CZ"], - [Blockly.Msg.WEBDUINO_SPEAK_da_DK,"da-DK"], - [Blockly.Msg.WEBDUINO_SPEAK_de_DE,"de-DE"], - [Blockly.Msg.WEBDUINO_SPEAK_en_AU,"en-AU"], - [Blockly.Msg.WEBDUINO_SPEAK_en_CA,"en-CA"], - [Blockly.Msg.WEBDUINO_SPEAK_en_GH,"en-GH"], - [Blockly.Msg.WEBDUINO_SPEAK_en_GB,"en-GB"], - [Blockly.Msg.WEBDUINO_SPEAK_en_IN,"en-IN"], - [Blockly.Msg.WEBDUINO_SPEAK_en_IE,"en-IE"], - [Blockly.Msg.WEBDUINO_SPEAK_en_KE,"en-KE"], - [Blockly.Msg.WEBDUINO_SPEAK_en_NZ,"en-NZ"], - [Blockly.Msg.WEBDUINO_SPEAK_en_NG,"en-NG"], - [Blockly.Msg.WEBDUINO_SPEAK_en_PH,"en-PH"], - [Blockly.Msg.WEBDUINO_SPEAK_en_ZA,"en-ZA"], - [Blockly.Msg.WEBDUINO_SPEAK_en_TZ,"en-TZ"], - [Blockly.Msg.WEBDUINO_SPEAK_es_AR,"es-AR"], - [Blockly.Msg.WEBDUINO_SPEAK_es_BO,"es-BO"], - [Blockly.Msg.WEBDUINO_SPEAK_es_CL,"es-CL"], - [Blockly.Msg.WEBDUINO_SPEAK_es_CO,"es-CO"], - [Blockly.Msg.WEBDUINO_SPEAK_es_CR,"es-CR"], - [Blockly.Msg.WEBDUINO_SPEAK_es_EC,"es-EC"], - [Blockly.Msg.WEBDUINO_SPEAK_es_SV,"es-SV"], - [Blockly.Msg.WEBDUINO_SPEAK_es_US,"es-US"], - [Blockly.Msg.WEBDUINO_SPEAK_es_GT,"es-GT"], - [Blockly.Msg.WEBDUINO_SPEAK_es_HN,"es-HN"], - [Blockly.Msg.WEBDUINO_SPEAK_es_MX,"es-MX"], - [Blockly.Msg.WEBDUINO_SPEAK_es_NI,"es-NI"], - [Blockly.Msg.WEBDUINO_SPEAK_es_PA,"es-PA"], - [Blockly.Msg.WEBDUINO_SPEAK_es_PY,"es-PY"], - [Blockly.Msg.WEBDUINO_SPEAK_es_PE,"es-PE"], - [Blockly.Msg.WEBDUINO_SPEAK_es_PR,"es-PR"], - [Blockly.Msg.WEBDUINO_SPEAK_es_DO,"es-DO"], - [Blockly.Msg.WEBDUINO_SPEAK_es_UY,"es-UY"], - [Blockly.Msg.WEBDUINO_SPEAK_es_VE,"es-VE"], - [Blockly.Msg.WEBDUINO_SPEAK_eu_ES,"eu-ES"], - [Blockly.Msg.WEBDUINO_SPEAK_fil_PH,"fil-PH"], - [Blockly.Msg.WEBDUINO_SPEAK_fr_CA,"fr-CA"], - [Blockly.Msg.WEBDUINO_SPEAK_gl_ES,"gl-ES"], - [Blockly.Msg.WEBDUINO_SPEAK_ka_GE,"ka-GE"], - [Blockly.Msg.WEBDUINO_SPEAK_gu_IN,"gu-IN"], - [Blockly.Msg.WEBDUINO_SPEAK_hr_HR,"hr-HR"], - [Blockly.Msg.WEBDUINO_SPEAK_zu_ZA,"zu-ZA"], - [Blockly.Msg.WEBDUINO_SPEAK_is_IS,"is-IS"], - [Blockly.Msg.WEBDUINO_SPEAK_jv_ID,"jv-ID"], - [Blockly.Msg.WEBDUINO_SPEAK_kn_IN,"kn-IN"], - [Blockly.Msg.WEBDUINO_SPEAK_km_KH,"km-KH"], - [Blockly.Msg.WEBDUINO_SPEAK_lo_LA,"lo-LA"], - [Blockly.Msg.WEBDUINO_SPEAK_lv_LV,"lv-LV"], - [Blockly.Msg.WEBDUINO_SPEAK_lt_LT,"lt-LT"], - [Blockly.Msg.WEBDUINO_SPEAK_hu_HU,"hu-HU"], - [Blockly.Msg.WEBDUINO_SPEAK_ml_IN,"ml-IN"], - [Blockly.Msg.WEBDUINO_SPEAK_mr_IN,"mr-IN"], - [Blockly.Msg.WEBDUINO_SPEAK_nl_NL,"nl-NL"], - [Blockly.Msg.WEBDUINO_SPEAK_ne_NP,"ne-NP"], - [Blockly.Msg.WEBDUINO_SPEAK_nb_NO,"nb-NO"], - [Blockly.Msg.WEBDUINO_SPEAK_pl_PL,"pl-PL"], - [Blockly.Msg.WEBDUINO_SPEAK_pt_BR,"pt-BR"], - [Blockly.Msg.WEBDUINO_SPEAK_pt_PT,"pt-PT"], - [Blockly.Msg.WEBDUINO_SPEAK_ro_RO,"ro-RO"], - [Blockly.Msg.WEBDUINO_SPEAK_si_LK,"si-LK"], - [Blockly.Msg.WEBDUINO_SPEAK_sk_SK,"sk-SK"], - [Blockly.Msg.WEBDUINO_SPEAK_sl_SI,"sl-SI"], - [Blockly.Msg.WEBDUINO_SPEAK_su_ID,"su-ID"], - [Blockly.Msg.WEBDUINO_SPEAK_sw_TZ,"sw-TZ"], - [Blockly.Msg.WEBDUINO_SPEAK_sw_KE,"sw-KE"], - [Blockly.Msg.WEBDUINO_SPEAK_fi_FI,"fi-FI"], - [Blockly.Msg.WEBDUINO_SPEAK_sv_SE,"sv-SE"], - [Blockly.Msg.WEBDUINO_SPEAK_ta_IN,"ta-IN"], - [Blockly.Msg.WEBDUINO_SPEAK_ta_SG,"ta-SG"], - [Blockly.Msg.WEBDUINO_SPEAK_ta_LK,"ta-LK"], - [Blockly.Msg.WEBDUINO_SPEAK_ta_MY,"ta-MY"], - [Blockly.Msg.WEBDUINO_SPEAK_te_IN,"te-IN"], - [Blockly.Msg.WEBDUINO_SPEAK_tr_TR,"tr-TR"], - [Blockly.Msg.WEBDUINO_SPEAK_ur_PK,"ur-PK"], - [Blockly.Msg.WEBDUINO_SPEAK_ur_IN,"ur-IN"], - [Blockly.Msg.WEBDUINO_SPEAK_el_GR,"el-GR"], - [Blockly.Msg.WEBDUINO_SPEAK_bg_BG,"bg-BG"], - [Blockly.Msg.WEBDUINO_SPEAK_ru_RU,"ru-RU"], - [Blockly.Msg.WEBDUINO_SPEAK_sr_RS,"sr-RS"], - [Blockly.Msg.WEBDUINO_SPEAK_uk_UA,"uk-UA"], - [Blockly.Msg.WEBDUINO_SPEAK_he_IL,"he-IL"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_IL,"ar-IL"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_JO,"ar-JO"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_AE,"ar-AE"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_BH,"ar-BH"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_DZ,"ar-DZ"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_SA,"ar-SA"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_IQ,"ar-IQ"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_KW,"ar-KW"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_MA,"ar-MA"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_TN,"ar-TN"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_OM,"ar-OM"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_PS,"ar-PS"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_QA,"ar-QA"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_LB,"ar-LB"], - [Blockly.Msg.WEBDUINO_SPEAK_ar_EG,"ar-EG"], - [Blockly.Msg.WEBDUINO_SPEAK_fa_IR,"fa-IR"], - [Blockly.Msg.WEBDUINO_SPEAK_hi_IN,"hi-IN"], - [Blockly.Msg.WEBDUINO_SPEAK_th_TH,"th-TH"] - ]), "lang_") - .appendField(Blockly.Msg.WEBDUINO_SPEAK_VOLUME) - .appendField(new Blockly.FieldDropdown([ - ["1", "1"], - ["0.9", "0.9"], - ["0.8", "0.8"], - ["0.7", "0.7"], - ["0.6", "0.6"], - ["0.5", "0.5"], - ["0.4", "0.4"], - ["0.3", "0.3"], - ["0.2", "0.3"], - ["0.1", "0.1"], - ["0", "0"] - ]), "volume_") - .appendField(Blockly.Msg.WEBDUINO_SPEAK_PITCH) - .appendField(new Blockly.FieldDropdown([ - [Blockly.Msg.WEBDUINO_SPEAK_P20, "2"], - [Blockly.Msg.WEBDUINO_SPEAK_P15, "1.5"], - [Blockly.Msg.WEBDUINO_SPEAK_P10, "1"], - [Blockly.Msg.WEBDUINO_SPEAK_P05, "0.5"], - [Blockly.Msg.WEBDUINO_SPEAK_P01, "0.1"] - ]), "pitch_") - .appendField(Blockly.Msg.WEBDUINO_SPEAK_RATE) - .appendField(new Blockly.FieldDropdown([ - [Blockly.Msg.WEBDUINO_SPEAK_R20, "2"], - [Blockly.Msg.WEBDUINO_SPEAK_R15, "1.5"], - [Blockly.Msg.WEBDUINO_SPEAK_R10, "1"], - [Blockly.Msg.WEBDUINO_SPEAK_R07, "0.7"], - [Blockly.Msg.WEBDUINO_SPEAK_R05, "0.5"] - ]), "rate_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setTooltip(''); - this.setColour(270); - this.setHelpUrl(mainUrl + 'useful/component/buzzer-clock.html' + utmUrl); - } -}; - -Blockly.Blocks['speak_setting_sample1_fustyles'] = { - init: function () { - this.appendValueInput("value_lang_") - .setCheck("String") - .appendField(Blockly.Msg.WEBDUINO_SPEAK_LANG) - this.appendDummyInput() - .appendField(Blockly.Msg.WEBDUINO_SPEAK_VOLUME) - .appendField(new Blockly.FieldDropdown([ - ["1", "1"], - ["0.9", "0.9"], - ["0.8", "0.8"], - ["0.7", "0.7"], - ["0.6", "0.6"], - ["0.5", "0.5"], - ["0.4", "0.4"], - ["0.3", "0.3"], - ["0.2", "0.3"], - ["0.1", "0.1"], - ["0", "0"] - ]), "volume_") - .appendField(Blockly.Msg.WEBDUINO_SPEAK_PITCH) - .appendField(new Blockly.FieldDropdown([ - [Blockly.Msg.WEBDUINO_SPEAK_P20, "2"], - [Blockly.Msg.WEBDUINO_SPEAK_P15, "1.5"], - [Blockly.Msg.WEBDUINO_SPEAK_P10, "1"], - [Blockly.Msg.WEBDUINO_SPEAK_P05, "0.5"], - [Blockly.Msg.WEBDUINO_SPEAK_P01, "0.1"] - ]), "pitch_") - .appendField(Blockly.Msg.WEBDUINO_SPEAK_RATE) - .appendField(new Blockly.FieldDropdown([ - [Blockly.Msg.WEBDUINO_SPEAK_R20, "2"], - [Blockly.Msg.WEBDUINO_SPEAK_R15, "1.5"], - [Blockly.Msg.WEBDUINO_SPEAK_R10, "1"], - [Blockly.Msg.WEBDUINO_SPEAK_R07, "0.7"], - [Blockly.Msg.WEBDUINO_SPEAK_R05, "0.5"] - ]), "rate_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setTooltip(''); - this.setColour(270); - this.setHelpUrl(mainUrl + 'useful/component/buzzer-clock.html' + utmUrl); - } -}; diff --git a/speak_setting_sample_fustyles/blockly/javascript.js b/speak_setting_sample_fustyles/blockly/javascript.js deleted file mode 100644 index 6088d2a3db..0000000000 --- a/speak_setting_sample_fustyles/blockly/javascript.js +++ /dev/null @@ -1,17 +0,0 @@ -Blockly.JavaScript['speak_setting_sample_fustyles'] = function (block) { - var dropdown_lang_ = block.getFieldValue('lang_'); - var dropdown_volume_ = block.getFieldValue('volume_'); - var dropdown_pitch_ = block.getFieldValue('pitch_'); - var dropdown_rate_ = block.getFieldValue('rate_'); - var code = '"' + dropdown_lang_ + '",' + dropdown_volume_ + ',' + dropdown_pitch_ + ',' + dropdown_rate_; - return [code, Blockly.JavaScript.ORDER_ATOMIC]; -}; - -Blockly.JavaScript['speak_setting_sample1_fustyles'] = function (block) { - var value_lang_ = Blockly.JavaScript.valueToCode(block, 'value_lang_', Blockly.JavaScript.ORDER_ATOMIC); - var dropdown_volume_ = block.getFieldValue('volume_'); - var dropdown_pitch_ = block.getFieldValue('pitch_'); - var dropdown_rate_ = block.getFieldValue('rate_'); - var code = value_lang_ + ',' + dropdown_volume_ + ',' + dropdown_pitch_ + ',' + dropdown_rate_; - return [code, Blockly.JavaScript.ORDER_ATOMIC]; -}; diff --git a/speak_setting_sample_fustyles/blockly/msg/blocks/en.js b/speak_setting_sample_fustyles/blockly/msg/blocks/en.js deleted file mode 100644 index 09214b83a2..0000000000 --- a/speak_setting_sample_fustyles/blockly/msg/blocks/en.js +++ /dev/null @@ -1,160 +0,0 @@ -Blockly.Msg.WEBDUINO_SPEECH_MALE = "male"; -Blockly.Msg.WEBDUINO_SPEECH_FEMALE = "female"; -Blockly.Msg.WEBDUINO_SPEECH = " speech:"; -Blockly.Msg.WEBDUINO_SPEECH_APPID = "AppID:"; -Blockly.Msg.WEBDUINO_SPEECH_SET = "Language:"; -Blockly.Msg.WEBDUINO_SPEECH_SEX = " Gender:"; -Blockly.Msg.WEBDUINO_SPEAK_TEXT = "Speak"; -Blockly.Msg.WEBDUINO_SPEAK_SETTING = "Setting"; -Blockly.Msg.WEBDUINO_SPEAK_WHEN = "When"; -Blockly.Msg.WEBDUINO_SPEAK_END = "ended"; -Blockly.Msg.WEBDUINO_SPEAK_START = "started"; -Blockly.Msg.WEBDUINO_SPEAK_DO = "do"; -Blockly.Msg.WEBDUINO_SPEAK_RESUME = "resume"; -Blockly.Msg.WEBDUINO_SPEAK_PAUSE = "pause"; -Blockly.Msg.WEBDUINO_SPEAK_CANCEL = "cancel"; -Blockly.Msg.WEBDUINO_SPEAK_READ = "speak"; -Blockly.Msg.WEBDUINO_SPEAK_LANG = "language"; -Blockly.Msg.WEBDUINO_SPEAK_TW = "zh-TW"; -Blockly.Msg.WEBDUINO_SPEAK_US = "en-US"; -Blockly.Msg.WEBDUINO_SPEAK_JP = "ja-JP"; -Blockly.Msg.WEBDUINO_SPEAK_YUEHANT = "yue-Hant-HK"; -Blockly.Msg.WEBDUINO_SPEAK_KR = "ko-KR"; -Blockly.Msg.WEBDUINO_SPEAK_TH = "th-TH"; -Blockly.Msg.WEBDUINO_SPEAK_VI = "vi-VN"; -Blockly.Msg.WEBDUINO_SPEAK_FR = "fr-FR"; -Blockly.Msg.WEBDUINO_SPEAK_ES = "es-ES"; -Blockly.Msg.WEBDUINO_SPEAK_IT = "it-IT"; -Blockly.Msg.WEBDUINO_SPEAK_VOLUME = " volume"; -Blockly.Msg.WEBDUINO_SPEAK_PITCH = " pitch"; -Blockly.Msg.WEBDUINO_SPEAK_P20 = "2"; -Blockly.Msg.WEBDUINO_SPEAK_P15 = "1.5"; -Blockly.Msg.WEBDUINO_SPEAK_P10 = "1"; -Blockly.Msg.WEBDUINO_SPEAK_P05 = "0.5"; -Blockly.Msg.WEBDUINO_SPEAK_P01 = "0.1"; -Blockly.Msg.WEBDUINO_SPEAK_RATE = " rate"; -Blockly.Msg.WEBDUINO_SPEAK_R20 = "2"; -Blockly.Msg.WEBDUINO_SPEAK_R15 = "1.5"; -Blockly.Msg.WEBDUINO_SPEAK_R10 = "1"; -Blockly.Msg.WEBDUINO_SPEAK_R07 = "0.7"; -Blockly.Msg.WEBDUINO_SPEAK_R05 = "0.5"; -Blockly.Msg.WEBDUINO_SPEAK_af_ZA = "Afrikaans (South Africa)"; -Blockly.Msg.WEBDUINO_SPEAK_am_ET = "Amharic (Ethiopia)"; -Blockly.Msg.WEBDUINO_SPEAK_hy_AM = "Armenian (Armenia)"; -Blockly.Msg.WEBDUINO_SPEAK_az_AZ = "Azerbaijani (Azerbaijan)"; -Blockly.Msg.WEBDUINO_SPEAK_id_ID = "Indonesian (Indonesia)"; -Blockly.Msg.WEBDUINO_SPEAK_ms_MY = "Malay (Malaysia)"; -Blockly.Msg.WEBDUINO_SPEAK_bn_BD = "Bengali (Bangladesh)"; -Blockly.Msg.WEBDUINO_SPEAK_bn_IN = "Bengali (India)"; -Blockly.Msg.WEBDUINO_SPEAK_ca_ES = "Catalan (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_cs_CZ = "Czech (Czech Republic)"; -Blockly.Msg.WEBDUINO_SPEAK_da_DK = "Danish (Denmark)"; -Blockly.Msg.WEBDUINO_SPEAK_de_DE = "German (Germany)"; -Blockly.Msg.WEBDUINO_SPEAK_en_AU = "English (Australia)"; -Blockly.Msg.WEBDUINO_SPEAK_en_CA = "English (Canada)"; -Blockly.Msg.WEBDUINO_SPEAK_en_GH = "English (Ghana)"; -Blockly.Msg.WEBDUINO_SPEAK_en_GB = "English (United Kingdom)"; -Blockly.Msg.WEBDUINO_SPEAK_en_IN = "English (India)"; -Blockly.Msg.WEBDUINO_SPEAK_en_IE = "English (Ireland)"; -Blockly.Msg.WEBDUINO_SPEAK_en_KE = "English (Kenya)"; -Blockly.Msg.WEBDUINO_SPEAK_en_NZ = "English (New Zealand)"; -Blockly.Msg.WEBDUINO_SPEAK_en_NG = "English (Nigeria)"; -Blockly.Msg.WEBDUINO_SPEAK_en_PH = "English (Philippines)"; -Blockly.Msg.WEBDUINO_SPEAK_en_ZA = "English (South Africa)"; -Blockly.Msg.WEBDUINO_SPEAK_en_TZ = "English (Tanzania)"; -Blockly.Msg.WEBDUINO_SPEAK_en_US = "English (United States)"; -Blockly.Msg.WEBDUINO_SPEAK_es_AR = "Spanish (Argentina)"; -Blockly.Msg.WEBDUINO_SPEAK_es_BO = "Spanish (Bolivia)"; -Blockly.Msg.WEBDUINO_SPEAK_es_CL = "Spanish (Chile)"; -Blockly.Msg.WEBDUINO_SPEAK_es_CO = "Spanish (Colombia)"; -Blockly.Msg.WEBDUINO_SPEAK_es_CR = "Spanish (Costa Rica)"; -Blockly.Msg.WEBDUINO_SPEAK_es_EC = "Spanish (Ecuador)"; -Blockly.Msg.WEBDUINO_SPEAK_es_SV = "Spanish (El Salvador)"; -Blockly.Msg.WEBDUINO_SPEAK_es_ES = "Spanish (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_es_US = "Spanish (United States)"; -Blockly.Msg.WEBDUINO_SPEAK_es_GT = "Spanish (Guatemala)"; -Blockly.Msg.WEBDUINO_SPEAK_es_HN = "Spanish (Honduras)"; -Blockly.Msg.WEBDUINO_SPEAK_es_MX = "Spanish (Mexico)"; -Blockly.Msg.WEBDUINO_SPEAK_es_NI = "Spanish (Nicaragua)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PA = "Spanish (Panama)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PY = "Spanish (Paraguay)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PE = "Spanish (Peru)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PR = "Spanish (Puerto Rico)"; -Blockly.Msg.WEBDUINO_SPEAK_es_DO = "Spanish (Dominican Republic)"; -Blockly.Msg.WEBDUINO_SPEAK_es_UY = "Spanish (Uruguay)"; -Blockly.Msg.WEBDUINO_SPEAK_es_VE = "Spanish (Venezuela)"; -Blockly.Msg.WEBDUINO_SPEAK_eu_ES = "Basque (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_fil_PH = "Filipino (Philippines)"; -Blockly.Msg.WEBDUINO_SPEAK_fr_CA = "French (Canada)"; -Blockly.Msg.WEBDUINO_SPEAK_fr_FR = "French (France)"; -Blockly.Msg.WEBDUINO_SPEAK_gl_ES = "Galician (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_ka_GE = "Georgian (Georgia)"; -Blockly.Msg.WEBDUINO_SPEAK_gu_IN = "Gujarati (India)"; -Blockly.Msg.WEBDUINO_SPEAK_hr_HR = "Croatian (Croatia)"; -Blockly.Msg.WEBDUINO_SPEAK_zu_ZA = "Zulu (South Africa)"; -Blockly.Msg.WEBDUINO_SPEAK_is_IS = "Icelandic (Iceland)"; -Blockly.Msg.WEBDUINO_SPEAK_it_IT = "Italian (Italy)"; -Blockly.Msg.WEBDUINO_SPEAK_jv_ID = "Javanese (Indonesia)"; -Blockly.Msg.WEBDUINO_SPEAK_kn_IN = "Kannada (India)"; -Blockly.Msg.WEBDUINO_SPEAK_km_KH = "Khmer (Cambodia)"; -Blockly.Msg.WEBDUINO_SPEAK_lo_LA = "Lao (Laos)"; -Blockly.Msg.WEBDUINO_SPEAK_lv_LV = "Latvian (Latvia)"; -Blockly.Msg.WEBDUINO_SPEAK_lt_LT = "Lithuanian (Lithuania)"; -Blockly.Msg.WEBDUINO_SPEAK_hu_HU = "Hungarian (Hungary)"; -Blockly.Msg.WEBDUINO_SPEAK_ml_IN = "Malayalam (India)"; -Blockly.Msg.WEBDUINO_SPEAK_mr_IN = "Marathi (India)"; -Blockly.Msg.WEBDUINO_SPEAK_nl_NL = "Dutch (Netherlands)"; -Blockly.Msg.WEBDUINO_SPEAK_ne_NP = "Nepali (Nepal)"; -Blockly.Msg.WEBDUINO_SPEAK_nb_NO = "Norwegian Bokmål (Norway)"; -Blockly.Msg.WEBDUINO_SPEAK_pl_PL = "Polish (Poland)"; -Blockly.Msg.WEBDUINO_SPEAK_pt_BR = "Portuguese (Brazil)"; -Blockly.Msg.WEBDUINO_SPEAK_pt_PT = "Portuguese (Portugal)"; -Blockly.Msg.WEBDUINO_SPEAK_ro_RO = "Romanian (Romania)"; -Blockly.Msg.WEBDUINO_SPEAK_si_LK = "Sinhala (Sri Lanka)"; -Blockly.Msg.WEBDUINO_SPEAK_sk_SK = "Slovak (Slovakia)"; -Blockly.Msg.WEBDUINO_SPEAK_sl_SI = "Slovenian (Slovenia)"; -Blockly.Msg.WEBDUINO_SPEAK_su_ID = "Sundanese (Indonesia)"; -Blockly.Msg.WEBDUINO_SPEAK_sw_TZ = "Swahili (Tanzania)"; -Blockly.Msg.WEBDUINO_SPEAK_sw_KE = "Swahili (Kenya)"; -Blockly.Msg.WEBDUINO_SPEAK_fi_FI = "Finnish (Finland)"; -Blockly.Msg.WEBDUINO_SPEAK_sv_SE = "Swedish (Sweden)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_IN = "Tamil (India)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_SG = "Tamil (Singapore)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_LK = "Tamil (Sri Lanka)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_MY = "Tamil (Malaysia)"; -Blockly.Msg.WEBDUINO_SPEAK_te_IN = "Telugu (India)"; -Blockly.Msg.WEBDUINO_SPEAK_vi_VN = "Vietnamese (Vietnam)"; -Blockly.Msg.WEBDUINO_SPEAK_tr_TR = "Turkish (Turkey)"; -Blockly.Msg.WEBDUINO_SPEAK_ur_PK = "Urdu (Pakistan)"; -Blockly.Msg.WEBDUINO_SPEAK_ur_IN = "Urdu (India)"; -Blockly.Msg.WEBDUINO_SPEAK_el_GR = "Greek (Greece)"; -Blockly.Msg.WEBDUINO_SPEAK_bg_BG = "Bulgarian (Bulgaria)"; -Blockly.Msg.WEBDUINO_SPEAK_ru_RU = "Russian (Russia)"; -Blockly.Msg.WEBDUINO_SPEAK_sr_RS = "Serbian (Serbia)"; -Blockly.Msg.WEBDUINO_SPEAK_uk_UA = "Ukrainian (Ukraine)"; -Blockly.Msg.WEBDUINO_SPEAK_he_IL = "Hebrew (Israel)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_IL = "Arabic (Israel)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_JO = "Arabic (Jordan)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_AE = "Arabic (United Arab Emirates)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_BH = "Arabic (Bahrain)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_DZ = "Arabic (Algeria)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_SA = "Arabic (Saudi Arabia)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_IQ = "Arabic (Iraq)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_KW = "Arabic (Kuwait)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_MA = "Arabic (Morocco)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_TN = "Arabic (Tunisia)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_OM = "Arabic (Oman)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_PS = "Arabic (State of Palestine)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_QA = "Arabic (Qatar)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_LB = "Arabic (Lebanon)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_EG = "Arabic (Egypt)"; -Blockly.Msg.WEBDUINO_SPEAK_fa_IR = "Persian (Iran)"; -Blockly.Msg.WEBDUINO_SPEAK_hi_IN = "Hindi (India)"; -Blockly.Msg.WEBDUINO_SPEAK_th_TH = "Thai (Thailand)"; -Blockly.Msg.WEBDUINO_SPEAK_ko_KR = "Korean (South Korea)"; -Blockly.Msg.WEBDUINO_SPEAK_cmn_Hant_TW = "Chinese, Mandarin (Traditional, Taiwan)"; -Blockly.Msg.WEBDUINO_SPEAK_yue_Hant_HK = "Chinese, Cantonese (Traditional, Hong Kong)"; -Blockly.Msg.WEBDUINO_SPEAK_ja_JP = "Japanese (Japan)"; -Blockly.Msg.WEBDUINO_SPEAK_cmn_Hans_HK = "Chinese, Mandarin (Simplified, Hong Kong)"; -Blockly.Msg.WEBDUINO_SPEAK_cmn_Hans_CN = "Chinese, Mandarin (Simplified, China)"; - diff --git a/speak_setting_sample_fustyles/blockly/msg/blocks/zh-hans.js b/speak_setting_sample_fustyles/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 53031f6481..0000000000 --- a/speak_setting_sample_fustyles/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,159 +0,0 @@ -Blockly.Msg.WEBDUINO_SPEECH_MALE = "男声"; -Blockly.Msg.WEBDUINO_SPEECH_FEMALE = "女声"; -Blockly.Msg.WEBDUINO_SPEECH = " 发音"; -Blockly.Msg.WEBDUINO_SPEECH_APPID = "语音 appID:"; -Blockly.Msg.WEBDUINO_SPEECH_SET = "语音"; -Blockly.Msg.WEBDUINO_SPEECH_SEX = " 性别"; -Blockly.Msg.WEBDUINO_SPEAK_TEXT = "朗读文字"; -Blockly.Msg.WEBDUINO_SPEAK_SETTING = "参数设定"; -Blockly.Msg.WEBDUINO_SPEAK_WHEN = "当朗读"; -Blockly.Msg.WEBDUINO_SPEAK_END = "结束"; -Blockly.Msg.WEBDUINO_SPEAK_START = "开始"; -Blockly.Msg.WEBDUINO_SPEAK_DO = "执行"; -Blockly.Msg.WEBDUINO_SPEAK_RESUME = "继续"; -Blockly.Msg.WEBDUINO_SPEAK_PAUSE = "暂停"; -Blockly.Msg.WEBDUINO_SPEAK_CANCEL = "停止"; -Blockly.Msg.WEBDUINO_SPEAK_READ = "朗读"; -Blockly.Msg.WEBDUINO_SPEAK_LANG = "朗读语言"; -Blockly.Msg.WEBDUINO_SPEAK_TW = "中文"; -Blockly.Msg.WEBDUINO_SPEAK_US = "英文"; -Blockly.Msg.WEBDUINO_SPEAK_JP = "日文"; -Blockly.Msg.WEBDUINO_SPEAK_YUEHANT = "广东话"; -Blockly.Msg.WEBDUINO_SPEAK_KR = "韩文"; -Blockly.Msg.WEBDUINO_SPEAK_TH ="泰文"; -Blockly.Msg.WEBDUINO_SPEAK_VI ="越南文"; -Blockly.Msg.WEBDUINO_SPEAK_FR = "法文"; -Blockly.Msg.WEBDUINO_SPEAK_ES = "德文"; -Blockly.Msg.WEBDUINO_SPEAK_IT = "义大利文"; -Blockly.Msg.WEBDUINO_SPEAK_VOLUME = " 音量"; -Blockly.Msg.WEBDUINO_SPEAK_PITCH = " 音调"; -Blockly.Msg.WEBDUINO_SPEAK_P20 = "尖锐"; -Blockly.Msg.WEBDUINO_SPEAK_P15 = "高昂"; -Blockly.Msg.WEBDUINO_SPEAK_P10 = "正常"; -Blockly.Msg.WEBDUINO_SPEAK_P05 = "低沉"; -Blockly.Msg.WEBDUINO_SPEAK_P01 = "沙哑"; -Blockly.Msg.WEBDUINO_SPEAK_RATE = " 速度"; -Blockly.Msg.WEBDUINO_SPEAK_R20 = "很快"; -Blockly.Msg.WEBDUINO_SPEAK_R15 = "快"; -Blockly.Msg.WEBDUINO_SPEAK_R10 = "正常"; -Blockly.Msg.WEBDUINO_SPEAK_R07 = "慢"; -Blockly.Msg.WEBDUINO_SPEAK_R05 = "很慢"; -Blockly.Msg.WEBDUINO_SPEAK_af_ZA = "Afrikaans (South Africa)"; -Blockly.Msg.WEBDUINO_SPEAK_am_ET = "Amharic (Ethiopia)"; -Blockly.Msg.WEBDUINO_SPEAK_hy_AM = "Armenian (Armenia)"; -Blockly.Msg.WEBDUINO_SPEAK_az_AZ = "Azerbaijani (Azerbaijan)"; -Blockly.Msg.WEBDUINO_SPEAK_id_ID = "Indonesian (Indonesia)"; -Blockly.Msg.WEBDUINO_SPEAK_ms_MY = "Malay (Malaysia)"; -Blockly.Msg.WEBDUINO_SPEAK_bn_BD = "Bengali (Bangladesh)"; -Blockly.Msg.WEBDUINO_SPEAK_bn_IN = "Bengali (India)"; -Blockly.Msg.WEBDUINO_SPEAK_ca_ES = "Catalan (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_cs_CZ = "Czech (Czech Republic)"; -Blockly.Msg.WEBDUINO_SPEAK_da_DK = "Danish (Denmark)"; -Blockly.Msg.WEBDUINO_SPEAK_de_DE = "German (Germany)"; -Blockly.Msg.WEBDUINO_SPEAK_en_AU = "English (Australia)"; -Blockly.Msg.WEBDUINO_SPEAK_en_CA = "English (Canada)"; -Blockly.Msg.WEBDUINO_SPEAK_en_GH = "English (Ghana)"; -Blockly.Msg.WEBDUINO_SPEAK_en_GB = "English (United Kingdom)"; -Blockly.Msg.WEBDUINO_SPEAK_en_IN = "English (India)"; -Blockly.Msg.WEBDUINO_SPEAK_en_IE = "English (Ireland)"; -Blockly.Msg.WEBDUINO_SPEAK_en_KE = "English (Kenya)"; -Blockly.Msg.WEBDUINO_SPEAK_en_NZ = "English (New Zealand)"; -Blockly.Msg.WEBDUINO_SPEAK_en_NG = "English (Nigeria)"; -Blockly.Msg.WEBDUINO_SPEAK_en_PH = "English (Philippines)"; -Blockly.Msg.WEBDUINO_SPEAK_en_ZA = "English (South Africa)"; -Blockly.Msg.WEBDUINO_SPEAK_en_TZ = "English (Tanzania)"; -Blockly.Msg.WEBDUINO_SPEAK_en_US = "English (United States)"; -Blockly.Msg.WEBDUINO_SPEAK_es_AR = "Spanish (Argentina)"; -Blockly.Msg.WEBDUINO_SPEAK_es_BO = "Spanish (Bolivia)"; -Blockly.Msg.WEBDUINO_SPEAK_es_CL = "Spanish (Chile)"; -Blockly.Msg.WEBDUINO_SPEAK_es_CO = "Spanish (Colombia)"; -Blockly.Msg.WEBDUINO_SPEAK_es_CR = "Spanish (Costa Rica)"; -Blockly.Msg.WEBDUINO_SPEAK_es_EC = "Spanish (Ecuador)"; -Blockly.Msg.WEBDUINO_SPEAK_es_SV = "Spanish (El Salvador)"; -Blockly.Msg.WEBDUINO_SPEAK_es_ES = "Spanish (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_es_US = "Spanish (United States)"; -Blockly.Msg.WEBDUINO_SPEAK_es_GT = "Spanish (Guatemala)"; -Blockly.Msg.WEBDUINO_SPEAK_es_HN = "Spanish (Honduras)"; -Blockly.Msg.WEBDUINO_SPEAK_es_MX = "Spanish (Mexico)"; -Blockly.Msg.WEBDUINO_SPEAK_es_NI = "Spanish (Nicaragua)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PA = "Spanish (Panama)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PY = "Spanish (Paraguay)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PE = "Spanish (Peru)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PR = "Spanish (Puerto Rico)"; -Blockly.Msg.WEBDUINO_SPEAK_es_DO = "Spanish (Dominican Republic)"; -Blockly.Msg.WEBDUINO_SPEAK_es_UY = "Spanish (Uruguay)"; -Blockly.Msg.WEBDUINO_SPEAK_es_VE = "Spanish (Venezuela)"; -Blockly.Msg.WEBDUINO_SPEAK_eu_ES = "Basque (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_fil_PH = "Filipino (Philippines)"; -Blockly.Msg.WEBDUINO_SPEAK_fr_CA = "French (Canada)"; -Blockly.Msg.WEBDUINO_SPEAK_fr_FR = "French (France)"; -Blockly.Msg.WEBDUINO_SPEAK_gl_ES = "Galician (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_ka_GE = "Georgian (Georgia)"; -Blockly.Msg.WEBDUINO_SPEAK_gu_IN = "Gujarati (India)"; -Blockly.Msg.WEBDUINO_SPEAK_hr_HR = "Croatian (Croatia)"; -Blockly.Msg.WEBDUINO_SPEAK_zu_ZA = "Zulu (South Africa)"; -Blockly.Msg.WEBDUINO_SPEAK_is_IS = "Icelandic (Iceland)"; -Blockly.Msg.WEBDUINO_SPEAK_it_IT = "Italian (Italy)"; -Blockly.Msg.WEBDUINO_SPEAK_jv_ID = "Javanese (Indonesia)"; -Blockly.Msg.WEBDUINO_SPEAK_kn_IN = "Kannada (India)"; -Blockly.Msg.WEBDUINO_SPEAK_km_KH = "Khmer (Cambodia)"; -Blockly.Msg.WEBDUINO_SPEAK_lo_LA = "Lao (Laos)"; -Blockly.Msg.WEBDUINO_SPEAK_lv_LV = "Latvian (Latvia)"; -Blockly.Msg.WEBDUINO_SPEAK_lt_LT = "Lithuanian (Lithuania)"; -Blockly.Msg.WEBDUINO_SPEAK_hu_HU = "Hungarian (Hungary)"; -Blockly.Msg.WEBDUINO_SPEAK_ml_IN = "Malayalam (India)"; -Blockly.Msg.WEBDUINO_SPEAK_mr_IN = "Marathi (India)"; -Blockly.Msg.WEBDUINO_SPEAK_nl_NL = "Dutch (Netherlands)"; -Blockly.Msg.WEBDUINO_SPEAK_ne_NP = "Nepali (Nepal)"; -Blockly.Msg.WEBDUINO_SPEAK_nb_NO = "Norwegian Bokmål (Norway)"; -Blockly.Msg.WEBDUINO_SPEAK_pl_PL = "Polish (Poland)"; -Blockly.Msg.WEBDUINO_SPEAK_pt_BR = "Portuguese (Brazil)"; -Blockly.Msg.WEBDUINO_SPEAK_pt_PT = "Portuguese (Portugal)"; -Blockly.Msg.WEBDUINO_SPEAK_ro_RO = "Romanian (Romania)"; -Blockly.Msg.WEBDUINO_SPEAK_si_LK = "Sinhala (Sri Lanka)"; -Blockly.Msg.WEBDUINO_SPEAK_sk_SK = "Slovak (Slovakia)"; -Blockly.Msg.WEBDUINO_SPEAK_sl_SI = "Slovenian (Slovenia)"; -Blockly.Msg.WEBDUINO_SPEAK_su_ID = "Sundanese (Indonesia)"; -Blockly.Msg.WEBDUINO_SPEAK_sw_TZ = "Swahili (Tanzania)"; -Blockly.Msg.WEBDUINO_SPEAK_sw_KE = "Swahili (Kenya)"; -Blockly.Msg.WEBDUINO_SPEAK_fi_FI = "Finnish (Finland)"; -Blockly.Msg.WEBDUINO_SPEAK_sv_SE = "Swedish (Sweden)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_IN = "Tamil (India)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_SG = "Tamil (Singapore)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_LK = "Tamil (Sri Lanka)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_MY = "Tamil (Malaysia)"; -Blockly.Msg.WEBDUINO_SPEAK_te_IN = "Telugu (India)"; -Blockly.Msg.WEBDUINO_SPEAK_vi_VN = "Vietnamese (Vietnam)"; -Blockly.Msg.WEBDUINO_SPEAK_tr_TR = "Turkish (Turkey)"; -Blockly.Msg.WEBDUINO_SPEAK_ur_PK = "Urdu (Pakistan)"; -Blockly.Msg.WEBDUINO_SPEAK_ur_IN = "Urdu (India)"; -Blockly.Msg.WEBDUINO_SPEAK_el_GR = "Greek (Greece)"; -Blockly.Msg.WEBDUINO_SPEAK_bg_BG = "Bulgarian (Bulgaria)"; -Blockly.Msg.WEBDUINO_SPEAK_ru_RU = "Russian (Russia)"; -Blockly.Msg.WEBDUINO_SPEAK_sr_RS = "Serbian (Serbia)"; -Blockly.Msg.WEBDUINO_SPEAK_uk_UA = "Ukrainian (Ukraine)"; -Blockly.Msg.WEBDUINO_SPEAK_he_IL = "Hebrew (Israel)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_IL = "Arabic (Israel)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_JO = "Arabic (Jordan)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_AE = "Arabic (United Arab Emirates)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_BH = "Arabic (Bahrain)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_DZ = "Arabic (Algeria)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_SA = "Arabic (Saudi Arabia)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_IQ = "Arabic (Iraq)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_KW = "Arabic (Kuwait)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_MA = "Arabic (Morocco)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_TN = "Arabic (Tunisia)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_OM = "Arabic (Oman)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_PS = "Arabic (State of Palestine)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_QA = "Arabic (Qatar)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_LB = "Arabic (Lebanon)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_EG = "Arabic (Egypt)"; -Blockly.Msg.WEBDUINO_SPEAK_fa_IR = "Persian (Iran)"; -Blockly.Msg.WEBDUINO_SPEAK_hi_IN = "Hindi (India)"; -Blockly.Msg.WEBDUINO_SPEAK_th_TH = "Thai (Thailand)"; -Blockly.Msg.WEBDUINO_SPEAK_ko_KR = "Korean (South Korea)"; -Blockly.Msg.WEBDUINO_SPEAK_cmn_Hant_TW = "Chinese, Mandarin (Traditional, Taiwan)"; -Blockly.Msg.WEBDUINO_SPEAK_yue_Hant_HK = "Chinese, Cantonese (Traditional, Hong Kong)"; -Blockly.Msg.WEBDUINO_SPEAK_ja_JP = "Japanese (Japan)"; -Blockly.Msg.WEBDUINO_SPEAK_cmn_Hans_HK = "Chinese, Mandarin (Simplified, Hong Kong)"; -Blockly.Msg.WEBDUINO_SPEAK_cmn_Hans_CN = "Chinese, Mandarin (Simplified, China)"; diff --git a/speak_setting_sample_fustyles/blockly/msg/blocks/zh-hant.js b/speak_setting_sample_fustyles/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 011e206f15..0000000000 --- a/speak_setting_sample_fustyles/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,159 +0,0 @@ -Blockly.Msg.WEBDUINO_SPEECH_MALE = "男聲"; -Blockly.Msg.WEBDUINO_SPEECH_FEMALE = "女聲"; -Blockly.Msg.WEBDUINO_SPEECH = " 發音"; -Blockly.Msg.WEBDUINO_SPEECH_APPID = "語音 appID:"; -Blockly.Msg.WEBDUINO_SPEECH_SET = "語音"; -Blockly.Msg.WEBDUINO_SPEECH_SEX = " 性別"; -Blockly.Msg.WEBDUINO_SPEAK_TEXT = "朗讀文字"; -Blockly.Msg.WEBDUINO_SPEAK_SETTING = "參數設定"; -Blockly.Msg.WEBDUINO_SPEAK_WHEN = "當朗讀"; -Blockly.Msg.WEBDUINO_SPEAK_END = "結束"; -Blockly.Msg.WEBDUINO_SPEAK_START = "開始"; -Blockly.Msg.WEBDUINO_SPEAK_DO = "執行"; -Blockly.Msg.WEBDUINO_SPEAK_RESUME = "繼續"; -Blockly.Msg.WEBDUINO_SPEAK_PAUSE = "暫停"; -Blockly.Msg.WEBDUINO_SPEAK_CANCEL = "停止"; -Blockly.Msg.WEBDUINO_SPEAK_READ = "朗讀"; -Blockly.Msg.WEBDUINO_SPEAK_LANG = "朗讀語言"; -Blockly.Msg.WEBDUINO_SPEAK_TW = "中文"; -Blockly.Msg.WEBDUINO_SPEAK_US = "英文"; -Blockly.Msg.WEBDUINO_SPEAK_JP = "日文"; -Blockly.Msg.WEBDUINO_SPEAK_YUEHANT = "廣東話"; -Blockly.Msg.WEBDUINO_SPEAK_KR = "韓文"; -Blockly.Msg.WEBDUINO_SPEAK_TH = "泰文"; -Blockly.Msg.WEBDUINO_SPEAK_VI = "越南文"; -Blockly.Msg.WEBDUINO_SPEAK_FR = "法文"; -Blockly.Msg.WEBDUINO_SPEAK_ES = "德文"; -Blockly.Msg.WEBDUINO_SPEAK_IT = "義大利文"; -Blockly.Msg.WEBDUINO_SPEAK_VOLUME = " 音量"; -Blockly.Msg.WEBDUINO_SPEAK_PITCH = " 音調"; -Blockly.Msg.WEBDUINO_SPEAK_P20 = "尖銳"; -Blockly.Msg.WEBDUINO_SPEAK_P15 = "高昂"; -Blockly.Msg.WEBDUINO_SPEAK_P10 = "正常"; -Blockly.Msg.WEBDUINO_SPEAK_P05 = "低沈"; -Blockly.Msg.WEBDUINO_SPEAK_P01 = "沙啞"; -Blockly.Msg.WEBDUINO_SPEAK_RATE = " 速度"; -Blockly.Msg.WEBDUINO_SPEAK_R20 = "很快"; -Blockly.Msg.WEBDUINO_SPEAK_R15 = "快"; -Blockly.Msg.WEBDUINO_SPEAK_R10 = "正常"; -Blockly.Msg.WEBDUINO_SPEAK_R07 = "慢"; -Blockly.Msg.WEBDUINO_SPEAK_R05 = "很慢"; -Blockly.Msg.WEBDUINO_SPEAK_af_ZA = "Afrikaans (South Africa)"; -Blockly.Msg.WEBDUINO_SPEAK_am_ET = "Amharic (Ethiopia)"; -Blockly.Msg.WEBDUINO_SPEAK_hy_AM = "Armenian (Armenia)"; -Blockly.Msg.WEBDUINO_SPEAK_az_AZ = "Azerbaijani (Azerbaijan)"; -Blockly.Msg.WEBDUINO_SPEAK_id_ID = "Indonesian (Indonesia)"; -Blockly.Msg.WEBDUINO_SPEAK_ms_MY = "Malay (Malaysia)"; -Blockly.Msg.WEBDUINO_SPEAK_bn_BD = "Bengali (Bangladesh)"; -Blockly.Msg.WEBDUINO_SPEAK_bn_IN = "Bengali (India)"; -Blockly.Msg.WEBDUINO_SPEAK_ca_ES = "Catalan (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_cs_CZ = "Czech (Czech Republic)"; -Blockly.Msg.WEBDUINO_SPEAK_da_DK = "Danish (Denmark)"; -Blockly.Msg.WEBDUINO_SPEAK_de_DE = "German (Germany)"; -Blockly.Msg.WEBDUINO_SPEAK_en_AU = "English (Australia)"; -Blockly.Msg.WEBDUINO_SPEAK_en_CA = "English (Canada)"; -Blockly.Msg.WEBDUINO_SPEAK_en_GH = "English (Ghana)"; -Blockly.Msg.WEBDUINO_SPEAK_en_GB = "English (United Kingdom)"; -Blockly.Msg.WEBDUINO_SPEAK_en_IN = "English (India)"; -Blockly.Msg.WEBDUINO_SPEAK_en_IE = "English (Ireland)"; -Blockly.Msg.WEBDUINO_SPEAK_en_KE = "English (Kenya)"; -Blockly.Msg.WEBDUINO_SPEAK_en_NZ = "English (New Zealand)"; -Blockly.Msg.WEBDUINO_SPEAK_en_NG = "English (Nigeria)"; -Blockly.Msg.WEBDUINO_SPEAK_en_PH = "English (Philippines)"; -Blockly.Msg.WEBDUINO_SPEAK_en_ZA = "English (South Africa)"; -Blockly.Msg.WEBDUINO_SPEAK_en_TZ = "English (Tanzania)"; -Blockly.Msg.WEBDUINO_SPEAK_en_US = "English (United States)"; -Blockly.Msg.WEBDUINO_SPEAK_es_AR = "Spanish (Argentina)"; -Blockly.Msg.WEBDUINO_SPEAK_es_BO = "Spanish (Bolivia)"; -Blockly.Msg.WEBDUINO_SPEAK_es_CL = "Spanish (Chile)"; -Blockly.Msg.WEBDUINO_SPEAK_es_CO = "Spanish (Colombia)"; -Blockly.Msg.WEBDUINO_SPEAK_es_CR = "Spanish (Costa Rica)"; -Blockly.Msg.WEBDUINO_SPEAK_es_EC = "Spanish (Ecuador)"; -Blockly.Msg.WEBDUINO_SPEAK_es_SV = "Spanish (El Salvador)"; -Blockly.Msg.WEBDUINO_SPEAK_es_ES = "Spanish (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_es_US = "Spanish (United States)"; -Blockly.Msg.WEBDUINO_SPEAK_es_GT = "Spanish (Guatemala)"; -Blockly.Msg.WEBDUINO_SPEAK_es_HN = "Spanish (Honduras)"; -Blockly.Msg.WEBDUINO_SPEAK_es_MX = "Spanish (Mexico)"; -Blockly.Msg.WEBDUINO_SPEAK_es_NI = "Spanish (Nicaragua)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PA = "Spanish (Panama)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PY = "Spanish (Paraguay)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PE = "Spanish (Peru)"; -Blockly.Msg.WEBDUINO_SPEAK_es_PR = "Spanish (Puerto Rico)"; -Blockly.Msg.WEBDUINO_SPEAK_es_DO = "Spanish (Dominican Republic)"; -Blockly.Msg.WEBDUINO_SPEAK_es_UY = "Spanish (Uruguay)"; -Blockly.Msg.WEBDUINO_SPEAK_es_VE = "Spanish (Venezuela)"; -Blockly.Msg.WEBDUINO_SPEAK_eu_ES = "Basque (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_fil_PH = "Filipino (Philippines)"; -Blockly.Msg.WEBDUINO_SPEAK_fr_CA = "French (Canada)"; -Blockly.Msg.WEBDUINO_SPEAK_fr_FR = "French (France)"; -Blockly.Msg.WEBDUINO_SPEAK_gl_ES = "Galician (Spain)"; -Blockly.Msg.WEBDUINO_SPEAK_ka_GE = "Georgian (Georgia)"; -Blockly.Msg.WEBDUINO_SPEAK_gu_IN = "Gujarati (India)"; -Blockly.Msg.WEBDUINO_SPEAK_hr_HR = "Croatian (Croatia)"; -Blockly.Msg.WEBDUINO_SPEAK_zu_ZA = "Zulu (South Africa)"; -Blockly.Msg.WEBDUINO_SPEAK_is_IS = "Icelandic (Iceland)"; -Blockly.Msg.WEBDUINO_SPEAK_it_IT = "Italian (Italy)"; -Blockly.Msg.WEBDUINO_SPEAK_jv_ID = "Javanese (Indonesia)"; -Blockly.Msg.WEBDUINO_SPEAK_kn_IN = "Kannada (India)"; -Blockly.Msg.WEBDUINO_SPEAK_km_KH = "Khmer (Cambodia)"; -Blockly.Msg.WEBDUINO_SPEAK_lo_LA = "Lao (Laos)"; -Blockly.Msg.WEBDUINO_SPEAK_lv_LV = "Latvian (Latvia)"; -Blockly.Msg.WEBDUINO_SPEAK_lt_LT = "Lithuanian (Lithuania)"; -Blockly.Msg.WEBDUINO_SPEAK_hu_HU = "Hungarian (Hungary)"; -Blockly.Msg.WEBDUINO_SPEAK_ml_IN = "Malayalam (India)"; -Blockly.Msg.WEBDUINO_SPEAK_mr_IN = "Marathi (India)"; -Blockly.Msg.WEBDUINO_SPEAK_nl_NL = "Dutch (Netherlands)"; -Blockly.Msg.WEBDUINO_SPEAK_ne_NP = "Nepali (Nepal)"; -Blockly.Msg.WEBDUINO_SPEAK_nb_NO = "Norwegian Bokmål (Norway)"; -Blockly.Msg.WEBDUINO_SPEAK_pl_PL = "Polish (Poland)"; -Blockly.Msg.WEBDUINO_SPEAK_pt_BR = "Portuguese (Brazil)"; -Blockly.Msg.WEBDUINO_SPEAK_pt_PT = "Portuguese (Portugal)"; -Blockly.Msg.WEBDUINO_SPEAK_ro_RO = "Romanian (Romania)"; -Blockly.Msg.WEBDUINO_SPEAK_si_LK = "Sinhala (Sri Lanka)"; -Blockly.Msg.WEBDUINO_SPEAK_sk_SK = "Slovak (Slovakia)"; -Blockly.Msg.WEBDUINO_SPEAK_sl_SI = "Slovenian (Slovenia)"; -Blockly.Msg.WEBDUINO_SPEAK_su_ID = "Sundanese (Indonesia)"; -Blockly.Msg.WEBDUINO_SPEAK_sw_TZ = "Swahili (Tanzania)"; -Blockly.Msg.WEBDUINO_SPEAK_sw_KE = "Swahili (Kenya)"; -Blockly.Msg.WEBDUINO_SPEAK_fi_FI = "Finnish (Finland)"; -Blockly.Msg.WEBDUINO_SPEAK_sv_SE = "Swedish (Sweden)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_IN = "Tamil (India)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_SG = "Tamil (Singapore)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_LK = "Tamil (Sri Lanka)"; -Blockly.Msg.WEBDUINO_SPEAK_ta_MY = "Tamil (Malaysia)"; -Blockly.Msg.WEBDUINO_SPEAK_te_IN = "Telugu (India)"; -Blockly.Msg.WEBDUINO_SPEAK_vi_VN = "Vietnamese (Vietnam)"; -Blockly.Msg.WEBDUINO_SPEAK_tr_TR = "Turkish (Turkey)"; -Blockly.Msg.WEBDUINO_SPEAK_ur_PK = "Urdu (Pakistan)"; -Blockly.Msg.WEBDUINO_SPEAK_ur_IN = "Urdu (India)"; -Blockly.Msg.WEBDUINO_SPEAK_el_GR = "Greek (Greece)"; -Blockly.Msg.WEBDUINO_SPEAK_bg_BG = "Bulgarian (Bulgaria)"; -Blockly.Msg.WEBDUINO_SPEAK_ru_RU = "Russian (Russia)"; -Blockly.Msg.WEBDUINO_SPEAK_sr_RS = "Serbian (Serbia)"; -Blockly.Msg.WEBDUINO_SPEAK_uk_UA = "Ukrainian (Ukraine)"; -Blockly.Msg.WEBDUINO_SPEAK_he_IL = "Hebrew (Israel)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_IL = "Arabic (Israel)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_JO = "Arabic (Jordan)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_AE = "Arabic (United Arab Emirates)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_BH = "Arabic (Bahrain)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_DZ = "Arabic (Algeria)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_SA = "Arabic (Saudi Arabia)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_IQ = "Arabic (Iraq)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_KW = "Arabic (Kuwait)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_MA = "Arabic (Morocco)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_TN = "Arabic (Tunisia)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_OM = "Arabic (Oman)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_PS = "Arabic (State of Palestine)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_QA = "Arabic (Qatar)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_LB = "Arabic (Lebanon)"; -Blockly.Msg.WEBDUINO_SPEAK_ar_EG = "Arabic (Egypt)"; -Blockly.Msg.WEBDUINO_SPEAK_fa_IR = "Persian (Iran)"; -Blockly.Msg.WEBDUINO_SPEAK_hi_IN = "Hindi (India)"; -Blockly.Msg.WEBDUINO_SPEAK_th_TH = "Thai (Thailand)"; -Blockly.Msg.WEBDUINO_SPEAK_ko_KR = "Korean (South Korea)"; -Blockly.Msg.WEBDUINO_SPEAK_cmn_Hant_TW = "Chinese, Mandarin (Traditional, Taiwan)"; -Blockly.Msg.WEBDUINO_SPEAK_yue_Hant_HK = "Chinese, Cantonese (Traditional, Hong Kong)"; -Blockly.Msg.WEBDUINO_SPEAK_ja_JP = "Japanese (Japan)"; -Blockly.Msg.WEBDUINO_SPEAK_cmn_Hans_HK = "Chinese, Mandarin (Simplified, Hong Kong)"; -Blockly.Msg.WEBDUINO_SPEAK_cmn_Hans_CN = "Chinese, Mandarin (Simplified, China)"; diff --git a/speak_setting_sample_fustyles/blockly/msg/en.js b/speak_setting_sample_fustyles/blockly/msg/en.js deleted file mode 100644 index 4dfe90a0f1..0000000000 --- a/speak_setting_sample_fustyles/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catSpeakmodify = "Speak Language"; diff --git a/speak_setting_sample_fustyles/blockly/msg/zh-hans.js b/speak_setting_sample_fustyles/blockly/msg/zh-hans.js deleted file mode 100644 index 98e4e3dec8..0000000000 --- a/speak_setting_sample_fustyles/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catSpeakmodify = "朗读语言"; diff --git a/speak_setting_sample_fustyles/blockly/msg/zh-hant.js b/speak_setting_sample_fustyles/blockly/msg/zh-hant.js deleted file mode 100644 index 0b238b08ef..0000000000 --- a/speak_setting_sample_fustyles/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catSpeakmodify = "朗讀語言"; diff --git a/speak_setting_sample_fustyles/blockly/toolbox.xml b/speak_setting_sample_fustyles/blockly/toolbox.xml deleted file mode 100644 index dadedf988b..0000000000 --- a/speak_setting_sample_fustyles/blockly/toolbox.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - 1 - 1 - 1 - - - 1 - 1 - 1 - - - cmn_Hant_TW - - - - diff --git a/speak_setting_sample_fustyles/speak_setting_sample.js b/speak_setting_sample_fustyles/speak_setting_sample.js deleted file mode 100644 index 6b9b0a25ac..0000000000 --- a/speak_setting_sample_fustyles/speak_setting_sample.js +++ /dev/null @@ -1,7 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - -}(window, window.document)); diff --git a/teachable_machine_boilerplate_20180808/blockly.json b/teachable_machine_boilerplate_20180808/blockly.json deleted file mode 100644 index f32a8a01f1..0000000000 --- a/teachable_machine_boilerplate_20180808/blockly.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "types": ["teachable_machine_open","teachable_machine_proportion"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "teachable_machine.js", - "build.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/teachable_machine_boilerplate_20180808/blockly/blocks.js b/teachable_machine_boilerplate_20180808/blockly/blocks.js deleted file mode 100644 index 0986b05d58..0000000000 --- a/teachable_machine_boilerplate_20180808/blockly/blocks.js +++ /dev/null @@ -1,20 +0,0 @@ -Blockly.Blocks['teachable_machine_open'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.TEACHABLE_MACHINE_OPEN_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(65); - } -}; - -Blockly.Blocks['teachable_machine_proportion'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.TEACHABLE_MACHINE_PROPORTION_SHOW) - .appendField(new Blockly.FieldDropdown([["train","train"], ["probability","probability"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(65); - } -}; diff --git a/teachable_machine_boilerplate_20180808/blockly/javascript.js b/teachable_machine_boilerplate_20180808/blockly/javascript.js deleted file mode 100644 index fe8d871a0a..0000000000 --- a/teachable_machine_boilerplate_20180808/blockly/javascript.js +++ /dev/null @@ -1,10 +0,0 @@ -Blockly.JavaScript['teachable_machine_open'] = function (block) { - var code = 'teachable_machine_open();\n'; - return code; -}; - -Blockly.JavaScript['teachable_machine_proportion'] = function(block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'teachable_machine_proportion("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; diff --git a/teachable_machine_boilerplate_20180808/blockly/msg/blocks/en.js b/teachable_machine_boilerplate_20180808/blockly/msg/blocks/en.js deleted file mode 100644 index 7a7c3889e9..0000000000 --- a/teachable_machine_boilerplate_20180808/blockly/msg/blocks/en.js +++ /dev/null @@ -1,2 +0,0 @@ -Blockly.Msg.TEACHABLE_MACHINE_OPEN_SHOW = "Deep Learning Initialize"; -Blockly.Msg.TEACHABLE_MACHINE_PROPORTION_SHOW = "Deep Learning Max Probability"; diff --git a/teachable_machine_boilerplate_20180808/blockly/msg/blocks/zh-hans.js b/teachable_machine_boilerplate_20180808/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index caa880063c..0000000000 --- a/teachable_machine_boilerplate_20180808/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,2 +0,0 @@ -Blockly.Msg.TEACHABLE_MACHINE_OPEN_SHOW = "深度学习 初始化"; -Blockly.Msg.TEACHABLE_MACHINE_PROPORTION_SHOW = "深度学习 最高机率"; diff --git a/teachable_machine_boilerplate_20180808/blockly/msg/blocks/zh-hant.js b/teachable_machine_boilerplate_20180808/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 8475f18603..0000000000 --- a/teachable_machine_boilerplate_20180808/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,2 +0,0 @@ -Blockly.Msg.TEACHABLE_MACHINE_OPEN_SHOW = "深度學習 初始化"; -Blockly.Msg.TEACHABLE_MACHINE_PROPORTION_SHOW = "深度學習 最高機率"; diff --git a/teachable_machine_boilerplate_20180808/blockly/msg/en.js b/teachable_machine_boilerplate_20180808/blockly/msg/en.js deleted file mode 100644 index 0b9eb27f46..0000000000 --- a/teachable_machine_boilerplate_20180808/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.teachable_machine = "Teachable Machine"; diff --git a/teachable_machine_boilerplate_20180808/blockly/msg/zh-hans.js b/teachable_machine_boilerplate_20180808/blockly/msg/zh-hans.js deleted file mode 100644 index f826b754fe..0000000000 --- a/teachable_machine_boilerplate_20180808/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.teachable_machine = "机械学习"; diff --git a/teachable_machine_boilerplate_20180808/blockly/msg/zh-hant.js b/teachable_machine_boilerplate_20180808/blockly/msg/zh-hant.js deleted file mode 100644 index c9cfac7f83..0000000000 --- a/teachable_machine_boilerplate_20180808/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.teachable_machine = "機械學習"; diff --git a/teachable_machine_boilerplate_20180808/blockly/toolbox.xml b/teachable_machine_boilerplate_20180808/blockly/toolbox.xml deleted file mode 100644 index 96ab84bfd9..0000000000 --- a/teachable_machine_boilerplate_20180808/blockly/toolbox.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/teachable_machine_boilerplate_20180808/build.js b/teachable_machine_boilerplate_20180808/build.js deleted file mode 100644 index 96fadb48c2..0000000000 --- a/teachable_machine_boilerplate_20180808/build.js +++ /dev/null @@ -1,21011 +0,0 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { - this.knn.predictClass(image).then(function (res) { - var max=0,maxid=-1; - for (var i = 0; i < NUM_CLASSES; i++) { - // Make the predicted class bold - if (res.classIndex == i) { - _this2.infoTexts[i].style.fontWeight = 'bold'; - } else { - _this2.infoTexts[i].style.fontWeight = 'normal'; - } - - // Update info text - - if (exampleCount[i] > 0) { - _this2.infoTexts[i].innerText = ' ' + exampleCount[i] + ' examples - ' + res.confidences[i] * 100 + '%'; - if ((res.confidences[i] * 100) >= max) - { - max=res.confidences[i] * 100; - maxid=i; - } - } - } - document.getElementById("train").innerHTML = maxid ; - document.getElementById("probability").innerHTML = max ; - }) - // Dispose image when done - .then(function () { - return image.dispose(); - }); - } else { - image.dispose(); - } - } - this.timer = requestAnimationFrame(this.animate.bind(this)); - } - }]); - - return Main; -}(); - -window.addEventListener('load', function () { - return new Main(); -}); - -},{"deeplearn":67,"deeplearn-knn-image-classifier":3}],2:[function(require,module,exports){ - -},{}],3:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var knn_image_classifier_1 = require("./knn_image_classifier"); -exports.KNNImageClassifier = knn_image_classifier_1.KNNImageClassifier; - -},{"./knn_image_classifier":4}],4:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dl = require("deeplearn"); -var deeplearn_squeezenet_1 = require("deeplearn-squeezenet"); -var model_util = require("../util"); -var KNNImageClassifier = (function () { - function KNNImageClassifier(numClasses, k) { - this.numClasses = numClasses; - this.k = k; - this.classLogitsMatrices = []; - this.classExampleCount = []; - this.varsLoaded = false; - this.squashLogitsDenominator = dl.scalar(300); - for (var i = 0; i < this.numClasses; i++) { - this.classLogitsMatrices.push(null); - this.classExampleCount.push(0); - } - this.squeezeNet = new deeplearn_squeezenet_1.SqueezeNet(); - } - KNNImageClassifier.prototype.load = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.squeezeNet.load()]; - case 1: - _a.sent(); - this.varsLoaded = true; - return [2]; - } - }); - }); - }; - KNNImageClassifier.prototype.clearClass = function (classIndex) { - if (classIndex >= this.numClasses) { - console.log('Cannot clear invalid class ${classIndex}'); - return; - } - this.classLogitsMatrices[classIndex] = null; - this.classExampleCount[classIndex] = 0; - this.clearTrainLogitsMatrix(); - }; - KNNImageClassifier.prototype.addImage = function (image, classIndex) { - var _this = this; - if (!this.varsLoaded) { - console.warn('Cannot add images until vars have been loaded.'); - return; - } - if (classIndex >= this.numClasses) { - console.warn('Cannot add to invalid class ${classIndex}'); - } - this.clearTrainLogitsMatrix(); - dl.tidy(function () { - var logits = _this.squeezeNet.predict(image); - var imageLogits = _this.normalizeVector(logits); - var logitsSize = imageLogits.shape[0]; - if (_this.classLogitsMatrices[classIndex] == null) { - _this.classLogitsMatrices[classIndex] = imageLogits.as2D(1, logitsSize); - } - else { - var newTrainLogitsMatrix = _this.classLogitsMatrices[classIndex] - .as2D(_this.classExampleCount[classIndex], logitsSize) - .concat(imageLogits.as2D(1, logitsSize), 0); - _this.classLogitsMatrices[classIndex].dispose(); - _this.classLogitsMatrices[classIndex] = newTrainLogitsMatrix; - } - dl.keep(_this.classLogitsMatrices[classIndex]); - _this.classExampleCount[classIndex]++; - }); - }; - KNNImageClassifier.prototype.predict = function (image) { - var _this = this; - if (!this.varsLoaded) { - throw new Error('Cannot predict until vars have been loaded.'); - } - return dl.tidy(function () { - var logits = _this.squeezeNet.predict(image); - var imageLogits = _this.normalizeVector(logits); - var logitsSize = imageLogits.shape[0]; - if (_this.trainLogitsMatrix == null) { - var newTrainLogitsMatrix = null; - for (var i = 0; i < _this.numClasses; i++) { - newTrainLogitsMatrix = _this.concatWithNulls(newTrainLogitsMatrix, _this.classLogitsMatrices[i]); - } - _this.trainLogitsMatrix = newTrainLogitsMatrix; - } - if (_this.trainLogitsMatrix == null) { - console.warn('Cannot predict without providing training images.'); - return null; - } - dl.keep(_this.trainLogitsMatrix); - var numExamples = _this.getNumExamples(); - return _this.trainLogitsMatrix.as2D(numExamples, logitsSize) - .matMul(imageLogits.as2D(logitsSize, 1)) - .as1D(); - }); - }; - KNNImageClassifier.prototype.predictClass = function (image) { - return __awaiter(this, void 0, void 0, function () { - var imageClass, confidences, knn, numExamples, kVal, topK, _a, _b, topKIndices, indicesForClasses, topKCountsForClasses, i, num, i, classForEntry, topConfidence, i, probability; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - imageClass = -1; - confidences = new Array(this.numClasses); - if (!this.varsLoaded) { - throw new Error('Cannot predict until vars have been loaded.'); - } - knn = this.predict(image).asType('float32'); - numExamples = this.getNumExamples(); - kVal = Math.min(this.k, numExamples); - _b = (_a = model_util).topK; - return [4, knn.data()]; - case 1: - topK = _b.apply(_a, [_c.sent(), kVal]); - knn.dispose(); - topKIndices = topK.indices; - if (topKIndices == null) { - return [2, { classIndex: imageClass, confidences: confidences }]; - } - indicesForClasses = []; - topKCountsForClasses = []; - for (i = 0; i < this.numClasses; i++) { - topKCountsForClasses.push(0); - num = this.classExampleCount[i]; - if (i > 0) { - num += indicesForClasses[i - 1]; - } - indicesForClasses.push(num); - } - for (i = 0; i < topKIndices.length; i++) { - for (classForEntry = 0; classForEntry < indicesForClasses.length; classForEntry++) { - if (topKIndices[i] < indicesForClasses[classForEntry]) { - topKCountsForClasses[classForEntry]++; - break; - } - } - } - topConfidence = 0; - for (i = 0; i < this.numClasses; i++) { - probability = topKCountsForClasses[i] / kVal; - if (probability > topConfidence) { - topConfidence = probability; - imageClass = i; - } - confidences[i] = probability; - } - return [2, { classIndex: imageClass, confidences: confidences }]; - } - }); - }); - }; - KNNImageClassifier.prototype.getClassExampleCount = function () { - return this.classExampleCount; - }; - KNNImageClassifier.prototype.clearTrainLogitsMatrix = function () { - if (this.trainLogitsMatrix != null) { - this.trainLogitsMatrix.dispose(); - this.trainLogitsMatrix = null; - } - }; - KNNImageClassifier.prototype.concatWithNulls = function (ndarray1, ndarray2) { - if (ndarray1 == null && ndarray2 == null) { - return null; - } - if (ndarray1 == null) { - return ndarray2.clone(); - } - else if (ndarray2 === null) { - return ndarray1.clone(); - } - return ndarray1.concat(ndarray2, 0); - }; - KNNImageClassifier.prototype.normalizeVector = function (vec) { - var squashedVec = dl.div(vec, this.squashLogitsDenominator); - var sqrtSum = squashedVec.square().sum().sqrt(); - return dl.div(squashedVec, sqrtSum); - }; - KNNImageClassifier.prototype.getNumExamples = function () { - var total = 0; - for (var i = 0; i < this.classExampleCount.length; i++) { - total += this.classExampleCount[i]; - } - return total; - }; - KNNImageClassifier.prototype.dispose = function () { - this.squeezeNet.dispose(); - this.clearTrainLogitsMatrix(); - this.classLogitsMatrices.forEach(function (classLogitsMatrix) { return classLogitsMatrix.dispose(); }); - this.squashLogitsDenominator.dispose(); - }; - return KNNImageClassifier; -}()); -exports.KNNImageClassifier = KNNImageClassifier; - -},{"../util":5,"deeplearn":67,"deeplearn-squeezenet":7}],5:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function topK(values, k) { - var valuesAndIndices = []; - for (var i = 0; i < values.length; i++) { - valuesAndIndices.push({ value: values[i], index: i }); - } - valuesAndIndices.sort(function (a, b) { - return b.value - a.value; - }); - var topkValues = new Float32Array(k); - var topkIndices = new Int32Array(k); - for (var i = 0; i < k; i++) { - topkValues[i] = valuesAndIndices[i].value; - topkIndices[i] = valuesAndIndices[i].index; - } - return { values: topkValues, indices: topkIndices }; -} -exports.topK = topK; - -},{}],6:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.IMAGENET_CLASSES = { - 0: 'tench, Tinca tinca', - 1: 'goldfish, Carassius auratus', - 2: 'great white shark, white shark, man-eater, man-eating shark, ' + - 'Carcharodon carcharias', - 3: 'tiger shark, Galeocerdo cuvieri', - 4: 'hammerhead, hammerhead shark', - 5: 'electric ray, crampfish, numbfish, torpedo', - 6: 'stingray', - 7: 'cock', - 8: 'hen', - 9: 'ostrich, Struthio camelus', - 10: 'brambling, Fringilla montifringilla', - 11: 'goldfinch, Carduelis carduelis', - 12: 'house finch, linnet, Carpodacus mexicanus', - 13: 'junco, snowbird', - 14: 'indigo bunting, indigo finch, indigo bird, Passerina cyanea', - 15: 'robin, American robin, Turdus migratorius', - 16: 'bulbul', - 17: 'jay', - 18: 'magpie', - 19: 'chickadee', - 20: 'water ouzel, dipper', - 21: 'kite', - 22: 'bald eagle, American eagle, Haliaeetus leucocephalus', - 23: 'vulture', - 24: 'great grey owl, great gray owl, Strix nebulosa', - 25: 'European fire salamander, Salamandra salamandra', - 26: 'common newt, Triturus vulgaris', - 27: 'eft', - 28: 'spotted salamander, Ambystoma maculatum', - 29: 'axolotl, mud puppy, Ambystoma mexicanum', - 30: 'bullfrog, Rana catesbeiana', - 31: 'tree frog, tree-frog', - 32: 'tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui', - 33: 'loggerhead, loggerhead turtle, Caretta caretta', - 34: 'leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea', - 35: 'mud turtle', - 36: 'terrapin', - 37: 'box turtle, box tortoise', - 38: 'banded gecko', - 39: 'common iguana, iguana, Iguana iguana', - 40: 'American chameleon, anole, Anolis carolinensis', - 41: 'whiptail, whiptail lizard', - 42: 'agama', - 43: 'frilled lizard, Chlamydosaurus kingi', - 44: 'alligator lizard', - 45: 'Gila monster, Heloderma suspectum', - 46: 'green lizard, Lacerta viridis', - 47: 'African chameleon, Chamaeleo chamaeleon', - 48: 'Komodo dragon, Komodo lizard, dragon lizard, giant lizard, ' + - 'Varanus komodoensis', - 49: 'African crocodile, Nile crocodile, Crocodylus niloticus', - 50: 'American alligator, Alligator mississipiensis', - 51: 'triceratops', - 52: 'thunder snake, worm snake, Carphophis amoenus', - 53: 'ringneck snake, ring-necked snake, ring snake', - 54: 'hognose snake, puff adder, sand viper', - 55: 'green snake, grass snake', - 56: 'king snake, kingsnake', - 57: 'garter snake, grass snake', - 58: 'water snake', - 59: 'vine snake', - 60: 'night snake, Hypsiglena torquata', - 61: 'boa constrictor, Constrictor constrictor', - 62: 'rock python, rock snake, Python sebae', - 63: 'Indian cobra, Naja naja', - 64: 'green mamba', - 65: 'sea snake', - 66: 'horned viper, cerastes, sand viper, horned asp, Cerastes cornutus', - 67: 'diamondback, diamondback rattlesnake, Crotalus adamanteus', - 68: 'sidewinder, horned rattlesnake, Crotalus cerastes', - 69: 'trilobite', - 70: 'harvestman, daddy longlegs, Phalangium opilio', - 71: 'scorpion', - 72: 'black and gold garden spider, Argiope aurantia', - 73: 'barn spider, Araneus cavaticus', - 74: 'garden spider, Aranea diademata', - 75: 'black widow, Latrodectus mactans', - 76: 'tarantula', - 77: 'wolf spider, hunting spider', - 78: 'tick', - 79: 'centipede', - 80: 'black grouse', - 81: 'ptarmigan', - 82: 'ruffed grouse, partridge, Bonasa umbellus', - 83: 'prairie chicken, prairie grouse, prairie fowl', - 84: 'peacock', - 85: 'quail', - 86: 'partridge', - 87: 'African grey, African gray, Psittacus erithacus', - 88: 'macaw', - 89: 'sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita', - 90: 'lorikeet', - 91: 'coucal', - 92: 'bee eater', - 93: 'hornbill', - 94: 'hummingbird', - 95: 'jacamar', - 96: 'toucan', - 97: 'drake', - 98: 'red-breasted merganser, Mergus serrator', - 99: 'goose', - 100: 'black swan, Cygnus atratus', - 101: 'tusker', - 102: 'echidna, spiny anteater, anteater', - 103: 'platypus, duckbill, duckbilled platypus, duck-billed platypus, ' + - 'Ornithorhynchus anatinus', - 104: 'wallaby, brush kangaroo', - 105: 'koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus', - 106: 'wombat', - 107: 'jelly fish', - 108: 'sea anemone, anemone', - 109: 'brain coral', - 110: 'flatworm, platyhelminth', - 111: 'nematode, nematode worm, roundworm', - 112: 'conch', - 113: 'snail', - 114: 'slug', - 115: 'sea slug, nudibranch', - 116: 'chiton, coat-of-mail shell, sea cradle, polyplacophore', - 117: 'chambered nautilus, pearly nautilus, nautilus', - 118: 'Dungeness crab, Cancer magister', - 119: 'rock crab, Cancer irroratus', - 120: 'fiddler crab', - 121: 'king crab, Alaska crab, Alaskan king crab, Alaska king crab, ' + - 'Paralithodes camtschatica', - 122: 'American lobster, Northern lobster, Maine lobster, Homarus americanus', - 123: 'spiny lobster, langouste, rock lobster, crawfish, crayfish, sea ' + - 'crawfish', - 124: 'crayfish, crawfish, crawdad, crawdaddy', - 125: 'hermit crab', - 126: 'isopod', - 127: 'white stork, Ciconia ciconia', - 128: 'black stork, Ciconia nigra', - 129: 'spoonbill', - 130: 'flamingo', - 131: 'little blue heron, Egretta caerulea', - 132: 'American egret, great white heron, Egretta albus', - 133: 'bittern', - 134: 'crane', - 135: 'limpkin, Aramus pictus', - 136: 'European gallinule, Porphyrio porphyrio', - 137: 'American coot, marsh hen, mud hen, water hen, Fulica americana', - 138: 'bustard', - 139: 'ruddy turnstone, Arenaria interpres', - 140: 'red-backed sandpiper, dunlin, Erolia alpina', - 141: 'redshank, Tringa totanus', - 142: 'dowitcher', - 143: 'oystercatcher, oyster catcher', - 144: 'pelican', - 145: 'king penguin, Aptenodytes patagonica', - 146: 'albatross, mollymawk', - 147: 'grey whale, gray whale, devilfish, Eschrichtius gibbosus, ' + - 'Eschrichtius robustus', - 148: 'killer whale, killer, orca, grampus, sea wolf, Orcinus orca', - 149: 'dugong, Dugong dugon', - 150: 'sea lion', - 151: 'Chihuahua', - 152: 'Japanese spaniel', - 153: 'Maltese dog, Maltese terrier, Maltese', - 154: 'Pekinese, Pekingese, Peke', - 155: 'Shih-Tzu', - 156: 'Blenheim spaniel', - 157: 'papillon', - 158: 'toy terrier', - 159: 'Rhodesian ridgeback', - 160: 'Afghan hound, Afghan', - 161: 'basset, basset hound', - 162: 'beagle', - 163: 'bloodhound, sleuthhound', - 164: 'bluetick', - 165: 'black-and-tan coonhound', - 166: 'Walker hound, Walker foxhound', - 167: 'English foxhound', - 168: 'redbone', - 169: 'borzoi, Russian wolfhound', - 170: 'Irish wolfhound', - 171: 'Italian greyhound', - 172: 'whippet', - 173: 'Ibizan hound, Ibizan Podenco', - 174: 'Norwegian elkhound, elkhound', - 175: 'otterhound, otter hound', - 176: 'Saluki, gazelle hound', - 177: 'Scottish deerhound, deerhound', - 178: 'Weimaraner', - 179: 'Staffordshire bullterrier, Staffordshire bull terrier', - 180: 'American Staffordshire terrier, Staffordshire terrier, American pit ' + - 'bull terrier, pit bull terrier', - 181: 'Bedlington terrier', - 182: 'Border terrier', - 183: 'Kerry blue terrier', - 184: 'Irish terrier', - 185: 'Norfolk terrier', - 186: 'Norwich terrier', - 187: 'Yorkshire terrier', - 188: 'wire-haired fox terrier', - 189: 'Lakeland terrier', - 190: 'Sealyham terrier, Sealyham', - 191: 'Airedale, Airedale terrier', - 192: 'cairn, cairn terrier', - 193: 'Australian terrier', - 194: 'Dandie Dinmont, Dandie Dinmont terrier', - 195: 'Boston bull, Boston terrier', - 196: 'miniature schnauzer', - 197: 'giant schnauzer', - 198: 'standard schnauzer', - 199: 'Scotch terrier, Scottish terrier, Scottie', - 200: 'Tibetan terrier, chrysanthemum dog', - 201: 'silky terrier, Sydney silky', - 202: 'soft-coated wheaten terrier', - 203: 'West Highland white terrier', - 204: 'Lhasa, Lhasa apso', - 205: 'flat-coated retriever', - 206: 'curly-coated retriever', - 207: 'golden retriever', - 208: 'Labrador retriever', - 209: 'Chesapeake Bay retriever', - 210: 'German short-haired pointer', - 211: 'vizsla, Hungarian pointer', - 212: 'English setter', - 213: 'Irish setter, red setter', - 214: 'Gordon setter', - 215: 'Brittany spaniel', - 216: 'clumber, clumber spaniel', - 217: 'English springer, English springer spaniel', - 218: 'Welsh springer spaniel', - 219: 'cocker spaniel, English cocker spaniel, cocker', - 220: 'Sussex spaniel', - 221: 'Irish water spaniel', - 222: 'kuvasz', - 223: 'schipperke', - 224: 'groenendael', - 225: 'malinois', - 226: 'briard', - 227: 'kelpie', - 228: 'komondor', - 229: 'Old English sheepdog, bobtail', - 230: 'Shetland sheepdog, Shetland sheep dog, Shetland', - 231: 'collie', - 232: 'Border collie', - 233: 'Bouvier des Flandres, Bouviers des Flandres', - 234: 'Rottweiler', - 235: 'German shepherd, German shepherd dog, German police dog, alsatian', - 236: 'Doberman, Doberman pinscher', - 237: 'miniature pinscher', - 238: 'Greater Swiss Mountain dog', - 239: 'Bernese mountain dog', - 240: 'Appenzeller', - 241: 'EntleBucher', - 242: 'boxer', - 243: 'bull mastiff', - 244: 'Tibetan mastiff', - 245: 'French bulldog', - 246: 'Great Dane', - 247: 'Saint Bernard, St Bernard', - 248: 'Eskimo dog, husky', - 249: 'malamute, malemute, Alaskan malamute', - 250: 'Siberian husky', - 251: 'dalmatian, coach dog, carriage dog', - 252: 'affenpinscher, monkey pinscher, monkey dog', - 253: 'basenji', - 254: 'pug, pug-dog', - 255: 'Leonberg', - 256: 'Newfoundland, Newfoundland dog', - 257: 'Great Pyrenees', - 258: 'Samoyed, Samoyede', - 259: 'Pomeranian', - 260: 'chow, chow chow', - 261: 'keeshond', - 262: 'Brabancon griffon', - 263: 'Pembroke, Pembroke Welsh corgi', - 264: 'Cardigan, Cardigan Welsh corgi', - 265: 'toy poodle', - 266: 'miniature poodle', - 267: 'standard poodle', - 268: 'Mexican hairless', - 269: 'timber wolf, grey wolf, gray wolf, Canis lupus', - 270: 'white wolf, Arctic wolf, Canis lupus tundrarum', - 271: 'red wolf, maned wolf, Canis rufus, Canis niger', - 272: 'coyote, prairie wolf, brush wolf, Canis latrans', - 273: 'dingo, warrigal, warragal, Canis dingo', - 274: 'dhole, Cuon alpinus', - 275: 'African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus', - 276: 'hyena, hyaena', - 277: 'red fox, Vulpes vulpes', - 278: 'kit fox, Vulpes macrotis', - 279: 'Arctic fox, white fox, Alopex lagopus', - 280: 'grey fox, gray fox, Urocyon cinereoargenteus', - 281: 'tabby, tabby cat', - 282: 'tiger cat', - 283: 'Persian cat', - 284: 'Siamese cat, Siamese', - 285: 'Egyptian cat', - 286: 'cougar, puma, catamount, mountain lion, painter, panther, ' + - 'Felis concolor', - 287: 'lynx, catamount', - 288: 'leopard, Panthera pardus', - 289: 'snow leopard, ounce, Panthera uncia', - 290: 'jaguar, panther, Panthera onca, Felis onca', - 291: 'lion, king of beasts, Panthera leo', - 292: 'tiger, Panthera tigris', - 293: 'cheetah, chetah, Acinonyx jubatus', - 294: 'brown bear, bruin, Ursus arctos', - 295: 'American black bear, black bear, Ursus americanus, Euarctos ' + - 'americanus', - 296: 'ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus', - 297: 'sloth bear, Melursus ursinus, Ursus ursinus', - 298: 'mongoose', - 299: 'meerkat, mierkat', - 300: 'tiger beetle', - 301: 'ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle', - 302: 'ground beetle, carabid beetle', - 303: 'long-horned beetle, longicorn, longicorn beetle', - 304: 'leaf beetle, chrysomelid', - 305: 'dung beetle', - 306: 'rhinoceros beetle', - 307: 'weevil', - 308: 'fly', - 309: 'bee', - 310: 'ant, emmet, pismire', - 311: 'grasshopper, hopper', - 312: 'cricket', - 313: 'walking stick, walkingstick, stick insect', - 314: 'cockroach, roach', - 315: 'mantis, mantid', - 316: 'cicada, cicala', - 317: 'leafhopper', - 318: 'lacewing, lacewing fly', - 319: 'dragonfly, darning needle, devil\'s darning needle, sewing needle, ' + - 'snake feeder, snake doctor, mosquito hawk, skeeter hawk', - 320: 'damselfly', - 321: 'admiral', - 322: 'ringlet, ringlet butterfly', - 323: 'monarch, monarch butterfly, milkweed butterfly, Danaus plexippus', - 324: 'cabbage butterfly', - 325: 'sulphur butterfly, sulfur butterfly', - 326: 'lycaenid, lycaenid butterfly', - 327: 'starfish, sea star', - 328: 'sea urchin', - 329: 'sea cucumber, holothurian', - 330: 'wood rabbit, cottontail, cottontail rabbit', - 331: 'hare', - 332: 'Angora, Angora rabbit', - 333: 'hamster', - 334: 'porcupine, hedgehog', - 335: 'fox squirrel, eastern fox squirrel, Sciurus niger', - 336: 'marmot', - 337: 'beaver', - 338: 'guinea pig, Cavia cobaya', - 339: 'sorrel', - 340: 'zebra', - 341: 'hog, pig, grunter, squealer, Sus scrofa', - 342: 'wild boar, boar, Sus scrofa', - 343: 'warthog', - 344: 'hippopotamus, hippo, river horse, Hippopotamus amphibius', - 345: 'ox', - 346: 'water buffalo, water ox, Asiatic buffalo, Bubalus bubalis', - 347: 'bison', - 348: 'ram, tup', - 349: 'bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky ' + - 'Mountain sheep, Ovis canadensis', - 350: 'ibex, Capra ibex', - 351: 'hartebeest', - 352: 'impala, Aepyceros melampus', - 353: 'gazelle', - 354: 'Arabian camel, dromedary, Camelus dromedarius', - 355: 'llama', - 356: 'weasel', - 357: 'mink', - 358: 'polecat, fitch, foulmart, foumart, Mustela putorius', - 359: 'black-footed ferret, ferret, Mustela nigripes', - 360: 'otter', - 361: 'skunk, polecat, wood pussy', - 362: 'badger', - 363: 'armadillo', - 364: 'three-toed sloth, ai, Bradypus tridactylus', - 365: 'orangutan, orang, orangutang, Pongo pygmaeus', - 366: 'gorilla, Gorilla gorilla', - 367: 'chimpanzee, chimp, Pan troglodytes', - 368: 'gibbon, Hylobates lar', - 369: 'siamang, Hylobates syndactylus, Symphalangus syndactylus', - 370: 'guenon, guenon monkey', - 371: 'patas, hussar monkey, Erythrocebus patas', - 372: 'baboon', - 373: 'macaque', - 374: 'langur', - 375: 'colobus, colobus monkey', - 376: 'proboscis monkey, Nasalis larvatus', - 377: 'marmoset', - 378: 'capuchin, ringtail, Cebus capucinus', - 379: 'howler monkey, howler', - 380: 'titi, titi monkey', - 381: 'spider monkey, Ateles geoffroyi', - 382: 'squirrel monkey, Saimiri sciureus', - 383: 'Madagascar cat, ring-tailed lemur, Lemur catta', - 384: 'indri, indris, Indri indri, Indri brevicaudatus', - 385: 'Indian elephant, Elephas maximus', - 386: 'African elephant, Loxodonta africana', - 387: 'lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens', - 388: 'giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca', - 389: 'barracouta, snoek', - 390: 'eel', - 391: 'coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus ' + - 'kisutch', - 392: 'rock beauty, Holocanthus tricolor', - 393: 'anemone fish', - 394: 'sturgeon', - 395: 'gar, garfish, garpike, billfish, Lepisosteus osseus', - 396: 'lionfish', - 397: 'puffer, pufferfish, blowfish, globefish', - 398: 'abacus', - 399: 'abaya', - 400: 'academic gown, academic robe, judge\'s robe', - 401: 'accordion, piano accordion, squeeze box', - 402: 'acoustic guitar', - 403: 'aircraft carrier, carrier, flattop, attack aircraft carrier', - 404: 'airliner', - 405: 'airship, dirigible', - 406: 'altar', - 407: 'ambulance', - 408: 'amphibian, amphibious vehicle', - 409: 'analog clock', - 410: 'apiary, bee house', - 411: 'apron', - 412: 'ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, ' + - 'dustbin, trash barrel, trash bin', - 413: 'assault rifle, assault gun', - 414: 'backpack, back pack, knapsack, packsack, rucksack, haversack', - 415: 'bakery, bakeshop, bakehouse', - 416: 'balance beam, beam', - 417: 'balloon', - 418: 'ballpoint, ballpoint pen, ballpen, Biro', - 419: 'Band Aid', - 420: 'banjo', - 421: 'bannister, banister, balustrade, balusters, handrail', - 422: 'barbell', - 423: 'barber chair', - 424: 'barbershop', - 425: 'barn', - 426: 'barometer', - 427: 'barrel, cask', - 428: 'barrow, garden cart, lawn cart, wheelbarrow', - 429: 'baseball', - 430: 'basketball', - 431: 'bassinet', - 432: 'bassoon', - 433: 'bathing cap, swimming cap', - 434: 'bath towel', - 435: 'bathtub, bathing tub, bath, tub', - 436: 'beach wagon, station wagon, wagon, estate car, beach waggon, station ' + - 'waggon, waggon', - 437: 'beacon, lighthouse, beacon light, pharos', - 438: 'beaker', - 439: 'bearskin, busby, shako', - 440: 'beer bottle', - 441: 'beer glass', - 442: 'bell cote, bell cot', - 443: 'bib', - 444: 'bicycle-built-for-two, tandem bicycle, tandem', - 445: 'bikini, two-piece', - 446: 'binder, ring-binder', - 447: 'binoculars, field glasses, opera glasses', - 448: 'birdhouse', - 449: 'boathouse', - 450: 'bobsled, bobsleigh, bob', - 451: 'bolo tie, bolo, bola tie, bola', - 452: 'bonnet, poke bonnet', - 453: 'bookcase', - 454: 'bookshop, bookstore, bookstall', - 455: 'bottlecap', - 456: 'bow', - 457: 'bow tie, bow-tie, bowtie', - 458: 'brass, memorial tablet, plaque', - 459: 'brassiere, bra, bandeau', - 460: 'breakwater, groin, groyne, mole, bulwark, seawall, jetty', - 461: 'breastplate, aegis, egis', - 462: 'broom', - 463: 'bucket, pail', - 464: 'buckle', - 465: 'bulletproof vest', - 466: 'bullet train, bullet', - 467: 'butcher shop, meat market', - 468: 'cab, hack, taxi, taxicab', - 469: 'caldron, cauldron', - 470: 'candle, taper, wax light', - 471: 'cannon', - 472: 'canoe', - 473: 'can opener, tin opener', - 474: 'cardigan', - 475: 'car mirror', - 476: 'carousel, carrousel, merry-go-round, roundabout, whirligig', - 477: 'carpenter\'s kit, tool kit', - 478: 'carton', - 479: 'car wheel', - 480: 'cash machine, cash dispenser, automated teller machine, automatic ' + - 'teller machine, automated teller, automatic teller, ATM', - 481: 'cassette', - 482: 'cassette player', - 483: 'castle', - 484: 'catamaran', - 485: 'CD player', - 486: 'cello, violoncello', - 487: 'cellular telephone, cellular phone, cellphone, cell, mobile phone', - 488: 'chain', - 489: 'chainlink fence', - 490: 'chain mail, ring mail, mail, chain armor, chain armour, ring armor, ' + - 'ring armour', - 491: 'chain saw, chainsaw', - 492: 'chest', - 493: 'chiffonier, commode', - 494: 'chime, bell, gong', - 495: 'china cabinet, china closet', - 496: 'Christmas stocking', - 497: 'church, church building', - 498: 'cinema, movie theater, movie theatre, movie house, picture palace', - 499: 'cleaver, meat cleaver, chopper', - 500: 'cliff dwelling', - 501: 'cloak', - 502: 'clog, geta, patten, sabot', - 503: 'cocktail shaker', - 504: 'coffee mug', - 505: 'coffeepot', - 506: 'coil, spiral, volute, whorl, helix', - 507: 'combination lock', - 508: 'computer keyboard, keypad', - 509: 'confectionery, confectionary, candy store', - 510: 'container ship, containership, container vessel', - 511: 'convertible', - 512: 'corkscrew, bottle screw', - 513: 'cornet, horn, trumpet, trump', - 514: 'cowboy boot', - 515: 'cowboy hat, ten-gallon hat', - 516: 'cradle', - 517: 'crane', - 518: 'crash helmet', - 519: 'crate', - 520: 'crib, cot', - 521: 'Crock Pot', - 522: 'croquet ball', - 523: 'crutch', - 524: 'cuirass', - 525: 'dam, dike, dyke', - 526: 'desk', - 527: 'desktop computer', - 528: 'dial telephone, dial phone', - 529: 'diaper, nappy, napkin', - 530: 'digital clock', - 531: 'digital watch', - 532: 'dining table, board', - 533: 'dishrag, dishcloth', - 534: 'dishwasher, dish washer, dishwashing machine', - 535: 'disk brake, disc brake', - 536: 'dock, dockage, docking facility', - 537: 'dogsled, dog sled, dog sleigh', - 538: 'dome', - 539: 'doormat, welcome mat', - 540: 'drilling platform, offshore rig', - 541: 'drum, membranophone, tympan', - 542: 'drumstick', - 543: 'dumbbell', - 544: 'Dutch oven', - 545: 'electric fan, blower', - 546: 'electric guitar', - 547: 'electric locomotive', - 548: 'entertainment center', - 549: 'envelope', - 550: 'espresso maker', - 551: 'face powder', - 552: 'feather boa, boa', - 553: 'file, file cabinet, filing cabinet', - 554: 'fireboat', - 555: 'fire engine, fire truck', - 556: 'fire screen, fireguard', - 557: 'flagpole, flagstaff', - 558: 'flute, transverse flute', - 559: 'folding chair', - 560: 'football helmet', - 561: 'forklift', - 562: 'fountain', - 563: 'fountain pen', - 564: 'four-poster', - 565: 'freight car', - 566: 'French horn, horn', - 567: 'frying pan, frypan, skillet', - 568: 'fur coat', - 569: 'garbage truck, dustcart', - 570: 'gasmask, respirator, gas helmet', - 571: 'gas pump, gasoline pump, petrol pump, island dispenser', - 572: 'goblet', - 573: 'go-kart', - 574: 'golf ball', - 575: 'golfcart, golf cart', - 576: 'gondola', - 577: 'gong, tam-tam', - 578: 'gown', - 579: 'grand piano, grand', - 580: 'greenhouse, nursery, glasshouse', - 581: 'grille, radiator grille', - 582: 'grocery store, grocery, food market, market', - 583: 'guillotine', - 584: 'hair slide', - 585: 'hair spray', - 586: 'half track', - 587: 'hammer', - 588: 'hamper', - 589: 'hand blower, blow dryer, blow drier, hair dryer, hair drier', - 590: 'hand-held computer, hand-held microcomputer', - 591: 'handkerchief, hankie, hanky, hankey', - 592: 'hard disc, hard disk, fixed disk', - 593: 'harmonica, mouth organ, harp, mouth harp', - 594: 'harp', - 595: 'harvester, reaper', - 596: 'hatchet', - 597: 'holster', - 598: 'home theater, home theatre', - 599: 'honeycomb', - 600: 'hook, claw', - 601: 'hoopskirt, crinoline', - 602: 'horizontal bar, high bar', - 603: 'horse cart, horse-cart', - 604: 'hourglass', - 605: 'iPod', - 606: 'iron, smoothing iron', - 607: 'jack-o\'-lantern', - 608: 'jean, blue jean, denim', - 609: 'jeep, landrover', - 610: 'jersey, T-shirt, tee shirt', - 611: 'jigsaw puzzle', - 612: 'jinrikisha, ricksha, rickshaw', - 613: 'joystick', - 614: 'kimono', - 615: 'knee pad', - 616: 'knot', - 617: 'lab coat, laboratory coat', - 618: 'ladle', - 619: 'lampshade, lamp shade', - 620: 'laptop, laptop computer', - 621: 'lawn mower, mower', - 622: 'lens cap, lens cover', - 623: 'letter opener, paper knife, paperknife', - 624: 'library', - 625: 'lifeboat', - 626: 'lighter, light, igniter, ignitor', - 627: 'limousine, limo', - 628: 'liner, ocean liner', - 629: 'lipstick, lip rouge', - 630: 'Loafer', - 631: 'lotion', - 632: 'loudspeaker, speaker, speaker unit, loudspeaker system, speaker ' + - 'system', - 633: 'loupe, jeweler\'s loupe', - 634: 'lumbermill, sawmill', - 635: 'magnetic compass', - 636: 'mailbag, postbag', - 637: 'mailbox, letter box', - 638: 'maillot', - 639: 'maillot, tank suit', - 640: 'manhole cover', - 641: 'maraca', - 642: 'marimba, xylophone', - 643: 'mask', - 644: 'matchstick', - 645: 'maypole', - 646: 'maze, labyrinth', - 647: 'measuring cup', - 648: 'medicine chest, medicine cabinet', - 649: 'megalith, megalithic structure', - 650: 'microphone, mike', - 651: 'microwave, microwave oven', - 652: 'military uniform', - 653: 'milk can', - 654: 'minibus', - 655: 'miniskirt, mini', - 656: 'minivan', - 657: 'missile', - 658: 'mitten', - 659: 'mixing bowl', - 660: 'mobile home, manufactured home', - 661: 'Model T', - 662: 'modem', - 663: 'monastery', - 664: 'monitor', - 665: 'moped', - 666: 'mortar', - 667: 'mortarboard', - 668: 'mosque', - 669: 'mosquito net', - 670: 'motor scooter, scooter', - 671: 'mountain bike, all-terrain bike, off-roader', - 672: 'mountain tent', - 673: 'mouse, computer mouse', - 674: 'mousetrap', - 675: 'moving van', - 676: 'muzzle', - 677: 'nail', - 678: 'neck brace', - 679: 'necklace', - 680: 'nipple', - 681: 'notebook, notebook computer', - 682: 'obelisk', - 683: 'oboe, hautboy, hautbois', - 684: 'ocarina, sweet potato', - 685: 'odometer, hodometer, mileometer, milometer', - 686: 'oil filter', - 687: 'organ, pipe organ', - 688: 'oscilloscope, scope, cathode-ray oscilloscope, CRO', - 689: 'overskirt', - 690: 'oxcart', - 691: 'oxygen mask', - 692: 'packet', - 693: 'paddle, boat paddle', - 694: 'paddlewheel, paddle wheel', - 695: 'padlock', - 696: 'paintbrush', - 697: 'pajama, pyjama, pj\'s, jammies', - 698: 'palace', - 699: 'panpipe, pandean pipe, syrinx', - 700: 'paper towel', - 701: 'parachute, chute', - 702: 'parallel bars, bars', - 703: 'park bench', - 704: 'parking meter', - 705: 'passenger car, coach, carriage', - 706: 'patio, terrace', - 707: 'pay-phone, pay-station', - 708: 'pedestal, plinth, footstall', - 709: 'pencil box, pencil case', - 710: 'pencil sharpener', - 711: 'perfume, essence', - 712: 'Petri dish', - 713: 'photocopier', - 714: 'pick, plectrum, plectron', - 715: 'pickelhaube', - 716: 'picket fence, paling', - 717: 'pickup, pickup truck', - 718: 'pier', - 719: 'piggy bank, penny bank', - 720: 'pill bottle', - 721: 'pillow', - 722: 'ping-pong ball', - 723: 'pinwheel', - 724: 'pirate, pirate ship', - 725: 'pitcher, ewer', - 726: 'plane, carpenter\'s plane, woodworking plane', - 727: 'planetarium', - 728: 'plastic bag', - 729: 'plate rack', - 730: 'plow, plough', - 731: 'plunger, plumber\'s helper', - 732: 'Polaroid camera, Polaroid Land camera', - 733: 'pole', - 734: 'police van, police wagon, paddy wagon, patrol wagon, wagon, black ' + - 'Maria', - 735: 'poncho', - 736: 'pool table, billiard table, snooker table', - 737: 'pop bottle, soda bottle', - 738: 'pot, flowerpot', - 739: 'potter\'s wheel', - 740: 'power drill', - 741: 'prayer rug, prayer mat', - 742: 'printer', - 743: 'prison, prison house', - 744: 'projectile, missile', - 745: 'projector', - 746: 'puck, hockey puck', - 747: 'punching bag, punch bag, punching ball, punchball', - 748: 'purse', - 749: 'quill, quill pen', - 750: 'quilt, comforter, comfort, puff', - 751: 'racer, race car, racing car', - 752: 'racket, racquet', - 753: 'radiator', - 754: 'radio, wireless', - 755: 'radio telescope, radio reflector', - 756: 'rain barrel', - 757: 'recreational vehicle, RV, R.V.', - 758: 'reel', - 759: 'reflex camera', - 760: 'refrigerator, icebox', - 761: 'remote control, remote', - 762: 'restaurant, eating house, eating place, eatery', - 763: 'revolver, six-gun, six-shooter', - 764: 'rifle', - 765: 'rocking chair, rocker', - 766: 'rotisserie', - 767: 'rubber eraser, rubber, pencil eraser', - 768: 'rugby ball', - 769: 'rule, ruler', - 770: 'running shoe', - 771: 'safe', - 772: 'safety pin', - 773: 'saltshaker, salt shaker', - 774: 'sandal', - 775: 'sarong', - 776: 'sax, saxophone', - 777: 'scabbard', - 778: 'scale, weighing machine', - 779: 'school bus', - 780: 'schooner', - 781: 'scoreboard', - 782: 'screen, CRT screen', - 783: 'screw', - 784: 'screwdriver', - 785: 'seat belt, seatbelt', - 786: 'sewing machine', - 787: 'shield, buckler', - 788: 'shoe shop, shoe-shop, shoe store', - 789: 'shoji', - 790: 'shopping basket', - 791: 'shopping cart', - 792: 'shovel', - 793: 'shower cap', - 794: 'shower curtain', - 795: 'ski', - 796: 'ski mask', - 797: 'sleeping bag', - 798: 'slide rule, slipstick', - 799: 'sliding door', - 800: 'slot, one-armed bandit', - 801: 'snorkel', - 802: 'snowmobile', - 803: 'snowplow, snowplough', - 804: 'soap dispenser', - 805: 'soccer ball', - 806: 'sock', - 807: 'solar dish, solar collector, solar furnace', - 808: 'sombrero', - 809: 'soup bowl', - 810: 'space bar', - 811: 'space heater', - 812: 'space shuttle', - 813: 'spatula', - 814: 'speedboat', - 815: 'spider web, spider\'s web', - 816: 'spindle', - 817: 'sports car, sport car', - 818: 'spotlight, spot', - 819: 'stage', - 820: 'steam locomotive', - 821: 'steel arch bridge', - 822: 'steel drum', - 823: 'stethoscope', - 824: 'stole', - 825: 'stone wall', - 826: 'stopwatch, stop watch', - 827: 'stove', - 828: 'strainer', - 829: 'streetcar, tram, tramcar, trolley, trolley car', - 830: 'stretcher', - 831: 'studio couch, day bed', - 832: 'stupa, tope', - 833: 'submarine, pigboat, sub, U-boat', - 834: 'suit, suit of clothes', - 835: 'sundial', - 836: 'sunglass', - 837: 'sunglasses, dark glasses, shades', - 838: 'sunscreen, sunblock, sun blocker', - 839: 'suspension bridge', - 840: 'swab, swob, mop', - 841: 'sweatshirt', - 842: 'swimming trunks, bathing trunks', - 843: 'swing', - 844: 'switch, electric switch, electrical switch', - 845: 'syringe', - 846: 'table lamp', - 847: 'tank, army tank, armored combat vehicle, armoured combat vehicle', - 848: 'tape player', - 849: 'teapot', - 850: 'teddy, teddy bear', - 851: 'television, television system', - 852: 'tennis ball', - 853: 'thatch, thatched roof', - 854: 'theater curtain, theatre curtain', - 855: 'thimble', - 856: 'thresher, thrasher, threshing machine', - 857: 'throne', - 858: 'tile roof', - 859: 'toaster', - 860: 'tobacco shop, tobacconist shop, tobacconist', - 861: 'toilet seat', - 862: 'torch', - 863: 'totem pole', - 864: 'tow truck, tow car, wrecker', - 865: 'toyshop', - 866: 'tractor', - 867: 'trailer truck, tractor trailer, trucking rig, rig, articulated ' + - 'lorry, semi', - 868: 'tray', - 869: 'trench coat', - 870: 'tricycle, trike, velocipede', - 871: 'trimaran', - 872: 'tripod', - 873: 'triumphal arch', - 874: 'trolleybus, trolley coach, trackless trolley', - 875: 'trombone', - 876: 'tub, vat', - 877: 'turnstile', - 878: 'typewriter keyboard', - 879: 'umbrella', - 880: 'unicycle, monocycle', - 881: 'upright, upright piano', - 882: 'vacuum, vacuum cleaner', - 883: 'vase', - 884: 'vault', - 885: 'velvet', - 886: 'vending machine', - 887: 'vestment', - 888: 'viaduct', - 889: 'violin, fiddle', - 890: 'volleyball', - 891: 'waffle iron', - 892: 'wall clock', - 893: 'wallet, billfold, notecase, pocketbook', - 894: 'wardrobe, closet, press', - 895: 'warplane, military plane', - 896: 'washbasin, handbasin, washbowl, lavabo, wash-hand basin', - 897: 'washer, automatic washer, washing machine', - 898: 'water bottle', - 899: 'water jug', - 900: 'water tower', - 901: 'whiskey jug', - 902: 'whistle', - 903: 'wig', - 904: 'window screen', - 905: 'window shade', - 906: 'Windsor tie', - 907: 'wine bottle', - 908: 'wing', - 909: 'wok', - 910: 'wooden spoon', - 911: 'wool, woolen, woollen', - 912: 'worm fence, snake fence, snake-rail fence, Virginia fence', - 913: 'wreck', - 914: 'yawl', - 915: 'yurt', - 916: 'web site, website, internet site, site', - 917: 'comic book', - 918: 'crossword puzzle, crossword', - 919: 'street sign', - 920: 'traffic light, traffic signal, stoplight', - 921: 'book jacket, dust cover, dust jacket, dust wrapper', - 922: 'menu', - 923: 'plate', - 924: 'guacamole', - 925: 'consomme', - 926: 'hot pot, hotpot', - 927: 'trifle', - 928: 'ice cream, icecream', - 929: 'ice lolly, lolly, lollipop, popsicle', - 930: 'French loaf', - 931: 'bagel, beigel', - 932: 'pretzel', - 933: 'cheeseburger', - 934: 'hotdog, hot dog, red hot', - 935: 'mashed potato', - 936: 'head cabbage', - 937: 'broccoli', - 938: 'cauliflower', - 939: 'zucchini, courgette', - 940: 'spaghetti squash', - 941: 'acorn squash', - 942: 'butternut squash', - 943: 'cucumber, cuke', - 944: 'artichoke, globe artichoke', - 945: 'bell pepper', - 946: 'cardoon', - 947: 'mushroom', - 948: 'Granny Smith', - 949: 'strawberry', - 950: 'orange', - 951: 'lemon', - 952: 'fig', - 953: 'pineapple, ananas', - 954: 'banana', - 955: 'jackfruit, jak, jack', - 956: 'custard apple', - 957: 'pomegranate', - 958: 'hay', - 959: 'carbonara', - 960: 'chocolate sauce, chocolate syrup', - 961: 'dough', - 962: 'meat loaf, meatloaf', - 963: 'pizza, pizza pie', - 964: 'potpie', - 965: 'burrito', - 966: 'red wine', - 967: 'espresso', - 968: 'cup', - 969: 'eggnog', - 970: 'alp', - 971: 'bubble', - 972: 'cliff, drop, drop-off', - 973: 'coral reef', - 974: 'geyser', - 975: 'lakeside, lakeshore', - 976: 'promontory, headland, head, foreland', - 977: 'sandbar, sand bar', - 978: 'seashore, coast, seacoast, sea-coast', - 979: 'valley, vale', - 980: 'volcano', - 981: 'ballplayer, baseball player', - 982: 'groom, bridegroom', - 983: 'scuba diver', - 984: 'rapeseed', - 985: 'daisy', - 986: 'yellow lady\'s slipper, yellow lady-slipper, Cypripedium calceolus, ' + - 'Cypripedium parviflorum', - 987: 'corn', - 988: 'acorn', - 989: 'hip, rose hip, rosehip', - 990: 'buckeye, horse chestnut, conker', - 991: 'coral fungus', - 992: 'agaric', - 993: 'gyromitra', - 994: 'stinkhorn, carrion fungus', - 995: 'earthstar', - 996: 'hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola ' + - 'frondosa', - 997: 'bolete', - 998: 'ear, spike, capitulum', - 999: 'toilet tissue, toilet paper, bathroom tissue' -}; - -},{}],7:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var squeezenet_1 = require("./squeezenet"); -exports.SqueezeNet = squeezenet_1.SqueezeNet; - -},{"./squeezenet":8}],8:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dl = require("deeplearn"); -var model_util = require("../util"); -var imagenet_classes_1 = require("./imagenet_classes"); -var GOOGLE_CLOUD_STORAGE_DIR = 'https://storage.googleapis.com/learnjs-data/checkpoint_zoo/'; -var SqueezeNet = (function () { - function SqueezeNet() { - this.preprocessOffset = dl.tensor1d([103.939, 116.779, 123.68]); - } - SqueezeNet.prototype.load = function () { - return __awaiter(this, void 0, void 0, function () { - var checkpointLoader, _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - checkpointLoader = new dl.CheckpointLoader(GOOGLE_CLOUD_STORAGE_DIR + 'squeezenet1_1/'); - _a = this; - return [4, checkpointLoader.getAllVariables()]; - case 1: - _a.variables = _b.sent(); - return [2]; - } - }); - }); - }; - SqueezeNet.prototype.predict = function (input) { - return this.predictWithActivation(input).logits; - }; - SqueezeNet.prototype.predictWithActivation = function (input, activationName) { - var _this = this; - return dl.tidy(function () { - var activation; - var preprocessedInput = dl.sub(input.asType('float32'), _this.preprocessOffset); - var conv1relu = preprocessedInput - .conv2d(_this.variables['conv1_W:0'], 2, 0) - .add(_this.variables['conv1_b:0']) - .relu(); - if (activationName === 'conv_1') { - activation = conv1relu; - } - var pool1 = conv1relu.maxPool(3, 2, 0); - if (activationName === 'maxpool_1') { - activation = pool1; - } - var fire2 = _this.fireModule(pool1, 2); - if (activationName === 'fire2') { - activation = fire2; - } - var fire3 = _this.fireModule(fire2, 3); - if (activationName === 'fire3') { - activation = fire3; - } - var pool2 = fire3.maxPool(3, 2, 'valid'); - if (activationName === 'maxpool_2') { - activation = pool2; - } - var fire4 = _this.fireModule(pool2, 4); - if (activationName === 'fire4') { - activation = fire4; - } - var fire5 = _this.fireModule(fire4, 5); - if (activationName === 'fire5') { - activation = fire5; - } - var pool3 = fire5.maxPool(3, 2, 0); - if (activationName === 'maxpool_3') { - activation = pool3; - } - var fire6 = _this.fireModule(pool3, 6); - if (activationName === 'fire6') { - activation = fire6; - } - var fire7 = _this.fireModule(fire6, 7); - if (activationName === 'fire7') { - activation = fire7; - } - var fire8 = _this.fireModule(fire7, 8); - if (activationName === 'fire8') { - activation = fire8; - } - var fire9 = _this.fireModule(fire8, 9); - if (activationName === 'fire9') { - activation = fire9; - } - var conv10 = fire9.conv2d(_this.variables['conv10_W:0'], 1, 0) - .add(_this.variables['conv10_b:0']); - if (activationName === 'conv10') { - activation = conv10; - } - return { - logits: dl.avgPool(conv10, conv10.shape[0], 1, 0).as1D(), - activation: activation - }; - }); - }; - SqueezeNet.prototype.fireModule = function (input, fireId) { - var y = dl.conv2d(input, this.variables["fire" + fireId + "/squeeze1x1_W:0"], 1, 0) - .add(this.variables["fire" + fireId + "/squeeze1x1_b:0"]) - .relu(); - var left = dl.conv2d(y, this.variables["fire" + fireId + "/expand1x1_W:0"], 1, 0) - .add(this.variables["fire" + fireId + "/expand1x1_b:0"]) - .relu(); - var right = dl.conv2d(y, this.variables["fire" + fireId + "/expand3x3_W:0"], 1, 1) - .add(this.variables["fire" + fireId + "/expand3x3_b:0"]) - .relu(); - return left.concat(right, 2); - }; - SqueezeNet.prototype.getTopKClasses = function (logits, topK) { - return __awaiter(this, void 0, void 0, function () { - var predictions, topk, _a, _b, topkIndices, topkValues, topClassesToProbability, i; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - predictions = dl.tidy(function () { - return dl.softmax(logits).asType('float32'); - }); - _b = (_a = model_util).topK; - return [4, predictions.data()]; - case 1: - topk = _b.apply(_a, [_c.sent(), topK]); - predictions.dispose(); - topkIndices = topk.indices; - topkValues = topk.values; - topClassesToProbability = {}; - for (i = 0; i < topkIndices.length; i++) { - topClassesToProbability[imagenet_classes_1.IMAGENET_CLASSES[topkIndices[i]]] = topkValues[i]; - } - return [2, topClassesToProbability]; - } - }); - }); - }; - SqueezeNet.prototype.dispose = function () { - this.preprocessOffset.dispose(); - for (var varName in this.variables) { - this.variables[varName].dispose(); - } - }; - return SqueezeNet; -}()); -exports.SqueezeNet = SqueezeNet; - -},{"../util":9,"./imagenet_classes":6,"deeplearn":67}],9:[function(require,module,exports){ -arguments[4][5][0].apply(exports,arguments) -},{"dup":5}],10:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var BrowserUtil = (function () { - function BrowserUtil() { - } - BrowserUtil.nextFrame = function () { - return new Promise(function (resolve) { return requestAnimationFrame(function () { return resolve(); }); }); - }; - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Timing' }) - ], BrowserUtil, "nextFrame", null); - return BrowserUtil; -}()); -exports.BrowserUtil = BrowserUtil; - -},{"./doc":32}],11:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var BatchDataset = (function () { - function BatchDataset(base, batchSize, smallLastBatch) { - if (smallLastBatch === void 0) { smallLastBatch = true; } - this.base = base; - this.batchSize = batchSize; - this.smallLastBatch = smallLastBatch; - } - BatchDataset.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - var batchesAsArrays; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.base.getStream()]; - case 1: - batchesAsArrays = (_a.sent()) - .batch(this.batchSize, this.smallLastBatch); - return [2, batchesAsArrays.map(makeDatasetBatch)]; - } - }); - }); - }; - return BatchDataset; -}()); -exports.BatchDataset = BatchDataset; -function makeDatasetBatch(elements) { - var rotated = {}; - var firstElement = elements[0]; - var keys = Object.keys(firstElement); - keys.forEach(function (key) { - rotated[key] = []; - }); - var _loop_1 = function (e) { - keys.forEach(function (key) { - var value = e[key]; - rotated[key].push(value); - }); - }; - for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) { - var e = elements_1[_i]; - _loop_1(e); - } - var result = {}; - for (var _a = 0, keys_1 = keys; _a < keys_1.length; _a++) { - var key = keys_1[_a]; - if (rotated[key].length !== elements.length) { - throw new Error("Batching failed to get a '" + key + "' value for each element."); - } - if (typeof rotated[key][0] === 'string') { - result[key] = rotated[key]; - } - else { - result[key] = batchConcat(rotated[key]); - } - } - return result; -} -function batchConcat(arrays) { - var elementShape = shapeAndValues(arrays[0])[0]; - var batchShape = [arrays.length].concat(elementShape); - var resultVals = new Float32Array(batchShape.reduce(function (x, y) { return x * y; })); - var offset = 0; - for (var _i = 0, arrays_1 = arrays; _i < arrays_1.length; _i++) { - var a = arrays_1[_i]; - var _a = shapeAndValues(a), aShape = _a[0], aVals = _a[1]; - if (!util.arraysEqual(aShape, elementShape)) { - throw new Error('Elements must have the same shape to be batched'); - } - resultVals.set(aVals, offset); - offset += aVals.length; - } - var result = tensor_1.Tensor.make(batchShape, { values: resultVals }); - return result; -} -function shapeAndValues(array) { - if (array instanceof tensor_1.Tensor) { - return [array.shape, array.dataSync()]; - } - else if (Array.isArray(array)) { - return [[array.length], array]; - } - else { - return [[], [array]]; - } -} - -},{"../../tensor":146,"../../util":151}],12:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var batch_dataset_1 = require("./batch_dataset"); -var statistics_1 = require("./statistics"); -var data_stream_1 = require("./streams/data_stream"); -var data_stream_2 = require("./streams/data_stream"); -var data_stream_3 = require("./streams/data_stream"); -var Dataset = (function () { - function Dataset() { - } - Dataset.prototype.computeStatistics = function (sampleSize, shuffleWindowSize) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, statistics_1.computeDatasetStatistics(this, sampleSize, shuffleWindowSize)]; - }); - }); - }; - Dataset.prototype.filter = function (filterer) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).filter(filterer)]; - } - }); - }); }); - }; - Dataset.prototype.map = function (transform) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).map(transform)]; - } - }); - }); }); - }; - Dataset.prototype.batch = function (batchSize, smallLastBatch) { - if (smallLastBatch === void 0) { smallLastBatch = true; } - return new batch_dataset_1.BatchDataset(this, batchSize, smallLastBatch); - }; - Dataset.prototype.concatenate = function (dataset) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: return [4, base.getStream()]; - case 1: - _b = (_a = (_c.sent())).concatenate; - return [4, dataset.getStream()]; - case 2: return [2, _b.apply(_a, [_c.sent()])]; - } - }); - }); }); - }; - Dataset.prototype.repeat = function (count) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var streamStream; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - streamStream = data_stream_2.streamFromFunction(function () { return base.getStream(); }); - return [4, data_stream_1.streamFromConcatenated(streamStream.take(count))]; - case 1: return [2, (_a.sent())]; - } - }); - }); }); - }; - Dataset.prototype.take = function (count) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).take(count)]; - } - }); - }); }); - }; - Dataset.prototype.skip = function (count) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).skip(count)]; - } - }); - }); }); - }; - Dataset.prototype.shuffle = function (bufferSize, seed, reshuffleEachIteration) { - var _this = this; - if (reshuffleEachIteration === void 0) { reshuffleEachIteration = true; } - var base = this; - var random = seedrandom(seed); - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var seed2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - seed2 = random.int32(); - if (reshuffleEachIteration) { - seed2 += random.int32(); - } - return [4, base.getStream()]; - case 1: return [2, (_a.sent()).shuffle(bufferSize, seed2.toString())]; - } - }); - }); }); - }; - Dataset.prototype.prefetch = function (bufferSize) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).prefetch(bufferSize)]; - } - }); - }); }); - }; - return Dataset; -}()); -exports.Dataset = Dataset; -function datasetFromStreamFn(getStreamFn) { - return new (function (_super) { - __extends(class_1, _super); - function class_1() { - return _super !== null && _super.apply(this, arguments) || this; - } - class_1.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, getStreamFn()]; - }); - }); - }; - return class_1; - }(Dataset))(); -} -exports.datasetFromStreamFn = datasetFromStreamFn; -function datasetFromElements(items) { - var _this = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, Promise.resolve(data_stream_3.streamFromItems(items))]; - }); - }); }); -} -exports.datasetFromElements = datasetFromElements; -function datasetFromConcatenated(datasets) { - var _this = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var streamStream; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, Promise.all(datasets.map(function (d) { return d.getStream(); }))]; - case 1: - streamStream = _a.sent(); - return [2, data_stream_1.streamFromConcatenated(data_stream_3.streamFromItems(streamStream))]; - } - }); - }); }); -} -exports.datasetFromConcatenated = datasetFromConcatenated; - -},{"./batch_dataset":11,"./statistics":18,"./streams/data_stream":20,"seedrandom":153}],13:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dataset_1 = require("../dataset"); -var text_line_dataset_1 = require("./text_line_dataset"); -var CsvHeaderConfig; -(function (CsvHeaderConfig) { - CsvHeaderConfig[CsvHeaderConfig["READ_FIRST_LINE"] = 0] = "READ_FIRST_LINE"; - CsvHeaderConfig[CsvHeaderConfig["NUMBERED"] = 1] = "NUMBERED"; -})(CsvHeaderConfig = exports.CsvHeaderConfig || (exports.CsvHeaderConfig = {})); -var CSVDataset = (function (_super) { - __extends(CSVDataset, _super); - function CSVDataset(input) { - var _this = _super.call(this) || this; - _this.input = input; - _this.hasHeaderLine = false; - _this.base = new text_line_dataset_1.TextLineDataset(input, CSVDataset.textColumnName); - return _this; - } - Object.defineProperty(CSVDataset.prototype, "csvColumnNames", { - get: function () { - return this._csvColumnNames; - }, - enumerable: true, - configurable: true - }); - CSVDataset.prototype.setCsvColumnNames = function (csvColumnNames) { - return __awaiter(this, void 0, void 0, function () { - var stream, firstElement, firstLine, stream, firstElement, firstLine; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(csvColumnNames == null || csvColumnNames === CsvHeaderConfig.NUMBERED)) return [3, 3]; - return [4, this.base.getStream()]; - case 1: - stream = _a.sent(); - return [4, stream.next()]; - case 2: - firstElement = _a.sent(); - firstLine = firstElement[CSVDataset.textColumnName]; - this._csvColumnNames = - Array.from(firstLine.split(',').keys()).map(function (x) { return x.toString(); }); - return [3, 7]; - case 3: - if (!(csvColumnNames === CsvHeaderConfig.READ_FIRST_LINE)) return [3, 6]; - return [4, this.base.getStream()]; - case 4: - stream = _a.sent(); - return [4, stream.next()]; - case 5: - firstElement = _a.sent(); - firstLine = firstElement[CSVDataset.textColumnName]; - this._csvColumnNames = firstLine.split(','); - this.hasHeaderLine = true; - return [3, 7]; - case 6: - this._csvColumnNames = csvColumnNames; - _a.label = 7; - case 7: return [2]; - } - }); - }); - }; - CSVDataset.create = function (input, csvColumnNames) { - if (csvColumnNames === void 0) { csvColumnNames = CsvHeaderConfig.NUMBERED; } - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - result = new CSVDataset(input); - return [4, result.setCsvColumnNames(csvColumnNames)]; - case 1: - _a.sent(); - return [2, result]; - } - }); - }); - }; - CSVDataset.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - var lines; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.base.getStream()]; - case 1: - lines = _a.sent(); - if (this.hasHeaderLine) { - lines = lines.skip(1); - } - return [2, lines.map(function (x) { return _this.makeDatasetElement(x); })]; - } - }); - }); - }; - CSVDataset.prototype.makeDatasetElement = function (element) { - var line = element[CSVDataset.textColumnName]; - var values = line.split(','); - var result = {}; - for (var i = 0; i < this._csvColumnNames.length; i++) { - var value = values[i]; - if (value === '') { - result[this._csvColumnNames[i]] = undefined; - } - else { - var valueAsNum = Number(value); - if (isNaN(valueAsNum)) { - result[this._csvColumnNames[i]] = value; - } - else { - result[this._csvColumnNames[i]] = valueAsNum; - } - } - } - return result; - }; - CSVDataset.textColumnName = 'line'; - return CSVDataset; -}(dataset_1.Dataset)); -exports.CSVDataset = CSVDataset; - -},{"../dataset":12,"./text_line_dataset":14}],14:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dataset_1 = require("../dataset"); -var TextLineDataset = (function (_super) { - __extends(TextLineDataset, _super); - function TextLineDataset(input, columnName) { - if (columnName === void 0) { columnName = 'line'; } - var _this = _super.call(this) || this; - _this.input = input; - _this.columnName = columnName; - return _this; - } - TextLineDataset.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - var readStream, utf8Stream, lineStream; - return __generator(this, function (_a) { - readStream = this.input.getStream(); - utf8Stream = readStream.decodeUTF8(); - lineStream = utf8Stream.split('\n'); - return [2, lineStream.map(function (x) { - return (_a = {}, _a[_this.columnName] = x, _a); - var _a; - })]; - }); - }); - }; - return TextLineDataset; -}(dataset_1.Dataset)); -exports.TextLineDataset = TextLineDataset; - -},{"../dataset":12}],15:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var DataSource = (function () { - function DataSource() { - } - return DataSource; -}()); -exports.DataSource = DataSource; - -},{}],16:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var datasource_1 = require("../datasource"); -var filereader_stream_1 = require("../streams/filereader_stream"); -var FileDataSource = (function (_super) { - __extends(FileDataSource, _super); - function FileDataSource(input, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.input = input; - _this.options = options; - return _this; - } - FileDataSource.prototype.getStream = function () { - return new filereader_stream_1.FileReaderStream(this.input, this.options); - }; - return FileDataSource; -}(datasource_1.DataSource)); -exports.FileDataSource = FileDataSource; - -},{"../datasource":15,"../streams/filereader_stream":21}],17:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var datasource_1 = require("../datasource"); -var url_stream_1 = require("../streams/url_stream"); -var URLDataSource = (function (_super) { - __extends(URLDataSource, _super); - function URLDataSource(url, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.url = url; - _this.options = options; - return _this; - } - URLDataSource.prototype.getStream = function () { - return new url_stream_1.URLStream(this.url, this.options); - }; - return URLDataSource; -}(datasource_1.DataSource)); -exports.URLDataSource = URLDataSource; - -},{"../datasource":15,"../streams/url_stream":23}],18:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../../tensor"); -function scaleTo01(min, max) { - var range = max - min; - var minTensor = tensor_1.Scalar.new(min); - var rangeTensor = tensor_1.Scalar.new(range); - return function (value) { - if (typeof (value) === 'string') { - throw new Error('Can\'t scale a string.'); - } - else { - if (value instanceof tensor_1.Tensor) { - var result = value.sub(minTensor).div(rangeTensor); - return result; - } - else if (value instanceof Array) { - return value.map(function (v) { return (v - min) / range; }); - } - else { - return (value - min) / range; - } - } - }; -} -exports.scaleTo01 = scaleTo01; -function computeDatasetStatistics(dataset, sampleSize, shuffleWindowSize) { - return __awaiter(this, void 0, void 0, function () { - var stream, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, dataset.getStream()]; - case 1: - stream = _a.sent(); - if (shuffleWindowSize != null) { - stream = stream.shuffle(shuffleWindowSize); - } - if (sampleSize != null) { - stream = stream.take(sampleSize); - } - result = {}; - return [4, stream.forEach(function (e) { - for (var key in e) { - var value = e[key]; - if (typeof (value) === 'string') { - } - else { - var recordMin = void 0; - var recordMax = void 0; - if (value instanceof tensor_1.Tensor) { - recordMin = value.min().dataSync()[0]; - recordMax = value.max().dataSync()[0]; - } - else if (value instanceof Array) { - recordMin = value.reduce(function (a, b) { return Math.min(a, b); }); - recordMax = value.reduce(function (a, b) { return Math.max(a, b); }); - } - else if (!isNaN(value) && isFinite(value)) { - recordMin = value; - recordMax = value; - } - else { - throw new Error("Cannot compute statistics: " + key + " = " + value); - } - var columnStats = result[key]; - if (columnStats == null) { - columnStats = { - min: Number.POSITIVE_INFINITY, - max: Number.NEGATIVE_INFINITY - }; - result[key] = columnStats; - } - columnStats.min = Math.min(columnStats.min, recordMin); - columnStats.max = Math.max(columnStats.max, recordMax); - } - } - return {}; - })]; - case 2: - _a.sent(); - return [2, result]; - } - }); - }); -} -exports.computeDatasetStatistics = computeDatasetStatistics; - -},{"../../tensor":146}],19:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var utf8 = require("utf8"); -var data_stream_1 = require("./data_stream"); -var string_stream_1 = require("./string_stream"); -var ByteStream = (function (_super) { - __extends(ByteStream, _super); - function ByteStream() { - return _super !== null && _super.apply(this, arguments) || this; - } - ByteStream.prototype.decodeUTF8 = function () { - return new Utf8Stream(this); - }; - return ByteStream; -}(data_stream_1.DataStream)); -exports.ByteStream = ByteStream; -var Utf8Stream = (function (_super) { - __extends(Utf8Stream, _super); - function Utf8Stream(upstream) { - var _this = _super.call(this) || this; - _this.impl = new Utf8StreamImpl(upstream); - return _this; - } - Utf8Stream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.impl.next()]; - }); - }); - }; - return Utf8Stream; -}(string_stream_1.StringStream)); -var Utf8StreamImpl = (function (_super) { - __extends(Utf8StreamImpl, _super); - function Utf8StreamImpl(upstream) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.partial = new Uint8Array([]); - _this.partialBytesValid = 0; - return _this; - } - Utf8StreamImpl.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var chunk, partialBytesRemaining, nextIndex, okUpToIndex, splitUtfWidth, bulk, reassembled; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - chunk = _a.sent(); - if (chunk == null) { - if (this.partial.length === 0) { - return [2, false]; - } - chunk = new Uint8Array([]); - } - partialBytesRemaining = this.partial.length - this.partialBytesValid; - nextIndex = partialBytesRemaining; - okUpToIndex = nextIndex; - splitUtfWidth = 0; - while (nextIndex < chunk.length) { - okUpToIndex = nextIndex; - splitUtfWidth = utfWidth(chunk[nextIndex]); - nextIndex = okUpToIndex + splitUtfWidth; - } - if (nextIndex === chunk.length) { - okUpToIndex = nextIndex; - } - bulk = utf8.decode(String.fromCharCode.apply(null, chunk.slice(partialBytesRemaining, okUpToIndex))); - if (partialBytesRemaining > 0) { - this.partial.set(chunk.slice(0, partialBytesRemaining), this.partialBytesValid); - reassembled = utf8.decode(String.fromCharCode.apply(null, this.partial)); - this.outputQueue.push(reassembled + bulk); - } - else { - this.outputQueue.push(bulk); - } - if (okUpToIndex === chunk.length) { - this.partial = new Uint8Array([]); - this.partialBytesValid = 0; - } - else { - this.partial = new Uint8Array(new ArrayBuffer(splitUtfWidth)); - this.partial.set(chunk.slice(okUpToIndex), 0); - this.partialBytesValid = chunk.length - okUpToIndex; - } - return [2, true]; - } - }); - }); - }; - return Utf8StreamImpl; -}(data_stream_1.QueueStream)); -function utfWidth(firstByte) { - if (firstByte >= 252) - return 6; - else if (firstByte >= 248) - return 5; - else if (firstByte >= 240) - return 4; - else if (firstByte >= 224) - return 3; - else if (firstByte >= 192) - return 2; - else - return 1; -} - -},{"./data_stream":20,"./string_stream":22,"utf8":161}],20:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var growing_ring_buffer_1 = require("../util/growing_ring_buffer"); -var ring_buffer_1 = require("../util/ring_buffer"); -function streamFromItems(items) { - return new ArrayStream(items); -} -exports.streamFromItems = streamFromItems; -function streamFromIncrementing(start) { - var i = start; - return streamFromFunction(function () { return i++; }); -} -exports.streamFromIncrementing = streamFromIncrementing; -function streamFromFunction(func) { - return new FunctionCallStream(func); -} -exports.streamFromFunction = streamFromFunction; -function streamFromConcatenated(baseStreams) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, ChainedStream.create(baseStreams)]; - }); - }); -} -exports.streamFromConcatenated = streamFromConcatenated; -function streamFromConcatenatedFunction(streamFunc, count) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, streamFromConcatenated(streamFromFunction(streamFunc).take(count))]; - }); - }); -} -exports.streamFromConcatenatedFunction = streamFromConcatenatedFunction; -var DataStream = (function () { - function DataStream() { - } - DataStream.prototype.collectRemaining = function () { - return __awaiter(this, void 0, void 0, function () { - var result, x; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - result = []; - return [4, this.next()]; - case 1: - x = _a.sent(); - _a.label = 2; - case 2: - if (!(x != null)) return [3, 4]; - result.push(x); - return [4, this.next()]; - case 3: - x = _a.sent(); - return [3, 2]; - case 4: return [2, result]; - } - }); - }); - }; - DataStream.prototype.resolveFully = function () { - return __awaiter(this, void 0, void 0, function () { - var x; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.next()]; - case 1: - x = _a.sent(); - _a.label = 2; - case 2: - if (!(x != null)) return [3, 4]; - return [4, this.next()]; - case 3: - x = _a.sent(); - return [3, 2]; - case 4: return [2]; - } - }); - }); - }; - DataStream.prototype.filter = function (predicate) { - return new FilterStream(this, predicate); - }; - DataStream.prototype.map = function (transform) { - return new MapStream(this, transform); - }; - DataStream.prototype.forEach = function (f) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.map(f).resolveFully()]; - }); - }); - }; - DataStream.prototype.batch = function (batchSize, smallLastBatch) { - if (smallLastBatch === void 0) { smallLastBatch = true; } - return new BatchStream(this, batchSize, smallLastBatch); - }; - DataStream.prototype.concatenate = function (stream) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, ChainedStream.create(new ArrayStream([this, stream]))]; - }); - }); - }; - DataStream.prototype.take = function (count) { - if (count < 0 || count == null) - return this; - return new TakeStream(this, count); - }; - DataStream.prototype.skip = function (count) { - if (count < 0 || count == null) - return this; - return new SkipStream(this, count); - }; - DataStream.prototype.prefetch = function (bufferSize) { - return new PrefetchStream(this, bufferSize); - }; - DataStream.prototype.shuffle = function (windowSize, seed) { - return new ShuffleStream(this, windowSize, seed); - }; - return DataStream; -}()); -exports.DataStream = DataStream; -var ArrayStream = (function (_super) { - __extends(ArrayStream, _super); - function ArrayStream(items) { - var _this = _super.call(this) || this; - _this.items = items; - _this.trav = 0; - return _this; - } - ArrayStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - if (this.trav >= this.items.length) { - return [2, undefined]; - } - result = this.items[this.trav]; - this.trav++; - return [2, result]; - }); - }); - }; - return ArrayStream; -}(DataStream)); -var FunctionCallStream = (function (_super) { - __extends(FunctionCallStream, _super); - function FunctionCallStream(nextFn) { - var _this = _super.call(this) || this; - _this.nextFn = nextFn; - return _this; - } - FunctionCallStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.nextFn()]; - }); - }); - }; - return FunctionCallStream; -}(DataStream)); -var SkipStream = (function (_super) { - __extends(SkipStream, _super); - function SkipStream(upstream, maxCount) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.maxCount = maxCount; - _this.count = 0; - return _this; - } - SkipStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var skipped; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.count++ < this.maxCount)) return [3, 2]; - return [4, this.upstream.next()]; - case 1: - skipped = _a.sent(); - if (skipped == null) { - return [2, undefined]; - } - return [3, 0]; - case 2: return [2, this.upstream.next()]; - } - }); - }); - }; - return SkipStream; -}(DataStream)); -var TakeStream = (function (_super) { - __extends(TakeStream, _super); - function TakeStream(upstream, maxCount) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.maxCount = maxCount; - _this.count = 0; - return _this; - } - TakeStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - if (this.count++ >= this.maxCount) { - return [2, undefined]; - } - return [2, this.upstream.next()]; - }); - }); - }; - return TakeStream; -}(DataStream)); -var QueueStream = (function (_super) { - __extends(QueueStream, _super); - function QueueStream() { - var _this = _super.call(this) || this; - _this.outputQueue = new growing_ring_buffer_1.GrowingRingBuffer(); - return _this; - } - QueueStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.outputQueue.length() === 0)) return [3, 2]; - return [4, this.pump()]; - case 1: - if (!(_a.sent())) { - return [2, undefined]; - } - return [3, 0]; - case 2: return [2, this.outputQueue.shift()]; - } - }); - }); - }; - return QueueStream; -}(DataStream)); -exports.QueueStream = QueueStream; -var BatchStream = (function (_super) { - __extends(BatchStream, _super); - function BatchStream(upstream, batchSize, enableSmallLastBatch) { - if (enableSmallLastBatch === void 0) { enableSmallLastBatch = true; } - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.batchSize = batchSize; - _this.enableSmallLastBatch = enableSmallLastBatch; - _this.currentBatch = []; - return _this; - } - BatchStream.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var item; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - item = _a.sent(); - if (item == null) { - if (this.enableSmallLastBatch && this.currentBatch.length > 0) { - this.outputQueue.push(this.currentBatch); - this.currentBatch = []; - return [2, true]; - } - return [2, false]; - } - this.currentBatch.push(item); - if (this.currentBatch.length === this.batchSize) { - this.outputQueue.push(this.currentBatch); - this.currentBatch = []; - } - return [2, true]; - } - }); - }); - }; - return BatchStream; -}(QueueStream)); -var FilterStream = (function (_super) { - __extends(FilterStream, _super); - function FilterStream(upstream, predicate) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.predicate = predicate; - return _this; - } - FilterStream.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var item, accept; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - item = _a.sent(); - if (item == null) { - return [2, false]; - } - accept = this.predicate(item); - if (!(accept instanceof Promise)) return [3, 3]; - return [4, accept]; - case 2: - accept = _a.sent(); - _a.label = 3; - case 3: - if (accept) { - this.outputQueue.push(item); - } - return [2, true]; - } - }); - }); - }; - return FilterStream; -}(QueueStream)); -var MapStream = (function (_super) { - __extends(MapStream, _super); - function MapStream(upstream, transform) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.transform = transform; - return _this; - } - MapStream.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var item, mapped; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - item = _a.sent(); - if (item == null) { - return [2, false]; - } - mapped = this.transform(item); - if (!(mapped instanceof Promise)) return [3, 3]; - return [4, mapped]; - case 2: - mapped = _a.sent(); - _a.label = 3; - case 3: - this.outputQueue.push(mapped); - return [2, true]; - } - }); - }); - }; - return MapStream; -}(QueueStream)); -var ChainState = (function () { - function ChainState(item, currentStream, moreStreams) { - this.item = item; - this.currentStream = currentStream; - this.moreStreams = moreStreams; - } - return ChainState; -}()); -function nextChainState(afterState) { - return __awaiter(this, void 0, void 0, function () { - var state, stream, item; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, afterState]; - case 1: - state = _a.sent(); - stream = state.currentStream; - if (stream == null) { - return [2, new ChainState(undefined, undefined, state.moreStreams)]; - } - return [4, stream.next()]; - case 2: - item = _a.sent(); - if (!(item == null)) return [3, 4]; - return [4, state.moreStreams.next()]; - case 3: - stream = _a.sent(); - return [2, nextChainState(Promise.resolve(new ChainState(undefined, stream, state.moreStreams)))]; - case 4: return [2, new ChainState(item, stream, state.moreStreams)]; - } - }); - }); -} -var ChainedStream = (function (_super) { - __extends(ChainedStream, _super); - function ChainedStream() { - return _super !== null && _super.apply(this, arguments) || this; - } - ChainedStream.create = function (baseStreams) { - return __awaiter(this, void 0, void 0, function () { - var c, currentStream; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - c = new ChainedStream(); - return [4, baseStreams.next()]; - case 1: - currentStream = _a.sent(); - c.currentPromise = - Promise.resolve(new ChainState(undefined, currentStream, baseStreams)); - return [2, c]; - } - }); - }); - }; - ChainedStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.currentPromise = nextChainState(this.currentPromise); - return [4, this.currentPromise]; - case 1: return [2, (_a.sent()).item]; - } - }); - }); - }; - return ChainedStream; -}(DataStream)); -exports.ChainedStream = ChainedStream; -var PrefetchStream = (function (_super) { - __extends(PrefetchStream, _super); - function PrefetchStream(upstream, bufferSize) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.bufferSize = bufferSize; - _this.total = 0; - _this.buffer = new ring_buffer_1.RingBuffer(bufferSize); - return _this; - } - PrefetchStream.prototype.refill = function () { - while (!this.buffer.isFull()) { - var v = this.upstream.next(); - if (v == null) { - return; - } - this.buffer.push(v); - } - }; - PrefetchStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.refill(); - if (this.buffer.isEmpty()) - return [2, undefined]; - return [4, this.buffer.shift()]; - case 1: - result = _a.sent(); - this.refill(); - return [2, result]; - } - }); - }); - }; - return PrefetchStream; -}(DataStream)); -exports.PrefetchStream = PrefetchStream; -var ShuffleStream = (function (_super) { - __extends(ShuffleStream, _super); - function ShuffleStream(upstream, windowSize, seed) { - var _this = _super.call(this, upstream, windowSize) || this; - _this.upstream = upstream; - _this.windowSize = windowSize; - _this.upstreamExhausted = false; - _this.random = seedrandom(seed); - return _this; - } - ShuffleStream.prototype.randomInt = function (max) { - return Math.floor(this.random() * max); - }; - ShuffleStream.prototype.chooseIndex = function () { - return this.randomInt(this.buffer.length()); - }; - ShuffleStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var chosenIndex, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!this.upstreamExhausted) { - this.refill(); - } - _a.label = 1; - case 1: - if (!!this.buffer.isEmpty()) return [3, 3]; - chosenIndex = this.chooseIndex(); - return [4, this.buffer.shuffleExcise(chosenIndex)]; - case 2: - result = _a.sent(); - if (result == null) { - this.upstreamExhausted = true; - } - else { - this.refill(); - return [2, result]; - } - return [3, 1]; - case 3: return [2, undefined]; - } - }); - }); - }; - return ShuffleStream; -}(PrefetchStream)); -exports.ShuffleStream = ShuffleStream; - -},{"../util/growing_ring_buffer":24,"../util/ring_buffer":25,"seedrandom":153}],21:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var byte_stream_1 = require("./byte_stream"); -var FileReaderStream = (function (_super) { - __extends(FileReaderStream, _super); - function FileReaderStream(file, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.file = file; - _this.options = options; - _this.offset = options.offset || 0; - _this.chunkSize = options.chunkSize || 1024 * 1024; - return _this; - } - FileReaderStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - var chunk; - return __generator(this, function (_a) { - if (this.offset >= this.file.size) { - return [2, undefined]; - } - chunk = new Promise(function (resolve, reject) { - var fileReader = new FileReader(); - fileReader.onload = function (event) { - var data = fileReader.result; - if (data instanceof ArrayBuffer) { - data = new Uint8Array(data); - } - if (!(data instanceof Uint8Array)) { - return reject(new TypeError('FileReader returned unknown type.')); - } - resolve(data); - }; - fileReader.onabort = function (event) { - return reject(new Error('Aborted')); - }; - fileReader.onerror = function (event) { - return reject(new Error(event.error)); - }; - var end = _this.offset + _this.chunkSize; - var slice = _this.file.slice(_this.offset, end); - fileReader.readAsArrayBuffer(slice); - _this.offset = end; - }); - return [2, chunk]; - }); - }); - }; - return FileReaderStream; -}(byte_stream_1.ByteStream)); -exports.FileReaderStream = FileReaderStream; - -},{"./byte_stream":19}],22:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var data_stream_1 = require("./data_stream"); -var StringStream = (function (_super) { - __extends(StringStream, _super); - function StringStream() { - return _super !== null && _super.apply(this, arguments) || this; - } - StringStream.prototype.split = function (separator) { - return new SplitStream(this, separator); - }; - return StringStream; -}(data_stream_1.DataStream)); -exports.StringStream = StringStream; -var SplitStream = (function (_super) { - __extends(SplitStream, _super); - function SplitStream(upstream, separator) { - var _this = _super.call(this) || this; - _this.impl = new SplitStreamImpl(upstream, separator); - return _this; - } - SplitStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.impl.next()]; - }); - }); - }; - return SplitStream; -}(StringStream)); -var SplitStreamImpl = (function (_super) { - __extends(SplitStreamImpl, _super); - function SplitStreamImpl(upstream, separator) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.separator = separator; - _this.carryover = ''; - return _this; - } - SplitStreamImpl.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var chunk, lines, _i, _a, line; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4, this.upstream.next()]; - case 1: - chunk = _b.sent(); - if (chunk == null) { - if (this.carryover === '') { - return [2, false]; - } - this.outputQueue.push(this.carryover); - this.carryover = ''; - return [2, true]; - } - lines = chunk.split(this.separator); - lines[0] = this.carryover + lines[0]; - for (_i = 0, _a = lines.slice(0, -1); _i < _a.length; _i++) { - line = _a[_i]; - this.outputQueue.push(line); - } - this.carryover = lines[lines.length - 1]; - return [2, true]; - } - }); - }); - }; - return SplitStreamImpl; -}(data_stream_1.QueueStream)); - -},{"./data_stream":20}],23:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var byte_stream_1 = require("./byte_stream"); -var data_stream_1 = require("./data_stream"); -var filereader_stream_1 = require("./filereader_stream"); -var URLStream = (function (_super) { - __extends(URLStream, _super); - function URLStream(url, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.impl = new URLStreamImpl(url, options); - return _this; - } - URLStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.impl.next()]; - }); - }); - }; - return URLStream; -}(byte_stream_1.ByteStream)); -exports.URLStream = URLStream; -var URLStreamImpl = (function (_super) { - __extends(URLStreamImpl, _super); - function URLStreamImpl(url, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.url = url; - _this.options = options; - _this.blobPromise = fetch(url, options).then(function (response) { - if (response.ok) { - return response.blob(); - } - else { - throw new Error(response.statusText); - } - }); - return _this; - } - URLStreamImpl.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var blob, chunk; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.fileReaderStream == null)) return [3, 2]; - return [4, this.blobPromise]; - case 1: - blob = _a.sent(); - this.fileReaderStream = new filereader_stream_1.FileReaderStream(blob, this.options); - _a.label = 2; - case 2: return [4, this.fileReaderStream.next()]; - case 3: - chunk = _a.sent(); - if (chunk == null) - return [2, false]; - this.outputQueue.push(chunk); - return [2, true]; - } - }); - }); - }; - return URLStreamImpl; -}(data_stream_1.QueueStream)); - -},{"./byte_stream":19,"./data_stream":20,"./filereader_stream":21}],24:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var ring_buffer_1 = require("./ring_buffer"); -var GrowingRingBuffer = (function (_super) { - __extends(GrowingRingBuffer, _super); - function GrowingRingBuffer() { - return _super.call(this, GrowingRingBuffer.INITIAL_CAPACITY) || this; - } - GrowingRingBuffer.prototype.isFull = function () { - return false; - }; - GrowingRingBuffer.prototype.push = function (value) { - if (_super.prototype.isFull.call(this)) { - this.expand(); - } - _super.prototype.push.call(this, value); - }; - GrowingRingBuffer.prototype.unshift = function (value) { - if (_super.prototype.isFull.call(this)) { - this.expand(); - } - _super.prototype.unshift.call(this, value); - }; - GrowingRingBuffer.prototype.expand = function () { - var newCapacity = this.capacity * 2; - var newData = new Array(newCapacity); - var len = this.length(); - for (var i = 0; i < len; i++) { - newData[i] = this.get(this.wrap(this.begin + i)); - } - this.data = newData; - this.capacity = newCapacity; - this.doubledCapacity = 2 * this.capacity; - this.begin = 0; - this.end = len; - }; - GrowingRingBuffer.INITIAL_CAPACITY = 32; - return GrowingRingBuffer; -}(ring_buffer_1.RingBuffer)); -exports.GrowingRingBuffer = GrowingRingBuffer; - -},{"./ring_buffer":25}],25:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var RingBuffer = (function () { - function RingBuffer(capacity) { - this.capacity = capacity; - this.begin = 0; - this.end = 0; - if (capacity < 1) { - throw new RangeError('Can\'t create ring buffer of capacity < 1.'); - } - this.data = new Array(capacity); - this.doubledCapacity = 2 * capacity; - } - RingBuffer.prototype.wrap = function (index) { - while (index < 0) { - index += this.doubledCapacity; - } - return index % this.doubledCapacity; - }; - RingBuffer.prototype.get = function (index) { - if (index < 0) { - throw new RangeError('Can\'t get item at a negative index.'); - } - return this.data[index % this.capacity]; - }; - RingBuffer.prototype.set = function (index, value) { - if (index < 0) { - throw new RangeError('Can\'t set item at a negative index.'); - } - this.data[index % this.capacity] = value; - }; - RingBuffer.prototype.length = function () { - var length = this.end - this.begin; - if (length < 0) { - length = this.doubledCapacity + length; - } - return length; - }; - RingBuffer.prototype.isFull = function () { - return this.length() === this.capacity; - }; - RingBuffer.prototype.isEmpty = function () { - return this.length() === 0; - }; - RingBuffer.prototype.push = function (value) { - if (this.isFull()) { - throw new RangeError('Ring buffer is full.'); - } - this.set(this.end, value); - this.end = this.wrap(this.end + 1); - }; - RingBuffer.prototype.pop = function () { - if (this.isEmpty()) { - throw new RangeError('Ring buffer is empty.'); - } - this.end = this.wrap(this.end - 1); - var result = this.get(this.end); - this.set(this.end, undefined); - return result; - }; - RingBuffer.prototype.unshift = function (value) { - if (this.isFull()) { - throw new RangeError('Ring buffer is full.'); - } - this.begin = this.wrap(this.begin - 1); - this.set(this.begin, value); - }; - RingBuffer.prototype.shift = function () { - if (this.isEmpty()) { - throw new RangeError('Ring buffer is empty.'); - } - var result = this.get(this.begin); - this.set(this.begin, undefined); - this.begin = this.wrap(this.begin + 1); - return result; - }; - RingBuffer.prototype.shuffleExcise = function (relativeIndex) { - if (this.isEmpty()) { - throw new RangeError('Ring buffer is empty.'); - } - var index = this.wrap(this.begin + relativeIndex); - var result = this.get(index); - this.set(index, this.pop()); - return result; - }; - return RingBuffer; -}()); -exports.RingBuffer = RingBuffer; - -},{}],26:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var dataset_1 = require("./data/dataset"); -exports.Dataset = dataset_1.Dataset; -var csv_dataset_1 = require("./data/datasets/csv_dataset"); -exports.CSVDataset = csv_dataset_1.CSVDataset; -var text_line_dataset_1 = require("./data/datasets/text_line_dataset"); -exports.TextLineDataset = text_line_dataset_1.TextLineDataset; -var file_data_source_1 = require("./data/sources/file_data_source"); -exports.FileDataSource = file_data_source_1.FileDataSource; -var url_data_source_1 = require("./data/sources/url_data_source"); -exports.URLDataSource = url_data_source_1.URLDataSource; - -},{"./data/dataset":12,"./data/datasets/csv_dataset":13,"./data/datasets/text_line_dataset":14,"./data/sources/file_data_source":16,"./data/sources/url_data_source":17}],27:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var MANIFEST_FILE = 'manifest.json'; -var CheckpointLoader = (function () { - function CheckpointLoader(urlPath) { - this.urlPath = urlPath; - if (this.urlPath.charAt(this.urlPath.length - 1) !== '/') { - this.urlPath += '/'; - } - } - CheckpointLoader.prototype.loadManifest = function () { - var _this = this; - return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', _this.urlPath + MANIFEST_FILE); - xhr.onload = function () { - _this.checkpointManifest = JSON.parse(xhr.responseText); - resolve(); - }; - xhr.onerror = function (error) { - throw new Error(MANIFEST_FILE + " not found at " + _this.urlPath + ". " + error); - }; - xhr.send(); - }); - }; - CheckpointLoader.prototype.getCheckpointManifest = function () { - var _this = this; - if (this.checkpointManifest == null) { - return new Promise(function (resolve, reject) { - _this.loadManifest().then(function () { - resolve(_this.checkpointManifest); - }); - }); - } - return new Promise(function (resolve, reject) { - resolve(_this.checkpointManifest); - }); - }; - CheckpointLoader.prototype.getAllVariables = function () { - var _this = this; - if (this.variables != null) { - return new Promise(function (resolve, reject) { - resolve(_this.variables); - }); - } - return new Promise(function (resolve, reject) { - _this.getCheckpointManifest().then(function (checkpointDefinition) { - var variableNames = Object.keys(_this.checkpointManifest); - var variablePromises = []; - for (var i = 0; i < variableNames.length; i++) { - variablePromises.push(_this.getVariable(variableNames[i])); - } - Promise.all(variablePromises).then(function (variables) { - _this.variables = {}; - for (var i = 0; i < variables.length; i++) { - _this.variables[variableNames[i]] = variables[i]; - } - resolve(_this.variables); - }); - }); - }); - }; - CheckpointLoader.prototype.getVariable = function (varName) { - var _this = this; - if (!(varName in this.checkpointManifest)) { - throw new Error('Cannot load non-existant variable ' + varName); - } - var variableRequestPromiseMethod = function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.responseType = 'arraybuffer'; - var fname = _this.checkpointManifest[varName].filename; - xhr.open('GET', _this.urlPath + fname); - xhr.onload = function () { - if (xhr.status === 404) { - throw new Error("Not found variable " + varName); - } - var values = new Float32Array(xhr.response); - var tensor = tensor_1.Tensor.make(_this.checkpointManifest[varName].shape, { values: values }); - resolve(tensor); - }; - xhr.onerror = function (error) { - throw new Error("Could not fetch variable " + varName + ": " + error); - }; - xhr.send(); - }; - if (this.checkpointManifest == null) { - return new Promise(function (resolve, reject) { - _this.loadManifest().then(function () { - new Promise(variableRequestPromiseMethod).then(resolve); - }); - }); - } - return new Promise(variableRequestPromiseMethod); - }; - return CheckpointLoader; -}()); -exports.CheckpointLoader = CheckpointLoader; - -},{"../tensor":146}],28:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var STATS_SAMPLE_PERCENTAGE = 0.1; -var InMemoryDataset = (function () { - function InMemoryDataset(dataShapes) { - this.dataShapes = dataShapes; - this.normalizationInfo = {}; - } - InMemoryDataset.prototype.getDataShape = function (dataIndex) { - return this.dataShapes[dataIndex]; - }; - InMemoryDataset.prototype.getData = function () { - return this.dataset; - }; - InMemoryDataset.prototype.getStats = function () { - var _this = this; - if (this.dataset == null) { - throw new Error('Data is null.'); - } - return this.dataset.map(function (d) { return _this.getStatsForData(d); }); - }; - InMemoryDataset.prototype.getStatsForData = function (data) { - var inputMin = Number.POSITIVE_INFINITY; - var inputMax = Number.NEGATIVE_INFINITY; - var exampleIndices = data.map(function (example, i) { return i; }); - util.shuffle(exampleIndices); - exampleIndices = - exampleIndices.slice(exampleIndices.length * STATS_SAMPLE_PERCENTAGE); - for (var i = 0; i < exampleIndices.length; i++) { - var inputValues = data[exampleIndices[i]].dataSync(); - for (var j = 0; j < inputValues.length; j++) { - inputMin = Math.min(inputMin, inputValues[j]); - inputMax = Math.max(inputMax, inputValues[j]); - } - } - return { - inputMin: inputMin, - inputMax: inputMax, - exampleCount: data.length, - shape: data[0].shape, - }; - }; - InMemoryDataset.prototype.normalizeExamplesToRange = function (examples, curLowerBounds, curUpperBounds, newLowerBounds, newUpperBounds) { - var curBoundsIsPerDimension = (curUpperBounds instanceof Float32Array && - curLowerBounds instanceof Float32Array); - var newBoundsIsPerDimension = (newLowerBounds instanceof Float32Array && - newUpperBounds instanceof Float32Array); - var inputSize = util.sizeFromShape(examples[0].shape); - var newExamples = []; - examples.forEach(function (example) { - var inputValues = example.dataSync(); - var normalizedValues = new Float32Array(inputSize); - for (var j = 0; j < inputSize; j++) { - var curLowerBound = curBoundsIsPerDimension ? - curLowerBounds[j] : - curLowerBounds; - var curUpperBound = curBoundsIsPerDimension ? - curUpperBounds[j] : - curUpperBounds; - var curRange = curUpperBound - curLowerBound; - var newLowerBound = newBoundsIsPerDimension ? - newLowerBounds[j] : - newLowerBounds; - var newUpperBound = newBoundsIsPerDimension ? - newUpperBounds[j] : - newUpperBounds; - var newRange = newUpperBound - newLowerBound; - if (curRange === 0) { - normalizedValues[j] = newLowerBound; - } - else { - normalizedValues[j] = newLowerBound + - newRange * (inputValues[j] - curLowerBound) / curRange; - } - } - newExamples.push(tensor_1.Tensor.make(example.shape, { values: normalizedValues }, 'float32')); - }); - return newExamples; - }; - InMemoryDataset.prototype.computeBounds = function (dataIndex) { - var _this = this; - if (this.dataset == null) { - throw new Error('Data is null.'); - } - var size = util.sizeFromShape(this.dataset[dataIndex][0].shape); - this.normalizationInfo[dataIndex] = { - isNormalized: false, - minValues: new Float32Array(size), - maxValues: new Float32Array(size) - }; - for (var i = 0; i < size; i++) { - this.normalizationInfo[dataIndex].minValues[i] = Number.POSITIVE_INFINITY; - this.normalizationInfo[dataIndex].maxValues[i] = Number.NEGATIVE_INFINITY; - } - this.dataset[dataIndex].forEach(function (example) { - var inputValues = example.dataSync(); - for (var k = 0; k < size; k++) { - _this.normalizationInfo[dataIndex].minValues[k] = Math.min(_this.normalizationInfo[dataIndex].minValues[k], inputValues[k]); - _this.normalizationInfo[dataIndex].maxValues[k] = Math.max(_this.normalizationInfo[dataIndex].maxValues[k], inputValues[k]); - } - }); - }; - InMemoryDataset.prototype.normalizeWithinBounds = function (dataIndex, lowerBound, upperBound) { - if (this.dataset == null) { - throw new Error('Data is null.'); - } - if (dataIndex >= this.dataset.length) { - throw new Error('dataIndex out of bounds.'); - } - if (this.normalizationInfo[dataIndex] == null) { - this.computeBounds(dataIndex); - } - var curLowerBounds; - var curUpperBounds; - if (this.normalizationInfo[dataIndex].isNormalized) { - curLowerBounds = this.normalizationInfo[dataIndex].lowerBound; - curUpperBounds = this.normalizationInfo[dataIndex].upperBound; - } - else { - curLowerBounds = this.normalizationInfo[dataIndex].minValues; - curUpperBounds = this.normalizationInfo[dataIndex].maxValues; - } - this.dataset[dataIndex] = this.normalizeExamplesToRange(this.dataset[dataIndex], curLowerBounds, curUpperBounds, lowerBound, upperBound); - this.normalizationInfo[dataIndex].isNormalized = true; - this.normalizationInfo[dataIndex].lowerBound = lowerBound; - this.normalizationInfo[dataIndex].upperBound = upperBound; - }; - InMemoryDataset.prototype.isNormalized = function (dataIndex) { - return this.normalizationInfo != null && - this.normalizationInfo[dataIndex].isNormalized; - }; - InMemoryDataset.prototype.removeNormalization = function (dataIndex) { - if (this.dataset == null) { - throw new Error('Training or test data is null.'); - } - if (!this.isNormalized(dataIndex)) { - return; - } - this.dataset[dataIndex] = this.normalizeExamplesToRange(this.dataset[dataIndex], this.normalizationInfo[dataIndex].lowerBound, this.normalizationInfo[dataIndex].upperBound, this.normalizationInfo[dataIndex].minValues, this.normalizationInfo[dataIndex].maxValues); - this.normalizationInfo[dataIndex].isNormalized = false; - }; - InMemoryDataset.prototype.unnormalizeExamples = function (examples, dataIndex) { - if (!this.isNormalized(dataIndex)) { - return examples; - } - return this.normalizeExamplesToRange(examples, this.normalizationInfo[dataIndex].lowerBound, this.normalizationInfo[dataIndex].upperBound, this.normalizationInfo[dataIndex].minValues, this.normalizationInfo[dataIndex].maxValues); - }; - InMemoryDataset.prototype.dispose = function () { - if (this.dataset == null) { - return; - } - for (var i = 0; i < this.dataset.length; i++) { - for (var j = 0; j < this.dataset[i].length; j++) { - this.dataset[i][j].dispose(); - } - } - this.dataset = []; - }; - return InMemoryDataset; -}()); -exports.InMemoryDataset = InMemoryDataset; - -},{"../tensor":146,"../util":151}],29:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -var InMemoryShuffledInputProviderBuilder = (function () { - function InMemoryShuffledInputProviderBuilder(inputs) { - this.inputs = inputs; - this.idx = 0; - this.inputCounter = 0; - this.epoch = 0; - this.shuffledIndices = util.createShuffledIndices(inputs[0].length); - this.numInputs = inputs.length; - var numExamples = this.inputs[0].length; - for (var i = 0; i < this.numInputs; i++) { - util.assert(this.inputs[i].length === numExamples, 'Number of examples must match across different inputs.'); - } - for (var i = 0; i < this.numInputs; i++) { - var inputShape = this.inputs[i][0].shape; - for (var j = 0; j < this.inputs[i].length; j++) { - util.assertShapesMatch(inputShape, this.inputs[i][j].shape); - } - } - } - InMemoryShuffledInputProviderBuilder.prototype.getCurrentExampleIndex = function () { - var returnIdx = this.idx; - this.inputCounter++; - if (this.inputCounter >= this.numInputs) { - this.idx++; - this.inputCounter = 0; - if (this.idx >= this.inputs[0].length) { - this.idx = 0; - this.epoch++; - } - } - return returnIdx; - }; - InMemoryShuffledInputProviderBuilder.prototype.getNextInput = function (inputId) { - var currentExampleIndex = this.getCurrentExampleIndex(); - return this.inputs[inputId][this.shuffledIndices[currentExampleIndex]]; - }; - InMemoryShuffledInputProviderBuilder.prototype.getEpoch = function () { - return this.epoch; - }; - InMemoryShuffledInputProviderBuilder.prototype.getInputProviders = function () { - var inputProviders = []; - for (var i = 0; i < this.numInputs; i++) { - inputProviders.push(this.getInputProvider(i)); - } - return inputProviders; - }; - return InMemoryShuffledInputProviderBuilder; -}()); -exports.InMemoryShuffledInputProviderBuilder = InMemoryShuffledInputProviderBuilder; -var InCPUMemoryShuffledInputProviderBuilder = (function (_super) { - __extends(InCPUMemoryShuffledInputProviderBuilder, _super); - function InCPUMemoryShuffledInputProviderBuilder() { - return _super !== null && _super.apply(this, arguments) || this; - } - InCPUMemoryShuffledInputProviderBuilder.prototype.getInputProvider = function (inputId) { - var shuffledInputProvider = this; - return { - getNextCopy: function () { - return shuffledInputProvider.getNextInput(inputId).clone(); - }, - disposeCopy: function (copy) { - copy.dispose(); - } - }; - }; - return InCPUMemoryShuffledInputProviderBuilder; -}(InMemoryShuffledInputProviderBuilder)); -exports.InCPUMemoryShuffledInputProviderBuilder = InCPUMemoryShuffledInputProviderBuilder; -var InGPUMemoryShuffledInputProviderBuilder = (function (_super) { - __extends(InGPUMemoryShuffledInputProviderBuilder, _super); - function InGPUMemoryShuffledInputProviderBuilder() { - return _super !== null && _super.apply(this, arguments) || this; - } - InGPUMemoryShuffledInputProviderBuilder.prototype.getInputProvider = function (inputId) { - var shuffledInputProvider = this; - return { - getNextCopy: function () { - return shuffledInputProvider.getNextInput(inputId).clone(); - }, - disposeCopy: function (copy) { - copy.dispose(); - } - }; - }; - return InGPUMemoryShuffledInputProviderBuilder; -}(InMemoryShuffledInputProviderBuilder)); -exports.InGPUMemoryShuffledInputProviderBuilder = InGPUMemoryShuffledInputProviderBuilder; - -},{"../util":151}],30:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var dataset_1 = require("./dataset"); -var PARSING_IMAGE_CANVAS_HEIGHT_PX = 1000; -function getXhrDatasetConfig(jsonConfigPath) { - return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', jsonConfigPath); - xhr.onload = function () { - resolve(JSON.parse(xhr.responseText)); - }; - xhr.onerror = function (error) { - reject(error); - }; - xhr.send(); - }); -} -exports.getXhrDatasetConfig = getXhrDatasetConfig; -var XhrDataset = (function (_super) { - __extends(XhrDataset, _super); - function XhrDataset(xhrDatasetConfig) { - var _this = _super.call(this, xhrDatasetConfig.data.map(function (x) { return x.shape; })) || this; - _this.xhrDatasetConfig = xhrDatasetConfig; - return _this; - } - XhrDataset.prototype.getTensor = function (info) { - var dataPromise = info.dataType === 'png' ? - parseTypedArrayFromPng(info, info.shape) : - parseTypedArrayFromBinary(info); - var inputSize = util.sizeFromShape(info.shape); - return dataPromise.then(function (data) { - var tensors = []; - for (var i = 0; i < data.length / inputSize; i++) { - var values = data.subarray(i * inputSize, (i + 1) * inputSize); - var tensor = tensor_1.Tensor.make(info.shape, { values: new Float32Array(values) }, 'float32'); - tensors.push(tensor); - } - return tensors; - }); - }; - XhrDataset.prototype.fetchData = function () { - var _this = this; - return new Promise(function (resolve, reject) { - var promises = _this.xhrDatasetConfig.data.map(function (x) { return _this.getTensor(x); }); - Promise.all(promises).then(function (data) { - _this.dataset = data; - resolve(); - }); - }); - }; - return XhrDataset; -}(dataset_1.InMemoryDataset)); -exports.XhrDataset = XhrDataset; -function parseTypedArrayFromBinary(info) { - return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', info.path); - xhr.responseType = 'arraybuffer'; - xhr.onload = function (event) { - var data = (info.dataType === 'float32') ? - new Float32Array(xhr.response) : - new Uint8Array(xhr.response); - resolve(data); - }; - xhr.onerror = function (err) { return reject(err); }; - xhr.send(); - }); -} -function parseGrayscaleImageData(data, result, resultOffset) { - var idx = resultOffset; - for (var i = 0; i < data.length; i += 4) { - result[idx++] = data[i]; - } -} -function parseRGBImageData(data, result, resultOffset) { - var idx = resultOffset; - for (var i = 0; i < data.length; i += 4) { - result[idx] = data[i]; - result[idx + 1] = data[i + 1]; - result[idx + 2] = data[i + 2]; - idx += 3; - } -} -function parseImage(img, shape) { - var canvas = document.createElement('canvas'); - var ctx = canvas.getContext('2d'); - var N = img.height; - var inputSize = util.sizeFromShape(shape); - var result = new Uint8Array(N * inputSize); - if (img.width !== shape[0] * shape[1]) { - throw new Error("Image width (" + img.width + ") must be multiple of " + - ("rows*columns (" + shape[0] + "*" + shape[1] + ") of the tensor")); - } - canvas.width = img.width; - canvas.height = PARSING_IMAGE_CANVAS_HEIGHT_PX; - var sx = 0; - var sWidth = canvas.width; - var sHeight = canvas.height; - var dx = 0; - var dy = 0; - var dWidth = sWidth; - var dHeight = sHeight; - var depth = shape[2]; - var offset = 0; - var numPasses = Math.ceil(N / canvas.height); - for (var pass = 0; pass < numPasses; ++pass) { - var sy = pass * canvas.height; - if ((pass === numPasses - 1) && (N % canvas.height > 0)) { - canvas.height = N % canvas.height; - sHeight = canvas.height; - dHeight = sHeight; - } - ctx.drawImage(img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); - var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data; - (depth === 1) ? parseGrayscaleImageData(data, result, offset) : - parseRGBImageData(data, result, offset); - offset += canvas.height * inputSize; - } - return result; -} -function parseTypedArrayFromPng(info, shape) { - return new Promise(function (resolve, reject) { - var img = new Image(); - img.setAttribute('crossOrigin', ''); - img.onload = function () { - var result = parseImage(img, shape); - img.src = ''; - img = null; - resolve(result); - }; - img.src = info.path; - }); -} - -},{"../tensor":146,"../util":151,"./dataset":28}],31:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function isMobile() { - var a = navigator.userAgent || navigator.vendor || window.opera; - return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i - .test(a) || - /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i - .test(a.substr(0, 4)); -} -exports.isMobile = isMobile; - -},{}],32:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function doc(info) { - return function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - }; -} -exports.doc = doc; - -},{}],33:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("./environment"); -var globals_1 = require("./globals"); -var kernel_registry = require("./kernels/kernel_registry"); -var ops = require("./ops/ops"); -var profiler_1 = require("./profiler"); -var tape_util = require("./tape_util"); -var tensor_1 = require("./tensor"); -var util = require("./util"); -var Engine = (function () { - function Engine(backend, customBackend, safeMode) { - this.backend = backend; - this.customBackend = customBackend; - this.safeMode = safeMode; - this.registeredVariables = {}; - this.refCounter = new WeakMap(); - this.nextTapeNodeId = 0; - this.numBytes = 0; - this.numTensors = 0; - this.numDataBuffers = 0; - this.gradientScopeCount = 0; - this.customGradientDepth = 0; - this.activeScope = { keep: [], track: [] }; - this.scopeStack = [this.activeScope]; - this.profiler = new profiler_1.Profiler(backend); - } - Engine.prototype.executeKernel = function (kernelName, config, grad) { - var _this = this; - var result; - if (!environment_1.ENV.get('DEBUG')) { - result = kernel_registry.executeKernel(this.backend, kernelName, config); - } - else { - result = this.profiler.profileKernel(kernelName, function () { - return kernel_registry.executeKernel(_this.backend, kernelName, config); - }); - } - var recordKernel = this.activeTape != null && this.customGradientDepth === 0; - if (recordKernel) { - config = tape_util.stripUndefinedInputsFromInputConfig(config); - var evaluatedNode = { - id: this.nextTapeNodeId++, - type: 'kernel', - name: "kernel: " + kernelName, - kernel: kernelName, - inputAndArgs: config, - output: result, - gradient: grad - }; - this.activeTape.push(evaluatedNode); - } - return result; - }; - Engine.prototype.registerTensor = function (a) { - var refCount = this.refCounter.has(a.dataId) ? this.refCounter.get(a.dataId) : 0; - this.numTensors++; - if (refCount === 0) { - this.numDataBuffers++; - this.numBytes += - util.sizeFromShape(a.shape) * util.bytesPerElement(a.dtype); - this.backend.register(a.dataId, a.shape, a.dtype); - } - this.refCounter.set(a.dataId, refCount + 1); - if (!(a instanceof tensor_1.Variable)) { - this.track(a); - } - }; - Engine.prototype.registerVariable = function (v) { - if (this.registeredVariables[v.name] != null) { - throw new Error("Variable with name " + v.name + " was already registered"); - } - this.registeredVariables[v.name] = v; - }; - Engine.prototype.disposeTensor = function (a) { - if (!this.refCounter.has(a.dataId)) { - return; - } - this.numTensors--; - var refCount = this.refCounter.get(a.dataId); - if (refCount <= 1) { - this.refCounter.delete(a.dataId); - this.backend.disposeData(a.dataId); - this.numDataBuffers--; - this.numBytes -= - util.sizeFromShape(a.shape) * util.bytesPerElement(a.dtype); - } - else { - this.refCounter.set(a.dataId, refCount - 1); - } - }; - Engine.prototype.memory = function () { - var info = this.backend.memory(); - info.numTensors = this.numTensors; - info.numDataBuffers = this.numDataBuffers; - info.numBytes = this.numBytes; - return info; - }; - Engine.prototype.shouldRecord = function () { - return this.activeTape != null && this.customGradientDepth === 0; - }; - Engine.prototype.addTapeNode = function (inputs, result, gradientsFunc) { - var inputsMap = {}; - inputs.forEach(function (input, idx) { - inputsMap[idx] = input; - }); - var gradient = function (dy) { - var res = gradientsFunc(dy); - var resMap = {}; - res.forEach(function (r, idx) { - resMap[idx] = function () { return r; }; - }); - return resMap; - }; - var evaluatedNode = { - id: this.nextTapeNodeId++, - type: 'customGradient', - name: name, - inputAndArgs: { inputs: inputsMap }, - output: result, - gradient: gradient - }; - this.activeTape.push(evaluatedNode); - }; - Engine.prototype.keep = function (result) { - if (this.scopeStack.length === 1 && environment_1.ENV.engine.safeMode) { - throw new Error('Safe mode is ON. Enclose all tensor operations inside dl.tidy(): ' + - 'dl.tidy(() => {...}) to avoid memory leaks.'); - } - this.activeScope.keep.push(result); - return result; - }; - Engine.prototype.startScope = function (gradientsMode) { - if (gradientsMode === void 0) { gradientsMode = false; } - if (gradientsMode && this.gradientScopeCount === 0) { - this.activeTape = []; - } - if (gradientsMode) { - this.gradientScopeCount++; - } - var newScopeArrays = { keep: [], track: [] }; - this.scopeStack.push(newScopeArrays); - this.activeScope = newScopeArrays; - }; - Engine.prototype.endScope = function (result, gradientsMode) { - var _this = this; - if (gradientsMode === void 0) { gradientsMode = false; } - if (gradientsMode) { - this.gradientScopeCount--; - if (this.gradientScopeCount === 0) { - this.activeTape = null; - } - } - var tensorsToKeep = this.activeScope.keep; - var tensorsToTrackInParent = tape_util.extractTensorsFromScopeResult(result); - tensorsToKeep = tensorsToKeep.concat(tensorsToTrackInParent); - for (var i = 0; i < this.activeScope.track.length; i++) { - var tensor = this.activeScope.track[i]; - if (util.isTensorInList(tensor, tensorsToKeep)) { - continue; - } - if (this.activeTape != null) { - tensorsToTrackInParent.push(tensor); - } - else { - tensor.dispose(); - } - } - this.scopeStack.pop(); - this.activeScope = this.scopeStack.length === 0 ? - { keep: [], track: [] } : - this.scopeStack[this.scopeStack.length - 1]; - tensorsToTrackInParent.forEach(function (tensor) { - if (!util.isTensorInList(tensor, _this.activeScope.keep)) { - _this.track(tensor); - } - }); - }; - Engine.prototype.dispose = function () { - if (this.customBackend) { - this.backend.dispose(); - } - }; - Engine.prototype.gradients = function (f, xs, dy, allowNoGradients) { - var _this = this; - if (allowNoGradients === void 0) { allowNoGradients = false; } - return globals_1.tidy('gradients', function () { - var y = f(); - util.assert(y instanceof tensor_1.Tensor, 'The result y returned by f() must be a tensor.'); - var filteredTape = tape_util.getFilteredNodesXToY(_this.activeTape, xs, y); - if (!allowNoGradients && filteredTape.length === 0 && xs.length > 0) { - throw new Error('Cannot compute gradient of y=f(x) with respect to x. Make sure ' + - 'that the f you passed encloses all operations that lead from x ' + - 'to y.'); - } - var accumulatedGradientMap = {}; - accumulatedGradientMap[y.id] = (dy == null) ? ops.onesLike(y) : dy; - tape_util.backpropagateGradients(accumulatedGradientMap, filteredTape); - var grads = xs.map(function (x) { return accumulatedGradientMap[x.id]; }); - return { value: y, grads: grads }; - }, true); - }; - Engine.prototype.customGrad = function (f) { - var _this = this; - util.assert(util.isFunction(f), 'The f passed in customGrad(f) must be a function.'); - return function () { - var inputs = []; - for (var _i = 0; _i < arguments.length; _i++) { - inputs[_i] = arguments[_i]; - } - util.assert(inputs.every(function (t) { return t instanceof tensor_1.Tensor; }), 'The args passed in customGrad(f)(x1, x2,...) must all be tensors'); - _this.customGradientDepth++; - var gradientsFunc; - var gradientsMode = true; - var result = globals_1.tidy(f.name, function () { - var _a = f.apply(void 0, inputs), value = _a.value, gradFunc = _a.gradFunc; - util.assert(value instanceof tensor_1.Tensor, 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.value` is a tensor'); - util.assert(util.isFunction(gradFunc), 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.gradFunc` is a function.'); - gradientsFunc = gradFunc; - return value; - }, gradientsMode); - _this.customGradientDepth--; - if (_this.shouldRecord()) { - var gradFunc = function (dy) { - var res = gradientsFunc(dy); - var grads = Array.isArray(res) ? res : [res]; - util.assert(grads.length === inputs.length, 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.gradFunc` is a function that returns the same ' + - 'number of tensors as inputs passed to f(...).'); - util.assert(grads.every(function (t) { return t instanceof tensor_1.Tensor; }), 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.gradFunc` is a function that returns a list of ' + - 'only tensors.'); - return grads; - }; - _this.addTapeNode(inputs, result, gradFunc); - } - return result; - }; - }; - Engine.prototype.write = function (dataId, values) { - this.backend.write(dataId, values); - }; - Engine.prototype.readSync = function (dataId) { - return this.backend.readSync(dataId); - }; - Engine.prototype.read = function (dataId) { - return this.backend.read(dataId); - }; - Engine.prototype.fromPixels = function (pixels, numChannels) { - return this.backend.fromPixels(pixels, numChannels); - }; - Engine.prototype.time = function (query) { - return __awaiter(this, void 0, void 0, function () { - var start, timingInfo; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - start = performance.now(); - return [4, this.backend.time(query)]; - case 1: - timingInfo = _a.sent(); - timingInfo.wallMs = performance.now() - start; - return [2, timingInfo]; - } - }); - }); - }; - Engine.prototype.track = function (result) { - if (this.scopeStack.length === 1 && this.safeMode) { - throw new Error('Safe mode is ON. Enclose all tensor operations inside dl.tidy(): ' + - 'dl.tidy(() => {op();...}); to avoid memory leaks.'); - } - this.activeScope.track.push(result); - return result; - }; - return Engine; -}()); -exports.Engine = Engine; - -},{"./environment":34,"./globals":35,"./kernels/kernel_registry":70,"./ops/ops":123,"./profiler":144,"./tape_util":145,"./tensor":146,"./util":151}],34:[function(require,module,exports){ -(function (global){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var device_util = require("./device_util"); -var doc_1 = require("./doc"); -var engine_1 = require("./engine"); -var math_1 = require("./math"); -var util = require("./util"); -var Type; -(function (Type) { - Type[Type["NUMBER"] = 0] = "NUMBER"; - Type[Type["BOOLEAN"] = 1] = "BOOLEAN"; - Type[Type["STRING"] = 2] = "STRING"; -})(Type = exports.Type || (exports.Type = {})); -exports.URL_PROPERTIES = [ - { name: 'DEBUG', type: Type.BOOLEAN }, - { name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION', type: Type.NUMBER }, - { name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE', type: Type.BOOLEAN }, - { name: 'WEBGL_VERSION', type: Type.NUMBER }, - { name: 'WEBGL_FLOAT_TEXTURE_ENABLED', type: Type.BOOLEAN }, { - name: 'WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED', - type: Type.BOOLEAN - }, - { name: 'BACKEND', type: Type.STRING } -]; -function hasExtension(gl, extensionName) { - var ext = gl.getExtension(extensionName); - return ext != null; -} -function getWebGLRenderingContext(webGLVersion) { - if (webGLVersion === 0) { - throw new Error('Cannot get WebGL rendering context, WebGL is disabled.'); - } - var tempCanvas = document.createElement('canvas'); - if (webGLVersion === 1) { - return (tempCanvas.getContext('webgl') || - tempCanvas.getContext('experimental-webgl')); - } - return tempCanvas.getContext('webgl2'); -} -function loseContext(gl) { - if (gl != null) { - var loseContextExtension = gl.getExtension('WEBGL_lose_context'); - if (loseContextExtension == null) { - throw new Error('Extension WEBGL_lose_context not supported on this browser.'); - } - loseContextExtension.loseContext(); - } -} -function isWebGLVersionEnabled(webGLVersion) { - var gl = getWebGLRenderingContext(webGLVersion); - if (gl != null) { - loseContext(gl); - return true; - } - return false; -} -function getWebGLDisjointQueryTimerVersion(webGLVersion) { - if (webGLVersion === 0) { - return 0; - } - var queryTimerVersion; - var gl = getWebGLRenderingContext(webGLVersion); - if (hasExtension(gl, 'EXT_disjoint_timer_query_webgl2') && - webGLVersion === 2) { - queryTimerVersion = 2; - } - else if (hasExtension(gl, 'EXT_disjoint_timer_query')) { - queryTimerVersion = 1; - } - else { - queryTimerVersion = 0; - } - if (gl != null) { - loseContext(gl); - } - return queryTimerVersion; -} -function isFloatTextureReadPixelsEnabled(webGLVersion) { - if (webGLVersion === 0) { - return false; - } - var gl = getWebGLRenderingContext(webGLVersion); - if (webGLVersion === 1) { - if (!hasExtension(gl, 'OES_texture_float')) { - return false; - } - } - else { - if (!hasExtension(gl, 'EXT_color_buffer_float')) { - return false; - } - } - var frameBuffer = gl.createFramebuffer(); - var texture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, texture); - var internalFormat = webGLVersion === 2 ? gl.RGBA32F : gl.RGBA; - gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, 1, 1, 0, gl.RGBA, gl.FLOAT, null); - gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); - var frameBufferComplete = (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE); - gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.FLOAT, new Float32Array(4)); - var readPixelsNoError = gl.getError() === gl.NO_ERROR; - loseContext(gl); - return frameBufferComplete && readPixelsNoError; -} -function isWebGLGetBufferSubDataAsyncExtensionEnabled(webGLVersion) { - if (webGLVersion !== 2) { - return false; - } - var gl = getWebGLRenderingContext(webGLVersion); - var isEnabled = hasExtension(gl, 'WEBGL_get_buffer_sub_data_async'); - loseContext(gl); - return isEnabled; -} -var SUPPORTED_BACKENDS = ['webgl', 'cpu']; -var Environment = (function () { - function Environment(features) { - this.features = {}; - this.BACKEND_REGISTRY = {}; - this.backends = this.BACKEND_REGISTRY; - if (features != null) { - this.features = features; - } - if (this.get('DEBUG')) { - console.warn('Debugging mode is ON. The output of every math call will ' + - 'be downloaded to CPU and checked for NaNs. ' + - 'This significantly impacts performance.'); - } - } - Environment.setBackend = function (backendType, safeMode) { - if (safeMode === void 0) { safeMode = false; } - if (!(backendType in exports.ENV.backends)) { - throw new Error("Backend type '" + backendType + "' not found in registry"); - } - exports.ENV.globalMath = new math_1.NDArrayMath(backendType, safeMode); - }; - Environment.getBackend = function () { - exports.ENV.initEngine(); - return exports.ENV.currentBackendType; - }; - Environment.memory = function () { - return exports.ENV.engine.memory(); - }; - Environment.prototype.get = function (feature) { - if (feature in this.features) { - return this.features[feature]; - } - this.features[feature] = this.evaluateFeature(feature); - return this.features[feature]; - }; - Environment.prototype.set = function (feature, value) { - this.features[feature] = value; - }; - Environment.prototype.getBestBackendType = function () { - for (var i = 0; i < SUPPORTED_BACKENDS.length; ++i) { - var backendId = SUPPORTED_BACKENDS[i]; - if (backendId in this.backends) { - return backendId; - } - } - throw new Error('No backend found in registry.'); - }; - Environment.prototype.evaluateFeature = function (feature) { - if (feature === 'DEBUG') { - return false; - } - else if (feature === 'BACKEND') { - return this.getBestBackendType(); - } - else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') { - var webGLVersion = this.get('WEBGL_VERSION'); - if (webGLVersion === 0) { - return 0; - } - return getWebGLDisjointQueryTimerVersion(webGLVersion); - } - else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE') { - return this.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0 && - !device_util.isMobile(); - } - else if (feature === 'WEBGL_VERSION') { - if (isWebGLVersionEnabled(2)) { - return 2; - } - else if (isWebGLVersionEnabled(1)) { - return 1; - } - return 0; - } - else if (feature === 'WEBGL_FLOAT_TEXTURE_ENABLED') { - return isFloatTextureReadPixelsEnabled(this.get('WEBGL_VERSION')); - } - else if (feature === 'WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED') { - return isWebGLGetBufferSubDataAsyncExtensionEnabled(this.get('WEBGL_VERSION')); - } - throw new Error("Unknown feature " + feature + "."); - }; - Environment.prototype.setFeatures = function (features) { - this.reset(); - this.features = features; - this.backends = {}; - }; - Environment.prototype.reset = function () { - this.features = getFeaturesFromURL(); - if (this.globalMath != null) { - this.globalMath.dispose(); - this.globalMath = null; - this.globalEngine = null; - } - if (this.backends !== this.BACKEND_REGISTRY) { - for (var name_1 in this.backends) { - this.backends[name_1].dispose(); - } - this.backends = this.BACKEND_REGISTRY; - } - }; - Environment.prototype.setMath = function (math, backend, safeMode) { - if (safeMode === void 0) { safeMode = false; } - if (this.globalMath === math) { - return; - } - var customBackend = false; - if (typeof backend === 'string') { - this.currentBackendType = backend; - backend = exports.ENV.findBackend(backend); - } - else { - customBackend = true; - this.currentBackendType = 'custom'; - } - this.globalEngine = new engine_1.Engine(backend, customBackend, safeMode); - this.globalMath = math; - }; - Environment.prototype.findBackend = function (name) { - return this.backends[name]; - }; - Environment.prototype.addCustomBackend = function (name, factory) { - if (name in this.backends) { - throw new Error(name + " backend was already registered"); - } - try { - var backend = factory(); - this.backends[name] = backend; - return true; - } - catch (err) { - return false; - } - }; - Environment.prototype.registerBackend = function (name, factory) { - if (name in this.BACKEND_REGISTRY) { - throw new Error(name + " backend was already registered as global"); - } - try { - var backend = factory(); - this.BACKEND_REGISTRY[name] = backend; - return true; - } - catch (err) { - return false; - } - }; - Object.defineProperty(Environment.prototype, "math", { - get: function () { - if (this.globalEngine == null) { - this.initEngine(); - } - return this.globalMath; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Environment.prototype, "engine", { - get: function () { - if (this.globalEngine == null) { - this.initEngine(); - } - return this.globalEngine; - }, - enumerable: true, - configurable: true - }); - Environment.prototype.initEngine = function () { - this.globalMath = new math_1.NDArrayMath(exports.ENV.get('BACKEND'), false); - }; - __decorate([ - doc_1.doc({ heading: 'Environment' }) - ], Environment, "setBackend", null); - __decorate([ - doc_1.doc({ heading: 'Environment' }) - ], Environment, "getBackend", null); - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Memory' }) - ], Environment, "memory", null); - return Environment; -}()); -exports.Environment = Environment; -var DEEPLEARNJS_FLAGS_PREFIX = 'dljsflags'; -function getFeaturesFromURL() { - var features = {}; - if (typeof window === 'undefined') { - return features; - } - var urlParams = util.getQueryParams(window.location.search); - if (DEEPLEARNJS_FLAGS_PREFIX in urlParams) { - var urlFlags_1 = {}; - var keyValues = urlParams[DEEPLEARNJS_FLAGS_PREFIX].split(','); - keyValues.forEach(function (keyValue) { - var _a = keyValue.split(':'), key = _a[0], value = _a[1]; - urlFlags_1[key] = value; - }); - exports.URL_PROPERTIES.forEach(function (urlProperty) { - if (urlProperty.name in urlFlags_1) { - console.log("Setting feature override from URL " + urlProperty.name + ": " + - ("" + urlFlags_1[urlProperty.name])); - if (urlProperty.type === Type.NUMBER) { - features[urlProperty.name] = +urlFlags_1[urlProperty.name]; - } - else if (urlProperty.type === Type.BOOLEAN) { - features[urlProperty.name] = urlFlags_1[urlProperty.name] === 'true'; - } - else if (urlProperty.type === Type.STRING) { - features[urlProperty.name] = urlFlags_1[urlProperty.name]; - } - else { - console.warn("Unknown URL param: " + urlProperty.name + "."); - } - } - }); - } - return features; -} -function getGlobalNamespace() { - var ns; - if (typeof (window) !== 'undefined') { - ns = window; - } - else if (typeof (global) !== 'undefined') { - ns = global; - } - else { - throw new Error('Could not find a global object'); - } - return ns; -} -function getOrMakeEnvironment() { - var ns = getGlobalNamespace(); - ns.ENV = ns.ENV || new Environment(getFeaturesFromURL()); - return ns.ENV; -} -exports.ENV = getOrMakeEnvironment(); - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./device_util":31,"./doc":32,"./engine":33,"./math":105,"./util":151}],35:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var gradients_1 = require("./gradients"); -var tracking_1 = require("./tracking"); -exports.tidy = tracking_1.Tracking.tidy; -exports.keep = tracking_1.Tracking.keep; -exports.time = tracking_1.Tracking.time; -exports.grad = gradients_1.Gradients.grad; -exports.valueAndGrad = gradients_1.Gradients.valueAndGrad; -exports.grads = gradients_1.Gradients.grads; -exports.valueAndGrads = gradients_1.Gradients.valueAndGrads; -exports.variableGrads = gradients_1.Gradients.variableGrads; -exports.customGrad = gradients_1.Gradients.customGrad; - -},{"./gradients":36,"./tracking":148}],36:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var environment_1 = require("./environment"); -var globals_1 = require("./globals"); -var tensor_1 = require("./tensor"); -var util = require("./util"); -var Gradients = (function () { - function Gradients() { - } - Gradients.gradScope = function (nameOrScopeFn, scopeFn) { - return globals_1.tidy(nameOrScopeFn, scopeFn, true); - }; - Gradients.grad = function (f) { - util.assert(util.isFunction(f), 'The f passed in grad(f) must be a function'); - return function (x, dy) { - util.assert(x instanceof tensor_1.Tensor, 'The x passed in grad(f)(x) must be a tensor'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in grad(f)(x, dy) must be a tensor'); - var _a = environment_1.ENV.engine.gradients(function () { return f(x); }, [x], dy), value = _a.value, grads = _a.grads; - if (dy != null) { - util.assertShapesMatch(value.shape, dy.shape, 'The shape of dy passed in grad(f)(x, dy) must match the shape ' + - 'returned by f(x)'); - } - value.dispose(); - checkGrads(grads); - return grads[0]; - }; - }; - Gradients.grads = function (f) { - util.assert(util.isFunction(f), 'The f passed in grads(f) must be a function'); - return function (args, dy) { - util.assert(Array.isArray(args) && args.every(function (arg) { return arg instanceof tensor_1.Tensor; }), 'The args passed in grads(f)(args) must be an array of tensors'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in grads(f)(args, dy) must be a tensor'); - var _a = environment_1.ENV.engine.gradients(function () { return f.apply(void 0, args); }, args, dy), value = _a.value, grads = _a.grads; - if (dy != null) { - util.assertShapesMatch(value.shape, dy.shape, 'The shape of dy passed in grads(f)([x1,...], dy) must match the ' + - 'shape returned by f([x1,...])'); - } - value.dispose(); - checkGrads(grads); - return grads; - }; - }; - Gradients.valueAndGrad = function (f) { - util.assert(util.isFunction(f), 'The f passed in valueAndGrad(f) must be a function'); - return function (x, dy) { - util.assert(x instanceof tensor_1.Tensor, 'The x passed in valueAndGrad(f)(x) must be a tensor'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in valueAndGrad(f)(x, dy) must be a tensor'); - var _a = environment_1.ENV.engine.gradients(function () { return f(x); }, [x], dy), grads = _a.grads, value = _a.value; - checkGrads(grads); - return { grad: grads[0], value: value }; - }; - }; - Gradients.valueAndGrads = function (f) { - util.assert(util.isFunction(f), 'The f passed in valueAndGrads(f) must be a function'); - return function (args, dy) { - util.assert(Array.isArray(args) && args.every(function (arg) { return arg instanceof tensor_1.Tensor; }), 'The args passed in valueAndGrads(f)(args) must be array of tensors'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in valueAndGrads(f)(args, dy) must be a tensor'); - var res = environment_1.ENV.engine.gradients(function () { return f.apply(void 0, args); }, args, dy); - if (dy != null) { - util.assertShapesMatch(res.value.shape, dy.shape, 'The shape of dy passed in valueAndGrads(f)([x1,...], dy) must ' + - 'match the shape returned by f([x1,...])'); - } - checkGrads(res.grads); - return res; - }; - }; - Gradients.variableGrads = function (f, varList) { - util.assert(util.isFunction(f), 'The f passed in variableGrads(f) must be a function'); - util.assert(varList == null || - Array.isArray(varList) && varList.every(function (v) { return v instanceof tensor_1.Variable; }), 'The varList passed in variableGrads(f, varList) must be an array ' + - 'of variables'); - if (varList == null) { - varList = []; - for (var varName in environment_1.ENV.engine.registeredVariables) { - varList.push(environment_1.ENV.engine.registeredVariables[varName]); - } - } - varList = varList.filter(function (variable) { return variable.trainable; }); - var allowNoGradients = true; - var _a = environment_1.ENV.engine.gradients(f, varList, null, allowNoGradients), value = _a.value, grads = _a.grads; - util.assert(grads.some(function (g) { return g != null; }), 'Cannot find a connection between any variable and the result of the ' + - 'loss function y=f(x). Please make sure the operations that use ' + - 'variables are inside the function f passed to minimize().'); - util.assert(value.rank === 0, "The f passed in variableGrads(f) must return a scalar, but it " + - ("returned a rank-" + value.rank + " tensor")); - var namedGrads = {}; - varList.forEach(function (v, i) { - if (grads[i] != null) { - namedGrads[v.name] = grads[i]; - } - }); - return { value: value, grads: namedGrads }; - }; - Gradients.customGrad = function (f) { - return environment_1.ENV.engine.customGrad(f); - }; - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "grad", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "grads", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "valueAndGrad", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "valueAndGrads", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "variableGrads", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "customGrad", null); - return Gradients; -}()); -exports.Gradients = Gradients; -function checkGrads(grads) { - var numNullGradients = grads.filter(function (g) { return g == null; }).length; - if (numNullGradients > 0) { - throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y."); - } -} - -},{"./doc":32,"./environment":34,"./globals":35,"./tensor":146,"./util":151}],37:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var TanHFunc = (function () { - function TanHFunc() { - this.one = tensor_1.Scalar.new(1); - } - TanHFunc.prototype.output = function (math, x) { - return math.tanh(x); - }; - TanHFunc.prototype.der = function (math, x, y) { - var _this = this; - return globals_1.tidy(function () { - var ySquared = math.multiplyStrict(y, y); - return math.subtract(_this.one, ySquared); - }); - }; - TanHFunc.prototype.dispose = function () { - this.one.dispose(); - }; - return TanHFunc; -}()); -exports.TanHFunc = TanHFunc; -var ReLUFunc = (function () { - function ReLUFunc() { - } - ReLUFunc.prototype.output = function (math, x) { - return math.relu(x); - }; - ReLUFunc.prototype.der = function (math, x, y) { - return math.step(x); - }; - ReLUFunc.prototype.dispose = function () { }; - return ReLUFunc; -}()); -exports.ReLUFunc = ReLUFunc; -var LeakyReluFunc = (function () { - function LeakyReluFunc(alpha) { - this.alpha = alpha; - } - LeakyReluFunc.prototype.output = function (math, x) { - return math.leakyRelu(x, this.alpha); - }; - LeakyReluFunc.prototype.der = function (math, x, y) { - return math.step(x, this.alpha); - }; - LeakyReluFunc.prototype.dispose = function () { }; - return LeakyReluFunc; -}()); -exports.LeakyReluFunc = LeakyReluFunc; -var SigmoidFunc = (function () { - function SigmoidFunc() { - } - SigmoidFunc.prototype.output = function (math, x) { - return math.sigmoid(x); - }; - SigmoidFunc.prototype.der = function (math, x, y) { - return globals_1.tidy(function () { - var ySquared = math.multiplyStrict(y, y); - return math.subStrict(y, ySquared); - }); - }; - SigmoidFunc.prototype.dispose = function () { }; - return SigmoidFunc; -}()); -exports.SigmoidFunc = SigmoidFunc; -var SquareFunc = (function () { - function SquareFunc() { - this.two = tensor_1.Scalar.new(2); - } - SquareFunc.prototype.output = function (math, x) { - return math.multiplyStrict(x, x); - }; - SquareFunc.prototype.der = function (math, x, y) { - return math.multiply(this.two, x); - }; - SquareFunc.prototype.dispose = function () { - this.two.dispose(); - }; - return SquareFunc; -}()); -exports.SquareFunc = SquareFunc; -var EluFunc = (function () { - function EluFunc() { - } - EluFunc.prototype.output = function (math, x) { - return math.elu(x); - }; - EluFunc.prototype.der = function (math, x, y) { - throw new Error('Not implemented'); - }; - EluFunc.prototype.dispose = function () { }; - return EluFunc; -}()); -exports.EluFunc = EluFunc; - -},{"../globals":35,"../tensor":146}],38:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var ops = require("../ops/ops"); -var SquareCostFunc = (function () { - function SquareCostFunc() { - this.halfOne = globals_1.keep(ops.scalar(0.5)); - } - SquareCostFunc.prototype.cost = function (x1, x2) { - var diff = x1.subStrict(x2); - var diffSquared = diff.square(); - var result = this.halfOne.mul(diffSquared); - diff.dispose(); - diffSquared.dispose(); - return result; - }; - SquareCostFunc.prototype.der = function (x1, x2) { - return x1.subStrict(x2); - }; - SquareCostFunc.prototype.dispose = function () { - this.halfOne.dispose(); - }; - return SquareCostFunc; -}()); -exports.SquareCostFunc = SquareCostFunc; - -},{"../globals":35,"../ops/ops":123}],39:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var concat_util = require("../ops/concat_util"); -var conv_util = require("../ops/conv_util"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var initializers_1 = require("./initializers"); -var GraphLayers = (function () { - function GraphLayers(g) { - this.g = g; - } - GraphLayers.prototype.dense = function (name, x, units, activation, useBias, kernelInitializer, biasInitializer) { - if (activation === void 0) { activation = null; } - if (useBias === void 0) { useBias = true; } - if (kernelInitializer === void 0) { kernelInitializer = new initializers_1.VarianceScalingInitializer(); } - if (biasInitializer === void 0) { biasInitializer = new initializers_1.ZerosInitializer(); } - var weights = this.g.variable(name + '-weights', kernelInitializer.initialize([x.shape[0], units], x.shape[0], units)); - var out = this.g.matmul(x, weights); - if (useBias) { - var bias = this.g.variable(name + '-bias', biasInitializer.initialize([units], x.shape[0], units)); - out = this.g.add(out, bias); - } - if (activation != null) { - out = activation(out); - } - return out; - }; - return GraphLayers; -}()); -exports.GraphLayers = GraphLayers; -var Graph = (function () { - function Graph() { - this.nodes = []; - this.layers = new GraphLayers(this); - } - Graph.prototype.variable = function (name, data) { - return this.addNodeAndReturnOutput(new VariableNode(this, name, data)); - }; - Graph.prototype.placeholder = function (name, shape) { - return this.addNodeAndReturnOutput(new PlaceholderNode(this, name, shape)); - }; - Graph.prototype.constant = function (value) { - var finalValue; - if (typeof value === 'number') { - finalValue = tensor_1.Scalar.new(value); - } - else if (value instanceof tensor_1.Tensor) { - finalValue = value; - } - else if (value instanceof Array) { - var flatValues = util.flatten(value); - var vals = new Float32Array(flatValues); - finalValue = tensor_1.Tensor.make(util.inferShape(value), { values: vals }); - } - else { - throw new Error('unimplemented constant type.'); - } - return this.addNodeAndReturnOutput(new ConstantNode(this, finalValue)); - }; - Graph.prototype.reshape = function (x, shape) { - return this.addNodeAndReturnOutput(new ReshapeNode(this, 'Reshape', x, shape)); - }; - Graph.prototype.fusedLinearCombination = function (x1, x2, c1, c2) { - return this.addNodeAndReturnOutput(new FusedLinearCombinationNode(this, x1, x2, c1, c2)); - }; - Graph.prototype.add = function (x1, x2) { - return this.addNodeAndReturnOutput(new AddNode(this, x1, x2)); - }; - Graph.prototype.subtract = function (x1, x2) { - return this.addNodeAndReturnOutput(new SubtractNode(this, x1, x2)); - }; - Graph.prototype.multiply = function (x1, x2) { - return this.addNodeAndReturnOutput(new MultiplyNode(this, x1, x2)); - }; - Graph.prototype.divide = function (x1, x2) { - return this.addNodeAndReturnOutput(new DivideNode(this, x1, x2)); - }; - Graph.prototype.reduceSum = function (x) { - return this.addNodeAndReturnOutput(new ReduceSumNode(this, x)); - }; - Graph.prototype.concat1d = function (x1, x2) { - return this.addNodeAndReturnOutput(new Concat1DNode(this, x1, x2)); - }; - Graph.prototype.concat2d = function (x1, x2, axis) { - return this.addNodeAndReturnOutput(new Concat2DNode(this, x1, x2, axis)); - }; - Graph.prototype.concat3d = function (x1, x2, axis) { - return this.addNodeAndReturnOutput(new Concat3DNode(this, x1, x2, axis)); - }; - Graph.prototype.concat4d = function (x1, x2, axis) { - return this.addNodeAndReturnOutput(new Concat4DNode(this, x1, x2, axis)); - }; - Graph.prototype.matmul = function (x1, x2) { - return this.addNodeAndReturnOutput(new MatMulNode(this, x1, x2)); - }; - Graph.prototype.conv2d = function (x, w, b, fieldSize, outputDepth, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - return this.addNodeAndReturnOutput(new Convolution2DNode(this, x, w, b, fieldSize, outputDepth, stride, zeroPad)); - }; - Graph.prototype.maxPool = function (x, fieldSize, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - return this.addNodeAndReturnOutput(new MaxPoolNode(this, x, fieldSize, stride, zeroPad)); - }; - Graph.prototype.exp = function (x) { - return this.addNodeAndReturnOutput(new ExpNode(this, x)); - }; - Graph.prototype.log = function (x) { - return this.addNodeAndReturnOutput(new LogNode(this, x)); - }; - Graph.prototype.relu = function (x) { - return this.addNodeAndReturnOutput(new ReLUNode(this, x)); - }; - Graph.prototype.leakyRelu = function (x, alpha) { - return this.addNodeAndReturnOutput(new LeakyReLUNode(this, x, alpha)); - }; - Graph.prototype.prelu = function (x, alpha) { - return this.addNodeAndReturnOutput(new PReLUNode(this, x, alpha)); - }; - Graph.prototype.elu = function (x) { - return this.addNodeAndReturnOutput(new EluNode(this, x)); - }; - Graph.prototype.tanh = function (x) { - return this.addNodeAndReturnOutput(new TanHNode(this, x)); - }; - Graph.prototype.sigmoid = function (x) { - return this.addNodeAndReturnOutput(new SigmoidNode(this, x)); - }; - Graph.prototype.square = function (x) { - return this.addNodeAndReturnOutput(new SquareNode(this, x)); - }; - Graph.prototype.softmax = function (x) { - return this.addNodeAndReturnOutput(new SoftmaxNode(this, x)); - }; - Graph.prototype.softmaxCrossEntropyCost = function (x, target) { - return this.addNodeAndReturnOutput(new SoftmaxCrossEntropyCostNode(this, x, target)); - }; - Graph.prototype.meanSquaredCost = function (label, prediction) { - return this.addNodeAndReturnOutput(new MeanSquaredCostNode(this, label, prediction)); - }; - Graph.prototype.argmax = function (x) { - return this.addNodeAndReturnOutput(new ArgMaxNode(this, x)); - }; - Graph.prototype.argmaxEquals = function (x1, x2) { - return this.addNodeAndReturnOutput(new ArgMaxEqualsNode(this, x1, x2)); - }; - Graph.prototype.addNodeAndReturnOutput = function (node) { - this.nodes.push(node); - node.validate(); - return node.output; - }; - Graph.prototype.getNodes = function () { - return this.nodes; - }; - return Graph; -}()); -exports.Graph = Graph; -var SymbolicTensor = (function (_super) { - __extends(SymbolicTensor, _super); - function SymbolicTensor(shape) { - var _this = _super.call(this, [], 'float32') || this; - _this.shape = shape; - _this.id = SymbolicTensor.nextID++; - return _this; - } - SymbolicTensor.nextID = 0; - return SymbolicTensor; -}(tensor_1.Tensor)); -exports.SymbolicTensor = SymbolicTensor; -var Node = (function () { - function Node(graph, name, inputs, output) { - this.graph = graph; - this.name = name; - this.inputs = inputs; - this.output = output; - this.id = Node.nextID++; - output.node = this; - } - Node.nextID = 0; - return Node; -}()); -exports.Node = Node; -var VariableNode = (function (_super) { - __extends(VariableNode, _super); - function VariableNode(graph, name, data) { - var _this = _super.call(this, graph, name, {}, new SymbolicTensor(data.shape)) || this; - _this.data = data; - return _this; - } - VariableNode.prototype.validate = function () { - util.assert(this.data != null, 'Error adding variable op: Data for variable \'' + this.name + - '\' is null or undefined'); - }; - return VariableNode; -}(Node)); -exports.VariableNode = VariableNode; -var PlaceholderNode = (function (_super) { - __extends(PlaceholderNode, _super); - function PlaceholderNode(graph, name, shape) { - return _super.call(this, graph, name, {}, new SymbolicTensor(shape)) || this; - } - PlaceholderNode.prototype.validate = function () { }; - return PlaceholderNode; -}(Node)); -exports.PlaceholderNode = PlaceholderNode; -var ConstantNode = (function (_super) { - __extends(ConstantNode, _super); - function ConstantNode(graph, data) { - var _this = _super.call(this, graph, 'Constant', {}, new SymbolicTensor(data.shape)) || this; - _this.data = data; - return _this; - } - ConstantNode.prototype.validate = function () { - util.assert(this.data != null, 'Error adding constant: data for placeholder \'' + this.name + - '\' is null or undefined'); - }; - return ConstantNode; -}(Node)); -exports.ConstantNode = ConstantNode; -var ReshapeNode = (function (_super) { - __extends(ReshapeNode, _super); - function ReshapeNode(graph, name, x, shape) { - var _this = _super.call(this, graph, name, { x: x }, new SymbolicTensor(shape)) || this; - _this.name = name; - _this.x = x; - _this.shape = shape; - return _this; - } - ReshapeNode.prototype.validate = function () { - var xSize = util.sizeFromShape(this.x.shape); - var shapeSize = util.sizeFromShape(this.shape); - util.assert(xSize === shapeSize, "Error making reshape operation: input to reshape '" + this.name + "'" + - (" of shape (" + this.x.shape + ") does not match size of ") + - ("requested shape " + this.shape + ".")); - }; - ReshapeNode.X = 'x'; - return ReshapeNode; -}(Node)); -exports.ReshapeNode = ReshapeNode; -var FusedLinearCombinationNode = (function (_super) { - __extends(FusedLinearCombinationNode, _super); - function FusedLinearCombinationNode(graph, t1, t2, c1, c2) { - var _this = _super.call(this, graph, 'Linear Combination', { t1: t1, t2: t2, c1: c1, c2: c2 }, new SymbolicTensor(t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - _this.c1 = c1; - _this.c2 = c2; - return _this; - } - FusedLinearCombinationNode.prototype.validate = function () { - util.assertShapesMatch(this.t1.shape, this.t2.shape); - if (!util.isScalarShape(this.c1.shape)) { - throw new Error('Error adding fusedLinearCombination: c1 is not a scalar, got ' + - ("shape: " + this.c1.shape)); - } - if (!util.isScalarShape(this.c2.shape)) { - throw new Error('Error adding fusedLinearCombination: c2 is not a scalar, got ' + - ("shape: " + this.c2.shape)); - } - }; - FusedLinearCombinationNode.T1 = 't1'; - FusedLinearCombinationNode.T2 = 't2'; - FusedLinearCombinationNode.C1 = 'c1'; - FusedLinearCombinationNode.C2 = 'c2'; - return FusedLinearCombinationNode; -}(Node)); -exports.FusedLinearCombinationNode = FusedLinearCombinationNode; -var AddNode = (function (_super) { - __extends(AddNode, _super); - function AddNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Add', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? - t2.shape : - (t1.shape.length < t2.shape.length ? t2.shape : t1.shape))) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - AddNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape) || - (this.t1.shape.length === 2 && this.t2.shape.length === 1 && - this.t1.shape[1] === this.t2.shape[0]) || - (this.t1.shape.length === 1 && this.t2.shape.length === 2 && - this.t1.shape[0] === this.t2.shape[1]), 'Error adding add operation op: one of inputs must be scalar, ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match,") + - 'or one of them can be broadcasted (2D and 1D).'); - }; - AddNode.T1 = 't1'; - AddNode.T2 = 't2'; - return AddNode; -}(Node)); -exports.AddNode = AddNode; -var SubtractNode = (function (_super) { - __extends(SubtractNode, _super); - function SubtractNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Subtract', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? t2.shape : t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - SubtractNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape), 'Error adding subtract op: one of inputs must be scalar or the ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match.")); - }; - SubtractNode.T1 = 't1'; - SubtractNode.T2 = 't2'; - return SubtractNode; -}(Node)); -exports.SubtractNode = SubtractNode; -var MultiplyNode = (function (_super) { - __extends(MultiplyNode, _super); - function MultiplyNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Multiply', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? t2.shape : t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - MultiplyNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape), 'Error adding multiply op: one of inputs must be scalar or the ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match.")); - }; - MultiplyNode.T1 = 't1'; - MultiplyNode.T2 = 't2'; - return MultiplyNode; -}(Node)); -exports.MultiplyNode = MultiplyNode; -var DivideNode = (function (_super) { - __extends(DivideNode, _super); - function DivideNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Divide', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? t2.shape : t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - DivideNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape), 'Error adding divide op: one of inputs must be scalar or the ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match.")); - }; - DivideNode.T1 = 't1'; - DivideNode.T2 = 't2'; - return DivideNode; -}(Node)); -exports.DivideNode = DivideNode; -var ReduceSumNode = (function (_super) { - __extends(ReduceSumNode, _super); - function ReduceSumNode(graph, x) { - return _super.call(this, graph, 'ReduceSum', { x: x }, new SymbolicTensor([])) || this; - } - ReduceSumNode.prototype.validate = function () { }; - ReduceSumNode.X = 'x'; - return ReduceSumNode; -}(Node)); -exports.ReduceSumNode = ReduceSumNode; -var Concat1DNode = (function (_super) { - __extends(Concat1DNode, _super); - function Concat1DNode(graph, x1, x2) { - return _super.call(this, graph, 'Concat1D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape1D(x1.shape, x2.shape))) || this; - } - Concat1DNode.prototype.validate = function () { }; - Concat1DNode.X1 = 'x1'; - Concat1DNode.X2 = 'x2'; - return Concat1DNode; -}(Node)); -exports.Concat1DNode = Concat1DNode; -var Concat2DNode = (function (_super) { - __extends(Concat2DNode, _super); - function Concat2DNode(graph, x1, x2, axis) { - var _this = _super.call(this, graph, 'Concat2D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape(x1.shape, x2.shape, axis))) || this; - _this.x1 = x1; - _this.x2 = x2; - _this.axis = axis; - return _this; - } - Concat2DNode.prototype.validate = function () { - concat_util.assertParams(this.x1.shape, this.x2.shape, this.axis); - }; - Concat2DNode.X1 = 'x1'; - Concat2DNode.X2 = 'x2'; - Concat2DNode.AXIS = 'axis'; - return Concat2DNode; -}(Node)); -exports.Concat2DNode = Concat2DNode; -var Concat3DNode = (function (_super) { - __extends(Concat3DNode, _super); - function Concat3DNode(graph, x1, x2, axis) { - var _this = _super.call(this, graph, 'Concat3D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape(x1.shape, x2.shape, axis))) || this; - _this.x1 = x1; - _this.x2 = x2; - _this.axis = axis; - return _this; - } - Concat3DNode.prototype.validate = function () { - concat_util.assertParams(this.x1.shape, this.x2.shape, this.axis); - }; - Concat3DNode.X1 = 'x1'; - Concat3DNode.X2 = 'x2'; - Concat3DNode.AXIS = 'axis'; - return Concat3DNode; -}(Node)); -exports.Concat3DNode = Concat3DNode; -var Concat4DNode = (function (_super) { - __extends(Concat4DNode, _super); - function Concat4DNode(graph, x1, x2, axis) { - var _this = _super.call(this, graph, 'Concat4D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape(x1.shape, x2.shape, axis))) || this; - _this.x1 = x1; - _this.x2 = x2; - _this.axis = axis; - return _this; - } - Concat4DNode.prototype.validate = function () { - concat_util.assertParams(this.x1.shape, this.x2.shape, this.axis); - }; - Concat4DNode.X1 = 'x1'; - Concat4DNode.X2 = 'x2'; - Concat4DNode.AXIS = 'axis'; - return Concat4DNode; -}(Node)); -exports.Concat4DNode = Concat4DNode; -function getMatMulOutputShape(x1Shape, x2Shape) { - if (x1Shape.length === 1 && x2Shape.length === 1) { - return [1]; - } - else if (x1Shape.length === 1 && x2Shape.length === 2) { - return [x2Shape[1]]; - } - else if (x1Shape.length === 2 && x2Shape.length === 1) { - return [x1Shape[0]]; - } - return [x1Shape[0], x2Shape[1]]; -} -var MatMulNode = (function (_super) { - __extends(MatMulNode, _super); - function MatMulNode(graph, x1, x2) { - var _this = _super.call(this, graph, 'MatMul', { x1: x1, x2: x2 }, new SymbolicTensor(getMatMulOutputShape(x1.shape, x2.shape))) || this; - _this.x1 = x1; - _this.x2 = x2; - return _this; - } - MatMulNode.prototype.validate = function () { - if (this.x1.shape.length === 2 && this.x2.shape.length === 2) { - util.assert(this.x1.shape[1] === this.x2.shape[0], 'Error adding matmul op: inner shapes of matrices with shapes ' + - (this.x1.shape + " and " + this.x2.shape + " must match.")); - } - else if (this.x1.shape.length === 2 && this.x2.shape.length === 1) { - util.assert(this.x1.shape[1] === this.x2.shape[0], 'Error adding matmul op: second dimension of matrix with shape ' + - this.x1.shape.toString() + - (" must match size of vector with shape " + this.x2.shape + ".")); - } - else if (this.x1.shape.length === 1 && this.x2.shape.length === 2) { - util.assert(this.x1.shape[0] === this.x2.shape[0], "Error adding matmul op: size of vector with shape " + this.x1.shape + - " must match first dimension of matrix with " + - ("shape " + this.x2.shape + ".")); - } - else { - throw new Error('Error adding matmul op: inputs must be vectors or matrices.'); - } - }; - MatMulNode.X1 = 'x1'; - MatMulNode.X2 = 'x2'; - return MatMulNode; -}(Node)); -exports.MatMulNode = MatMulNode; -var Convolution2DNode = (function (_super) { - __extends(Convolution2DNode, _super); - function Convolution2DNode(graph, x, w, b, fieldSize, outputDepth, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this, graph, 'Convolution 2D', { x: x, w: w, b: b }, new SymbolicTensor(conv_util.computeOutputShape3D(x.shape, fieldSize, outputDepth, stride, zeroPad))) || this; - _this.x = x; - _this.w = w; - _this.b = b; - _this.fieldSize = fieldSize; - _this.outputDepth = outputDepth; - _this.stride = stride; - _this.zeroPad = zeroPad; - return _this; - } - Convolution2DNode.prototype.validate = function () { - util.assert(this.x.shape.length === 3, 'Error adding conv2d op: input must be of rank 3, but got shape: ' + - (this.x.shape + ".")); - util.assert(this.w.shape.length === 4, 'Error adding conv2d op: weights must be of rank 4, but got shape: ' + - (this.w.shape + ".")); - util.assert(this.b.shape.length === 1, 'Error adding conv2d op: biases must be of rank 1, but got shape: ' + - (this.b.shape + ".")); - util.assert(this.x.shape[2] === this.w.shape[2], "Error adding conv2d op: depth of input (" + this.x.shape[2] + ") " + - ("must match input depth for weights (" + this.w.shape[2] + ").")); - }; - Convolution2DNode.X = 'x'; - Convolution2DNode.W = 'w'; - Convolution2DNode.B = 'b'; - return Convolution2DNode; -}(Node)); -exports.Convolution2DNode = Convolution2DNode; -var MaxPoolNode = (function (_super) { - __extends(MaxPoolNode, _super); - function MaxPoolNode(graph, x, fieldSize, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this, graph, 'Max pool', { x: x }, new SymbolicTensor(conv_util.computeOutputShape3D(x.shape, fieldSize, x.shape[2], stride, zeroPad))) || this; - _this.x = x; - _this.fieldSize = fieldSize; - _this.stride = stride; - _this.zeroPad = zeroPad; - return _this; - } - MaxPoolNode.prototype.validate = function () { - util.assert(this.x.shape.length === 3, 'Error adding maxPool op: input must be of rank 3, but got shape: ' + - (this.x.shape + ".")); - }; - MaxPoolNode.X = 'x'; - return MaxPoolNode; -}(Node)); -exports.MaxPoolNode = MaxPoolNode; -var ReLUNode = (function (_super) { - __extends(ReLUNode, _super); - function ReLUNode(graph, x) { - return _super.call(this, graph, 'ReLU', { x: x }, new SymbolicTensor(x.shape)) || this; - } - ReLUNode.prototype.validate = function () { }; - ReLUNode.X = 'x'; - return ReLUNode; -}(Node)); -exports.ReLUNode = ReLUNode; -var LeakyReLUNode = (function (_super) { - __extends(LeakyReLUNode, _super); - function LeakyReLUNode(graph, x, alpha) { - var _this = _super.call(this, graph, 'LeakyReLU', { x: x }, new SymbolicTensor(x.shape)) || this; - _this.alpha = alpha; - return _this; - } - LeakyReLUNode.prototype.validate = function () { }; - LeakyReLUNode.X = 'x'; - return LeakyReLUNode; -}(Node)); -exports.LeakyReLUNode = LeakyReLUNode; -var PReLUNode = (function (_super) { - __extends(PReLUNode, _super); - function PReLUNode(graph, x, alpha) { - var _this = _super.call(this, graph, 'PReLU', { x: x, alpha: alpha }, new SymbolicTensor(x.shape)) || this; - _this.x = x; - _this.alpha = alpha; - return _this; - } - PReLUNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.x.shape, this.alpha.shape), 'Error adding pRelu op: the ' + - ("shapes x: " + this.x.shape + " and alpha: " + this.alpha.shape + " must match.")); - }; - PReLUNode.X = 'x'; - PReLUNode.ALPHA = 'alpha'; - return PReLUNode; -}(Node)); -exports.PReLUNode = PReLUNode; -var EluNode = (function (_super) { - __extends(EluNode, _super); - function EluNode(graph, x) { - return _super.call(this, graph, 'Elu', { x: x }, new SymbolicTensor(x.shape)) || this; - } - EluNode.prototype.validate = function () { }; - EluNode.X = 'x'; - return EluNode; -}(Node)); -exports.EluNode = EluNode; -var ExpNode = (function (_super) { - __extends(ExpNode, _super); - function ExpNode(graph, x) { - return _super.call(this, graph, 'Exp', { x: x }, new SymbolicTensor(x.shape)) || this; - } - ExpNode.prototype.validate = function () { }; - ExpNode.X = 'x'; - return ExpNode; -}(Node)); -exports.ExpNode = ExpNode; -var LogNode = (function (_super) { - __extends(LogNode, _super); - function LogNode(graph, x) { - return _super.call(this, graph, 'Log', { x: x }, new SymbolicTensor(x.shape)) || this; - } - LogNode.prototype.validate = function () { }; - LogNode.X = 'x'; - return LogNode; -}(Node)); -exports.LogNode = LogNode; -var TanHNode = (function (_super) { - __extends(TanHNode, _super); - function TanHNode(graph, x) { - return _super.call(this, graph, 'TanH', { x: x }, new SymbolicTensor(x.shape)) || this; - } - TanHNode.prototype.validate = function () { }; - TanHNode.X = 'x'; - return TanHNode; -}(Node)); -exports.TanHNode = TanHNode; -var SigmoidNode = (function (_super) { - __extends(SigmoidNode, _super); - function SigmoidNode(graph, x) { - return _super.call(this, graph, 'Sigmoid', { x: x }, new SymbolicTensor(x.shape)) || this; - } - SigmoidNode.prototype.validate = function () { }; - SigmoidNode.X = 'x'; - return SigmoidNode; -}(Node)); -exports.SigmoidNode = SigmoidNode; -var SquareNode = (function (_super) { - __extends(SquareNode, _super); - function SquareNode(graph, x) { - return _super.call(this, graph, 'Square', { x: x }, new SymbolicTensor(x.shape)) || this; - } - SquareNode.prototype.validate = function () { }; - SquareNode.X = 'x'; - return SquareNode; -}(Node)); -exports.SquareNode = SquareNode; -var SoftmaxCrossEntropyCostNode = (function (_super) { - __extends(SoftmaxCrossEntropyCostNode, _super); - function SoftmaxCrossEntropyCostNode(graph, x, target) { - var _this = _super.call(this, graph, 'SoftmaxCrossEntropyCost', { x: x, target: target }, new SymbolicTensor([])) || this; - _this.x = x; - _this.target = target; - return _this; - } - SoftmaxCrossEntropyCostNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.x.shape, this.target.shape), "Error adding softmaxCrossEntropyCost op: x shape (" + this.x.shape + ") " + - ("must match target shape (" + this.target.shape + ").")); - }; - SoftmaxCrossEntropyCostNode.X = 'x'; - SoftmaxCrossEntropyCostNode.TARGET = 'target'; - return SoftmaxCrossEntropyCostNode; -}(Node)); -exports.SoftmaxCrossEntropyCostNode = SoftmaxCrossEntropyCostNode; -var SoftmaxNode = (function (_super) { - __extends(SoftmaxNode, _super); - function SoftmaxNode(graph, x) { - var _this = _super.call(this, graph, 'Softmax', { x: x }, new SymbolicTensor(x.shape)) || this; - _this.x = x; - return _this; - } - SoftmaxNode.prototype.validate = function () { - util.assert(this.x.shape.length === 1, 'The input to a softmax must be a 1-D tensor'); - util.assert(this.x.shape[0] >= 2, 'The input to a softmax must have at least 2 values'); - }; - SoftmaxNode.X = 'x'; - return SoftmaxNode; -}(Node)); -exports.SoftmaxNode = SoftmaxNode; -var MeanSquaredCostNode = (function (_super) { - __extends(MeanSquaredCostNode, _super); - function MeanSquaredCostNode(graph, label, prediction) { - var _this = _super.call(this, graph, 'Mean Squared Cost', { label: label, prediction: prediction }, new SymbolicTensor([])) || this; - _this.label = label; - _this.prediction = prediction; - return _this; - } - MeanSquaredCostNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.label.shape, this.prediction.shape), "Error adding meanSquaredCost op: label shape (" + this.label.shape + ") " + - ("must match prediction shape (" + this.prediction.shape + ").")); - }; - MeanSquaredCostNode.LABEL = 'label'; - MeanSquaredCostNode.PREDICTION = 'prediction'; - return MeanSquaredCostNode; -}(Node)); -exports.MeanSquaredCostNode = MeanSquaredCostNode; -var ArgMaxNode = (function (_super) { - __extends(ArgMaxNode, _super); - function ArgMaxNode(graph, x) { - var _this = _super.call(this, graph, 'ArgMax', { x: x }, new SymbolicTensor([1])) || this; - _this.x = x; - return _this; - } - ArgMaxNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.x.shape) > 0, 'Error adding argmax op: input tensor must have at least one entry.'); - }; - ArgMaxNode.X = 'x'; - return ArgMaxNode; -}(Node)); -exports.ArgMaxNode = ArgMaxNode; -var ArgMaxEqualsNode = (function (_super) { - __extends(ArgMaxEqualsNode, _super); - function ArgMaxEqualsNode(graph, x1, x2) { - var _this = _super.call(this, graph, 'ArgMaxEquals', { x1: x1, x2: x2 }, new SymbolicTensor([1])) || this; - _this.x1 = x1; - _this.x2 = x2; - return _this; - } - ArgMaxEqualsNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.x1.shape, this.x2.shape), "Error adding ArgMaxEquals op: x1 shape (" + this.x1.shape + ") " + - ("must match x2 shape (" + this.x2.shape + ").")); - }; - ArgMaxEqualsNode.X1 = 'x1'; - ArgMaxEqualsNode.X2 = 'x2'; - return ArgMaxEqualsNode; -}(Node)); -exports.ArgMaxEqualsNode = ArgMaxEqualsNode; - -},{"../ops/concat_util":113,"../ops/conv_util":115,"../tensor":146,"../util":151,"./initializers":42}],40:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var session_1 = require("./session"); -var DEFAULT_EVAL_INTERVAL_MS = 1500; -var DEFAULT_COST_INTERVAL_MS = 500; -var DEFAULT_INFERENCE_EXAMPLE_INTERVAL_MS = 3000; -var MetricReduction; -(function (MetricReduction) { - MetricReduction[MetricReduction["SUM"] = 0] = "SUM"; - MetricReduction[MetricReduction["MEAN"] = 1] = "MEAN"; -})(MetricReduction = exports.MetricReduction || (exports.MetricReduction = {})); -var GraphRunner = (function () { - function GraphRunner(math, session, eventObserver) { - this.math = math; - this.session = session; - this.eventObserver = eventObserver; - this.lastCostTimestamp = 0; - this.lastEvalTimestamp = 0; - this.resetStatistics(); - this.zeroScalar = tensor_1.Scalar.new(0); - } - GraphRunner.prototype.resetStatistics = function () { - this.totalBatchesTrained = 0; - }; - GraphRunner.prototype.train = function (costTensor, trainFeedEntries, batchSize, optimizer, numBatches, metricTensor, metricFeedEntries, metricBatchSize, metricReduction, evalIntervalMs, costIntervalMs) { - if (metricReduction === void 0) { metricReduction = MetricReduction.MEAN; } - if (evalIntervalMs === void 0) { evalIntervalMs = DEFAULT_EVAL_INTERVAL_MS; } - if (costIntervalMs === void 0) { costIntervalMs = DEFAULT_COST_INTERVAL_MS; } - this.costTensor = costTensor; - this.trainFeedEntries = trainFeedEntries; - this.metricTensor = metricTensor; - this.metricFeedEntries = metricFeedEntries; - if (metricBatchSize != null && this.metricBatchSize !== metricBatchSize) { - if (this.metricBatchSizeScalar != null) { - this.metricBatchSizeScalar.dispose(); - } - this.metricBatchSizeScalar = tensor_1.Scalar.new(metricBatchSize); - } - this.metricBatchSize = metricBatchSize; - this.metricReduction = metricReduction; - this.batchSize = batchSize; - this.optimizer = optimizer; - this.metricIntervalMs = evalIntervalMs; - this.costIntervalMs = costIntervalMs; - this.currentTrainLoopNumBatches = numBatches; - this.batchesTrainedThisRun = 0; - this.isTraining = true; - this.trainStartTimestamp = performance.now(); - this.trainNetwork(); - }; - GraphRunner.prototype.stopTraining = function () { - this.isTraining = false; - }; - GraphRunner.prototype.resumeTraining = function () { - this.isTraining = true; - this.trainNetwork(); - }; - GraphRunner.prototype.trainNetwork = function () { - var _this = this; - if (this.batchesTrainedThisRun === this.currentTrainLoopNumBatches) { - this.stopTraining(); - } - if (!this.isTraining) { - if (this.eventObserver.doneTrainingCallback != null) { - this.eventObserver.doneTrainingCallback(); - } - return; - } - var start = performance.now(); - var shouldComputeCost = this.eventObserver.avgCostCallback != null && - (start - this.lastCostTimestamp > this.costIntervalMs); - if (shouldComputeCost) { - this.lastCostTimestamp = start; - } - var costReduction = shouldComputeCost ? session_1.CostReduction.MEAN : session_1.CostReduction.NONE; - globals_1.tidy(function () { - var avgCost = _this.session.train(_this.costTensor, _this.trainFeedEntries, _this.batchSize, _this.optimizer, costReduction); - if (shouldComputeCost) { - var trainTime = performance.now() - start; - _this.eventObserver.avgCostCallback(avgCost); - if (_this.eventObserver.trainExamplesPerSecCallback != null) { - var examplesPerSec = (_this.batchSize * 1000 / trainTime); - _this.eventObserver.trainExamplesPerSecCallback(examplesPerSec); - } - } - if (_this.eventObserver.metricCallback != null && - _this.metricFeedEntries != null && - start - _this.lastEvalTimestamp > _this.metricIntervalMs) { - _this.lastEvalTimestamp = start; - if (_this.lastComputedMetric != null) { - _this.lastComputedMetric.dispose(); - } - _this.lastComputedMetric = _this.computeMetric(); - _this.eventObserver.metricCallback(_this.lastComputedMetric); - } - if (_this.eventObserver.totalTimeCallback != null) { - _this.eventObserver.totalTimeCallback((start - _this.trainStartTimestamp) / 1000); - } - _this.batchesTrainedThisRun++; - _this.totalBatchesTrained++; - if (_this.eventObserver.batchesTrainedCallback != null) { - _this.eventObserver.batchesTrainedCallback(_this.totalBatchesTrained); - } - }); - requestAnimationFrame(function () { return _this.trainNetwork(); }); - }; - GraphRunner.prototype.infer = function (inferenceTensor, inferenceFeedEntries, inferenceExampleIntervalMs, inferenceExampleCount, numPasses) { - var _this = this; - if (inferenceExampleIntervalMs === void 0) { inferenceExampleIntervalMs = DEFAULT_INFERENCE_EXAMPLE_INTERVAL_MS; } - if (inferenceExampleCount === void 0) { inferenceExampleCount = 5; } - if (this.eventObserver.inferenceExamplesCallback == null && - this.eventObserver.inferenceExamplesPerSecCallback == null) { - throw new Error('Cannot start inference loop, no inference example or ' + - 'examples/sec observer provided.'); - } - for (var i = 0; i < inferenceFeedEntries.length; i++) { - var feedEntry = inferenceFeedEntries[i]; - if (feedEntry.data instanceof tensor_1.Tensor) { - throw new Error('Cannot start inference on the model runner with feed entries of ' + - 'type NDArray. Please use InputProviders.'); - } - } - this.inferenceExampleIntervalMs = inferenceExampleIntervalMs; - this.inferenceTensor = inferenceTensor; - this.inferenceFeedEntries = inferenceFeedEntries; - this.inferenceExampleCount = inferenceExampleCount; - this.currentInferenceLoopNumPasses = numPasses; - if (!this.isInferring) { - this.inferencePassesThisRun = 0; - requestAnimationFrame(function () { return _this.inferNetwork(); }); - } - this.isInferring = true; - }; - GraphRunner.prototype.inferNetwork = function () { - var _this = this; - if (!this.isInferring || - this.inferencePassesThisRun === this.currentInferenceLoopNumPasses) { - return; - } - globals_1.tidy(function () { - var feeds = []; - var inferenceValues = []; - var start = performance.now(); - for (var i = 0; i < _this.inferenceExampleCount; i++) { - var ndarrayFeedEntries = []; - for (var j = 0; j < _this.inferenceFeedEntries.length; j++) { - var feedEntry = _this.inferenceFeedEntries[j]; - var nextCopy = feedEntry.data.getNextCopy(); - ndarrayFeedEntries.push({ tensor: feedEntry.tensor, data: nextCopy }); - } - feeds.push(ndarrayFeedEntries); - inferenceValues.push(_this.session.eval(_this.inferenceTensor, ndarrayFeedEntries)); - } - if (_this.eventObserver.inferenceExamplesPerSecCallback != null) { - inferenceValues[inferenceValues.length - 1].dataSync(); - var inferenceExamplesPerSecTime = performance.now() - start; - var examplesPerSec = (_this.inferenceExampleCount * 1000 / inferenceExamplesPerSecTime); - _this.eventObserver.inferenceExamplesPerSecCallback(examplesPerSec); - } - if (_this.eventObserver.inferenceExamplesCallback != null) { - _this.eventObserver.inferenceExamplesCallback(feeds, inferenceValues); - } - _this.inferencePassesThisRun++; - }); - this.lastInferTimeoutID = window.setTimeout(function () { return _this.inferNetwork(); }, this.inferenceExampleIntervalMs); - }; - GraphRunner.prototype.stopInferring = function () { - this.isInferring = false; - window.clearTimeout(this.lastInferTimeoutID); - }; - GraphRunner.prototype.isInferenceRunning = function () { - return this.isInferring; - }; - GraphRunner.prototype.computeMetric = function () { - var _this = this; - if (this.metricFeedEntries == null) { - throw new Error('Cannot compute metric, no metric FeedEntries provided.'); - } - var metric = this.zeroScalar; - return globals_1.tidy(function () { - for (var i = 0; i < _this.metricBatchSize; i++) { - var metricValue = _this.session.eval(_this.metricTensor, _this.metricFeedEntries); - metric = _this.math.add(metric, metricValue.toFloat()); - } - if (_this.metricReduction === MetricReduction.MEAN) { - metric = _this.math.divide(metric, _this.metricBatchSizeScalar); - } - return metric; - }); - }; - GraphRunner.prototype.getTotalBatchesTrained = function () { - return this.totalBatchesTrained; - }; - GraphRunner.prototype.getLastComputedMetric = function () { - return this.lastComputedMetric; - }; - GraphRunner.prototype.setMath = function (math) { - this.math = math; - }; - GraphRunner.prototype.setSession = function (session) { - this.session = session; - }; - GraphRunner.prototype.setInferenceTensor = function (inferenceTensor) { - this.inferenceTensor = inferenceTensor; - }; - GraphRunner.prototype.setInferenceExampleCount = function (inferenceExampleCount) { - this.inferenceExampleCount = inferenceExampleCount; - }; - return GraphRunner; -}()); -exports.GraphRunner = GraphRunner; - -},{"../globals":35,"../tensor":146,"./session":64}],41:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var graph_1 = require("./graph"); -var priority_queue = require("./priority_queue"); -var priority_queue_1 = require("./priority_queue"); -function getUnorderedEvaluationSet(nodes, terminatingNodes) { - var terminatingNodeMap = {}; - var seen = {}; - var set = []; - var visit = nodes.slice(); - terminatingNodes.forEach(function (node) { return terminatingNodeMap[node.id] = node; }); - var _loop_1 = function () { - var cur = visit.pop(); - if (seen[cur.id] == null) { - if (terminatingNodeMap[cur.id] == null) { - Object.keys(cur.inputs) - .map(function (inputName) { return cur.inputs[inputName]; }) - .forEach(function (input) { return visit.push(input.node); }); - } - set.push(cur); - seen[cur.id] = cur; - } - }; - while (visit.length !== 0) { - _loop_1(); - } - return set; -} -exports.getUnorderedEvaluationSet = getUnorderedEvaluationSet; -function getOrderedEvaluationSet(unorderedEvaluationSet) { - var set = []; - var nodeIndices = {}; - var pendingDependencies = {}; - var nodeQueue = new priority_queue_1.PriorityQueue(function (a, b) { return priority_queue.defaultCompare(pendingDependencies[a.id], pendingDependencies[b.id]); }, function (node, newIndex) { return nodeIndices[node.id] = newIndex; }); - unorderedEvaluationSet.forEach(function (node) { return pendingDependencies[node.id] = 0; }); - unorderedEvaluationSet.forEach(function (node) { return Object.keys(node.inputs) - .map(function (key) { return node.inputs[key]; }) - .forEach(function (input) { - if (unorderedEvaluationSet.indexOf(input.node) !== -1) { - pendingDependencies[input.node.id]++; - } - }); }); - unorderedEvaluationSet.forEach(function (node) { return nodeQueue.enqueue(node); }); - while (!nodeQueue.empty()) { - set.unshift(nodeQueue.dequeue()); - Object.keys(set[0].inputs).map(function (key) { return set[0].inputs[key]; }).forEach(function (input) { - if (unorderedEvaluationSet.indexOf(input.node) === -1) { - return; - } - pendingDependencies[input.node.id]--; - nodeQueue.update(input.node, nodeIndices[input.node.id]); - }); - } - return set; -} -exports.getOrderedEvaluationSet = getOrderedEvaluationSet; -function isInputNode(node) { - return Object.keys(node.inputs).length === 0; -} -exports.isInputNode = isInputNode; -function shouldBackProp(t) { - return !(t.node instanceof graph_1.ConstantNode); -} -exports.shouldBackProp = shouldBackProp; -function isPassthroughNode(node, map) { - var keys = Object.keys(node.inputs); - for (var i = 0; i < keys.length; i++) { - var input = node.inputs[keys[i]]; - if (map.get(input, true) === map.get(node.output, true)) { - return true; - } - } - return false; -} -exports.isPassthroughNode = isPassthroughNode; - -},{"./graph":39,"./priority_queue":63}],42:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ops = require("../ops/ops"); -var VarianceScalingInitializer = (function () { - function VarianceScalingInitializer(scale, mode, distribution) { - if (scale === void 0) { scale = 1.0; } - if (mode === void 0) { mode = 'fan_in'; } - if (distribution === void 0) { distribution = 'normal'; } - this.scale = scale; - this.mode = mode; - this.distribution = distribution; - } - VarianceScalingInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - var n = 0; - if (this.mode === 'fan_in') { - n = inputUnits; - } - else if (this.mode === 'fan_out') { - n = outputUnits; - } - else if (this.mode === 'fan_avg') { - n = (inputUnits + outputUnits) / 2; - } - else { - throw new Error("Unexpected mode for variance scaling initializer: " + this.mode); - } - if (this.distribution === 'normal') { - return ops.truncatedNormal(weightsShape, 0.0, Math.sqrt(this.scale / n)); - } - else if (this.distribution === 'uniform') { - return ops.randomUniform(weightsShape, 0.0, Math.sqrt(3 * this.scale / n)); - } - else { - throw new Error("Unexpected distribution for variance scaling initializer: " + - ("" + this.distribution)); - } - }; - return VarianceScalingInitializer; -}()); -exports.VarianceScalingInitializer = VarianceScalingInitializer; -var ZerosInitializer = (function () { - function ZerosInitializer() { - } - ZerosInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.zeros(weightsShape); - }; - return ZerosInitializer; -}()); -exports.ZerosInitializer = ZerosInitializer; -var OnesInitializer = (function () { - function OnesInitializer() { - } - OnesInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.ones(weightsShape); - }; - return OnesInitializer; -}()); -exports.OnesInitializer = OnesInitializer; -var ConstantInitializer = (function () { - function ConstantInitializer(value) { - if (value === void 0) { value = 0; } - this.value = value; - } - ConstantInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.fill(weightsShape, this.value); - }; - return ConstantInitializer; -}()); -exports.ConstantInitializer = ConstantInitializer; -var TensorInitializer = (function () { - function TensorInitializer(tensor) { - this.tensor = tensor; - } - TensorInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return this.tensor; - }; - return TensorInitializer; -}()); -exports.TensorInitializer = TensorInitializer; -var RandomNormalInitializer = (function () { - function RandomNormalInitializer(mean, stdev) { - if (mean === void 0) { mean = 0; } - if (stdev === void 0) { stdev = .05; } - this.mean = mean; - this.stdev = stdev; - } - RandomNormalInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.randomNormal(weightsShape, this.mean, this.stdev); - }; - return RandomNormalInitializer; -}()); -exports.RandomNormalInitializer = RandomNormalInitializer; -var RandomTruncatedNormalInitializer = (function () { - function RandomTruncatedNormalInitializer(mean, stdev) { - if (mean === void 0) { mean = 0; } - if (stdev === void 0) { stdev = .05; } - this.mean = mean; - this.stdev = stdev; - } - RandomTruncatedNormalInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.truncatedNormal(weightsShape, this.mean, this.stdev); - }; - return RandomTruncatedNormalInitializer; -}()); -exports.RandomTruncatedNormalInitializer = RandomTruncatedNormalInitializer; -var RandomUniformInitializer = (function () { - function RandomUniformInitializer(minval, maxval) { - if (minval === void 0) { minval = -.05; } - if (maxval === void 0) { maxval = .05; } - this.minval = minval; - this.maxval = maxval; - } - RandomUniformInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.randomUniform(weightsShape, this.minval, this.maxval); - }; - return RandomUniformInitializer; -}()); -exports.RandomUniformInitializer = RandomUniformInitializer; - -},{"../ops/ops":123}],43:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var graph_1 = require("./graph"); -var graph_util = require("./graph_util"); -var add_1 = require("./ops/add"); -var argmax_1 = require("./ops/argmax"); -var argmaxequals_1 = require("./ops/argmaxequals"); -var concat_1 = require("./ops/concat"); -var convolution_1 = require("./ops/convolution"); -var divide_1 = require("./ops/divide"); -var element_wise_activation_1 = require("./ops/element_wise_activation"); -var element_wise_cost_1 = require("./ops/element_wise_cost"); -var exp_1 = require("./ops/exp"); -var linear_combination_1 = require("./ops/linear_combination"); -var log_1 = require("./ops/log"); -var matmul_1 = require("./ops/matmul"); -var max_pool_1 = require("./ops/max_pool"); -var multiply_1 = require("./ops/multiply"); -var reduce_sum_1 = require("./ops/reduce_sum"); -var reshape_1 = require("./ops/reshape"); -var softmax_1 = require("./ops/softmax"); -var subtract_1 = require("./ops/subtract"); -function emitFromGraphNodes(nodes) { - var ops = []; - nodes.forEach(function (node) { return Array.prototype.push.apply(ops, emitOpFromNode(node)); }); - return ops; -} -exports.emitFromGraphNodes = emitFromGraphNodes; -function emitOpFromNode(node) { - if (node instanceof graph_1.ReshapeNode) { - return [new reshape_1.Reshape(node.inputs[graph_1.ReshapeNode.X], node.output)]; - } - else if (node instanceof graph_1.MatMulNode) { - var x1 = node.inputs[graph_1.MatMulNode.X1]; - var x2 = node.inputs[graph_1.MatMulNode.X2]; - return [new matmul_1.MatMul(x1, x2, node.output)]; - } - else if (node instanceof graph_1.Convolution2DNode) { - var w = node.inputs[graph_1.Convolution2DNode.W]; - var x = node.inputs[graph_1.Convolution2DNode.X]; - var b = node.inputs[graph_1.Convolution2DNode.B]; - return [new convolution_1.Convolution2D(w, x, b, node.output, node.fieldSize, node.outputDepth, node.stride, node.zeroPad)]; - } - else if (node instanceof graph_1.MaxPoolNode) { - var x = node.inputs[graph_1.MaxPoolNode.X]; - return [new max_pool_1.MaxPool(x, node.output, node.fieldSize, node.stride, node.zeroPad)]; - } - else if (node instanceof graph_1.ExpNode) { - return [new exp_1.Exp(node.inputs[graph_1.ExpNode.X], node.output)]; - } - else if (node instanceof graph_1.LogNode) { - return [new log_1.Log(node.inputs[graph_1.LogNode.X], node.output)]; - } - else if (node instanceof graph_1.ReLUNode) { - return [new element_wise_activation_1.ReLU(node.inputs[graph_1.ReLUNode.X], node.output)]; - } - else if (node instanceof graph_1.LeakyReLUNode) { - return [new element_wise_activation_1.LeakyReLU(node.inputs[graph_1.LeakyReLUNode.X], node.output, node.alpha)]; - } - else if (node instanceof graph_1.PReLUNode) { - return [new element_wise_activation_1.PReLU(node.inputs[graph_1.PReLUNode.X], node.inputs[graph_1.PReLUNode.ALPHA], node.output)]; - } - else if (node instanceof graph_1.EluNode) { - return [new element_wise_activation_1.Elu(node.inputs[graph_1.EluNode.X], node.output)]; - } - else if (node instanceof graph_1.TanHNode) { - return [new element_wise_activation_1.TanH(node.inputs[graph_1.TanHNode.X], node.output)]; - } - else if (node instanceof graph_1.SigmoidNode) { - return [new element_wise_activation_1.Sigmoid(node.inputs[graph_1.SigmoidNode.X], node.output)]; - } - else if (node instanceof graph_1.SoftmaxCrossEntropyCostNode) { - var x = node.inputs[graph_1.SoftmaxCrossEntropyCostNode.X]; - var target = node.inputs[graph_1.SoftmaxCrossEntropyCostNode.TARGET]; - return [new softmax_1.SoftmaxCrossEntropyCost(x, target, node.output)]; - } - else if (node instanceof graph_1.SoftmaxNode) { - return [new softmax_1.Softmax(node.inputs[graph_1.SoftmaxNode.X], node.output)]; - } - else if (node instanceof graph_1.MeanSquaredCostNode) { - var label = node.inputs[graph_1.MeanSquaredCostNode.LABEL]; - var prediction = node.inputs[graph_1.MeanSquaredCostNode.PREDICTION]; - return [new element_wise_cost_1.MeanSquaredCost(label, prediction, node.output)]; - } - else if (node instanceof graph_1.ArgMaxEqualsNode) { - return [new argmaxequals_1.ArgMaxEquals(node.inputs[graph_1.ArgMaxEqualsNode.X1], node.inputs[graph_1.ArgMaxEqualsNode.X2], node.output)]; - } - else if (node instanceof graph_1.ArgMaxNode) { - return [new argmax_1.ArgMax(node.x, node.output)]; - } - else if (node instanceof graph_1.FusedLinearCombinationNode) { - return [new linear_combination_1.LinearCombination(node.inputs[graph_1.FusedLinearCombinationNode.T1], node.inputs[graph_1.FusedLinearCombinationNode.T2], node.inputs[graph_1.FusedLinearCombinationNode.C1], node.inputs[graph_1.FusedLinearCombinationNode.C2], node.output)]; - } - else if (node instanceof graph_1.Concat1DNode) { - return [new concat_1.Concat1D(node.inputs[graph_1.Concat1DNode.X1], node.inputs[graph_1.Concat1DNode.X2], node.output)]; - } - else if (node instanceof graph_1.Concat2DNode) { - return [new concat_1.Concat2D(node.inputs[graph_1.Concat2DNode.X1], node.inputs[graph_1.Concat2DNode.X2], node.axis, node.output)]; - } - else if (node instanceof graph_1.Concat3DNode) { - return [new concat_1.Concat3D(node.inputs[graph_1.Concat3DNode.X1], node.inputs[graph_1.Concat3DNode.X2], node.axis, node.output)]; - } - else if (node instanceof graph_1.Concat4DNode) { - return [new concat_1.Concat4D(node.inputs[graph_1.Concat4DNode.X1], node.inputs[graph_1.Concat4DNode.X2], node.axis, node.output)]; - } - else if (node instanceof graph_1.SquareNode) { - return [new element_wise_activation_1.Square(node.inputs[graph_1.SquareNode.X], node.output)]; - } - else if (node instanceof graph_1.AddNode) { - return [new add_1.Add(node.inputs[graph_1.AddNode.T1], node.inputs[graph_1.AddNode.T2], node.output)]; - } - else if (node instanceof graph_1.SubtractNode) { - return [new subtract_1.Subtract(node.inputs[graph_1.SubtractNode.T1], node.inputs[graph_1.SubtractNode.T2], node.output)]; - } - else if (node instanceof graph_1.MultiplyNode) { - return [new multiply_1.Multiply(node.inputs[graph_1.MultiplyNode.T1], node.inputs[graph_1.MultiplyNode.T2], node.output)]; - } - else if (node instanceof graph_1.DivideNode) { - return [new divide_1.Divide(node.inputs[graph_1.DivideNode.T1], node.inputs[graph_1.DivideNode.T2], node.output)]; - } - else if (node instanceof graph_1.ReduceSumNode) { - return [new reduce_sum_1.ReduceSum(node.inputs[graph_1.ReduceSumNode.X], node.output)]; - } - else if (graph_util.isInputNode(node)) { - return []; - } - else { - throw Error("Unsupported node type: " + node.constructor.name); - } -} - -},{"./graph":39,"./graph_util":41,"./ops/add":44,"./ops/argmax":45,"./ops/argmaxequals":46,"./ops/concat":47,"./ops/convolution":48,"./ops/divide":49,"./ops/element_wise_activation":50,"./ops/element_wise_cost":51,"./ops/exp":52,"./ops/linear_combination":53,"./ops/log":54,"./ops/matmul":55,"./ops/max_pool":56,"./ops/multiply":57,"./ops/reduce_sum":59,"./ops/reshape":60,"./ops/softmax":61,"./ops/subtract":62}],44:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Add = (function (_super) { - __extends(Add, _super); - function Add(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - util.assert(util.sizeFromShape(x1Tensor.shape) === 1 || - util.sizeFromShape(x2Tensor.shape) === 1 || - util.arraysEqual(x1Tensor.shape, x2Tensor.shape) || - (x1Tensor.shape.length === 2 && x2Tensor.shape.length === 1 && - x1Tensor.shape[1] === x2Tensor.shape[0]) || - (x1Tensor.shape.length === 1 && x2Tensor.shape.length === 2 && - x1Tensor.shape[0] === x2Tensor.shape[1]), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape, ' + - 'or one of them can be broadcasted (2D and 1D).'); - return _this; - } - Add.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(x1.shape)) { - result = math.scalarPlusArray(x1, x2); - } - else if (util.isScalarShape(x2.shape)) { - result = math.scalarPlusArray(x2, x1); - } - else { - result = math.add(x1, x2); - } - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - Add.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - if (_this.x1Tensor.shape.length === 1 && - _this.x2Tensor.shape.length === 2 && - _this.x1Tensor.shape[0] === _this.x2Tensor.shape[1]) { - var sum = math.sum(dy, 0); - gradientArrays.add(_this.x1Tensor, sum); - } - else if (util.isScalarShape(_this.x1Tensor.shape)) { - var sum = math.sum(dy); - gradientArrays.add(_this.x1Tensor, sum); - } - else { - gradientArrays.add(_this.x1Tensor, math.clone(dy)); - } - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - if (_this.x1Tensor.shape.length === 2 && - _this.x2Tensor.shape.length === 1 && - _this.x1Tensor.shape[1] === _this.x2Tensor.shape[0]) { - var sum = math.sum(dy, 0); - gradientArrays.add(_this.x2Tensor, sum); - } - else if (util.isScalarShape(_this.x2Tensor.shape)) { - var sum = math.sum(dy); - gradientArrays.add(_this.x2Tensor, sum); - } - else { - gradientArrays.add(_this.x2Tensor, math.clone(dy)); - } - } - }); - }; - Add.prototype.dispose = function () { - if (this.dySizeScalar != null) { - this.dySizeScalar.dispose(); - } - }; - return Add; -}(op_1.Operation)); -exports.Add = Add; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],45:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var op_1 = require("./op"); -var ArgMax = (function (_super) { - __extends(ArgMax, _super); - function ArgMax(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - return _this; - } - ArgMax.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.argMax(x))); - }); - }; - ArgMax.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - throw new Error('ArgMax backprop unimplemented'); - }; - return ArgMax; -}(op_1.Operation)); -exports.ArgMax = ArgMax; - -},{"../../globals":35,"./op":58}],46:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var op_1 = require("./op"); -var ArgMaxEquals = (function (_super) { - __extends(ArgMaxEquals, _super); - function ArgMaxEquals(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - return _this; - } - ArgMaxEquals.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.argMaxEquals(x1, x2))); - }); - }; - ArgMaxEquals.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - throw new Error('ArgMaxEquals backprop unimplemented'); - }; - return ArgMaxEquals; -}(op_1.Operation)); -exports.ArgMaxEquals = ArgMaxEquals; - -},{"../../globals":35,"./op":58}],47:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var concat_util = require("../../ops/concat_util"); -var util = require("../../util"); -var op_1 = require("./op"); -var Concat1D = (function (_super) { - __extends(Concat1D, _super); - function Concat1D(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - return _this; - } - Concat1D.prototype.feedForward = function (math, inferecenArrays) { - var _this = this; - var x1 = inferecenArrays.get(this.x1Tensor); - var x2 = inferecenArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat1D(x1, x2); - inferecenArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat1D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, 0, gradientArrays, inferenceArrays); - }); - }; - return Concat1D; -}(op_1.Operation)); -exports.Concat1D = Concat1D; -var Concat2D = (function (_super) { - __extends(Concat2D, _super); - function Concat2D(x1Tensor, x2Tensor, axis, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.axis = axis; - _this.yTensor = yTensor; - concat_util.assertParams(x1Tensor.shape, x2Tensor.shape, axis); - return _this; - } - Concat2D.prototype.feedForward = function (math, inferecenArrays) { - var _this = this; - var x1 = inferecenArrays.get(this.x1Tensor); - var x2 = inferecenArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat2D(x1, x2, _this.axis); - inferecenArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat2D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, _this.axis, gradientArrays, inferenceArrays); - }); - }; - return Concat2D; -}(op_1.Operation)); -exports.Concat2D = Concat2D; -var Concat3D = (function (_super) { - __extends(Concat3D, _super); - function Concat3D(x1Tensor, x2Tensor, axis, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.axis = axis; - _this.yTensor = yTensor; - concat_util.assertParams(x1Tensor.shape, x2Tensor.shape, axis); - return _this; - } - Concat3D.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat3D(x1, x2, _this.axis); - inferenceArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat3D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, _this.axis, gradientArrays, inferenceArrays); - }); - }; - return Concat3D; -}(op_1.Operation)); -exports.Concat3D = Concat3D; -var Concat4D = (function (_super) { - __extends(Concat4D, _super); - function Concat4D(x1Tensor, x2Tensor, axis, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.axis = axis; - _this.yTensor = yTensor; - concat_util.assertParams(x1Tensor.shape, x2Tensor.shape, axis); - return _this; - } - Concat4D.prototype.feedForward = function (math, inferecenArrays) { - var _this = this; - var x1 = inferecenArrays.get(this.x1Tensor); - var x2 = inferecenArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat4D(x1, x2, _this.axis); - inferecenArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat4D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, _this.axis, gradientArrays, inferenceArrays); - }); - }; - return Concat4D; -}(op_1.Operation)); -exports.Concat4D = Concat4D; -function concatBackProp(math, aTensor, bTensor, yTensor, axis, gradArrays, infArrays) { - var dy = gradArrays.get(yTensor); - var a = infArrays.get(aTensor); - var b = infArrays.get(bTensor); - var a2D = a.as2D(-1, util.sizeFromShape(a.shape.slice(axis))); - var b2D = b.as2D(-1, util.sizeFromShape(b.shape.slice(axis))); - var _a = concat_util.computeGradientSliceShapes(a2D.shape, b2D.shape), aBegin = _a.aBegin, aSize = _a.aSize, bBegin = _a.bBegin, bSize = _a.bSize; - var dy2D = dy.as2D(-1, a2D.shape[1] + b2D.shape[1]); - var slice1Result = math.slice2D(dy2D, aBegin, aSize).reshapeAs(a); - var slice2Result = math.slice2D(dy2D, bBegin, bSize).reshapeAs(b); - gradArrays.add(aTensor, slice1Result); - gradArrays.add(bTensor, slice2Result); -} - -},{"../../globals":35,"../../ops/concat_util":113,"../../util":151,"./op":58}],48:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var conv_util = require("../../ops/conv_util"); -var util = require("../../util"); -var op_1 = require("./op"); -var Convolution2D = (function (_super) { - __extends(Convolution2D, _super); - function Convolution2D(wTensor, xTensor, bTensor, yTensor, fieldSize, outputDepth, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this) || this; - _this.wTensor = wTensor; - _this.xTensor = xTensor; - _this.bTensor = bTensor; - _this.yTensor = yTensor; - _this.fieldSize = fieldSize; - _this.outputDepth = outputDepth; - _this.stride = stride; - _this.assertWeightsShape(wTensor.shape); - _this.zeroPad = zeroPad != null ? - zeroPad : - conv_util.computeDefaultPad(_this.xTensor.shape, _this.fieldSize, _this.stride); - util.assert(util.isInt(_this.zeroPad), "The zero padding (" + _this.zeroPad + ") must be an integer. Change the " + - "stride and/or zero pad parameters"); - return _this; - } - Convolution2D.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var weights = inferenceArrays.get(this.wTensor); - var biases = inferenceArrays.get(this.bTensor); - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.conv2d(x, weights, biases, _this.stride, _this.zeroPad))); - }); - }; - Convolution2D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var filter = inferenceArrays.get(this.wTensor); - var x = inferenceArrays.get(this.xTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - var dw = math.conv2dDerFilter(x, dy, filter.shape, _this.stride, _this.zeroPad); - var db = math.sum(dy, [0, 1]); - var dx = math.conv2dDerInput(x.shape, dy, filter, _this.stride, _this.zeroPad); - gradientArrays.add(_this.wTensor, dw); - gradientArrays.add(_this.bTensor, db); - gradientArrays.add(_this.xTensor, dx); - }); - }; - Convolution2D.prototype.assertWeightsShape = function (weightsShape) { - util.assert(weightsShape[0] === this.fieldSize && - weightsShape[1] === this.fieldSize && - weightsShape[2] === this.xTensor.shape[2] && - weightsShape[3] === this.outputDepth, "weights must be of shape [" + this.fieldSize + "," + this.fieldSize + "," + - (this.xTensor.shape[2] + "," + this.outputDepth + "] but they are of") + - ("shape [" + weightsShape + "]")); - }; - return Convolution2D; -}(op_1.Operation)); -exports.Convolution2D = Convolution2D; - -},{"../../globals":35,"../../ops/conv_util":115,"../../util":151,"./op":58}],49:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Divide = (function (_super) { - __extends(Divide, _super); - function Divide(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - util.assert(util.sizeFromShape(x1Tensor.shape) === 1 || - util.sizeFromShape(x2Tensor.shape) === 1 || - util.arraysEqual(x1Tensor.shape, x2Tensor.shape), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape'); - return _this; - } - Divide.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var t1 = inferenceArrays.get(this.x1Tensor); - var t2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(t1.shape)) { - result = math.scalarDividedByArray(t1, t2); - } - else if (util.isScalarShape(t2.shape)) { - result = math.arrayDividedByScalar(t1, t2); - } - else { - result = math.divide(t1, t2); - } - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - Divide.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var dy = gradientArrays.get(this.yTensor); - var x1IsScalar = util.isScalarShape(x1.shape); - var x2IsScalar = util.isScalarShape(x2.shape); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - if (x1IsScalar) { - var div = math.divide(dy, x2); - gradientArrays.add(_this.x1Tensor, math.sum(div)); - div.dispose(); - } - else if (x2IsScalar) { - gradientArrays.add(_this.x1Tensor, math.arrayDividedByScalar(dy, x2)); - } - else { - gradientArrays.add(_this.x1Tensor, math.divide(dy, x2)); - } - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - var x2Squared = math.elementWiseMul(x2, x2); - var x1OverX2Squared = void 0; - if (x2IsScalar) { - x1OverX2Squared = math.arrayDividedByScalar(x1, x2Squared); - } - else if (x1IsScalar) { - x1OverX2Squared = math.scalarDividedByArray(x1, x2Squared); - } - else { - x1OverX2Squared = math.divide(x1, x2Squared); - } - var dx2 = math.neg(x1OverX2Squared); - var dyTimesDerivative = math.elementWiseMul(dy, dx2); - if (x2IsScalar) { - gradientArrays.add(_this.x2Tensor, math.sum(dyTimesDerivative)); - } - else { - gradientArrays.add(_this.x2Tensor, dyTimesDerivative); - } - } - }); - }; - return Divide; -}(op_1.Operation)); -exports.Divide = Divide; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],50:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var activation_functions_1 = require("../activation_functions"); -var op_1 = require("./op"); -var ElementWiseActivation = (function (_super) { - __extends(ElementWiseActivation, _super); - function ElementWiseActivation(xTensor, yTensor, func) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - _this.func = func; - return _this; - } - ElementWiseActivation.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(_this.func.output(math, x))); - }); - }; - ElementWiseActivation.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var y = inferenceArrays.get(this.yTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - var dydx = _this.func.der(math, x, y); - gradientArrays.add(_this.xTensor, math.elementWiseMul(dy, dydx)); - dydx.dispose(); - }); - }; - ElementWiseActivation.prototype.dispose = function () { - this.func.dispose(); - }; - return ElementWiseActivation; -}(op_1.Operation)); -exports.ElementWiseActivation = ElementWiseActivation; -var ReLU = (function (_super) { - __extends(ReLU, _super); - function ReLU(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.ReLUFunc()) || this; - } - return ReLU; -}(ElementWiseActivation)); -exports.ReLU = ReLU; -var LeakyReLU = (function (_super) { - __extends(LeakyReLU, _super); - function LeakyReLU(xTensor, yTensor, alpha) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.LeakyReluFunc(alpha)) || this; - } - return LeakyReLU; -}(ElementWiseActivation)); -exports.LeakyReLU = LeakyReLU; -var TanH = (function (_super) { - __extends(TanH, _super); - function TanH(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.TanHFunc()) || this; - } - return TanH; -}(ElementWiseActivation)); -exports.TanH = TanH; -var Sigmoid = (function (_super) { - __extends(Sigmoid, _super); - function Sigmoid(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.SigmoidFunc()) || this; - } - return Sigmoid; -}(ElementWiseActivation)); -exports.Sigmoid = Sigmoid; -var Square = (function (_super) { - __extends(Square, _super); - function Square(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.SquareFunc()) || this; - } - return Square; -}(ElementWiseActivation)); -exports.Square = Square; -var Elu = (function (_super) { - __extends(Elu, _super); - function Elu(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.EluFunc()) || this; - } - return Elu; -}(ElementWiseActivation)); -exports.Elu = Elu; -var PReLU = (function (_super) { - __extends(PReLU, _super); - function PReLU(xTensor, alphaTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.alphaTensor = alphaTensor; - _this.yTensor = yTensor; - return _this; - } - PReLU.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var alpha = inferenceArrays.get(this.alphaTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.prelu(x, alpha))); - }); - }; - PReLU.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - throw new Error('Not implemented'); - }; - return PReLU; -}(op_1.Operation)); -exports.PReLU = PReLU; - -},{"../../globals":35,"../activation_functions":37,"./op":58}],51:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var globals_1 = require("../../globals"); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var cost_functions_1 = require("../cost_functions"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var ElementWiseCost = (function (_super) { - __extends(ElementWiseCost, _super); - function ElementWiseCost(x1Tensor, x2Tensor, yTensor, func) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - _this.func = func; - _this.oneOverNScalar = - environment_1.ENV.math.keep(tensor_1.Scalar.new(1 / util.sizeFromShape(x1Tensor.shape))); - return _this; - } - ElementWiseCost.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var elementWiseCost = _this.func.cost(x1, x2); - var sum = math.sum(elementWiseCost); - var result = math.scalarTimesArray(_this.oneOverNScalar, sum); - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - ElementWiseCost.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - gradientArrays.add(_this.x1Tensor, _this.func.der(x1, x2)); - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - gradientArrays.add(_this.x2Tensor, _this.func.der(x2, x1)); - } - }); - }; - ElementWiseCost.prototype.dispose = function () { - this.func.dispose(); - this.oneOverNScalar.dispose(); - }; - return ElementWiseCost; -}(op_1.Operation)); -exports.ElementWiseCost = ElementWiseCost; -var MeanSquaredCost = (function (_super) { - __extends(MeanSquaredCost, _super); - function MeanSquaredCost(x1Tensor, x2Tensor, yTensor) { - return _super.call(this, x1Tensor, x2Tensor, yTensor, new cost_functions_1.SquareCostFunc()) || this; - } - return MeanSquaredCost; -}(ElementWiseCost)); -exports.MeanSquaredCost = MeanSquaredCost; - -},{"../../environment":34,"../../globals":35,"../../tensor":146,"../../util":151,"../cost_functions":38,"../graph_util":41,"./op":58}],52:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Exp = (function (_super) { - __extends(Exp, _super); - function Exp(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - return _this; - } - Exp.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.exp(x))); - }); - }; - Exp.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var y = inferenceArrays.get(this.yTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.xTensor)) { - gradientArrays.add(_this.xTensor, math.elementWiseMul(y, dy)); - } - }); - }; - return Exp; -}(op_1.Operation)); -exports.Exp = Exp; - -},{"../../globals":35,"../graph_util":41,"./op":58}],53:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var LinearCombination = (function (_super) { - __extends(LinearCombination, _super); - function LinearCombination(x1Tensor, x2Tensor, c1Tensor, c2Tensor, outTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.c1Tensor = c1Tensor; - _this.c2Tensor = c2Tensor; - _this.outTensor = outTensor; - return _this; - } - LinearCombination.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var c1 = inferenceArrays.get(this.c1Tensor).asScalar(); - var c2 = inferenceArrays.get(this.c2Tensor).asScalar(); - globals_1.tidy(function () { - inferenceArrays.set(_this.outTensor, globals_1.keep(math.scaledArrayAdd(c1, x1, c2, x2))); - }); - }; - LinearCombination.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var c1 = inferenceArrays.get(this.c1Tensor); - var c2 = inferenceArrays.get(this.c2Tensor); - var dy = gradientArrays.get(this.outTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - gradientArrays.add(_this.x1Tensor, math.scalarTimesArray(c1, dy)); - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - gradientArrays.add(_this.x2Tensor, math.scalarTimesArray(c2, dy)); - } - if (graph_util.shouldBackProp(_this.c1Tensor)) { - var dotProduct1 = math.elementWiseMul(x1, dy); - gradientArrays.add(_this.c1Tensor, math.sum(dotProduct1)); - } - if (graph_util.shouldBackProp(_this.c2Tensor)) { - var dotProduct2 = math.elementWiseMul(x2, dy); - gradientArrays.add(_this.c2Tensor, math.sum(dotProduct2)); - } - }); - }; - return LinearCombination; -}(op_1.Operation)); -exports.LinearCombination = LinearCombination; - -},{"../../globals":35,"../graph_util":41,"./op":58}],54:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Log = (function (_super) { - __extends(Log, _super); - function Log(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - return _this; - } - Log.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.log(x))); - }); - }; - Log.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.xTensor)) { - gradientArrays.add(_this.xTensor, math.divide(dy, x)); - } - }); - }; - return Log; -}(op_1.Operation)); -exports.Log = Log; - -},{"../../globals":35,"../graph_util":41,"./op":58}],55:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var MatMul = (function (_super) { - __extends(MatMul, _super); - function MatMul(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - return _this; - } - MatMul.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - if (x1.shape.length === 2 && x2.shape.length === 2) { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.matMul(x1, x2))); - } - else if (x1.shape.length === 2 && x2.shape.length === 1) { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.matrixTimesVector(x1, x2))); - } - else if (x1.shape.length === 1 && x2.shape.length === 2) { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.vectorTimesMatrix(x1, x2))); - } - }); - }; - MatMul.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var dy = gradientArrays.get(this.yTensor); - if (x1.shape.length === 1) { - x1 = x1.reshape([1, x1.size]); - dy = dy.reshape([1, dy.size]); - } - if (x2.shape.length === 1) { - x2 = x2.reshape([x2.size, 1]); - dy = dy.reshape([dy.size, 1]); - } - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - var dx1 = math.matMul(dy, x2, false, true); - gradientArrays.add(_this.x1Tensor, _this.x1Tensor.shape.length === 1 ? dx1.as1D() : dx1); - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - var dx2 = math.matMul(x1, dy, true, false); - gradientArrays.add(_this.x2Tensor, _this.x2Tensor.shape.length === 1 ? dx2.as1D() : dx2); - } - }); - }; - return MatMul; -}(op_1.Operation)); -exports.MatMul = MatMul; - -},{"../../globals":35,"../graph_util":41,"./op":58}],56:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var conv_util = require("../../ops/conv_util"); -var util = require("../../util"); -var op_1 = require("./op"); -var MaxPool = (function (_super) { - __extends(MaxPool, _super); - function MaxPool(xTensor, yTensor, fieldSize, stride, pad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - _this.fieldSize = fieldSize; - _this.stride = stride; - if (pad != null) { - _this.pad = pad; - } - else { - _this.pad = conv_util.computeDefaultPad(xTensor.shape, _this.fieldSize, _this.stride); - } - util.assert(util.isInt(_this.pad), "The zero padding (" + _this.pad + ") must be an integer. Change the " + - "stride and/or zero pad parameters"); - return _this; - } - MaxPool.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.maxPool(x, _this.fieldSize, _this.stride, _this.pad))); - }); - }; - MaxPool.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - gradientArrays.add(_this.xTensor, math.maxPoolBackprop(dy, x, _this.fieldSize, _this.stride, _this.pad)); - }); - }; - return MaxPool; -}(op_1.Operation)); -exports.MaxPool = MaxPool; - -},{"../../globals":35,"../../ops/conv_util":115,"../../util":151,"./op":58}],57:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Multiply = (function (_super) { - __extends(Multiply, _super); - function Multiply(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - util.assert(util.sizeFromShape(x1Tensor.shape) === 1 || - util.sizeFromShape(x2Tensor.shape) === 1 || - util.arraysEqual(x1Tensor.shape, x2Tensor.shape), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape'); - return _this; - } - Multiply.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var t1 = inferenceArrays.get(this.x1Tensor); - var t2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(t1.shape)) { - result = math.scalarTimesArray(t1, t2); - } - else if (util.isScalarShape(t2.shape)) { - result = math.scalarTimesArray(t2, t1); - } - else { - result = math.elementWiseMul(t1, t2); - } - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - Multiply.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - if (util.isScalarShape(_this.x1Tensor.shape)) { - var mul = math.elementWiseMul(dy, x2); - gradientArrays.add(_this.x1Tensor, math.sum(mul)); - } - else if (util.isScalarShape(x2.shape)) { - gradientArrays.add(_this.x1Tensor, math.scalarTimesArray(x2, dy)); - } - else { - gradientArrays.add(_this.x1Tensor, math.elementWiseMul(x2, dy)); - } - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - if (util.isScalarShape(_this.x2Tensor.shape)) { - var mul = math.elementWiseMul(dy, x1); - gradientArrays.add(_this.x2Tensor, math.sum(mul)); - } - else if (util.isScalarShape(x1.shape)) { - gradientArrays.add(_this.x2Tensor, math.scalarTimesArray(x1, dy)); - } - else { - gradientArrays.add(_this.x2Tensor, math.elementWiseMul(x1, dy)); - } - } - }); - }; - return Multiply; -}(op_1.Operation)); -exports.Multiply = Multiply; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],58:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Operation = (function () { - function Operation() { - } - Operation.prototype.disposeTransientArrays = function (inferenceArrays, gradientArrays) { }; - Operation.prototype.dispose = function () { }; - return Operation; -}()); -exports.Operation = Operation; - -},{}],59:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var globals_1 = require("../../globals"); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var ReduceSum = (function (_super) { - __extends(ReduceSum, _super); - function ReduceSum(x, outTensor) { - var _this = _super.call(this) || this; - _this.x = x; - _this.outTensor = outTensor; - util.assertShapesMatch(outTensor.shape, []); - _this.ones = environment_1.ENV.math.keep(tensor_1.Tensor.ones(x.shape)); - return _this; - } - ReduceSum.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.x); - globals_1.tidy(function () { - inferenceArrays.set(_this.outTensor, globals_1.keep(math.sum(x))); - }); - }; - ReduceSum.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - if (!graph_util.shouldBackProp(this.x)) { - return; - } - globals_1.tidy(function () { - var dy = gradientArrays.get(_this.outTensor); - gradientArrays.add(_this.x, math.scalarTimesArray(dy, _this.ones)); - }); - }; - ReduceSum.prototype.dispose = function () { - this.ones.dispose(); - }; - return ReduceSum; -}(op_1.Operation)); -exports.ReduceSum = ReduceSum; - -},{"../../environment":34,"../../globals":35,"../../tensor":146,"../../util":151,"../graph_util":41,"./op":58}],60:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var op_1 = require("./op"); -var Reshape = (function (_super) { - __extends(Reshape, _super); - function Reshape(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - var xSize = util.sizeFromShape(xTensor.shape); - var ySize = util.sizeFromShape(yTensor.shape); - util.assert(xSize === ySize, "The input size (" + xSize + ") and output size (" + ySize + ") must match"); - return _this; - } - Reshape.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var clone = math.clone(x); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(clone.reshape(_this.yTensor.shape))); - }); - }; - Reshape.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var dy = gradientArrays.get(this.yTensor); - var clone = math.clone(dy); - globals_1.tidy(function () { - gradientArrays.add(_this.xTensor, clone.reshape(_this.xTensor.shape)); - }); - }; - return Reshape; -}(op_1.Operation)); -exports.Reshape = Reshape; - -},{"../../globals":35,"../../util":151,"./op":58}],61:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var globals_1 = require("../../globals"); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var graph_1 = require("../graph"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Softmax = (function (_super) { - __extends(Softmax, _super); - function Softmax(logitsTensor, output) { - var _this = _super.call(this) || this; - _this.logitsTensor = logitsTensor; - _this.output = output; - return _this; - } - Softmax.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var logits = inferenceArrays.get(this.logitsTensor); - return globals_1.tidy(function () { - inferenceArrays.set(_this.output, globals_1.keep(math.softmax(logits))); - }); - }; - Softmax.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var y = inferenceArrays.get(this.output); - var dy = gradientArrays.get(this.output); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.logitsTensor)) { - var dlogits = math.elementWiseMul(math.subtract(dy, math.sum(math.elementWiseMul(dy, y))), y); - gradientArrays.add(_this.logitsTensor, dlogits); - } - }); - }; - return Softmax; -}(op_1.Operation)); -exports.Softmax = Softmax; -var SoftmaxCrossEntropyCost = (function (_super) { - __extends(SoftmaxCrossEntropyCost, _super); - function SoftmaxCrossEntropyCost(logitsTensor, labelTensor, yTensor) { - var _this = _super.call(this) || this; - _this.logitsTensor = logitsTensor; - _this.labelTensor = labelTensor; - _this.yTensor = yTensor; - _this.softmaxTensor = new graph_1.SymbolicTensor(logitsTensor.shape); - _this.epsilon = environment_1.ENV.math.keep(tensor_1.Scalar.new(1e-5)); - return _this; - } - SoftmaxCrossEntropyCost.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var logits = inferenceArrays.get(this.logitsTensor); - var label = inferenceArrays.get(this.labelTensor); - globals_1.tidy(function () { - var softmaxResult = math.softmax(logits); - inferenceArrays.set(_this.softmaxTensor, globals_1.keep(softmaxResult)); - inferenceArrays.set(_this.yTensor, globals_1.keep(crossEntropyCost(math, softmaxResult, label, _this.epsilon))); - }); - }; - SoftmaxCrossEntropyCost.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var softmax = inferenceArrays.get(this.softmaxTensor); - var label = inferenceArrays.get(this.labelTensor); - globals_1.tidy(function () { - gradientArrays.add(_this.logitsTensor, math.subtract(softmax, label)); - }); - }; - SoftmaxCrossEntropyCost.prototype.disposeTransientArrays = function (inferenceArrays, gradientArrays) { - inferenceArrays.disposeArray(this.softmaxTensor); - }; - SoftmaxCrossEntropyCost.prototype.dispose = function () { - this.epsilon.dispose(); - }; - return SoftmaxCrossEntropyCost; -}(op_1.Operation)); -exports.SoftmaxCrossEntropyCost = SoftmaxCrossEntropyCost; -function crossEntropyCost(math, y, target, epsilon) { - util.assert(y.size === target.size, 'The output and target must be the same size'); - return globals_1.tidy(function () { - var yPlusEps = math.scalarPlusArray(epsilon, y); - var logOutput = math.log(yPlusEps); - var tarLogOutput = math.elementWiseMul(target, logOutput); - var costVector = math.neg(tarLogOutput); - return math.sum(costVector); - }); -} -exports.crossEntropyCost = crossEntropyCost; - -},{"../../environment":34,"../../globals":35,"../../tensor":146,"../../util":151,"../graph":39,"../graph_util":41,"./op":58}],62:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Subtract = (function (_super) { - __extends(Subtract, _super); - function Subtract(t1, t2, outTensor) { - var _this = _super.call(this) || this; - _this.t1 = t1; - _this.t2 = t2; - _this.outTensor = outTensor; - util.assert(util.sizeFromShape(t1.shape) === 1 || - util.sizeFromShape(t2.shape) === 1 || - util.arraysEqual(t1.shape, t2.shape), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape'); - return _this; - } - Subtract.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var t1 = inferenceArrays.get(this.t1); - var t2 = inferenceArrays.get(this.t2); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(t1.shape)) { - result = math.scalarMinusArray(t1, t2); - } - else if (util.isScalarShape(t2.shape)) { - result = math.arrayMinusScalar(t1, t2); - } - else { - result = math.subtract(t1, t2); - } - inferenceArrays.set(_this.outTensor, globals_1.keep(result)); - }); - }; - Subtract.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var dy = gradientArrays.get(this.outTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.t1)) { - if (util.isScalarShape(_this.t1.shape)) { - var sum = math.sum(dy); - gradientArrays.add(_this.t1, sum); - } - else { - gradientArrays.add(_this.t1, math.clone(dy)); - } - } - if (graph_util.shouldBackProp(_this.t2)) { - if (util.isScalarShape(_this.t2.shape)) { - var sum = math.sum(dy); - var negSum = math.neg(sum); - gradientArrays.add(_this.t2, negSum); - } - else { - gradientArrays.add(_this.t2, math.neg(dy)); - } - } - }); - }; - Subtract.prototype.dispose = function () { - if (this.dySizeScalar != null) { - this.dySizeScalar.dispose(); - } - }; - return Subtract; -}(op_1.Operation)); -exports.Subtract = Subtract; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],63:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function defaultCompare(a, b) { - if (a === b) { - return 0; - } - else if (a < b) { - return -1; - } - else { - return 1; - } -} -exports.defaultCompare = defaultCompare; -var PriorityQueue = (function () { - function PriorityQueue(comparator, indexObserver) { - this.comparator = comparator; - this.indexObserver = indexObserver; - this.heap = []; - } - PriorityQueue.prototype.enqueue = function (t) { - this.heap.push(t); - this.onIndexChanged(t, this.heap.length - 1); - this.siftUp(this.heap.length - 1); - }; - PriorityQueue.prototype.dequeue = function () { - if (this.empty()) { - throw new Error('dequeue called on empty priority queue.'); - } - var t = this.heap[0]; - this.swap(0, this.heap.length - 1); - this.heap.pop(); - this.siftDown(0); - return t; - }; - PriorityQueue.prototype.update = function (newT, index) { - var last = (index === this.heap.length - 1); - if (!last) { - this.swap(index, this.heap.length - 1); - } - this.heap.pop(); - if (!last) { - if (this.siftUpIndex(index) !== -1) { - this.siftUp(index); - } - else if (this.siftDownIndex(index) !== -1) { - this.siftDown(index); - } - } - this.enqueue(newT); - }; - PriorityQueue.prototype.empty = function () { - return this.heap.length === 0; - }; - PriorityQueue.prototype.onIndexChanged = function (t, newIndex) { - if (this.indexObserver) { - this.indexObserver(t, newIndex); - } - }; - PriorityQueue.prototype.getParentIndex = function (index) { - if (index === 0) { - return -1; - } - return Math.floor((index - 1) / 2); - }; - PriorityQueue.prototype.getLeftChildIndex = function (index) { - var candidate = index * 2 + 1; - return candidate < this.heap.length ? candidate : -1; - }; - PriorityQueue.prototype.getRightChildIndex = function (index) { - var candidate = index * 2 + 2; - return candidate < this.heap.length ? candidate : -1; - }; - PriorityQueue.prototype.siftUpIndex = function (index) { - var parentIndex = this.getParentIndex(index); - if (parentIndex === -1) { - return -1; - } - if (this.compare(parentIndex, index) > 0) { - return parentIndex; - } - return -1; - }; - PriorityQueue.prototype.siftUp = function (index) { - var siftIndex = this.siftUpIndex(index); - while (siftIndex !== -1) { - this.swap(index, siftIndex); - index = siftIndex; - siftIndex = this.siftUpIndex(index); - } - }; - PriorityQueue.prototype.siftDownIndex = function (index) { - if (index >= this.heap.length) { - return -1; - } - var largestChildIndex = index; - var leftChildIndex = this.getLeftChildIndex(index); - if ((leftChildIndex !== -1) && - (this.compare(leftChildIndex, largestChildIndex) < 0)) { - largestChildIndex = leftChildIndex; - } - var rightChildIndex = this.getRightChildIndex(index); - if ((rightChildIndex !== -1) && - (this.compare(rightChildIndex, largestChildIndex) < 0)) { - largestChildIndex = rightChildIndex; - } - return (largestChildIndex === index) ? -1 : largestChildIndex; - }; - PriorityQueue.prototype.siftDown = function (index) { - var siftIndex = this.siftDownIndex(index); - while (siftIndex !== -1) { - this.swap(index, siftIndex); - index = siftIndex; - siftIndex = this.siftDownIndex(index); - } - }; - PriorityQueue.prototype.compare = function (aIndex, bIndex) { - return this.comparator(this.heap[aIndex], this.heap[bIndex]); - }; - PriorityQueue.prototype.swap = function (a, b) { - var temp = this.heap[a]; - this.heap[a] = this.heap[b]; - this.heap[b] = temp; - this.onIndexChanged(this.heap[a], a); - this.onIndexChanged(this.heap[b], b); - }; - return PriorityQueue; -}()); -exports.PriorityQueue = PriorityQueue; - -},{}],64:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var operation_emitter = require("./operation_emitter"); -var session_util = require("./session_util"); -var tensor_array_map_1 = require("./tensor_array_map"); -var FeedDictionary = (function () { - function FeedDictionary(feedEntries) { - var _this = this; - this.dict = {}; - if (feedEntries) { - feedEntries.forEach(function (entry) { return _this.dict[entry.tensor.id] = entry; }); - } - } - return FeedDictionary; -}()); -exports.FeedDictionary = FeedDictionary; -var CostReduction; -(function (CostReduction) { - CostReduction[CostReduction["NONE"] = 0] = "NONE"; - CostReduction[CostReduction["SUM"] = 1] = "SUM"; - CostReduction[CostReduction["MEAN"] = 2] = "MEAN"; -})(CostReduction = exports.CostReduction || (exports.CostReduction = {})); -var Session = (function () { - function Session(graph, math) { - this.math = math; - this.activationArrayMap = new tensor_array_map_1.TensorArrayMap(); - this.runtimeCache = {}; - this.oneScalar = tensor_1.Scalar.new(1); - this.gradientArrayMap = new tensor_array_map_1.SummedTensorArrayMap(this.math); - } - Session.prototype.dispose = function () { - var _this = this; - this.activationArrayMap.dispose(); - Object.keys(this.runtimeCache).forEach(function (key) { - var runtime = _this.runtimeCache[key]; - if (runtime.operations) { - runtime.operations.forEach(function (op) { return op.dispose(); }); - } - }); - this.runtimeCache = {}; - if (this.batchSizeScalar != null) { - this.batchSizeScalar.dispose(); - } - this.oneScalar.dispose(); - }; - Session.prototype.evalAll = function (tensors, feedEntries) { - var _this = this; - return globals_1.tidy(function () { - var feed = new FeedDictionary(feedEntries); - var runtime = _this.getOrCreateRuntime(tensors, feed); - var activations = _this.activationArrayMap; - session_util.disposeAndInitializeOperationOutputs(runtime.nodes, activations); - session_util.disposeTransientOperationArrays(runtime.operations, _this.activationArrayMap, _this.gradientArrayMap); - session_util.addPersistentArraysToTensorArrayMap(runtime.nodes, activations); - session_util.loadInputsFromFeedDictionaryToTensorArrayMap(feed, activations, _this.math); - runtime.operations.forEach(function (op) { return op.feedForward(_this.math, activations); }); - var results = tensors.map(function (x) { return activations.get(x); }); - tensors.forEach(function (x) { return activations.delete(x); }); - session_util.releaseFeedDictionaryInputsFromTensorArrayMap(feed, activations, _this.math); - return results; - }); - }; - Session.prototype.eval = function (tensor, feedEntries) { - return this.evalAll([tensor], feedEntries)[0]; - }; - Session.prototype.train = function (costTensor, feedEntries, batchSize, optimizer, costReduction) { - var _this = this; - if (costReduction === void 0) { costReduction = CostReduction.NONE; } - util.assert(util.isScalarShape(costTensor.shape), 'Cost tensor for training must be a scalar value.'); - if (this.prevBatchSize !== batchSize) { - this.prevBatchSize = batchSize; - if (this.batchSizeScalar != null) { - this.batchSizeScalar.dispose(); - } - this.batchSizeScalar = this.math.keep(tensor_1.Scalar.new(batchSize)); - } - var feed = new FeedDictionary(feedEntries); - session_util.throwIfFeedDictionaryContainsNDArrays(feed); - var runtime = this.getOrCreateRuntime([costTensor], feed); - var inferenceOperations = runtime.operations; - var backPropOperations = runtime.operations.slice().reverse(); - var activations = this.activationArrayMap; - var gradients = this.gradientArrayMap; - gradients.nullify(costTensor); - gradients.add(costTensor, this.oneScalar); - session_util.addPersistentArraysToTensorArrayMap(runtime.nodes, activations); - optimizer.beforeBatch(this.math, batchSize, runtime, activations, gradients); - return globals_1.tidy(function () { - var cost = tensor_1.Scalar.new(0); - for (var i = 0; i < batchSize; ++i) { - session_util.disposeAndInitializeOperationOutputs(runtime.nodes, activations); - session_util.disposeAndInitializeOperationInputGradients(runtime.nodes, gradients); - session_util.disposeTransientOperationArrays(runtime.operations, activations, gradients); - session_util.loadInputsFromFeedDictionaryToTensorArrayMap(feed, activations, _this.math); - inferenceOperations.forEach(function (op) { return op.feedForward(_this.math, activations); }); - backPropOperations.forEach(function (op) { return op.backProp(_this.math, activations, gradients); }); - optimizer.afterExample(_this.math, runtime, activations, gradients); - session_util.releaseFeedDictionaryInputsFromTensorArrayMap(feed, activations, _this.math); - cost = _this.updateCostForExample(cost, activations.get(costTensor), costReduction); - } - optimizer.afterBatch(_this.math, batchSize, runtime, activations, gradients); - return _this.updateCostForBatch(cost, costReduction); - }); - }; - Session.prototype.updateCostForExample = function (totalCost, currCost, costReduction) { - if (costReduction === CostReduction.MEAN || - costReduction === CostReduction.SUM) { - return this.math.add(totalCost, currCost); - } - return totalCost; - }; - Session.prototype.updateCostForBatch = function (totalCost, costReduction) { - if (costReduction === CostReduction.MEAN) { - return this.math.divide(totalCost, this.batchSizeScalar); - } - return totalCost; - }; - Session.prototype.getOrCreateRuntime = function (tensors, feed) { - var key = this.makeRuntimeCacheKey(tensors, feed); - var runtime = this.runtimeCache[key]; - if (runtime === undefined) { - var nodes = session_util.getOrderedEvaluationSetFromEvalTensor(tensors, feed); - session_util.removeFeedDictionaryNodesFromEvaluationSet(feed, nodes); - session_util.throwErrorIfEvaluationSetContainsPlaceholderNodes(nodes); - var operations = operation_emitter.emitFromGraphNodes(nodes); - runtime = { nodes: nodes, operations: operations }; - this.runtimeCache[key] = runtime; - } - return runtime; - }; - Session.prototype.makeRuntimeCacheKey = function (tensors, feed) { - return tensors.map(function (x) { return x.id; }).sort().join('_') + '__' + - Object.keys(feed.dict).sort().join('_'); - }; - return Session; -}()); -exports.Session = Session; - -},{"../globals":35,"../tensor":146,"../util":151,"./operation_emitter":43,"./session_util":65,"./tensor_array_map":66}],65:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var graph_1 = require("./graph"); -var graph_util = require("./graph_util"); -function getTerminatingNodesFromFeedDictionary(feedDictionary) { - return Object.keys(feedDictionary.dict) - .map(function (tensorID) { return feedDictionary.dict[+tensorID].tensor.node; }); -} -exports.getTerminatingNodesFromFeedDictionary = getTerminatingNodesFromFeedDictionary; -function getOrderedEvaluationSetFromEvalTensor(evalTensors, feedDictionary) { - var terminatingNodes = getTerminatingNodesFromFeedDictionary(feedDictionary); - var evalNodes = evalTensors.map(function (x) { return x.node; }); - var unorderedEvaluationSet = graph_util.getUnorderedEvaluationSet(evalNodes, terminatingNodes); - var orderedEvaluationSet = graph_util.getOrderedEvaluationSet(unorderedEvaluationSet); - return orderedEvaluationSet; -} -exports.getOrderedEvaluationSetFromEvalTensor = getOrderedEvaluationSetFromEvalTensor; -function addPersistentArraysToTensorArrayMap(evaluationSet, tensorArrayMap) { - evaluationSet.forEach(function (node) { - if (node instanceof graph_1.VariableNode || node instanceof graph_1.ConstantNode) { - tensorArrayMap.set(node.output, node.data); - } - }); -} -exports.addPersistentArraysToTensorArrayMap = addPersistentArraysToTensorArrayMap; -function getVariableNodesFromEvaluationSet(evaluationSet) { - var nodes = []; - evaluationSet.forEach(function (node) { - if (node instanceof graph_1.VariableNode) { - nodes.push(node); - } - }); - return nodes; -} -exports.getVariableNodesFromEvaluationSet = getVariableNodesFromEvaluationSet; -function throwIfFeedDictionaryContainsNDArrays(feedDictionary) { - Object.keys(feedDictionary.dict).forEach(function (tensorID) { - if (feedDictionary.dict[+tensorID].data instanceof tensor_1.Tensor) { - throw new Error('training requires FeedDictionary entries to be InputProviders' + - 'and not NDArrays.'); - } - }); -} -exports.throwIfFeedDictionaryContainsNDArrays = throwIfFeedDictionaryContainsNDArrays; -function loadInputsFromFeedDictionaryToTensorArrayMap(batchFeed, activations, math) { - Object.keys(batchFeed.dict).forEach(function (tensorID) { - var feedEntry = batchFeed.dict[+tensorID]; - var data; - if (feedEntry.data instanceof tensor_1.Tensor) { - data = feedEntry.data; - } - else { - var provider = feedEntry.data; - data = provider.getNextCopy(); - } - util.assert(util.arraysEqual(feedEntry.tensor.shape, data.shape), "Error loading FeedEntry: feeding NDArray of shape " + data.shape + " " + - ("does not match Tensor (id: " + feedEntry.tensor.id + ") shape: ") + - (feedEntry.tensor.shape + ".")); - activations.set(feedEntry.tensor, data); - }); -} -exports.loadInputsFromFeedDictionaryToTensorArrayMap = loadInputsFromFeedDictionaryToTensorArrayMap; -function releaseFeedDictionaryInputsFromTensorArrayMap(batchFeed, activations, math) { - Object.keys(batchFeed.dict).forEach(function (tensorID) { - var feedEntry = batchFeed.dict[+tensorID]; - if (!(feedEntry.data instanceof tensor_1.Tensor)) { - var provider = feedEntry.data; - var feedEntryArray = activations.get(feedEntry.tensor); - provider.disposeCopy(feedEntryArray); - } - activations.delete(feedEntry.tensor); - }); -} -exports.releaseFeedDictionaryInputsFromTensorArrayMap = releaseFeedDictionaryInputsFromTensorArrayMap; -function removeFeedDictionaryNodesFromEvaluationSet(feedDictionary, evaluationSet) { - var i = 0; - while (i < evaluationSet.length) { - var node = evaluationSet[i]; - if (feedDictionary.dict[node.output.id] != null) { - evaluationSet.splice(i, 1); - } - else { - ++i; - } - } -} -exports.removeFeedDictionaryNodesFromEvaluationSet = removeFeedDictionaryNodesFromEvaluationSet; -function disposeAndInitializeOperationOutputs(evaluationSet, tensorArrayMap) { - evaluationSet.forEach(function (node) { - if (!graph_util.isInputNode(node)) { - if (!graph_util.isPassthroughNode(node, tensorArrayMap)) { - tensorArrayMap.disposeArray(node.output); - } - tensorArrayMap.set(node.output, null); - } - }); -} -exports.disposeAndInitializeOperationOutputs = disposeAndInitializeOperationOutputs; -function disposeAndInitializeOperationInputGradients(evaluationSet, gradients) { - evaluationSet.forEach(function (node) { - Object.keys(node.inputs).forEach(function (inputName) { - var input = node.inputs[inputName]; - if (gradients.get(input, true) !== gradients.get(node.output, true)) { - gradients.disposeArray(input); - } - gradients.nullify(input); - }); - }); -} -exports.disposeAndInitializeOperationInputGradients = disposeAndInitializeOperationInputGradients; -function disposeTransientOperationArrays(operations, activations, gradients) { - operations.forEach(function (op) { return op.disposeTransientArrays(activations, gradients); }); -} -exports.disposeTransientOperationArrays = disposeTransientOperationArrays; -function throwErrorIfEvaluationSetContainsPlaceholderNodes(evaluationSet) { - evaluationSet.forEach(function (node) { - if (node instanceof graph_1.PlaceholderNode) { - var shape = '[' + node.output.shape.join(', ') + ']'; - throw new Error('Placeholder node "' + node.name + '" ' + shape + - ' not present in feed dictionary.'); - } - }); -} -exports.throwErrorIfEvaluationSetContainsPlaceholderNodes = throwErrorIfEvaluationSetContainsPlaceholderNodes; - -},{"../tensor":146,"../util":151,"./graph":39,"./graph_util":41}],66:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var TensorArrayMapBase = (function () { - function TensorArrayMapBase() { - this.dict = {}; - } - TensorArrayMapBase.prototype.get = function (tensor, skipChecks) { - if (skipChecks === void 0) { skipChecks = false; } - if (!skipChecks && this.dict[tensor.id] === undefined) { - throw new Error("tensor " + tensor.id + " not in array map."); - } - var nda = this.dict[tensor.id]; - if (!skipChecks && nda === null) { - throw new Error("tensor " + tensor.id + " has null array."); - } - return nda; - }; - TensorArrayMapBase.prototype.delete = function (tensor) { - delete this.dict[tensor.id]; - }; - TensorArrayMapBase.prototype.nullify = function (tensor) { - this.dict[tensor.id] = null; - }; - TensorArrayMapBase.prototype.disposeArray = function (tensor) { - if (this.dict[tensor.id] === undefined) { - return; - } - var nda = this.dict[tensor.id]; - if (nda === null) { - return; - } - nda.dispose(); - this.dict[tensor.id] = null; - }; - TensorArrayMapBase.prototype.size = function () { - return Object.keys(this.dict).length; - }; - TensorArrayMapBase.prototype.dispose = function () { - var _this = this; - Object.keys(this.dict).forEach(function (tensorID) { - var nda = _this.dict[+tensorID]; - if (nda) { - nda.dispose(); - } - }); - this.dict = {}; - }; - TensorArrayMapBase.prototype.hasNullArray = function (tensor) { - if (this.dict[tensor.id] === undefined) { - throw new Error("tensor " + tensor.id + " not in array map."); - } - return this.dict[tensor.id] === null; - }; - return TensorArrayMapBase; -}()); -exports.TensorArrayMapBase = TensorArrayMapBase; -var TensorArrayMap = (function (_super) { - __extends(TensorArrayMap, _super); - function TensorArrayMap() { - return _super !== null && _super.apply(this, arguments) || this; - } - TensorArrayMap.prototype.set = function (tensor, array) { - this.dict[tensor.id] = array; - }; - return TensorArrayMap; -}(TensorArrayMapBase)); -exports.TensorArrayMap = TensorArrayMap; -var SummedTensorArrayMap = (function (_super) { - __extends(SummedTensorArrayMap, _super); - function SummedTensorArrayMap(math) { - var _this = _super.call(this) || this; - _this.math = math; - return _this; - } - SummedTensorArrayMap.prototype.add = function (tensor, array) { - if (this.dict[tensor.id] == null) { - this.dict[tensor.id] = this.math.keep(array); - } - else { - var oldValue = this.get(tensor); - var newValue = this.math.keep(this.math.addStrict(oldValue, array)); - this.dict[tensor.id] = newValue; - oldValue.dispose(); - } - }; - return SummedTensorArrayMap; -}(TensorArrayMapBase)); -exports.SummedTensorArrayMap = SummedTensorArrayMap; - -},{}],67:[function(require,module,exports){ -"use strict"; -function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; -} -Object.defineProperty(exports, "__esModule", { value: true }); -var browser_util_1 = require("./browser_util"); -var contrib = require("./contrib"); -exports.contrib = contrib; -var xhr_dataset = require("./data/xhr-dataset"); -exports.xhr_dataset = xhr_dataset; -var environment = require("./environment"); -exports.environment = environment; -var environment_1 = require("./environment"); -var gpgpu_util = require("./kernels/webgl/gpgpu_util"); -exports.gpgpu_util = gpgpu_util; -var webgl_util = require("./kernels/webgl/webgl_util"); -exports.webgl_util = webgl_util; -var conv_util = require("./ops/conv_util"); -exports.conv_util = conv_util; -var test_util = require("./test_util"); -exports.test_util = test_util; -var util = require("./util"); -exports.util = util; -var version_1 = require("./version"); -exports.version = version_1.version; -var checkpoint_loader_1 = require("./data/checkpoint_loader"); -exports.CheckpointLoader = checkpoint_loader_1.CheckpointLoader; -var dataset_1 = require("./data/dataset"); -exports.InMemoryDataset = dataset_1.InMemoryDataset; -var input_provider_1 = require("./data/input_provider"); -exports.InCPUMemoryShuffledInputProviderBuilder = input_provider_1.InCPUMemoryShuffledInputProviderBuilder; -exports.InGPUMemoryShuffledInputProviderBuilder = input_provider_1.InGPUMemoryShuffledInputProviderBuilder; -var xhr_dataset_1 = require("./data/xhr-dataset"); -exports.XhrDataset = xhr_dataset_1.XhrDataset; -var environment_2 = require("./environment"); -exports.ENV = environment_2.ENV; -exports.Environment = environment_2.Environment; -var graph_1 = require("./graph/graph"); -exports.Graph = graph_1.Graph; -exports.SymbolicTensor = graph_1.SymbolicTensor; -var graph_runner_1 = require("./graph/graph_runner"); -exports.GraphRunner = graph_runner_1.GraphRunner; -exports.MetricReduction = graph_runner_1.MetricReduction; -var initializers_1 = require("./graph/initializers"); -exports.ConstantInitializer = initializers_1.ConstantInitializer; -exports.OnesInitializer = initializers_1.OnesInitializer; -exports.RandomNormalInitializer = initializers_1.RandomNormalInitializer; -exports.RandomTruncatedNormalInitializer = initializers_1.RandomTruncatedNormalInitializer; -exports.RandomUniformInitializer = initializers_1.RandomUniformInitializer; -exports.TensorInitializer = initializers_1.TensorInitializer; -exports.VarianceScalingInitializer = initializers_1.VarianceScalingInitializer; -exports.ZerosInitializer = initializers_1.ZerosInitializer; -var session_1 = require("./graph/session"); -exports.CostReduction = session_1.CostReduction; -exports.Session = session_1.Session; -var backend_cpu_1 = require("./kernels/backend_cpu"); -exports.MathBackendCPU = backend_cpu_1.MathBackendCPU; -exports.NDArrayMathCPU = backend_cpu_1.NDArrayMathCPU; -var backend_webgl_1 = require("./kernels/backend_webgl"); -exports.MathBackendWebGL = backend_webgl_1.MathBackendWebGL; -exports.NDArrayMathGPU = backend_webgl_1.NDArrayMathGPU; -var matmul_1 = require("./kernels/types/matmul"); -exports.MatrixOrientation = matmul_1.MatrixOrientation; -var gpgpu_context_1 = require("./kernels/webgl/gpgpu_context"); -exports.GPGPUContext = gpgpu_context_1.GPGPUContext; -var math_1 = require("./math"); -exports.NDArrayMath = math_1.NDArrayMath; -var adadelta_optimizer_1 = require("./optimizers/adadelta_optimizer"); -exports.AdadeltaOptimizer = adadelta_optimizer_1.AdadeltaOptimizer; -var adagrad_optimizer_1 = require("./optimizers/adagrad_optimizer"); -exports.AdagradOptimizer = adagrad_optimizer_1.AdagradOptimizer; -var adam_optimizer_1 = require("./optimizers/adam_optimizer"); -exports.AdamOptimizer = adam_optimizer_1.AdamOptimizer; -var adamax_optimizer_1 = require("./optimizers/adamax_optimizer"); -exports.AdamaxOptimizer = adamax_optimizer_1.AdamaxOptimizer; -var momentum_optimizer_1 = require("./optimizers/momentum_optimizer"); -exports.MomentumOptimizer = momentum_optimizer_1.MomentumOptimizer; -var optimizer_1 = require("./optimizers/optimizer"); -exports.Optimizer = optimizer_1.Optimizer; -var rmsprop_optimizer_1 = require("./optimizers/rmsprop_optimizer"); -exports.RMSPropOptimizer = rmsprop_optimizer_1.RMSPropOptimizer; -var sgd_optimizer_1 = require("./optimizers/sgd_optimizer"); -exports.SGDOptimizer = sgd_optimizer_1.SGDOptimizer; -var tensor_1 = require("./tensor"); -exports.Array1D = tensor_1.Array1D; -exports.Array2D = tensor_1.Array2D; -exports.Array3D = tensor_1.Array3D; -exports.Array4D = tensor_1.Array4D; -exports.NDArray = tensor_1.NDArray; -exports.Scalar = tensor_1.Scalar; -exports.Tensor = tensor_1.Tensor; -exports.Tensor1D = tensor_1.Tensor1D; -exports.Tensor2D = tensor_1.Tensor2D; -exports.Tensor3D = tensor_1.Tensor3D; -exports.Tensor4D = tensor_1.Tensor4D; -exports.variable = tensor_1.variable; -exports.Variable = tensor_1.Variable; -var types_1 = require("./types"); -exports.Rank = types_1.Rank; -__export(require("./ops/ops")); -__export(require("./train")); -__export(require("./globals")); -exports.setBackend = environment_1.Environment.setBackend; -exports.getBackend = environment_1.Environment.getBackend; -exports.memory = environment_1.Environment.memory; -exports.nextFrame = browser_util_1.BrowserUtil.nextFrame; - -},{"./browser_util":10,"./contrib":26,"./data/checkpoint_loader":27,"./data/dataset":28,"./data/input_provider":29,"./data/xhr-dataset":30,"./environment":34,"./globals":35,"./graph/graph":39,"./graph/graph_runner":40,"./graph/initializers":42,"./graph/session":64,"./kernels/backend_cpu":68,"./kernels/backend_webgl":69,"./kernels/types/matmul":71,"./kernels/webgl/gpgpu_context":83,"./kernels/webgl/gpgpu_util":85,"./kernels/webgl/webgl_util":104,"./math":105,"./ops/conv_util":115,"./ops/ops":123,"./optimizers/adadelta_optimizer":135,"./optimizers/adagrad_optimizer":136,"./optimizers/adam_optimizer":137,"./optimizers/adamax_optimizer":138,"./optimizers/momentum_optimizer":139,"./optimizers/optimizer":140,"./optimizers/rmsprop_optimizer":142,"./optimizers/sgd_optimizer":143,"./tensor":146,"./test_util":147,"./train":149,"./types":150,"./util":151,"./version":152}],68:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var environment_1 = require("../environment"); -var math_1 = require("../math"); -var axis_util = require("../ops/axis_util"); -var broadcast_util = require("../ops/broadcast_util"); -var concat_util = require("../ops/concat_util"); -var ops = require("../ops/ops"); -var ops_1 = require("../ops/ops"); -var selu_util = require("../ops/selu_util"); -var tensor_1 = require("../tensor"); -var types = require("../types"); -var util = require("../util"); -var MathBackendCPU = (function () { - function MathBackendCPU() { - this.data = new WeakMap(); - if (typeof document !== 'undefined') { - this.canvas = document.createElement('canvas'); - } - } - MathBackendCPU.prototype.register = function (dataId, shape, dtype) { - if (this.data.has(dataId)) { - throw new Error("Data buffer is already registered"); - } - this.data.set(dataId, null); - }; - MathBackendCPU.prototype.write = function (dataId, values) { - if (values == null) { - throw new Error('MathBackendCPU.write(): values can not be null'); - } - this.throwIfNoData(dataId); - this.data.set(dataId, values); - }; - MathBackendCPU.prototype.fromPixels = function (pixels, numChannels) { - if (pixels == null) { - throw new Error('MathBackendCPU.writePixels(): pixels can not be null'); - } - var vals; - if (pixels instanceof ImageData) { - vals = pixels.data; - } - else if (pixels instanceof HTMLCanvasElement) { - vals = pixels.getContext('2d') - .getImageData(0, 0, pixels.width, pixels.height) - .data; - } - else if (pixels instanceof HTMLImageElement || - pixels instanceof HTMLVideoElement) { - if (this.canvas == null) { - throw new Error('Can\'t read pixels from HTMLImageElement outside ' + - 'the browser.'); - } - this.canvas.width = pixels.width; - this.canvas.height = pixels.height; - this.canvas.getContext('2d').drawImage(pixels, 0, 0, pixels.width, pixels.height); - vals = this.canvas.getContext('2d') - .getImageData(0, 0, pixels.width, pixels.height) - .data; - } - else { - throw new Error("pixels is of unknown type: " + pixels.constructor.name); - } - var values; - if (numChannels === 4) { - values = new Int32Array(vals); - } - else { - var numPixels = pixels.width * pixels.height; - values = new Int32Array(numPixels * numChannels); - for (var i = 0; i < numPixels; i++) { - for (var channel = 0; channel < numChannels; ++channel) { - values[i * numChannels + channel] = vals[i * 4 + channel]; - } - } - } - var outShape = [pixels.height, pixels.width, numChannels]; - return ops_1.tensor3d(values, outShape, 'int32'); - }; - MathBackendCPU.prototype.read = function (dataId) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.readSync(dataId)]; - }); - }); - }; - MathBackendCPU.prototype.readSync = function (dataId) { - this.throwIfNoData(dataId); - return this.data.get(dataId); - }; - MathBackendCPU.prototype.disposeData = function (dataId) { - if (this.data.has(dataId)) { - this.data.delete(dataId); - } - }; - MathBackendCPU.prototype.time = function (f) { - return __awaiter(this, void 0, void 0, function () { - var start, kernelMs; - return __generator(this, function (_a) { - start = performance.now(); - f(); - kernelMs = performance.now() - start; - return [2, { kernelMs: kernelMs }]; - }); - }); - }; - MathBackendCPU.prototype.memory = function () { - return { - unreliable: true - }; - }; - MathBackendCPU.prototype.throwIfNoData = function (dataId) { - if (!this.data.has(dataId)) { - throw new Error("CPU backend: No data found for this tensor. " + - "Did you change your backend in the middle of the program? " + - "New backends can't use Tensors created with previous backends"); - } - }; - MathBackendCPU.prototype.slice1D = function (x, begin, size) { - var newVals = x.dataSync().slice(begin, begin + size); - return ops.tensor1d(newVals, x.dtype); - }; - MathBackendCPU.prototype.slice2D = function (x, begin, size) { - var buffer = ops.buffer(size, x.dtype); - var startI = begin[0], startJ = begin[1]; - for (var i = 0; i < size[0]; ++i) { - for (var j = 0; j < size[1]; ++j) { - var val = x.get(i + startI, j + startJ); - buffer.set(val, i, j); - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.slice3D = function (x, begin, size) { - var buffer = ops.buffer(size, x.dtype); - var startI = begin[0], startJ = begin[1], startK = begin[2]; - for (var i = 0; i < size[0]; ++i) { - for (var j = 0; j < size[1]; ++j) { - for (var k = 0; k < size[2]; ++k) { - var val = x.get(i + startI, j + startJ, k + startK); - buffer.set(val, i, j, k); - } - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.slice4D = function (x, begin, size) { - var buffer = ops.buffer(size, x.dtype); - var startI = begin[0], startJ = begin[1], startK = begin[2], startL = begin[3]; - for (var i = 0; i < size[0]; ++i) { - for (var j = 0; j < size[1]; ++j) { - for (var k = 0; k < size[2]; ++k) { - for (var l = 0; l < size[3]; ++l) { - var val = x.get(i + startI, j + startJ, k + startK, l + startL); - buffer.set(val, i, j, k, l); - } - } - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.reverse4D = function (x, axis) { - var buffer = ops.buffer(x.shape, x.dtype); - var revAxis = function (i) { return axis.indexOf(i) !== -1 && x.shape[i] !== 1; }; - for (var b = 0; b < x.shape[0]; ++b) { - for (var r = 0; r < x.shape[1]; ++r) { - for (var c = 0; c < x.shape[2]; ++c) { - for (var d = 0; d < x.shape[3]; ++d) { - var b0 = revAxis(0) ? x.shape[0] - b - 1 : b; - var r0 = revAxis(1) ? x.shape[1] - r - 1 : r; - var c0 = revAxis(2) ? x.shape[2] - c - 1 : c; - var d0 = revAxis(3) ? x.shape[3] - d - 1 : d; - var val = x.get(b0, r0, c0, d0); - buffer.set(val, b, r, c, d); - } - } - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.concat = function (a, b) { - var outShape = concat_util.computeOutShape(a.shape, b.shape, 1); - var buffer = ops.buffer(outShape, a.dtype); - if (a.shape[0] === 1 && b.shape[0] === 1) { - var aVals = a.dataSync(); - var bVals = b.dataSync(); - var vals = buffer.values; - vals.set(aVals, 0); - vals.set(bVals, a.size); - return buffer.toTensor(); - } - for (var i = 0; i < outShape[0]; ++i) { - for (var j = 0; j < a.shape[1]; ++j) { - buffer.set(a.get(i, j), i, j); - } - for (var j = 0; j < b.shape[1]; ++j) { - buffer.set(b.get(i, j), i, j + a.shape[1]); - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.neg = function (x) { - return this.multiply(ops.scalar(-1), x); - }; - MathBackendCPU.prototype.add = function (a, b) { - return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue + bValue; }); - }; - MathBackendCPU.prototype.subtract = function (a, b) { - return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue - bValue; }); - }; - MathBackendCPU.prototype.pow = function (a, b) { - return this.broadcastedBinaryOp(a, b, a.dtype, function (aValue, bValue) { return Math.pow(aValue, bValue); }); - }; - MathBackendCPU.prototype.matMul = function (a, b, transposeA, transposeB) { - var sharedDim = transposeA ? a.shape[0] : a.shape[1]; - var leftDim = transposeA ? a.shape[1] : a.shape[0]; - var rightDim = transposeB ? b.shape[0] : b.shape[1]; - var normalGetter = function (matrix, i, j) { - return matrix.get(i, j); - }; - var transposedGetter = function (matrix, i, j) { - return matrix.get(j, i); - }; - var aGetter = transposeA ? transposedGetter : normalGetter; - var bGetter = transposeB ? transposedGetter : normalGetter; - var values = new Float32Array(leftDim * rightDim); - var index = 0; - for (var i = 0; i < leftDim; ++i) { - for (var j = 0; j < rightDim; ++j) { - var sum = 0; - for (var k = 0; k < sharedDim; ++k) { - sum += aGetter(a, i, k) * bGetter(b, k, j); - } - values[index++] = sum; - } - } - return ops.tensor2d(values, [leftDim, rightDim]); - }; - MathBackendCPU.prototype.multiply = function (a, b) { - return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue * bValue; }); - }; - MathBackendCPU.prototype.divide = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'float32', function (aValue, bValue) { return aValue / bValue; }); - }; - MathBackendCPU.prototype.sum = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('sum', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var resultDtype = types.upcastType(x.dtype, 'int32'); - var result = ops.zeros(outShape, resultDtype); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var sum = 0; - for (var j = 0; j < reduceSize; ++j) { - sum += aVals[offset + j]; - } - vals[i] = sum; - } - return result; - }; - MathBackendCPU.prototype.argMin = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMin', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, 'int32'); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var min = aVals[offset]; - var minIndex = 0; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - minIndex = util.NAN_INT32; - break; - } - if (value < min) { - min = value; - minIndex = j; - } - } - vals[i] = minIndex; - } - return result; - }; - MathBackendCPU.prototype.argMax = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMax', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, 'int32'); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var max = aVals[offset]; - var maxIndex = 0; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - maxIndex = util.NAN_INT32; - break; - } - if (value > max) { - max = value; - maxIndex = j; - } - } - vals[i] = maxIndex; - } - return result; - }; - MathBackendCPU.prototype.equal = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal === bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.notEqual = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal !== bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.less = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal < bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.lessEqual = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal <= bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.greater = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal > bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.greaterEqual = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal >= bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.logicalNot = function (x) { - var values = x.dataSync(); - var newValues = new Int32Array(values.length); - for (var i = 0; i < values.length; ++i) { - if (util.isValNaN(values[i], x.dtype)) { - newValues[i] = util.getNaN('bool'); - } - else { - newValues[i] = values[i] ? 0 : 1; - } - } - return tensor_1.Tensor.make(x.shape, { values: newValues }, 'bool'); - }; - MathBackendCPU.prototype.logicalAnd = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return aVal && bVal; - } - }); - }; - MathBackendCPU.prototype.logicalOr = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return aVal || bVal; - } - }); - }; - MathBackendCPU.prototype.logicalXor = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return aVal ^ bVal; - } - }); - }; - MathBackendCPU.prototype.where = function (condition, a, b, dtype) { - var values = condition.dataSync(); - var aValues = a.dataSync(); - var bValues = b.dataSync(); - var result = ops.zeros(a.shape, dtype); - var newValues = result.dataSync(); - var index = 0; - var offset = condition.rank === 0 || condition.rank > 1 || a.rank === 1 ? - 1 : - a.shape[1]; - for (var i = 0; i < values.length; i++) { - for (var j = 0; j < offset; j++) { - if (values[i] === 1) { - newValues[index++] = aValues[i]; - } - else { - newValues[index++] = bValues[i]; - } - } - } - return result; - }; - MathBackendCPU.prototype.topKValues = function (x, k) { - return this.topK(x, k).values; - }; - MathBackendCPU.prototype.topKIndices = function (x, k) { - return this.topK(x, k).indices; - }; - MathBackendCPU.prototype.topK = function (x, k) { - var values = x.dataSync(); - var valuesAndIndices = []; - for (var i = 0; i < values.length; i++) { - valuesAndIndices.push({ value: values[i], index: i }); - } - valuesAndIndices.sort(function (a, b) { - return b.value - a.value; - }); - var topkValues = util.getTypedArrayFromDType(x.dtype, k); - var topkIndices = new Int32Array(k); - for (var i = 0; i < k; i++) { - topkValues[i] = valuesAndIndices[i].value; - topkIndices[i] = valuesAndIndices[i].index; - } - return { - values: ops.tensor1d(topkValues, x.dtype), - indices: tensor_1.Tensor1D.new(topkIndices) - }; - }; - MathBackendCPU.prototype.min = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('min', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, x.dtype); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var min = aVals[0]; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - min = Number.NaN; - break; - } - if (value < min) { - min = value; - } - } - vals[i] = min; - } - return result; - }; - MathBackendCPU.prototype.minimum = function (a, b) { - return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) { return Math.min(aVal, bVal); }); - }; - MathBackendCPU.prototype.max = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('max', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, x.dtype); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var max = aVals[offset]; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - max = Number.NaN; - break; - } - if (value > max) { - max = value; - } - } - vals[i] = max; - } - return result; - }; - MathBackendCPU.prototype.maximum = function (a, b) { - return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) { return Math.max(aVal, bVal); }); - }; - MathBackendCPU.prototype.ceil = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - newValues[i] = Math.ceil(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.floor = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - newValues[i] = Math.floor(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.exp = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - newValues[i] = Math.exp(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.log = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - newValues[i] = Math.log(value); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.sqrt = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - newValues[i] = Math.sqrt(value); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.square = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - newValues[i] = value * value; - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.relu = function (x) { - var res = ops.zeros(x.shape, x.dtype); - var resVals = res.dataSync(); - var inVals = x.dataSync(); - for (var i = 0; i < inVals.length; ++i) { - var val = inVals[i]; - if (util.isValNaN(val, x.dtype)) { - resVals[i] = util.getNaN(res.dtype); - } - else { - resVals[i] = Math.max(0, inVals[i]); - } - } - return res; - }; - MathBackendCPU.prototype.elu = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = v; - } - else { - resultValues[i] = (Math.exp(v) - 1); - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.eluDer = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = 1; - } - else { - resultValues[i] = Math.exp(v); - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.selu = function (x) { - var scaleAlpha = selu_util.SELU_SCALEALPHA; - var scale = selu_util.SELU_SCALE; - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = scale * v; - } - else { - resultValues[i] = scaleAlpha * (Math.exp(v) - 1); - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.leakyRelu = function (x, alpha) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; i++) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = v; - } - else { - resultValues[i] = alpha * v; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.prelu = function (x, alpha) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - var alphas = alpha.dataSync(); - for (var i = 0; i < values.length; i++) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = v; - } - else { - resultValues[i] = alphas[i] * v; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.preluDer = function (x, alpha) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - var alphas = alpha.dataSync(); - for (var i = 0; i < values.length; i++) { - var v = values[i]; - if (v > 0) { - resultValues[i] = 1; - } - else if (v < 0) { - resultValues[i] = alphas[i]; - } - else { - resultValues[i] = v; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.clip = function (x, min, max) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.min(max, Math.max(min, values[i])); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.abs = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.abs(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.int = function (x) { - var resultValues = new Int32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = values[i]; - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }, 'int32'); - }; - MathBackendCPU.prototype.sigmoid = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = 1 / (1 + Math.exp(-values[i])); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.sin = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.sin(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.cos = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.cos(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.tan = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.tan(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.asin = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.asin(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.acos = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.acos(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.atan = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.atan(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.sinh = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.sinh(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.cosh = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.cosh(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.tanh = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = util.tanh(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.step = function (x, alpha) { - if (alpha === void 0) { alpha = 0; } - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - if (util.isValNaN(value, x.dtype)) { - resultValues[i] = util.getNaN(x.dtype); - } - else { - resultValues[i] = value > 0 ? 1 : alpha; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.conv2d = function (x, filter, convInfo) { - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = convInfo.padInfo.left; - var padTop = convInfo.padInfo.top; - var y = ops.buffer(convInfo.outShape, x.dtype); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d2 = 0; d2 < convInfo.outChannels; ++d2) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * convInfo.strideHeight - padLeft; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * convInfo.strideWidth - padTop; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - var dotProd = 0; - for (var xR = xRMin; xR < xRMax; ++xR) { - var wR = xR - xRCorner; - for (var xC = xCMin; xC < xCMax; ++xC) { - var wC = xC - xCCorner; - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - var pixel = x.get(b, xR, xC, d1); - var weight = filter.get(wR, wC, d1, d2); - dotProd += pixel * weight; - } - } - } - y.set(dotProd, b, yR, yC, d2); - } - } - } - } - return y.toTensor(); - }; - MathBackendCPU.prototype.conv2dDerInput = function (dy, filter, convInfo) { - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var topPad = filterHeight - 1 - convInfo.padInfo.top; - var leftPad = filterWidth - 1 - convInfo.padInfo.left; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var dx = ops.buffer(convInfo.inShape, 'float32'); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - for (var xR = 0; xR < convInfo.inHeight; ++xR) { - var xRCorner = xR - leftPad; - var xRMin = Math.max(0, Math.ceil(xRCorner / strideHeight)); - var yRMax = Math.min(convInfo.outHeight, (filterHeight + xRCorner) / strideHeight); - for (var xC = 0; xC < convInfo.inWidth; ++xC) { - var xCCorner = xC - topPad; - var xCMin = Math.max(0, Math.ceil(xCCorner / strideWidth)); - var yCMax = Math.min(convInfo.outWidth, (filterWidth + xCCorner) / strideWidth); - var dotProd = 0; - for (var yR = xRMin; yR < yRMax; ++yR) { - var wR = yR * strideHeight - xRCorner; - for (var yC = xCMin; yC < yCMax; ++yC) { - var wC = yC * strideWidth - xCCorner; - for (var d2 = 0; d2 < convInfo.outChannels; ++d2) { - var pixel = dy.get(b, yR, yC, d2); - var weight = filter.get(filterHeight - 1 - wR, filterWidth - 1 - wC, d1, d2); - dotProd += pixel * weight; - } - } - } - dx.set(dotProd, b, xR, xC, d1); - } - } - } - } - return dx.toTensor(); - }; - MathBackendCPU.prototype.conv2dDerFilter = function (x, dy, convInfo) { - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var dW = ops.buffer(convInfo.filterShape, 'float32'); - var leftPad = convInfo.padInfo.left; - var topPad = convInfo.padInfo.top; - for (var wR = 0; wR < filterHeight; ++wR) { - var yRMin = Math.max(0, Math.ceil((topPad - wR) / strideHeight)); - var yRMax = Math.min(convInfo.outHeight, (convInfo.inHeight + topPad - wR) / strideHeight); - for (var wC = 0; wC < filterWidth; ++wC) { - var yCMin = Math.max(0, Math.ceil((leftPad - wC) / strideWidth)); - var yCMax = Math.min(convInfo.outWidth, (convInfo.inWidth + leftPad - wC) / strideWidth); - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - for (var d2 = 0; d2 < convInfo.outChannels; ++d2) { - var dotProd = 0; - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var yR = yRMin; yR < yRMax; ++yR) { - var xR = wR + yR * strideHeight - topPad; - for (var yC = yCMin; yC < yCMax; ++yC) { - var xC = wC + yC * strideWidth - leftPad; - dotProd += x.get(b, xR, xC, d1) * dy.get(b, yR, yC, d2); - } - } - } - dW.set(dotProd, wR, wC, d1, d2); - } - } - } - } - return dW.toTensor(); - }; - MathBackendCPU.prototype.depthwiseConv2D = function (x, filter, convInfo) { - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = convInfo.padInfo.left; - var padTop = convInfo.padInfo.top; - var chMul = convInfo.outChannels / convInfo.inChannels; - var y = ops.buffer(convInfo.outShape, x.dtype); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * convInfo.strideHeight - padLeft; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * convInfo.strideWidth - padTop; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - for (var q = 0; q < chMul; ++q) { - var dotProd = 0; - for (var xR = xRMin; xR < xRMax; ++xR) { - var wR = xR - xRCorner; - for (var xC = xCMin; xC < xCMax; ++xC) { - var wC = xC - xCCorner; - var pixel = x.get(b, xR, xC, d1); - var weight = filter.get(wR, wC, d1, q); - dotProd += pixel * weight; - } - } - y.set(dotProd, b, yR, yC, d1 * chMul + q); - } - } - } - } - } - return y.toTensor(); - }; - MathBackendCPU.prototype.tile = function (x, reps) { - var newShape = new Array(x.rank); - for (var i = 0; i < newShape.length; i++) { - newShape[i] = x.shape[i] * reps[i]; - } - var result = ops.buffer(newShape, x.dtype); - var values = x.dataSync(); - for (var i = 0; i < result.values.length; ++i) { - var newLoc = result.indexToLoc(i); - var originalLoc = new Array(x.rank); - for (var i_1 = 0; i_1 < originalLoc.length; i_1++) { - originalLoc[i_1] = newLoc[i_1] % x.shape[i_1]; - } - var originalIndex = x.locToIndex(originalLoc); - result.values[i] = values[originalIndex]; - } - return result.toTensor(); - }; - MathBackendCPU.prototype.pad1D = function (x, paddings, constantValue) { - var leftPadding = paddings[0]; - var rightPadding = paddings[1]; - var values = x.dataSync(); - var result = ops.zeros([leftPadding + values.length + rightPadding], x.dtype); - var newValues = result.dataSync(); - var z = 0; - for (var i = 0; i < newValues.length; i++) { - if (i >= leftPadding && i < leftPadding + values.length) { - newValues[i] = values[z++]; - } - else { - newValues[i] = constantValue; - } - } - return result; - }; - MathBackendCPU.prototype.pad2D = function (x, paddings, constantValue) { - var topPadding = paddings[0][0]; - var bottomPadding = paddings[0][1]; - var leftPadding = paddings[1][0]; - var rightPadding = paddings[1][1]; - var newShape = [ - topPadding + x.shape[0] + bottomPadding, - leftPadding + x.shape[1] + rightPadding - ]; - var result = ops.zeros(newShape, x.dtype); - var newValues = result.dataSync(); - var values = x.dataSync(); - var z = 0; - for (var i = 0; i < newShape[0]; i++) { - var rangeStart = -1; - var rangeEnd = -1; - if (i >= topPadding && i < newShape[0] - bottomPadding) { - rangeStart = i * newShape[1] + leftPadding; - rangeEnd = rangeStart + x.shape[1] - 1; - } - for (var j = 0; j < newShape[1]; j++) { - var v = i * newShape[1] + j; - if (v >= rangeStart && v <= rangeEnd) { - newValues[v] = values[z++]; - } - else { - newValues[v] = constantValue; - } - } - } - return result; - }; - MathBackendCPU.prototype.transpose = function (x, perm) { - var newShape = new Array(x.rank); - for (var i = 0; i < newShape.length; i++) { - newShape[i] = x.shape[perm[i]]; - } - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - var result = tensor_1.Tensor.make(newShape, { values: resultValues }); - for (var i = 0; i < x.size; ++i) { - var loc = x.indexToLoc(i); - var newLoc = new Array(loc.length); - for (var i_2 = 0; i_2 < newLoc.length; i_2++) { - newLoc[i_2] = loc[perm[i_2]]; - } - var newIndex = result.locToIndex(newLoc); - resultValues[newIndex] = values[i]; - } - return result; - }; - MathBackendCPU.prototype.gather = function (x, indices, axis) { - var newShape = x.shape.slice(); - var indicesValues = indices.dataSync(); - newShape[axis] = indicesValues.length; - var result = ops.zeros(newShape, x.dtype); - var values = x.dataSync(); - var resultValues = result.dataSync(); - for (var i = 0; i < result.size; ++i) { - var newLoc = result.indexToLoc(i); - var originalLoc = newLoc.slice(); - originalLoc[axis] = indicesValues[newLoc[axis]]; - var originalIndex = x.locToIndex(originalLoc); - resultValues[i] = values[originalIndex]; - } - return result; - }; - MathBackendCPU.prototype.pool = function (x, convInfo, poolType) { - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var y = ops.buffer(convInfo.outShape, 'float32'); - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * strideHeight - padTop; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * strideWidth - padLeft; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - var minMaxValue = (poolType === 'max' ? Number.NEGATIVE_INFINITY : - Number.POSITIVE_INFINITY); - var avgValue = 0; - for (var xR = xRMin; xR < xRMax; ++xR) { - for (var xC = xCMin; xC < xCMax; ++xC) { - var pixel = x.get(b, xR, xC, d); - if (isNaN(pixel)) { - minMaxValue = NaN; - avgValue = NaN; - break; - } - if ((poolType === 'max' && pixel > minMaxValue) || - (poolType === 'min' && pixel < minMaxValue)) { - minMaxValue = pixel; - } - else if (poolType === 'avg') { - avgValue += pixel / (filterHeight * filterWidth); - } - } - if (isNaN(minMaxValue)) { - break; - } - } - y.set(poolType === 'avg' ? avgValue : minMaxValue, b, yR, yC, d); - } - } - } - } - return y.toTensor(); - }; - MathBackendCPU.prototype.maxPool = function (x, convInfo) { - return this.pool(x, convInfo, 'max'); - }; - MathBackendCPU.prototype.maxPoolPositions = function (x, convInfo) { - var maxPositions = ops.buffer(convInfo.outShape, 'int32'); - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * strideHeight - padTop; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * strideWidth - padLeft; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - var maxValue = Number.NEGATIVE_INFINITY; - var maxPosition = -1; - for (var xR = xRMin; xR < xRMax; ++xR) { - var wR = xR - xRCorner; - for (var xC = xCMin; xC < xCMax; ++xC) { - var wC = xC - xCCorner; - var pixel = x.get(b, xR, xC, d); - if (pixel > maxValue) { - maxValue = pixel; - maxPosition = wR * filterWidth + wC; - } - } - } - maxPositions.set(maxPosition, b, yR, yC, d); - } - } - } - } - return maxPositions.toTensor(); - }; - MathBackendCPU.prototype.maxPoolBackprop = function (dy, x, convInfo) { - var maxPositions = this.maxPoolPositions(x, convInfo); - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var dx = ops.buffer(x.shape, 'float32'); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var dxR = 0; dxR < convInfo.inHeight; ++dxR) { - for (var dxC = 0; dxC < convInfo.inWidth; ++dxC) { - var dyRCorner = dxR - padTop; - var dyCCorner = dxC - padLeft; - var dotProd = 0; - for (var wR = 0; wR < filterHeight; ++wR) { - var dyR = (dyRCorner + wR) / strideHeight; - if (dyR < 0 || dyR >= convInfo.outHeight || - Math.floor(dyR) !== dyR) { - continue; - } - for (var wC = 0; wC < filterWidth; ++wC) { - var dyC = (dyCCorner + wC) / strideWidth; - if (dyC < 0 || dyC >= convInfo.outWidth || - Math.floor(dyC) !== dyC) { - continue; - } - var maxPos = filterHeight * filterWidth - 1 - - maxPositions.get(b, dyR, dyC, d); - var curPos = wR * filterWidth + wC; - var mask = maxPos === curPos ? 1 : 0; - if (mask === 0) { - continue; - } - var pixel = dy.get(b, dyR, dyC, d); - dotProd += pixel * mask; - } - } - dx.set(dotProd, b, dxR, dxC, d); - } - } - } - } - return dx.toTensor(); - }; - MathBackendCPU.prototype.avgPoolBackprop = function (dy, x, convInfo) { - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var dx = ops.buffer(x.shape, 'float32'); - var avgMultiplier = 1 / (filterHeight * filterWidth); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var dxR = 0; dxR < convInfo.inHeight; ++dxR) { - for (var dxC = 0; dxC < convInfo.inWidth; ++dxC) { - var dyRCorner = dxR - padTop; - var dyCCorner = dxC - padLeft; - var dotProd = 0; - for (var wR = 0; wR < filterHeight; ++wR) { - var dyR = (dyRCorner + wR) / strideHeight; - if (dyR < 0 || dyR >= convInfo.outHeight || - Math.floor(dyR) !== dyR) { - continue; - } - for (var wC = 0; wC < filterWidth; ++wC) { - var dyC = (dyCCorner + wC) / strideWidth; - if (dyC < 0 || dyC >= convInfo.outWidth || - Math.floor(dyC) !== dyC) { - continue; - } - var pixel = dy.get(b, dyR, dyC, d); - dotProd += pixel; - } - } - dx.set(dotProd * avgMultiplier, b, dxR, dxC, d); - } - } - } - } - return dx.toTensor(); - }; - MathBackendCPU.prototype.minPool = function (x, convInfo) { - return this.pool(x, convInfo, 'min'); - }; - MathBackendCPU.prototype.avgPool = function (x, convInfo) { - return this.pool(x, convInfo, 'avg').toFloat(); - }; - MathBackendCPU.prototype.resizeBilinear = function (x, newHeight, newWidth, alignCorners) { - var _a = x.shape, batch = _a[0], oldHeight = _a[1], oldWidth = _a[2], numChannels = _a[3]; - var output = ops.buffer([batch, newHeight, newWidth, numChannels], x.dtype); - var effectiveInputSize = alignCorners ? [oldHeight - 1, oldWidth - 1] : [oldHeight, oldWidth]; - var effectiveOutputSize = alignCorners ? [newHeight - 1, newWidth - 1] : [newHeight, newWidth]; - for (var b = 0; b < batch; b++) { - for (var r = 0; r < newHeight; r++) { - for (var c = 0; c < newWidth; c++) { - for (var d = 0; d < numChannels; d++) { - var sourceFracRow = (effectiveInputSize[0]) * r / (effectiveOutputSize[0]); - var sourceFracCol = (effectiveInputSize[1]) * c / (effectiveOutputSize[1]); - var sourceRowFloor = Math.floor(sourceFracRow); - var sourceRowCeil = Math.min(oldHeight - 1, Math.ceil(sourceFracRow)); - var sourceColFloor = Math.floor(sourceFracCol); - var sourceColCeil = Math.min(oldWidth - 1, Math.ceil(sourceFracCol)); - var topLeft = x.get(b, sourceRowFloor, sourceColFloor, d); - var bottomLeft = x.get(b, sourceRowCeil, sourceColFloor, d); - var topRight = x.get(b, sourceRowFloor, sourceColCeil, d); - var bottomRight = x.get(b, sourceRowCeil, sourceColCeil, d); - var rowFrac = sourceFracRow - sourceRowFloor; - var colFrac = sourceFracCol - sourceColFloor; - var top_1 = topLeft + (topRight - topLeft) * colFrac; - var bottom = bottomLeft + (bottomRight - bottomLeft) * colFrac; - var newValue = top_1 + (bottom - top_1) * rowFrac; - output.set(newValue, b, r, c, d); - } - } - } - } - return output.toTensor(); - }; - MathBackendCPU.prototype.batchNormalization4D = function (x, mean, variance, varianceEpsilon, scale, offset) { - var xValues = x.dataSync(); - var meanValues = mean.dataSync(); - var varianceValues = variance.dataSync(); - var scaleValues = scale ? scale.dataSync() : new Float32Array([1]); - var offsetValues = offset ? offset.dataSync() : new Float32Array([0]); - var outValues = new Float32Array(xValues.length); - for (var i = 0; i < xValues.length; i++) { - outValues[i] = offsetValues[i % offsetValues.length] + - (xValues[i] - meanValues[i % meanValues.length]) * - scaleValues[i % scaleValues.length] / - Math.sqrt(varianceValues[i % varianceValues.length] + varianceEpsilon); - } - return ops_1.tensor4d(outValues, x.shape); - }; - MathBackendCPU.prototype.localResponseNormalization4D = function (x, radius, bias, alpha, beta, normRegion) { - var output = ops.buffer(x.shape, 'float32'); - var rad = radius; - var maxW = output.shape[1] - 1; - var maxH = output.shape[2] - 1; - var maxD = output.shape[3] - 1; - var sumAcrossChannels = function (b, r, c, d) { - var sum = 0.0; - for (var j = Math.max(0, d - rad); j <= Math.min(d + rad, maxD); j++) { - var z = x.get(b, r, c, j); - sum += z * z; - } - return sum; - }; - var sumWithinChannel = function (b, r, c, d) { - var sum = 0.0; - for (var u = Math.max(0, r - rad); u <= Math.min(r + rad, maxW); u++) { - for (var v = Math.max(0, c - rad); v <= Math.min(c + rad, maxH); v++) { - sum += Math.pow(x.get(b, u, v, d), 2); - } - } - return sum; - }; - for (var b = 0; b < output.shape[0]; b++) { - for (var r = 0; r <= output.shape[1]; r++) { - for (var c = 0; c < output.shape[2]; c++) { - for (var d = 0; d < output.shape[3]; d++) { - var sum = normRegion === 'withinChannel' ? - sumWithinChannel(b, r, c, d) : - sumAcrossChannels(b, r, c, d); - var val = x.get(b, r, c, d) * Math.pow(bias + alpha * sum, -beta); - output.set(val, b, r, c, d); - } - } - } - } - return output.toTensor(); - }; - MathBackendCPU.prototype.multinomial = function (probabilities, numSamples, seed) { - var batchSize = probabilities.shape[0]; - var numEvents = probabilities.shape[1]; - var res = ops.zeros([batchSize, numSamples], 'int32'); - var resVals = res.dataSync(); - var probVals = probabilities.dataSync(); - for (var b = 0; b < batchSize; ++b) { - var offset = b * numEvents; - var cdf = new Float32Array(numEvents - 1); - cdf[0] = probVals[offset]; - for (var event_1 = 1; event_1 < cdf.length; ++event_1) { - cdf[event_1] = cdf[event_1 - 1] + probVals[offset + event_1]; - } - var random = seedrandom.alea(seed.toString()); - var outOffset = b * numSamples; - for (var sampleId = 0; sampleId < numSamples; ++sampleId) { - var r = random(); - resVals[outOffset + sampleId] = cdf.length; - for (var event_2 = 0; event_2 < cdf.length; event_2++) { - if (r < cdf[event_2]) { - resVals[outOffset + sampleId] = event_2; - break; - } - } - } - } - return res; - }; - MathBackendCPU.prototype.oneHot = function (indices, depth, onValue, offValue) { - var res = new Float32Array(indices.size * depth); - res.fill(offValue); - for (var event_3 = 0; event_3 < indices.size; ++event_3) { - res[event_3 * depth + indices.get(event_3)] = onValue; - } - return ops.tensor2d(res, [indices.size, depth]); - }; - MathBackendCPU.prototype.broadcastedBinaryOp = function (a, b, dtype, op) { - var newShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var result = ops.buffer(newShape, dtype); - var aValues = a.dataSync(); - var bValues = b.dataSync(); - var aBroadcastDims = broadcast_util.getBroadcastDims(a.shape, newShape); - var bBroadcastDims = broadcast_util.getBroadcastDims(b.shape, newShape); - var _loop_1 = function (i) { - var loc = result.indexToLoc(i); - var aLoc = loc.slice(-a.rank); - aBroadcastDims.forEach(function (d) { return aLoc[d] = 0; }); - var aIndex = a.locToIndex(aLoc); - var bLoc = loc.slice(-b.rank); - bBroadcastDims.forEach(function (d) { return bLoc[d] = 0; }); - var bIndex = b.locToIndex(bLoc); - result.values[i] = op(aValues[aIndex], bValues[bIndex]); - }; - for (var i = 0; i < result.values.length; ++i) { - _loop_1(i); - } - return result.toTensor(); - }; - MathBackendCPU.prototype.dispose = function () { }; - return MathBackendCPU; -}()); -exports.MathBackendCPU = MathBackendCPU; -environment_1.ENV.registerBackend('cpu', function () { return new MathBackendCPU(); }); -var NDArrayMathCPU = (function (_super) { - __extends(NDArrayMathCPU, _super); - function NDArrayMathCPU(safeMode) { - if (safeMode === void 0) { safeMode = false; } - var _this = this; - console.warn('new NDArrayMathCPU() is deprecated. Please use ' + - 'dl.setBackend(\'cpu\').'); - _this = _super.call(this, 'cpu', safeMode) || this; - return _this; - } - return NDArrayMathCPU; -}(math_1.NDArrayMath)); -exports.NDArrayMathCPU = NDArrayMathCPU; - -},{"../environment":34,"../math":105,"../ops/axis_util":107,"../ops/broadcast_util":110,"../ops/concat_util":113,"../ops/ops":123,"../ops/selu_util":129,"../tensor":146,"../types":150,"../util":151,"seedrandom":153}],69:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var math_1 = require("../math"); -var axis_util = require("../ops/axis_util"); -var reduce_util = require("../ops/reduce_util"); -var tensor_1 = require("../tensor"); -var types = require("../types"); -var util = require("../util"); -var argminmax_gpu_1 = require("./webgl/argminmax_gpu"); -var avg_pool_backprop_gpu_1 = require("./webgl/avg_pool_backprop_gpu"); -var batchnorm_gpu_1 = require("./webgl/batchnorm_gpu"); -var binaryop_gpu = require("./webgl/binaryop_gpu"); -var binaryop_gpu_1 = require("./webgl/binaryop_gpu"); -var clip_gpu_1 = require("./webgl/clip_gpu"); -var concat_gpu_1 = require("./webgl/concat_gpu"); -var conv_backprop_gpu_1 = require("./webgl/conv_backprop_gpu"); -var conv_gpu_1 = require("./webgl/conv_gpu"); -var conv_gpu_depthwise_1 = require("./webgl/conv_gpu_depthwise"); -var from_pixels_gpu_1 = require("./webgl/from_pixels_gpu"); -var gather_gpu_1 = require("./webgl/gather_gpu"); -var gpgpu_context_1 = require("./webgl/gpgpu_context"); -var gpgpu_math = require("./webgl/gpgpu_math"); -var logical_gpu_1 = require("./webgl/logical_gpu"); -var lrn_gpu_1 = require("./webgl/lrn_gpu"); -var max_pool_backprop_gpu_1 = require("./webgl/max_pool_backprop_gpu"); -var mulmat_gpu_1 = require("./webgl/mulmat_gpu"); -var multinomial_gpu_1 = require("./webgl/multinomial_gpu"); -var onehot_gpu_1 = require("./webgl/onehot_gpu"); -var pad_gpu_1 = require("./webgl/pad_gpu"); -var pool_gpu_1 = require("./webgl/pool_gpu"); -var reduce_gpu_1 = require("./webgl/reduce_gpu"); -var resize_bilinear_gpu_1 = require("./webgl/resize_bilinear_gpu"); -var reverse_gpu_1 = require("./webgl/reverse_gpu"); -var slice_gpu_1 = require("./webgl/slice_gpu"); -var tex_util_1 = require("./webgl/tex_util"); -var texture_manager_1 = require("./webgl/texture_manager"); -var tile_gpu_1 = require("./webgl/tile_gpu"); -var transpose_gpu_1 = require("./webgl/transpose_gpu"); -var unary_op = require("./webgl/unaryop_gpu"); -var unaryop_gpu_1 = require("./webgl/unaryop_gpu"); -var webgl_util = require("./webgl/webgl_util"); -var MathBackendWebGL = (function () { - function MathBackendWebGL(gpgpu, delayedStorage) { - if (delayedStorage === void 0) { delayedStorage = true; } - this.gpgpu = gpgpu; - this.delayedStorage = delayedStorage; - this.texData = new WeakMap(); - this.uploadWaitMs = 0; - this.downloadWaitMs = 0; - this.binaryCache = {}; - this.disposed = false; - if (environment_1.ENV.get('WEBGL_VERSION') < 1) { - throw new Error('WebGL is not supported on this device'); - } - if (gpgpu == null) { - this.gpgpu = new gpgpu_context_1.GPGPUContext(); - this.gpgpuCreatedLocally = true; - } - else { - this.gpgpuCreatedLocally = false; - } - if (typeof document !== 'undefined') { - this.canvas = document.createElement('canvas'); - } - this.textureManager = new texture_manager_1.TextureManager(this.gpgpu); - } - MathBackendWebGL.prototype.register = function (dataId, shape, dtype) { - if (this.texData.has(dataId)) { - throw new Error('Data buffer is already registered'); - } - this.texData.set(dataId, { - shape: shape, - dtype: dtype, - values: null, - texture: null, - texShape: null, - texType: tex_util_1.TextureType.FLOAT - }); - }; - MathBackendWebGL.prototype.fromPixels = function (pixels, numChannels) { - if (pixels == null) { - throw new Error('MathBackendWebGL.writePixels(): pixels can not be null'); - } - var texShape = [pixels.height, pixels.width]; - var outShape = [pixels.height, pixels.width, numChannels]; - if (pixels instanceof HTMLVideoElement) { - if (this.canvas == null) { - throw new Error('Can\'t read pixels from HTMLImageElement outside ' + - 'the browser.'); - } - this.canvas.width = pixels.width; - this.canvas.height = pixels.height; - this.canvas.getContext('2d').drawImage(pixels, 0, 0, pixels.width, pixels.height); - pixels = this.canvas; - } - var tempPixelArray = tensor_1.Tensor.make(texShape, {}, 'int32'); - this.texData.get(tempPixelArray.dataId).texType = tex_util_1.TextureType.UNSIGNED_BYTE; - this.gpgpu.uploadPixelDataToTexture(this.getTexture(tempPixelArray.dataId), pixels); - var program = new from_pixels_gpu_1.FromPixelsProgram(outShape); - var res = this.compileAndRun(program, [tempPixelArray]); - tempPixelArray.dispose(); - return res; - }; - MathBackendWebGL.prototype.write = function (dataId, values) { - if (values == null) { - throw new Error('MathBackendWebGL.write(): values can not be null'); - } - this.throwIfNoData(dataId); - var texData = this.texData.get(dataId); - var texture = texData.texture, texShape = texData.texShape, texType = texData.texType; - if (texture != null) { - this.textureManager.releaseTexture(texture, texShape, texType); - texData.texture = null; - texData.texShape = null; - } - texData.values = values; - if (!this.delayedStorage) { - this.uploadToGPU(dataId); - } - }; - MathBackendWebGL.prototype.readSync = function (dataId) { - this.throwIfNoData(dataId); - var texData = this.texData.get(dataId); - var texture = texData.texture, values = texData.values, texShape = texData.texShape; - if (values != null) { - this.cacheOnCPU(dataId); - return values; - } - var shouldTimeProgram = this.activeTimers != null; - var start; - if (shouldTimeProgram) { - start = performance.now(); - } - var float32Values = this.gpgpu.downloadMatrixFromTexture(texture, texShape[0], texShape[1]); - if (shouldTimeProgram) { - this.downloadWaitMs += performance.now() - start; - } - this.cacheOnCPU(dataId, float32Values); - return texData.values; - }; - MathBackendWebGL.prototype.read = function (dataId) { - return __awaiter(this, void 0, void 0, function () { - var texData, texture, values, texShape, float32Values; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.throwIfNoData(dataId); - texData = this.texData.get(dataId); - texture = texData.texture, values = texData.values, texShape = texData.texShape; - if (values != null) { - this.cacheOnCPU(dataId); - return [2, values]; - } - if (!environment_1.ENV.get('WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED')) return [3, 2]; - return [4, this.gpgpu.downloadMatrixFromTextureAsync(texture, texShape[0], texShape[1])]; - case 1: - float32Values = _a.sent(); - this.cacheOnCPU(dataId, float32Values); - return [2, texData.values]; - case 2: - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 0) { - return [2, this.readSync(dataId)]; - } - return [4, this.gpgpu.runQuery(function () { })]; - case 3: - _a.sent(); - return [2, this.readSync(dataId)]; - } - }); - }); - }; - MathBackendWebGL.prototype.time = function (f) { - return __awaiter(this, void 0, void 0, function () { - var oldActiveTimers, newActiveTimers, outerMostTime, flattenedActiveTimers, kernelMs, res; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - oldActiveTimers = this.activeTimers; - newActiveTimers = []; - outerMostTime = false; - if (this.programTimersStack == null) { - this.programTimersStack = newActiveTimers; - outerMostTime = true; - } - else { - this.activeTimers.push(newActiveTimers); - } - this.activeTimers = newActiveTimers; - f(); - flattenedActiveTimers = util.flatten(this.activeTimers); - this.activeTimers = oldActiveTimers; - if (outerMostTime) { - this.programTimersStack = null; - } - return [4, Promise.all(flattenedActiveTimers).then(function (results) { - var sum = 0; - results.forEach(function (result) { return sum += result; }); - return sum; - })]; - case 1: - kernelMs = _a.sent(); - res = { - uploadWaitMs: this.uploadWaitMs, - downloadWaitMs: this.downloadWaitMs, - kernelMs: kernelMs, - wallMs: null - }; - this.uploadWaitMs = 0; - this.downloadWaitMs = 0; - return [2, res]; - } - }); - }); - }; - MathBackendWebGL.prototype.memory = function () { - return { unreliable: false }; - }; - MathBackendWebGL.prototype.startTimer = function () { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) { - return this.gpgpu.beginQuery(); - } - return { startMs: performance.now(), endMs: null }; - }; - MathBackendWebGL.prototype.endTimer = function (query) { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) { - this.gpgpu.endQuery(); - return query; - } - query.endMs = performance.now(); - return query; - }; - MathBackendWebGL.prototype.getQueryTime = function (query) { - return __awaiter(this, void 0, void 0, function () { - var timerQuery; - return __generator(this, function (_a) { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) { - return [2, this.gpgpu.pollQueryTime(query)]; - } - timerQuery = query; - return [2, timerQuery.endMs - timerQuery.startMs]; - }); - }); - }; - MathBackendWebGL.prototype.disposeData = function (dataId) { - if (this.texData.has(dataId)) { - var _a = this.texData.get(dataId), texture = _a.texture, texShape = _a.texShape, texType = _a.texType; - if (texture != null) { - this.textureManager.releaseTexture(texture, texShape, texType); - } - this.texData.delete(dataId); - } - }; - MathBackendWebGL.prototype.getTexture = function (dataId) { - this.uploadToGPU(dataId); - return this.texData.get(dataId).texture; - }; - MathBackendWebGL.prototype.getTextureData = function (dataId) { - this.uploadToGPU(dataId); - return this.texData.get(dataId); - }; - MathBackendWebGL.prototype.getGPGPUContext = function () { - return this.gpgpu; - }; - MathBackendWebGL.prototype.slice1D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram([size]); - var customSetup = program.getCustomSetupFunc([begin]); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.slice2D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram(size); - var customSetup = program.getCustomSetupFunc(begin); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.slice3D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram(size); - var customSetup = program.getCustomSetupFunc(begin); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.slice4D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram(size); - var customSetup = program.getCustomSetupFunc(begin); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.reverse4D = function (x, axis) { - var program = new reverse_gpu_1.ReverseProgram(x.shape, axis); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.concat = function (a, b) { - var program = new concat_gpu_1.ConcatProgram(a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.neg = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.NEG); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.matMul = function (a, b, transposeA, transposeB) { - var program = new mulmat_gpu_1.MatMulProgram(a.shape, b.shape, transposeA, transposeB); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.multiply = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MUL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.batchNormalization4D = function (x, mean, variance, varianceEpsilon, scale, offset) { - var inputs = [x, mean, variance]; - var offsetShape = null; - if (offset != null) { - offsetShape = offset.shape; - inputs.push(offset); - } - var scaleShape = null; - if (scale != null) { - scaleShape = scale.shape; - inputs.push(scale); - } - var program = new batchnorm_gpu_1.BatchNormProgram(x.shape, mean.shape, variance.shape, offsetShape, scaleShape, varianceEpsilon); - return this.compileAndRun(program, inputs); - }; - MathBackendWebGL.prototype.localResponseNormalization4D = function (x, radius, bias, alpha, beta, normRegion) { - var program = new lrn_gpu_1.LRNProgram(x.shape, radius, bias, alpha, beta, normRegion); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.tile = function (x, reps) { - var program = new tile_gpu_1.TileProgram(x.shape, reps); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.pad1D = function (x, paddings, constantValue) { - var program = new pad_gpu_1.Pad1DProgram(x.shape, paddings, constantValue); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.pad2D = function (x, paddings, constantValue) { - var program = new pad_gpu_1.Pad2DProgram(x.shape, paddings, constantValue); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.transpose = function (x, perm) { - var program = new transpose_gpu_1.TransposeProgram(x.shape, perm); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.gather = function (x, indices, axis) { - var program = new gather_gpu_1.GatherProgram(x.shape, indices.size, axis); - return this.compileAndRun(program, [x, indices]); - }; - MathBackendWebGL.prototype.reduce = function (x, reduceType, dtype) { - var batchSize = x.shape[0]; - var inSize = x.shape[1]; - var windowSize = reduce_util.computeOptimalWindowSize(inSize); - var reduceInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize }; - var program = new reduce_gpu_1.ReduceProgram(reduceInfo, reduceType); - var _a = program.outputShape, rows = _a[0], cols = _a[1]; - var output = this.makeOutputArray([rows, cols], dtype); - this.compileAndRun(program, [x], output); - if (output.shape[1] === 1) { - return output; - } - return this.reduce(output, reduceType, dtype); - }; - MathBackendWebGL.prototype.argReduce = function (x, reduceType, bestIndicesA) { - if (bestIndicesA === void 0) { bestIndicesA = null; } - var batchSize = x.shape[0]; - var inSize = x.shape[1]; - if (bestIndicesA != null) { - batchSize = bestIndicesA.shape[0]; - inSize = bestIndicesA.shape[1]; - } - var windowSize = reduce_util.computeOptimalWindowSize(inSize); - var reduceInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize }; - var program = new argminmax_gpu_1.ArgMinMaxProgram(reduceInfo, reduceType, bestIndicesA == null); - var _a = program.outputShape, rows = _a[0], cols = _a[1]; - var output = this.makeOutputArray([rows, cols], 'int32'); - var inputs = [x]; - if (bestIndicesA != null) { - inputs.push(bestIndicesA); - } - this.compileAndRun(program, inputs, output); - if (output.shape[1] === 1) { - return output; - } - return this.argReduce(x, reduceType, output); - }; - MathBackendWebGL.prototype.sum = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('sum', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - var outputDType = types.sumOutType(x.dtype); - return this.reduce(a2D, 'sum', outputDType).reshape(outShape); - }; - MathBackendWebGL.prototype.argMin = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMin', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.argReduce(a2D, 'min').reshape(outShape); - }; - MathBackendWebGL.prototype.argMax = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMax', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.argReduce(a2D, 'max').reshape(outShape); - }; - MathBackendWebGL.prototype.equal = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.notEqual = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.NOT_EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.less = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LESS, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.lessEqual = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LESS_EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.greater = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.GREATER, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.greaterEqual = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.GREATER_EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.logicalNot = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOGICAL_NOT); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.logicalAnd = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_AND, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.logicalOr = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_OR, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.logicalXor = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_XOR, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.where = function (condition, a, b, dtype) { - var program = new logical_gpu_1.WhereProgram(condition.rank, a.shape, a.rank); - var output = this.makeOutputArray(program.outputShape, dtype); - return this.compileAndRun(program, [condition, a, b], output); - }; - MathBackendWebGL.prototype.topKValues = function (x, k) { - throw new Error('topKValues GPU not yet implemented!'); - }; - MathBackendWebGL.prototype.topKIndices = function (x, k) { - throw new Error('topKIndices GPU not yet implemented!'); - }; - MathBackendWebGL.prototype.min = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('min', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.reduce(a2D, 'min', a2D.dtype).reshape(outShape); - }; - MathBackendWebGL.prototype.minimum = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MIN, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.max = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('max', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.reduce(a2D, 'max', a2D.dtype).reshape(outShape); - }; - MathBackendWebGL.prototype.maximum = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MAX, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.divide = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.DIV, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'float32'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.add = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.ADD, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.subtract = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.SUB, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.pow = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.POW, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.ceil = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.CEIL); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.floor = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.FLOOR); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.exp = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.EXP); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.log = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOG); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sqrt = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SQRT); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.square = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SQUARE); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.relu = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.RELU); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.elu = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ELU); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.eluDer = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ELU_DER); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.selu = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SELU); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.leakyRelu = function (x, alpha) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LEAKY_RELU(alpha)); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.prelu = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.PRELU, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.preluDer = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.PRELU_DER, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.int = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TO_INT); - var output = this.makeOutputArray(program.outputShape, 'int32'); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.clip = function (x, min, max) { - var program = new clip_gpu_1.ClipProgram(x.shape, min, max); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.abs = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ABS); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sigmoid = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIGMOID); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sin = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.cos = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.COS); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.tan = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TAN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.asin = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ASIN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.acos = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ACOS); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.atan = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ATAN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sinh = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SINH); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.cosh = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.COSH); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.tanh = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TANH); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.step = function (x, alpha) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.STEP(alpha)); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.conv2d = function (x, filter, convInfo) { - var program = new conv_gpu_1.Conv2DProgram(convInfo); - return this.compileAndRun(program, [x, filter]); - }; - MathBackendWebGL.prototype.conv2dDerInput = function (dy, filter, convInfo) { - var program = new conv_backprop_gpu_1.Conv2DDerInputProgram(convInfo); - return this.compileAndRun(program, [dy, filter]); - }; - MathBackendWebGL.prototype.conv2dDerFilter = function (x, dy, convInfo) { - var program = new conv_backprop_gpu_1.Conv2DDerFilterProgram(convInfo); - return this.compileAndRun(program, [x, dy]); - }; - MathBackendWebGL.prototype.depthwiseConv2D = function (x, filter, convInfo) { - var program = new conv_gpu_depthwise_1.DepthwiseConv2DProgram(convInfo); - return this.compileAndRun(program, [x, filter]); - }; - MathBackendWebGL.prototype.maxPool = function (x, convInfo) { - var program = new pool_gpu_1.Pool2DProgram(convInfo, 'max', false); - var output = this.makeOutputArray(program.outputShape, x.dtype); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.minPool = function (x, convInfo) { - var program = new pool_gpu_1.Pool2DProgram(convInfo, 'min', false); - var output = this.makeOutputArray(program.outputShape, x.dtype); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.avgPool = function (x, convInfo) { - var program = new pool_gpu_1.Pool2DProgram(convInfo, 'avg', false); - var output = this.makeOutputArray(program.outputShape, 'float32'); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.maxPoolBackprop = function (dy, x, convInfo) { - var getPositions = true; - var maxPoolPositionsProgram = new pool_gpu_1.Pool2DProgram(convInfo, 'max', getPositions); - var maxPoolPositions = this.compileAndRun(maxPoolPositionsProgram, [x]); - var maxPoolBackPropProgram = new max_pool_backprop_gpu_1.MaxPool2DBackpropProgram(convInfo); - var output = this.makeOutputArray(maxPoolBackPropProgram.outputShape, x.dtype); - var result = this.compileAndRun(maxPoolBackPropProgram, [dy, maxPoolPositions], output); - maxPoolPositions.dispose(); - return result; - }; - MathBackendWebGL.prototype.avgPoolBackprop = function (dy, x, convInfo) { - var avgPoolBackpropProgram = new avg_pool_backprop_gpu_1.AvgPool2DBackpropProgram(convInfo); - var output = this.makeOutputArray(avgPoolBackpropProgram.outputShape, x.dtype); - return this.compileAndRun(avgPoolBackpropProgram, [dy], output); - }; - MathBackendWebGL.prototype.resizeBilinear = function (x, newHeight, newWidth, alignCorners) { - var program = new resize_bilinear_gpu_1.ResizeBilinearProgram(x.shape, newHeight, newWidth, alignCorners); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.multinomial = function (probs, numSamples, seed) { - var batchSize = probs.shape[0]; - var numOutcomes = probs.shape[1]; - var program = new multinomial_gpu_1.MultinomialProgram(batchSize, numOutcomes, numSamples); - var output = this.makeOutputArray(program.outputShape, 'int32'); - var customSetup = program.getCustomSetupFunc(seed); - return this.compileAndRun(program, [probs], output, customSetup); - }; - MathBackendWebGL.prototype.oneHot = function (indices, depth, onValue, offValue) { - var program = new onehot_gpu_1.OneHotProgram(indices.size, depth, onValue, offValue); - return this.compileAndRun(program, [indices]); - }; - MathBackendWebGL.prototype.makeOutputArray = function (shape, dtype) { - return tensor_1.Tensor.make(shape, {}, dtype); - }; - MathBackendWebGL.prototype.compileAndRun = function (program, inputs, output, customSetup) { - var _this = this; - if (output == null) { - output = this.makeOutputArray(program.outputShape, inputs[0].dtype); - } - var inputsData = inputs.map(function (input) { - _this.uploadToGPU(input.dataId); - return { tensor: input, texData: _this.texData.get(input.dataId) }; - }); - this.uploadToGPU(output.dataId); - var outputData = { - tensor: output, - texData: this.texData.get(output.dataId) - }; - var key = gpgpu_math.makeShaderKey(program, inputsData, outputData); - var binary = this.getAndSaveBinary(key, function () { - return gpgpu_math.compileProgram(_this.gpgpu, program, inputsData, outputData); - }); - var shouldTimeProgram = this.activeTimers != null; - var query; - if (shouldTimeProgram) { - query = this.startTimer(); - } - gpgpu_math.runProgram(binary, inputsData, outputData, customSetup); - if (shouldTimeProgram) { - query = this.endTimer(query); - this.activeTimers.push(this.getQueryTime(query)); - } - return output; - }; - MathBackendWebGL.prototype.getAndSaveBinary = function (key, getBinary) { - if (!(key in this.binaryCache)) { - this.binaryCache[key] = getBinary(); - } - return this.binaryCache[key]; - }; - MathBackendWebGL.prototype.getTextureManager = function () { - return this.textureManager; - }; - MathBackendWebGL.prototype.dispose = function () { - if (this.disposed) { - return; - } - for (var key in this.binaryCache) { - this.gpgpu.deleteProgram(this.binaryCache[key].webGLProgram); - } - this.textureManager.dispose(); - this.canvas.remove(); - if (this.gpgpuCreatedLocally) { - this.gpgpu.dispose(); - } - this.disposed = true; - }; - MathBackendWebGL.prototype.throwIfNoData = function (dataId) { - if (!this.texData.has(dataId)) { - throw new Error("WebGL backend: No data found for this tensor. " + - "Did you change your backend in the middle of the program? " + - "New backends can't use Tensors created with previous backends"); - } - }; - MathBackendWebGL.prototype.uploadToGPU = function (dataId) { - this.throwIfNoData(dataId); - var texData = this.texData.get(dataId); - var shape = texData.shape, values = texData.values, texture = texData.texture, dtype = texData.dtype, texType = texData.texType; - if (texture != null) { - return; - } - var shouldTimeProgram = this.activeTimers != null; - var start; - if (shouldTimeProgram) { - start = performance.now(); - } - var texShape = webgl_util.getTextureShapeFromLogicalShape(this.gpgpu.gl, shape); - texData.texShape = texShape; - var newTexture = this.textureManager.acquireTexture(texShape, texType); - texData.texture = newTexture; - if (values != null) { - this.gpgpu.uploadMatrixToTexture(newTexture, texShape[0], texShape[1], typedArrayToFloat32(values, dtype)); - texData.values = null; - if (shouldTimeProgram) { - this.uploadWaitMs += performance.now() - start; - } - } - }; - MathBackendWebGL.prototype.cacheOnCPU = function (dataId, float32Values) { - var dontKeepCopyOnGPU = this.delayedStorage; - var texData = this.texData.get(dataId); - var texture = texData.texture, texShape = texData.texShape, dtype = texData.dtype, texType = texData.texType; - if (dontKeepCopyOnGPU && texture != null) { - this.textureManager.releaseTexture(texture, texShape, texType); - texData.texture = null; - texData.texShape = null; - } - if (float32Values != null) { - texData.values = float32ToTypedArray(float32Values, dtype); - } - }; - return MathBackendWebGL; -}()); -exports.MathBackendWebGL = MathBackendWebGL; -environment_1.ENV.registerBackend('webgl', function () { return new MathBackendWebGL(); }); -var NDArrayMathGPU = (function (_super) { - __extends(NDArrayMathGPU, _super); - function NDArrayMathGPU(gpgpu, safeMode) { - if (safeMode === void 0) { safeMode = false; } - var _this = this; - console.warn('new NDArrayMathGPU() is deprecated. Please use ' + - 'dl.setBackend(\'webgl\').'); - _this = _super.call(this, new MathBackendWebGL(gpgpu), safeMode) || this; - return _this; - } - NDArrayMathGPU.prototype.getGPGPUContext = function () { - return this.engine.backend.getGPGPUContext(); - }; - NDArrayMathGPU.prototype.getTextureManager = function () { - return this.engine.backend.getTextureManager(); - }; - return NDArrayMathGPU; -}(math_1.NDArrayMath)); -exports.NDArrayMathGPU = NDArrayMathGPU; -function float32ToTypedArray(a, dtype) { - if (dtype === 'float32') { - return a; - } - else if (dtype === 'int32' || dtype === 'bool') { - var result = (dtype === 'int32') ? new Int32Array(a.length) : - new Uint8Array(a.length); - for (var i = 0; i < result.length; ++i) { - var val = a[i]; - val = isNaN(val) ? util.getNaN(dtype) : Math.round(val); - result[i] = val; - } - return result; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -function typedArrayToFloat32(a, dtype) { - if (a instanceof Float32Array) { - return a; - } - else { - var res = new Float32Array(a.length); - for (var i = 0; i < res.length; i++) { - var val = a[i]; - res[i] = util.isValNaN(val, dtype) ? NaN : val; - } - return res; - } -} - -},{"../environment":34,"../math":105,"../ops/axis_util":107,"../ops/reduce_util":126,"../tensor":146,"../types":150,"../util":151,"./webgl/argminmax_gpu":72,"./webgl/avg_pool_backprop_gpu":73,"./webgl/batchnorm_gpu":74,"./webgl/binaryop_gpu":75,"./webgl/clip_gpu":76,"./webgl/concat_gpu":77,"./webgl/conv_backprop_gpu":78,"./webgl/conv_gpu":79,"./webgl/conv_gpu_depthwise":80,"./webgl/from_pixels_gpu":81,"./webgl/gather_gpu":82,"./webgl/gpgpu_context":83,"./webgl/gpgpu_math":84,"./webgl/logical_gpu":86,"./webgl/lrn_gpu":87,"./webgl/max_pool_backprop_gpu":88,"./webgl/mulmat_gpu":89,"./webgl/multinomial_gpu":90,"./webgl/onehot_gpu":91,"./webgl/pad_gpu":92,"./webgl/pool_gpu":93,"./webgl/reduce_gpu":94,"./webgl/resize_bilinear_gpu":95,"./webgl/reverse_gpu":96,"./webgl/slice_gpu":98,"./webgl/tex_util":99,"./webgl/texture_manager":100,"./webgl/tile_gpu":101,"./webgl/transpose_gpu":102,"./webgl/unaryop_gpu":103,"./webgl/webgl_util":104}],70:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ops = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -function executeKernel(backend, kernelName, inputAndArgs) { - if (kernelName === 'MatMul') { - var config = inputAndArgs; - return backend.matMul(config.inputs.a, config.inputs.b, config.args.transposeA, config.args.transposeB); - } - else if (kernelName === 'Slice1D') { - var config = inputAndArgs; - return backend.slice1D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Slice2D') { - var config = inputAndArgs; - return backend.slice2D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Slice3D') { - var config = inputAndArgs; - return backend.slice3D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Slice4D') { - var config = inputAndArgs; - return backend.slice4D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Reverse4D') { - var config = inputAndArgs; - return backend.reverse4D(config.inputs.x, config.args.axis); - } - else if (kernelName === 'Concat') { - var config = inputAndArgs; - return backend.concat(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Neg') { - var config = inputAndArgs; - return backend.neg(config.inputs.x); - } - else if (kernelName === 'Add') { - var config = inputAndArgs; - return backend.add(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Sub') { - var config = inputAndArgs; - return backend.subtract(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Mul') { - var config = inputAndArgs; - return backend.multiply(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Div') { - var config = inputAndArgs; - return backend.divide(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Sum') { - var config = inputAndArgs; - return backend.sum(config.inputs.x, config.args.axes); - } - else if (kernelName === 'ArgMax') { - var config = inputAndArgs; - return backend.argMax(config.inputs.x, config.args.axes); - } - else if (kernelName === 'ArgMin') { - var config = inputAndArgs; - return backend.argMin(config.inputs.x, config.args.axes); - } - else if (kernelName === 'Equal') { - var config = inputAndArgs; - return backend.equal(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'NotEqual') { - var config = inputAndArgs; - return backend.notEqual(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Less') { - var config = inputAndArgs; - return backend.less(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LessEqual') { - var config = inputAndArgs; - return backend.lessEqual(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Greater') { - var config = inputAndArgs; - return backend.greater(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'GreaterEqual') { - var config = inputAndArgs; - return backend.greaterEqual(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LogicalNot') { - var config = inputAndArgs; - return backend.logicalNot(config.inputs.x); - } - else if (kernelName === 'LogicalAnd') { - var config = inputAndArgs; - return backend.logicalAnd(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LogicalOr') { - var config = inputAndArgs; - return backend.logicalOr(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LogicalXor') { - var config = inputAndArgs; - return backend.logicalXor(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Where') { - var config = inputAndArgs; - return backend.where(config.inputs.condition, config.inputs.a, config.inputs.b, config.args.dtype); - } - else if (kernelName === 'TopKValues') { - var config = inputAndArgs; - return backend.topKValues(config.inputs.x, config.args.k); - } - else if (kernelName === 'TopKIndices') { - var config = inputAndArgs; - return backend.topKIndices(config.inputs.x, config.args.k); - } - else if (kernelName === 'Min') { - var config = inputAndArgs; - return backend.min(config.inputs.x, config.args.axes); - } - else if (kernelName === 'Minimum') { - var config = inputAndArgs; - return backend.minimum(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Max') { - var config = inputAndArgs; - return backend.max(config.inputs.x, config.args.axes); - } - else if (kernelName === 'Maximum') { - var config = inputAndArgs; - return backend.maximum(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Ceil') { - var config = inputAndArgs; - return backend.ceil(config.inputs.x); - } - else if (kernelName === 'Floor') { - var config = inputAndArgs; - return backend.floor(config.inputs.x); - } - else if (kernelName === 'Pow') { - var config = inputAndArgs; - return backend.pow(config.inputs.base, config.inputs.exp); - } - else if (kernelName === 'Exp') { - var config = inputAndArgs; - return backend.exp(config.inputs.x); - } - else if (kernelName === 'Log') { - var config = inputAndArgs; - return backend.log(config.inputs.x); - } - else if (kernelName === 'Sqrt') { - var config = inputAndArgs; - return backend.sqrt(config.inputs.x); - } - else if (kernelName === 'Square') { - var config = inputAndArgs; - return backend.square(config.inputs.x); - } - else if (kernelName === 'Relu') { - var config = inputAndArgs; - return backend.relu(config.inputs.x); - } - else if (kernelName === 'Reshape') { - var config = inputAndArgs; - var x = config.inputs.x; - var newShape = config.args.newShape; - return tensor_1.Tensor.make(newShape, { dataId: x.dataId }, x.dtype); - } - else if (kernelName === 'Cast') { - var config = inputAndArgs; - var x = config.inputs.x; - var newDType = config.args.newDType; - if (!util.hasEncodingLoss(x.dtype, newDType)) { - return tensor_1.Tensor.make(x.shape, { dataId: x.dataId }, newDType); - } - if (newDType === 'int32') { - return backend.int(x); - } - else if (newDType === 'bool') { - return backend.notEqual(x, ops.scalar(0, x.dtype)); - } - else { - throw new Error("Error in Cast: unknown dtype argument (" + newDType + ")"); - } - } - else if (kernelName === 'LeakyRelu') { - var config = inputAndArgs; - return backend.leakyRelu(config.inputs.x, config.args.alpha); - } - else if (kernelName === 'PReLU') { - var config = inputAndArgs; - return backend.prelu(config.inputs.x, config.inputs.alpha); - } - else if (kernelName === 'PReLUDer') { - var config = inputAndArgs; - return backend.preluDer(config.inputs.x, config.inputs.alpha); - } - else if (kernelName === 'Elu') { - var config = inputAndArgs; - return backend.elu(config.inputs.x); - } - else if (kernelName === 'EluDer') { - var config = inputAndArgs; - return backend.eluDer(config.inputs.x); - } - else if (kernelName === 'Selu') { - var config = inputAndArgs; - return backend.selu(config.inputs.x); - } - else if (kernelName === 'Abs') { - var config = inputAndArgs; - return backend.abs(config.inputs.x); - } - else if (kernelName === 'Sigmoid') { - var config = inputAndArgs; - return backend.sigmoid(config.inputs.x); - } - else if (kernelName === 'Step') { - var config = inputAndArgs; - return backend.step(config.inputs.x, config.args.alpha); - } - else if (kernelName === 'Sin') { - var config = inputAndArgs; - return backend.sin(config.inputs.x); - } - else if (kernelName === 'Cos') { - var config = inputAndArgs; - return backend.cos(config.inputs.x); - } - else if (kernelName === 'Tan') { - var config = inputAndArgs; - return backend.tan(config.inputs.x); - } - else if (kernelName === 'Asin') { - var config = inputAndArgs; - return backend.asin(config.inputs.x); - } - else if (kernelName === 'Acos') { - var config = inputAndArgs; - return backend.acos(config.inputs.x); - } - else if (kernelName === 'Atan') { - var config = inputAndArgs; - return backend.atan(config.inputs.x); - } - else if (kernelName === 'Sinh') { - var config = inputAndArgs; - return backend.sinh(config.inputs.x); - } - else if (kernelName === 'Cosh') { - var config = inputAndArgs; - return backend.cosh(config.inputs.x); - } - else if (kernelName === 'Tanh') { - var config = inputAndArgs; - return backend.tanh(config.inputs.x); - } - else if (kernelName === 'Clip') { - var config = inputAndArgs; - return backend.clip(config.inputs.x, config.args.min, config.args.max); - } - else if (kernelName === 'Tile') { - var config = inputAndArgs; - return backend.tile(config.inputs.x, config.args.reps); - } - else if (kernelName === 'Gather') { - var config = inputAndArgs; - return backend.gather(config.inputs.x, config.inputs.indices, config.args.axis); - } - else if (kernelName === 'Pad1D') { - var config = inputAndArgs; - return backend.pad1D(config.inputs.x, config.args.paddings, config.args.constantValue); - } - else if (kernelName === 'Pad2D') { - var config = inputAndArgs; - return backend.pad2D(config.inputs.x, config.args.paddings, config.args.constantValue); - } - else if (kernelName === 'Transpose') { - var config = inputAndArgs; - return backend.transpose(config.inputs.x, config.args.perm); - } - else if (kernelName === 'Conv2D') { - var config = inputAndArgs; - return backend.conv2d(config.inputs.x, config.inputs.filter, config.args.convInfo); - } - else if (kernelName === 'Conv2DDerInput') { - var config = inputAndArgs; - return backend.conv2dDerInput(config.inputs.dy, config.inputs.filter, config.args.convInfo); - } - else if (kernelName === 'Conv2DDerFilter') { - var config = inputAndArgs; - return backend.conv2dDerFilter(config.inputs.x, config.inputs.dy, config.args.convInfo); - } - else if (kernelName === 'DepthwiseConv2D') { - var config = inputAndArgs; - return backend.depthwiseConv2D(config.inputs.x, config.inputs.filter, config.args.convInfo); - } - else if (kernelName === 'MaxPool') { - var config = inputAndArgs; - return backend.maxPool(config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'MaxPoolBackprop') { - var config = inputAndArgs; - return backend.maxPoolBackprop(config.inputs.dy, config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'AvgPool') { - var config = inputAndArgs; - return backend.avgPool(config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'AvgPoolBackprop') { - var config = inputAndArgs; - return backend.avgPoolBackprop(config.inputs.dy, config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'MinPool') { - var config = inputAndArgs; - return backend.minPool(config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'ResizeBilinear') { - var config = inputAndArgs; - return backend.resizeBilinear(config.inputs.x, config.args.newHeight, config.args.newWidth, config.args.alignCorners); - } - else if (kernelName === 'BatchNorm4D') { - var config = inputAndArgs; - return backend.batchNormalization4D(config.inputs.x, config.inputs.mean, config.inputs.variance, config.args.varianceEpsilon, config.inputs.scale, config.inputs.offset); - } - else if (kernelName === 'LRN4D') { - var config = inputAndArgs; - return backend.localResponseNormalization4D(config.inputs.x, config.args.radius, config.args.bias, config.args.alpha, config.args.beta, config.args.normRegion); - } - else if (kernelName === 'Multinomial') { - var config = inputAndArgs; - return backend.multinomial(config.inputs.probs, config.args.numSamples, config.args.seed); - } - else if (kernelName === 'OneHot') { - var config = inputAndArgs; - return backend.oneHot(config.inputs.indices, config.args.depth, config.args.onValue, config.args.offValue); - } - throw new Error("No backend method found for kernel " + kernelName); -} -exports.executeKernel = executeKernel; - -},{"../ops/ops":123,"../tensor":146,"../util":151}],71:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MatrixOrientation; -(function (MatrixOrientation) { - MatrixOrientation[MatrixOrientation["REGULAR"] = 0] = "REGULAR"; - MatrixOrientation[MatrixOrientation["TRANSPOSED"] = 1] = "TRANSPOSED"; -})(MatrixOrientation = exports.MatrixOrientation || (exports.MatrixOrientation = {})); - -},{}],72:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ArgMinMaxProgram = (function () { - function ArgMinMaxProgram(reduceInfo, op, firstPass) { - this.variableNames = ['A']; - var windowSize = reduceInfo.windowSize; - var batchSize = reduceInfo.batchSize; - var inSize = reduceInfo.inSize; - var outSize = Math.ceil(inSize / windowSize); - if (!firstPass) { - this.variableNames.push('bestIndicesA'); - } - this.outputShape = [batchSize, outSize]; - var compOp = (op === 'max') ? '>' : '<'; - var indexSnippet = firstPass ? - 'inOffset + i;' : - 'round(getBestIndicesA(batch, inOffset + i));'; - this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * " + windowSize + ";\n\n int bestIndex = 0;\n float bestValue = getA(batch, inOffset);\n\n for (int i = 0; i < " + windowSize + "; i++) {\n int inIdx = " + indexSnippet + ";\n float candidate = getA(batch, inIdx);\n if (isNaN(candidate)) {\n setOutput(candidate);\n return;\n }\n if (candidate " + compOp + " bestValue) {\n bestValue = candidate;\n bestIndex = inIdx;\n }\n }\n setOutput(float(bestIndex));\n }\n "; - } - return ArgMinMaxProgram; -}()); -exports.ArgMinMaxProgram = ArgMinMaxProgram; - -},{}],73:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var AvgPool2DBackpropProgram = (function () { - function AvgPool2DBackpropProgram(convInfo) { - this.variableNames = ['dy']; - this.outputShape = convInfo.inShape; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var avgMultiplier = 1 / (filterHeight * filterWidth); - this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n const float avgMultiplier = float(" + avgMultiplier + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n setOutput(dotProd);\n }\n "; - } - return AvgPool2DBackpropProgram; -}()); -exports.AvgPool2DBackpropProgram = AvgPool2DBackpropProgram; - -},{}],74:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var broadcast_util = require("../../ops/broadcast_util"); -var BatchNormProgram = (function () { - function BatchNormProgram(xShape, meanShape, varianceShape, offsetShape, scaleShape, varianceEpsilon) { - this.outputShape = []; - this.supportsBroadcasting = true; - this.variableNames = ['x', 'mean', 'variance']; - broadcast_util.assertAndGetBroadcastShape(xShape, meanShape); - broadcast_util.assertAndGetBroadcastShape(xShape, varianceShape); - var offsetSnippet = '0.0'; - if (offsetShape != null) { - broadcast_util.assertAndGetBroadcastShape(xShape, offsetShape); - this.variableNames.push('offset'); - offsetSnippet = 'getOffsetAtOutCoords()'; - } - var scaleSnippet = '1.0'; - if (scaleShape != null) { - broadcast_util.assertAndGetBroadcastShape(xShape, scaleShape); - this.variableNames.push('scale'); - scaleSnippet = 'getScaleAtOutCoords()'; - } - this.outputShape = xShape; - this.userCode = "\n void main() {\n float x = getXAtOutCoords();\n float mean = getMeanAtOutCoords();\n float variance = getVarianceAtOutCoords();\n float offset = " + offsetSnippet + ";\n float scale = " + scaleSnippet + ";\n float inv = scale / sqrt(variance + float(" + varianceEpsilon + "));\n setOutput((x - mean) * inv + offset);\n }\n "; - } - return BatchNormProgram; -}()); -exports.BatchNormProgram = BatchNormProgram; - -},{"../../ops/broadcast_util":110}],75:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var broadcast_util = require("../../ops/broadcast_util"); -var CHECK_NAN_SNIPPET = "\n if (isNaN(a)) return a;\n if (isNaN(b)) return b;\n"; -exports.ADD = 'return a + b;'; -exports.SUB = 'return a - b;'; -exports.MUL = 'return a * b;'; -exports.DIV = 'return a / b;'; -exports.POW = "\n return (round(mod(b, 2.0)) == 0 || round(mod(b, 2.0)) == 2) ?\n pow(abs(a), b) : sign(a) * pow(abs(a), b);\n"; -exports.EQUAL = CHECK_NAN_SNIPPET + "\n return float(a == b);\n"; -exports.NOT_EQUAL = CHECK_NAN_SNIPPET + "\n return float(a != b);\n"; -exports.LESS = CHECK_NAN_SNIPPET + "\n return float(a < b);\n"; -exports.LESS_EQUAL = CHECK_NAN_SNIPPET + "\n return float(a <= b);\n"; -exports.GREATER = CHECK_NAN_SNIPPET + "\n return float(a > b);\n"; -exports.GREATER_EQUAL = CHECK_NAN_SNIPPET + "\n return float(a >= b);\n"; -exports.LOGICAL_AND = CHECK_NAN_SNIPPET + "\n return float(a >= 1.0 && b >= 1.0);\n"; -exports.LOGICAL_OR = CHECK_NAN_SNIPPET + "\n return float(a >= 1.0 || b >= 1.0);\n"; -exports.LOGICAL_XOR = CHECK_NAN_SNIPPET + "\n return float(a >= 1.0 ^^ b >= 1.0);\n"; -exports.PRELU = "\n return (a >= 0.0) ? a : b * a;\n"; -exports.PRELU_DER = "\n return (a > 0.0) ? 1.0 : ((a < 0.0) ? b : a);\n"; -exports.MAX = CHECK_NAN_SNIPPET + "\n return max(a, b);\n"; -exports.MIN = CHECK_NAN_SNIPPET + "\n return min(a, b);\n"; -var BinaryOpProgram = (function () { - function BinaryOpProgram(op, aShape, bShape) { - this.variableNames = ['A', 'B']; - this.supportsBroadcasting = true; - this.outputShape = - broadcast_util.assertAndGetBroadcastShape(aShape, bShape); - this.userCode = "\n float binaryOperation(float a, float b) {\n " + op + "\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n "; - } - return BinaryOpProgram; -}()); -exports.BinaryOpProgram = BinaryOpProgram; - -},{"../../ops/broadcast_util":110}],76:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ClipProgram = (function () { - function ClipProgram(aShape, min, max) { - this.variableNames = ['A']; - this.outputShape = aShape; - var minFixed = min.toFixed(20); - var maxFixed = max.toFixed(20); - this.userCode = "\n void main() {\n float value = getAAtOutCoords();\n if (isNaN(value)) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, " + minFixed + ", " + maxFixed + "));\n }\n "; - } - return ClipProgram; -}()); -exports.ClipProgram = ClipProgram; - -},{}],77:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var concat_util = require("../../ops/concat_util"); -var ConcatProgram = (function () { - function ConcatProgram(aShape, bShape) { - this.variableNames = ['A', 'B']; - this.outputShape = []; - this.outputShape = - concat_util.computeOutShape(aShape, bShape, 1); - this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int yR = coords.x;\n int yC = coords.y;\n\n float value = 0.0;\n if (yC < " + aShape[1] + ") {\n value = getA(yR, yC);\n } else {\n yC -= " + aShape[1] + ";\n value = getB(yR, yC);\n }\n\n setOutput(value);\n }\n "; - } - return ConcatProgram; -}()); -exports.ConcatProgram = ConcatProgram; - -},{"../../ops/concat_util":113}],78:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Conv2DDerFilterProgram = (function () { - function Conv2DDerFilterProgram(convInfo) { - this.variableNames = ['x', 'dy']; - this.outputShape = convInfo.filterShape; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int d2 = coords.w;\n\n // Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int b = 0; b < " + convInfo.batchSize + "; b++) {\n for (int yR = 0; yR < " + convInfo.outHeight + "; yR++) {\n int xR = wR + yR * " + strideHeight + " - " + padTop + ";\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int yC = 0; yC < " + convInfo.outWidth + "; yC++) {\n int xC = wC + yC * " + strideWidth + " - " + padLeft + ";\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n "; - } - return Conv2DDerFilterProgram; -}()); -exports.Conv2DDerFilterProgram = Conv2DDerFilterProgram; -var Conv2DDerInputProgram = (function () { - function Conv2DDerInputProgram(convInfo) { - this.variableNames = ['dy', 'W']; - this.outputShape = convInfo.inShape; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n\n ivec2 dyCorner = coords.yz - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = " + filterHeight + " - 1 - wR;\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = " + filterWidth + " - 1 - wC;\n\n for (int d2 = 0; d2 < " + convInfo.outChannels + "; d2++) {\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n "; - } - return Conv2DDerInputProgram; -}()); -exports.Conv2DDerInputProgram = Conv2DDerInputProgram; - -},{}],79:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Conv2DProgram = (function () { - function Conv2DProgram(convInfo) { - this.variableNames = ['x', 'W']; - this.outputShape = convInfo.outShape; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var inputDepthNearestVec4 = Math.floor(convInfo.inChannels / 4) * 4; - var inputDepthVec4Remainder = convInfo.inChannels % 4; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d2 = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n for (int d1 = 0; d1 < " + inputDepthNearestVec4 + "; d1 += 4) {\n vec4 xValues = vec4(\n getX(batch, xR, xC, d1),\n getX(batch, xR, xC, d1 + 1),\n getX(batch, xR, xC, d1 + 2),\n getX(batch, xR, xC, d1 + 3)\n );\n vec4 wValues = vec4(\n getW(wR, wC, d1, d2),\n getW(wR, wC, d1 + 1, d2),\n getW(wR, wC, d1 + 2, d2),\n getW(wR, wC, d1 + 3, d2)\n );\n\n dotProd += dot(xValues, wValues);\n }\n\n if (" + (inputDepthVec4Remainder === 1) + ") {\n dotProd +=\n getX(batch, xR, xC, " + inputDepthNearestVec4 + ") *\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2);\n } else if (" + (inputDepthVec4Remainder === 2) + ") {\n vec2 xValues = vec2(\n getX(batch, xR, xC, " + inputDepthNearestVec4 + "),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 1)\n );\n vec2 wValues = vec2(\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if (" + (inputDepthVec4Remainder === 3) + ") {\n vec3 xValues = vec3(\n getX(batch, xR, xC, " + inputDepthNearestVec4 + "),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 1),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 2)\n );\n vec3 wValues = vec3(\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 1, d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n setOutput(dotProd);\n }\n "; - } - return Conv2DProgram; -}()); -exports.Conv2DProgram = Conv2DProgram; - -},{}],80:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var DepthwiseConv2DProgram = (function () { - function DepthwiseConv2DProgram(convInfo) { - this.variableNames = ['x', 'W']; - this.outputShape = convInfo.outShape; - var xNumRows = convInfo.inHeight; - var xNumCols = convInfo.inWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var channelMul = convInfo.outChannels / convInfo.inChannels; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2 / " + channelMul + ";\n int q = d2 - d1 * " + channelMul + ";\n\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n // TODO(dsmilkov): Flatten the two for loops and vec4 the operations.\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + xNumRows + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + xNumCols + ") {\n continue;\n }\n\n float xVal = getX(batch, xR, xC, d1);\n float wVal = getW(wR, wC, d1, q);\n dotProd += xVal * wVal;\n }\n }\n setOutput(dotProd);\n }\n "; - } - return DepthwiseConv2DProgram; -}()); -exports.DepthwiseConv2DProgram = DepthwiseConv2DProgram; - -},{}],81:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var FromPixelsProgram = (function () { - function FromPixelsProgram(outputShape) { - this.variableNames = ['A']; - var height = outputShape[0], width = outputShape[1]; - this.outputShape = outputShape; - this.userCode = "\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + width + ".0, " + height + ".0);\n\n vec4 values = texture2D(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n setOutput(floor(value * 255.0 + 0.5));\n }\n "; - } - return FromPixelsProgram; -}()); -exports.FromPixelsProgram = FromPixelsProgram; - -},{}],82:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var GatherProgram = (function () { - function GatherProgram(aShape, indicesLength, axis) { - this.variableNames = ['A', 'indices']; - var outputShape = aShape.slice(); - outputShape[axis] = indicesLength; - this.outputShape = outputShape; - this.rank = outputShape.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var sourceCoords = getSourceCoords(aShape, axis); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + sourceCoords + "));\n }\n "; - } - return GatherProgram; -}()); -exports.GatherProgram = GatherProgram; -function getSourceCoords(aShape, axis) { - var rank = aShape.length; - if (rank > 4) { - throw Error("Gather for rank " + rank + " is not yet supported"); - } - if (rank === 1) { - return "int(getIndices(resRC))"; - } - var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var sourceCoords = []; - for (var i = 0; i < aShape.length; i++) { - if (i === axis) { - sourceCoords.push("int(getIndices(" + currentCoords[i] + "))"); - } - else { - sourceCoords.push("" + currentCoords[i]); - } - } - return sourceCoords.join(); -} - -},{"./shader_compiler":97}],83:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var util = require("../../util"); -var gpgpu_util = require("./gpgpu_util"); -var tex_util = require("./tex_util"); -var webgl_util = require("./webgl_util"); -var GPGPUContext = (function () { - function GPGPUContext(gl) { - this.outputTexture = null; - this.program = null; - this.disposed = false; - this.autoDebugValidate = false; - if (gl != null) { - this.gl = gl; - } - else { - this.gl = gpgpu_util.createWebGLContext(); - } - if (environment_1.ENV.get('WEBGL_VERSION') === 1) { - this.textureFloatExtension = - webgl_util.getExtensionOrThrow(this.gl, 'OES_texture_float'); - this.colorBufferFloatExtension = - this.gl.getExtension('WEBGL_color_buffer_float'); - } - else { - this.colorBufferFloatExtension = - webgl_util.getExtensionOrThrow(this.gl, 'EXT_color_buffer_float'); - } - this.loseContextExtension = - webgl_util.getExtensionOrThrow(this.gl, 'WEBGL_lose_context'); - if (environment_1.ENV.get('WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED')) { - this.getBufferSubDataAsyncExtension = - this.gl.getExtension('WEBGL_get_buffer_sub_data_async'); - } - this.vertexBuffer = gpgpu_util.createVertexBuffer(this.gl); - this.indexBuffer = gpgpu_util.createIndexBuffer(this.gl); - this.framebuffer = webgl_util.createFramebuffer(this.gl); - } - GPGPUContext.prototype.dispose = function () { - var _this = this; - if (this.disposed) { - return; - } - if (this.program != null) { - console.warn('Disposing a GPGPUContext that still has a bound WebGLProgram.' + - ' This is probably a resource leak, delete the program with ' + - 'GPGPUContext.deleteProgram before disposing.'); - } - if (this.outputTexture != null) { - console.warn('Disposing a GPGPUContext that still has a bound output matrix ' + - 'texture. This is probably a resource leak, delete the output ' + - 'matrix texture with GPGPUContext.deleteMatrixTexture before ' + - 'disposing.'); - } - var gl = this.gl; - webgl_util.callAndCheck(gl, function () { return gl.finish(); }); - webgl_util.callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, null); }); - webgl_util.callAndCheck(gl, function () { return gl.deleteFramebuffer(_this.framebuffer); }); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, null); }); - webgl_util.callAndCheck(gl, function () { return gl.deleteBuffer(_this.vertexBuffer); }); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); }); - webgl_util.callAndCheck(gl, function () { return gl.deleteBuffer(_this.indexBuffer); }); - this.loseContextExtension.loseContext(); - this.disposed = true; - }; - GPGPUContext.prototype.enableAutomaticDebugValidation = function (enabled) { - this.autoDebugValidate = enabled; - webgl_util.enableDebugWebGLErrorChecking(enabled); - }; - GPGPUContext.prototype.createMatrixTexture = function (rows, columns) { - this.throwIfDisposed(); - return gpgpu_util.createMatrixTexture(this.gl, rows, columns); - }; - GPGPUContext.prototype.uploadPixelDataToTexture = function (texture, pixels) { - this.throwIfDisposed(); - gpgpu_util.uploadPixelDataToTexture(this.gl, texture, pixels); - }; - GPGPUContext.prototype.createPackedMatrixTexture = function (rows, columns) { - this.throwIfDisposed(); - return gpgpu_util.createPackedMatrixTexture(this.gl, rows, columns); - }; - GPGPUContext.prototype.deleteMatrixTexture = function (texture) { - var _this = this; - this.throwIfDisposed(); - if (this.outputTexture === texture) { - webgl_util.unbindColorTextureFromFramebuffer(this.gl, this.framebuffer); - this.outputTexture = null; - } - webgl_util.callAndCheck(this.gl, function () { return _this.gl.deleteTexture(texture); }); - }; - GPGPUContext.prototype.uploadMatrixToTexture = function (texture, rows, columns, matrix) { - this.throwIfDisposed(); - var numChannels = 1; - return gpgpu_util.uploadMatrixToTexture(this.gl, texture, rows, columns, matrix, numChannels); - }; - GPGPUContext.prototype.uploadMatrixToPackedTexture = function (texture, rows, columns, matrix) { - this.throwIfDisposed(); - return gpgpu_util.uploadMatrixToPackedTexture(this.gl, texture, rows, columns, matrix); - }; - GPGPUContext.prototype.downloadMatrixFromTexture = function (texture, rows, columns) { - var _this = this; - return this.downloadMatrixDriver(texture, function () { - return gpgpu_util.downloadMatrixFromOutputTexture(_this.gl, rows, columns); - }); - }; - GPGPUContext.prototype.downloadMatrixFromTextureAsync = function (texture, rows, columns) { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - if (this.getBufferSubDataAsyncExtension == null) { - throw new Error("Cannot download matrix from output texture asynchronously, " + - "WEBGL_get_buffer_sub_data_async is not enabled."); - } - return [2, this.downloadMatrixDriverAsync(texture, function () { return gpgpu_util.downloadMatrixFromOutputTextureAsync(_this.gl, _this.getBufferSubDataAsyncExtension, rows, columns); })]; - }); - }); - }; - GPGPUContext.prototype.downloadMatrixFromRGBAColorTexture = function (texture, rows, columns, channels) { - var _this = this; - return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadMatrixFromRGBAColorTexture(_this.gl, rows, columns, channels); }); - }; - GPGPUContext.prototype.downloadMatrixFromPackedTexture = function (texture, rows, columns) { - var _this = this; - return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadMatrixFromPackedOutputTexture(_this.gl, rows, columns); }); - }; - GPGPUContext.prototype.createProgram = function (fragmentShaderSource) { - this.throwIfDisposed(); - var gl = this.gl; - var fragmentShader = webgl_util.createFragmentShader(gl, fragmentShaderSource); - var vertexShader = gpgpu_util.createVertexShader(gl); - var program = webgl_util.createProgram(gl); - webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, vertexShader); }); - webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, fragmentShader); }); - webgl_util.linkProgram(gl, program); - if (this.autoDebugValidate) { - webgl_util.validateProgram(gl, program); - } - return program; - }; - GPGPUContext.prototype.deleteProgram = function (program) { - var _this = this; - this.throwIfDisposed(); - if (program === this.program) { - this.program = null; - } - if (program != null) { - webgl_util.callAndCheck(this.gl, function () { return _this.gl.deleteProgram(program); }); - } - }; - GPGPUContext.prototype.setProgram = function (program) { - var _this = this; - this.throwIfDisposed(); - this.program = program; - if ((this.program != null) && this.autoDebugValidate) { - webgl_util.validateProgram(this.gl, this.program); - } - webgl_util.callAndCheck(this.gl, function () { return _this.gl.useProgram(program); }); - }; - GPGPUContext.prototype.getUniformLocation = function (program, uniformName, shouldThrow) { - if (shouldThrow === void 0) { shouldThrow = true; } - this.throwIfDisposed(); - if (shouldThrow) { - return webgl_util.getProgramUniformLocationOrThrow(this.gl, program, uniformName); - } - else { - return webgl_util.getProgramUniformLocation(this.gl, program, uniformName); - } - }; - GPGPUContext.prototype.getAttributeLocation = function (program, attribute) { - var _this = this; - this.throwIfDisposed(); - return webgl_util.callAndCheck(this.gl, function () { return _this.gl.getAttribLocation(program, attribute); }); - }; - GPGPUContext.prototype.getUniformLocationNoThrow = function (program, uniformName) { - this.throwIfDisposed(); - return this.gl.getUniformLocation(program, uniformName); - }; - GPGPUContext.prototype.setInputMatrixTexture = function (inputMatrixTexture, uniformLocation, textureUnit) { - this.throwIfDisposed(); - this.throwIfNoProgram(); - webgl_util.bindTextureToProgramUniformSampler(this.gl, this.program, inputMatrixTexture, uniformLocation, textureUnit); - }; - GPGPUContext.prototype.setOutputMatrixTexture = function (outputMatrixTexture, rows, columns) { - this.setOutputMatrixTextureDriver(outputMatrixTexture, columns, rows); - }; - GPGPUContext.prototype.setOutputPackedMatrixTexture = function (outputPackedMatrixTexture, rows, columns) { - this.throwIfDisposed(); - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - this.setOutputMatrixTextureDriver(outputPackedMatrixTexture, width, height); - }; - GPGPUContext.prototype.setOutputMatrixWriteRegion = function (startRow, numRows, startColumn, numColumns) { - this.setOutputMatrixWriteRegionDriver(startColumn, startRow, numColumns, numRows); - }; - GPGPUContext.prototype.setOutputPackedMatrixWriteRegion = function (startRow, numRows, startColumn, numColumns) { - throw new Error('setOutputPackedMatrixWriteRegion not implemented.'); - }; - GPGPUContext.prototype.debugValidate = function () { - if (this.program != null) { - webgl_util.validateProgram(this.gl, this.program); - } - webgl_util.validateFramebuffer(this.gl); - }; - GPGPUContext.prototype.executeProgram = function (attribLocations) { - this.throwIfDisposed(); - this.throwIfNoProgram(); - var gl = this.gl; - gpgpu_util.bindVertexProgramAttributeStreams(gl, this.program, this.vertexBuffer, attribLocations); - if (this.autoDebugValidate) { - this.debugValidate(); - } - webgl_util.callAndCheck(gl, function () { return gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0); }); - }; - GPGPUContext.prototype.blockUntilAllProgramsCompleted = function () { - var _this = this; - this.throwIfDisposed(); - webgl_util.callAndCheck(this.gl, function () { return _this.gl.finish(); }); - }; - GPGPUContext.prototype.getQueryTimerExtension = function () { - if (this.disjointQueryTimerExtension == null) { - this.disjointQueryTimerExtension = - webgl_util.getExtensionOrThrow(this.gl, environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2 ? - 'EXT_disjoint_timer_query_webgl2' : - 'EXT_disjoint_timer_query'); - } - return this.disjointQueryTimerExtension; - }; - GPGPUContext.prototype.getQueryTimerExtensionWebGL2 = function () { - return this.getQueryTimerExtension(); - }; - GPGPUContext.prototype.getQueryTimerExtensionWebGL1 = function () { - return this.getQueryTimerExtension(); - }; - GPGPUContext.prototype.runQuery = function (queryFn) { - var query = this.beginQuery(); - queryFn(); - this.endQuery(); - return this.pollQueryTime(query); - }; - GPGPUContext.prototype.beginQuery = function () { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2) { - var gl2 = this.gl; - var ext = this.getQueryTimerExtensionWebGL2(); - var query = gl2.createQuery(); - gl2.beginQuery(ext.TIME_ELAPSED_EXT, query); - return query; - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - var query = ext.createQueryEXT(); - ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, query); - return query; - } - }; - GPGPUContext.prototype.endQuery = function () { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2) { - var gl2 = this.gl; - var ext = this.getQueryTimerExtensionWebGL2(); - gl2.endQuery(ext.TIME_ELAPSED_EXT); - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - ext.endQueryEXT(ext.TIME_ELAPSED_EXT); - } - }; - GPGPUContext.prototype.isQueryAvailable = function (query, queryTimerVersion) { - if (queryTimerVersion === 0) { - return true; - } - if (queryTimerVersion === 2) { - var gl2 = this.gl; - var ext = this.getQueryTimerExtensionWebGL2(); - var available = gl2.getQueryParameter(query, gl2.QUERY_RESULT_AVAILABLE); - var disjoint = this.gl.getParameter(ext.GPU_DISJOINT_EXT); - return available && !disjoint; - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - var available = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_AVAILABLE_EXT); - var disjoint = this.gl.getParameter(ext.GPU_DISJOINT_EXT); - return available && !disjoint; - } - }; - GPGPUContext.prototype.pollQueryTime = function (query) { - var _this = this; - return new Promise(function (resolve, reject) { - var resolveWithWarning = function () { - console.warn('Disjoint query timer never available.'); - resolve(-1); - }; - var queryTimerVersion = environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION'); - util.repeatedTry(function () { return _this.isQueryAvailable(query, queryTimerVersion); }) - .then(function () { return resolve(_this.getQueryTime(query, queryTimerVersion)); }) - .catch(resolveWithWarning); - }); - }; - GPGPUContext.prototype.getQueryTime = function (query, queryTimerVersion) { - if (queryTimerVersion === 0) { - return null; - } - if (queryTimerVersion === 2) { - var gl2 = this.gl; - var timeElapsedNanos = gl2.getQueryParameter(query, gl2.QUERY_RESULT); - return timeElapsedNanos / 1000000; - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - var timeElapsedNanos = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_EXT); - return timeElapsedNanos / 1000000; - } - }; - GPGPUContext.prototype.downloadMatrixDriverSetup = function (texture) { - this.throwIfDisposed(); - webgl_util.bindColorTextureToFramebuffer(this.gl, texture, this.framebuffer); - if (this.autoDebugValidate) { - webgl_util.validateFramebuffer(this.gl); - } - }; - GPGPUContext.prototype.downloadMatrixDriverTeardown = function () { - if (this.outputTexture != null) { - webgl_util.bindColorTextureToFramebuffer(this.gl, this.outputTexture, this.framebuffer); - if (this.autoDebugValidate) { - webgl_util.validateFramebuffer(this.gl); - } - } - else { - webgl_util.unbindColorTextureFromFramebuffer(this.gl, this.framebuffer); - } - }; - GPGPUContext.prototype.downloadMatrixDriver = function (texture, downloadAndDecode) { - this.downloadMatrixDriverSetup(texture); - var result = downloadAndDecode(); - this.downloadMatrixDriverTeardown(); - return result; - }; - GPGPUContext.prototype.downloadMatrixDriverAsync = function (texture, downloadAndDecode) { - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.downloadMatrixDriverSetup(texture); - return [4, downloadAndDecode()]; - case 1: - result = _a.sent(); - this.downloadMatrixDriverTeardown(); - return [2, result]; - } - }); - }); - }; - GPGPUContext.prototype.setOutputMatrixTextureDriver = function (outputMatrixTextureMaybePacked, width, height) { - this.throwIfDisposed(); - var gl = this.gl; - webgl_util.bindColorTextureToFramebuffer(gl, outputMatrixTextureMaybePacked, this.framebuffer); - if (this.autoDebugValidate) { - webgl_util.validateFramebuffer(gl); - } - this.outputTexture = outputMatrixTextureMaybePacked; - webgl_util.callAndCheck(gl, function () { return gl.viewport(0, 0, width, height); }); - webgl_util.callAndCheck(gl, function () { return gl.scissor(0, 0, width, height); }); - }; - GPGPUContext.prototype.setOutputMatrixWriteRegionDriver = function (x, y, width, height) { - var _this = this; - this.throwIfDisposed(); - webgl_util.callAndCheck(this.gl, function () { return _this.gl.scissor(x, y, width, height); }); - }; - GPGPUContext.prototype.throwIfDisposed = function () { - if (this.disposed) { - throw new Error('Attempted to use disposed GPGPUContext.'); - } - }; - GPGPUContext.prototype.throwIfNoProgram = function () { - if (this.program == null) { - throw new Error('No GPU program is currently set.'); - } - }; - return GPGPUContext; -}()); -exports.GPGPUContext = GPGPUContext; - -},{"../../environment":34,"../../util":151,"./gpgpu_util":85,"./tex_util":99,"./webgl_util":104}],84:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var util = require("../../util"); -var shader_compiler = require("./shader_compiler"); -var ATTRIBUTE_NAMES = ['uv', 'clipSpacePos']; -var NAN_UNIFORM_NAME = 'NaN'; -function shouldUploadNaNUniform() { - return !environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED'); -} -function compileProgram(gpgpu, program, inputs, output) { - var userCode = program.userCode; - var inputInfos = inputs.map(function (input, i) { - var shapeInfo = { - logicalShape: input.tensor.shape, - texShape: input.texData.texShape - }; - return { name: program.variableNames[i], shapeInfo: shapeInfo }; - }); - var inShapeInfos = inputInfos.map(function (x) { return x.shapeInfo; }); - var outShapeInfo = { - logicalShape: output.tensor.shape, - texShape: output.texData.texShape - }; - var source = shader_compiler.makeShader(inputInfos, outShapeInfo, userCode, program.supportsBroadcasting === true); - var webGLProgram = gpgpu.createProgram(source); - var uniformLocations = {}; - for (var i = 0; i < program.variableNames.length; i++) { - var uniformName = program.variableNames[i]; - uniformLocations[uniformName] = - gpgpu.getUniformLocation(webGLProgram, uniformName); - } - var attributeLocations = {}; - ATTRIBUTE_NAMES.forEach(function (attribute) { - attributeLocations[attribute] = - gpgpu.getAttributeLocation(webGLProgram, attribute); - }); - if (shouldUploadNaNUniform()) { - var throwIfNaNUniformIsNotUsed = false; - uniformLocations[NAN_UNIFORM_NAME] = gpgpu.getUniformLocation(webGLProgram, NAN_UNIFORM_NAME, throwIfNaNUniformIsNotUsed); - } - return { - program: program, - source: source, - webGLProgram: webGLProgram, - uniformLocations: uniformLocations, - attributeLocations: attributeLocations, - gpgpu: gpgpu, - inShapeInfos: inShapeInfos, - outShapeInfo: outShapeInfo - }; -} -exports.compileProgram = compileProgram; -function validateBinaryAndProgram(shapeInfos, inputs) { - if (shapeInfos.length !== inputs.length) { - throw Error("Binary was compiled with " + shapeInfos.length + " inputs, but " + - ("was executed with " + inputs.length + " inputs")); - } - shapeInfos.forEach(function (s, i) { - var shapeA = s.logicalShape; - var texShapeA = s.texShape; - var shapeB = inputs[i].tensor.shape; - var texShapeB = inputs[i].texData.texShape; - if (!util.arraysEqual(shapeA, shapeB)) { - throw Error("Binary was compiled with different shapes than " + - ("the current args. Shapes " + shapeA + " and " + shapeB + " must match")); - } - if (!util.arraysEqual(texShapeA, texShapeB)) { - throw Error("Binary was compiled with different texture shapes than the" + - (" current args. Shape " + texShapeA + " and " + texShapeB + " must match")); - } - }); -} -function runProgram(binary, inputs, output, customSetup) { - validateBinaryAndProgram(binary.inShapeInfos, inputs); - validateBinaryAndProgram([binary.outShapeInfo], [output]); - var outTex = output.texData.texture; - var outTexShape = output.texData.texShape; - var gpgpu = binary.gpgpu; - gpgpu.setOutputMatrixTexture(outTex, outTexShape[0], outTexShape[1]); - gpgpu.setProgram(binary.webGLProgram); - inputs.forEach(function (input, i) { - var tex = input.texData.texture; - var variableName = binary.program.variableNames[i]; - var variableUniformLocation = binary.uniformLocations[variableName]; - gpgpu.setInputMatrixTexture(tex, variableUniformLocation, i); - }); - if (shouldUploadNaNUniform()) { - gpgpu.gl.uniform1f(binary.uniformLocations[NAN_UNIFORM_NAME], NaN); - } - if (customSetup != null) { - customSetup(gpgpu, binary.webGLProgram); - } - gpgpu.executeProgram(binary.attributeLocations); -} -exports.runProgram = runProgram; -function makeShaderKey(program, inputs, output) { - var keyInputs = ''; - inputs.concat(output).forEach(function (x) { - keyInputs += x.tensor.shape + "_" + x.texData.texShape; - }); - var keyUserCode = program.userCode; - var keyBroadcast = (program.supportsBroadcasting === true).toString(); - var key = program.constructor.name; - key += '_' + keyBroadcast + '_' + keyInputs + '_' + keyUserCode; - return key; -} -exports.makeShaderKey = makeShaderKey; - -},{"../../environment":34,"../../util":151,"./shader_compiler":97}],85:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var tex_util = require("./tex_util"); -var webgl_util = require("./webgl_util"); -function getWebGLContextAttributes() { - return { - alpha: false, - antialias: false, - premultipliedAlpha: false, - preserveDrawingBuffer: false, - depth: false, - stencil: false, - failIfMajorPerformanceCaveat: true - }; -} -exports.getWebGLContextAttributes = getWebGLContextAttributes; -function createWebGLContext(canvas) { - var attributes = getWebGLContextAttributes(); - var gl; - if (canvas != null) { - gl = webgl_util.createWebGLRenderingContextFromCanvas(canvas, attributes); - } - else { - gl = webgl_util.createWebGLRenderingContext(attributes); - } - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.DEPTH_TEST); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.STENCIL_TEST); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.BLEND); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.DITHER); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.POLYGON_OFFSET_FILL); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.SAMPLE_COVERAGE); }); - webgl_util.callAndCheck(gl, function () { return gl.enable(gl.SCISSOR_TEST); }); - webgl_util.callAndCheck(gl, function () { return gl.enable(gl.CULL_FACE); }); - webgl_util.callAndCheck(gl, function () { return gl.cullFace(gl.BACK); }); - return gl; -} -exports.createWebGLContext = createWebGLContext; -function createVertexShader(gl) { - var vertexShaderSource = "\n precision highp float;\n attribute vec3 clipSpacePos;\n attribute vec2 uv;\n varying vec2 resultUV;\n\n void main() {\n gl_Position = vec4(clipSpacePos, 1);\n resultUV = uv;\n }"; - return webgl_util.createVertexShader(gl, vertexShaderSource); -} -exports.createVertexShader = createVertexShader; -function createVertexBuffer(gl) { - var vertexArray = new Float32Array([-1, 1, 0, 0, 1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 1, -1, 0, 1, 0]); - return webgl_util.createStaticVertexBuffer(gl, vertexArray); -} -exports.createVertexBuffer = createVertexBuffer; -function createIndexBuffer(gl) { - var triangleVertexIndices = new Uint16Array([0, 1, 2, 2, 1, 3]); - return webgl_util.createStaticIndexBuffer(gl, triangleVertexIndices); -} -exports.createIndexBuffer = createIndexBuffer; -function getTextureInternalFormat(gl, numChannels) { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return gl.RGBA; - } - if (environment_1.ENV.get('WEBGL_VERSION') === 2) { - if (numChannels === 4) { - return gl.RGBA32F; - } - return gl.R32F; - } - return gl.RGBA; -} -function getTextureFormat(gl, numChannels) { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return gl.RGBA; - } - if (environment_1.ENV.get('WEBGL_VERSION') === 2) { - if (numChannels === 4) { - return gl.RGBA; - } - return gl.RED; - } - return gl.RGBA; -} -function getTextureType(gl) { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return gl.UNSIGNED_BYTE; - } - return gl.FLOAT; -} -function createAndConfigureTexture(gl, width, height, numChannels) { - webgl_util.validateTextureSize(gl, width, height); - var texture = webgl_util.createTexture(gl); - var tex2d = gl.TEXTURE_2D; - var internalFormat = getTextureInternalFormat(gl, numChannels); - var format = getTextureFormat(gl, numChannels); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(tex2d, texture); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MIN_FILTER, gl.NEAREST); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MAG_FILTER, gl.NEAREST); }); - webgl_util.callAndCheck(gl, function () { return gl.texImage2D(tex2d, 0, internalFormat, width, height, 0, format, getTextureType(gl), null); }); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); - return texture; -} -function createMatrixTexture(gl, rows, columns) { - var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - var numChannels = 1; - return createAndConfigureTexture(gl, width, height, numChannels); -} -exports.createMatrixTexture = createMatrixTexture; -function createColorMatrixTexture(gl, rows, columns) { - var _a = tex_util.getColorMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - var numChannels = 4; - return createAndConfigureTexture(gl, width, height, numChannels); -} -exports.createColorMatrixTexture = createColorMatrixTexture; -function createPackedMatrixTexture(gl, rows, columns) { - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - var numChannels = 4; - return createAndConfigureTexture(gl, width, height, numChannels); -} -exports.createPackedMatrixTexture = createPackedMatrixTexture; -function bindVertexProgramAttributeStreams(gl, program, vertexBuffer, attribLocations) { - var posOffset = 0; - var uvOffset = 3 * 4; - var stride = (3 * 4) + (2 * 4); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); }); - webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'clipSpacePos', vertexBuffer, 3, stride, posOffset, attribLocations); - webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'uv', vertexBuffer, 2, stride, uvOffset, attribLocations); -} -exports.bindVertexProgramAttributeStreams = bindVertexProgramAttributeStreams; -function uploadPixelDataToTexture(gl, texture, pixels) { - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); }); - webgl_util.callAndCheck(gl, function () { return gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels); }); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); -} -exports.uploadPixelDataToTexture = uploadPixelDataToTexture; -function uploadDataToTexture(gl, texture, width, height, data, numChannels) { - var textureFormat = getTextureFormat(gl, numChannels); - webgl_util.validateTextureSize(gl, width, height); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); }); - webgl_util.callAndCheck(gl, function () { return gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, textureFormat, getTextureType(gl), data); }); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); -} -function uploadMatrixToTexture(gl, texture, rows, columns, matrix, numChannels) { - var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var unpackedArray; - if (environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - var channelsPerTexture = numChannels === 1 ? webgl_util.getChannelsPerTexture() : numChannels; - if (channelsPerTexture === 1) { - unpackedArray = matrix; - } - else { - unpackedArray = - new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(matrix.length, channelsPerTexture)); - tex_util.encodeMatrixToUnpackedArray(matrix, unpackedArray, channelsPerTexture); - } - } - else { - unpackedArray = tex_util.encodeFloatArray(matrix); - } - uploadDataToTexture(gl, texture, w, h, unpackedArray, numChannels); -} -exports.uploadMatrixToTexture = uploadMatrixToTexture; -function uploadMatrixToPackedTexture(gl, texture, rows, columns, matrix) { - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var packedRGBA = new Float32Array(tex_util.getPackedRGBAArraySizeFromMatrixShape(rows, columns)); - tex_util.encodeMatrixToPackedRGBA(matrix, rows, columns, packedRGBA); - var numChannels = 4; - uploadDataToTexture(gl, texture, w, h, packedRGBA, numChannels); -} -exports.uploadMatrixToPackedTexture = uploadMatrixToPackedTexture; -function getDownloadTargetArrayBuffer(rows, columns, channelsPerTexture) { - var isFloatTexture = environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED'); - var downloadTarget; - if (isFloatTexture) { - downloadTarget = - new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(rows * columns, channelsPerTexture)); - } - else { - downloadTarget = new Uint8Array(rows * columns * channelsPerTexture); - } - return downloadTarget; -} -function decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel) { - var isFloatTexture = environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED'); - if (isFloatTexture) { - var matrix = new Float32Array(rows * columns); - tex_util.decodeMatrixFromUnpackedArray(downloadTarget, matrix, channelsPerPixel); - return matrix; - } - else { - return tex_util.decodeToFloatArray(downloadTarget); - } -} -function downloadMatrixFromOutputTextureAsync(gl, getBufferSubDataAsyncExtension, rows, columns) { - return __awaiter(this, void 0, void 0, function () { - var gl2, channelsPerPixel, downloadTarget, bufferSizeBytes, buffer; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - gl2 = gl; - channelsPerPixel = 4; - downloadTarget = getDownloadTargetArrayBuffer(rows, columns, channelsPerPixel); - bufferSizeBytes = downloadTarget instanceof Float32Array ? - downloadTarget.length * 4 : - downloadTarget; - buffer = gl.createBuffer(); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl2.PIXEL_PACK_BUFFER, buffer); }); - webgl_util.callAndCheck(gl, function () { return gl.bufferData(gl2.PIXEL_PACK_BUFFER, bufferSizeBytes, gl.STATIC_DRAW); }); - webgl_util.callAndCheck(gl, function () { - return gl2.readPixels(0, 0, columns, rows, gl.RGBA, getTextureType(gl), 0); - }); - return [4, getBufferSubDataAsyncExtension.getBufferSubDataAsync(gl2.PIXEL_PACK_BUFFER, 0, downloadTarget)]; - case 1: - _a.sent(); - return [2, decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel)]; - } - }); - }); -} -exports.downloadMatrixFromOutputTextureAsync = downloadMatrixFromOutputTextureAsync; -function downloadMatrixFromOutputTexture(gl, rows, columns) { - var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var channelsPerPixel = 4; - var downloadTarget = getDownloadTargetArrayBuffer(rows, columns, channelsPerPixel); - webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, gl.RGBA, getTextureType(gl), downloadTarget); }); - return decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel); -} -exports.downloadMatrixFromOutputTexture = downloadMatrixFromOutputTexture; -function downloadMatrixFromRGBAColorTexture(gl, rows, columns, channels) { - var size = rows * columns * 4; - var downloadTarget = new Uint8Array(size); - webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, columns, rows, gl.RGBA, gl.UNSIGNED_BYTE, downloadTarget); }); - var packedRGBA = new Float32Array(size); - for (var i = 0; i < downloadTarget.length; i++) { - packedRGBA[i] = downloadTarget[i]; - } - var matrix = new Float32Array(rows * columns * channels); - tex_util.decodeMatrixFromUnpackedColorRGBAArray(packedRGBA, matrix, channels); - return matrix; -} -exports.downloadMatrixFromRGBAColorTexture = downloadMatrixFromRGBAColorTexture; -function downloadMatrixFromPackedOutputTexture(gl, rows, columns) { - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var packedRGBA = new Float32Array(tex_util.getPackedRGBAArraySizeFromMatrixShape(rows, columns)); - webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, gl.RGBA, getTextureType(gl), packedRGBA); }); - var matrix = new Float32Array(rows * columns); - return tex_util.decodeMatrixFromPackedRGBA(packedRGBA, rows, columns, matrix); -} -exports.downloadMatrixFromPackedOutputTexture = downloadMatrixFromPackedOutputTexture; - -},{"../../environment":34,"./tex_util":99,"./webgl_util":104}],86:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var WhereProgram = (function () { - function WhereProgram(cRank, shape, rank) { - this.variableNames = ['c', 'a', 'b']; - this.outputShape = shape; - var cCoords; - var abCoords; - if (rank > 4) { - throw Error("Where for rank " + rank + " is not yet supported"); - } - if (rank === 1) { - abCoords = "resRC"; - cCoords = "resRC"; - } - else { - var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var cCoordVars = []; - var abCoordVars = []; - for (var i = 0; i < shape.length; i++) { - abCoordVars.push("" + currentCoords[i]); - if (i < cRank) { - cCoordVars.push("" + currentCoords[i]); - } - } - cCoords = cCoordVars.join(); - abCoords = abCoordVars.join(); - } - var dtype = shader_compiler_1.getCoordsDataType(rank); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n float cVal = getC(" + cCoords + ");\n if (cVal >= 1.0) {\n setOutput(getA(" + abCoords + "));\n } else {\n setOutput(getB(" + abCoords + "));\n }\n }\n "; - } - return WhereProgram; -}()); -exports.WhereProgram = WhereProgram; - -},{"./shader_compiler":97}],87:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var LRNProgram = (function () { - function LRNProgram(xShape, radius, bias, alpha, beta, normRegion) { - this.variableNames = ['x']; - this.outputShape = []; - var rad = radius; - var maxW = xShape[1] - 1; - var maxH = xShape[2] - 1; - var maxD = xShape[3] - 1; - this.outputShape = xShape; - var powOperator; - var basis = "float(" + bias + ") + float(" + alpha + ") * sum"; - if (beta === 0.5) { - powOperator = "inversesqrt(" + basis + ")"; - } - else if (beta === 1.0) { - powOperator = "1.0/(" + basis + ")"; - } - else { - powOperator = "exp(log(" + basis + ") * float(-" + beta + "));"; - } - if (normRegion === 'withinChannel') { - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int u = -" + rad + "; u <= " + rad + "; u++) {\n for (int v = -" + rad + "; v <= " + rad + "; v++) {\n int idx = r + u;\n int idy = c + v;\n if (idx >= 0 && idx <= " + maxW + " && idy >= 0 && idy <= " + maxH + ") {\n float z = getX(b, idx, idy, d);\n sum += z * z;\n }\n }\n }\n float val = x * " + powOperator + ";\n setOutput(val);\n }\n "; - } - else { - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int j = -" + rad + "; j <= " + rad + "; j++) {\n int idx = d + j;\n if (idx >= 0 && idx <= " + maxD + ") {\n float z = getX(b, r, c, idx);\n sum += z * z;\n }\n }\n float val = x * " + powOperator + ";\n setOutput(val);\n }\n "; - } - } - return LRNProgram; -}()); -exports.LRNProgram = LRNProgram; - -},{}],88:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MaxPool2DBackpropProgram = (function () { - function MaxPool2DBackpropProgram(convInfo) { - this.variableNames = ['dy', 'maxPos']; - this.outputShape = convInfo.inShape; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var lastIndex = filterHeight * filterWidth - 1; - this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n int maxPosValue = " + lastIndex + " - int(getMaxPos(b, idyR, idyC, d));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue = wR * " + filterWidth + " + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n setOutput(dotProd);\n }\n "; - } - return MaxPool2DBackpropProgram; -}()); -exports.MaxPool2DBackpropProgram = MaxPool2DBackpropProgram; - -},{}],89:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MatMulProgram = (function () { - function MatMulProgram(aShape, bShape, transposeA, transposeB) { - if (transposeA === void 0) { transposeA = false; } - if (transposeB === void 0) { transposeB = false; } - this.variableNames = ['matrixA', 'matrixB']; - var outerShapeA = transposeA ? aShape[1] : aShape[0]; - var outerShapeB = transposeB ? bShape[0] : bShape[1]; - var sharedDim = transposeA ? aShape[0] : aShape[1]; - this.outputShape = [outerShapeA, outerShapeB]; - var aSnippetFromOffset = function (vec4Offset, indexVar) { - return transposeA ? indexVar + " + " + vec4Offset + ", aRow" : - "aRow, " + indexVar + " + " + vec4Offset; - }; - var bSnippetFromOffset = function (vec4Offset, indexVar) { - return transposeB ? "bCol, " + indexVar + " + " + vec4Offset : - indexVar + " + " + vec4Offset + ", bCol"; - }; - var sharedDimNearestVec4 = Math.floor(sharedDim / 4) * 4; - var sharedDimVec4Remainder = sharedDim % 4; - this.userCode = " float dotARowBCol(int aRow, int bCol) {\n float result = 0.0;\n for (int i = 0; i < " + sharedDimNearestVec4 + "; i += 4) {\n vec4 a = vec4(\n getMatrixA(" + aSnippetFromOffset(0, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(1, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(2, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(3, 'i') + ")\n );\n vec4 b = vec4(\n getMatrixB(" + bSnippetFromOffset(0, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(1, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(2, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(3, 'i') + ")\n );\n\n result += dot(a, b);\n }\n\n if (" + (sharedDimVec4Remainder === 1) + ") {\n result += getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + ") *\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + ");\n } else if (" + (sharedDimVec4Remainder === 2) + ") {\n vec2 a = vec2(\n getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(1, sharedDimNearestVec4) + ")\n );\n vec2 b = vec2(\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(1, sharedDimNearestVec4) + ")\n );\n result += dot(a, b);\n } else if (" + (sharedDimVec4Remainder === 3) + ") {\n vec3 a = vec3(\n getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(1, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(2, sharedDimNearestVec4) + ")\n );\n vec3 b = vec3(\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(1, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(2, sharedDimNearestVec4) + ")\n );\n result += dot(a, b);\n }\n\n return result;\n }\n\n void main() {\n ivec2 resRC = getOutputCoords();\n setOutput(dotARowBCol(resRC.x, resRC.y));\n }\n "; - } - return MatMulProgram; -}()); -exports.MatMulProgram = MatMulProgram; - -},{}],90:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MultinomialProgram = (function () { - function MultinomialProgram(batchSize, numOutcomes, numSamples) { - this.variableNames = ['probs']; - this.outputShape = [batchSize, numSamples]; - this.userCode = "\n uniform float seed;\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n\n float r = random(seed);\n float cdf = 0.0;\n\n for (int i = 0; i < " + (numOutcomes - 1) + "; i++) {\n cdf += getProbs(batch, i);\n\n if (r < cdf) {\n setOutput(float(i));\n return;\n }\n }\n\n // If no other event happened, last event happened.\n setOutput(float(" + (numOutcomes - 1) + "));\n }\n "; - } - MultinomialProgram.prototype.getCustomSetupFunc = function (seed) { - var _this = this; - return function (gpgpu, webGLProgram) { - if (_this.seedLoc == null) { - _this.seedLoc = gpgpu.getUniformLocation(webGLProgram, 'seed'); - } - gpgpu.gl.uniform1f(_this.seedLoc, seed); - }; - }; - return MultinomialProgram; -}()); -exports.MultinomialProgram = MultinomialProgram; - -},{}],91:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var OneHotProgram = (function () { - function OneHotProgram(numIndices, depth, onValue, offValue) { - this.variableNames = ['indices']; - this.outputShape = [numIndices, depth]; - this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int index = round(getIndices(coords.x));\n setOutput(mix(float(" + offValue + "), float(" + onValue + "),\n float(index == coords.y)));\n }\n "; - } - return OneHotProgram; -}()); -exports.OneHotProgram = OneHotProgram; - -},{}],92:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Pad1DProgram = (function () { - function Pad1DProgram(xShape, paddings, constantValue) { - this.variableNames = ['x']; - var leftPadding = paddings[0]; - var rightPadding = paddings[1]; - this.outputShape = [leftPadding + xShape[0] + rightPadding]; - this.rank = 1; - this.userCode = "\n void main() {\n int resRC = getOutputCoords();\n if (resRC < " + leftPadding + " || resRC >= " + leftPadding + " + " + xShape[0] + ") {\n setOutput(float(" + constantValue + "));\n } else {\n setOutput(getX(resRC - " + leftPadding + "));\n }\n }\n "; - } - return Pad1DProgram; -}()); -exports.Pad1DProgram = Pad1DProgram; -var Pad2DProgram = (function () { - function Pad2DProgram(xShape, paddings, constantValue) { - this.variableNames = ['x']; - var topPadding = paddings[0][0]; - var bottomPadding = paddings[0][1]; - var leftPadding = paddings[1][0]; - var rightPadding = paddings[1][1]; - this.outputShape = [ - topPadding + xShape[0] + bottomPadding, - leftPadding + xShape[1] + rightPadding - ]; - this.rank = 2; - var sourceCoords = "resRC.x - " + topPadding + ", resRC.y - " + leftPadding; - this.userCode = "\n void main() {\n ivec2 resRC = getOutputCoords();\n int topShape = " + topPadding + " + " + xShape[0] + ";\n int leftShape = " + leftPadding + " + " + xShape[1] + ";\n if (resRC.x < " + topPadding + " || resRC.x >= topShape ||\n resRC.y < " + leftPadding + " || resRC.y >= leftShape) {\n setOutput(float(" + constantValue + "));\n } else {\n setOutput(getX(" + sourceCoords + "));\n }\n }\n "; - } - return Pad2DProgram; -}()); -exports.Pad2DProgram = Pad2DProgram; - -},{}],93:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Pool2DProgram = (function () { - function Pool2DProgram(convInfo, poolType, computePositions) { - this.variableNames = ['x']; - if (poolType === 'avg' && computePositions) { - throw new Error('Cannot compute positions for average pool.'); - } - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - this.outputShape = convInfo.outShape; - var isAvgPool = poolType === 'avg'; - var initializationValue = '0.0'; - if (!isAvgPool) { - if (poolType === 'min') { - initializationValue = '1.0 / 0.0'; - } - else { - initializationValue = '-1.0 / 0.0'; - } - } - if (computePositions) { - var compareOp_1 = poolType === 'min' ? '<=' : '>='; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n float avgValue = 0.0;\n\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n float value = getX(batch, xR, xC, d);\n\n if (isNaN(value)) {\n setOutput(value);\n return;\n }\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value " + compareOp_1 + " currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = wR * " + filterWidth + " + wC;\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n "; - return; - } - var compareOp = poolType === 'min' ? 'min' : 'max'; - var returnValue = poolType + "(" + poolType + "(" + poolType + "(" + - 'minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])'; - if (poolType === 'avg') { - returnValue = "avgValue / " + filterHeight * filterWidth + ".0"; - } - var filterWidthNearestVec4 = Math.floor(filterWidth / 4) * 4; - var filterWidthVec4Remainder = filterWidth % 4; - var updateSnippet = "\n if (hasNaN(values)) {\n setOutput(getNaN(values));\n return;\n }\n if (" + isAvgPool + ") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = " + compareOp + "(values, minMaxValue);\n }\n "; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n const float initializationValue = " + initializationValue + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int xR, int xC, int d) {\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n return initializationValue;\n }\n return getX(batch, xR, xC, d);\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n vec4 minMaxValue = vec4(" + initializationValue + ");\n float avgValue = 0.0;\n\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidthNearestVec4 + "; wC += 4) {\n int xC = xCCorner + wC;\n\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n getValue(batch, xR, xC + 2, d),\n getValue(batch, xR, xC + 3, d)\n );\n\n " + updateSnippet + "\n }\n\n int xC = xCCorner + " + filterWidthNearestVec4 + ";\n if (" + (filterWidthVec4Remainder === 1) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n initializationValue,\n initializationValue,\n initializationValue\n );\n " + updateSnippet + "\n } else if (" + (filterWidthVec4Remainder === 2) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n initializationValue,\n initializationValue\n );\n\n " + updateSnippet + "\n } else if (" + (filterWidthVec4Remainder === 3) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n getValue(batch, xR, xC + 2, d),\n initializationValue\n );\n\n " + updateSnippet + "\n }\n }\n setOutput(" + returnValue + ");\n }\n "; - } - return Pool2DProgram; -}()); -exports.Pool2DProgram = Pool2DProgram; - -},{}],94:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ReduceProgram = (function () { - function ReduceProgram(reduceInfo, reduceType) { - this.variableNames = ['x']; - var windowSize = reduceInfo.windowSize; - var batchSize = reduceInfo.batchSize; - var inSize = reduceInfo.inSize; - var outSize = Math.ceil(inSize / windowSize); - this.outputShape = [batchSize, outSize]; - var isReduceSum = reduceType === 'sum'; - var initializationValue = '0.0'; - if (!isReduceSum) { - if (reduceType === 'min') { - initializationValue = '1.0 / 0.0'; - } - else { - initializationValue = '-1.0 / 0.0'; - } - } - var compareOp = reduceType === 'min' ? 'min' : 'max'; - var returnValue = reduceType + "(" + reduceType + "(" + reduceType + "(" + - 'minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])'; - if (reduceType === 'sum') { - returnValue = "sumValue"; - } - var windowSizeNearestVec4 = Math.floor(windowSize / 4) * 4; - var windowSizeVec4Remainder = windowSize % 4; - var updateSnippet = "\n if (" + isReduceSum + ") {\n sumValue += dot(values, ones);\n } else {\n if (hasNaN(values)) {\n setOutput(getNaN(values));\n return;\n }\n minMaxValue = " + compareOp + "(values, minMaxValue);\n }\n "; - var checkOutOfBounds = ''; - if (inSize % windowSize > 0) { - checkOutOfBounds = "\n if (inIdx < 0 || inIdx >= " + inSize + ") {\n return initializationValue;\n }\n "; - } - this.userCode = "\n const float initializationValue = " + initializationValue + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int inIdx) {\n " + checkOutOfBounds + "\n return getX(batch, inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * " + windowSize + ";\n\n vec4 minMaxValue = vec4(" + initializationValue + ");\n float sumValue = 0.0;\n\n for (int i = 0; i < " + windowSizeNearestVec4 + "; i += 4) {\n int inIdx = inOffset + i;\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n " + updateSnippet + "\n }\n\n int inIdx = inOffset + " + windowSizeNearestVec4 + ";\n if (" + (windowSizeVec4Remainder === 1) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n " + updateSnippet + "\n } else if (" + (windowSizeVec4Remainder === 2) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n " + updateSnippet + "\n } else if (" + (windowSizeVec4Remainder === 3) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n " + updateSnippet + "\n }\n setOutput(" + returnValue + ");\n }\n "; - } - return ReduceProgram; -}()); -exports.ReduceProgram = ReduceProgram; - -},{}],95:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ResizeBilinearProgram = (function () { - function ResizeBilinearProgram(inputShape, newHeight, newWidth, alignCorners) { - this.variableNames = ['A']; - this.outputShape = []; - var batch = inputShape[0], oldHeight = inputShape[1], oldWidth = inputShape[2], depth = inputShape[3]; - this.outputShape = [batch, newHeight, newWidth, depth]; - var effectiveInSize = alignCorners ? [oldHeight - 1, oldWidth - 1] : [oldHeight, oldWidth]; - var effectiveOutSize = alignCorners ? [newHeight - 1, newWidth - 1] : [newHeight, newWidth]; - this.userCode = "\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n " + effectiveInSize[0] / effectiveOutSize[0] + ",\n " + effectiveInSize[1] / effectiveOutSize[1] + ");\n const vec2 inputShapeRC = vec2(" + oldHeight + ".0, " + oldWidth + ".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);\n ivec2 sourceCeilRC = ivec2(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);\n float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);\n float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);\n float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);\n\n vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);\n\n float top = topLeft + (topRight - topLeft) * fracRC.y;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;\n float newValue = top + (bottom - top) * fracRC.x;\n\n setOutput(newValue);\n }\n "; - } - return ResizeBilinearProgram; -}()); -exports.ResizeBilinearProgram = ResizeBilinearProgram; - -},{}],96:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ReverseProgram = (function () { - function ReverseProgram(xShape, axis) { - this.variableNames = ['x']; - this.outputShape = xShape; - var getRevVar = function (i) { - if (axis.indexOf(i) !== -1 && xShape[i] !== 1) { - return xShape[i] + " - coords[" + i + "] - 1"; - } - return "coords[" + i + "]"; - }; - var b = getRevVar(0); - var r = getRevVar(1); - var c = getRevVar(2); - var d = getRevVar(3); - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n float val = getX(" + b + ", " + r + ", " + c + ", " + d + ");\n setOutput(val);\n }\n "; - } - return ReverseProgram; -}()); -exports.ReverseProgram = ReverseProgram; - -},{}],97:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var util = require("../../util"); -var broadcast_util = require("../../ops/broadcast_util"); -var tex_util = require("./tex_util"); -function makeShader(inputsInfo, outputShape, userCode, broadcast) { - var sampleSnippet = getSampleSnippet(); - var setOutputSnippet = getSetOutputSnippet(); - var inputPrefixSnippet = inputsInfo.map(function (x) { return "uniform sampler2D " + x.name + ";"; }).join('\n'); - var inputSamplingSnippet = inputsInfo.map(function (x) { return getInputSamplingSnippet(x, outputShape, broadcast); }) - .join('\n'); - var outTexShape = outputShape.texShape; - var outputSamplingSnippet = getOutputSamplingSnippet(outputShape.logicalShape, outTexShape); - var source = [ - SHADER_PREFIX, sampleSnippet, setOutputSnippet, inputPrefixSnippet, - outputSamplingSnippet, inputSamplingSnippet, userCode - ].join('\n'); - return source; -} -exports.makeShader = makeShader; -function getSampleSnippet() { - return environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED') ? - FLOAT_TEXTURE_SAMPLE_SNIPPET : - UNSIGNED_BYTE_TEXTURE_SAMPLE_SNIPPET; -} -function getSetOutputSnippet() { - return environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED') ? - FLOAT_TEXTURE_SETOUTPUT_SNIPPET : - UNSIGNED_BYTE_TEXTURE_SETOUTPUT_SNIPPET; -} -function getSamplerFromInInfo(inInfo) { - var shape = inInfo.shapeInfo.logicalShape; - switch (shape.length) { - case 0: - return getSamplerScalar(inInfo); - case 1: - return getSampler1D(inInfo); - case 2: - return getSampler2D(inInfo); - case 3: - return getSampler3D(inInfo); - case 4: - return getSampler4D(inInfo); - default: - throw new Error(shape.length + "-D input sampling" + - " is not yet supported"); - } -} -function getInputSamplingSnippet(inInfo, outShapeInfo, broadcast) { - var res = getSamplerFlat(inInfo); - res += getSamplerFromInInfo(inInfo); - if (broadcast || - util.arraysEqual(inInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape)) { - res += getSamplerAtOutputCoords(inInfo, outShapeInfo, broadcast); - } - return res; -} -function getOutputSamplingSnippet(outShape, outTexShape) { - switch (outShape.length) { - case 0: - return getOutputScalarCoords(); - case 1: - return getOutput1DCoords(outShape, outTexShape); - case 2: - return getOutput2DCoords(outShape, outTexShape); - case 3: - return getOutput3DCoords(outShape, outTexShape); - case 4: - return getOutput4DCoords(outShape, outTexShape); - default: - throw new Error(outShape.length + "-D output sampling is not yet supported"); - } -} -var SAMPLE_1D_SNIPPET = "\nvec2 UVfrom1D(int texNumR, int texNumC, int index) {\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var SAMPLE_2D_SNIPPET = "\nvec2 UVfrom2D(int texNumR, int texNumC, int numC, int row, int col) {\n int index = row * numC + col;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var SAMPLE_3D_SNIPPET = "\nvec2 UVfrom3D(int texNumR, int texNumC, int stride0,\n int stride1, int row, int col, int depth) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var SAMPLE_4D_SNIPPET = "\nvec2 UVfrom4D(int texNumR, int texNumC, int stride0,\n int stride1, int stride2, int row, int col, int depth,\n int depth2) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth * stride2 + depth2;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var UNSIGNED_BYTE_TEXTURE_SAMPLE_SNIPPET = "\n uniform float NaN;\n\n const vec4 floatDeltas = vec4(\n 1.0,\n 1.0 / 255.0,\n 1.0 / (255.0 * 255.0),\n 1.0 / (255.0 * 255.0 * 255.0)\n );\n const float minValue = " + tex_util.FLOAT_MIN + ".0;\n const float maxValue = " + tex_util.FLOAT_MAX + ".0;\n const float range = (maxValue - minValue) / 255.0;\n const vec2 dotRange = vec2(1.0, range);\n\n float sample(sampler2D texture, vec2 uv) {\n vec4 sampleValue = texture2D(texture, uv);\n if (all(equal(sampleValue, vec4(" + tex_util.BYTE_NAN_VALUE + ")))) {\n return NaN;\n }\n\n vec4 encValue = floor(sampleValue * 255.0 + 0.5);\n float decodedValue = dot(encValue, floatDeltas);\n return dot(vec2(minValue, decodedValue), dotRange);\n }\n"; -var UNSIGNED_BYTE_TEXTURE_SETOUTPUT_SNIPPET = "\n const vec4 floatPowers = vec4(\n 1.0,\n 255.0,\n 255.0 * 255.0,\n 255.0 * 255.0 * 255.0\n );\n const vec2 recipRange = vec2(1.0/range);\n const vec2 recipRange255 = vec2(1.0/(maxValue - minValue));\n\n void setOutput(float decodedValue) {\n if (isNaN(decodedValue)) {\n gl_FragColor = vec4(" + tex_util.BYTE_NAN_VALUE + ");\n return;\n }\n\n float a = dot(vec2(decodedValue, -minValue), recipRange);\n float b = fract(a) * 255.0;\n float c = fract(b) * 255.0;\n float d = fract(c) * 255.0;\n gl_FragColor = floor(vec4(a, b, c, d)) / 255.0;\n\n // TODO(dsmilkov): Version above gets better accuracy but probably slower\n // than the version below. Benchmark to determine if the accuracy is worth\n // the cost.\n\n // float normValue = dot(vec2(decodedValue, -minValue), recipRange255);\n // vec4 f = normValue * floatPowers;\n // gl_FragColor = floor(fract(f) * 255.0) / 255.0;\n }\n"; -var FLOAT_TEXTURE_SAMPLE_SNIPPET = "\n float sample(sampler2D texture, vec2 uv) {\n return texture2D(texture, uv).r;\n }\n"; -var FLOAT_TEXTURE_SETOUTPUT_SNIPPET = "\n void setOutput(float val) {\n gl_FragColor = vec4(val, 0, 0, 0);\n }\n"; -var SHADER_PREFIX = "\n precision highp float;\n precision highp int;\n varying vec2 resultUV;\n const vec2 halfCR = vec2(0.5, 0.5);\n\n bool isNaN(float val) {\n float v1 = val * val;\n float v2 = val * val;\n return v1 == v2 ? false : true;\n }\n\n bool hasNaN(vec4 values) {\n vec4 v1 = values * values;\n vec4 v2 = values * values;\n return any(notEqual(v1, v2));\n }\n\n float getNaN(vec4 values) {\n return dot(vec4(1), values);\n }\n\n int round(float value) {\n return int(floor(value + 0.5));\n }\n\n int imod(int x, int y) {\n return x - y * (x / y);\n }\n\n const vec2 randomConst = vec2(\n 23.14069263277926, // e^pi (Gelfond's constant)\n 2.665144142690225 // 2^sqrt(2) (Gelfond\u2013Schneider constant)\n );\n\n float random(float seed) {\n return fract(cos(dot(resultUV * seed, randomConst)) * 12345.6789);\n }\n\n " + SAMPLE_1D_SNIPPET + "\n " + SAMPLE_2D_SNIPPET + "\n " + SAMPLE_3D_SNIPPET + "\n " + SAMPLE_4D_SNIPPET + "\n"; -function getOutputScalarCoords() { - return "\n int getOutputCoords() {\n return 0;\n }\n "; -} -function getOutput1DCoords(shape, texShape) { - if (texShape[0] === 1) { - return "\n int getOutputCoords() {\n return int(resultUV.x * " + texShape[1] + ".0);\n }\n "; - } - if (texShape[1] === 1) { - return "\n int getOutputCoords() {\n return int(resultUV.y * " + texShape[0] + ".0);\n }\n "; - } - return "\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n return resTexRC.x * " + texShape[1] + " + resTexRC.y;\n }\n "; -} -function getOutput3DCoords(shape, texShape) { - var stride0 = shape[1] * shape[2]; - var stride1 = shape[2]; - return "\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n int r = index / " + stride0 + ";\n index -= r * " + stride0 + ";\n int c = index / " + stride1 + ";\n int d = index - c * " + stride1 + ";\n return ivec3(r, c, d);\n }\n "; -} -function getOutput4DCoords(shape, texShape) { - var stride2 = shape[3]; - var stride1 = shape[2] * stride2; - var stride0 = shape[1] * stride1; - return "\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n\n int r = index / " + stride0 + ";\n index -= r * " + stride0 + ";\n\n int c = index / " + stride1 + ";\n index -= c * " + stride1 + ";\n\n int d = index / " + stride2 + ";\n int d2 = index - d * " + stride2 + ";\n\n return ivec4(r, c, d, d2);\n }\n "; -} -function getOutput2DCoords(shape, texShape) { - if (util.arraysEqual(shape, texShape)) { - return "\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2(" + texShape[0] + ", " + texShape[1] + "));\n }\n "; - } - if (shape[1] === 1) { - return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n return ivec2(index, 0);\n }\n "; - } - if (shape[0] === 1) { - return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n return ivec2(0, index);\n }\n "; - } - return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n int r = index / " + shape[1] + ";\n int c = index - r * " + shape[1] + ";\n return ivec2(r, c);\n }\n "; -} -function getSamplerScalar(inputInfo) { - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - return "\n float " + funcName + "() {\n return sample(" + texName + ", halfCR);\n }\n "; -} -function getSampler1D(inputInfo) { - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - return "\n float " + funcName + "(int index) {\n return " + funcName + "Flat(index);\n }\n "; -} -function getSampler2D(inputInfo) { - var shape = inputInfo.shapeInfo.logicalShape; - var texShape = inputInfo.shapeInfo.texShape; - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - var texNumR = texShape[0]; - var texNumC = texShape[1]; - if (util.arraysEqual(shape, texShape)) { - return "\n float " + funcName + "(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims; - var squeezedShape = newShape; - if (squeezedShape.length < shape.length) { - var newInputInfo = squeezeInputInfo(inputInfo, squeezedShape); - var params = ['row', 'col']; - return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n "; - } - if (texNumC === 1) { - return "\n float " + funcName + "(int row, int col) {\n int index = row * " + shape[1] + " + col;\n vec2 uv = vec2(0.5, (float(index) + 0.5) / " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (texNumR === 1) { - return "\n float " + funcName + "(int row, int col) {\n int index = row * " + shape[1] + " + col;\n vec2 uv = vec2((float(index) + 0.5) / " + texNumC + ".0, 0.5);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int row, int col) {\n vec2 uv = UVfrom2D(" + texNumR + ", " + texNumC + ", " + shape[1] + ", row, col);\n return sample(" + texName + ", uv);\n }\n"; -} -function getSampler3D(inputInfo) { - var texShape = inputInfo.shapeInfo.texShape; - var shape = inputInfo.shapeInfo.logicalShape; - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - var texNumR = texShape[0]; - var texNumC = texShape[1]; - var stride0 = shape[1] * shape[2]; - var stride1 = shape[2]; - var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims; - var squeezedShape = newShape; - if (squeezedShape.length < shape.length) { - var newInputInfo = squeezeInputInfo(inputInfo, squeezedShape); - var params = ['row', 'col', 'depth']; - return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col, int depth) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n "; - } - if (texNumC === stride0) { - return "\n float " + funcName + "(int row, int col, int depth) {\n int texR = row;\n int texC = col * " + stride1 + " + depth;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (texNumC === stride1) { - return "\n float " + funcName + "(int row, int col, int depth) {\n int texR = row * " + shape[1] + " + col;\n int texC = depth;\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int row, int col, int depth) {\n vec2 uv = UVfrom3D(\n " + texNumR + ", " + texNumC + ", " + stride0 + ", " + stride1 + ", row, col, depth);\n return sample(" + texName + ", uv);\n }\n "; -} -function getSampler4D(inputInfo) { - var shape = inputInfo.shapeInfo.logicalShape; - var texShape = inputInfo.shapeInfo.texShape; - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - var texNumR = texShape[0]; - var texNumC = texShape[1]; - var stride2 = shape[3]; - var stride1 = shape[2] * stride2; - var stride0 = shape[1] * stride1; - var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims; - if (newShape.length < shape.length) { - var newInputInfo = squeezeInputInfo(inputInfo, newShape); - var params = ['row', 'col', 'depth', 'depth2']; - return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n "; - } - if (texNumC === stride0) { - return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n int texR = row;\n int texC = col * " + stride1 + " + depth * " + stride2 + " + depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (texNumC === stride2) { - return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n int texR = row * " + shape[1] * shape[2] + " + col * " + shape[2] + " + depth;\n int texC = depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n vec2 uv = UVfrom4D(" + texNumR + ", " + texNumC + ", " + stride0 + ", " + stride1 + ",\n " + stride2 + ", row, col, depth, depth2);\n return sample(" + texName + ", uv);\n }\n "; -} -function getSamplerFlat(inputInfo) { - var texName = inputInfo.name; - var texShape = inputInfo.shapeInfo.texShape; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1) + 'Flat'; - var tNumR = texShape[0]; - var tNumC = texShape[1]; - if (tNumC === 1 && tNumR === 1) { - return "\n float " + funcName + "(int index) {\n return sample(" + texName + ", halfCR);\n }\n "; - } - if (tNumC === 1) { - return "\n float " + funcName + "(int index) {\n vec2 uv = vec2(0.5, (float(index) + 0.5) / " + tNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (tNumR === 1) { - return "\n float " + funcName + "(int index) {\n vec2 uv = vec2((float(index) + 0.5) / " + tNumC + ".0, 0.5);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int index) {\n vec2 uv = UVfrom1D(" + tNumR + ", " + tNumC + ", index);\n return sample(" + texName + ", uv);\n }\n "; -} -function getBroadcastOutputCoordsSampler(inputInfo, outShapeInfo, texFuncSnippet, funcName) { - var inRank = inputInfo.shapeInfo.logicalShape.length; - var outRank = outShapeInfo.logicalShape.length; - var type = 'int'; - if (outRank === 2) { - type = 'ivec2'; - } - else if (outRank === 3) { - type = 'ivec3'; - } - else if (outRank === 4) { - type = 'ivec4'; - } - var broadcastDims = broadcast_util.getBroadcastDims(inputInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape); - var rankDiff = outRank - inRank; - var coordsSnippet; - if (inRank === 0) { - coordsSnippet = ''; - } - else if (outRank < 2 && broadcastDims.length >= 1) { - coordsSnippet = 'coords = 0;'; - } - else { - coordsSnippet = - broadcastDims.map(function (d) { return "coords[" + (d + rankDiff) + "] = 0;"; }).join('\n'); - } - var unpackedCoordsSnippet = ''; - if (outRank < 2 && inRank > 0) { - unpackedCoordsSnippet = 'coords'; - } - else { - unpackedCoordsSnippet = inputInfo.shapeInfo.logicalShape - .map(function (s, i) { return "coords[" + (i + rankDiff) + "]"; }) - .join(', '); - } - return "\n float " + funcName + "() {\n " + type + " coords = getOutputCoords();\n " + coordsSnippet + "\n return get" + texFuncSnippet + "(" + unpackedCoordsSnippet + ");\n }\n "; -} -function getSamplerAtOutputCoords(inputInfo, outShapeInfo, supportsBroadcasting) { - var inTexShape = inputInfo.shapeInfo.texShape; - var texName = inputInfo.name; - var texFuncSnippet = texName.charAt(0).toUpperCase() + texName.slice(1); - var funcName = 'get' + texFuncSnippet + 'AtOutCoords'; - var broadcastDims = broadcast_util.getBroadcastDims(inputInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape); - var inRank = inputInfo.shapeInfo.logicalShape.length; - var outRank = outShapeInfo.logicalShape.length; - var doBroadcast = supportsBroadcasting && ((outRank > inRank) || broadcastDims.length > 0); - var broadcastOverOuter = broadcast_util.broadcastDimsAreOuter(broadcastDims); - if (doBroadcast && !broadcastOverOuter) { - return getBroadcastOutputCoordsSampler(inputInfo, outShapeInfo, texFuncSnippet, funcName); - } - var outTexShape = outShapeInfo.texShape; - if (util.arraysEqual(inTexShape, outTexShape)) { - return "\n float " + funcName + "() {\n return sample(" + texName + ", resultUV);\n }\n "; - } - var inSize = util.sizeFromShape(inTexShape); - var broadcastSnippet = ''; - if (doBroadcast && broadcastOverOuter) { - broadcastSnippet = "\n int mainPart = index / " + inSize + ";\n index -= mainPart * " + inSize + ";\n "; - } - return "\n float " + funcName + "() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + outTexShape[0] + ", " + outTexShape[1] + "));\n int index = resTexRC.x * " + outTexShape[1] + " + resTexRC.y;\n " + broadcastSnippet + "\n int texR = index / " + inTexShape[1] + ";\n int texC = index - texR * " + inTexShape[1] + ";\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + inTexShape[1] + ".0, " + inTexShape[0] + ".0);\n\n return sample(" + texName + ", uv);\n }\n "; -} -function getCoordsDataType(rank) { - if (rank <= 1) { - return 'int'; - } - else if (rank === 2) { - return 'ivec2'; - } - else if (rank === 3) { - return 'ivec3'; - } - else if (rank === 4) { - return 'ivec4'; - } - else { - throw Error("GPU for rank " + rank + " is not yet supported"); - } -} -exports.getCoordsDataType = getCoordsDataType; -function squeezeInputInfo(inInfo, squeezedShape) { - var newInputInfo = JSON.parse(JSON.stringify(inInfo)); - newInputInfo.shapeInfo.logicalShape = squeezedShape; - return newInputInfo; -} -function getSqueezedParams(params, keptDims) { - return keptDims.map(function (d) { return params[d]; }).join(', '); -} - -},{"../../environment":34,"../../ops/broadcast_util":110,"../../util":151,"./tex_util":99}],98:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var SliceProgram = (function () { - function SliceProgram(destSize) { - this.variableNames = ['source']; - this.outputShape = destSize; - this.rank = destSize.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var sourceCoords = getCoords(this.rank); - this.userCode = "\n uniform " + dtype + " start;\n\n void main() {\n " + dtype + " sourceLoc = start + getOutputCoords();\n setOutput(getSource(" + sourceCoords + "));\n }\n "; - } - SliceProgram.prototype.getCustomSetupFunc = function (start) { - var _this = this; - if (start.length !== this.rank) { - throw Error("The rank (" + this.rank + ") of the program must match the " + - ("length of start (" + start.length + ")")); - } - return function (gpgpu, webGLProgram) { - if (_this.startLoc == null) { - _this.startLoc = gpgpu.getUniformLocationNoThrow(webGLProgram, 'start'); - if (_this.startLoc == null) { - return; - } - } - if (_this.rank === 1) { - gpgpu.gl.uniform1i(_this.startLoc, start[0]); - } - else if (_this.rank === 2) { - gpgpu.gl.uniform2i(_this.startLoc, start[0], start[1]); - } - else if (_this.rank === 3) { - gpgpu.gl.uniform3i(_this.startLoc, start[0], start[1], start[2]); - } - else if (_this.rank === 4) { - gpgpu.gl.uniform4i(_this.startLoc, start[0], start[1], start[2], start[3]); - } - else { - throw Error("Slicing for rank " + _this.rank + " is not yet supported"); - } - }; - }; - return SliceProgram; -}()); -exports.SliceProgram = SliceProgram; -function getCoords(rank) { - if (rank === 1) { - return 'sourceLoc'; - } - else if (rank === 2) { - return 'sourceLoc.x, sourceLoc.y'; - } - else if (rank === 3) { - return 'sourceLoc.x, sourceLoc.y, sourceLoc.z'; - } - else if (rank === 4) { - return 'sourceLoc.x, sourceLoc.y, sourceLoc.z, sourceLoc.w'; - } - else { - throw Error("Slicing for rank " + rank + " is not yet supported"); - } -} - -},{"./shader_compiler":97}],99:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var TextureType; -(function (TextureType) { - TextureType[TextureType["FLOAT"] = 0] = "FLOAT"; - TextureType[TextureType["UNSIGNED_BYTE"] = 1] = "UNSIGNED_BYTE"; -})(TextureType = exports.TextureType || (exports.TextureType = {})); -function getUnpackedMatrixTextureShapeWidthHeight(rows, columns) { - return [columns, rows]; -} -exports.getUnpackedMatrixTextureShapeWidthHeight = getUnpackedMatrixTextureShapeWidthHeight; -function getUnpackedArraySizeFromMatrixSize(matrixSize, channelsPerTexture) { - return matrixSize * channelsPerTexture; -} -exports.getUnpackedArraySizeFromMatrixSize = getUnpackedArraySizeFromMatrixSize; -function getColorMatrixTextureShapeWidthHeight(rows, columns) { - return [columns * 4, rows]; -} -exports.getColorMatrixTextureShapeWidthHeight = getColorMatrixTextureShapeWidthHeight; -function getMatrixSizeFromUnpackedArraySize(unpackedSize, channelsPerTexture) { - if (unpackedSize % channelsPerTexture !== 0) { - throw new Error("unpackedSize (" + unpackedSize + ") must be a multiple of " + - ("" + channelsPerTexture)); - } - return unpackedSize / channelsPerTexture; -} -exports.getMatrixSizeFromUnpackedArraySize = getMatrixSizeFromUnpackedArraySize; -function encodeMatrixToUnpackedArray(matrix, unpackedArray, channelsPerTexture) { - var requiredSize = getUnpackedArraySizeFromMatrixSize(matrix.length, channelsPerTexture); - if (unpackedArray.length < requiredSize) { - throw new Error("unpackedArray length (" + unpackedArray.length + ") must be >= " + - ("" + requiredSize)); - } - var dst = 0; - for (var src = 0; src < matrix.length; ++src) { - unpackedArray[dst] = matrix[src]; - dst += channelsPerTexture; - } -} -exports.encodeMatrixToUnpackedArray = encodeMatrixToUnpackedArray; -exports.FLOAT_MAX = 20000; -exports.FLOAT_MIN = -exports.FLOAT_MAX; -var FLOAT_RANGE = (exports.FLOAT_MAX - exports.FLOAT_MIN) / 255; -var FLOAT_DELTAS = [1, 1 / 255, 1 / (255 * 255), 1 / (255 * 255 * 255)]; -var FLOAT_POWERS = [1, 255, 255 * 255]; -exports.BYTE_NAN_VALUE = 0; -function encodeFloatArray(floatArray) { - var uintArray = new Uint8Array(floatArray.length * 4); - var _loop_1 = function (i) { - var value = floatArray[i / 4]; - if (isNaN(value)) { - uintArray[i] = exports.BYTE_NAN_VALUE; - uintArray[i + 1] = exports.BYTE_NAN_VALUE; - uintArray[i + 2] = exports.BYTE_NAN_VALUE; - uintArray[i + 3] = exports.BYTE_NAN_VALUE; - return "continue"; - } - var normalizedValue = (value - exports.FLOAT_MIN) / FLOAT_RANGE; - var enc = FLOAT_POWERS.map(function (pow) { return pow * normalizedValue; }); - var buckets = enc.map(function (value) { return Math.floor((value % 1) * 255); }); - uintArray[i] = Math.floor(normalizedValue); - uintArray[i + 1] = buckets[0]; - uintArray[i + 2] = buckets[1]; - uintArray[i + 3] = buckets[2]; - }; - for (var i = 0; i < uintArray.length; i += 4) { - _loop_1(i); - } - return uintArray; -} -exports.encodeFloatArray = encodeFloatArray; -function decodeToFloatArray(uintArray) { - var floatArray = new Float32Array(uintArray.length / 4); - var _loop_2 = function (i) { - if (uintArray[i] === exports.BYTE_NAN_VALUE && - uintArray[i + 1] === exports.BYTE_NAN_VALUE && - uintArray[i + 2] === exports.BYTE_NAN_VALUE && - uintArray[i + 3] === exports.BYTE_NAN_VALUE) { - floatArray[i / 4] = NaN; - return "continue"; - } - var dot = 0; - FLOAT_DELTAS.forEach(function (delta, j) { - dot += delta * uintArray[i + j]; - }); - var value = dot * FLOAT_RANGE + exports.FLOAT_MIN; - floatArray[i / 4] = value; - }; - for (var i = 0; i < uintArray.length; i += 4) { - _loop_2(i); - } - return floatArray; -} -exports.decodeToFloatArray = decodeToFloatArray; -function decodeMatrixFromUnpackedArray(unpackedArray, matrix, channelsPerTexture) { - var requiredSize = getMatrixSizeFromUnpackedArraySize(unpackedArray.length, channelsPerTexture); - if (matrix.length < requiredSize) { - throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize); - } - var dst = 0; - for (var src = 0; src < unpackedArray.length; src += channelsPerTexture) { - matrix[dst++] = unpackedArray[src]; - } -} -exports.decodeMatrixFromUnpackedArray = decodeMatrixFromUnpackedArray; -function decodeMatrixFromUnpackedColorRGBAArray(unpackedArray, matrix, channels) { - var requiredSize = unpackedArray.length * channels / 4; - if (matrix.length < requiredSize) { - throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize); - } - var dst = 0; - for (var src = 0; src < unpackedArray.length; src += 4) { - for (var c = 0; c < channels; c++) { - matrix[dst++] = unpackedArray[src + c]; - } - } -} -exports.decodeMatrixFromUnpackedColorRGBAArray = decodeMatrixFromUnpackedColorRGBAArray; -function getPackedMatrixTextureShapeWidthHeight(rows, columns) { - return [Math.ceil(columns / 2), Math.ceil(rows / 2)]; -} -exports.getPackedMatrixTextureShapeWidthHeight = getPackedMatrixTextureShapeWidthHeight; -function getPackedRGBAArraySizeFromMatrixShape(rows, columns) { - var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - return w * h * 4; -} -exports.getPackedRGBAArraySizeFromMatrixShape = getPackedRGBAArraySizeFromMatrixShape; -function encodeMatrixToPackedRGBA(matrix, rows, columns, packedRGBA) { - var requiredSize = getPackedRGBAArraySizeFromMatrixShape(rows, columns); - if (packedRGBA.length < requiredSize) { - throw new Error("packedRGBA length (" + packedRGBA.length + ") must be >= " + requiredSize); - } - var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), textureWidth = _a[0], textureHeight = _a[1]; - var oddWidth = (columns % 2) === 1; - var oddHeight = (rows % 2) === 1; - var widthInFullBlocks = Math.floor(columns / 2); - var heightInFullBlocks = Math.floor(rows / 2); - { - var dstStride = (oddWidth ? 4 : 0); - var oneRow = columns; - var dst = 0; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - var matrixSrcRow = (blockY * 2 * columns); - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - var matrixSrcCol = blockX * 2; - var src = matrixSrcRow + matrixSrcCol; - packedRGBA[dst] = matrix[src]; - packedRGBA[dst + 1] = matrix[src + 1]; - packedRGBA[dst + 2] = matrix[src + oneRow]; - packedRGBA[dst + 3] = matrix[src + oneRow + 1]; - dst += 4; - } - dst += dstStride; - } - } - if (oddWidth) { - var src = columns - 1; - var dst = (textureWidth - 1) * 4; - var srcStride = 2 * columns; - var dstStride = textureWidth * 4; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - packedRGBA[dst] = matrix[src]; - packedRGBA[dst + 2] = matrix[src + columns]; - src += srcStride; - dst += dstStride; - } - } - if (oddHeight) { - var src = (rows - 1) * columns; - var dst = (textureHeight - 1) * textureWidth * 4; - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - packedRGBA[dst++] = matrix[src++]; - packedRGBA[dst++] = matrix[src++]; - dst += 2; - } - } - if (oddWidth && oddHeight) { - packedRGBA[packedRGBA.length - 4] = matrix[matrix.length - 1]; - } - return packedRGBA; -} -exports.encodeMatrixToPackedRGBA = encodeMatrixToPackedRGBA; -function decodeMatrixFromPackedRGBA(packedRGBA, rows, columns, matrix) { - var requiredSize = rows * columns; - if (requiredSize < matrix.length) { - throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize); - } - var oddWidth = (columns % 2) === 1; - var oddHeight = (rows % 2) === 1; - var widthInFullBlocks = Math.floor(columns / 2); - var heightInFullBlocks = Math.floor(rows / 2); - var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), textureWidth = _a[0], textureHeight = _a[1]; - { - var srcStride = oddWidth ? 4 : 0; - var dstStride = columns + (oddWidth ? 1 : 0); - var src = 0; - var dstRow1 = 0; - var dstRow2 = columns; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - matrix[dstRow1++] = packedRGBA[src++]; - matrix[dstRow1++] = packedRGBA[src++]; - matrix[dstRow2++] = packedRGBA[src++]; - matrix[dstRow2++] = packedRGBA[src++]; - } - src += srcStride; - dstRow1 += dstStride; - dstRow2 += dstStride; - } - } - if (oddWidth) { - var src = (textureWidth - 1) * 4; - var dst = columns - 1; - var srcStride = textureWidth * 4; - var dstStride = 2 * columns; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - matrix[dst] = packedRGBA[src]; - matrix[dst + columns] = packedRGBA[src + 2]; - src += srcStride; - dst += dstStride; - } - } - if (oddHeight) { - var src = (textureHeight - 1) * textureWidth * 4; - var dst = (rows - 1) * columns; - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - matrix[dst++] = packedRGBA[src++]; - matrix[dst++] = packedRGBA[src++]; - src += 2; - } - } - if (oddWidth && oddHeight) { - matrix[matrix.length - 1] = packedRGBA[packedRGBA.length - 4]; - } - return matrix; -} -exports.decodeMatrixFromPackedRGBA = decodeMatrixFromPackedRGBA; - -},{}],100:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tex_util_1 = require("./tex_util"); -var TextureManager = (function () { - function TextureManager(gpgpu) { - this.gpgpu = gpgpu; - this.numUsedTextures = 0; - this.numFreeTextures = 0; - this.freeTextures = {}; - this.logEnabled = false; - this.allocatedTextures = []; - this.usedTextureCount = {}; - } - TextureManager.prototype.acquireTexture = function (shapeRC, texType) { - if (texType === void 0) { texType = tex_util_1.TextureType.FLOAT; } - var shapeKey = getKeyFromTextureShape(shapeRC, texType); - if (!(shapeKey in this.freeTextures)) { - this.freeTextures[shapeKey] = []; - } - if (!(shapeKey in this.usedTextureCount)) { - this.usedTextureCount[shapeKey] = 0; - } - this.usedTextureCount[shapeKey]++; - if (this.freeTextures[shapeKey].length > 0) { - this.numFreeTextures--; - this.numUsedTextures++; - this.log(); - return this.freeTextures[shapeKey].shift(); - } - this.numUsedTextures++; - this.log(); - var newTexture = this.gpgpu.createMatrixTexture(shapeRC[0], shapeRC[1]); - this.allocatedTextures.push(newTexture); - return newTexture; - }; - TextureManager.prototype.releaseTexture = function (texture, shape, texType) { - if (texType === void 0) { texType = tex_util_1.TextureType.FLOAT; } - var shapeKey = getKeyFromTextureShape(shape, texType); - if (!(shapeKey in this.freeTextures)) { - this.freeTextures[shapeKey] = []; - } - this.freeTextures[shapeKey].push(texture); - this.numFreeTextures++; - this.numUsedTextures--; - this.usedTextureCount[shapeKey]--; - this.log(); - }; - TextureManager.prototype.log = function () { - if (!this.logEnabled) { - return; - } - var total = this.numFreeTextures + this.numUsedTextures; - console.log('Free/Used', this.numFreeTextures + " / " + this.numUsedTextures, "(" + total + ")"); - }; - TextureManager.prototype.getNumUsedTextures = function () { - return this.numUsedTextures; - }; - TextureManager.prototype.getNumFreeTextures = function () { - return this.numFreeTextures; - }; - TextureManager.prototype.dispose = function () { - var _this = this; - if (this.allocatedTextures == null) { - return; - } - this.allocatedTextures.forEach(function (texture) { - _this.gpgpu.deleteMatrixTexture(texture); - }); - this.freeTextures = null; - this.allocatedTextures = null; - this.usedTextureCount = null; - this.numUsedTextures = 0; - this.numFreeTextures = 0; - }; - return TextureManager; -}()); -exports.TextureManager = TextureManager; -function getKeyFromTextureShape(shapeRowsCol, texType) { - return shapeRowsCol[0] + "_" + shapeRowsCol[1] + "_" + texType; -} - -},{"./tex_util":99}],101:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var TileProgram = (function () { - function TileProgram(aShape, reps) { - this.variableNames = ['A']; - var outputShape = new Array(aShape.length); - for (var i = 0; i < outputShape.length; i++) { - outputShape[i] = aShape[i] * reps[i]; - } - this.outputShape = outputShape; - this.rank = outputShape.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var sourceCoords = getSourceCoords(aShape); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + sourceCoords + "));\n }\n "; - } - return TileProgram; -}()); -exports.TileProgram = TileProgram; -function getSourceCoords(aShape) { - var rank = aShape.length; - if (rank > 4) { - throw Error("Tile for rank " + rank + " is not yet supported"); - } - if (rank === 1) { - return "imod(resRC, " + aShape[0] + ")"; - } - var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var sourceCoords = []; - for (var i = 0; i < aShape.length; i++) { - sourceCoords.push("imod(" + currentCoords[i] + ", " + aShape[i] + ")"); - } - return sourceCoords.join(); -} - -},{"./shader_compiler":97}],102:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var TransposeProgram = (function () { - function TransposeProgram(aShape, newDim) { - this.variableNames = ['A']; - var outputShape = new Array(aShape.length); - for (var i = 0; i < outputShape.length; i++) { - outputShape[i] = aShape[newDim[i]]; - } - this.outputShape = outputShape; - this.rank = outputShape.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var switched = getSwitchedCoords(newDim); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + switched + "));\n }\n "; - } - return TransposeProgram; -}()); -exports.TransposeProgram = TransposeProgram; -function getSwitchedCoords(newDim) { - var rank = newDim.length; - if (rank > 4) { - throw Error("Transpose for rank " + rank + " is not yet supported"); - } - var originalOrder = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var switchedCoords = new Array(rank); - for (var i = 0; i < newDim.length; i++) { - switchedCoords[newDim[i]] = originalOrder[i]; - } - return switchedCoords.join(); -} - -},{"./shader_compiler":97}],103:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var selu_util = require("../../ops/selu_util"); -var UnaryOpProgram = (function () { - function UnaryOpProgram(aShape, opSnippet) { - this.variableNames = ['A']; - this.outputShape = aShape; - this.userCode = "\n float unaryOperation(float x) {\n " + opSnippet + "\n }\n\n void main() {\n float x = getAAtOutCoords();\n float y = unaryOperation(x);\n\n setOutput(y);\n }\n "; - } - return UnaryOpProgram; -}()); -exports.UnaryOpProgram = UnaryOpProgram; -var CHECK_NAN_SNIPPET = "\n if (isNaN(x)) return x;\n"; -exports.ABS = "\n return abs(x);\n"; -exports.RELU = CHECK_NAN_SNIPPET + "\n return (x < 0.0) ? 0.0 : x;\n"; -exports.ELU = "\n return (x >= 0.0) ? x : (exp(x) - 1.0);\n"; -exports.ELU_DER = "\n return (x >= 0.0) ? 1.0 : exp(x);\n"; -exports.SELU = "\n // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.\n // see: https://arxiv.org/abs/1706.02515\n float scaleAlpha = " + selu_util.SELU_SCALEALPHA + ";\n float scale = " + selu_util.SELU_SCALE + ";\n return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\n"; -function LEAKY_RELU(alpha) { - return "\n return (x >= 0.0) ? x : " + alpha + " * x;\n "; -} -exports.LEAKY_RELU = LEAKY_RELU; -function STEP(alpha) { - if (alpha === void 0) { alpha = 0.0; } - return CHECK_NAN_SNIPPET + ("\n return x > 0.0 ? 1.0 : float(" + alpha + ");\n "); -} -exports.STEP = STEP; -exports.NEG = "\n return -x;\n"; -exports.CEIL = "\n return ceil(x);\n"; -exports.FLOOR = "\n return floor(x);\n"; -exports.EXP = "\n return exp(x);\n"; -exports.LOG = "\n return log(x);\n"; -exports.SQRT = CHECK_NAN_SNIPPET + "\n return sqrt(x);\n"; -exports.SIGMOID = "\n return 1.0 / (1.0 + exp(-1.0 * x));\n"; -exports.SIN = CHECK_NAN_SNIPPET + "\n return sin(x);\n"; -exports.COS = CHECK_NAN_SNIPPET + "\n return cos(x);\n"; -exports.TAN = "\n return tan(x);\n"; -exports.ASIN = CHECK_NAN_SNIPPET + "\n return asin(x);\n"; -exports.ACOS = CHECK_NAN_SNIPPET + "\n return acos(x);\n"; -exports.ATAN = CHECK_NAN_SNIPPET + "\n return atan(x);\n"; -exports.SINH = "\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n"; -exports.COSH = "\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n"; -exports.TANH = "\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n"; -exports.SQUARE = "\n return x * x;\n"; -exports.LOGICAL_NOT = CHECK_NAN_SNIPPET + "\n return float(!(x >= 1.0));\n"; -exports.TO_INT = "\n return float(int(x));\n"; - -},{"../../ops/selu_util":129}],104:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MAX_TEXTURE_SIZE = null; -var util = require("../../util"); -var environment_1 = require("../../environment"); -function createWebGLRenderingContext(attributes) { - var canvas = document.createElement('canvas'); - canvas.width = 1; - canvas.height = 1; - return createWebGLRenderingContextFromCanvas(canvas, attributes); -} -exports.createWebGLRenderingContext = createWebGLRenderingContext; -function createWebGLRenderingContextFromCanvas(canvas, attributes) { - var gl; - var webglVersion = environment_1.ENV.get('WEBGL_VERSION'); - if (webglVersion === 2) { - gl = canvas.getContext('webgl2', attributes); - } - else if (webglVersion === 1) { - gl = (canvas.getContext('webgl', attributes) || - canvas.getContext('experimental-webgl', attributes)); - } - if (webglVersion === 0 || gl == null) { - throw new Error('This browser does not support WebGL.'); - } - return gl; -} -exports.createWebGLRenderingContextFromCanvas = createWebGLRenderingContextFromCanvas; -function callAndCheck(gl, func) { - var returnValue = func(); - checkWebGLError(gl); - return returnValue; -} -exports.callAndCheck = callAndCheck; -var webGLDebugErrorCheckingEnabled = false; -function enableDebugWebGLErrorChecking(enabled) { - webGLDebugErrorCheckingEnabled = enabled; -} -exports.enableDebugWebGLErrorChecking = enableDebugWebGLErrorChecking; -function checkWebGLError(gl) { - if (webGLDebugErrorCheckingEnabled) { - var error = gl.getError(); - if (error !== gl.NO_ERROR) { - throw new Error('WebGL Error: ' + getWebGLErrorMessage(gl, error)); - } - } -} -exports.checkWebGLError = checkWebGLError; -function getWebGLErrorMessage(gl, status) { - switch (status) { - case gl.NO_ERROR: - return 'NO_ERROR'; - case gl.INVALID_ENUM: - return 'INVALID_ENUM'; - case gl.INVALID_VALUE: - return 'INVALID_VALUE'; - case gl.INVALID_OPERATION: - return 'INVALID_OPERATION'; - case gl.INVALID_FRAMEBUFFER_OPERATION: - return 'INVALID_FRAMEBUFFER_OPERATION'; - case gl.OUT_OF_MEMORY: - return 'OUT_OF_MEMORY'; - case gl.CONTEXT_LOST_WEBGL: - return 'CONTEXT_LOST_WEBGL'; - default: - return "Unknown error code " + status; - } -} -exports.getWebGLErrorMessage = getWebGLErrorMessage; -function getExtensionOrThrow(gl, extensionName) { - return throwIfNull(gl, function () { return gl.getExtension(extensionName); }, 'Extension "' + extensionName + '" not supported on this browser.'); -} -exports.getExtensionOrThrow = getExtensionOrThrow; -function createVertexShader(gl, vertexShaderSource) { - var vertexShader = throwIfNull(gl, function () { return gl.createShader(gl.VERTEX_SHADER); }, 'Unable to create vertex WebGLShader.'); - callAndCheck(gl, function () { return gl.shaderSource(vertexShader, vertexShaderSource); }); - callAndCheck(gl, function () { return gl.compileShader(vertexShader); }); - if (gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS) === false) { - console.log(gl.getShaderInfoLog(vertexShader)); - throw new Error('Failed to compile vertex shader.'); - } - return vertexShader; -} -exports.createVertexShader = createVertexShader; -function createFragmentShader(gl, fragmentShaderSource) { - var fragmentShader = throwIfNull(gl, function () { return gl.createShader(gl.FRAGMENT_SHADER); }, 'Unable to create fragment WebGLShader.'); - callAndCheck(gl, function () { return gl.shaderSource(fragmentShader, fragmentShaderSource); }); - callAndCheck(gl, function () { return gl.compileShader(fragmentShader); }); - if (gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS) === false) { - logShaderSourceAndInfoLog(fragmentShaderSource, gl.getShaderInfoLog(fragmentShader)); - throw new Error('Failed to compile fragment shader.'); - } - return fragmentShader; -} -exports.createFragmentShader = createFragmentShader; -var lineNumberRegex = /ERROR: [0-9]+:([0-9]+):/g; -function logShaderSourceAndInfoLog(shaderSource, shaderInfoLog) { - var lineNumberRegexResult = lineNumberRegex.exec(shaderInfoLog); - if (lineNumberRegexResult == null) { - console.log("Couldn't parse line number in error: " + shaderInfoLog); - console.log(shaderSource); - return; - } - var lineNumber = +lineNumberRegexResult[1]; - var shaderLines = shaderSource.split('\n'); - var pad = shaderLines.length.toString().length + 2; - var linesWithLineNumbers = shaderLines.map(function (line, lineNumber) { - return util.rightPad((lineNumber + 1).toString(), pad) + line; - }); - var maxLineLength = 0; - for (var i = 0; i < linesWithLineNumbers.length; i++) { - maxLineLength = Math.max(linesWithLineNumbers[i].length, maxLineLength); - } - var beforeErrorLines = linesWithLineNumbers.slice(0, lineNumber - 1); - var errorLine = linesWithLineNumbers.slice(lineNumber - 1, lineNumber); - var afterErrorLines = linesWithLineNumbers.slice(lineNumber); - console.log(beforeErrorLines.join('\n')); - console.log(shaderInfoLog.split('\n')[0]); - console.log("%c " + util.rightPad(errorLine[0], maxLineLength), 'border:1px solid red; background-color:#e3d2d2; color:#a61717'); - console.log(afterErrorLines.join('\n')); -} -function createProgram(gl) { - return throwIfNull(gl, function () { return gl.createProgram(); }, 'Unable to create WebGLProgram.'); -} -exports.createProgram = createProgram; -function linkProgram(gl, program) { - callAndCheck(gl, function () { return gl.linkProgram(program); }); - if (gl.getProgramParameter(program, gl.LINK_STATUS) === false) { - console.log(gl.getProgramInfoLog(program)); - throw new Error('Failed to link vertex and fragment shaders.'); - } -} -exports.linkProgram = linkProgram; -function validateProgram(gl, program) { - callAndCheck(gl, function () { return gl.validateProgram(program); }); - if (gl.getProgramParameter(program, gl.VALIDATE_STATUS) === false) { - console.log(gl.getProgramInfoLog(program)); - throw new Error('Shader program validation failed.'); - } -} -exports.validateProgram = validateProgram; -function createStaticVertexBuffer(gl, data) { - var buffer = throwIfNull(gl, function () { return gl.createBuffer(); }, 'Unable to create WebGLBuffer'); - callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, buffer); }); - callAndCheck(gl, function () { return gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW); }); - return buffer; -} -exports.createStaticVertexBuffer = createStaticVertexBuffer; -function createStaticIndexBuffer(gl, data) { - var buffer = throwIfNull(gl, function () { return gl.createBuffer(); }, 'Unable to create WebGLBuffer'); - callAndCheck(gl, function () { return gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer); }); - callAndCheck(gl, function () { return gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data, gl.STATIC_DRAW); }); - return buffer; -} -exports.createStaticIndexBuffer = createStaticIndexBuffer; -function queryMaxTextureSize(gl) { - if (MAX_TEXTURE_SIZE != null) { - return MAX_TEXTURE_SIZE; - } - MAX_TEXTURE_SIZE = - callAndCheck(gl, function () { return gl.getParameter(gl.MAX_TEXTURE_SIZE); }); - return MAX_TEXTURE_SIZE; -} -exports.queryMaxTextureSize = queryMaxTextureSize; -function getChannelsPerTexture() { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return 4; - } - if (environment_1.ENV.get('WEBGL_VERSION') === 2) { - return 1; - } - return 4; -} -exports.getChannelsPerTexture = getChannelsPerTexture; -function createTexture(gl) { - return throwIfNull(gl, function () { return gl.createTexture(); }, 'Unable to create WebGLTexture.'); -} -exports.createTexture = createTexture; -function validateTextureSize(gl, width, height) { - var maxTextureSize = queryMaxTextureSize(gl); - if ((width <= 0) || (height <= 0)) { - var requested = "[" + width + "x" + height + "]"; - throw new Error('Requested texture size ' + requested + ' is invalid.'); - } - if ((width > maxTextureSize) || (height > maxTextureSize)) { - var requested = "[" + width + "x" + height + "]"; - var max = "[" + maxTextureSize + "x" + maxTextureSize + "]"; - throw new Error('Requested texture size ' + requested + - ' greater than WebGL maximum on this browser / GPU ' + max + '.'); - } -} -exports.validateTextureSize = validateTextureSize; -function createFramebuffer(gl) { - return throwIfNull(gl, function () { return gl.createFramebuffer(); }, 'Unable to create WebGLFramebuffer.'); -} -exports.createFramebuffer = createFramebuffer; -function bindVertexBufferToProgramAttribute(gl, program, attribute, buffer, arrayEntriesPerItem, itemStrideInBytes, itemOffsetInBytes, attribLocations) { - var loc = -1; - if ((attribLocations != null) && (attribute in attribLocations)) { - loc = attribLocations[attribute]; - } - else { - loc = gl.getAttribLocation(program, attribute); - } - if (loc === -1) { - return; - } - callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, buffer); }); - callAndCheck(gl, function () { return gl.vertexAttribPointer(loc, arrayEntriesPerItem, gl.FLOAT, false, itemStrideInBytes, itemOffsetInBytes); }); - callAndCheck(gl, function () { return gl.enableVertexAttribArray(loc); }); -} -exports.bindVertexBufferToProgramAttribute = bindVertexBufferToProgramAttribute; -function bindTextureUnit(gl, texture, textureUnit) { - validateTextureUnit(gl, textureUnit); - callAndCheck(gl, function () { return gl.activeTexture(gl.TEXTURE0 + textureUnit); }); - callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); }); -} -exports.bindTextureUnit = bindTextureUnit; -function unbindTextureUnit(gl, textureUnit) { - validateTextureUnit(gl, textureUnit); - callAndCheck(gl, function () { return gl.activeTexture(gl.TEXTURE0 + textureUnit); }); - callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); -} -exports.unbindTextureUnit = unbindTextureUnit; -function getProgramUniformLocationOrThrow(gl, program, uniformName) { - return throwIfNull(gl, function () { return gl.getUniformLocation(program, uniformName); }, 'uniform "' + uniformName + '" not present in program.'); -} -exports.getProgramUniformLocationOrThrow = getProgramUniformLocationOrThrow; -function getProgramUniformLocation(gl, program, uniformName) { - return gl.getUniformLocation(program, uniformName); -} -exports.getProgramUniformLocation = getProgramUniformLocation; -function bindTextureToProgramUniformSampler(gl, program, texture, uniformSamplerLocation, textureUnit) { - callAndCheck(gl, function () { return bindTextureUnit(gl, texture, textureUnit); }); - callAndCheck(gl, function () { return gl.uniform1i(uniformSamplerLocation, textureUnit); }); -} -exports.bindTextureToProgramUniformSampler = bindTextureToProgramUniformSampler; -function bindCanvasToFramebuffer(gl) { - callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, null); }); - callAndCheck(gl, function () { return gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); }); - callAndCheck(gl, function () { return gl.scissor(0, 0, gl.canvas.width, gl.canvas.height); }); -} -exports.bindCanvasToFramebuffer = bindCanvasToFramebuffer; -function bindColorTextureToFramebuffer(gl, texture, framebuffer) { - callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); }); - callAndCheck(gl, function () { return gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); }); -} -exports.bindColorTextureToFramebuffer = bindColorTextureToFramebuffer; -function unbindColorTextureFromFramebuffer(gl, framebuffer) { - callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); }); - callAndCheck(gl, function () { return gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0); }); -} -exports.unbindColorTextureFromFramebuffer = unbindColorTextureFromFramebuffer; -function validateFramebuffer(gl) { - var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER); - if (status !== gl.FRAMEBUFFER_COMPLETE) { - throw new Error('Error binding framebuffer: ' + getFramebufferErrorMessage(gl, status)); - } -} -exports.validateFramebuffer = validateFramebuffer; -function getFramebufferErrorMessage(gl, status) { - switch (status) { - case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: - return 'FRAMEBUFFER_INCOMPLETE_ATTACHMENT'; - case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: - return 'FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT'; - case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: - return 'FRAMEBUFFER_INCOMPLETE_DIMENSIONS'; - case gl.FRAMEBUFFER_UNSUPPORTED: - return 'FRAMEBUFFER_UNSUPPORTED'; - default: - return "unknown error " + status; - } -} -exports.getFramebufferErrorMessage = getFramebufferErrorMessage; -function throwIfNull(gl, returnTOrNull, failureMessage) { - var tOrNull = callAndCheck(gl, function () { return returnTOrNull(); }); - if (tOrNull == null) { - throw new Error(failureMessage); - } - return tOrNull; -} -function validateTextureUnit(gl, textureUnit) { - var maxTextureUnit = gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1; - var glTextureUnit = textureUnit + gl.TEXTURE0; - if (glTextureUnit < gl.TEXTURE0 || glTextureUnit > maxTextureUnit) { - var textureUnitRange = "[gl.TEXTURE0, gl.TEXTURE" + maxTextureUnit + "]"; - throw new Error("textureUnit must be in " + textureUnitRange + "."); - } -} -function getTextureShapeFromLogicalShape(gl, logShape) { - if (logShape.length !== 2) { - var squeezeResult = util.squeezeShape(logShape); - logShape = squeezeResult.newShape; - } - var maxTexSize = queryMaxTextureSize(gl); - var size = util.sizeFromShape(logShape); - if (logShape.length <= 1 && size <= maxTexSize) { - return [size, 1]; - } - else if (logShape.length === 2 && logShape[0] <= maxTexSize && - logShape[1] <= maxTexSize) { - return logShape; - } - else if (logShape.length === 3 && logShape[0] <= maxTexSize && - logShape[1] * logShape[2] <= maxTexSize) { - return [logShape[0], logShape[1] * logShape[2]]; - } - else if (logShape.length === 4 && logShape[0] <= maxTexSize && - logShape[1] * logShape[2] * logShape[3] <= maxTexSize) { - return [logShape[0], logShape[1] * logShape[2] * logShape[3]]; - } - else { - return util.sizeToSquarishShape(size); - } -} -exports.getTextureShapeFromLogicalShape = getTextureShapeFromLogicalShape; - -},{"../../environment":34,"../../util":151}],105:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("./environment"); -var array_ops = require("./ops/array_ops"); -var batchnorm = require("./ops/batchnorm"); -var binary_ops = require("./ops/binary_ops"); -var compare = require("./ops/compare"); -var conv = require("./ops/conv"); -var image_ops = require("./ops/image_ops"); -var logical = require("./ops/logical_ops"); -var lrn_ops = require("./ops/lrn"); -var lstm_ops = require("./ops/lstm"); -var matmul = require("./ops/matmul"); -var norm = require("./ops/norm"); -var ops = require("./ops/ops"); -var pool = require("./ops/pool"); -var reduction_ops = require("./ops/reduction_ops"); -var reverse = require("./ops/reverse"); -var slice = require("./ops/slice"); -var softmax_ops = require("./ops/softmax"); -var transpose = require("./ops/transpose"); -var unary_ops = require("./ops/unary_ops"); -var tracking_1 = require("./tracking"); -var util = require("./util"); -var tidy = tracking_1.Tracking.tidy; -var keep = tracking_1.Tracking.keep; -var NDArrayMath = (function () { - function NDArrayMath(backend, safeMode) { - this.matMul = matmul.Ops.matMul; - this.vectorTimesMatrix = matmul.Ops.vectorTimesMatrix; - this.outerProduct = matmul.Ops.outerProduct; - this.matrixTimesVector = matmul.Ops.matrixTimesVector; - this.dotProduct = matmul.Ops.dotProduct; - this.slice = slice.Ops.slice; - this.slice1D = slice.Ops.slice1d; - this.slice2D = slice.Ops.slice2d; - this.slice3D = slice.Ops.slice3d; - this.slice4D = slice.Ops.slice4d; - this.reverse = reverse.Ops.reverse; - this.reverse1D = reverse.Ops.reverse1d; - this.reverse2D = reverse.Ops.reverse2d; - this.reverse3D = reverse.Ops.reverse3d; - this.reverse4D = reverse.Ops.reverse4d; - this.batchNormalization = batchnorm.Ops.batchNormalization; - this.batchNormalization2D = batchnorm.Ops.batchNormalization2d; - this.batchNormalization3D = batchnorm.Ops.batchNormalization3d; - this.batchNormalization4D = batchnorm.Ops.batchNormalization4d; - this.avgPool = pool.Ops.avgPool; - this.maxPool = pool.Ops.maxPool; - this.minPool = pool.Ops.minPool; - this.maxPoolBackprop = pool.Ops.maxPoolBackprop; - this.conv2dTranspose = conv.Ops.conv2dTranspose; - this.depthwiseConv2D = conv.Ops.depthwiseConv2d; - this.conv2dDerFilter = conv.Ops.conv2dDerFilter; - this.conv2dDerInput = conv.Ops.conv2dDerInput; - this.argMax = reduction_ops.Ops.argMax; - this.argMin = reduction_ops.Ops.argMin; - this.logSumExp = reduction_ops.Ops.logSumExp; - this.max = reduction_ops.Ops.max; - this.mean = reduction_ops.Ops.mean; - this.min = reduction_ops.Ops.min; - this.moments = reduction_ops.Ops.moments; - this.sum = reduction_ops.Ops.sum; - this.add = binary_ops.Ops.add; - this.addStrict = binary_ops.Ops.addStrict; - this.div = binary_ops.Ops.div; - this.divide = this.div; - this.divStrict = binary_ops.Ops.divStrict; - this.divideStrict = this.divStrict; - this.maximum = binary_ops.Ops.maximum; - this.maximumStrict = binary_ops.Ops.maximumStrict; - this.minimum = binary_ops.Ops.minimum; - this.minimumStrict = binary_ops.Ops.minimumStrict; - this.mul = binary_ops.Ops.mul; - this.multiply = this.mul; - this.mulStrict = binary_ops.Ops.mulStrict; - this.multiplyStrict = this.mulStrict; - this.pow = binary_ops.Ops.pow; - this.powStrict = binary_ops.Ops.powStrict; - this.sub = binary_ops.Ops.sub; - this.subtract = this.sub; - this.subStrict = binary_ops.Ops.subStrict; - this.logicalNot = logical.Ops.logicalNot; - this.logicalAnd = logical.Ops.logicalAnd; - this.logicalOr = logical.Ops.logicalOr; - this.logicalXor = logical.Ops.logicalXor; - this.where = logical.Ops.where; - this.transpose = transpose.Ops.transpose; - this.equal = compare.Ops.equal; - this.equalStrict = compare.Ops.equalStrict; - this.greater = compare.Ops.greater; - this.greaterStrict = compare.Ops.greaterStrict; - this.greaterEqual = compare.Ops.greaterEqual; - this.greaterEqualStrict = compare.Ops.greaterEqualStrict; - this.less = compare.Ops.less; - this.lessStrict = compare.Ops.lessStrict; - this.lessEqual = compare.Ops.lessEqual; - this.lessEqualStrict = compare.Ops.lessEqualStrict; - this.notEqual = compare.Ops.notEqual; - this.notEqualStrict = compare.Ops.notEqualStrict; - this.abs = unary_ops.Ops.abs; - this.acos = unary_ops.Ops.acos; - this.asin = unary_ops.Ops.asin; - this.atan = unary_ops.Ops.atan; - this.ceil = unary_ops.Ops.ceil; - this.clip = unary_ops.Ops.clipByValue; - this.cos = unary_ops.Ops.cos; - this.cosh = unary_ops.Ops.cosh; - this.elu = unary_ops.Ops.elu; - this.exp = unary_ops.Ops.exp; - this.floor = unary_ops.Ops.floor; - this.leakyRelu = unary_ops.Ops.leakyRelu; - this.log = unary_ops.Ops.log; - this.neg = unary_ops.Ops.neg; - this.prelu = unary_ops.Ops.prelu; - this.relu = unary_ops.Ops.relu; - this.selu = unary_ops.Ops.selu; - this.sigmoid = unary_ops.Ops.sigmoid; - this.sin = unary_ops.Ops.sin; - this.sinh = unary_ops.Ops.sinh; - this.sqrt = unary_ops.Ops.sqrt; - this.square = unary_ops.Ops.square; - this.step = unary_ops.Ops.step; - this.tan = unary_ops.Ops.tan; - this.tanh = unary_ops.Ops.tanh; - this.norm = norm.Ops.norm; - this.basicLSTMCell = lstm_ops.Ops.basicLSTMCell; - this.multiRNNCell = lstm_ops.Ops.multiRNNCell; - this.softmax = softmax_ops.Ops.softmax; - this.softmaxCrossEntropy = softmax_ops.Ops.softmaxCrossEntropy; - this.cast = array_ops.Ops.cast; - this.clone = array_ops.Ops.clone; - this.gather = array_ops.Ops.gather; - this.reshape = array_ops.Ops.reshape; - this.tile = array_ops.Ops.tile; - this.oneHot = array_ops.Ops.oneHot; - this.multinomial = array_ops.Ops.multinomial; - this.pad1D = array_ops.Ops.pad1d; - this.pad2D = array_ops.Ops.pad2d; - this.resizeBilinear3D = image_ops.Ops.resizeBilinear; - this.localResponseNormalization3D = lrn_ops.LRN.localResponseNormalization; - this.localResponseNormalization4D = lrn_ops.LRN.localResponseNormalization; - this.keep = tracking_1.Tracking.keep; - environment_1.ENV.setMath(this, backend, safeMode); - this.engine = environment_1.ENV.engine; - this.dispose = environment_1.ENV.engine.dispose.bind(environment_1.ENV.engine); - this.registeredVariables = environment_1.ENV.engine.registeredVariables; - this.startScope = environment_1.ENV.engine.startScope.bind(environment_1.ENV.engine); - this.endScope = environment_1.ENV.engine.endScope.bind(environment_1.ENV.engine); - } - NDArrayMath.prototype.scope = function (scopeFn) { - var keepFn = function (tensor) { return keep(tensor); }; - var trackFn = function (tensor) { return tensor; }; - return tidy(function () { return scopeFn(keepFn, trackFn); }); - }; - NDArrayMath.prototype.track = function (result) { - return result; - }; - NDArrayMath.prototype.topK = function (x, k) { - util.assert(k <= x.size, "Error in topK: k value (" + k + ") must be less than size of input " + - ("tensor, got shape " + x.shape + ".")); - var values; - var indices; - tidy('topK', function () { - values = environment_1.ENV.engine.executeKernel('TopKValues', { inputs: { x: x }, args: { k: k } }); - indices = - environment_1.ENV.engine.executeKernel('TopKIndices', { inputs: { x: x }, args: { k: k } }); - return values; - }); - var result = { values: values, indices: indices }; - return result; - }; - NDArrayMath.prototype.elementWiseMul = function (a, b) { - return a.mulStrict(b); - }; - NDArrayMath.prototype.scalarDividedByArray = function (c, a) { - util.assert(c.size === 1, "Error in scalarDividedByArray: first argument must be rank 0, but " + - ("got Tensor of rank " + c.rank + ".")); - return c.div(a); - }; - NDArrayMath.prototype.arrayDividedByScalar = function (a, c) { - util.assert(c.size === 1, "Error in arrayDividedByScalar: second argument must be rank 0, " + - ("but got Tensor of rank " + c.rank + ".")); - return a.div(c); - }; - NDArrayMath.prototype.switchDim = function (x, perm) { - return ops.transpose(x, perm); - }; - NDArrayMath.prototype.scalarPlusArray = function (c, a) { - util.assert(c.size === 1, "Error in scalarPlusArray: first argument must be rank 0, but got " + - ("rank " + c.rank + ".")); - return this.add(c, a); - }; - NDArrayMath.prototype.scalarMinusArray = function (c, a) { - util.assert(c.size === 1, "Error in scalarMinusArray: first argument must be rank 0, but got " + - ("rank " + c.rank + ".")); - return this.subtract(c, a); - }; - NDArrayMath.prototype.arrayMinusScalar = function (a, c) { - util.assert(c.size === 1, "Error in arrayMinusScalar: second argument must be rank 0, but " + - ("got rank " + c.rank + ".")); - return this.subtract(a, c); - }; - NDArrayMath.prototype.scaledArrayAdd = function (c1, a, c2, b) { - var _this = this; - util.assert(c1.size === 1, "Error in scaledArrayAdd: first argument must rank 0, but got " + - (" rank " + c1.rank + ".")); - util.assert(c2.size === 1, "Error in scaledArrayAdd: third argument must be rank 0, but got " + - ("Tensor of rank " + c2.rank + ".")); - util.assertShapesMatch(a.shape, b.shape, 'Error in scaledArrayAdd: '); - return tidy('scaledArrayAdd', function () { - return _this.add(_this.multiply(c1, a), _this.multiply(c2, b)); - }); - }; - NDArrayMath.prototype.scalarTimesArray = function (c, a) { - util.assert(c.size === 1, "Error in arrayDividedByScalar: first argument must be rank 0, but " + - ("got rank " + c.rank + ".")); - return this.multiply(c, a); - }; - NDArrayMath.prototype.concat = function (a, b, axis) { - return ops.concat([a, b], axis); - }; - NDArrayMath.prototype.concat1D = function (a, b) { - return ops.concat1d([a, b]); - }; - NDArrayMath.prototype.concat2D = function (a, b, axis) { - return ops.concat2d([a, b], axis); - }; - NDArrayMath.prototype.concat3D = function (a, b, axis) { - return ops.concat3d([a, b], axis); - }; - NDArrayMath.prototype.concat4D = function (a, b, axis) { - return ops.concat4d([a, b], axis); - }; - NDArrayMath.prototype.conv1d = function (input, filter, bias, stride, pad, dimRoundingMode) { - if (bias != null) { - util.assert(bias.rank === 1, "Error in conv1d: bias must be rank 1, but got rank " + - (bias.rank + ".")); - } - var res = ops.conv1d(input, filter, stride, pad, dimRoundingMode); - return res.add(bias); - }; - NDArrayMath.prototype.conv2d = function (x, filter, bias, strides, pad, dimRoundingMode) { - if (bias != null) { - util.assert(bias.rank === 1, "Error in conv2d: bias must be rank 1, but got rank " + - (bias.rank + ".")); - } - var res = ops.conv2d(x, filter, strides, pad, dimRoundingMode); - return res.add(bias); - }; - NDArrayMath.prototype.argMaxEquals = function (x1, x2) { - util.assertShapesMatch(x1.shape, x2.shape, 'Error in argMaxEquals: '); - return x1.argMax().equal(x2.argMax()); - }; - return NDArrayMath; -}()); -exports.NDArrayMath = NDArrayMath; - -},{"./environment":34,"./ops/array_ops":106,"./ops/batchnorm":108,"./ops/binary_ops":109,"./ops/compare":111,"./ops/conv":114,"./ops/image_ops":116,"./ops/logical_ops":117,"./ops/lrn":118,"./ops/lstm":119,"./ops/matmul":120,"./ops/norm":121,"./ops/ops":123,"./ops/pool":124,"./ops/reduction_ops":127,"./ops/reverse":128,"./ops/slice":130,"./ops/softmax":132,"./ops/transpose":133,"./ops/unary_ops":134,"./tracking":148,"./util":151}],106:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var concat_1 = require("./concat"); -var operation_1 = require("./operation"); -var rand_1 = require("./rand"); -var Ops = (function () { - function Ops() { - } - Ops.tensor = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (shape != null && inferredShape.length !== 1) { - util.assertShapesMatch(shape, inferredShape, "Error creating a new Tensor. " + - ("Inferred shape (" + inferredShape + ") does not match the ") + - ("provided shape (" + shape + "). ")); - } - if (!util.isTypedArray(values) && !Array.isArray(values)) { - values = [values]; - } - shape = shape || inferredShape; - return tensor_1.Tensor.make(shape, { values: toTypedArray(values, dtype) }, dtype); - }; - Ops.scalar = function (value, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - if (util.isTypedArray(value) || Array.isArray(value)) { - throw new Error('Error creating a new Scalar: value must be a primitive ' + - '(number|boolean)'); - } - return Ops.tensor(value, [], dtype); - }; - Ops.tensor1d = function (values, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor1D: values must be a flat/TypedArray'); - } - return Ops.tensor(values, inferredShape, dtype); - }; - Ops.tensor2d = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 2 && inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor2D: values must be number[][] ' + - 'or flat/TypedArray'); - } - shape = shape || inferredShape; - return Ops.tensor(values, shape, dtype); - }; - Ops.tensor3d = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 3 && inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor3D: values must be number[][][]' + - 'or flat/TypedArray'); - } - shape = shape || inferredShape; - return Ops.tensor(values, shape, dtype); - }; - Ops.tensor4d = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 4 && inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor4D: values must be number[][][][]' + - 'or flat/TypedArray'); - } - shape = shape || inferredShape; - return Ops.tensor(values, shape, dtype); - }; - Ops.ones = function (shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var values = makeOnesTypedArray(util.sizeFromShape(shape), dtype); - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.zeros = function (shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var values = makeZerosTypedArray(util.sizeFromShape(shape), dtype); - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.fill = function (shape, value, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var values = util.getTypedArrayFromDType(dtype, util.sizeFromShape(shape)); - values.fill(value); - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.onesLike = function (x) { - return Ops.ones(x.shape, x.dtype); - }; - Ops.zerosLike = function (x) { - return Ops.zeros(x.shape, x.dtype); - }; - Ops.clone = function (x) { - return tensor_1.Tensor.make(x.shape, { dataId: x.dataId }, x.dtype); - }; - Ops.randomNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - if (dtype != null && dtype === 'bool') { - throw new Error("Unsupported data type " + dtype); - } - var randGauss = new rand_1.MPRandGauss(mean, stdDev, dtype, false, seed); - return tensor_1.Tensor.rand(shape, function () { return randGauss.nextValue(); }, dtype); - }; - Ops.truncatedNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - if (dtype != null && dtype === 'bool') { - throw new Error("Unsupported data type " + dtype); - } - var randGauss = new rand_1.MPRandGauss(mean, stdDev, dtype, true, seed); - return tensor_1.Tensor.rand(shape, function () { return randGauss.nextValue(); }, dtype); - }; - Ops.randomUniform = function (shape, minval, maxval, dtype) { - if (minval === void 0) { minval = 0; } - if (maxval === void 0) { maxval = 1; } - if (dtype === void 0) { dtype = 'float32'; } - return tensor_1.Tensor.rand(shape, function () { return util.randUniform(minval, maxval); }, dtype); - }; - Ops.rand = function (shape, randFunction, dtype) { - var size = util.sizeFromShape(shape); - var values = null; - if (dtype == null || dtype === 'float32') { - values = new Float32Array(size); - } - else if (dtype === 'int32') { - values = new Int32Array(size); - } - else if (dtype === 'bool') { - values = new Uint8Array(size); - } - else { - throw new Error("Unknown data type " + dtype); - } - for (var i = 0; i < size; i++) { - values[i] = randFunction(); - } - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.multinomial = function (probabilities, numSamples, seed) { - var numOutcomes = probabilities.size; - if (numOutcomes < 2) { - throw new Error("Error in multinomial: you need at least 2 outcomes, but got " + - (numOutcomes + ".")); - } - if (probabilities.rank > 2) { - throw new Error("Rank of probabilities must be 1 or 2, but is " + probabilities.rank); - } - seed = seed || Math.random(); - var origRank = probabilities.rank; - if (probabilities.rank === 1) { - probabilities = probabilities.as2D(1, -1); - } - var res = environment_1.ENV.engine.executeKernel('Multinomial', { - inputs: { probs: probabilities }, - args: { numSamples: numSamples, seed: seed } - }); - if (origRank === 1) { - return res.as1D(); - } - return res; - }; - Ops.oneHot = function (indices, depth, onValue, offValue) { - if (onValue === void 0) { onValue = 1; } - if (offValue === void 0) { offValue = 0; } - if (depth < 2) { - throw new Error("Error in oneHot: depth must be >=2, but it is " + depth); - } - return environment_1.ENV.engine.executeKernel('OneHot', { inputs: { indices: indices }, args: { depth: depth, onValue: onValue, offValue: offValue } }); - }; - Ops.fromPixels = function (pixels, numChannels) { - if (numChannels === void 0) { numChannels = 3; } - if (numChannels > 4) { - throw new Error('Cannot construct Tensor with more than 4 channels from pixels.'); - } - return environment_1.ENV.engine.fromPixels(pixels, numChannels); - }; - Ops.reshape = function (x, shape) { - shape = util.inferFromImplicitShape(shape, x.size); - util.assert(x.size === util.sizeFromShape(shape), 'new shape and old shape must have the same number of elements.'); - var grad = function (dy, y) { - return { x: function () { return dy.reshape(x.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Reshape', { inputs: { x: x }, args: { newShape: shape } }, grad); - }; - Ops.squeeze = function (x, axis) { - return Ops.reshape(x, util.squeezeShape(x.shape, axis).newShape); - }; - Ops.cast = function (x, dtype) { - var grad = function (dy, y) { - return { x: function () { return dy.reshape(dy.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Cast', { inputs: { x: x }, args: { newDType: dtype } }, grad); - }; - Ops.tile = function (x, reps) { - util.assert(x.rank === reps.length, "Error in transpose: rank of input " + x.rank + " " + - ("must match length of reps " + reps + ".")); - return environment_1.ENV.engine.executeKernel('Tile', { inputs: { x: x }, args: { reps: reps } }); - }; - Ops.gather = function (x, indices, axis) { - if (axis === void 0) { axis = 0; } - return environment_1.ENV.engine.executeKernel('Gather', { inputs: { x: x, indices: indices }, args: { axis: axis } }); - }; - Ops.pad1d = function (x, paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - util.assert(paddings.length === 2, 'Invalid number of paddings. Must be length of 2.'); - return environment_1.ENV.engine.executeKernel('Pad1D', { inputs: { x: x }, args: { paddings: paddings, constantValue: constantValue } }); - }; - Ops.pad2d = function (x, paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - util.assert(paddings.length === 2 && paddings[0].length === 2 && - paddings[1].length === 2, 'Invalid number of paddings. Must be length of 2 each.'); - return environment_1.ENV.engine.executeKernel('Pad2D', { inputs: { x: x }, args: { paddings: paddings, constantValue: constantValue } }); - }; - Ops.pad = function (x, paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - if (x.rank === 0) { - throw new Error('pad(scalar) is not defined. Pass non-scalar to pad'); - } - else if (x.rank === 1) { - return Ops.pad1d(x, paddings[0], constantValue); - } - else if (x.rank === 2) { - return Ops.pad2d(x, paddings, constantValue); - } - else { - throw new Error("pad of rank-" + x.rank + " tensor is not yet supported"); - } - }; - Ops.stack = function (tensors, axis) { - if (axis === void 0) { axis = 0; } - util.assert(tensors.length >= 2, 'Pass at least two tensors to dl.stack'); - var rank = tensors[0].rank; - var shape = tensors[0].shape; - var dtype = tensors[0].dtype; - util.assert(axis <= rank, 'Axis must be <= rank of the tensor'); - tensors.forEach(function (t) { - util.assertShapesMatch(shape, t.shape, 'All tensors passed to stack must have matching shapes'); - }); - tensors.forEach(function (t) { - util.assert(dtype === t.dtype, 'All tensors passed to stack must have matching dtypes'); - }); - var expandedTensors = tensors.map(function (t) { return t.expandDims(axis); }); - return concat_1.Concat.concat(expandedTensors, axis); - }; - Ops.expandDims = function (x, axis) { - if (axis === void 0) { axis = 0; } - util.assert(axis <= x.rank, 'Axis must be <= rank of the tensor'); - var newShape = x.shape.slice(); - newShape.splice(axis, 0, 1); - return Ops.reshape(x, newShape); - }; - Ops.linspace = function (start, stop, num) { - if (num === 0) { - throw new Error('Cannot request zero samples'); - } - var step = (stop - start) / (num - 1); - var values = makeZerosTypedArray(num, 'float32'); - values[0] = start; - for (var i = 1; i < values.length; i++) { - values[i] = values[i - 1] + step; - } - return tensor_1.Tensor1D.new(values, 'float32'); - }; - Ops.range = function (start, stop, step, dtype) { - if (step === void 0) { step = 1; } - if (dtype === void 0) { dtype = 'float32'; } - if (step === 0) { - throw new Error('Cannot have a step of zero'); - } - var sameStartStop = start === stop; - var increasingRangeNegativeStep = start < stop && step < 0; - var decreasingRangePositiveStep = stop < start && step > 1; - if (sameStartStop || increasingRangeNegativeStep || - decreasingRangePositiveStep) { - return Ops.zeros([0], dtype); - } - var numElements = Math.abs(Math.ceil((stop - start) / step)); - var values = makeZerosTypedArray(numElements, dtype); - if (stop < start && step === 1) { - step = -1; - } - values[0] = start; - for (var i = 1; i < values.length; i++) { - values[i] = values[i - 1] + step; - } - return Ops.tensor1d(values, dtype); - }; - Ops.buffer = function (shape, dtype, values) { - if (dtype === void 0) { dtype = 'float32'; } - return new tensor_1.TensorBuffer(shape, dtype, values); - }; - Ops.print = function (x, verbose) { - if (verbose === void 0) { verbose = false; } - var C = (function () { - function Tensor() { - } - return Tensor; - }()); - var displayTensor = new C(); - displayTensor.shape = x.shape; - displayTensor.values = Array.from(x.dataSync()); - displayTensor.toString = function () { - var fields = [ - "values: [" + this.values.join(', ') + "]", "shape: [" + x.shape.join(', ') + "]", - "rank: " + x.rank - ]; - if (verbose) { - fields.push("dtype: '" + this.dtype + "'"); - fields.push("size: " + this.size); - } - for (var i = 0; i < fields.length; i++) { - fields[i] = ' ' + fields[i]; - } - return 'TensorInfo {\n' + fields.join(',\n') + '\n}'; - }; - if (verbose) { - displayTensor.dtype = x.dtype; - displayTensor.size = x.size; - } - console.log(displayTensor); - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "scalar", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor1d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor2d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor3d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor4d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "ones", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "zeros", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "fill", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "onesLike", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "zerosLike", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "clone", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "randomNormal", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "truncatedNormal", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "randomUniform", null); - __decorate([ - operation_1.operation - ], Ops, "rand", null); - __decorate([ - operation_1.operation - ], Ops, "multinomial", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "oneHot", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "fromPixels", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "reshape", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }) - ], Ops, "squeeze", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "cast", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "tile", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "gather", null); - __decorate([ - operation_1.operation - ], Ops, "pad1d", null); - __decorate([ - operation_1.operation - ], Ops, "pad2d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "pad", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "stack", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "expandDims", null); - __decorate([ - operation_1.operation, - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "linspace", null); - __decorate([ - operation_1.operation, - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "range", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "buffer", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "print", null); - return Ops; -}()); -exports.Ops = Ops; -function makeZerosTypedArray(size, dtype) { - if (dtype == null || dtype === 'float32') { - return new Float32Array(size); - } - else if (dtype === 'int32') { - return new Int32Array(size); - } - else if (dtype === 'bool') { - return new Uint8Array(size); - } - else { - throw new Error("Unknown data type $ {dtype}"); - } -} -function makeOnesTypedArray(size, dtype) { - var array = makeZerosTypedArray(size, dtype); - for (var i = 0; i < array.length; i++) { - array[i] = 1; - } - return array; -} -function toTypedArray(a, dtype) { - if (noConversionNeeded(a, dtype)) { - return a; - } - if (Array.isArray(a)) { - a = util.flatten(a); - } - return util.copyTypedArray(a, dtype); -} -function noConversionNeeded(a, dtype) { - return (a instanceof Float32Array && dtype === 'float32') || - (a instanceof Int32Array && dtype === 'int32') || - (a instanceof Uint8Array && dtype === 'bool'); -} - -},{"../doc":32,"../environment":34,"../tensor":146,"../util":151,"./concat":112,"./operation":122,"./rand":125}],107:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function axesAreInnerMostDims(axes, rank) { - for (var i = 0; i < axes.length; ++i) { - if (axes[axes.length - i - 1] !== rank - 1 - i) { - return false; - } - } - return true; -} -exports.axesAreInnerMostDims = axesAreInnerMostDims; -function combineLocations(outputLoc, reduceLoc, axes) { - var rank = outputLoc.length + reduceLoc.length; - var loc = []; - var outIdx = 0; - var reduceIdx = 0; - for (var dim = 0; dim < rank; dim++) { - if (axes.indexOf(dim) === -1) { - loc.push(outputLoc[outIdx++]); - } - else { - loc.push(reduceLoc[reduceIdx++]); - } - } - return loc; -} -exports.combineLocations = combineLocations; -function computeOutAndReduceShapes(aShape, axes) { - var outShape = []; - var rank = aShape.length; - for (var dim = 0; dim < rank; dim++) { - if (axes.indexOf(dim) === -1) { - outShape.push(aShape[dim]); - } - } - var reduceShape = axes.map(function (dim) { return aShape[dim]; }); - return [outShape, reduceShape]; -} -exports.computeOutAndReduceShapes = computeOutAndReduceShapes; -function expandShapeToKeepDim(shape, axes) { - var reduceSubShape = axes.map(function (x) { return 1; }); - return combineLocations(shape, reduceSubShape, axes); -} -exports.expandShapeToKeepDim = expandShapeToKeepDim; -function parseAxisParam(axis, shape) { - var rank = shape.length; - axis = axis == null ? shape.map(function (s, i) { return i; }) : [].concat(axis); - util.assert(axis.every(function (ax) { return ax >= -rank && ax < rank; }), "All values in axis param must be in range [-" + rank + ", " + rank + ") but " + - ("got axis " + axis)); - util.assert(axis.every(function (ax) { return util.isInt(ax); }), "All values in axis param must be integers but " + - ("got axis " + axis)); - return axis.map(function (a) { return a < 0 ? rank + a : a; }); -} -exports.parseAxisParam = parseAxisParam; -function assertAxesAreInnerMostDims(msg, axes, rank) { - util.assert(axesAreInnerMostDims(axes, rank), msg + " supports only inner-most axes for now. " + - ("Got axes " + axes + " and rank-" + rank + " input.")); -} -exports.assertAxesAreInnerMostDims = assertAxesAreInnerMostDims; -function getAxesPermutation(axes, rank) { - if (axesAreInnerMostDims(axes, rank)) { - return null; - } - var result = []; - for (var i = 0; i < rank; ++i) { - if (axes.indexOf(i) === -1) { - result.push(i); - } - } - axes.forEach(function (axis) { return result.push(axis); }); - return result; -} -exports.getAxesPermutation = getAxesPermutation; -function getUndoAxesPermutation(axes) { - return axes.map(function (axis, i) { return [i, axis]; }) - .sort(function (a, b) { return a[1] - b[1]; }) - .map(function (x) { return x[0]; }); -} -exports.getUndoAxesPermutation = getUndoAxesPermutation; -function getInnerMostAxes(numAxes, rank) { - var res = []; - for (var i = rank - numAxes; i < rank; ++i) { - res.push(i); - } - return res; -} -exports.getInnerMostAxes = getInnerMostAxes; - -},{"../util":151}],108:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.batchNormalization2d = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - util.assert(x.rank === 2, "Error in batchNormalization3D: x must be rank 3 but got rank " + - (x.rank + ".")); - util.assert(mean.rank === 2 || mean.rank === 1, "Error in batchNormalization2D: mean must be rank 2 or rank 1 but " + - ("got rank " + mean.rank + ".")); - util.assert(variance.rank === 2 || variance.rank === 1, "Error in batchNormalization2D: variance must be rank 2 or rank 1 " + - ("but got rank " + variance.rank + ".")); - if (scale != null) { - util.assert(scale.rank === 2 || scale.rank === 1, "Error in batchNormalization2D: scale must be rank 2 or rank 1 " + - ("but got rank " + scale.rank + ".")); - } - if (offset != null) { - util.assert(offset.rank === 2 || offset.rank === 1, "Error in batchNormalization2D: offset must be rank 2 or rank 1 " + - ("but got rank " + offset.rank + ".")); - } - return Ops.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset); - }; - Ops.batchNormalization3d = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - util.assert(x.rank === 3, "Error in batchNormalization3D: x must be rank 3 but got rank " + - (x.rank + ".")); - util.assert(mean.rank === 3 || mean.rank === 1, "Error in batchNormalization3D: mean must be rank 3 or rank 1 but " + - ("got rank " + mean.rank + ".")); - util.assert(variance.rank === 3 || variance.rank === 1, "Error in batchNormalization3D: variance must be rank 3 or rank 1 " + - ("but got rank " + variance.rank + ".")); - if (scale != null) { - util.assert(scale.rank === 3 || scale.rank === 1, "Error in batchNormalization3D: scale must be rank 3 or rank 1 " + - ("but got rank " + scale.rank + ".")); - } - if (offset != null) { - util.assert(offset.rank === 3 || offset.rank === 1, "Error in batchNormalization3D: offset must be rank 3 or rank 1 " + - ("but got rank " + offset.rank + ".")); - } - return Ops.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset); - }; - Ops.batchNormalization4d = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - util.assert(x.rank === 4, "Error in batchNormalization4D: x must be rank 4 but got rank " + - (x.rank + ".")); - util.assert(mean.rank === 4 || mean.rank === 1, "Error in batchNormalization4D: mean must be rank 4 or rank 1 but " + - ("got rank " + mean.rank + ".")); - util.assert(variance.rank === 4 || variance.rank === 1, "Error in batchNormalization4D: variance must be rank 4 or rank 1 " + - ("but got rank " + variance.rank + ".")); - if (scale != null) { - util.assert(scale.rank === 4 || scale.rank === 1, "Error in batchNormalization4D: scale must be rank 4 or rank 1 " + - ("but got rank " + scale.rank + ".")); - } - if (offset != null) { - util.assert(offset.rank === 4 || offset.rank === 1, "Error in batchNormalization4D: offset must be rank 4 or rank 1 " + - ("but got rank " + offset.rank + ".")); - } - return Ops.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset); - }; - Ops.batchNormalization = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - var x4D; - if (x.rank === 0 || x.rank === 1) { - x4D = x.as4D(1, 1, 1, x.size); - } - else if (x.rank === 2) { - x4D = x.as4D(1, 1, x.shape[0], x.shape[1]); - } - else if (x.rank === 3) { - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - else { - x4D = x; - } - return environment_1.ENV.engine - .executeKernel('BatchNorm4D', { - inputs: { - x: x4D, - mean: batchnormReshape4D(mean), - variance: batchnormReshape4D(variance), - scale: batchnormReshape4D(scale), - offset: batchnormReshape4D(offset) - }, - args: { varianceEpsilon: varianceEpsilon } - }) - .reshape(x.shape); - }; - __decorate([ - operation_1.operation - ], Ops, "batchNormalization2d", null); - __decorate([ - operation_1.operation - ], Ops, "batchNormalization3d", null); - __decorate([ - operation_1.operation - ], Ops, "batchNormalization4d", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }) - ], Ops, "batchNormalization", null); - return Ops; -}()); -exports.Ops = Ops; -function batchnormReshape4D(x) { - if (x == null) { - return null; - } - if (x.rank === 0) { - return x.as1D(); - } - else if (x.rank === 1) { - return x; - } - else if (x.rank === 2) { - return x.as4D(1, 1, x.shape[0], x.shape[1]); - } - else if (x.rank === 3) { - return x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - return x; -} - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122}],109:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var broadcast_util = require("./broadcast_util"); -var operation_1 = require("./operation"); -var ops_1 = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.add = function (a, b) { - util.assertTypesMatch(a, b); - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.reshape(a.shape); - }; - var derB = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.reshape(b.shape); - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Add', { inputs: { a: a, b: b } }, der); - }; - Ops.addStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in addStrict: '); - return a.add(b); - }; - Ops.sub = function (a, b) { - util.assertTypesMatch(a, b); - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.reshape(a.shape); - }; - var derB = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.neg().reshape(b.shape); - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Sub', { inputs: { a: a, b: b } }, der); - }; - Ops.subStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in subStrict: '); - return a.sub(b); - }; - Ops.pow = function (base, exp) { - util.assert(exp.dtype === 'int32', 'only supports int32 data type for the exponent parameter.'); - broadcast_util.assertAndGetBroadcastShape(base.shape, exp.shape); - var gradient = function (dy, y) { - if (!util.arraysEqual(base.shape, exp.shape) && - !util.isScalarShape(exp.shape)) { - throw new Error("Gradient of pow not yet supported for broadcasted shapes."); - } - var derBase = function () { - var dx = exp.toFloat().mul(base.pow(exp.sub(ops_1.scalar(1, 'int32'))).toFloat()); - return dy.mul(dx); - }; - var derExp = function () { - throw new Error("Backprop through exponent not implemented yet."); - }; - return { base: derBase, exp: derExp }; - }; - return environment_1.ENV.engine.executeKernel('Pow', { inputs: { base: base, exp: exp } }, gradient); - }; - Ops.powStrict = function (base, exp) { - util.assertShapesMatch(base.shape, exp.shape, 'Error in powStrict: '); - return base.pow(exp); - }; - Ops.mul = function (a, b) { - util.assertTypesMatch(a, b); - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy.mul(b.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - return res.sum(reduceAxes).reshape(a.shape); - } - return res; - }; - var derB = function () { - var res = dy.mul(a.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - return res.sum(reduceAxes).reshape(b.shape); - } - return res; - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Mul', { inputs: { a: a, b: b } }, der); - }; - Ops.mulStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in multiplyStrict: '); - return a.mul(b); - }; - Ops.div = function (a, b) { - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy.div(b.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - return res.sum(reduceAxes).reshape(a.shape); - } - return res; - }; - var derB = function () { - var res = dy.mul(a.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes).reshape(b.shape); - } - var tmp = b.square(); - return res.div(tmp.toFloat()).neg(); - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Div', { inputs: { a: a, b: b } }, der); - }; - Ops.divStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in divideStrict: '); - return a.div(b); - }; - Ops.minimum = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { return dy.mul(a.lessEqual(b).toFloat()); }; - var derB = function () { return dy.mul(a.greater(b).toFloat()); }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Minimum', { inputs: { a: a, b: b } }, der); - }; - Ops.minimumStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in minimumStrict: '); - return a.minimum(b); - }; - Ops.maximum = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { return dy.mul(a.greaterEqual(b).toFloat()); }; - var derB = function () { return dy.mul(a.less(b).toFloat()); }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Maximum', { inputs: { a: a, b: b } }, der); - }; - Ops.maximumStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in minimumStrict: '); - return a.maximum(b); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "add", null); - __decorate([ - operation_1.operation - ], Ops, "addStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "sub", null); - __decorate([ - operation_1.operation - ], Ops, "subStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "pow", null); - __decorate([ - operation_1.operation - ], Ops, "powStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "mul", null); - __decorate([ - operation_1.operation - ], Ops, "mulStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "div", null); - __decorate([ - operation_1.operation - ], Ops, "divStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "minimum", null); - __decorate([ - operation_1.operation - ], Ops, "minimumStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "maximum", null); - __decorate([ - operation_1.operation - ], Ops, "maximumStrict", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./broadcast_util":110,"./operation":122,"./ops":123}],110:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function getBroadcastDims(inShape, outShape) { - var inRank = inShape.length; - var dims = []; - for (var i = 0; i < inRank; i++) { - var dim = inRank - 1 - i; - var a = inShape[dim] || 1; - var b = outShape[outShape.length - 1 - i] || 1; - if (b > 1 && a === 1) { - dims.unshift(dim); - } - } - return dims; -} -exports.getBroadcastDims = getBroadcastDims; -function getReductionAxes(inShape, outShape) { - var result = []; - for (var i = 0; i < outShape.length; i++) { - var inDim = inShape[inShape.length - i - 1]; - var outAxis = outShape.length - i - 1; - var outDim = outShape[outAxis]; - if (inDim == null || (inDim === 1 && outDim > 1)) { - result.unshift(outAxis); - } - } - return result; -} -exports.getReductionAxes = getReductionAxes; -function broadcastDimsAreOuter(dims) { - for (var i = 0; i < dims.length; i++) { - if (dims[i] !== i) { - return false; - } - } - return true; -} -exports.broadcastDimsAreOuter = broadcastDimsAreOuter; -function assertAndGetBroadcastShape(shapeA, shapeB) { - var result = []; - var errMsg = "Operands could not be broadcast together with shapes " + - (shapeA + " and " + shapeB + "."); - var l = Math.max(shapeA.length, shapeB.length); - for (var i = 0; i < l; i++) { - var a = shapeA[shapeA.length - i - 1] || 1; - var b = shapeB[shapeB.length - i - 1] || 1; - if (a > 1 && b > 1 && a !== b) { - throw Error(errMsg); - } - result.unshift(Math.max(a, b)); - } - return result; -} -exports.assertAndGetBroadcastShape = assertAndGetBroadcastShape; - -},{}],111:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var broadcast_util = require("./broadcast_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.notEqual = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('NotEqual', { inputs: { a: a, b: b } }); - }; - Ops.notEqualStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in notEqualStrict: '); - return a.notEqual(b); - }; - Ops.less = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('Less', { inputs: { a: a, b: b } }); - }; - Ops.lessStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in lessStrict: '); - return a.less(b); - }; - Ops.equal = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('Equal', { inputs: { a: a, b: b } }); - }; - Ops.equalStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in equalStrict: '); - return a.equal(b); - }; - Ops.lessEqual = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LessEqual', { inputs: { a: a, b: b } }); - }; - Ops.lessEqualStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in lessEqualStrict: '); - return a.lessEqual(b); - }; - Ops.greater = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('Greater', { inputs: { a: a, b: b } }); - }; - Ops.greaterStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in greaterStrict: '); - return a.greater(b); - }; - Ops.greaterEqual = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('GreaterEqual', { inputs: { a: a, b: b } }); - }; - Ops.greaterEqualStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in greaterEqualStrict: '); - return a.greaterEqual(b); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "notEqual", null); - __decorate([ - operation_1.operation - ], Ops, "notEqualStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "less", null); - __decorate([ - operation_1.operation - ], Ops, "lessStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "equal", null); - __decorate([ - operation_1.operation - ], Ops, "equalStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "lessEqual", null); - __decorate([ - operation_1.operation - ], Ops, "lessEqualStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "greater", null); - __decorate([ - operation_1.operation - ], Ops, "greaterStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "greaterEqual", null); - __decorate([ - operation_1.operation - ], Ops, "greaterEqualStrict", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./broadcast_util":110,"./operation":122}],112:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var concat_util = require("./concat_util"); -var operation_1 = require("./operation"); -var Concat = (function () { - function Concat() { - } - Concat.concat1d = function (tensors) { - return Concat.concat(tensors, 0); - }; - Concat.concat2d = function (tensors, axis) { - return Concat.concat(tensors, axis); - }; - Concat.concat3d = function (tensors, axis) { - return Concat.concat(tensors, axis); - }; - Concat.concat4d = function (tensors, axis) { - return Concat.concat(tensors, axis); - }; - Concat.concat = function (tensors, axis) { - if (axis === void 0) { axis = 0; } - util.assert(tensors.length >= 2, 'Pass at least two tensors to concat'); - var result = tensors[0]; - for (var i = 1; i < tensors.length; ++i) { - result = concat2Tensors(result, tensors[i], axis); - } - return result; - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Concat, "concat", null); - return Concat; -}()); -exports.Concat = Concat; -function concat2Tensors(a, b, axis) { - concat_util.assertParams(a.shape, b.shape, axis); - var outShape = concat_util.computeOutShape(a.shape, b.shape, axis); - var a2D = a.as2D(-1, util.sizeFromShape(a.shape.slice(axis))); - var b2D = b.as2D(-1, util.sizeFromShape(b.shape.slice(axis))); - var _a = concat_util.computeGradientSliceShapes(a2D.shape, b2D.shape), aBegin = _a.aBegin, aSize = _a.aSize, bBegin = _a.bBegin, bSize = _a.bSize; - var der = function (dy) { - return { a: function () { return dy.slice(aBegin, aSize); }, b: function () { return dy.slice(bBegin, bSize); } }; - }; - var res = environment_1.ENV.engine.executeKernel('Concat', { inputs: { a: a2D, b: b2D } }, der); - return res.reshape(outShape); -} - -},{"../doc":32,"../environment":34,"../util":151,"./concat_util":113,"./operation":122}],113:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function assertParams(aShape, bShape, axis) { - var aRank = aShape.length; - var bRank = bShape.length; - util.assert(aShape.length === bShape.length, "Error in concat" + aRank + "D: rank of x1 (" + aRank + ") and x2 (" + bRank + ") " + - "must be the same."); - util.assert(axis >= 0 && axis < aRank, "Error in concat" + aRank + "D: axis must be " + - ("between 0 and " + (aRank - 1) + ".")); - for (var i = 0; i < aRank; i++) { - util.assert((i === axis) || (aShape[i] === bShape[i]), "Error in concat" + aRank + "D: Shape (" + aShape + ") does not match " + - ("(" + bShape + ") along the non-concatenated axis " + i + ".")); - } -} -exports.assertParams = assertParams; -function computeOutShape1D(x1Shape, x2Shape) { - util.assert(x1Shape.length === 1 && x2Shape.length === 1, 'x1 and x2 should be 1d array.'); - var outputShape = x1Shape.slice(); - outputShape[0] += x2Shape[0]; - return outputShape; -} -exports.computeOutShape1D = computeOutShape1D; -function computeOutShape(x1Shape, x2Shape, axis) { - util.assert(x1Shape.length === x2Shape.length, 'x1 and x2 should have the same rank.'); - var outputShape = x1Shape.slice(); - outputShape[axis] += x2Shape[axis]; - return outputShape; -} -exports.computeOutShape = computeOutShape; -function computeGradientSliceShapes(aShape, bShape) { - return { - aBegin: [0, 0], - aSize: aShape, - bBegin: [0, aShape[1]], - bSize: bShape - }; -} -exports.computeGradientSliceShapes = computeGradientSliceShapes; - -},{"../util":151}],114:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var conv_util = require("./conv_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.conv1d = function (input, filter, stride, pad, dimRoundingMode) { - var input3D = input; - var reshapedTo3D = false; - if (input.rank === 2) { - reshapedTo3D = true; - input3D = input.as3D(1, input.shape[0], input.shape[1]); - } - util.assert(input3D.rank === 3, "Error in conv1d: input must be rank 3, but got rank " + input3D.rank + "."); - util.assert(filter.rank === 3, "Error in conv1d: filter must be rank 3, but got rank " + - (filter.rank + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv1d: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - util.assert(input3D.shape[2] === filter.shape[1], "Error in conv1d: depth of input (" + input3D.shape[2] + ") must match " + - ("input depth for filter " + filter.shape[1] + ".")); - var filter4D = filter.as4D(1, filter.shape[0], filter.shape[1], filter.shape[2]); - var input4D = input3D.as4D(input3D.shape[0], 1, input3D.shape[1], input3D.shape[2]); - var strides = [1, stride]; - var res = Ops.conv2d(input4D, filter4D, strides, pad, dimRoundingMode); - if (reshapedTo3D) { - return res.as2D(res.shape[2], res.shape[3]); - } - return res.as3D(res.shape[0], res.shape[2], res.shape[3]); - }; - Ops.conv2d = function (x, filter, strides, pad, dimRoundingMode) { - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - util.assert(x4D.rank === 4, "Error in conv2d: input must be rank 4, but got rank " + x4D.rank + "."); - util.assert(filter.rank === 4, "Error in conv2d: filter must be rank 4, but got rank " + - (filter.rank + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv2d: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - util.assert(x4D.shape[3] === filter.shape[2], "Error in conv2d: depth of input (" + x4D.shape[3] + ") must match " + - ("input depth for filter " + filter.shape[2] + ".")); - var convInfo = conv_util.computeConv2DInfo(x4D.shape, filter.shape, strides, pad, dimRoundingMode); - var gradients = function (dy, y) { - return { - x: function () { return Ops.conv2dDerInput(x4D.shape, dy, filter, strides, pad); }, - filter: function () { return Ops.conv2dDerFilter(x4D, dy, filter.shape, strides, pad); } - }; - }; - var res = environment_1.ENV.engine.executeKernel('Conv2D', { inputs: { x: x4D, filter: filter }, args: { convInfo: convInfo } }, gradients); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.conv2dDerInput = function (xShape, dy, filter, strides, pad, dimRoundingMode) { - util.assert(xShape.length === dy.rank, "Length of inShape " + - ("(" + xShape.length + ") and rank of dy (" + dy.rank + ") must match")); - var xShape4D = xShape; - var dy4D = dy; - var reshapedTo4D = false; - if (dy.rank === 3) { - reshapedTo4D = true; - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - xShape4D = [1, xShape[0], xShape[1], xShape[2]]; - } - var inDepth = xShape4D[3]; - var outDepth = dy4D.shape[3]; - util.assert(xShape4D.length === 4, "Error in conv2dDerInput: inShape must be length 4, but got length " + - (xShape4D.length + ".")); - util.assert(dy4D.rank === 4, "Error in conv2dDerInput: dy must be rank 4, but got " + - ("rank " + dy4D.rank)); - util.assert(filter.rank === 4, "Error in conv2dDerInput: filter must be rank 4, but got " + - ("rank " + filter.rank)); - util.assert(inDepth === filter.shape[2], "Error in conv2dDerInput: depth of input (" + inDepth + ") must " + - ("match input depth for filter " + filter.shape[2] + ".")); - util.assert(outDepth === filter.shape[3], "Error in conv2dDerInput: depth of output (" + outDepth + ") must" + - ("match output depth for filter " + filter.shape[3] + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv2dDerInput: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computeConv2DInfo(xShape4D, filter.shape, strides, pad, dimRoundingMode); - var res = environment_1.ENV.engine.executeKernel('Conv2DDerInput', { inputs: { dy: dy4D, filter: filter }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.conv2dDerFilter = function (x, dy, filterShape, strides, pad, dimRoundingMode) { - var x4D = x; - if (x.rank === 3) { - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - var dy4D = dy; - if (dy4D.rank === 3) { - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - } - util.assert(x4D.rank === 4, "Error in conv2dDerFilter: input must be rank 4, but got shape " + - (x4D.shape + ".")); - util.assert(dy4D.rank === 4, "Error in conv2dDerFilter: dy must be rank 4, but got shape " + - (dy4D.shape + ".")); - util.assert(filterShape.length === 4, "Error in conv2dDerFilter: filterShape must be length 4, but got " + - (filterShape + ".")); - util.assert(x4D.shape[3] === filterShape[2], "Error in conv2dDerFilter: depth of input " + x4D.shape[3] + ") must " + - ("match input depth in filter (" + filterShape[2] + ".")); - util.assert(dy4D.shape[3] === filterShape[3], "Error in conv2dDerFilter: depth of dy (" + dy4D.shape[3] + ") must " + - ("match output depth for filter (" + filterShape[3] + ").")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv2dDerFilter: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computeConv2DInfo(x4D.shape, filterShape, strides, pad, dimRoundingMode); - return environment_1.ENV.engine.executeKernel('Conv2DDerFilter', { inputs: { x: x4D, dy: dy4D }, args: { convInfo: convInfo } }); - }; - Ops.conv2dTranspose = function (x, filter, outputShape, strides, pad, dimRoundingMode) { - return Ops.conv2dDerInput(outputShape, x, filter, strides, pad, dimRoundingMode); - }; - Ops.depthwiseConv2d = function (input, filter, strides, pad, rates, dimRoundingMode) { - if (rates === void 0) { rates = [1, 1]; } - var input4D = input; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - } - util.assert(input4D.rank === 4, "Error in depthwiseConv2D: input must be rank 4, but got " + - ("rank " + input4D.rank + ".")); - util.assert(filter.rank === 4, "Error in depthwiseConv2D: filter must be rank 4, but got rank " + - (filter.rank + ".")); - util.assert(input4D.shape[3] === filter.shape[2], "Error in depthwiseConv2D: number of input channels " + - ("(" + input4D.shape[3] + ") must match the inChannels dimension in ") + - ("filter " + filter.shape[2] + ".")); - rates = rates || [1, 1]; - var _a = parseTupleParam(rates), rateHeight = _a[0], rateWidth = _a[1]; - util.assert(rateHeight === 1 && rateWidth === 1, 'Error in depthwiseConv2D: rates greater than 1 are not yet ' + - ("supported. Got rates '" + rates + "'")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in depthwiseConv2D: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computeConv2DInfo(input4D.shape, filter.shape, strides, pad, dimRoundingMode, true); - var res = environment_1.ENV.engine.executeKernel('DepthwiseConv2D', { inputs: { x: input4D, filter: filter }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "conv1d", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "conv2d", null); - __decorate([ - operation_1.operation - ], Ops, "conv2dDerInput", null); - __decorate([ - operation_1.operation - ], Ops, "conv2dDerFilter", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "conv2dTranspose", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "depthwiseConv2d", null); - return Ops; -}()); -exports.Ops = Ops; -function parseTupleParam(param) { - return typeof param === 'number' ? [param, param] : param; -} - -},{"../doc":32,"../environment":34,"../util":151,"./conv_util":115,"./operation":122}],115:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function computePool2DInfo(inShape, filterSize, strides, pad, roundingMode, dataFormat) { - if (dataFormat === void 0) { dataFormat = 'channelsLast'; } - var _a = parseTupleParam(filterSize), filterHeight = _a[0], filterWidth = _a[1]; - var filterShape; - if (dataFormat === 'channelsLast') { - filterShape = [filterHeight, filterWidth, inShape[3], inShape[3]]; - } - else if (dataFormat === 'channelsFirst') { - filterShape = [filterHeight, filterWidth, inShape[1], inShape[1]]; - } - else { - throw new Error("Unknown dataFormat " + dataFormat); - } - return computeConv2DInfo(inShape, filterShape, strides, pad, roundingMode, false, dataFormat); -} -exports.computePool2DInfo = computePool2DInfo; -function computeConv2DInfo(inShape, filterShape, strides, pad, roundingMode, depthwise, dataFormat) { - if (depthwise === void 0) { depthwise = false; } - if (dataFormat === void 0) { dataFormat = 'channelsLast'; } - var _a = [-1, -1, -1, -1], batchSize = _a[0], inHeight = _a[1], inWidth = _a[2], inChannels = _a[3]; - if (dataFormat === 'channelsLast') { - batchSize = inShape[0], inHeight = inShape[1], inWidth = inShape[2], inChannels = inShape[3]; - } - else if (dataFormat === 'channelsFirst') { - batchSize = inShape[0], inChannels = inShape[1], inHeight = inShape[2], inWidth = inShape[3]; - } - else { - throw new Error("Unknown dataFormat " + dataFormat); - } - var filterHeight = filterShape[0], filterWidth = filterShape[1], filterChannels = filterShape[3]; - var _b = parseTupleParam(strides), strideHeight = _b[0], strideWidth = _b[1]; - var _c = getPadAndOutInfo(pad, inHeight, inWidth, strideHeight, strideWidth, filterHeight, filterWidth, roundingMode), padInfo = _c.padInfo, outHeight = _c.outHeight, outWidth = _c.outWidth; - var outChannels = depthwise ? filterChannels * inChannels : filterChannels; - var outShape; - if (dataFormat === 'channelsFirst') { - outShape = [batchSize, outChannels, outHeight, outWidth]; - } - else if (dataFormat === 'channelsLast') { - outShape = [batchSize, outHeight, outWidth, outChannels]; - } - return { - batchSize: batchSize, - dataFormat: dataFormat, - inHeight: inHeight, - inWidth: inWidth, - inChannels: inChannels, - outHeight: outHeight, - outWidth: outWidth, - outChannels: outChannels, - padInfo: padInfo, - strideHeight: strideHeight, - strideWidth: strideWidth, - filterHeight: filterHeight, - filterWidth: filterWidth, - inShape: inShape, - outShape: outShape, - filterShape: filterShape - }; -} -exports.computeConv2DInfo = computeConv2DInfo; -function computeOutputShape3D(inShape, fieldSize, outDepth, stride, zeroPad, roundingMode) { - if (zeroPad == null) { - zeroPad = computeDefaultPad(inShape, fieldSize, stride); - } - var inputRows = inShape[0]; - var inputCols = inShape[1]; - var outputRows = conditionalRound((inputRows - fieldSize + 2 * zeroPad) / stride + 1, roundingMode); - util.assert(util.isInt(outputRows), "The output # of rows (" + outputRows + ") must be an integer. Change the " + - "stride and/or zero pad parameters"); - var outputCols = conditionalRound((inputCols - fieldSize + 2 * zeroPad) / stride + 1, roundingMode); - util.assert(util.isInt(outputCols), "The output # of columns (" + outputCols + ") must be an integer. Change " + - "the stride and/or zero pad parameters"); - return [outputRows, outputCols, outDepth]; -} -exports.computeOutputShape3D = computeOutputShape3D; -function computeDefaultPad(inputShape, fieldSize, stride) { - return Math.floor((inputShape[0] * (stride - 1) - stride + fieldSize) / 2); -} -exports.computeDefaultPad = computeDefaultPad; -function computeWeightsShape4D(inputDepth, outputDepth, filterHeight, filterWidth) { - return [filterHeight, filterWidth, inputDepth, outputDepth]; -} -exports.computeWeightsShape4D = computeWeightsShape4D; -function computeDilatedRC(rc, origStride) { - var rowsDilated = (rc[0] - 1) * origStride + 1; - var colsDilated = (rc[1] - 1) * origStride + 1; - return [rowsDilated, colsDilated]; -} -exports.computeDilatedRC = computeDilatedRC; -function parseTupleParam(param) { - return typeof param === 'number' ? [param, param] : param; -} -function getPadAndOutInfo(pad, inHeight, inWidth, strideHeight, strideWidth, filterHeight, filterWidth, roundingMode) { - var padInfo; - var outHeight; - var outWidth; - if (typeof pad === 'number') { - padInfo = { top: pad, bottom: pad, left: pad, right: pad }; - var outShape = computeOutputShape3D([inHeight, inWidth, 1], filterHeight, 1, strideHeight, pad, roundingMode); - outHeight = outShape[0]; - outWidth = outShape[1]; - } - else if (pad === 'same') { - outHeight = Math.ceil(inHeight / strideHeight); - outWidth = Math.ceil(inWidth / strideWidth); - var padAlongHeight = (outHeight - 1) * strideHeight + filterHeight - inHeight; - var padAlongWidth = (outWidth - 1) * strideWidth + filterWidth - inWidth; - var top_1 = Math.floor(padAlongHeight / 2); - var bottom = padAlongHeight - top_1; - var left = Math.floor(padAlongWidth / 2); - var right = padAlongWidth - left; - padInfo = { top: top_1, bottom: bottom, left: left, right: right }; - } - else if (pad === 'valid') { - padInfo = { top: 0, bottom: 0, left: 0, right: 0 }; - outHeight = Math.ceil((inHeight - filterHeight + 1) / strideHeight); - outWidth = Math.ceil((inWidth - filterWidth + 1) / strideWidth); - } - else { - throw Error("Unknown padding parameter: " + pad); - } - return { padInfo: padInfo, outHeight: outHeight, outWidth: outWidth }; -} -function conditionalRound(value, roundingMode) { - if (!roundingMode) { - return value; - } - switch (roundingMode) { - case 'round': - return Math.round(value); - case 'ceil': - return Math.ceil(value); - case 'floor': - return Math.floor(value); - default: - throw new Error("Unknown roundingMode " + roundingMode); - } -} - -},{"../util":151}],116:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.resizeBilinear = function (images, size, alignCorners) { - if (alignCorners === void 0) { alignCorners = false; } - util.assert(images.rank === 3 || images.rank === 4, "Error in resizeBilinear: x must be rank 3 or 4, but got " + - ("rank " + images.rank + ".")); - util.assert(size.length === 2, "Error in resizeBilinear: new shape must 2D, but got shape " + - (size + ".")); - var batchImages = images; - var reshapedTo4D = false; - if (images.rank === 3) { - reshapedTo4D = true; - batchImages = - images.as4D(1, images.shape[0], images.shape[1], images.shape[2]); - } - var newHeight = size[0], newWidth = size[1]; - var res = environment_1.ENV.engine.executeKernel('ResizeBilinear', { inputs: { x: batchImages }, args: { newHeight: newHeight, newWidth: newWidth, alignCorners: alignCorners } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Images', namespace: 'image' }), - operation_1.operation - ], Ops, "resizeBilinear", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122}],117:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var types = require("../types"); -var util = require("../util"); -var broadcast_util = require("./broadcast_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.logicalNot = function (x) { - util.assert(x.dtype === 'bool', 'Error Array must be of type bool.'); - return environment_1.ENV.engine.executeKernel('LogicalNot', { inputs: { x: x } }); - }; - Ops.logicalAnd = function (a, b) { - util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.'); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LogicalAnd', { inputs: { a: a, b: b } }); - }; - Ops.logicalOr = function (a, b) { - util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.'); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LogicalOr', { inputs: { a: a, b: b } }); - }; - Ops.logicalXor = function (a, b) { - util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.'); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LogicalXor', { inputs: { a: a, b: b } }); - }; - Ops.where = function (condition, a, b) { - util.assert(condition.dtype === 'bool' || a.dtype === 'bool' || b.dtype === 'bool', 'Error Array must be of type bool.'); - util.assertShapesMatch(a.shape, b.shape, 'Error in where: '); - if (condition.rank === 1) { - util.assert(condition.shape[0] === a.shape[0], 'The first dimension of `a` must match the size of `condition`.'); - } - else { - util.assertShapesMatch(condition.shape, b.shape, 'Error in where: '); - } - var dtype = types.upcastType(a.dtype, b.dtype); - return environment_1.ENV.engine.executeKernel('Where', { inputs: { condition: condition, a: a, b: b }, args: { dtype: dtype } }); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalNot", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalAnd", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalOr", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalXor", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "where", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../types":150,"../util":151,"./broadcast_util":110,"./operation":122}],118:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var LRN = (function () { - function LRN() { - } - LRN.localResponseNormalization = function (x, radius, bias, alpha, beta, normRegion) { - if (radius === void 0) { radius = 5; } - if (bias === void 0) { bias = 1; } - if (alpha === void 0) { alpha = 1; } - if (beta === void 0) { beta = 0.5; } - if (normRegion === void 0) { normRegion = 'acrossChannels'; } - util.assert(x.rank === 4 || x.rank === 3, "Error in localResponseNormalization: x must be rank 3 or 4 but got\n rank " + x.rank + "."); - util.assert(util.isInt(radius), "Error in localResponseNormalization3D: radius must be an integer\n but got radius " + radius + "."); - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - var res = environment_1.ENV.engine.executeKernel('LRN4D', { inputs: { x: x4D }, args: { radius: radius, bias: bias, alpha: alpha, beta: beta, normRegion: normRegion } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - else { - return res; - } - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }), - operation_1.operation - ], LRN, "localResponseNormalization", null); - return LRN; -}()); -exports.LRN = LRN; - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122}],119:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.multiRNNCell = function (lstmCells, data, c, h) { - var input = data; - var newStates = []; - for (var i = 0; i < lstmCells.length; i++) { - var output = lstmCells[i](input, c[i], h[i]); - newStates.push(output[0]); - newStates.push(output[1]); - input = output[1]; - } - var newC = []; - var newH = []; - for (var i = 0; i < newStates.length; i += 2) { - newC.push(newStates[i]); - newH.push(newStates[i + 1]); - } - return [newC, newH]; - }; - Ops.basicLSTMCell = function (forgetBias, lstmKernel, lstmBias, data, c, h) { - var combined = data.concat(h, 1); - var weighted = combined.matMul(lstmKernel); - var res = weighted.add(lstmBias); - var batchSize = res.shape[0]; - var sliceCols = res.shape[1] / 4; - var sliceSize = [batchSize, sliceCols]; - var i = res.slice([0, 0], sliceSize); - var j = res.slice([0, sliceCols], sliceSize); - var f = res.slice([0, sliceCols * 2], sliceSize); - var o = res.slice([0, sliceCols * 3], sliceSize); - var newC = i.sigmoid().mulStrict(j.tanh()).addStrict(c.mulStrict(forgetBias.add(f).sigmoid())); - var newH = newC.tanh().mulStrict(o.sigmoid()); - return [newC, newH]; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'RNN' }), - operation_1.operation - ], Ops, "multiRNNCell", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'RNN' }), - operation_1.operation - ], Ops, "basicLSTMCell", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"./operation":122}],120:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var matmul_1 = require("../kernels/types/matmul"); -var util = require("../util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.matMul = function (a, b, transposeA, transposeB) { - if (transposeA === void 0) { transposeA = false; } - if (transposeB === void 0) { transposeB = false; } - _a = [enumToBool(transposeA), enumToBool(transposeB)], transposeA = _a[0], transposeB = _a[1]; - var innerShapeA = transposeA ? a.shape[0] : a.shape[1]; - var innerShapeB = transposeB ? b.shape[1] : b.shape[0]; - util.assert(a.rank === 2 && b.rank === 2, "Error in matMul: inputs must be rank 2, got ranks " + a.rank + - (" and " + b.rank + ".")); - util.assert(innerShapeA === innerShapeB, "Error in matMul: inner shapes (" + innerShapeA + ") and (" + - (innerShapeB + ") of Tensors with shapes " + a.shape + " and ") + - (b.shape + " and transposeA=" + transposeA) + - (" and transposeB=" + transposeB + " must match.")); - return environment_1.ENV.engine.executeKernel('MatMul', { inputs: { a: a, b: b }, args: { transposeA: transposeA, transposeB: transposeB } }, function (dy, y) { - if (transposeA || transposeB) { - throw new Error("Backprop for transposed MatMul not yet implemented."); - } - return { - a: function () { return dy.matMul(b.toFloat(), false, true); }, - b: function () { return a.toFloat().matMul(dy, true, false); } - }; - }); - var _a; - }; - Ops.vectorTimesMatrix = function (v, matrix) { - util.assert(v.rank === 1, "Error in vectorTimesMatrix: first input must be rank 1, but got " + - ("rank " + v.rank + ".")); - util.assert(matrix.rank === 2, "Error in vectorTimesMatrix: second input must be rank 2, but got " + - ("rank " + matrix.rank + ".")); - util.assert(v.size === matrix.shape[0], "Error in vectorTimesMatrix: size of vector (" + v.size + ") " + - ("must match first dimension of matrix (" + matrix.shape[0] + ")")); - return v.as2D(1, -1).matMul(matrix).as1D(); - }; - Ops.matrixTimesVector = function (matrix, v) { - util.assert(v.rank === 1, "Error in matrixTimesVector: second input must rank 1, but got " + - ("rank " + v.rank + ".")); - util.assert(matrix.rank === 2, "Error in matrixTimesVector: first input must be a rank 2, but got " + - ("rank " + matrix.rank + ".")); - util.assert(v.size === matrix.shape[1], "Error in matrixTimesVector: size of first rank 1 input " + v.size + " " + - "must match inner dimension of second rank 2 input, but got " + - ("shape " + matrix.shape + ".")); - return matrix.matMul(v.as2D(-1, 1)).as1D(); - }; - Ops.dotProduct = function (v1, v2) { - util.assert(v1.rank === 1 && v2.rank === 1, "Error in dotProduct: inputs must be rank 1, but got ranks " + - (v1.rank + " and " + v2.rank + ".")); - util.assert(v1.size === v2.size, "Error in dotProduct: size of inputs (" + v1.size + ") and (" + - (v2.size + ") must match.")); - return v1.as2D(1, -1).matMul(v2.as2D(-1, 1)).asScalar(); - }; - Ops.outerProduct = function (v1, v2) { - util.assert(v1.rank === 1 && v2.rank === 1, "Error in outerProduct: inputs must be rank 1, but got ranks " + - (v1.rank + " and " + v2.rank + ".")); - return v1.as2D(-1, 1).matMul(v2.as2D(1, -1)); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "matMul", null); - __decorate([ - operation_1.operation - ], Ops, "vectorTimesMatrix", null); - __decorate([ - operation_1.operation - ], Ops, "matrixTimesVector", null); - __decorate([ - operation_1.operation - ], Ops, "dotProduct", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "outerProduct", null); - return Ops; -}()); -exports.Ops = Ops; -function enumToBool(transpose) { - if (transpose === matmul_1.MatrixOrientation.REGULAR) { - return false; - } - if (transpose === matmul_1.MatrixOrientation.TRANSPOSED) { - return true; - } - return transpose; -} - -},{"../doc":32,"../environment":34,"../kernels/types/matmul":71,"../util":151,"./operation":122}],121:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.norm = function (x, ord, axis, keepDims) { - if (ord === void 0) { ord = 'euclidean'; } - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var norm = normImpl(x, ord, axis); - var keepDimsShape = norm.shape; - if (keepDims) { - var axes = axis_util.parseAxisParam(axis, x.shape); - keepDimsShape = axis_util.expandShapeToKeepDim(norm.shape, axes); - } - return norm.reshape(keepDimsShape); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "norm", null); - return Ops; -}()); -exports.Ops = Ops; -function normImpl(x, p, axis) { - if (axis === void 0) { axis = null; } - if (x.rank === 0) { - return x.abs(); - } - if (x.rank !== 1 && axis === null) { - return normImpl(x.reshape([-1]), p, axis); - } - if (x.rank === 1 || typeof axis === 'number' || - axis instanceof Array && axis.length === 1) { - if (p === 1) { - return x.abs().sum(axis); - } - if (p === Infinity) { - return x.abs().max(axis); - } - if (p === -Infinity) { - return x.abs().min(axis); - } - if (p === 'euclidean' || p === 2) { - return x.abs().pow(ops.scalar(2, 'int32')).sum(axis).sqrt(); - } - throw new Error("Error in norm: invalid ord value: " + p); - } - if (axis instanceof Array && axis.length === 2) { - if (p === 1) { - return x.abs().sum(axis[0]).max(axis[1] - 1); - } - if (p === Infinity) { - return x.abs().sum(axis[1]).max(axis[0]); - } - if (p === -Infinity) { - return x.abs().sum(axis[1]).min(axis[0]); - } - if (p === 'fro' || p === 'euclidean') { - return x.square().sum(axis).sqrt(); - } - throw new Error("Error in norm: invalid ord value: " + p); - } - throw new Error("Error in norm: invalid axis: " + axis); -} - -},{"../doc":32,"./axis_util":107,"./operation":122,"./ops":123}],122:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -function operation(target, name, descriptor) { - var fn = descriptor.value; - descriptor.value = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return globals_1.tidy(name, function () { return fn.apply(void 0, args); }); - }; - return descriptor; -} -exports.operation = operation; - -},{"../globals":35}],123:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var array_ops = require("./array_ops"); -var batchnorm_ops = require("./batchnorm"); -var binary_ops = require("./binary_ops"); -var compare_ops = require("./compare"); -var concat_ops = require("./concat"); -var conv_ops = require("./conv"); -var image_ops = require("./image_ops"); -var logical_ops = require("./logical_ops"); -var lrn_ops = require("./lrn"); -var lstm_ops = require("./lstm"); -var matmul_ops = require("./matmul"); -var norm_ops = require("./norm"); -var pool_ops = require("./pool"); -var reduction_ops = require("./reduction_ops"); -var reverse_ops = require("./reverse"); -var slice_ops = require("./slice"); -var softmax_ops = require("./softmax"); -var transpose_ops = require("./transpose"); -var unary_ops = require("./unary_ops"); -exports.batchNormalization = batchnorm_ops.Ops.batchNormalization; -exports.batchNormalization2d = batchnorm_ops.Ops.batchNormalization2d; -exports.batchNormalization3d = batchnorm_ops.Ops.batchNormalization3d; -exports.batchNormalization4d = batchnorm_ops.Ops.batchNormalization4d; -exports.concat = concat_ops.Concat.concat; -exports.concat1d = concat_ops.Concat.concat1d; -exports.concat2d = concat_ops.Concat.concat2d; -exports.concat3d = concat_ops.Concat.concat3d; -exports.concat4d = concat_ops.Concat.concat4d; -exports.conv1d = conv_ops.Ops.conv1d; -exports.conv2d = conv_ops.Ops.conv2d; -exports.conv2dTranspose = conv_ops.Ops.conv2dTranspose; -exports.depthwiseConv2d = conv_ops.Ops.depthwiseConv2d; -exports.matMul = matmul_ops.Ops.matMul; -exports.matrixTimesVector = matmul_ops.Ops.matrixTimesVector; -exports.outerProduct = matmul_ops.Ops.outerProduct; -exports.vectorTimesMatrix = matmul_ops.Ops.vectorTimesMatrix; -exports.avgPool = pool_ops.Ops.avgPool; -exports.maxPool = pool_ops.Ops.maxPool; -exports.minPool = pool_ops.Ops.minPool; -exports.transpose = transpose_ops.Ops.transpose; -exports.reverse = reverse_ops.Ops.reverse; -exports.reverse1d = reverse_ops.Ops.reverse1d; -exports.reverse2d = reverse_ops.Ops.reverse2d; -exports.reverse3d = reverse_ops.Ops.reverse3d; -exports.reverse4d = reverse_ops.Ops.reverse4d; -exports.slice = slice_ops.Ops.slice; -exports.slice1d = slice_ops.Ops.slice1d; -exports.slice2d = slice_ops.Ops.slice2d; -exports.slice3d = slice_ops.Ops.slice3d; -exports.slice4d = slice_ops.Ops.slice4d; -exports.argMax = reduction_ops.Ops.argMax; -exports.argMin = reduction_ops.Ops.argMin; -exports.logSumExp = reduction_ops.Ops.logSumExp; -exports.max = reduction_ops.Ops.max; -exports.mean = reduction_ops.Ops.mean; -exports.min = reduction_ops.Ops.min; -exports.moments = reduction_ops.Ops.moments; -exports.sum = reduction_ops.Ops.sum; -exports.equal = compare_ops.Ops.equal; -exports.equalStrict = compare_ops.Ops.equalStrict; -exports.greater = compare_ops.Ops.greater; -exports.greaterStrict = compare_ops.Ops.greaterStrict; -exports.greaterEqual = compare_ops.Ops.greaterEqual; -exports.greaterEqualStrict = compare_ops.Ops.greaterEqualStrict; -exports.less = compare_ops.Ops.less; -exports.lessStrict = compare_ops.Ops.lessStrict; -exports.lessEqual = compare_ops.Ops.lessEqual; -exports.lessEqualStrict = compare_ops.Ops.lessEqualStrict; -exports.notEqual = compare_ops.Ops.notEqual; -exports.notEqualStrict = compare_ops.Ops.notEqualStrict; -exports.logicalNot = logical_ops.Ops.logicalNot; -exports.logicalAnd = logical_ops.Ops.logicalAnd; -exports.logicalOr = logical_ops.Ops.logicalOr; -exports.logicalXor = logical_ops.Ops.logicalXor; -exports.where = logical_ops.Ops.where; -exports.abs = unary_ops.Ops.abs; -exports.acos = unary_ops.Ops.acos; -exports.asin = unary_ops.Ops.asin; -exports.atan = unary_ops.Ops.atan; -exports.ceil = unary_ops.Ops.ceil; -exports.clipByValue = unary_ops.Ops.clipByValue; -exports.cos = unary_ops.Ops.cos; -exports.cosh = unary_ops.Ops.cosh; -exports.elu = unary_ops.Ops.elu; -exports.exp = unary_ops.Ops.exp; -exports.floor = unary_ops.Ops.floor; -exports.leakyRelu = unary_ops.Ops.leakyRelu; -exports.log = unary_ops.Ops.log; -exports.neg = unary_ops.Ops.neg; -exports.prelu = unary_ops.Ops.prelu; -exports.relu = unary_ops.Ops.relu; -exports.selu = unary_ops.Ops.selu; -exports.sigmoid = unary_ops.Ops.sigmoid; -exports.sin = unary_ops.Ops.sin; -exports.sinh = unary_ops.Ops.sinh; -exports.sqrt = unary_ops.Ops.sqrt; -exports.square = unary_ops.Ops.square; -exports.step = unary_ops.Ops.step; -exports.tan = unary_ops.Ops.tan; -exports.tanh = unary_ops.Ops.tanh; -exports.add = binary_ops.Ops.add; -exports.addStrict = binary_ops.Ops.addStrict; -exports.div = binary_ops.Ops.div; -exports.divStrict = binary_ops.Ops.divStrict; -exports.maximum = binary_ops.Ops.maximum; -exports.maximumStrict = binary_ops.Ops.maximumStrict; -exports.minimum = binary_ops.Ops.minimum; -exports.minimumStrict = binary_ops.Ops.minimumStrict; -exports.mul = binary_ops.Ops.mul; -exports.mulStrict = binary_ops.Ops.mulStrict; -exports.pow = binary_ops.Ops.pow; -exports.powStrict = binary_ops.Ops.powStrict; -exports.sub = binary_ops.Ops.sub; -exports.subStrict = binary_ops.Ops.subStrict; -exports.norm = norm_ops.Ops.norm; -exports.cast = array_ops.Ops.cast; -exports.clone = array_ops.Ops.clone; -exports.fromPixels = array_ops.Ops.fromPixels; -exports.ones = array_ops.Ops.ones; -exports.onesLike = array_ops.Ops.onesLike; -exports.zeros = array_ops.Ops.zeros; -exports.zerosLike = array_ops.Ops.zerosLike; -exports.rand = array_ops.Ops.rand; -exports.randomNormal = array_ops.Ops.randomNormal; -exports.truncatedNormal = array_ops.Ops.truncatedNormal; -exports.randomUniform = array_ops.Ops.randomUniform; -exports.reshape = array_ops.Ops.reshape; -exports.squeeze = array_ops.Ops.squeeze; -exports.tile = array_ops.Ops.tile; -exports.gather = array_ops.Ops.gather; -exports.oneHot = array_ops.Ops.oneHot; -exports.linspace = array_ops.Ops.linspace; -exports.range = array_ops.Ops.range; -exports.buffer = array_ops.Ops.buffer; -exports.fill = array_ops.Ops.fill; -exports.tensor = array_ops.Ops.tensor; -exports.scalar = array_ops.Ops.scalar; -exports.tensor1d = array_ops.Ops.tensor1d; -exports.tensor2d = array_ops.Ops.tensor2d; -exports.tensor3d = array_ops.Ops.tensor3d; -exports.tensor4d = array_ops.Ops.tensor4d; -exports.print = array_ops.Ops.print; -exports.expandDims = array_ops.Ops.expandDims; -exports.stack = array_ops.Ops.stack; -exports.pad = array_ops.Ops.pad; -exports.pad1d = array_ops.Ops.pad1d; -exports.pad2d = array_ops.Ops.pad2d; -exports.basicLSTMCell = lstm_ops.Ops.basicLSTMCell; -exports.multiRNNCell = lstm_ops.Ops.multiRNNCell; -exports.softmax = softmax_ops.Ops.softmax; -exports.localResponseNormalization = lrn_ops.LRN.localResponseNormalization; -var tensor_1 = require("../tensor"); -var types_1 = require("../types"); -[tensor_1.Tensor, types_1.Rank, tensor_1.Tensor3D, tensor_1.Tensor4D]; -exports.losses = { - softmaxCrossEntropy: softmax_ops.Ops.softmaxCrossEntropy -}; -exports.image = { - resizeBilinear: image_ops.Ops.resizeBilinear -}; - -},{"../tensor":146,"../types":150,"./array_ops":106,"./batchnorm":108,"./binary_ops":109,"./compare":111,"./concat":112,"./conv":114,"./image_ops":116,"./logical_ops":117,"./lrn":118,"./lstm":119,"./matmul":120,"./norm":121,"./pool":124,"./reduction_ops":127,"./reverse":128,"./slice":130,"./softmax":132,"./transpose":133,"./unary_ops":134}],124:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var conv_util = require("./conv_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.maxPool = function (x, filterSize, strides, pad, dimRoundingMode) { - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - util.assert(x4D.rank === 4, "Error in maxPool: input must be rank 4 but got rank " + x4D.rank + "."); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in maxPool: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(x4D.shape, filterSize, strides, pad, dimRoundingMode); - var gradients = function (dy, y) { - return { x: function () { return Ops.maxPoolBackprop(dy, x4D, filterSize, strides, pad); } }; - }; - var res = environment_1.ENV.engine.executeKernel('MaxPool', { inputs: { x: x4D }, args: { convInfo: convInfo } }, gradients); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.maxPoolBackprop = function (dy, input, filterSize, strides, pad, dimRoundingMode) { - util.assert(input.rank === dy.rank, "Rank of input (" + input.rank + ") does not match rank of dy (" + dy.rank + ")"); - var input4D = input; - var dy4D = dy; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - } - util.assert(dy4D.rank === 4, "Error in maxPoolBackprop: dy must be rank 4 but got rank " + - (dy4D.rank + ".")); - util.assert(input4D.rank === 4, "Error in maxPoolBackprop: input must be rank 4 but got rank " + - (input4D.rank + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in maxPoolBackprop: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad, dimRoundingMode); - var res = environment_1.ENV.engine.executeKernel('MaxPoolBackprop', { inputs: { dy: dy4D, x: input4D }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.minPool = function (input, filterSize, strides, pad, dimRoundingMode) { - var input4D = input; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - } - util.assert(input4D.rank === 4, "Error in minPool: x must be rank 4 but got rank " + input4D.rank + "."); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in minPool: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad, dimRoundingMode); - var res = environment_1.ENV.engine.executeKernel('MinPool', { inputs: { x: input4D }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.avgPool = function (x, filterSize, strides, pad, dimRoundingMode) { - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - util.assert(x4D.rank === 4, "Error in avgPool: x must be rank 4 but got rank " + x4D.rank + "."); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in avgPool: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(x4D.shape, filterSize, strides, pad); - var gradients = function (dy, y) { - return { x: function () { return Ops.avgPoolBackprop(dy, x4D, filterSize, strides, pad); } }; - }; - var res = environment_1.ENV.engine.executeKernel('AvgPool', { inputs: { x: x4D }, args: { convInfo: convInfo } }, gradients); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.avgPoolBackprop = function (dy, input, filterSize, strides, pad) { - util.assert(input.rank === dy.rank, "Rank of input (" + input.rank + ") does not match rank of dy (" + dy.rank + ")"); - var input4D = input; - var dy4D = dy; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - } - util.assert(dy4D.rank === 4, "Error in avgPoolBackprop: dy must be rank 4 but got rank " + - (dy4D.rank + ".")); - util.assert(input4D.rank === 4, "Error in avgPoolBackprop: input must be rank 4 but got rank " + - (input4D.rank + ".")); - var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad); - var res = environment_1.ENV.engine.executeKernel('AvgPoolBackprop', { inputs: { dy: dy4D, x: input4D }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "maxPool", null); - __decorate([ - operation_1.operation - ], Ops, "maxPoolBackprop", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "minPool", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "avgPool", null); - __decorate([ - operation_1.operation - ], Ops, "avgPoolBackprop", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./conv_util":115,"./operation":122}],125:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var MPRandGauss = (function () { - function MPRandGauss(mean, stdDeviation, dtype, truncated, seed) { - this.mean = mean; - this.stdDev = stdDeviation; - this.dtype = dtype; - this.nextVal = NaN; - this.truncated = truncated; - if (this.truncated) { - this.upper = this.mean + this.stdDev * 2; - this.lower = this.mean - this.stdDev * 2; - } - var seedValue = seed ? seed : Math.random(); - this.random = seedrandom.alea(seedValue.toString()); - } - MPRandGauss.prototype.nextValue = function () { - if (!isNaN(this.nextVal)) { - var value = this.nextVal; - this.nextVal = NaN; - return value; - } - var resultX, resultY; - var isValid = false; - while (!isValid) { - var v1 = void 0, v2 = void 0, s = void 0; - do { - v1 = 2 * this.random() - 1; - v2 = 2 * this.random() - 1; - s = v1 * v1 + v2 * v2; - } while (s >= 1 || s === 0); - var mul = Math.sqrt(-2.0 * Math.log(s) / s); - resultX = this.mean + this.stdDev * v1 * mul; - resultY = this.mean + this.stdDev * v2 * mul; - if (!this.truncated || this.isValidTruncated(resultX)) { - isValid = true; - } - } - if (!this.truncated || this.isValidTruncated(resultY)) { - this.nextVal = this.convertValue(resultY); - } - return this.convertValue(resultX); - }; - MPRandGauss.prototype.convertValue = function (value) { - if (this.dtype == null || this.dtype === 'float32') { - return value; - } - return Math.round(value); - }; - MPRandGauss.prototype.isValidTruncated = function (value) { - return value <= this.upper && value >= this.lower; - }; - return MPRandGauss; -}()); -exports.MPRandGauss = MPRandGauss; - -},{"seedrandom":153}],126:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.PARALLELIZE_THRESHOLD = 30; -function computeOptimalWindowSize(inSize) { - if (inSize <= exports.PARALLELIZE_THRESHOLD) { - return inSize; - } - return nearestDivisor(inSize, Math.floor(Math.sqrt(inSize))); -} -exports.computeOptimalWindowSize = computeOptimalWindowSize; -function nearestDivisor(size, start) { - for (var i = start; i < size; ++i) { - if (size % i === 0) { - return i; - } - } - return size; -} - -},{}],127:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.logSumExp = function (input, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, input.shape); - var xMax = input.max(axes, true); - var a = input.sub(xMax); - var b = a.exp(); - var c = b.sum(axes); - var d = c.log(); - var res = xMax.reshape(d.shape).add(d); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(res.shape, axes); - return res.reshape(newShape); - } - return res; - }; - Ops.sum = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var customOp = globals_1.customGrad(function (x) { - var permutation = axis_util.getAxesPermutation(axes, x.rank); - var reductionAxes = axes; - var permutedX = x; - if (permutation != null) { - permutedX = x.transpose(permutation); - reductionAxes = - axis_util.getInnerMostAxes(reductionAxes.length, x.rank); - } - var value = environment_1.ENV.engine.executeKernel('Sum', { inputs: { x: permutedX }, args: { axes: reductionAxes } }); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(value.shape, axes); - value = value.reshape(newShape); - } - var gradFunc = function (dy) { - var expandedDyShape = x.shape.slice(); - axes.forEach(function (axis) { - expandedDyShape[axis] = 1; - }); - var expandedDy = dy.reshape(expandedDyShape); - var derX = expandedDy.mul(tensor_1.Tensor.ones(x.shape, 'float32')); - return derX; - }; - return { value: value, gradFunc: gradFunc }; - }); - return customOp(x); - }; - Ops.mean = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var shapes = axis_util.computeOutAndReduceShapes(x.shape, axes); - var reduceShape = shapes[1]; - var reduceSize = util.sizeFromShape(reduceShape); - var customOp = globals_1.customGrad(function (x) { - var reduceSizeScalar = ops.scalar(reduceSize); - var res = x.div(reduceSizeScalar); - var value = res.sum(axis, keepDims); - var gradFunc = function (dy) { - var expandedDyShape = x.shape.slice(); - axes.forEach(function (axis) { - expandedDyShape[axis] = 1; - }); - var expandedDy = dy.reshape(expandedDyShape); - var derX = expandedDy.mul(tensor_1.Tensor.ones(x.shape, 'float32')) - .div(reduceSizeScalar); - return derX; - }; - return { value: value, gradFunc: gradFunc }; - }); - return customOp(x); - }; - Ops.min = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var origAxes = axis_util.parseAxisParam(axis, x.shape); - var axes = origAxes; - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - var res = environment_1.ENV.engine.executeKernel('Min', { inputs: { x: x }, args: { axes: axes } }); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes); - return res.reshape(newShape); - } - return res; - }; - Ops.max = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var origAxes = axis_util.parseAxisParam(axis, x.shape); - var axes = origAxes; - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - var res = environment_1.ENV.engine.executeKernel('Max', { inputs: { x: x }, args: { axes: axes } }); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes); - return res.reshape(newShape); - } - return res; - }; - Ops.argMin = function (x, axis) { - if (axis === void 0) { axis = null; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - return environment_1.ENV.engine.executeKernel('ArgMin', { inputs: { x: x }, args: { axes: axes } }); - }; - Ops.argMax = function (x, axis) { - if (axis === void 0) { axis = null; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - return environment_1.ENV.engine.executeKernel('ArgMax', { inputs: { x: x }, args: { axes: axes } }); - }; - Ops.moments = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var mean = x.mean(axes, keepDims); - var keepDimsShape = mean.shape; - if (!keepDims) { - keepDimsShape = axis_util.expandShapeToKeepDim(mean.shape, axes); - } - var devSquared = x.toFloat().sub(mean.reshape(keepDimsShape)).square(); - var variance = devSquared.mean(axes, keepDims); - return { mean: mean, variance: variance }; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "logSumExp", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "sum", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "mean", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "min", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "max", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "argMin", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "argMax", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }), - operation_1.operation - ], Ops, "moments", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../globals":35,"../tensor":146,"../util":151,"./axis_util":107,"./operation":122,"./ops":123}],128:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.reverse1d = function (x) { - util.assert(x.rank === 1, "Error in reverse1D: x must be rank 1 but got\n rank " + x.rank + "."); - return Ops.reverse(x, 0); - }; - Ops.reverse2d = function (x, axis) { - util.assert(x.rank === 2, "Error in reverse2D: x must be rank 2 but got\n rank " + x.rank + "."); - return Ops.reverse(x, axis); - }; - Ops.reverse3d = function (x, axis) { - util.assert(x.rank === 3, "Error in reverse3D: x must be rank 3 but got\n rank " + x.rank + "."); - return Ops.reverse(x, axis); - }; - Ops.reverse4d = function (x, axis) { - util.assert(x.rank === 4, "Error in reverse4D: x must be rank 4 but got\n rank " + x.rank + "."); - return Ops.reverse(x, axis); - }; - Ops.reverse = function (x, axis) { - var x4d; - var axisCleaned = axis_util.parseAxisParam(axis, x.shape).map(function (a) { return a + 4 - x.rank; }); - if (x.rank === 0) { - return x.clone(); - } - else if (x.rank === 1) { - x4d = x.as4D(1, 1, 1, x.shape[0]); - } - else if (x.rank === 2) { - x4d = x.as4D(1, 1, x.shape[0], x.shape[1]); - } - else if (x.rank === 3) { - x4d = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - else if (x.rank === 4) { - x4d = x; - } - else { - throw new Error("Reverse for rank " + x.rank + " is not yet implemented"); - } - var res = environment_1.ENV.engine.executeKernel('Reverse4D', { inputs: { x: x4d }, args: { axis: axisCleaned } }); - return res.reshapeAs(x); - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "reverse", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./axis_util":107,"./operation":122}],129:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SELU_SCALEALPHA = 1.7580993408473768599402175208123; -exports.SELU_SCALE = 1.0507009873554804934193349852946; - -},{}],130:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var operation_1 = require("./operation"); -var slice_util = require("./slice_util"); -var Ops = (function () { - function Ops() { - } - Ops.slice1d = function (x, begin, size) { - slice_util.assertParamsValid(x, [begin], [size]); - return environment_1.ENV.engine.executeKernel('Slice1D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice2d = function (x, begin, size) { - slice_util.assertParamsValid(x, begin, size); - return environment_1.ENV.engine.executeKernel('Slice2D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice3d = function (x, begin, size) { - slice_util.assertParamsValid(x, begin, size); - return environment_1.ENV.engine.executeKernel('Slice3D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice4d = function (x, begin, size) { - slice_util.assertParamsValid(x, begin, size); - return environment_1.ENV.engine.executeKernel('Slice4D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice = function (x, begin, size) { - if (x.rank === 0) { - throw new Error('Slicing scalar is not possible'); - } - else if (x.rank === 1) { - return Ops.slice1d(x, begin[0], size[0]); - } - else if (x.rank === 2) { - return Ops.slice2d(x, begin, size); - } - else if (x.rank === 3) { - return Ops.slice3d(x, begin, size); - } - else if (x.rank === 4) { - return Ops.slice4d(x, begin, size); - } - else { - throw new Error("Slicing for rank " + x.rank + " not implemented yet"); - } - }; - __decorate([ - operation_1.operation - ], Ops, "slice1d", null); - __decorate([ - operation_1.operation - ], Ops, "slice2d", null); - __decorate([ - operation_1.operation - ], Ops, "slice3d", null); - __decorate([ - operation_1.operation - ], Ops, "slice4d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "slice", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"./operation":122,"./slice_util":131}],131:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function assertParamsValid(input, begin, size) { - util.assert(input.rank === begin.length, "Error in slice" + input.rank + "D: Length of begin " + begin + " must " + - ("match the rank of the array (" + input.rank + ").")); - util.assert(input.rank === size.length, "Error in slice" + input.rank + "D: Length of size " + size + " must " + - ("match the rank of the array (" + input.rank + ").")); - for (var i = 0; i < input.rank; ++i) { - util.assert(begin[i] + size[i] <= input.shape[i], "Error in slice" + input.rank + "D: begin[" + i + "] + size[" + i + "] " + - ("(" + (begin[i] + size[i]) + ") would overflow input.shape[" + i + "] (" + input.shape[i] + ")")); - } -} -exports.assertParamsValid = assertParamsValid; - -},{"../util":151}],132:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var globals_1 = require("../globals"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.softmax = function (logits, dim) { - if (dim === void 0) { dim = -1; } - if (dim === -1) { - dim = logits.rank - 1; - } - if (dim !== logits.rank - 1) { - throw Error('Softmax along a non-last dimension is not yet supported. ' + - ("Logits was rank " + logits.rank + " and dim was " + dim)); - } - var customOp = globals_1.customGrad(function (logits) { - var keepDims = true; - var lse = logits.logSumExp([dim], keepDims); - var logResult = logits.toFloat().sub(lse); - var y = logResult.exp(); - var gradFunc = function (dy) { - var dyTimesY = dy.mul(y); - var keepDims = true; - return dyTimesY.sub(dyTimesY.sum([dim], keepDims).mul(y)); - }; - return { value: y, gradFunc: gradFunc }; - }); - return customOp(logits); - }; - Ops.softmaxCrossEntropy = function (labels, logits, dim) { - if (dim === void 0) { dim = -1; } - util.assertShapesMatch(labels.shape, logits.shape, 'Error in softmaxCrossEntropy: '); - if (dim === -1) { - dim = logits.rank - 1; - } - if (dim !== logits.rank - 1) { - throw Error("Softmax cross entropy along a non-last dimension is not yet " + - ("supported. Labels / logits was rank " + logits.rank + " ") + - ("and dim was " + dim)); - } - var customOp = globals_1.customGrad(function (labels, logits) { - var predictedProbs = logits.softmax(dim); - var costVector = ops.scalar(1e-5).add(predictedProbs).log().mul(labels).neg(); - var value = costVector.sum([dim]); - var gradFunc = function (dy) { - var dyShape = axis_util.expandShapeToKeepDim(dy.shape, [dim]); - return [ - dy.reshape(dyShape).mul(labels.toFloat().sub(predictedProbs)), - dy.reshape(dyShape).mul(predictedProbs.sub(labels.toFloat())), - ]; - }; - return { value: value, gradFunc: gradFunc }; - }); - return customOp(labels, logits); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }), - operation_1.operation - ], Ops, "softmax", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }), - operation_1.operation - ], Ops, "softmaxCrossEntropy", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../globals":35,"../util":151,"./axis_util":107,"./operation":122,"./ops":123}],133:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.transpose = function (x, perm) { - if (perm == null) { - perm = x.shape.map(function (s, i) { return i; }).reverse(); - } - var der = function (dy) { - var undoPerm = axis_util.getUndoAxesPermutation(perm); - var derX = function () { return dy.transpose(undoPerm); }; - return { x: derX }; - }; - util.assert(x.rank === perm.length, "Error in transpose: rank of input " + x.rank + " " + - ("must match length of perm " + perm + ".")); - return environment_1.ENV.engine.executeKernel('Transpose', { inputs: { x: x }, args: { perm: perm } }, der); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "transpose", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./axis_util":107,"./operation":122}],134:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var ops_1 = require("./ops"); -var selu_util = require("./selu_util"); -var Ops = (function () { - function Ops() { - } - Ops.neg = function (x) { - return environment_1.ENV.engine.executeKernel('Neg', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.neg(); } }; - }); - }; - Ops.ceil = function (x) { - var gradient = function (dy, y) { - return { x: function () { return ops.zeros(y.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Ceil', { inputs: { x: x } }, gradient); - }; - Ops.floor = function (x) { - var gradient = function (dy, y) { - return { x: function () { return ops.zeros(y.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Floor', { inputs: { x: x } }, gradient); - }; - Ops.exp = function (x) { - return environment_1.ENV.engine.executeKernel('Exp', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(y); } }; - }); - }; - Ops.log = function (x) { - return environment_1.ENV.engine.executeKernel('Log', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(x.toFloat()); } }; - }); - }; - Ops.sqrt = function (x) { - return environment_1.ENV.engine.executeKernel('Sqrt', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(x.toFloat().sqrt().mul(ops.scalar(2))); } }; - }); - }; - Ops.square = function (x) { - return environment_1.ENV.engine.executeKernel('Square', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(x.toFloat().mul(ops.scalar(2))); } }; - }); - }; - Ops.abs = function (x) { - return environment_1.ENV.engine.executeKernel('Abs', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(x.toFloat().step(-1)); } }; - }); - }; - Ops.clipByValue = function (x, clipValueMin, clipValueMax) { - util.assert((clipValueMin <= clipValueMax), "Error in clip: min (" + clipValueMin + ") must be" + - ("less than or equal to max (" + clipValueMax + ").")); - return environment_1.ENV.engine.executeKernel('Clip', { inputs: { x: x }, args: { min: clipValueMin, max: clipValueMax } }, function (dy, y) { - return { - x: function () { return dy.where(x.greater(ops.scalar(clipValueMin)) - .logicalAnd(x.less(ops.scalar(clipValueMax))), ops_1.zerosLike(dy)); }, - }; - }); - }; - Ops.relu = function (x) { - return environment_1.ENV.engine.executeKernel('Relu', { inputs: { x: x } }, function (dy, y) { - var stepRes = x.step(); - return { x: function () { return dy.mul(stepRes.toFloat()); } }; - }); - }; - Ops.elu = function (x) { - var der = function (dy) { - return { - x: function () { return dy.mul(eluDer(x)); }, - alpha: function () { - throw new Error('Derivative of prelu with respect to alpha is ' + - 'not implemented yet'); - } - }; - }; - return environment_1.ENV.engine.executeKernel('Elu', { inputs: { x: x } }, der); - }; - Ops.selu = function (x) { - var gradient = function (dy, y) { - return { - x: function () { - var mask = x.greater(ops.scalar(0)); - var scaleAlpha = ops.scalar(selu_util.SELU_SCALEALPHA); - var scale = ops.scalar(selu_util.SELU_SCALE); - var greaterThanZeroDer = dy.mul(scale); - var lessEqualZeroDer = dy.mul(scaleAlpha).mul(x.toFloat().exp()); - var res = ops.where(mask, greaterThanZeroDer, lessEqualZeroDer); - return res; - } - }; - }; - return environment_1.ENV.engine.executeKernel('Selu', { inputs: { x: x } }, gradient); - }; - Ops.leakyRelu = function (x, alpha) { - if (alpha === void 0) { alpha = 0.2; } - var gradient = function (dy, y) { - return { x: function () { return dy.mul(x.step(alpha)); } }; - }; - return environment_1.ENV.engine.executeKernel('LeakyRelu', { inputs: { x: x }, args: { alpha: alpha } }, gradient); - }; - Ops.prelu = function (x, alpha) { - var der = function (dy) { - return { - x: function () { return dy.mul(preluDer(x, alpha)); }, - alpha: function () { - throw new Error('Derivative of prelu with respect to alpha is ' + - 'not implemented yet'); - } - }; - }; - return environment_1.ENV.engine.executeKernel('PReLU', { inputs: { x: x, alpha: alpha } }, der); - }; - Ops.sigmoid = function (x) { - return environment_1.ENV.engine.executeKernel('Sigmoid', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(y.mul(ops.scalar(1).sub(y))); } }; - }); - }; - Ops.sin = function (x) { - return environment_1.ENV.engine.executeKernel('Sin', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().cos().mul(dy); } }; - }); - }; - Ops.cos = function (x) { - return environment_1.ENV.engine.executeKernel('Cos', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().sin().neg().mul(dy); } }; - }); - }; - Ops.tan = function (x) { - return environment_1.ENV.engine.executeKernel('Tan', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(x.cos().square()); } }; - }); - }; - Ops.asin = function (x) { - return environment_1.ENV.engine.executeKernel('Asin', { inputs: { x: x } }, function (dy, y) { - return { - x: function () { return dy.div(Ops.sqrt(ops.scalar(1).sub(x.toFloat().square()))); } - }; - }); - }; - Ops.acos = function (x) { - return environment_1.ENV.engine.executeKernel('Acos', { inputs: { x: x } }, function (dy, y) { - return { - x: function () { return dy.div(Ops.sqrt(ops.scalar(1).sub(x.toFloat().square()))).neg(); } - }; - }); - }; - Ops.atan = function (x) { - return environment_1.ENV.engine.executeKernel('Atan', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(ops.scalar(1).add(x.toFloat().square())); } }; - }); - }; - Ops.sinh = function (x) { - return environment_1.ENV.engine.executeKernel('Sinh', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().cosh().mul(dy); } }; - }); - }; - Ops.cosh = function (x) { - return environment_1.ENV.engine.executeKernel('Cosh', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().sinh().mul(dy); } }; - }); - }; - Ops.tanh = function (x) { - return environment_1.ENV.engine.executeKernel('Tanh', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return ops.scalar(1).sub(y.square()).mul(dy); } }; - }); - }; - Ops.step = function (x, alpha) { - if (alpha === void 0) { alpha = 0.0; } - return environment_1.ENV.engine.executeKernel('Step', { inputs: { x: x }, args: { alpha: alpha } }, function (dy, y) { - return { x: function () { return ops.zeros(y.shape); } }; - }); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "neg", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "ceil", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "floor", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "exp", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "log", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sqrt", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "square", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "abs", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "clipByValue", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "relu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "elu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "selu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "leakyRelu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "prelu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sigmoid", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sin", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "cos", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "tan", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "asin", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "acos", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "atan", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sinh", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "cosh", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "tanh", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "step", null); - return Ops; -}()); -exports.Ops = Ops; -function preluDer(x, alpha) { - return environment_1.ENV.engine.executeKernel('PReLUDer', { inputs: { x: x, alpha: alpha } }); -} -function eluDer(x) { - return environment_1.ENV.engine.executeKernel('EluDer', { inputs: { x: x } }); -} - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122,"./ops":123,"./selu_util":129}],135:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdadeltaOptimizer = (function (_super) { - __extends(AdadeltaOptimizer, _super); - function AdadeltaOptimizer(learningRate, rho, specifiedVariableList, epsilon) { - if (epsilon === void 0) { epsilon = 1e-8; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.accumulatedGrads = {}; - _this.accumulatedUpdates = {}; - _this.accumulatedSquaredGradientsGraph = new tensor_array_map_1.TensorArrayMap(); - _this.accumulatedUpdatesGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.epsilon = globals_1.keep(ops_1.scalar(epsilon)); - _this.rho = globals_1.keep(ops_1.scalar(rho)); - _this.oneMinusRho = globals_1.keep(ops_1.scalar(1 - rho)); - return _this; - } - AdadeltaOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulatedGrads[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulatedGrads[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_1); - }); - } - if (this_1.accumulatedUpdates[variableName] == null) { - var trainable_2 = false; - globals_1.tidy(function () { - _this.accumulatedUpdates[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_2); - }); - } - var gradient = variableGradients[variableName]; - var accumulatedGrad = this_1.accumulatedGrads[variableName]; - var accumulatedUpdate = this_1.accumulatedUpdates[variableName]; - globals_1.tidy(function () { - var newAccumulatedGrad = _this.rho.mul(accumulatedGrad) - .add(_this.oneMinusRho.mul(gradient.square())); - var updates = accumulatedUpdate.add(_this.epsilon) - .sqrt() - .div(accumulatedGrad.add(_this.epsilon).sqrt()) - .mul(gradient); - var newAccumulatedUpdate = _this.rho.mul(accumulatedUpdate) - .add(_this.oneMinusRho.mul(updates.square())); - _this.accumulatedGrads[variableName].assign(newAccumulatedGrad); - _this.accumulatedUpdates[variableName].assign(newAccumulatedUpdate); - var newValue = _this.c.mul(updates).add(value); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - AdadeltaOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.accumulatedSquaredGradientsGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.accumulatedSquaredGradientsGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - _this.accumulatedUpdatesGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdadeltaOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldCache = _this.accumulatedSquaredGradientsGraph.get(node.output); - var oldUpdates = _this.accumulatedUpdatesGraph.get(node.output); - var gradientSquare = math.multiply(gradient, gradient); - var cache = math.scaledArrayAdd(_this.rho, oldCache, math.subtract(_this.one, _this.rho), gradientSquare); - var updates = math.multiply(math.divide(math.sqrt(math.add(oldUpdates, _this.epsilon)), math.sqrt(math.add(oldCache, _this.epsilon))), gradient); - var variable = math.scaledArrayAdd(_this.cGraph, updates, _this.one, oldVariable); - var updateSquare = math.multiply(updates, updates); - var newUpdates = math.scaledArrayAdd(_this.rho, oldUpdates, math.subtract(_this.one, _this.rho), updateSquare); - _this.accumulatedSquaredGradientsGraph.set(node.output, globals_1.keep(cache)); - _this.accumulatedUpdatesGraph.set(node.output, globals_1.keep(newUpdates)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldCache.dispose(); - oldUpdates.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdadeltaOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.epsilon.dispose(); - this.rho.dispose(); - this.oneMinusRho.dispose(); - if (this.one != null) { - this.one.dispose(); - } - if (this.accumulatedSquaredGradientsGraph != null) { - this.accumulatedSquaredGradientsGraph.dispose(); - } - if (this.accumulatedUpdatesGraph != null) { - this.accumulatedUpdatesGraph.dispose(); - } - if (this.accumulatedUpdates != null) { - Object.keys(this.accumulatedUpdates) - .forEach(function (name) { return _this.accumulatedUpdates[name].dispose(); }); - Object.keys(this.accumulatedGrads) - .forEach(function (name) { return _this.accumulatedGrads[name].dispose(); }); - } - }; - return AdadeltaOptimizer; -}(optimizer_1.Optimizer)); -exports.AdadeltaOptimizer = AdadeltaOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],136:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdagradOptimizer = (function (_super) { - __extends(AdagradOptimizer, _super); - function AdagradOptimizer(learningRate, specifiedVariableList, initialAccumulatorValue) { - if (initialAccumulatorValue === void 0) { initialAccumulatorValue = 0.1; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.initialAccumulatorValue = initialAccumulatorValue; - _this.accumulatedGrads = {}; - _this.accumulatedSquaredGradients = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.epsilon = globals_1.keep(ops_1.scalar(1e-8)); - return _this; - } - AdagradOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulatedGrads[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulatedGrads[variableName] = tensor_2.variable(ops_1.fill(value.shape, _this.initialAccumulatorValue), trainable_1); - }); - } - var gradient = variableGradients[variableName]; - var accumulatedGrad = this_1.accumulatedGrads[variableName]; - globals_1.tidy(function () { - var newAccumulatedGrad = accumulatedGrad.add(gradient.square()); - _this.accumulatedGrads[variableName].assign(newAccumulatedGrad); - var newValue = _this.c - .mul(gradient.div(newAccumulatedGrad.add(_this.epsilon).sqrt())) - .add(value); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - AdagradOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.accumulatedSquaredGradients.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.accumulatedSquaredGradients.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdagradOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldCache = _this.accumulatedSquaredGradients.get(node.output); - var gradientSquare = math.multiply(gradient, gradient); - var cache = math.add(oldCache, gradientSquare); - var variable = math.scaledArrayAdd(_this.cGraph, math.divide(gradient, math.add(math.sqrt(cache), _this.epsilon)), _this.one, oldVariable); - _this.accumulatedSquaredGradients.set(node.output, globals_1.keep(cache)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldCache.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdagradOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.epsilon.dispose(); - this.c.dispose(); - if (this.one != null) { - this.one.dispose(); - } - if (this.accumulatedSquaredGradients != null) { - this.accumulatedSquaredGradients.dispose(); - } - if (this.accumulatedGrads != null) { - Object.keys(this.accumulatedGrads) - .forEach(function (name) { return _this.accumulatedGrads[name].dispose(); }); - } - }; - return AdagradOptimizer; -}(optimizer_1.Optimizer)); -exports.AdagradOptimizer = AdagradOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],137:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdamOptimizer = (function (_super) { - __extends(AdamOptimizer, _super); - function AdamOptimizer(learningRate, beta1, beta2, epsilon, specifiedVariableList) { - if (epsilon === void 0) { epsilon = 1e-8; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.accumulatedFirstMoment = {}; - _this.accumulatedSecondMoment = {}; - _this.firstMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.secondMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.eps = globals_1.keep(ops_1.scalar(epsilon)); - _this.beta1 = globals_1.keep(ops_1.scalar(beta1)); - _this.beta2 = globals_1.keep(ops_1.scalar(beta2)); - globals_1.tidy(function () { - _this.accBeta1 = tensor_2.variable(ops_1.scalar(beta1)); - _this.accBeta2 = tensor_2.variable(ops_1.scalar(beta2)); - }); - _this.oneMinusBeta1 = globals_1.keep(ops_1.scalar(1 - beta1)); - _this.oneMinusBeta2 = globals_1.keep(ops_1.scalar(1 - beta2)); - _this.one = globals_1.keep(ops_1.scalar(1)); - return _this; - } - AdamOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - globals_1.tidy(function () { - var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1); - var oneMinusAccBeta2 = _this.one.sub(_this.accBeta2); - for (var variableName in variableGradients) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (_this.accumulatedFirstMoment[variableName] == null) { - var trainable = false; - _this.accumulatedFirstMoment[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - if (_this.accumulatedSecondMoment[variableName] == null) { - var trainable = false; - _this.accumulatedSecondMoment[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - var gradient = variableGradients[variableName]; - var firstMoment = _this.accumulatedFirstMoment[variableName]; - var secondMoment = _this.accumulatedSecondMoment[variableName]; - var newFirstMoment = _this.beta1.mul(firstMoment).add(_this.oneMinusBeta1.mul(gradient)); - var newSecondMoment = _this.beta2.mul(secondMoment) - .add(_this.oneMinusBeta2.mul(gradient.square())); - var biasCorrectedFirstMoment = newFirstMoment.div(oneMinusAccBeta1); - var biasCorrectedSecondMoment = newSecondMoment.div(oneMinusAccBeta2); - _this.accumulatedFirstMoment[variableName].assign(newFirstMoment); - _this.accumulatedSecondMoment[variableName].assign(newSecondMoment); - var newValue = _this.c - .mul(biasCorrectedFirstMoment.div(_this.eps.add(biasCorrectedSecondMoment.sqrt()))) - .add(value); - value.assign(newValue); - } - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - _this.accBeta2.assign(_this.accBeta2.mul(_this.beta2)); - }); - }; - AdamOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.firstMomentGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.firstMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - if (this.secondMomentGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.secondMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdamOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1); - var oneMinusAccBeta2 = _this.one.sub(_this.accBeta2); - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldFirstMoment = _this.firstMomentGraph.get(node.output); - var oldSecondMoment = _this.secondMomentGraph.get(node.output); - var newFirstMoment = math.scaledArrayAdd(_this.beta1, oldFirstMoment, _this.oneMinusBeta1, gradient); - var newSecondMoment = math.scaledArrayAdd(_this.beta2, oldSecondMoment, _this.oneMinusBeta2, gradient.square()); - var biasCorrectedFirstMoment = newFirstMoment.div(oneMinusAccBeta1); - var biasCorrectedSecondMoment = newSecondMoment.div(oneMinusAccBeta2); - var variable = math.scaledArrayAdd(_this.cGraph, biasCorrectedFirstMoment.div(_this.eps.add(biasCorrectedSecondMoment.sqrt())), _this.one, oldVariable); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - _this.firstMomentGraph.set(node.output, globals_1.keep(newFirstMoment)); - _this.secondMomentGraph.set(node.output, globals_1.keep(newSecondMoment)); - oldVariable.dispose(); - gradient.dispose(); - oldFirstMoment.dispose(); - oldSecondMoment.dispose(); - }); - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - _this.accBeta2.assign(_this.accBeta2.mul(_this.beta2)); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdamOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.eps.dispose(); - this.beta1.dispose(); - this.beta2.dispose(); - this.accBeta1.dispose(); - this.accBeta2.dispose(); - this.oneMinusBeta1.dispose(); - this.oneMinusBeta2.dispose(); - this.one.dispose(); - if (this.firstMomentGraph != null) { - this.firstMomentGraph.dispose(); - } - if (this.secondMomentGraph != null) { - this.secondMomentGraph.dispose(); - } - if (this.accumulatedFirstMoment != null) { - Object.keys(this.accumulatedFirstMoment) - .forEach(function (name) { return _this.accumulatedFirstMoment[name].dispose(); }); - } - if (this.accumulatedSecondMoment != null) { - Object.keys(this.accumulatedSecondMoment) - .forEach(function (name) { return _this.accumulatedSecondMoment[name].dispose(); }); - } - }; - return AdamOptimizer; -}(optimizer_1.Optimizer)); -exports.AdamOptimizer = AdamOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],138:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdamaxOptimizer = (function (_super) { - __extends(AdamaxOptimizer, _super); - function AdamaxOptimizer(learningRate, beta1, beta2, epsilon, decay, specifiedVariableList) { - if (epsilon === void 0) { epsilon = 1e-8; } - if (decay === void 0) { decay = 0.0; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.accumulatedFirstMoment = {}; - _this.accumulatedWeightedInfNorm = {}; - _this.firstMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.weightedInfNormGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.eps = globals_1.keep(ops_1.scalar(epsilon)); - _this.beta1 = globals_1.keep(ops_1.scalar(beta1)); - _this.beta2 = globals_1.keep(ops_1.scalar(beta2)); - _this.decay = globals_1.keep(ops_1.scalar(decay)); - globals_1.tidy(function () { - _this.iteration = tensor_2.variable(ops_1.scalar(0)); - _this.accBeta1 = tensor_2.variable(ops_1.scalar(beta1)); - }); - _this.oneMinusBeta1 = globals_1.keep(ops_1.scalar(1 - beta1)); - _this.one = globals_1.keep(ops_1.scalar(1)); - return _this; - } - AdamaxOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - globals_1.tidy(function () { - var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1); - var lr = _this.c.div(_this.one.add(_this.decay.mul(_this.iteration))); - for (var variableName in variableGradients) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (_this.accumulatedFirstMoment[variableName] == null) { - var trainable = false; - _this.accumulatedFirstMoment[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - if (_this.accumulatedWeightedInfNorm[variableName] == null) { - var trainable = false; - _this.accumulatedWeightedInfNorm[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - var gradient = variableGradients[variableName]; - var firstMoment = _this.accumulatedFirstMoment[variableName]; - var weightedInfNorm = _this.accumulatedWeightedInfNorm[variableName]; - var newFirstMoment = _this.beta1.mul(firstMoment).add(_this.oneMinusBeta1.mul(gradient)); - var ut0 = _this.beta2.mul(weightedInfNorm); - var ut1 = gradient.abs(); - var newWeightedInfNorm = ut0.maximum(ut1); - _this.accumulatedFirstMoment[variableName].assign(newFirstMoment); - _this.accumulatedWeightedInfNorm[variableName].assign(newWeightedInfNorm); - var newValue = lr.div(oneMinusAccBeta1) - .mul(newFirstMoment.div(_this.eps.add(newWeightedInfNorm))) - .add(value); - value.assign(newValue); - } - _this.iteration.assign(_this.iteration.add(_this.one)); - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - }); - }; - AdamaxOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.firstMomentGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.firstMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - if (this.weightedInfNormGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.weightedInfNormGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdamaxOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - var lr = _this.cGraph.div(_this.one.add(_this.decay.mul(_this.iteration))); - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldFirstMoment = _this.firstMomentGraph.get(node.output); - var oldWeightedInfNorm = _this.weightedInfNormGraph.get(node.output); - var newFirstMoment = math.scaledArrayAdd(_this.beta1, oldFirstMoment, _this.oneMinusBeta1, gradient); - var ut0 = _this.beta2.mul(oldWeightedInfNorm); - var ut1 = gradient.abs(); - var newWeightedInfNorm = ut0.maximum(ut1); - var variable = math.scaledArrayAdd(_this.one, oldVariable, lr.div(_this.one.sub(_this.accBeta1)), newFirstMoment.div(_this.eps.add(newWeightedInfNorm))); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - _this.firstMomentGraph.set(node.output, globals_1.keep(newFirstMoment)); - _this.weightedInfNormGraph.set(node.output, globals_1.keep(newWeightedInfNorm)); - oldVariable.dispose(); - gradient.dispose(); - oldFirstMoment.dispose(); - oldWeightedInfNorm.dispose(); - }); - _this.iteration.assign(_this.iteration.add(_this.one)); - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdamaxOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.eps.dispose(); - this.accBeta1.dispose(); - this.beta1.dispose(); - this.beta2.dispose(); - this.oneMinusBeta1.dispose(); - this.decay.dispose(); - this.iteration.dispose(); - this.one.dispose(); - if (this.firstMomentGraph != null) { - this.firstMomentGraph.dispose(); - } - if (this.weightedInfNormGraph != null) { - this.weightedInfNormGraph.dispose(); - } - if (this.accumulatedFirstMoment != null) { - Object.keys(this.accumulatedFirstMoment) - .forEach(function (name) { return _this.accumulatedFirstMoment[name].dispose(); }); - } - if (this.accumulatedWeightedInfNorm != null) { - Object.keys(this.accumulatedWeightedInfNorm) - .forEach(function (name) { return _this.accumulatedWeightedInfNorm[name].dispose(); }); - } - }; - return AdamaxOptimizer; -}(optimizer_1.Optimizer)); -exports.AdamaxOptimizer = AdamaxOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],139:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var sgd_optimizer_1 = require("./sgd_optimizer"); -var MomentumOptimizer = (function (_super) { - __extends(MomentumOptimizer, _super); - function MomentumOptimizer(learningRate, momentum, specifiedVariableList) { - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.momentum = momentum; - _this.m = ops_1.scalar(_this.momentum); - _this.accumulations = {}; - return _this; - } - MomentumOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulations[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulations[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_1); - }); - } - var accumulation = this_1.accumulations[variableName]; - var gradient = variableGradients[variableName]; - globals_1.tidy(function () { - var newAccumulation = _this.m.mul(accumulation).add(gradient); - _this.accumulations[variableName].assign(newAccumulation); - var newValue = _this.c.mul(newAccumulation).add(value); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - MomentumOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.variableVelocitiesGraph == null) { - this.variableVelocitiesGraph = new tensor_array_map_1.TensorArrayMap(); - } - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.variableVelocitiesGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.variableVelocitiesGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - MomentumOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldVelocity = _this.variableVelocitiesGraph.get(node.output); - var velocity = math.scaledArrayAdd(_this.m, oldVelocity, _this.one, gradient); - var variable = math.scaledArrayAdd(_this.cGraph, velocity, _this.one, oldVariable); - _this.variableVelocitiesGraph.set(node.output, globals_1.keep(velocity)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldVelocity.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - MomentumOptimizer.prototype.dispose = function () { - _super.prototype.dispose.call(this); - this.m.dispose(); - if (this.one != null) { - this.one.dispose(); - } - if (this.variableVelocitiesGraph != null) { - this.variableVelocitiesGraph.dispose(); - } - if (this.accumulations != null) { - for (var variableName in this.accumulations) { - this.accumulations[variableName].dispose(); - } - } - }; - MomentumOptimizer.prototype.setMomentum = function (momentum) { - this.momentum = momentum; - }; - return MomentumOptimizer; -}(sgd_optimizer_1.SGDOptimizer)); -exports.MomentumOptimizer = MomentumOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./sgd_optimizer":143}],140:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var globals_1 = require("../globals"); -var session_util = require("../graph/session_util"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var Optimizer = (function () { - function Optimizer(learningRate, specifiedVariableList) { - this.learningRate = learningRate; - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - if (specifiedVariableList != null) { - this.specifiedVariableNodes = specifiedVariableList; - } - } - Optimizer.prototype.minimize = function (f, returnCost, varList) { - if (returnCost === void 0) { returnCost = false; } - var _a = this.computeGradients(f, varList), value = _a.value, grads = _a.grads; - this.applyGradients(grads); - var varNames = Object.keys(grads); - varNames.forEach(function (varName) { return grads[varName].dispose(); }); - if (returnCost) { - return value; - } - else { - value.dispose(); - return null; - } - }; - Optimizer.prototype.computeGradients = function (f, varList) { - return globals_1.variableGrads(f, varList); - }; - Optimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - this.variableNodes = this.specifiedVariableNodes == null ? - session_util.getVariableNodesFromEvaluationSet(runtime.nodes) : - this.specifiedVariableNodes; - if (batchSize !== this.prevBatchSize) { - if (this.cGraph != null) { - this.cGraph.dispose(); - } - this.prevBatchSize = batchSize; - this.cGraph = math.keep(ops.scalar(-this.learningRate / batchSize)); - } - this.variableNodes.forEach(function (node) { return _this.variableGradients.set(node.output, math.keep(tensor_1.Tensor.zeros(node.output.shape))); }); - }; - Optimizer.prototype.afterExample = function (math, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var gradient = gradientArrayMap.get(node.output); - var accumulatedGradient = _this.variableGradients.get(node.output); - _this.variableGradients.set(node.output, globals_1.keep(math.add(gradient, accumulatedGradient))); - accumulatedGradient.dispose(); - }); - }); - }; - Optimizer.prototype.dispose = function () { - if (this.cGraph != null) { - this.cGraph.dispose(); - } - if (this.variableNodes != null) { - this.variableNodes.forEach(function (node) { - node.data.dispose(); - }); - } - if (this.specifiedVariableNodes != null) { - this.specifiedVariableNodes.forEach(function (node) { - node.data.dispose(); - }); - } - }; - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers' }) - ], Optimizer.prototype, "minimize", null); - Optimizer = __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Classes', namespace: 'train' }) - ], Optimizer); - return Optimizer; -}()); -exports.Optimizer = Optimizer; - -},{"../doc":32,"../globals":35,"../graph/session_util":65,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146}],141:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var adadelta_optimizer_1 = require("./adadelta_optimizer"); -var adagrad_optimizer_1 = require("./adagrad_optimizer"); -var adam_optimizer_1 = require("./adam_optimizer"); -var adamax_optimizer_1 = require("./adamax_optimizer"); -var momentum_optimizer_1 = require("./momentum_optimizer"); -var rmsprop_optimizer_1 = require("./rmsprop_optimizer"); -var sgd_optimizer_1 = require("./sgd_optimizer"); -var OptimizerConstructors = (function () { - function OptimizerConstructors() { - } - OptimizerConstructors.sgd = function (learningRate) { - return new sgd_optimizer_1.SGDOptimizer(learningRate); - }; - OptimizerConstructors.momentum = function (learningRate, momentum) { - return new momentum_optimizer_1.MomentumOptimizer(learningRate, momentum); - }; - OptimizerConstructors.rmsprop = function (learningRate, decay, momentum, epsilon) { - if (decay === void 0) { decay = .9; } - if (momentum === void 0) { momentum = 0.0; } - if (epsilon === void 0) { epsilon = 1e-8; } - return new rmsprop_optimizer_1.RMSPropOptimizer(learningRate, decay, momentum, undefined, epsilon); - }; - OptimizerConstructors.adam = function (learningRate, beta1, beta2, epsilon) { - if (learningRate === void 0) { learningRate = 0.001; } - if (beta1 === void 0) { beta1 = 0.9; } - if (beta2 === void 0) { beta2 = 0.999; } - if (epsilon === void 0) { epsilon = 1e-8; } - return new adam_optimizer_1.AdamOptimizer(learningRate, beta1, beta2, epsilon, undefined); - }; - OptimizerConstructors.adadelta = function (learningRate, rho, epsilon) { - if (learningRate === void 0) { learningRate = .001; } - if (rho === void 0) { rho = .95; } - if (epsilon === void 0) { epsilon = 1e-8; } - return new adadelta_optimizer_1.AdadeltaOptimizer(learningRate, rho, undefined, epsilon); - }; - OptimizerConstructors.adamax = function (learningRate, beta1, beta2, epsilon, decay) { - if (learningRate === void 0) { learningRate = 0.002; } - if (beta1 === void 0) { beta1 = 0.9; } - if (beta2 === void 0) { beta2 = 0.999; } - if (epsilon === void 0) { epsilon = 1e-8; } - if (decay === void 0) { decay = 0.0; } - return new adamax_optimizer_1.AdamaxOptimizer(learningRate, beta1, beta2, epsilon, decay, undefined); - }; - OptimizerConstructors.adagrad = function (learningRate, initialAccumulatorValue) { - if (initialAccumulatorValue === void 0) { initialAccumulatorValue = 0.1; } - return new adagrad_optimizer_1.AdagradOptimizer(learningRate, undefined, initialAccumulatorValue); - }; - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "sgd", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "momentum", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "rmsprop", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adam", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adadelta", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adamax", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adagrad", null); - return OptimizerConstructors; -}()); -exports.OptimizerConstructors = OptimizerConstructors; - -},{"../doc":32,"./adadelta_optimizer":135,"./adagrad_optimizer":136,"./adam_optimizer":137,"./adamax_optimizer":138,"./momentum_optimizer":139,"./rmsprop_optimizer":142,"./sgd_optimizer":143}],142:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var session_util = require("../graph/session_util"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var RMSPropOptimizer = (function (_super) { - __extends(RMSPropOptimizer, _super); - function RMSPropOptimizer(learningRate, decay, momentum, specifiedVariableList, epsilon) { - if (decay === void 0) { decay = 0.9; } - if (momentum === void 0) { momentum = 0.0; } - if (epsilon === void 0) { epsilon = 1e-8; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.accumulatedMeanSquares = {}; - _this.accumulatedMoments = {}; - _this.accumulatedMeanSquaredGraph = new tensor_array_map_1.TensorArrayMap(); - _this.accumulatedMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(learningRate)); - _this.epsilon = globals_1.keep(ops_1.scalar(epsilon)); - _this.decay = globals_1.keep(ops_1.scalar(decay)); - _this.momentum = globals_1.keep(ops_1.scalar(momentum)); - _this.oneMinusDecay = globals_1.keep(ops_1.scalar(1 - decay)); - return _this; - } - RMSPropOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulatedMeanSquares[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulatedMeanSquares[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_1); - }); - } - if (this_1.accumulatedMoments[variableName] == null) { - var trainable_2 = false; - globals_1.tidy(function () { - _this.accumulatedMoments[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_2); - }); - } - var accumulatedMeanSquare = this_1.accumulatedMeanSquares[variableName]; - var accumulatedMoments = this_1.accumulatedMoments[variableName]; - var gradient = variableGradients[variableName]; - globals_1.tidy(function () { - var newAccumulatedMeanSquare = _this.decay.mul(accumulatedMeanSquare) - .add(_this.oneMinusDecay.mul(gradient.square())); - var newAccumulatedMoments = _this.momentum.mul(accumulatedMoments) - .add(_this.c.mul(gradient).div(newAccumulatedMeanSquare.add(_this.epsilon).sqrt())); - _this.accumulatedMeanSquares[variableName].assign(newAccumulatedMeanSquare); - _this.accumulatedMoments[variableName].assign(newAccumulatedMoments); - var newValue = value.sub(newAccumulatedMoments); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - RMSPropOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - this.variableNodes = this.specifiedVariableNodes == null ? - session_util.getVariableNodesFromEvaluationSet(runtime.nodes) : - this.specifiedVariableNodes; - if (batchSize !== this.prevBatchSize) { - if (this.cGraph != null) { - this.cGraph.dispose(); - } - this.prevBatchSize = batchSize; - this.cGraph = math.keep(ops_1.scalar(this.learningRate / batchSize)); - } - this.variableNodes.forEach(function (node) { return _this.variableGradients.set(node.output, math.keep(tensor_1.Tensor.zeros(node.output.shape))); }); - if (this.accumulatedMeanSquaredGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.accumulatedMeanSquaredGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - _this.accumulatedMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - RMSPropOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldMeanSquare = _this.accumulatedMeanSquaredGraph.get(node.output); - var oldMoment = _this.accumulatedMomentGraph.get(node.output); - var meanSquare = math.scaledArrayAdd(_this.decay, oldMeanSquare, _this.oneMinusDecay, gradient.square()); - var moment = math.scaledArrayAdd(_this.momentum, oldMoment, _this.cGraph, gradient.div(meanSquare.add(_this.epsilon).sqrt())); - var variable = oldVariable.sub(moment); - _this.accumulatedMeanSquaredGraph.set(node.output, globals_1.keep(meanSquare)); - _this.accumulatedMomentGraph.set(node.output, globals_1.keep(moment)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldMeanSquare.dispose(); - oldMoment.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - RMSPropOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.epsilon.dispose(); - this.decay.dispose(); - this.momentum.dispose(); - this.oneMinusDecay.dispose(); - if (this.accumulatedMeanSquaredGraph != null) { - this.accumulatedMeanSquaredGraph.dispose(); - } - if (this.accumulatedMomentGraph != null) { - this.accumulatedMomentGraph.dispose(); - } - if (this.accumulatedMeanSquares != null) { - Object.keys(this.accumulatedMeanSquares) - .forEach(function (name) { return _this.accumulatedMeanSquares[name].dispose(); }); - } - if (this.accumulatedMoments != null) { - Object.keys(this.accumulatedMoments) - .forEach(function (name) { return _this.accumulatedMoments[name].dispose(); }); - } - }; - return RMSPropOptimizer; -}(optimizer_1.Optimizer)); -exports.RMSPropOptimizer = RMSPropOptimizer; - -},{"../environment":34,"../globals":35,"../graph/session_util":65,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],143:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var optimizer_1 = require("./optimizer"); -var SGDOptimizer = (function (_super) { - __extends(SGDOptimizer, _super); - function SGDOptimizer(learningRate, specifiedVariableList) { - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.setLearningRate(learningRate); - return _this; - } - SGDOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var varNames = Object.keys(variableGradients); - varNames.forEach(function (varName) { - var gradient = variableGradients[varName]; - var value = environment_1.ENV.engine.registeredVariables[varName]; - globals_1.tidy(function () { - var newValue = _this.c.mul(gradient).add(value); - value.assign(newValue); - }); - }); - }; - SGDOptimizer.prototype.setLearningRate = function (learningRate) { - this.learningRate = learningRate; - if (this.c != null) { - this.c.dispose(); - } - this.c = environment_1.ENV.math.keep(ops_1.scalar(-learningRate)); - }; - SGDOptimizer.prototype.dispose = function () { - this.c.dispose(); - if (this.one != null) { - this.one.dispose(); - } - _super.prototype.dispose.call(this); - }; - SGDOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var variable = math.scaledArrayAdd(_this.cGraph, gradient, _this.one, oldVariable); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - return SGDOptimizer; -}(optimizer_1.Optimizer)); -exports.SGDOptimizer = SGDOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"./optimizer":140}],144:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("./util"); -var Profiler = (function () { - function Profiler(backendTimer, logger) { - this.backendTimer = backendTimer; - this.logger = logger; - if (logger == null) { - this.logger = new Logger(); - } - } - Profiler.prototype.profileKernel = function (kernelName, f) { - var _this = this; - var result; - var holdResultWrapperFn = function () { - result = f(); - }; - var timer = this.backendTimer.time(holdResultWrapperFn); - var vals = result.dataSync(); - util.checkForNaN(vals, result.dtype, kernelName); - timer.then(function (timing) { - _this.logger.logKernelProfile(kernelName, result, vals, timing.kernelMs); - }); - return result; - }; - return Profiler; -}()); -exports.Profiler = Profiler; -var Logger = (function () { - function Logger() { - } - Logger.prototype.logKernelProfile = function (kernelName, result, vals, timeMs) { - var time = util.rightPad(timeMs + "ms", 9); - var paddedName = util.rightPad(kernelName, 25); - var rank = result.rank; - var size = result.size; - var shape = util.rightPad(result.shape.toString(), 14); - console.log("%c" + paddedName + "\t%c" + time + "\t%c" + rank + "D " + shape + "\t%c" + size, 'font-weight:bold', 'color:red', 'color:blue', 'color: orange'); - }; - return Logger; -}()); -exports.Logger = Logger; - -},{"./util":151}],145:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("./util"); -var tensor_1 = require("./tensor"); -function getFilteredNodesXToY(tape, xs, y) { - var tensorsFromX = {}; - var nodesFromX = {}; - for (var i = 0; i < xs.length; i++) { - tensorsFromX[xs[i].id] = true; - } - for (var i = 0; i < tape.length; i++) { - var node = tape[i]; - var nodeInputs = node.inputAndArgs.inputs; - for (var inputName in nodeInputs) { - var input = nodeInputs[inputName]; - var anyInputFromX = false; - for (var j = 0; j < xs.length; j++) { - if (tensorsFromX[input.id]) { - if (node.output instanceof tensor_1.Tensor) { - tensorsFromX[node.output.id] = true; - } - else { - var keys = Object.keys(node.output); - for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { - var key = keys_1[_i]; - tensorsFromX[node.output[key].id] = true; - } - } - anyInputFromX = true; - nodesFromX[node.id] = true; - break; - } - } - if (anyInputFromX) { - break; - } - } - } - var tensorsLeadToY = {}; - tensorsLeadToY[y.id] = true; - var nodesToY = {}; - for (var i = tape.length - 1; i >= 0; i--) { - var node = tape[i]; - var nodeInputs = node.inputAndArgs.inputs; - var outputs = []; - if (node.output instanceof tensor_1.Tensor) { - outputs.push(node.output); - } - else { - var keys = Object.keys(node.output); - for (var _a = 0, keys_2 = keys; _a < keys_2.length; _a++) { - var key = keys_2[_a]; - outputs.push(node.output[key]); - } - } - for (var j = 0; j < outputs.length; j++) { - if (tensorsLeadToY[outputs[j].id]) { - for (var inputName in nodeInputs) { - tensorsLeadToY[nodeInputs[inputName].id] = true; - nodesToY[node.id] = true; - } - break; - } - } - } - var filteredTape = []; - for (var i = 0; i < tape.length; i++) { - var node = tape[i]; - if (nodesFromX[node.id] && nodesToY[node.id]) { - var prunedInputs = {}; - for (var inputName in node.inputAndArgs.inputs) { - var nodeInput = node.inputAndArgs.inputs[inputName]; - if (tensorsFromX[nodeInput.id]) { - prunedInputs[inputName] = nodeInput; - } - } - var prunedOutputs = void 0; - if (node.output instanceof tensor_1.Tensor) { - prunedOutputs = node.output; - } - else { - prunedOutputs = {}; - for (var outputName in node.output) { - var output = node.output[outputName]; - if (tensorsLeadToY[output.id]) { - prunedOutputs[outputName] = node.output[outputName]; - } - } - } - var prunedNode = Object.assign({}, node); - prunedNode.inputAndArgs = { inputs: prunedInputs }; - prunedNode.output = prunedOutputs; - filteredTape.push(prunedNode); - } - } - return filteredTape; -} -exports.getFilteredNodesXToY = getFilteredNodesXToY; -function backpropagateGradients(tensorAccumulatedGradientMap, filteredTape) { - for (var i = filteredTape.length - 1; i >= 0; i--) { - var node = filteredTape[i]; - var dy = void 0; - if (node.output instanceof tensor_1.Tensor) { - dy = tensorAccumulatedGradientMap[node.output.id]; - } - else { - dy = {}; - var keys = Object.keys(node.output); - for (var _i = 0, keys_3 = keys; _i < keys_3.length; _i++) { - var key = keys_3[_i]; - dy[key] = tensorAccumulatedGradientMap[node.output[key].id]; - } - } - if (node.gradient == null) { - throw new Error("Cannot compute gradient: gradient function not found " + - ("for " + node.name + ".")); - } - var inputGradients = node.gradient(dy, node.output); - for (var inputName in node.inputAndArgs.inputs) { - if (!(inputName in inputGradients)) { - throw new Error("Cannot backprop through input " + inputName + ". " + - ("Available gradients found: " + Object.keys(inputGradients) + ".")); - } - var dx = inputGradients[inputName](); - var x = node.inputAndArgs.inputs[inputName]; - if (!util.arraysEqual(dx.shape, x.shape)) { - throw new Error("Error in gradient for op " + node.name + ". The gradient of input " + - ("'" + inputName + "' has shape '" + dx.shape + "', which does not match ") + - ("the shape of the input '" + x.shape + "'")); - } - if (tensorAccumulatedGradientMap[x.id] == null) { - tensorAccumulatedGradientMap[x.id] = dx; - } - else { - var curGradient = tensorAccumulatedGradientMap[x.id]; - tensorAccumulatedGradientMap[x.id] = curGradient.add(dx); - curGradient.dispose(); - } - } - } -} -exports.backpropagateGradients = backpropagateGradients; -function extractTensorsFromScopeResult(result) { - if (result == null) { - return []; - } - if (result instanceof tensor_1.Tensor) { - return [result]; - } - var list = []; - var resultObj = result; - for (var k in resultObj) { - var sublist = util.flatten(resultObj[k]).filter(function (x) { return x instanceof tensor_1.Tensor; }); - list.push.apply(list, sublist); - } - return list; -} -exports.extractTensorsFromScopeResult = extractTensorsFromScopeResult; -function stripUndefinedInputsFromInputConfig(config) { - var keys = Object.keys(config.inputs); - keys.forEach(function (key) { - if (config.inputs[key] == null) { - delete config.inputs[key]; - } - }); - return config; -} -exports.stripUndefinedInputsFromInputConfig = stripUndefinedInputsFromInputConfig; - -},{"./tensor":146,"./util":151}],146:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var environment_1 = require("./environment"); -var ops = require("./ops/ops"); -var util = require("./util"); -var TensorBuffer = (function () { - function TensorBuffer(shape, dtype, values) { - this.shape = shape; - this.dtype = dtype; - this.values = values; - if (values != null) { - var n = values.length; - var size = util.sizeFromShape(shape); - util.assert(n === size, "Length of values '" + n + "' does not match the size " + - ("inferred by the shape '" + size + "'")); - } - this.values = - values || util.getTypedArrayFromDType(dtype, util.sizeFromShape(shape)); - this.strides = computeStrides(shape); - } - TensorBuffer.prototype.set = function (value) { - var locs = []; - for (var _i = 1; _i < arguments.length; _i++) { - locs[_i - 1] = arguments[_i]; - } - if (locs.length === 0) { - locs = [0]; - } - util.assert(locs.length === this.rank, "The number of provided coordinates (" + locs.length + ") must " + - ("match the rank (" + this.rank + ")")); - var index = this.locToIndex(locs); - this.values[index] = value; - }; - TensorBuffer.prototype.get = function () { - var locs = []; - for (var _i = 0; _i < arguments.length; _i++) { - locs[_i] = arguments[_i]; - } - if (locs.length === 0) { - locs = [0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return this.values[index]; - }; - TensorBuffer.prototype.locToIndex = function (locs) { - if (this.rank === 0) { - return 0; - } - else if (this.rank === 1) { - return locs[0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return index; - }; - TensorBuffer.prototype.indexToLoc = function (index) { - if (this.rank === 0) { - return []; - } - else if (this.rank === 1) { - return [index]; - } - var locs = new Array(this.shape.length); - for (var i = 0; i < locs.length - 1; ++i) { - locs[i] = Math.floor(index / this.strides[i]); - index -= locs[i] * this.strides[i]; - } - locs[locs.length - 1] = index; - return locs; - }; - Object.defineProperty(TensorBuffer.prototype, "rank", { - get: function () { - return this.shape.length; - }, - enumerable: true, - configurable: true - }); - TensorBuffer.prototype.toTensor = function () { - return Tensor.make(this.shape, { values: this.values }, this.dtype); - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], TensorBuffer.prototype, "set", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], TensorBuffer.prototype, "get", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], TensorBuffer.prototype, "toTensor", null); - TensorBuffer = __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], TensorBuffer); - return TensorBuffer; -}()); -exports.TensorBuffer = TensorBuffer; -var Tensor = (function () { - function Tensor(shape, dtype, values, dataId) { - this.isDisposed = false; - this.size = util.sizeFromShape(shape); - if (values != null) { - util.assert(this.size === values.length, "Constructing tensor of shape (" + this.size + ") should match the " + - ("length of values (" + values.length + ")")); - } - this.shape = shape; - this.dtype = dtype || 'float32'; - this.strides = computeStrides(shape); - this.dataId = dataId != null ? dataId : {}; - this.id = Tensor_1.nextId++; - this.rankType = (this.rank < 5 ? this.rank.toString() : 'higher'); - environment_1.ENV.engine.registerTensor(this); - if (values != null) { - environment_1.ENV.engine.write(this.dataId, values); - } - } - Tensor_1 = Tensor; - Tensor.ones = function (shape, dtype) { - return ops.ones(shape, dtype); - }; - Tensor.zeros = function (shape, dtype) { - return ops.zeros(shape, dtype); - }; - Tensor.onesLike = function (x) { - return ops.onesLike(x); - }; - Tensor.zerosLike = function (x) { - return ops.zerosLike(x); - }; - Tensor.like = function (x) { - return ops.clone(x); - }; - Tensor.make = function (shape, data, dtype) { - return new Tensor_1(shape, dtype, data.values, data.dataId); - }; - Tensor.fromPixels = function (pixels, numChannels) { - if (numChannels === void 0) { numChannels = 3; } - return ops.fromPixels(pixels, numChannels); - }; - Tensor.rand = function (shape, randFunction, dtype) { - return ops.rand(shape, randFunction, dtype); - }; - Tensor.randNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - return ops.randomNormal(shape, mean, stdDev, dtype, seed); - }; - Tensor.randTruncatedNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - return ops.truncatedNormal(shape, mean, stdDev, dtype, seed); - }; - Tensor.randUniform = function (shape, a, b, dtype) { - return ops.randomUniform(shape, a, b, dtype); - }; - Tensor.prototype.flatten = function () { - this.throwIfDisposed(); - return this.as1D(); - }; - Tensor.prototype.asScalar = function () { - this.throwIfDisposed(); - util.assert(this.size === 1, 'The array must have only 1 element.'); - return this.reshape([]); - }; - Tensor.prototype.as1D = function () { - this.throwIfDisposed(); - return this.reshape([this.size]); - }; - Tensor.prototype.as2D = function (rows, columns) { - this.throwIfDisposed(); - return this.reshape([rows, columns]); - }; - Tensor.prototype.as3D = function (rows, columns, depth) { - this.throwIfDisposed(); - return this.reshape([rows, columns, depth]); - }; - Tensor.prototype.as4D = function (rows, columns, depth, depth2) { - this.throwIfDisposed(); - return this.reshape([rows, columns, depth, depth2]); - }; - Tensor.prototype.asType = function (dtype) { - this.throwIfDisposed(); - return ops.cast(this, dtype); - }; - Object.defineProperty(Tensor.prototype, "rank", { - get: function () { - return this.shape.length; - }, - enumerable: true, - configurable: true - }); - Tensor.prototype.get = function () { - var locs = []; - for (var _i = 0; _i < arguments.length; _i++) { - locs[_i] = arguments[_i]; - } - this.throwIfDisposed(); - if (locs.length === 0) { - locs = [0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return this.dataSync()[index]; - }; - Tensor.prototype.val = function () { - var locs = []; - for (var _i = 0; _i < arguments.length; _i++) { - locs[_i] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (locs.length === 0) { - locs = [0]; - } - this.throwIfDisposed(); - return [4, this.data()]; - case 1: - _a.sent(); - return [2, this.get.apply(this, locs)]; - } - }); - }); - }; - Tensor.prototype.locToIndex = function (locs) { - this.throwIfDisposed(); - if (this.rank === 0) { - return 0; - } - else if (this.rank === 1) { - return locs[0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return index; - }; - Tensor.prototype.indexToLoc = function (index) { - this.throwIfDisposed(); - if (this.rank === 0) { - return []; - } - else if (this.rank === 1) { - return [index]; - } - var locs = new Array(this.shape.length); - for (var i = 0; i < locs.length - 1; ++i) { - locs[i] = Math.floor(index / this.strides[i]); - index -= locs[i] * this.strides[i]; - } - locs[locs.length - 1] = index; - return locs; - }; - Tensor.prototype.getValues = function () { - return this.dataSync(); - }; - Tensor.prototype.getValuesAsync = function () { - return this.data(); - }; - Tensor.prototype.buffer = function () { - return ops.buffer(this.shape, this.dtype, this.dataSync()); - }; - Tensor.prototype.data = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - this.throwIfDisposed(); - return [2, environment_1.ENV.engine.read(this.dataId)]; - }); - }); - }; - Tensor.prototype.dataSync = function () { - this.throwIfDisposed(); - return environment_1.ENV.engine.readSync(this.dataId); - }; - Tensor.prototype.dispose = function () { - if (this.isDisposed) { - return; - } - this.isDisposed = true; - environment_1.ENV.engine.disposeTensor(this); - }; - Tensor.prototype.throwIfDisposed = function () { - if (this.isDisposed) { - throw new Error("Tensor is disposed."); - } - }; - Tensor.prototype.toFloat = function () { - return this.asType('float32'); - }; - Tensor.prototype.toInt = function () { - return this.asType('int32'); - }; - Tensor.prototype.toBool = function () { - return this.asType('bool'); - }; - Tensor.prototype.print = function (verbose) { - if (verbose === void 0) { verbose = false; } - return ops.print(this, verbose); - }; - Tensor.prototype.reshape = function (newShape) { - this.throwIfDisposed(); - return ops.reshape(this, newShape); - }; - Tensor.prototype.reshapeAs = function (x) { - this.throwIfDisposed(); - return this.reshape(x.shape); - }; - Tensor.prototype.expandDims = function (axis) { - if (axis === void 0) { axis = 0; } - return ops.expandDims(this, axis); - }; - Tensor.prototype.squeeze = function (axis) { - this.throwIfDisposed(); - return ops.squeeze(this, axis); - }; - Tensor.prototype.clone = function () { - this.throwIfDisposed(); - return ops.clone(this); - }; - Tensor.prototype.tile = function (reps) { - this.throwIfDisposed(); - return ops.tile(this, reps); - }; - Tensor.prototype.gather = function (indices, axis) { - if (axis === void 0) { axis = 0; } - this.throwIfDisposed(); - return ops.gather(this, indices); - }; - Tensor.prototype.matMul = function (b, transposeA, transposeB) { - if (transposeA === void 0) { transposeA = false; } - if (transposeB === void 0) { transposeB = false; } - this.throwIfDisposed(); - return ops.matMul(this, b, transposeA, transposeB); - }; - Tensor.prototype.norm = function (ord, axis, keepDims) { - if (ord === void 0) { ord = 'euclidean'; } - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.norm(this, ord, axis, keepDims); - }; - Tensor.prototype.slice = function (begin, size) { - this.throwIfDisposed(); - return ops.slice(this, begin, size); - }; - Tensor.prototype.reverse = function (axis) { - this.throwIfDisposed(); - return ops.reverse(this, axis); - }; - Tensor.prototype.concat = function (x, axis) { - if (axis === void 0) { axis = 0; } - this.throwIfDisposed(); - return ops.concat([this, x], axis); - }; - Tensor.prototype.stack = function (x, axis) { - if (axis === void 0) { axis = 0; } - return ops.stack([this, x], axis); - }; - Tensor.prototype.pad = function (paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - return ops.pad(this, paddings, constantValue); - }; - Tensor.prototype.batchNormalization = function (mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - this.throwIfDisposed(); - return ops.batchNormalization(this, mean, variance, varianceEpsilon, scale, offset); - }; - Tensor.prototype.logSumExp = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.logSumExp(this, axis, keepDims); - }; - Tensor.prototype.sum = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.sum(this, axis, keepDims); - }; - Tensor.prototype.mean = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.mean(this, axis, keepDims); - }; - Tensor.prototype.min = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.min(this, axis, keepDims); - }; - Tensor.prototype.max = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.max(this, axis, keepDims); - }; - Tensor.prototype.argMin = function (axis) { - if (axis === void 0) { axis = null; } - this.throwIfDisposed(); - return ops.argMin(this, axis); - }; - Tensor.prototype.argMax = function (axis) { - if (axis === void 0) { axis = null; } - this.throwIfDisposed(); - return ops.argMax(this, axis); - }; - Tensor.prototype.add = function (x) { - this.throwIfDisposed(); - return ops.add(this, x); - }; - Tensor.prototype.addStrict = function (x) { - this.throwIfDisposed(); - return ops.addStrict(this, x); - }; - Tensor.prototype.sub = function (x) { - this.throwIfDisposed(); - return ops.sub(this, x); - }; - Tensor.prototype.subStrict = function (x) { - this.throwIfDisposed(); - return ops.subStrict(this, x); - }; - Tensor.prototype.pow = function (exp) { - this.throwIfDisposed(); - return ops.pow(this, exp); - }; - Tensor.prototype.powStrict = function (exp) { - this.throwIfDisposed(); - return ops.powStrict(this, exp); - }; - Tensor.prototype.mul = function (x) { - this.throwIfDisposed(); - return ops.mul(this, x); - }; - Tensor.prototype.mulStrict = function (x) { - this.throwIfDisposed(); - return ops.mulStrict(this, x); - }; - Tensor.prototype.div = function (x) { - this.throwIfDisposed(); - return ops.div(this, x); - }; - Tensor.prototype.divStrict = function (x) { - this.throwIfDisposed(); - return ops.divStrict(this, x); - }; - Tensor.prototype.minimum = function (x) { - this.throwIfDisposed(); - return ops.minimum(this, x); - }; - Tensor.prototype.minimumStrict = function (x) { - this.throwIfDisposed(); - return ops.minimumStrict(this, x); - }; - Tensor.prototype.maximum = function (x) { - this.throwIfDisposed(); - return ops.maximum(this, x); - }; - Tensor.prototype.maximumStrict = function (x) { - this.throwIfDisposed(); - return ops.maximumStrict(this, x); - }; - Tensor.prototype.transpose = function (perm) { - this.throwIfDisposed(); - return ops.transpose(this, perm); - }; - Tensor.prototype.notEqual = function (x) { - this.throwIfDisposed(); - return ops.notEqual(this, x); - }; - Tensor.prototype.notEqualStrict = function (x) { - this.throwIfDisposed(); - return ops.notEqualStrict(this, x); - }; - Tensor.prototype.less = function (x) { - this.throwIfDisposed(); - return ops.less(this, x); - }; - Tensor.prototype.lessStrict = function (x) { - this.throwIfDisposed(); - return ops.lessStrict(this, x); - }; - Tensor.prototype.equal = function (x) { - this.throwIfDisposed(); - return ops.equal(this, x); - }; - Tensor.prototype.equalStrict = function (x) { - this.throwIfDisposed(); - return ops.equalStrict(this, x); - }; - Tensor.prototype.lessEqual = function (x) { - this.throwIfDisposed(); - return ops.lessEqual(this, x); - }; - Tensor.prototype.lessEqualStrict = function (x) { - this.throwIfDisposed(); - return ops.lessEqualStrict(this, x); - }; - Tensor.prototype.greater = function (x) { - this.throwIfDisposed(); - return ops.greater(this, x); - }; - Tensor.prototype.greaterStrict = function (x) { - this.throwIfDisposed(); - return ops.greaterStrict(this, x); - }; - Tensor.prototype.greaterEqual = function (x) { - this.throwIfDisposed(); - return ops.greaterEqual(this, x); - }; - Tensor.prototype.greaterEqualStrict = function (x) { - this.throwIfDisposed(); - return ops.greaterEqualStrict(this, x); - }; - Tensor.prototype.logicalAnd = function (x) { - this.throwIfDisposed(); - return ops.logicalAnd(this, x); - }; - Tensor.prototype.logicalOr = function (x) { - this.throwIfDisposed(); - return ops.logicalOr(this, x); - }; - Tensor.prototype.logicalXor = function (x) { - this.throwIfDisposed(); - return ops.logicalXor(this, x); - }; - Tensor.prototype.where = function (condition, x) { - this.throwIfDisposed(); - return ops.where(condition, this, x); - }; - Tensor.prototype.neg = function () { - this.throwIfDisposed(); - return ops.neg(this); - }; - Tensor.prototype.ceil = function () { - this.throwIfDisposed(); - return ops.ceil(this); - }; - Tensor.prototype.floor = function () { - this.throwIfDisposed(); - return ops.floor(this); - }; - Tensor.prototype.exp = function () { - this.throwIfDisposed(); - return ops.exp(this); - }; - Tensor.prototype.log = function () { - this.throwIfDisposed(); - return ops.log(this); - }; - Tensor.prototype.sqrt = function () { - this.throwIfDisposed(); - return ops.sqrt(this); - }; - Tensor.prototype.square = function () { - this.throwIfDisposed(); - return ops.square(this); - }; - Tensor.prototype.abs = function () { - this.throwIfDisposed(); - return ops.abs(this); - }; - Tensor.prototype.clipByValue = function (min, max) { - this.throwIfDisposed(); - return ops.clipByValue(this, min, max); - }; - Tensor.prototype.relu = function () { - this.throwIfDisposed(); - return ops.relu(this); - }; - Tensor.prototype.elu = function () { - this.throwIfDisposed(); - return ops.elu(this); - }; - Tensor.prototype.selu = function () { - this.throwIfDisposed(); - return ops.selu(this); - }; - Tensor.prototype.leakyRelu = function (alpha) { - if (alpha === void 0) { alpha = 0.2; } - this.throwIfDisposed(); - return ops.leakyRelu(this, alpha); - }; - Tensor.prototype.prelu = function (alpha) { - this.throwIfDisposed(); - return ops.prelu(this, alpha); - }; - Tensor.prototype.sigmoid = function () { - this.throwIfDisposed(); - return ops.sigmoid(this); - }; - Tensor.prototype.sin = function () { - this.throwIfDisposed(); - return ops.sin(this); - }; - Tensor.prototype.cos = function () { - this.throwIfDisposed(); - return ops.cos(this); - }; - Tensor.prototype.tan = function () { - this.throwIfDisposed(); - return ops.tan(this); - }; - Tensor.prototype.asin = function () { - this.throwIfDisposed(); - return ops.asin(this); - }; - Tensor.prototype.acos = function () { - this.throwIfDisposed(); - return ops.acos(this); - }; - Tensor.prototype.atan = function () { - this.throwIfDisposed(); - return ops.atan(this); - }; - Tensor.prototype.sinh = function () { - this.throwIfDisposed(); - return ops.sinh(this); - }; - Tensor.prototype.cosh = function () { - this.throwIfDisposed(); - return ops.cosh(this); - }; - Tensor.prototype.tanh = function () { - this.throwIfDisposed(); - return ops.tanh(this); - }; - Tensor.prototype.step = function (alpha) { - if (alpha === void 0) { alpha = 0.0; } - this.throwIfDisposed(); - return ops.step(this, alpha); - }; - Tensor.prototype.softmax = function (dim) { - if (dim === void 0) { dim = -1; } - this.throwIfDisposed(); - return ops.softmax(this, dim); - }; - Tensor.prototype.resizeBilinear = function (newShape2D, alignCorners) { - if (alignCorners === void 0) { alignCorners = false; } - this.throwIfDisposed(); - return ops.image.resizeBilinear(this, newShape2D, alignCorners); - }; - Tensor.prototype.conv1d = function (filter, stride, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.conv1d(this, filter, stride, pad, dimRoundingMode); - }; - Tensor.prototype.conv2d = function (filter, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.conv2d(this, filter, strides, pad, dimRoundingMode); - }; - Tensor.prototype.conv2dTranspose = function (filter, outputShape, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.conv2dTranspose(this, filter, outputShape, strides, pad, dimRoundingMode); - }; - Tensor.prototype.depthwiseConv2D = function (filter, strides, pad, rates, dimRoundingMode) { - if (rates === void 0) { rates = [1, 1]; } - this.throwIfDisposed(); - return ops.depthwiseConv2d(this, filter, strides, pad, rates, dimRoundingMode); - }; - Tensor.prototype.avgPool = function (filterSize, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.avgPool(this, filterSize, strides, pad, dimRoundingMode); - }; - Tensor.prototype.maxPool = function (filterSize, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.maxPool(this, filterSize, strides, pad, dimRoundingMode); - }; - Tensor.prototype.minPool = function (filterSize, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.minPool(this, filterSize, strides, pad, dimRoundingMode); - }; - Tensor.prototype.localResponseNormalization = function (radius, bias, alpha, beta, normRegion) { - if (radius === void 0) { radius = 5; } - if (bias === void 0) { bias = 1; } - if (alpha === void 0) { alpha = 1; } - if (beta === void 0) { beta = 0.5; } - if (normRegion === void 0) { normRegion = 'acrossChannels'; } - return ops.localResponseNormalization(this, radius, bias, alpha, beta, normRegion); - }; - Tensor.prototype.variable = function (trainable, name, dtype) { - if (trainable === void 0) { trainable = true; } - this.throwIfDisposed(); - return Variable.variable(this, trainable, name, dtype); - }; - Tensor.nextId = 0; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "flatten", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "asScalar", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as1D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as2D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as3D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as4D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "asType", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "buffer", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "data", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "dataSync", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "dispose", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "toFloat", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "toInt", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "toBool", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "print", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "reshape", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "reshapeAs", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "expandDims", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "squeeze", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "clone", null); - Tensor = Tensor_1 = __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor); - return Tensor; - var Tensor_1; -}()); -exports.Tensor = Tensor; -exports.NDArray = Tensor; -var Scalar = (function (_super) { - __extends(Scalar, _super); - function Scalar() { - return _super !== null && _super.apply(this, arguments) || this; - } - Scalar.new = function (value, dtype) { - return ops.scalar(value, dtype); - }; - return Scalar; -}(Tensor)); -exports.Scalar = Scalar; -var Tensor1D = (function (_super) { - __extends(Tensor1D, _super); - function Tensor1D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor1D.new = function (values, dtype) { - return ops.tensor1d(values, dtype); - }; - return Tensor1D; -}(Tensor)); -exports.Tensor1D = Tensor1D; -exports.Array1D = Tensor1D; -var Tensor2D = (function (_super) { - __extends(Tensor2D, _super); - function Tensor2D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor2D.new = function (shape, values, dtype) { - return ops.tensor2d(values, shape, dtype); - }; - return Tensor2D; -}(Tensor)); -exports.Tensor2D = Tensor2D; -exports.Array2D = Tensor2D; -var Tensor3D = (function (_super) { - __extends(Tensor3D, _super); - function Tensor3D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor3D.new = function (shape, values, dtype) { - return ops.tensor3d(values, shape, dtype); - }; - return Tensor3D; -}(Tensor)); -exports.Tensor3D = Tensor3D; -exports.Array3D = Tensor3D; -var Tensor4D = (function (_super) { - __extends(Tensor4D, _super); - function Tensor4D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor4D.new = function (shape, values, dtype) { - return ops.tensor4d(values, shape, dtype); - }; - return Tensor4D; -}(Tensor)); -exports.Tensor4D = Tensor4D; -exports.Array4D = Tensor4D; -var Variable = (function (_super) { - __extends(Variable, _super); - function Variable(initialValue, trainable, name) { - if (trainable === void 0) { trainable = true; } - var _this = _super.call(this, initialValue.shape, initialValue.dtype, null, initialValue.dataId) || this; - _this.trainable = trainable; - _this.name = name; - if (_this.name == null) { - _this.name = Variable_1.nextVarId.toString(); - Variable_1.nextVarId++; - } - environment_1.ENV.engine.registerVariable(_this); - return _this; - } - Variable_1 = Variable; - Variable.variable = function (initialValue, trainable, name, dtype) { - if (trainable === void 0) { trainable = true; } - if (dtype != null && dtype !== initialValue.dtype) { - initialValue = initialValue.asType(dtype); - } - return new Variable_1(initialValue, trainable, name); - }; - Variable.prototype.assign = function (newValue) { - if (newValue.dtype !== this.dtype) { - throw new Error("dtype of the new value (" + newValue.dtype + ") and " + - ("previous value (" + this.dtype + ") must match")); - } - if (!util.arraysEqual(newValue.shape, this.shape)) { - throw new Error("shape of the new value (" + newValue.shape + ") and " + - ("previous value (" + this.shape + ") must match")); - } - environment_1.ENV.engine.disposeTensor(this); - this.dataId = newValue.dataId; - environment_1.ENV.engine.registerTensor(this); - }; - Variable.nextVarId = 0; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Variable.prototype, "assign", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Variable, "variable", null); - Variable = Variable_1 = __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Variable); - return Variable; - var Variable_1; -}(Tensor)); -exports.Variable = Variable; -var variable = Variable.variable; -exports.variable = variable; -function computeStrides(shape) { - var rank = shape.length; - if (rank < 2) { - return []; - } - var strides = new Array(rank - 1); - strides[rank - 2] = shape[rank - 1]; - for (var i = rank - 3; i >= 0; --i) { - strides[i] = strides[i + 1] * shape[i + 1]; - } - return strides; -} - -},{"./doc":32,"./environment":34,"./ops/ops":123,"./util":151}],147:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("./environment"); -var backend_cpu_1 = require("./kernels/backend_cpu"); -var backend_webgl_1 = require("./kernels/backend_webgl"); -var tensor_1 = require("./tensor"); -var util = require("./util"); -var WEBGL_FLOAT_ENVS = [ - { 'BACKEND': 'webgl', 'WEBGL_FLOAT_TEXTURE_ENABLED': true, 'WEBGL_VERSION': 1 }, - { - 'BACKEND': 'webgl', - 'WEBGL_FLOAT_TEXTURE_ENABLED': true, - 'WEBGL_VERSION': 2 - } -]; -exports.WEBGL_ENVS = WEBGL_FLOAT_ENVS.concat([{ - 'BACKEND': 'webgl', - 'WEBGL_FLOAT_TEXTURE_ENABLED': false, - 'WEBGL_VERSION': 1 - }]); -exports.CPU_ENVS = [{ 'BACKEND': 'cpu' }]; -exports.ALL_FLOAT_ENVS = WEBGL_FLOAT_ENVS.concat(exports.CPU_ENVS); -exports.ALL_ENVS = exports.WEBGL_ENVS.concat(exports.CPU_ENVS); -exports.TEST_EPSILON = 1e-2; -function expectArraysClose(actual, expected, epsilon) { - if (epsilon === void 0) { epsilon = exports.TEST_EPSILON; } - if (!(actual instanceof tensor_1.Tensor) && !(expected instanceof tensor_1.Tensor)) { - var aType = actual.constructor.name; - var bType = expected.constructor.name; - if (aType !== bType) { - throw new Error("Arrays are of different type actual: " + aType + " " + - ("vs expected: " + bType)); - } - } - else if (actual instanceof tensor_1.Tensor && expected instanceof tensor_1.Tensor) { - if (actual.dtype !== expected.dtype) { - throw new Error("Arrays are of different type actual: " + actual.dtype + " " + - ("vs expected: " + expected.dtype + ".")); - } - if (!util.arraysEqual(actual.shape, expected.shape)) { - throw new Error("Arrays are of different shape actual: " + actual.shape + " " + - ("vs expected: " + expected.shape + ".")); - } - } - var actualValues; - var expectedValues; - if (actual instanceof tensor_1.Tensor) { - actualValues = actual.dataSync(); - } - else { - actualValues = actual; - } - if (expected instanceof tensor_1.Tensor) { - expectedValues = expected.dataSync(); - } - else { - expectedValues = expected; - } - if (actualValues.length !== expectedValues.length) { - throw new Error("Arrays have different lengths actual: " + actualValues.length + " vs " + - ("expected: " + expectedValues.length + ".\n") + - ("Actual: " + actualValues + ".\n") + - ("Expected: " + expectedValues + ".")); - } - for (var i = 0; i < expectedValues.length; ++i) { - var a = actualValues[i]; - var e = expectedValues[i]; - if (!areClose(a, Number(e), epsilon)) { - throw new Error("Arrays differ: actual[" + i + "] = " + a + ", expected[" + i + "] = " + e + ".\n" + - ("Actual: " + actualValues + ".\n") + - ("Expected: " + expectedValues + ".")); - } - } -} -exports.expectArraysClose = expectArraysClose; -function expectArraysEqual(actual, expected) { - return expectArraysClose(actual, expected, 0); -} -exports.expectArraysEqual = expectArraysEqual; -function expectNumbersClose(a, e, epsilon) { - if (epsilon === void 0) { epsilon = exports.TEST_EPSILON; } - if (!areClose(a, e, epsilon)) { - throw new Error("Numbers differ: actual === " + a + ", expected === " + e); - } -} -exports.expectNumbersClose = expectNumbersClose; -function areClose(a, e, epsilon) { - if (isNaN(a) && isNaN(e)) { - return true; - } - if (isNaN(a) || isNaN(e) || Math.abs(a - e) > epsilon) { - return false; - } - return true; -} -function expectValuesInRange(actual, low, high) { - var actualVals; - if (actual instanceof tensor_1.Tensor) { - actualVals = actual.dataSync(); - } - else { - actualVals = actual; - } - for (var i = 0; i < actualVals.length; i++) { - if (actualVals[i] < low || actualVals[i] > high) { - throw new Error("Value out of range:" + actualVals[i] + " low: " + low + ", high: " + high); - } - } -} -exports.expectValuesInRange = expectValuesInRange; -function describeWithFlags(name, featuresList, tests) { - featuresList.forEach(function (features) { - var testName = name + ' ' + JSON.stringify(features); - executeTests(testName, tests, features); - }); -} -exports.describeWithFlags = describeWithFlags; -function executeTests(testName, tests, features) { - describe(testName, function () { - beforeEach(function () { - environment_1.ENV.setFeatures(features || {}); - environment_1.ENV.addCustomBackend('webgl', function () { return new backend_webgl_1.MathBackendWebGL(); }); - environment_1.ENV.addCustomBackend('cpu', function () { return new backend_cpu_1.MathBackendCPU(); }); - if (features && features.BACKEND != null) { - environment_1.Environment.setBackend(features.BACKEND); - } - environment_1.ENV.engine.startScope(); - }); - afterEach(function () { - environment_1.ENV.engine.endScope(null); - environment_1.ENV.reset(); - }); - tests(); - }); -} -function assertIsNan(val, dtype) { - if (!util.isValNaN(val, dtype)) { - throw new Error("Value " + val + " does not represent NaN for dtype " + dtype); - } -} -exports.assertIsNan = assertIsNan; - -},{"./environment":34,"./kernels/backend_cpu":68,"./kernels/backend_webgl":69,"./tensor":146,"./util":151}],148:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var environment_1 = require("./environment"); -var Tracking = (function () { - function Tracking() { - } - Tracking.tidy = function (nameOrFn, fn, gradMode) { - if (gradMode === void 0) { gradMode = false; } - if (fn == null) { - if (typeof nameOrFn !== 'function') { - throw new Error('Please provide a function to dl.tidy()'); - } - fn = nameOrFn; - nameOrFn = ''; - } - else { - if (typeof nameOrFn !== 'string' && !(nameOrFn instanceof String)) { - throw new Error('When calling with two arguments, the first argument ' + - 'to dl.tidy() must be a string'); - } - if (typeof fn !== 'function') { - throw new Error('When calling with two arguments, the 2nd argument ' + - 'to dl.tidy() must be a function'); - } - } - environment_1.ENV.engine.startScope(gradMode); - var result = fn(); - if (result instanceof Promise) { - result.then(function (r) { return environment_1.ENV.engine.endScope(r, gradMode); }); - return result; - } - else { - environment_1.ENV.engine.endScope(result, gradMode); - return result; - } - }; - Tracking.keep = function (result) { - return environment_1.ENV.engine.keep(result); - }; - Tracking.time = function (f) { - return environment_1.ENV.engine.time(f); - }; - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Memory' }) - ], Tracking, "tidy", null); - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Memory' }) - ], Tracking, "keep", null); - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Timing' }) - ], Tracking, "time", null); - return Tracking; -}()); -exports.Tracking = Tracking; - -},{"./doc":32,"./environment":34}],149:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var adadelta_optimizer_1 = require("./optimizers/adadelta_optimizer"); -var adagrad_optimizer_1 = require("./optimizers/adagrad_optimizer"); -var adam_optimizer_1 = require("./optimizers/adam_optimizer"); -var adamax_optimizer_1 = require("./optimizers/adamax_optimizer"); -var momentum_optimizer_1 = require("./optimizers/momentum_optimizer"); -var optimizer_constructors_1 = require("./optimizers/optimizer_constructors"); -var rmsprop_optimizer_1 = require("./optimizers/rmsprop_optimizer"); -var sgd_optimizer_1 = require("./optimizers/sgd_optimizer"); -[momentum_optimizer_1.MomentumOptimizer, sgd_optimizer_1.SGDOptimizer, adadelta_optimizer_1.AdadeltaOptimizer, adagrad_optimizer_1.AdagradOptimizer, - rmsprop_optimizer_1.RMSPropOptimizer, adamax_optimizer_1.AdamaxOptimizer, adam_optimizer_1.AdamOptimizer]; -exports.train = { - sgd: optimizer_constructors_1.OptimizerConstructors.sgd, - momentum: optimizer_constructors_1.OptimizerConstructors.momentum, - adadelta: optimizer_constructors_1.OptimizerConstructors.adadelta, - adagrad: optimizer_constructors_1.OptimizerConstructors.adagrad, - rmsprop: optimizer_constructors_1.OptimizerConstructors.rmsprop, - adamax: optimizer_constructors_1.OptimizerConstructors.adamax, - adam: optimizer_constructors_1.OptimizerConstructors.adam -}; - -},{"./optimizers/adadelta_optimizer":135,"./optimizers/adagrad_optimizer":136,"./optimizers/adam_optimizer":137,"./optimizers/adamax_optimizer":138,"./optimizers/momentum_optimizer":139,"./optimizers/optimizer_constructors":141,"./optimizers/rmsprop_optimizer":142,"./optimizers/sgd_optimizer":143}],150:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var DType; -(function (DType) { - DType["float32"] = "float32"; - DType["int32"] = "int32"; - DType["bool"] = "bool"; -})(DType = exports.DType || (exports.DType = {})); -var Rank; -(function (Rank) { - Rank["R0"] = "R0"; - Rank["R1"] = "R1"; - Rank["R2"] = "R2"; - Rank["R3"] = "R3"; - Rank["R4"] = "R4"; -})(Rank = exports.Rank || (exports.Rank = {})); -var UpcastInt32AndMap; -(function (UpcastInt32AndMap) { - UpcastInt32AndMap["float32"] = "float32"; - UpcastInt32AndMap["int32"] = "int32"; - UpcastInt32AndMap["bool"] = "int32"; -})(UpcastInt32AndMap || (UpcastInt32AndMap = {})); -var UpcastBoolAndMap; -(function (UpcastBoolAndMap) { - UpcastBoolAndMap["float32"] = "float32"; - UpcastBoolAndMap["int32"] = "int32"; - UpcastBoolAndMap["bool"] = "bool"; -})(UpcastBoolAndMap || (UpcastBoolAndMap = {})); -var UpcastFloat32AndMap; -(function (UpcastFloat32AndMap) { - UpcastFloat32AndMap["float32"] = "float32"; - UpcastFloat32AndMap["int32"] = "float32"; - UpcastFloat32AndMap["bool"] = "float32"; -})(UpcastFloat32AndMap || (UpcastFloat32AndMap = {})); -var upcastTypeMap = { - float32: UpcastFloat32AndMap, - int32: UpcastInt32AndMap, - bool: UpcastBoolAndMap -}; -function upcastType(typeA, typeB) { - return upcastTypeMap[typeA][typeB]; -} -exports.upcastType = upcastType; -function sumOutType(type) { - return upcastType(type, 'int32'); -} -exports.sumOutType = sumOutType; - -},{}],151:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("./tensor"); -function shuffle(array) { - var counter = array.length; - var temp = 0; - var index = 0; - while (counter > 0) { - index = (Math.random() * counter) | 0; - counter--; - temp = array[counter]; - array[counter] = array[index]; - array[index] = temp; - } -} -exports.shuffle = shuffle; -function clamp(min, x, max) { - return Math.max(min, Math.min(x, max)); -} -exports.clamp = clamp; -function randUniform(a, b) { - return Math.random() * (b - a) + a; -} -exports.randUniform = randUniform; -function distSquared(a, b) { - var result = 0; - for (var i = 0; i < a.length; i++) { - var diff = Number(a[i]) - Number(b[i]); - result += diff * diff; - } - return result; -} -exports.distSquared = distSquared; -function assert(expr, msg) { - if (!expr) { - throw new Error(msg); - } -} -exports.assert = assert; -function assertShapesMatch(shapeA, shapeB, errorMessagePrefix) { - if (errorMessagePrefix === void 0) { errorMessagePrefix = ''; } - assert(arraysEqual(shapeA, shapeB), errorMessagePrefix + ("Shapes " + shapeA + " and " + shapeB + " must match")); -} -exports.assertShapesMatch = assertShapesMatch; -function assertTypesMatch(a, b) { - assert(a.dtype === b.dtype, "The dtypes of the first (" + a.dtype + ") and " + - ("second (" + b.dtype + ") input must match")); -} -exports.assertTypesMatch = assertTypesMatch; -function flatten(arr, ret) { - if (ret === void 0) { ret = []; } - if (Array.isArray(arr)) { - for (var i = 0; i < arr.length; ++i) { - flatten(arr[i], ret); - } - } - else { - ret.push(arr); - } - return ret; -} -exports.flatten = flatten; -function inferShape(val) { - if (isTypedArray(val)) { - return [val.length]; - } - if (!Array.isArray(val)) { - return []; - } - var shape = []; - while (val instanceof Array) { - shape.push(val.length); - val = val[0]; - } - return shape; -} -exports.inferShape = inferShape; -function sizeFromShape(shape) { - if (shape.length === 0) { - return 1; - } - var size = shape[0]; - for (var i = 1; i < shape.length; i++) { - size *= shape[i]; - } - return size; -} -exports.sizeFromShape = sizeFromShape; -function isScalarShape(shape) { - return shape.length === 0; -} -exports.isScalarShape = isScalarShape; -function arraysEqual(n1, n2) { - if (n1.length !== n2.length) { - return false; - } - for (var i = 0; i < n1.length; i++) { - if (n1[i] !== n2[i]) { - return false; - } - } - return true; -} -exports.arraysEqual = arraysEqual; -function isInt(a) { - return a % 1 === 0; -} -exports.isInt = isInt; -function tanh(x) { - if (Math.tanh != null) { - return Math.tanh(x); - } - if (x === Infinity) { - return 1; - } - else if (x === -Infinity) { - return -1; - } - else { - var e2x = Math.exp(2 * x); - return (e2x - 1) / (e2x + 1); - } -} -exports.tanh = tanh; -function sizeToSquarishShape(size) { - for (var a = Math.floor(Math.sqrt(size)); a > 1; --a) { - if (size % a === 0) { - return [a, size / a]; - } - } - return [1, size]; -} -exports.sizeToSquarishShape = sizeToSquarishShape; -function createShuffledIndices(n) { - var shuffledIndices = new Uint32Array(n); - for (var i = 0; i < n; ++i) { - shuffledIndices[i] = i; - } - shuffle(shuffledIndices); - return shuffledIndices; -} -exports.createShuffledIndices = createShuffledIndices; -function rightPad(a, size) { - if (size <= a.length) { - return a; - } - return a + ' '.repeat(size - a.length); -} -exports.rightPad = rightPad; -function repeatedTry(checkFn, delayFn, maxCounter) { - if (delayFn === void 0) { delayFn = function (counter) { return 0; }; } - return new Promise(function (resolve, reject) { - var tryCount = 0; - var tryFn = function () { - if (checkFn()) { - resolve(); - return; - } - tryCount++; - var nextBackoff = delayFn(tryCount); - if (maxCounter != null && tryCount >= maxCounter) { - reject(); - return; - } - setTimeout(tryFn, nextBackoff); - }; - setTimeout(tryFn, 0); - }); -} -exports.repeatedTry = repeatedTry; -function getQueryParams(queryString) { - var params = {}; - queryString.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function (s) { - var t = []; - for (var _i = 1; _i < arguments.length; _i++) { - t[_i - 1] = arguments[_i]; - } - decodeParam(params, t[0], t[1]); - return t.join('='); - }); - return params; -} -exports.getQueryParams = getQueryParams; -function decodeParam(params, name, value) { - params[decodeURIComponent(name)] = decodeURIComponent(value || ''); -} -function inferFromImplicitShape(shape, size) { - var shapeProd = 1; - var implicitIdx = -1; - for (var i = 0; i < shape.length; ++i) { - if (shape[i] > 0) { - shapeProd *= shape[i]; - } - else if (shape[i] === -1) { - if (implicitIdx !== -1) { - throw Error("Shapes can only have 1 implicit size. " + - ("Found -1 at dim " + implicitIdx + " and dim " + i)); - } - implicitIdx = i; - } - else if (shape[i] <= 0) { - throw Error("Shapes can not be <= 0. Found " + shape[i] + " at dim " + i); - } - } - if (implicitIdx === -1) { - if (size > 0 && size !== shapeProd) { - throw Error("Size (" + size + ") must match the product of shape " + shape); - } - return shape; - } - if (size % shapeProd !== 0) { - throw Error("The implicit shape can't be a fractional number. " + - ("Got " + size + " / " + shapeProd)); - } - var newShape = shape.slice(); - newShape[implicitIdx] = size / shapeProd; - return newShape; -} -exports.inferFromImplicitShape = inferFromImplicitShape; -exports.NAN_INT32 = 1 << 31; -exports.NAN_BOOL = 255; -exports.NAN_FLOAT32 = NaN; -function getNaN(dtype) { - if (dtype === 'float32') { - return exports.NAN_FLOAT32; - } - else if (dtype === 'int32') { - return exports.NAN_INT32; - } - else if (dtype === 'bool') { - return exports.NAN_BOOL; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -exports.getNaN = getNaN; -function isValNaN(val, dtype) { - if (isNaN(val)) { - return true; - } - if (dtype === 'float32') { - return false; - } - else if (dtype === 'int32') { - return val === exports.NAN_INT32; - } - else if (dtype === 'bool') { - return val === exports.NAN_BOOL; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -exports.isValNaN = isValNaN; -function squeezeShape(shape, axis) { - var newShape = []; - var keptDims = []; - var j = 0; - for (var i = 0; i < shape.length; ++i) { - if (axis !== undefined) { - if (axis[j] === i && shape[i] > 1) { - throw new Error("axis " + i + " is not 1"); - } - if ((axis[j] === undefined || axis[j] > i) && shape[i] === 1) { - newShape.push(shape[i]); - keptDims.push(i); - } - if (axis[j] <= i) - j++; - } - if (shape[i] > 1) { - newShape.push(shape[i]); - keptDims.push(i); - } - } - return { newShape: newShape, keptDims: keptDims }; -} -exports.squeezeShape = squeezeShape; -function getTypedArrayFromDType(dtype, size) { - var values = null; - if (dtype == null || dtype === 'float32') { - values = new Float32Array(size); - } - else if (dtype === 'int32') { - values = new Int32Array(size); - } - else if (dtype === 'bool') { - values = new Uint8Array(size); - } - else { - throw new Error("Unknown data type " + dtype); - } - return values; -} -exports.getTypedArrayFromDType = getTypedArrayFromDType; -function isTensorInList(tensor, tensorList) { - for (var i = 0; i < tensorList.length; i++) { - if (tensorList[i].id === tensor.id) { - return true; - } - } - return false; -} -exports.isTensorInList = isTensorInList; -function checkForNaN(vals, dtype, name) { - for (var i = 0; i < vals.length; i++) { - if (isValNaN(vals[i], dtype)) { - throw Error("The result of the '" + name + "' has NaNs."); - } - } -} -exports.checkForNaN = checkForNaN; -function flattenNameArrayMap(nameArrayMap, keys) { - var xs = []; - if (nameArrayMap instanceof tensor_1.Tensor) { - xs.push(nameArrayMap); - } - else { - var xMap = nameArrayMap; - for (var i = 0; i < keys.length; i++) { - xs.push(xMap[keys[i]]); - } - } - return xs; -} -exports.flattenNameArrayMap = flattenNameArrayMap; -function unflattenToNameArrayMap(keys, flatArrays) { - if (keys.length !== flatArrays.length) { - throw new Error("Cannot unflatten Tensor[], keys and arrays are not of same length."); - } - var result = {}; - for (var i = 0; i < keys.length; i++) { - result[keys[i]] = flatArrays[i]; - } - return result; -} -exports.unflattenToNameArrayMap = unflattenToNameArrayMap; -function hasEncodingLoss(oldType, newType) { - if (newType === 'float32') { - return false; - } - if (newType === 'int32' && oldType !== 'float32') { - return false; - } - if (newType === 'bool' && oldType === 'bool') { - return false; - } - return true; -} -exports.hasEncodingLoss = hasEncodingLoss; -function copyTypedArray(array, dtype) { - if (dtype == null || dtype === 'float32') { - return new Float32Array(array); - } - else if (dtype === 'int32') { - var vals = new Int32Array(array.length); - for (var i = 0; i < vals.length; ++i) { - var val = array[i]; - if (isValNaN(val, 'int32')) { - vals[i] = getNaN('int32'); - } - else { - vals[i] = val; - } - } - return vals; - } - else if (dtype === 'bool') { - var bool = new Uint8Array(array.length); - for (var i = 0; i < bool.length; ++i) { - var val = array[i]; - if (isValNaN(val, 'bool')) { - bool[i] = getNaN('bool'); - } - else if (Math.round(val) !== 0) { - bool[i] = 1; - } - } - return bool; - } - else { - throw new Error("Unknown data type " + dtype); - } -} -exports.copyTypedArray = copyTypedArray; -function isTypedArray(a) { - return a instanceof Float32Array || a instanceof Int32Array || - a instanceof Uint8Array; -} -exports.isTypedArray = isTypedArray; -function bytesPerElement(dtype) { - if (dtype === 'float32' || dtype === 'int32') { - return 4; - } - else if (dtype === 'bool') { - return 1; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -exports.bytesPerElement = bytesPerElement; -function isFunction(f) { - return !!(f && f.constructor && f.call && f.apply); -} -exports.isFunction = isFunction; - -},{"./tensor":146}],152:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var version = '0.5.0'; -exports.version = version; - -},{}],153:[function(require,module,exports){ -// A library of seedable RNGs implemented in Javascript. -// -// Usage: -// -// var seedrandom = require('seedrandom'); -// var random = seedrandom(1); // or any seed. -// var x = random(); // 0 <= x < 1. Every bit is random. -// var x = random.quick(); // 0 <= x < 1. 32 bits of randomness. - -// alea, a 53-bit multiply-with-carry generator by Johannes Baagøe. -// Period: ~2^116 -// Reported to pass all BigCrush tests. -var alea = require('./lib/alea'); - -// xor128, a pure xor-shift generator by George Marsaglia. -// Period: 2^128-1. -// Reported to fail: MatrixRank and LinearComp. -var xor128 = require('./lib/xor128'); - -// xorwow, George Marsaglia's 160-bit xor-shift combined plus weyl. -// Period: 2^192-2^32 -// Reported to fail: CollisionOver, SimpPoker, and LinearComp. -var xorwow = require('./lib/xorwow'); - -// xorshift7, by François Panneton and Pierre L'ecuyer, takes -// a different approach: it adds robustness by allowing more shifts -// than Marsaglia's original three. It is a 7-shift generator -// with 256 bits, that passes BigCrush with no systmatic failures. -// Period 2^256-1. -// No systematic BigCrush failures reported. -var xorshift7 = require('./lib/xorshift7'); - -// xor4096, by Richard Brent, is a 4096-bit xor-shift with a -// very long period that also adds a Weyl generator. It also passes -// BigCrush with no systematic failures. Its long period may -// be useful if you have many generators and need to avoid -// collisions. -// Period: 2^4128-2^32. -// No systematic BigCrush failures reported. -var xor4096 = require('./lib/xor4096'); - -// Tyche-i, by Samuel Neves and Filipe Araujo, is a bit-shifting random -// number generator derived from ChaCha, a modern stream cipher. -// https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf -// Period: ~2^127 -// No systematic BigCrush failures reported. -var tychei = require('./lib/tychei'); - -// The original ARC4-based prng included in this library. -// Period: ~2^1600 -var sr = require('./seedrandom'); - -sr.alea = alea; -sr.xor128 = xor128; -sr.xorwow = xorwow; -sr.xorshift7 = xorshift7; -sr.xor4096 = xor4096; -sr.tychei = tychei; - -module.exports = sr; - -},{"./lib/alea":154,"./lib/tychei":155,"./lib/xor128":156,"./lib/xor4096":157,"./lib/xorshift7":158,"./lib/xorwow":159,"./seedrandom":160}],154:[function(require,module,exports){ -// A port of an algorithm by Johannes Baagøe , 2010 -// http://baagoe.com/en/RandomMusings/javascript/ -// https://github.com/nquinlan/better-random-numbers-for-javascript-mirror -// Original work is under MIT license - - -// Copyright (C) 2010 by Johannes Baagøe -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall 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. - - - -(function(global, module, define) { - -function Alea(seed) { - var me = this, mash = Mash(); - - me.next = function() { - var t = 2091639 * me.s0 + me.c * 2.3283064365386963e-10; // 2^-32 - me.s0 = me.s1; - me.s1 = me.s2; - return me.s2 = t - (me.c = t | 0); - }; - - // Apply the seeding algorithm from Baagoe. - me.c = 1; - me.s0 = mash(' '); - me.s1 = mash(' '); - me.s2 = mash(' '); - me.s0 -= mash(seed); - if (me.s0 < 0) { me.s0 += 1; } - me.s1 -= mash(seed); - if (me.s1 < 0) { me.s1 += 1; } - me.s2 -= mash(seed); - if (me.s2 < 0) { me.s2 += 1; } - mash = null; -} - -function copy(f, t) { - t.c = f.c; - t.s0 = f.s0; - t.s1 = f.s1; - t.s2 = f.s2; - return t; -} - -function impl(seed, opts) { - var xg = new Alea(seed), - state = opts && opts.state, - prng = xg.next; - prng.int32 = function() { return (xg.next() * 0x100000000) | 0; } - prng.double = function() { - return prng() + (prng() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53 - }; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -function Mash() { - var n = 0xefc8249d; - - var mash = function(data) { - data = data.toString(); - for (var i = 0; i < data.length; i++) { - n += data.charCodeAt(i); - var h = 0.02519603282416938 * n; - n = h >>> 0; - h -= n; - h *= n; - n = h >>> 0; - h -= n; - n += h * 0x100000000; // 2^32 - } - return (n >>> 0) * 2.3283064365386963e-10; // 2^-32 - }; - - return mash; -} - - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.alea = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],155:[function(require,module,exports){ -// A Javascript implementaion of the "Tyche-i" prng algorithm by -// Samuel Neves and Filipe Araujo. -// See https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf - -(function(global, module, define) { - -function XorGen(seed) { - var me = this, strseed = ''; - - // Set up generator function. - me.next = function() { - var b = me.b, c = me.c, d = me.d, a = me.a; - b = (b << 25) ^ (b >>> 7) ^ c; - c = (c - d) | 0; - d = (d << 24) ^ (d >>> 8) ^ a; - a = (a - b) | 0; - me.b = b = (b << 20) ^ (b >>> 12) ^ c; - me.c = c = (c - d) | 0; - me.d = (d << 16) ^ (c >>> 16) ^ a; - return me.a = (a - b) | 0; - }; - - /* The following is non-inverted tyche, which has better internal - * bit diffusion, but which is about 25% slower than tyche-i in JS. - me.next = function() { - var a = me.a, b = me.b, c = me.c, d = me.d; - a = (me.a + me.b | 0) >>> 0; - d = me.d ^ a; d = d << 16 ^ d >>> 16; - c = me.c + d | 0; - b = me.b ^ c; b = b << 12 ^ d >>> 20; - me.a = a = a + b | 0; - d = d ^ a; me.d = d = d << 8 ^ d >>> 24; - me.c = c = c + d | 0; - b = b ^ c; - return me.b = (b << 7 ^ b >>> 25); - } - */ - - me.a = 0; - me.b = 0; - me.c = 2654435769 | 0; - me.d = 1367130551; - - if (seed === Math.floor(seed)) { - // Integer seed. - me.a = (seed / 0x100000000) | 0; - me.b = seed | 0; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 20; k++) { - me.b ^= strseed.charCodeAt(k) | 0; - me.next(); - } -} - -function copy(f, t) { - t.a = f.a; - t.b = f.b; - t.c = f.c; - t.d = f.d; - return t; -}; - -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.tychei = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],156:[function(require,module,exports){ -// A Javascript implementaion of the "xor128" prng algorithm by -// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper - -(function(global, module, define) { - -function XorGen(seed) { - var me = this, strseed = ''; - - me.x = 0; - me.y = 0; - me.z = 0; - me.w = 0; - - // Set up generator function. - me.next = function() { - var t = me.x ^ (me.x << 11); - me.x = me.y; - me.y = me.z; - me.z = me.w; - return me.w ^= (me.w >>> 19) ^ t ^ (t >>> 8); - }; - - if (seed === (seed | 0)) { - // Integer seed. - me.x = seed; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 64; k++) { - me.x ^= strseed.charCodeAt(k) | 0; - me.next(); - } -} - -function copy(f, t) { - t.x = f.x; - t.y = f.y; - t.z = f.z; - t.w = f.w; - return t; -} - -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xor128 = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],157:[function(require,module,exports){ -// A Javascript implementaion of Richard Brent's Xorgens xor4096 algorithm. -// -// This fast non-cryptographic random number generator is designed for -// use in Monte-Carlo algorithms. It combines a long-period xorshift -// generator with a Weyl generator, and it passes all common batteries -// of stasticial tests for randomness while consuming only a few nanoseconds -// for each prng generated. For background on the generator, see Brent's -// paper: "Some long-period random number generators using shifts and xors." -// http://arxiv.org/pdf/1004.3115v1.pdf -// -// Usage: -// -// var xor4096 = require('xor4096'); -// random = xor4096(1); // Seed with int32 or string. -// assert.equal(random(), 0.1520436450538547); // (0, 1) range, 53 bits. -// assert.equal(random.int32(), 1806534897); // signed int32, 32 bits. -// -// For nonzero numeric keys, this impelementation provides a sequence -// identical to that by Brent's xorgens 3 implementaion in C. This -// implementation also provides for initalizing the generator with -// string seeds, or for saving and restoring the state of the generator. -// -// On Chrome, this prng benchmarks about 2.1 times slower than -// Javascript's built-in Math.random(). - -(function(global, module, define) { - -function XorGen(seed) { - var me = this; - - // Set up generator function. - me.next = function() { - var w = me.w, - X = me.X, i = me.i, t, v; - // Update Weyl generator. - me.w = w = (w + 0x61c88647) | 0; - // Update xor generator. - v = X[(i + 34) & 127]; - t = X[i = ((i + 1) & 127)]; - v ^= v << 13; - t ^= t << 17; - v ^= v >>> 15; - t ^= t >>> 12; - // Update Xor generator array state. - v = X[i] = v ^ t; - me.i = i; - // Result is the combination. - return (v + (w ^ (w >>> 16))) | 0; - }; - - function init(me, seed) { - var t, v, i, j, w, X = [], limit = 128; - if (seed === (seed | 0)) { - // Numeric seeds initialize v, which is used to generates X. - v = seed; - seed = null; - } else { - // String seeds are mixed into v and X one character at a time. - seed = seed + '\0'; - v = 0; - limit = Math.max(limit, seed.length); - } - // Initialize circular array and weyl value. - for (i = 0, j = -32; j < limit; ++j) { - // Put the unicode characters into the array, and shuffle them. - if (seed) v ^= seed.charCodeAt((j + 32) % seed.length); - // After 32 shuffles, take v as the starting w value. - if (j === 0) w = v; - v ^= v << 10; - v ^= v >>> 15; - v ^= v << 4; - v ^= v >>> 13; - if (j >= 0) { - w = (w + 0x61c88647) | 0; // Weyl. - t = (X[j & 127] ^= (v + w)); // Combine xor and weyl to init array. - i = (0 == t) ? i + 1 : 0; // Count zeroes. - } - } - // We have detected all zeroes; make the key nonzero. - if (i >= 128) { - X[(seed && seed.length || 0) & 127] = -1; - } - // Run the generator 512 times to further mix the state before using it. - // Factoring this as a function slows the main generator, so it is just - // unrolled here. The weyl generator is not advanced while warming up. - i = 127; - for (j = 4 * 128; j > 0; --j) { - v = X[(i + 34) & 127]; - t = X[i = ((i + 1) & 127)]; - v ^= v << 13; - t ^= t << 17; - v ^= v >>> 15; - t ^= t >>> 12; - X[i] = v ^ t; - } - // Storing state as object members is faster than using closure variables. - me.w = w; - me.X = X; - me.i = i; - } - - init(me, seed); -} - -function copy(f, t) { - t.i = f.i; - t.w = f.w; - t.X = f.X.slice(); - return t; -}; - -function impl(seed, opts) { - if (seed == null) seed = +(new Date); - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (state.X) copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xor4096 = impl; -} - -})( - this, // window object or global - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - -},{}],158:[function(require,module,exports){ -// A Javascript implementaion of the "xorshift7" algorithm by -// François Panneton and Pierre L'ecuyer: -// "On the Xorgshift Random Number Generators" -// http://saluc.engr.uconn.edu/refs/crypto/rng/panneton05onthexorshift.pdf - -(function(global, module, define) { - -function XorGen(seed) { - var me = this; - - // Set up generator function. - me.next = function() { - // Update xor generator. - var X = me.x, i = me.i, t, v, w; - t = X[i]; t ^= (t >>> 7); v = t ^ (t << 24); - t = X[(i + 1) & 7]; v ^= t ^ (t >>> 10); - t = X[(i + 3) & 7]; v ^= t ^ (t >>> 3); - t = X[(i + 4) & 7]; v ^= t ^ (t << 7); - t = X[(i + 7) & 7]; t = t ^ (t << 13); v ^= t ^ (t << 9); - X[i] = v; - me.i = (i + 1) & 7; - return v; - }; - - function init(me, seed) { - var j, w, X = []; - - if (seed === (seed | 0)) { - // Seed state array using a 32-bit integer. - w = X[0] = seed; - } else { - // Seed state using a string. - seed = '' + seed; - for (j = 0; j < seed.length; ++j) { - X[j & 7] = (X[j & 7] << 15) ^ - (seed.charCodeAt(j) + X[(j + 1) & 7] << 13); - } - } - // Enforce an array length of 8, not all zeroes. - while (X.length < 8) X.push(0); - for (j = 0; j < 8 && X[j] === 0; ++j); - if (j == 8) w = X[7] = -1; else w = X[j]; - - me.x = X; - me.i = 0; - - // Discard an initial 256 values. - for (j = 256; j > 0; --j) { - me.next(); - } - } - - init(me, seed); -} - -function copy(f, t) { - t.x = f.x.slice(); - t.i = f.i; - return t; -} - -function impl(seed, opts) { - if (seed == null) seed = +(new Date); - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (state.x) copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xorshift7 = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - -},{}],159:[function(require,module,exports){ -// A Javascript implementaion of the "xorwow" prng algorithm by -// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper - -(function(global, module, define) { - -function XorGen(seed) { - var me = this, strseed = ''; - - // Set up generator function. - me.next = function() { - var t = (me.x ^ (me.x >>> 2)); - me.x = me.y; me.y = me.z; me.z = me.w; me.w = me.v; - return (me.d = (me.d + 362437 | 0)) + - (me.v = (me.v ^ (me.v << 4)) ^ (t ^ (t << 1))) | 0; - }; - - me.x = 0; - me.y = 0; - me.z = 0; - me.w = 0; - me.v = 0; - - if (seed === (seed | 0)) { - // Integer seed. - me.x = seed; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 64; k++) { - me.x ^= strseed.charCodeAt(k) | 0; - if (k == strseed.length) { - me.d = me.x << 10 ^ me.x >>> 4; - } - me.next(); - } -} - -function copy(f, t) { - t.x = f.x; - t.y = f.y; - t.z = f.z; - t.w = f.w; - t.v = f.v; - t.d = f.d; - return t; -} - -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xorwow = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],160:[function(require,module,exports){ -/* -Copyright 2014 David Bau. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall 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. - -*/ - -(function (pool, math) { -// -// The following constants are related to IEEE 754 limits. -// -var global = this, - width = 256, // each RC4 output is 0 <= x < 256 - chunks = 6, // at least six RC4 outputs for each double - digits = 52, // there are 52 significant digits in a double - rngname = 'random', // rngname: name for Math.random and Math.seedrandom - startdenom = math.pow(width, chunks), - significance = math.pow(2, digits), - overflow = significance * 2, - mask = width - 1, - nodecrypto; // node.js crypto module, initialized at the bottom. - -// -// seedrandom() -// This is the seedrandom function described above. -// -function seedrandom(seed, options, callback) { - var key = []; - options = (options == true) ? { entropy: true } : (options || {}); - - // Flatten the seed string or build one from local entropy if needed. - var shortseed = mixkey(flatten( - options.entropy ? [seed, tostring(pool)] : - (seed == null) ? autoseed() : seed, 3), key); - - // Use the seed to initialize an ARC4 generator. - var arc4 = new ARC4(key); - - // This function returns a random double in [0, 1) that contains - // randomness in every bit of the mantissa of the IEEE 754 value. - var prng = function() { - var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48 - d = startdenom, // and denominator d = 2 ^ 48. - x = 0; // and no 'extra last byte'. - while (n < significance) { // Fill up all significant digits by - n = (n + x) * width; // shifting numerator and - d *= width; // denominator and generating a - x = arc4.g(1); // new least-significant-byte. - } - while (n >= overflow) { // To avoid rounding up, before adding - n /= 2; // last byte, shift everything - d /= 2; // right using integer math until - x >>>= 1; // we have exactly the desired bits. - } - return (n + x) / d; // Form the number within [0, 1). - }; - - prng.int32 = function() { return arc4.g(4) | 0; } - prng.quick = function() { return arc4.g(4) / 0x100000000; } - prng.double = prng; - - // Mix the randomness into accumulated entropy. - mixkey(tostring(arc4.S), pool); - - // Calling convention: what to return as a function of prng, seed, is_math. - return (options.pass || callback || - function(prng, seed, is_math_call, state) { - if (state) { - // Load the arc4 state from the given state if it has an S array. - if (state.S) { copy(state, arc4); } - // Only provide the .state method if requested via options.state. - prng.state = function() { return copy(arc4, {}); } - } - - // If called as a method of Math (Math.seedrandom()), mutate - // Math.random because that is how seedrandom.js has worked since v1.0. - if (is_math_call) { math[rngname] = prng; return seed; } - - // Otherwise, it is a newer calling convention, so return the - // prng directly. - else return prng; - })( - prng, - shortseed, - 'global' in options ? options.global : (this == math), - options.state); -} -math['seed' + rngname] = seedrandom; - -// -// ARC4 -// -// An ARC4 implementation. The constructor takes a key in the form of -// an array of at most (width) integers that should be 0 <= x < (width). -// -// The g(count) method returns a pseudorandom integer that concatenates -// the next (count) outputs from ARC4. Its return value is a number x -// that is in the range 0 <= x < (width ^ count). -// -function ARC4(key) { - var t, keylen = key.length, - me = this, i = 0, j = me.i = me.j = 0, s = me.S = []; - - // The empty key [] is treated as [0]. - if (!keylen) { key = [keylen++]; } - - // Set up S using the standard key scheduling algorithm. - while (i < width) { - s[i] = i++; - } - for (i = 0; i < width; i++) { - s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))]; - s[j] = t; - } - - // The "g" method returns the next (count) outputs as one number. - (me.g = function(count) { - // Using instance members instead of closure state nearly doubles speed. - var t, r = 0, - i = me.i, j = me.j, s = me.S; - while (count--) { - t = s[i = mask & (i + 1)]; - r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))]; - } - me.i = i; me.j = j; - return r; - // For robust unpredictability, the function call below automatically - // discards an initial batch of values. This is called RC4-drop[256]. - // See http://google.com/search?q=rsa+fluhrer+response&btnI - })(width); -} - -// -// copy() -// Copies internal state of ARC4 to or from a plain object. -// -function copy(f, t) { - t.i = f.i; - t.j = f.j; - t.S = f.S.slice(); - return t; -}; - -// -// flatten() -// Converts an object tree to nested arrays of strings. -// -function flatten(obj, depth) { - var result = [], typ = (typeof obj), prop; - if (depth && typ == 'object') { - for (prop in obj) { - try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {} - } - } - return (result.length ? result : typ == 'string' ? obj : obj + '\0'); -} - -// -// mixkey() -// Mixes a string seed into a key that is an array of integers, and -// returns a shortened string seed that is equivalent to the result key. -// -function mixkey(seed, key) { - var stringseed = seed + '', smear, j = 0; - while (j < stringseed.length) { - key[mask & j] = - mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++)); - } - return tostring(key); -} - -// -// autoseed() -// Returns an object for autoseeding, using window.crypto and Node crypto -// module if available. -// -function autoseed() { - try { - var out; - if (nodecrypto && (out = nodecrypto.randomBytes)) { - // The use of 'out' to remember randomBytes makes tight minified code. - out = out(width); - } else { - out = new Uint8Array(width); - (global.crypto || global.msCrypto).getRandomValues(out); - } - return tostring(out); - } catch (e) { - var browser = global.navigator, - plugins = browser && browser.plugins; - return [+new Date, global, plugins, global.screen, tostring(pool)]; - } -} - -// -// tostring() -// Converts an array of charcodes to a string -// -function tostring(a) { - return String.fromCharCode.apply(0, a); -} - -// -// When seedrandom.js is loaded, we immediately mix a few bits -// from the built-in RNG into the entropy pool. Because we do -// not want to interfere with deterministic PRNG state later, -// seedrandom will not call math.random on its own again after -// initialization. -// -mixkey(math.random(), pool); - -// -// Nodejs and AMD support: export the implementation as a module using -// either convention. -// -if ((typeof module) == 'object' && module.exports) { - module.exports = seedrandom; - // When in node.js, try using crypto package for autoseeding. - try { - nodecrypto = require('crypto'); - } catch (ex) {} -} else if ((typeof define) == 'function' && define.amd) { - define(function() { return seedrandom; }); -} - -// End anonymous scope, and pass initial values. -})( - [], // pool: entropy pool starts empty - Math // math: package containing random, pow, and seedrandom -); - -},{"crypto":2}],161:[function(require,module,exports){ -(function (global){ -/*! https://mths.be/utf8js v2.1.2 by @mathias */ -;(function(root) { - - // Detect free variables `exports` - var freeExports = typeof exports == 'object' && exports; - - // Detect free variable `module` - var freeModule = typeof module == 'object' && module && - module.exports == freeExports && module; - - // Detect free variable `global`, from Node.js or Browserified code, - // and use it as `root` - var freeGlobal = typeof global == 'object' && global; - if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { - root = freeGlobal; - } - - /*--------------------------------------------------------------------------*/ - - var stringFromCharCode = String.fromCharCode; - - // Taken from https://mths.be/punycode - function ucs2decode(string) { - var output = []; - var counter = 0; - var length = string.length; - var value; - var extra; - while (counter < length) { - value = string.charCodeAt(counter++); - if (value >= 0xD800 && value <= 0xDBFF && counter < length) { - // high surrogate, and there is a next character - extra = string.charCodeAt(counter++); - if ((extra & 0xFC00) == 0xDC00) { // low surrogate - output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); - } else { - // unmatched surrogate; only append this code unit, in case the next - // code unit is the high surrogate of a surrogate pair - output.push(value); - counter--; - } - } else { - output.push(value); - } - } - return output; - } - - // Taken from https://mths.be/punycode - function ucs2encode(array) { - var length = array.length; - var index = -1; - var value; - var output = ''; - while (++index < length) { - value = array[index]; - if (value > 0xFFFF) { - value -= 0x10000; - output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); - value = 0xDC00 | value & 0x3FF; - } - output += stringFromCharCode(value); - } - return output; - } - - function checkScalarValue(codePoint) { - if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { - throw Error( - 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + - ' is not a scalar value' - ); - } - } - /*--------------------------------------------------------------------------*/ - - function createByte(codePoint, shift) { - return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); - } - - function encodeCodePoint(codePoint) { - if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence - return stringFromCharCode(codePoint); - } - var symbol = ''; - if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence - symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); - } - else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence - checkScalarValue(codePoint); - symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); - symbol += createByte(codePoint, 6); - } - else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence - symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); - symbol += createByte(codePoint, 12); - symbol += createByte(codePoint, 6); - } - symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); - return symbol; - } - - function utf8encode(string) { - var codePoints = ucs2decode(string); - var length = codePoints.length; - var index = -1; - var codePoint; - var byteString = ''; - while (++index < length) { - codePoint = codePoints[index]; - byteString += encodeCodePoint(codePoint); - } - return byteString; - } - - /*--------------------------------------------------------------------------*/ - - function readContinuationByte() { - if (byteIndex >= byteCount) { - throw Error('Invalid byte index'); - } - - var continuationByte = byteArray[byteIndex] & 0xFF; - byteIndex++; - - if ((continuationByte & 0xC0) == 0x80) { - return continuationByte & 0x3F; - } - - // If we end up here, it?™s not a continuation byte - throw Error('Invalid continuation byte'); - } - - function decodeSymbol() { - var byte1; - var byte2; - var byte3; - var byte4; - var codePoint; - - if (byteIndex > byteCount) { - throw Error('Invalid byte index'); - } - - if (byteIndex == byteCount) { - return false; - } - - // Read first byte - byte1 = byteArray[byteIndex] & 0xFF; - byteIndex++; - - // 1-byte sequence (no continuation bytes) - if ((byte1 & 0x80) == 0) { - return byte1; - } - - // 2-byte sequence - if ((byte1 & 0xE0) == 0xC0) { - byte2 = readContinuationByte(); - codePoint = ((byte1 & 0x1F) << 6) | byte2; - if (codePoint >= 0x80) { - return codePoint; - } else { - throw Error('Invalid continuation byte'); - } - } - - // 3-byte sequence (may include unpaired surrogates) - if ((byte1 & 0xF0) == 0xE0) { - byte2 = readContinuationByte(); - byte3 = readContinuationByte(); - codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; - if (codePoint >= 0x0800) { - checkScalarValue(codePoint); - return codePoint; - } else { - throw Error('Invalid continuation byte'); - } - } - - // 4-byte sequence - if ((byte1 & 0xF8) == 0xF0) { - byte2 = readContinuationByte(); - byte3 = readContinuationByte(); - byte4 = readContinuationByte(); - codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | - (byte3 << 0x06) | byte4; - if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { - return codePoint; - } - } - - throw Error('Invalid UTF-8 detected'); - } - - var byteArray; - var byteCount; - var byteIndex; - function utf8decode(byteString) { - byteArray = ucs2decode(byteString); - byteCount = byteArray.length; - byteIndex = 0; - var codePoints = []; - var tmp; - while ((tmp = decodeSymbol()) !== false) { - codePoints.push(tmp); - } - return ucs2encode(codePoints); - } - - /*--------------------------------------------------------------------------*/ - - var utf8 = { - 'version': '2.1.2', - 'encode': utf8encode, - 'decode': utf8decode - }; - - // Some AMD build optimizers, like r.js, check for specific condition patterns - // like the following: - if ( - typeof define == 'function' && - typeof define.amd == 'object' && - define.amd - ) { - define(function() { - return utf8; - }); - } else if (freeExports && !freeExports.nodeType) { - if (freeModule) { // in Node.js or RingoJS v0.8.0+ - freeModule.exports = utf8; - } else { // in Narwhal or RingoJS v0.7.0- - var object = {}; - var hasOwnProperty = object.hasOwnProperty; - for (var key in utf8) { - hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); - } - } - } else { // in Rhino or a web browser - root.utf8 = utf8; - } - -}(this)); - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}]},{},[1]); diff --git a/teachable_machine_boilerplate_20180808/teachable_machine.js b/teachable_machine_boilerplate_20180808/teachable_machine.js deleted file mode 100644 index 9ab21812b2..0000000000 --- a/teachable_machine_boilerplate_20180808/teachable_machine.js +++ /dev/null @@ -1,45 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function teachable_machine_open() { - if (document.getElementById("train")) - { - document.getElementById("train").innerHTML = ""; - document.getElementById("probability").innerHTML = ""; - } - else - { - var div = document.createElement('div'); - div.id = "train"; - div.style.position = 'absolute'; - div.style.display = 'none'; - document.body.appendChild(div); - - var div1 = document.createElement('div'); - div1.id = "probability"; - div1.style.position = 'absolute'; - div1.style.display = 'none'; - document.body.appendChild(div1); - } - - /* - var s = document.createElement("script") - s.src = "https://rawgit.com/fustyles/webduino/temp/teachable_machine_boilerplate_20180808/build.js"; - document.getElementsByTagName("head")[0].appendChild(s); - */ - } - - function teachable_machine_proportion(input_property){ - if (input_property=="train") - return Number(document.getElementById("train").innerHTML); - else if (input_property=="probability") - return Number(document.getElementById("probability").innerHTML); - } - - window.teachable_machine_open = teachable_machine_open; - window.teachable_machine_proportion = teachable_machine_proportion; - -}(window, window.document)); diff --git a/teachable_machine_boilerplate_20180818/blockly.json b/teachable_machine_boilerplate_20180818/blockly.json deleted file mode 100644 index f32a8a01f1..0000000000 --- a/teachable_machine_boilerplate_20180818/blockly.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "types": ["teachable_machine_open","teachable_machine_proportion"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "teachable_machine.js", - "build.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/teachable_machine_boilerplate_20180818/blockly/blocks.js b/teachable_machine_boilerplate_20180818/blockly/blocks.js deleted file mode 100644 index 0986b05d58..0000000000 --- a/teachable_machine_boilerplate_20180818/blockly/blocks.js +++ /dev/null @@ -1,20 +0,0 @@ -Blockly.Blocks['teachable_machine_open'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.TEACHABLE_MACHINE_OPEN_SHOW); - this.setPreviousStatement(true); - this.setNextStatement(true); - this.setColour(65); - } -}; - -Blockly.Blocks['teachable_machine_proportion'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.TEACHABLE_MACHINE_PROPORTION_SHOW) - .appendField(new Blockly.FieldDropdown([["train","train"], ["probability","probability"]]), "property_"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(65); - } -}; diff --git a/teachable_machine_boilerplate_20180818/blockly/javascript.js b/teachable_machine_boilerplate_20180818/blockly/javascript.js deleted file mode 100644 index fe8d871a0a..0000000000 --- a/teachable_machine_boilerplate_20180818/blockly/javascript.js +++ /dev/null @@ -1,10 +0,0 @@ -Blockly.JavaScript['teachable_machine_open'] = function (block) { - var code = 'teachable_machine_open();\n'; - return code; -}; - -Blockly.JavaScript['teachable_machine_proportion'] = function(block) { - var value_property_ = block.getFieldValue('property_'); - var code = 'teachable_machine_proportion("' + value_property_ + '")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; diff --git a/teachable_machine_boilerplate_20180818/blockly/msg/blocks/en.js b/teachable_machine_boilerplate_20180818/blockly/msg/blocks/en.js deleted file mode 100644 index 647a3bc8f8..0000000000 --- a/teachable_machine_boilerplate_20180818/blockly/msg/blocks/en.js +++ /dev/null @@ -1,2 +0,0 @@ -Blockly.Msg.TEACHABLE_MACHINE_OPEN_SHOW = "Deep Learning Initialize (old version)"; -Blockly.Msg.TEACHABLE_MACHINE_PROPORTION_SHOW = "Deep Learning Max Probability (old version)"; diff --git a/teachable_machine_boilerplate_20180818/blockly/msg/blocks/zh-hans.js b/teachable_machine_boilerplate_20180818/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index 6a5827eed6..0000000000 --- a/teachable_machine_boilerplate_20180818/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1,2 +0,0 @@ -Blockly.Msg.TEACHABLE_MACHINE_OPEN_SHOW = "深度学习 初始化 (old version)"; -Blockly.Msg.TEACHABLE_MACHINE_PROPORTION_SHOW = "深度学习 最高机率 (old version)"; diff --git a/teachable_machine_boilerplate_20180818/blockly/msg/blocks/zh-hant.js b/teachable_machine_boilerplate_20180818/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index c00444fdce..0000000000 --- a/teachable_machine_boilerplate_20180818/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1,2 +0,0 @@ -Blockly.Msg.TEACHABLE_MACHINE_OPEN_SHOW = "深度學習 初始化 (old version)"; -Blockly.Msg.TEACHABLE_MACHINE_PROPORTION_SHOW = "深度學習 最高機率 (old version)"; diff --git a/teachable_machine_boilerplate_20180818/blockly/msg/en.js b/teachable_machine_boilerplate_20180818/blockly/msg/en.js deleted file mode 100644 index 0b9eb27f46..0000000000 --- a/teachable_machine_boilerplate_20180818/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.teachable_machine = "Teachable Machine"; diff --git a/teachable_machine_boilerplate_20180818/blockly/msg/zh-hans.js b/teachable_machine_boilerplate_20180818/blockly/msg/zh-hans.js deleted file mode 100644 index f826b754fe..0000000000 --- a/teachable_machine_boilerplate_20180818/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.teachable_machine = "机械学习"; diff --git a/teachable_machine_boilerplate_20180818/blockly/msg/zh-hant.js b/teachable_machine_boilerplate_20180818/blockly/msg/zh-hant.js deleted file mode 100644 index c9cfac7f83..0000000000 --- a/teachable_machine_boilerplate_20180818/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.teachable_machine = "機械學習"; diff --git a/teachable_machine_boilerplate_20180818/blockly/toolbox.xml b/teachable_machine_boilerplate_20180818/blockly/toolbox.xml deleted file mode 100644 index 96ab84bfd9..0000000000 --- a/teachable_machine_boilerplate_20180818/blockly/toolbox.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/teachable_machine_boilerplate_20180818/build.js b/teachable_machine_boilerplate_20180818/build.js deleted file mode 100644 index ed0f5ace7c..0000000000 --- a/teachable_machine_boilerplate_20180818/build.js +++ /dev/null @@ -1,21011 +0,0 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { - this.knn.predictClass(image).then(function (res) { - var max=0,maxid=-1; - for (var i = 0; i < NUM_CLASSES; i++) { - // Make the predicted class bold - if (res.classIndex == i) { - _this2.infoTexts[i].style.fontWeight = 'bold'; - } else { - _this2.infoTexts[i].style.fontWeight = 'normal'; - } - - // Update info text - - if (exampleCount[i] > 0) { - _this2.infoTexts[i].innerText = ' ' + exampleCount[i] + ' examples - ' + res.confidences[i] * 100 + '%'; - if ((res.confidences[i] * 100) >= max) - { - max=res.confidences[i] * 100; - maxid=i; - } - } - } - document.getElementById("train").innerHTML = maxid ; - document.getElementById("probability").innerHTML = max ; - }) - // Dispose image when done - .then(function () { - return image.dispose(); - }); - } else { - image.dispose(); - } - } - this.timer = requestAnimationFrame(this.animate.bind(this)); - } - }]); - - return Main; -}(); - -window.addEventListener('load', function () { - return new Main(); -}); - -},{"deeplearn":67,"deeplearn-knn-image-classifier":3}],2:[function(require,module,exports){ - -},{}],3:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var knn_image_classifier_1 = require("./knn_image_classifier"); -exports.KNNImageClassifier = knn_image_classifier_1.KNNImageClassifier; - -},{"./knn_image_classifier":4}],4:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dl = require("deeplearn"); -var deeplearn_squeezenet_1 = require("deeplearn-squeezenet"); -var model_util = require("../util"); -var KNNImageClassifier = (function () { - function KNNImageClassifier(numClasses, k) { - this.numClasses = numClasses; - this.k = k; - this.classLogitsMatrices = []; - this.classExampleCount = []; - this.varsLoaded = false; - this.squashLogitsDenominator = dl.scalar(300); - for (var i = 0; i < this.numClasses; i++) { - this.classLogitsMatrices.push(null); - this.classExampleCount.push(0); - } - this.squeezeNet = new deeplearn_squeezenet_1.SqueezeNet(); - } - KNNImageClassifier.prototype.load = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.squeezeNet.load()]; - case 1: - _a.sent(); - this.varsLoaded = true; - return [2]; - } - }); - }); - }; - KNNImageClassifier.prototype.clearClass = function (classIndex) { - if (classIndex >= this.numClasses) { - console.log('Cannot clear invalid class ${classIndex}'); - return; - } - this.classLogitsMatrices[classIndex] = null; - this.classExampleCount[classIndex] = 0; - this.clearTrainLogitsMatrix(); - }; - KNNImageClassifier.prototype.addImage = function (image, classIndex) { - var _this = this; - if (!this.varsLoaded) { - console.warn('Cannot add images until vars have been loaded.'); - return; - } - if (classIndex >= this.numClasses) { - console.warn('Cannot add to invalid class ${classIndex}'); - } - this.clearTrainLogitsMatrix(); - dl.tidy(function () { - var logits = _this.squeezeNet.predict(image); - var imageLogits = _this.normalizeVector(logits); - var logitsSize = imageLogits.shape[0]; - if (_this.classLogitsMatrices[classIndex] == null) { - _this.classLogitsMatrices[classIndex] = imageLogits.as2D(1, logitsSize); - } - else { - var newTrainLogitsMatrix = _this.classLogitsMatrices[classIndex] - .as2D(_this.classExampleCount[classIndex], logitsSize) - .concat(imageLogits.as2D(1, logitsSize), 0); - _this.classLogitsMatrices[classIndex].dispose(); - _this.classLogitsMatrices[classIndex] = newTrainLogitsMatrix; - } - dl.keep(_this.classLogitsMatrices[classIndex]); - _this.classExampleCount[classIndex]++; - }); - }; - KNNImageClassifier.prototype.predict = function (image) { - var _this = this; - if (!this.varsLoaded) { - throw new Error('Cannot predict until vars have been loaded.'); - } - return dl.tidy(function () { - var logits = _this.squeezeNet.predict(image); - var imageLogits = _this.normalizeVector(logits); - var logitsSize = imageLogits.shape[0]; - if (_this.trainLogitsMatrix == null) { - var newTrainLogitsMatrix = null; - for (var i = 0; i < _this.numClasses; i++) { - newTrainLogitsMatrix = _this.concatWithNulls(newTrainLogitsMatrix, _this.classLogitsMatrices[i]); - } - _this.trainLogitsMatrix = newTrainLogitsMatrix; - } - if (_this.trainLogitsMatrix == null) { - console.warn('Cannot predict without providing training images.'); - return null; - } - dl.keep(_this.trainLogitsMatrix); - var numExamples = _this.getNumExamples(); - return _this.trainLogitsMatrix.as2D(numExamples, logitsSize) - .matMul(imageLogits.as2D(logitsSize, 1)) - .as1D(); - }); - }; - KNNImageClassifier.prototype.predictClass = function (image) { - return __awaiter(this, void 0, void 0, function () { - var imageClass, confidences, knn, numExamples, kVal, topK, _a, _b, topKIndices, indicesForClasses, topKCountsForClasses, i, num, i, classForEntry, topConfidence, i, probability; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - imageClass = -1; - confidences = new Array(this.numClasses); - if (!this.varsLoaded) { - throw new Error('Cannot predict until vars have been loaded.'); - } - knn = this.predict(image).asType('float32'); - numExamples = this.getNumExamples(); - kVal = Math.min(this.k, numExamples); - _b = (_a = model_util).topK; - return [4, knn.data()]; - case 1: - topK = _b.apply(_a, [_c.sent(), kVal]); - knn.dispose(); - topKIndices = topK.indices; - if (topKIndices == null) { - return [2, { classIndex: imageClass, confidences: confidences }]; - } - indicesForClasses = []; - topKCountsForClasses = []; - for (i = 0; i < this.numClasses; i++) { - topKCountsForClasses.push(0); - num = this.classExampleCount[i]; - if (i > 0) { - num += indicesForClasses[i - 1]; - } - indicesForClasses.push(num); - } - for (i = 0; i < topKIndices.length; i++) { - for (classForEntry = 0; classForEntry < indicesForClasses.length; classForEntry++) { - if (topKIndices[i] < indicesForClasses[classForEntry]) { - topKCountsForClasses[classForEntry]++; - break; - } - } - } - topConfidence = 0; - for (i = 0; i < this.numClasses; i++) { - probability = topKCountsForClasses[i] / kVal; - if (probability > topConfidence) { - topConfidence = probability; - imageClass = i; - } - confidences[i] = probability; - } - return [2, { classIndex: imageClass, confidences: confidences }]; - } - }); - }); - }; - KNNImageClassifier.prototype.getClassExampleCount = function () { - return this.classExampleCount; - }; - KNNImageClassifier.prototype.clearTrainLogitsMatrix = function () { - if (this.trainLogitsMatrix != null) { - this.trainLogitsMatrix.dispose(); - this.trainLogitsMatrix = null; - } - }; - KNNImageClassifier.prototype.concatWithNulls = function (ndarray1, ndarray2) { - if (ndarray1 == null && ndarray2 == null) { - return null; - } - if (ndarray1 == null) { - return ndarray2.clone(); - } - else if (ndarray2 === null) { - return ndarray1.clone(); - } - return ndarray1.concat(ndarray2, 0); - }; - KNNImageClassifier.prototype.normalizeVector = function (vec) { - var squashedVec = dl.div(vec, this.squashLogitsDenominator); - var sqrtSum = squashedVec.square().sum().sqrt(); - return dl.div(squashedVec, sqrtSum); - }; - KNNImageClassifier.prototype.getNumExamples = function () { - var total = 0; - for (var i = 0; i < this.classExampleCount.length; i++) { - total += this.classExampleCount[i]; - } - return total; - }; - KNNImageClassifier.prototype.dispose = function () { - this.squeezeNet.dispose(); - this.clearTrainLogitsMatrix(); - this.classLogitsMatrices.forEach(function (classLogitsMatrix) { return classLogitsMatrix.dispose(); }); - this.squashLogitsDenominator.dispose(); - }; - return KNNImageClassifier; -}()); -exports.KNNImageClassifier = KNNImageClassifier; - -},{"../util":5,"deeplearn":67,"deeplearn-squeezenet":7}],5:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function topK(values, k) { - var valuesAndIndices = []; - for (var i = 0; i < values.length; i++) { - valuesAndIndices.push({ value: values[i], index: i }); - } - valuesAndIndices.sort(function (a, b) { - return b.value - a.value; - }); - var topkValues = new Float32Array(k); - var topkIndices = new Int32Array(k); - for (var i = 0; i < k; i++) { - topkValues[i] = valuesAndIndices[i].value; - topkIndices[i] = valuesAndIndices[i].index; - } - return { values: topkValues, indices: topkIndices }; -} -exports.topK = topK; - -},{}],6:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.IMAGENET_CLASSES = { - 0: 'tench, Tinca tinca', - 1: 'goldfish, Carassius auratus', - 2: 'great white shark, white shark, man-eater, man-eating shark, ' + - 'Carcharodon carcharias', - 3: 'tiger shark, Galeocerdo cuvieri', - 4: 'hammerhead, hammerhead shark', - 5: 'electric ray, crampfish, numbfish, torpedo', - 6: 'stingray', - 7: 'cock', - 8: 'hen', - 9: 'ostrich, Struthio camelus', - 10: 'brambling, Fringilla montifringilla', - 11: 'goldfinch, Carduelis carduelis', - 12: 'house finch, linnet, Carpodacus mexicanus', - 13: 'junco, snowbird', - 14: 'indigo bunting, indigo finch, indigo bird, Passerina cyanea', - 15: 'robin, American robin, Turdus migratorius', - 16: 'bulbul', - 17: 'jay', - 18: 'magpie', - 19: 'chickadee', - 20: 'water ouzel, dipper', - 21: 'kite', - 22: 'bald eagle, American eagle, Haliaeetus leucocephalus', - 23: 'vulture', - 24: 'great grey owl, great gray owl, Strix nebulosa', - 25: 'European fire salamander, Salamandra salamandra', - 26: 'common newt, Triturus vulgaris', - 27: 'eft', - 28: 'spotted salamander, Ambystoma maculatum', - 29: 'axolotl, mud puppy, Ambystoma mexicanum', - 30: 'bullfrog, Rana catesbeiana', - 31: 'tree frog, tree-frog', - 32: 'tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui', - 33: 'loggerhead, loggerhead turtle, Caretta caretta', - 34: 'leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea', - 35: 'mud turtle', - 36: 'terrapin', - 37: 'box turtle, box tortoise', - 38: 'banded gecko', - 39: 'common iguana, iguana, Iguana iguana', - 40: 'American chameleon, anole, Anolis carolinensis', - 41: 'whiptail, whiptail lizard', - 42: 'agama', - 43: 'frilled lizard, Chlamydosaurus kingi', - 44: 'alligator lizard', - 45: 'Gila monster, Heloderma suspectum', - 46: 'green lizard, Lacerta viridis', - 47: 'African chameleon, Chamaeleo chamaeleon', - 48: 'Komodo dragon, Komodo lizard, dragon lizard, giant lizard, ' + - 'Varanus komodoensis', - 49: 'African crocodile, Nile crocodile, Crocodylus niloticus', - 50: 'American alligator, Alligator mississipiensis', - 51: 'triceratops', - 52: 'thunder snake, worm snake, Carphophis amoenus', - 53: 'ringneck snake, ring-necked snake, ring snake', - 54: 'hognose snake, puff adder, sand viper', - 55: 'green snake, grass snake', - 56: 'king snake, kingsnake', - 57: 'garter snake, grass snake', - 58: 'water snake', - 59: 'vine snake', - 60: 'night snake, Hypsiglena torquata', - 61: 'boa constrictor, Constrictor constrictor', - 62: 'rock python, rock snake, Python sebae', - 63: 'Indian cobra, Naja naja', - 64: 'green mamba', - 65: 'sea snake', - 66: 'horned viper, cerastes, sand viper, horned asp, Cerastes cornutus', - 67: 'diamondback, diamondback rattlesnake, Crotalus adamanteus', - 68: 'sidewinder, horned rattlesnake, Crotalus cerastes', - 69: 'trilobite', - 70: 'harvestman, daddy longlegs, Phalangium opilio', - 71: 'scorpion', - 72: 'black and gold garden spider, Argiope aurantia', - 73: 'barn spider, Araneus cavaticus', - 74: 'garden spider, Aranea diademata', - 75: 'black widow, Latrodectus mactans', - 76: 'tarantula', - 77: 'wolf spider, hunting spider', - 78: 'tick', - 79: 'centipede', - 80: 'black grouse', - 81: 'ptarmigan', - 82: 'ruffed grouse, partridge, Bonasa umbellus', - 83: 'prairie chicken, prairie grouse, prairie fowl', - 84: 'peacock', - 85: 'quail', - 86: 'partridge', - 87: 'African grey, African gray, Psittacus erithacus', - 88: 'macaw', - 89: 'sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita', - 90: 'lorikeet', - 91: 'coucal', - 92: 'bee eater', - 93: 'hornbill', - 94: 'hummingbird', - 95: 'jacamar', - 96: 'toucan', - 97: 'drake', - 98: 'red-breasted merganser, Mergus serrator', - 99: 'goose', - 100: 'black swan, Cygnus atratus', - 101: 'tusker', - 102: 'echidna, spiny anteater, anteater', - 103: 'platypus, duckbill, duckbilled platypus, duck-billed platypus, ' + - 'Ornithorhynchus anatinus', - 104: 'wallaby, brush kangaroo', - 105: 'koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus', - 106: 'wombat', - 107: 'jelly fish', - 108: 'sea anemone, anemone', - 109: 'brain coral', - 110: 'flatworm, platyhelminth', - 111: 'nematode, nematode worm, roundworm', - 112: 'conch', - 113: 'snail', - 114: 'slug', - 115: 'sea slug, nudibranch', - 116: 'chiton, coat-of-mail shell, sea cradle, polyplacophore', - 117: 'chambered nautilus, pearly nautilus, nautilus', - 118: 'Dungeness crab, Cancer magister', - 119: 'rock crab, Cancer irroratus', - 120: 'fiddler crab', - 121: 'king crab, Alaska crab, Alaskan king crab, Alaska king crab, ' + - 'Paralithodes camtschatica', - 122: 'American lobster, Northern lobster, Maine lobster, Homarus americanus', - 123: 'spiny lobster, langouste, rock lobster, crawfish, crayfish, sea ' + - 'crawfish', - 124: 'crayfish, crawfish, crawdad, crawdaddy', - 125: 'hermit crab', - 126: 'isopod', - 127: 'white stork, Ciconia ciconia', - 128: 'black stork, Ciconia nigra', - 129: 'spoonbill', - 130: 'flamingo', - 131: 'little blue heron, Egretta caerulea', - 132: 'American egret, great white heron, Egretta albus', - 133: 'bittern', - 134: 'crane', - 135: 'limpkin, Aramus pictus', - 136: 'European gallinule, Porphyrio porphyrio', - 137: 'American coot, marsh hen, mud hen, water hen, Fulica americana', - 138: 'bustard', - 139: 'ruddy turnstone, Arenaria interpres', - 140: 'red-backed sandpiper, dunlin, Erolia alpina', - 141: 'redshank, Tringa totanus', - 142: 'dowitcher', - 143: 'oystercatcher, oyster catcher', - 144: 'pelican', - 145: 'king penguin, Aptenodytes patagonica', - 146: 'albatross, mollymawk', - 147: 'grey whale, gray whale, devilfish, Eschrichtius gibbosus, ' + - 'Eschrichtius robustus', - 148: 'killer whale, killer, orca, grampus, sea wolf, Orcinus orca', - 149: 'dugong, Dugong dugon', - 150: 'sea lion', - 151: 'Chihuahua', - 152: 'Japanese spaniel', - 153: 'Maltese dog, Maltese terrier, Maltese', - 154: 'Pekinese, Pekingese, Peke', - 155: 'Shih-Tzu', - 156: 'Blenheim spaniel', - 157: 'papillon', - 158: 'toy terrier', - 159: 'Rhodesian ridgeback', - 160: 'Afghan hound, Afghan', - 161: 'basset, basset hound', - 162: 'beagle', - 163: 'bloodhound, sleuthhound', - 164: 'bluetick', - 165: 'black-and-tan coonhound', - 166: 'Walker hound, Walker foxhound', - 167: 'English foxhound', - 168: 'redbone', - 169: 'borzoi, Russian wolfhound', - 170: 'Irish wolfhound', - 171: 'Italian greyhound', - 172: 'whippet', - 173: 'Ibizan hound, Ibizan Podenco', - 174: 'Norwegian elkhound, elkhound', - 175: 'otterhound, otter hound', - 176: 'Saluki, gazelle hound', - 177: 'Scottish deerhound, deerhound', - 178: 'Weimaraner', - 179: 'Staffordshire bullterrier, Staffordshire bull terrier', - 180: 'American Staffordshire terrier, Staffordshire terrier, American pit ' + - 'bull terrier, pit bull terrier', - 181: 'Bedlington terrier', - 182: 'Border terrier', - 183: 'Kerry blue terrier', - 184: 'Irish terrier', - 185: 'Norfolk terrier', - 186: 'Norwich terrier', - 187: 'Yorkshire terrier', - 188: 'wire-haired fox terrier', - 189: 'Lakeland terrier', - 190: 'Sealyham terrier, Sealyham', - 191: 'Airedale, Airedale terrier', - 192: 'cairn, cairn terrier', - 193: 'Australian terrier', - 194: 'Dandie Dinmont, Dandie Dinmont terrier', - 195: 'Boston bull, Boston terrier', - 196: 'miniature schnauzer', - 197: 'giant schnauzer', - 198: 'standard schnauzer', - 199: 'Scotch terrier, Scottish terrier, Scottie', - 200: 'Tibetan terrier, chrysanthemum dog', - 201: 'silky terrier, Sydney silky', - 202: 'soft-coated wheaten terrier', - 203: 'West Highland white terrier', - 204: 'Lhasa, Lhasa apso', - 205: 'flat-coated retriever', - 206: 'curly-coated retriever', - 207: 'golden retriever', - 208: 'Labrador retriever', - 209: 'Chesapeake Bay retriever', - 210: 'German short-haired pointer', - 211: 'vizsla, Hungarian pointer', - 212: 'English setter', - 213: 'Irish setter, red setter', - 214: 'Gordon setter', - 215: 'Brittany spaniel', - 216: 'clumber, clumber spaniel', - 217: 'English springer, English springer spaniel', - 218: 'Welsh springer spaniel', - 219: 'cocker spaniel, English cocker spaniel, cocker', - 220: 'Sussex spaniel', - 221: 'Irish water spaniel', - 222: 'kuvasz', - 223: 'schipperke', - 224: 'groenendael', - 225: 'malinois', - 226: 'briard', - 227: 'kelpie', - 228: 'komondor', - 229: 'Old English sheepdog, bobtail', - 230: 'Shetland sheepdog, Shetland sheep dog, Shetland', - 231: 'collie', - 232: 'Border collie', - 233: 'Bouvier des Flandres, Bouviers des Flandres', - 234: 'Rottweiler', - 235: 'German shepherd, German shepherd dog, German police dog, alsatian', - 236: 'Doberman, Doberman pinscher', - 237: 'miniature pinscher', - 238: 'Greater Swiss Mountain dog', - 239: 'Bernese mountain dog', - 240: 'Appenzeller', - 241: 'EntleBucher', - 242: 'boxer', - 243: 'bull mastiff', - 244: 'Tibetan mastiff', - 245: 'French bulldog', - 246: 'Great Dane', - 247: 'Saint Bernard, St Bernard', - 248: 'Eskimo dog, husky', - 249: 'malamute, malemute, Alaskan malamute', - 250: 'Siberian husky', - 251: 'dalmatian, coach dog, carriage dog', - 252: 'affenpinscher, monkey pinscher, monkey dog', - 253: 'basenji', - 254: 'pug, pug-dog', - 255: 'Leonberg', - 256: 'Newfoundland, Newfoundland dog', - 257: 'Great Pyrenees', - 258: 'Samoyed, Samoyede', - 259: 'Pomeranian', - 260: 'chow, chow chow', - 261: 'keeshond', - 262: 'Brabancon griffon', - 263: 'Pembroke, Pembroke Welsh corgi', - 264: 'Cardigan, Cardigan Welsh corgi', - 265: 'toy poodle', - 266: 'miniature poodle', - 267: 'standard poodle', - 268: 'Mexican hairless', - 269: 'timber wolf, grey wolf, gray wolf, Canis lupus', - 270: 'white wolf, Arctic wolf, Canis lupus tundrarum', - 271: 'red wolf, maned wolf, Canis rufus, Canis niger', - 272: 'coyote, prairie wolf, brush wolf, Canis latrans', - 273: 'dingo, warrigal, warragal, Canis dingo', - 274: 'dhole, Cuon alpinus', - 275: 'African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus', - 276: 'hyena, hyaena', - 277: 'red fox, Vulpes vulpes', - 278: 'kit fox, Vulpes macrotis', - 279: 'Arctic fox, white fox, Alopex lagopus', - 280: 'grey fox, gray fox, Urocyon cinereoargenteus', - 281: 'tabby, tabby cat', - 282: 'tiger cat', - 283: 'Persian cat', - 284: 'Siamese cat, Siamese', - 285: 'Egyptian cat', - 286: 'cougar, puma, catamount, mountain lion, painter, panther, ' + - 'Felis concolor', - 287: 'lynx, catamount', - 288: 'leopard, Panthera pardus', - 289: 'snow leopard, ounce, Panthera uncia', - 290: 'jaguar, panther, Panthera onca, Felis onca', - 291: 'lion, king of beasts, Panthera leo', - 292: 'tiger, Panthera tigris', - 293: 'cheetah, chetah, Acinonyx jubatus', - 294: 'brown bear, bruin, Ursus arctos', - 295: 'American black bear, black bear, Ursus americanus, Euarctos ' + - 'americanus', - 296: 'ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus', - 297: 'sloth bear, Melursus ursinus, Ursus ursinus', - 298: 'mongoose', - 299: 'meerkat, mierkat', - 300: 'tiger beetle', - 301: 'ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle', - 302: 'ground beetle, carabid beetle', - 303: 'long-horned beetle, longicorn, longicorn beetle', - 304: 'leaf beetle, chrysomelid', - 305: 'dung beetle', - 306: 'rhinoceros beetle', - 307: 'weevil', - 308: 'fly', - 309: 'bee', - 310: 'ant, emmet, pismire', - 311: 'grasshopper, hopper', - 312: 'cricket', - 313: 'walking stick, walkingstick, stick insect', - 314: 'cockroach, roach', - 315: 'mantis, mantid', - 316: 'cicada, cicala', - 317: 'leafhopper', - 318: 'lacewing, lacewing fly', - 319: 'dragonfly, darning needle, devil\'s darning needle, sewing needle, ' + - 'snake feeder, snake doctor, mosquito hawk, skeeter hawk', - 320: 'damselfly', - 321: 'admiral', - 322: 'ringlet, ringlet butterfly', - 323: 'monarch, monarch butterfly, milkweed butterfly, Danaus plexippus', - 324: 'cabbage butterfly', - 325: 'sulphur butterfly, sulfur butterfly', - 326: 'lycaenid, lycaenid butterfly', - 327: 'starfish, sea star', - 328: 'sea urchin', - 329: 'sea cucumber, holothurian', - 330: 'wood rabbit, cottontail, cottontail rabbit', - 331: 'hare', - 332: 'Angora, Angora rabbit', - 333: 'hamster', - 334: 'porcupine, hedgehog', - 335: 'fox squirrel, eastern fox squirrel, Sciurus niger', - 336: 'marmot', - 337: 'beaver', - 338: 'guinea pig, Cavia cobaya', - 339: 'sorrel', - 340: 'zebra', - 341: 'hog, pig, grunter, squealer, Sus scrofa', - 342: 'wild boar, boar, Sus scrofa', - 343: 'warthog', - 344: 'hippopotamus, hippo, river horse, Hippopotamus amphibius', - 345: 'ox', - 346: 'water buffalo, water ox, Asiatic buffalo, Bubalus bubalis', - 347: 'bison', - 348: 'ram, tup', - 349: 'bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky ' + - 'Mountain sheep, Ovis canadensis', - 350: 'ibex, Capra ibex', - 351: 'hartebeest', - 352: 'impala, Aepyceros melampus', - 353: 'gazelle', - 354: 'Arabian camel, dromedary, Camelus dromedarius', - 355: 'llama', - 356: 'weasel', - 357: 'mink', - 358: 'polecat, fitch, foulmart, foumart, Mustela putorius', - 359: 'black-footed ferret, ferret, Mustela nigripes', - 360: 'otter', - 361: 'skunk, polecat, wood pussy', - 362: 'badger', - 363: 'armadillo', - 364: 'three-toed sloth, ai, Bradypus tridactylus', - 365: 'orangutan, orang, orangutang, Pongo pygmaeus', - 366: 'gorilla, Gorilla gorilla', - 367: 'chimpanzee, chimp, Pan troglodytes', - 368: 'gibbon, Hylobates lar', - 369: 'siamang, Hylobates syndactylus, Symphalangus syndactylus', - 370: 'guenon, guenon monkey', - 371: 'patas, hussar monkey, Erythrocebus patas', - 372: 'baboon', - 373: 'macaque', - 374: 'langur', - 375: 'colobus, colobus monkey', - 376: 'proboscis monkey, Nasalis larvatus', - 377: 'marmoset', - 378: 'capuchin, ringtail, Cebus capucinus', - 379: 'howler monkey, howler', - 380: 'titi, titi monkey', - 381: 'spider monkey, Ateles geoffroyi', - 382: 'squirrel monkey, Saimiri sciureus', - 383: 'Madagascar cat, ring-tailed lemur, Lemur catta', - 384: 'indri, indris, Indri indri, Indri brevicaudatus', - 385: 'Indian elephant, Elephas maximus', - 386: 'African elephant, Loxodonta africana', - 387: 'lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens', - 388: 'giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca', - 389: 'barracouta, snoek', - 390: 'eel', - 391: 'coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus ' + - 'kisutch', - 392: 'rock beauty, Holocanthus tricolor', - 393: 'anemone fish', - 394: 'sturgeon', - 395: 'gar, garfish, garpike, billfish, Lepisosteus osseus', - 396: 'lionfish', - 397: 'puffer, pufferfish, blowfish, globefish', - 398: 'abacus', - 399: 'abaya', - 400: 'academic gown, academic robe, judge\'s robe', - 401: 'accordion, piano accordion, squeeze box', - 402: 'acoustic guitar', - 403: 'aircraft carrier, carrier, flattop, attack aircraft carrier', - 404: 'airliner', - 405: 'airship, dirigible', - 406: 'altar', - 407: 'ambulance', - 408: 'amphibian, amphibious vehicle', - 409: 'analog clock', - 410: 'apiary, bee house', - 411: 'apron', - 412: 'ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, ' + - 'dustbin, trash barrel, trash bin', - 413: 'assault rifle, assault gun', - 414: 'backpack, back pack, knapsack, packsack, rucksack, haversack', - 415: 'bakery, bakeshop, bakehouse', - 416: 'balance beam, beam', - 417: 'balloon', - 418: 'ballpoint, ballpoint pen, ballpen, Biro', - 419: 'Band Aid', - 420: 'banjo', - 421: 'bannister, banister, balustrade, balusters, handrail', - 422: 'barbell', - 423: 'barber chair', - 424: 'barbershop', - 425: 'barn', - 426: 'barometer', - 427: 'barrel, cask', - 428: 'barrow, garden cart, lawn cart, wheelbarrow', - 429: 'baseball', - 430: 'basketball', - 431: 'bassinet', - 432: 'bassoon', - 433: 'bathing cap, swimming cap', - 434: 'bath towel', - 435: 'bathtub, bathing tub, bath, tub', - 436: 'beach wagon, station wagon, wagon, estate car, beach waggon, station ' + - 'waggon, waggon', - 437: 'beacon, lighthouse, beacon light, pharos', - 438: 'beaker', - 439: 'bearskin, busby, shako', - 440: 'beer bottle', - 441: 'beer glass', - 442: 'bell cote, bell cot', - 443: 'bib', - 444: 'bicycle-built-for-two, tandem bicycle, tandem', - 445: 'bikini, two-piece', - 446: 'binder, ring-binder', - 447: 'binoculars, field glasses, opera glasses', - 448: 'birdhouse', - 449: 'boathouse', - 450: 'bobsled, bobsleigh, bob', - 451: 'bolo tie, bolo, bola tie, bola', - 452: 'bonnet, poke bonnet', - 453: 'bookcase', - 454: 'bookshop, bookstore, bookstall', - 455: 'bottlecap', - 456: 'bow', - 457: 'bow tie, bow-tie, bowtie', - 458: 'brass, memorial tablet, plaque', - 459: 'brassiere, bra, bandeau', - 460: 'breakwater, groin, groyne, mole, bulwark, seawall, jetty', - 461: 'breastplate, aegis, egis', - 462: 'broom', - 463: 'bucket, pail', - 464: 'buckle', - 465: 'bulletproof vest', - 466: 'bullet train, bullet', - 467: 'butcher shop, meat market', - 468: 'cab, hack, taxi, taxicab', - 469: 'caldron, cauldron', - 470: 'candle, taper, wax light', - 471: 'cannon', - 472: 'canoe', - 473: 'can opener, tin opener', - 474: 'cardigan', - 475: 'car mirror', - 476: 'carousel, carrousel, merry-go-round, roundabout, whirligig', - 477: 'carpenter\'s kit, tool kit', - 478: 'carton', - 479: 'car wheel', - 480: 'cash machine, cash dispenser, automated teller machine, automatic ' + - 'teller machine, automated teller, automatic teller, ATM', - 481: 'cassette', - 482: 'cassette player', - 483: 'castle', - 484: 'catamaran', - 485: 'CD player', - 486: 'cello, violoncello', - 487: 'cellular telephone, cellular phone, cellphone, cell, mobile phone', - 488: 'chain', - 489: 'chainlink fence', - 490: 'chain mail, ring mail, mail, chain armor, chain armour, ring armor, ' + - 'ring armour', - 491: 'chain saw, chainsaw', - 492: 'chest', - 493: 'chiffonier, commode', - 494: 'chime, bell, gong', - 495: 'china cabinet, china closet', - 496: 'Christmas stocking', - 497: 'church, church building', - 498: 'cinema, movie theater, movie theatre, movie house, picture palace', - 499: 'cleaver, meat cleaver, chopper', - 500: 'cliff dwelling', - 501: 'cloak', - 502: 'clog, geta, patten, sabot', - 503: 'cocktail shaker', - 504: 'coffee mug', - 505: 'coffeepot', - 506: 'coil, spiral, volute, whorl, helix', - 507: 'combination lock', - 508: 'computer keyboard, keypad', - 509: 'confectionery, confectionary, candy store', - 510: 'container ship, containership, container vessel', - 511: 'convertible', - 512: 'corkscrew, bottle screw', - 513: 'cornet, horn, trumpet, trump', - 514: 'cowboy boot', - 515: 'cowboy hat, ten-gallon hat', - 516: 'cradle', - 517: 'crane', - 518: 'crash helmet', - 519: 'crate', - 520: 'crib, cot', - 521: 'Crock Pot', - 522: 'croquet ball', - 523: 'crutch', - 524: 'cuirass', - 525: 'dam, dike, dyke', - 526: 'desk', - 527: 'desktop computer', - 528: 'dial telephone, dial phone', - 529: 'diaper, nappy, napkin', - 530: 'digital clock', - 531: 'digital watch', - 532: 'dining table, board', - 533: 'dishrag, dishcloth', - 534: 'dishwasher, dish washer, dishwashing machine', - 535: 'disk brake, disc brake', - 536: 'dock, dockage, docking facility', - 537: 'dogsled, dog sled, dog sleigh', - 538: 'dome', - 539: 'doormat, welcome mat', - 540: 'drilling platform, offshore rig', - 541: 'drum, membranophone, tympan', - 542: 'drumstick', - 543: 'dumbbell', - 544: 'Dutch oven', - 545: 'electric fan, blower', - 546: 'electric guitar', - 547: 'electric locomotive', - 548: 'entertainment center', - 549: 'envelope', - 550: 'espresso maker', - 551: 'face powder', - 552: 'feather boa, boa', - 553: 'file, file cabinet, filing cabinet', - 554: 'fireboat', - 555: 'fire engine, fire truck', - 556: 'fire screen, fireguard', - 557: 'flagpole, flagstaff', - 558: 'flute, transverse flute', - 559: 'folding chair', - 560: 'football helmet', - 561: 'forklift', - 562: 'fountain', - 563: 'fountain pen', - 564: 'four-poster', - 565: 'freight car', - 566: 'French horn, horn', - 567: 'frying pan, frypan, skillet', - 568: 'fur coat', - 569: 'garbage truck, dustcart', - 570: 'gasmask, respirator, gas helmet', - 571: 'gas pump, gasoline pump, petrol pump, island dispenser', - 572: 'goblet', - 573: 'go-kart', - 574: 'golf ball', - 575: 'golfcart, golf cart', - 576: 'gondola', - 577: 'gong, tam-tam', - 578: 'gown', - 579: 'grand piano, grand', - 580: 'greenhouse, nursery, glasshouse', - 581: 'grille, radiator grille', - 582: 'grocery store, grocery, food market, market', - 583: 'guillotine', - 584: 'hair slide', - 585: 'hair spray', - 586: 'half track', - 587: 'hammer', - 588: 'hamper', - 589: 'hand blower, blow dryer, blow drier, hair dryer, hair drier', - 590: 'hand-held computer, hand-held microcomputer', - 591: 'handkerchief, hankie, hanky, hankey', - 592: 'hard disc, hard disk, fixed disk', - 593: 'harmonica, mouth organ, harp, mouth harp', - 594: 'harp', - 595: 'harvester, reaper', - 596: 'hatchet', - 597: 'holster', - 598: 'home theater, home theatre', - 599: 'honeycomb', - 600: 'hook, claw', - 601: 'hoopskirt, crinoline', - 602: 'horizontal bar, high bar', - 603: 'horse cart, horse-cart', - 604: 'hourglass', - 605: 'iPod', - 606: 'iron, smoothing iron', - 607: 'jack-o\'-lantern', - 608: 'jean, blue jean, denim', - 609: 'jeep, landrover', - 610: 'jersey, T-shirt, tee shirt', - 611: 'jigsaw puzzle', - 612: 'jinrikisha, ricksha, rickshaw', - 613: 'joystick', - 614: 'kimono', - 615: 'knee pad', - 616: 'knot', - 617: 'lab coat, laboratory coat', - 618: 'ladle', - 619: 'lampshade, lamp shade', - 620: 'laptop, laptop computer', - 621: 'lawn mower, mower', - 622: 'lens cap, lens cover', - 623: 'letter opener, paper knife, paperknife', - 624: 'library', - 625: 'lifeboat', - 626: 'lighter, light, igniter, ignitor', - 627: 'limousine, limo', - 628: 'liner, ocean liner', - 629: 'lipstick, lip rouge', - 630: 'Loafer', - 631: 'lotion', - 632: 'loudspeaker, speaker, speaker unit, loudspeaker system, speaker ' + - 'system', - 633: 'loupe, jeweler\'s loupe', - 634: 'lumbermill, sawmill', - 635: 'magnetic compass', - 636: 'mailbag, postbag', - 637: 'mailbox, letter box', - 638: 'maillot', - 639: 'maillot, tank suit', - 640: 'manhole cover', - 641: 'maraca', - 642: 'marimba, xylophone', - 643: 'mask', - 644: 'matchstick', - 645: 'maypole', - 646: 'maze, labyrinth', - 647: 'measuring cup', - 648: 'medicine chest, medicine cabinet', - 649: 'megalith, megalithic structure', - 650: 'microphone, mike', - 651: 'microwave, microwave oven', - 652: 'military uniform', - 653: 'milk can', - 654: 'minibus', - 655: 'miniskirt, mini', - 656: 'minivan', - 657: 'missile', - 658: 'mitten', - 659: 'mixing bowl', - 660: 'mobile home, manufactured home', - 661: 'Model T', - 662: 'modem', - 663: 'monastery', - 664: 'monitor', - 665: 'moped', - 666: 'mortar', - 667: 'mortarboard', - 668: 'mosque', - 669: 'mosquito net', - 670: 'motor scooter, scooter', - 671: 'mountain bike, all-terrain bike, off-roader', - 672: 'mountain tent', - 673: 'mouse, computer mouse', - 674: 'mousetrap', - 675: 'moving van', - 676: 'muzzle', - 677: 'nail', - 678: 'neck brace', - 679: 'necklace', - 680: 'nipple', - 681: 'notebook, notebook computer', - 682: 'obelisk', - 683: 'oboe, hautboy, hautbois', - 684: 'ocarina, sweet potato', - 685: 'odometer, hodometer, mileometer, milometer', - 686: 'oil filter', - 687: 'organ, pipe organ', - 688: 'oscilloscope, scope, cathode-ray oscilloscope, CRO', - 689: 'overskirt', - 690: 'oxcart', - 691: 'oxygen mask', - 692: 'packet', - 693: 'paddle, boat paddle', - 694: 'paddlewheel, paddle wheel', - 695: 'padlock', - 696: 'paintbrush', - 697: 'pajama, pyjama, pj\'s, jammies', - 698: 'palace', - 699: 'panpipe, pandean pipe, syrinx', - 700: 'paper towel', - 701: 'parachute, chute', - 702: 'parallel bars, bars', - 703: 'park bench', - 704: 'parking meter', - 705: 'passenger car, coach, carriage', - 706: 'patio, terrace', - 707: 'pay-phone, pay-station', - 708: 'pedestal, plinth, footstall', - 709: 'pencil box, pencil case', - 710: 'pencil sharpener', - 711: 'perfume, essence', - 712: 'Petri dish', - 713: 'photocopier', - 714: 'pick, plectrum, plectron', - 715: 'pickelhaube', - 716: 'picket fence, paling', - 717: 'pickup, pickup truck', - 718: 'pier', - 719: 'piggy bank, penny bank', - 720: 'pill bottle', - 721: 'pillow', - 722: 'ping-pong ball', - 723: 'pinwheel', - 724: 'pirate, pirate ship', - 725: 'pitcher, ewer', - 726: 'plane, carpenter\'s plane, woodworking plane', - 727: 'planetarium', - 728: 'plastic bag', - 729: 'plate rack', - 730: 'plow, plough', - 731: 'plunger, plumber\'s helper', - 732: 'Polaroid camera, Polaroid Land camera', - 733: 'pole', - 734: 'police van, police wagon, paddy wagon, patrol wagon, wagon, black ' + - 'Maria', - 735: 'poncho', - 736: 'pool table, billiard table, snooker table', - 737: 'pop bottle, soda bottle', - 738: 'pot, flowerpot', - 739: 'potter\'s wheel', - 740: 'power drill', - 741: 'prayer rug, prayer mat', - 742: 'printer', - 743: 'prison, prison house', - 744: 'projectile, missile', - 745: 'projector', - 746: 'puck, hockey puck', - 747: 'punching bag, punch bag, punching ball, punchball', - 748: 'purse', - 749: 'quill, quill pen', - 750: 'quilt, comforter, comfort, puff', - 751: 'racer, race car, racing car', - 752: 'racket, racquet', - 753: 'radiator', - 754: 'radio, wireless', - 755: 'radio telescope, radio reflector', - 756: 'rain barrel', - 757: 'recreational vehicle, RV, R.V.', - 758: 'reel', - 759: 'reflex camera', - 760: 'refrigerator, icebox', - 761: 'remote control, remote', - 762: 'restaurant, eating house, eating place, eatery', - 763: 'revolver, six-gun, six-shooter', - 764: 'rifle', - 765: 'rocking chair, rocker', - 766: 'rotisserie', - 767: 'rubber eraser, rubber, pencil eraser', - 768: 'rugby ball', - 769: 'rule, ruler', - 770: 'running shoe', - 771: 'safe', - 772: 'safety pin', - 773: 'saltshaker, salt shaker', - 774: 'sandal', - 775: 'sarong', - 776: 'sax, saxophone', - 777: 'scabbard', - 778: 'scale, weighing machine', - 779: 'school bus', - 780: 'schooner', - 781: 'scoreboard', - 782: 'screen, CRT screen', - 783: 'screw', - 784: 'screwdriver', - 785: 'seat belt, seatbelt', - 786: 'sewing machine', - 787: 'shield, buckler', - 788: 'shoe shop, shoe-shop, shoe store', - 789: 'shoji', - 790: 'shopping basket', - 791: 'shopping cart', - 792: 'shovel', - 793: 'shower cap', - 794: 'shower curtain', - 795: 'ski', - 796: 'ski mask', - 797: 'sleeping bag', - 798: 'slide rule, slipstick', - 799: 'sliding door', - 800: 'slot, one-armed bandit', - 801: 'snorkel', - 802: 'snowmobile', - 803: 'snowplow, snowplough', - 804: 'soap dispenser', - 805: 'soccer ball', - 806: 'sock', - 807: 'solar dish, solar collector, solar furnace', - 808: 'sombrero', - 809: 'soup bowl', - 810: 'space bar', - 811: 'space heater', - 812: 'space shuttle', - 813: 'spatula', - 814: 'speedboat', - 815: 'spider web, spider\'s web', - 816: 'spindle', - 817: 'sports car, sport car', - 818: 'spotlight, spot', - 819: 'stage', - 820: 'steam locomotive', - 821: 'steel arch bridge', - 822: 'steel drum', - 823: 'stethoscope', - 824: 'stole', - 825: 'stone wall', - 826: 'stopwatch, stop watch', - 827: 'stove', - 828: 'strainer', - 829: 'streetcar, tram, tramcar, trolley, trolley car', - 830: 'stretcher', - 831: 'studio couch, day bed', - 832: 'stupa, tope', - 833: 'submarine, pigboat, sub, U-boat', - 834: 'suit, suit of clothes', - 835: 'sundial', - 836: 'sunglass', - 837: 'sunglasses, dark glasses, shades', - 838: 'sunscreen, sunblock, sun blocker', - 839: 'suspension bridge', - 840: 'swab, swob, mop', - 841: 'sweatshirt', - 842: 'swimming trunks, bathing trunks', - 843: 'swing', - 844: 'switch, electric switch, electrical switch', - 845: 'syringe', - 846: 'table lamp', - 847: 'tank, army tank, armored combat vehicle, armoured combat vehicle', - 848: 'tape player', - 849: 'teapot', - 850: 'teddy, teddy bear', - 851: 'television, television system', - 852: 'tennis ball', - 853: 'thatch, thatched roof', - 854: 'theater curtain, theatre curtain', - 855: 'thimble', - 856: 'thresher, thrasher, threshing machine', - 857: 'throne', - 858: 'tile roof', - 859: 'toaster', - 860: 'tobacco shop, tobacconist shop, tobacconist', - 861: 'toilet seat', - 862: 'torch', - 863: 'totem pole', - 864: 'tow truck, tow car, wrecker', - 865: 'toyshop', - 866: 'tractor', - 867: 'trailer truck, tractor trailer, trucking rig, rig, articulated ' + - 'lorry, semi', - 868: 'tray', - 869: 'trench coat', - 870: 'tricycle, trike, velocipede', - 871: 'trimaran', - 872: 'tripod', - 873: 'triumphal arch', - 874: 'trolleybus, trolley coach, trackless trolley', - 875: 'trombone', - 876: 'tub, vat', - 877: 'turnstile', - 878: 'typewriter keyboard', - 879: 'umbrella', - 880: 'unicycle, monocycle', - 881: 'upright, upright piano', - 882: 'vacuum, vacuum cleaner', - 883: 'vase', - 884: 'vault', - 885: 'velvet', - 886: 'vending machine', - 887: 'vestment', - 888: 'viaduct', - 889: 'violin, fiddle', - 890: 'volleyball', - 891: 'waffle iron', - 892: 'wall clock', - 893: 'wallet, billfold, notecase, pocketbook', - 894: 'wardrobe, closet, press', - 895: 'warplane, military plane', - 896: 'washbasin, handbasin, washbowl, lavabo, wash-hand basin', - 897: 'washer, automatic washer, washing machine', - 898: 'water bottle', - 899: 'water jug', - 900: 'water tower', - 901: 'whiskey jug', - 902: 'whistle', - 903: 'wig', - 904: 'window screen', - 905: 'window shade', - 906: 'Windsor tie', - 907: 'wine bottle', - 908: 'wing', - 909: 'wok', - 910: 'wooden spoon', - 911: 'wool, woolen, woollen', - 912: 'worm fence, snake fence, snake-rail fence, Virginia fence', - 913: 'wreck', - 914: 'yawl', - 915: 'yurt', - 916: 'web site, website, internet site, site', - 917: 'comic book', - 918: 'crossword puzzle, crossword', - 919: 'street sign', - 920: 'traffic light, traffic signal, stoplight', - 921: 'book jacket, dust cover, dust jacket, dust wrapper', - 922: 'menu', - 923: 'plate', - 924: 'guacamole', - 925: 'consomme', - 926: 'hot pot, hotpot', - 927: 'trifle', - 928: 'ice cream, icecream', - 929: 'ice lolly, lolly, lollipop, popsicle', - 930: 'French loaf', - 931: 'bagel, beigel', - 932: 'pretzel', - 933: 'cheeseburger', - 934: 'hotdog, hot dog, red hot', - 935: 'mashed potato', - 936: 'head cabbage', - 937: 'broccoli', - 938: 'cauliflower', - 939: 'zucchini, courgette', - 940: 'spaghetti squash', - 941: 'acorn squash', - 942: 'butternut squash', - 943: 'cucumber, cuke', - 944: 'artichoke, globe artichoke', - 945: 'bell pepper', - 946: 'cardoon', - 947: 'mushroom', - 948: 'Granny Smith', - 949: 'strawberry', - 950: 'orange', - 951: 'lemon', - 952: 'fig', - 953: 'pineapple, ananas', - 954: 'banana', - 955: 'jackfruit, jak, jack', - 956: 'custard apple', - 957: 'pomegranate', - 958: 'hay', - 959: 'carbonara', - 960: 'chocolate sauce, chocolate syrup', - 961: 'dough', - 962: 'meat loaf, meatloaf', - 963: 'pizza, pizza pie', - 964: 'potpie', - 965: 'burrito', - 966: 'red wine', - 967: 'espresso', - 968: 'cup', - 969: 'eggnog', - 970: 'alp', - 971: 'bubble', - 972: 'cliff, drop, drop-off', - 973: 'coral reef', - 974: 'geyser', - 975: 'lakeside, lakeshore', - 976: 'promontory, headland, head, foreland', - 977: 'sandbar, sand bar', - 978: 'seashore, coast, seacoast, sea-coast', - 979: 'valley, vale', - 980: 'volcano', - 981: 'ballplayer, baseball player', - 982: 'groom, bridegroom', - 983: 'scuba diver', - 984: 'rapeseed', - 985: 'daisy', - 986: 'yellow lady\'s slipper, yellow lady-slipper, Cypripedium calceolus, ' + - 'Cypripedium parviflorum', - 987: 'corn', - 988: 'acorn', - 989: 'hip, rose hip, rosehip', - 990: 'buckeye, horse chestnut, conker', - 991: 'coral fungus', - 992: 'agaric', - 993: 'gyromitra', - 994: 'stinkhorn, carrion fungus', - 995: 'earthstar', - 996: 'hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola ' + - 'frondosa', - 997: 'bolete', - 998: 'ear, spike, capitulum', - 999: 'toilet tissue, toilet paper, bathroom tissue' -}; - -},{}],7:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var squeezenet_1 = require("./squeezenet"); -exports.SqueezeNet = squeezenet_1.SqueezeNet; - -},{"./squeezenet":8}],8:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dl = require("deeplearn"); -var model_util = require("../util"); -var imagenet_classes_1 = require("./imagenet_classes"); -var GOOGLE_CLOUD_STORAGE_DIR = 'https://storage.googleapis.com/learnjs-data/checkpoint_zoo/'; -var SqueezeNet = (function () { - function SqueezeNet() { - this.preprocessOffset = dl.tensor1d([103.939, 116.779, 123.68]); - } - SqueezeNet.prototype.load = function () { - return __awaiter(this, void 0, void 0, function () { - var checkpointLoader, _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - checkpointLoader = new dl.CheckpointLoader(GOOGLE_CLOUD_STORAGE_DIR + 'squeezenet1_1/'); - _a = this; - return [4, checkpointLoader.getAllVariables()]; - case 1: - _a.variables = _b.sent(); - return [2]; - } - }); - }); - }; - SqueezeNet.prototype.predict = function (input) { - return this.predictWithActivation(input).logits; - }; - SqueezeNet.prototype.predictWithActivation = function (input, activationName) { - var _this = this; - return dl.tidy(function () { - var activation; - var preprocessedInput = dl.sub(input.asType('float32'), _this.preprocessOffset); - var conv1relu = preprocessedInput - .conv2d(_this.variables['conv1_W:0'], 2, 0) - .add(_this.variables['conv1_b:0']) - .relu(); - if (activationName === 'conv_1') { - activation = conv1relu; - } - var pool1 = conv1relu.maxPool(3, 2, 0); - if (activationName === 'maxpool_1') { - activation = pool1; - } - var fire2 = _this.fireModule(pool1, 2); - if (activationName === 'fire2') { - activation = fire2; - } - var fire3 = _this.fireModule(fire2, 3); - if (activationName === 'fire3') { - activation = fire3; - } - var pool2 = fire3.maxPool(3, 2, 'valid'); - if (activationName === 'maxpool_2') { - activation = pool2; - } - var fire4 = _this.fireModule(pool2, 4); - if (activationName === 'fire4') { - activation = fire4; - } - var fire5 = _this.fireModule(fire4, 5); - if (activationName === 'fire5') { - activation = fire5; - } - var pool3 = fire5.maxPool(3, 2, 0); - if (activationName === 'maxpool_3') { - activation = pool3; - } - var fire6 = _this.fireModule(pool3, 6); - if (activationName === 'fire6') { - activation = fire6; - } - var fire7 = _this.fireModule(fire6, 7); - if (activationName === 'fire7') { - activation = fire7; - } - var fire8 = _this.fireModule(fire7, 8); - if (activationName === 'fire8') { - activation = fire8; - } - var fire9 = _this.fireModule(fire8, 9); - if (activationName === 'fire9') { - activation = fire9; - } - var conv10 = fire9.conv2d(_this.variables['conv10_W:0'], 1, 0) - .add(_this.variables['conv10_b:0']); - if (activationName === 'conv10') { - activation = conv10; - } - return { - logits: dl.avgPool(conv10, conv10.shape[0], 1, 0).as1D(), - activation: activation - }; - }); - }; - SqueezeNet.prototype.fireModule = function (input, fireId) { - var y = dl.conv2d(input, this.variables["fire" + fireId + "/squeeze1x1_W:0"], 1, 0) - .add(this.variables["fire" + fireId + "/squeeze1x1_b:0"]) - .relu(); - var left = dl.conv2d(y, this.variables["fire" + fireId + "/expand1x1_W:0"], 1, 0) - .add(this.variables["fire" + fireId + "/expand1x1_b:0"]) - .relu(); - var right = dl.conv2d(y, this.variables["fire" + fireId + "/expand3x3_W:0"], 1, 1) - .add(this.variables["fire" + fireId + "/expand3x3_b:0"]) - .relu(); - return left.concat(right, 2); - }; - SqueezeNet.prototype.getTopKClasses = function (logits, topK) { - return __awaiter(this, void 0, void 0, function () { - var predictions, topk, _a, _b, topkIndices, topkValues, topClassesToProbability, i; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - predictions = dl.tidy(function () { - return dl.softmax(logits).asType('float32'); - }); - _b = (_a = model_util).topK; - return [4, predictions.data()]; - case 1: - topk = _b.apply(_a, [_c.sent(), topK]); - predictions.dispose(); - topkIndices = topk.indices; - topkValues = topk.values; - topClassesToProbability = {}; - for (i = 0; i < topkIndices.length; i++) { - topClassesToProbability[imagenet_classes_1.IMAGENET_CLASSES[topkIndices[i]]] = topkValues[i]; - } - return [2, topClassesToProbability]; - } - }); - }); - }; - SqueezeNet.prototype.dispose = function () { - this.preprocessOffset.dispose(); - for (var varName in this.variables) { - this.variables[varName].dispose(); - } - }; - return SqueezeNet; -}()); -exports.SqueezeNet = SqueezeNet; - -},{"../util":9,"./imagenet_classes":6,"deeplearn":67}],9:[function(require,module,exports){ -arguments[4][5][0].apply(exports,arguments) -},{"dup":5}],10:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var BrowserUtil = (function () { - function BrowserUtil() { - } - BrowserUtil.nextFrame = function () { - return new Promise(function (resolve) { return requestAnimationFrame(function () { return resolve(); }); }); - }; - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Timing' }) - ], BrowserUtil, "nextFrame", null); - return BrowserUtil; -}()); -exports.BrowserUtil = BrowserUtil; - -},{"./doc":32}],11:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var BatchDataset = (function () { - function BatchDataset(base, batchSize, smallLastBatch) { - if (smallLastBatch === void 0) { smallLastBatch = true; } - this.base = base; - this.batchSize = batchSize; - this.smallLastBatch = smallLastBatch; - } - BatchDataset.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - var batchesAsArrays; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.base.getStream()]; - case 1: - batchesAsArrays = (_a.sent()) - .batch(this.batchSize, this.smallLastBatch); - return [2, batchesAsArrays.map(makeDatasetBatch)]; - } - }); - }); - }; - return BatchDataset; -}()); -exports.BatchDataset = BatchDataset; -function makeDatasetBatch(elements) { - var rotated = {}; - var firstElement = elements[0]; - var keys = Object.keys(firstElement); - keys.forEach(function (key) { - rotated[key] = []; - }); - var _loop_1 = function (e) { - keys.forEach(function (key) { - var value = e[key]; - rotated[key].push(value); - }); - }; - for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) { - var e = elements_1[_i]; - _loop_1(e); - } - var result = {}; - for (var _a = 0, keys_1 = keys; _a < keys_1.length; _a++) { - var key = keys_1[_a]; - if (rotated[key].length !== elements.length) { - throw new Error("Batching failed to get a '" + key + "' value for each element."); - } - if (typeof rotated[key][0] === 'string') { - result[key] = rotated[key]; - } - else { - result[key] = batchConcat(rotated[key]); - } - } - return result; -} -function batchConcat(arrays) { - var elementShape = shapeAndValues(arrays[0])[0]; - var batchShape = [arrays.length].concat(elementShape); - var resultVals = new Float32Array(batchShape.reduce(function (x, y) { return x * y; })); - var offset = 0; - for (var _i = 0, arrays_1 = arrays; _i < arrays_1.length; _i++) { - var a = arrays_1[_i]; - var _a = shapeAndValues(a), aShape = _a[0], aVals = _a[1]; - if (!util.arraysEqual(aShape, elementShape)) { - throw new Error('Elements must have the same shape to be batched'); - } - resultVals.set(aVals, offset); - offset += aVals.length; - } - var result = tensor_1.Tensor.make(batchShape, { values: resultVals }); - return result; -} -function shapeAndValues(array) { - if (array instanceof tensor_1.Tensor) { - return [array.shape, array.dataSync()]; - } - else if (Array.isArray(array)) { - return [[array.length], array]; - } - else { - return [[], [array]]; - } -} - -},{"../../tensor":146,"../../util":151}],12:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var batch_dataset_1 = require("./batch_dataset"); -var statistics_1 = require("./statistics"); -var data_stream_1 = require("./streams/data_stream"); -var data_stream_2 = require("./streams/data_stream"); -var data_stream_3 = require("./streams/data_stream"); -var Dataset = (function () { - function Dataset() { - } - Dataset.prototype.computeStatistics = function (sampleSize, shuffleWindowSize) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, statistics_1.computeDatasetStatistics(this, sampleSize, shuffleWindowSize)]; - }); - }); - }; - Dataset.prototype.filter = function (filterer) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).filter(filterer)]; - } - }); - }); }); - }; - Dataset.prototype.map = function (transform) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).map(transform)]; - } - }); - }); }); - }; - Dataset.prototype.batch = function (batchSize, smallLastBatch) { - if (smallLastBatch === void 0) { smallLastBatch = true; } - return new batch_dataset_1.BatchDataset(this, batchSize, smallLastBatch); - }; - Dataset.prototype.concatenate = function (dataset) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: return [4, base.getStream()]; - case 1: - _b = (_a = (_c.sent())).concatenate; - return [4, dataset.getStream()]; - case 2: return [2, _b.apply(_a, [_c.sent()])]; - } - }); - }); }); - }; - Dataset.prototype.repeat = function (count) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var streamStream; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - streamStream = data_stream_2.streamFromFunction(function () { return base.getStream(); }); - return [4, data_stream_1.streamFromConcatenated(streamStream.take(count))]; - case 1: return [2, (_a.sent())]; - } - }); - }); }); - }; - Dataset.prototype.take = function (count) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).take(count)]; - } - }); - }); }); - }; - Dataset.prototype.skip = function (count) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).skip(count)]; - } - }); - }); }); - }; - Dataset.prototype.shuffle = function (bufferSize, seed, reshuffleEachIteration) { - var _this = this; - if (reshuffleEachIteration === void 0) { reshuffleEachIteration = true; } - var base = this; - var random = seedrandom(seed); - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var seed2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - seed2 = random.int32(); - if (reshuffleEachIteration) { - seed2 += random.int32(); - } - return [4, base.getStream()]; - case 1: return [2, (_a.sent()).shuffle(bufferSize, seed2.toString())]; - } - }); - }); }); - }; - Dataset.prototype.prefetch = function (bufferSize) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).prefetch(bufferSize)]; - } - }); - }); }); - }; - return Dataset; -}()); -exports.Dataset = Dataset; -function datasetFromStreamFn(getStreamFn) { - return new (function (_super) { - __extends(class_1, _super); - function class_1() { - return _super !== null && _super.apply(this, arguments) || this; - } - class_1.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, getStreamFn()]; - }); - }); - }; - return class_1; - }(Dataset))(); -} -exports.datasetFromStreamFn = datasetFromStreamFn; -function datasetFromElements(items) { - var _this = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, Promise.resolve(data_stream_3.streamFromItems(items))]; - }); - }); }); -} -exports.datasetFromElements = datasetFromElements; -function datasetFromConcatenated(datasets) { - var _this = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var streamStream; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, Promise.all(datasets.map(function (d) { return d.getStream(); }))]; - case 1: - streamStream = _a.sent(); - return [2, data_stream_1.streamFromConcatenated(data_stream_3.streamFromItems(streamStream))]; - } - }); - }); }); -} -exports.datasetFromConcatenated = datasetFromConcatenated; - -},{"./batch_dataset":11,"./statistics":18,"./streams/data_stream":20,"seedrandom":153}],13:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dataset_1 = require("../dataset"); -var text_line_dataset_1 = require("./text_line_dataset"); -var CsvHeaderConfig; -(function (CsvHeaderConfig) { - CsvHeaderConfig[CsvHeaderConfig["READ_FIRST_LINE"] = 0] = "READ_FIRST_LINE"; - CsvHeaderConfig[CsvHeaderConfig["NUMBERED"] = 1] = "NUMBERED"; -})(CsvHeaderConfig = exports.CsvHeaderConfig || (exports.CsvHeaderConfig = {})); -var CSVDataset = (function (_super) { - __extends(CSVDataset, _super); - function CSVDataset(input) { - var _this = _super.call(this) || this; - _this.input = input; - _this.hasHeaderLine = false; - _this.base = new text_line_dataset_1.TextLineDataset(input, CSVDataset.textColumnName); - return _this; - } - Object.defineProperty(CSVDataset.prototype, "csvColumnNames", { - get: function () { - return this._csvColumnNames; - }, - enumerable: true, - configurable: true - }); - CSVDataset.prototype.setCsvColumnNames = function (csvColumnNames) { - return __awaiter(this, void 0, void 0, function () { - var stream, firstElement, firstLine, stream, firstElement, firstLine; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(csvColumnNames == null || csvColumnNames === CsvHeaderConfig.NUMBERED)) return [3, 3]; - return [4, this.base.getStream()]; - case 1: - stream = _a.sent(); - return [4, stream.next()]; - case 2: - firstElement = _a.sent(); - firstLine = firstElement[CSVDataset.textColumnName]; - this._csvColumnNames = - Array.from(firstLine.split(',').keys()).map(function (x) { return x.toString(); }); - return [3, 7]; - case 3: - if (!(csvColumnNames === CsvHeaderConfig.READ_FIRST_LINE)) return [3, 6]; - return [4, this.base.getStream()]; - case 4: - stream = _a.sent(); - return [4, stream.next()]; - case 5: - firstElement = _a.sent(); - firstLine = firstElement[CSVDataset.textColumnName]; - this._csvColumnNames = firstLine.split(','); - this.hasHeaderLine = true; - return [3, 7]; - case 6: - this._csvColumnNames = csvColumnNames; - _a.label = 7; - case 7: return [2]; - } - }); - }); - }; - CSVDataset.create = function (input, csvColumnNames) { - if (csvColumnNames === void 0) { csvColumnNames = CsvHeaderConfig.NUMBERED; } - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - result = new CSVDataset(input); - return [4, result.setCsvColumnNames(csvColumnNames)]; - case 1: - _a.sent(); - return [2, result]; - } - }); - }); - }; - CSVDataset.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - var lines; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.base.getStream()]; - case 1: - lines = _a.sent(); - if (this.hasHeaderLine) { - lines = lines.skip(1); - } - return [2, lines.map(function (x) { return _this.makeDatasetElement(x); })]; - } - }); - }); - }; - CSVDataset.prototype.makeDatasetElement = function (element) { - var line = element[CSVDataset.textColumnName]; - var values = line.split(','); - var result = {}; - for (var i = 0; i < this._csvColumnNames.length; i++) { - var value = values[i]; - if (value === '') { - result[this._csvColumnNames[i]] = undefined; - } - else { - var valueAsNum = Number(value); - if (isNaN(valueAsNum)) { - result[this._csvColumnNames[i]] = value; - } - else { - result[this._csvColumnNames[i]] = valueAsNum; - } - } - } - return result; - }; - CSVDataset.textColumnName = 'line'; - return CSVDataset; -}(dataset_1.Dataset)); -exports.CSVDataset = CSVDataset; - -},{"../dataset":12,"./text_line_dataset":14}],14:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dataset_1 = require("../dataset"); -var TextLineDataset = (function (_super) { - __extends(TextLineDataset, _super); - function TextLineDataset(input, columnName) { - if (columnName === void 0) { columnName = 'line'; } - var _this = _super.call(this) || this; - _this.input = input; - _this.columnName = columnName; - return _this; - } - TextLineDataset.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - var readStream, utf8Stream, lineStream; - return __generator(this, function (_a) { - readStream = this.input.getStream(); - utf8Stream = readStream.decodeUTF8(); - lineStream = utf8Stream.split('\n'); - return [2, lineStream.map(function (x) { - return (_a = {}, _a[_this.columnName] = x, _a); - var _a; - })]; - }); - }); - }; - return TextLineDataset; -}(dataset_1.Dataset)); -exports.TextLineDataset = TextLineDataset; - -},{"../dataset":12}],15:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var DataSource = (function () { - function DataSource() { - } - return DataSource; -}()); -exports.DataSource = DataSource; - -},{}],16:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var datasource_1 = require("../datasource"); -var filereader_stream_1 = require("../streams/filereader_stream"); -var FileDataSource = (function (_super) { - __extends(FileDataSource, _super); - function FileDataSource(input, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.input = input; - _this.options = options; - return _this; - } - FileDataSource.prototype.getStream = function () { - return new filereader_stream_1.FileReaderStream(this.input, this.options); - }; - return FileDataSource; -}(datasource_1.DataSource)); -exports.FileDataSource = FileDataSource; - -},{"../datasource":15,"../streams/filereader_stream":21}],17:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var datasource_1 = require("../datasource"); -var url_stream_1 = require("../streams/url_stream"); -var URLDataSource = (function (_super) { - __extends(URLDataSource, _super); - function URLDataSource(url, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.url = url; - _this.options = options; - return _this; - } - URLDataSource.prototype.getStream = function () { - return new url_stream_1.URLStream(this.url, this.options); - }; - return URLDataSource; -}(datasource_1.DataSource)); -exports.URLDataSource = URLDataSource; - -},{"../datasource":15,"../streams/url_stream":23}],18:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../../tensor"); -function scaleTo01(min, max) { - var range = max - min; - var minTensor = tensor_1.Scalar.new(min); - var rangeTensor = tensor_1.Scalar.new(range); - return function (value) { - if (typeof (value) === 'string') { - throw new Error('Can\'t scale a string.'); - } - else { - if (value instanceof tensor_1.Tensor) { - var result = value.sub(minTensor).div(rangeTensor); - return result; - } - else if (value instanceof Array) { - return value.map(function (v) { return (v - min) / range; }); - } - else { - return (value - min) / range; - } - } - }; -} -exports.scaleTo01 = scaleTo01; -function computeDatasetStatistics(dataset, sampleSize, shuffleWindowSize) { - return __awaiter(this, void 0, void 0, function () { - var stream, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, dataset.getStream()]; - case 1: - stream = _a.sent(); - if (shuffleWindowSize != null) { - stream = stream.shuffle(shuffleWindowSize); - } - if (sampleSize != null) { - stream = stream.take(sampleSize); - } - result = {}; - return [4, stream.forEach(function (e) { - for (var key in e) { - var value = e[key]; - if (typeof (value) === 'string') { - } - else { - var recordMin = void 0; - var recordMax = void 0; - if (value instanceof tensor_1.Tensor) { - recordMin = value.min().dataSync()[0]; - recordMax = value.max().dataSync()[0]; - } - else if (value instanceof Array) { - recordMin = value.reduce(function (a, b) { return Math.min(a, b); }); - recordMax = value.reduce(function (a, b) { return Math.max(a, b); }); - } - else if (!isNaN(value) && isFinite(value)) { - recordMin = value; - recordMax = value; - } - else { - throw new Error("Cannot compute statistics: " + key + " = " + value); - } - var columnStats = result[key]; - if (columnStats == null) { - columnStats = { - min: Number.POSITIVE_INFINITY, - max: Number.NEGATIVE_INFINITY - }; - result[key] = columnStats; - } - columnStats.min = Math.min(columnStats.min, recordMin); - columnStats.max = Math.max(columnStats.max, recordMax); - } - } - return {}; - })]; - case 2: - _a.sent(); - return [2, result]; - } - }); - }); -} -exports.computeDatasetStatistics = computeDatasetStatistics; - -},{"../../tensor":146}],19:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var utf8 = require("utf8"); -var data_stream_1 = require("./data_stream"); -var string_stream_1 = require("./string_stream"); -var ByteStream = (function (_super) { - __extends(ByteStream, _super); - function ByteStream() { - return _super !== null && _super.apply(this, arguments) || this; - } - ByteStream.prototype.decodeUTF8 = function () { - return new Utf8Stream(this); - }; - return ByteStream; -}(data_stream_1.DataStream)); -exports.ByteStream = ByteStream; -var Utf8Stream = (function (_super) { - __extends(Utf8Stream, _super); - function Utf8Stream(upstream) { - var _this = _super.call(this) || this; - _this.impl = new Utf8StreamImpl(upstream); - return _this; - } - Utf8Stream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.impl.next()]; - }); - }); - }; - return Utf8Stream; -}(string_stream_1.StringStream)); -var Utf8StreamImpl = (function (_super) { - __extends(Utf8StreamImpl, _super); - function Utf8StreamImpl(upstream) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.partial = new Uint8Array([]); - _this.partialBytesValid = 0; - return _this; - } - Utf8StreamImpl.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var chunk, partialBytesRemaining, nextIndex, okUpToIndex, splitUtfWidth, bulk, reassembled; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - chunk = _a.sent(); - if (chunk == null) { - if (this.partial.length === 0) { - return [2, false]; - } - chunk = new Uint8Array([]); - } - partialBytesRemaining = this.partial.length - this.partialBytesValid; - nextIndex = partialBytesRemaining; - okUpToIndex = nextIndex; - splitUtfWidth = 0; - while (nextIndex < chunk.length) { - okUpToIndex = nextIndex; - splitUtfWidth = utfWidth(chunk[nextIndex]); - nextIndex = okUpToIndex + splitUtfWidth; - } - if (nextIndex === chunk.length) { - okUpToIndex = nextIndex; - } - bulk = utf8.decode(String.fromCharCode.apply(null, chunk.slice(partialBytesRemaining, okUpToIndex))); - if (partialBytesRemaining > 0) { - this.partial.set(chunk.slice(0, partialBytesRemaining), this.partialBytesValid); - reassembled = utf8.decode(String.fromCharCode.apply(null, this.partial)); - this.outputQueue.push(reassembled + bulk); - } - else { - this.outputQueue.push(bulk); - } - if (okUpToIndex === chunk.length) { - this.partial = new Uint8Array([]); - this.partialBytesValid = 0; - } - else { - this.partial = new Uint8Array(new ArrayBuffer(splitUtfWidth)); - this.partial.set(chunk.slice(okUpToIndex), 0); - this.partialBytesValid = chunk.length - okUpToIndex; - } - return [2, true]; - } - }); - }); - }; - return Utf8StreamImpl; -}(data_stream_1.QueueStream)); -function utfWidth(firstByte) { - if (firstByte >= 252) - return 6; - else if (firstByte >= 248) - return 5; - else if (firstByte >= 240) - return 4; - else if (firstByte >= 224) - return 3; - else if (firstByte >= 192) - return 2; - else - return 1; -} - -},{"./data_stream":20,"./string_stream":22,"utf8":161}],20:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var growing_ring_buffer_1 = require("../util/growing_ring_buffer"); -var ring_buffer_1 = require("../util/ring_buffer"); -function streamFromItems(items) { - return new ArrayStream(items); -} -exports.streamFromItems = streamFromItems; -function streamFromIncrementing(start) { - var i = start; - return streamFromFunction(function () { return i++; }); -} -exports.streamFromIncrementing = streamFromIncrementing; -function streamFromFunction(func) { - return new FunctionCallStream(func); -} -exports.streamFromFunction = streamFromFunction; -function streamFromConcatenated(baseStreams) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, ChainedStream.create(baseStreams)]; - }); - }); -} -exports.streamFromConcatenated = streamFromConcatenated; -function streamFromConcatenatedFunction(streamFunc, count) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, streamFromConcatenated(streamFromFunction(streamFunc).take(count))]; - }); - }); -} -exports.streamFromConcatenatedFunction = streamFromConcatenatedFunction; -var DataStream = (function () { - function DataStream() { - } - DataStream.prototype.collectRemaining = function () { - return __awaiter(this, void 0, void 0, function () { - var result, x; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - result = []; - return [4, this.next()]; - case 1: - x = _a.sent(); - _a.label = 2; - case 2: - if (!(x != null)) return [3, 4]; - result.push(x); - return [4, this.next()]; - case 3: - x = _a.sent(); - return [3, 2]; - case 4: return [2, result]; - } - }); - }); - }; - DataStream.prototype.resolveFully = function () { - return __awaiter(this, void 0, void 0, function () { - var x; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.next()]; - case 1: - x = _a.sent(); - _a.label = 2; - case 2: - if (!(x != null)) return [3, 4]; - return [4, this.next()]; - case 3: - x = _a.sent(); - return [3, 2]; - case 4: return [2]; - } - }); - }); - }; - DataStream.prototype.filter = function (predicate) { - return new FilterStream(this, predicate); - }; - DataStream.prototype.map = function (transform) { - return new MapStream(this, transform); - }; - DataStream.prototype.forEach = function (f) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.map(f).resolveFully()]; - }); - }); - }; - DataStream.prototype.batch = function (batchSize, smallLastBatch) { - if (smallLastBatch === void 0) { smallLastBatch = true; } - return new BatchStream(this, batchSize, smallLastBatch); - }; - DataStream.prototype.concatenate = function (stream) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, ChainedStream.create(new ArrayStream([this, stream]))]; - }); - }); - }; - DataStream.prototype.take = function (count) { - if (count < 0 || count == null) - return this; - return new TakeStream(this, count); - }; - DataStream.prototype.skip = function (count) { - if (count < 0 || count == null) - return this; - return new SkipStream(this, count); - }; - DataStream.prototype.prefetch = function (bufferSize) { - return new PrefetchStream(this, bufferSize); - }; - DataStream.prototype.shuffle = function (windowSize, seed) { - return new ShuffleStream(this, windowSize, seed); - }; - return DataStream; -}()); -exports.DataStream = DataStream; -var ArrayStream = (function (_super) { - __extends(ArrayStream, _super); - function ArrayStream(items) { - var _this = _super.call(this) || this; - _this.items = items; - _this.trav = 0; - return _this; - } - ArrayStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - if (this.trav >= this.items.length) { - return [2, undefined]; - } - result = this.items[this.trav]; - this.trav++; - return [2, result]; - }); - }); - }; - return ArrayStream; -}(DataStream)); -var FunctionCallStream = (function (_super) { - __extends(FunctionCallStream, _super); - function FunctionCallStream(nextFn) { - var _this = _super.call(this) || this; - _this.nextFn = nextFn; - return _this; - } - FunctionCallStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.nextFn()]; - }); - }); - }; - return FunctionCallStream; -}(DataStream)); -var SkipStream = (function (_super) { - __extends(SkipStream, _super); - function SkipStream(upstream, maxCount) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.maxCount = maxCount; - _this.count = 0; - return _this; - } - SkipStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var skipped; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.count++ < this.maxCount)) return [3, 2]; - return [4, this.upstream.next()]; - case 1: - skipped = _a.sent(); - if (skipped == null) { - return [2, undefined]; - } - return [3, 0]; - case 2: return [2, this.upstream.next()]; - } - }); - }); - }; - return SkipStream; -}(DataStream)); -var TakeStream = (function (_super) { - __extends(TakeStream, _super); - function TakeStream(upstream, maxCount) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.maxCount = maxCount; - _this.count = 0; - return _this; - } - TakeStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - if (this.count++ >= this.maxCount) { - return [2, undefined]; - } - return [2, this.upstream.next()]; - }); - }); - }; - return TakeStream; -}(DataStream)); -var QueueStream = (function (_super) { - __extends(QueueStream, _super); - function QueueStream() { - var _this = _super.call(this) || this; - _this.outputQueue = new growing_ring_buffer_1.GrowingRingBuffer(); - return _this; - } - QueueStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.outputQueue.length() === 0)) return [3, 2]; - return [4, this.pump()]; - case 1: - if (!(_a.sent())) { - return [2, undefined]; - } - return [3, 0]; - case 2: return [2, this.outputQueue.shift()]; - } - }); - }); - }; - return QueueStream; -}(DataStream)); -exports.QueueStream = QueueStream; -var BatchStream = (function (_super) { - __extends(BatchStream, _super); - function BatchStream(upstream, batchSize, enableSmallLastBatch) { - if (enableSmallLastBatch === void 0) { enableSmallLastBatch = true; } - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.batchSize = batchSize; - _this.enableSmallLastBatch = enableSmallLastBatch; - _this.currentBatch = []; - return _this; - } - BatchStream.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var item; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - item = _a.sent(); - if (item == null) { - if (this.enableSmallLastBatch && this.currentBatch.length > 0) { - this.outputQueue.push(this.currentBatch); - this.currentBatch = []; - return [2, true]; - } - return [2, false]; - } - this.currentBatch.push(item); - if (this.currentBatch.length === this.batchSize) { - this.outputQueue.push(this.currentBatch); - this.currentBatch = []; - } - return [2, true]; - } - }); - }); - }; - return BatchStream; -}(QueueStream)); -var FilterStream = (function (_super) { - __extends(FilterStream, _super); - function FilterStream(upstream, predicate) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.predicate = predicate; - return _this; - } - FilterStream.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var item, accept; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - item = _a.sent(); - if (item == null) { - return [2, false]; - } - accept = this.predicate(item); - if (!(accept instanceof Promise)) return [3, 3]; - return [4, accept]; - case 2: - accept = _a.sent(); - _a.label = 3; - case 3: - if (accept) { - this.outputQueue.push(item); - } - return [2, true]; - } - }); - }); - }; - return FilterStream; -}(QueueStream)); -var MapStream = (function (_super) { - __extends(MapStream, _super); - function MapStream(upstream, transform) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.transform = transform; - return _this; - } - MapStream.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var item, mapped; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - item = _a.sent(); - if (item == null) { - return [2, false]; - } - mapped = this.transform(item); - if (!(mapped instanceof Promise)) return [3, 3]; - return [4, mapped]; - case 2: - mapped = _a.sent(); - _a.label = 3; - case 3: - this.outputQueue.push(mapped); - return [2, true]; - } - }); - }); - }; - return MapStream; -}(QueueStream)); -var ChainState = (function () { - function ChainState(item, currentStream, moreStreams) { - this.item = item; - this.currentStream = currentStream; - this.moreStreams = moreStreams; - } - return ChainState; -}()); -function nextChainState(afterState) { - return __awaiter(this, void 0, void 0, function () { - var state, stream, item; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, afterState]; - case 1: - state = _a.sent(); - stream = state.currentStream; - if (stream == null) { - return [2, new ChainState(undefined, undefined, state.moreStreams)]; - } - return [4, stream.next()]; - case 2: - item = _a.sent(); - if (!(item == null)) return [3, 4]; - return [4, state.moreStreams.next()]; - case 3: - stream = _a.sent(); - return [2, nextChainState(Promise.resolve(new ChainState(undefined, stream, state.moreStreams)))]; - case 4: return [2, new ChainState(item, stream, state.moreStreams)]; - } - }); - }); -} -var ChainedStream = (function (_super) { - __extends(ChainedStream, _super); - function ChainedStream() { - return _super !== null && _super.apply(this, arguments) || this; - } - ChainedStream.create = function (baseStreams) { - return __awaiter(this, void 0, void 0, function () { - var c, currentStream; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - c = new ChainedStream(); - return [4, baseStreams.next()]; - case 1: - currentStream = _a.sent(); - c.currentPromise = - Promise.resolve(new ChainState(undefined, currentStream, baseStreams)); - return [2, c]; - } - }); - }); - }; - ChainedStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.currentPromise = nextChainState(this.currentPromise); - return [4, this.currentPromise]; - case 1: return [2, (_a.sent()).item]; - } - }); - }); - }; - return ChainedStream; -}(DataStream)); -exports.ChainedStream = ChainedStream; -var PrefetchStream = (function (_super) { - __extends(PrefetchStream, _super); - function PrefetchStream(upstream, bufferSize) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.bufferSize = bufferSize; - _this.total = 0; - _this.buffer = new ring_buffer_1.RingBuffer(bufferSize); - return _this; - } - PrefetchStream.prototype.refill = function () { - while (!this.buffer.isFull()) { - var v = this.upstream.next(); - if (v == null) { - return; - } - this.buffer.push(v); - } - }; - PrefetchStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.refill(); - if (this.buffer.isEmpty()) - return [2, undefined]; - return [4, this.buffer.shift()]; - case 1: - result = _a.sent(); - this.refill(); - return [2, result]; - } - }); - }); - }; - return PrefetchStream; -}(DataStream)); -exports.PrefetchStream = PrefetchStream; -var ShuffleStream = (function (_super) { - __extends(ShuffleStream, _super); - function ShuffleStream(upstream, windowSize, seed) { - var _this = _super.call(this, upstream, windowSize) || this; - _this.upstream = upstream; - _this.windowSize = windowSize; - _this.upstreamExhausted = false; - _this.random = seedrandom(seed); - return _this; - } - ShuffleStream.prototype.randomInt = function (max) { - return Math.floor(this.random() * max); - }; - ShuffleStream.prototype.chooseIndex = function () { - return this.randomInt(this.buffer.length()); - }; - ShuffleStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var chosenIndex, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!this.upstreamExhausted) { - this.refill(); - } - _a.label = 1; - case 1: - if (!!this.buffer.isEmpty()) return [3, 3]; - chosenIndex = this.chooseIndex(); - return [4, this.buffer.shuffleExcise(chosenIndex)]; - case 2: - result = _a.sent(); - if (result == null) { - this.upstreamExhausted = true; - } - else { - this.refill(); - return [2, result]; - } - return [3, 1]; - case 3: return [2, undefined]; - } - }); - }); - }; - return ShuffleStream; -}(PrefetchStream)); -exports.ShuffleStream = ShuffleStream; - -},{"../util/growing_ring_buffer":24,"../util/ring_buffer":25,"seedrandom":153}],21:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var byte_stream_1 = require("./byte_stream"); -var FileReaderStream = (function (_super) { - __extends(FileReaderStream, _super); - function FileReaderStream(file, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.file = file; - _this.options = options; - _this.offset = options.offset || 0; - _this.chunkSize = options.chunkSize || 1024 * 1024; - return _this; - } - FileReaderStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - var chunk; - return __generator(this, function (_a) { - if (this.offset >= this.file.size) { - return [2, undefined]; - } - chunk = new Promise(function (resolve, reject) { - var fileReader = new FileReader(); - fileReader.onload = function (event) { - var data = fileReader.result; - if (data instanceof ArrayBuffer) { - data = new Uint8Array(data); - } - if (!(data instanceof Uint8Array)) { - return reject(new TypeError('FileReader returned unknown type.')); - } - resolve(data); - }; - fileReader.onabort = function (event) { - return reject(new Error('Aborted')); - }; - fileReader.onerror = function (event) { - return reject(new Error(event.error)); - }; - var end = _this.offset + _this.chunkSize; - var slice = _this.file.slice(_this.offset, end); - fileReader.readAsArrayBuffer(slice); - _this.offset = end; - }); - return [2, chunk]; - }); - }); - }; - return FileReaderStream; -}(byte_stream_1.ByteStream)); -exports.FileReaderStream = FileReaderStream; - -},{"./byte_stream":19}],22:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var data_stream_1 = require("./data_stream"); -var StringStream = (function (_super) { - __extends(StringStream, _super); - function StringStream() { - return _super !== null && _super.apply(this, arguments) || this; - } - StringStream.prototype.split = function (separator) { - return new SplitStream(this, separator); - }; - return StringStream; -}(data_stream_1.DataStream)); -exports.StringStream = StringStream; -var SplitStream = (function (_super) { - __extends(SplitStream, _super); - function SplitStream(upstream, separator) { - var _this = _super.call(this) || this; - _this.impl = new SplitStreamImpl(upstream, separator); - return _this; - } - SplitStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.impl.next()]; - }); - }); - }; - return SplitStream; -}(StringStream)); -var SplitStreamImpl = (function (_super) { - __extends(SplitStreamImpl, _super); - function SplitStreamImpl(upstream, separator) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.separator = separator; - _this.carryover = ''; - return _this; - } - SplitStreamImpl.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var chunk, lines, _i, _a, line; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4, this.upstream.next()]; - case 1: - chunk = _b.sent(); - if (chunk == null) { - if (this.carryover === '') { - return [2, false]; - } - this.outputQueue.push(this.carryover); - this.carryover = ''; - return [2, true]; - } - lines = chunk.split(this.separator); - lines[0] = this.carryover + lines[0]; - for (_i = 0, _a = lines.slice(0, -1); _i < _a.length; _i++) { - line = _a[_i]; - this.outputQueue.push(line); - } - this.carryover = lines[lines.length - 1]; - return [2, true]; - } - }); - }); - }; - return SplitStreamImpl; -}(data_stream_1.QueueStream)); - -},{"./data_stream":20}],23:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var byte_stream_1 = require("./byte_stream"); -var data_stream_1 = require("./data_stream"); -var filereader_stream_1 = require("./filereader_stream"); -var URLStream = (function (_super) { - __extends(URLStream, _super); - function URLStream(url, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.impl = new URLStreamImpl(url, options); - return _this; - } - URLStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.impl.next()]; - }); - }); - }; - return URLStream; -}(byte_stream_1.ByteStream)); -exports.URLStream = URLStream; -var URLStreamImpl = (function (_super) { - __extends(URLStreamImpl, _super); - function URLStreamImpl(url, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.url = url; - _this.options = options; - _this.blobPromise = fetch(url, options).then(function (response) { - if (response.ok) { - return response.blob(); - } - else { - throw new Error(response.statusText); - } - }); - return _this; - } - URLStreamImpl.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var blob, chunk; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.fileReaderStream == null)) return [3, 2]; - return [4, this.blobPromise]; - case 1: - blob = _a.sent(); - this.fileReaderStream = new filereader_stream_1.FileReaderStream(blob, this.options); - _a.label = 2; - case 2: return [4, this.fileReaderStream.next()]; - case 3: - chunk = _a.sent(); - if (chunk == null) - return [2, false]; - this.outputQueue.push(chunk); - return [2, true]; - } - }); - }); - }; - return URLStreamImpl; -}(data_stream_1.QueueStream)); - -},{"./byte_stream":19,"./data_stream":20,"./filereader_stream":21}],24:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var ring_buffer_1 = require("./ring_buffer"); -var GrowingRingBuffer = (function (_super) { - __extends(GrowingRingBuffer, _super); - function GrowingRingBuffer() { - return _super.call(this, GrowingRingBuffer.INITIAL_CAPACITY) || this; - } - GrowingRingBuffer.prototype.isFull = function () { - return false; - }; - GrowingRingBuffer.prototype.push = function (value) { - if (_super.prototype.isFull.call(this)) { - this.expand(); - } - _super.prototype.push.call(this, value); - }; - GrowingRingBuffer.prototype.unshift = function (value) { - if (_super.prototype.isFull.call(this)) { - this.expand(); - } - _super.prototype.unshift.call(this, value); - }; - GrowingRingBuffer.prototype.expand = function () { - var newCapacity = this.capacity * 2; - var newData = new Array(newCapacity); - var len = this.length(); - for (var i = 0; i < len; i++) { - newData[i] = this.get(this.wrap(this.begin + i)); - } - this.data = newData; - this.capacity = newCapacity; - this.doubledCapacity = 2 * this.capacity; - this.begin = 0; - this.end = len; - }; - GrowingRingBuffer.INITIAL_CAPACITY = 32; - return GrowingRingBuffer; -}(ring_buffer_1.RingBuffer)); -exports.GrowingRingBuffer = GrowingRingBuffer; - -},{"./ring_buffer":25}],25:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var RingBuffer = (function () { - function RingBuffer(capacity) { - this.capacity = capacity; - this.begin = 0; - this.end = 0; - if (capacity < 1) { - throw new RangeError('Can\'t create ring buffer of capacity < 1.'); - } - this.data = new Array(capacity); - this.doubledCapacity = 2 * capacity; - } - RingBuffer.prototype.wrap = function (index) { - while (index < 0) { - index += this.doubledCapacity; - } - return index % this.doubledCapacity; - }; - RingBuffer.prototype.get = function (index) { - if (index < 0) { - throw new RangeError('Can\'t get item at a negative index.'); - } - return this.data[index % this.capacity]; - }; - RingBuffer.prototype.set = function (index, value) { - if (index < 0) { - throw new RangeError('Can\'t set item at a negative index.'); - } - this.data[index % this.capacity] = value; - }; - RingBuffer.prototype.length = function () { - var length = this.end - this.begin; - if (length < 0) { - length = this.doubledCapacity + length; - } - return length; - }; - RingBuffer.prototype.isFull = function () { - return this.length() === this.capacity; - }; - RingBuffer.prototype.isEmpty = function () { - return this.length() === 0; - }; - RingBuffer.prototype.push = function (value) { - if (this.isFull()) { - throw new RangeError('Ring buffer is full.'); - } - this.set(this.end, value); - this.end = this.wrap(this.end + 1); - }; - RingBuffer.prototype.pop = function () { - if (this.isEmpty()) { - throw new RangeError('Ring buffer is empty.'); - } - this.end = this.wrap(this.end - 1); - var result = this.get(this.end); - this.set(this.end, undefined); - return result; - }; - RingBuffer.prototype.unshift = function (value) { - if (this.isFull()) { - throw new RangeError('Ring buffer is full.'); - } - this.begin = this.wrap(this.begin - 1); - this.set(this.begin, value); - }; - RingBuffer.prototype.shift = function () { - if (this.isEmpty()) { - throw new RangeError('Ring buffer is empty.'); - } - var result = this.get(this.begin); - this.set(this.begin, undefined); - this.begin = this.wrap(this.begin + 1); - return result; - }; - RingBuffer.prototype.shuffleExcise = function (relativeIndex) { - if (this.isEmpty()) { - throw new RangeError('Ring buffer is empty.'); - } - var index = this.wrap(this.begin + relativeIndex); - var result = this.get(index); - this.set(index, this.pop()); - return result; - }; - return RingBuffer; -}()); -exports.RingBuffer = RingBuffer; - -},{}],26:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var dataset_1 = require("./data/dataset"); -exports.Dataset = dataset_1.Dataset; -var csv_dataset_1 = require("./data/datasets/csv_dataset"); -exports.CSVDataset = csv_dataset_1.CSVDataset; -var text_line_dataset_1 = require("./data/datasets/text_line_dataset"); -exports.TextLineDataset = text_line_dataset_1.TextLineDataset; -var file_data_source_1 = require("./data/sources/file_data_source"); -exports.FileDataSource = file_data_source_1.FileDataSource; -var url_data_source_1 = require("./data/sources/url_data_source"); -exports.URLDataSource = url_data_source_1.URLDataSource; - -},{"./data/dataset":12,"./data/datasets/csv_dataset":13,"./data/datasets/text_line_dataset":14,"./data/sources/file_data_source":16,"./data/sources/url_data_source":17}],27:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var MANIFEST_FILE = 'manifest.json'; -var CheckpointLoader = (function () { - function CheckpointLoader(urlPath) { - this.urlPath = urlPath; - if (this.urlPath.charAt(this.urlPath.length - 1) !== '/') { - this.urlPath += '/'; - } - } - CheckpointLoader.prototype.loadManifest = function () { - var _this = this; - return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', _this.urlPath + MANIFEST_FILE); - xhr.onload = function () { - _this.checkpointManifest = JSON.parse(xhr.responseText); - resolve(); - }; - xhr.onerror = function (error) { - throw new Error(MANIFEST_FILE + " not found at " + _this.urlPath + ". " + error); - }; - xhr.send(); - }); - }; - CheckpointLoader.prototype.getCheckpointManifest = function () { - var _this = this; - if (this.checkpointManifest == null) { - return new Promise(function (resolve, reject) { - _this.loadManifest().then(function () { - resolve(_this.checkpointManifest); - }); - }); - } - return new Promise(function (resolve, reject) { - resolve(_this.checkpointManifest); - }); - }; - CheckpointLoader.prototype.getAllVariables = function () { - var _this = this; - if (this.variables != null) { - return new Promise(function (resolve, reject) { - resolve(_this.variables); - }); - } - return new Promise(function (resolve, reject) { - _this.getCheckpointManifest().then(function (checkpointDefinition) { - var variableNames = Object.keys(_this.checkpointManifest); - var variablePromises = []; - for (var i = 0; i < variableNames.length; i++) { - variablePromises.push(_this.getVariable(variableNames[i])); - } - Promise.all(variablePromises).then(function (variables) { - _this.variables = {}; - for (var i = 0; i < variables.length; i++) { - _this.variables[variableNames[i]] = variables[i]; - } - resolve(_this.variables); - }); - }); - }); - }; - CheckpointLoader.prototype.getVariable = function (varName) { - var _this = this; - if (!(varName in this.checkpointManifest)) { - throw new Error('Cannot load non-existant variable ' + varName); - } - var variableRequestPromiseMethod = function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.responseType = 'arraybuffer'; - var fname = _this.checkpointManifest[varName].filename; - xhr.open('GET', _this.urlPath + fname); - xhr.onload = function () { - if (xhr.status === 404) { - throw new Error("Not found variable " + varName); - } - var values = new Float32Array(xhr.response); - var tensor = tensor_1.Tensor.make(_this.checkpointManifest[varName].shape, { values: values }); - resolve(tensor); - }; - xhr.onerror = function (error) { - throw new Error("Could not fetch variable " + varName + ": " + error); - }; - xhr.send(); - }; - if (this.checkpointManifest == null) { - return new Promise(function (resolve, reject) { - _this.loadManifest().then(function () { - new Promise(variableRequestPromiseMethod).then(resolve); - }); - }); - } - return new Promise(variableRequestPromiseMethod); - }; - return CheckpointLoader; -}()); -exports.CheckpointLoader = CheckpointLoader; - -},{"../tensor":146}],28:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var STATS_SAMPLE_PERCENTAGE = 0.1; -var InMemoryDataset = (function () { - function InMemoryDataset(dataShapes) { - this.dataShapes = dataShapes; - this.normalizationInfo = {}; - } - InMemoryDataset.prototype.getDataShape = function (dataIndex) { - return this.dataShapes[dataIndex]; - }; - InMemoryDataset.prototype.getData = function () { - return this.dataset; - }; - InMemoryDataset.prototype.getStats = function () { - var _this = this; - if (this.dataset == null) { - throw new Error('Data is null.'); - } - return this.dataset.map(function (d) { return _this.getStatsForData(d); }); - }; - InMemoryDataset.prototype.getStatsForData = function (data) { - var inputMin = Number.POSITIVE_INFINITY; - var inputMax = Number.NEGATIVE_INFINITY; - var exampleIndices = data.map(function (example, i) { return i; }); - util.shuffle(exampleIndices); - exampleIndices = - exampleIndices.slice(exampleIndices.length * STATS_SAMPLE_PERCENTAGE); - for (var i = 0; i < exampleIndices.length; i++) { - var inputValues = data[exampleIndices[i]].dataSync(); - for (var j = 0; j < inputValues.length; j++) { - inputMin = Math.min(inputMin, inputValues[j]); - inputMax = Math.max(inputMax, inputValues[j]); - } - } - return { - inputMin: inputMin, - inputMax: inputMax, - exampleCount: data.length, - shape: data[0].shape, - }; - }; - InMemoryDataset.prototype.normalizeExamplesToRange = function (examples, curLowerBounds, curUpperBounds, newLowerBounds, newUpperBounds) { - var curBoundsIsPerDimension = (curUpperBounds instanceof Float32Array && - curLowerBounds instanceof Float32Array); - var newBoundsIsPerDimension = (newLowerBounds instanceof Float32Array && - newUpperBounds instanceof Float32Array); - var inputSize = util.sizeFromShape(examples[0].shape); - var newExamples = []; - examples.forEach(function (example) { - var inputValues = example.dataSync(); - var normalizedValues = new Float32Array(inputSize); - for (var j = 0; j < inputSize; j++) { - var curLowerBound = curBoundsIsPerDimension ? - curLowerBounds[j] : - curLowerBounds; - var curUpperBound = curBoundsIsPerDimension ? - curUpperBounds[j] : - curUpperBounds; - var curRange = curUpperBound - curLowerBound; - var newLowerBound = newBoundsIsPerDimension ? - newLowerBounds[j] : - newLowerBounds; - var newUpperBound = newBoundsIsPerDimension ? - newUpperBounds[j] : - newUpperBounds; - var newRange = newUpperBound - newLowerBound; - if (curRange === 0) { - normalizedValues[j] = newLowerBound; - } - else { - normalizedValues[j] = newLowerBound + - newRange * (inputValues[j] - curLowerBound) / curRange; - } - } - newExamples.push(tensor_1.Tensor.make(example.shape, { values: normalizedValues }, 'float32')); - }); - return newExamples; - }; - InMemoryDataset.prototype.computeBounds = function (dataIndex) { - var _this = this; - if (this.dataset == null) { - throw new Error('Data is null.'); - } - var size = util.sizeFromShape(this.dataset[dataIndex][0].shape); - this.normalizationInfo[dataIndex] = { - isNormalized: false, - minValues: new Float32Array(size), - maxValues: new Float32Array(size) - }; - for (var i = 0; i < size; i++) { - this.normalizationInfo[dataIndex].minValues[i] = Number.POSITIVE_INFINITY; - this.normalizationInfo[dataIndex].maxValues[i] = Number.NEGATIVE_INFINITY; - } - this.dataset[dataIndex].forEach(function (example) { - var inputValues = example.dataSync(); - for (var k = 0; k < size; k++) { - _this.normalizationInfo[dataIndex].minValues[k] = Math.min(_this.normalizationInfo[dataIndex].minValues[k], inputValues[k]); - _this.normalizationInfo[dataIndex].maxValues[k] = Math.max(_this.normalizationInfo[dataIndex].maxValues[k], inputValues[k]); - } - }); - }; - InMemoryDataset.prototype.normalizeWithinBounds = function (dataIndex, lowerBound, upperBound) { - if (this.dataset == null) { - throw new Error('Data is null.'); - } - if (dataIndex >= this.dataset.length) { - throw new Error('dataIndex out of bounds.'); - } - if (this.normalizationInfo[dataIndex] == null) { - this.computeBounds(dataIndex); - } - var curLowerBounds; - var curUpperBounds; - if (this.normalizationInfo[dataIndex].isNormalized) { - curLowerBounds = this.normalizationInfo[dataIndex].lowerBound; - curUpperBounds = this.normalizationInfo[dataIndex].upperBound; - } - else { - curLowerBounds = this.normalizationInfo[dataIndex].minValues; - curUpperBounds = this.normalizationInfo[dataIndex].maxValues; - } - this.dataset[dataIndex] = this.normalizeExamplesToRange(this.dataset[dataIndex], curLowerBounds, curUpperBounds, lowerBound, upperBound); - this.normalizationInfo[dataIndex].isNormalized = true; - this.normalizationInfo[dataIndex].lowerBound = lowerBound; - this.normalizationInfo[dataIndex].upperBound = upperBound; - }; - InMemoryDataset.prototype.isNormalized = function (dataIndex) { - return this.normalizationInfo != null && - this.normalizationInfo[dataIndex].isNormalized; - }; - InMemoryDataset.prototype.removeNormalization = function (dataIndex) { - if (this.dataset == null) { - throw new Error('Training or test data is null.'); - } - if (!this.isNormalized(dataIndex)) { - return; - } - this.dataset[dataIndex] = this.normalizeExamplesToRange(this.dataset[dataIndex], this.normalizationInfo[dataIndex].lowerBound, this.normalizationInfo[dataIndex].upperBound, this.normalizationInfo[dataIndex].minValues, this.normalizationInfo[dataIndex].maxValues); - this.normalizationInfo[dataIndex].isNormalized = false; - }; - InMemoryDataset.prototype.unnormalizeExamples = function (examples, dataIndex) { - if (!this.isNormalized(dataIndex)) { - return examples; - } - return this.normalizeExamplesToRange(examples, this.normalizationInfo[dataIndex].lowerBound, this.normalizationInfo[dataIndex].upperBound, this.normalizationInfo[dataIndex].minValues, this.normalizationInfo[dataIndex].maxValues); - }; - InMemoryDataset.prototype.dispose = function () { - if (this.dataset == null) { - return; - } - for (var i = 0; i < this.dataset.length; i++) { - for (var j = 0; j < this.dataset[i].length; j++) { - this.dataset[i][j].dispose(); - } - } - this.dataset = []; - }; - return InMemoryDataset; -}()); -exports.InMemoryDataset = InMemoryDataset; - -},{"../tensor":146,"../util":151}],29:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -var InMemoryShuffledInputProviderBuilder = (function () { - function InMemoryShuffledInputProviderBuilder(inputs) { - this.inputs = inputs; - this.idx = 0; - this.inputCounter = 0; - this.epoch = 0; - this.shuffledIndices = util.createShuffledIndices(inputs[0].length); - this.numInputs = inputs.length; - var numExamples = this.inputs[0].length; - for (var i = 0; i < this.numInputs; i++) { - util.assert(this.inputs[i].length === numExamples, 'Number of examples must match across different inputs.'); - } - for (var i = 0; i < this.numInputs; i++) { - var inputShape = this.inputs[i][0].shape; - for (var j = 0; j < this.inputs[i].length; j++) { - util.assertShapesMatch(inputShape, this.inputs[i][j].shape); - } - } - } - InMemoryShuffledInputProviderBuilder.prototype.getCurrentExampleIndex = function () { - var returnIdx = this.idx; - this.inputCounter++; - if (this.inputCounter >= this.numInputs) { - this.idx++; - this.inputCounter = 0; - if (this.idx >= this.inputs[0].length) { - this.idx = 0; - this.epoch++; - } - } - return returnIdx; - }; - InMemoryShuffledInputProviderBuilder.prototype.getNextInput = function (inputId) { - var currentExampleIndex = this.getCurrentExampleIndex(); - return this.inputs[inputId][this.shuffledIndices[currentExampleIndex]]; - }; - InMemoryShuffledInputProviderBuilder.prototype.getEpoch = function () { - return this.epoch; - }; - InMemoryShuffledInputProviderBuilder.prototype.getInputProviders = function () { - var inputProviders = []; - for (var i = 0; i < this.numInputs; i++) { - inputProviders.push(this.getInputProvider(i)); - } - return inputProviders; - }; - return InMemoryShuffledInputProviderBuilder; -}()); -exports.InMemoryShuffledInputProviderBuilder = InMemoryShuffledInputProviderBuilder; -var InCPUMemoryShuffledInputProviderBuilder = (function (_super) { - __extends(InCPUMemoryShuffledInputProviderBuilder, _super); - function InCPUMemoryShuffledInputProviderBuilder() { - return _super !== null && _super.apply(this, arguments) || this; - } - InCPUMemoryShuffledInputProviderBuilder.prototype.getInputProvider = function (inputId) { - var shuffledInputProvider = this; - return { - getNextCopy: function () { - return shuffledInputProvider.getNextInput(inputId).clone(); - }, - disposeCopy: function (copy) { - copy.dispose(); - } - }; - }; - return InCPUMemoryShuffledInputProviderBuilder; -}(InMemoryShuffledInputProviderBuilder)); -exports.InCPUMemoryShuffledInputProviderBuilder = InCPUMemoryShuffledInputProviderBuilder; -var InGPUMemoryShuffledInputProviderBuilder = (function (_super) { - __extends(InGPUMemoryShuffledInputProviderBuilder, _super); - function InGPUMemoryShuffledInputProviderBuilder() { - return _super !== null && _super.apply(this, arguments) || this; - } - InGPUMemoryShuffledInputProviderBuilder.prototype.getInputProvider = function (inputId) { - var shuffledInputProvider = this; - return { - getNextCopy: function () { - return shuffledInputProvider.getNextInput(inputId).clone(); - }, - disposeCopy: function (copy) { - copy.dispose(); - } - }; - }; - return InGPUMemoryShuffledInputProviderBuilder; -}(InMemoryShuffledInputProviderBuilder)); -exports.InGPUMemoryShuffledInputProviderBuilder = InGPUMemoryShuffledInputProviderBuilder; - -},{"../util":151}],30:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var dataset_1 = require("./dataset"); -var PARSING_IMAGE_CANVAS_HEIGHT_PX = 1000; -function getXhrDatasetConfig(jsonConfigPath) { - return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', jsonConfigPath); - xhr.onload = function () { - resolve(JSON.parse(xhr.responseText)); - }; - xhr.onerror = function (error) { - reject(error); - }; - xhr.send(); - }); -} -exports.getXhrDatasetConfig = getXhrDatasetConfig; -var XhrDataset = (function (_super) { - __extends(XhrDataset, _super); - function XhrDataset(xhrDatasetConfig) { - var _this = _super.call(this, xhrDatasetConfig.data.map(function (x) { return x.shape; })) || this; - _this.xhrDatasetConfig = xhrDatasetConfig; - return _this; - } - XhrDataset.prototype.getTensor = function (info) { - var dataPromise = info.dataType === 'png' ? - parseTypedArrayFromPng(info, info.shape) : - parseTypedArrayFromBinary(info); - var inputSize = util.sizeFromShape(info.shape); - return dataPromise.then(function (data) { - var tensors = []; - for (var i = 0; i < data.length / inputSize; i++) { - var values = data.subarray(i * inputSize, (i + 1) * inputSize); - var tensor = tensor_1.Tensor.make(info.shape, { values: new Float32Array(values) }, 'float32'); - tensors.push(tensor); - } - return tensors; - }); - }; - XhrDataset.prototype.fetchData = function () { - var _this = this; - return new Promise(function (resolve, reject) { - var promises = _this.xhrDatasetConfig.data.map(function (x) { return _this.getTensor(x); }); - Promise.all(promises).then(function (data) { - _this.dataset = data; - resolve(); - }); - }); - }; - return XhrDataset; -}(dataset_1.InMemoryDataset)); -exports.XhrDataset = XhrDataset; -function parseTypedArrayFromBinary(info) { - return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', info.path); - xhr.responseType = 'arraybuffer'; - xhr.onload = function (event) { - var data = (info.dataType === 'float32') ? - new Float32Array(xhr.response) : - new Uint8Array(xhr.response); - resolve(data); - }; - xhr.onerror = function (err) { return reject(err); }; - xhr.send(); - }); -} -function parseGrayscaleImageData(data, result, resultOffset) { - var idx = resultOffset; - for (var i = 0; i < data.length; i += 4) { - result[idx++] = data[i]; - } -} -function parseRGBImageData(data, result, resultOffset) { - var idx = resultOffset; - for (var i = 0; i < data.length; i += 4) { - result[idx] = data[i]; - result[idx + 1] = data[i + 1]; - result[idx + 2] = data[i + 2]; - idx += 3; - } -} -function parseImage(img, shape) { - var canvas = document.createElement('canvas'); - var ctx = canvas.getContext('2d'); - var N = img.height; - var inputSize = util.sizeFromShape(shape); - var result = new Uint8Array(N * inputSize); - if (img.width !== shape[0] * shape[1]) { - throw new Error("Image width (" + img.width + ") must be multiple of " + - ("rows*columns (" + shape[0] + "*" + shape[1] + ") of the tensor")); - } - canvas.width = img.width; - canvas.height = PARSING_IMAGE_CANVAS_HEIGHT_PX; - var sx = 0; - var sWidth = canvas.width; - var sHeight = canvas.height; - var dx = 0; - var dy = 0; - var dWidth = sWidth; - var dHeight = sHeight; - var depth = shape[2]; - var offset = 0; - var numPasses = Math.ceil(N / canvas.height); - for (var pass = 0; pass < numPasses; ++pass) { - var sy = pass * canvas.height; - if ((pass === numPasses - 1) && (N % canvas.height > 0)) { - canvas.height = N % canvas.height; - sHeight = canvas.height; - dHeight = sHeight; - } - ctx.drawImage(img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); - var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data; - (depth === 1) ? parseGrayscaleImageData(data, result, offset) : - parseRGBImageData(data, result, offset); - offset += canvas.height * inputSize; - } - return result; -} -function parseTypedArrayFromPng(info, shape) { - return new Promise(function (resolve, reject) { - var img = new Image(); - img.setAttribute('crossOrigin', ''); - img.onload = function () { - var result = parseImage(img, shape); - img.src = ''; - img = null; - resolve(result); - }; - img.src = info.path; - }); -} - -},{"../tensor":146,"../util":151,"./dataset":28}],31:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function isMobile() { - var a = navigator.userAgent || navigator.vendor || window.opera; - return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i - .test(a) || - /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i - .test(a.substr(0, 4)); -} -exports.isMobile = isMobile; - -},{}],32:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function doc(info) { - return function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - }; -} -exports.doc = doc; - -},{}],33:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("./environment"); -var globals_1 = require("./globals"); -var kernel_registry = require("./kernels/kernel_registry"); -var ops = require("./ops/ops"); -var profiler_1 = require("./profiler"); -var tape_util = require("./tape_util"); -var tensor_1 = require("./tensor"); -var util = require("./util"); -var Engine = (function () { - function Engine(backend, customBackend, safeMode) { - this.backend = backend; - this.customBackend = customBackend; - this.safeMode = safeMode; - this.registeredVariables = {}; - this.refCounter = new WeakMap(); - this.nextTapeNodeId = 0; - this.numBytes = 0; - this.numTensors = 0; - this.numDataBuffers = 0; - this.gradientScopeCount = 0; - this.customGradientDepth = 0; - this.activeScope = { keep: [], track: [] }; - this.scopeStack = [this.activeScope]; - this.profiler = new profiler_1.Profiler(backend); - } - Engine.prototype.executeKernel = function (kernelName, config, grad) { - var _this = this; - var result; - if (!environment_1.ENV.get('DEBUG')) { - result = kernel_registry.executeKernel(this.backend, kernelName, config); - } - else { - result = this.profiler.profileKernel(kernelName, function () { - return kernel_registry.executeKernel(_this.backend, kernelName, config); - }); - } - var recordKernel = this.activeTape != null && this.customGradientDepth === 0; - if (recordKernel) { - config = tape_util.stripUndefinedInputsFromInputConfig(config); - var evaluatedNode = { - id: this.nextTapeNodeId++, - type: 'kernel', - name: "kernel: " + kernelName, - kernel: kernelName, - inputAndArgs: config, - output: result, - gradient: grad - }; - this.activeTape.push(evaluatedNode); - } - return result; - }; - Engine.prototype.registerTensor = function (a) { - var refCount = this.refCounter.has(a.dataId) ? this.refCounter.get(a.dataId) : 0; - this.numTensors++; - if (refCount === 0) { - this.numDataBuffers++; - this.numBytes += - util.sizeFromShape(a.shape) * util.bytesPerElement(a.dtype); - this.backend.register(a.dataId, a.shape, a.dtype); - } - this.refCounter.set(a.dataId, refCount + 1); - if (!(a instanceof tensor_1.Variable)) { - this.track(a); - } - }; - Engine.prototype.registerVariable = function (v) { - if (this.registeredVariables[v.name] != null) { - throw new Error("Variable with name " + v.name + " was already registered"); - } - this.registeredVariables[v.name] = v; - }; - Engine.prototype.disposeTensor = function (a) { - if (!this.refCounter.has(a.dataId)) { - return; - } - this.numTensors--; - var refCount = this.refCounter.get(a.dataId); - if (refCount <= 1) { - this.refCounter.delete(a.dataId); - this.backend.disposeData(a.dataId); - this.numDataBuffers--; - this.numBytes -= - util.sizeFromShape(a.shape) * util.bytesPerElement(a.dtype); - } - else { - this.refCounter.set(a.dataId, refCount - 1); - } - }; - Engine.prototype.memory = function () { - var info = this.backend.memory(); - info.numTensors = this.numTensors; - info.numDataBuffers = this.numDataBuffers; - info.numBytes = this.numBytes; - return info; - }; - Engine.prototype.shouldRecord = function () { - return this.activeTape != null && this.customGradientDepth === 0; - }; - Engine.prototype.addTapeNode = function (inputs, result, gradientsFunc) { - var inputsMap = {}; - inputs.forEach(function (input, idx) { - inputsMap[idx] = input; - }); - var gradient = function (dy) { - var res = gradientsFunc(dy); - var resMap = {}; - res.forEach(function (r, idx) { - resMap[idx] = function () { return r; }; - }); - return resMap; - }; - var evaluatedNode = { - id: this.nextTapeNodeId++, - type: 'customGradient', - name: name, - inputAndArgs: { inputs: inputsMap }, - output: result, - gradient: gradient - }; - this.activeTape.push(evaluatedNode); - }; - Engine.prototype.keep = function (result) { - if (this.scopeStack.length === 1 && environment_1.ENV.engine.safeMode) { - throw new Error('Safe mode is ON. Enclose all tensor operations inside dl.tidy(): ' + - 'dl.tidy(() => {...}) to avoid memory leaks.'); - } - this.activeScope.keep.push(result); - return result; - }; - Engine.prototype.startScope = function (gradientsMode) { - if (gradientsMode === void 0) { gradientsMode = false; } - if (gradientsMode && this.gradientScopeCount === 0) { - this.activeTape = []; - } - if (gradientsMode) { - this.gradientScopeCount++; - } - var newScopeArrays = { keep: [], track: [] }; - this.scopeStack.push(newScopeArrays); - this.activeScope = newScopeArrays; - }; - Engine.prototype.endScope = function (result, gradientsMode) { - var _this = this; - if (gradientsMode === void 0) { gradientsMode = false; } - if (gradientsMode) { - this.gradientScopeCount--; - if (this.gradientScopeCount === 0) { - this.activeTape = null; - } - } - var tensorsToKeep = this.activeScope.keep; - var tensorsToTrackInParent = tape_util.extractTensorsFromScopeResult(result); - tensorsToKeep = tensorsToKeep.concat(tensorsToTrackInParent); - for (var i = 0; i < this.activeScope.track.length; i++) { - var tensor = this.activeScope.track[i]; - if (util.isTensorInList(tensor, tensorsToKeep)) { - continue; - } - if (this.activeTape != null) { - tensorsToTrackInParent.push(tensor); - } - else { - tensor.dispose(); - } - } - this.scopeStack.pop(); - this.activeScope = this.scopeStack.length === 0 ? - { keep: [], track: [] } : - this.scopeStack[this.scopeStack.length - 1]; - tensorsToTrackInParent.forEach(function (tensor) { - if (!util.isTensorInList(tensor, _this.activeScope.keep)) { - _this.track(tensor); - } - }); - }; - Engine.prototype.dispose = function () { - if (this.customBackend) { - this.backend.dispose(); - } - }; - Engine.prototype.gradients = function (f, xs, dy, allowNoGradients) { - var _this = this; - if (allowNoGradients === void 0) { allowNoGradients = false; } - return globals_1.tidy('gradients', function () { - var y = f(); - util.assert(y instanceof tensor_1.Tensor, 'The result y returned by f() must be a tensor.'); - var filteredTape = tape_util.getFilteredNodesXToY(_this.activeTape, xs, y); - if (!allowNoGradients && filteredTape.length === 0 && xs.length > 0) { - throw new Error('Cannot compute gradient of y=f(x) with respect to x. Make sure ' + - 'that the f you passed encloses all operations that lead from x ' + - 'to y.'); - } - var accumulatedGradientMap = {}; - accumulatedGradientMap[y.id] = (dy == null) ? ops.onesLike(y) : dy; - tape_util.backpropagateGradients(accumulatedGradientMap, filteredTape); - var grads = xs.map(function (x) { return accumulatedGradientMap[x.id]; }); - return { value: y, grads: grads }; - }, true); - }; - Engine.prototype.customGrad = function (f) { - var _this = this; - util.assert(util.isFunction(f), 'The f passed in customGrad(f) must be a function.'); - return function () { - var inputs = []; - for (var _i = 0; _i < arguments.length; _i++) { - inputs[_i] = arguments[_i]; - } - util.assert(inputs.every(function (t) { return t instanceof tensor_1.Tensor; }), 'The args passed in customGrad(f)(x1, x2,...) must all be tensors'); - _this.customGradientDepth++; - var gradientsFunc; - var gradientsMode = true; - var result = globals_1.tidy(f.name, function () { - var _a = f.apply(void 0, inputs), value = _a.value, gradFunc = _a.gradFunc; - util.assert(value instanceof tensor_1.Tensor, 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.value` is a tensor'); - util.assert(util.isFunction(gradFunc), 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.gradFunc` is a function.'); - gradientsFunc = gradFunc; - return value; - }, gradientsMode); - _this.customGradientDepth--; - if (_this.shouldRecord()) { - var gradFunc = function (dy) { - var res = gradientsFunc(dy); - var grads = Array.isArray(res) ? res : [res]; - util.assert(grads.length === inputs.length, 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.gradFunc` is a function that returns the same ' + - 'number of tensors as inputs passed to f(...).'); - util.assert(grads.every(function (t) { return t instanceof tensor_1.Tensor; }), 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.gradFunc` is a function that returns a list of ' + - 'only tensors.'); - return grads; - }; - _this.addTapeNode(inputs, result, gradFunc); - } - return result; - }; - }; - Engine.prototype.write = function (dataId, values) { - this.backend.write(dataId, values); - }; - Engine.prototype.readSync = function (dataId) { - return this.backend.readSync(dataId); - }; - Engine.prototype.read = function (dataId) { - return this.backend.read(dataId); - }; - Engine.prototype.fromPixels = function (pixels, numChannels) { - return this.backend.fromPixels(pixels, numChannels); - }; - Engine.prototype.time = function (query) { - return __awaiter(this, void 0, void 0, function () { - var start, timingInfo; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - start = performance.now(); - return [4, this.backend.time(query)]; - case 1: - timingInfo = _a.sent(); - timingInfo.wallMs = performance.now() - start; - return [2, timingInfo]; - } - }); - }); - }; - Engine.prototype.track = function (result) { - if (this.scopeStack.length === 1 && this.safeMode) { - throw new Error('Safe mode is ON. Enclose all tensor operations inside dl.tidy(): ' + - 'dl.tidy(() => {op();...}); to avoid memory leaks.'); - } - this.activeScope.track.push(result); - return result; - }; - return Engine; -}()); -exports.Engine = Engine; - -},{"./environment":34,"./globals":35,"./kernels/kernel_registry":70,"./ops/ops":123,"./profiler":144,"./tape_util":145,"./tensor":146,"./util":151}],34:[function(require,module,exports){ -(function (global){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var device_util = require("./device_util"); -var doc_1 = require("./doc"); -var engine_1 = require("./engine"); -var math_1 = require("./math"); -var util = require("./util"); -var Type; -(function (Type) { - Type[Type["NUMBER"] = 0] = "NUMBER"; - Type[Type["BOOLEAN"] = 1] = "BOOLEAN"; - Type[Type["STRING"] = 2] = "STRING"; -})(Type = exports.Type || (exports.Type = {})); -exports.URL_PROPERTIES = [ - { name: 'DEBUG', type: Type.BOOLEAN }, - { name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION', type: Type.NUMBER }, - { name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE', type: Type.BOOLEAN }, - { name: 'WEBGL_VERSION', type: Type.NUMBER }, - { name: 'WEBGL_FLOAT_TEXTURE_ENABLED', type: Type.BOOLEAN }, { - name: 'WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED', - type: Type.BOOLEAN - }, - { name: 'BACKEND', type: Type.STRING } -]; -function hasExtension(gl, extensionName) { - var ext = gl.getExtension(extensionName); - return ext != null; -} -function getWebGLRenderingContext(webGLVersion) { - if (webGLVersion === 0) { - throw new Error('Cannot get WebGL rendering context, WebGL is disabled.'); - } - var tempCanvas = document.createElement('canvas'); - if (webGLVersion === 1) { - return (tempCanvas.getContext('webgl') || - tempCanvas.getContext('experimental-webgl')); - } - return tempCanvas.getContext('webgl2'); -} -function loseContext(gl) { - if (gl != null) { - var loseContextExtension = gl.getExtension('WEBGL_lose_context'); - if (loseContextExtension == null) { - throw new Error('Extension WEBGL_lose_context not supported on this browser.'); - } - loseContextExtension.loseContext(); - } -} -function isWebGLVersionEnabled(webGLVersion) { - var gl = getWebGLRenderingContext(webGLVersion); - if (gl != null) { - loseContext(gl); - return true; - } - return false; -} -function getWebGLDisjointQueryTimerVersion(webGLVersion) { - if (webGLVersion === 0) { - return 0; - } - var queryTimerVersion; - var gl = getWebGLRenderingContext(webGLVersion); - if (hasExtension(gl, 'EXT_disjoint_timer_query_webgl2') && - webGLVersion === 2) { - queryTimerVersion = 2; - } - else if (hasExtension(gl, 'EXT_disjoint_timer_query')) { - queryTimerVersion = 1; - } - else { - queryTimerVersion = 0; - } - if (gl != null) { - loseContext(gl); - } - return queryTimerVersion; -} -function isFloatTextureReadPixelsEnabled(webGLVersion) { - if (webGLVersion === 0) { - return false; - } - var gl = getWebGLRenderingContext(webGLVersion); - if (webGLVersion === 1) { - if (!hasExtension(gl, 'OES_texture_float')) { - return false; - } - } - else { - if (!hasExtension(gl, 'EXT_color_buffer_float')) { - return false; - } - } - var frameBuffer = gl.createFramebuffer(); - var texture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, texture); - var internalFormat = webGLVersion === 2 ? gl.RGBA32F : gl.RGBA; - gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, 1, 1, 0, gl.RGBA, gl.FLOAT, null); - gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); - var frameBufferComplete = (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE); - gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.FLOAT, new Float32Array(4)); - var readPixelsNoError = gl.getError() === gl.NO_ERROR; - loseContext(gl); - return frameBufferComplete && readPixelsNoError; -} -function isWebGLGetBufferSubDataAsyncExtensionEnabled(webGLVersion) { - if (webGLVersion !== 2) { - return false; - } - var gl = getWebGLRenderingContext(webGLVersion); - var isEnabled = hasExtension(gl, 'WEBGL_get_buffer_sub_data_async'); - loseContext(gl); - return isEnabled; -} -var SUPPORTED_BACKENDS = ['webgl', 'cpu']; -var Environment = (function () { - function Environment(features) { - this.features = {}; - this.BACKEND_REGISTRY = {}; - this.backends = this.BACKEND_REGISTRY; - if (features != null) { - this.features = features; - } - if (this.get('DEBUG')) { - console.warn('Debugging mode is ON. The output of every math call will ' + - 'be downloaded to CPU and checked for NaNs. ' + - 'This significantly impacts performance.'); - } - } - Environment.setBackend = function (backendType, safeMode) { - if (safeMode === void 0) { safeMode = false; } - if (!(backendType in exports.ENV.backends)) { - throw new Error("Backend type '" + backendType + "' not found in registry"); - } - exports.ENV.globalMath = new math_1.NDArrayMath(backendType, safeMode); - }; - Environment.getBackend = function () { - exports.ENV.initEngine(); - return exports.ENV.currentBackendType; - }; - Environment.memory = function () { - return exports.ENV.engine.memory(); - }; - Environment.prototype.get = function (feature) { - if (feature in this.features) { - return this.features[feature]; - } - this.features[feature] = this.evaluateFeature(feature); - return this.features[feature]; - }; - Environment.prototype.set = function (feature, value) { - this.features[feature] = value; - }; - Environment.prototype.getBestBackendType = function () { - for (var i = 0; i < SUPPORTED_BACKENDS.length; ++i) { - var backendId = SUPPORTED_BACKENDS[i]; - if (backendId in this.backends) { - return backendId; - } - } - throw new Error('No backend found in registry.'); - }; - Environment.prototype.evaluateFeature = function (feature) { - if (feature === 'DEBUG') { - return false; - } - else if (feature === 'BACKEND') { - return this.getBestBackendType(); - } - else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') { - var webGLVersion = this.get('WEBGL_VERSION'); - if (webGLVersion === 0) { - return 0; - } - return getWebGLDisjointQueryTimerVersion(webGLVersion); - } - else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE') { - return this.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0 && - !device_util.isMobile(); - } - else if (feature === 'WEBGL_VERSION') { - if (isWebGLVersionEnabled(2)) { - return 2; - } - else if (isWebGLVersionEnabled(1)) { - return 1; - } - return 0; - } - else if (feature === 'WEBGL_FLOAT_TEXTURE_ENABLED') { - return isFloatTextureReadPixelsEnabled(this.get('WEBGL_VERSION')); - } - else if (feature === 'WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED') { - return isWebGLGetBufferSubDataAsyncExtensionEnabled(this.get('WEBGL_VERSION')); - } - throw new Error("Unknown feature " + feature + "."); - }; - Environment.prototype.setFeatures = function (features) { - this.reset(); - this.features = features; - this.backends = {}; - }; - Environment.prototype.reset = function () { - this.features = getFeaturesFromURL(); - if (this.globalMath != null) { - this.globalMath.dispose(); - this.globalMath = null; - this.globalEngine = null; - } - if (this.backends !== this.BACKEND_REGISTRY) { - for (var name_1 in this.backends) { - this.backends[name_1].dispose(); - } - this.backends = this.BACKEND_REGISTRY; - } - }; - Environment.prototype.setMath = function (math, backend, safeMode) { - if (safeMode === void 0) { safeMode = false; } - if (this.globalMath === math) { - return; - } - var customBackend = false; - if (typeof backend === 'string') { - this.currentBackendType = backend; - backend = exports.ENV.findBackend(backend); - } - else { - customBackend = true; - this.currentBackendType = 'custom'; - } - this.globalEngine = new engine_1.Engine(backend, customBackend, safeMode); - this.globalMath = math; - }; - Environment.prototype.findBackend = function (name) { - return this.backends[name]; - }; - Environment.prototype.addCustomBackend = function (name, factory) { - if (name in this.backends) { - throw new Error(name + " backend was already registered"); - } - try { - var backend = factory(); - this.backends[name] = backend; - return true; - } - catch (err) { - return false; - } - }; - Environment.prototype.registerBackend = function (name, factory) { - if (name in this.BACKEND_REGISTRY) { - throw new Error(name + " backend was already registered as global"); - } - try { - var backend = factory(); - this.BACKEND_REGISTRY[name] = backend; - return true; - } - catch (err) { - return false; - } - }; - Object.defineProperty(Environment.prototype, "math", { - get: function () { - if (this.globalEngine == null) { - this.initEngine(); - } - return this.globalMath; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Environment.prototype, "engine", { - get: function () { - if (this.globalEngine == null) { - this.initEngine(); - } - return this.globalEngine; - }, - enumerable: true, - configurable: true - }); - Environment.prototype.initEngine = function () { - this.globalMath = new math_1.NDArrayMath(exports.ENV.get('BACKEND'), false); - }; - __decorate([ - doc_1.doc({ heading: 'Environment' }) - ], Environment, "setBackend", null); - __decorate([ - doc_1.doc({ heading: 'Environment' }) - ], Environment, "getBackend", null); - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Memory' }) - ], Environment, "memory", null); - return Environment; -}()); -exports.Environment = Environment; -var DEEPLEARNJS_FLAGS_PREFIX = 'dljsflags'; -function getFeaturesFromURL() { - var features = {}; - if (typeof window === 'undefined') { - return features; - } - var urlParams = util.getQueryParams(window.location.search); - if (DEEPLEARNJS_FLAGS_PREFIX in urlParams) { - var urlFlags_1 = {}; - var keyValues = urlParams[DEEPLEARNJS_FLAGS_PREFIX].split(','); - keyValues.forEach(function (keyValue) { - var _a = keyValue.split(':'), key = _a[0], value = _a[1]; - urlFlags_1[key] = value; - }); - exports.URL_PROPERTIES.forEach(function (urlProperty) { - if (urlProperty.name in urlFlags_1) { - console.log("Setting feature override from URL " + urlProperty.name + ": " + - ("" + urlFlags_1[urlProperty.name])); - if (urlProperty.type === Type.NUMBER) { - features[urlProperty.name] = +urlFlags_1[urlProperty.name]; - } - else if (urlProperty.type === Type.BOOLEAN) { - features[urlProperty.name] = urlFlags_1[urlProperty.name] === 'true'; - } - else if (urlProperty.type === Type.STRING) { - features[urlProperty.name] = urlFlags_1[urlProperty.name]; - } - else { - console.warn("Unknown URL param: " + urlProperty.name + "."); - } - } - }); - } - return features; -} -function getGlobalNamespace() { - var ns; - if (typeof (window) !== 'undefined') { - ns = window; - } - else if (typeof (global) !== 'undefined') { - ns = global; - } - else { - throw new Error('Could not find a global object'); - } - return ns; -} -function getOrMakeEnvironment() { - var ns = getGlobalNamespace(); - ns.ENV = ns.ENV || new Environment(getFeaturesFromURL()); - return ns.ENV; -} -exports.ENV = getOrMakeEnvironment(); - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./device_util":31,"./doc":32,"./engine":33,"./math":105,"./util":151}],35:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var gradients_1 = require("./gradients"); -var tracking_1 = require("./tracking"); -exports.tidy = tracking_1.Tracking.tidy; -exports.keep = tracking_1.Tracking.keep; -exports.time = tracking_1.Tracking.time; -exports.grad = gradients_1.Gradients.grad; -exports.valueAndGrad = gradients_1.Gradients.valueAndGrad; -exports.grads = gradients_1.Gradients.grads; -exports.valueAndGrads = gradients_1.Gradients.valueAndGrads; -exports.variableGrads = gradients_1.Gradients.variableGrads; -exports.customGrad = gradients_1.Gradients.customGrad; - -},{"./gradients":36,"./tracking":148}],36:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var environment_1 = require("./environment"); -var globals_1 = require("./globals"); -var tensor_1 = require("./tensor"); -var util = require("./util"); -var Gradients = (function () { - function Gradients() { - } - Gradients.gradScope = function (nameOrScopeFn, scopeFn) { - return globals_1.tidy(nameOrScopeFn, scopeFn, true); - }; - Gradients.grad = function (f) { - util.assert(util.isFunction(f), 'The f passed in grad(f) must be a function'); - return function (x, dy) { - util.assert(x instanceof tensor_1.Tensor, 'The x passed in grad(f)(x) must be a tensor'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in grad(f)(x, dy) must be a tensor'); - var _a = environment_1.ENV.engine.gradients(function () { return f(x); }, [x], dy), value = _a.value, grads = _a.grads; - if (dy != null) { - util.assertShapesMatch(value.shape, dy.shape, 'The shape of dy passed in grad(f)(x, dy) must match the shape ' + - 'returned by f(x)'); - } - value.dispose(); - checkGrads(grads); - return grads[0]; - }; - }; - Gradients.grads = function (f) { - util.assert(util.isFunction(f), 'The f passed in grads(f) must be a function'); - return function (args, dy) { - util.assert(Array.isArray(args) && args.every(function (arg) { return arg instanceof tensor_1.Tensor; }), 'The args passed in grads(f)(args) must be an array of tensors'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in grads(f)(args, dy) must be a tensor'); - var _a = environment_1.ENV.engine.gradients(function () { return f.apply(void 0, args); }, args, dy), value = _a.value, grads = _a.grads; - if (dy != null) { - util.assertShapesMatch(value.shape, dy.shape, 'The shape of dy passed in grads(f)([x1,...], dy) must match the ' + - 'shape returned by f([x1,...])'); - } - value.dispose(); - checkGrads(grads); - return grads; - }; - }; - Gradients.valueAndGrad = function (f) { - util.assert(util.isFunction(f), 'The f passed in valueAndGrad(f) must be a function'); - return function (x, dy) { - util.assert(x instanceof tensor_1.Tensor, 'The x passed in valueAndGrad(f)(x) must be a tensor'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in valueAndGrad(f)(x, dy) must be a tensor'); - var _a = environment_1.ENV.engine.gradients(function () { return f(x); }, [x], dy), grads = _a.grads, value = _a.value; - checkGrads(grads); - return { grad: grads[0], value: value }; - }; - }; - Gradients.valueAndGrads = function (f) { - util.assert(util.isFunction(f), 'The f passed in valueAndGrads(f) must be a function'); - return function (args, dy) { - util.assert(Array.isArray(args) && args.every(function (arg) { return arg instanceof tensor_1.Tensor; }), 'The args passed in valueAndGrads(f)(args) must be array of tensors'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in valueAndGrads(f)(args, dy) must be a tensor'); - var res = environment_1.ENV.engine.gradients(function () { return f.apply(void 0, args); }, args, dy); - if (dy != null) { - util.assertShapesMatch(res.value.shape, dy.shape, 'The shape of dy passed in valueAndGrads(f)([x1,...], dy) must ' + - 'match the shape returned by f([x1,...])'); - } - checkGrads(res.grads); - return res; - }; - }; - Gradients.variableGrads = function (f, varList) { - util.assert(util.isFunction(f), 'The f passed in variableGrads(f) must be a function'); - util.assert(varList == null || - Array.isArray(varList) && varList.every(function (v) { return v instanceof tensor_1.Variable; }), 'The varList passed in variableGrads(f, varList) must be an array ' + - 'of variables'); - if (varList == null) { - varList = []; - for (var varName in environment_1.ENV.engine.registeredVariables) { - varList.push(environment_1.ENV.engine.registeredVariables[varName]); - } - } - varList = varList.filter(function (variable) { return variable.trainable; }); - var allowNoGradients = true; - var _a = environment_1.ENV.engine.gradients(f, varList, null, allowNoGradients), value = _a.value, grads = _a.grads; - util.assert(grads.some(function (g) { return g != null; }), 'Cannot find a connection between any variable and the result of the ' + - 'loss function y=f(x). Please make sure the operations that use ' + - 'variables are inside the function f passed to minimize().'); - util.assert(value.rank === 0, "The f passed in variableGrads(f) must return a scalar, but it " + - ("returned a rank-" + value.rank + " tensor")); - var namedGrads = {}; - varList.forEach(function (v, i) { - if (grads[i] != null) { - namedGrads[v.name] = grads[i]; - } - }); - return { value: value, grads: namedGrads }; - }; - Gradients.customGrad = function (f) { - return environment_1.ENV.engine.customGrad(f); - }; - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "grad", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "grads", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "valueAndGrad", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "valueAndGrads", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "variableGrads", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "customGrad", null); - return Gradients; -}()); -exports.Gradients = Gradients; -function checkGrads(grads) { - var numNullGradients = grads.filter(function (g) { return g == null; }).length; - if (numNullGradients > 0) { - throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y."); - } -} - -},{"./doc":32,"./environment":34,"./globals":35,"./tensor":146,"./util":151}],37:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var TanHFunc = (function () { - function TanHFunc() { - this.one = tensor_1.Scalar.new(1); - } - TanHFunc.prototype.output = function (math, x) { - return math.tanh(x); - }; - TanHFunc.prototype.der = function (math, x, y) { - var _this = this; - return globals_1.tidy(function () { - var ySquared = math.multiplyStrict(y, y); - return math.subtract(_this.one, ySquared); - }); - }; - TanHFunc.prototype.dispose = function () { - this.one.dispose(); - }; - return TanHFunc; -}()); -exports.TanHFunc = TanHFunc; -var ReLUFunc = (function () { - function ReLUFunc() { - } - ReLUFunc.prototype.output = function (math, x) { - return math.relu(x); - }; - ReLUFunc.prototype.der = function (math, x, y) { - return math.step(x); - }; - ReLUFunc.prototype.dispose = function () { }; - return ReLUFunc; -}()); -exports.ReLUFunc = ReLUFunc; -var LeakyReluFunc = (function () { - function LeakyReluFunc(alpha) { - this.alpha = alpha; - } - LeakyReluFunc.prototype.output = function (math, x) { - return math.leakyRelu(x, this.alpha); - }; - LeakyReluFunc.prototype.der = function (math, x, y) { - return math.step(x, this.alpha); - }; - LeakyReluFunc.prototype.dispose = function () { }; - return LeakyReluFunc; -}()); -exports.LeakyReluFunc = LeakyReluFunc; -var SigmoidFunc = (function () { - function SigmoidFunc() { - } - SigmoidFunc.prototype.output = function (math, x) { - return math.sigmoid(x); - }; - SigmoidFunc.prototype.der = function (math, x, y) { - return globals_1.tidy(function () { - var ySquared = math.multiplyStrict(y, y); - return math.subStrict(y, ySquared); - }); - }; - SigmoidFunc.prototype.dispose = function () { }; - return SigmoidFunc; -}()); -exports.SigmoidFunc = SigmoidFunc; -var SquareFunc = (function () { - function SquareFunc() { - this.two = tensor_1.Scalar.new(2); - } - SquareFunc.prototype.output = function (math, x) { - return math.multiplyStrict(x, x); - }; - SquareFunc.prototype.der = function (math, x, y) { - return math.multiply(this.two, x); - }; - SquareFunc.prototype.dispose = function () { - this.two.dispose(); - }; - return SquareFunc; -}()); -exports.SquareFunc = SquareFunc; -var EluFunc = (function () { - function EluFunc() { - } - EluFunc.prototype.output = function (math, x) { - return math.elu(x); - }; - EluFunc.prototype.der = function (math, x, y) { - throw new Error('Not implemented'); - }; - EluFunc.prototype.dispose = function () { }; - return EluFunc; -}()); -exports.EluFunc = EluFunc; - -},{"../globals":35,"../tensor":146}],38:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var ops = require("../ops/ops"); -var SquareCostFunc = (function () { - function SquareCostFunc() { - this.halfOne = globals_1.keep(ops.scalar(0.5)); - } - SquareCostFunc.prototype.cost = function (x1, x2) { - var diff = x1.subStrict(x2); - var diffSquared = diff.square(); - var result = this.halfOne.mul(diffSquared); - diff.dispose(); - diffSquared.dispose(); - return result; - }; - SquareCostFunc.prototype.der = function (x1, x2) { - return x1.subStrict(x2); - }; - SquareCostFunc.prototype.dispose = function () { - this.halfOne.dispose(); - }; - return SquareCostFunc; -}()); -exports.SquareCostFunc = SquareCostFunc; - -},{"../globals":35,"../ops/ops":123}],39:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var concat_util = require("../ops/concat_util"); -var conv_util = require("../ops/conv_util"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var initializers_1 = require("./initializers"); -var GraphLayers = (function () { - function GraphLayers(g) { - this.g = g; - } - GraphLayers.prototype.dense = function (name, x, units, activation, useBias, kernelInitializer, biasInitializer) { - if (activation === void 0) { activation = null; } - if (useBias === void 0) { useBias = true; } - if (kernelInitializer === void 0) { kernelInitializer = new initializers_1.VarianceScalingInitializer(); } - if (biasInitializer === void 0) { biasInitializer = new initializers_1.ZerosInitializer(); } - var weights = this.g.variable(name + '-weights', kernelInitializer.initialize([x.shape[0], units], x.shape[0], units)); - var out = this.g.matmul(x, weights); - if (useBias) { - var bias = this.g.variable(name + '-bias', biasInitializer.initialize([units], x.shape[0], units)); - out = this.g.add(out, bias); - } - if (activation != null) { - out = activation(out); - } - return out; - }; - return GraphLayers; -}()); -exports.GraphLayers = GraphLayers; -var Graph = (function () { - function Graph() { - this.nodes = []; - this.layers = new GraphLayers(this); - } - Graph.prototype.variable = function (name, data) { - return this.addNodeAndReturnOutput(new VariableNode(this, name, data)); - }; - Graph.prototype.placeholder = function (name, shape) { - return this.addNodeAndReturnOutput(new PlaceholderNode(this, name, shape)); - }; - Graph.prototype.constant = function (value) { - var finalValue; - if (typeof value === 'number') { - finalValue = tensor_1.Scalar.new(value); - } - else if (value instanceof tensor_1.Tensor) { - finalValue = value; - } - else if (value instanceof Array) { - var flatValues = util.flatten(value); - var vals = new Float32Array(flatValues); - finalValue = tensor_1.Tensor.make(util.inferShape(value), { values: vals }); - } - else { - throw new Error('unimplemented constant type.'); - } - return this.addNodeAndReturnOutput(new ConstantNode(this, finalValue)); - }; - Graph.prototype.reshape = function (x, shape) { - return this.addNodeAndReturnOutput(new ReshapeNode(this, 'Reshape', x, shape)); - }; - Graph.prototype.fusedLinearCombination = function (x1, x2, c1, c2) { - return this.addNodeAndReturnOutput(new FusedLinearCombinationNode(this, x1, x2, c1, c2)); - }; - Graph.prototype.add = function (x1, x2) { - return this.addNodeAndReturnOutput(new AddNode(this, x1, x2)); - }; - Graph.prototype.subtract = function (x1, x2) { - return this.addNodeAndReturnOutput(new SubtractNode(this, x1, x2)); - }; - Graph.prototype.multiply = function (x1, x2) { - return this.addNodeAndReturnOutput(new MultiplyNode(this, x1, x2)); - }; - Graph.prototype.divide = function (x1, x2) { - return this.addNodeAndReturnOutput(new DivideNode(this, x1, x2)); - }; - Graph.prototype.reduceSum = function (x) { - return this.addNodeAndReturnOutput(new ReduceSumNode(this, x)); - }; - Graph.prototype.concat1d = function (x1, x2) { - return this.addNodeAndReturnOutput(new Concat1DNode(this, x1, x2)); - }; - Graph.prototype.concat2d = function (x1, x2, axis) { - return this.addNodeAndReturnOutput(new Concat2DNode(this, x1, x2, axis)); - }; - Graph.prototype.concat3d = function (x1, x2, axis) { - return this.addNodeAndReturnOutput(new Concat3DNode(this, x1, x2, axis)); - }; - Graph.prototype.concat4d = function (x1, x2, axis) { - return this.addNodeAndReturnOutput(new Concat4DNode(this, x1, x2, axis)); - }; - Graph.prototype.matmul = function (x1, x2) { - return this.addNodeAndReturnOutput(new MatMulNode(this, x1, x2)); - }; - Graph.prototype.conv2d = function (x, w, b, fieldSize, outputDepth, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - return this.addNodeAndReturnOutput(new Convolution2DNode(this, x, w, b, fieldSize, outputDepth, stride, zeroPad)); - }; - Graph.prototype.maxPool = function (x, fieldSize, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - return this.addNodeAndReturnOutput(new MaxPoolNode(this, x, fieldSize, stride, zeroPad)); - }; - Graph.prototype.exp = function (x) { - return this.addNodeAndReturnOutput(new ExpNode(this, x)); - }; - Graph.prototype.log = function (x) { - return this.addNodeAndReturnOutput(new LogNode(this, x)); - }; - Graph.prototype.relu = function (x) { - return this.addNodeAndReturnOutput(new ReLUNode(this, x)); - }; - Graph.prototype.leakyRelu = function (x, alpha) { - return this.addNodeAndReturnOutput(new LeakyReLUNode(this, x, alpha)); - }; - Graph.prototype.prelu = function (x, alpha) { - return this.addNodeAndReturnOutput(new PReLUNode(this, x, alpha)); - }; - Graph.prototype.elu = function (x) { - return this.addNodeAndReturnOutput(new EluNode(this, x)); - }; - Graph.prototype.tanh = function (x) { - return this.addNodeAndReturnOutput(new TanHNode(this, x)); - }; - Graph.prototype.sigmoid = function (x) { - return this.addNodeAndReturnOutput(new SigmoidNode(this, x)); - }; - Graph.prototype.square = function (x) { - return this.addNodeAndReturnOutput(new SquareNode(this, x)); - }; - Graph.prototype.softmax = function (x) { - return this.addNodeAndReturnOutput(new SoftmaxNode(this, x)); - }; - Graph.prototype.softmaxCrossEntropyCost = function (x, target) { - return this.addNodeAndReturnOutput(new SoftmaxCrossEntropyCostNode(this, x, target)); - }; - Graph.prototype.meanSquaredCost = function (label, prediction) { - return this.addNodeAndReturnOutput(new MeanSquaredCostNode(this, label, prediction)); - }; - Graph.prototype.argmax = function (x) { - return this.addNodeAndReturnOutput(new ArgMaxNode(this, x)); - }; - Graph.prototype.argmaxEquals = function (x1, x2) { - return this.addNodeAndReturnOutput(new ArgMaxEqualsNode(this, x1, x2)); - }; - Graph.prototype.addNodeAndReturnOutput = function (node) { - this.nodes.push(node); - node.validate(); - return node.output; - }; - Graph.prototype.getNodes = function () { - return this.nodes; - }; - return Graph; -}()); -exports.Graph = Graph; -var SymbolicTensor = (function (_super) { - __extends(SymbolicTensor, _super); - function SymbolicTensor(shape) { - var _this = _super.call(this, [], 'float32') || this; - _this.shape = shape; - _this.id = SymbolicTensor.nextID++; - return _this; - } - SymbolicTensor.nextID = 0; - return SymbolicTensor; -}(tensor_1.Tensor)); -exports.SymbolicTensor = SymbolicTensor; -var Node = (function () { - function Node(graph, name, inputs, output) { - this.graph = graph; - this.name = name; - this.inputs = inputs; - this.output = output; - this.id = Node.nextID++; - output.node = this; - } - Node.nextID = 0; - return Node; -}()); -exports.Node = Node; -var VariableNode = (function (_super) { - __extends(VariableNode, _super); - function VariableNode(graph, name, data) { - var _this = _super.call(this, graph, name, {}, new SymbolicTensor(data.shape)) || this; - _this.data = data; - return _this; - } - VariableNode.prototype.validate = function () { - util.assert(this.data != null, 'Error adding variable op: Data for variable \'' + this.name + - '\' is null or undefined'); - }; - return VariableNode; -}(Node)); -exports.VariableNode = VariableNode; -var PlaceholderNode = (function (_super) { - __extends(PlaceholderNode, _super); - function PlaceholderNode(graph, name, shape) { - return _super.call(this, graph, name, {}, new SymbolicTensor(shape)) || this; - } - PlaceholderNode.prototype.validate = function () { }; - return PlaceholderNode; -}(Node)); -exports.PlaceholderNode = PlaceholderNode; -var ConstantNode = (function (_super) { - __extends(ConstantNode, _super); - function ConstantNode(graph, data) { - var _this = _super.call(this, graph, 'Constant', {}, new SymbolicTensor(data.shape)) || this; - _this.data = data; - return _this; - } - ConstantNode.prototype.validate = function () { - util.assert(this.data != null, 'Error adding constant: data for placeholder \'' + this.name + - '\' is null or undefined'); - }; - return ConstantNode; -}(Node)); -exports.ConstantNode = ConstantNode; -var ReshapeNode = (function (_super) { - __extends(ReshapeNode, _super); - function ReshapeNode(graph, name, x, shape) { - var _this = _super.call(this, graph, name, { x: x }, new SymbolicTensor(shape)) || this; - _this.name = name; - _this.x = x; - _this.shape = shape; - return _this; - } - ReshapeNode.prototype.validate = function () { - var xSize = util.sizeFromShape(this.x.shape); - var shapeSize = util.sizeFromShape(this.shape); - util.assert(xSize === shapeSize, "Error making reshape operation: input to reshape '" + this.name + "'" + - (" of shape (" + this.x.shape + ") does not match size of ") + - ("requested shape " + this.shape + ".")); - }; - ReshapeNode.X = 'x'; - return ReshapeNode; -}(Node)); -exports.ReshapeNode = ReshapeNode; -var FusedLinearCombinationNode = (function (_super) { - __extends(FusedLinearCombinationNode, _super); - function FusedLinearCombinationNode(graph, t1, t2, c1, c2) { - var _this = _super.call(this, graph, 'Linear Combination', { t1: t1, t2: t2, c1: c1, c2: c2 }, new SymbolicTensor(t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - _this.c1 = c1; - _this.c2 = c2; - return _this; - } - FusedLinearCombinationNode.prototype.validate = function () { - util.assertShapesMatch(this.t1.shape, this.t2.shape); - if (!util.isScalarShape(this.c1.shape)) { - throw new Error('Error adding fusedLinearCombination: c1 is not a scalar, got ' + - ("shape: " + this.c1.shape)); - } - if (!util.isScalarShape(this.c2.shape)) { - throw new Error('Error adding fusedLinearCombination: c2 is not a scalar, got ' + - ("shape: " + this.c2.shape)); - } - }; - FusedLinearCombinationNode.T1 = 't1'; - FusedLinearCombinationNode.T2 = 't2'; - FusedLinearCombinationNode.C1 = 'c1'; - FusedLinearCombinationNode.C2 = 'c2'; - return FusedLinearCombinationNode; -}(Node)); -exports.FusedLinearCombinationNode = FusedLinearCombinationNode; -var AddNode = (function (_super) { - __extends(AddNode, _super); - function AddNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Add', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? - t2.shape : - (t1.shape.length < t2.shape.length ? t2.shape : t1.shape))) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - AddNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape) || - (this.t1.shape.length === 2 && this.t2.shape.length === 1 && - this.t1.shape[1] === this.t2.shape[0]) || - (this.t1.shape.length === 1 && this.t2.shape.length === 2 && - this.t1.shape[0] === this.t2.shape[1]), 'Error adding add operation op: one of inputs must be scalar, ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match,") + - 'or one of them can be broadcasted (2D and 1D).'); - }; - AddNode.T1 = 't1'; - AddNode.T2 = 't2'; - return AddNode; -}(Node)); -exports.AddNode = AddNode; -var SubtractNode = (function (_super) { - __extends(SubtractNode, _super); - function SubtractNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Subtract', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? t2.shape : t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - SubtractNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape), 'Error adding subtract op: one of inputs must be scalar or the ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match.")); - }; - SubtractNode.T1 = 't1'; - SubtractNode.T2 = 't2'; - return SubtractNode; -}(Node)); -exports.SubtractNode = SubtractNode; -var MultiplyNode = (function (_super) { - __extends(MultiplyNode, _super); - function MultiplyNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Multiply', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? t2.shape : t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - MultiplyNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape), 'Error adding multiply op: one of inputs must be scalar or the ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match.")); - }; - MultiplyNode.T1 = 't1'; - MultiplyNode.T2 = 't2'; - return MultiplyNode; -}(Node)); -exports.MultiplyNode = MultiplyNode; -var DivideNode = (function (_super) { - __extends(DivideNode, _super); - function DivideNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Divide', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? t2.shape : t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - DivideNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape), 'Error adding divide op: one of inputs must be scalar or the ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match.")); - }; - DivideNode.T1 = 't1'; - DivideNode.T2 = 't2'; - return DivideNode; -}(Node)); -exports.DivideNode = DivideNode; -var ReduceSumNode = (function (_super) { - __extends(ReduceSumNode, _super); - function ReduceSumNode(graph, x) { - return _super.call(this, graph, 'ReduceSum', { x: x }, new SymbolicTensor([])) || this; - } - ReduceSumNode.prototype.validate = function () { }; - ReduceSumNode.X = 'x'; - return ReduceSumNode; -}(Node)); -exports.ReduceSumNode = ReduceSumNode; -var Concat1DNode = (function (_super) { - __extends(Concat1DNode, _super); - function Concat1DNode(graph, x1, x2) { - return _super.call(this, graph, 'Concat1D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape1D(x1.shape, x2.shape))) || this; - } - Concat1DNode.prototype.validate = function () { }; - Concat1DNode.X1 = 'x1'; - Concat1DNode.X2 = 'x2'; - return Concat1DNode; -}(Node)); -exports.Concat1DNode = Concat1DNode; -var Concat2DNode = (function (_super) { - __extends(Concat2DNode, _super); - function Concat2DNode(graph, x1, x2, axis) { - var _this = _super.call(this, graph, 'Concat2D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape(x1.shape, x2.shape, axis))) || this; - _this.x1 = x1; - _this.x2 = x2; - _this.axis = axis; - return _this; - } - Concat2DNode.prototype.validate = function () { - concat_util.assertParams(this.x1.shape, this.x2.shape, this.axis); - }; - Concat2DNode.X1 = 'x1'; - Concat2DNode.X2 = 'x2'; - Concat2DNode.AXIS = 'axis'; - return Concat2DNode; -}(Node)); -exports.Concat2DNode = Concat2DNode; -var Concat3DNode = (function (_super) { - __extends(Concat3DNode, _super); - function Concat3DNode(graph, x1, x2, axis) { - var _this = _super.call(this, graph, 'Concat3D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape(x1.shape, x2.shape, axis))) || this; - _this.x1 = x1; - _this.x2 = x2; - _this.axis = axis; - return _this; - } - Concat3DNode.prototype.validate = function () { - concat_util.assertParams(this.x1.shape, this.x2.shape, this.axis); - }; - Concat3DNode.X1 = 'x1'; - Concat3DNode.X2 = 'x2'; - Concat3DNode.AXIS = 'axis'; - return Concat3DNode; -}(Node)); -exports.Concat3DNode = Concat3DNode; -var Concat4DNode = (function (_super) { - __extends(Concat4DNode, _super); - function Concat4DNode(graph, x1, x2, axis) { - var _this = _super.call(this, graph, 'Concat4D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape(x1.shape, x2.shape, axis))) || this; - _this.x1 = x1; - _this.x2 = x2; - _this.axis = axis; - return _this; - } - Concat4DNode.prototype.validate = function () { - concat_util.assertParams(this.x1.shape, this.x2.shape, this.axis); - }; - Concat4DNode.X1 = 'x1'; - Concat4DNode.X2 = 'x2'; - Concat4DNode.AXIS = 'axis'; - return Concat4DNode; -}(Node)); -exports.Concat4DNode = Concat4DNode; -function getMatMulOutputShape(x1Shape, x2Shape) { - if (x1Shape.length === 1 && x2Shape.length === 1) { - return [1]; - } - else if (x1Shape.length === 1 && x2Shape.length === 2) { - return [x2Shape[1]]; - } - else if (x1Shape.length === 2 && x2Shape.length === 1) { - return [x1Shape[0]]; - } - return [x1Shape[0], x2Shape[1]]; -} -var MatMulNode = (function (_super) { - __extends(MatMulNode, _super); - function MatMulNode(graph, x1, x2) { - var _this = _super.call(this, graph, 'MatMul', { x1: x1, x2: x2 }, new SymbolicTensor(getMatMulOutputShape(x1.shape, x2.shape))) || this; - _this.x1 = x1; - _this.x2 = x2; - return _this; - } - MatMulNode.prototype.validate = function () { - if (this.x1.shape.length === 2 && this.x2.shape.length === 2) { - util.assert(this.x1.shape[1] === this.x2.shape[0], 'Error adding matmul op: inner shapes of matrices with shapes ' + - (this.x1.shape + " and " + this.x2.shape + " must match.")); - } - else if (this.x1.shape.length === 2 && this.x2.shape.length === 1) { - util.assert(this.x1.shape[1] === this.x2.shape[0], 'Error adding matmul op: second dimension of matrix with shape ' + - this.x1.shape.toString() + - (" must match size of vector with shape " + this.x2.shape + ".")); - } - else if (this.x1.shape.length === 1 && this.x2.shape.length === 2) { - util.assert(this.x1.shape[0] === this.x2.shape[0], "Error adding matmul op: size of vector with shape " + this.x1.shape + - " must match first dimension of matrix with " + - ("shape " + this.x2.shape + ".")); - } - else { - throw new Error('Error adding matmul op: inputs must be vectors or matrices.'); - } - }; - MatMulNode.X1 = 'x1'; - MatMulNode.X2 = 'x2'; - return MatMulNode; -}(Node)); -exports.MatMulNode = MatMulNode; -var Convolution2DNode = (function (_super) { - __extends(Convolution2DNode, _super); - function Convolution2DNode(graph, x, w, b, fieldSize, outputDepth, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this, graph, 'Convolution 2D', { x: x, w: w, b: b }, new SymbolicTensor(conv_util.computeOutputShape3D(x.shape, fieldSize, outputDepth, stride, zeroPad))) || this; - _this.x = x; - _this.w = w; - _this.b = b; - _this.fieldSize = fieldSize; - _this.outputDepth = outputDepth; - _this.stride = stride; - _this.zeroPad = zeroPad; - return _this; - } - Convolution2DNode.prototype.validate = function () { - util.assert(this.x.shape.length === 3, 'Error adding conv2d op: input must be of rank 3, but got shape: ' + - (this.x.shape + ".")); - util.assert(this.w.shape.length === 4, 'Error adding conv2d op: weights must be of rank 4, but got shape: ' + - (this.w.shape + ".")); - util.assert(this.b.shape.length === 1, 'Error adding conv2d op: biases must be of rank 1, but got shape: ' + - (this.b.shape + ".")); - util.assert(this.x.shape[2] === this.w.shape[2], "Error adding conv2d op: depth of input (" + this.x.shape[2] + ") " + - ("must match input depth for weights (" + this.w.shape[2] + ").")); - }; - Convolution2DNode.X = 'x'; - Convolution2DNode.W = 'w'; - Convolution2DNode.B = 'b'; - return Convolution2DNode; -}(Node)); -exports.Convolution2DNode = Convolution2DNode; -var MaxPoolNode = (function (_super) { - __extends(MaxPoolNode, _super); - function MaxPoolNode(graph, x, fieldSize, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this, graph, 'Max pool', { x: x }, new SymbolicTensor(conv_util.computeOutputShape3D(x.shape, fieldSize, x.shape[2], stride, zeroPad))) || this; - _this.x = x; - _this.fieldSize = fieldSize; - _this.stride = stride; - _this.zeroPad = zeroPad; - return _this; - } - MaxPoolNode.prototype.validate = function () { - util.assert(this.x.shape.length === 3, 'Error adding maxPool op: input must be of rank 3, but got shape: ' + - (this.x.shape + ".")); - }; - MaxPoolNode.X = 'x'; - return MaxPoolNode; -}(Node)); -exports.MaxPoolNode = MaxPoolNode; -var ReLUNode = (function (_super) { - __extends(ReLUNode, _super); - function ReLUNode(graph, x) { - return _super.call(this, graph, 'ReLU', { x: x }, new SymbolicTensor(x.shape)) || this; - } - ReLUNode.prototype.validate = function () { }; - ReLUNode.X = 'x'; - return ReLUNode; -}(Node)); -exports.ReLUNode = ReLUNode; -var LeakyReLUNode = (function (_super) { - __extends(LeakyReLUNode, _super); - function LeakyReLUNode(graph, x, alpha) { - var _this = _super.call(this, graph, 'LeakyReLU', { x: x }, new SymbolicTensor(x.shape)) || this; - _this.alpha = alpha; - return _this; - } - LeakyReLUNode.prototype.validate = function () { }; - LeakyReLUNode.X = 'x'; - return LeakyReLUNode; -}(Node)); -exports.LeakyReLUNode = LeakyReLUNode; -var PReLUNode = (function (_super) { - __extends(PReLUNode, _super); - function PReLUNode(graph, x, alpha) { - var _this = _super.call(this, graph, 'PReLU', { x: x, alpha: alpha }, new SymbolicTensor(x.shape)) || this; - _this.x = x; - _this.alpha = alpha; - return _this; - } - PReLUNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.x.shape, this.alpha.shape), 'Error adding pRelu op: the ' + - ("shapes x: " + this.x.shape + " and alpha: " + this.alpha.shape + " must match.")); - }; - PReLUNode.X = 'x'; - PReLUNode.ALPHA = 'alpha'; - return PReLUNode; -}(Node)); -exports.PReLUNode = PReLUNode; -var EluNode = (function (_super) { - __extends(EluNode, _super); - function EluNode(graph, x) { - return _super.call(this, graph, 'Elu', { x: x }, new SymbolicTensor(x.shape)) || this; - } - EluNode.prototype.validate = function () { }; - EluNode.X = 'x'; - return EluNode; -}(Node)); -exports.EluNode = EluNode; -var ExpNode = (function (_super) { - __extends(ExpNode, _super); - function ExpNode(graph, x) { - return _super.call(this, graph, 'Exp', { x: x }, new SymbolicTensor(x.shape)) || this; - } - ExpNode.prototype.validate = function () { }; - ExpNode.X = 'x'; - return ExpNode; -}(Node)); -exports.ExpNode = ExpNode; -var LogNode = (function (_super) { - __extends(LogNode, _super); - function LogNode(graph, x) { - return _super.call(this, graph, 'Log', { x: x }, new SymbolicTensor(x.shape)) || this; - } - LogNode.prototype.validate = function () { }; - LogNode.X = 'x'; - return LogNode; -}(Node)); -exports.LogNode = LogNode; -var TanHNode = (function (_super) { - __extends(TanHNode, _super); - function TanHNode(graph, x) { - return _super.call(this, graph, 'TanH', { x: x }, new SymbolicTensor(x.shape)) || this; - } - TanHNode.prototype.validate = function () { }; - TanHNode.X = 'x'; - return TanHNode; -}(Node)); -exports.TanHNode = TanHNode; -var SigmoidNode = (function (_super) { - __extends(SigmoidNode, _super); - function SigmoidNode(graph, x) { - return _super.call(this, graph, 'Sigmoid', { x: x }, new SymbolicTensor(x.shape)) || this; - } - SigmoidNode.prototype.validate = function () { }; - SigmoidNode.X = 'x'; - return SigmoidNode; -}(Node)); -exports.SigmoidNode = SigmoidNode; -var SquareNode = (function (_super) { - __extends(SquareNode, _super); - function SquareNode(graph, x) { - return _super.call(this, graph, 'Square', { x: x }, new SymbolicTensor(x.shape)) || this; - } - SquareNode.prototype.validate = function () { }; - SquareNode.X = 'x'; - return SquareNode; -}(Node)); -exports.SquareNode = SquareNode; -var SoftmaxCrossEntropyCostNode = (function (_super) { - __extends(SoftmaxCrossEntropyCostNode, _super); - function SoftmaxCrossEntropyCostNode(graph, x, target) { - var _this = _super.call(this, graph, 'SoftmaxCrossEntropyCost', { x: x, target: target }, new SymbolicTensor([])) || this; - _this.x = x; - _this.target = target; - return _this; - } - SoftmaxCrossEntropyCostNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.x.shape, this.target.shape), "Error adding softmaxCrossEntropyCost op: x shape (" + this.x.shape + ") " + - ("must match target shape (" + this.target.shape + ").")); - }; - SoftmaxCrossEntropyCostNode.X = 'x'; - SoftmaxCrossEntropyCostNode.TARGET = 'target'; - return SoftmaxCrossEntropyCostNode; -}(Node)); -exports.SoftmaxCrossEntropyCostNode = SoftmaxCrossEntropyCostNode; -var SoftmaxNode = (function (_super) { - __extends(SoftmaxNode, _super); - function SoftmaxNode(graph, x) { - var _this = _super.call(this, graph, 'Softmax', { x: x }, new SymbolicTensor(x.shape)) || this; - _this.x = x; - return _this; - } - SoftmaxNode.prototype.validate = function () { - util.assert(this.x.shape.length === 1, 'The input to a softmax must be a 1-D tensor'); - util.assert(this.x.shape[0] >= 2, 'The input to a softmax must have at least 2 values'); - }; - SoftmaxNode.X = 'x'; - return SoftmaxNode; -}(Node)); -exports.SoftmaxNode = SoftmaxNode; -var MeanSquaredCostNode = (function (_super) { - __extends(MeanSquaredCostNode, _super); - function MeanSquaredCostNode(graph, label, prediction) { - var _this = _super.call(this, graph, 'Mean Squared Cost', { label: label, prediction: prediction }, new SymbolicTensor([])) || this; - _this.label = label; - _this.prediction = prediction; - return _this; - } - MeanSquaredCostNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.label.shape, this.prediction.shape), "Error adding meanSquaredCost op: label shape (" + this.label.shape + ") " + - ("must match prediction shape (" + this.prediction.shape + ").")); - }; - MeanSquaredCostNode.LABEL = 'label'; - MeanSquaredCostNode.PREDICTION = 'prediction'; - return MeanSquaredCostNode; -}(Node)); -exports.MeanSquaredCostNode = MeanSquaredCostNode; -var ArgMaxNode = (function (_super) { - __extends(ArgMaxNode, _super); - function ArgMaxNode(graph, x) { - var _this = _super.call(this, graph, 'ArgMax', { x: x }, new SymbolicTensor([1])) || this; - _this.x = x; - return _this; - } - ArgMaxNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.x.shape) > 0, 'Error adding argmax op: input tensor must have at least one entry.'); - }; - ArgMaxNode.X = 'x'; - return ArgMaxNode; -}(Node)); -exports.ArgMaxNode = ArgMaxNode; -var ArgMaxEqualsNode = (function (_super) { - __extends(ArgMaxEqualsNode, _super); - function ArgMaxEqualsNode(graph, x1, x2) { - var _this = _super.call(this, graph, 'ArgMaxEquals', { x1: x1, x2: x2 }, new SymbolicTensor([1])) || this; - _this.x1 = x1; - _this.x2 = x2; - return _this; - } - ArgMaxEqualsNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.x1.shape, this.x2.shape), "Error adding ArgMaxEquals op: x1 shape (" + this.x1.shape + ") " + - ("must match x2 shape (" + this.x2.shape + ").")); - }; - ArgMaxEqualsNode.X1 = 'x1'; - ArgMaxEqualsNode.X2 = 'x2'; - return ArgMaxEqualsNode; -}(Node)); -exports.ArgMaxEqualsNode = ArgMaxEqualsNode; - -},{"../ops/concat_util":113,"../ops/conv_util":115,"../tensor":146,"../util":151,"./initializers":42}],40:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var session_1 = require("./session"); -var DEFAULT_EVAL_INTERVAL_MS = 1500; -var DEFAULT_COST_INTERVAL_MS = 500; -var DEFAULT_INFERENCE_EXAMPLE_INTERVAL_MS = 3000; -var MetricReduction; -(function (MetricReduction) { - MetricReduction[MetricReduction["SUM"] = 0] = "SUM"; - MetricReduction[MetricReduction["MEAN"] = 1] = "MEAN"; -})(MetricReduction = exports.MetricReduction || (exports.MetricReduction = {})); -var GraphRunner = (function () { - function GraphRunner(math, session, eventObserver) { - this.math = math; - this.session = session; - this.eventObserver = eventObserver; - this.lastCostTimestamp = 0; - this.lastEvalTimestamp = 0; - this.resetStatistics(); - this.zeroScalar = tensor_1.Scalar.new(0); - } - GraphRunner.prototype.resetStatistics = function () { - this.totalBatchesTrained = 0; - }; - GraphRunner.prototype.train = function (costTensor, trainFeedEntries, batchSize, optimizer, numBatches, metricTensor, metricFeedEntries, metricBatchSize, metricReduction, evalIntervalMs, costIntervalMs) { - if (metricReduction === void 0) { metricReduction = MetricReduction.MEAN; } - if (evalIntervalMs === void 0) { evalIntervalMs = DEFAULT_EVAL_INTERVAL_MS; } - if (costIntervalMs === void 0) { costIntervalMs = DEFAULT_COST_INTERVAL_MS; } - this.costTensor = costTensor; - this.trainFeedEntries = trainFeedEntries; - this.metricTensor = metricTensor; - this.metricFeedEntries = metricFeedEntries; - if (metricBatchSize != null && this.metricBatchSize !== metricBatchSize) { - if (this.metricBatchSizeScalar != null) { - this.metricBatchSizeScalar.dispose(); - } - this.metricBatchSizeScalar = tensor_1.Scalar.new(metricBatchSize); - } - this.metricBatchSize = metricBatchSize; - this.metricReduction = metricReduction; - this.batchSize = batchSize; - this.optimizer = optimizer; - this.metricIntervalMs = evalIntervalMs; - this.costIntervalMs = costIntervalMs; - this.currentTrainLoopNumBatches = numBatches; - this.batchesTrainedThisRun = 0; - this.isTraining = true; - this.trainStartTimestamp = performance.now(); - this.trainNetwork(); - }; - GraphRunner.prototype.stopTraining = function () { - this.isTraining = false; - }; - GraphRunner.prototype.resumeTraining = function () { - this.isTraining = true; - this.trainNetwork(); - }; - GraphRunner.prototype.trainNetwork = function () { - var _this = this; - if (this.batchesTrainedThisRun === this.currentTrainLoopNumBatches) { - this.stopTraining(); - } - if (!this.isTraining) { - if (this.eventObserver.doneTrainingCallback != null) { - this.eventObserver.doneTrainingCallback(); - } - return; - } - var start = performance.now(); - var shouldComputeCost = this.eventObserver.avgCostCallback != null && - (start - this.lastCostTimestamp > this.costIntervalMs); - if (shouldComputeCost) { - this.lastCostTimestamp = start; - } - var costReduction = shouldComputeCost ? session_1.CostReduction.MEAN : session_1.CostReduction.NONE; - globals_1.tidy(function () { - var avgCost = _this.session.train(_this.costTensor, _this.trainFeedEntries, _this.batchSize, _this.optimizer, costReduction); - if (shouldComputeCost) { - var trainTime = performance.now() - start; - _this.eventObserver.avgCostCallback(avgCost); - if (_this.eventObserver.trainExamplesPerSecCallback != null) { - var examplesPerSec = (_this.batchSize * 1000 / trainTime); - _this.eventObserver.trainExamplesPerSecCallback(examplesPerSec); - } - } - if (_this.eventObserver.metricCallback != null && - _this.metricFeedEntries != null && - start - _this.lastEvalTimestamp > _this.metricIntervalMs) { - _this.lastEvalTimestamp = start; - if (_this.lastComputedMetric != null) { - _this.lastComputedMetric.dispose(); - } - _this.lastComputedMetric = _this.computeMetric(); - _this.eventObserver.metricCallback(_this.lastComputedMetric); - } - if (_this.eventObserver.totalTimeCallback != null) { - _this.eventObserver.totalTimeCallback((start - _this.trainStartTimestamp) / 1000); - } - _this.batchesTrainedThisRun++; - _this.totalBatchesTrained++; - if (_this.eventObserver.batchesTrainedCallback != null) { - _this.eventObserver.batchesTrainedCallback(_this.totalBatchesTrained); - } - }); - requestAnimationFrame(function () { return _this.trainNetwork(); }); - }; - GraphRunner.prototype.infer = function (inferenceTensor, inferenceFeedEntries, inferenceExampleIntervalMs, inferenceExampleCount, numPasses) { - var _this = this; - if (inferenceExampleIntervalMs === void 0) { inferenceExampleIntervalMs = DEFAULT_INFERENCE_EXAMPLE_INTERVAL_MS; } - if (inferenceExampleCount === void 0) { inferenceExampleCount = 5; } - if (this.eventObserver.inferenceExamplesCallback == null && - this.eventObserver.inferenceExamplesPerSecCallback == null) { - throw new Error('Cannot start inference loop, no inference example or ' + - 'examples/sec observer provided.'); - } - for (var i = 0; i < inferenceFeedEntries.length; i++) { - var feedEntry = inferenceFeedEntries[i]; - if (feedEntry.data instanceof tensor_1.Tensor) { - throw new Error('Cannot start inference on the model runner with feed entries of ' + - 'type NDArray. Please use InputProviders.'); - } - } - this.inferenceExampleIntervalMs = inferenceExampleIntervalMs; - this.inferenceTensor = inferenceTensor; - this.inferenceFeedEntries = inferenceFeedEntries; - this.inferenceExampleCount = inferenceExampleCount; - this.currentInferenceLoopNumPasses = numPasses; - if (!this.isInferring) { - this.inferencePassesThisRun = 0; - requestAnimationFrame(function () { return _this.inferNetwork(); }); - } - this.isInferring = true; - }; - GraphRunner.prototype.inferNetwork = function () { - var _this = this; - if (!this.isInferring || - this.inferencePassesThisRun === this.currentInferenceLoopNumPasses) { - return; - } - globals_1.tidy(function () { - var feeds = []; - var inferenceValues = []; - var start = performance.now(); - for (var i = 0; i < _this.inferenceExampleCount; i++) { - var ndarrayFeedEntries = []; - for (var j = 0; j < _this.inferenceFeedEntries.length; j++) { - var feedEntry = _this.inferenceFeedEntries[j]; - var nextCopy = feedEntry.data.getNextCopy(); - ndarrayFeedEntries.push({ tensor: feedEntry.tensor, data: nextCopy }); - } - feeds.push(ndarrayFeedEntries); - inferenceValues.push(_this.session.eval(_this.inferenceTensor, ndarrayFeedEntries)); - } - if (_this.eventObserver.inferenceExamplesPerSecCallback != null) { - inferenceValues[inferenceValues.length - 1].dataSync(); - var inferenceExamplesPerSecTime = performance.now() - start; - var examplesPerSec = (_this.inferenceExampleCount * 1000 / inferenceExamplesPerSecTime); - _this.eventObserver.inferenceExamplesPerSecCallback(examplesPerSec); - } - if (_this.eventObserver.inferenceExamplesCallback != null) { - _this.eventObserver.inferenceExamplesCallback(feeds, inferenceValues); - } - _this.inferencePassesThisRun++; - }); - this.lastInferTimeoutID = window.setTimeout(function () { return _this.inferNetwork(); }, this.inferenceExampleIntervalMs); - }; - GraphRunner.prototype.stopInferring = function () { - this.isInferring = false; - window.clearTimeout(this.lastInferTimeoutID); - }; - GraphRunner.prototype.isInferenceRunning = function () { - return this.isInferring; - }; - GraphRunner.prototype.computeMetric = function () { - var _this = this; - if (this.metricFeedEntries == null) { - throw new Error('Cannot compute metric, no metric FeedEntries provided.'); - } - var metric = this.zeroScalar; - return globals_1.tidy(function () { - for (var i = 0; i < _this.metricBatchSize; i++) { - var metricValue = _this.session.eval(_this.metricTensor, _this.metricFeedEntries); - metric = _this.math.add(metric, metricValue.toFloat()); - } - if (_this.metricReduction === MetricReduction.MEAN) { - metric = _this.math.divide(metric, _this.metricBatchSizeScalar); - } - return metric; - }); - }; - GraphRunner.prototype.getTotalBatchesTrained = function () { - return this.totalBatchesTrained; - }; - GraphRunner.prototype.getLastComputedMetric = function () { - return this.lastComputedMetric; - }; - GraphRunner.prototype.setMath = function (math) { - this.math = math; - }; - GraphRunner.prototype.setSession = function (session) { - this.session = session; - }; - GraphRunner.prototype.setInferenceTensor = function (inferenceTensor) { - this.inferenceTensor = inferenceTensor; - }; - GraphRunner.prototype.setInferenceExampleCount = function (inferenceExampleCount) { - this.inferenceExampleCount = inferenceExampleCount; - }; - return GraphRunner; -}()); -exports.GraphRunner = GraphRunner; - -},{"../globals":35,"../tensor":146,"./session":64}],41:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var graph_1 = require("./graph"); -var priority_queue = require("./priority_queue"); -var priority_queue_1 = require("./priority_queue"); -function getUnorderedEvaluationSet(nodes, terminatingNodes) { - var terminatingNodeMap = {}; - var seen = {}; - var set = []; - var visit = nodes.slice(); - terminatingNodes.forEach(function (node) { return terminatingNodeMap[node.id] = node; }); - var _loop_1 = function () { - var cur = visit.pop(); - if (seen[cur.id] == null) { - if (terminatingNodeMap[cur.id] == null) { - Object.keys(cur.inputs) - .map(function (inputName) { return cur.inputs[inputName]; }) - .forEach(function (input) { return visit.push(input.node); }); - } - set.push(cur); - seen[cur.id] = cur; - } - }; - while (visit.length !== 0) { - _loop_1(); - } - return set; -} -exports.getUnorderedEvaluationSet = getUnorderedEvaluationSet; -function getOrderedEvaluationSet(unorderedEvaluationSet) { - var set = []; - var nodeIndices = {}; - var pendingDependencies = {}; - var nodeQueue = new priority_queue_1.PriorityQueue(function (a, b) { return priority_queue.defaultCompare(pendingDependencies[a.id], pendingDependencies[b.id]); }, function (node, newIndex) { return nodeIndices[node.id] = newIndex; }); - unorderedEvaluationSet.forEach(function (node) { return pendingDependencies[node.id] = 0; }); - unorderedEvaluationSet.forEach(function (node) { return Object.keys(node.inputs) - .map(function (key) { return node.inputs[key]; }) - .forEach(function (input) { - if (unorderedEvaluationSet.indexOf(input.node) !== -1) { - pendingDependencies[input.node.id]++; - } - }); }); - unorderedEvaluationSet.forEach(function (node) { return nodeQueue.enqueue(node); }); - while (!nodeQueue.empty()) { - set.unshift(nodeQueue.dequeue()); - Object.keys(set[0].inputs).map(function (key) { return set[0].inputs[key]; }).forEach(function (input) { - if (unorderedEvaluationSet.indexOf(input.node) === -1) { - return; - } - pendingDependencies[input.node.id]--; - nodeQueue.update(input.node, nodeIndices[input.node.id]); - }); - } - return set; -} -exports.getOrderedEvaluationSet = getOrderedEvaluationSet; -function isInputNode(node) { - return Object.keys(node.inputs).length === 0; -} -exports.isInputNode = isInputNode; -function shouldBackProp(t) { - return !(t.node instanceof graph_1.ConstantNode); -} -exports.shouldBackProp = shouldBackProp; -function isPassthroughNode(node, map) { - var keys = Object.keys(node.inputs); - for (var i = 0; i < keys.length; i++) { - var input = node.inputs[keys[i]]; - if (map.get(input, true) === map.get(node.output, true)) { - return true; - } - } - return false; -} -exports.isPassthroughNode = isPassthroughNode; - -},{"./graph":39,"./priority_queue":63}],42:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ops = require("../ops/ops"); -var VarianceScalingInitializer = (function () { - function VarianceScalingInitializer(scale, mode, distribution) { - if (scale === void 0) { scale = 1.0; } - if (mode === void 0) { mode = 'fan_in'; } - if (distribution === void 0) { distribution = 'normal'; } - this.scale = scale; - this.mode = mode; - this.distribution = distribution; - } - VarianceScalingInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - var n = 0; - if (this.mode === 'fan_in') { - n = inputUnits; - } - else if (this.mode === 'fan_out') { - n = outputUnits; - } - else if (this.mode === 'fan_avg') { - n = (inputUnits + outputUnits) / 2; - } - else { - throw new Error("Unexpected mode for variance scaling initializer: " + this.mode); - } - if (this.distribution === 'normal') { - return ops.truncatedNormal(weightsShape, 0.0, Math.sqrt(this.scale / n)); - } - else if (this.distribution === 'uniform') { - return ops.randomUniform(weightsShape, 0.0, Math.sqrt(3 * this.scale / n)); - } - else { - throw new Error("Unexpected distribution for variance scaling initializer: " + - ("" + this.distribution)); - } - }; - return VarianceScalingInitializer; -}()); -exports.VarianceScalingInitializer = VarianceScalingInitializer; -var ZerosInitializer = (function () { - function ZerosInitializer() { - } - ZerosInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.zeros(weightsShape); - }; - return ZerosInitializer; -}()); -exports.ZerosInitializer = ZerosInitializer; -var OnesInitializer = (function () { - function OnesInitializer() { - } - OnesInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.ones(weightsShape); - }; - return OnesInitializer; -}()); -exports.OnesInitializer = OnesInitializer; -var ConstantInitializer = (function () { - function ConstantInitializer(value) { - if (value === void 0) { value = 0; } - this.value = value; - } - ConstantInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.fill(weightsShape, this.value); - }; - return ConstantInitializer; -}()); -exports.ConstantInitializer = ConstantInitializer; -var TensorInitializer = (function () { - function TensorInitializer(tensor) { - this.tensor = tensor; - } - TensorInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return this.tensor; - }; - return TensorInitializer; -}()); -exports.TensorInitializer = TensorInitializer; -var RandomNormalInitializer = (function () { - function RandomNormalInitializer(mean, stdev) { - if (mean === void 0) { mean = 0; } - if (stdev === void 0) { stdev = .05; } - this.mean = mean; - this.stdev = stdev; - } - RandomNormalInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.randomNormal(weightsShape, this.mean, this.stdev); - }; - return RandomNormalInitializer; -}()); -exports.RandomNormalInitializer = RandomNormalInitializer; -var RandomTruncatedNormalInitializer = (function () { - function RandomTruncatedNormalInitializer(mean, stdev) { - if (mean === void 0) { mean = 0; } - if (stdev === void 0) { stdev = .05; } - this.mean = mean; - this.stdev = stdev; - } - RandomTruncatedNormalInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.truncatedNormal(weightsShape, this.mean, this.stdev); - }; - return RandomTruncatedNormalInitializer; -}()); -exports.RandomTruncatedNormalInitializer = RandomTruncatedNormalInitializer; -var RandomUniformInitializer = (function () { - function RandomUniformInitializer(minval, maxval) { - if (minval === void 0) { minval = -.05; } - if (maxval === void 0) { maxval = .05; } - this.minval = minval; - this.maxval = maxval; - } - RandomUniformInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.randomUniform(weightsShape, this.minval, this.maxval); - }; - return RandomUniformInitializer; -}()); -exports.RandomUniformInitializer = RandomUniformInitializer; - -},{"../ops/ops":123}],43:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var graph_1 = require("./graph"); -var graph_util = require("./graph_util"); -var add_1 = require("./ops/add"); -var argmax_1 = require("./ops/argmax"); -var argmaxequals_1 = require("./ops/argmaxequals"); -var concat_1 = require("./ops/concat"); -var convolution_1 = require("./ops/convolution"); -var divide_1 = require("./ops/divide"); -var element_wise_activation_1 = require("./ops/element_wise_activation"); -var element_wise_cost_1 = require("./ops/element_wise_cost"); -var exp_1 = require("./ops/exp"); -var linear_combination_1 = require("./ops/linear_combination"); -var log_1 = require("./ops/log"); -var matmul_1 = require("./ops/matmul"); -var max_pool_1 = require("./ops/max_pool"); -var multiply_1 = require("./ops/multiply"); -var reduce_sum_1 = require("./ops/reduce_sum"); -var reshape_1 = require("./ops/reshape"); -var softmax_1 = require("./ops/softmax"); -var subtract_1 = require("./ops/subtract"); -function emitFromGraphNodes(nodes) { - var ops = []; - nodes.forEach(function (node) { return Array.prototype.push.apply(ops, emitOpFromNode(node)); }); - return ops; -} -exports.emitFromGraphNodes = emitFromGraphNodes; -function emitOpFromNode(node) { - if (node instanceof graph_1.ReshapeNode) { - return [new reshape_1.Reshape(node.inputs[graph_1.ReshapeNode.X], node.output)]; - } - else if (node instanceof graph_1.MatMulNode) { - var x1 = node.inputs[graph_1.MatMulNode.X1]; - var x2 = node.inputs[graph_1.MatMulNode.X2]; - return [new matmul_1.MatMul(x1, x2, node.output)]; - } - else if (node instanceof graph_1.Convolution2DNode) { - var w = node.inputs[graph_1.Convolution2DNode.W]; - var x = node.inputs[graph_1.Convolution2DNode.X]; - var b = node.inputs[graph_1.Convolution2DNode.B]; - return [new convolution_1.Convolution2D(w, x, b, node.output, node.fieldSize, node.outputDepth, node.stride, node.zeroPad)]; - } - else if (node instanceof graph_1.MaxPoolNode) { - var x = node.inputs[graph_1.MaxPoolNode.X]; - return [new max_pool_1.MaxPool(x, node.output, node.fieldSize, node.stride, node.zeroPad)]; - } - else if (node instanceof graph_1.ExpNode) { - return [new exp_1.Exp(node.inputs[graph_1.ExpNode.X], node.output)]; - } - else if (node instanceof graph_1.LogNode) { - return [new log_1.Log(node.inputs[graph_1.LogNode.X], node.output)]; - } - else if (node instanceof graph_1.ReLUNode) { - return [new element_wise_activation_1.ReLU(node.inputs[graph_1.ReLUNode.X], node.output)]; - } - else if (node instanceof graph_1.LeakyReLUNode) { - return [new element_wise_activation_1.LeakyReLU(node.inputs[graph_1.LeakyReLUNode.X], node.output, node.alpha)]; - } - else if (node instanceof graph_1.PReLUNode) { - return [new element_wise_activation_1.PReLU(node.inputs[graph_1.PReLUNode.X], node.inputs[graph_1.PReLUNode.ALPHA], node.output)]; - } - else if (node instanceof graph_1.EluNode) { - return [new element_wise_activation_1.Elu(node.inputs[graph_1.EluNode.X], node.output)]; - } - else if (node instanceof graph_1.TanHNode) { - return [new element_wise_activation_1.TanH(node.inputs[graph_1.TanHNode.X], node.output)]; - } - else if (node instanceof graph_1.SigmoidNode) { - return [new element_wise_activation_1.Sigmoid(node.inputs[graph_1.SigmoidNode.X], node.output)]; - } - else if (node instanceof graph_1.SoftmaxCrossEntropyCostNode) { - var x = node.inputs[graph_1.SoftmaxCrossEntropyCostNode.X]; - var target = node.inputs[graph_1.SoftmaxCrossEntropyCostNode.TARGET]; - return [new softmax_1.SoftmaxCrossEntropyCost(x, target, node.output)]; - } - else if (node instanceof graph_1.SoftmaxNode) { - return [new softmax_1.Softmax(node.inputs[graph_1.SoftmaxNode.X], node.output)]; - } - else if (node instanceof graph_1.MeanSquaredCostNode) { - var label = node.inputs[graph_1.MeanSquaredCostNode.LABEL]; - var prediction = node.inputs[graph_1.MeanSquaredCostNode.PREDICTION]; - return [new element_wise_cost_1.MeanSquaredCost(label, prediction, node.output)]; - } - else if (node instanceof graph_1.ArgMaxEqualsNode) { - return [new argmaxequals_1.ArgMaxEquals(node.inputs[graph_1.ArgMaxEqualsNode.X1], node.inputs[graph_1.ArgMaxEqualsNode.X2], node.output)]; - } - else if (node instanceof graph_1.ArgMaxNode) { - return [new argmax_1.ArgMax(node.x, node.output)]; - } - else if (node instanceof graph_1.FusedLinearCombinationNode) { - return [new linear_combination_1.LinearCombination(node.inputs[graph_1.FusedLinearCombinationNode.T1], node.inputs[graph_1.FusedLinearCombinationNode.T2], node.inputs[graph_1.FusedLinearCombinationNode.C1], node.inputs[graph_1.FusedLinearCombinationNode.C2], node.output)]; - } - else if (node instanceof graph_1.Concat1DNode) { - return [new concat_1.Concat1D(node.inputs[graph_1.Concat1DNode.X1], node.inputs[graph_1.Concat1DNode.X2], node.output)]; - } - else if (node instanceof graph_1.Concat2DNode) { - return [new concat_1.Concat2D(node.inputs[graph_1.Concat2DNode.X1], node.inputs[graph_1.Concat2DNode.X2], node.axis, node.output)]; - } - else if (node instanceof graph_1.Concat3DNode) { - return [new concat_1.Concat3D(node.inputs[graph_1.Concat3DNode.X1], node.inputs[graph_1.Concat3DNode.X2], node.axis, node.output)]; - } - else if (node instanceof graph_1.Concat4DNode) { - return [new concat_1.Concat4D(node.inputs[graph_1.Concat4DNode.X1], node.inputs[graph_1.Concat4DNode.X2], node.axis, node.output)]; - } - else if (node instanceof graph_1.SquareNode) { - return [new element_wise_activation_1.Square(node.inputs[graph_1.SquareNode.X], node.output)]; - } - else if (node instanceof graph_1.AddNode) { - return [new add_1.Add(node.inputs[graph_1.AddNode.T1], node.inputs[graph_1.AddNode.T2], node.output)]; - } - else if (node instanceof graph_1.SubtractNode) { - return [new subtract_1.Subtract(node.inputs[graph_1.SubtractNode.T1], node.inputs[graph_1.SubtractNode.T2], node.output)]; - } - else if (node instanceof graph_1.MultiplyNode) { - return [new multiply_1.Multiply(node.inputs[graph_1.MultiplyNode.T1], node.inputs[graph_1.MultiplyNode.T2], node.output)]; - } - else if (node instanceof graph_1.DivideNode) { - return [new divide_1.Divide(node.inputs[graph_1.DivideNode.T1], node.inputs[graph_1.DivideNode.T2], node.output)]; - } - else if (node instanceof graph_1.ReduceSumNode) { - return [new reduce_sum_1.ReduceSum(node.inputs[graph_1.ReduceSumNode.X], node.output)]; - } - else if (graph_util.isInputNode(node)) { - return []; - } - else { - throw Error("Unsupported node type: " + node.constructor.name); - } -} - -},{"./graph":39,"./graph_util":41,"./ops/add":44,"./ops/argmax":45,"./ops/argmaxequals":46,"./ops/concat":47,"./ops/convolution":48,"./ops/divide":49,"./ops/element_wise_activation":50,"./ops/element_wise_cost":51,"./ops/exp":52,"./ops/linear_combination":53,"./ops/log":54,"./ops/matmul":55,"./ops/max_pool":56,"./ops/multiply":57,"./ops/reduce_sum":59,"./ops/reshape":60,"./ops/softmax":61,"./ops/subtract":62}],44:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Add = (function (_super) { - __extends(Add, _super); - function Add(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - util.assert(util.sizeFromShape(x1Tensor.shape) === 1 || - util.sizeFromShape(x2Tensor.shape) === 1 || - util.arraysEqual(x1Tensor.shape, x2Tensor.shape) || - (x1Tensor.shape.length === 2 && x2Tensor.shape.length === 1 && - x1Tensor.shape[1] === x2Tensor.shape[0]) || - (x1Tensor.shape.length === 1 && x2Tensor.shape.length === 2 && - x1Tensor.shape[0] === x2Tensor.shape[1]), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape, ' + - 'or one of them can be broadcasted (2D and 1D).'); - return _this; - } - Add.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(x1.shape)) { - result = math.scalarPlusArray(x1, x2); - } - else if (util.isScalarShape(x2.shape)) { - result = math.scalarPlusArray(x2, x1); - } - else { - result = math.add(x1, x2); - } - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - Add.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - if (_this.x1Tensor.shape.length === 1 && - _this.x2Tensor.shape.length === 2 && - _this.x1Tensor.shape[0] === _this.x2Tensor.shape[1]) { - var sum = math.sum(dy, 0); - gradientArrays.add(_this.x1Tensor, sum); - } - else if (util.isScalarShape(_this.x1Tensor.shape)) { - var sum = math.sum(dy); - gradientArrays.add(_this.x1Tensor, sum); - } - else { - gradientArrays.add(_this.x1Tensor, math.clone(dy)); - } - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - if (_this.x1Tensor.shape.length === 2 && - _this.x2Tensor.shape.length === 1 && - _this.x1Tensor.shape[1] === _this.x2Tensor.shape[0]) { - var sum = math.sum(dy, 0); - gradientArrays.add(_this.x2Tensor, sum); - } - else if (util.isScalarShape(_this.x2Tensor.shape)) { - var sum = math.sum(dy); - gradientArrays.add(_this.x2Tensor, sum); - } - else { - gradientArrays.add(_this.x2Tensor, math.clone(dy)); - } - } - }); - }; - Add.prototype.dispose = function () { - if (this.dySizeScalar != null) { - this.dySizeScalar.dispose(); - } - }; - return Add; -}(op_1.Operation)); -exports.Add = Add; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],45:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var op_1 = require("./op"); -var ArgMax = (function (_super) { - __extends(ArgMax, _super); - function ArgMax(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - return _this; - } - ArgMax.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.argMax(x))); - }); - }; - ArgMax.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - throw new Error('ArgMax backprop unimplemented'); - }; - return ArgMax; -}(op_1.Operation)); -exports.ArgMax = ArgMax; - -},{"../../globals":35,"./op":58}],46:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var op_1 = require("./op"); -var ArgMaxEquals = (function (_super) { - __extends(ArgMaxEquals, _super); - function ArgMaxEquals(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - return _this; - } - ArgMaxEquals.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.argMaxEquals(x1, x2))); - }); - }; - ArgMaxEquals.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - throw new Error('ArgMaxEquals backprop unimplemented'); - }; - return ArgMaxEquals; -}(op_1.Operation)); -exports.ArgMaxEquals = ArgMaxEquals; - -},{"../../globals":35,"./op":58}],47:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var concat_util = require("../../ops/concat_util"); -var util = require("../../util"); -var op_1 = require("./op"); -var Concat1D = (function (_super) { - __extends(Concat1D, _super); - function Concat1D(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - return _this; - } - Concat1D.prototype.feedForward = function (math, inferecenArrays) { - var _this = this; - var x1 = inferecenArrays.get(this.x1Tensor); - var x2 = inferecenArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat1D(x1, x2); - inferecenArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat1D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, 0, gradientArrays, inferenceArrays); - }); - }; - return Concat1D; -}(op_1.Operation)); -exports.Concat1D = Concat1D; -var Concat2D = (function (_super) { - __extends(Concat2D, _super); - function Concat2D(x1Tensor, x2Tensor, axis, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.axis = axis; - _this.yTensor = yTensor; - concat_util.assertParams(x1Tensor.shape, x2Tensor.shape, axis); - return _this; - } - Concat2D.prototype.feedForward = function (math, inferecenArrays) { - var _this = this; - var x1 = inferecenArrays.get(this.x1Tensor); - var x2 = inferecenArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat2D(x1, x2, _this.axis); - inferecenArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat2D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, _this.axis, gradientArrays, inferenceArrays); - }); - }; - return Concat2D; -}(op_1.Operation)); -exports.Concat2D = Concat2D; -var Concat3D = (function (_super) { - __extends(Concat3D, _super); - function Concat3D(x1Tensor, x2Tensor, axis, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.axis = axis; - _this.yTensor = yTensor; - concat_util.assertParams(x1Tensor.shape, x2Tensor.shape, axis); - return _this; - } - Concat3D.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat3D(x1, x2, _this.axis); - inferenceArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat3D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, _this.axis, gradientArrays, inferenceArrays); - }); - }; - return Concat3D; -}(op_1.Operation)); -exports.Concat3D = Concat3D; -var Concat4D = (function (_super) { - __extends(Concat4D, _super); - function Concat4D(x1Tensor, x2Tensor, axis, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.axis = axis; - _this.yTensor = yTensor; - concat_util.assertParams(x1Tensor.shape, x2Tensor.shape, axis); - return _this; - } - Concat4D.prototype.feedForward = function (math, inferecenArrays) { - var _this = this; - var x1 = inferecenArrays.get(this.x1Tensor); - var x2 = inferecenArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat4D(x1, x2, _this.axis); - inferecenArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat4D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, _this.axis, gradientArrays, inferenceArrays); - }); - }; - return Concat4D; -}(op_1.Operation)); -exports.Concat4D = Concat4D; -function concatBackProp(math, aTensor, bTensor, yTensor, axis, gradArrays, infArrays) { - var dy = gradArrays.get(yTensor); - var a = infArrays.get(aTensor); - var b = infArrays.get(bTensor); - var a2D = a.as2D(-1, util.sizeFromShape(a.shape.slice(axis))); - var b2D = b.as2D(-1, util.sizeFromShape(b.shape.slice(axis))); - var _a = concat_util.computeGradientSliceShapes(a2D.shape, b2D.shape), aBegin = _a.aBegin, aSize = _a.aSize, bBegin = _a.bBegin, bSize = _a.bSize; - var dy2D = dy.as2D(-1, a2D.shape[1] + b2D.shape[1]); - var slice1Result = math.slice2D(dy2D, aBegin, aSize).reshapeAs(a); - var slice2Result = math.slice2D(dy2D, bBegin, bSize).reshapeAs(b); - gradArrays.add(aTensor, slice1Result); - gradArrays.add(bTensor, slice2Result); -} - -},{"../../globals":35,"../../ops/concat_util":113,"../../util":151,"./op":58}],48:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var conv_util = require("../../ops/conv_util"); -var util = require("../../util"); -var op_1 = require("./op"); -var Convolution2D = (function (_super) { - __extends(Convolution2D, _super); - function Convolution2D(wTensor, xTensor, bTensor, yTensor, fieldSize, outputDepth, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this) || this; - _this.wTensor = wTensor; - _this.xTensor = xTensor; - _this.bTensor = bTensor; - _this.yTensor = yTensor; - _this.fieldSize = fieldSize; - _this.outputDepth = outputDepth; - _this.stride = stride; - _this.assertWeightsShape(wTensor.shape); - _this.zeroPad = zeroPad != null ? - zeroPad : - conv_util.computeDefaultPad(_this.xTensor.shape, _this.fieldSize, _this.stride); - util.assert(util.isInt(_this.zeroPad), "The zero padding (" + _this.zeroPad + ") must be an integer. Change the " + - "stride and/or zero pad parameters"); - return _this; - } - Convolution2D.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var weights = inferenceArrays.get(this.wTensor); - var biases = inferenceArrays.get(this.bTensor); - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.conv2d(x, weights, biases, _this.stride, _this.zeroPad))); - }); - }; - Convolution2D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var filter = inferenceArrays.get(this.wTensor); - var x = inferenceArrays.get(this.xTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - var dw = math.conv2dDerFilter(x, dy, filter.shape, _this.stride, _this.zeroPad); - var db = math.sum(dy, [0, 1]); - var dx = math.conv2dDerInput(x.shape, dy, filter, _this.stride, _this.zeroPad); - gradientArrays.add(_this.wTensor, dw); - gradientArrays.add(_this.bTensor, db); - gradientArrays.add(_this.xTensor, dx); - }); - }; - Convolution2D.prototype.assertWeightsShape = function (weightsShape) { - util.assert(weightsShape[0] === this.fieldSize && - weightsShape[1] === this.fieldSize && - weightsShape[2] === this.xTensor.shape[2] && - weightsShape[3] === this.outputDepth, "weights must be of shape [" + this.fieldSize + "," + this.fieldSize + "," + - (this.xTensor.shape[2] + "," + this.outputDepth + "] but they are of") + - ("shape [" + weightsShape + "]")); - }; - return Convolution2D; -}(op_1.Operation)); -exports.Convolution2D = Convolution2D; - -},{"../../globals":35,"../../ops/conv_util":115,"../../util":151,"./op":58}],49:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Divide = (function (_super) { - __extends(Divide, _super); - function Divide(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - util.assert(util.sizeFromShape(x1Tensor.shape) === 1 || - util.sizeFromShape(x2Tensor.shape) === 1 || - util.arraysEqual(x1Tensor.shape, x2Tensor.shape), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape'); - return _this; - } - Divide.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var t1 = inferenceArrays.get(this.x1Tensor); - var t2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(t1.shape)) { - result = math.scalarDividedByArray(t1, t2); - } - else if (util.isScalarShape(t2.shape)) { - result = math.arrayDividedByScalar(t1, t2); - } - else { - result = math.divide(t1, t2); - } - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - Divide.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var dy = gradientArrays.get(this.yTensor); - var x1IsScalar = util.isScalarShape(x1.shape); - var x2IsScalar = util.isScalarShape(x2.shape); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - if (x1IsScalar) { - var div = math.divide(dy, x2); - gradientArrays.add(_this.x1Tensor, math.sum(div)); - div.dispose(); - } - else if (x2IsScalar) { - gradientArrays.add(_this.x1Tensor, math.arrayDividedByScalar(dy, x2)); - } - else { - gradientArrays.add(_this.x1Tensor, math.divide(dy, x2)); - } - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - var x2Squared = math.elementWiseMul(x2, x2); - var x1OverX2Squared = void 0; - if (x2IsScalar) { - x1OverX2Squared = math.arrayDividedByScalar(x1, x2Squared); - } - else if (x1IsScalar) { - x1OverX2Squared = math.scalarDividedByArray(x1, x2Squared); - } - else { - x1OverX2Squared = math.divide(x1, x2Squared); - } - var dx2 = math.neg(x1OverX2Squared); - var dyTimesDerivative = math.elementWiseMul(dy, dx2); - if (x2IsScalar) { - gradientArrays.add(_this.x2Tensor, math.sum(dyTimesDerivative)); - } - else { - gradientArrays.add(_this.x2Tensor, dyTimesDerivative); - } - } - }); - }; - return Divide; -}(op_1.Operation)); -exports.Divide = Divide; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],50:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var activation_functions_1 = require("../activation_functions"); -var op_1 = require("./op"); -var ElementWiseActivation = (function (_super) { - __extends(ElementWiseActivation, _super); - function ElementWiseActivation(xTensor, yTensor, func) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - _this.func = func; - return _this; - } - ElementWiseActivation.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(_this.func.output(math, x))); - }); - }; - ElementWiseActivation.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var y = inferenceArrays.get(this.yTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - var dydx = _this.func.der(math, x, y); - gradientArrays.add(_this.xTensor, math.elementWiseMul(dy, dydx)); - dydx.dispose(); - }); - }; - ElementWiseActivation.prototype.dispose = function () { - this.func.dispose(); - }; - return ElementWiseActivation; -}(op_1.Operation)); -exports.ElementWiseActivation = ElementWiseActivation; -var ReLU = (function (_super) { - __extends(ReLU, _super); - function ReLU(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.ReLUFunc()) || this; - } - return ReLU; -}(ElementWiseActivation)); -exports.ReLU = ReLU; -var LeakyReLU = (function (_super) { - __extends(LeakyReLU, _super); - function LeakyReLU(xTensor, yTensor, alpha) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.LeakyReluFunc(alpha)) || this; - } - return LeakyReLU; -}(ElementWiseActivation)); -exports.LeakyReLU = LeakyReLU; -var TanH = (function (_super) { - __extends(TanH, _super); - function TanH(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.TanHFunc()) || this; - } - return TanH; -}(ElementWiseActivation)); -exports.TanH = TanH; -var Sigmoid = (function (_super) { - __extends(Sigmoid, _super); - function Sigmoid(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.SigmoidFunc()) || this; - } - return Sigmoid; -}(ElementWiseActivation)); -exports.Sigmoid = Sigmoid; -var Square = (function (_super) { - __extends(Square, _super); - function Square(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.SquareFunc()) || this; - } - return Square; -}(ElementWiseActivation)); -exports.Square = Square; -var Elu = (function (_super) { - __extends(Elu, _super); - function Elu(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.EluFunc()) || this; - } - return Elu; -}(ElementWiseActivation)); -exports.Elu = Elu; -var PReLU = (function (_super) { - __extends(PReLU, _super); - function PReLU(xTensor, alphaTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.alphaTensor = alphaTensor; - _this.yTensor = yTensor; - return _this; - } - PReLU.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var alpha = inferenceArrays.get(this.alphaTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.prelu(x, alpha))); - }); - }; - PReLU.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - throw new Error('Not implemented'); - }; - return PReLU; -}(op_1.Operation)); -exports.PReLU = PReLU; - -},{"../../globals":35,"../activation_functions":37,"./op":58}],51:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var globals_1 = require("../../globals"); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var cost_functions_1 = require("../cost_functions"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var ElementWiseCost = (function (_super) { - __extends(ElementWiseCost, _super); - function ElementWiseCost(x1Tensor, x2Tensor, yTensor, func) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - _this.func = func; - _this.oneOverNScalar = - environment_1.ENV.math.keep(tensor_1.Scalar.new(1 / util.sizeFromShape(x1Tensor.shape))); - return _this; - } - ElementWiseCost.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var elementWiseCost = _this.func.cost(x1, x2); - var sum = math.sum(elementWiseCost); - var result = math.scalarTimesArray(_this.oneOverNScalar, sum); - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - ElementWiseCost.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - gradientArrays.add(_this.x1Tensor, _this.func.der(x1, x2)); - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - gradientArrays.add(_this.x2Tensor, _this.func.der(x2, x1)); - } - }); - }; - ElementWiseCost.prototype.dispose = function () { - this.func.dispose(); - this.oneOverNScalar.dispose(); - }; - return ElementWiseCost; -}(op_1.Operation)); -exports.ElementWiseCost = ElementWiseCost; -var MeanSquaredCost = (function (_super) { - __extends(MeanSquaredCost, _super); - function MeanSquaredCost(x1Tensor, x2Tensor, yTensor) { - return _super.call(this, x1Tensor, x2Tensor, yTensor, new cost_functions_1.SquareCostFunc()) || this; - } - return MeanSquaredCost; -}(ElementWiseCost)); -exports.MeanSquaredCost = MeanSquaredCost; - -},{"../../environment":34,"../../globals":35,"../../tensor":146,"../../util":151,"../cost_functions":38,"../graph_util":41,"./op":58}],52:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Exp = (function (_super) { - __extends(Exp, _super); - function Exp(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - return _this; - } - Exp.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.exp(x))); - }); - }; - Exp.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var y = inferenceArrays.get(this.yTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.xTensor)) { - gradientArrays.add(_this.xTensor, math.elementWiseMul(y, dy)); - } - }); - }; - return Exp; -}(op_1.Operation)); -exports.Exp = Exp; - -},{"../../globals":35,"../graph_util":41,"./op":58}],53:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var LinearCombination = (function (_super) { - __extends(LinearCombination, _super); - function LinearCombination(x1Tensor, x2Tensor, c1Tensor, c2Tensor, outTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.c1Tensor = c1Tensor; - _this.c2Tensor = c2Tensor; - _this.outTensor = outTensor; - return _this; - } - LinearCombination.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var c1 = inferenceArrays.get(this.c1Tensor).asScalar(); - var c2 = inferenceArrays.get(this.c2Tensor).asScalar(); - globals_1.tidy(function () { - inferenceArrays.set(_this.outTensor, globals_1.keep(math.scaledArrayAdd(c1, x1, c2, x2))); - }); - }; - LinearCombination.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var c1 = inferenceArrays.get(this.c1Tensor); - var c2 = inferenceArrays.get(this.c2Tensor); - var dy = gradientArrays.get(this.outTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - gradientArrays.add(_this.x1Tensor, math.scalarTimesArray(c1, dy)); - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - gradientArrays.add(_this.x2Tensor, math.scalarTimesArray(c2, dy)); - } - if (graph_util.shouldBackProp(_this.c1Tensor)) { - var dotProduct1 = math.elementWiseMul(x1, dy); - gradientArrays.add(_this.c1Tensor, math.sum(dotProduct1)); - } - if (graph_util.shouldBackProp(_this.c2Tensor)) { - var dotProduct2 = math.elementWiseMul(x2, dy); - gradientArrays.add(_this.c2Tensor, math.sum(dotProduct2)); - } - }); - }; - return LinearCombination; -}(op_1.Operation)); -exports.LinearCombination = LinearCombination; - -},{"../../globals":35,"../graph_util":41,"./op":58}],54:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Log = (function (_super) { - __extends(Log, _super); - function Log(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - return _this; - } - Log.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.log(x))); - }); - }; - Log.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.xTensor)) { - gradientArrays.add(_this.xTensor, math.divide(dy, x)); - } - }); - }; - return Log; -}(op_1.Operation)); -exports.Log = Log; - -},{"../../globals":35,"../graph_util":41,"./op":58}],55:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var MatMul = (function (_super) { - __extends(MatMul, _super); - function MatMul(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - return _this; - } - MatMul.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - if (x1.shape.length === 2 && x2.shape.length === 2) { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.matMul(x1, x2))); - } - else if (x1.shape.length === 2 && x2.shape.length === 1) { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.matrixTimesVector(x1, x2))); - } - else if (x1.shape.length === 1 && x2.shape.length === 2) { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.vectorTimesMatrix(x1, x2))); - } - }); - }; - MatMul.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var dy = gradientArrays.get(this.yTensor); - if (x1.shape.length === 1) { - x1 = x1.reshape([1, x1.size]); - dy = dy.reshape([1, dy.size]); - } - if (x2.shape.length === 1) { - x2 = x2.reshape([x2.size, 1]); - dy = dy.reshape([dy.size, 1]); - } - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - var dx1 = math.matMul(dy, x2, false, true); - gradientArrays.add(_this.x1Tensor, _this.x1Tensor.shape.length === 1 ? dx1.as1D() : dx1); - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - var dx2 = math.matMul(x1, dy, true, false); - gradientArrays.add(_this.x2Tensor, _this.x2Tensor.shape.length === 1 ? dx2.as1D() : dx2); - } - }); - }; - return MatMul; -}(op_1.Operation)); -exports.MatMul = MatMul; - -},{"../../globals":35,"../graph_util":41,"./op":58}],56:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var conv_util = require("../../ops/conv_util"); -var util = require("../../util"); -var op_1 = require("./op"); -var MaxPool = (function (_super) { - __extends(MaxPool, _super); - function MaxPool(xTensor, yTensor, fieldSize, stride, pad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - _this.fieldSize = fieldSize; - _this.stride = stride; - if (pad != null) { - _this.pad = pad; - } - else { - _this.pad = conv_util.computeDefaultPad(xTensor.shape, _this.fieldSize, _this.stride); - } - util.assert(util.isInt(_this.pad), "The zero padding (" + _this.pad + ") must be an integer. Change the " + - "stride and/or zero pad parameters"); - return _this; - } - MaxPool.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.maxPool(x, _this.fieldSize, _this.stride, _this.pad))); - }); - }; - MaxPool.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - gradientArrays.add(_this.xTensor, math.maxPoolBackprop(dy, x, _this.fieldSize, _this.stride, _this.pad)); - }); - }; - return MaxPool; -}(op_1.Operation)); -exports.MaxPool = MaxPool; - -},{"../../globals":35,"../../ops/conv_util":115,"../../util":151,"./op":58}],57:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Multiply = (function (_super) { - __extends(Multiply, _super); - function Multiply(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - util.assert(util.sizeFromShape(x1Tensor.shape) === 1 || - util.sizeFromShape(x2Tensor.shape) === 1 || - util.arraysEqual(x1Tensor.shape, x2Tensor.shape), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape'); - return _this; - } - Multiply.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var t1 = inferenceArrays.get(this.x1Tensor); - var t2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(t1.shape)) { - result = math.scalarTimesArray(t1, t2); - } - else if (util.isScalarShape(t2.shape)) { - result = math.scalarTimesArray(t2, t1); - } - else { - result = math.elementWiseMul(t1, t2); - } - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - Multiply.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - if (util.isScalarShape(_this.x1Tensor.shape)) { - var mul = math.elementWiseMul(dy, x2); - gradientArrays.add(_this.x1Tensor, math.sum(mul)); - } - else if (util.isScalarShape(x2.shape)) { - gradientArrays.add(_this.x1Tensor, math.scalarTimesArray(x2, dy)); - } - else { - gradientArrays.add(_this.x1Tensor, math.elementWiseMul(x2, dy)); - } - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - if (util.isScalarShape(_this.x2Tensor.shape)) { - var mul = math.elementWiseMul(dy, x1); - gradientArrays.add(_this.x2Tensor, math.sum(mul)); - } - else if (util.isScalarShape(x1.shape)) { - gradientArrays.add(_this.x2Tensor, math.scalarTimesArray(x1, dy)); - } - else { - gradientArrays.add(_this.x2Tensor, math.elementWiseMul(x1, dy)); - } - } - }); - }; - return Multiply; -}(op_1.Operation)); -exports.Multiply = Multiply; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],58:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Operation = (function () { - function Operation() { - } - Operation.prototype.disposeTransientArrays = function (inferenceArrays, gradientArrays) { }; - Operation.prototype.dispose = function () { }; - return Operation; -}()); -exports.Operation = Operation; - -},{}],59:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var globals_1 = require("../../globals"); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var ReduceSum = (function (_super) { - __extends(ReduceSum, _super); - function ReduceSum(x, outTensor) { - var _this = _super.call(this) || this; - _this.x = x; - _this.outTensor = outTensor; - util.assertShapesMatch(outTensor.shape, []); - _this.ones = environment_1.ENV.math.keep(tensor_1.Tensor.ones(x.shape)); - return _this; - } - ReduceSum.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.x); - globals_1.tidy(function () { - inferenceArrays.set(_this.outTensor, globals_1.keep(math.sum(x))); - }); - }; - ReduceSum.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - if (!graph_util.shouldBackProp(this.x)) { - return; - } - globals_1.tidy(function () { - var dy = gradientArrays.get(_this.outTensor); - gradientArrays.add(_this.x, math.scalarTimesArray(dy, _this.ones)); - }); - }; - ReduceSum.prototype.dispose = function () { - this.ones.dispose(); - }; - return ReduceSum; -}(op_1.Operation)); -exports.ReduceSum = ReduceSum; - -},{"../../environment":34,"../../globals":35,"../../tensor":146,"../../util":151,"../graph_util":41,"./op":58}],60:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var op_1 = require("./op"); -var Reshape = (function (_super) { - __extends(Reshape, _super); - function Reshape(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - var xSize = util.sizeFromShape(xTensor.shape); - var ySize = util.sizeFromShape(yTensor.shape); - util.assert(xSize === ySize, "The input size (" + xSize + ") and output size (" + ySize + ") must match"); - return _this; - } - Reshape.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var clone = math.clone(x); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(clone.reshape(_this.yTensor.shape))); - }); - }; - Reshape.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var dy = gradientArrays.get(this.yTensor); - var clone = math.clone(dy); - globals_1.tidy(function () { - gradientArrays.add(_this.xTensor, clone.reshape(_this.xTensor.shape)); - }); - }; - return Reshape; -}(op_1.Operation)); -exports.Reshape = Reshape; - -},{"../../globals":35,"../../util":151,"./op":58}],61:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var globals_1 = require("../../globals"); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var graph_1 = require("../graph"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Softmax = (function (_super) { - __extends(Softmax, _super); - function Softmax(logitsTensor, output) { - var _this = _super.call(this) || this; - _this.logitsTensor = logitsTensor; - _this.output = output; - return _this; - } - Softmax.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var logits = inferenceArrays.get(this.logitsTensor); - return globals_1.tidy(function () { - inferenceArrays.set(_this.output, globals_1.keep(math.softmax(logits))); - }); - }; - Softmax.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var y = inferenceArrays.get(this.output); - var dy = gradientArrays.get(this.output); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.logitsTensor)) { - var dlogits = math.elementWiseMul(math.subtract(dy, math.sum(math.elementWiseMul(dy, y))), y); - gradientArrays.add(_this.logitsTensor, dlogits); - } - }); - }; - return Softmax; -}(op_1.Operation)); -exports.Softmax = Softmax; -var SoftmaxCrossEntropyCost = (function (_super) { - __extends(SoftmaxCrossEntropyCost, _super); - function SoftmaxCrossEntropyCost(logitsTensor, labelTensor, yTensor) { - var _this = _super.call(this) || this; - _this.logitsTensor = logitsTensor; - _this.labelTensor = labelTensor; - _this.yTensor = yTensor; - _this.softmaxTensor = new graph_1.SymbolicTensor(logitsTensor.shape); - _this.epsilon = environment_1.ENV.math.keep(tensor_1.Scalar.new(1e-5)); - return _this; - } - SoftmaxCrossEntropyCost.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var logits = inferenceArrays.get(this.logitsTensor); - var label = inferenceArrays.get(this.labelTensor); - globals_1.tidy(function () { - var softmaxResult = math.softmax(logits); - inferenceArrays.set(_this.softmaxTensor, globals_1.keep(softmaxResult)); - inferenceArrays.set(_this.yTensor, globals_1.keep(crossEntropyCost(math, softmaxResult, label, _this.epsilon))); - }); - }; - SoftmaxCrossEntropyCost.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var softmax = inferenceArrays.get(this.softmaxTensor); - var label = inferenceArrays.get(this.labelTensor); - globals_1.tidy(function () { - gradientArrays.add(_this.logitsTensor, math.subtract(softmax, label)); - }); - }; - SoftmaxCrossEntropyCost.prototype.disposeTransientArrays = function (inferenceArrays, gradientArrays) { - inferenceArrays.disposeArray(this.softmaxTensor); - }; - SoftmaxCrossEntropyCost.prototype.dispose = function () { - this.epsilon.dispose(); - }; - return SoftmaxCrossEntropyCost; -}(op_1.Operation)); -exports.SoftmaxCrossEntropyCost = SoftmaxCrossEntropyCost; -function crossEntropyCost(math, y, target, epsilon) { - util.assert(y.size === target.size, 'The output and target must be the same size'); - return globals_1.tidy(function () { - var yPlusEps = math.scalarPlusArray(epsilon, y); - var logOutput = math.log(yPlusEps); - var tarLogOutput = math.elementWiseMul(target, logOutput); - var costVector = math.neg(tarLogOutput); - return math.sum(costVector); - }); -} -exports.crossEntropyCost = crossEntropyCost; - -},{"../../environment":34,"../../globals":35,"../../tensor":146,"../../util":151,"../graph":39,"../graph_util":41,"./op":58}],62:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Subtract = (function (_super) { - __extends(Subtract, _super); - function Subtract(t1, t2, outTensor) { - var _this = _super.call(this) || this; - _this.t1 = t1; - _this.t2 = t2; - _this.outTensor = outTensor; - util.assert(util.sizeFromShape(t1.shape) === 1 || - util.sizeFromShape(t2.shape) === 1 || - util.arraysEqual(t1.shape, t2.shape), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape'); - return _this; - } - Subtract.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var t1 = inferenceArrays.get(this.t1); - var t2 = inferenceArrays.get(this.t2); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(t1.shape)) { - result = math.scalarMinusArray(t1, t2); - } - else if (util.isScalarShape(t2.shape)) { - result = math.arrayMinusScalar(t1, t2); - } - else { - result = math.subtract(t1, t2); - } - inferenceArrays.set(_this.outTensor, globals_1.keep(result)); - }); - }; - Subtract.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var dy = gradientArrays.get(this.outTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.t1)) { - if (util.isScalarShape(_this.t1.shape)) { - var sum = math.sum(dy); - gradientArrays.add(_this.t1, sum); - } - else { - gradientArrays.add(_this.t1, math.clone(dy)); - } - } - if (graph_util.shouldBackProp(_this.t2)) { - if (util.isScalarShape(_this.t2.shape)) { - var sum = math.sum(dy); - var negSum = math.neg(sum); - gradientArrays.add(_this.t2, negSum); - } - else { - gradientArrays.add(_this.t2, math.neg(dy)); - } - } - }); - }; - Subtract.prototype.dispose = function () { - if (this.dySizeScalar != null) { - this.dySizeScalar.dispose(); - } - }; - return Subtract; -}(op_1.Operation)); -exports.Subtract = Subtract; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],63:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function defaultCompare(a, b) { - if (a === b) { - return 0; - } - else if (a < b) { - return -1; - } - else { - return 1; - } -} -exports.defaultCompare = defaultCompare; -var PriorityQueue = (function () { - function PriorityQueue(comparator, indexObserver) { - this.comparator = comparator; - this.indexObserver = indexObserver; - this.heap = []; - } - PriorityQueue.prototype.enqueue = function (t) { - this.heap.push(t); - this.onIndexChanged(t, this.heap.length - 1); - this.siftUp(this.heap.length - 1); - }; - PriorityQueue.prototype.dequeue = function () { - if (this.empty()) { - throw new Error('dequeue called on empty priority queue.'); - } - var t = this.heap[0]; - this.swap(0, this.heap.length - 1); - this.heap.pop(); - this.siftDown(0); - return t; - }; - PriorityQueue.prototype.update = function (newT, index) { - var last = (index === this.heap.length - 1); - if (!last) { - this.swap(index, this.heap.length - 1); - } - this.heap.pop(); - if (!last) { - if (this.siftUpIndex(index) !== -1) { - this.siftUp(index); - } - else if (this.siftDownIndex(index) !== -1) { - this.siftDown(index); - } - } - this.enqueue(newT); - }; - PriorityQueue.prototype.empty = function () { - return this.heap.length === 0; - }; - PriorityQueue.prototype.onIndexChanged = function (t, newIndex) { - if (this.indexObserver) { - this.indexObserver(t, newIndex); - } - }; - PriorityQueue.prototype.getParentIndex = function (index) { - if (index === 0) { - return -1; - } - return Math.floor((index - 1) / 2); - }; - PriorityQueue.prototype.getLeftChildIndex = function (index) { - var candidate = index * 2 + 1; - return candidate < this.heap.length ? candidate : -1; - }; - PriorityQueue.prototype.getRightChildIndex = function (index) { - var candidate = index * 2 + 2; - return candidate < this.heap.length ? candidate : -1; - }; - PriorityQueue.prototype.siftUpIndex = function (index) { - var parentIndex = this.getParentIndex(index); - if (parentIndex === -1) { - return -1; - } - if (this.compare(parentIndex, index) > 0) { - return parentIndex; - } - return -1; - }; - PriorityQueue.prototype.siftUp = function (index) { - var siftIndex = this.siftUpIndex(index); - while (siftIndex !== -1) { - this.swap(index, siftIndex); - index = siftIndex; - siftIndex = this.siftUpIndex(index); - } - }; - PriorityQueue.prototype.siftDownIndex = function (index) { - if (index >= this.heap.length) { - return -1; - } - var largestChildIndex = index; - var leftChildIndex = this.getLeftChildIndex(index); - if ((leftChildIndex !== -1) && - (this.compare(leftChildIndex, largestChildIndex) < 0)) { - largestChildIndex = leftChildIndex; - } - var rightChildIndex = this.getRightChildIndex(index); - if ((rightChildIndex !== -1) && - (this.compare(rightChildIndex, largestChildIndex) < 0)) { - largestChildIndex = rightChildIndex; - } - return (largestChildIndex === index) ? -1 : largestChildIndex; - }; - PriorityQueue.prototype.siftDown = function (index) { - var siftIndex = this.siftDownIndex(index); - while (siftIndex !== -1) { - this.swap(index, siftIndex); - index = siftIndex; - siftIndex = this.siftDownIndex(index); - } - }; - PriorityQueue.prototype.compare = function (aIndex, bIndex) { - return this.comparator(this.heap[aIndex], this.heap[bIndex]); - }; - PriorityQueue.prototype.swap = function (a, b) { - var temp = this.heap[a]; - this.heap[a] = this.heap[b]; - this.heap[b] = temp; - this.onIndexChanged(this.heap[a], a); - this.onIndexChanged(this.heap[b], b); - }; - return PriorityQueue; -}()); -exports.PriorityQueue = PriorityQueue; - -},{}],64:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var operation_emitter = require("./operation_emitter"); -var session_util = require("./session_util"); -var tensor_array_map_1 = require("./tensor_array_map"); -var FeedDictionary = (function () { - function FeedDictionary(feedEntries) { - var _this = this; - this.dict = {}; - if (feedEntries) { - feedEntries.forEach(function (entry) { return _this.dict[entry.tensor.id] = entry; }); - } - } - return FeedDictionary; -}()); -exports.FeedDictionary = FeedDictionary; -var CostReduction; -(function (CostReduction) { - CostReduction[CostReduction["NONE"] = 0] = "NONE"; - CostReduction[CostReduction["SUM"] = 1] = "SUM"; - CostReduction[CostReduction["MEAN"] = 2] = "MEAN"; -})(CostReduction = exports.CostReduction || (exports.CostReduction = {})); -var Session = (function () { - function Session(graph, math) { - this.math = math; - this.activationArrayMap = new tensor_array_map_1.TensorArrayMap(); - this.runtimeCache = {}; - this.oneScalar = tensor_1.Scalar.new(1); - this.gradientArrayMap = new tensor_array_map_1.SummedTensorArrayMap(this.math); - } - Session.prototype.dispose = function () { - var _this = this; - this.activationArrayMap.dispose(); - Object.keys(this.runtimeCache).forEach(function (key) { - var runtime = _this.runtimeCache[key]; - if (runtime.operations) { - runtime.operations.forEach(function (op) { return op.dispose(); }); - } - }); - this.runtimeCache = {}; - if (this.batchSizeScalar != null) { - this.batchSizeScalar.dispose(); - } - this.oneScalar.dispose(); - }; - Session.prototype.evalAll = function (tensors, feedEntries) { - var _this = this; - return globals_1.tidy(function () { - var feed = new FeedDictionary(feedEntries); - var runtime = _this.getOrCreateRuntime(tensors, feed); - var activations = _this.activationArrayMap; - session_util.disposeAndInitializeOperationOutputs(runtime.nodes, activations); - session_util.disposeTransientOperationArrays(runtime.operations, _this.activationArrayMap, _this.gradientArrayMap); - session_util.addPersistentArraysToTensorArrayMap(runtime.nodes, activations); - session_util.loadInputsFromFeedDictionaryToTensorArrayMap(feed, activations, _this.math); - runtime.operations.forEach(function (op) { return op.feedForward(_this.math, activations); }); - var results = tensors.map(function (x) { return activations.get(x); }); - tensors.forEach(function (x) { return activations.delete(x); }); - session_util.releaseFeedDictionaryInputsFromTensorArrayMap(feed, activations, _this.math); - return results; - }); - }; - Session.prototype.eval = function (tensor, feedEntries) { - return this.evalAll([tensor], feedEntries)[0]; - }; - Session.prototype.train = function (costTensor, feedEntries, batchSize, optimizer, costReduction) { - var _this = this; - if (costReduction === void 0) { costReduction = CostReduction.NONE; } - util.assert(util.isScalarShape(costTensor.shape), 'Cost tensor for training must be a scalar value.'); - if (this.prevBatchSize !== batchSize) { - this.prevBatchSize = batchSize; - if (this.batchSizeScalar != null) { - this.batchSizeScalar.dispose(); - } - this.batchSizeScalar = this.math.keep(tensor_1.Scalar.new(batchSize)); - } - var feed = new FeedDictionary(feedEntries); - session_util.throwIfFeedDictionaryContainsNDArrays(feed); - var runtime = this.getOrCreateRuntime([costTensor], feed); - var inferenceOperations = runtime.operations; - var backPropOperations = runtime.operations.slice().reverse(); - var activations = this.activationArrayMap; - var gradients = this.gradientArrayMap; - gradients.nullify(costTensor); - gradients.add(costTensor, this.oneScalar); - session_util.addPersistentArraysToTensorArrayMap(runtime.nodes, activations); - optimizer.beforeBatch(this.math, batchSize, runtime, activations, gradients); - return globals_1.tidy(function () { - var cost = tensor_1.Scalar.new(0); - for (var i = 0; i < batchSize; ++i) { - session_util.disposeAndInitializeOperationOutputs(runtime.nodes, activations); - session_util.disposeAndInitializeOperationInputGradients(runtime.nodes, gradients); - session_util.disposeTransientOperationArrays(runtime.operations, activations, gradients); - session_util.loadInputsFromFeedDictionaryToTensorArrayMap(feed, activations, _this.math); - inferenceOperations.forEach(function (op) { return op.feedForward(_this.math, activations); }); - backPropOperations.forEach(function (op) { return op.backProp(_this.math, activations, gradients); }); - optimizer.afterExample(_this.math, runtime, activations, gradients); - session_util.releaseFeedDictionaryInputsFromTensorArrayMap(feed, activations, _this.math); - cost = _this.updateCostForExample(cost, activations.get(costTensor), costReduction); - } - optimizer.afterBatch(_this.math, batchSize, runtime, activations, gradients); - return _this.updateCostForBatch(cost, costReduction); - }); - }; - Session.prototype.updateCostForExample = function (totalCost, currCost, costReduction) { - if (costReduction === CostReduction.MEAN || - costReduction === CostReduction.SUM) { - return this.math.add(totalCost, currCost); - } - return totalCost; - }; - Session.prototype.updateCostForBatch = function (totalCost, costReduction) { - if (costReduction === CostReduction.MEAN) { - return this.math.divide(totalCost, this.batchSizeScalar); - } - return totalCost; - }; - Session.prototype.getOrCreateRuntime = function (tensors, feed) { - var key = this.makeRuntimeCacheKey(tensors, feed); - var runtime = this.runtimeCache[key]; - if (runtime === undefined) { - var nodes = session_util.getOrderedEvaluationSetFromEvalTensor(tensors, feed); - session_util.removeFeedDictionaryNodesFromEvaluationSet(feed, nodes); - session_util.throwErrorIfEvaluationSetContainsPlaceholderNodes(nodes); - var operations = operation_emitter.emitFromGraphNodes(nodes); - runtime = { nodes: nodes, operations: operations }; - this.runtimeCache[key] = runtime; - } - return runtime; - }; - Session.prototype.makeRuntimeCacheKey = function (tensors, feed) { - return tensors.map(function (x) { return x.id; }).sort().join('_') + '__' + - Object.keys(feed.dict).sort().join('_'); - }; - return Session; -}()); -exports.Session = Session; - -},{"../globals":35,"../tensor":146,"../util":151,"./operation_emitter":43,"./session_util":65,"./tensor_array_map":66}],65:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var graph_1 = require("./graph"); -var graph_util = require("./graph_util"); -function getTerminatingNodesFromFeedDictionary(feedDictionary) { - return Object.keys(feedDictionary.dict) - .map(function (tensorID) { return feedDictionary.dict[+tensorID].tensor.node; }); -} -exports.getTerminatingNodesFromFeedDictionary = getTerminatingNodesFromFeedDictionary; -function getOrderedEvaluationSetFromEvalTensor(evalTensors, feedDictionary) { - var terminatingNodes = getTerminatingNodesFromFeedDictionary(feedDictionary); - var evalNodes = evalTensors.map(function (x) { return x.node; }); - var unorderedEvaluationSet = graph_util.getUnorderedEvaluationSet(evalNodes, terminatingNodes); - var orderedEvaluationSet = graph_util.getOrderedEvaluationSet(unorderedEvaluationSet); - return orderedEvaluationSet; -} -exports.getOrderedEvaluationSetFromEvalTensor = getOrderedEvaluationSetFromEvalTensor; -function addPersistentArraysToTensorArrayMap(evaluationSet, tensorArrayMap) { - evaluationSet.forEach(function (node) { - if (node instanceof graph_1.VariableNode || node instanceof graph_1.ConstantNode) { - tensorArrayMap.set(node.output, node.data); - } - }); -} -exports.addPersistentArraysToTensorArrayMap = addPersistentArraysToTensorArrayMap; -function getVariableNodesFromEvaluationSet(evaluationSet) { - var nodes = []; - evaluationSet.forEach(function (node) { - if (node instanceof graph_1.VariableNode) { - nodes.push(node); - } - }); - return nodes; -} -exports.getVariableNodesFromEvaluationSet = getVariableNodesFromEvaluationSet; -function throwIfFeedDictionaryContainsNDArrays(feedDictionary) { - Object.keys(feedDictionary.dict).forEach(function (tensorID) { - if (feedDictionary.dict[+tensorID].data instanceof tensor_1.Tensor) { - throw new Error('training requires FeedDictionary entries to be InputProviders' + - 'and not NDArrays.'); - } - }); -} -exports.throwIfFeedDictionaryContainsNDArrays = throwIfFeedDictionaryContainsNDArrays; -function loadInputsFromFeedDictionaryToTensorArrayMap(batchFeed, activations, math) { - Object.keys(batchFeed.dict).forEach(function (tensorID) { - var feedEntry = batchFeed.dict[+tensorID]; - var data; - if (feedEntry.data instanceof tensor_1.Tensor) { - data = feedEntry.data; - } - else { - var provider = feedEntry.data; - data = provider.getNextCopy(); - } - util.assert(util.arraysEqual(feedEntry.tensor.shape, data.shape), "Error loading FeedEntry: feeding NDArray of shape " + data.shape + " " + - ("does not match Tensor (id: " + feedEntry.tensor.id + ") shape: ") + - (feedEntry.tensor.shape + ".")); - activations.set(feedEntry.tensor, data); - }); -} -exports.loadInputsFromFeedDictionaryToTensorArrayMap = loadInputsFromFeedDictionaryToTensorArrayMap; -function releaseFeedDictionaryInputsFromTensorArrayMap(batchFeed, activations, math) { - Object.keys(batchFeed.dict).forEach(function (tensorID) { - var feedEntry = batchFeed.dict[+tensorID]; - if (!(feedEntry.data instanceof tensor_1.Tensor)) { - var provider = feedEntry.data; - var feedEntryArray = activations.get(feedEntry.tensor); - provider.disposeCopy(feedEntryArray); - } - activations.delete(feedEntry.tensor); - }); -} -exports.releaseFeedDictionaryInputsFromTensorArrayMap = releaseFeedDictionaryInputsFromTensorArrayMap; -function removeFeedDictionaryNodesFromEvaluationSet(feedDictionary, evaluationSet) { - var i = 0; - while (i < evaluationSet.length) { - var node = evaluationSet[i]; - if (feedDictionary.dict[node.output.id] != null) { - evaluationSet.splice(i, 1); - } - else { - ++i; - } - } -} -exports.removeFeedDictionaryNodesFromEvaluationSet = removeFeedDictionaryNodesFromEvaluationSet; -function disposeAndInitializeOperationOutputs(evaluationSet, tensorArrayMap) { - evaluationSet.forEach(function (node) { - if (!graph_util.isInputNode(node)) { - if (!graph_util.isPassthroughNode(node, tensorArrayMap)) { - tensorArrayMap.disposeArray(node.output); - } - tensorArrayMap.set(node.output, null); - } - }); -} -exports.disposeAndInitializeOperationOutputs = disposeAndInitializeOperationOutputs; -function disposeAndInitializeOperationInputGradients(evaluationSet, gradients) { - evaluationSet.forEach(function (node) { - Object.keys(node.inputs).forEach(function (inputName) { - var input = node.inputs[inputName]; - if (gradients.get(input, true) !== gradients.get(node.output, true)) { - gradients.disposeArray(input); - } - gradients.nullify(input); - }); - }); -} -exports.disposeAndInitializeOperationInputGradients = disposeAndInitializeOperationInputGradients; -function disposeTransientOperationArrays(operations, activations, gradients) { - operations.forEach(function (op) { return op.disposeTransientArrays(activations, gradients); }); -} -exports.disposeTransientOperationArrays = disposeTransientOperationArrays; -function throwErrorIfEvaluationSetContainsPlaceholderNodes(evaluationSet) { - evaluationSet.forEach(function (node) { - if (node instanceof graph_1.PlaceholderNode) { - var shape = '[' + node.output.shape.join(', ') + ']'; - throw new Error('Placeholder node "' + node.name + '" ' + shape + - ' not present in feed dictionary.'); - } - }); -} -exports.throwErrorIfEvaluationSetContainsPlaceholderNodes = throwErrorIfEvaluationSetContainsPlaceholderNodes; - -},{"../tensor":146,"../util":151,"./graph":39,"./graph_util":41}],66:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var TensorArrayMapBase = (function () { - function TensorArrayMapBase() { - this.dict = {}; - } - TensorArrayMapBase.prototype.get = function (tensor, skipChecks) { - if (skipChecks === void 0) { skipChecks = false; } - if (!skipChecks && this.dict[tensor.id] === undefined) { - throw new Error("tensor " + tensor.id + " not in array map."); - } - var nda = this.dict[tensor.id]; - if (!skipChecks && nda === null) { - throw new Error("tensor " + tensor.id + " has null array."); - } - return nda; - }; - TensorArrayMapBase.prototype.delete = function (tensor) { - delete this.dict[tensor.id]; - }; - TensorArrayMapBase.prototype.nullify = function (tensor) { - this.dict[tensor.id] = null; - }; - TensorArrayMapBase.prototype.disposeArray = function (tensor) { - if (this.dict[tensor.id] === undefined) { - return; - } - var nda = this.dict[tensor.id]; - if (nda === null) { - return; - } - nda.dispose(); - this.dict[tensor.id] = null; - }; - TensorArrayMapBase.prototype.size = function () { - return Object.keys(this.dict).length; - }; - TensorArrayMapBase.prototype.dispose = function () { - var _this = this; - Object.keys(this.dict).forEach(function (tensorID) { - var nda = _this.dict[+tensorID]; - if (nda) { - nda.dispose(); - } - }); - this.dict = {}; - }; - TensorArrayMapBase.prototype.hasNullArray = function (tensor) { - if (this.dict[tensor.id] === undefined) { - throw new Error("tensor " + tensor.id + " not in array map."); - } - return this.dict[tensor.id] === null; - }; - return TensorArrayMapBase; -}()); -exports.TensorArrayMapBase = TensorArrayMapBase; -var TensorArrayMap = (function (_super) { - __extends(TensorArrayMap, _super); - function TensorArrayMap() { - return _super !== null && _super.apply(this, arguments) || this; - } - TensorArrayMap.prototype.set = function (tensor, array) { - this.dict[tensor.id] = array; - }; - return TensorArrayMap; -}(TensorArrayMapBase)); -exports.TensorArrayMap = TensorArrayMap; -var SummedTensorArrayMap = (function (_super) { - __extends(SummedTensorArrayMap, _super); - function SummedTensorArrayMap(math) { - var _this = _super.call(this) || this; - _this.math = math; - return _this; - } - SummedTensorArrayMap.prototype.add = function (tensor, array) { - if (this.dict[tensor.id] == null) { - this.dict[tensor.id] = this.math.keep(array); - } - else { - var oldValue = this.get(tensor); - var newValue = this.math.keep(this.math.addStrict(oldValue, array)); - this.dict[tensor.id] = newValue; - oldValue.dispose(); - } - }; - return SummedTensorArrayMap; -}(TensorArrayMapBase)); -exports.SummedTensorArrayMap = SummedTensorArrayMap; - -},{}],67:[function(require,module,exports){ -"use strict"; -function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; -} -Object.defineProperty(exports, "__esModule", { value: true }); -var browser_util_1 = require("./browser_util"); -var contrib = require("./contrib"); -exports.contrib = contrib; -var xhr_dataset = require("./data/xhr-dataset"); -exports.xhr_dataset = xhr_dataset; -var environment = require("./environment"); -exports.environment = environment; -var environment_1 = require("./environment"); -var gpgpu_util = require("./kernels/webgl/gpgpu_util"); -exports.gpgpu_util = gpgpu_util; -var webgl_util = require("./kernels/webgl/webgl_util"); -exports.webgl_util = webgl_util; -var conv_util = require("./ops/conv_util"); -exports.conv_util = conv_util; -var test_util = require("./test_util"); -exports.test_util = test_util; -var util = require("./util"); -exports.util = util; -var version_1 = require("./version"); -exports.version = version_1.version; -var checkpoint_loader_1 = require("./data/checkpoint_loader"); -exports.CheckpointLoader = checkpoint_loader_1.CheckpointLoader; -var dataset_1 = require("./data/dataset"); -exports.InMemoryDataset = dataset_1.InMemoryDataset; -var input_provider_1 = require("./data/input_provider"); -exports.InCPUMemoryShuffledInputProviderBuilder = input_provider_1.InCPUMemoryShuffledInputProviderBuilder; -exports.InGPUMemoryShuffledInputProviderBuilder = input_provider_1.InGPUMemoryShuffledInputProviderBuilder; -var xhr_dataset_1 = require("./data/xhr-dataset"); -exports.XhrDataset = xhr_dataset_1.XhrDataset; -var environment_2 = require("./environment"); -exports.ENV = environment_2.ENV; -exports.Environment = environment_2.Environment; -var graph_1 = require("./graph/graph"); -exports.Graph = graph_1.Graph; -exports.SymbolicTensor = graph_1.SymbolicTensor; -var graph_runner_1 = require("./graph/graph_runner"); -exports.GraphRunner = graph_runner_1.GraphRunner; -exports.MetricReduction = graph_runner_1.MetricReduction; -var initializers_1 = require("./graph/initializers"); -exports.ConstantInitializer = initializers_1.ConstantInitializer; -exports.OnesInitializer = initializers_1.OnesInitializer; -exports.RandomNormalInitializer = initializers_1.RandomNormalInitializer; -exports.RandomTruncatedNormalInitializer = initializers_1.RandomTruncatedNormalInitializer; -exports.RandomUniformInitializer = initializers_1.RandomUniformInitializer; -exports.TensorInitializer = initializers_1.TensorInitializer; -exports.VarianceScalingInitializer = initializers_1.VarianceScalingInitializer; -exports.ZerosInitializer = initializers_1.ZerosInitializer; -var session_1 = require("./graph/session"); -exports.CostReduction = session_1.CostReduction; -exports.Session = session_1.Session; -var backend_cpu_1 = require("./kernels/backend_cpu"); -exports.MathBackendCPU = backend_cpu_1.MathBackendCPU; -exports.NDArrayMathCPU = backend_cpu_1.NDArrayMathCPU; -var backend_webgl_1 = require("./kernels/backend_webgl"); -exports.MathBackendWebGL = backend_webgl_1.MathBackendWebGL; -exports.NDArrayMathGPU = backend_webgl_1.NDArrayMathGPU; -var matmul_1 = require("./kernels/types/matmul"); -exports.MatrixOrientation = matmul_1.MatrixOrientation; -var gpgpu_context_1 = require("./kernels/webgl/gpgpu_context"); -exports.GPGPUContext = gpgpu_context_1.GPGPUContext; -var math_1 = require("./math"); -exports.NDArrayMath = math_1.NDArrayMath; -var adadelta_optimizer_1 = require("./optimizers/adadelta_optimizer"); -exports.AdadeltaOptimizer = adadelta_optimizer_1.AdadeltaOptimizer; -var adagrad_optimizer_1 = require("./optimizers/adagrad_optimizer"); -exports.AdagradOptimizer = adagrad_optimizer_1.AdagradOptimizer; -var adam_optimizer_1 = require("./optimizers/adam_optimizer"); -exports.AdamOptimizer = adam_optimizer_1.AdamOptimizer; -var adamax_optimizer_1 = require("./optimizers/adamax_optimizer"); -exports.AdamaxOptimizer = adamax_optimizer_1.AdamaxOptimizer; -var momentum_optimizer_1 = require("./optimizers/momentum_optimizer"); -exports.MomentumOptimizer = momentum_optimizer_1.MomentumOptimizer; -var optimizer_1 = require("./optimizers/optimizer"); -exports.Optimizer = optimizer_1.Optimizer; -var rmsprop_optimizer_1 = require("./optimizers/rmsprop_optimizer"); -exports.RMSPropOptimizer = rmsprop_optimizer_1.RMSPropOptimizer; -var sgd_optimizer_1 = require("./optimizers/sgd_optimizer"); -exports.SGDOptimizer = sgd_optimizer_1.SGDOptimizer; -var tensor_1 = require("./tensor"); -exports.Array1D = tensor_1.Array1D; -exports.Array2D = tensor_1.Array2D; -exports.Array3D = tensor_1.Array3D; -exports.Array4D = tensor_1.Array4D; -exports.NDArray = tensor_1.NDArray; -exports.Scalar = tensor_1.Scalar; -exports.Tensor = tensor_1.Tensor; -exports.Tensor1D = tensor_1.Tensor1D; -exports.Tensor2D = tensor_1.Tensor2D; -exports.Tensor3D = tensor_1.Tensor3D; -exports.Tensor4D = tensor_1.Tensor4D; -exports.variable = tensor_1.variable; -exports.Variable = tensor_1.Variable; -var types_1 = require("./types"); -exports.Rank = types_1.Rank; -__export(require("./ops/ops")); -__export(require("./train")); -__export(require("./globals")); -exports.setBackend = environment_1.Environment.setBackend; -exports.getBackend = environment_1.Environment.getBackend; -exports.memory = environment_1.Environment.memory; -exports.nextFrame = browser_util_1.BrowserUtil.nextFrame; - -},{"./browser_util":10,"./contrib":26,"./data/checkpoint_loader":27,"./data/dataset":28,"./data/input_provider":29,"./data/xhr-dataset":30,"./environment":34,"./globals":35,"./graph/graph":39,"./graph/graph_runner":40,"./graph/initializers":42,"./graph/session":64,"./kernels/backend_cpu":68,"./kernels/backend_webgl":69,"./kernels/types/matmul":71,"./kernels/webgl/gpgpu_context":83,"./kernels/webgl/gpgpu_util":85,"./kernels/webgl/webgl_util":104,"./math":105,"./ops/conv_util":115,"./ops/ops":123,"./optimizers/adadelta_optimizer":135,"./optimizers/adagrad_optimizer":136,"./optimizers/adam_optimizer":137,"./optimizers/adamax_optimizer":138,"./optimizers/momentum_optimizer":139,"./optimizers/optimizer":140,"./optimizers/rmsprop_optimizer":142,"./optimizers/sgd_optimizer":143,"./tensor":146,"./test_util":147,"./train":149,"./types":150,"./util":151,"./version":152}],68:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var environment_1 = require("../environment"); -var math_1 = require("../math"); -var axis_util = require("../ops/axis_util"); -var broadcast_util = require("../ops/broadcast_util"); -var concat_util = require("../ops/concat_util"); -var ops = require("../ops/ops"); -var ops_1 = require("../ops/ops"); -var selu_util = require("../ops/selu_util"); -var tensor_1 = require("../tensor"); -var types = require("../types"); -var util = require("../util"); -var MathBackendCPU = (function () { - function MathBackendCPU() { - this.data = new WeakMap(); - if (typeof document !== 'undefined') { - this.canvas = document.createElement('canvas'); - } - } - MathBackendCPU.prototype.register = function (dataId, shape, dtype) { - if (this.data.has(dataId)) { - throw new Error("Data buffer is already registered"); - } - this.data.set(dataId, null); - }; - MathBackendCPU.prototype.write = function (dataId, values) { - if (values == null) { - throw new Error('MathBackendCPU.write(): values can not be null'); - } - this.throwIfNoData(dataId); - this.data.set(dataId, values); - }; - MathBackendCPU.prototype.fromPixels = function (pixels, numChannels) { - if (pixels == null) { - throw new Error('MathBackendCPU.writePixels(): pixels can not be null'); - } - var vals; - if (pixels instanceof ImageData) { - vals = pixels.data; - } - else if (pixels instanceof HTMLCanvasElement) { - vals = pixels.getContext('2d') - .getImageData(0, 0, pixels.width, pixels.height) - .data; - } - else if (pixels instanceof HTMLImageElement || - pixels instanceof HTMLVideoElement) { - if (this.canvas == null) { - throw new Error('Can\'t read pixels from HTMLImageElement outside ' + - 'the browser.'); - } - this.canvas.width = pixels.width; - this.canvas.height = pixels.height; - this.canvas.getContext('2d').drawImage(pixels, 0, 0, pixels.width, pixels.height); - vals = this.canvas.getContext('2d') - .getImageData(0, 0, pixels.width, pixels.height) - .data; - } - else { - throw new Error("pixels is of unknown type: " + pixels.constructor.name); - } - var values; - if (numChannels === 4) { - values = new Int32Array(vals); - } - else { - var numPixels = pixels.width * pixels.height; - values = new Int32Array(numPixels * numChannels); - for (var i = 0; i < numPixels; i++) { - for (var channel = 0; channel < numChannels; ++channel) { - values[i * numChannels + channel] = vals[i * 4 + channel]; - } - } - } - var outShape = [pixels.height, pixels.width, numChannels]; - return ops_1.tensor3d(values, outShape, 'int32'); - }; - MathBackendCPU.prototype.read = function (dataId) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.readSync(dataId)]; - }); - }); - }; - MathBackendCPU.prototype.readSync = function (dataId) { - this.throwIfNoData(dataId); - return this.data.get(dataId); - }; - MathBackendCPU.prototype.disposeData = function (dataId) { - if (this.data.has(dataId)) { - this.data.delete(dataId); - } - }; - MathBackendCPU.prototype.time = function (f) { - return __awaiter(this, void 0, void 0, function () { - var start, kernelMs; - return __generator(this, function (_a) { - start = performance.now(); - f(); - kernelMs = performance.now() - start; - return [2, { kernelMs: kernelMs }]; - }); - }); - }; - MathBackendCPU.prototype.memory = function () { - return { - unreliable: true - }; - }; - MathBackendCPU.prototype.throwIfNoData = function (dataId) { - if (!this.data.has(dataId)) { - throw new Error("CPU backend: No data found for this tensor. " + - "Did you change your backend in the middle of the program? " + - "New backends can't use Tensors created with previous backends"); - } - }; - MathBackendCPU.prototype.slice1D = function (x, begin, size) { - var newVals = x.dataSync().slice(begin, begin + size); - return ops.tensor1d(newVals, x.dtype); - }; - MathBackendCPU.prototype.slice2D = function (x, begin, size) { - var buffer = ops.buffer(size, x.dtype); - var startI = begin[0], startJ = begin[1]; - for (var i = 0; i < size[0]; ++i) { - for (var j = 0; j < size[1]; ++j) { - var val = x.get(i + startI, j + startJ); - buffer.set(val, i, j); - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.slice3D = function (x, begin, size) { - var buffer = ops.buffer(size, x.dtype); - var startI = begin[0], startJ = begin[1], startK = begin[2]; - for (var i = 0; i < size[0]; ++i) { - for (var j = 0; j < size[1]; ++j) { - for (var k = 0; k < size[2]; ++k) { - var val = x.get(i + startI, j + startJ, k + startK); - buffer.set(val, i, j, k); - } - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.slice4D = function (x, begin, size) { - var buffer = ops.buffer(size, x.dtype); - var startI = begin[0], startJ = begin[1], startK = begin[2], startL = begin[3]; - for (var i = 0; i < size[0]; ++i) { - for (var j = 0; j < size[1]; ++j) { - for (var k = 0; k < size[2]; ++k) { - for (var l = 0; l < size[3]; ++l) { - var val = x.get(i + startI, j + startJ, k + startK, l + startL); - buffer.set(val, i, j, k, l); - } - } - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.reverse4D = function (x, axis) { - var buffer = ops.buffer(x.shape, x.dtype); - var revAxis = function (i) { return axis.indexOf(i) !== -1 && x.shape[i] !== 1; }; - for (var b = 0; b < x.shape[0]; ++b) { - for (var r = 0; r < x.shape[1]; ++r) { - for (var c = 0; c < x.shape[2]; ++c) { - for (var d = 0; d < x.shape[3]; ++d) { - var b0 = revAxis(0) ? x.shape[0] - b - 1 : b; - var r0 = revAxis(1) ? x.shape[1] - r - 1 : r; - var c0 = revAxis(2) ? x.shape[2] - c - 1 : c; - var d0 = revAxis(3) ? x.shape[3] - d - 1 : d; - var val = x.get(b0, r0, c0, d0); - buffer.set(val, b, r, c, d); - } - } - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.concat = function (a, b) { - var outShape = concat_util.computeOutShape(a.shape, b.shape, 1); - var buffer = ops.buffer(outShape, a.dtype); - if (a.shape[0] === 1 && b.shape[0] === 1) { - var aVals = a.dataSync(); - var bVals = b.dataSync(); - var vals = buffer.values; - vals.set(aVals, 0); - vals.set(bVals, a.size); - return buffer.toTensor(); - } - for (var i = 0; i < outShape[0]; ++i) { - for (var j = 0; j < a.shape[1]; ++j) { - buffer.set(a.get(i, j), i, j); - } - for (var j = 0; j < b.shape[1]; ++j) { - buffer.set(b.get(i, j), i, j + a.shape[1]); - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.neg = function (x) { - return this.multiply(ops.scalar(-1), x); - }; - MathBackendCPU.prototype.add = function (a, b) { - return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue + bValue; }); - }; - MathBackendCPU.prototype.subtract = function (a, b) { - return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue - bValue; }); - }; - MathBackendCPU.prototype.pow = function (a, b) { - return this.broadcastedBinaryOp(a, b, a.dtype, function (aValue, bValue) { return Math.pow(aValue, bValue); }); - }; - MathBackendCPU.prototype.matMul = function (a, b, transposeA, transposeB) { - var sharedDim = transposeA ? a.shape[0] : a.shape[1]; - var leftDim = transposeA ? a.shape[1] : a.shape[0]; - var rightDim = transposeB ? b.shape[0] : b.shape[1]; - var normalGetter = function (matrix, i, j) { - return matrix.get(i, j); - }; - var transposedGetter = function (matrix, i, j) { - return matrix.get(j, i); - }; - var aGetter = transposeA ? transposedGetter : normalGetter; - var bGetter = transposeB ? transposedGetter : normalGetter; - var values = new Float32Array(leftDim * rightDim); - var index = 0; - for (var i = 0; i < leftDim; ++i) { - for (var j = 0; j < rightDim; ++j) { - var sum = 0; - for (var k = 0; k < sharedDim; ++k) { - sum += aGetter(a, i, k) * bGetter(b, k, j); - } - values[index++] = sum; - } - } - return ops.tensor2d(values, [leftDim, rightDim]); - }; - MathBackendCPU.prototype.multiply = function (a, b) { - return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue * bValue; }); - }; - MathBackendCPU.prototype.divide = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'float32', function (aValue, bValue) { return aValue / bValue; }); - }; - MathBackendCPU.prototype.sum = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('sum', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var resultDtype = types.upcastType(x.dtype, 'int32'); - var result = ops.zeros(outShape, resultDtype); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var sum = 0; - for (var j = 0; j < reduceSize; ++j) { - sum += aVals[offset + j]; - } - vals[i] = sum; - } - return result; - }; - MathBackendCPU.prototype.argMin = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMin', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, 'int32'); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var min = aVals[offset]; - var minIndex = 0; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - minIndex = util.NAN_INT32; - break; - } - if (value < min) { - min = value; - minIndex = j; - } - } - vals[i] = minIndex; - } - return result; - }; - MathBackendCPU.prototype.argMax = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMax', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, 'int32'); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var max = aVals[offset]; - var maxIndex = 0; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - maxIndex = util.NAN_INT32; - break; - } - if (value > max) { - max = value; - maxIndex = j; - } - } - vals[i] = maxIndex; - } - return result; - }; - MathBackendCPU.prototype.equal = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal === bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.notEqual = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal !== bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.less = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal < bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.lessEqual = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal <= bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.greater = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal > bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.greaterEqual = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal >= bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.logicalNot = function (x) { - var values = x.dataSync(); - var newValues = new Int32Array(values.length); - for (var i = 0; i < values.length; ++i) { - if (util.isValNaN(values[i], x.dtype)) { - newValues[i] = util.getNaN('bool'); - } - else { - newValues[i] = values[i] ? 0 : 1; - } - } - return tensor_1.Tensor.make(x.shape, { values: newValues }, 'bool'); - }; - MathBackendCPU.prototype.logicalAnd = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return aVal && bVal; - } - }); - }; - MathBackendCPU.prototype.logicalOr = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return aVal || bVal; - } - }); - }; - MathBackendCPU.prototype.logicalXor = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return aVal ^ bVal; - } - }); - }; - MathBackendCPU.prototype.where = function (condition, a, b, dtype) { - var values = condition.dataSync(); - var aValues = a.dataSync(); - var bValues = b.dataSync(); - var result = ops.zeros(a.shape, dtype); - var newValues = result.dataSync(); - var index = 0; - var offset = condition.rank === 0 || condition.rank > 1 || a.rank === 1 ? - 1 : - a.shape[1]; - for (var i = 0; i < values.length; i++) { - for (var j = 0; j < offset; j++) { - if (values[i] === 1) { - newValues[index++] = aValues[i]; - } - else { - newValues[index++] = bValues[i]; - } - } - } - return result; - }; - MathBackendCPU.prototype.topKValues = function (x, k) { - return this.topK(x, k).values; - }; - MathBackendCPU.prototype.topKIndices = function (x, k) { - return this.topK(x, k).indices; - }; - MathBackendCPU.prototype.topK = function (x, k) { - var values = x.dataSync(); - var valuesAndIndices = []; - for (var i = 0; i < values.length; i++) { - valuesAndIndices.push({ value: values[i], index: i }); - } - valuesAndIndices.sort(function (a, b) { - return b.value - a.value; - }); - var topkValues = util.getTypedArrayFromDType(x.dtype, k); - var topkIndices = new Int32Array(k); - for (var i = 0; i < k; i++) { - topkValues[i] = valuesAndIndices[i].value; - topkIndices[i] = valuesAndIndices[i].index; - } - return { - values: ops.tensor1d(topkValues, x.dtype), - indices: tensor_1.Tensor1D.new(topkIndices) - }; - }; - MathBackendCPU.prototype.min = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('min', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, x.dtype); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var min = aVals[0]; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - min = Number.NaN; - break; - } - if (value < min) { - min = value; - } - } - vals[i] = min; - } - return result; - }; - MathBackendCPU.prototype.minimum = function (a, b) { - return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) { return Math.min(aVal, bVal); }); - }; - MathBackendCPU.prototype.max = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('max', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, x.dtype); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var max = aVals[offset]; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - max = Number.NaN; - break; - } - if (value > max) { - max = value; - } - } - vals[i] = max; - } - return result; - }; - MathBackendCPU.prototype.maximum = function (a, b) { - return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) { return Math.max(aVal, bVal); }); - }; - MathBackendCPU.prototype.ceil = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - newValues[i] = Math.ceil(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.floor = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - newValues[i] = Math.floor(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.exp = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - newValues[i] = Math.exp(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.log = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - newValues[i] = Math.log(value); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.sqrt = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - newValues[i] = Math.sqrt(value); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.square = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - newValues[i] = value * value; - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.relu = function (x) { - var res = ops.zeros(x.shape, x.dtype); - var resVals = res.dataSync(); - var inVals = x.dataSync(); - for (var i = 0; i < inVals.length; ++i) { - var val = inVals[i]; - if (util.isValNaN(val, x.dtype)) { - resVals[i] = util.getNaN(res.dtype); - } - else { - resVals[i] = Math.max(0, inVals[i]); - } - } - return res; - }; - MathBackendCPU.prototype.elu = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = v; - } - else { - resultValues[i] = (Math.exp(v) - 1); - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.eluDer = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = 1; - } - else { - resultValues[i] = Math.exp(v); - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.selu = function (x) { - var scaleAlpha = selu_util.SELU_SCALEALPHA; - var scale = selu_util.SELU_SCALE; - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = scale * v; - } - else { - resultValues[i] = scaleAlpha * (Math.exp(v) - 1); - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.leakyRelu = function (x, alpha) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; i++) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = v; - } - else { - resultValues[i] = alpha * v; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.prelu = function (x, alpha) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - var alphas = alpha.dataSync(); - for (var i = 0; i < values.length; i++) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = v; - } - else { - resultValues[i] = alphas[i] * v; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.preluDer = function (x, alpha) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - var alphas = alpha.dataSync(); - for (var i = 0; i < values.length; i++) { - var v = values[i]; - if (v > 0) { - resultValues[i] = 1; - } - else if (v < 0) { - resultValues[i] = alphas[i]; - } - else { - resultValues[i] = v; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.clip = function (x, min, max) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.min(max, Math.max(min, values[i])); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.abs = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.abs(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.int = function (x) { - var resultValues = new Int32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = values[i]; - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }, 'int32'); - }; - MathBackendCPU.prototype.sigmoid = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = 1 / (1 + Math.exp(-values[i])); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.sin = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.sin(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.cos = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.cos(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.tan = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.tan(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.asin = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.asin(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.acos = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.acos(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.atan = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.atan(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.sinh = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.sinh(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.cosh = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.cosh(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.tanh = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = util.tanh(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.step = function (x, alpha) { - if (alpha === void 0) { alpha = 0; } - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - if (util.isValNaN(value, x.dtype)) { - resultValues[i] = util.getNaN(x.dtype); - } - else { - resultValues[i] = value > 0 ? 1 : alpha; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.conv2d = function (x, filter, convInfo) { - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = convInfo.padInfo.left; - var padTop = convInfo.padInfo.top; - var y = ops.buffer(convInfo.outShape, x.dtype); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d2 = 0; d2 < convInfo.outChannels; ++d2) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * convInfo.strideHeight - padLeft; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * convInfo.strideWidth - padTop; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - var dotProd = 0; - for (var xR = xRMin; xR < xRMax; ++xR) { - var wR = xR - xRCorner; - for (var xC = xCMin; xC < xCMax; ++xC) { - var wC = xC - xCCorner; - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - var pixel = x.get(b, xR, xC, d1); - var weight = filter.get(wR, wC, d1, d2); - dotProd += pixel * weight; - } - } - } - y.set(dotProd, b, yR, yC, d2); - } - } - } - } - return y.toTensor(); - }; - MathBackendCPU.prototype.conv2dDerInput = function (dy, filter, convInfo) { - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var topPad = filterHeight - 1 - convInfo.padInfo.top; - var leftPad = filterWidth - 1 - convInfo.padInfo.left; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var dx = ops.buffer(convInfo.inShape, 'float32'); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - for (var xR = 0; xR < convInfo.inHeight; ++xR) { - var xRCorner = xR - leftPad; - var xRMin = Math.max(0, Math.ceil(xRCorner / strideHeight)); - var yRMax = Math.min(convInfo.outHeight, (filterHeight + xRCorner) / strideHeight); - for (var xC = 0; xC < convInfo.inWidth; ++xC) { - var xCCorner = xC - topPad; - var xCMin = Math.max(0, Math.ceil(xCCorner / strideWidth)); - var yCMax = Math.min(convInfo.outWidth, (filterWidth + xCCorner) / strideWidth); - var dotProd = 0; - for (var yR = xRMin; yR < yRMax; ++yR) { - var wR = yR * strideHeight - xRCorner; - for (var yC = xCMin; yC < yCMax; ++yC) { - var wC = yC * strideWidth - xCCorner; - for (var d2 = 0; d2 < convInfo.outChannels; ++d2) { - var pixel = dy.get(b, yR, yC, d2); - var weight = filter.get(filterHeight - 1 - wR, filterWidth - 1 - wC, d1, d2); - dotProd += pixel * weight; - } - } - } - dx.set(dotProd, b, xR, xC, d1); - } - } - } - } - return dx.toTensor(); - }; - MathBackendCPU.prototype.conv2dDerFilter = function (x, dy, convInfo) { - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var dW = ops.buffer(convInfo.filterShape, 'float32'); - var leftPad = convInfo.padInfo.left; - var topPad = convInfo.padInfo.top; - for (var wR = 0; wR < filterHeight; ++wR) { - var yRMin = Math.max(0, Math.ceil((topPad - wR) / strideHeight)); - var yRMax = Math.min(convInfo.outHeight, (convInfo.inHeight + topPad - wR) / strideHeight); - for (var wC = 0; wC < filterWidth; ++wC) { - var yCMin = Math.max(0, Math.ceil((leftPad - wC) / strideWidth)); - var yCMax = Math.min(convInfo.outWidth, (convInfo.inWidth + leftPad - wC) / strideWidth); - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - for (var d2 = 0; d2 < convInfo.outChannels; ++d2) { - var dotProd = 0; - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var yR = yRMin; yR < yRMax; ++yR) { - var xR = wR + yR * strideHeight - topPad; - for (var yC = yCMin; yC < yCMax; ++yC) { - var xC = wC + yC * strideWidth - leftPad; - dotProd += x.get(b, xR, xC, d1) * dy.get(b, yR, yC, d2); - } - } - } - dW.set(dotProd, wR, wC, d1, d2); - } - } - } - } - return dW.toTensor(); - }; - MathBackendCPU.prototype.depthwiseConv2D = function (x, filter, convInfo) { - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = convInfo.padInfo.left; - var padTop = convInfo.padInfo.top; - var chMul = convInfo.outChannels / convInfo.inChannels; - var y = ops.buffer(convInfo.outShape, x.dtype); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * convInfo.strideHeight - padLeft; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * convInfo.strideWidth - padTop; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - for (var q = 0; q < chMul; ++q) { - var dotProd = 0; - for (var xR = xRMin; xR < xRMax; ++xR) { - var wR = xR - xRCorner; - for (var xC = xCMin; xC < xCMax; ++xC) { - var wC = xC - xCCorner; - var pixel = x.get(b, xR, xC, d1); - var weight = filter.get(wR, wC, d1, q); - dotProd += pixel * weight; - } - } - y.set(dotProd, b, yR, yC, d1 * chMul + q); - } - } - } - } - } - return y.toTensor(); - }; - MathBackendCPU.prototype.tile = function (x, reps) { - var newShape = new Array(x.rank); - for (var i = 0; i < newShape.length; i++) { - newShape[i] = x.shape[i] * reps[i]; - } - var result = ops.buffer(newShape, x.dtype); - var values = x.dataSync(); - for (var i = 0; i < result.values.length; ++i) { - var newLoc = result.indexToLoc(i); - var originalLoc = new Array(x.rank); - for (var i_1 = 0; i_1 < originalLoc.length; i_1++) { - originalLoc[i_1] = newLoc[i_1] % x.shape[i_1]; - } - var originalIndex = x.locToIndex(originalLoc); - result.values[i] = values[originalIndex]; - } - return result.toTensor(); - }; - MathBackendCPU.prototype.pad1D = function (x, paddings, constantValue) { - var leftPadding = paddings[0]; - var rightPadding = paddings[1]; - var values = x.dataSync(); - var result = ops.zeros([leftPadding + values.length + rightPadding], x.dtype); - var newValues = result.dataSync(); - var z = 0; - for (var i = 0; i < newValues.length; i++) { - if (i >= leftPadding && i < leftPadding + values.length) { - newValues[i] = values[z++]; - } - else { - newValues[i] = constantValue; - } - } - return result; - }; - MathBackendCPU.prototype.pad2D = function (x, paddings, constantValue) { - var topPadding = paddings[0][0]; - var bottomPadding = paddings[0][1]; - var leftPadding = paddings[1][0]; - var rightPadding = paddings[1][1]; - var newShape = [ - topPadding + x.shape[0] + bottomPadding, - leftPadding + x.shape[1] + rightPadding - ]; - var result = ops.zeros(newShape, x.dtype); - var newValues = result.dataSync(); - var values = x.dataSync(); - var z = 0; - for (var i = 0; i < newShape[0]; i++) { - var rangeStart = -1; - var rangeEnd = -1; - if (i >= topPadding && i < newShape[0] - bottomPadding) { - rangeStart = i * newShape[1] + leftPadding; - rangeEnd = rangeStart + x.shape[1] - 1; - } - for (var j = 0; j < newShape[1]; j++) { - var v = i * newShape[1] + j; - if (v >= rangeStart && v <= rangeEnd) { - newValues[v] = values[z++]; - } - else { - newValues[v] = constantValue; - } - } - } - return result; - }; - MathBackendCPU.prototype.transpose = function (x, perm) { - var newShape = new Array(x.rank); - for (var i = 0; i < newShape.length; i++) { - newShape[i] = x.shape[perm[i]]; - } - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - var result = tensor_1.Tensor.make(newShape, { values: resultValues }); - for (var i = 0; i < x.size; ++i) { - var loc = x.indexToLoc(i); - var newLoc = new Array(loc.length); - for (var i_2 = 0; i_2 < newLoc.length; i_2++) { - newLoc[i_2] = loc[perm[i_2]]; - } - var newIndex = result.locToIndex(newLoc); - resultValues[newIndex] = values[i]; - } - return result; - }; - MathBackendCPU.prototype.gather = function (x, indices, axis) { - var newShape = x.shape.slice(); - var indicesValues = indices.dataSync(); - newShape[axis] = indicesValues.length; - var result = ops.zeros(newShape, x.dtype); - var values = x.dataSync(); - var resultValues = result.dataSync(); - for (var i = 0; i < result.size; ++i) { - var newLoc = result.indexToLoc(i); - var originalLoc = newLoc.slice(); - originalLoc[axis] = indicesValues[newLoc[axis]]; - var originalIndex = x.locToIndex(originalLoc); - resultValues[i] = values[originalIndex]; - } - return result; - }; - MathBackendCPU.prototype.pool = function (x, convInfo, poolType) { - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var y = ops.buffer(convInfo.outShape, 'float32'); - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * strideHeight - padTop; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * strideWidth - padLeft; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - var minMaxValue = (poolType === 'max' ? Number.NEGATIVE_INFINITY : - Number.POSITIVE_INFINITY); - var avgValue = 0; - for (var xR = xRMin; xR < xRMax; ++xR) { - for (var xC = xCMin; xC < xCMax; ++xC) { - var pixel = x.get(b, xR, xC, d); - if (isNaN(pixel)) { - minMaxValue = NaN; - avgValue = NaN; - break; - } - if ((poolType === 'max' && pixel > minMaxValue) || - (poolType === 'min' && pixel < minMaxValue)) { - minMaxValue = pixel; - } - else if (poolType === 'avg') { - avgValue += pixel / (filterHeight * filterWidth); - } - } - if (isNaN(minMaxValue)) { - break; - } - } - y.set(poolType === 'avg' ? avgValue : minMaxValue, b, yR, yC, d); - } - } - } - } - return y.toTensor(); - }; - MathBackendCPU.prototype.maxPool = function (x, convInfo) { - return this.pool(x, convInfo, 'max'); - }; - MathBackendCPU.prototype.maxPoolPositions = function (x, convInfo) { - var maxPositions = ops.buffer(convInfo.outShape, 'int32'); - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * strideHeight - padTop; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * strideWidth - padLeft; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - var maxValue = Number.NEGATIVE_INFINITY; - var maxPosition = -1; - for (var xR = xRMin; xR < xRMax; ++xR) { - var wR = xR - xRCorner; - for (var xC = xCMin; xC < xCMax; ++xC) { - var wC = xC - xCCorner; - var pixel = x.get(b, xR, xC, d); - if (pixel > maxValue) { - maxValue = pixel; - maxPosition = wR * filterWidth + wC; - } - } - } - maxPositions.set(maxPosition, b, yR, yC, d); - } - } - } - } - return maxPositions.toTensor(); - }; - MathBackendCPU.prototype.maxPoolBackprop = function (dy, x, convInfo) { - var maxPositions = this.maxPoolPositions(x, convInfo); - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var dx = ops.buffer(x.shape, 'float32'); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var dxR = 0; dxR < convInfo.inHeight; ++dxR) { - for (var dxC = 0; dxC < convInfo.inWidth; ++dxC) { - var dyRCorner = dxR - padTop; - var dyCCorner = dxC - padLeft; - var dotProd = 0; - for (var wR = 0; wR < filterHeight; ++wR) { - var dyR = (dyRCorner + wR) / strideHeight; - if (dyR < 0 || dyR >= convInfo.outHeight || - Math.floor(dyR) !== dyR) { - continue; - } - for (var wC = 0; wC < filterWidth; ++wC) { - var dyC = (dyCCorner + wC) / strideWidth; - if (dyC < 0 || dyC >= convInfo.outWidth || - Math.floor(dyC) !== dyC) { - continue; - } - var maxPos = filterHeight * filterWidth - 1 - - maxPositions.get(b, dyR, dyC, d); - var curPos = wR * filterWidth + wC; - var mask = maxPos === curPos ? 1 : 0; - if (mask === 0) { - continue; - } - var pixel = dy.get(b, dyR, dyC, d); - dotProd += pixel * mask; - } - } - dx.set(dotProd, b, dxR, dxC, d); - } - } - } - } - return dx.toTensor(); - }; - MathBackendCPU.prototype.avgPoolBackprop = function (dy, x, convInfo) { - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var dx = ops.buffer(x.shape, 'float32'); - var avgMultiplier = 1 / (filterHeight * filterWidth); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var dxR = 0; dxR < convInfo.inHeight; ++dxR) { - for (var dxC = 0; dxC < convInfo.inWidth; ++dxC) { - var dyRCorner = dxR - padTop; - var dyCCorner = dxC - padLeft; - var dotProd = 0; - for (var wR = 0; wR < filterHeight; ++wR) { - var dyR = (dyRCorner + wR) / strideHeight; - if (dyR < 0 || dyR >= convInfo.outHeight || - Math.floor(dyR) !== dyR) { - continue; - } - for (var wC = 0; wC < filterWidth; ++wC) { - var dyC = (dyCCorner + wC) / strideWidth; - if (dyC < 0 || dyC >= convInfo.outWidth || - Math.floor(dyC) !== dyC) { - continue; - } - var pixel = dy.get(b, dyR, dyC, d); - dotProd += pixel; - } - } - dx.set(dotProd * avgMultiplier, b, dxR, dxC, d); - } - } - } - } - return dx.toTensor(); - }; - MathBackendCPU.prototype.minPool = function (x, convInfo) { - return this.pool(x, convInfo, 'min'); - }; - MathBackendCPU.prototype.avgPool = function (x, convInfo) { - return this.pool(x, convInfo, 'avg').toFloat(); - }; - MathBackendCPU.prototype.resizeBilinear = function (x, newHeight, newWidth, alignCorners) { - var _a = x.shape, batch = _a[0], oldHeight = _a[1], oldWidth = _a[2], numChannels = _a[3]; - var output = ops.buffer([batch, newHeight, newWidth, numChannels], x.dtype); - var effectiveInputSize = alignCorners ? [oldHeight - 1, oldWidth - 1] : [oldHeight, oldWidth]; - var effectiveOutputSize = alignCorners ? [newHeight - 1, newWidth - 1] : [newHeight, newWidth]; - for (var b = 0; b < batch; b++) { - for (var r = 0; r < newHeight; r++) { - for (var c = 0; c < newWidth; c++) { - for (var d = 0; d < numChannels; d++) { - var sourceFracRow = (effectiveInputSize[0]) * r / (effectiveOutputSize[0]); - var sourceFracCol = (effectiveInputSize[1]) * c / (effectiveOutputSize[1]); - var sourceRowFloor = Math.floor(sourceFracRow); - var sourceRowCeil = Math.min(oldHeight - 1, Math.ceil(sourceFracRow)); - var sourceColFloor = Math.floor(sourceFracCol); - var sourceColCeil = Math.min(oldWidth - 1, Math.ceil(sourceFracCol)); - var topLeft = x.get(b, sourceRowFloor, sourceColFloor, d); - var bottomLeft = x.get(b, sourceRowCeil, sourceColFloor, d); - var topRight = x.get(b, sourceRowFloor, sourceColCeil, d); - var bottomRight = x.get(b, sourceRowCeil, sourceColCeil, d); - var rowFrac = sourceFracRow - sourceRowFloor; - var colFrac = sourceFracCol - sourceColFloor; - var top_1 = topLeft + (topRight - topLeft) * colFrac; - var bottom = bottomLeft + (bottomRight - bottomLeft) * colFrac; - var newValue = top_1 + (bottom - top_1) * rowFrac; - output.set(newValue, b, r, c, d); - } - } - } - } - return output.toTensor(); - }; - MathBackendCPU.prototype.batchNormalization4D = function (x, mean, variance, varianceEpsilon, scale, offset) { - var xValues = x.dataSync(); - var meanValues = mean.dataSync(); - var varianceValues = variance.dataSync(); - var scaleValues = scale ? scale.dataSync() : new Float32Array([1]); - var offsetValues = offset ? offset.dataSync() : new Float32Array([0]); - var outValues = new Float32Array(xValues.length); - for (var i = 0; i < xValues.length; i++) { - outValues[i] = offsetValues[i % offsetValues.length] + - (xValues[i] - meanValues[i % meanValues.length]) * - scaleValues[i % scaleValues.length] / - Math.sqrt(varianceValues[i % varianceValues.length] + varianceEpsilon); - } - return ops_1.tensor4d(outValues, x.shape); - }; - MathBackendCPU.prototype.localResponseNormalization4D = function (x, radius, bias, alpha, beta, normRegion) { - var output = ops.buffer(x.shape, 'float32'); - var rad = radius; - var maxW = output.shape[1] - 1; - var maxH = output.shape[2] - 1; - var maxD = output.shape[3] - 1; - var sumAcrossChannels = function (b, r, c, d) { - var sum = 0.0; - for (var j = Math.max(0, d - rad); j <= Math.min(d + rad, maxD); j++) { - var z = x.get(b, r, c, j); - sum += z * z; - } - return sum; - }; - var sumWithinChannel = function (b, r, c, d) { - var sum = 0.0; - for (var u = Math.max(0, r - rad); u <= Math.min(r + rad, maxW); u++) { - for (var v = Math.max(0, c - rad); v <= Math.min(c + rad, maxH); v++) { - sum += Math.pow(x.get(b, u, v, d), 2); - } - } - return sum; - }; - for (var b = 0; b < output.shape[0]; b++) { - for (var r = 0; r <= output.shape[1]; r++) { - for (var c = 0; c < output.shape[2]; c++) { - for (var d = 0; d < output.shape[3]; d++) { - var sum = normRegion === 'withinChannel' ? - sumWithinChannel(b, r, c, d) : - sumAcrossChannels(b, r, c, d); - var val = x.get(b, r, c, d) * Math.pow(bias + alpha * sum, -beta); - output.set(val, b, r, c, d); - } - } - } - } - return output.toTensor(); - }; - MathBackendCPU.prototype.multinomial = function (probabilities, numSamples, seed) { - var batchSize = probabilities.shape[0]; - var numEvents = probabilities.shape[1]; - var res = ops.zeros([batchSize, numSamples], 'int32'); - var resVals = res.dataSync(); - var probVals = probabilities.dataSync(); - for (var b = 0; b < batchSize; ++b) { - var offset = b * numEvents; - var cdf = new Float32Array(numEvents - 1); - cdf[0] = probVals[offset]; - for (var event_1 = 1; event_1 < cdf.length; ++event_1) { - cdf[event_1] = cdf[event_1 - 1] + probVals[offset + event_1]; - } - var random = seedrandom.alea(seed.toString()); - var outOffset = b * numSamples; - for (var sampleId = 0; sampleId < numSamples; ++sampleId) { - var r = random(); - resVals[outOffset + sampleId] = cdf.length; - for (var event_2 = 0; event_2 < cdf.length; event_2++) { - if (r < cdf[event_2]) { - resVals[outOffset + sampleId] = event_2; - break; - } - } - } - } - return res; - }; - MathBackendCPU.prototype.oneHot = function (indices, depth, onValue, offValue) { - var res = new Float32Array(indices.size * depth); - res.fill(offValue); - for (var event_3 = 0; event_3 < indices.size; ++event_3) { - res[event_3 * depth + indices.get(event_3)] = onValue; - } - return ops.tensor2d(res, [indices.size, depth]); - }; - MathBackendCPU.prototype.broadcastedBinaryOp = function (a, b, dtype, op) { - var newShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var result = ops.buffer(newShape, dtype); - var aValues = a.dataSync(); - var bValues = b.dataSync(); - var aBroadcastDims = broadcast_util.getBroadcastDims(a.shape, newShape); - var bBroadcastDims = broadcast_util.getBroadcastDims(b.shape, newShape); - var _loop_1 = function (i) { - var loc = result.indexToLoc(i); - var aLoc = loc.slice(-a.rank); - aBroadcastDims.forEach(function (d) { return aLoc[d] = 0; }); - var aIndex = a.locToIndex(aLoc); - var bLoc = loc.slice(-b.rank); - bBroadcastDims.forEach(function (d) { return bLoc[d] = 0; }); - var bIndex = b.locToIndex(bLoc); - result.values[i] = op(aValues[aIndex], bValues[bIndex]); - }; - for (var i = 0; i < result.values.length; ++i) { - _loop_1(i); - } - return result.toTensor(); - }; - MathBackendCPU.prototype.dispose = function () { }; - return MathBackendCPU; -}()); -exports.MathBackendCPU = MathBackendCPU; -environment_1.ENV.registerBackend('cpu', function () { return new MathBackendCPU(); }); -var NDArrayMathCPU = (function (_super) { - __extends(NDArrayMathCPU, _super); - function NDArrayMathCPU(safeMode) { - if (safeMode === void 0) { safeMode = false; } - var _this = this; - console.warn('new NDArrayMathCPU() is deprecated. Please use ' + - 'dl.setBackend(\'cpu\').'); - _this = _super.call(this, 'cpu', safeMode) || this; - return _this; - } - return NDArrayMathCPU; -}(math_1.NDArrayMath)); -exports.NDArrayMathCPU = NDArrayMathCPU; - -},{"../environment":34,"../math":105,"../ops/axis_util":107,"../ops/broadcast_util":110,"../ops/concat_util":113,"../ops/ops":123,"../ops/selu_util":129,"../tensor":146,"../types":150,"../util":151,"seedrandom":153}],69:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var math_1 = require("../math"); -var axis_util = require("../ops/axis_util"); -var reduce_util = require("../ops/reduce_util"); -var tensor_1 = require("../tensor"); -var types = require("../types"); -var util = require("../util"); -var argminmax_gpu_1 = require("./webgl/argminmax_gpu"); -var avg_pool_backprop_gpu_1 = require("./webgl/avg_pool_backprop_gpu"); -var batchnorm_gpu_1 = require("./webgl/batchnorm_gpu"); -var binaryop_gpu = require("./webgl/binaryop_gpu"); -var binaryop_gpu_1 = require("./webgl/binaryop_gpu"); -var clip_gpu_1 = require("./webgl/clip_gpu"); -var concat_gpu_1 = require("./webgl/concat_gpu"); -var conv_backprop_gpu_1 = require("./webgl/conv_backprop_gpu"); -var conv_gpu_1 = require("./webgl/conv_gpu"); -var conv_gpu_depthwise_1 = require("./webgl/conv_gpu_depthwise"); -var from_pixels_gpu_1 = require("./webgl/from_pixels_gpu"); -var gather_gpu_1 = require("./webgl/gather_gpu"); -var gpgpu_context_1 = require("./webgl/gpgpu_context"); -var gpgpu_math = require("./webgl/gpgpu_math"); -var logical_gpu_1 = require("./webgl/logical_gpu"); -var lrn_gpu_1 = require("./webgl/lrn_gpu"); -var max_pool_backprop_gpu_1 = require("./webgl/max_pool_backprop_gpu"); -var mulmat_gpu_1 = require("./webgl/mulmat_gpu"); -var multinomial_gpu_1 = require("./webgl/multinomial_gpu"); -var onehot_gpu_1 = require("./webgl/onehot_gpu"); -var pad_gpu_1 = require("./webgl/pad_gpu"); -var pool_gpu_1 = require("./webgl/pool_gpu"); -var reduce_gpu_1 = require("./webgl/reduce_gpu"); -var resize_bilinear_gpu_1 = require("./webgl/resize_bilinear_gpu"); -var reverse_gpu_1 = require("./webgl/reverse_gpu"); -var slice_gpu_1 = require("./webgl/slice_gpu"); -var tex_util_1 = require("./webgl/tex_util"); -var texture_manager_1 = require("./webgl/texture_manager"); -var tile_gpu_1 = require("./webgl/tile_gpu"); -var transpose_gpu_1 = require("./webgl/transpose_gpu"); -var unary_op = require("./webgl/unaryop_gpu"); -var unaryop_gpu_1 = require("./webgl/unaryop_gpu"); -var webgl_util = require("./webgl/webgl_util"); -var MathBackendWebGL = (function () { - function MathBackendWebGL(gpgpu, delayedStorage) { - if (delayedStorage === void 0) { delayedStorage = true; } - this.gpgpu = gpgpu; - this.delayedStorage = delayedStorage; - this.texData = new WeakMap(); - this.uploadWaitMs = 0; - this.downloadWaitMs = 0; - this.binaryCache = {}; - this.disposed = false; - if (environment_1.ENV.get('WEBGL_VERSION') < 1) { - throw new Error('WebGL is not supported on this device'); - } - if (gpgpu == null) { - this.gpgpu = new gpgpu_context_1.GPGPUContext(); - this.gpgpuCreatedLocally = true; - } - else { - this.gpgpuCreatedLocally = false; - } - if (typeof document !== 'undefined') { - this.canvas = document.createElement('canvas'); - } - this.textureManager = new texture_manager_1.TextureManager(this.gpgpu); - } - MathBackendWebGL.prototype.register = function (dataId, shape, dtype) { - if (this.texData.has(dataId)) { - throw new Error('Data buffer is already registered'); - } - this.texData.set(dataId, { - shape: shape, - dtype: dtype, - values: null, - texture: null, - texShape: null, - texType: tex_util_1.TextureType.FLOAT - }); - }; - MathBackendWebGL.prototype.fromPixels = function (pixels, numChannels) { - if (pixels == null) { - throw new Error('MathBackendWebGL.writePixels(): pixels can not be null'); - } - var texShape = [pixels.height, pixels.width]; - var outShape = [pixels.height, pixels.width, numChannels]; - if (pixels instanceof HTMLVideoElement) { - if (this.canvas == null) { - throw new Error('Can\'t read pixels from HTMLImageElement outside ' + - 'the browser.'); - } - this.canvas.width = pixels.width; - this.canvas.height = pixels.height; - this.canvas.getContext('2d').drawImage(pixels, 0, 0, pixels.width, pixels.height); - pixels = this.canvas; - } - var tempPixelArray = tensor_1.Tensor.make(texShape, {}, 'int32'); - this.texData.get(tempPixelArray.dataId).texType = tex_util_1.TextureType.UNSIGNED_BYTE; - this.gpgpu.uploadPixelDataToTexture(this.getTexture(tempPixelArray.dataId), pixels); - var program = new from_pixels_gpu_1.FromPixelsProgram(outShape); - var res = this.compileAndRun(program, [tempPixelArray]); - tempPixelArray.dispose(); - return res; - }; - MathBackendWebGL.prototype.write = function (dataId, values) { - if (values == null) { - throw new Error('MathBackendWebGL.write(): values can not be null'); - } - this.throwIfNoData(dataId); - var texData = this.texData.get(dataId); - var texture = texData.texture, texShape = texData.texShape, texType = texData.texType; - if (texture != null) { - this.textureManager.releaseTexture(texture, texShape, texType); - texData.texture = null; - texData.texShape = null; - } - texData.values = values; - if (!this.delayedStorage) { - this.uploadToGPU(dataId); - } - }; - MathBackendWebGL.prototype.readSync = function (dataId) { - this.throwIfNoData(dataId); - var texData = this.texData.get(dataId); - var texture = texData.texture, values = texData.values, texShape = texData.texShape; - if (values != null) { - this.cacheOnCPU(dataId); - return values; - } - var shouldTimeProgram = this.activeTimers != null; - var start; - if (shouldTimeProgram) { - start = performance.now(); - } - var float32Values = this.gpgpu.downloadMatrixFromTexture(texture, texShape[0], texShape[1]); - if (shouldTimeProgram) { - this.downloadWaitMs += performance.now() - start; - } - this.cacheOnCPU(dataId, float32Values); - return texData.values; - }; - MathBackendWebGL.prototype.read = function (dataId) { - return __awaiter(this, void 0, void 0, function () { - var texData, texture, values, texShape, float32Values; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.throwIfNoData(dataId); - texData = this.texData.get(dataId); - texture = texData.texture, values = texData.values, texShape = texData.texShape; - if (values != null) { - this.cacheOnCPU(dataId); - return [2, values]; - } - if (!environment_1.ENV.get('WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED')) return [3, 2]; - return [4, this.gpgpu.downloadMatrixFromTextureAsync(texture, texShape[0], texShape[1])]; - case 1: - float32Values = _a.sent(); - this.cacheOnCPU(dataId, float32Values); - return [2, texData.values]; - case 2: - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 0) { - return [2, this.readSync(dataId)]; - } - return [4, this.gpgpu.runQuery(function () { })]; - case 3: - _a.sent(); - return [2, this.readSync(dataId)]; - } - }); - }); - }; - MathBackendWebGL.prototype.time = function (f) { - return __awaiter(this, void 0, void 0, function () { - var oldActiveTimers, newActiveTimers, outerMostTime, flattenedActiveTimers, kernelMs, res; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - oldActiveTimers = this.activeTimers; - newActiveTimers = []; - outerMostTime = false; - if (this.programTimersStack == null) { - this.programTimersStack = newActiveTimers; - outerMostTime = true; - } - else { - this.activeTimers.push(newActiveTimers); - } - this.activeTimers = newActiveTimers; - f(); - flattenedActiveTimers = util.flatten(this.activeTimers); - this.activeTimers = oldActiveTimers; - if (outerMostTime) { - this.programTimersStack = null; - } - return [4, Promise.all(flattenedActiveTimers).then(function (results) { - var sum = 0; - results.forEach(function (result) { return sum += result; }); - return sum; - })]; - case 1: - kernelMs = _a.sent(); - res = { - uploadWaitMs: this.uploadWaitMs, - downloadWaitMs: this.downloadWaitMs, - kernelMs: kernelMs, - wallMs: null - }; - this.uploadWaitMs = 0; - this.downloadWaitMs = 0; - return [2, res]; - } - }); - }); - }; - MathBackendWebGL.prototype.memory = function () { - return { unreliable: false }; - }; - MathBackendWebGL.prototype.startTimer = function () { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) { - return this.gpgpu.beginQuery(); - } - return { startMs: performance.now(), endMs: null }; - }; - MathBackendWebGL.prototype.endTimer = function (query) { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) { - this.gpgpu.endQuery(); - return query; - } - query.endMs = performance.now(); - return query; - }; - MathBackendWebGL.prototype.getQueryTime = function (query) { - return __awaiter(this, void 0, void 0, function () { - var timerQuery; - return __generator(this, function (_a) { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) { - return [2, this.gpgpu.pollQueryTime(query)]; - } - timerQuery = query; - return [2, timerQuery.endMs - timerQuery.startMs]; - }); - }); - }; - MathBackendWebGL.prototype.disposeData = function (dataId) { - if (this.texData.has(dataId)) { - var _a = this.texData.get(dataId), texture = _a.texture, texShape = _a.texShape, texType = _a.texType; - if (texture != null) { - this.textureManager.releaseTexture(texture, texShape, texType); - } - this.texData.delete(dataId); - } - }; - MathBackendWebGL.prototype.getTexture = function (dataId) { - this.uploadToGPU(dataId); - return this.texData.get(dataId).texture; - }; - MathBackendWebGL.prototype.getTextureData = function (dataId) { - this.uploadToGPU(dataId); - return this.texData.get(dataId); - }; - MathBackendWebGL.prototype.getGPGPUContext = function () { - return this.gpgpu; - }; - MathBackendWebGL.prototype.slice1D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram([size]); - var customSetup = program.getCustomSetupFunc([begin]); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.slice2D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram(size); - var customSetup = program.getCustomSetupFunc(begin); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.slice3D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram(size); - var customSetup = program.getCustomSetupFunc(begin); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.slice4D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram(size); - var customSetup = program.getCustomSetupFunc(begin); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.reverse4D = function (x, axis) { - var program = new reverse_gpu_1.ReverseProgram(x.shape, axis); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.concat = function (a, b) { - var program = new concat_gpu_1.ConcatProgram(a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.neg = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.NEG); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.matMul = function (a, b, transposeA, transposeB) { - var program = new mulmat_gpu_1.MatMulProgram(a.shape, b.shape, transposeA, transposeB); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.multiply = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MUL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.batchNormalization4D = function (x, mean, variance, varianceEpsilon, scale, offset) { - var inputs = [x, mean, variance]; - var offsetShape = null; - if (offset != null) { - offsetShape = offset.shape; - inputs.push(offset); - } - var scaleShape = null; - if (scale != null) { - scaleShape = scale.shape; - inputs.push(scale); - } - var program = new batchnorm_gpu_1.BatchNormProgram(x.shape, mean.shape, variance.shape, offsetShape, scaleShape, varianceEpsilon); - return this.compileAndRun(program, inputs); - }; - MathBackendWebGL.prototype.localResponseNormalization4D = function (x, radius, bias, alpha, beta, normRegion) { - var program = new lrn_gpu_1.LRNProgram(x.shape, radius, bias, alpha, beta, normRegion); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.tile = function (x, reps) { - var program = new tile_gpu_1.TileProgram(x.shape, reps); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.pad1D = function (x, paddings, constantValue) { - var program = new pad_gpu_1.Pad1DProgram(x.shape, paddings, constantValue); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.pad2D = function (x, paddings, constantValue) { - var program = new pad_gpu_1.Pad2DProgram(x.shape, paddings, constantValue); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.transpose = function (x, perm) { - var program = new transpose_gpu_1.TransposeProgram(x.shape, perm); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.gather = function (x, indices, axis) { - var program = new gather_gpu_1.GatherProgram(x.shape, indices.size, axis); - return this.compileAndRun(program, [x, indices]); - }; - MathBackendWebGL.prototype.reduce = function (x, reduceType, dtype) { - var batchSize = x.shape[0]; - var inSize = x.shape[1]; - var windowSize = reduce_util.computeOptimalWindowSize(inSize); - var reduceInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize }; - var program = new reduce_gpu_1.ReduceProgram(reduceInfo, reduceType); - var _a = program.outputShape, rows = _a[0], cols = _a[1]; - var output = this.makeOutputArray([rows, cols], dtype); - this.compileAndRun(program, [x], output); - if (output.shape[1] === 1) { - return output; - } - return this.reduce(output, reduceType, dtype); - }; - MathBackendWebGL.prototype.argReduce = function (x, reduceType, bestIndicesA) { - if (bestIndicesA === void 0) { bestIndicesA = null; } - var batchSize = x.shape[0]; - var inSize = x.shape[1]; - if (bestIndicesA != null) { - batchSize = bestIndicesA.shape[0]; - inSize = bestIndicesA.shape[1]; - } - var windowSize = reduce_util.computeOptimalWindowSize(inSize); - var reduceInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize }; - var program = new argminmax_gpu_1.ArgMinMaxProgram(reduceInfo, reduceType, bestIndicesA == null); - var _a = program.outputShape, rows = _a[0], cols = _a[1]; - var output = this.makeOutputArray([rows, cols], 'int32'); - var inputs = [x]; - if (bestIndicesA != null) { - inputs.push(bestIndicesA); - } - this.compileAndRun(program, inputs, output); - if (output.shape[1] === 1) { - return output; - } - return this.argReduce(x, reduceType, output); - }; - MathBackendWebGL.prototype.sum = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('sum', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - var outputDType = types.sumOutType(x.dtype); - return this.reduce(a2D, 'sum', outputDType).reshape(outShape); - }; - MathBackendWebGL.prototype.argMin = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMin', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.argReduce(a2D, 'min').reshape(outShape); - }; - MathBackendWebGL.prototype.argMax = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMax', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.argReduce(a2D, 'max').reshape(outShape); - }; - MathBackendWebGL.prototype.equal = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.notEqual = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.NOT_EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.less = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LESS, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.lessEqual = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LESS_EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.greater = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.GREATER, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.greaterEqual = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.GREATER_EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.logicalNot = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOGICAL_NOT); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.logicalAnd = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_AND, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.logicalOr = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_OR, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.logicalXor = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_XOR, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.where = function (condition, a, b, dtype) { - var program = new logical_gpu_1.WhereProgram(condition.rank, a.shape, a.rank); - var output = this.makeOutputArray(program.outputShape, dtype); - return this.compileAndRun(program, [condition, a, b], output); - }; - MathBackendWebGL.prototype.topKValues = function (x, k) { - throw new Error('topKValues GPU not yet implemented!'); - }; - MathBackendWebGL.prototype.topKIndices = function (x, k) { - throw new Error('topKIndices GPU not yet implemented!'); - }; - MathBackendWebGL.prototype.min = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('min', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.reduce(a2D, 'min', a2D.dtype).reshape(outShape); - }; - MathBackendWebGL.prototype.minimum = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MIN, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.max = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('max', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.reduce(a2D, 'max', a2D.dtype).reshape(outShape); - }; - MathBackendWebGL.prototype.maximum = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MAX, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.divide = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.DIV, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'float32'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.add = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.ADD, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.subtract = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.SUB, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.pow = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.POW, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.ceil = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.CEIL); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.floor = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.FLOOR); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.exp = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.EXP); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.log = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOG); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sqrt = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SQRT); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.square = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SQUARE); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.relu = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.RELU); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.elu = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ELU); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.eluDer = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ELU_DER); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.selu = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SELU); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.leakyRelu = function (x, alpha) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LEAKY_RELU(alpha)); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.prelu = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.PRELU, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.preluDer = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.PRELU_DER, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.int = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TO_INT); - var output = this.makeOutputArray(program.outputShape, 'int32'); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.clip = function (x, min, max) { - var program = new clip_gpu_1.ClipProgram(x.shape, min, max); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.abs = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ABS); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sigmoid = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIGMOID); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sin = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.cos = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.COS); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.tan = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TAN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.asin = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ASIN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.acos = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ACOS); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.atan = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ATAN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sinh = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SINH); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.cosh = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.COSH); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.tanh = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TANH); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.step = function (x, alpha) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.STEP(alpha)); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.conv2d = function (x, filter, convInfo) { - var program = new conv_gpu_1.Conv2DProgram(convInfo); - return this.compileAndRun(program, [x, filter]); - }; - MathBackendWebGL.prototype.conv2dDerInput = function (dy, filter, convInfo) { - var program = new conv_backprop_gpu_1.Conv2DDerInputProgram(convInfo); - return this.compileAndRun(program, [dy, filter]); - }; - MathBackendWebGL.prototype.conv2dDerFilter = function (x, dy, convInfo) { - var program = new conv_backprop_gpu_1.Conv2DDerFilterProgram(convInfo); - return this.compileAndRun(program, [x, dy]); - }; - MathBackendWebGL.prototype.depthwiseConv2D = function (x, filter, convInfo) { - var program = new conv_gpu_depthwise_1.DepthwiseConv2DProgram(convInfo); - return this.compileAndRun(program, [x, filter]); - }; - MathBackendWebGL.prototype.maxPool = function (x, convInfo) { - var program = new pool_gpu_1.Pool2DProgram(convInfo, 'max', false); - var output = this.makeOutputArray(program.outputShape, x.dtype); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.minPool = function (x, convInfo) { - var program = new pool_gpu_1.Pool2DProgram(convInfo, 'min', false); - var output = this.makeOutputArray(program.outputShape, x.dtype); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.avgPool = function (x, convInfo) { - var program = new pool_gpu_1.Pool2DProgram(convInfo, 'avg', false); - var output = this.makeOutputArray(program.outputShape, 'float32'); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.maxPoolBackprop = function (dy, x, convInfo) { - var getPositions = true; - var maxPoolPositionsProgram = new pool_gpu_1.Pool2DProgram(convInfo, 'max', getPositions); - var maxPoolPositions = this.compileAndRun(maxPoolPositionsProgram, [x]); - var maxPoolBackPropProgram = new max_pool_backprop_gpu_1.MaxPool2DBackpropProgram(convInfo); - var output = this.makeOutputArray(maxPoolBackPropProgram.outputShape, x.dtype); - var result = this.compileAndRun(maxPoolBackPropProgram, [dy, maxPoolPositions], output); - maxPoolPositions.dispose(); - return result; - }; - MathBackendWebGL.prototype.avgPoolBackprop = function (dy, x, convInfo) { - var avgPoolBackpropProgram = new avg_pool_backprop_gpu_1.AvgPool2DBackpropProgram(convInfo); - var output = this.makeOutputArray(avgPoolBackpropProgram.outputShape, x.dtype); - return this.compileAndRun(avgPoolBackpropProgram, [dy], output); - }; - MathBackendWebGL.prototype.resizeBilinear = function (x, newHeight, newWidth, alignCorners) { - var program = new resize_bilinear_gpu_1.ResizeBilinearProgram(x.shape, newHeight, newWidth, alignCorners); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.multinomial = function (probs, numSamples, seed) { - var batchSize = probs.shape[0]; - var numOutcomes = probs.shape[1]; - var program = new multinomial_gpu_1.MultinomialProgram(batchSize, numOutcomes, numSamples); - var output = this.makeOutputArray(program.outputShape, 'int32'); - var customSetup = program.getCustomSetupFunc(seed); - return this.compileAndRun(program, [probs], output, customSetup); - }; - MathBackendWebGL.prototype.oneHot = function (indices, depth, onValue, offValue) { - var program = new onehot_gpu_1.OneHotProgram(indices.size, depth, onValue, offValue); - return this.compileAndRun(program, [indices]); - }; - MathBackendWebGL.prototype.makeOutputArray = function (shape, dtype) { - return tensor_1.Tensor.make(shape, {}, dtype); - }; - MathBackendWebGL.prototype.compileAndRun = function (program, inputs, output, customSetup) { - var _this = this; - if (output == null) { - output = this.makeOutputArray(program.outputShape, inputs[0].dtype); - } - var inputsData = inputs.map(function (input) { - _this.uploadToGPU(input.dataId); - return { tensor: input, texData: _this.texData.get(input.dataId) }; - }); - this.uploadToGPU(output.dataId); - var outputData = { - tensor: output, - texData: this.texData.get(output.dataId) - }; - var key = gpgpu_math.makeShaderKey(program, inputsData, outputData); - var binary = this.getAndSaveBinary(key, function () { - return gpgpu_math.compileProgram(_this.gpgpu, program, inputsData, outputData); - }); - var shouldTimeProgram = this.activeTimers != null; - var query; - if (shouldTimeProgram) { - query = this.startTimer(); - } - gpgpu_math.runProgram(binary, inputsData, outputData, customSetup); - if (shouldTimeProgram) { - query = this.endTimer(query); - this.activeTimers.push(this.getQueryTime(query)); - } - return output; - }; - MathBackendWebGL.prototype.getAndSaveBinary = function (key, getBinary) { - if (!(key in this.binaryCache)) { - this.binaryCache[key] = getBinary(); - } - return this.binaryCache[key]; - }; - MathBackendWebGL.prototype.getTextureManager = function () { - return this.textureManager; - }; - MathBackendWebGL.prototype.dispose = function () { - if (this.disposed) { - return; - } - for (var key in this.binaryCache) { - this.gpgpu.deleteProgram(this.binaryCache[key].webGLProgram); - } - this.textureManager.dispose(); - this.canvas.remove(); - if (this.gpgpuCreatedLocally) { - this.gpgpu.dispose(); - } - this.disposed = true; - }; - MathBackendWebGL.prototype.throwIfNoData = function (dataId) { - if (!this.texData.has(dataId)) { - throw new Error("WebGL backend: No data found for this tensor. " + - "Did you change your backend in the middle of the program? " + - "New backends can't use Tensors created with previous backends"); - } - }; - MathBackendWebGL.prototype.uploadToGPU = function (dataId) { - this.throwIfNoData(dataId); - var texData = this.texData.get(dataId); - var shape = texData.shape, values = texData.values, texture = texData.texture, dtype = texData.dtype, texType = texData.texType; - if (texture != null) { - return; - } - var shouldTimeProgram = this.activeTimers != null; - var start; - if (shouldTimeProgram) { - start = performance.now(); - } - var texShape = webgl_util.getTextureShapeFromLogicalShape(this.gpgpu.gl, shape); - texData.texShape = texShape; - var newTexture = this.textureManager.acquireTexture(texShape, texType); - texData.texture = newTexture; - if (values != null) { - this.gpgpu.uploadMatrixToTexture(newTexture, texShape[0], texShape[1], typedArrayToFloat32(values, dtype)); - texData.values = null; - if (shouldTimeProgram) { - this.uploadWaitMs += performance.now() - start; - } - } - }; - MathBackendWebGL.prototype.cacheOnCPU = function (dataId, float32Values) { - var dontKeepCopyOnGPU = this.delayedStorage; - var texData = this.texData.get(dataId); - var texture = texData.texture, texShape = texData.texShape, dtype = texData.dtype, texType = texData.texType; - if (dontKeepCopyOnGPU && texture != null) { - this.textureManager.releaseTexture(texture, texShape, texType); - texData.texture = null; - texData.texShape = null; - } - if (float32Values != null) { - texData.values = float32ToTypedArray(float32Values, dtype); - } - }; - return MathBackendWebGL; -}()); -exports.MathBackendWebGL = MathBackendWebGL; -environment_1.ENV.registerBackend('webgl', function () { return new MathBackendWebGL(); }); -var NDArrayMathGPU = (function (_super) { - __extends(NDArrayMathGPU, _super); - function NDArrayMathGPU(gpgpu, safeMode) { - if (safeMode === void 0) { safeMode = false; } - var _this = this; - console.warn('new NDArrayMathGPU() is deprecated. Please use ' + - 'dl.setBackend(\'webgl\').'); - _this = _super.call(this, new MathBackendWebGL(gpgpu), safeMode) || this; - return _this; - } - NDArrayMathGPU.prototype.getGPGPUContext = function () { - return this.engine.backend.getGPGPUContext(); - }; - NDArrayMathGPU.prototype.getTextureManager = function () { - return this.engine.backend.getTextureManager(); - }; - return NDArrayMathGPU; -}(math_1.NDArrayMath)); -exports.NDArrayMathGPU = NDArrayMathGPU; -function float32ToTypedArray(a, dtype) { - if (dtype === 'float32') { - return a; - } - else if (dtype === 'int32' || dtype === 'bool') { - var result = (dtype === 'int32') ? new Int32Array(a.length) : - new Uint8Array(a.length); - for (var i = 0; i < result.length; ++i) { - var val = a[i]; - val = isNaN(val) ? util.getNaN(dtype) : Math.round(val); - result[i] = val; - } - return result; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -function typedArrayToFloat32(a, dtype) { - if (a instanceof Float32Array) { - return a; - } - else { - var res = new Float32Array(a.length); - for (var i = 0; i < res.length; i++) { - var val = a[i]; - res[i] = util.isValNaN(val, dtype) ? NaN : val; - } - return res; - } -} - -},{"../environment":34,"../math":105,"../ops/axis_util":107,"../ops/reduce_util":126,"../tensor":146,"../types":150,"../util":151,"./webgl/argminmax_gpu":72,"./webgl/avg_pool_backprop_gpu":73,"./webgl/batchnorm_gpu":74,"./webgl/binaryop_gpu":75,"./webgl/clip_gpu":76,"./webgl/concat_gpu":77,"./webgl/conv_backprop_gpu":78,"./webgl/conv_gpu":79,"./webgl/conv_gpu_depthwise":80,"./webgl/from_pixels_gpu":81,"./webgl/gather_gpu":82,"./webgl/gpgpu_context":83,"./webgl/gpgpu_math":84,"./webgl/logical_gpu":86,"./webgl/lrn_gpu":87,"./webgl/max_pool_backprop_gpu":88,"./webgl/mulmat_gpu":89,"./webgl/multinomial_gpu":90,"./webgl/onehot_gpu":91,"./webgl/pad_gpu":92,"./webgl/pool_gpu":93,"./webgl/reduce_gpu":94,"./webgl/resize_bilinear_gpu":95,"./webgl/reverse_gpu":96,"./webgl/slice_gpu":98,"./webgl/tex_util":99,"./webgl/texture_manager":100,"./webgl/tile_gpu":101,"./webgl/transpose_gpu":102,"./webgl/unaryop_gpu":103,"./webgl/webgl_util":104}],70:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ops = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -function executeKernel(backend, kernelName, inputAndArgs) { - if (kernelName === 'MatMul') { - var config = inputAndArgs; - return backend.matMul(config.inputs.a, config.inputs.b, config.args.transposeA, config.args.transposeB); - } - else if (kernelName === 'Slice1D') { - var config = inputAndArgs; - return backend.slice1D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Slice2D') { - var config = inputAndArgs; - return backend.slice2D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Slice3D') { - var config = inputAndArgs; - return backend.slice3D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Slice4D') { - var config = inputAndArgs; - return backend.slice4D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Reverse4D') { - var config = inputAndArgs; - return backend.reverse4D(config.inputs.x, config.args.axis); - } - else if (kernelName === 'Concat') { - var config = inputAndArgs; - return backend.concat(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Neg') { - var config = inputAndArgs; - return backend.neg(config.inputs.x); - } - else if (kernelName === 'Add') { - var config = inputAndArgs; - return backend.add(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Sub') { - var config = inputAndArgs; - return backend.subtract(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Mul') { - var config = inputAndArgs; - return backend.multiply(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Div') { - var config = inputAndArgs; - return backend.divide(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Sum') { - var config = inputAndArgs; - return backend.sum(config.inputs.x, config.args.axes); - } - else if (kernelName === 'ArgMax') { - var config = inputAndArgs; - return backend.argMax(config.inputs.x, config.args.axes); - } - else if (kernelName === 'ArgMin') { - var config = inputAndArgs; - return backend.argMin(config.inputs.x, config.args.axes); - } - else if (kernelName === 'Equal') { - var config = inputAndArgs; - return backend.equal(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'NotEqual') { - var config = inputAndArgs; - return backend.notEqual(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Less') { - var config = inputAndArgs; - return backend.less(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LessEqual') { - var config = inputAndArgs; - return backend.lessEqual(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Greater') { - var config = inputAndArgs; - return backend.greater(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'GreaterEqual') { - var config = inputAndArgs; - return backend.greaterEqual(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LogicalNot') { - var config = inputAndArgs; - return backend.logicalNot(config.inputs.x); - } - else if (kernelName === 'LogicalAnd') { - var config = inputAndArgs; - return backend.logicalAnd(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LogicalOr') { - var config = inputAndArgs; - return backend.logicalOr(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LogicalXor') { - var config = inputAndArgs; - return backend.logicalXor(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Where') { - var config = inputAndArgs; - return backend.where(config.inputs.condition, config.inputs.a, config.inputs.b, config.args.dtype); - } - else if (kernelName === 'TopKValues') { - var config = inputAndArgs; - return backend.topKValues(config.inputs.x, config.args.k); - } - else if (kernelName === 'TopKIndices') { - var config = inputAndArgs; - return backend.topKIndices(config.inputs.x, config.args.k); - } - else if (kernelName === 'Min') { - var config = inputAndArgs; - return backend.min(config.inputs.x, config.args.axes); - } - else if (kernelName === 'Minimum') { - var config = inputAndArgs; - return backend.minimum(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Max') { - var config = inputAndArgs; - return backend.max(config.inputs.x, config.args.axes); - } - else if (kernelName === 'Maximum') { - var config = inputAndArgs; - return backend.maximum(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Ceil') { - var config = inputAndArgs; - return backend.ceil(config.inputs.x); - } - else if (kernelName === 'Floor') { - var config = inputAndArgs; - return backend.floor(config.inputs.x); - } - else if (kernelName === 'Pow') { - var config = inputAndArgs; - return backend.pow(config.inputs.base, config.inputs.exp); - } - else if (kernelName === 'Exp') { - var config = inputAndArgs; - return backend.exp(config.inputs.x); - } - else if (kernelName === 'Log') { - var config = inputAndArgs; - return backend.log(config.inputs.x); - } - else if (kernelName === 'Sqrt') { - var config = inputAndArgs; - return backend.sqrt(config.inputs.x); - } - else if (kernelName === 'Square') { - var config = inputAndArgs; - return backend.square(config.inputs.x); - } - else if (kernelName === 'Relu') { - var config = inputAndArgs; - return backend.relu(config.inputs.x); - } - else if (kernelName === 'Reshape') { - var config = inputAndArgs; - var x = config.inputs.x; - var newShape = config.args.newShape; - return tensor_1.Tensor.make(newShape, { dataId: x.dataId }, x.dtype); - } - else if (kernelName === 'Cast') { - var config = inputAndArgs; - var x = config.inputs.x; - var newDType = config.args.newDType; - if (!util.hasEncodingLoss(x.dtype, newDType)) { - return tensor_1.Tensor.make(x.shape, { dataId: x.dataId }, newDType); - } - if (newDType === 'int32') { - return backend.int(x); - } - else if (newDType === 'bool') { - return backend.notEqual(x, ops.scalar(0, x.dtype)); - } - else { - throw new Error("Error in Cast: unknown dtype argument (" + newDType + ")"); - } - } - else if (kernelName === 'LeakyRelu') { - var config = inputAndArgs; - return backend.leakyRelu(config.inputs.x, config.args.alpha); - } - else if (kernelName === 'PReLU') { - var config = inputAndArgs; - return backend.prelu(config.inputs.x, config.inputs.alpha); - } - else if (kernelName === 'PReLUDer') { - var config = inputAndArgs; - return backend.preluDer(config.inputs.x, config.inputs.alpha); - } - else if (kernelName === 'Elu') { - var config = inputAndArgs; - return backend.elu(config.inputs.x); - } - else if (kernelName === 'EluDer') { - var config = inputAndArgs; - return backend.eluDer(config.inputs.x); - } - else if (kernelName === 'Selu') { - var config = inputAndArgs; - return backend.selu(config.inputs.x); - } - else if (kernelName === 'Abs') { - var config = inputAndArgs; - return backend.abs(config.inputs.x); - } - else if (kernelName === 'Sigmoid') { - var config = inputAndArgs; - return backend.sigmoid(config.inputs.x); - } - else if (kernelName === 'Step') { - var config = inputAndArgs; - return backend.step(config.inputs.x, config.args.alpha); - } - else if (kernelName === 'Sin') { - var config = inputAndArgs; - return backend.sin(config.inputs.x); - } - else if (kernelName === 'Cos') { - var config = inputAndArgs; - return backend.cos(config.inputs.x); - } - else if (kernelName === 'Tan') { - var config = inputAndArgs; - return backend.tan(config.inputs.x); - } - else if (kernelName === 'Asin') { - var config = inputAndArgs; - return backend.asin(config.inputs.x); - } - else if (kernelName === 'Acos') { - var config = inputAndArgs; - return backend.acos(config.inputs.x); - } - else if (kernelName === 'Atan') { - var config = inputAndArgs; - return backend.atan(config.inputs.x); - } - else if (kernelName === 'Sinh') { - var config = inputAndArgs; - return backend.sinh(config.inputs.x); - } - else if (kernelName === 'Cosh') { - var config = inputAndArgs; - return backend.cosh(config.inputs.x); - } - else if (kernelName === 'Tanh') { - var config = inputAndArgs; - return backend.tanh(config.inputs.x); - } - else if (kernelName === 'Clip') { - var config = inputAndArgs; - return backend.clip(config.inputs.x, config.args.min, config.args.max); - } - else if (kernelName === 'Tile') { - var config = inputAndArgs; - return backend.tile(config.inputs.x, config.args.reps); - } - else if (kernelName === 'Gather') { - var config = inputAndArgs; - return backend.gather(config.inputs.x, config.inputs.indices, config.args.axis); - } - else if (kernelName === 'Pad1D') { - var config = inputAndArgs; - return backend.pad1D(config.inputs.x, config.args.paddings, config.args.constantValue); - } - else if (kernelName === 'Pad2D') { - var config = inputAndArgs; - return backend.pad2D(config.inputs.x, config.args.paddings, config.args.constantValue); - } - else if (kernelName === 'Transpose') { - var config = inputAndArgs; - return backend.transpose(config.inputs.x, config.args.perm); - } - else if (kernelName === 'Conv2D') { - var config = inputAndArgs; - return backend.conv2d(config.inputs.x, config.inputs.filter, config.args.convInfo); - } - else if (kernelName === 'Conv2DDerInput') { - var config = inputAndArgs; - return backend.conv2dDerInput(config.inputs.dy, config.inputs.filter, config.args.convInfo); - } - else if (kernelName === 'Conv2DDerFilter') { - var config = inputAndArgs; - return backend.conv2dDerFilter(config.inputs.x, config.inputs.dy, config.args.convInfo); - } - else if (kernelName === 'DepthwiseConv2D') { - var config = inputAndArgs; - return backend.depthwiseConv2D(config.inputs.x, config.inputs.filter, config.args.convInfo); - } - else if (kernelName === 'MaxPool') { - var config = inputAndArgs; - return backend.maxPool(config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'MaxPoolBackprop') { - var config = inputAndArgs; - return backend.maxPoolBackprop(config.inputs.dy, config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'AvgPool') { - var config = inputAndArgs; - return backend.avgPool(config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'AvgPoolBackprop') { - var config = inputAndArgs; - return backend.avgPoolBackprop(config.inputs.dy, config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'MinPool') { - var config = inputAndArgs; - return backend.minPool(config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'ResizeBilinear') { - var config = inputAndArgs; - return backend.resizeBilinear(config.inputs.x, config.args.newHeight, config.args.newWidth, config.args.alignCorners); - } - else if (kernelName === 'BatchNorm4D') { - var config = inputAndArgs; - return backend.batchNormalization4D(config.inputs.x, config.inputs.mean, config.inputs.variance, config.args.varianceEpsilon, config.inputs.scale, config.inputs.offset); - } - else if (kernelName === 'LRN4D') { - var config = inputAndArgs; - return backend.localResponseNormalization4D(config.inputs.x, config.args.radius, config.args.bias, config.args.alpha, config.args.beta, config.args.normRegion); - } - else if (kernelName === 'Multinomial') { - var config = inputAndArgs; - return backend.multinomial(config.inputs.probs, config.args.numSamples, config.args.seed); - } - else if (kernelName === 'OneHot') { - var config = inputAndArgs; - return backend.oneHot(config.inputs.indices, config.args.depth, config.args.onValue, config.args.offValue); - } - throw new Error("No backend method found for kernel " + kernelName); -} -exports.executeKernel = executeKernel; - -},{"../ops/ops":123,"../tensor":146,"../util":151}],71:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MatrixOrientation; -(function (MatrixOrientation) { - MatrixOrientation[MatrixOrientation["REGULAR"] = 0] = "REGULAR"; - MatrixOrientation[MatrixOrientation["TRANSPOSED"] = 1] = "TRANSPOSED"; -})(MatrixOrientation = exports.MatrixOrientation || (exports.MatrixOrientation = {})); - -},{}],72:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ArgMinMaxProgram = (function () { - function ArgMinMaxProgram(reduceInfo, op, firstPass) { - this.variableNames = ['A']; - var windowSize = reduceInfo.windowSize; - var batchSize = reduceInfo.batchSize; - var inSize = reduceInfo.inSize; - var outSize = Math.ceil(inSize / windowSize); - if (!firstPass) { - this.variableNames.push('bestIndicesA'); - } - this.outputShape = [batchSize, outSize]; - var compOp = (op === 'max') ? '>' : '<'; - var indexSnippet = firstPass ? - 'inOffset + i;' : - 'round(getBestIndicesA(batch, inOffset + i));'; - this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * " + windowSize + ";\n\n int bestIndex = 0;\n float bestValue = getA(batch, inOffset);\n\n for (int i = 0; i < " + windowSize + "; i++) {\n int inIdx = " + indexSnippet + ";\n float candidate = getA(batch, inIdx);\n if (isNaN(candidate)) {\n setOutput(candidate);\n return;\n }\n if (candidate " + compOp + " bestValue) {\n bestValue = candidate;\n bestIndex = inIdx;\n }\n }\n setOutput(float(bestIndex));\n }\n "; - } - return ArgMinMaxProgram; -}()); -exports.ArgMinMaxProgram = ArgMinMaxProgram; - -},{}],73:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var AvgPool2DBackpropProgram = (function () { - function AvgPool2DBackpropProgram(convInfo) { - this.variableNames = ['dy']; - this.outputShape = convInfo.inShape; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var avgMultiplier = 1 / (filterHeight * filterWidth); - this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n const float avgMultiplier = float(" + avgMultiplier + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n setOutput(dotProd);\n }\n "; - } - return AvgPool2DBackpropProgram; -}()); -exports.AvgPool2DBackpropProgram = AvgPool2DBackpropProgram; - -},{}],74:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var broadcast_util = require("../../ops/broadcast_util"); -var BatchNormProgram = (function () { - function BatchNormProgram(xShape, meanShape, varianceShape, offsetShape, scaleShape, varianceEpsilon) { - this.outputShape = []; - this.supportsBroadcasting = true; - this.variableNames = ['x', 'mean', 'variance']; - broadcast_util.assertAndGetBroadcastShape(xShape, meanShape); - broadcast_util.assertAndGetBroadcastShape(xShape, varianceShape); - var offsetSnippet = '0.0'; - if (offsetShape != null) { - broadcast_util.assertAndGetBroadcastShape(xShape, offsetShape); - this.variableNames.push('offset'); - offsetSnippet = 'getOffsetAtOutCoords()'; - } - var scaleSnippet = '1.0'; - if (scaleShape != null) { - broadcast_util.assertAndGetBroadcastShape(xShape, scaleShape); - this.variableNames.push('scale'); - scaleSnippet = 'getScaleAtOutCoords()'; - } - this.outputShape = xShape; - this.userCode = "\n void main() {\n float x = getXAtOutCoords();\n float mean = getMeanAtOutCoords();\n float variance = getVarianceAtOutCoords();\n float offset = " + offsetSnippet + ";\n float scale = " + scaleSnippet + ";\n float inv = scale / sqrt(variance + float(" + varianceEpsilon + "));\n setOutput((x - mean) * inv + offset);\n }\n "; - } - return BatchNormProgram; -}()); -exports.BatchNormProgram = BatchNormProgram; - -},{"../../ops/broadcast_util":110}],75:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var broadcast_util = require("../../ops/broadcast_util"); -var CHECK_NAN_SNIPPET = "\n if (isNaN(a)) return a;\n if (isNaN(b)) return b;\n"; -exports.ADD = 'return a + b;'; -exports.SUB = 'return a - b;'; -exports.MUL = 'return a * b;'; -exports.DIV = 'return a / b;'; -exports.POW = "\n return (round(mod(b, 2.0)) == 0 || round(mod(b, 2.0)) == 2) ?\n pow(abs(a), b) : sign(a) * pow(abs(a), b);\n"; -exports.EQUAL = CHECK_NAN_SNIPPET + "\n return float(a == b);\n"; -exports.NOT_EQUAL = CHECK_NAN_SNIPPET + "\n return float(a != b);\n"; -exports.LESS = CHECK_NAN_SNIPPET + "\n return float(a < b);\n"; -exports.LESS_EQUAL = CHECK_NAN_SNIPPET + "\n return float(a <= b);\n"; -exports.GREATER = CHECK_NAN_SNIPPET + "\n return float(a > b);\n"; -exports.GREATER_EQUAL = CHECK_NAN_SNIPPET + "\n return float(a >= b);\n"; -exports.LOGICAL_AND = CHECK_NAN_SNIPPET + "\n return float(a >= 1.0 && b >= 1.0);\n"; -exports.LOGICAL_OR = CHECK_NAN_SNIPPET + "\n return float(a >= 1.0 || b >= 1.0);\n"; -exports.LOGICAL_XOR = CHECK_NAN_SNIPPET + "\n return float(a >= 1.0 ^^ b >= 1.0);\n"; -exports.PRELU = "\n return (a >= 0.0) ? a : b * a;\n"; -exports.PRELU_DER = "\n return (a > 0.0) ? 1.0 : ((a < 0.0) ? b : a);\n"; -exports.MAX = CHECK_NAN_SNIPPET + "\n return max(a, b);\n"; -exports.MIN = CHECK_NAN_SNIPPET + "\n return min(a, b);\n"; -var BinaryOpProgram = (function () { - function BinaryOpProgram(op, aShape, bShape) { - this.variableNames = ['A', 'B']; - this.supportsBroadcasting = true; - this.outputShape = - broadcast_util.assertAndGetBroadcastShape(aShape, bShape); - this.userCode = "\n float binaryOperation(float a, float b) {\n " + op + "\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n "; - } - return BinaryOpProgram; -}()); -exports.BinaryOpProgram = BinaryOpProgram; - -},{"../../ops/broadcast_util":110}],76:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ClipProgram = (function () { - function ClipProgram(aShape, min, max) { - this.variableNames = ['A']; - this.outputShape = aShape; - var minFixed = min.toFixed(20); - var maxFixed = max.toFixed(20); - this.userCode = "\n void main() {\n float value = getAAtOutCoords();\n if (isNaN(value)) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, " + minFixed + ", " + maxFixed + "));\n }\n "; - } - return ClipProgram; -}()); -exports.ClipProgram = ClipProgram; - -},{}],77:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var concat_util = require("../../ops/concat_util"); -var ConcatProgram = (function () { - function ConcatProgram(aShape, bShape) { - this.variableNames = ['A', 'B']; - this.outputShape = []; - this.outputShape = - concat_util.computeOutShape(aShape, bShape, 1); - this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int yR = coords.x;\n int yC = coords.y;\n\n float value = 0.0;\n if (yC < " + aShape[1] + ") {\n value = getA(yR, yC);\n } else {\n yC -= " + aShape[1] + ";\n value = getB(yR, yC);\n }\n\n setOutput(value);\n }\n "; - } - return ConcatProgram; -}()); -exports.ConcatProgram = ConcatProgram; - -},{"../../ops/concat_util":113}],78:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Conv2DDerFilterProgram = (function () { - function Conv2DDerFilterProgram(convInfo) { - this.variableNames = ['x', 'dy']; - this.outputShape = convInfo.filterShape; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int d2 = coords.w;\n\n // Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int b = 0; b < " + convInfo.batchSize + "; b++) {\n for (int yR = 0; yR < " + convInfo.outHeight + "; yR++) {\n int xR = wR + yR * " + strideHeight + " - " + padTop + ";\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int yC = 0; yC < " + convInfo.outWidth + "; yC++) {\n int xC = wC + yC * " + strideWidth + " - " + padLeft + ";\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n "; - } - return Conv2DDerFilterProgram; -}()); -exports.Conv2DDerFilterProgram = Conv2DDerFilterProgram; -var Conv2DDerInputProgram = (function () { - function Conv2DDerInputProgram(convInfo) { - this.variableNames = ['dy', 'W']; - this.outputShape = convInfo.inShape; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n\n ivec2 dyCorner = coords.yz - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = " + filterHeight + " - 1 - wR;\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = " + filterWidth + " - 1 - wC;\n\n for (int d2 = 0; d2 < " + convInfo.outChannels + "; d2++) {\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n "; - } - return Conv2DDerInputProgram; -}()); -exports.Conv2DDerInputProgram = Conv2DDerInputProgram; - -},{}],79:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Conv2DProgram = (function () { - function Conv2DProgram(convInfo) { - this.variableNames = ['x', 'W']; - this.outputShape = convInfo.outShape; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var inputDepthNearestVec4 = Math.floor(convInfo.inChannels / 4) * 4; - var inputDepthVec4Remainder = convInfo.inChannels % 4; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d2 = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n for (int d1 = 0; d1 < " + inputDepthNearestVec4 + "; d1 += 4) {\n vec4 xValues = vec4(\n getX(batch, xR, xC, d1),\n getX(batch, xR, xC, d1 + 1),\n getX(batch, xR, xC, d1 + 2),\n getX(batch, xR, xC, d1 + 3)\n );\n vec4 wValues = vec4(\n getW(wR, wC, d1, d2),\n getW(wR, wC, d1 + 1, d2),\n getW(wR, wC, d1 + 2, d2),\n getW(wR, wC, d1 + 3, d2)\n );\n\n dotProd += dot(xValues, wValues);\n }\n\n if (" + (inputDepthVec4Remainder === 1) + ") {\n dotProd +=\n getX(batch, xR, xC, " + inputDepthNearestVec4 + ") *\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2);\n } else if (" + (inputDepthVec4Remainder === 2) + ") {\n vec2 xValues = vec2(\n getX(batch, xR, xC, " + inputDepthNearestVec4 + "),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 1)\n );\n vec2 wValues = vec2(\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if (" + (inputDepthVec4Remainder === 3) + ") {\n vec3 xValues = vec3(\n getX(batch, xR, xC, " + inputDepthNearestVec4 + "),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 1),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 2)\n );\n vec3 wValues = vec3(\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 1, d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n setOutput(dotProd);\n }\n "; - } - return Conv2DProgram; -}()); -exports.Conv2DProgram = Conv2DProgram; - -},{}],80:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var DepthwiseConv2DProgram = (function () { - function DepthwiseConv2DProgram(convInfo) { - this.variableNames = ['x', 'W']; - this.outputShape = convInfo.outShape; - var xNumRows = convInfo.inHeight; - var xNumCols = convInfo.inWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var channelMul = convInfo.outChannels / convInfo.inChannels; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2 / " + channelMul + ";\n int q = d2 - d1 * " + channelMul + ";\n\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n // TODO(dsmilkov): Flatten the two for loops and vec4 the operations.\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + xNumRows + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + xNumCols + ") {\n continue;\n }\n\n float xVal = getX(batch, xR, xC, d1);\n float wVal = getW(wR, wC, d1, q);\n dotProd += xVal * wVal;\n }\n }\n setOutput(dotProd);\n }\n "; - } - return DepthwiseConv2DProgram; -}()); -exports.DepthwiseConv2DProgram = DepthwiseConv2DProgram; - -},{}],81:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var FromPixelsProgram = (function () { - function FromPixelsProgram(outputShape) { - this.variableNames = ['A']; - var height = outputShape[0], width = outputShape[1]; - this.outputShape = outputShape; - this.userCode = "\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + width + ".0, " + height + ".0);\n\n vec4 values = texture2D(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n setOutput(floor(value * 255.0 + 0.5));\n }\n "; - } - return FromPixelsProgram; -}()); -exports.FromPixelsProgram = FromPixelsProgram; - -},{}],82:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var GatherProgram = (function () { - function GatherProgram(aShape, indicesLength, axis) { - this.variableNames = ['A', 'indices']; - var outputShape = aShape.slice(); - outputShape[axis] = indicesLength; - this.outputShape = outputShape; - this.rank = outputShape.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var sourceCoords = getSourceCoords(aShape, axis); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + sourceCoords + "));\n }\n "; - } - return GatherProgram; -}()); -exports.GatherProgram = GatherProgram; -function getSourceCoords(aShape, axis) { - var rank = aShape.length; - if (rank > 4) { - throw Error("Gather for rank " + rank + " is not yet supported"); - } - if (rank === 1) { - return "int(getIndices(resRC))"; - } - var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var sourceCoords = []; - for (var i = 0; i < aShape.length; i++) { - if (i === axis) { - sourceCoords.push("int(getIndices(" + currentCoords[i] + "))"); - } - else { - sourceCoords.push("" + currentCoords[i]); - } - } - return sourceCoords.join(); -} - -},{"./shader_compiler":97}],83:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var util = require("../../util"); -var gpgpu_util = require("./gpgpu_util"); -var tex_util = require("./tex_util"); -var webgl_util = require("./webgl_util"); -var GPGPUContext = (function () { - function GPGPUContext(gl) { - this.outputTexture = null; - this.program = null; - this.disposed = false; - this.autoDebugValidate = false; - if (gl != null) { - this.gl = gl; - } - else { - this.gl = gpgpu_util.createWebGLContext(); - } - if (environment_1.ENV.get('WEBGL_VERSION') === 1) { - this.textureFloatExtension = - webgl_util.getExtensionOrThrow(this.gl, 'OES_texture_float'); - this.colorBufferFloatExtension = - this.gl.getExtension('WEBGL_color_buffer_float'); - } - else { - this.colorBufferFloatExtension = - webgl_util.getExtensionOrThrow(this.gl, 'EXT_color_buffer_float'); - } - this.loseContextExtension = - webgl_util.getExtensionOrThrow(this.gl, 'WEBGL_lose_context'); - if (environment_1.ENV.get('WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED')) { - this.getBufferSubDataAsyncExtension = - this.gl.getExtension('WEBGL_get_buffer_sub_data_async'); - } - this.vertexBuffer = gpgpu_util.createVertexBuffer(this.gl); - this.indexBuffer = gpgpu_util.createIndexBuffer(this.gl); - this.framebuffer = webgl_util.createFramebuffer(this.gl); - } - GPGPUContext.prototype.dispose = function () { - var _this = this; - if (this.disposed) { - return; - } - if (this.program != null) { - console.warn('Disposing a GPGPUContext that still has a bound WebGLProgram.' + - ' This is probably a resource leak, delete the program with ' + - 'GPGPUContext.deleteProgram before disposing.'); - } - if (this.outputTexture != null) { - console.warn('Disposing a GPGPUContext that still has a bound output matrix ' + - 'texture. This is probably a resource leak, delete the output ' + - 'matrix texture with GPGPUContext.deleteMatrixTexture before ' + - 'disposing.'); - } - var gl = this.gl; - webgl_util.callAndCheck(gl, function () { return gl.finish(); }); - webgl_util.callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, null); }); - webgl_util.callAndCheck(gl, function () { return gl.deleteFramebuffer(_this.framebuffer); }); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, null); }); - webgl_util.callAndCheck(gl, function () { return gl.deleteBuffer(_this.vertexBuffer); }); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); }); - webgl_util.callAndCheck(gl, function () { return gl.deleteBuffer(_this.indexBuffer); }); - this.loseContextExtension.loseContext(); - this.disposed = true; - }; - GPGPUContext.prototype.enableAutomaticDebugValidation = function (enabled) { - this.autoDebugValidate = enabled; - webgl_util.enableDebugWebGLErrorChecking(enabled); - }; - GPGPUContext.prototype.createMatrixTexture = function (rows, columns) { - this.throwIfDisposed(); - return gpgpu_util.createMatrixTexture(this.gl, rows, columns); - }; - GPGPUContext.prototype.uploadPixelDataToTexture = function (texture, pixels) { - this.throwIfDisposed(); - gpgpu_util.uploadPixelDataToTexture(this.gl, texture, pixels); - }; - GPGPUContext.prototype.createPackedMatrixTexture = function (rows, columns) { - this.throwIfDisposed(); - return gpgpu_util.createPackedMatrixTexture(this.gl, rows, columns); - }; - GPGPUContext.prototype.deleteMatrixTexture = function (texture) { - var _this = this; - this.throwIfDisposed(); - if (this.outputTexture === texture) { - webgl_util.unbindColorTextureFromFramebuffer(this.gl, this.framebuffer); - this.outputTexture = null; - } - webgl_util.callAndCheck(this.gl, function () { return _this.gl.deleteTexture(texture); }); - }; - GPGPUContext.prototype.uploadMatrixToTexture = function (texture, rows, columns, matrix) { - this.throwIfDisposed(); - var numChannels = 1; - return gpgpu_util.uploadMatrixToTexture(this.gl, texture, rows, columns, matrix, numChannels); - }; - GPGPUContext.prototype.uploadMatrixToPackedTexture = function (texture, rows, columns, matrix) { - this.throwIfDisposed(); - return gpgpu_util.uploadMatrixToPackedTexture(this.gl, texture, rows, columns, matrix); - }; - GPGPUContext.prototype.downloadMatrixFromTexture = function (texture, rows, columns) { - var _this = this; - return this.downloadMatrixDriver(texture, function () { - return gpgpu_util.downloadMatrixFromOutputTexture(_this.gl, rows, columns); - }); - }; - GPGPUContext.prototype.downloadMatrixFromTextureAsync = function (texture, rows, columns) { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - if (this.getBufferSubDataAsyncExtension == null) { - throw new Error("Cannot download matrix from output texture asynchronously, " + - "WEBGL_get_buffer_sub_data_async is not enabled."); - } - return [2, this.downloadMatrixDriverAsync(texture, function () { return gpgpu_util.downloadMatrixFromOutputTextureAsync(_this.gl, _this.getBufferSubDataAsyncExtension, rows, columns); })]; - }); - }); - }; - GPGPUContext.prototype.downloadMatrixFromRGBAColorTexture = function (texture, rows, columns, channels) { - var _this = this; - return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadMatrixFromRGBAColorTexture(_this.gl, rows, columns, channels); }); - }; - GPGPUContext.prototype.downloadMatrixFromPackedTexture = function (texture, rows, columns) { - var _this = this; - return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadMatrixFromPackedOutputTexture(_this.gl, rows, columns); }); - }; - GPGPUContext.prototype.createProgram = function (fragmentShaderSource) { - this.throwIfDisposed(); - var gl = this.gl; - var fragmentShader = webgl_util.createFragmentShader(gl, fragmentShaderSource); - var vertexShader = gpgpu_util.createVertexShader(gl); - var program = webgl_util.createProgram(gl); - webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, vertexShader); }); - webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, fragmentShader); }); - webgl_util.linkProgram(gl, program); - if (this.autoDebugValidate) { - webgl_util.validateProgram(gl, program); - } - return program; - }; - GPGPUContext.prototype.deleteProgram = function (program) { - var _this = this; - this.throwIfDisposed(); - if (program === this.program) { - this.program = null; - } - if (program != null) { - webgl_util.callAndCheck(this.gl, function () { return _this.gl.deleteProgram(program); }); - } - }; - GPGPUContext.prototype.setProgram = function (program) { - var _this = this; - this.throwIfDisposed(); - this.program = program; - if ((this.program != null) && this.autoDebugValidate) { - webgl_util.validateProgram(this.gl, this.program); - } - webgl_util.callAndCheck(this.gl, function () { return _this.gl.useProgram(program); }); - }; - GPGPUContext.prototype.getUniformLocation = function (program, uniformName, shouldThrow) { - if (shouldThrow === void 0) { shouldThrow = true; } - this.throwIfDisposed(); - if (shouldThrow) { - return webgl_util.getProgramUniformLocationOrThrow(this.gl, program, uniformName); - } - else { - return webgl_util.getProgramUniformLocation(this.gl, program, uniformName); - } - }; - GPGPUContext.prototype.getAttributeLocation = function (program, attribute) { - var _this = this; - this.throwIfDisposed(); - return webgl_util.callAndCheck(this.gl, function () { return _this.gl.getAttribLocation(program, attribute); }); - }; - GPGPUContext.prototype.getUniformLocationNoThrow = function (program, uniformName) { - this.throwIfDisposed(); - return this.gl.getUniformLocation(program, uniformName); - }; - GPGPUContext.prototype.setInputMatrixTexture = function (inputMatrixTexture, uniformLocation, textureUnit) { - this.throwIfDisposed(); - this.throwIfNoProgram(); - webgl_util.bindTextureToProgramUniformSampler(this.gl, this.program, inputMatrixTexture, uniformLocation, textureUnit); - }; - GPGPUContext.prototype.setOutputMatrixTexture = function (outputMatrixTexture, rows, columns) { - this.setOutputMatrixTextureDriver(outputMatrixTexture, columns, rows); - }; - GPGPUContext.prototype.setOutputPackedMatrixTexture = function (outputPackedMatrixTexture, rows, columns) { - this.throwIfDisposed(); - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - this.setOutputMatrixTextureDriver(outputPackedMatrixTexture, width, height); - }; - GPGPUContext.prototype.setOutputMatrixWriteRegion = function (startRow, numRows, startColumn, numColumns) { - this.setOutputMatrixWriteRegionDriver(startColumn, startRow, numColumns, numRows); - }; - GPGPUContext.prototype.setOutputPackedMatrixWriteRegion = function (startRow, numRows, startColumn, numColumns) { - throw new Error('setOutputPackedMatrixWriteRegion not implemented.'); - }; - GPGPUContext.prototype.debugValidate = function () { - if (this.program != null) { - webgl_util.validateProgram(this.gl, this.program); - } - webgl_util.validateFramebuffer(this.gl); - }; - GPGPUContext.prototype.executeProgram = function (attribLocations) { - this.throwIfDisposed(); - this.throwIfNoProgram(); - var gl = this.gl; - gpgpu_util.bindVertexProgramAttributeStreams(gl, this.program, this.vertexBuffer, attribLocations); - if (this.autoDebugValidate) { - this.debugValidate(); - } - webgl_util.callAndCheck(gl, function () { return gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0); }); - }; - GPGPUContext.prototype.blockUntilAllProgramsCompleted = function () { - var _this = this; - this.throwIfDisposed(); - webgl_util.callAndCheck(this.gl, function () { return _this.gl.finish(); }); - }; - GPGPUContext.prototype.getQueryTimerExtension = function () { - if (this.disjointQueryTimerExtension == null) { - this.disjointQueryTimerExtension = - webgl_util.getExtensionOrThrow(this.gl, environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2 ? - 'EXT_disjoint_timer_query_webgl2' : - 'EXT_disjoint_timer_query'); - } - return this.disjointQueryTimerExtension; - }; - GPGPUContext.prototype.getQueryTimerExtensionWebGL2 = function () { - return this.getQueryTimerExtension(); - }; - GPGPUContext.prototype.getQueryTimerExtensionWebGL1 = function () { - return this.getQueryTimerExtension(); - }; - GPGPUContext.prototype.runQuery = function (queryFn) { - var query = this.beginQuery(); - queryFn(); - this.endQuery(); - return this.pollQueryTime(query); - }; - GPGPUContext.prototype.beginQuery = function () { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2) { - var gl2 = this.gl; - var ext = this.getQueryTimerExtensionWebGL2(); - var query = gl2.createQuery(); - gl2.beginQuery(ext.TIME_ELAPSED_EXT, query); - return query; - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - var query = ext.createQueryEXT(); - ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, query); - return query; - } - }; - GPGPUContext.prototype.endQuery = function () { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2) { - var gl2 = this.gl; - var ext = this.getQueryTimerExtensionWebGL2(); - gl2.endQuery(ext.TIME_ELAPSED_EXT); - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - ext.endQueryEXT(ext.TIME_ELAPSED_EXT); - } - }; - GPGPUContext.prototype.isQueryAvailable = function (query, queryTimerVersion) { - if (queryTimerVersion === 0) { - return true; - } - if (queryTimerVersion === 2) { - var gl2 = this.gl; - var ext = this.getQueryTimerExtensionWebGL2(); - var available = gl2.getQueryParameter(query, gl2.QUERY_RESULT_AVAILABLE); - var disjoint = this.gl.getParameter(ext.GPU_DISJOINT_EXT); - return available && !disjoint; - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - var available = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_AVAILABLE_EXT); - var disjoint = this.gl.getParameter(ext.GPU_DISJOINT_EXT); - return available && !disjoint; - } - }; - GPGPUContext.prototype.pollQueryTime = function (query) { - var _this = this; - return new Promise(function (resolve, reject) { - var resolveWithWarning = function () { - console.warn('Disjoint query timer never available.'); - resolve(-1); - }; - var queryTimerVersion = environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION'); - util.repeatedTry(function () { return _this.isQueryAvailable(query, queryTimerVersion); }) - .then(function () { return resolve(_this.getQueryTime(query, queryTimerVersion)); }) - .catch(resolveWithWarning); - }); - }; - GPGPUContext.prototype.getQueryTime = function (query, queryTimerVersion) { - if (queryTimerVersion === 0) { - return null; - } - if (queryTimerVersion === 2) { - var gl2 = this.gl; - var timeElapsedNanos = gl2.getQueryParameter(query, gl2.QUERY_RESULT); - return timeElapsedNanos / 1000000; - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - var timeElapsedNanos = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_EXT); - return timeElapsedNanos / 1000000; - } - }; - GPGPUContext.prototype.downloadMatrixDriverSetup = function (texture) { - this.throwIfDisposed(); - webgl_util.bindColorTextureToFramebuffer(this.gl, texture, this.framebuffer); - if (this.autoDebugValidate) { - webgl_util.validateFramebuffer(this.gl); - } - }; - GPGPUContext.prototype.downloadMatrixDriverTeardown = function () { - if (this.outputTexture != null) { - webgl_util.bindColorTextureToFramebuffer(this.gl, this.outputTexture, this.framebuffer); - if (this.autoDebugValidate) { - webgl_util.validateFramebuffer(this.gl); - } - } - else { - webgl_util.unbindColorTextureFromFramebuffer(this.gl, this.framebuffer); - } - }; - GPGPUContext.prototype.downloadMatrixDriver = function (texture, downloadAndDecode) { - this.downloadMatrixDriverSetup(texture); - var result = downloadAndDecode(); - this.downloadMatrixDriverTeardown(); - return result; - }; - GPGPUContext.prototype.downloadMatrixDriverAsync = function (texture, downloadAndDecode) { - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.downloadMatrixDriverSetup(texture); - return [4, downloadAndDecode()]; - case 1: - result = _a.sent(); - this.downloadMatrixDriverTeardown(); - return [2, result]; - } - }); - }); - }; - GPGPUContext.prototype.setOutputMatrixTextureDriver = function (outputMatrixTextureMaybePacked, width, height) { - this.throwIfDisposed(); - var gl = this.gl; - webgl_util.bindColorTextureToFramebuffer(gl, outputMatrixTextureMaybePacked, this.framebuffer); - if (this.autoDebugValidate) { - webgl_util.validateFramebuffer(gl); - } - this.outputTexture = outputMatrixTextureMaybePacked; - webgl_util.callAndCheck(gl, function () { return gl.viewport(0, 0, width, height); }); - webgl_util.callAndCheck(gl, function () { return gl.scissor(0, 0, width, height); }); - }; - GPGPUContext.prototype.setOutputMatrixWriteRegionDriver = function (x, y, width, height) { - var _this = this; - this.throwIfDisposed(); - webgl_util.callAndCheck(this.gl, function () { return _this.gl.scissor(x, y, width, height); }); - }; - GPGPUContext.prototype.throwIfDisposed = function () { - if (this.disposed) { - throw new Error('Attempted to use disposed GPGPUContext.'); - } - }; - GPGPUContext.prototype.throwIfNoProgram = function () { - if (this.program == null) { - throw new Error('No GPU program is currently set.'); - } - }; - return GPGPUContext; -}()); -exports.GPGPUContext = GPGPUContext; - -},{"../../environment":34,"../../util":151,"./gpgpu_util":85,"./tex_util":99,"./webgl_util":104}],84:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var util = require("../../util"); -var shader_compiler = require("./shader_compiler"); -var ATTRIBUTE_NAMES = ['uv', 'clipSpacePos']; -var NAN_UNIFORM_NAME = 'NaN'; -function shouldUploadNaNUniform() { - return !environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED'); -} -function compileProgram(gpgpu, program, inputs, output) { - var userCode = program.userCode; - var inputInfos = inputs.map(function (input, i) { - var shapeInfo = { - logicalShape: input.tensor.shape, - texShape: input.texData.texShape - }; - return { name: program.variableNames[i], shapeInfo: shapeInfo }; - }); - var inShapeInfos = inputInfos.map(function (x) { return x.shapeInfo; }); - var outShapeInfo = { - logicalShape: output.tensor.shape, - texShape: output.texData.texShape - }; - var source = shader_compiler.makeShader(inputInfos, outShapeInfo, userCode, program.supportsBroadcasting === true); - var webGLProgram = gpgpu.createProgram(source); - var uniformLocations = {}; - for (var i = 0; i < program.variableNames.length; i++) { - var uniformName = program.variableNames[i]; - uniformLocations[uniformName] = - gpgpu.getUniformLocation(webGLProgram, uniformName); - } - var attributeLocations = {}; - ATTRIBUTE_NAMES.forEach(function (attribute) { - attributeLocations[attribute] = - gpgpu.getAttributeLocation(webGLProgram, attribute); - }); - if (shouldUploadNaNUniform()) { - var throwIfNaNUniformIsNotUsed = false; - uniformLocations[NAN_UNIFORM_NAME] = gpgpu.getUniformLocation(webGLProgram, NAN_UNIFORM_NAME, throwIfNaNUniformIsNotUsed); - } - return { - program: program, - source: source, - webGLProgram: webGLProgram, - uniformLocations: uniformLocations, - attributeLocations: attributeLocations, - gpgpu: gpgpu, - inShapeInfos: inShapeInfos, - outShapeInfo: outShapeInfo - }; -} -exports.compileProgram = compileProgram; -function validateBinaryAndProgram(shapeInfos, inputs) { - if (shapeInfos.length !== inputs.length) { - throw Error("Binary was compiled with " + shapeInfos.length + " inputs, but " + - ("was executed with " + inputs.length + " inputs")); - } - shapeInfos.forEach(function (s, i) { - var shapeA = s.logicalShape; - var texShapeA = s.texShape; - var shapeB = inputs[i].tensor.shape; - var texShapeB = inputs[i].texData.texShape; - if (!util.arraysEqual(shapeA, shapeB)) { - throw Error("Binary was compiled with different shapes than " + - ("the current args. Shapes " + shapeA + " and " + shapeB + " must match")); - } - if (!util.arraysEqual(texShapeA, texShapeB)) { - throw Error("Binary was compiled with different texture shapes than the" + - (" current args. Shape " + texShapeA + " and " + texShapeB + " must match")); - } - }); -} -function runProgram(binary, inputs, output, customSetup) { - validateBinaryAndProgram(binary.inShapeInfos, inputs); - validateBinaryAndProgram([binary.outShapeInfo], [output]); - var outTex = output.texData.texture; - var outTexShape = output.texData.texShape; - var gpgpu = binary.gpgpu; - gpgpu.setOutputMatrixTexture(outTex, outTexShape[0], outTexShape[1]); - gpgpu.setProgram(binary.webGLProgram); - inputs.forEach(function (input, i) { - var tex = input.texData.texture; - var variableName = binary.program.variableNames[i]; - var variableUniformLocation = binary.uniformLocations[variableName]; - gpgpu.setInputMatrixTexture(tex, variableUniformLocation, i); - }); - if (shouldUploadNaNUniform()) { - gpgpu.gl.uniform1f(binary.uniformLocations[NAN_UNIFORM_NAME], NaN); - } - if (customSetup != null) { - customSetup(gpgpu, binary.webGLProgram); - } - gpgpu.executeProgram(binary.attributeLocations); -} -exports.runProgram = runProgram; -function makeShaderKey(program, inputs, output) { - var keyInputs = ''; - inputs.concat(output).forEach(function (x) { - keyInputs += x.tensor.shape + "_" + x.texData.texShape; - }); - var keyUserCode = program.userCode; - var keyBroadcast = (program.supportsBroadcasting === true).toString(); - var key = program.constructor.name; - key += '_' + keyBroadcast + '_' + keyInputs + '_' + keyUserCode; - return key; -} -exports.makeShaderKey = makeShaderKey; - -},{"../../environment":34,"../../util":151,"./shader_compiler":97}],85:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var tex_util = require("./tex_util"); -var webgl_util = require("./webgl_util"); -function getWebGLContextAttributes() { - return { - alpha: false, - antialias: false, - premultipliedAlpha: false, - preserveDrawingBuffer: false, - depth: false, - stencil: false, - failIfMajorPerformanceCaveat: true - }; -} -exports.getWebGLContextAttributes = getWebGLContextAttributes; -function createWebGLContext(canvas) { - var attributes = getWebGLContextAttributes(); - var gl; - if (canvas != null) { - gl = webgl_util.createWebGLRenderingContextFromCanvas(canvas, attributes); - } - else { - gl = webgl_util.createWebGLRenderingContext(attributes); - } - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.DEPTH_TEST); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.STENCIL_TEST); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.BLEND); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.DITHER); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.POLYGON_OFFSET_FILL); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.SAMPLE_COVERAGE); }); - webgl_util.callAndCheck(gl, function () { return gl.enable(gl.SCISSOR_TEST); }); - webgl_util.callAndCheck(gl, function () { return gl.enable(gl.CULL_FACE); }); - webgl_util.callAndCheck(gl, function () { return gl.cullFace(gl.BACK); }); - return gl; -} -exports.createWebGLContext = createWebGLContext; -function createVertexShader(gl) { - var vertexShaderSource = "\n precision highp float;\n attribute vec3 clipSpacePos;\n attribute vec2 uv;\n varying vec2 resultUV;\n\n void main() {\n gl_Position = vec4(clipSpacePos, 1);\n resultUV = uv;\n }"; - return webgl_util.createVertexShader(gl, vertexShaderSource); -} -exports.createVertexShader = createVertexShader; -function createVertexBuffer(gl) { - var vertexArray = new Float32Array([-1, 1, 0, 0, 1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 1, -1, 0, 1, 0]); - return webgl_util.createStaticVertexBuffer(gl, vertexArray); -} -exports.createVertexBuffer = createVertexBuffer; -function createIndexBuffer(gl) { - var triangleVertexIndices = new Uint16Array([0, 1, 2, 2, 1, 3]); - return webgl_util.createStaticIndexBuffer(gl, triangleVertexIndices); -} -exports.createIndexBuffer = createIndexBuffer; -function getTextureInternalFormat(gl, numChannels) { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return gl.RGBA; - } - if (environment_1.ENV.get('WEBGL_VERSION') === 2) { - if (numChannels === 4) { - return gl.RGBA32F; - } - return gl.R32F; - } - return gl.RGBA; -} -function getTextureFormat(gl, numChannels) { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return gl.RGBA; - } - if (environment_1.ENV.get('WEBGL_VERSION') === 2) { - if (numChannels === 4) { - return gl.RGBA; - } - return gl.RED; - } - return gl.RGBA; -} -function getTextureType(gl) { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return gl.UNSIGNED_BYTE; - } - return gl.FLOAT; -} -function createAndConfigureTexture(gl, width, height, numChannels) { - webgl_util.validateTextureSize(gl, width, height); - var texture = webgl_util.createTexture(gl); - var tex2d = gl.TEXTURE_2D; - var internalFormat = getTextureInternalFormat(gl, numChannels); - var format = getTextureFormat(gl, numChannels); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(tex2d, texture); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MIN_FILTER, gl.NEAREST); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MAG_FILTER, gl.NEAREST); }); - webgl_util.callAndCheck(gl, function () { return gl.texImage2D(tex2d, 0, internalFormat, width, height, 0, format, getTextureType(gl), null); }); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); - return texture; -} -function createMatrixTexture(gl, rows, columns) { - var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - var numChannels = 1; - return createAndConfigureTexture(gl, width, height, numChannels); -} -exports.createMatrixTexture = createMatrixTexture; -function createColorMatrixTexture(gl, rows, columns) { - var _a = tex_util.getColorMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - var numChannels = 4; - return createAndConfigureTexture(gl, width, height, numChannels); -} -exports.createColorMatrixTexture = createColorMatrixTexture; -function createPackedMatrixTexture(gl, rows, columns) { - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - var numChannels = 4; - return createAndConfigureTexture(gl, width, height, numChannels); -} -exports.createPackedMatrixTexture = createPackedMatrixTexture; -function bindVertexProgramAttributeStreams(gl, program, vertexBuffer, attribLocations) { - var posOffset = 0; - var uvOffset = 3 * 4; - var stride = (3 * 4) + (2 * 4); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); }); - webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'clipSpacePos', vertexBuffer, 3, stride, posOffset, attribLocations); - webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'uv', vertexBuffer, 2, stride, uvOffset, attribLocations); -} -exports.bindVertexProgramAttributeStreams = bindVertexProgramAttributeStreams; -function uploadPixelDataToTexture(gl, texture, pixels) { - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); }); - webgl_util.callAndCheck(gl, function () { return gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels); }); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); -} -exports.uploadPixelDataToTexture = uploadPixelDataToTexture; -function uploadDataToTexture(gl, texture, width, height, data, numChannels) { - var textureFormat = getTextureFormat(gl, numChannels); - webgl_util.validateTextureSize(gl, width, height); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); }); - webgl_util.callAndCheck(gl, function () { return gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, textureFormat, getTextureType(gl), data); }); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); -} -function uploadMatrixToTexture(gl, texture, rows, columns, matrix, numChannels) { - var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var unpackedArray; - if (environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - var channelsPerTexture = numChannels === 1 ? webgl_util.getChannelsPerTexture() : numChannels; - if (channelsPerTexture === 1) { - unpackedArray = matrix; - } - else { - unpackedArray = - new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(matrix.length, channelsPerTexture)); - tex_util.encodeMatrixToUnpackedArray(matrix, unpackedArray, channelsPerTexture); - } - } - else { - unpackedArray = tex_util.encodeFloatArray(matrix); - } - uploadDataToTexture(gl, texture, w, h, unpackedArray, numChannels); -} -exports.uploadMatrixToTexture = uploadMatrixToTexture; -function uploadMatrixToPackedTexture(gl, texture, rows, columns, matrix) { - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var packedRGBA = new Float32Array(tex_util.getPackedRGBAArraySizeFromMatrixShape(rows, columns)); - tex_util.encodeMatrixToPackedRGBA(matrix, rows, columns, packedRGBA); - var numChannels = 4; - uploadDataToTexture(gl, texture, w, h, packedRGBA, numChannels); -} -exports.uploadMatrixToPackedTexture = uploadMatrixToPackedTexture; -function getDownloadTargetArrayBuffer(rows, columns, channelsPerTexture) { - var isFloatTexture = environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED'); - var downloadTarget; - if (isFloatTexture) { - downloadTarget = - new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(rows * columns, channelsPerTexture)); - } - else { - downloadTarget = new Uint8Array(rows * columns * channelsPerTexture); - } - return downloadTarget; -} -function decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel) { - var isFloatTexture = environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED'); - if (isFloatTexture) { - var matrix = new Float32Array(rows * columns); - tex_util.decodeMatrixFromUnpackedArray(downloadTarget, matrix, channelsPerPixel); - return matrix; - } - else { - return tex_util.decodeToFloatArray(downloadTarget); - } -} -function downloadMatrixFromOutputTextureAsync(gl, getBufferSubDataAsyncExtension, rows, columns) { - return __awaiter(this, void 0, void 0, function () { - var gl2, channelsPerPixel, downloadTarget, bufferSizeBytes, buffer; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - gl2 = gl; - channelsPerPixel = 4; - downloadTarget = getDownloadTargetArrayBuffer(rows, columns, channelsPerPixel); - bufferSizeBytes = downloadTarget instanceof Float32Array ? - downloadTarget.length * 4 : - downloadTarget; - buffer = gl.createBuffer(); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl2.PIXEL_PACK_BUFFER, buffer); }); - webgl_util.callAndCheck(gl, function () { return gl.bufferData(gl2.PIXEL_PACK_BUFFER, bufferSizeBytes, gl.STATIC_DRAW); }); - webgl_util.callAndCheck(gl, function () { - return gl2.readPixels(0, 0, columns, rows, gl.RGBA, getTextureType(gl), 0); - }); - return [4, getBufferSubDataAsyncExtension.getBufferSubDataAsync(gl2.PIXEL_PACK_BUFFER, 0, downloadTarget)]; - case 1: - _a.sent(); - return [2, decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel)]; - } - }); - }); -} -exports.downloadMatrixFromOutputTextureAsync = downloadMatrixFromOutputTextureAsync; -function downloadMatrixFromOutputTexture(gl, rows, columns) { - var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var channelsPerPixel = 4; - var downloadTarget = getDownloadTargetArrayBuffer(rows, columns, channelsPerPixel); - webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, gl.RGBA, getTextureType(gl), downloadTarget); }); - return decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel); -} -exports.downloadMatrixFromOutputTexture = downloadMatrixFromOutputTexture; -function downloadMatrixFromRGBAColorTexture(gl, rows, columns, channels) { - var size = rows * columns * 4; - var downloadTarget = new Uint8Array(size); - webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, columns, rows, gl.RGBA, gl.UNSIGNED_BYTE, downloadTarget); }); - var packedRGBA = new Float32Array(size); - for (var i = 0; i < downloadTarget.length; i++) { - packedRGBA[i] = downloadTarget[i]; - } - var matrix = new Float32Array(rows * columns * channels); - tex_util.decodeMatrixFromUnpackedColorRGBAArray(packedRGBA, matrix, channels); - return matrix; -} -exports.downloadMatrixFromRGBAColorTexture = downloadMatrixFromRGBAColorTexture; -function downloadMatrixFromPackedOutputTexture(gl, rows, columns) { - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var packedRGBA = new Float32Array(tex_util.getPackedRGBAArraySizeFromMatrixShape(rows, columns)); - webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, gl.RGBA, getTextureType(gl), packedRGBA); }); - var matrix = new Float32Array(rows * columns); - return tex_util.decodeMatrixFromPackedRGBA(packedRGBA, rows, columns, matrix); -} -exports.downloadMatrixFromPackedOutputTexture = downloadMatrixFromPackedOutputTexture; - -},{"../../environment":34,"./tex_util":99,"./webgl_util":104}],86:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var WhereProgram = (function () { - function WhereProgram(cRank, shape, rank) { - this.variableNames = ['c', 'a', 'b']; - this.outputShape = shape; - var cCoords; - var abCoords; - if (rank > 4) { - throw Error("Where for rank " + rank + " is not yet supported"); - } - if (rank === 1) { - abCoords = "resRC"; - cCoords = "resRC"; - } - else { - var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var cCoordVars = []; - var abCoordVars = []; - for (var i = 0; i < shape.length; i++) { - abCoordVars.push("" + currentCoords[i]); - if (i < cRank) { - cCoordVars.push("" + currentCoords[i]); - } - } - cCoords = cCoordVars.join(); - abCoords = abCoordVars.join(); - } - var dtype = shader_compiler_1.getCoordsDataType(rank); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n float cVal = getC(" + cCoords + ");\n if (cVal >= 1.0) {\n setOutput(getA(" + abCoords + "));\n } else {\n setOutput(getB(" + abCoords + "));\n }\n }\n "; - } - return WhereProgram; -}()); -exports.WhereProgram = WhereProgram; - -},{"./shader_compiler":97}],87:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var LRNProgram = (function () { - function LRNProgram(xShape, radius, bias, alpha, beta, normRegion) { - this.variableNames = ['x']; - this.outputShape = []; - var rad = radius; - var maxW = xShape[1] - 1; - var maxH = xShape[2] - 1; - var maxD = xShape[3] - 1; - this.outputShape = xShape; - var powOperator; - var basis = "float(" + bias + ") + float(" + alpha + ") * sum"; - if (beta === 0.5) { - powOperator = "inversesqrt(" + basis + ")"; - } - else if (beta === 1.0) { - powOperator = "1.0/(" + basis + ")"; - } - else { - powOperator = "exp(log(" + basis + ") * float(-" + beta + "));"; - } - if (normRegion === 'withinChannel') { - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int u = -" + rad + "; u <= " + rad + "; u++) {\n for (int v = -" + rad + "; v <= " + rad + "; v++) {\n int idx = r + u;\n int idy = c + v;\n if (idx >= 0 && idx <= " + maxW + " && idy >= 0 && idy <= " + maxH + ") {\n float z = getX(b, idx, idy, d);\n sum += z * z;\n }\n }\n }\n float val = x * " + powOperator + ";\n setOutput(val);\n }\n "; - } - else { - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int j = -" + rad + "; j <= " + rad + "; j++) {\n int idx = d + j;\n if (idx >= 0 && idx <= " + maxD + ") {\n float z = getX(b, r, c, idx);\n sum += z * z;\n }\n }\n float val = x * " + powOperator + ";\n setOutput(val);\n }\n "; - } - } - return LRNProgram; -}()); -exports.LRNProgram = LRNProgram; - -},{}],88:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MaxPool2DBackpropProgram = (function () { - function MaxPool2DBackpropProgram(convInfo) { - this.variableNames = ['dy', 'maxPos']; - this.outputShape = convInfo.inShape; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var lastIndex = filterHeight * filterWidth - 1; - this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n int maxPosValue = " + lastIndex + " - int(getMaxPos(b, idyR, idyC, d));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue = wR * " + filterWidth + " + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n setOutput(dotProd);\n }\n "; - } - return MaxPool2DBackpropProgram; -}()); -exports.MaxPool2DBackpropProgram = MaxPool2DBackpropProgram; - -},{}],89:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MatMulProgram = (function () { - function MatMulProgram(aShape, bShape, transposeA, transposeB) { - if (transposeA === void 0) { transposeA = false; } - if (transposeB === void 0) { transposeB = false; } - this.variableNames = ['matrixA', 'matrixB']; - var outerShapeA = transposeA ? aShape[1] : aShape[0]; - var outerShapeB = transposeB ? bShape[0] : bShape[1]; - var sharedDim = transposeA ? aShape[0] : aShape[1]; - this.outputShape = [outerShapeA, outerShapeB]; - var aSnippetFromOffset = function (vec4Offset, indexVar) { - return transposeA ? indexVar + " + " + vec4Offset + ", aRow" : - "aRow, " + indexVar + " + " + vec4Offset; - }; - var bSnippetFromOffset = function (vec4Offset, indexVar) { - return transposeB ? "bCol, " + indexVar + " + " + vec4Offset : - indexVar + " + " + vec4Offset + ", bCol"; - }; - var sharedDimNearestVec4 = Math.floor(sharedDim / 4) * 4; - var sharedDimVec4Remainder = sharedDim % 4; - this.userCode = " float dotARowBCol(int aRow, int bCol) {\n float result = 0.0;\n for (int i = 0; i < " + sharedDimNearestVec4 + "; i += 4) {\n vec4 a = vec4(\n getMatrixA(" + aSnippetFromOffset(0, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(1, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(2, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(3, 'i') + ")\n );\n vec4 b = vec4(\n getMatrixB(" + bSnippetFromOffset(0, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(1, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(2, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(3, 'i') + ")\n );\n\n result += dot(a, b);\n }\n\n if (" + (sharedDimVec4Remainder === 1) + ") {\n result += getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + ") *\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + ");\n } else if (" + (sharedDimVec4Remainder === 2) + ") {\n vec2 a = vec2(\n getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(1, sharedDimNearestVec4) + ")\n );\n vec2 b = vec2(\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(1, sharedDimNearestVec4) + ")\n );\n result += dot(a, b);\n } else if (" + (sharedDimVec4Remainder === 3) + ") {\n vec3 a = vec3(\n getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(1, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(2, sharedDimNearestVec4) + ")\n );\n vec3 b = vec3(\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(1, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(2, sharedDimNearestVec4) + ")\n );\n result += dot(a, b);\n }\n\n return result;\n }\n\n void main() {\n ivec2 resRC = getOutputCoords();\n setOutput(dotARowBCol(resRC.x, resRC.y));\n }\n "; - } - return MatMulProgram; -}()); -exports.MatMulProgram = MatMulProgram; - -},{}],90:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MultinomialProgram = (function () { - function MultinomialProgram(batchSize, numOutcomes, numSamples) { - this.variableNames = ['probs']; - this.outputShape = [batchSize, numSamples]; - this.userCode = "\n uniform float seed;\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n\n float r = random(seed);\n float cdf = 0.0;\n\n for (int i = 0; i < " + (numOutcomes - 1) + "; i++) {\n cdf += getProbs(batch, i);\n\n if (r < cdf) {\n setOutput(float(i));\n return;\n }\n }\n\n // If no other event happened, last event happened.\n setOutput(float(" + (numOutcomes - 1) + "));\n }\n "; - } - MultinomialProgram.prototype.getCustomSetupFunc = function (seed) { - var _this = this; - return function (gpgpu, webGLProgram) { - if (_this.seedLoc == null) { - _this.seedLoc = gpgpu.getUniformLocation(webGLProgram, 'seed'); - } - gpgpu.gl.uniform1f(_this.seedLoc, seed); - }; - }; - return MultinomialProgram; -}()); -exports.MultinomialProgram = MultinomialProgram; - -},{}],91:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var OneHotProgram = (function () { - function OneHotProgram(numIndices, depth, onValue, offValue) { - this.variableNames = ['indices']; - this.outputShape = [numIndices, depth]; - this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int index = round(getIndices(coords.x));\n setOutput(mix(float(" + offValue + "), float(" + onValue + "),\n float(index == coords.y)));\n }\n "; - } - return OneHotProgram; -}()); -exports.OneHotProgram = OneHotProgram; - -},{}],92:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Pad1DProgram = (function () { - function Pad1DProgram(xShape, paddings, constantValue) { - this.variableNames = ['x']; - var leftPadding = paddings[0]; - var rightPadding = paddings[1]; - this.outputShape = [leftPadding + xShape[0] + rightPadding]; - this.rank = 1; - this.userCode = "\n void main() {\n int resRC = getOutputCoords();\n if (resRC < " + leftPadding + " || resRC >= " + leftPadding + " + " + xShape[0] + ") {\n setOutput(float(" + constantValue + "));\n } else {\n setOutput(getX(resRC - " + leftPadding + "));\n }\n }\n "; - } - return Pad1DProgram; -}()); -exports.Pad1DProgram = Pad1DProgram; -var Pad2DProgram = (function () { - function Pad2DProgram(xShape, paddings, constantValue) { - this.variableNames = ['x']; - var topPadding = paddings[0][0]; - var bottomPadding = paddings[0][1]; - var leftPadding = paddings[1][0]; - var rightPadding = paddings[1][1]; - this.outputShape = [ - topPadding + xShape[0] + bottomPadding, - leftPadding + xShape[1] + rightPadding - ]; - this.rank = 2; - var sourceCoords = "resRC.x - " + topPadding + ", resRC.y - " + leftPadding; - this.userCode = "\n void main() {\n ivec2 resRC = getOutputCoords();\n int topShape = " + topPadding + " + " + xShape[0] + ";\n int leftShape = " + leftPadding + " + " + xShape[1] + ";\n if (resRC.x < " + topPadding + " || resRC.x >= topShape ||\n resRC.y < " + leftPadding + " || resRC.y >= leftShape) {\n setOutput(float(" + constantValue + "));\n } else {\n setOutput(getX(" + sourceCoords + "));\n }\n }\n "; - } - return Pad2DProgram; -}()); -exports.Pad2DProgram = Pad2DProgram; - -},{}],93:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Pool2DProgram = (function () { - function Pool2DProgram(convInfo, poolType, computePositions) { - this.variableNames = ['x']; - if (poolType === 'avg' && computePositions) { - throw new Error('Cannot compute positions for average pool.'); - } - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - this.outputShape = convInfo.outShape; - var isAvgPool = poolType === 'avg'; - var initializationValue = '0.0'; - if (!isAvgPool) { - if (poolType === 'min') { - initializationValue = '1.0 / 0.0'; - } - else { - initializationValue = '-1.0 / 0.0'; - } - } - if (computePositions) { - var compareOp_1 = poolType === 'min' ? '<=' : '>='; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n float avgValue = 0.0;\n\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n float value = getX(batch, xR, xC, d);\n\n if (isNaN(value)) {\n setOutput(value);\n return;\n }\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value " + compareOp_1 + " currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = wR * " + filterWidth + " + wC;\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n "; - return; - } - var compareOp = poolType === 'min' ? 'min' : 'max'; - var returnValue = poolType + "(" + poolType + "(" + poolType + "(" + - 'minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])'; - if (poolType === 'avg') { - returnValue = "avgValue / " + filterHeight * filterWidth + ".0"; - } - var filterWidthNearestVec4 = Math.floor(filterWidth / 4) * 4; - var filterWidthVec4Remainder = filterWidth % 4; - var updateSnippet = "\n if (hasNaN(values)) {\n setOutput(getNaN(values));\n return;\n }\n if (" + isAvgPool + ") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = " + compareOp + "(values, minMaxValue);\n }\n "; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n const float initializationValue = " + initializationValue + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int xR, int xC, int d) {\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n return initializationValue;\n }\n return getX(batch, xR, xC, d);\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n vec4 minMaxValue = vec4(" + initializationValue + ");\n float avgValue = 0.0;\n\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidthNearestVec4 + "; wC += 4) {\n int xC = xCCorner + wC;\n\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n getValue(batch, xR, xC + 2, d),\n getValue(batch, xR, xC + 3, d)\n );\n\n " + updateSnippet + "\n }\n\n int xC = xCCorner + " + filterWidthNearestVec4 + ";\n if (" + (filterWidthVec4Remainder === 1) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n initializationValue,\n initializationValue,\n initializationValue\n );\n " + updateSnippet + "\n } else if (" + (filterWidthVec4Remainder === 2) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n initializationValue,\n initializationValue\n );\n\n " + updateSnippet + "\n } else if (" + (filterWidthVec4Remainder === 3) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n getValue(batch, xR, xC + 2, d),\n initializationValue\n );\n\n " + updateSnippet + "\n }\n }\n setOutput(" + returnValue + ");\n }\n "; - } - return Pool2DProgram; -}()); -exports.Pool2DProgram = Pool2DProgram; - -},{}],94:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ReduceProgram = (function () { - function ReduceProgram(reduceInfo, reduceType) { - this.variableNames = ['x']; - var windowSize = reduceInfo.windowSize; - var batchSize = reduceInfo.batchSize; - var inSize = reduceInfo.inSize; - var outSize = Math.ceil(inSize / windowSize); - this.outputShape = [batchSize, outSize]; - var isReduceSum = reduceType === 'sum'; - var initializationValue = '0.0'; - if (!isReduceSum) { - if (reduceType === 'min') { - initializationValue = '1.0 / 0.0'; - } - else { - initializationValue = '-1.0 / 0.0'; - } - } - var compareOp = reduceType === 'min' ? 'min' : 'max'; - var returnValue = reduceType + "(" + reduceType + "(" + reduceType + "(" + - 'minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])'; - if (reduceType === 'sum') { - returnValue = "sumValue"; - } - var windowSizeNearestVec4 = Math.floor(windowSize / 4) * 4; - var windowSizeVec4Remainder = windowSize % 4; - var updateSnippet = "\n if (" + isReduceSum + ") {\n sumValue += dot(values, ones);\n } else {\n if (hasNaN(values)) {\n setOutput(getNaN(values));\n return;\n }\n minMaxValue = " + compareOp + "(values, minMaxValue);\n }\n "; - var checkOutOfBounds = ''; - if (inSize % windowSize > 0) { - checkOutOfBounds = "\n if (inIdx < 0 || inIdx >= " + inSize + ") {\n return initializationValue;\n }\n "; - } - this.userCode = "\n const float initializationValue = " + initializationValue + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int inIdx) {\n " + checkOutOfBounds + "\n return getX(batch, inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * " + windowSize + ";\n\n vec4 minMaxValue = vec4(" + initializationValue + ");\n float sumValue = 0.0;\n\n for (int i = 0; i < " + windowSizeNearestVec4 + "; i += 4) {\n int inIdx = inOffset + i;\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n " + updateSnippet + "\n }\n\n int inIdx = inOffset + " + windowSizeNearestVec4 + ";\n if (" + (windowSizeVec4Remainder === 1) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n " + updateSnippet + "\n } else if (" + (windowSizeVec4Remainder === 2) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n " + updateSnippet + "\n } else if (" + (windowSizeVec4Remainder === 3) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n " + updateSnippet + "\n }\n setOutput(" + returnValue + ");\n }\n "; - } - return ReduceProgram; -}()); -exports.ReduceProgram = ReduceProgram; - -},{}],95:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ResizeBilinearProgram = (function () { - function ResizeBilinearProgram(inputShape, newHeight, newWidth, alignCorners) { - this.variableNames = ['A']; - this.outputShape = []; - var batch = inputShape[0], oldHeight = inputShape[1], oldWidth = inputShape[2], depth = inputShape[3]; - this.outputShape = [batch, newHeight, newWidth, depth]; - var effectiveInSize = alignCorners ? [oldHeight - 1, oldWidth - 1] : [oldHeight, oldWidth]; - var effectiveOutSize = alignCorners ? [newHeight - 1, newWidth - 1] : [newHeight, newWidth]; - this.userCode = "\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n " + effectiveInSize[0] / effectiveOutSize[0] + ",\n " + effectiveInSize[1] / effectiveOutSize[1] + ");\n const vec2 inputShapeRC = vec2(" + oldHeight + ".0, " + oldWidth + ".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);\n ivec2 sourceCeilRC = ivec2(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);\n float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);\n float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);\n float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);\n\n vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);\n\n float top = topLeft + (topRight - topLeft) * fracRC.y;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;\n float newValue = top + (bottom - top) * fracRC.x;\n\n setOutput(newValue);\n }\n "; - } - return ResizeBilinearProgram; -}()); -exports.ResizeBilinearProgram = ResizeBilinearProgram; - -},{}],96:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ReverseProgram = (function () { - function ReverseProgram(xShape, axis) { - this.variableNames = ['x']; - this.outputShape = xShape; - var getRevVar = function (i) { - if (axis.indexOf(i) !== -1 && xShape[i] !== 1) { - return xShape[i] + " - coords[" + i + "] - 1"; - } - return "coords[" + i + "]"; - }; - var b = getRevVar(0); - var r = getRevVar(1); - var c = getRevVar(2); - var d = getRevVar(3); - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n float val = getX(" + b + ", " + r + ", " + c + ", " + d + ");\n setOutput(val);\n }\n "; - } - return ReverseProgram; -}()); -exports.ReverseProgram = ReverseProgram; - -},{}],97:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var util = require("../../util"); -var broadcast_util = require("../../ops/broadcast_util"); -var tex_util = require("./tex_util"); -function makeShader(inputsInfo, outputShape, userCode, broadcast) { - var sampleSnippet = getSampleSnippet(); - var setOutputSnippet = getSetOutputSnippet(); - var inputPrefixSnippet = inputsInfo.map(function (x) { return "uniform sampler2D " + x.name + ";"; }).join('\n'); - var inputSamplingSnippet = inputsInfo.map(function (x) { return getInputSamplingSnippet(x, outputShape, broadcast); }) - .join('\n'); - var outTexShape = outputShape.texShape; - var outputSamplingSnippet = getOutputSamplingSnippet(outputShape.logicalShape, outTexShape); - var source = [ - SHADER_PREFIX, sampleSnippet, setOutputSnippet, inputPrefixSnippet, - outputSamplingSnippet, inputSamplingSnippet, userCode - ].join('\n'); - return source; -} -exports.makeShader = makeShader; -function getSampleSnippet() { - return environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED') ? - FLOAT_TEXTURE_SAMPLE_SNIPPET : - UNSIGNED_BYTE_TEXTURE_SAMPLE_SNIPPET; -} -function getSetOutputSnippet() { - return environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED') ? - FLOAT_TEXTURE_SETOUTPUT_SNIPPET : - UNSIGNED_BYTE_TEXTURE_SETOUTPUT_SNIPPET; -} -function getSamplerFromInInfo(inInfo) { - var shape = inInfo.shapeInfo.logicalShape; - switch (shape.length) { - case 0: - return getSamplerScalar(inInfo); - case 1: - return getSampler1D(inInfo); - case 2: - return getSampler2D(inInfo); - case 3: - return getSampler3D(inInfo); - case 4: - return getSampler4D(inInfo); - default: - throw new Error(shape.length + "-D input sampling" + - " is not yet supported"); - } -} -function getInputSamplingSnippet(inInfo, outShapeInfo, broadcast) { - var res = getSamplerFlat(inInfo); - res += getSamplerFromInInfo(inInfo); - if (broadcast || - util.arraysEqual(inInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape)) { - res += getSamplerAtOutputCoords(inInfo, outShapeInfo, broadcast); - } - return res; -} -function getOutputSamplingSnippet(outShape, outTexShape) { - switch (outShape.length) { - case 0: - return getOutputScalarCoords(); - case 1: - return getOutput1DCoords(outShape, outTexShape); - case 2: - return getOutput2DCoords(outShape, outTexShape); - case 3: - return getOutput3DCoords(outShape, outTexShape); - case 4: - return getOutput4DCoords(outShape, outTexShape); - default: - throw new Error(outShape.length + "-D output sampling is not yet supported"); - } -} -var SAMPLE_1D_SNIPPET = "\nvec2 UVfrom1D(int texNumR, int texNumC, int index) {\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var SAMPLE_2D_SNIPPET = "\nvec2 UVfrom2D(int texNumR, int texNumC, int numC, int row, int col) {\n int index = row * numC + col;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var SAMPLE_3D_SNIPPET = "\nvec2 UVfrom3D(int texNumR, int texNumC, int stride0,\n int stride1, int row, int col, int depth) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var SAMPLE_4D_SNIPPET = "\nvec2 UVfrom4D(int texNumR, int texNumC, int stride0,\n int stride1, int stride2, int row, int col, int depth,\n int depth2) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth * stride2 + depth2;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var UNSIGNED_BYTE_TEXTURE_SAMPLE_SNIPPET = "\n uniform float NaN;\n\n const vec4 floatDeltas = vec4(\n 1.0,\n 1.0 / 255.0,\n 1.0 / (255.0 * 255.0),\n 1.0 / (255.0 * 255.0 * 255.0)\n );\n const float minValue = " + tex_util.FLOAT_MIN + ".0;\n const float maxValue = " + tex_util.FLOAT_MAX + ".0;\n const float range = (maxValue - minValue) / 255.0;\n const vec2 dotRange = vec2(1.0, range);\n\n float sample(sampler2D texture, vec2 uv) {\n vec4 sampleValue = texture2D(texture, uv);\n if (all(equal(sampleValue, vec4(" + tex_util.BYTE_NAN_VALUE + ")))) {\n return NaN;\n }\n\n vec4 encValue = floor(sampleValue * 255.0 + 0.5);\n float decodedValue = dot(encValue, floatDeltas);\n return dot(vec2(minValue, decodedValue), dotRange);\n }\n"; -var UNSIGNED_BYTE_TEXTURE_SETOUTPUT_SNIPPET = "\n const vec4 floatPowers = vec4(\n 1.0,\n 255.0,\n 255.0 * 255.0,\n 255.0 * 255.0 * 255.0\n );\n const vec2 recipRange = vec2(1.0/range);\n const vec2 recipRange255 = vec2(1.0/(maxValue - minValue));\n\n void setOutput(float decodedValue) {\n if (isNaN(decodedValue)) {\n gl_FragColor = vec4(" + tex_util.BYTE_NAN_VALUE + ");\n return;\n }\n\n float a = dot(vec2(decodedValue, -minValue), recipRange);\n float b = fract(a) * 255.0;\n float c = fract(b) * 255.0;\n float d = fract(c) * 255.0;\n gl_FragColor = floor(vec4(a, b, c, d)) / 255.0;\n\n // TODO(dsmilkov): Version above gets better accuracy but probably slower\n // than the version below. Benchmark to determine if the accuracy is worth\n // the cost.\n\n // float normValue = dot(vec2(decodedValue, -minValue), recipRange255);\n // vec4 f = normValue * floatPowers;\n // gl_FragColor = floor(fract(f) * 255.0) / 255.0;\n }\n"; -var FLOAT_TEXTURE_SAMPLE_SNIPPET = "\n float sample(sampler2D texture, vec2 uv) {\n return texture2D(texture, uv).r;\n }\n"; -var FLOAT_TEXTURE_SETOUTPUT_SNIPPET = "\n void setOutput(float val) {\n gl_FragColor = vec4(val, 0, 0, 0);\n }\n"; -var SHADER_PREFIX = "\n precision highp float;\n precision highp int;\n varying vec2 resultUV;\n const vec2 halfCR = vec2(0.5, 0.5);\n\n bool isNaN(float val) {\n float v1 = val * val;\n float v2 = val * val;\n return v1 == v2 ? false : true;\n }\n\n bool hasNaN(vec4 values) {\n vec4 v1 = values * values;\n vec4 v2 = values * values;\n return any(notEqual(v1, v2));\n }\n\n float getNaN(vec4 values) {\n return dot(vec4(1), values);\n }\n\n int round(float value) {\n return int(floor(value + 0.5));\n }\n\n int imod(int x, int y) {\n return x - y * (x / y);\n }\n\n const vec2 randomConst = vec2(\n 23.14069263277926, // e^pi (Gelfond's constant)\n 2.665144142690225 // 2^sqrt(2) (Gelfond\u2013Schneider constant)\n );\n\n float random(float seed) {\n return fract(cos(dot(resultUV * seed, randomConst)) * 12345.6789);\n }\n\n " + SAMPLE_1D_SNIPPET + "\n " + SAMPLE_2D_SNIPPET + "\n " + SAMPLE_3D_SNIPPET + "\n " + SAMPLE_4D_SNIPPET + "\n"; -function getOutputScalarCoords() { - return "\n int getOutputCoords() {\n return 0;\n }\n "; -} -function getOutput1DCoords(shape, texShape) { - if (texShape[0] === 1) { - return "\n int getOutputCoords() {\n return int(resultUV.x * " + texShape[1] + ".0);\n }\n "; - } - if (texShape[1] === 1) { - return "\n int getOutputCoords() {\n return int(resultUV.y * " + texShape[0] + ".0);\n }\n "; - } - return "\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n return resTexRC.x * " + texShape[1] + " + resTexRC.y;\n }\n "; -} -function getOutput3DCoords(shape, texShape) { - var stride0 = shape[1] * shape[2]; - var stride1 = shape[2]; - return "\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n int r = index / " + stride0 + ";\n index -= r * " + stride0 + ";\n int c = index / " + stride1 + ";\n int d = index - c * " + stride1 + ";\n return ivec3(r, c, d);\n }\n "; -} -function getOutput4DCoords(shape, texShape) { - var stride2 = shape[3]; - var stride1 = shape[2] * stride2; - var stride0 = shape[1] * stride1; - return "\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n\n int r = index / " + stride0 + ";\n index -= r * " + stride0 + ";\n\n int c = index / " + stride1 + ";\n index -= c * " + stride1 + ";\n\n int d = index / " + stride2 + ";\n int d2 = index - d * " + stride2 + ";\n\n return ivec4(r, c, d, d2);\n }\n "; -} -function getOutput2DCoords(shape, texShape) { - if (util.arraysEqual(shape, texShape)) { - return "\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2(" + texShape[0] + ", " + texShape[1] + "));\n }\n "; - } - if (shape[1] === 1) { - return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n return ivec2(index, 0);\n }\n "; - } - if (shape[0] === 1) { - return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n return ivec2(0, index);\n }\n "; - } - return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n int r = index / " + shape[1] + ";\n int c = index - r * " + shape[1] + ";\n return ivec2(r, c);\n }\n "; -} -function getSamplerScalar(inputInfo) { - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - return "\n float " + funcName + "() {\n return sample(" + texName + ", halfCR);\n }\n "; -} -function getSampler1D(inputInfo) { - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - return "\n float " + funcName + "(int index) {\n return " + funcName + "Flat(index);\n }\n "; -} -function getSampler2D(inputInfo) { - var shape = inputInfo.shapeInfo.logicalShape; - var texShape = inputInfo.shapeInfo.texShape; - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - var texNumR = texShape[0]; - var texNumC = texShape[1]; - if (util.arraysEqual(shape, texShape)) { - return "\n float " + funcName + "(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims; - var squeezedShape = newShape; - if (squeezedShape.length < shape.length) { - var newInputInfo = squeezeInputInfo(inputInfo, squeezedShape); - var params = ['row', 'col']; - return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n "; - } - if (texNumC === 1) { - return "\n float " + funcName + "(int row, int col) {\n int index = row * " + shape[1] + " + col;\n vec2 uv = vec2(0.5, (float(index) + 0.5) / " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (texNumR === 1) { - return "\n float " + funcName + "(int row, int col) {\n int index = row * " + shape[1] + " + col;\n vec2 uv = vec2((float(index) + 0.5) / " + texNumC + ".0, 0.5);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int row, int col) {\n vec2 uv = UVfrom2D(" + texNumR + ", " + texNumC + ", " + shape[1] + ", row, col);\n return sample(" + texName + ", uv);\n }\n"; -} -function getSampler3D(inputInfo) { - var texShape = inputInfo.shapeInfo.texShape; - var shape = inputInfo.shapeInfo.logicalShape; - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - var texNumR = texShape[0]; - var texNumC = texShape[1]; - var stride0 = shape[1] * shape[2]; - var stride1 = shape[2]; - var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims; - var squeezedShape = newShape; - if (squeezedShape.length < shape.length) { - var newInputInfo = squeezeInputInfo(inputInfo, squeezedShape); - var params = ['row', 'col', 'depth']; - return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col, int depth) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n "; - } - if (texNumC === stride0) { - return "\n float " + funcName + "(int row, int col, int depth) {\n int texR = row;\n int texC = col * " + stride1 + " + depth;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (texNumC === stride1) { - return "\n float " + funcName + "(int row, int col, int depth) {\n int texR = row * " + shape[1] + " + col;\n int texC = depth;\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int row, int col, int depth) {\n vec2 uv = UVfrom3D(\n " + texNumR + ", " + texNumC + ", " + stride0 + ", " + stride1 + ", row, col, depth);\n return sample(" + texName + ", uv);\n }\n "; -} -function getSampler4D(inputInfo) { - var shape = inputInfo.shapeInfo.logicalShape; - var texShape = inputInfo.shapeInfo.texShape; - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - var texNumR = texShape[0]; - var texNumC = texShape[1]; - var stride2 = shape[3]; - var stride1 = shape[2] * stride2; - var stride0 = shape[1] * stride1; - var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims; - if (newShape.length < shape.length) { - var newInputInfo = squeezeInputInfo(inputInfo, newShape); - var params = ['row', 'col', 'depth', 'depth2']; - return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n "; - } - if (texNumC === stride0) { - return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n int texR = row;\n int texC = col * " + stride1 + " + depth * " + stride2 + " + depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (texNumC === stride2) { - return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n int texR = row * " + shape[1] * shape[2] + " + col * " + shape[2] + " + depth;\n int texC = depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n vec2 uv = UVfrom4D(" + texNumR + ", " + texNumC + ", " + stride0 + ", " + stride1 + ",\n " + stride2 + ", row, col, depth, depth2);\n return sample(" + texName + ", uv);\n }\n "; -} -function getSamplerFlat(inputInfo) { - var texName = inputInfo.name; - var texShape = inputInfo.shapeInfo.texShape; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1) + 'Flat'; - var tNumR = texShape[0]; - var tNumC = texShape[1]; - if (tNumC === 1 && tNumR === 1) { - return "\n float " + funcName + "(int index) {\n return sample(" + texName + ", halfCR);\n }\n "; - } - if (tNumC === 1) { - return "\n float " + funcName + "(int index) {\n vec2 uv = vec2(0.5, (float(index) + 0.5) / " + tNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (tNumR === 1) { - return "\n float " + funcName + "(int index) {\n vec2 uv = vec2((float(index) + 0.5) / " + tNumC + ".0, 0.5);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int index) {\n vec2 uv = UVfrom1D(" + tNumR + ", " + tNumC + ", index);\n return sample(" + texName + ", uv);\n }\n "; -} -function getBroadcastOutputCoordsSampler(inputInfo, outShapeInfo, texFuncSnippet, funcName) { - var inRank = inputInfo.shapeInfo.logicalShape.length; - var outRank = outShapeInfo.logicalShape.length; - var type = 'int'; - if (outRank === 2) { - type = 'ivec2'; - } - else if (outRank === 3) { - type = 'ivec3'; - } - else if (outRank === 4) { - type = 'ivec4'; - } - var broadcastDims = broadcast_util.getBroadcastDims(inputInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape); - var rankDiff = outRank - inRank; - var coordsSnippet; - if (inRank === 0) { - coordsSnippet = ''; - } - else if (outRank < 2 && broadcastDims.length >= 1) { - coordsSnippet = 'coords = 0;'; - } - else { - coordsSnippet = - broadcastDims.map(function (d) { return "coords[" + (d + rankDiff) + "] = 0;"; }).join('\n'); - } - var unpackedCoordsSnippet = ''; - if (outRank < 2 && inRank > 0) { - unpackedCoordsSnippet = 'coords'; - } - else { - unpackedCoordsSnippet = inputInfo.shapeInfo.logicalShape - .map(function (s, i) { return "coords[" + (i + rankDiff) + "]"; }) - .join(', '); - } - return "\n float " + funcName + "() {\n " + type + " coords = getOutputCoords();\n " + coordsSnippet + "\n return get" + texFuncSnippet + "(" + unpackedCoordsSnippet + ");\n }\n "; -} -function getSamplerAtOutputCoords(inputInfo, outShapeInfo, supportsBroadcasting) { - var inTexShape = inputInfo.shapeInfo.texShape; - var texName = inputInfo.name; - var texFuncSnippet = texName.charAt(0).toUpperCase() + texName.slice(1); - var funcName = 'get' + texFuncSnippet + 'AtOutCoords'; - var broadcastDims = broadcast_util.getBroadcastDims(inputInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape); - var inRank = inputInfo.shapeInfo.logicalShape.length; - var outRank = outShapeInfo.logicalShape.length; - var doBroadcast = supportsBroadcasting && ((outRank > inRank) || broadcastDims.length > 0); - var broadcastOverOuter = broadcast_util.broadcastDimsAreOuter(broadcastDims); - if (doBroadcast && !broadcastOverOuter) { - return getBroadcastOutputCoordsSampler(inputInfo, outShapeInfo, texFuncSnippet, funcName); - } - var outTexShape = outShapeInfo.texShape; - if (util.arraysEqual(inTexShape, outTexShape)) { - return "\n float " + funcName + "() {\n return sample(" + texName + ", resultUV);\n }\n "; - } - var inSize = util.sizeFromShape(inTexShape); - var broadcastSnippet = ''; - if (doBroadcast && broadcastOverOuter) { - broadcastSnippet = "\n int mainPart = index / " + inSize + ";\n index -= mainPart * " + inSize + ";\n "; - } - return "\n float " + funcName + "() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + outTexShape[0] + ", " + outTexShape[1] + "));\n int index = resTexRC.x * " + outTexShape[1] + " + resTexRC.y;\n " + broadcastSnippet + "\n int texR = index / " + inTexShape[1] + ";\n int texC = index - texR * " + inTexShape[1] + ";\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + inTexShape[1] + ".0, " + inTexShape[0] + ".0);\n\n return sample(" + texName + ", uv);\n }\n "; -} -function getCoordsDataType(rank) { - if (rank <= 1) { - return 'int'; - } - else if (rank === 2) { - return 'ivec2'; - } - else if (rank === 3) { - return 'ivec3'; - } - else if (rank === 4) { - return 'ivec4'; - } - else { - throw Error("GPU for rank " + rank + " is not yet supported"); - } -} -exports.getCoordsDataType = getCoordsDataType; -function squeezeInputInfo(inInfo, squeezedShape) { - var newInputInfo = JSON.parse(JSON.stringify(inInfo)); - newInputInfo.shapeInfo.logicalShape = squeezedShape; - return newInputInfo; -} -function getSqueezedParams(params, keptDims) { - return keptDims.map(function (d) { return params[d]; }).join(', '); -} - -},{"../../environment":34,"../../ops/broadcast_util":110,"../../util":151,"./tex_util":99}],98:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var SliceProgram = (function () { - function SliceProgram(destSize) { - this.variableNames = ['source']; - this.outputShape = destSize; - this.rank = destSize.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var sourceCoords = getCoords(this.rank); - this.userCode = "\n uniform " + dtype + " start;\n\n void main() {\n " + dtype + " sourceLoc = start + getOutputCoords();\n setOutput(getSource(" + sourceCoords + "));\n }\n "; - } - SliceProgram.prototype.getCustomSetupFunc = function (start) { - var _this = this; - if (start.length !== this.rank) { - throw Error("The rank (" + this.rank + ") of the program must match the " + - ("length of start (" + start.length + ")")); - } - return function (gpgpu, webGLProgram) { - if (_this.startLoc == null) { - _this.startLoc = gpgpu.getUniformLocationNoThrow(webGLProgram, 'start'); - if (_this.startLoc == null) { - return; - } - } - if (_this.rank === 1) { - gpgpu.gl.uniform1i(_this.startLoc, start[0]); - } - else if (_this.rank === 2) { - gpgpu.gl.uniform2i(_this.startLoc, start[0], start[1]); - } - else if (_this.rank === 3) { - gpgpu.gl.uniform3i(_this.startLoc, start[0], start[1], start[2]); - } - else if (_this.rank === 4) { - gpgpu.gl.uniform4i(_this.startLoc, start[0], start[1], start[2], start[3]); - } - else { - throw Error("Slicing for rank " + _this.rank + " is not yet supported"); - } - }; - }; - return SliceProgram; -}()); -exports.SliceProgram = SliceProgram; -function getCoords(rank) { - if (rank === 1) { - return 'sourceLoc'; - } - else if (rank === 2) { - return 'sourceLoc.x, sourceLoc.y'; - } - else if (rank === 3) { - return 'sourceLoc.x, sourceLoc.y, sourceLoc.z'; - } - else if (rank === 4) { - return 'sourceLoc.x, sourceLoc.y, sourceLoc.z, sourceLoc.w'; - } - else { - throw Error("Slicing for rank " + rank + " is not yet supported"); - } -} - -},{"./shader_compiler":97}],99:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var TextureType; -(function (TextureType) { - TextureType[TextureType["FLOAT"] = 0] = "FLOAT"; - TextureType[TextureType["UNSIGNED_BYTE"] = 1] = "UNSIGNED_BYTE"; -})(TextureType = exports.TextureType || (exports.TextureType = {})); -function getUnpackedMatrixTextureShapeWidthHeight(rows, columns) { - return [columns, rows]; -} -exports.getUnpackedMatrixTextureShapeWidthHeight = getUnpackedMatrixTextureShapeWidthHeight; -function getUnpackedArraySizeFromMatrixSize(matrixSize, channelsPerTexture) { - return matrixSize * channelsPerTexture; -} -exports.getUnpackedArraySizeFromMatrixSize = getUnpackedArraySizeFromMatrixSize; -function getColorMatrixTextureShapeWidthHeight(rows, columns) { - return [columns * 4, rows]; -} -exports.getColorMatrixTextureShapeWidthHeight = getColorMatrixTextureShapeWidthHeight; -function getMatrixSizeFromUnpackedArraySize(unpackedSize, channelsPerTexture) { - if (unpackedSize % channelsPerTexture !== 0) { - throw new Error("unpackedSize (" + unpackedSize + ") must be a multiple of " + - ("" + channelsPerTexture)); - } - return unpackedSize / channelsPerTexture; -} -exports.getMatrixSizeFromUnpackedArraySize = getMatrixSizeFromUnpackedArraySize; -function encodeMatrixToUnpackedArray(matrix, unpackedArray, channelsPerTexture) { - var requiredSize = getUnpackedArraySizeFromMatrixSize(matrix.length, channelsPerTexture); - if (unpackedArray.length < requiredSize) { - throw new Error("unpackedArray length (" + unpackedArray.length + ") must be >= " + - ("" + requiredSize)); - } - var dst = 0; - for (var src = 0; src < matrix.length; ++src) { - unpackedArray[dst] = matrix[src]; - dst += channelsPerTexture; - } -} -exports.encodeMatrixToUnpackedArray = encodeMatrixToUnpackedArray; -exports.FLOAT_MAX = 20000; -exports.FLOAT_MIN = -exports.FLOAT_MAX; -var FLOAT_RANGE = (exports.FLOAT_MAX - exports.FLOAT_MIN) / 255; -var FLOAT_DELTAS = [1, 1 / 255, 1 / (255 * 255), 1 / (255 * 255 * 255)]; -var FLOAT_POWERS = [1, 255, 255 * 255]; -exports.BYTE_NAN_VALUE = 0; -function encodeFloatArray(floatArray) { - var uintArray = new Uint8Array(floatArray.length * 4); - var _loop_1 = function (i) { - var value = floatArray[i / 4]; - if (isNaN(value)) { - uintArray[i] = exports.BYTE_NAN_VALUE; - uintArray[i + 1] = exports.BYTE_NAN_VALUE; - uintArray[i + 2] = exports.BYTE_NAN_VALUE; - uintArray[i + 3] = exports.BYTE_NAN_VALUE; - return "continue"; - } - var normalizedValue = (value - exports.FLOAT_MIN) / FLOAT_RANGE; - var enc = FLOAT_POWERS.map(function (pow) { return pow * normalizedValue; }); - var buckets = enc.map(function (value) { return Math.floor((value % 1) * 255); }); - uintArray[i] = Math.floor(normalizedValue); - uintArray[i + 1] = buckets[0]; - uintArray[i + 2] = buckets[1]; - uintArray[i + 3] = buckets[2]; - }; - for (var i = 0; i < uintArray.length; i += 4) { - _loop_1(i); - } - return uintArray; -} -exports.encodeFloatArray = encodeFloatArray; -function decodeToFloatArray(uintArray) { - var floatArray = new Float32Array(uintArray.length / 4); - var _loop_2 = function (i) { - if (uintArray[i] === exports.BYTE_NAN_VALUE && - uintArray[i + 1] === exports.BYTE_NAN_VALUE && - uintArray[i + 2] === exports.BYTE_NAN_VALUE && - uintArray[i + 3] === exports.BYTE_NAN_VALUE) { - floatArray[i / 4] = NaN; - return "continue"; - } - var dot = 0; - FLOAT_DELTAS.forEach(function (delta, j) { - dot += delta * uintArray[i + j]; - }); - var value = dot * FLOAT_RANGE + exports.FLOAT_MIN; - floatArray[i / 4] = value; - }; - for (var i = 0; i < uintArray.length; i += 4) { - _loop_2(i); - } - return floatArray; -} -exports.decodeToFloatArray = decodeToFloatArray; -function decodeMatrixFromUnpackedArray(unpackedArray, matrix, channelsPerTexture) { - var requiredSize = getMatrixSizeFromUnpackedArraySize(unpackedArray.length, channelsPerTexture); - if (matrix.length < requiredSize) { - throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize); - } - var dst = 0; - for (var src = 0; src < unpackedArray.length; src += channelsPerTexture) { - matrix[dst++] = unpackedArray[src]; - } -} -exports.decodeMatrixFromUnpackedArray = decodeMatrixFromUnpackedArray; -function decodeMatrixFromUnpackedColorRGBAArray(unpackedArray, matrix, channels) { - var requiredSize = unpackedArray.length * channels / 4; - if (matrix.length < requiredSize) { - throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize); - } - var dst = 0; - for (var src = 0; src < unpackedArray.length; src += 4) { - for (var c = 0; c < channels; c++) { - matrix[dst++] = unpackedArray[src + c]; - } - } -} -exports.decodeMatrixFromUnpackedColorRGBAArray = decodeMatrixFromUnpackedColorRGBAArray; -function getPackedMatrixTextureShapeWidthHeight(rows, columns) { - return [Math.ceil(columns / 2), Math.ceil(rows / 2)]; -} -exports.getPackedMatrixTextureShapeWidthHeight = getPackedMatrixTextureShapeWidthHeight; -function getPackedRGBAArraySizeFromMatrixShape(rows, columns) { - var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - return w * h * 4; -} -exports.getPackedRGBAArraySizeFromMatrixShape = getPackedRGBAArraySizeFromMatrixShape; -function encodeMatrixToPackedRGBA(matrix, rows, columns, packedRGBA) { - var requiredSize = getPackedRGBAArraySizeFromMatrixShape(rows, columns); - if (packedRGBA.length < requiredSize) { - throw new Error("packedRGBA length (" + packedRGBA.length + ") must be >= " + requiredSize); - } - var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), textureWidth = _a[0], textureHeight = _a[1]; - var oddWidth = (columns % 2) === 1; - var oddHeight = (rows % 2) === 1; - var widthInFullBlocks = Math.floor(columns / 2); - var heightInFullBlocks = Math.floor(rows / 2); - { - var dstStride = (oddWidth ? 4 : 0); - var oneRow = columns; - var dst = 0; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - var matrixSrcRow = (blockY * 2 * columns); - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - var matrixSrcCol = blockX * 2; - var src = matrixSrcRow + matrixSrcCol; - packedRGBA[dst] = matrix[src]; - packedRGBA[dst + 1] = matrix[src + 1]; - packedRGBA[dst + 2] = matrix[src + oneRow]; - packedRGBA[dst + 3] = matrix[src + oneRow + 1]; - dst += 4; - } - dst += dstStride; - } - } - if (oddWidth) { - var src = columns - 1; - var dst = (textureWidth - 1) * 4; - var srcStride = 2 * columns; - var dstStride = textureWidth * 4; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - packedRGBA[dst] = matrix[src]; - packedRGBA[dst + 2] = matrix[src + columns]; - src += srcStride; - dst += dstStride; - } - } - if (oddHeight) { - var src = (rows - 1) * columns; - var dst = (textureHeight - 1) * textureWidth * 4; - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - packedRGBA[dst++] = matrix[src++]; - packedRGBA[dst++] = matrix[src++]; - dst += 2; - } - } - if (oddWidth && oddHeight) { - packedRGBA[packedRGBA.length - 4] = matrix[matrix.length - 1]; - } - return packedRGBA; -} -exports.encodeMatrixToPackedRGBA = encodeMatrixToPackedRGBA; -function decodeMatrixFromPackedRGBA(packedRGBA, rows, columns, matrix) { - var requiredSize = rows * columns; - if (requiredSize < matrix.length) { - throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize); - } - var oddWidth = (columns % 2) === 1; - var oddHeight = (rows % 2) === 1; - var widthInFullBlocks = Math.floor(columns / 2); - var heightInFullBlocks = Math.floor(rows / 2); - var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), textureWidth = _a[0], textureHeight = _a[1]; - { - var srcStride = oddWidth ? 4 : 0; - var dstStride = columns + (oddWidth ? 1 : 0); - var src = 0; - var dstRow1 = 0; - var dstRow2 = columns; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - matrix[dstRow1++] = packedRGBA[src++]; - matrix[dstRow1++] = packedRGBA[src++]; - matrix[dstRow2++] = packedRGBA[src++]; - matrix[dstRow2++] = packedRGBA[src++]; - } - src += srcStride; - dstRow1 += dstStride; - dstRow2 += dstStride; - } - } - if (oddWidth) { - var src = (textureWidth - 1) * 4; - var dst = columns - 1; - var srcStride = textureWidth * 4; - var dstStride = 2 * columns; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - matrix[dst] = packedRGBA[src]; - matrix[dst + columns] = packedRGBA[src + 2]; - src += srcStride; - dst += dstStride; - } - } - if (oddHeight) { - var src = (textureHeight - 1) * textureWidth * 4; - var dst = (rows - 1) * columns; - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - matrix[dst++] = packedRGBA[src++]; - matrix[dst++] = packedRGBA[src++]; - src += 2; - } - } - if (oddWidth && oddHeight) { - matrix[matrix.length - 1] = packedRGBA[packedRGBA.length - 4]; - } - return matrix; -} -exports.decodeMatrixFromPackedRGBA = decodeMatrixFromPackedRGBA; - -},{}],100:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tex_util_1 = require("./tex_util"); -var TextureManager = (function () { - function TextureManager(gpgpu) { - this.gpgpu = gpgpu; - this.numUsedTextures = 0; - this.numFreeTextures = 0; - this.freeTextures = {}; - this.logEnabled = false; - this.allocatedTextures = []; - this.usedTextureCount = {}; - } - TextureManager.prototype.acquireTexture = function (shapeRC, texType) { - if (texType === void 0) { texType = tex_util_1.TextureType.FLOAT; } - var shapeKey = getKeyFromTextureShape(shapeRC, texType); - if (!(shapeKey in this.freeTextures)) { - this.freeTextures[shapeKey] = []; - } - if (!(shapeKey in this.usedTextureCount)) { - this.usedTextureCount[shapeKey] = 0; - } - this.usedTextureCount[shapeKey]++; - if (this.freeTextures[shapeKey].length > 0) { - this.numFreeTextures--; - this.numUsedTextures++; - this.log(); - return this.freeTextures[shapeKey].shift(); - } - this.numUsedTextures++; - this.log(); - var newTexture = this.gpgpu.createMatrixTexture(shapeRC[0], shapeRC[1]); - this.allocatedTextures.push(newTexture); - return newTexture; - }; - TextureManager.prototype.releaseTexture = function (texture, shape, texType) { - if (texType === void 0) { texType = tex_util_1.TextureType.FLOAT; } - var shapeKey = getKeyFromTextureShape(shape, texType); - if (!(shapeKey in this.freeTextures)) { - this.freeTextures[shapeKey] = []; - } - this.freeTextures[shapeKey].push(texture); - this.numFreeTextures++; - this.numUsedTextures--; - this.usedTextureCount[shapeKey]--; - this.log(); - }; - TextureManager.prototype.log = function () { - if (!this.logEnabled) { - return; - } - var total = this.numFreeTextures + this.numUsedTextures; - console.log('Free/Used', this.numFreeTextures + " / " + this.numUsedTextures, "(" + total + ")"); - }; - TextureManager.prototype.getNumUsedTextures = function () { - return this.numUsedTextures; - }; - TextureManager.prototype.getNumFreeTextures = function () { - return this.numFreeTextures; - }; - TextureManager.prototype.dispose = function () { - var _this = this; - if (this.allocatedTextures == null) { - return; - } - this.allocatedTextures.forEach(function (texture) { - _this.gpgpu.deleteMatrixTexture(texture); - }); - this.freeTextures = null; - this.allocatedTextures = null; - this.usedTextureCount = null; - this.numUsedTextures = 0; - this.numFreeTextures = 0; - }; - return TextureManager; -}()); -exports.TextureManager = TextureManager; -function getKeyFromTextureShape(shapeRowsCol, texType) { - return shapeRowsCol[0] + "_" + shapeRowsCol[1] + "_" + texType; -} - -},{"./tex_util":99}],101:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var TileProgram = (function () { - function TileProgram(aShape, reps) { - this.variableNames = ['A']; - var outputShape = new Array(aShape.length); - for (var i = 0; i < outputShape.length; i++) { - outputShape[i] = aShape[i] * reps[i]; - } - this.outputShape = outputShape; - this.rank = outputShape.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var sourceCoords = getSourceCoords(aShape); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + sourceCoords + "));\n }\n "; - } - return TileProgram; -}()); -exports.TileProgram = TileProgram; -function getSourceCoords(aShape) { - var rank = aShape.length; - if (rank > 4) { - throw Error("Tile for rank " + rank + " is not yet supported"); - } - if (rank === 1) { - return "imod(resRC, " + aShape[0] + ")"; - } - var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var sourceCoords = []; - for (var i = 0; i < aShape.length; i++) { - sourceCoords.push("imod(" + currentCoords[i] + ", " + aShape[i] + ")"); - } - return sourceCoords.join(); -} - -},{"./shader_compiler":97}],102:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var TransposeProgram = (function () { - function TransposeProgram(aShape, newDim) { - this.variableNames = ['A']; - var outputShape = new Array(aShape.length); - for (var i = 0; i < outputShape.length; i++) { - outputShape[i] = aShape[newDim[i]]; - } - this.outputShape = outputShape; - this.rank = outputShape.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var switched = getSwitchedCoords(newDim); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + switched + "));\n }\n "; - } - return TransposeProgram; -}()); -exports.TransposeProgram = TransposeProgram; -function getSwitchedCoords(newDim) { - var rank = newDim.length; - if (rank > 4) { - throw Error("Transpose for rank " + rank + " is not yet supported"); - } - var originalOrder = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var switchedCoords = new Array(rank); - for (var i = 0; i < newDim.length; i++) { - switchedCoords[newDim[i]] = originalOrder[i]; - } - return switchedCoords.join(); -} - -},{"./shader_compiler":97}],103:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var selu_util = require("../../ops/selu_util"); -var UnaryOpProgram = (function () { - function UnaryOpProgram(aShape, opSnippet) { - this.variableNames = ['A']; - this.outputShape = aShape; - this.userCode = "\n float unaryOperation(float x) {\n " + opSnippet + "\n }\n\n void main() {\n float x = getAAtOutCoords();\n float y = unaryOperation(x);\n\n setOutput(y);\n }\n "; - } - return UnaryOpProgram; -}()); -exports.UnaryOpProgram = UnaryOpProgram; -var CHECK_NAN_SNIPPET = "\n if (isNaN(x)) return x;\n"; -exports.ABS = "\n return abs(x);\n"; -exports.RELU = CHECK_NAN_SNIPPET + "\n return (x < 0.0) ? 0.0 : x;\n"; -exports.ELU = "\n return (x >= 0.0) ? x : (exp(x) - 1.0);\n"; -exports.ELU_DER = "\n return (x >= 0.0) ? 1.0 : exp(x);\n"; -exports.SELU = "\n // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.\n // see: https://arxiv.org/abs/1706.02515\n float scaleAlpha = " + selu_util.SELU_SCALEALPHA + ";\n float scale = " + selu_util.SELU_SCALE + ";\n return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\n"; -function LEAKY_RELU(alpha) { - return "\n return (x >= 0.0) ? x : " + alpha + " * x;\n "; -} -exports.LEAKY_RELU = LEAKY_RELU; -function STEP(alpha) { - if (alpha === void 0) { alpha = 0.0; } - return CHECK_NAN_SNIPPET + ("\n return x > 0.0 ? 1.0 : float(" + alpha + ");\n "); -} -exports.STEP = STEP; -exports.NEG = "\n return -x;\n"; -exports.CEIL = "\n return ceil(x);\n"; -exports.FLOOR = "\n return floor(x);\n"; -exports.EXP = "\n return exp(x);\n"; -exports.LOG = "\n return log(x);\n"; -exports.SQRT = CHECK_NAN_SNIPPET + "\n return sqrt(x);\n"; -exports.SIGMOID = "\n return 1.0 / (1.0 + exp(-1.0 * x));\n"; -exports.SIN = CHECK_NAN_SNIPPET + "\n return sin(x);\n"; -exports.COS = CHECK_NAN_SNIPPET + "\n return cos(x);\n"; -exports.TAN = "\n return tan(x);\n"; -exports.ASIN = CHECK_NAN_SNIPPET + "\n return asin(x);\n"; -exports.ACOS = CHECK_NAN_SNIPPET + "\n return acos(x);\n"; -exports.ATAN = CHECK_NAN_SNIPPET + "\n return atan(x);\n"; -exports.SINH = "\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n"; -exports.COSH = "\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n"; -exports.TANH = "\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n"; -exports.SQUARE = "\n return x * x;\n"; -exports.LOGICAL_NOT = CHECK_NAN_SNIPPET + "\n return float(!(x >= 1.0));\n"; -exports.TO_INT = "\n return float(int(x));\n"; - -},{"../../ops/selu_util":129}],104:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MAX_TEXTURE_SIZE = null; -var util = require("../../util"); -var environment_1 = require("../../environment"); -function createWebGLRenderingContext(attributes) { - var canvas = document.createElement('canvas'); - canvas.width = 1; - canvas.height = 1; - return createWebGLRenderingContextFromCanvas(canvas, attributes); -} -exports.createWebGLRenderingContext = createWebGLRenderingContext; -function createWebGLRenderingContextFromCanvas(canvas, attributes) { - var gl; - var webglVersion = environment_1.ENV.get('WEBGL_VERSION'); - if (webglVersion === 2) { - gl = canvas.getContext('webgl2', attributes); - } - else if (webglVersion === 1) { - gl = (canvas.getContext('webgl', attributes) || - canvas.getContext('experimental-webgl', attributes)); - } - if (webglVersion === 0 || gl == null) { - throw new Error('This browser does not support WebGL.'); - } - return gl; -} -exports.createWebGLRenderingContextFromCanvas = createWebGLRenderingContextFromCanvas; -function callAndCheck(gl, func) { - var returnValue = func(); - checkWebGLError(gl); - return returnValue; -} -exports.callAndCheck = callAndCheck; -var webGLDebugErrorCheckingEnabled = false; -function enableDebugWebGLErrorChecking(enabled) { - webGLDebugErrorCheckingEnabled = enabled; -} -exports.enableDebugWebGLErrorChecking = enableDebugWebGLErrorChecking; -function checkWebGLError(gl) { - if (webGLDebugErrorCheckingEnabled) { - var error = gl.getError(); - if (error !== gl.NO_ERROR) { - throw new Error('WebGL Error: ' + getWebGLErrorMessage(gl, error)); - } - } -} -exports.checkWebGLError = checkWebGLError; -function getWebGLErrorMessage(gl, status) { - switch (status) { - case gl.NO_ERROR: - return 'NO_ERROR'; - case gl.INVALID_ENUM: - return 'INVALID_ENUM'; - case gl.INVALID_VALUE: - return 'INVALID_VALUE'; - case gl.INVALID_OPERATION: - return 'INVALID_OPERATION'; - case gl.INVALID_FRAMEBUFFER_OPERATION: - return 'INVALID_FRAMEBUFFER_OPERATION'; - case gl.OUT_OF_MEMORY: - return 'OUT_OF_MEMORY'; - case gl.CONTEXT_LOST_WEBGL: - return 'CONTEXT_LOST_WEBGL'; - default: - return "Unknown error code " + status; - } -} -exports.getWebGLErrorMessage = getWebGLErrorMessage; -function getExtensionOrThrow(gl, extensionName) { - return throwIfNull(gl, function () { return gl.getExtension(extensionName); }, 'Extension "' + extensionName + '" not supported on this browser.'); -} -exports.getExtensionOrThrow = getExtensionOrThrow; -function createVertexShader(gl, vertexShaderSource) { - var vertexShader = throwIfNull(gl, function () { return gl.createShader(gl.VERTEX_SHADER); }, 'Unable to create vertex WebGLShader.'); - callAndCheck(gl, function () { return gl.shaderSource(vertexShader, vertexShaderSource); }); - callAndCheck(gl, function () { return gl.compileShader(vertexShader); }); - if (gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS) === false) { - console.log(gl.getShaderInfoLog(vertexShader)); - throw new Error('Failed to compile vertex shader.'); - } - return vertexShader; -} -exports.createVertexShader = createVertexShader; -function createFragmentShader(gl, fragmentShaderSource) { - var fragmentShader = throwIfNull(gl, function () { return gl.createShader(gl.FRAGMENT_SHADER); }, 'Unable to create fragment WebGLShader.'); - callAndCheck(gl, function () { return gl.shaderSource(fragmentShader, fragmentShaderSource); }); - callAndCheck(gl, function () { return gl.compileShader(fragmentShader); }); - if (gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS) === false) { - logShaderSourceAndInfoLog(fragmentShaderSource, gl.getShaderInfoLog(fragmentShader)); - throw new Error('Failed to compile fragment shader.'); - } - return fragmentShader; -} -exports.createFragmentShader = createFragmentShader; -var lineNumberRegex = /ERROR: [0-9]+:([0-9]+):/g; -function logShaderSourceAndInfoLog(shaderSource, shaderInfoLog) { - var lineNumberRegexResult = lineNumberRegex.exec(shaderInfoLog); - if (lineNumberRegexResult == null) { - console.log("Couldn't parse line number in error: " + shaderInfoLog); - console.log(shaderSource); - return; - } - var lineNumber = +lineNumberRegexResult[1]; - var shaderLines = shaderSource.split('\n'); - var pad = shaderLines.length.toString().length + 2; - var linesWithLineNumbers = shaderLines.map(function (line, lineNumber) { - return util.rightPad((lineNumber + 1).toString(), pad) + line; - }); - var maxLineLength = 0; - for (var i = 0; i < linesWithLineNumbers.length; i++) { - maxLineLength = Math.max(linesWithLineNumbers[i].length, maxLineLength); - } - var beforeErrorLines = linesWithLineNumbers.slice(0, lineNumber - 1); - var errorLine = linesWithLineNumbers.slice(lineNumber - 1, lineNumber); - var afterErrorLines = linesWithLineNumbers.slice(lineNumber); - console.log(beforeErrorLines.join('\n')); - console.log(shaderInfoLog.split('\n')[0]); - console.log("%c " + util.rightPad(errorLine[0], maxLineLength), 'border:1px solid red; background-color:#e3d2d2; color:#a61717'); - console.log(afterErrorLines.join('\n')); -} -function createProgram(gl) { - return throwIfNull(gl, function () { return gl.createProgram(); }, 'Unable to create WebGLProgram.'); -} -exports.createProgram = createProgram; -function linkProgram(gl, program) { - callAndCheck(gl, function () { return gl.linkProgram(program); }); - if (gl.getProgramParameter(program, gl.LINK_STATUS) === false) { - console.log(gl.getProgramInfoLog(program)); - throw new Error('Failed to link vertex and fragment shaders.'); - } -} -exports.linkProgram = linkProgram; -function validateProgram(gl, program) { - callAndCheck(gl, function () { return gl.validateProgram(program); }); - if (gl.getProgramParameter(program, gl.VALIDATE_STATUS) === false) { - console.log(gl.getProgramInfoLog(program)); - throw new Error('Shader program validation failed.'); - } -} -exports.validateProgram = validateProgram; -function createStaticVertexBuffer(gl, data) { - var buffer = throwIfNull(gl, function () { return gl.createBuffer(); }, 'Unable to create WebGLBuffer'); - callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, buffer); }); - callAndCheck(gl, function () { return gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW); }); - return buffer; -} -exports.createStaticVertexBuffer = createStaticVertexBuffer; -function createStaticIndexBuffer(gl, data) { - var buffer = throwIfNull(gl, function () { return gl.createBuffer(); }, 'Unable to create WebGLBuffer'); - callAndCheck(gl, function () { return gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer); }); - callAndCheck(gl, function () { return gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data, gl.STATIC_DRAW); }); - return buffer; -} -exports.createStaticIndexBuffer = createStaticIndexBuffer; -function queryMaxTextureSize(gl) { - if (MAX_TEXTURE_SIZE != null) { - return MAX_TEXTURE_SIZE; - } - MAX_TEXTURE_SIZE = - callAndCheck(gl, function () { return gl.getParameter(gl.MAX_TEXTURE_SIZE); }); - return MAX_TEXTURE_SIZE; -} -exports.queryMaxTextureSize = queryMaxTextureSize; -function getChannelsPerTexture() { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return 4; - } - if (environment_1.ENV.get('WEBGL_VERSION') === 2) { - return 1; - } - return 4; -} -exports.getChannelsPerTexture = getChannelsPerTexture; -function createTexture(gl) { - return throwIfNull(gl, function () { return gl.createTexture(); }, 'Unable to create WebGLTexture.'); -} -exports.createTexture = createTexture; -function validateTextureSize(gl, width, height) { - var maxTextureSize = queryMaxTextureSize(gl); - if ((width <= 0) || (height <= 0)) { - var requested = "[" + width + "x" + height + "]"; - throw new Error('Requested texture size ' + requested + ' is invalid.'); - } - if ((width > maxTextureSize) || (height > maxTextureSize)) { - var requested = "[" + width + "x" + height + "]"; - var max = "[" + maxTextureSize + "x" + maxTextureSize + "]"; - throw new Error('Requested texture size ' + requested + - ' greater than WebGL maximum on this browser / GPU ' + max + '.'); - } -} -exports.validateTextureSize = validateTextureSize; -function createFramebuffer(gl) { - return throwIfNull(gl, function () { return gl.createFramebuffer(); }, 'Unable to create WebGLFramebuffer.'); -} -exports.createFramebuffer = createFramebuffer; -function bindVertexBufferToProgramAttribute(gl, program, attribute, buffer, arrayEntriesPerItem, itemStrideInBytes, itemOffsetInBytes, attribLocations) { - var loc = -1; - if ((attribLocations != null) && (attribute in attribLocations)) { - loc = attribLocations[attribute]; - } - else { - loc = gl.getAttribLocation(program, attribute); - } - if (loc === -1) { - return; - } - callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, buffer); }); - callAndCheck(gl, function () { return gl.vertexAttribPointer(loc, arrayEntriesPerItem, gl.FLOAT, false, itemStrideInBytes, itemOffsetInBytes); }); - callAndCheck(gl, function () { return gl.enableVertexAttribArray(loc); }); -} -exports.bindVertexBufferToProgramAttribute = bindVertexBufferToProgramAttribute; -function bindTextureUnit(gl, texture, textureUnit) { - validateTextureUnit(gl, textureUnit); - callAndCheck(gl, function () { return gl.activeTexture(gl.TEXTURE0 + textureUnit); }); - callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); }); -} -exports.bindTextureUnit = bindTextureUnit; -function unbindTextureUnit(gl, textureUnit) { - validateTextureUnit(gl, textureUnit); - callAndCheck(gl, function () { return gl.activeTexture(gl.TEXTURE0 + textureUnit); }); - callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); -} -exports.unbindTextureUnit = unbindTextureUnit; -function getProgramUniformLocationOrThrow(gl, program, uniformName) { - return throwIfNull(gl, function () { return gl.getUniformLocation(program, uniformName); }, 'uniform "' + uniformName + '" not present in program.'); -} -exports.getProgramUniformLocationOrThrow = getProgramUniformLocationOrThrow; -function getProgramUniformLocation(gl, program, uniformName) { - return gl.getUniformLocation(program, uniformName); -} -exports.getProgramUniformLocation = getProgramUniformLocation; -function bindTextureToProgramUniformSampler(gl, program, texture, uniformSamplerLocation, textureUnit) { - callAndCheck(gl, function () { return bindTextureUnit(gl, texture, textureUnit); }); - callAndCheck(gl, function () { return gl.uniform1i(uniformSamplerLocation, textureUnit); }); -} -exports.bindTextureToProgramUniformSampler = bindTextureToProgramUniformSampler; -function bindCanvasToFramebuffer(gl) { - callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, null); }); - callAndCheck(gl, function () { return gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); }); - callAndCheck(gl, function () { return gl.scissor(0, 0, gl.canvas.width, gl.canvas.height); }); -} -exports.bindCanvasToFramebuffer = bindCanvasToFramebuffer; -function bindColorTextureToFramebuffer(gl, texture, framebuffer) { - callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); }); - callAndCheck(gl, function () { return gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); }); -} -exports.bindColorTextureToFramebuffer = bindColorTextureToFramebuffer; -function unbindColorTextureFromFramebuffer(gl, framebuffer) { - callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); }); - callAndCheck(gl, function () { return gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0); }); -} -exports.unbindColorTextureFromFramebuffer = unbindColorTextureFromFramebuffer; -function validateFramebuffer(gl) { - var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER); - if (status !== gl.FRAMEBUFFER_COMPLETE) { - throw new Error('Error binding framebuffer: ' + getFramebufferErrorMessage(gl, status)); - } -} -exports.validateFramebuffer = validateFramebuffer; -function getFramebufferErrorMessage(gl, status) { - switch (status) { - case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: - return 'FRAMEBUFFER_INCOMPLETE_ATTACHMENT'; - case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: - return 'FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT'; - case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: - return 'FRAMEBUFFER_INCOMPLETE_DIMENSIONS'; - case gl.FRAMEBUFFER_UNSUPPORTED: - return 'FRAMEBUFFER_UNSUPPORTED'; - default: - return "unknown error " + status; - } -} -exports.getFramebufferErrorMessage = getFramebufferErrorMessage; -function throwIfNull(gl, returnTOrNull, failureMessage) { - var tOrNull = callAndCheck(gl, function () { return returnTOrNull(); }); - if (tOrNull == null) { - throw new Error(failureMessage); - } - return tOrNull; -} -function validateTextureUnit(gl, textureUnit) { - var maxTextureUnit = gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1; - var glTextureUnit = textureUnit + gl.TEXTURE0; - if (glTextureUnit < gl.TEXTURE0 || glTextureUnit > maxTextureUnit) { - var textureUnitRange = "[gl.TEXTURE0, gl.TEXTURE" + maxTextureUnit + "]"; - throw new Error("textureUnit must be in " + textureUnitRange + "."); - } -} -function getTextureShapeFromLogicalShape(gl, logShape) { - if (logShape.length !== 2) { - var squeezeResult = util.squeezeShape(logShape); - logShape = squeezeResult.newShape; - } - var maxTexSize = queryMaxTextureSize(gl); - var size = util.sizeFromShape(logShape); - if (logShape.length <= 1 && size <= maxTexSize) { - return [size, 1]; - } - else if (logShape.length === 2 && logShape[0] <= maxTexSize && - logShape[1] <= maxTexSize) { - return logShape; - } - else if (logShape.length === 3 && logShape[0] <= maxTexSize && - logShape[1] * logShape[2] <= maxTexSize) { - return [logShape[0], logShape[1] * logShape[2]]; - } - else if (logShape.length === 4 && logShape[0] <= maxTexSize && - logShape[1] * logShape[2] * logShape[3] <= maxTexSize) { - return [logShape[0], logShape[1] * logShape[2] * logShape[3]]; - } - else { - return util.sizeToSquarishShape(size); - } -} -exports.getTextureShapeFromLogicalShape = getTextureShapeFromLogicalShape; - -},{"../../environment":34,"../../util":151}],105:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("./environment"); -var array_ops = require("./ops/array_ops"); -var batchnorm = require("./ops/batchnorm"); -var binary_ops = require("./ops/binary_ops"); -var compare = require("./ops/compare"); -var conv = require("./ops/conv"); -var image_ops = require("./ops/image_ops"); -var logical = require("./ops/logical_ops"); -var lrn_ops = require("./ops/lrn"); -var lstm_ops = require("./ops/lstm"); -var matmul = require("./ops/matmul"); -var norm = require("./ops/norm"); -var ops = require("./ops/ops"); -var pool = require("./ops/pool"); -var reduction_ops = require("./ops/reduction_ops"); -var reverse = require("./ops/reverse"); -var slice = require("./ops/slice"); -var softmax_ops = require("./ops/softmax"); -var transpose = require("./ops/transpose"); -var unary_ops = require("./ops/unary_ops"); -var tracking_1 = require("./tracking"); -var util = require("./util"); -var tidy = tracking_1.Tracking.tidy; -var keep = tracking_1.Tracking.keep; -var NDArrayMath = (function () { - function NDArrayMath(backend, safeMode) { - this.matMul = matmul.Ops.matMul; - this.vectorTimesMatrix = matmul.Ops.vectorTimesMatrix; - this.outerProduct = matmul.Ops.outerProduct; - this.matrixTimesVector = matmul.Ops.matrixTimesVector; - this.dotProduct = matmul.Ops.dotProduct; - this.slice = slice.Ops.slice; - this.slice1D = slice.Ops.slice1d; - this.slice2D = slice.Ops.slice2d; - this.slice3D = slice.Ops.slice3d; - this.slice4D = slice.Ops.slice4d; - this.reverse = reverse.Ops.reverse; - this.reverse1D = reverse.Ops.reverse1d; - this.reverse2D = reverse.Ops.reverse2d; - this.reverse3D = reverse.Ops.reverse3d; - this.reverse4D = reverse.Ops.reverse4d; - this.batchNormalization = batchnorm.Ops.batchNormalization; - this.batchNormalization2D = batchnorm.Ops.batchNormalization2d; - this.batchNormalization3D = batchnorm.Ops.batchNormalization3d; - this.batchNormalization4D = batchnorm.Ops.batchNormalization4d; - this.avgPool = pool.Ops.avgPool; - this.maxPool = pool.Ops.maxPool; - this.minPool = pool.Ops.minPool; - this.maxPoolBackprop = pool.Ops.maxPoolBackprop; - this.conv2dTranspose = conv.Ops.conv2dTranspose; - this.depthwiseConv2D = conv.Ops.depthwiseConv2d; - this.conv2dDerFilter = conv.Ops.conv2dDerFilter; - this.conv2dDerInput = conv.Ops.conv2dDerInput; - this.argMax = reduction_ops.Ops.argMax; - this.argMin = reduction_ops.Ops.argMin; - this.logSumExp = reduction_ops.Ops.logSumExp; - this.max = reduction_ops.Ops.max; - this.mean = reduction_ops.Ops.mean; - this.min = reduction_ops.Ops.min; - this.moments = reduction_ops.Ops.moments; - this.sum = reduction_ops.Ops.sum; - this.add = binary_ops.Ops.add; - this.addStrict = binary_ops.Ops.addStrict; - this.div = binary_ops.Ops.div; - this.divide = this.div; - this.divStrict = binary_ops.Ops.divStrict; - this.divideStrict = this.divStrict; - this.maximum = binary_ops.Ops.maximum; - this.maximumStrict = binary_ops.Ops.maximumStrict; - this.minimum = binary_ops.Ops.minimum; - this.minimumStrict = binary_ops.Ops.minimumStrict; - this.mul = binary_ops.Ops.mul; - this.multiply = this.mul; - this.mulStrict = binary_ops.Ops.mulStrict; - this.multiplyStrict = this.mulStrict; - this.pow = binary_ops.Ops.pow; - this.powStrict = binary_ops.Ops.powStrict; - this.sub = binary_ops.Ops.sub; - this.subtract = this.sub; - this.subStrict = binary_ops.Ops.subStrict; - this.logicalNot = logical.Ops.logicalNot; - this.logicalAnd = logical.Ops.logicalAnd; - this.logicalOr = logical.Ops.logicalOr; - this.logicalXor = logical.Ops.logicalXor; - this.where = logical.Ops.where; - this.transpose = transpose.Ops.transpose; - this.equal = compare.Ops.equal; - this.equalStrict = compare.Ops.equalStrict; - this.greater = compare.Ops.greater; - this.greaterStrict = compare.Ops.greaterStrict; - this.greaterEqual = compare.Ops.greaterEqual; - this.greaterEqualStrict = compare.Ops.greaterEqualStrict; - this.less = compare.Ops.less; - this.lessStrict = compare.Ops.lessStrict; - this.lessEqual = compare.Ops.lessEqual; - this.lessEqualStrict = compare.Ops.lessEqualStrict; - this.notEqual = compare.Ops.notEqual; - this.notEqualStrict = compare.Ops.notEqualStrict; - this.abs = unary_ops.Ops.abs; - this.acos = unary_ops.Ops.acos; - this.asin = unary_ops.Ops.asin; - this.atan = unary_ops.Ops.atan; - this.ceil = unary_ops.Ops.ceil; - this.clip = unary_ops.Ops.clipByValue; - this.cos = unary_ops.Ops.cos; - this.cosh = unary_ops.Ops.cosh; - this.elu = unary_ops.Ops.elu; - this.exp = unary_ops.Ops.exp; - this.floor = unary_ops.Ops.floor; - this.leakyRelu = unary_ops.Ops.leakyRelu; - this.log = unary_ops.Ops.log; - this.neg = unary_ops.Ops.neg; - this.prelu = unary_ops.Ops.prelu; - this.relu = unary_ops.Ops.relu; - this.selu = unary_ops.Ops.selu; - this.sigmoid = unary_ops.Ops.sigmoid; - this.sin = unary_ops.Ops.sin; - this.sinh = unary_ops.Ops.sinh; - this.sqrt = unary_ops.Ops.sqrt; - this.square = unary_ops.Ops.square; - this.step = unary_ops.Ops.step; - this.tan = unary_ops.Ops.tan; - this.tanh = unary_ops.Ops.tanh; - this.norm = norm.Ops.norm; - this.basicLSTMCell = lstm_ops.Ops.basicLSTMCell; - this.multiRNNCell = lstm_ops.Ops.multiRNNCell; - this.softmax = softmax_ops.Ops.softmax; - this.softmaxCrossEntropy = softmax_ops.Ops.softmaxCrossEntropy; - this.cast = array_ops.Ops.cast; - this.clone = array_ops.Ops.clone; - this.gather = array_ops.Ops.gather; - this.reshape = array_ops.Ops.reshape; - this.tile = array_ops.Ops.tile; - this.oneHot = array_ops.Ops.oneHot; - this.multinomial = array_ops.Ops.multinomial; - this.pad1D = array_ops.Ops.pad1d; - this.pad2D = array_ops.Ops.pad2d; - this.resizeBilinear3D = image_ops.Ops.resizeBilinear; - this.localResponseNormalization3D = lrn_ops.LRN.localResponseNormalization; - this.localResponseNormalization4D = lrn_ops.LRN.localResponseNormalization; - this.keep = tracking_1.Tracking.keep; - environment_1.ENV.setMath(this, backend, safeMode); - this.engine = environment_1.ENV.engine; - this.dispose = environment_1.ENV.engine.dispose.bind(environment_1.ENV.engine); - this.registeredVariables = environment_1.ENV.engine.registeredVariables; - this.startScope = environment_1.ENV.engine.startScope.bind(environment_1.ENV.engine); - this.endScope = environment_1.ENV.engine.endScope.bind(environment_1.ENV.engine); - } - NDArrayMath.prototype.scope = function (scopeFn) { - var keepFn = function (tensor) { return keep(tensor); }; - var trackFn = function (tensor) { return tensor; }; - return tidy(function () { return scopeFn(keepFn, trackFn); }); - }; - NDArrayMath.prototype.track = function (result) { - return result; - }; - NDArrayMath.prototype.topK = function (x, k) { - util.assert(k <= x.size, "Error in topK: k value (" + k + ") must be less than size of input " + - ("tensor, got shape " + x.shape + ".")); - var values; - var indices; - tidy('topK', function () { - values = environment_1.ENV.engine.executeKernel('TopKValues', { inputs: { x: x }, args: { k: k } }); - indices = - environment_1.ENV.engine.executeKernel('TopKIndices', { inputs: { x: x }, args: { k: k } }); - return values; - }); - var result = { values: values, indices: indices }; - return result; - }; - NDArrayMath.prototype.elementWiseMul = function (a, b) { - return a.mulStrict(b); - }; - NDArrayMath.prototype.scalarDividedByArray = function (c, a) { - util.assert(c.size === 1, "Error in scalarDividedByArray: first argument must be rank 0, but " + - ("got Tensor of rank " + c.rank + ".")); - return c.div(a); - }; - NDArrayMath.prototype.arrayDividedByScalar = function (a, c) { - util.assert(c.size === 1, "Error in arrayDividedByScalar: second argument must be rank 0, " + - ("but got Tensor of rank " + c.rank + ".")); - return a.div(c); - }; - NDArrayMath.prototype.switchDim = function (x, perm) { - return ops.transpose(x, perm); - }; - NDArrayMath.prototype.scalarPlusArray = function (c, a) { - util.assert(c.size === 1, "Error in scalarPlusArray: first argument must be rank 0, but got " + - ("rank " + c.rank + ".")); - return this.add(c, a); - }; - NDArrayMath.prototype.scalarMinusArray = function (c, a) { - util.assert(c.size === 1, "Error in scalarMinusArray: first argument must be rank 0, but got " + - ("rank " + c.rank + ".")); - return this.subtract(c, a); - }; - NDArrayMath.prototype.arrayMinusScalar = function (a, c) { - util.assert(c.size === 1, "Error in arrayMinusScalar: second argument must be rank 0, but " + - ("got rank " + c.rank + ".")); - return this.subtract(a, c); - }; - NDArrayMath.prototype.scaledArrayAdd = function (c1, a, c2, b) { - var _this = this; - util.assert(c1.size === 1, "Error in scaledArrayAdd: first argument must rank 0, but got " + - (" rank " + c1.rank + ".")); - util.assert(c2.size === 1, "Error in scaledArrayAdd: third argument must be rank 0, but got " + - ("Tensor of rank " + c2.rank + ".")); - util.assertShapesMatch(a.shape, b.shape, 'Error in scaledArrayAdd: '); - return tidy('scaledArrayAdd', function () { - return _this.add(_this.multiply(c1, a), _this.multiply(c2, b)); - }); - }; - NDArrayMath.prototype.scalarTimesArray = function (c, a) { - util.assert(c.size === 1, "Error in arrayDividedByScalar: first argument must be rank 0, but " + - ("got rank " + c.rank + ".")); - return this.multiply(c, a); - }; - NDArrayMath.prototype.concat = function (a, b, axis) { - return ops.concat([a, b], axis); - }; - NDArrayMath.prototype.concat1D = function (a, b) { - return ops.concat1d([a, b]); - }; - NDArrayMath.prototype.concat2D = function (a, b, axis) { - return ops.concat2d([a, b], axis); - }; - NDArrayMath.prototype.concat3D = function (a, b, axis) { - return ops.concat3d([a, b], axis); - }; - NDArrayMath.prototype.concat4D = function (a, b, axis) { - return ops.concat4d([a, b], axis); - }; - NDArrayMath.prototype.conv1d = function (input, filter, bias, stride, pad, dimRoundingMode) { - if (bias != null) { - util.assert(bias.rank === 1, "Error in conv1d: bias must be rank 1, but got rank " + - (bias.rank + ".")); - } - var res = ops.conv1d(input, filter, stride, pad, dimRoundingMode); - return res.add(bias); - }; - NDArrayMath.prototype.conv2d = function (x, filter, bias, strides, pad, dimRoundingMode) { - if (bias != null) { - util.assert(bias.rank === 1, "Error in conv2d: bias must be rank 1, but got rank " + - (bias.rank + ".")); - } - var res = ops.conv2d(x, filter, strides, pad, dimRoundingMode); - return res.add(bias); - }; - NDArrayMath.prototype.argMaxEquals = function (x1, x2) { - util.assertShapesMatch(x1.shape, x2.shape, 'Error in argMaxEquals: '); - return x1.argMax().equal(x2.argMax()); - }; - return NDArrayMath; -}()); -exports.NDArrayMath = NDArrayMath; - -},{"./environment":34,"./ops/array_ops":106,"./ops/batchnorm":108,"./ops/binary_ops":109,"./ops/compare":111,"./ops/conv":114,"./ops/image_ops":116,"./ops/logical_ops":117,"./ops/lrn":118,"./ops/lstm":119,"./ops/matmul":120,"./ops/norm":121,"./ops/ops":123,"./ops/pool":124,"./ops/reduction_ops":127,"./ops/reverse":128,"./ops/slice":130,"./ops/softmax":132,"./ops/transpose":133,"./ops/unary_ops":134,"./tracking":148,"./util":151}],106:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var concat_1 = require("./concat"); -var operation_1 = require("./operation"); -var rand_1 = require("./rand"); -var Ops = (function () { - function Ops() { - } - Ops.tensor = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (shape != null && inferredShape.length !== 1) { - util.assertShapesMatch(shape, inferredShape, "Error creating a new Tensor. " + - ("Inferred shape (" + inferredShape + ") does not match the ") + - ("provided shape (" + shape + "). ")); - } - if (!util.isTypedArray(values) && !Array.isArray(values)) { - values = [values]; - } - shape = shape || inferredShape; - return tensor_1.Tensor.make(shape, { values: toTypedArray(values, dtype) }, dtype); - }; - Ops.scalar = function (value, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - if (util.isTypedArray(value) || Array.isArray(value)) { - throw new Error('Error creating a new Scalar: value must be a primitive ' + - '(number|boolean)'); - } - return Ops.tensor(value, [], dtype); - }; - Ops.tensor1d = function (values, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor1D: values must be a flat/TypedArray'); - } - return Ops.tensor(values, inferredShape, dtype); - }; - Ops.tensor2d = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 2 && inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor2D: values must be number[][] ' + - 'or flat/TypedArray'); - } - shape = shape || inferredShape; - return Ops.tensor(values, shape, dtype); - }; - Ops.tensor3d = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 3 && inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor3D: values must be number[][][]' + - 'or flat/TypedArray'); - } - shape = shape || inferredShape; - return Ops.tensor(values, shape, dtype); - }; - Ops.tensor4d = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 4 && inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor4D: values must be number[][][][]' + - 'or flat/TypedArray'); - } - shape = shape || inferredShape; - return Ops.tensor(values, shape, dtype); - }; - Ops.ones = function (shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var values = makeOnesTypedArray(util.sizeFromShape(shape), dtype); - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.zeros = function (shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var values = makeZerosTypedArray(util.sizeFromShape(shape), dtype); - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.fill = function (shape, value, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var values = util.getTypedArrayFromDType(dtype, util.sizeFromShape(shape)); - values.fill(value); - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.onesLike = function (x) { - return Ops.ones(x.shape, x.dtype); - }; - Ops.zerosLike = function (x) { - return Ops.zeros(x.shape, x.dtype); - }; - Ops.clone = function (x) { - return tensor_1.Tensor.make(x.shape, { dataId: x.dataId }, x.dtype); - }; - Ops.randomNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - if (dtype != null && dtype === 'bool') { - throw new Error("Unsupported data type " + dtype); - } - var randGauss = new rand_1.MPRandGauss(mean, stdDev, dtype, false, seed); - return tensor_1.Tensor.rand(shape, function () { return randGauss.nextValue(); }, dtype); - }; - Ops.truncatedNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - if (dtype != null && dtype === 'bool') { - throw new Error("Unsupported data type " + dtype); - } - var randGauss = new rand_1.MPRandGauss(mean, stdDev, dtype, true, seed); - return tensor_1.Tensor.rand(shape, function () { return randGauss.nextValue(); }, dtype); - }; - Ops.randomUniform = function (shape, minval, maxval, dtype) { - if (minval === void 0) { minval = 0; } - if (maxval === void 0) { maxval = 1; } - if (dtype === void 0) { dtype = 'float32'; } - return tensor_1.Tensor.rand(shape, function () { return util.randUniform(minval, maxval); }, dtype); - }; - Ops.rand = function (shape, randFunction, dtype) { - var size = util.sizeFromShape(shape); - var values = null; - if (dtype == null || dtype === 'float32') { - values = new Float32Array(size); - } - else if (dtype === 'int32') { - values = new Int32Array(size); - } - else if (dtype === 'bool') { - values = new Uint8Array(size); - } - else { - throw new Error("Unknown data type " + dtype); - } - for (var i = 0; i < size; i++) { - values[i] = randFunction(); - } - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.multinomial = function (probabilities, numSamples, seed) { - var numOutcomes = probabilities.size; - if (numOutcomes < 2) { - throw new Error("Error in multinomial: you need at least 2 outcomes, but got " + - (numOutcomes + ".")); - } - if (probabilities.rank > 2) { - throw new Error("Rank of probabilities must be 1 or 2, but is " + probabilities.rank); - } - seed = seed || Math.random(); - var origRank = probabilities.rank; - if (probabilities.rank === 1) { - probabilities = probabilities.as2D(1, -1); - } - var res = environment_1.ENV.engine.executeKernel('Multinomial', { - inputs: { probs: probabilities }, - args: { numSamples: numSamples, seed: seed } - }); - if (origRank === 1) { - return res.as1D(); - } - return res; - }; - Ops.oneHot = function (indices, depth, onValue, offValue) { - if (onValue === void 0) { onValue = 1; } - if (offValue === void 0) { offValue = 0; } - if (depth < 2) { - throw new Error("Error in oneHot: depth must be >=2, but it is " + depth); - } - return environment_1.ENV.engine.executeKernel('OneHot', { inputs: { indices: indices }, args: { depth: depth, onValue: onValue, offValue: offValue } }); - }; - Ops.fromPixels = function (pixels, numChannels) { - if (numChannels === void 0) { numChannels = 3; } - if (numChannels > 4) { - throw new Error('Cannot construct Tensor with more than 4 channels from pixels.'); - } - return environment_1.ENV.engine.fromPixels(pixels, numChannels); - }; - Ops.reshape = function (x, shape) { - shape = util.inferFromImplicitShape(shape, x.size); - util.assert(x.size === util.sizeFromShape(shape), 'new shape and old shape must have the same number of elements.'); - var grad = function (dy, y) { - return { x: function () { return dy.reshape(x.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Reshape', { inputs: { x: x }, args: { newShape: shape } }, grad); - }; - Ops.squeeze = function (x, axis) { - return Ops.reshape(x, util.squeezeShape(x.shape, axis).newShape); - }; - Ops.cast = function (x, dtype) { - var grad = function (dy, y) { - return { x: function () { return dy.reshape(dy.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Cast', { inputs: { x: x }, args: { newDType: dtype } }, grad); - }; - Ops.tile = function (x, reps) { - util.assert(x.rank === reps.length, "Error in transpose: rank of input " + x.rank + " " + - ("must match length of reps " + reps + ".")); - return environment_1.ENV.engine.executeKernel('Tile', { inputs: { x: x }, args: { reps: reps } }); - }; - Ops.gather = function (x, indices, axis) { - if (axis === void 0) { axis = 0; } - return environment_1.ENV.engine.executeKernel('Gather', { inputs: { x: x, indices: indices }, args: { axis: axis } }); - }; - Ops.pad1d = function (x, paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - util.assert(paddings.length === 2, 'Invalid number of paddings. Must be length of 2.'); - return environment_1.ENV.engine.executeKernel('Pad1D', { inputs: { x: x }, args: { paddings: paddings, constantValue: constantValue } }); - }; - Ops.pad2d = function (x, paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - util.assert(paddings.length === 2 && paddings[0].length === 2 && - paddings[1].length === 2, 'Invalid number of paddings. Must be length of 2 each.'); - return environment_1.ENV.engine.executeKernel('Pad2D', { inputs: { x: x }, args: { paddings: paddings, constantValue: constantValue } }); - }; - Ops.pad = function (x, paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - if (x.rank === 0) { - throw new Error('pad(scalar) is not defined. Pass non-scalar to pad'); - } - else if (x.rank === 1) { - return Ops.pad1d(x, paddings[0], constantValue); - } - else if (x.rank === 2) { - return Ops.pad2d(x, paddings, constantValue); - } - else { - throw new Error("pad of rank-" + x.rank + " tensor is not yet supported"); - } - }; - Ops.stack = function (tensors, axis) { - if (axis === void 0) { axis = 0; } - util.assert(tensors.length >= 2, 'Pass at least two tensors to dl.stack'); - var rank = tensors[0].rank; - var shape = tensors[0].shape; - var dtype = tensors[0].dtype; - util.assert(axis <= rank, 'Axis must be <= rank of the tensor'); - tensors.forEach(function (t) { - util.assertShapesMatch(shape, t.shape, 'All tensors passed to stack must have matching shapes'); - }); - tensors.forEach(function (t) { - util.assert(dtype === t.dtype, 'All tensors passed to stack must have matching dtypes'); - }); - var expandedTensors = tensors.map(function (t) { return t.expandDims(axis); }); - return concat_1.Concat.concat(expandedTensors, axis); - }; - Ops.expandDims = function (x, axis) { - if (axis === void 0) { axis = 0; } - util.assert(axis <= x.rank, 'Axis must be <= rank of the tensor'); - var newShape = x.shape.slice(); - newShape.splice(axis, 0, 1); - return Ops.reshape(x, newShape); - }; - Ops.linspace = function (start, stop, num) { - if (num === 0) { - throw new Error('Cannot request zero samples'); - } - var step = (stop - start) / (num - 1); - var values = makeZerosTypedArray(num, 'float32'); - values[0] = start; - for (var i = 1; i < values.length; i++) { - values[i] = values[i - 1] + step; - } - return tensor_1.Tensor1D.new(values, 'float32'); - }; - Ops.range = function (start, stop, step, dtype) { - if (step === void 0) { step = 1; } - if (dtype === void 0) { dtype = 'float32'; } - if (step === 0) { - throw new Error('Cannot have a step of zero'); - } - var sameStartStop = start === stop; - var increasingRangeNegativeStep = start < stop && step < 0; - var decreasingRangePositiveStep = stop < start && step > 1; - if (sameStartStop || increasingRangeNegativeStep || - decreasingRangePositiveStep) { - return Ops.zeros([0], dtype); - } - var numElements = Math.abs(Math.ceil((stop - start) / step)); - var values = makeZerosTypedArray(numElements, dtype); - if (stop < start && step === 1) { - step = -1; - } - values[0] = start; - for (var i = 1; i < values.length; i++) { - values[i] = values[i - 1] + step; - } - return Ops.tensor1d(values, dtype); - }; - Ops.buffer = function (shape, dtype, values) { - if (dtype === void 0) { dtype = 'float32'; } - return new tensor_1.TensorBuffer(shape, dtype, values); - }; - Ops.print = function (x, verbose) { - if (verbose === void 0) { verbose = false; } - var C = (function () { - function Tensor() { - } - return Tensor; - }()); - var displayTensor = new C(); - displayTensor.shape = x.shape; - displayTensor.values = Array.from(x.dataSync()); - displayTensor.toString = function () { - var fields = [ - "values: [" + this.values.join(', ') + "]", "shape: [" + x.shape.join(', ') + "]", - "rank: " + x.rank - ]; - if (verbose) { - fields.push("dtype: '" + this.dtype + "'"); - fields.push("size: " + this.size); - } - for (var i = 0; i < fields.length; i++) { - fields[i] = ' ' + fields[i]; - } - return 'TensorInfo {\n' + fields.join(',\n') + '\n}'; - }; - if (verbose) { - displayTensor.dtype = x.dtype; - displayTensor.size = x.size; - } - console.log(displayTensor); - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "scalar", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor1d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor2d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor3d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor4d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "ones", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "zeros", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "fill", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "onesLike", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "zerosLike", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "clone", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "randomNormal", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "truncatedNormal", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "randomUniform", null); - __decorate([ - operation_1.operation - ], Ops, "rand", null); - __decorate([ - operation_1.operation - ], Ops, "multinomial", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "oneHot", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "fromPixels", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "reshape", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }) - ], Ops, "squeeze", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "cast", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "tile", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "gather", null); - __decorate([ - operation_1.operation - ], Ops, "pad1d", null); - __decorate([ - operation_1.operation - ], Ops, "pad2d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "pad", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "stack", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "expandDims", null); - __decorate([ - operation_1.operation, - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "linspace", null); - __decorate([ - operation_1.operation, - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "range", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "buffer", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "print", null); - return Ops; -}()); -exports.Ops = Ops; -function makeZerosTypedArray(size, dtype) { - if (dtype == null || dtype === 'float32') { - return new Float32Array(size); - } - else if (dtype === 'int32') { - return new Int32Array(size); - } - else if (dtype === 'bool') { - return new Uint8Array(size); - } - else { - throw new Error("Unknown data type $ {dtype}"); - } -} -function makeOnesTypedArray(size, dtype) { - var array = makeZerosTypedArray(size, dtype); - for (var i = 0; i < array.length; i++) { - array[i] = 1; - } - return array; -} -function toTypedArray(a, dtype) { - if (noConversionNeeded(a, dtype)) { - return a; - } - if (Array.isArray(a)) { - a = util.flatten(a); - } - return util.copyTypedArray(a, dtype); -} -function noConversionNeeded(a, dtype) { - return (a instanceof Float32Array && dtype === 'float32') || - (a instanceof Int32Array && dtype === 'int32') || - (a instanceof Uint8Array && dtype === 'bool'); -} - -},{"../doc":32,"../environment":34,"../tensor":146,"../util":151,"./concat":112,"./operation":122,"./rand":125}],107:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function axesAreInnerMostDims(axes, rank) { - for (var i = 0; i < axes.length; ++i) { - if (axes[axes.length - i - 1] !== rank - 1 - i) { - return false; - } - } - return true; -} -exports.axesAreInnerMostDims = axesAreInnerMostDims; -function combineLocations(outputLoc, reduceLoc, axes) { - var rank = outputLoc.length + reduceLoc.length; - var loc = []; - var outIdx = 0; - var reduceIdx = 0; - for (var dim = 0; dim < rank; dim++) { - if (axes.indexOf(dim) === -1) { - loc.push(outputLoc[outIdx++]); - } - else { - loc.push(reduceLoc[reduceIdx++]); - } - } - return loc; -} -exports.combineLocations = combineLocations; -function computeOutAndReduceShapes(aShape, axes) { - var outShape = []; - var rank = aShape.length; - for (var dim = 0; dim < rank; dim++) { - if (axes.indexOf(dim) === -1) { - outShape.push(aShape[dim]); - } - } - var reduceShape = axes.map(function (dim) { return aShape[dim]; }); - return [outShape, reduceShape]; -} -exports.computeOutAndReduceShapes = computeOutAndReduceShapes; -function expandShapeToKeepDim(shape, axes) { - var reduceSubShape = axes.map(function (x) { return 1; }); - return combineLocations(shape, reduceSubShape, axes); -} -exports.expandShapeToKeepDim = expandShapeToKeepDim; -function parseAxisParam(axis, shape) { - var rank = shape.length; - axis = axis == null ? shape.map(function (s, i) { return i; }) : [].concat(axis); - util.assert(axis.every(function (ax) { return ax >= -rank && ax < rank; }), "All values in axis param must be in range [-" + rank + ", " + rank + ") but " + - ("got axis " + axis)); - util.assert(axis.every(function (ax) { return util.isInt(ax); }), "All values in axis param must be integers but " + - ("got axis " + axis)); - return axis.map(function (a) { return a < 0 ? rank + a : a; }); -} -exports.parseAxisParam = parseAxisParam; -function assertAxesAreInnerMostDims(msg, axes, rank) { - util.assert(axesAreInnerMostDims(axes, rank), msg + " supports only inner-most axes for now. " + - ("Got axes " + axes + " and rank-" + rank + " input.")); -} -exports.assertAxesAreInnerMostDims = assertAxesAreInnerMostDims; -function getAxesPermutation(axes, rank) { - if (axesAreInnerMostDims(axes, rank)) { - return null; - } - var result = []; - for (var i = 0; i < rank; ++i) { - if (axes.indexOf(i) === -1) { - result.push(i); - } - } - axes.forEach(function (axis) { return result.push(axis); }); - return result; -} -exports.getAxesPermutation = getAxesPermutation; -function getUndoAxesPermutation(axes) { - return axes.map(function (axis, i) { return [i, axis]; }) - .sort(function (a, b) { return a[1] - b[1]; }) - .map(function (x) { return x[0]; }); -} -exports.getUndoAxesPermutation = getUndoAxesPermutation; -function getInnerMostAxes(numAxes, rank) { - var res = []; - for (var i = rank - numAxes; i < rank; ++i) { - res.push(i); - } - return res; -} -exports.getInnerMostAxes = getInnerMostAxes; - -},{"../util":151}],108:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.batchNormalization2d = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - util.assert(x.rank === 2, "Error in batchNormalization3D: x must be rank 3 but got rank " + - (x.rank + ".")); - util.assert(mean.rank === 2 || mean.rank === 1, "Error in batchNormalization2D: mean must be rank 2 or rank 1 but " + - ("got rank " + mean.rank + ".")); - util.assert(variance.rank === 2 || variance.rank === 1, "Error in batchNormalization2D: variance must be rank 2 or rank 1 " + - ("but got rank " + variance.rank + ".")); - if (scale != null) { - util.assert(scale.rank === 2 || scale.rank === 1, "Error in batchNormalization2D: scale must be rank 2 or rank 1 " + - ("but got rank " + scale.rank + ".")); - } - if (offset != null) { - util.assert(offset.rank === 2 || offset.rank === 1, "Error in batchNormalization2D: offset must be rank 2 or rank 1 " + - ("but got rank " + offset.rank + ".")); - } - return Ops.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset); - }; - Ops.batchNormalization3d = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - util.assert(x.rank === 3, "Error in batchNormalization3D: x must be rank 3 but got rank " + - (x.rank + ".")); - util.assert(mean.rank === 3 || mean.rank === 1, "Error in batchNormalization3D: mean must be rank 3 or rank 1 but " + - ("got rank " + mean.rank + ".")); - util.assert(variance.rank === 3 || variance.rank === 1, "Error in batchNormalization3D: variance must be rank 3 or rank 1 " + - ("but got rank " + variance.rank + ".")); - if (scale != null) { - util.assert(scale.rank === 3 || scale.rank === 1, "Error in batchNormalization3D: scale must be rank 3 or rank 1 " + - ("but got rank " + scale.rank + ".")); - } - if (offset != null) { - util.assert(offset.rank === 3 || offset.rank === 1, "Error in batchNormalization3D: offset must be rank 3 or rank 1 " + - ("but got rank " + offset.rank + ".")); - } - return Ops.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset); - }; - Ops.batchNormalization4d = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - util.assert(x.rank === 4, "Error in batchNormalization4D: x must be rank 4 but got rank " + - (x.rank + ".")); - util.assert(mean.rank === 4 || mean.rank === 1, "Error in batchNormalization4D: mean must be rank 4 or rank 1 but " + - ("got rank " + mean.rank + ".")); - util.assert(variance.rank === 4 || variance.rank === 1, "Error in batchNormalization4D: variance must be rank 4 or rank 1 " + - ("but got rank " + variance.rank + ".")); - if (scale != null) { - util.assert(scale.rank === 4 || scale.rank === 1, "Error in batchNormalization4D: scale must be rank 4 or rank 1 " + - ("but got rank " + scale.rank + ".")); - } - if (offset != null) { - util.assert(offset.rank === 4 || offset.rank === 1, "Error in batchNormalization4D: offset must be rank 4 or rank 1 " + - ("but got rank " + offset.rank + ".")); - } - return Ops.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset); - }; - Ops.batchNormalization = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - var x4D; - if (x.rank === 0 || x.rank === 1) { - x4D = x.as4D(1, 1, 1, x.size); - } - else if (x.rank === 2) { - x4D = x.as4D(1, 1, x.shape[0], x.shape[1]); - } - else if (x.rank === 3) { - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - else { - x4D = x; - } - return environment_1.ENV.engine - .executeKernel('BatchNorm4D', { - inputs: { - x: x4D, - mean: batchnormReshape4D(mean), - variance: batchnormReshape4D(variance), - scale: batchnormReshape4D(scale), - offset: batchnormReshape4D(offset) - }, - args: { varianceEpsilon: varianceEpsilon } - }) - .reshape(x.shape); - }; - __decorate([ - operation_1.operation - ], Ops, "batchNormalization2d", null); - __decorate([ - operation_1.operation - ], Ops, "batchNormalization3d", null); - __decorate([ - operation_1.operation - ], Ops, "batchNormalization4d", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }) - ], Ops, "batchNormalization", null); - return Ops; -}()); -exports.Ops = Ops; -function batchnormReshape4D(x) { - if (x == null) { - return null; - } - if (x.rank === 0) { - return x.as1D(); - } - else if (x.rank === 1) { - return x; - } - else if (x.rank === 2) { - return x.as4D(1, 1, x.shape[0], x.shape[1]); - } - else if (x.rank === 3) { - return x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - return x; -} - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122}],109:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var broadcast_util = require("./broadcast_util"); -var operation_1 = require("./operation"); -var ops_1 = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.add = function (a, b) { - util.assertTypesMatch(a, b); - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.reshape(a.shape); - }; - var derB = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.reshape(b.shape); - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Add', { inputs: { a: a, b: b } }, der); - }; - Ops.addStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in addStrict: '); - return a.add(b); - }; - Ops.sub = function (a, b) { - util.assertTypesMatch(a, b); - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.reshape(a.shape); - }; - var derB = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.neg().reshape(b.shape); - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Sub', { inputs: { a: a, b: b } }, der); - }; - Ops.subStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in subStrict: '); - return a.sub(b); - }; - Ops.pow = function (base, exp) { - util.assert(exp.dtype === 'int32', 'only supports int32 data type for the exponent parameter.'); - broadcast_util.assertAndGetBroadcastShape(base.shape, exp.shape); - var gradient = function (dy, y) { - if (!util.arraysEqual(base.shape, exp.shape) && - !util.isScalarShape(exp.shape)) { - throw new Error("Gradient of pow not yet supported for broadcasted shapes."); - } - var derBase = function () { - var dx = exp.toFloat().mul(base.pow(exp.sub(ops_1.scalar(1, 'int32'))).toFloat()); - return dy.mul(dx); - }; - var derExp = function () { - throw new Error("Backprop through exponent not implemented yet."); - }; - return { base: derBase, exp: derExp }; - }; - return environment_1.ENV.engine.executeKernel('Pow', { inputs: { base: base, exp: exp } }, gradient); - }; - Ops.powStrict = function (base, exp) { - util.assertShapesMatch(base.shape, exp.shape, 'Error in powStrict: '); - return base.pow(exp); - }; - Ops.mul = function (a, b) { - util.assertTypesMatch(a, b); - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy.mul(b.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - return res.sum(reduceAxes).reshape(a.shape); - } - return res; - }; - var derB = function () { - var res = dy.mul(a.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - return res.sum(reduceAxes).reshape(b.shape); - } - return res; - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Mul', { inputs: { a: a, b: b } }, der); - }; - Ops.mulStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in multiplyStrict: '); - return a.mul(b); - }; - Ops.div = function (a, b) { - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy.div(b.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - return res.sum(reduceAxes).reshape(a.shape); - } - return res; - }; - var derB = function () { - var res = dy.mul(a.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes).reshape(b.shape); - } - var tmp = b.square(); - return res.div(tmp.toFloat()).neg(); - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Div', { inputs: { a: a, b: b } }, der); - }; - Ops.divStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in divideStrict: '); - return a.div(b); - }; - Ops.minimum = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { return dy.mul(a.lessEqual(b).toFloat()); }; - var derB = function () { return dy.mul(a.greater(b).toFloat()); }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Minimum', { inputs: { a: a, b: b } }, der); - }; - Ops.minimumStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in minimumStrict: '); - return a.minimum(b); - }; - Ops.maximum = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { return dy.mul(a.greaterEqual(b).toFloat()); }; - var derB = function () { return dy.mul(a.less(b).toFloat()); }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Maximum', { inputs: { a: a, b: b } }, der); - }; - Ops.maximumStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in minimumStrict: '); - return a.maximum(b); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "add", null); - __decorate([ - operation_1.operation - ], Ops, "addStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "sub", null); - __decorate([ - operation_1.operation - ], Ops, "subStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "pow", null); - __decorate([ - operation_1.operation - ], Ops, "powStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "mul", null); - __decorate([ - operation_1.operation - ], Ops, "mulStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "div", null); - __decorate([ - operation_1.operation - ], Ops, "divStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "minimum", null); - __decorate([ - operation_1.operation - ], Ops, "minimumStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "maximum", null); - __decorate([ - operation_1.operation - ], Ops, "maximumStrict", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./broadcast_util":110,"./operation":122,"./ops":123}],110:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function getBroadcastDims(inShape, outShape) { - var inRank = inShape.length; - var dims = []; - for (var i = 0; i < inRank; i++) { - var dim = inRank - 1 - i; - var a = inShape[dim] || 1; - var b = outShape[outShape.length - 1 - i] || 1; - if (b > 1 && a === 1) { - dims.unshift(dim); - } - } - return dims; -} -exports.getBroadcastDims = getBroadcastDims; -function getReductionAxes(inShape, outShape) { - var result = []; - for (var i = 0; i < outShape.length; i++) { - var inDim = inShape[inShape.length - i - 1]; - var outAxis = outShape.length - i - 1; - var outDim = outShape[outAxis]; - if (inDim == null || (inDim === 1 && outDim > 1)) { - result.unshift(outAxis); - } - } - return result; -} -exports.getReductionAxes = getReductionAxes; -function broadcastDimsAreOuter(dims) { - for (var i = 0; i < dims.length; i++) { - if (dims[i] !== i) { - return false; - } - } - return true; -} -exports.broadcastDimsAreOuter = broadcastDimsAreOuter; -function assertAndGetBroadcastShape(shapeA, shapeB) { - var result = []; - var errMsg = "Operands could not be broadcast together with shapes " + - (shapeA + " and " + shapeB + "."); - var l = Math.max(shapeA.length, shapeB.length); - for (var i = 0; i < l; i++) { - var a = shapeA[shapeA.length - i - 1] || 1; - var b = shapeB[shapeB.length - i - 1] || 1; - if (a > 1 && b > 1 && a !== b) { - throw Error(errMsg); - } - result.unshift(Math.max(a, b)); - } - return result; -} -exports.assertAndGetBroadcastShape = assertAndGetBroadcastShape; - -},{}],111:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var broadcast_util = require("./broadcast_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.notEqual = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('NotEqual', { inputs: { a: a, b: b } }); - }; - Ops.notEqualStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in notEqualStrict: '); - return a.notEqual(b); - }; - Ops.less = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('Less', { inputs: { a: a, b: b } }); - }; - Ops.lessStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in lessStrict: '); - return a.less(b); - }; - Ops.equal = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('Equal', { inputs: { a: a, b: b } }); - }; - Ops.equalStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in equalStrict: '); - return a.equal(b); - }; - Ops.lessEqual = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LessEqual', { inputs: { a: a, b: b } }); - }; - Ops.lessEqualStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in lessEqualStrict: '); - return a.lessEqual(b); - }; - Ops.greater = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('Greater', { inputs: { a: a, b: b } }); - }; - Ops.greaterStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in greaterStrict: '); - return a.greater(b); - }; - Ops.greaterEqual = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('GreaterEqual', { inputs: { a: a, b: b } }); - }; - Ops.greaterEqualStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in greaterEqualStrict: '); - return a.greaterEqual(b); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "notEqual", null); - __decorate([ - operation_1.operation - ], Ops, "notEqualStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "less", null); - __decorate([ - operation_1.operation - ], Ops, "lessStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "equal", null); - __decorate([ - operation_1.operation - ], Ops, "equalStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "lessEqual", null); - __decorate([ - operation_1.operation - ], Ops, "lessEqualStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "greater", null); - __decorate([ - operation_1.operation - ], Ops, "greaterStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "greaterEqual", null); - __decorate([ - operation_1.operation - ], Ops, "greaterEqualStrict", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./broadcast_util":110,"./operation":122}],112:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var concat_util = require("./concat_util"); -var operation_1 = require("./operation"); -var Concat = (function () { - function Concat() { - } - Concat.concat1d = function (tensors) { - return Concat.concat(tensors, 0); - }; - Concat.concat2d = function (tensors, axis) { - return Concat.concat(tensors, axis); - }; - Concat.concat3d = function (tensors, axis) { - return Concat.concat(tensors, axis); - }; - Concat.concat4d = function (tensors, axis) { - return Concat.concat(tensors, axis); - }; - Concat.concat = function (tensors, axis) { - if (axis === void 0) { axis = 0; } - util.assert(tensors.length >= 2, 'Pass at least two tensors to concat'); - var result = tensors[0]; - for (var i = 1; i < tensors.length; ++i) { - result = concat2Tensors(result, tensors[i], axis); - } - return result; - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Concat, "concat", null); - return Concat; -}()); -exports.Concat = Concat; -function concat2Tensors(a, b, axis) { - concat_util.assertParams(a.shape, b.shape, axis); - var outShape = concat_util.computeOutShape(a.shape, b.shape, axis); - var a2D = a.as2D(-1, util.sizeFromShape(a.shape.slice(axis))); - var b2D = b.as2D(-1, util.sizeFromShape(b.shape.slice(axis))); - var _a = concat_util.computeGradientSliceShapes(a2D.shape, b2D.shape), aBegin = _a.aBegin, aSize = _a.aSize, bBegin = _a.bBegin, bSize = _a.bSize; - var der = function (dy) { - return { a: function () { return dy.slice(aBegin, aSize); }, b: function () { return dy.slice(bBegin, bSize); } }; - }; - var res = environment_1.ENV.engine.executeKernel('Concat', { inputs: { a: a2D, b: b2D } }, der); - return res.reshape(outShape); -} - -},{"../doc":32,"../environment":34,"../util":151,"./concat_util":113,"./operation":122}],113:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function assertParams(aShape, bShape, axis) { - var aRank = aShape.length; - var bRank = bShape.length; - util.assert(aShape.length === bShape.length, "Error in concat" + aRank + "D: rank of x1 (" + aRank + ") and x2 (" + bRank + ") " + - "must be the same."); - util.assert(axis >= 0 && axis < aRank, "Error in concat" + aRank + "D: axis must be " + - ("between 0 and " + (aRank - 1) + ".")); - for (var i = 0; i < aRank; i++) { - util.assert((i === axis) || (aShape[i] === bShape[i]), "Error in concat" + aRank + "D: Shape (" + aShape + ") does not match " + - ("(" + bShape + ") along the non-concatenated axis " + i + ".")); - } -} -exports.assertParams = assertParams; -function computeOutShape1D(x1Shape, x2Shape) { - util.assert(x1Shape.length === 1 && x2Shape.length === 1, 'x1 and x2 should be 1d array.'); - var outputShape = x1Shape.slice(); - outputShape[0] += x2Shape[0]; - return outputShape; -} -exports.computeOutShape1D = computeOutShape1D; -function computeOutShape(x1Shape, x2Shape, axis) { - util.assert(x1Shape.length === x2Shape.length, 'x1 and x2 should have the same rank.'); - var outputShape = x1Shape.slice(); - outputShape[axis] += x2Shape[axis]; - return outputShape; -} -exports.computeOutShape = computeOutShape; -function computeGradientSliceShapes(aShape, bShape) { - return { - aBegin: [0, 0], - aSize: aShape, - bBegin: [0, aShape[1]], - bSize: bShape - }; -} -exports.computeGradientSliceShapes = computeGradientSliceShapes; - -},{"../util":151}],114:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var conv_util = require("./conv_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.conv1d = function (input, filter, stride, pad, dimRoundingMode) { - var input3D = input; - var reshapedTo3D = false; - if (input.rank === 2) { - reshapedTo3D = true; - input3D = input.as3D(1, input.shape[0], input.shape[1]); - } - util.assert(input3D.rank === 3, "Error in conv1d: input must be rank 3, but got rank " + input3D.rank + "."); - util.assert(filter.rank === 3, "Error in conv1d: filter must be rank 3, but got rank " + - (filter.rank + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv1d: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - util.assert(input3D.shape[2] === filter.shape[1], "Error in conv1d: depth of input (" + input3D.shape[2] + ") must match " + - ("input depth for filter " + filter.shape[1] + ".")); - var filter4D = filter.as4D(1, filter.shape[0], filter.shape[1], filter.shape[2]); - var input4D = input3D.as4D(input3D.shape[0], 1, input3D.shape[1], input3D.shape[2]); - var strides = [1, stride]; - var res = Ops.conv2d(input4D, filter4D, strides, pad, dimRoundingMode); - if (reshapedTo3D) { - return res.as2D(res.shape[2], res.shape[3]); - } - return res.as3D(res.shape[0], res.shape[2], res.shape[3]); - }; - Ops.conv2d = function (x, filter, strides, pad, dimRoundingMode) { - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - util.assert(x4D.rank === 4, "Error in conv2d: input must be rank 4, but got rank " + x4D.rank + "."); - util.assert(filter.rank === 4, "Error in conv2d: filter must be rank 4, but got rank " + - (filter.rank + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv2d: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - util.assert(x4D.shape[3] === filter.shape[2], "Error in conv2d: depth of input (" + x4D.shape[3] + ") must match " + - ("input depth for filter " + filter.shape[2] + ".")); - var convInfo = conv_util.computeConv2DInfo(x4D.shape, filter.shape, strides, pad, dimRoundingMode); - var gradients = function (dy, y) { - return { - x: function () { return Ops.conv2dDerInput(x4D.shape, dy, filter, strides, pad); }, - filter: function () { return Ops.conv2dDerFilter(x4D, dy, filter.shape, strides, pad); } - }; - }; - var res = environment_1.ENV.engine.executeKernel('Conv2D', { inputs: { x: x4D, filter: filter }, args: { convInfo: convInfo } }, gradients); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.conv2dDerInput = function (xShape, dy, filter, strides, pad, dimRoundingMode) { - util.assert(xShape.length === dy.rank, "Length of inShape " + - ("(" + xShape.length + ") and rank of dy (" + dy.rank + ") must match")); - var xShape4D = xShape; - var dy4D = dy; - var reshapedTo4D = false; - if (dy.rank === 3) { - reshapedTo4D = true; - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - xShape4D = [1, xShape[0], xShape[1], xShape[2]]; - } - var inDepth = xShape4D[3]; - var outDepth = dy4D.shape[3]; - util.assert(xShape4D.length === 4, "Error in conv2dDerInput: inShape must be length 4, but got length " + - (xShape4D.length + ".")); - util.assert(dy4D.rank === 4, "Error in conv2dDerInput: dy must be rank 4, but got " + - ("rank " + dy4D.rank)); - util.assert(filter.rank === 4, "Error in conv2dDerInput: filter must be rank 4, but got " + - ("rank " + filter.rank)); - util.assert(inDepth === filter.shape[2], "Error in conv2dDerInput: depth of input (" + inDepth + ") must " + - ("match input depth for filter " + filter.shape[2] + ".")); - util.assert(outDepth === filter.shape[3], "Error in conv2dDerInput: depth of output (" + outDepth + ") must" + - ("match output depth for filter " + filter.shape[3] + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv2dDerInput: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computeConv2DInfo(xShape4D, filter.shape, strides, pad, dimRoundingMode); - var res = environment_1.ENV.engine.executeKernel('Conv2DDerInput', { inputs: { dy: dy4D, filter: filter }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.conv2dDerFilter = function (x, dy, filterShape, strides, pad, dimRoundingMode) { - var x4D = x; - if (x.rank === 3) { - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - var dy4D = dy; - if (dy4D.rank === 3) { - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - } - util.assert(x4D.rank === 4, "Error in conv2dDerFilter: input must be rank 4, but got shape " + - (x4D.shape + ".")); - util.assert(dy4D.rank === 4, "Error in conv2dDerFilter: dy must be rank 4, but got shape " + - (dy4D.shape + ".")); - util.assert(filterShape.length === 4, "Error in conv2dDerFilter: filterShape must be length 4, but got " + - (filterShape + ".")); - util.assert(x4D.shape[3] === filterShape[2], "Error in conv2dDerFilter: depth of input " + x4D.shape[3] + ") must " + - ("match input depth in filter (" + filterShape[2] + ".")); - util.assert(dy4D.shape[3] === filterShape[3], "Error in conv2dDerFilter: depth of dy (" + dy4D.shape[3] + ") must " + - ("match output depth for filter (" + filterShape[3] + ").")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv2dDerFilter: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computeConv2DInfo(x4D.shape, filterShape, strides, pad, dimRoundingMode); - return environment_1.ENV.engine.executeKernel('Conv2DDerFilter', { inputs: { x: x4D, dy: dy4D }, args: { convInfo: convInfo } }); - }; - Ops.conv2dTranspose = function (x, filter, outputShape, strides, pad, dimRoundingMode) { - return Ops.conv2dDerInput(outputShape, x, filter, strides, pad, dimRoundingMode); - }; - Ops.depthwiseConv2d = function (input, filter, strides, pad, rates, dimRoundingMode) { - if (rates === void 0) { rates = [1, 1]; } - var input4D = input; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - } - util.assert(input4D.rank === 4, "Error in depthwiseConv2D: input must be rank 4, but got " + - ("rank " + input4D.rank + ".")); - util.assert(filter.rank === 4, "Error in depthwiseConv2D: filter must be rank 4, but got rank " + - (filter.rank + ".")); - util.assert(input4D.shape[3] === filter.shape[2], "Error in depthwiseConv2D: number of input channels " + - ("(" + input4D.shape[3] + ") must match the inChannels dimension in ") + - ("filter " + filter.shape[2] + ".")); - rates = rates || [1, 1]; - var _a = parseTupleParam(rates), rateHeight = _a[0], rateWidth = _a[1]; - util.assert(rateHeight === 1 && rateWidth === 1, 'Error in depthwiseConv2D: rates greater than 1 are not yet ' + - ("supported. Got rates '" + rates + "'")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in depthwiseConv2D: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computeConv2DInfo(input4D.shape, filter.shape, strides, pad, dimRoundingMode, true); - var res = environment_1.ENV.engine.executeKernel('DepthwiseConv2D', { inputs: { x: input4D, filter: filter }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "conv1d", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "conv2d", null); - __decorate([ - operation_1.operation - ], Ops, "conv2dDerInput", null); - __decorate([ - operation_1.operation - ], Ops, "conv2dDerFilter", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "conv2dTranspose", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "depthwiseConv2d", null); - return Ops; -}()); -exports.Ops = Ops; -function parseTupleParam(param) { - return typeof param === 'number' ? [param, param] : param; -} - -},{"../doc":32,"../environment":34,"../util":151,"./conv_util":115,"./operation":122}],115:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function computePool2DInfo(inShape, filterSize, strides, pad, roundingMode, dataFormat) { - if (dataFormat === void 0) { dataFormat = 'channelsLast'; } - var _a = parseTupleParam(filterSize), filterHeight = _a[0], filterWidth = _a[1]; - var filterShape; - if (dataFormat === 'channelsLast') { - filterShape = [filterHeight, filterWidth, inShape[3], inShape[3]]; - } - else if (dataFormat === 'channelsFirst') { - filterShape = [filterHeight, filterWidth, inShape[1], inShape[1]]; - } - else { - throw new Error("Unknown dataFormat " + dataFormat); - } - return computeConv2DInfo(inShape, filterShape, strides, pad, roundingMode, false, dataFormat); -} -exports.computePool2DInfo = computePool2DInfo; -function computeConv2DInfo(inShape, filterShape, strides, pad, roundingMode, depthwise, dataFormat) { - if (depthwise === void 0) { depthwise = false; } - if (dataFormat === void 0) { dataFormat = 'channelsLast'; } - var _a = [-1, -1, -1, -1], batchSize = _a[0], inHeight = _a[1], inWidth = _a[2], inChannels = _a[3]; - if (dataFormat === 'channelsLast') { - batchSize = inShape[0], inHeight = inShape[1], inWidth = inShape[2], inChannels = inShape[3]; - } - else if (dataFormat === 'channelsFirst') { - batchSize = inShape[0], inChannels = inShape[1], inHeight = inShape[2], inWidth = inShape[3]; - } - else { - throw new Error("Unknown dataFormat " + dataFormat); - } - var filterHeight = filterShape[0], filterWidth = filterShape[1], filterChannels = filterShape[3]; - var _b = parseTupleParam(strides), strideHeight = _b[0], strideWidth = _b[1]; - var _c = getPadAndOutInfo(pad, inHeight, inWidth, strideHeight, strideWidth, filterHeight, filterWidth, roundingMode), padInfo = _c.padInfo, outHeight = _c.outHeight, outWidth = _c.outWidth; - var outChannels = depthwise ? filterChannels * inChannels : filterChannels; - var outShape; - if (dataFormat === 'channelsFirst') { - outShape = [batchSize, outChannels, outHeight, outWidth]; - } - else if (dataFormat === 'channelsLast') { - outShape = [batchSize, outHeight, outWidth, outChannels]; - } - return { - batchSize: batchSize, - dataFormat: dataFormat, - inHeight: inHeight, - inWidth: inWidth, - inChannels: inChannels, - outHeight: outHeight, - outWidth: outWidth, - outChannels: outChannels, - padInfo: padInfo, - strideHeight: strideHeight, - strideWidth: strideWidth, - filterHeight: filterHeight, - filterWidth: filterWidth, - inShape: inShape, - outShape: outShape, - filterShape: filterShape - }; -} -exports.computeConv2DInfo = computeConv2DInfo; -function computeOutputShape3D(inShape, fieldSize, outDepth, stride, zeroPad, roundingMode) { - if (zeroPad == null) { - zeroPad = computeDefaultPad(inShape, fieldSize, stride); - } - var inputRows = inShape[0]; - var inputCols = inShape[1]; - var outputRows = conditionalRound((inputRows - fieldSize + 2 * zeroPad) / stride + 1, roundingMode); - util.assert(util.isInt(outputRows), "The output # of rows (" + outputRows + ") must be an integer. Change the " + - "stride and/or zero pad parameters"); - var outputCols = conditionalRound((inputCols - fieldSize + 2 * zeroPad) / stride + 1, roundingMode); - util.assert(util.isInt(outputCols), "The output # of columns (" + outputCols + ") must be an integer. Change " + - "the stride and/or zero pad parameters"); - return [outputRows, outputCols, outDepth]; -} -exports.computeOutputShape3D = computeOutputShape3D; -function computeDefaultPad(inputShape, fieldSize, stride) { - return Math.floor((inputShape[0] * (stride - 1) - stride + fieldSize) / 2); -} -exports.computeDefaultPad = computeDefaultPad; -function computeWeightsShape4D(inputDepth, outputDepth, filterHeight, filterWidth) { - return [filterHeight, filterWidth, inputDepth, outputDepth]; -} -exports.computeWeightsShape4D = computeWeightsShape4D; -function computeDilatedRC(rc, origStride) { - var rowsDilated = (rc[0] - 1) * origStride + 1; - var colsDilated = (rc[1] - 1) * origStride + 1; - return [rowsDilated, colsDilated]; -} -exports.computeDilatedRC = computeDilatedRC; -function parseTupleParam(param) { - return typeof param === 'number' ? [param, param] : param; -} -function getPadAndOutInfo(pad, inHeight, inWidth, strideHeight, strideWidth, filterHeight, filterWidth, roundingMode) { - var padInfo; - var outHeight; - var outWidth; - if (typeof pad === 'number') { - padInfo = { top: pad, bottom: pad, left: pad, right: pad }; - var outShape = computeOutputShape3D([inHeight, inWidth, 1], filterHeight, 1, strideHeight, pad, roundingMode); - outHeight = outShape[0]; - outWidth = outShape[1]; - } - else if (pad === 'same') { - outHeight = Math.ceil(inHeight / strideHeight); - outWidth = Math.ceil(inWidth / strideWidth); - var padAlongHeight = (outHeight - 1) * strideHeight + filterHeight - inHeight; - var padAlongWidth = (outWidth - 1) * strideWidth + filterWidth - inWidth; - var top_1 = Math.floor(padAlongHeight / 2); - var bottom = padAlongHeight - top_1; - var left = Math.floor(padAlongWidth / 2); - var right = padAlongWidth - left; - padInfo = { top: top_1, bottom: bottom, left: left, right: right }; - } - else if (pad === 'valid') { - padInfo = { top: 0, bottom: 0, left: 0, right: 0 }; - outHeight = Math.ceil((inHeight - filterHeight + 1) / strideHeight); - outWidth = Math.ceil((inWidth - filterWidth + 1) / strideWidth); - } - else { - throw Error("Unknown padding parameter: " + pad); - } - return { padInfo: padInfo, outHeight: outHeight, outWidth: outWidth }; -} -function conditionalRound(value, roundingMode) { - if (!roundingMode) { - return value; - } - switch (roundingMode) { - case 'round': - return Math.round(value); - case 'ceil': - return Math.ceil(value); - case 'floor': - return Math.floor(value); - default: - throw new Error("Unknown roundingMode " + roundingMode); - } -} - -},{"../util":151}],116:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.resizeBilinear = function (images, size, alignCorners) { - if (alignCorners === void 0) { alignCorners = false; } - util.assert(images.rank === 3 || images.rank === 4, "Error in resizeBilinear: x must be rank 3 or 4, but got " + - ("rank " + images.rank + ".")); - util.assert(size.length === 2, "Error in resizeBilinear: new shape must 2D, but got shape " + - (size + ".")); - var batchImages = images; - var reshapedTo4D = false; - if (images.rank === 3) { - reshapedTo4D = true; - batchImages = - images.as4D(1, images.shape[0], images.shape[1], images.shape[2]); - } - var newHeight = size[0], newWidth = size[1]; - var res = environment_1.ENV.engine.executeKernel('ResizeBilinear', { inputs: { x: batchImages }, args: { newHeight: newHeight, newWidth: newWidth, alignCorners: alignCorners } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Images', namespace: 'image' }), - operation_1.operation - ], Ops, "resizeBilinear", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122}],117:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var types = require("../types"); -var util = require("../util"); -var broadcast_util = require("./broadcast_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.logicalNot = function (x) { - util.assert(x.dtype === 'bool', 'Error Array must be of type bool.'); - return environment_1.ENV.engine.executeKernel('LogicalNot', { inputs: { x: x } }); - }; - Ops.logicalAnd = function (a, b) { - util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.'); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LogicalAnd', { inputs: { a: a, b: b } }); - }; - Ops.logicalOr = function (a, b) { - util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.'); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LogicalOr', { inputs: { a: a, b: b } }); - }; - Ops.logicalXor = function (a, b) { - util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.'); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LogicalXor', { inputs: { a: a, b: b } }); - }; - Ops.where = function (condition, a, b) { - util.assert(condition.dtype === 'bool' || a.dtype === 'bool' || b.dtype === 'bool', 'Error Array must be of type bool.'); - util.assertShapesMatch(a.shape, b.shape, 'Error in where: '); - if (condition.rank === 1) { - util.assert(condition.shape[0] === a.shape[0], 'The first dimension of `a` must match the size of `condition`.'); - } - else { - util.assertShapesMatch(condition.shape, b.shape, 'Error in where: '); - } - var dtype = types.upcastType(a.dtype, b.dtype); - return environment_1.ENV.engine.executeKernel('Where', { inputs: { condition: condition, a: a, b: b }, args: { dtype: dtype } }); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalNot", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalAnd", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalOr", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalXor", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "where", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../types":150,"../util":151,"./broadcast_util":110,"./operation":122}],118:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var LRN = (function () { - function LRN() { - } - LRN.localResponseNormalization = function (x, radius, bias, alpha, beta, normRegion) { - if (radius === void 0) { radius = 5; } - if (bias === void 0) { bias = 1; } - if (alpha === void 0) { alpha = 1; } - if (beta === void 0) { beta = 0.5; } - if (normRegion === void 0) { normRegion = 'acrossChannels'; } - util.assert(x.rank === 4 || x.rank === 3, "Error in localResponseNormalization: x must be rank 3 or 4 but got\n rank " + x.rank + "."); - util.assert(util.isInt(radius), "Error in localResponseNormalization3D: radius must be an integer\n but got radius " + radius + "."); - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - var res = environment_1.ENV.engine.executeKernel('LRN4D', { inputs: { x: x4D }, args: { radius: radius, bias: bias, alpha: alpha, beta: beta, normRegion: normRegion } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - else { - return res; - } - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }), - operation_1.operation - ], LRN, "localResponseNormalization", null); - return LRN; -}()); -exports.LRN = LRN; - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122}],119:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.multiRNNCell = function (lstmCells, data, c, h) { - var input = data; - var newStates = []; - for (var i = 0; i < lstmCells.length; i++) { - var output = lstmCells[i](input, c[i], h[i]); - newStates.push(output[0]); - newStates.push(output[1]); - input = output[1]; - } - var newC = []; - var newH = []; - for (var i = 0; i < newStates.length; i += 2) { - newC.push(newStates[i]); - newH.push(newStates[i + 1]); - } - return [newC, newH]; - }; - Ops.basicLSTMCell = function (forgetBias, lstmKernel, lstmBias, data, c, h) { - var combined = data.concat(h, 1); - var weighted = combined.matMul(lstmKernel); - var res = weighted.add(lstmBias); - var batchSize = res.shape[0]; - var sliceCols = res.shape[1] / 4; - var sliceSize = [batchSize, sliceCols]; - var i = res.slice([0, 0], sliceSize); - var j = res.slice([0, sliceCols], sliceSize); - var f = res.slice([0, sliceCols * 2], sliceSize); - var o = res.slice([0, sliceCols * 3], sliceSize); - var newC = i.sigmoid().mulStrict(j.tanh()).addStrict(c.mulStrict(forgetBias.add(f).sigmoid())); - var newH = newC.tanh().mulStrict(o.sigmoid()); - return [newC, newH]; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'RNN' }), - operation_1.operation - ], Ops, "multiRNNCell", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'RNN' }), - operation_1.operation - ], Ops, "basicLSTMCell", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"./operation":122}],120:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var matmul_1 = require("../kernels/types/matmul"); -var util = require("../util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.matMul = function (a, b, transposeA, transposeB) { - if (transposeA === void 0) { transposeA = false; } - if (transposeB === void 0) { transposeB = false; } - _a = [enumToBool(transposeA), enumToBool(transposeB)], transposeA = _a[0], transposeB = _a[1]; - var innerShapeA = transposeA ? a.shape[0] : a.shape[1]; - var innerShapeB = transposeB ? b.shape[1] : b.shape[0]; - util.assert(a.rank === 2 && b.rank === 2, "Error in matMul: inputs must be rank 2, got ranks " + a.rank + - (" and " + b.rank + ".")); - util.assert(innerShapeA === innerShapeB, "Error in matMul: inner shapes (" + innerShapeA + ") and (" + - (innerShapeB + ") of Tensors with shapes " + a.shape + " and ") + - (b.shape + " and transposeA=" + transposeA) + - (" and transposeB=" + transposeB + " must match.")); - return environment_1.ENV.engine.executeKernel('MatMul', { inputs: { a: a, b: b }, args: { transposeA: transposeA, transposeB: transposeB } }, function (dy, y) { - if (transposeA || transposeB) { - throw new Error("Backprop for transposed MatMul not yet implemented."); - } - return { - a: function () { return dy.matMul(b.toFloat(), false, true); }, - b: function () { return a.toFloat().matMul(dy, true, false); } - }; - }); - var _a; - }; - Ops.vectorTimesMatrix = function (v, matrix) { - util.assert(v.rank === 1, "Error in vectorTimesMatrix: first input must be rank 1, but got " + - ("rank " + v.rank + ".")); - util.assert(matrix.rank === 2, "Error in vectorTimesMatrix: second input must be rank 2, but got " + - ("rank " + matrix.rank + ".")); - util.assert(v.size === matrix.shape[0], "Error in vectorTimesMatrix: size of vector (" + v.size + ") " + - ("must match first dimension of matrix (" + matrix.shape[0] + ")")); - return v.as2D(1, -1).matMul(matrix).as1D(); - }; - Ops.matrixTimesVector = function (matrix, v) { - util.assert(v.rank === 1, "Error in matrixTimesVector: second input must rank 1, but got " + - ("rank " + v.rank + ".")); - util.assert(matrix.rank === 2, "Error in matrixTimesVector: first input must be a rank 2, but got " + - ("rank " + matrix.rank + ".")); - util.assert(v.size === matrix.shape[1], "Error in matrixTimesVector: size of first rank 1 input " + v.size + " " + - "must match inner dimension of second rank 2 input, but got " + - ("shape " + matrix.shape + ".")); - return matrix.matMul(v.as2D(-1, 1)).as1D(); - }; - Ops.dotProduct = function (v1, v2) { - util.assert(v1.rank === 1 && v2.rank === 1, "Error in dotProduct: inputs must be rank 1, but got ranks " + - (v1.rank + " and " + v2.rank + ".")); - util.assert(v1.size === v2.size, "Error in dotProduct: size of inputs (" + v1.size + ") and (" + - (v2.size + ") must match.")); - return v1.as2D(1, -1).matMul(v2.as2D(-1, 1)).asScalar(); - }; - Ops.outerProduct = function (v1, v2) { - util.assert(v1.rank === 1 && v2.rank === 1, "Error in outerProduct: inputs must be rank 1, but got ranks " + - (v1.rank + " and " + v2.rank + ".")); - return v1.as2D(-1, 1).matMul(v2.as2D(1, -1)); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "matMul", null); - __decorate([ - operation_1.operation - ], Ops, "vectorTimesMatrix", null); - __decorate([ - operation_1.operation - ], Ops, "matrixTimesVector", null); - __decorate([ - operation_1.operation - ], Ops, "dotProduct", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "outerProduct", null); - return Ops; -}()); -exports.Ops = Ops; -function enumToBool(transpose) { - if (transpose === matmul_1.MatrixOrientation.REGULAR) { - return false; - } - if (transpose === matmul_1.MatrixOrientation.TRANSPOSED) { - return true; - } - return transpose; -} - -},{"../doc":32,"../environment":34,"../kernels/types/matmul":71,"../util":151,"./operation":122}],121:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.norm = function (x, ord, axis, keepDims) { - if (ord === void 0) { ord = 'euclidean'; } - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var norm = normImpl(x, ord, axis); - var keepDimsShape = norm.shape; - if (keepDims) { - var axes = axis_util.parseAxisParam(axis, x.shape); - keepDimsShape = axis_util.expandShapeToKeepDim(norm.shape, axes); - } - return norm.reshape(keepDimsShape); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "norm", null); - return Ops; -}()); -exports.Ops = Ops; -function normImpl(x, p, axis) { - if (axis === void 0) { axis = null; } - if (x.rank === 0) { - return x.abs(); - } - if (x.rank !== 1 && axis === null) { - return normImpl(x.reshape([-1]), p, axis); - } - if (x.rank === 1 || typeof axis === 'number' || - axis instanceof Array && axis.length === 1) { - if (p === 1) { - return x.abs().sum(axis); - } - if (p === Infinity) { - return x.abs().max(axis); - } - if (p === -Infinity) { - return x.abs().min(axis); - } - if (p === 'euclidean' || p === 2) { - return x.abs().pow(ops.scalar(2, 'int32')).sum(axis).sqrt(); - } - throw new Error("Error in norm: invalid ord value: " + p); - } - if (axis instanceof Array && axis.length === 2) { - if (p === 1) { - return x.abs().sum(axis[0]).max(axis[1] - 1); - } - if (p === Infinity) { - return x.abs().sum(axis[1]).max(axis[0]); - } - if (p === -Infinity) { - return x.abs().sum(axis[1]).min(axis[0]); - } - if (p === 'fro' || p === 'euclidean') { - return x.square().sum(axis).sqrt(); - } - throw new Error("Error in norm: invalid ord value: " + p); - } - throw new Error("Error in norm: invalid axis: " + axis); -} - -},{"../doc":32,"./axis_util":107,"./operation":122,"./ops":123}],122:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -function operation(target, name, descriptor) { - var fn = descriptor.value; - descriptor.value = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return globals_1.tidy(name, function () { return fn.apply(void 0, args); }); - }; - return descriptor; -} -exports.operation = operation; - -},{"../globals":35}],123:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var array_ops = require("./array_ops"); -var batchnorm_ops = require("./batchnorm"); -var binary_ops = require("./binary_ops"); -var compare_ops = require("./compare"); -var concat_ops = require("./concat"); -var conv_ops = require("./conv"); -var image_ops = require("./image_ops"); -var logical_ops = require("./logical_ops"); -var lrn_ops = require("./lrn"); -var lstm_ops = require("./lstm"); -var matmul_ops = require("./matmul"); -var norm_ops = require("./norm"); -var pool_ops = require("./pool"); -var reduction_ops = require("./reduction_ops"); -var reverse_ops = require("./reverse"); -var slice_ops = require("./slice"); -var softmax_ops = require("./softmax"); -var transpose_ops = require("./transpose"); -var unary_ops = require("./unary_ops"); -exports.batchNormalization = batchnorm_ops.Ops.batchNormalization; -exports.batchNormalization2d = batchnorm_ops.Ops.batchNormalization2d; -exports.batchNormalization3d = batchnorm_ops.Ops.batchNormalization3d; -exports.batchNormalization4d = batchnorm_ops.Ops.batchNormalization4d; -exports.concat = concat_ops.Concat.concat; -exports.concat1d = concat_ops.Concat.concat1d; -exports.concat2d = concat_ops.Concat.concat2d; -exports.concat3d = concat_ops.Concat.concat3d; -exports.concat4d = concat_ops.Concat.concat4d; -exports.conv1d = conv_ops.Ops.conv1d; -exports.conv2d = conv_ops.Ops.conv2d; -exports.conv2dTranspose = conv_ops.Ops.conv2dTranspose; -exports.depthwiseConv2d = conv_ops.Ops.depthwiseConv2d; -exports.matMul = matmul_ops.Ops.matMul; -exports.matrixTimesVector = matmul_ops.Ops.matrixTimesVector; -exports.outerProduct = matmul_ops.Ops.outerProduct; -exports.vectorTimesMatrix = matmul_ops.Ops.vectorTimesMatrix; -exports.avgPool = pool_ops.Ops.avgPool; -exports.maxPool = pool_ops.Ops.maxPool; -exports.minPool = pool_ops.Ops.minPool; -exports.transpose = transpose_ops.Ops.transpose; -exports.reverse = reverse_ops.Ops.reverse; -exports.reverse1d = reverse_ops.Ops.reverse1d; -exports.reverse2d = reverse_ops.Ops.reverse2d; -exports.reverse3d = reverse_ops.Ops.reverse3d; -exports.reverse4d = reverse_ops.Ops.reverse4d; -exports.slice = slice_ops.Ops.slice; -exports.slice1d = slice_ops.Ops.slice1d; -exports.slice2d = slice_ops.Ops.slice2d; -exports.slice3d = slice_ops.Ops.slice3d; -exports.slice4d = slice_ops.Ops.slice4d; -exports.argMax = reduction_ops.Ops.argMax; -exports.argMin = reduction_ops.Ops.argMin; -exports.logSumExp = reduction_ops.Ops.logSumExp; -exports.max = reduction_ops.Ops.max; -exports.mean = reduction_ops.Ops.mean; -exports.min = reduction_ops.Ops.min; -exports.moments = reduction_ops.Ops.moments; -exports.sum = reduction_ops.Ops.sum; -exports.equal = compare_ops.Ops.equal; -exports.equalStrict = compare_ops.Ops.equalStrict; -exports.greater = compare_ops.Ops.greater; -exports.greaterStrict = compare_ops.Ops.greaterStrict; -exports.greaterEqual = compare_ops.Ops.greaterEqual; -exports.greaterEqualStrict = compare_ops.Ops.greaterEqualStrict; -exports.less = compare_ops.Ops.less; -exports.lessStrict = compare_ops.Ops.lessStrict; -exports.lessEqual = compare_ops.Ops.lessEqual; -exports.lessEqualStrict = compare_ops.Ops.lessEqualStrict; -exports.notEqual = compare_ops.Ops.notEqual; -exports.notEqualStrict = compare_ops.Ops.notEqualStrict; -exports.logicalNot = logical_ops.Ops.logicalNot; -exports.logicalAnd = logical_ops.Ops.logicalAnd; -exports.logicalOr = logical_ops.Ops.logicalOr; -exports.logicalXor = logical_ops.Ops.logicalXor; -exports.where = logical_ops.Ops.where; -exports.abs = unary_ops.Ops.abs; -exports.acos = unary_ops.Ops.acos; -exports.asin = unary_ops.Ops.asin; -exports.atan = unary_ops.Ops.atan; -exports.ceil = unary_ops.Ops.ceil; -exports.clipByValue = unary_ops.Ops.clipByValue; -exports.cos = unary_ops.Ops.cos; -exports.cosh = unary_ops.Ops.cosh; -exports.elu = unary_ops.Ops.elu; -exports.exp = unary_ops.Ops.exp; -exports.floor = unary_ops.Ops.floor; -exports.leakyRelu = unary_ops.Ops.leakyRelu; -exports.log = unary_ops.Ops.log; -exports.neg = unary_ops.Ops.neg; -exports.prelu = unary_ops.Ops.prelu; -exports.relu = unary_ops.Ops.relu; -exports.selu = unary_ops.Ops.selu; -exports.sigmoid = unary_ops.Ops.sigmoid; -exports.sin = unary_ops.Ops.sin; -exports.sinh = unary_ops.Ops.sinh; -exports.sqrt = unary_ops.Ops.sqrt; -exports.square = unary_ops.Ops.square; -exports.step = unary_ops.Ops.step; -exports.tan = unary_ops.Ops.tan; -exports.tanh = unary_ops.Ops.tanh; -exports.add = binary_ops.Ops.add; -exports.addStrict = binary_ops.Ops.addStrict; -exports.div = binary_ops.Ops.div; -exports.divStrict = binary_ops.Ops.divStrict; -exports.maximum = binary_ops.Ops.maximum; -exports.maximumStrict = binary_ops.Ops.maximumStrict; -exports.minimum = binary_ops.Ops.minimum; -exports.minimumStrict = binary_ops.Ops.minimumStrict; -exports.mul = binary_ops.Ops.mul; -exports.mulStrict = binary_ops.Ops.mulStrict; -exports.pow = binary_ops.Ops.pow; -exports.powStrict = binary_ops.Ops.powStrict; -exports.sub = binary_ops.Ops.sub; -exports.subStrict = binary_ops.Ops.subStrict; -exports.norm = norm_ops.Ops.norm; -exports.cast = array_ops.Ops.cast; -exports.clone = array_ops.Ops.clone; -exports.fromPixels = array_ops.Ops.fromPixels; -exports.ones = array_ops.Ops.ones; -exports.onesLike = array_ops.Ops.onesLike; -exports.zeros = array_ops.Ops.zeros; -exports.zerosLike = array_ops.Ops.zerosLike; -exports.rand = array_ops.Ops.rand; -exports.randomNormal = array_ops.Ops.randomNormal; -exports.truncatedNormal = array_ops.Ops.truncatedNormal; -exports.randomUniform = array_ops.Ops.randomUniform; -exports.reshape = array_ops.Ops.reshape; -exports.squeeze = array_ops.Ops.squeeze; -exports.tile = array_ops.Ops.tile; -exports.gather = array_ops.Ops.gather; -exports.oneHot = array_ops.Ops.oneHot; -exports.linspace = array_ops.Ops.linspace; -exports.range = array_ops.Ops.range; -exports.buffer = array_ops.Ops.buffer; -exports.fill = array_ops.Ops.fill; -exports.tensor = array_ops.Ops.tensor; -exports.scalar = array_ops.Ops.scalar; -exports.tensor1d = array_ops.Ops.tensor1d; -exports.tensor2d = array_ops.Ops.tensor2d; -exports.tensor3d = array_ops.Ops.tensor3d; -exports.tensor4d = array_ops.Ops.tensor4d; -exports.print = array_ops.Ops.print; -exports.expandDims = array_ops.Ops.expandDims; -exports.stack = array_ops.Ops.stack; -exports.pad = array_ops.Ops.pad; -exports.pad1d = array_ops.Ops.pad1d; -exports.pad2d = array_ops.Ops.pad2d; -exports.basicLSTMCell = lstm_ops.Ops.basicLSTMCell; -exports.multiRNNCell = lstm_ops.Ops.multiRNNCell; -exports.softmax = softmax_ops.Ops.softmax; -exports.localResponseNormalization = lrn_ops.LRN.localResponseNormalization; -var tensor_1 = require("../tensor"); -var types_1 = require("../types"); -[tensor_1.Tensor, types_1.Rank, tensor_1.Tensor3D, tensor_1.Tensor4D]; -exports.losses = { - softmaxCrossEntropy: softmax_ops.Ops.softmaxCrossEntropy -}; -exports.image = { - resizeBilinear: image_ops.Ops.resizeBilinear -}; - -},{"../tensor":146,"../types":150,"./array_ops":106,"./batchnorm":108,"./binary_ops":109,"./compare":111,"./concat":112,"./conv":114,"./image_ops":116,"./logical_ops":117,"./lrn":118,"./lstm":119,"./matmul":120,"./norm":121,"./pool":124,"./reduction_ops":127,"./reverse":128,"./slice":130,"./softmax":132,"./transpose":133,"./unary_ops":134}],124:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var conv_util = require("./conv_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.maxPool = function (x, filterSize, strides, pad, dimRoundingMode) { - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - util.assert(x4D.rank === 4, "Error in maxPool: input must be rank 4 but got rank " + x4D.rank + "."); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in maxPool: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(x4D.shape, filterSize, strides, pad, dimRoundingMode); - var gradients = function (dy, y) { - return { x: function () { return Ops.maxPoolBackprop(dy, x4D, filterSize, strides, pad); } }; - }; - var res = environment_1.ENV.engine.executeKernel('MaxPool', { inputs: { x: x4D }, args: { convInfo: convInfo } }, gradients); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.maxPoolBackprop = function (dy, input, filterSize, strides, pad, dimRoundingMode) { - util.assert(input.rank === dy.rank, "Rank of input (" + input.rank + ") does not match rank of dy (" + dy.rank + ")"); - var input4D = input; - var dy4D = dy; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - } - util.assert(dy4D.rank === 4, "Error in maxPoolBackprop: dy must be rank 4 but got rank " + - (dy4D.rank + ".")); - util.assert(input4D.rank === 4, "Error in maxPoolBackprop: input must be rank 4 but got rank " + - (input4D.rank + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in maxPoolBackprop: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad, dimRoundingMode); - var res = environment_1.ENV.engine.executeKernel('MaxPoolBackprop', { inputs: { dy: dy4D, x: input4D }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.minPool = function (input, filterSize, strides, pad, dimRoundingMode) { - var input4D = input; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - } - util.assert(input4D.rank === 4, "Error in minPool: x must be rank 4 but got rank " + input4D.rank + "."); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in minPool: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad, dimRoundingMode); - var res = environment_1.ENV.engine.executeKernel('MinPool', { inputs: { x: input4D }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.avgPool = function (x, filterSize, strides, pad, dimRoundingMode) { - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - util.assert(x4D.rank === 4, "Error in avgPool: x must be rank 4 but got rank " + x4D.rank + "."); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in avgPool: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(x4D.shape, filterSize, strides, pad); - var gradients = function (dy, y) { - return { x: function () { return Ops.avgPoolBackprop(dy, x4D, filterSize, strides, pad); } }; - }; - var res = environment_1.ENV.engine.executeKernel('AvgPool', { inputs: { x: x4D }, args: { convInfo: convInfo } }, gradients); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.avgPoolBackprop = function (dy, input, filterSize, strides, pad) { - util.assert(input.rank === dy.rank, "Rank of input (" + input.rank + ") does not match rank of dy (" + dy.rank + ")"); - var input4D = input; - var dy4D = dy; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - } - util.assert(dy4D.rank === 4, "Error in avgPoolBackprop: dy must be rank 4 but got rank " + - (dy4D.rank + ".")); - util.assert(input4D.rank === 4, "Error in avgPoolBackprop: input must be rank 4 but got rank " + - (input4D.rank + ".")); - var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad); - var res = environment_1.ENV.engine.executeKernel('AvgPoolBackprop', { inputs: { dy: dy4D, x: input4D }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "maxPool", null); - __decorate([ - operation_1.operation - ], Ops, "maxPoolBackprop", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "minPool", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "avgPool", null); - __decorate([ - operation_1.operation - ], Ops, "avgPoolBackprop", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./conv_util":115,"./operation":122}],125:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var MPRandGauss = (function () { - function MPRandGauss(mean, stdDeviation, dtype, truncated, seed) { - this.mean = mean; - this.stdDev = stdDeviation; - this.dtype = dtype; - this.nextVal = NaN; - this.truncated = truncated; - if (this.truncated) { - this.upper = this.mean + this.stdDev * 2; - this.lower = this.mean - this.stdDev * 2; - } - var seedValue = seed ? seed : Math.random(); - this.random = seedrandom.alea(seedValue.toString()); - } - MPRandGauss.prototype.nextValue = function () { - if (!isNaN(this.nextVal)) { - var value = this.nextVal; - this.nextVal = NaN; - return value; - } - var resultX, resultY; - var isValid = false; - while (!isValid) { - var v1 = void 0, v2 = void 0, s = void 0; - do { - v1 = 2 * this.random() - 1; - v2 = 2 * this.random() - 1; - s = v1 * v1 + v2 * v2; - } while (s >= 1 || s === 0); - var mul = Math.sqrt(-2.0 * Math.log(s) / s); - resultX = this.mean + this.stdDev * v1 * mul; - resultY = this.mean + this.stdDev * v2 * mul; - if (!this.truncated || this.isValidTruncated(resultX)) { - isValid = true; - } - } - if (!this.truncated || this.isValidTruncated(resultY)) { - this.nextVal = this.convertValue(resultY); - } - return this.convertValue(resultX); - }; - MPRandGauss.prototype.convertValue = function (value) { - if (this.dtype == null || this.dtype === 'float32') { - return value; - } - return Math.round(value); - }; - MPRandGauss.prototype.isValidTruncated = function (value) { - return value <= this.upper && value >= this.lower; - }; - return MPRandGauss; -}()); -exports.MPRandGauss = MPRandGauss; - -},{"seedrandom":153}],126:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.PARALLELIZE_THRESHOLD = 30; -function computeOptimalWindowSize(inSize) { - if (inSize <= exports.PARALLELIZE_THRESHOLD) { - return inSize; - } - return nearestDivisor(inSize, Math.floor(Math.sqrt(inSize))); -} -exports.computeOptimalWindowSize = computeOptimalWindowSize; -function nearestDivisor(size, start) { - for (var i = start; i < size; ++i) { - if (size % i === 0) { - return i; - } - } - return size; -} - -},{}],127:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.logSumExp = function (input, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, input.shape); - var xMax = input.max(axes, true); - var a = input.sub(xMax); - var b = a.exp(); - var c = b.sum(axes); - var d = c.log(); - var res = xMax.reshape(d.shape).add(d); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(res.shape, axes); - return res.reshape(newShape); - } - return res; - }; - Ops.sum = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var customOp = globals_1.customGrad(function (x) { - var permutation = axis_util.getAxesPermutation(axes, x.rank); - var reductionAxes = axes; - var permutedX = x; - if (permutation != null) { - permutedX = x.transpose(permutation); - reductionAxes = - axis_util.getInnerMostAxes(reductionAxes.length, x.rank); - } - var value = environment_1.ENV.engine.executeKernel('Sum', { inputs: { x: permutedX }, args: { axes: reductionAxes } }); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(value.shape, axes); - value = value.reshape(newShape); - } - var gradFunc = function (dy) { - var expandedDyShape = x.shape.slice(); - axes.forEach(function (axis) { - expandedDyShape[axis] = 1; - }); - var expandedDy = dy.reshape(expandedDyShape); - var derX = expandedDy.mul(tensor_1.Tensor.ones(x.shape, 'float32')); - return derX; - }; - return { value: value, gradFunc: gradFunc }; - }); - return customOp(x); - }; - Ops.mean = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var shapes = axis_util.computeOutAndReduceShapes(x.shape, axes); - var reduceShape = shapes[1]; - var reduceSize = util.sizeFromShape(reduceShape); - var customOp = globals_1.customGrad(function (x) { - var reduceSizeScalar = ops.scalar(reduceSize); - var res = x.div(reduceSizeScalar); - var value = res.sum(axis, keepDims); - var gradFunc = function (dy) { - var expandedDyShape = x.shape.slice(); - axes.forEach(function (axis) { - expandedDyShape[axis] = 1; - }); - var expandedDy = dy.reshape(expandedDyShape); - var derX = expandedDy.mul(tensor_1.Tensor.ones(x.shape, 'float32')) - .div(reduceSizeScalar); - return derX; - }; - return { value: value, gradFunc: gradFunc }; - }); - return customOp(x); - }; - Ops.min = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var origAxes = axis_util.parseAxisParam(axis, x.shape); - var axes = origAxes; - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - var res = environment_1.ENV.engine.executeKernel('Min', { inputs: { x: x }, args: { axes: axes } }); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes); - return res.reshape(newShape); - } - return res; - }; - Ops.max = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var origAxes = axis_util.parseAxisParam(axis, x.shape); - var axes = origAxes; - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - var res = environment_1.ENV.engine.executeKernel('Max', { inputs: { x: x }, args: { axes: axes } }); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes); - return res.reshape(newShape); - } - return res; - }; - Ops.argMin = function (x, axis) { - if (axis === void 0) { axis = null; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - return environment_1.ENV.engine.executeKernel('ArgMin', { inputs: { x: x }, args: { axes: axes } }); - }; - Ops.argMax = function (x, axis) { - if (axis === void 0) { axis = null; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - return environment_1.ENV.engine.executeKernel('ArgMax', { inputs: { x: x }, args: { axes: axes } }); - }; - Ops.moments = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var mean = x.mean(axes, keepDims); - var keepDimsShape = mean.shape; - if (!keepDims) { - keepDimsShape = axis_util.expandShapeToKeepDim(mean.shape, axes); - } - var devSquared = x.toFloat().sub(mean.reshape(keepDimsShape)).square(); - var variance = devSquared.mean(axes, keepDims); - return { mean: mean, variance: variance }; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "logSumExp", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "sum", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "mean", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "min", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "max", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "argMin", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "argMax", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }), - operation_1.operation - ], Ops, "moments", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../globals":35,"../tensor":146,"../util":151,"./axis_util":107,"./operation":122,"./ops":123}],128:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.reverse1d = function (x) { - util.assert(x.rank === 1, "Error in reverse1D: x must be rank 1 but got\n rank " + x.rank + "."); - return Ops.reverse(x, 0); - }; - Ops.reverse2d = function (x, axis) { - util.assert(x.rank === 2, "Error in reverse2D: x must be rank 2 but got\n rank " + x.rank + "."); - return Ops.reverse(x, axis); - }; - Ops.reverse3d = function (x, axis) { - util.assert(x.rank === 3, "Error in reverse3D: x must be rank 3 but got\n rank " + x.rank + "."); - return Ops.reverse(x, axis); - }; - Ops.reverse4d = function (x, axis) { - util.assert(x.rank === 4, "Error in reverse4D: x must be rank 4 but got\n rank " + x.rank + "."); - return Ops.reverse(x, axis); - }; - Ops.reverse = function (x, axis) { - var x4d; - var axisCleaned = axis_util.parseAxisParam(axis, x.shape).map(function (a) { return a + 4 - x.rank; }); - if (x.rank === 0) { - return x.clone(); - } - else if (x.rank === 1) { - x4d = x.as4D(1, 1, 1, x.shape[0]); - } - else if (x.rank === 2) { - x4d = x.as4D(1, 1, x.shape[0], x.shape[1]); - } - else if (x.rank === 3) { - x4d = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - else if (x.rank === 4) { - x4d = x; - } - else { - throw new Error("Reverse for rank " + x.rank + " is not yet implemented"); - } - var res = environment_1.ENV.engine.executeKernel('Reverse4D', { inputs: { x: x4d }, args: { axis: axisCleaned } }); - return res.reshapeAs(x); - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "reverse", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./axis_util":107,"./operation":122}],129:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SELU_SCALEALPHA = 1.7580993408473768599402175208123; -exports.SELU_SCALE = 1.0507009873554804934193349852946; - -},{}],130:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var operation_1 = require("./operation"); -var slice_util = require("./slice_util"); -var Ops = (function () { - function Ops() { - } - Ops.slice1d = function (x, begin, size) { - slice_util.assertParamsValid(x, [begin], [size]); - return environment_1.ENV.engine.executeKernel('Slice1D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice2d = function (x, begin, size) { - slice_util.assertParamsValid(x, begin, size); - return environment_1.ENV.engine.executeKernel('Slice2D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice3d = function (x, begin, size) { - slice_util.assertParamsValid(x, begin, size); - return environment_1.ENV.engine.executeKernel('Slice3D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice4d = function (x, begin, size) { - slice_util.assertParamsValid(x, begin, size); - return environment_1.ENV.engine.executeKernel('Slice4D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice = function (x, begin, size) { - if (x.rank === 0) { - throw new Error('Slicing scalar is not possible'); - } - else if (x.rank === 1) { - return Ops.slice1d(x, begin[0], size[0]); - } - else if (x.rank === 2) { - return Ops.slice2d(x, begin, size); - } - else if (x.rank === 3) { - return Ops.slice3d(x, begin, size); - } - else if (x.rank === 4) { - return Ops.slice4d(x, begin, size); - } - else { - throw new Error("Slicing for rank " + x.rank + " not implemented yet"); - } - }; - __decorate([ - operation_1.operation - ], Ops, "slice1d", null); - __decorate([ - operation_1.operation - ], Ops, "slice2d", null); - __decorate([ - operation_1.operation - ], Ops, "slice3d", null); - __decorate([ - operation_1.operation - ], Ops, "slice4d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "slice", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"./operation":122,"./slice_util":131}],131:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function assertParamsValid(input, begin, size) { - util.assert(input.rank === begin.length, "Error in slice" + input.rank + "D: Length of begin " + begin + " must " + - ("match the rank of the array (" + input.rank + ").")); - util.assert(input.rank === size.length, "Error in slice" + input.rank + "D: Length of size " + size + " must " + - ("match the rank of the array (" + input.rank + ").")); - for (var i = 0; i < input.rank; ++i) { - util.assert(begin[i] + size[i] <= input.shape[i], "Error in slice" + input.rank + "D: begin[" + i + "] + size[" + i + "] " + - ("(" + (begin[i] + size[i]) + ") would overflow input.shape[" + i + "] (" + input.shape[i] + ")")); - } -} -exports.assertParamsValid = assertParamsValid; - -},{"../util":151}],132:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var globals_1 = require("../globals"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.softmax = function (logits, dim) { - if (dim === void 0) { dim = -1; } - if (dim === -1) { - dim = logits.rank - 1; - } - if (dim !== logits.rank - 1) { - throw Error('Softmax along a non-last dimension is not yet supported. ' + - ("Logits was rank " + logits.rank + " and dim was " + dim)); - } - var customOp = globals_1.customGrad(function (logits) { - var keepDims = true; - var lse = logits.logSumExp([dim], keepDims); - var logResult = logits.toFloat().sub(lse); - var y = logResult.exp(); - var gradFunc = function (dy) { - var dyTimesY = dy.mul(y); - var keepDims = true; - return dyTimesY.sub(dyTimesY.sum([dim], keepDims).mul(y)); - }; - return { value: y, gradFunc: gradFunc }; - }); - return customOp(logits); - }; - Ops.softmaxCrossEntropy = function (labels, logits, dim) { - if (dim === void 0) { dim = -1; } - util.assertShapesMatch(labels.shape, logits.shape, 'Error in softmaxCrossEntropy: '); - if (dim === -1) { - dim = logits.rank - 1; - } - if (dim !== logits.rank - 1) { - throw Error("Softmax cross entropy along a non-last dimension is not yet " + - ("supported. Labels / logits was rank " + logits.rank + " ") + - ("and dim was " + dim)); - } - var customOp = globals_1.customGrad(function (labels, logits) { - var predictedProbs = logits.softmax(dim); - var costVector = ops.scalar(1e-5).add(predictedProbs).log().mul(labels).neg(); - var value = costVector.sum([dim]); - var gradFunc = function (dy) { - var dyShape = axis_util.expandShapeToKeepDim(dy.shape, [dim]); - return [ - dy.reshape(dyShape).mul(labels.toFloat().sub(predictedProbs)), - dy.reshape(dyShape).mul(predictedProbs.sub(labels.toFloat())), - ]; - }; - return { value: value, gradFunc: gradFunc }; - }); - return customOp(labels, logits); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }), - operation_1.operation - ], Ops, "softmax", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }), - operation_1.operation - ], Ops, "softmaxCrossEntropy", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../globals":35,"../util":151,"./axis_util":107,"./operation":122,"./ops":123}],133:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.transpose = function (x, perm) { - if (perm == null) { - perm = x.shape.map(function (s, i) { return i; }).reverse(); - } - var der = function (dy) { - var undoPerm = axis_util.getUndoAxesPermutation(perm); - var derX = function () { return dy.transpose(undoPerm); }; - return { x: derX }; - }; - util.assert(x.rank === perm.length, "Error in transpose: rank of input " + x.rank + " " + - ("must match length of perm " + perm + ".")); - return environment_1.ENV.engine.executeKernel('Transpose', { inputs: { x: x }, args: { perm: perm } }, der); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "transpose", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./axis_util":107,"./operation":122}],134:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var ops_1 = require("./ops"); -var selu_util = require("./selu_util"); -var Ops = (function () { - function Ops() { - } - Ops.neg = function (x) { - return environment_1.ENV.engine.executeKernel('Neg', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.neg(); } }; - }); - }; - Ops.ceil = function (x) { - var gradient = function (dy, y) { - return { x: function () { return ops.zeros(y.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Ceil', { inputs: { x: x } }, gradient); - }; - Ops.floor = function (x) { - var gradient = function (dy, y) { - return { x: function () { return ops.zeros(y.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Floor', { inputs: { x: x } }, gradient); - }; - Ops.exp = function (x) { - return environment_1.ENV.engine.executeKernel('Exp', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(y); } }; - }); - }; - Ops.log = function (x) { - return environment_1.ENV.engine.executeKernel('Log', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(x.toFloat()); } }; - }); - }; - Ops.sqrt = function (x) { - return environment_1.ENV.engine.executeKernel('Sqrt', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(x.toFloat().sqrt().mul(ops.scalar(2))); } }; - }); - }; - Ops.square = function (x) { - return environment_1.ENV.engine.executeKernel('Square', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(x.toFloat().mul(ops.scalar(2))); } }; - }); - }; - Ops.abs = function (x) { - return environment_1.ENV.engine.executeKernel('Abs', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(x.toFloat().step(-1)); } }; - }); - }; - Ops.clipByValue = function (x, clipValueMin, clipValueMax) { - util.assert((clipValueMin <= clipValueMax), "Error in clip: min (" + clipValueMin + ") must be" + - ("less than or equal to max (" + clipValueMax + ").")); - return environment_1.ENV.engine.executeKernel('Clip', { inputs: { x: x }, args: { min: clipValueMin, max: clipValueMax } }, function (dy, y) { - return { - x: function () { return dy.where(x.greater(ops.scalar(clipValueMin)) - .logicalAnd(x.less(ops.scalar(clipValueMax))), ops_1.zerosLike(dy)); }, - }; - }); - }; - Ops.relu = function (x) { - return environment_1.ENV.engine.executeKernel('Relu', { inputs: { x: x } }, function (dy, y) { - var stepRes = x.step(); - return { x: function () { return dy.mul(stepRes.toFloat()); } }; - }); - }; - Ops.elu = function (x) { - var der = function (dy) { - return { - x: function () { return dy.mul(eluDer(x)); }, - alpha: function () { - throw new Error('Derivative of prelu with respect to alpha is ' + - 'not implemented yet'); - } - }; - }; - return environment_1.ENV.engine.executeKernel('Elu', { inputs: { x: x } }, der); - }; - Ops.selu = function (x) { - var gradient = function (dy, y) { - return { - x: function () { - var mask = x.greater(ops.scalar(0)); - var scaleAlpha = ops.scalar(selu_util.SELU_SCALEALPHA); - var scale = ops.scalar(selu_util.SELU_SCALE); - var greaterThanZeroDer = dy.mul(scale); - var lessEqualZeroDer = dy.mul(scaleAlpha).mul(x.toFloat().exp()); - var res = ops.where(mask, greaterThanZeroDer, lessEqualZeroDer); - return res; - } - }; - }; - return environment_1.ENV.engine.executeKernel('Selu', { inputs: { x: x } }, gradient); - }; - Ops.leakyRelu = function (x, alpha) { - if (alpha === void 0) { alpha = 0.2; } - var gradient = function (dy, y) { - return { x: function () { return dy.mul(x.step(alpha)); } }; - }; - return environment_1.ENV.engine.executeKernel('LeakyRelu', { inputs: { x: x }, args: { alpha: alpha } }, gradient); - }; - Ops.prelu = function (x, alpha) { - var der = function (dy) { - return { - x: function () { return dy.mul(preluDer(x, alpha)); }, - alpha: function () { - throw new Error('Derivative of prelu with respect to alpha is ' + - 'not implemented yet'); - } - }; - }; - return environment_1.ENV.engine.executeKernel('PReLU', { inputs: { x: x, alpha: alpha } }, der); - }; - Ops.sigmoid = function (x) { - return environment_1.ENV.engine.executeKernel('Sigmoid', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(y.mul(ops.scalar(1).sub(y))); } }; - }); - }; - Ops.sin = function (x) { - return environment_1.ENV.engine.executeKernel('Sin', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().cos().mul(dy); } }; - }); - }; - Ops.cos = function (x) { - return environment_1.ENV.engine.executeKernel('Cos', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().sin().neg().mul(dy); } }; - }); - }; - Ops.tan = function (x) { - return environment_1.ENV.engine.executeKernel('Tan', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(x.cos().square()); } }; - }); - }; - Ops.asin = function (x) { - return environment_1.ENV.engine.executeKernel('Asin', { inputs: { x: x } }, function (dy, y) { - return { - x: function () { return dy.div(Ops.sqrt(ops.scalar(1).sub(x.toFloat().square()))); } - }; - }); - }; - Ops.acos = function (x) { - return environment_1.ENV.engine.executeKernel('Acos', { inputs: { x: x } }, function (dy, y) { - return { - x: function () { return dy.div(Ops.sqrt(ops.scalar(1).sub(x.toFloat().square()))).neg(); } - }; - }); - }; - Ops.atan = function (x) { - return environment_1.ENV.engine.executeKernel('Atan', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(ops.scalar(1).add(x.toFloat().square())); } }; - }); - }; - Ops.sinh = function (x) { - return environment_1.ENV.engine.executeKernel('Sinh', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().cosh().mul(dy); } }; - }); - }; - Ops.cosh = function (x) { - return environment_1.ENV.engine.executeKernel('Cosh', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().sinh().mul(dy); } }; - }); - }; - Ops.tanh = function (x) { - return environment_1.ENV.engine.executeKernel('Tanh', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return ops.scalar(1).sub(y.square()).mul(dy); } }; - }); - }; - Ops.step = function (x, alpha) { - if (alpha === void 0) { alpha = 0.0; } - return environment_1.ENV.engine.executeKernel('Step', { inputs: { x: x }, args: { alpha: alpha } }, function (dy, y) { - return { x: function () { return ops.zeros(y.shape); } }; - }); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "neg", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "ceil", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "floor", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "exp", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "log", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sqrt", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "square", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "abs", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "clipByValue", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "relu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "elu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "selu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "leakyRelu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "prelu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sigmoid", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sin", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "cos", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "tan", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "asin", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "acos", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "atan", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sinh", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "cosh", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "tanh", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "step", null); - return Ops; -}()); -exports.Ops = Ops; -function preluDer(x, alpha) { - return environment_1.ENV.engine.executeKernel('PReLUDer', { inputs: { x: x, alpha: alpha } }); -} -function eluDer(x) { - return environment_1.ENV.engine.executeKernel('EluDer', { inputs: { x: x } }); -} - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122,"./ops":123,"./selu_util":129}],135:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdadeltaOptimizer = (function (_super) { - __extends(AdadeltaOptimizer, _super); - function AdadeltaOptimizer(learningRate, rho, specifiedVariableList, epsilon) { - if (epsilon === void 0) { epsilon = 1e-8; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.accumulatedGrads = {}; - _this.accumulatedUpdates = {}; - _this.accumulatedSquaredGradientsGraph = new tensor_array_map_1.TensorArrayMap(); - _this.accumulatedUpdatesGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.epsilon = globals_1.keep(ops_1.scalar(epsilon)); - _this.rho = globals_1.keep(ops_1.scalar(rho)); - _this.oneMinusRho = globals_1.keep(ops_1.scalar(1 - rho)); - return _this; - } - AdadeltaOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulatedGrads[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulatedGrads[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_1); - }); - } - if (this_1.accumulatedUpdates[variableName] == null) { - var trainable_2 = false; - globals_1.tidy(function () { - _this.accumulatedUpdates[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_2); - }); - } - var gradient = variableGradients[variableName]; - var accumulatedGrad = this_1.accumulatedGrads[variableName]; - var accumulatedUpdate = this_1.accumulatedUpdates[variableName]; - globals_1.tidy(function () { - var newAccumulatedGrad = _this.rho.mul(accumulatedGrad) - .add(_this.oneMinusRho.mul(gradient.square())); - var updates = accumulatedUpdate.add(_this.epsilon) - .sqrt() - .div(accumulatedGrad.add(_this.epsilon).sqrt()) - .mul(gradient); - var newAccumulatedUpdate = _this.rho.mul(accumulatedUpdate) - .add(_this.oneMinusRho.mul(updates.square())); - _this.accumulatedGrads[variableName].assign(newAccumulatedGrad); - _this.accumulatedUpdates[variableName].assign(newAccumulatedUpdate); - var newValue = _this.c.mul(updates).add(value); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - AdadeltaOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.accumulatedSquaredGradientsGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.accumulatedSquaredGradientsGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - _this.accumulatedUpdatesGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdadeltaOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldCache = _this.accumulatedSquaredGradientsGraph.get(node.output); - var oldUpdates = _this.accumulatedUpdatesGraph.get(node.output); - var gradientSquare = math.multiply(gradient, gradient); - var cache = math.scaledArrayAdd(_this.rho, oldCache, math.subtract(_this.one, _this.rho), gradientSquare); - var updates = math.multiply(math.divide(math.sqrt(math.add(oldUpdates, _this.epsilon)), math.sqrt(math.add(oldCache, _this.epsilon))), gradient); - var variable = math.scaledArrayAdd(_this.cGraph, updates, _this.one, oldVariable); - var updateSquare = math.multiply(updates, updates); - var newUpdates = math.scaledArrayAdd(_this.rho, oldUpdates, math.subtract(_this.one, _this.rho), updateSquare); - _this.accumulatedSquaredGradientsGraph.set(node.output, globals_1.keep(cache)); - _this.accumulatedUpdatesGraph.set(node.output, globals_1.keep(newUpdates)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldCache.dispose(); - oldUpdates.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdadeltaOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.epsilon.dispose(); - this.rho.dispose(); - this.oneMinusRho.dispose(); - if (this.one != null) { - this.one.dispose(); - } - if (this.accumulatedSquaredGradientsGraph != null) { - this.accumulatedSquaredGradientsGraph.dispose(); - } - if (this.accumulatedUpdatesGraph != null) { - this.accumulatedUpdatesGraph.dispose(); - } - if (this.accumulatedUpdates != null) { - Object.keys(this.accumulatedUpdates) - .forEach(function (name) { return _this.accumulatedUpdates[name].dispose(); }); - Object.keys(this.accumulatedGrads) - .forEach(function (name) { return _this.accumulatedGrads[name].dispose(); }); - } - }; - return AdadeltaOptimizer; -}(optimizer_1.Optimizer)); -exports.AdadeltaOptimizer = AdadeltaOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],136:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdagradOptimizer = (function (_super) { - __extends(AdagradOptimizer, _super); - function AdagradOptimizer(learningRate, specifiedVariableList, initialAccumulatorValue) { - if (initialAccumulatorValue === void 0) { initialAccumulatorValue = 0.1; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.initialAccumulatorValue = initialAccumulatorValue; - _this.accumulatedGrads = {}; - _this.accumulatedSquaredGradients = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.epsilon = globals_1.keep(ops_1.scalar(1e-8)); - return _this; - } - AdagradOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulatedGrads[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulatedGrads[variableName] = tensor_2.variable(ops_1.fill(value.shape, _this.initialAccumulatorValue), trainable_1); - }); - } - var gradient = variableGradients[variableName]; - var accumulatedGrad = this_1.accumulatedGrads[variableName]; - globals_1.tidy(function () { - var newAccumulatedGrad = accumulatedGrad.add(gradient.square()); - _this.accumulatedGrads[variableName].assign(newAccumulatedGrad); - var newValue = _this.c - .mul(gradient.div(newAccumulatedGrad.add(_this.epsilon).sqrt())) - .add(value); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - AdagradOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.accumulatedSquaredGradients.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.accumulatedSquaredGradients.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdagradOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldCache = _this.accumulatedSquaredGradients.get(node.output); - var gradientSquare = math.multiply(gradient, gradient); - var cache = math.add(oldCache, gradientSquare); - var variable = math.scaledArrayAdd(_this.cGraph, math.divide(gradient, math.add(math.sqrt(cache), _this.epsilon)), _this.one, oldVariable); - _this.accumulatedSquaredGradients.set(node.output, globals_1.keep(cache)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldCache.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdagradOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.epsilon.dispose(); - this.c.dispose(); - if (this.one != null) { - this.one.dispose(); - } - if (this.accumulatedSquaredGradients != null) { - this.accumulatedSquaredGradients.dispose(); - } - if (this.accumulatedGrads != null) { - Object.keys(this.accumulatedGrads) - .forEach(function (name) { return _this.accumulatedGrads[name].dispose(); }); - } - }; - return AdagradOptimizer; -}(optimizer_1.Optimizer)); -exports.AdagradOptimizer = AdagradOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],137:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdamOptimizer = (function (_super) { - __extends(AdamOptimizer, _super); - function AdamOptimizer(learningRate, beta1, beta2, epsilon, specifiedVariableList) { - if (epsilon === void 0) { epsilon = 1e-8; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.accumulatedFirstMoment = {}; - _this.accumulatedSecondMoment = {}; - _this.firstMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.secondMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.eps = globals_1.keep(ops_1.scalar(epsilon)); - _this.beta1 = globals_1.keep(ops_1.scalar(beta1)); - _this.beta2 = globals_1.keep(ops_1.scalar(beta2)); - globals_1.tidy(function () { - _this.accBeta1 = tensor_2.variable(ops_1.scalar(beta1)); - _this.accBeta2 = tensor_2.variable(ops_1.scalar(beta2)); - }); - _this.oneMinusBeta1 = globals_1.keep(ops_1.scalar(1 - beta1)); - _this.oneMinusBeta2 = globals_1.keep(ops_1.scalar(1 - beta2)); - _this.one = globals_1.keep(ops_1.scalar(1)); - return _this; - } - AdamOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - globals_1.tidy(function () { - var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1); - var oneMinusAccBeta2 = _this.one.sub(_this.accBeta2); - for (var variableName in variableGradients) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (_this.accumulatedFirstMoment[variableName] == null) { - var trainable = false; - _this.accumulatedFirstMoment[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - if (_this.accumulatedSecondMoment[variableName] == null) { - var trainable = false; - _this.accumulatedSecondMoment[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - var gradient = variableGradients[variableName]; - var firstMoment = _this.accumulatedFirstMoment[variableName]; - var secondMoment = _this.accumulatedSecondMoment[variableName]; - var newFirstMoment = _this.beta1.mul(firstMoment).add(_this.oneMinusBeta1.mul(gradient)); - var newSecondMoment = _this.beta2.mul(secondMoment) - .add(_this.oneMinusBeta2.mul(gradient.square())); - var biasCorrectedFirstMoment = newFirstMoment.div(oneMinusAccBeta1); - var biasCorrectedSecondMoment = newSecondMoment.div(oneMinusAccBeta2); - _this.accumulatedFirstMoment[variableName].assign(newFirstMoment); - _this.accumulatedSecondMoment[variableName].assign(newSecondMoment); - var newValue = _this.c - .mul(biasCorrectedFirstMoment.div(_this.eps.add(biasCorrectedSecondMoment.sqrt()))) - .add(value); - value.assign(newValue); - } - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - _this.accBeta2.assign(_this.accBeta2.mul(_this.beta2)); - }); - }; - AdamOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.firstMomentGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.firstMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - if (this.secondMomentGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.secondMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdamOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1); - var oneMinusAccBeta2 = _this.one.sub(_this.accBeta2); - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldFirstMoment = _this.firstMomentGraph.get(node.output); - var oldSecondMoment = _this.secondMomentGraph.get(node.output); - var newFirstMoment = math.scaledArrayAdd(_this.beta1, oldFirstMoment, _this.oneMinusBeta1, gradient); - var newSecondMoment = math.scaledArrayAdd(_this.beta2, oldSecondMoment, _this.oneMinusBeta2, gradient.square()); - var biasCorrectedFirstMoment = newFirstMoment.div(oneMinusAccBeta1); - var biasCorrectedSecondMoment = newSecondMoment.div(oneMinusAccBeta2); - var variable = math.scaledArrayAdd(_this.cGraph, biasCorrectedFirstMoment.div(_this.eps.add(biasCorrectedSecondMoment.sqrt())), _this.one, oldVariable); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - _this.firstMomentGraph.set(node.output, globals_1.keep(newFirstMoment)); - _this.secondMomentGraph.set(node.output, globals_1.keep(newSecondMoment)); - oldVariable.dispose(); - gradient.dispose(); - oldFirstMoment.dispose(); - oldSecondMoment.dispose(); - }); - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - _this.accBeta2.assign(_this.accBeta2.mul(_this.beta2)); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdamOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.eps.dispose(); - this.beta1.dispose(); - this.beta2.dispose(); - this.accBeta1.dispose(); - this.accBeta2.dispose(); - this.oneMinusBeta1.dispose(); - this.oneMinusBeta2.dispose(); - this.one.dispose(); - if (this.firstMomentGraph != null) { - this.firstMomentGraph.dispose(); - } - if (this.secondMomentGraph != null) { - this.secondMomentGraph.dispose(); - } - if (this.accumulatedFirstMoment != null) { - Object.keys(this.accumulatedFirstMoment) - .forEach(function (name) { return _this.accumulatedFirstMoment[name].dispose(); }); - } - if (this.accumulatedSecondMoment != null) { - Object.keys(this.accumulatedSecondMoment) - .forEach(function (name) { return _this.accumulatedSecondMoment[name].dispose(); }); - } - }; - return AdamOptimizer; -}(optimizer_1.Optimizer)); -exports.AdamOptimizer = AdamOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],138:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdamaxOptimizer = (function (_super) { - __extends(AdamaxOptimizer, _super); - function AdamaxOptimizer(learningRate, beta1, beta2, epsilon, decay, specifiedVariableList) { - if (epsilon === void 0) { epsilon = 1e-8; } - if (decay === void 0) { decay = 0.0; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.accumulatedFirstMoment = {}; - _this.accumulatedWeightedInfNorm = {}; - _this.firstMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.weightedInfNormGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.eps = globals_1.keep(ops_1.scalar(epsilon)); - _this.beta1 = globals_1.keep(ops_1.scalar(beta1)); - _this.beta2 = globals_1.keep(ops_1.scalar(beta2)); - _this.decay = globals_1.keep(ops_1.scalar(decay)); - globals_1.tidy(function () { - _this.iteration = tensor_2.variable(ops_1.scalar(0)); - _this.accBeta1 = tensor_2.variable(ops_1.scalar(beta1)); - }); - _this.oneMinusBeta1 = globals_1.keep(ops_1.scalar(1 - beta1)); - _this.one = globals_1.keep(ops_1.scalar(1)); - return _this; - } - AdamaxOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - globals_1.tidy(function () { - var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1); - var lr = _this.c.div(_this.one.add(_this.decay.mul(_this.iteration))); - for (var variableName in variableGradients) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (_this.accumulatedFirstMoment[variableName] == null) { - var trainable = false; - _this.accumulatedFirstMoment[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - if (_this.accumulatedWeightedInfNorm[variableName] == null) { - var trainable = false; - _this.accumulatedWeightedInfNorm[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - var gradient = variableGradients[variableName]; - var firstMoment = _this.accumulatedFirstMoment[variableName]; - var weightedInfNorm = _this.accumulatedWeightedInfNorm[variableName]; - var newFirstMoment = _this.beta1.mul(firstMoment).add(_this.oneMinusBeta1.mul(gradient)); - var ut0 = _this.beta2.mul(weightedInfNorm); - var ut1 = gradient.abs(); - var newWeightedInfNorm = ut0.maximum(ut1); - _this.accumulatedFirstMoment[variableName].assign(newFirstMoment); - _this.accumulatedWeightedInfNorm[variableName].assign(newWeightedInfNorm); - var newValue = lr.div(oneMinusAccBeta1) - .mul(newFirstMoment.div(_this.eps.add(newWeightedInfNorm))) - .add(value); - value.assign(newValue); - } - _this.iteration.assign(_this.iteration.add(_this.one)); - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - }); - }; - AdamaxOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.firstMomentGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.firstMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - if (this.weightedInfNormGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.weightedInfNormGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdamaxOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - var lr = _this.cGraph.div(_this.one.add(_this.decay.mul(_this.iteration))); - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldFirstMoment = _this.firstMomentGraph.get(node.output); - var oldWeightedInfNorm = _this.weightedInfNormGraph.get(node.output); - var newFirstMoment = math.scaledArrayAdd(_this.beta1, oldFirstMoment, _this.oneMinusBeta1, gradient); - var ut0 = _this.beta2.mul(oldWeightedInfNorm); - var ut1 = gradient.abs(); - var newWeightedInfNorm = ut0.maximum(ut1); - var variable = math.scaledArrayAdd(_this.one, oldVariable, lr.div(_this.one.sub(_this.accBeta1)), newFirstMoment.div(_this.eps.add(newWeightedInfNorm))); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - _this.firstMomentGraph.set(node.output, globals_1.keep(newFirstMoment)); - _this.weightedInfNormGraph.set(node.output, globals_1.keep(newWeightedInfNorm)); - oldVariable.dispose(); - gradient.dispose(); - oldFirstMoment.dispose(); - oldWeightedInfNorm.dispose(); - }); - _this.iteration.assign(_this.iteration.add(_this.one)); - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdamaxOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.eps.dispose(); - this.accBeta1.dispose(); - this.beta1.dispose(); - this.beta2.dispose(); - this.oneMinusBeta1.dispose(); - this.decay.dispose(); - this.iteration.dispose(); - this.one.dispose(); - if (this.firstMomentGraph != null) { - this.firstMomentGraph.dispose(); - } - if (this.weightedInfNormGraph != null) { - this.weightedInfNormGraph.dispose(); - } - if (this.accumulatedFirstMoment != null) { - Object.keys(this.accumulatedFirstMoment) - .forEach(function (name) { return _this.accumulatedFirstMoment[name].dispose(); }); - } - if (this.accumulatedWeightedInfNorm != null) { - Object.keys(this.accumulatedWeightedInfNorm) - .forEach(function (name) { return _this.accumulatedWeightedInfNorm[name].dispose(); }); - } - }; - return AdamaxOptimizer; -}(optimizer_1.Optimizer)); -exports.AdamaxOptimizer = AdamaxOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],139:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var sgd_optimizer_1 = require("./sgd_optimizer"); -var MomentumOptimizer = (function (_super) { - __extends(MomentumOptimizer, _super); - function MomentumOptimizer(learningRate, momentum, specifiedVariableList) { - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.momentum = momentum; - _this.m = ops_1.scalar(_this.momentum); - _this.accumulations = {}; - return _this; - } - MomentumOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulations[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulations[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_1); - }); - } - var accumulation = this_1.accumulations[variableName]; - var gradient = variableGradients[variableName]; - globals_1.tidy(function () { - var newAccumulation = _this.m.mul(accumulation).add(gradient); - _this.accumulations[variableName].assign(newAccumulation); - var newValue = _this.c.mul(newAccumulation).add(value); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - MomentumOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.variableVelocitiesGraph == null) { - this.variableVelocitiesGraph = new tensor_array_map_1.TensorArrayMap(); - } - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.variableVelocitiesGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.variableVelocitiesGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - MomentumOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldVelocity = _this.variableVelocitiesGraph.get(node.output); - var velocity = math.scaledArrayAdd(_this.m, oldVelocity, _this.one, gradient); - var variable = math.scaledArrayAdd(_this.cGraph, velocity, _this.one, oldVariable); - _this.variableVelocitiesGraph.set(node.output, globals_1.keep(velocity)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldVelocity.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - MomentumOptimizer.prototype.dispose = function () { - _super.prototype.dispose.call(this); - this.m.dispose(); - if (this.one != null) { - this.one.dispose(); - } - if (this.variableVelocitiesGraph != null) { - this.variableVelocitiesGraph.dispose(); - } - if (this.accumulations != null) { - for (var variableName in this.accumulations) { - this.accumulations[variableName].dispose(); - } - } - }; - MomentumOptimizer.prototype.setMomentum = function (momentum) { - this.momentum = momentum; - }; - return MomentumOptimizer; -}(sgd_optimizer_1.SGDOptimizer)); -exports.MomentumOptimizer = MomentumOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./sgd_optimizer":143}],140:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var globals_1 = require("../globals"); -var session_util = require("../graph/session_util"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var Optimizer = (function () { - function Optimizer(learningRate, specifiedVariableList) { - this.learningRate = learningRate; - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - if (specifiedVariableList != null) { - this.specifiedVariableNodes = specifiedVariableList; - } - } - Optimizer.prototype.minimize = function (f, returnCost, varList) { - if (returnCost === void 0) { returnCost = false; } - var _a = this.computeGradients(f, varList), value = _a.value, grads = _a.grads; - this.applyGradients(grads); - var varNames = Object.keys(grads); - varNames.forEach(function (varName) { return grads[varName].dispose(); }); - if (returnCost) { - return value; - } - else { - value.dispose(); - return null; - } - }; - Optimizer.prototype.computeGradients = function (f, varList) { - return globals_1.variableGrads(f, varList); - }; - Optimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - this.variableNodes = this.specifiedVariableNodes == null ? - session_util.getVariableNodesFromEvaluationSet(runtime.nodes) : - this.specifiedVariableNodes; - if (batchSize !== this.prevBatchSize) { - if (this.cGraph != null) { - this.cGraph.dispose(); - } - this.prevBatchSize = batchSize; - this.cGraph = math.keep(ops.scalar(-this.learningRate / batchSize)); - } - this.variableNodes.forEach(function (node) { return _this.variableGradients.set(node.output, math.keep(tensor_1.Tensor.zeros(node.output.shape))); }); - }; - Optimizer.prototype.afterExample = function (math, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var gradient = gradientArrayMap.get(node.output); - var accumulatedGradient = _this.variableGradients.get(node.output); - _this.variableGradients.set(node.output, globals_1.keep(math.add(gradient, accumulatedGradient))); - accumulatedGradient.dispose(); - }); - }); - }; - Optimizer.prototype.dispose = function () { - if (this.cGraph != null) { - this.cGraph.dispose(); - } - if (this.variableNodes != null) { - this.variableNodes.forEach(function (node) { - node.data.dispose(); - }); - } - if (this.specifiedVariableNodes != null) { - this.specifiedVariableNodes.forEach(function (node) { - node.data.dispose(); - }); - } - }; - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers' }) - ], Optimizer.prototype, "minimize", null); - Optimizer = __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Classes', namespace: 'train' }) - ], Optimizer); - return Optimizer; -}()); -exports.Optimizer = Optimizer; - -},{"../doc":32,"../globals":35,"../graph/session_util":65,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146}],141:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var adadelta_optimizer_1 = require("./adadelta_optimizer"); -var adagrad_optimizer_1 = require("./adagrad_optimizer"); -var adam_optimizer_1 = require("./adam_optimizer"); -var adamax_optimizer_1 = require("./adamax_optimizer"); -var momentum_optimizer_1 = require("./momentum_optimizer"); -var rmsprop_optimizer_1 = require("./rmsprop_optimizer"); -var sgd_optimizer_1 = require("./sgd_optimizer"); -var OptimizerConstructors = (function () { - function OptimizerConstructors() { - } - OptimizerConstructors.sgd = function (learningRate) { - return new sgd_optimizer_1.SGDOptimizer(learningRate); - }; - OptimizerConstructors.momentum = function (learningRate, momentum) { - return new momentum_optimizer_1.MomentumOptimizer(learningRate, momentum); - }; - OptimizerConstructors.rmsprop = function (learningRate, decay, momentum, epsilon) { - if (decay === void 0) { decay = .9; } - if (momentum === void 0) { momentum = 0.0; } - if (epsilon === void 0) { epsilon = 1e-8; } - return new rmsprop_optimizer_1.RMSPropOptimizer(learningRate, decay, momentum, undefined, epsilon); - }; - OptimizerConstructors.adam = function (learningRate, beta1, beta2, epsilon) { - if (learningRate === void 0) { learningRate = 0.001; } - if (beta1 === void 0) { beta1 = 0.9; } - if (beta2 === void 0) { beta2 = 0.999; } - if (epsilon === void 0) { epsilon = 1e-8; } - return new adam_optimizer_1.AdamOptimizer(learningRate, beta1, beta2, epsilon, undefined); - }; - OptimizerConstructors.adadelta = function (learningRate, rho, epsilon) { - if (learningRate === void 0) { learningRate = .001; } - if (rho === void 0) { rho = .95; } - if (epsilon === void 0) { epsilon = 1e-8; } - return new adadelta_optimizer_1.AdadeltaOptimizer(learningRate, rho, undefined, epsilon); - }; - OptimizerConstructors.adamax = function (learningRate, beta1, beta2, epsilon, decay) { - if (learningRate === void 0) { learningRate = 0.002; } - if (beta1 === void 0) { beta1 = 0.9; } - if (beta2 === void 0) { beta2 = 0.999; } - if (epsilon === void 0) { epsilon = 1e-8; } - if (decay === void 0) { decay = 0.0; } - return new adamax_optimizer_1.AdamaxOptimizer(learningRate, beta1, beta2, epsilon, decay, undefined); - }; - OptimizerConstructors.adagrad = function (learningRate, initialAccumulatorValue) { - if (initialAccumulatorValue === void 0) { initialAccumulatorValue = 0.1; } - return new adagrad_optimizer_1.AdagradOptimizer(learningRate, undefined, initialAccumulatorValue); - }; - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "sgd", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "momentum", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "rmsprop", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adam", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adadelta", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adamax", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adagrad", null); - return OptimizerConstructors; -}()); -exports.OptimizerConstructors = OptimizerConstructors; - -},{"../doc":32,"./adadelta_optimizer":135,"./adagrad_optimizer":136,"./adam_optimizer":137,"./adamax_optimizer":138,"./momentum_optimizer":139,"./rmsprop_optimizer":142,"./sgd_optimizer":143}],142:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var session_util = require("../graph/session_util"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var RMSPropOptimizer = (function (_super) { - __extends(RMSPropOptimizer, _super); - function RMSPropOptimizer(learningRate, decay, momentum, specifiedVariableList, epsilon) { - if (decay === void 0) { decay = 0.9; } - if (momentum === void 0) { momentum = 0.0; } - if (epsilon === void 0) { epsilon = 1e-8; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.accumulatedMeanSquares = {}; - _this.accumulatedMoments = {}; - _this.accumulatedMeanSquaredGraph = new tensor_array_map_1.TensorArrayMap(); - _this.accumulatedMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(learningRate)); - _this.epsilon = globals_1.keep(ops_1.scalar(epsilon)); - _this.decay = globals_1.keep(ops_1.scalar(decay)); - _this.momentum = globals_1.keep(ops_1.scalar(momentum)); - _this.oneMinusDecay = globals_1.keep(ops_1.scalar(1 - decay)); - return _this; - } - RMSPropOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulatedMeanSquares[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulatedMeanSquares[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_1); - }); - } - if (this_1.accumulatedMoments[variableName] == null) { - var trainable_2 = false; - globals_1.tidy(function () { - _this.accumulatedMoments[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_2); - }); - } - var accumulatedMeanSquare = this_1.accumulatedMeanSquares[variableName]; - var accumulatedMoments = this_1.accumulatedMoments[variableName]; - var gradient = variableGradients[variableName]; - globals_1.tidy(function () { - var newAccumulatedMeanSquare = _this.decay.mul(accumulatedMeanSquare) - .add(_this.oneMinusDecay.mul(gradient.square())); - var newAccumulatedMoments = _this.momentum.mul(accumulatedMoments) - .add(_this.c.mul(gradient).div(newAccumulatedMeanSquare.add(_this.epsilon).sqrt())); - _this.accumulatedMeanSquares[variableName].assign(newAccumulatedMeanSquare); - _this.accumulatedMoments[variableName].assign(newAccumulatedMoments); - var newValue = value.sub(newAccumulatedMoments); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - RMSPropOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - this.variableNodes = this.specifiedVariableNodes == null ? - session_util.getVariableNodesFromEvaluationSet(runtime.nodes) : - this.specifiedVariableNodes; - if (batchSize !== this.prevBatchSize) { - if (this.cGraph != null) { - this.cGraph.dispose(); - } - this.prevBatchSize = batchSize; - this.cGraph = math.keep(ops_1.scalar(this.learningRate / batchSize)); - } - this.variableNodes.forEach(function (node) { return _this.variableGradients.set(node.output, math.keep(tensor_1.Tensor.zeros(node.output.shape))); }); - if (this.accumulatedMeanSquaredGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.accumulatedMeanSquaredGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - _this.accumulatedMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - RMSPropOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldMeanSquare = _this.accumulatedMeanSquaredGraph.get(node.output); - var oldMoment = _this.accumulatedMomentGraph.get(node.output); - var meanSquare = math.scaledArrayAdd(_this.decay, oldMeanSquare, _this.oneMinusDecay, gradient.square()); - var moment = math.scaledArrayAdd(_this.momentum, oldMoment, _this.cGraph, gradient.div(meanSquare.add(_this.epsilon).sqrt())); - var variable = oldVariable.sub(moment); - _this.accumulatedMeanSquaredGraph.set(node.output, globals_1.keep(meanSquare)); - _this.accumulatedMomentGraph.set(node.output, globals_1.keep(moment)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldMeanSquare.dispose(); - oldMoment.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - RMSPropOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.epsilon.dispose(); - this.decay.dispose(); - this.momentum.dispose(); - this.oneMinusDecay.dispose(); - if (this.accumulatedMeanSquaredGraph != null) { - this.accumulatedMeanSquaredGraph.dispose(); - } - if (this.accumulatedMomentGraph != null) { - this.accumulatedMomentGraph.dispose(); - } - if (this.accumulatedMeanSquares != null) { - Object.keys(this.accumulatedMeanSquares) - .forEach(function (name) { return _this.accumulatedMeanSquares[name].dispose(); }); - } - if (this.accumulatedMoments != null) { - Object.keys(this.accumulatedMoments) - .forEach(function (name) { return _this.accumulatedMoments[name].dispose(); }); - } - }; - return RMSPropOptimizer; -}(optimizer_1.Optimizer)); -exports.RMSPropOptimizer = RMSPropOptimizer; - -},{"../environment":34,"../globals":35,"../graph/session_util":65,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],143:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var optimizer_1 = require("./optimizer"); -var SGDOptimizer = (function (_super) { - __extends(SGDOptimizer, _super); - function SGDOptimizer(learningRate, specifiedVariableList) { - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.setLearningRate(learningRate); - return _this; - } - SGDOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var varNames = Object.keys(variableGradients); - varNames.forEach(function (varName) { - var gradient = variableGradients[varName]; - var value = environment_1.ENV.engine.registeredVariables[varName]; - globals_1.tidy(function () { - var newValue = _this.c.mul(gradient).add(value); - value.assign(newValue); - }); - }); - }; - SGDOptimizer.prototype.setLearningRate = function (learningRate) { - this.learningRate = learningRate; - if (this.c != null) { - this.c.dispose(); - } - this.c = environment_1.ENV.math.keep(ops_1.scalar(-learningRate)); - }; - SGDOptimizer.prototype.dispose = function () { - this.c.dispose(); - if (this.one != null) { - this.one.dispose(); - } - _super.prototype.dispose.call(this); - }; - SGDOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var variable = math.scaledArrayAdd(_this.cGraph, gradient, _this.one, oldVariable); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - return SGDOptimizer; -}(optimizer_1.Optimizer)); -exports.SGDOptimizer = SGDOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"./optimizer":140}],144:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("./util"); -var Profiler = (function () { - function Profiler(backendTimer, logger) { - this.backendTimer = backendTimer; - this.logger = logger; - if (logger == null) { - this.logger = new Logger(); - } - } - Profiler.prototype.profileKernel = function (kernelName, f) { - var _this = this; - var result; - var holdResultWrapperFn = function () { - result = f(); - }; - var timer = this.backendTimer.time(holdResultWrapperFn); - var vals = result.dataSync(); - util.checkForNaN(vals, result.dtype, kernelName); - timer.then(function (timing) { - _this.logger.logKernelProfile(kernelName, result, vals, timing.kernelMs); - }); - return result; - }; - return Profiler; -}()); -exports.Profiler = Profiler; -var Logger = (function () { - function Logger() { - } - Logger.prototype.logKernelProfile = function (kernelName, result, vals, timeMs) { - var time = util.rightPad(timeMs + "ms", 9); - var paddedName = util.rightPad(kernelName, 25); - var rank = result.rank; - var size = result.size; - var shape = util.rightPad(result.shape.toString(), 14); - console.log("%c" + paddedName + "\t%c" + time + "\t%c" + rank + "D " + shape + "\t%c" + size, 'font-weight:bold', 'color:red', 'color:blue', 'color: orange'); - }; - return Logger; -}()); -exports.Logger = Logger; - -},{"./util":151}],145:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("./util"); -var tensor_1 = require("./tensor"); -function getFilteredNodesXToY(tape, xs, y) { - var tensorsFromX = {}; - var nodesFromX = {}; - for (var i = 0; i < xs.length; i++) { - tensorsFromX[xs[i].id] = true; - } - for (var i = 0; i < tape.length; i++) { - var node = tape[i]; - var nodeInputs = node.inputAndArgs.inputs; - for (var inputName in nodeInputs) { - var input = nodeInputs[inputName]; - var anyInputFromX = false; - for (var j = 0; j < xs.length; j++) { - if (tensorsFromX[input.id]) { - if (node.output instanceof tensor_1.Tensor) { - tensorsFromX[node.output.id] = true; - } - else { - var keys = Object.keys(node.output); - for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { - var key = keys_1[_i]; - tensorsFromX[node.output[key].id] = true; - } - } - anyInputFromX = true; - nodesFromX[node.id] = true; - break; - } - } - if (anyInputFromX) { - break; - } - } - } - var tensorsLeadToY = {}; - tensorsLeadToY[y.id] = true; - var nodesToY = {}; - for (var i = tape.length - 1; i >= 0; i--) { - var node = tape[i]; - var nodeInputs = node.inputAndArgs.inputs; - var outputs = []; - if (node.output instanceof tensor_1.Tensor) { - outputs.push(node.output); - } - else { - var keys = Object.keys(node.output); - for (var _a = 0, keys_2 = keys; _a < keys_2.length; _a++) { - var key = keys_2[_a]; - outputs.push(node.output[key]); - } - } - for (var j = 0; j < outputs.length; j++) { - if (tensorsLeadToY[outputs[j].id]) { - for (var inputName in nodeInputs) { - tensorsLeadToY[nodeInputs[inputName].id] = true; - nodesToY[node.id] = true; - } - break; - } - } - } - var filteredTape = []; - for (var i = 0; i < tape.length; i++) { - var node = tape[i]; - if (nodesFromX[node.id] && nodesToY[node.id]) { - var prunedInputs = {}; - for (var inputName in node.inputAndArgs.inputs) { - var nodeInput = node.inputAndArgs.inputs[inputName]; - if (tensorsFromX[nodeInput.id]) { - prunedInputs[inputName] = nodeInput; - } - } - var prunedOutputs = void 0; - if (node.output instanceof tensor_1.Tensor) { - prunedOutputs = node.output; - } - else { - prunedOutputs = {}; - for (var outputName in node.output) { - var output = node.output[outputName]; - if (tensorsLeadToY[output.id]) { - prunedOutputs[outputName] = node.output[outputName]; - } - } - } - var prunedNode = Object.assign({}, node); - prunedNode.inputAndArgs = { inputs: prunedInputs }; - prunedNode.output = prunedOutputs; - filteredTape.push(prunedNode); - } - } - return filteredTape; -} -exports.getFilteredNodesXToY = getFilteredNodesXToY; -function backpropagateGradients(tensorAccumulatedGradientMap, filteredTape) { - for (var i = filteredTape.length - 1; i >= 0; i--) { - var node = filteredTape[i]; - var dy = void 0; - if (node.output instanceof tensor_1.Tensor) { - dy = tensorAccumulatedGradientMap[node.output.id]; - } - else { - dy = {}; - var keys = Object.keys(node.output); - for (var _i = 0, keys_3 = keys; _i < keys_3.length; _i++) { - var key = keys_3[_i]; - dy[key] = tensorAccumulatedGradientMap[node.output[key].id]; - } - } - if (node.gradient == null) { - throw new Error("Cannot compute gradient: gradient function not found " + - ("for " + node.name + ".")); - } - var inputGradients = node.gradient(dy, node.output); - for (var inputName in node.inputAndArgs.inputs) { - if (!(inputName in inputGradients)) { - throw new Error("Cannot backprop through input " + inputName + ". " + - ("Available gradients found: " + Object.keys(inputGradients) + ".")); - } - var dx = inputGradients[inputName](); - var x = node.inputAndArgs.inputs[inputName]; - if (!util.arraysEqual(dx.shape, x.shape)) { - throw new Error("Error in gradient for op " + node.name + ". The gradient of input " + - ("'" + inputName + "' has shape '" + dx.shape + "', which does not match ") + - ("the shape of the input '" + x.shape + "'")); - } - if (tensorAccumulatedGradientMap[x.id] == null) { - tensorAccumulatedGradientMap[x.id] = dx; - } - else { - var curGradient = tensorAccumulatedGradientMap[x.id]; - tensorAccumulatedGradientMap[x.id] = curGradient.add(dx); - curGradient.dispose(); - } - } - } -} -exports.backpropagateGradients = backpropagateGradients; -function extractTensorsFromScopeResult(result) { - if (result == null) { - return []; - } - if (result instanceof tensor_1.Tensor) { - return [result]; - } - var list = []; - var resultObj = result; - for (var k in resultObj) { - var sublist = util.flatten(resultObj[k]).filter(function (x) { return x instanceof tensor_1.Tensor; }); - list.push.apply(list, sublist); - } - return list; -} -exports.extractTensorsFromScopeResult = extractTensorsFromScopeResult; -function stripUndefinedInputsFromInputConfig(config) { - var keys = Object.keys(config.inputs); - keys.forEach(function (key) { - if (config.inputs[key] == null) { - delete config.inputs[key]; - } - }); - return config; -} -exports.stripUndefinedInputsFromInputConfig = stripUndefinedInputsFromInputConfig; - -},{"./tensor":146,"./util":151}],146:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var environment_1 = require("./environment"); -var ops = require("./ops/ops"); -var util = require("./util"); -var TensorBuffer = (function () { - function TensorBuffer(shape, dtype, values) { - this.shape = shape; - this.dtype = dtype; - this.values = values; - if (values != null) { - var n = values.length; - var size = util.sizeFromShape(shape); - util.assert(n === size, "Length of values '" + n + "' does not match the size " + - ("inferred by the shape '" + size + "'")); - } - this.values = - values || util.getTypedArrayFromDType(dtype, util.sizeFromShape(shape)); - this.strides = computeStrides(shape); - } - TensorBuffer.prototype.set = function (value) { - var locs = []; - for (var _i = 1; _i < arguments.length; _i++) { - locs[_i - 1] = arguments[_i]; - } - if (locs.length === 0) { - locs = [0]; - } - util.assert(locs.length === this.rank, "The number of provided coordinates (" + locs.length + ") must " + - ("match the rank (" + this.rank + ")")); - var index = this.locToIndex(locs); - this.values[index] = value; - }; - TensorBuffer.prototype.get = function () { - var locs = []; - for (var _i = 0; _i < arguments.length; _i++) { - locs[_i] = arguments[_i]; - } - if (locs.length === 0) { - locs = [0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return this.values[index]; - }; - TensorBuffer.prototype.locToIndex = function (locs) { - if (this.rank === 0) { - return 0; - } - else if (this.rank === 1) { - return locs[0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return index; - }; - TensorBuffer.prototype.indexToLoc = function (index) { - if (this.rank === 0) { - return []; - } - else if (this.rank === 1) { - return [index]; - } - var locs = new Array(this.shape.length); - for (var i = 0; i < locs.length - 1; ++i) { - locs[i] = Math.floor(index / this.strides[i]); - index -= locs[i] * this.strides[i]; - } - locs[locs.length - 1] = index; - return locs; - }; - Object.defineProperty(TensorBuffer.prototype, "rank", { - get: function () { - return this.shape.length; - }, - enumerable: true, - configurable: true - }); - TensorBuffer.prototype.toTensor = function () { - return Tensor.make(this.shape, { values: this.values }, this.dtype); - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], TensorBuffer.prototype, "set", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], TensorBuffer.prototype, "get", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], TensorBuffer.prototype, "toTensor", null); - TensorBuffer = __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], TensorBuffer); - return TensorBuffer; -}()); -exports.TensorBuffer = TensorBuffer; -var Tensor = (function () { - function Tensor(shape, dtype, values, dataId) { - this.isDisposed = false; - this.size = util.sizeFromShape(shape); - if (values != null) { - util.assert(this.size === values.length, "Constructing tensor of shape (" + this.size + ") should match the " + - ("length of values (" + values.length + ")")); - } - this.shape = shape; - this.dtype = dtype || 'float32'; - this.strides = computeStrides(shape); - this.dataId = dataId != null ? dataId : {}; - this.id = Tensor_1.nextId++; - this.rankType = (this.rank < 5 ? this.rank.toString() : 'higher'); - environment_1.ENV.engine.registerTensor(this); - if (values != null) { - environment_1.ENV.engine.write(this.dataId, values); - } - } - Tensor_1 = Tensor; - Tensor.ones = function (shape, dtype) { - return ops.ones(shape, dtype); - }; - Tensor.zeros = function (shape, dtype) { - return ops.zeros(shape, dtype); - }; - Tensor.onesLike = function (x) { - return ops.onesLike(x); - }; - Tensor.zerosLike = function (x) { - return ops.zerosLike(x); - }; - Tensor.like = function (x) { - return ops.clone(x); - }; - Tensor.make = function (shape, data, dtype) { - return new Tensor_1(shape, dtype, data.values, data.dataId); - }; - Tensor.fromPixels = function (pixels, numChannels) { - if (numChannels === void 0) { numChannels = 3; } - return ops.fromPixels(pixels, numChannels); - }; - Tensor.rand = function (shape, randFunction, dtype) { - return ops.rand(shape, randFunction, dtype); - }; - Tensor.randNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - return ops.randomNormal(shape, mean, stdDev, dtype, seed); - }; - Tensor.randTruncatedNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - return ops.truncatedNormal(shape, mean, stdDev, dtype, seed); - }; - Tensor.randUniform = function (shape, a, b, dtype) { - return ops.randomUniform(shape, a, b, dtype); - }; - Tensor.prototype.flatten = function () { - this.throwIfDisposed(); - return this.as1D(); - }; - Tensor.prototype.asScalar = function () { - this.throwIfDisposed(); - util.assert(this.size === 1, 'The array must have only 1 element.'); - return this.reshape([]); - }; - Tensor.prototype.as1D = function () { - this.throwIfDisposed(); - return this.reshape([this.size]); - }; - Tensor.prototype.as2D = function (rows, columns) { - this.throwIfDisposed(); - return this.reshape([rows, columns]); - }; - Tensor.prototype.as3D = function (rows, columns, depth) { - this.throwIfDisposed(); - return this.reshape([rows, columns, depth]); - }; - Tensor.prototype.as4D = function (rows, columns, depth, depth2) { - this.throwIfDisposed(); - return this.reshape([rows, columns, depth, depth2]); - }; - Tensor.prototype.asType = function (dtype) { - this.throwIfDisposed(); - return ops.cast(this, dtype); - }; - Object.defineProperty(Tensor.prototype, "rank", { - get: function () { - return this.shape.length; - }, - enumerable: true, - configurable: true - }); - Tensor.prototype.get = function () { - var locs = []; - for (var _i = 0; _i < arguments.length; _i++) { - locs[_i] = arguments[_i]; - } - this.throwIfDisposed(); - if (locs.length === 0) { - locs = [0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return this.dataSync()[index]; - }; - Tensor.prototype.val = function () { - var locs = []; - for (var _i = 0; _i < arguments.length; _i++) { - locs[_i] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (locs.length === 0) { - locs = [0]; - } - this.throwIfDisposed(); - return [4, this.data()]; - case 1: - _a.sent(); - return [2, this.get.apply(this, locs)]; - } - }); - }); - }; - Tensor.prototype.locToIndex = function (locs) { - this.throwIfDisposed(); - if (this.rank === 0) { - return 0; - } - else if (this.rank === 1) { - return locs[0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return index; - }; - Tensor.prototype.indexToLoc = function (index) { - this.throwIfDisposed(); - if (this.rank === 0) { - return []; - } - else if (this.rank === 1) { - return [index]; - } - var locs = new Array(this.shape.length); - for (var i = 0; i < locs.length - 1; ++i) { - locs[i] = Math.floor(index / this.strides[i]); - index -= locs[i] * this.strides[i]; - } - locs[locs.length - 1] = index; - return locs; - }; - Tensor.prototype.getValues = function () { - return this.dataSync(); - }; - Tensor.prototype.getValuesAsync = function () { - return this.data(); - }; - Tensor.prototype.buffer = function () { - return ops.buffer(this.shape, this.dtype, this.dataSync()); - }; - Tensor.prototype.data = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - this.throwIfDisposed(); - return [2, environment_1.ENV.engine.read(this.dataId)]; - }); - }); - }; - Tensor.prototype.dataSync = function () { - this.throwIfDisposed(); - return environment_1.ENV.engine.readSync(this.dataId); - }; - Tensor.prototype.dispose = function () { - if (this.isDisposed) { - return; - } - this.isDisposed = true; - environment_1.ENV.engine.disposeTensor(this); - }; - Tensor.prototype.throwIfDisposed = function () { - if (this.isDisposed) { - throw new Error("Tensor is disposed."); - } - }; - Tensor.prototype.toFloat = function () { - return this.asType('float32'); - }; - Tensor.prototype.toInt = function () { - return this.asType('int32'); - }; - Tensor.prototype.toBool = function () { - return this.asType('bool'); - }; - Tensor.prototype.print = function (verbose) { - if (verbose === void 0) { verbose = false; } - return ops.print(this, verbose); - }; - Tensor.prototype.reshape = function (newShape) { - this.throwIfDisposed(); - return ops.reshape(this, newShape); - }; - Tensor.prototype.reshapeAs = function (x) { - this.throwIfDisposed(); - return this.reshape(x.shape); - }; - Tensor.prototype.expandDims = function (axis) { - if (axis === void 0) { axis = 0; } - return ops.expandDims(this, axis); - }; - Tensor.prototype.squeeze = function (axis) { - this.throwIfDisposed(); - return ops.squeeze(this, axis); - }; - Tensor.prototype.clone = function () { - this.throwIfDisposed(); - return ops.clone(this); - }; - Tensor.prototype.tile = function (reps) { - this.throwIfDisposed(); - return ops.tile(this, reps); - }; - Tensor.prototype.gather = function (indices, axis) { - if (axis === void 0) { axis = 0; } - this.throwIfDisposed(); - return ops.gather(this, indices); - }; - Tensor.prototype.matMul = function (b, transposeA, transposeB) { - if (transposeA === void 0) { transposeA = false; } - if (transposeB === void 0) { transposeB = false; } - this.throwIfDisposed(); - return ops.matMul(this, b, transposeA, transposeB); - }; - Tensor.prototype.norm = function (ord, axis, keepDims) { - if (ord === void 0) { ord = 'euclidean'; } - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.norm(this, ord, axis, keepDims); - }; - Tensor.prototype.slice = function (begin, size) { - this.throwIfDisposed(); - return ops.slice(this, begin, size); - }; - Tensor.prototype.reverse = function (axis) { - this.throwIfDisposed(); - return ops.reverse(this, axis); - }; - Tensor.prototype.concat = function (x, axis) { - if (axis === void 0) { axis = 0; } - this.throwIfDisposed(); - return ops.concat([this, x], axis); - }; - Tensor.prototype.stack = function (x, axis) { - if (axis === void 0) { axis = 0; } - return ops.stack([this, x], axis); - }; - Tensor.prototype.pad = function (paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - return ops.pad(this, paddings, constantValue); - }; - Tensor.prototype.batchNormalization = function (mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - this.throwIfDisposed(); - return ops.batchNormalization(this, mean, variance, varianceEpsilon, scale, offset); - }; - Tensor.prototype.logSumExp = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.logSumExp(this, axis, keepDims); - }; - Tensor.prototype.sum = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.sum(this, axis, keepDims); - }; - Tensor.prototype.mean = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.mean(this, axis, keepDims); - }; - Tensor.prototype.min = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.min(this, axis, keepDims); - }; - Tensor.prototype.max = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.max(this, axis, keepDims); - }; - Tensor.prototype.argMin = function (axis) { - if (axis === void 0) { axis = null; } - this.throwIfDisposed(); - return ops.argMin(this, axis); - }; - Tensor.prototype.argMax = function (axis) { - if (axis === void 0) { axis = null; } - this.throwIfDisposed(); - return ops.argMax(this, axis); - }; - Tensor.prototype.add = function (x) { - this.throwIfDisposed(); - return ops.add(this, x); - }; - Tensor.prototype.addStrict = function (x) { - this.throwIfDisposed(); - return ops.addStrict(this, x); - }; - Tensor.prototype.sub = function (x) { - this.throwIfDisposed(); - return ops.sub(this, x); - }; - Tensor.prototype.subStrict = function (x) { - this.throwIfDisposed(); - return ops.subStrict(this, x); - }; - Tensor.prototype.pow = function (exp) { - this.throwIfDisposed(); - return ops.pow(this, exp); - }; - Tensor.prototype.powStrict = function (exp) { - this.throwIfDisposed(); - return ops.powStrict(this, exp); - }; - Tensor.prototype.mul = function (x) { - this.throwIfDisposed(); - return ops.mul(this, x); - }; - Tensor.prototype.mulStrict = function (x) { - this.throwIfDisposed(); - return ops.mulStrict(this, x); - }; - Tensor.prototype.div = function (x) { - this.throwIfDisposed(); - return ops.div(this, x); - }; - Tensor.prototype.divStrict = function (x) { - this.throwIfDisposed(); - return ops.divStrict(this, x); - }; - Tensor.prototype.minimum = function (x) { - this.throwIfDisposed(); - return ops.minimum(this, x); - }; - Tensor.prototype.minimumStrict = function (x) { - this.throwIfDisposed(); - return ops.minimumStrict(this, x); - }; - Tensor.prototype.maximum = function (x) { - this.throwIfDisposed(); - return ops.maximum(this, x); - }; - Tensor.prototype.maximumStrict = function (x) { - this.throwIfDisposed(); - return ops.maximumStrict(this, x); - }; - Tensor.prototype.transpose = function (perm) { - this.throwIfDisposed(); - return ops.transpose(this, perm); - }; - Tensor.prototype.notEqual = function (x) { - this.throwIfDisposed(); - return ops.notEqual(this, x); - }; - Tensor.prototype.notEqualStrict = function (x) { - this.throwIfDisposed(); - return ops.notEqualStrict(this, x); - }; - Tensor.prototype.less = function (x) { - this.throwIfDisposed(); - return ops.less(this, x); - }; - Tensor.prototype.lessStrict = function (x) { - this.throwIfDisposed(); - return ops.lessStrict(this, x); - }; - Tensor.prototype.equal = function (x) { - this.throwIfDisposed(); - return ops.equal(this, x); - }; - Tensor.prototype.equalStrict = function (x) { - this.throwIfDisposed(); - return ops.equalStrict(this, x); - }; - Tensor.prototype.lessEqual = function (x) { - this.throwIfDisposed(); - return ops.lessEqual(this, x); - }; - Tensor.prototype.lessEqualStrict = function (x) { - this.throwIfDisposed(); - return ops.lessEqualStrict(this, x); - }; - Tensor.prototype.greater = function (x) { - this.throwIfDisposed(); - return ops.greater(this, x); - }; - Tensor.prototype.greaterStrict = function (x) { - this.throwIfDisposed(); - return ops.greaterStrict(this, x); - }; - Tensor.prototype.greaterEqual = function (x) { - this.throwIfDisposed(); - return ops.greaterEqual(this, x); - }; - Tensor.prototype.greaterEqualStrict = function (x) { - this.throwIfDisposed(); - return ops.greaterEqualStrict(this, x); - }; - Tensor.prototype.logicalAnd = function (x) { - this.throwIfDisposed(); - return ops.logicalAnd(this, x); - }; - Tensor.prototype.logicalOr = function (x) { - this.throwIfDisposed(); - return ops.logicalOr(this, x); - }; - Tensor.prototype.logicalXor = function (x) { - this.throwIfDisposed(); - return ops.logicalXor(this, x); - }; - Tensor.prototype.where = function (condition, x) { - this.throwIfDisposed(); - return ops.where(condition, this, x); - }; - Tensor.prototype.neg = function () { - this.throwIfDisposed(); - return ops.neg(this); - }; - Tensor.prototype.ceil = function () { - this.throwIfDisposed(); - return ops.ceil(this); - }; - Tensor.prototype.floor = function () { - this.throwIfDisposed(); - return ops.floor(this); - }; - Tensor.prototype.exp = function () { - this.throwIfDisposed(); - return ops.exp(this); - }; - Tensor.prototype.log = function () { - this.throwIfDisposed(); - return ops.log(this); - }; - Tensor.prototype.sqrt = function () { - this.throwIfDisposed(); - return ops.sqrt(this); - }; - Tensor.prototype.square = function () { - this.throwIfDisposed(); - return ops.square(this); - }; - Tensor.prototype.abs = function () { - this.throwIfDisposed(); - return ops.abs(this); - }; - Tensor.prototype.clipByValue = function (min, max) { - this.throwIfDisposed(); - return ops.clipByValue(this, min, max); - }; - Tensor.prototype.relu = function () { - this.throwIfDisposed(); - return ops.relu(this); - }; - Tensor.prototype.elu = function () { - this.throwIfDisposed(); - return ops.elu(this); - }; - Tensor.prototype.selu = function () { - this.throwIfDisposed(); - return ops.selu(this); - }; - Tensor.prototype.leakyRelu = function (alpha) { - if (alpha === void 0) { alpha = 0.2; } - this.throwIfDisposed(); - return ops.leakyRelu(this, alpha); - }; - Tensor.prototype.prelu = function (alpha) { - this.throwIfDisposed(); - return ops.prelu(this, alpha); - }; - Tensor.prototype.sigmoid = function () { - this.throwIfDisposed(); - return ops.sigmoid(this); - }; - Tensor.prototype.sin = function () { - this.throwIfDisposed(); - return ops.sin(this); - }; - Tensor.prototype.cos = function () { - this.throwIfDisposed(); - return ops.cos(this); - }; - Tensor.prototype.tan = function () { - this.throwIfDisposed(); - return ops.tan(this); - }; - Tensor.prototype.asin = function () { - this.throwIfDisposed(); - return ops.asin(this); - }; - Tensor.prototype.acos = function () { - this.throwIfDisposed(); - return ops.acos(this); - }; - Tensor.prototype.atan = function () { - this.throwIfDisposed(); - return ops.atan(this); - }; - Tensor.prototype.sinh = function () { - this.throwIfDisposed(); - return ops.sinh(this); - }; - Tensor.prototype.cosh = function () { - this.throwIfDisposed(); - return ops.cosh(this); - }; - Tensor.prototype.tanh = function () { - this.throwIfDisposed(); - return ops.tanh(this); - }; - Tensor.prototype.step = function (alpha) { - if (alpha === void 0) { alpha = 0.0; } - this.throwIfDisposed(); - return ops.step(this, alpha); - }; - Tensor.prototype.softmax = function (dim) { - if (dim === void 0) { dim = -1; } - this.throwIfDisposed(); - return ops.softmax(this, dim); - }; - Tensor.prototype.resizeBilinear = function (newShape2D, alignCorners) { - if (alignCorners === void 0) { alignCorners = false; } - this.throwIfDisposed(); - return ops.image.resizeBilinear(this, newShape2D, alignCorners); - }; - Tensor.prototype.conv1d = function (filter, stride, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.conv1d(this, filter, stride, pad, dimRoundingMode); - }; - Tensor.prototype.conv2d = function (filter, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.conv2d(this, filter, strides, pad, dimRoundingMode); - }; - Tensor.prototype.conv2dTranspose = function (filter, outputShape, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.conv2dTranspose(this, filter, outputShape, strides, pad, dimRoundingMode); - }; - Tensor.prototype.depthwiseConv2D = function (filter, strides, pad, rates, dimRoundingMode) { - if (rates === void 0) { rates = [1, 1]; } - this.throwIfDisposed(); - return ops.depthwiseConv2d(this, filter, strides, pad, rates, dimRoundingMode); - }; - Tensor.prototype.avgPool = function (filterSize, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.avgPool(this, filterSize, strides, pad, dimRoundingMode); - }; - Tensor.prototype.maxPool = function (filterSize, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.maxPool(this, filterSize, strides, pad, dimRoundingMode); - }; - Tensor.prototype.minPool = function (filterSize, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.minPool(this, filterSize, strides, pad, dimRoundingMode); - }; - Tensor.prototype.localResponseNormalization = function (radius, bias, alpha, beta, normRegion) { - if (radius === void 0) { radius = 5; } - if (bias === void 0) { bias = 1; } - if (alpha === void 0) { alpha = 1; } - if (beta === void 0) { beta = 0.5; } - if (normRegion === void 0) { normRegion = 'acrossChannels'; } - return ops.localResponseNormalization(this, radius, bias, alpha, beta, normRegion); - }; - Tensor.prototype.variable = function (trainable, name, dtype) { - if (trainable === void 0) { trainable = true; } - this.throwIfDisposed(); - return Variable.variable(this, trainable, name, dtype); - }; - Tensor.nextId = 0; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "flatten", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "asScalar", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as1D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as2D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as3D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as4D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "asType", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "buffer", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "data", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "dataSync", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "dispose", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "toFloat", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "toInt", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "toBool", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "print", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "reshape", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "reshapeAs", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "expandDims", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "squeeze", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "clone", null); - Tensor = Tensor_1 = __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor); - return Tensor; - var Tensor_1; -}()); -exports.Tensor = Tensor; -exports.NDArray = Tensor; -var Scalar = (function (_super) { - __extends(Scalar, _super); - function Scalar() { - return _super !== null && _super.apply(this, arguments) || this; - } - Scalar.new = function (value, dtype) { - return ops.scalar(value, dtype); - }; - return Scalar; -}(Tensor)); -exports.Scalar = Scalar; -var Tensor1D = (function (_super) { - __extends(Tensor1D, _super); - function Tensor1D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor1D.new = function (values, dtype) { - return ops.tensor1d(values, dtype); - }; - return Tensor1D; -}(Tensor)); -exports.Tensor1D = Tensor1D; -exports.Array1D = Tensor1D; -var Tensor2D = (function (_super) { - __extends(Tensor2D, _super); - function Tensor2D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor2D.new = function (shape, values, dtype) { - return ops.tensor2d(values, shape, dtype); - }; - return Tensor2D; -}(Tensor)); -exports.Tensor2D = Tensor2D; -exports.Array2D = Tensor2D; -var Tensor3D = (function (_super) { - __extends(Tensor3D, _super); - function Tensor3D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor3D.new = function (shape, values, dtype) { - return ops.tensor3d(values, shape, dtype); - }; - return Tensor3D; -}(Tensor)); -exports.Tensor3D = Tensor3D; -exports.Array3D = Tensor3D; -var Tensor4D = (function (_super) { - __extends(Tensor4D, _super); - function Tensor4D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor4D.new = function (shape, values, dtype) { - return ops.tensor4d(values, shape, dtype); - }; - return Tensor4D; -}(Tensor)); -exports.Tensor4D = Tensor4D; -exports.Array4D = Tensor4D; -var Variable = (function (_super) { - __extends(Variable, _super); - function Variable(initialValue, trainable, name) { - if (trainable === void 0) { trainable = true; } - var _this = _super.call(this, initialValue.shape, initialValue.dtype, null, initialValue.dataId) || this; - _this.trainable = trainable; - _this.name = name; - if (_this.name == null) { - _this.name = Variable_1.nextVarId.toString(); - Variable_1.nextVarId++; - } - environment_1.ENV.engine.registerVariable(_this); - return _this; - } - Variable_1 = Variable; - Variable.variable = function (initialValue, trainable, name, dtype) { - if (trainable === void 0) { trainable = true; } - if (dtype != null && dtype !== initialValue.dtype) { - initialValue = initialValue.asType(dtype); - } - return new Variable_1(initialValue, trainable, name); - }; - Variable.prototype.assign = function (newValue) { - if (newValue.dtype !== this.dtype) { - throw new Error("dtype of the new value (" + newValue.dtype + ") and " + - ("previous value (" + this.dtype + ") must match")); - } - if (!util.arraysEqual(newValue.shape, this.shape)) { - throw new Error("shape of the new value (" + newValue.shape + ") and " + - ("previous value (" + this.shape + ") must match")); - } - environment_1.ENV.engine.disposeTensor(this); - this.dataId = newValue.dataId; - environment_1.ENV.engine.registerTensor(this); - }; - Variable.nextVarId = 0; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Variable.prototype, "assign", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Variable, "variable", null); - Variable = Variable_1 = __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Variable); - return Variable; - var Variable_1; -}(Tensor)); -exports.Variable = Variable; -var variable = Variable.variable; -exports.variable = variable; -function computeStrides(shape) { - var rank = shape.length; - if (rank < 2) { - return []; - } - var strides = new Array(rank - 1); - strides[rank - 2] = shape[rank - 1]; - for (var i = rank - 3; i >= 0; --i) { - strides[i] = strides[i + 1] * shape[i + 1]; - } - return strides; -} - -},{"./doc":32,"./environment":34,"./ops/ops":123,"./util":151}],147:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("./environment"); -var backend_cpu_1 = require("./kernels/backend_cpu"); -var backend_webgl_1 = require("./kernels/backend_webgl"); -var tensor_1 = require("./tensor"); -var util = require("./util"); -var WEBGL_FLOAT_ENVS = [ - { 'BACKEND': 'webgl', 'WEBGL_FLOAT_TEXTURE_ENABLED': true, 'WEBGL_VERSION': 1 }, - { - 'BACKEND': 'webgl', - 'WEBGL_FLOAT_TEXTURE_ENABLED': true, - 'WEBGL_VERSION': 2 - } -]; -exports.WEBGL_ENVS = WEBGL_FLOAT_ENVS.concat([{ - 'BACKEND': 'webgl', - 'WEBGL_FLOAT_TEXTURE_ENABLED': false, - 'WEBGL_VERSION': 1 - }]); -exports.CPU_ENVS = [{ 'BACKEND': 'cpu' }]; -exports.ALL_FLOAT_ENVS = WEBGL_FLOAT_ENVS.concat(exports.CPU_ENVS); -exports.ALL_ENVS = exports.WEBGL_ENVS.concat(exports.CPU_ENVS); -exports.TEST_EPSILON = 1e-2; -function expectArraysClose(actual, expected, epsilon) { - if (epsilon === void 0) { epsilon = exports.TEST_EPSILON; } - if (!(actual instanceof tensor_1.Tensor) && !(expected instanceof tensor_1.Tensor)) { - var aType = actual.constructor.name; - var bType = expected.constructor.name; - if (aType !== bType) { - throw new Error("Arrays are of different type actual: " + aType + " " + - ("vs expected: " + bType)); - } - } - else if (actual instanceof tensor_1.Tensor && expected instanceof tensor_1.Tensor) { - if (actual.dtype !== expected.dtype) { - throw new Error("Arrays are of different type actual: " + actual.dtype + " " + - ("vs expected: " + expected.dtype + ".")); - } - if (!util.arraysEqual(actual.shape, expected.shape)) { - throw new Error("Arrays are of different shape actual: " + actual.shape + " " + - ("vs expected: " + expected.shape + ".")); - } - } - var actualValues; - var expectedValues; - if (actual instanceof tensor_1.Tensor) { - actualValues = actual.dataSync(); - } - else { - actualValues = actual; - } - if (expected instanceof tensor_1.Tensor) { - expectedValues = expected.dataSync(); - } - else { - expectedValues = expected; - } - if (actualValues.length !== expectedValues.length) { - throw new Error("Arrays have different lengths actual: " + actualValues.length + " vs " + - ("expected: " + expectedValues.length + ".\n") + - ("Actual: " + actualValues + ".\n") + - ("Expected: " + expectedValues + ".")); - } - for (var i = 0; i < expectedValues.length; ++i) { - var a = actualValues[i]; - var e = expectedValues[i]; - if (!areClose(a, Number(e), epsilon)) { - throw new Error("Arrays differ: actual[" + i + "] = " + a + ", expected[" + i + "] = " + e + ".\n" + - ("Actual: " + actualValues + ".\n") + - ("Expected: " + expectedValues + ".")); - } - } -} -exports.expectArraysClose = expectArraysClose; -function expectArraysEqual(actual, expected) { - return expectArraysClose(actual, expected, 0); -} -exports.expectArraysEqual = expectArraysEqual; -function expectNumbersClose(a, e, epsilon) { - if (epsilon === void 0) { epsilon = exports.TEST_EPSILON; } - if (!areClose(a, e, epsilon)) { - throw new Error("Numbers differ: actual === " + a + ", expected === " + e); - } -} -exports.expectNumbersClose = expectNumbersClose; -function areClose(a, e, epsilon) { - if (isNaN(a) && isNaN(e)) { - return true; - } - if (isNaN(a) || isNaN(e) || Math.abs(a - e) > epsilon) { - return false; - } - return true; -} -function expectValuesInRange(actual, low, high) { - var actualVals; - if (actual instanceof tensor_1.Tensor) { - actualVals = actual.dataSync(); - } - else { - actualVals = actual; - } - for (var i = 0; i < actualVals.length; i++) { - if (actualVals[i] < low || actualVals[i] > high) { - throw new Error("Value out of range:" + actualVals[i] + " low: " + low + ", high: " + high); - } - } -} -exports.expectValuesInRange = expectValuesInRange; -function describeWithFlags(name, featuresList, tests) { - featuresList.forEach(function (features) { - var testName = name + ' ' + JSON.stringify(features); - executeTests(testName, tests, features); - }); -} -exports.describeWithFlags = describeWithFlags; -function executeTests(testName, tests, features) { - describe(testName, function () { - beforeEach(function () { - environment_1.ENV.setFeatures(features || {}); - environment_1.ENV.addCustomBackend('webgl', function () { return new backend_webgl_1.MathBackendWebGL(); }); - environment_1.ENV.addCustomBackend('cpu', function () { return new backend_cpu_1.MathBackendCPU(); }); - if (features && features.BACKEND != null) { - environment_1.Environment.setBackend(features.BACKEND); - } - environment_1.ENV.engine.startScope(); - }); - afterEach(function () { - environment_1.ENV.engine.endScope(null); - environment_1.ENV.reset(); - }); - tests(); - }); -} -function assertIsNan(val, dtype) { - if (!util.isValNaN(val, dtype)) { - throw new Error("Value " + val + " does not represent NaN for dtype " + dtype); - } -} -exports.assertIsNan = assertIsNan; - -},{"./environment":34,"./kernels/backend_cpu":68,"./kernels/backend_webgl":69,"./tensor":146,"./util":151}],148:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var environment_1 = require("./environment"); -var Tracking = (function () { - function Tracking() { - } - Tracking.tidy = function (nameOrFn, fn, gradMode) { - if (gradMode === void 0) { gradMode = false; } - if (fn == null) { - if (typeof nameOrFn !== 'function') { - throw new Error('Please provide a function to dl.tidy()'); - } - fn = nameOrFn; - nameOrFn = ''; - } - else { - if (typeof nameOrFn !== 'string' && !(nameOrFn instanceof String)) { - throw new Error('When calling with two arguments, the first argument ' + - 'to dl.tidy() must be a string'); - } - if (typeof fn !== 'function') { - throw new Error('When calling with two arguments, the 2nd argument ' + - 'to dl.tidy() must be a function'); - } - } - environment_1.ENV.engine.startScope(gradMode); - var result = fn(); - if (result instanceof Promise) { - result.then(function (r) { return environment_1.ENV.engine.endScope(r, gradMode); }); - return result; - } - else { - environment_1.ENV.engine.endScope(result, gradMode); - return result; - } - }; - Tracking.keep = function (result) { - return environment_1.ENV.engine.keep(result); - }; - Tracking.time = function (f) { - return environment_1.ENV.engine.time(f); - }; - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Memory' }) - ], Tracking, "tidy", null); - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Memory' }) - ], Tracking, "keep", null); - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Timing' }) - ], Tracking, "time", null); - return Tracking; -}()); -exports.Tracking = Tracking; - -},{"./doc":32,"./environment":34}],149:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var adadelta_optimizer_1 = require("./optimizers/adadelta_optimizer"); -var adagrad_optimizer_1 = require("./optimizers/adagrad_optimizer"); -var adam_optimizer_1 = require("./optimizers/adam_optimizer"); -var adamax_optimizer_1 = require("./optimizers/adamax_optimizer"); -var momentum_optimizer_1 = require("./optimizers/momentum_optimizer"); -var optimizer_constructors_1 = require("./optimizers/optimizer_constructors"); -var rmsprop_optimizer_1 = require("./optimizers/rmsprop_optimizer"); -var sgd_optimizer_1 = require("./optimizers/sgd_optimizer"); -[momentum_optimizer_1.MomentumOptimizer, sgd_optimizer_1.SGDOptimizer, adadelta_optimizer_1.AdadeltaOptimizer, adagrad_optimizer_1.AdagradOptimizer, - rmsprop_optimizer_1.RMSPropOptimizer, adamax_optimizer_1.AdamaxOptimizer, adam_optimizer_1.AdamOptimizer]; -exports.train = { - sgd: optimizer_constructors_1.OptimizerConstructors.sgd, - momentum: optimizer_constructors_1.OptimizerConstructors.momentum, - adadelta: optimizer_constructors_1.OptimizerConstructors.adadelta, - adagrad: optimizer_constructors_1.OptimizerConstructors.adagrad, - rmsprop: optimizer_constructors_1.OptimizerConstructors.rmsprop, - adamax: optimizer_constructors_1.OptimizerConstructors.adamax, - adam: optimizer_constructors_1.OptimizerConstructors.adam -}; - -},{"./optimizers/adadelta_optimizer":135,"./optimizers/adagrad_optimizer":136,"./optimizers/adam_optimizer":137,"./optimizers/adamax_optimizer":138,"./optimizers/momentum_optimizer":139,"./optimizers/optimizer_constructors":141,"./optimizers/rmsprop_optimizer":142,"./optimizers/sgd_optimizer":143}],150:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var DType; -(function (DType) { - DType["float32"] = "float32"; - DType["int32"] = "int32"; - DType["bool"] = "bool"; -})(DType = exports.DType || (exports.DType = {})); -var Rank; -(function (Rank) { - Rank["R0"] = "R0"; - Rank["R1"] = "R1"; - Rank["R2"] = "R2"; - Rank["R3"] = "R3"; - Rank["R4"] = "R4"; -})(Rank = exports.Rank || (exports.Rank = {})); -var UpcastInt32AndMap; -(function (UpcastInt32AndMap) { - UpcastInt32AndMap["float32"] = "float32"; - UpcastInt32AndMap["int32"] = "int32"; - UpcastInt32AndMap["bool"] = "int32"; -})(UpcastInt32AndMap || (UpcastInt32AndMap = {})); -var UpcastBoolAndMap; -(function (UpcastBoolAndMap) { - UpcastBoolAndMap["float32"] = "float32"; - UpcastBoolAndMap["int32"] = "int32"; - UpcastBoolAndMap["bool"] = "bool"; -})(UpcastBoolAndMap || (UpcastBoolAndMap = {})); -var UpcastFloat32AndMap; -(function (UpcastFloat32AndMap) { - UpcastFloat32AndMap["float32"] = "float32"; - UpcastFloat32AndMap["int32"] = "float32"; - UpcastFloat32AndMap["bool"] = "float32"; -})(UpcastFloat32AndMap || (UpcastFloat32AndMap = {})); -var upcastTypeMap = { - float32: UpcastFloat32AndMap, - int32: UpcastInt32AndMap, - bool: UpcastBoolAndMap -}; -function upcastType(typeA, typeB) { - return upcastTypeMap[typeA][typeB]; -} -exports.upcastType = upcastType; -function sumOutType(type) { - return upcastType(type, 'int32'); -} -exports.sumOutType = sumOutType; - -},{}],151:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("./tensor"); -function shuffle(array) { - var counter = array.length; - var temp = 0; - var index = 0; - while (counter > 0) { - index = (Math.random() * counter) | 0; - counter--; - temp = array[counter]; - array[counter] = array[index]; - array[index] = temp; - } -} -exports.shuffle = shuffle; -function clamp(min, x, max) { - return Math.max(min, Math.min(x, max)); -} -exports.clamp = clamp; -function randUniform(a, b) { - return Math.random() * (b - a) + a; -} -exports.randUniform = randUniform; -function distSquared(a, b) { - var result = 0; - for (var i = 0; i < a.length; i++) { - var diff = Number(a[i]) - Number(b[i]); - result += diff * diff; - } - return result; -} -exports.distSquared = distSquared; -function assert(expr, msg) { - if (!expr) { - throw new Error(msg); - } -} -exports.assert = assert; -function assertShapesMatch(shapeA, shapeB, errorMessagePrefix) { - if (errorMessagePrefix === void 0) { errorMessagePrefix = ''; } - assert(arraysEqual(shapeA, shapeB), errorMessagePrefix + ("Shapes " + shapeA + " and " + shapeB + " must match")); -} -exports.assertShapesMatch = assertShapesMatch; -function assertTypesMatch(a, b) { - assert(a.dtype === b.dtype, "The dtypes of the first (" + a.dtype + ") and " + - ("second (" + b.dtype + ") input must match")); -} -exports.assertTypesMatch = assertTypesMatch; -function flatten(arr, ret) { - if (ret === void 0) { ret = []; } - if (Array.isArray(arr)) { - for (var i = 0; i < arr.length; ++i) { - flatten(arr[i], ret); - } - } - else { - ret.push(arr); - } - return ret; -} -exports.flatten = flatten; -function inferShape(val) { - if (isTypedArray(val)) { - return [val.length]; - } - if (!Array.isArray(val)) { - return []; - } - var shape = []; - while (val instanceof Array) { - shape.push(val.length); - val = val[0]; - } - return shape; -} -exports.inferShape = inferShape; -function sizeFromShape(shape) { - if (shape.length === 0) { - return 1; - } - var size = shape[0]; - for (var i = 1; i < shape.length; i++) { - size *= shape[i]; - } - return size; -} -exports.sizeFromShape = sizeFromShape; -function isScalarShape(shape) { - return shape.length === 0; -} -exports.isScalarShape = isScalarShape; -function arraysEqual(n1, n2) { - if (n1.length !== n2.length) { - return false; - } - for (var i = 0; i < n1.length; i++) { - if (n1[i] !== n2[i]) { - return false; - } - } - return true; -} -exports.arraysEqual = arraysEqual; -function isInt(a) { - return a % 1 === 0; -} -exports.isInt = isInt; -function tanh(x) { - if (Math.tanh != null) { - return Math.tanh(x); - } - if (x === Infinity) { - return 1; - } - else if (x === -Infinity) { - return -1; - } - else { - var e2x = Math.exp(2 * x); - return (e2x - 1) / (e2x + 1); - } -} -exports.tanh = tanh; -function sizeToSquarishShape(size) { - for (var a = Math.floor(Math.sqrt(size)); a > 1; --a) { - if (size % a === 0) { - return [a, size / a]; - } - } - return [1, size]; -} -exports.sizeToSquarishShape = sizeToSquarishShape; -function createShuffledIndices(n) { - var shuffledIndices = new Uint32Array(n); - for (var i = 0; i < n; ++i) { - shuffledIndices[i] = i; - } - shuffle(shuffledIndices); - return shuffledIndices; -} -exports.createShuffledIndices = createShuffledIndices; -function rightPad(a, size) { - if (size <= a.length) { - return a; - } - return a + ' '.repeat(size - a.length); -} -exports.rightPad = rightPad; -function repeatedTry(checkFn, delayFn, maxCounter) { - if (delayFn === void 0) { delayFn = function (counter) { return 0; }; } - return new Promise(function (resolve, reject) { - var tryCount = 0; - var tryFn = function () { - if (checkFn()) { - resolve(); - return; - } - tryCount++; - var nextBackoff = delayFn(tryCount); - if (maxCounter != null && tryCount >= maxCounter) { - reject(); - return; - } - setTimeout(tryFn, nextBackoff); - }; - setTimeout(tryFn, 0); - }); -} -exports.repeatedTry = repeatedTry; -function getQueryParams(queryString) { - var params = {}; - queryString.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function (s) { - var t = []; - for (var _i = 1; _i < arguments.length; _i++) { - t[_i - 1] = arguments[_i]; - } - decodeParam(params, t[0], t[1]); - return t.join('='); - }); - return params; -} -exports.getQueryParams = getQueryParams; -function decodeParam(params, name, value) { - params[decodeURIComponent(name)] = decodeURIComponent(value || ''); -} -function inferFromImplicitShape(shape, size) { - var shapeProd = 1; - var implicitIdx = -1; - for (var i = 0; i < shape.length; ++i) { - if (shape[i] > 0) { - shapeProd *= shape[i]; - } - else if (shape[i] === -1) { - if (implicitIdx !== -1) { - throw Error("Shapes can only have 1 implicit size. " + - ("Found -1 at dim " + implicitIdx + " and dim " + i)); - } - implicitIdx = i; - } - else if (shape[i] <= 0) { - throw Error("Shapes can not be <= 0. Found " + shape[i] + " at dim " + i); - } - } - if (implicitIdx === -1) { - if (size > 0 && size !== shapeProd) { - throw Error("Size (" + size + ") must match the product of shape " + shape); - } - return shape; - } - if (size % shapeProd !== 0) { - throw Error("The implicit shape can't be a fractional number. " + - ("Got " + size + " / " + shapeProd)); - } - var newShape = shape.slice(); - newShape[implicitIdx] = size / shapeProd; - return newShape; -} -exports.inferFromImplicitShape = inferFromImplicitShape; -exports.NAN_INT32 = 1 << 31; -exports.NAN_BOOL = 255; -exports.NAN_FLOAT32 = NaN; -function getNaN(dtype) { - if (dtype === 'float32') { - return exports.NAN_FLOAT32; - } - else if (dtype === 'int32') { - return exports.NAN_INT32; - } - else if (dtype === 'bool') { - return exports.NAN_BOOL; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -exports.getNaN = getNaN; -function isValNaN(val, dtype) { - if (isNaN(val)) { - return true; - } - if (dtype === 'float32') { - return false; - } - else if (dtype === 'int32') { - return val === exports.NAN_INT32; - } - else if (dtype === 'bool') { - return val === exports.NAN_BOOL; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -exports.isValNaN = isValNaN; -function squeezeShape(shape, axis) { - var newShape = []; - var keptDims = []; - var j = 0; - for (var i = 0; i < shape.length; ++i) { - if (axis !== undefined) { - if (axis[j] === i && shape[i] > 1) { - throw new Error("axis " + i + " is not 1"); - } - if ((axis[j] === undefined || axis[j] > i) && shape[i] === 1) { - newShape.push(shape[i]); - keptDims.push(i); - } - if (axis[j] <= i) - j++; - } - if (shape[i] > 1) { - newShape.push(shape[i]); - keptDims.push(i); - } - } - return { newShape: newShape, keptDims: keptDims }; -} -exports.squeezeShape = squeezeShape; -function getTypedArrayFromDType(dtype, size) { - var values = null; - if (dtype == null || dtype === 'float32') { - values = new Float32Array(size); - } - else if (dtype === 'int32') { - values = new Int32Array(size); - } - else if (dtype === 'bool') { - values = new Uint8Array(size); - } - else { - throw new Error("Unknown data type " + dtype); - } - return values; -} -exports.getTypedArrayFromDType = getTypedArrayFromDType; -function isTensorInList(tensor, tensorList) { - for (var i = 0; i < tensorList.length; i++) { - if (tensorList[i].id === tensor.id) { - return true; - } - } - return false; -} -exports.isTensorInList = isTensorInList; -function checkForNaN(vals, dtype, name) { - for (var i = 0; i < vals.length; i++) { - if (isValNaN(vals[i], dtype)) { - throw Error("The result of the '" + name + "' has NaNs."); - } - } -} -exports.checkForNaN = checkForNaN; -function flattenNameArrayMap(nameArrayMap, keys) { - var xs = []; - if (nameArrayMap instanceof tensor_1.Tensor) { - xs.push(nameArrayMap); - } - else { - var xMap = nameArrayMap; - for (var i = 0; i < keys.length; i++) { - xs.push(xMap[keys[i]]); - } - } - return xs; -} -exports.flattenNameArrayMap = flattenNameArrayMap; -function unflattenToNameArrayMap(keys, flatArrays) { - if (keys.length !== flatArrays.length) { - throw new Error("Cannot unflatten Tensor[], keys and arrays are not of same length."); - } - var result = {}; - for (var i = 0; i < keys.length; i++) { - result[keys[i]] = flatArrays[i]; - } - return result; -} -exports.unflattenToNameArrayMap = unflattenToNameArrayMap; -function hasEncodingLoss(oldType, newType) { - if (newType === 'float32') { - return false; - } - if (newType === 'int32' && oldType !== 'float32') { - return false; - } - if (newType === 'bool' && oldType === 'bool') { - return false; - } - return true; -} -exports.hasEncodingLoss = hasEncodingLoss; -function copyTypedArray(array, dtype) { - if (dtype == null || dtype === 'float32') { - return new Float32Array(array); - } - else if (dtype === 'int32') { - var vals = new Int32Array(array.length); - for (var i = 0; i < vals.length; ++i) { - var val = array[i]; - if (isValNaN(val, 'int32')) { - vals[i] = getNaN('int32'); - } - else { - vals[i] = val; - } - } - return vals; - } - else if (dtype === 'bool') { - var bool = new Uint8Array(array.length); - for (var i = 0; i < bool.length; ++i) { - var val = array[i]; - if (isValNaN(val, 'bool')) { - bool[i] = getNaN('bool'); - } - else if (Math.round(val) !== 0) { - bool[i] = 1; - } - } - return bool; - } - else { - throw new Error("Unknown data type " + dtype); - } -} -exports.copyTypedArray = copyTypedArray; -function isTypedArray(a) { - return a instanceof Float32Array || a instanceof Int32Array || - a instanceof Uint8Array; -} -exports.isTypedArray = isTypedArray; -function bytesPerElement(dtype) { - if (dtype === 'float32' || dtype === 'int32') { - return 4; - } - else if (dtype === 'bool') { - return 1; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -exports.bytesPerElement = bytesPerElement; -function isFunction(f) { - return !!(f && f.constructor && f.call && f.apply); -} -exports.isFunction = isFunction; - -},{"./tensor":146}],152:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var version = '0.5.0'; -exports.version = version; - -},{}],153:[function(require,module,exports){ -// A library of seedable RNGs implemented in Javascript. -// -// Usage: -// -// var seedrandom = require('seedrandom'); -// var random = seedrandom(1); // or any seed. -// var x = random(); // 0 <= x < 1. Every bit is random. -// var x = random.quick(); // 0 <= x < 1. 32 bits of randomness. - -// alea, a 53-bit multiply-with-carry generator by Johannes Baagøe. -// Period: ~2^116 -// Reported to pass all BigCrush tests. -var alea = require('./lib/alea'); - -// xor128, a pure xor-shift generator by George Marsaglia. -// Period: 2^128-1. -// Reported to fail: MatrixRank and LinearComp. -var xor128 = require('./lib/xor128'); - -// xorwow, George Marsaglia's 160-bit xor-shift combined plus weyl. -// Period: 2^192-2^32 -// Reported to fail: CollisionOver, SimpPoker, and LinearComp. -var xorwow = require('./lib/xorwow'); - -// xorshift7, by François Panneton and Pierre L'ecuyer, takes -// a different approach: it adds robustness by allowing more shifts -// than Marsaglia's original three. It is a 7-shift generator -// with 256 bits, that passes BigCrush with no systmatic failures. -// Period 2^256-1. -// No systematic BigCrush failures reported. -var xorshift7 = require('./lib/xorshift7'); - -// xor4096, by Richard Brent, is a 4096-bit xor-shift with a -// very long period that also adds a Weyl generator. It also passes -// BigCrush with no systematic failures. Its long period may -// be useful if you have many generators and need to avoid -// collisions. -// Period: 2^4128-2^32. -// No systematic BigCrush failures reported. -var xor4096 = require('./lib/xor4096'); - -// Tyche-i, by Samuel Neves and Filipe Araujo, is a bit-shifting random -// number generator derived from ChaCha, a modern stream cipher. -// https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf -// Period: ~2^127 -// No systematic BigCrush failures reported. -var tychei = require('./lib/tychei'); - -// The original ARC4-based prng included in this library. -// Period: ~2^1600 -var sr = require('./seedrandom'); - -sr.alea = alea; -sr.xor128 = xor128; -sr.xorwow = xorwow; -sr.xorshift7 = xorshift7; -sr.xor4096 = xor4096; -sr.tychei = tychei; - -module.exports = sr; - -},{"./lib/alea":154,"./lib/tychei":155,"./lib/xor128":156,"./lib/xor4096":157,"./lib/xorshift7":158,"./lib/xorwow":159,"./seedrandom":160}],154:[function(require,module,exports){ -// A port of an algorithm by Johannes Baagøe , 2010 -// http://baagoe.com/en/RandomMusings/javascript/ -// https://github.com/nquinlan/better-random-numbers-for-javascript-mirror -// Original work is under MIT license - - -// Copyright (C) 2010 by Johannes Baagøe -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall 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. - - - -(function(global, module, define) { - -function Alea(seed) { - var me = this, mash = Mash(); - - me.next = function() { - var t = 2091639 * me.s0 + me.c * 2.3283064365386963e-10; // 2^-32 - me.s0 = me.s1; - me.s1 = me.s2; - return me.s2 = t - (me.c = t | 0); - }; - - // Apply the seeding algorithm from Baagoe. - me.c = 1; - me.s0 = mash(' '); - me.s1 = mash(' '); - me.s2 = mash(' '); - me.s0 -= mash(seed); - if (me.s0 < 0) { me.s0 += 1; } - me.s1 -= mash(seed); - if (me.s1 < 0) { me.s1 += 1; } - me.s2 -= mash(seed); - if (me.s2 < 0) { me.s2 += 1; } - mash = null; -} - -function copy(f, t) { - t.c = f.c; - t.s0 = f.s0; - t.s1 = f.s1; - t.s2 = f.s2; - return t; -} - -function impl(seed, opts) { - var xg = new Alea(seed), - state = opts && opts.state, - prng = xg.next; - prng.int32 = function() { return (xg.next() * 0x100000000) | 0; } - prng.double = function() { - return prng() + (prng() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53 - }; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -function Mash() { - var n = 0xefc8249d; - - var mash = function(data) { - data = data.toString(); - for (var i = 0; i < data.length; i++) { - n += data.charCodeAt(i); - var h = 0.02519603282416938 * n; - n = h >>> 0; - h -= n; - h *= n; - n = h >>> 0; - h -= n; - n += h * 0x100000000; // 2^32 - } - return (n >>> 0) * 2.3283064365386963e-10; // 2^-32 - }; - - return mash; -} - - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.alea = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],155:[function(require,module,exports){ -// A Javascript implementaion of the "Tyche-i" prng algorithm by -// Samuel Neves and Filipe Araujo. -// See https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf - -(function(global, module, define) { - -function XorGen(seed) { - var me = this, strseed = ''; - - // Set up generator function. - me.next = function() { - var b = me.b, c = me.c, d = me.d, a = me.a; - b = (b << 25) ^ (b >>> 7) ^ c; - c = (c - d) | 0; - d = (d << 24) ^ (d >>> 8) ^ a; - a = (a - b) | 0; - me.b = b = (b << 20) ^ (b >>> 12) ^ c; - me.c = c = (c - d) | 0; - me.d = (d << 16) ^ (c >>> 16) ^ a; - return me.a = (a - b) | 0; - }; - - /* The following is non-inverted tyche, which has better internal - * bit diffusion, but which is about 25% slower than tyche-i in JS. - me.next = function() { - var a = me.a, b = me.b, c = me.c, d = me.d; - a = (me.a + me.b | 0) >>> 0; - d = me.d ^ a; d = d << 16 ^ d >>> 16; - c = me.c + d | 0; - b = me.b ^ c; b = b << 12 ^ d >>> 20; - me.a = a = a + b | 0; - d = d ^ a; me.d = d = d << 8 ^ d >>> 24; - me.c = c = c + d | 0; - b = b ^ c; - return me.b = (b << 7 ^ b >>> 25); - } - */ - - me.a = 0; - me.b = 0; - me.c = 2654435769 | 0; - me.d = 1367130551; - - if (seed === Math.floor(seed)) { - // Integer seed. - me.a = (seed / 0x100000000) | 0; - me.b = seed | 0; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 20; k++) { - me.b ^= strseed.charCodeAt(k) | 0; - me.next(); - } -} - -function copy(f, t) { - t.a = f.a; - t.b = f.b; - t.c = f.c; - t.d = f.d; - return t; -}; - -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.tychei = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],156:[function(require,module,exports){ -// A Javascript implementaion of the "xor128" prng algorithm by -// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper - -(function(global, module, define) { - -function XorGen(seed) { - var me = this, strseed = ''; - - me.x = 0; - me.y = 0; - me.z = 0; - me.w = 0; - - // Set up generator function. - me.next = function() { - var t = me.x ^ (me.x << 11); - me.x = me.y; - me.y = me.z; - me.z = me.w; - return me.w ^= (me.w >>> 19) ^ t ^ (t >>> 8); - }; - - if (seed === (seed | 0)) { - // Integer seed. - me.x = seed; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 64; k++) { - me.x ^= strseed.charCodeAt(k) | 0; - me.next(); - } -} - -function copy(f, t) { - t.x = f.x; - t.y = f.y; - t.z = f.z; - t.w = f.w; - return t; -} - -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xor128 = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],157:[function(require,module,exports){ -// A Javascript implementaion of Richard Brent's Xorgens xor4096 algorithm. -// -// This fast non-cryptographic random number generator is designed for -// use in Monte-Carlo algorithms. It combines a long-period xorshift -// generator with a Weyl generator, and it passes all common batteries -// of stasticial tests for randomness while consuming only a few nanoseconds -// for each prng generated. For background on the generator, see Brent's -// paper: "Some long-period random number generators using shifts and xors." -// http://arxiv.org/pdf/1004.3115v1.pdf -// -// Usage: -// -// var xor4096 = require('xor4096'); -// random = xor4096(1); // Seed with int32 or string. -// assert.equal(random(), 0.1520436450538547); // (0, 1) range, 53 bits. -// assert.equal(random.int32(), 1806534897); // signed int32, 32 bits. -// -// For nonzero numeric keys, this impelementation provides a sequence -// identical to that by Brent's xorgens 3 implementaion in C. This -// implementation also provides for initalizing the generator with -// string seeds, or for saving and restoring the state of the generator. -// -// On Chrome, this prng benchmarks about 2.1 times slower than -// Javascript's built-in Math.random(). - -(function(global, module, define) { - -function XorGen(seed) { - var me = this; - - // Set up generator function. - me.next = function() { - var w = me.w, - X = me.X, i = me.i, t, v; - // Update Weyl generator. - me.w = w = (w + 0x61c88647) | 0; - // Update xor generator. - v = X[(i + 34) & 127]; - t = X[i = ((i + 1) & 127)]; - v ^= v << 13; - t ^= t << 17; - v ^= v >>> 15; - t ^= t >>> 12; - // Update Xor generator array state. - v = X[i] = v ^ t; - me.i = i; - // Result is the combination. - return (v + (w ^ (w >>> 16))) | 0; - }; - - function init(me, seed) { - var t, v, i, j, w, X = [], limit = 128; - if (seed === (seed | 0)) { - // Numeric seeds initialize v, which is used to generates X. - v = seed; - seed = null; - } else { - // String seeds are mixed into v and X one character at a time. - seed = seed + '\0'; - v = 0; - limit = Math.max(limit, seed.length); - } - // Initialize circular array and weyl value. - for (i = 0, j = -32; j < limit; ++j) { - // Put the unicode characters into the array, and shuffle them. - if (seed) v ^= seed.charCodeAt((j + 32) % seed.length); - // After 32 shuffles, take v as the starting w value. - if (j === 0) w = v; - v ^= v << 10; - v ^= v >>> 15; - v ^= v << 4; - v ^= v >>> 13; - if (j >= 0) { - w = (w + 0x61c88647) | 0; // Weyl. - t = (X[j & 127] ^= (v + w)); // Combine xor and weyl to init array. - i = (0 == t) ? i + 1 : 0; // Count zeroes. - } - } - // We have detected all zeroes; make the key nonzero. - if (i >= 128) { - X[(seed && seed.length || 0) & 127] = -1; - } - // Run the generator 512 times to further mix the state before using it. - // Factoring this as a function slows the main generator, so it is just - // unrolled here. The weyl generator is not advanced while warming up. - i = 127; - for (j = 4 * 128; j > 0; --j) { - v = X[(i + 34) & 127]; - t = X[i = ((i + 1) & 127)]; - v ^= v << 13; - t ^= t << 17; - v ^= v >>> 15; - t ^= t >>> 12; - X[i] = v ^ t; - } - // Storing state as object members is faster than using closure variables. - me.w = w; - me.X = X; - me.i = i; - } - - init(me, seed); -} - -function copy(f, t) { - t.i = f.i; - t.w = f.w; - t.X = f.X.slice(); - return t; -}; - -function impl(seed, opts) { - if (seed == null) seed = +(new Date); - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (state.X) copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xor4096 = impl; -} - -})( - this, // window object or global - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - -},{}],158:[function(require,module,exports){ -// A Javascript implementaion of the "xorshift7" algorithm by -// François Panneton and Pierre L'ecuyer: -// "On the Xorgshift Random Number Generators" -// http://saluc.engr.uconn.edu/refs/crypto/rng/panneton05onthexorshift.pdf - -(function(global, module, define) { - -function XorGen(seed) { - var me = this; - - // Set up generator function. - me.next = function() { - // Update xor generator. - var X = me.x, i = me.i, t, v, w; - t = X[i]; t ^= (t >>> 7); v = t ^ (t << 24); - t = X[(i + 1) & 7]; v ^= t ^ (t >>> 10); - t = X[(i + 3) & 7]; v ^= t ^ (t >>> 3); - t = X[(i + 4) & 7]; v ^= t ^ (t << 7); - t = X[(i + 7) & 7]; t = t ^ (t << 13); v ^= t ^ (t << 9); - X[i] = v; - me.i = (i + 1) & 7; - return v; - }; - - function init(me, seed) { - var j, w, X = []; - - if (seed === (seed | 0)) { - // Seed state array using a 32-bit integer. - w = X[0] = seed; - } else { - // Seed state using a string. - seed = '' + seed; - for (j = 0; j < seed.length; ++j) { - X[j & 7] = (X[j & 7] << 15) ^ - (seed.charCodeAt(j) + X[(j + 1) & 7] << 13); - } - } - // Enforce an array length of 8, not all zeroes. - while (X.length < 8) X.push(0); - for (j = 0; j < 8 && X[j] === 0; ++j); - if (j == 8) w = X[7] = -1; else w = X[j]; - - me.x = X; - me.i = 0; - - // Discard an initial 256 values. - for (j = 256; j > 0; --j) { - me.next(); - } - } - - init(me, seed); -} - -function copy(f, t) { - t.x = f.x.slice(); - t.i = f.i; - return t; -} - -function impl(seed, opts) { - if (seed == null) seed = +(new Date); - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (state.x) copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xorshift7 = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - -},{}],159:[function(require,module,exports){ -// A Javascript implementaion of the "xorwow" prng algorithm by -// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper - -(function(global, module, define) { - -function XorGen(seed) { - var me = this, strseed = ''; - - // Set up generator function. - me.next = function() { - var t = (me.x ^ (me.x >>> 2)); - me.x = me.y; me.y = me.z; me.z = me.w; me.w = me.v; - return (me.d = (me.d + 362437 | 0)) + - (me.v = (me.v ^ (me.v << 4)) ^ (t ^ (t << 1))) | 0; - }; - - me.x = 0; - me.y = 0; - me.z = 0; - me.w = 0; - me.v = 0; - - if (seed === (seed | 0)) { - // Integer seed. - me.x = seed; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 64; k++) { - me.x ^= strseed.charCodeAt(k) | 0; - if (k == strseed.length) { - me.d = me.x << 10 ^ me.x >>> 4; - } - me.next(); - } -} - -function copy(f, t) { - t.x = f.x; - t.y = f.y; - t.z = f.z; - t.w = f.w; - t.v = f.v; - t.d = f.d; - return t; -} - -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xorwow = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],160:[function(require,module,exports){ -/* -Copyright 2014 David Bau. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall 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. - -*/ - -(function (pool, math) { -// -// The following constants are related to IEEE 754 limits. -// -var global = this, - width = 256, // each RC4 output is 0 <= x < 256 - chunks = 6, // at least six RC4 outputs for each double - digits = 52, // there are 52 significant digits in a double - rngname = 'random', // rngname: name for Math.random and Math.seedrandom - startdenom = math.pow(width, chunks), - significance = math.pow(2, digits), - overflow = significance * 2, - mask = width - 1, - nodecrypto; // node.js crypto module, initialized at the bottom. - -// -// seedrandom() -// This is the seedrandom function described above. -// -function seedrandom(seed, options, callback) { - var key = []; - options = (options == true) ? { entropy: true } : (options || {}); - - // Flatten the seed string or build one from local entropy if needed. - var shortseed = mixkey(flatten( - options.entropy ? [seed, tostring(pool)] : - (seed == null) ? autoseed() : seed, 3), key); - - // Use the seed to initialize an ARC4 generator. - var arc4 = new ARC4(key); - - // This function returns a random double in [0, 1) that contains - // randomness in every bit of the mantissa of the IEEE 754 value. - var prng = function() { - var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48 - d = startdenom, // and denominator d = 2 ^ 48. - x = 0; // and no 'extra last byte'. - while (n < significance) { // Fill up all significant digits by - n = (n + x) * width; // shifting numerator and - d *= width; // denominator and generating a - x = arc4.g(1); // new least-significant-byte. - } - while (n >= overflow) { // To avoid rounding up, before adding - n /= 2; // last byte, shift everything - d /= 2; // right using integer math until - x >>>= 1; // we have exactly the desired bits. - } - return (n + x) / d; // Form the number within [0, 1). - }; - - prng.int32 = function() { return arc4.g(4) | 0; } - prng.quick = function() { return arc4.g(4) / 0x100000000; } - prng.double = prng; - - // Mix the randomness into accumulated entropy. - mixkey(tostring(arc4.S), pool); - - // Calling convention: what to return as a function of prng, seed, is_math. - return (options.pass || callback || - function(prng, seed, is_math_call, state) { - if (state) { - // Load the arc4 state from the given state if it has an S array. - if (state.S) { copy(state, arc4); } - // Only provide the .state method if requested via options.state. - prng.state = function() { return copy(arc4, {}); } - } - - // If called as a method of Math (Math.seedrandom()), mutate - // Math.random because that is how seedrandom.js has worked since v1.0. - if (is_math_call) { math[rngname] = prng; return seed; } - - // Otherwise, it is a newer calling convention, so return the - // prng directly. - else return prng; - })( - prng, - shortseed, - 'global' in options ? options.global : (this == math), - options.state); -} -math['seed' + rngname] = seedrandom; - -// -// ARC4 -// -// An ARC4 implementation. The constructor takes a key in the form of -// an array of at most (width) integers that should be 0 <= x < (width). -// -// The g(count) method returns a pseudorandom integer that concatenates -// the next (count) outputs from ARC4. Its return value is a number x -// that is in the range 0 <= x < (width ^ count). -// -function ARC4(key) { - var t, keylen = key.length, - me = this, i = 0, j = me.i = me.j = 0, s = me.S = []; - - // The empty key [] is treated as [0]. - if (!keylen) { key = [keylen++]; } - - // Set up S using the standard key scheduling algorithm. - while (i < width) { - s[i] = i++; - } - for (i = 0; i < width; i++) { - s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))]; - s[j] = t; - } - - // The "g" method returns the next (count) outputs as one number. - (me.g = function(count) { - // Using instance members instead of closure state nearly doubles speed. - var t, r = 0, - i = me.i, j = me.j, s = me.S; - while (count--) { - t = s[i = mask & (i + 1)]; - r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))]; - } - me.i = i; me.j = j; - return r; - // For robust unpredictability, the function call below automatically - // discards an initial batch of values. This is called RC4-drop[256]. - // See http://google.com/search?q=rsa+fluhrer+response&btnI - })(width); -} - -// -// copy() -// Copies internal state of ARC4 to or from a plain object. -// -function copy(f, t) { - t.i = f.i; - t.j = f.j; - t.S = f.S.slice(); - return t; -}; - -// -// flatten() -// Converts an object tree to nested arrays of strings. -// -function flatten(obj, depth) { - var result = [], typ = (typeof obj), prop; - if (depth && typ == 'object') { - for (prop in obj) { - try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {} - } - } - return (result.length ? result : typ == 'string' ? obj : obj + '\0'); -} - -// -// mixkey() -// Mixes a string seed into a key that is an array of integers, and -// returns a shortened string seed that is equivalent to the result key. -// -function mixkey(seed, key) { - var stringseed = seed + '', smear, j = 0; - while (j < stringseed.length) { - key[mask & j] = - mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++)); - } - return tostring(key); -} - -// -// autoseed() -// Returns an object for autoseeding, using window.crypto and Node crypto -// module if available. -// -function autoseed() { - try { - var out; - if (nodecrypto && (out = nodecrypto.randomBytes)) { - // The use of 'out' to remember randomBytes makes tight minified code. - out = out(width); - } else { - out = new Uint8Array(width); - (global.crypto || global.msCrypto).getRandomValues(out); - } - return tostring(out); - } catch (e) { - var browser = global.navigator, - plugins = browser && browser.plugins; - return [+new Date, global, plugins, global.screen, tostring(pool)]; - } -} - -// -// tostring() -// Converts an array of charcodes to a string -// -function tostring(a) { - return String.fromCharCode.apply(0, a); -} - -// -// When seedrandom.js is loaded, we immediately mix a few bits -// from the built-in RNG into the entropy pool. Because we do -// not want to interfere with deterministic PRNG state later, -// seedrandom will not call math.random on its own again after -// initialization. -// -mixkey(math.random(), pool); - -// -// Nodejs and AMD support: export the implementation as a module using -// either convention. -// -if ((typeof module) == 'object' && module.exports) { - module.exports = seedrandom; - // When in node.js, try using crypto package for autoseeding. - try { - nodecrypto = require('crypto'); - } catch (ex) {} -} else if ((typeof define) == 'function' && define.amd) { - define(function() { return seedrandom; }); -} - -// End anonymous scope, and pass initial values. -})( - [], // pool: entropy pool starts empty - Math // math: package containing random, pow, and seedrandom -); - -},{"crypto":2}],161:[function(require,module,exports){ -(function (global){ -/*! https://mths.be/utf8js v2.1.2 by @mathias */ -;(function(root) { - - // Detect free variables `exports` - var freeExports = typeof exports == 'object' && exports; - - // Detect free variable `module` - var freeModule = typeof module == 'object' && module && - module.exports == freeExports && module; - - // Detect free variable `global`, from Node.js or Browserified code, - // and use it as `root` - var freeGlobal = typeof global == 'object' && global; - if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { - root = freeGlobal; - } - - /*--------------------------------------------------------------------------*/ - - var stringFromCharCode = String.fromCharCode; - - // Taken from https://mths.be/punycode - function ucs2decode(string) { - var output = []; - var counter = 0; - var length = string.length; - var value; - var extra; - while (counter < length) { - value = string.charCodeAt(counter++); - if (value >= 0xD800 && value <= 0xDBFF && counter < length) { - // high surrogate, and there is a next character - extra = string.charCodeAt(counter++); - if ((extra & 0xFC00) == 0xDC00) { // low surrogate - output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); - } else { - // unmatched surrogate; only append this code unit, in case the next - // code unit is the high surrogate of a surrogate pair - output.push(value); - counter--; - } - } else { - output.push(value); - } - } - return output; - } - - // Taken from https://mths.be/punycode - function ucs2encode(array) { - var length = array.length; - var index = -1; - var value; - var output = ''; - while (++index < length) { - value = array[index]; - if (value > 0xFFFF) { - value -= 0x10000; - output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); - value = 0xDC00 | value & 0x3FF; - } - output += stringFromCharCode(value); - } - return output; - } - - function checkScalarValue(codePoint) { - if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { - throw Error( - 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + - ' is not a scalar value' - ); - } - } - /*--------------------------------------------------------------------------*/ - - function createByte(codePoint, shift) { - return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); - } - - function encodeCodePoint(codePoint) { - if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence - return stringFromCharCode(codePoint); - } - var symbol = ''; - if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence - symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); - } - else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence - checkScalarValue(codePoint); - symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); - symbol += createByte(codePoint, 6); - } - else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence - symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); - symbol += createByte(codePoint, 12); - symbol += createByte(codePoint, 6); - } - symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); - return symbol; - } - - function utf8encode(string) { - var codePoints = ucs2decode(string); - var length = codePoints.length; - var index = -1; - var codePoint; - var byteString = ''; - while (++index < length) { - codePoint = codePoints[index]; - byteString += encodeCodePoint(codePoint); - } - return byteString; - } - - /*--------------------------------------------------------------------------*/ - - function readContinuationByte() { - if (byteIndex >= byteCount) { - throw Error('Invalid byte index'); - } - - var continuationByte = byteArray[byteIndex] & 0xFF; - byteIndex++; - - if ((continuationByte & 0xC0) == 0x80) { - return continuationByte & 0x3F; - } - - // If we end up here, it?™s not a continuation byte - throw Error('Invalid continuation byte'); - } - - function decodeSymbol() { - var byte1; - var byte2; - var byte3; - var byte4; - var codePoint; - - if (byteIndex > byteCount) { - throw Error('Invalid byte index'); - } - - if (byteIndex == byteCount) { - return false; - } - - // Read first byte - byte1 = byteArray[byteIndex] & 0xFF; - byteIndex++; - - // 1-byte sequence (no continuation bytes) - if ((byte1 & 0x80) == 0) { - return byte1; - } - - // 2-byte sequence - if ((byte1 & 0xE0) == 0xC0) { - byte2 = readContinuationByte(); - codePoint = ((byte1 & 0x1F) << 6) | byte2; - if (codePoint >= 0x80) { - return codePoint; - } else { - throw Error('Invalid continuation byte'); - } - } - - // 3-byte sequence (may include unpaired surrogates) - if ((byte1 & 0xF0) == 0xE0) { - byte2 = readContinuationByte(); - byte3 = readContinuationByte(); - codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; - if (codePoint >= 0x0800) { - checkScalarValue(codePoint); - return codePoint; - } else { - throw Error('Invalid continuation byte'); - } - } - - // 4-byte sequence - if ((byte1 & 0xF8) == 0xF0) { - byte2 = readContinuationByte(); - byte3 = readContinuationByte(); - byte4 = readContinuationByte(); - codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | - (byte3 << 0x06) | byte4; - if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { - return codePoint; - } - } - - throw Error('Invalid UTF-8 detected'); - } - - var byteArray; - var byteCount; - var byteIndex; - function utf8decode(byteString) { - byteArray = ucs2decode(byteString); - byteCount = byteArray.length; - byteIndex = 0; - var codePoints = []; - var tmp; - while ((tmp = decodeSymbol()) !== false) { - codePoints.push(tmp); - } - return ucs2encode(codePoints); - } - - /*--------------------------------------------------------------------------*/ - - var utf8 = { - 'version': '2.1.2', - 'encode': utf8encode, - 'decode': utf8decode - }; - - // Some AMD build optimizers, like r.js, check for specific condition patterns - // like the following: - if ( - typeof define == 'function' && - typeof define.amd == 'object' && - define.amd - ) { - define(function() { - return utf8; - }); - } else if (freeExports && !freeExports.nodeType) { - if (freeModule) { // in Node.js or RingoJS v0.8.0+ - freeModule.exports = utf8; - } else { // in Narwhal or RingoJS v0.7.0- - var object = {}; - var hasOwnProperty = object.hasOwnProperty; - for (var key in utf8) { - hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); - } - } - } else { // in Rhino or a web browser - root.utf8 = utf8; - } - -}(this)); - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}]},{},[1]); diff --git a/teachable_machine_boilerplate_20180818/teachable_machine.js b/teachable_machine_boilerplate_20180818/teachable_machine.js deleted file mode 100644 index 9ab21812b2..0000000000 --- a/teachable_machine_boilerplate_20180818/teachable_machine.js +++ /dev/null @@ -1,45 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function teachable_machine_open() { - if (document.getElementById("train")) - { - document.getElementById("train").innerHTML = ""; - document.getElementById("probability").innerHTML = ""; - } - else - { - var div = document.createElement('div'); - div.id = "train"; - div.style.position = 'absolute'; - div.style.display = 'none'; - document.body.appendChild(div); - - var div1 = document.createElement('div'); - div1.id = "probability"; - div1.style.position = 'absolute'; - div1.style.display = 'none'; - document.body.appendChild(div1); - } - - /* - var s = document.createElement("script") - s.src = "https://rawgit.com/fustyles/webduino/temp/teachable_machine_boilerplate_20180808/build.js"; - document.getElementsByTagName("head")[0].appendChild(s); - */ - } - - function teachable_machine_proportion(input_property){ - if (input_property=="train") - return Number(document.getElementById("train").innerHTML); - else if (input_property=="probability") - return Number(document.getElementById("probability").innerHTML); - } - - window.teachable_machine_open = teachable_machine_open; - window.teachable_machine_proportion = teachable_machine_proportion; - -}(window, window.document)); diff --git a/telegrambot_Gemini_Vision.gs b/telegrambot_Gemini_Vision.gs new file mode 100644 index 0000000000..64777c46e4 --- /dev/null +++ b/telegrambot_Gemini_Vision.gs @@ -0,0 +1,311 @@ +/* + +Author : ChungYi Fu (Kaohsiung, Taiwan) 2025/3/31 00:00 +https://www.facebook.com/francefu +Telegram Bot Webhook & Google Apps script & Gemini Vision + +若傳訊無回應: +1. Gemini api額度已用盡或Key已失效。 +2. 不明原因,可能太久無人使用自動停用,重新佈署或重建Apps script專案並開放存取權限。 +3. Apps script程式碼有bug。 +4. Telegram Bot未執行START。 +5. 上傳圖檔已過時無法取得或圖檔太小模糊不清,請重新上傳圖檔。 +6. 對話輸入"clear"清除歷史對話資料。 + +Apps Script +https://script.google.com/home + +Gemini Vision +https://ai.google.dev/gemini-api/docs/vision + +Telegram Bot API +https://core.telegram.org/bots/api + +Webhook Set: (瀏覽器貼入網址執行) +https://api.telegram.org/bot{權杖}/setWebhook?allowed_updates=["message"]&url={Apps Script網址} + +Webhook Delete: (瀏覽器貼入網址執行) +https://api.telegram.org/bot{權杖}/deleteWebhook + +Webhook Info: (瀏覽器貼入網址執行) +https://api.telegram.org/bot{權杖}/getWebhookInfo + +*/ + +// Telegram bot +let channel_access_TOKEN = "xxxxx"; +let channel_access_UserID = "xxxxx"; //暫無使用 + +// Gemini設定 +let Gemini_api_key = "xxxxx"; +let gemini_chat_times_max = 100; //聊天次數超過則自動清除對話紀錄 +let chat_message_remind = ""; //每次對話內容最後附加的文字,可不填 + +let scriptProperties = PropertiesService.getScriptProperties(); + +let getTelegrambotData = { + "chatId": "", + "userMessage": "", + "userImageId": "", + "userImage": "", + "replayToMessage": "", + "date": "" +} + +let gemini_chat_messages = []; +let gemini_vision_urls = []; + +function doPost(e) { + if (e.postData) { + let telegrambot_response = "請先上傳影像或輸入影像網址,再引用影像或網址回覆輸入提示詞!"; + let chat_message = "請分析影像中的場景與情境,若有文字資料請將內容進行重點摘要。"; + + let msg = JSON.parse(e.postData.contents); + + getTelegrambotData.chatId = msg['message']['chat']['id']; + + if (scriptProperties.getProperty("messages")==""||scriptProperties.getProperty("messages")==null) + gemini_chat_messages = []; + else { + gemini_chat_messages = JSON.parse(scriptProperties.getProperty("messages")); + if (gemini_chat_messages.length > gemini_chat_times_max*2) + msg['message']['text'] = "clear"; + } + + if (scriptProperties.getProperty("urls")==""||scriptProperties.getProperty("urls")==null) + gemini_vision_urls = []; + else + gemini_vision_urls = JSON.parse(scriptProperties.getProperty("urls")); + + if (msg['message']['text']) { + getTelegrambotData.userMessage = msg['message']['text'].trim(); + + if (getTelegrambotData.userMessage.toLowerCase()=="clear") { + gemini_clear(); + telegrambot_response = "Conversation history is full and has been cleared."; + } else if (getTelegrambotData.userMessage.toLowerCase().indexOf("https://")==0) { + let urlData = getTelegrambotData.userMessage.split("\n"); + if (urlData.length>1) + chat_message = getTelegrambotData.userMessage.replace(urlData[0], "").trim(); + getTelegrambotData.date = msg['message']['date']; + saveHistoricalURL(getTelegrambotData.date, urlData[0].trim()); + getTelegrambotData.userImage = getImageUrlBase64(urlData[0].trim()); + //sendPhotoToTelegramBot(channel_access_TOKEN, getTelegrambotData.chatId, urlData[0].trim()); + } else if (msg['message']['reply_to_message']) { + getTelegrambotData.replayToMessage = msg['message']['reply_to_message']; + getTelegrambotData.date = getTelegrambotData.replayToMessage['date']; + chat_message = getTelegrambotData.userMessage; + let imageURL = getHistoricalURL(getTelegrambotData.date); + if (imageURL) + getTelegrambotData.userImage = getImageUrlBase64(imageURL); + } else { + gemini_messages_insert_request(getTelegrambotData.userMessage + chat_message_remind); + telegrambot_response = sendMessageToGeminiChat(Gemini_api_key, gemini_chat_messages); + gemini_messages_insert_response(telegrambot_response); + } + } + else if (msg['message']['photo']) { + getTelegrambotData.date = msg['message']['date']; + getTelegrambotData.userImageId = msg['message']['photo'][0]['file_id']; + getTelegrambotData.userImage = getTelegramBotImageBase64(channel_access_TOKEN, getTelegrambotData.userImageId); + } + + if (getTelegrambotData.userImage) { + gemini_messages_insert_request(chat_message+" (Image Number:"+getTelegrambotData.date+")"); + telegrambot_response = sendImageToGeminiVision(Gemini_api_key, chat_message + chat_message_remind, getTelegrambotData.userImage); + gemini_messages_insert_response(telegrambot_response); + } + + sendMessageToTelegramBot(channel_access_TOKEN, getTelegrambotData.chatId, telegrambot_response); + } +} + +function saveHistoricalURL(visionDate, visionURL) { + gemini_vision_urls.push([visionDate, visionURL]); + scriptProperties.setProperty("urls", JSON.stringify(gemini_vision_urls)); +} + +function getHistoricalURL(visionDate) { + for (let i=0;i - - - - 4 - - - - - - diff --git a/test_teachable_machine_boilerplate/build.js b/test_teachable_machine_boilerplate/build.js deleted file mode 100644 index ed0f5ace7c..0000000000 --- a/test_teachable_machine_boilerplate/build.js +++ /dev/null @@ -1,21011 +0,0 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { - this.knn.predictClass(image).then(function (res) { - var max=0,maxid=-1; - for (var i = 0; i < NUM_CLASSES; i++) { - // Make the predicted class bold - if (res.classIndex == i) { - _this2.infoTexts[i].style.fontWeight = 'bold'; - } else { - _this2.infoTexts[i].style.fontWeight = 'normal'; - } - - // Update info text - - if (exampleCount[i] > 0) { - _this2.infoTexts[i].innerText = ' ' + exampleCount[i] + ' examples - ' + res.confidences[i] * 100 + '%'; - if ((res.confidences[i] * 100) >= max) - { - max=res.confidences[i] * 100; - maxid=i; - } - } - } - document.getElementById("train").innerHTML = maxid ; - document.getElementById("probability").innerHTML = max ; - }) - // Dispose image when done - .then(function () { - return image.dispose(); - }); - } else { - image.dispose(); - } - } - this.timer = requestAnimationFrame(this.animate.bind(this)); - } - }]); - - return Main; -}(); - -window.addEventListener('load', function () { - return new Main(); -}); - -},{"deeplearn":67,"deeplearn-knn-image-classifier":3}],2:[function(require,module,exports){ - -},{}],3:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var knn_image_classifier_1 = require("./knn_image_classifier"); -exports.KNNImageClassifier = knn_image_classifier_1.KNNImageClassifier; - -},{"./knn_image_classifier":4}],4:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dl = require("deeplearn"); -var deeplearn_squeezenet_1 = require("deeplearn-squeezenet"); -var model_util = require("../util"); -var KNNImageClassifier = (function () { - function KNNImageClassifier(numClasses, k) { - this.numClasses = numClasses; - this.k = k; - this.classLogitsMatrices = []; - this.classExampleCount = []; - this.varsLoaded = false; - this.squashLogitsDenominator = dl.scalar(300); - for (var i = 0; i < this.numClasses; i++) { - this.classLogitsMatrices.push(null); - this.classExampleCount.push(0); - } - this.squeezeNet = new deeplearn_squeezenet_1.SqueezeNet(); - } - KNNImageClassifier.prototype.load = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.squeezeNet.load()]; - case 1: - _a.sent(); - this.varsLoaded = true; - return [2]; - } - }); - }); - }; - KNNImageClassifier.prototype.clearClass = function (classIndex) { - if (classIndex >= this.numClasses) { - console.log('Cannot clear invalid class ${classIndex}'); - return; - } - this.classLogitsMatrices[classIndex] = null; - this.classExampleCount[classIndex] = 0; - this.clearTrainLogitsMatrix(); - }; - KNNImageClassifier.prototype.addImage = function (image, classIndex) { - var _this = this; - if (!this.varsLoaded) { - console.warn('Cannot add images until vars have been loaded.'); - return; - } - if (classIndex >= this.numClasses) { - console.warn('Cannot add to invalid class ${classIndex}'); - } - this.clearTrainLogitsMatrix(); - dl.tidy(function () { - var logits = _this.squeezeNet.predict(image); - var imageLogits = _this.normalizeVector(logits); - var logitsSize = imageLogits.shape[0]; - if (_this.classLogitsMatrices[classIndex] == null) { - _this.classLogitsMatrices[classIndex] = imageLogits.as2D(1, logitsSize); - } - else { - var newTrainLogitsMatrix = _this.classLogitsMatrices[classIndex] - .as2D(_this.classExampleCount[classIndex], logitsSize) - .concat(imageLogits.as2D(1, logitsSize), 0); - _this.classLogitsMatrices[classIndex].dispose(); - _this.classLogitsMatrices[classIndex] = newTrainLogitsMatrix; - } - dl.keep(_this.classLogitsMatrices[classIndex]); - _this.classExampleCount[classIndex]++; - }); - }; - KNNImageClassifier.prototype.predict = function (image) { - var _this = this; - if (!this.varsLoaded) { - throw new Error('Cannot predict until vars have been loaded.'); - } - return dl.tidy(function () { - var logits = _this.squeezeNet.predict(image); - var imageLogits = _this.normalizeVector(logits); - var logitsSize = imageLogits.shape[0]; - if (_this.trainLogitsMatrix == null) { - var newTrainLogitsMatrix = null; - for (var i = 0; i < _this.numClasses; i++) { - newTrainLogitsMatrix = _this.concatWithNulls(newTrainLogitsMatrix, _this.classLogitsMatrices[i]); - } - _this.trainLogitsMatrix = newTrainLogitsMatrix; - } - if (_this.trainLogitsMatrix == null) { - console.warn('Cannot predict without providing training images.'); - return null; - } - dl.keep(_this.trainLogitsMatrix); - var numExamples = _this.getNumExamples(); - return _this.trainLogitsMatrix.as2D(numExamples, logitsSize) - .matMul(imageLogits.as2D(logitsSize, 1)) - .as1D(); - }); - }; - KNNImageClassifier.prototype.predictClass = function (image) { - return __awaiter(this, void 0, void 0, function () { - var imageClass, confidences, knn, numExamples, kVal, topK, _a, _b, topKIndices, indicesForClasses, topKCountsForClasses, i, num, i, classForEntry, topConfidence, i, probability; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - imageClass = -1; - confidences = new Array(this.numClasses); - if (!this.varsLoaded) { - throw new Error('Cannot predict until vars have been loaded.'); - } - knn = this.predict(image).asType('float32'); - numExamples = this.getNumExamples(); - kVal = Math.min(this.k, numExamples); - _b = (_a = model_util).topK; - return [4, knn.data()]; - case 1: - topK = _b.apply(_a, [_c.sent(), kVal]); - knn.dispose(); - topKIndices = topK.indices; - if (topKIndices == null) { - return [2, { classIndex: imageClass, confidences: confidences }]; - } - indicesForClasses = []; - topKCountsForClasses = []; - for (i = 0; i < this.numClasses; i++) { - topKCountsForClasses.push(0); - num = this.classExampleCount[i]; - if (i > 0) { - num += indicesForClasses[i - 1]; - } - indicesForClasses.push(num); - } - for (i = 0; i < topKIndices.length; i++) { - for (classForEntry = 0; classForEntry < indicesForClasses.length; classForEntry++) { - if (topKIndices[i] < indicesForClasses[classForEntry]) { - topKCountsForClasses[classForEntry]++; - break; - } - } - } - topConfidence = 0; - for (i = 0; i < this.numClasses; i++) { - probability = topKCountsForClasses[i] / kVal; - if (probability > topConfidence) { - topConfidence = probability; - imageClass = i; - } - confidences[i] = probability; - } - return [2, { classIndex: imageClass, confidences: confidences }]; - } - }); - }); - }; - KNNImageClassifier.prototype.getClassExampleCount = function () { - return this.classExampleCount; - }; - KNNImageClassifier.prototype.clearTrainLogitsMatrix = function () { - if (this.trainLogitsMatrix != null) { - this.trainLogitsMatrix.dispose(); - this.trainLogitsMatrix = null; - } - }; - KNNImageClassifier.prototype.concatWithNulls = function (ndarray1, ndarray2) { - if (ndarray1 == null && ndarray2 == null) { - return null; - } - if (ndarray1 == null) { - return ndarray2.clone(); - } - else if (ndarray2 === null) { - return ndarray1.clone(); - } - return ndarray1.concat(ndarray2, 0); - }; - KNNImageClassifier.prototype.normalizeVector = function (vec) { - var squashedVec = dl.div(vec, this.squashLogitsDenominator); - var sqrtSum = squashedVec.square().sum().sqrt(); - return dl.div(squashedVec, sqrtSum); - }; - KNNImageClassifier.prototype.getNumExamples = function () { - var total = 0; - for (var i = 0; i < this.classExampleCount.length; i++) { - total += this.classExampleCount[i]; - } - return total; - }; - KNNImageClassifier.prototype.dispose = function () { - this.squeezeNet.dispose(); - this.clearTrainLogitsMatrix(); - this.classLogitsMatrices.forEach(function (classLogitsMatrix) { return classLogitsMatrix.dispose(); }); - this.squashLogitsDenominator.dispose(); - }; - return KNNImageClassifier; -}()); -exports.KNNImageClassifier = KNNImageClassifier; - -},{"../util":5,"deeplearn":67,"deeplearn-squeezenet":7}],5:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function topK(values, k) { - var valuesAndIndices = []; - for (var i = 0; i < values.length; i++) { - valuesAndIndices.push({ value: values[i], index: i }); - } - valuesAndIndices.sort(function (a, b) { - return b.value - a.value; - }); - var topkValues = new Float32Array(k); - var topkIndices = new Int32Array(k); - for (var i = 0; i < k; i++) { - topkValues[i] = valuesAndIndices[i].value; - topkIndices[i] = valuesAndIndices[i].index; - } - return { values: topkValues, indices: topkIndices }; -} -exports.topK = topK; - -},{}],6:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.IMAGENET_CLASSES = { - 0: 'tench, Tinca tinca', - 1: 'goldfish, Carassius auratus', - 2: 'great white shark, white shark, man-eater, man-eating shark, ' + - 'Carcharodon carcharias', - 3: 'tiger shark, Galeocerdo cuvieri', - 4: 'hammerhead, hammerhead shark', - 5: 'electric ray, crampfish, numbfish, torpedo', - 6: 'stingray', - 7: 'cock', - 8: 'hen', - 9: 'ostrich, Struthio camelus', - 10: 'brambling, Fringilla montifringilla', - 11: 'goldfinch, Carduelis carduelis', - 12: 'house finch, linnet, Carpodacus mexicanus', - 13: 'junco, snowbird', - 14: 'indigo bunting, indigo finch, indigo bird, Passerina cyanea', - 15: 'robin, American robin, Turdus migratorius', - 16: 'bulbul', - 17: 'jay', - 18: 'magpie', - 19: 'chickadee', - 20: 'water ouzel, dipper', - 21: 'kite', - 22: 'bald eagle, American eagle, Haliaeetus leucocephalus', - 23: 'vulture', - 24: 'great grey owl, great gray owl, Strix nebulosa', - 25: 'European fire salamander, Salamandra salamandra', - 26: 'common newt, Triturus vulgaris', - 27: 'eft', - 28: 'spotted salamander, Ambystoma maculatum', - 29: 'axolotl, mud puppy, Ambystoma mexicanum', - 30: 'bullfrog, Rana catesbeiana', - 31: 'tree frog, tree-frog', - 32: 'tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui', - 33: 'loggerhead, loggerhead turtle, Caretta caretta', - 34: 'leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea', - 35: 'mud turtle', - 36: 'terrapin', - 37: 'box turtle, box tortoise', - 38: 'banded gecko', - 39: 'common iguana, iguana, Iguana iguana', - 40: 'American chameleon, anole, Anolis carolinensis', - 41: 'whiptail, whiptail lizard', - 42: 'agama', - 43: 'frilled lizard, Chlamydosaurus kingi', - 44: 'alligator lizard', - 45: 'Gila monster, Heloderma suspectum', - 46: 'green lizard, Lacerta viridis', - 47: 'African chameleon, Chamaeleo chamaeleon', - 48: 'Komodo dragon, Komodo lizard, dragon lizard, giant lizard, ' + - 'Varanus komodoensis', - 49: 'African crocodile, Nile crocodile, Crocodylus niloticus', - 50: 'American alligator, Alligator mississipiensis', - 51: 'triceratops', - 52: 'thunder snake, worm snake, Carphophis amoenus', - 53: 'ringneck snake, ring-necked snake, ring snake', - 54: 'hognose snake, puff adder, sand viper', - 55: 'green snake, grass snake', - 56: 'king snake, kingsnake', - 57: 'garter snake, grass snake', - 58: 'water snake', - 59: 'vine snake', - 60: 'night snake, Hypsiglena torquata', - 61: 'boa constrictor, Constrictor constrictor', - 62: 'rock python, rock snake, Python sebae', - 63: 'Indian cobra, Naja naja', - 64: 'green mamba', - 65: 'sea snake', - 66: 'horned viper, cerastes, sand viper, horned asp, Cerastes cornutus', - 67: 'diamondback, diamondback rattlesnake, Crotalus adamanteus', - 68: 'sidewinder, horned rattlesnake, Crotalus cerastes', - 69: 'trilobite', - 70: 'harvestman, daddy longlegs, Phalangium opilio', - 71: 'scorpion', - 72: 'black and gold garden spider, Argiope aurantia', - 73: 'barn spider, Araneus cavaticus', - 74: 'garden spider, Aranea diademata', - 75: 'black widow, Latrodectus mactans', - 76: 'tarantula', - 77: 'wolf spider, hunting spider', - 78: 'tick', - 79: 'centipede', - 80: 'black grouse', - 81: 'ptarmigan', - 82: 'ruffed grouse, partridge, Bonasa umbellus', - 83: 'prairie chicken, prairie grouse, prairie fowl', - 84: 'peacock', - 85: 'quail', - 86: 'partridge', - 87: 'African grey, African gray, Psittacus erithacus', - 88: 'macaw', - 89: 'sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita', - 90: 'lorikeet', - 91: 'coucal', - 92: 'bee eater', - 93: 'hornbill', - 94: 'hummingbird', - 95: 'jacamar', - 96: 'toucan', - 97: 'drake', - 98: 'red-breasted merganser, Mergus serrator', - 99: 'goose', - 100: 'black swan, Cygnus atratus', - 101: 'tusker', - 102: 'echidna, spiny anteater, anteater', - 103: 'platypus, duckbill, duckbilled platypus, duck-billed platypus, ' + - 'Ornithorhynchus anatinus', - 104: 'wallaby, brush kangaroo', - 105: 'koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus', - 106: 'wombat', - 107: 'jelly fish', - 108: 'sea anemone, anemone', - 109: 'brain coral', - 110: 'flatworm, platyhelminth', - 111: 'nematode, nematode worm, roundworm', - 112: 'conch', - 113: 'snail', - 114: 'slug', - 115: 'sea slug, nudibranch', - 116: 'chiton, coat-of-mail shell, sea cradle, polyplacophore', - 117: 'chambered nautilus, pearly nautilus, nautilus', - 118: 'Dungeness crab, Cancer magister', - 119: 'rock crab, Cancer irroratus', - 120: 'fiddler crab', - 121: 'king crab, Alaska crab, Alaskan king crab, Alaska king crab, ' + - 'Paralithodes camtschatica', - 122: 'American lobster, Northern lobster, Maine lobster, Homarus americanus', - 123: 'spiny lobster, langouste, rock lobster, crawfish, crayfish, sea ' + - 'crawfish', - 124: 'crayfish, crawfish, crawdad, crawdaddy', - 125: 'hermit crab', - 126: 'isopod', - 127: 'white stork, Ciconia ciconia', - 128: 'black stork, Ciconia nigra', - 129: 'spoonbill', - 130: 'flamingo', - 131: 'little blue heron, Egretta caerulea', - 132: 'American egret, great white heron, Egretta albus', - 133: 'bittern', - 134: 'crane', - 135: 'limpkin, Aramus pictus', - 136: 'European gallinule, Porphyrio porphyrio', - 137: 'American coot, marsh hen, mud hen, water hen, Fulica americana', - 138: 'bustard', - 139: 'ruddy turnstone, Arenaria interpres', - 140: 'red-backed sandpiper, dunlin, Erolia alpina', - 141: 'redshank, Tringa totanus', - 142: 'dowitcher', - 143: 'oystercatcher, oyster catcher', - 144: 'pelican', - 145: 'king penguin, Aptenodytes patagonica', - 146: 'albatross, mollymawk', - 147: 'grey whale, gray whale, devilfish, Eschrichtius gibbosus, ' + - 'Eschrichtius robustus', - 148: 'killer whale, killer, orca, grampus, sea wolf, Orcinus orca', - 149: 'dugong, Dugong dugon', - 150: 'sea lion', - 151: 'Chihuahua', - 152: 'Japanese spaniel', - 153: 'Maltese dog, Maltese terrier, Maltese', - 154: 'Pekinese, Pekingese, Peke', - 155: 'Shih-Tzu', - 156: 'Blenheim spaniel', - 157: 'papillon', - 158: 'toy terrier', - 159: 'Rhodesian ridgeback', - 160: 'Afghan hound, Afghan', - 161: 'basset, basset hound', - 162: 'beagle', - 163: 'bloodhound, sleuthhound', - 164: 'bluetick', - 165: 'black-and-tan coonhound', - 166: 'Walker hound, Walker foxhound', - 167: 'English foxhound', - 168: 'redbone', - 169: 'borzoi, Russian wolfhound', - 170: 'Irish wolfhound', - 171: 'Italian greyhound', - 172: 'whippet', - 173: 'Ibizan hound, Ibizan Podenco', - 174: 'Norwegian elkhound, elkhound', - 175: 'otterhound, otter hound', - 176: 'Saluki, gazelle hound', - 177: 'Scottish deerhound, deerhound', - 178: 'Weimaraner', - 179: 'Staffordshire bullterrier, Staffordshire bull terrier', - 180: 'American Staffordshire terrier, Staffordshire terrier, American pit ' + - 'bull terrier, pit bull terrier', - 181: 'Bedlington terrier', - 182: 'Border terrier', - 183: 'Kerry blue terrier', - 184: 'Irish terrier', - 185: 'Norfolk terrier', - 186: 'Norwich terrier', - 187: 'Yorkshire terrier', - 188: 'wire-haired fox terrier', - 189: 'Lakeland terrier', - 190: 'Sealyham terrier, Sealyham', - 191: 'Airedale, Airedale terrier', - 192: 'cairn, cairn terrier', - 193: 'Australian terrier', - 194: 'Dandie Dinmont, Dandie Dinmont terrier', - 195: 'Boston bull, Boston terrier', - 196: 'miniature schnauzer', - 197: 'giant schnauzer', - 198: 'standard schnauzer', - 199: 'Scotch terrier, Scottish terrier, Scottie', - 200: 'Tibetan terrier, chrysanthemum dog', - 201: 'silky terrier, Sydney silky', - 202: 'soft-coated wheaten terrier', - 203: 'West Highland white terrier', - 204: 'Lhasa, Lhasa apso', - 205: 'flat-coated retriever', - 206: 'curly-coated retriever', - 207: 'golden retriever', - 208: 'Labrador retriever', - 209: 'Chesapeake Bay retriever', - 210: 'German short-haired pointer', - 211: 'vizsla, Hungarian pointer', - 212: 'English setter', - 213: 'Irish setter, red setter', - 214: 'Gordon setter', - 215: 'Brittany spaniel', - 216: 'clumber, clumber spaniel', - 217: 'English springer, English springer spaniel', - 218: 'Welsh springer spaniel', - 219: 'cocker spaniel, English cocker spaniel, cocker', - 220: 'Sussex spaniel', - 221: 'Irish water spaniel', - 222: 'kuvasz', - 223: 'schipperke', - 224: 'groenendael', - 225: 'malinois', - 226: 'briard', - 227: 'kelpie', - 228: 'komondor', - 229: 'Old English sheepdog, bobtail', - 230: 'Shetland sheepdog, Shetland sheep dog, Shetland', - 231: 'collie', - 232: 'Border collie', - 233: 'Bouvier des Flandres, Bouviers des Flandres', - 234: 'Rottweiler', - 235: 'German shepherd, German shepherd dog, German police dog, alsatian', - 236: 'Doberman, Doberman pinscher', - 237: 'miniature pinscher', - 238: 'Greater Swiss Mountain dog', - 239: 'Bernese mountain dog', - 240: 'Appenzeller', - 241: 'EntleBucher', - 242: 'boxer', - 243: 'bull mastiff', - 244: 'Tibetan mastiff', - 245: 'French bulldog', - 246: 'Great Dane', - 247: 'Saint Bernard, St Bernard', - 248: 'Eskimo dog, husky', - 249: 'malamute, malemute, Alaskan malamute', - 250: 'Siberian husky', - 251: 'dalmatian, coach dog, carriage dog', - 252: 'affenpinscher, monkey pinscher, monkey dog', - 253: 'basenji', - 254: 'pug, pug-dog', - 255: 'Leonberg', - 256: 'Newfoundland, Newfoundland dog', - 257: 'Great Pyrenees', - 258: 'Samoyed, Samoyede', - 259: 'Pomeranian', - 260: 'chow, chow chow', - 261: 'keeshond', - 262: 'Brabancon griffon', - 263: 'Pembroke, Pembroke Welsh corgi', - 264: 'Cardigan, Cardigan Welsh corgi', - 265: 'toy poodle', - 266: 'miniature poodle', - 267: 'standard poodle', - 268: 'Mexican hairless', - 269: 'timber wolf, grey wolf, gray wolf, Canis lupus', - 270: 'white wolf, Arctic wolf, Canis lupus tundrarum', - 271: 'red wolf, maned wolf, Canis rufus, Canis niger', - 272: 'coyote, prairie wolf, brush wolf, Canis latrans', - 273: 'dingo, warrigal, warragal, Canis dingo', - 274: 'dhole, Cuon alpinus', - 275: 'African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus', - 276: 'hyena, hyaena', - 277: 'red fox, Vulpes vulpes', - 278: 'kit fox, Vulpes macrotis', - 279: 'Arctic fox, white fox, Alopex lagopus', - 280: 'grey fox, gray fox, Urocyon cinereoargenteus', - 281: 'tabby, tabby cat', - 282: 'tiger cat', - 283: 'Persian cat', - 284: 'Siamese cat, Siamese', - 285: 'Egyptian cat', - 286: 'cougar, puma, catamount, mountain lion, painter, panther, ' + - 'Felis concolor', - 287: 'lynx, catamount', - 288: 'leopard, Panthera pardus', - 289: 'snow leopard, ounce, Panthera uncia', - 290: 'jaguar, panther, Panthera onca, Felis onca', - 291: 'lion, king of beasts, Panthera leo', - 292: 'tiger, Panthera tigris', - 293: 'cheetah, chetah, Acinonyx jubatus', - 294: 'brown bear, bruin, Ursus arctos', - 295: 'American black bear, black bear, Ursus americanus, Euarctos ' + - 'americanus', - 296: 'ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus', - 297: 'sloth bear, Melursus ursinus, Ursus ursinus', - 298: 'mongoose', - 299: 'meerkat, mierkat', - 300: 'tiger beetle', - 301: 'ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle', - 302: 'ground beetle, carabid beetle', - 303: 'long-horned beetle, longicorn, longicorn beetle', - 304: 'leaf beetle, chrysomelid', - 305: 'dung beetle', - 306: 'rhinoceros beetle', - 307: 'weevil', - 308: 'fly', - 309: 'bee', - 310: 'ant, emmet, pismire', - 311: 'grasshopper, hopper', - 312: 'cricket', - 313: 'walking stick, walkingstick, stick insect', - 314: 'cockroach, roach', - 315: 'mantis, mantid', - 316: 'cicada, cicala', - 317: 'leafhopper', - 318: 'lacewing, lacewing fly', - 319: 'dragonfly, darning needle, devil\'s darning needle, sewing needle, ' + - 'snake feeder, snake doctor, mosquito hawk, skeeter hawk', - 320: 'damselfly', - 321: 'admiral', - 322: 'ringlet, ringlet butterfly', - 323: 'monarch, monarch butterfly, milkweed butterfly, Danaus plexippus', - 324: 'cabbage butterfly', - 325: 'sulphur butterfly, sulfur butterfly', - 326: 'lycaenid, lycaenid butterfly', - 327: 'starfish, sea star', - 328: 'sea urchin', - 329: 'sea cucumber, holothurian', - 330: 'wood rabbit, cottontail, cottontail rabbit', - 331: 'hare', - 332: 'Angora, Angora rabbit', - 333: 'hamster', - 334: 'porcupine, hedgehog', - 335: 'fox squirrel, eastern fox squirrel, Sciurus niger', - 336: 'marmot', - 337: 'beaver', - 338: 'guinea pig, Cavia cobaya', - 339: 'sorrel', - 340: 'zebra', - 341: 'hog, pig, grunter, squealer, Sus scrofa', - 342: 'wild boar, boar, Sus scrofa', - 343: 'warthog', - 344: 'hippopotamus, hippo, river horse, Hippopotamus amphibius', - 345: 'ox', - 346: 'water buffalo, water ox, Asiatic buffalo, Bubalus bubalis', - 347: 'bison', - 348: 'ram, tup', - 349: 'bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky ' + - 'Mountain sheep, Ovis canadensis', - 350: 'ibex, Capra ibex', - 351: 'hartebeest', - 352: 'impala, Aepyceros melampus', - 353: 'gazelle', - 354: 'Arabian camel, dromedary, Camelus dromedarius', - 355: 'llama', - 356: 'weasel', - 357: 'mink', - 358: 'polecat, fitch, foulmart, foumart, Mustela putorius', - 359: 'black-footed ferret, ferret, Mustela nigripes', - 360: 'otter', - 361: 'skunk, polecat, wood pussy', - 362: 'badger', - 363: 'armadillo', - 364: 'three-toed sloth, ai, Bradypus tridactylus', - 365: 'orangutan, orang, orangutang, Pongo pygmaeus', - 366: 'gorilla, Gorilla gorilla', - 367: 'chimpanzee, chimp, Pan troglodytes', - 368: 'gibbon, Hylobates lar', - 369: 'siamang, Hylobates syndactylus, Symphalangus syndactylus', - 370: 'guenon, guenon monkey', - 371: 'patas, hussar monkey, Erythrocebus patas', - 372: 'baboon', - 373: 'macaque', - 374: 'langur', - 375: 'colobus, colobus monkey', - 376: 'proboscis monkey, Nasalis larvatus', - 377: 'marmoset', - 378: 'capuchin, ringtail, Cebus capucinus', - 379: 'howler monkey, howler', - 380: 'titi, titi monkey', - 381: 'spider monkey, Ateles geoffroyi', - 382: 'squirrel monkey, Saimiri sciureus', - 383: 'Madagascar cat, ring-tailed lemur, Lemur catta', - 384: 'indri, indris, Indri indri, Indri brevicaudatus', - 385: 'Indian elephant, Elephas maximus', - 386: 'African elephant, Loxodonta africana', - 387: 'lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens', - 388: 'giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca', - 389: 'barracouta, snoek', - 390: 'eel', - 391: 'coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus ' + - 'kisutch', - 392: 'rock beauty, Holocanthus tricolor', - 393: 'anemone fish', - 394: 'sturgeon', - 395: 'gar, garfish, garpike, billfish, Lepisosteus osseus', - 396: 'lionfish', - 397: 'puffer, pufferfish, blowfish, globefish', - 398: 'abacus', - 399: 'abaya', - 400: 'academic gown, academic robe, judge\'s robe', - 401: 'accordion, piano accordion, squeeze box', - 402: 'acoustic guitar', - 403: 'aircraft carrier, carrier, flattop, attack aircraft carrier', - 404: 'airliner', - 405: 'airship, dirigible', - 406: 'altar', - 407: 'ambulance', - 408: 'amphibian, amphibious vehicle', - 409: 'analog clock', - 410: 'apiary, bee house', - 411: 'apron', - 412: 'ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, ' + - 'dustbin, trash barrel, trash bin', - 413: 'assault rifle, assault gun', - 414: 'backpack, back pack, knapsack, packsack, rucksack, haversack', - 415: 'bakery, bakeshop, bakehouse', - 416: 'balance beam, beam', - 417: 'balloon', - 418: 'ballpoint, ballpoint pen, ballpen, Biro', - 419: 'Band Aid', - 420: 'banjo', - 421: 'bannister, banister, balustrade, balusters, handrail', - 422: 'barbell', - 423: 'barber chair', - 424: 'barbershop', - 425: 'barn', - 426: 'barometer', - 427: 'barrel, cask', - 428: 'barrow, garden cart, lawn cart, wheelbarrow', - 429: 'baseball', - 430: 'basketball', - 431: 'bassinet', - 432: 'bassoon', - 433: 'bathing cap, swimming cap', - 434: 'bath towel', - 435: 'bathtub, bathing tub, bath, tub', - 436: 'beach wagon, station wagon, wagon, estate car, beach waggon, station ' + - 'waggon, waggon', - 437: 'beacon, lighthouse, beacon light, pharos', - 438: 'beaker', - 439: 'bearskin, busby, shako', - 440: 'beer bottle', - 441: 'beer glass', - 442: 'bell cote, bell cot', - 443: 'bib', - 444: 'bicycle-built-for-two, tandem bicycle, tandem', - 445: 'bikini, two-piece', - 446: 'binder, ring-binder', - 447: 'binoculars, field glasses, opera glasses', - 448: 'birdhouse', - 449: 'boathouse', - 450: 'bobsled, bobsleigh, bob', - 451: 'bolo tie, bolo, bola tie, bola', - 452: 'bonnet, poke bonnet', - 453: 'bookcase', - 454: 'bookshop, bookstore, bookstall', - 455: 'bottlecap', - 456: 'bow', - 457: 'bow tie, bow-tie, bowtie', - 458: 'brass, memorial tablet, plaque', - 459: 'brassiere, bra, bandeau', - 460: 'breakwater, groin, groyne, mole, bulwark, seawall, jetty', - 461: 'breastplate, aegis, egis', - 462: 'broom', - 463: 'bucket, pail', - 464: 'buckle', - 465: 'bulletproof vest', - 466: 'bullet train, bullet', - 467: 'butcher shop, meat market', - 468: 'cab, hack, taxi, taxicab', - 469: 'caldron, cauldron', - 470: 'candle, taper, wax light', - 471: 'cannon', - 472: 'canoe', - 473: 'can opener, tin opener', - 474: 'cardigan', - 475: 'car mirror', - 476: 'carousel, carrousel, merry-go-round, roundabout, whirligig', - 477: 'carpenter\'s kit, tool kit', - 478: 'carton', - 479: 'car wheel', - 480: 'cash machine, cash dispenser, automated teller machine, automatic ' + - 'teller machine, automated teller, automatic teller, ATM', - 481: 'cassette', - 482: 'cassette player', - 483: 'castle', - 484: 'catamaran', - 485: 'CD player', - 486: 'cello, violoncello', - 487: 'cellular telephone, cellular phone, cellphone, cell, mobile phone', - 488: 'chain', - 489: 'chainlink fence', - 490: 'chain mail, ring mail, mail, chain armor, chain armour, ring armor, ' + - 'ring armour', - 491: 'chain saw, chainsaw', - 492: 'chest', - 493: 'chiffonier, commode', - 494: 'chime, bell, gong', - 495: 'china cabinet, china closet', - 496: 'Christmas stocking', - 497: 'church, church building', - 498: 'cinema, movie theater, movie theatre, movie house, picture palace', - 499: 'cleaver, meat cleaver, chopper', - 500: 'cliff dwelling', - 501: 'cloak', - 502: 'clog, geta, patten, sabot', - 503: 'cocktail shaker', - 504: 'coffee mug', - 505: 'coffeepot', - 506: 'coil, spiral, volute, whorl, helix', - 507: 'combination lock', - 508: 'computer keyboard, keypad', - 509: 'confectionery, confectionary, candy store', - 510: 'container ship, containership, container vessel', - 511: 'convertible', - 512: 'corkscrew, bottle screw', - 513: 'cornet, horn, trumpet, trump', - 514: 'cowboy boot', - 515: 'cowboy hat, ten-gallon hat', - 516: 'cradle', - 517: 'crane', - 518: 'crash helmet', - 519: 'crate', - 520: 'crib, cot', - 521: 'Crock Pot', - 522: 'croquet ball', - 523: 'crutch', - 524: 'cuirass', - 525: 'dam, dike, dyke', - 526: 'desk', - 527: 'desktop computer', - 528: 'dial telephone, dial phone', - 529: 'diaper, nappy, napkin', - 530: 'digital clock', - 531: 'digital watch', - 532: 'dining table, board', - 533: 'dishrag, dishcloth', - 534: 'dishwasher, dish washer, dishwashing machine', - 535: 'disk brake, disc brake', - 536: 'dock, dockage, docking facility', - 537: 'dogsled, dog sled, dog sleigh', - 538: 'dome', - 539: 'doormat, welcome mat', - 540: 'drilling platform, offshore rig', - 541: 'drum, membranophone, tympan', - 542: 'drumstick', - 543: 'dumbbell', - 544: 'Dutch oven', - 545: 'electric fan, blower', - 546: 'electric guitar', - 547: 'electric locomotive', - 548: 'entertainment center', - 549: 'envelope', - 550: 'espresso maker', - 551: 'face powder', - 552: 'feather boa, boa', - 553: 'file, file cabinet, filing cabinet', - 554: 'fireboat', - 555: 'fire engine, fire truck', - 556: 'fire screen, fireguard', - 557: 'flagpole, flagstaff', - 558: 'flute, transverse flute', - 559: 'folding chair', - 560: 'football helmet', - 561: 'forklift', - 562: 'fountain', - 563: 'fountain pen', - 564: 'four-poster', - 565: 'freight car', - 566: 'French horn, horn', - 567: 'frying pan, frypan, skillet', - 568: 'fur coat', - 569: 'garbage truck, dustcart', - 570: 'gasmask, respirator, gas helmet', - 571: 'gas pump, gasoline pump, petrol pump, island dispenser', - 572: 'goblet', - 573: 'go-kart', - 574: 'golf ball', - 575: 'golfcart, golf cart', - 576: 'gondola', - 577: 'gong, tam-tam', - 578: 'gown', - 579: 'grand piano, grand', - 580: 'greenhouse, nursery, glasshouse', - 581: 'grille, radiator grille', - 582: 'grocery store, grocery, food market, market', - 583: 'guillotine', - 584: 'hair slide', - 585: 'hair spray', - 586: 'half track', - 587: 'hammer', - 588: 'hamper', - 589: 'hand blower, blow dryer, blow drier, hair dryer, hair drier', - 590: 'hand-held computer, hand-held microcomputer', - 591: 'handkerchief, hankie, hanky, hankey', - 592: 'hard disc, hard disk, fixed disk', - 593: 'harmonica, mouth organ, harp, mouth harp', - 594: 'harp', - 595: 'harvester, reaper', - 596: 'hatchet', - 597: 'holster', - 598: 'home theater, home theatre', - 599: 'honeycomb', - 600: 'hook, claw', - 601: 'hoopskirt, crinoline', - 602: 'horizontal bar, high bar', - 603: 'horse cart, horse-cart', - 604: 'hourglass', - 605: 'iPod', - 606: 'iron, smoothing iron', - 607: 'jack-o\'-lantern', - 608: 'jean, blue jean, denim', - 609: 'jeep, landrover', - 610: 'jersey, T-shirt, tee shirt', - 611: 'jigsaw puzzle', - 612: 'jinrikisha, ricksha, rickshaw', - 613: 'joystick', - 614: 'kimono', - 615: 'knee pad', - 616: 'knot', - 617: 'lab coat, laboratory coat', - 618: 'ladle', - 619: 'lampshade, lamp shade', - 620: 'laptop, laptop computer', - 621: 'lawn mower, mower', - 622: 'lens cap, lens cover', - 623: 'letter opener, paper knife, paperknife', - 624: 'library', - 625: 'lifeboat', - 626: 'lighter, light, igniter, ignitor', - 627: 'limousine, limo', - 628: 'liner, ocean liner', - 629: 'lipstick, lip rouge', - 630: 'Loafer', - 631: 'lotion', - 632: 'loudspeaker, speaker, speaker unit, loudspeaker system, speaker ' + - 'system', - 633: 'loupe, jeweler\'s loupe', - 634: 'lumbermill, sawmill', - 635: 'magnetic compass', - 636: 'mailbag, postbag', - 637: 'mailbox, letter box', - 638: 'maillot', - 639: 'maillot, tank suit', - 640: 'manhole cover', - 641: 'maraca', - 642: 'marimba, xylophone', - 643: 'mask', - 644: 'matchstick', - 645: 'maypole', - 646: 'maze, labyrinth', - 647: 'measuring cup', - 648: 'medicine chest, medicine cabinet', - 649: 'megalith, megalithic structure', - 650: 'microphone, mike', - 651: 'microwave, microwave oven', - 652: 'military uniform', - 653: 'milk can', - 654: 'minibus', - 655: 'miniskirt, mini', - 656: 'minivan', - 657: 'missile', - 658: 'mitten', - 659: 'mixing bowl', - 660: 'mobile home, manufactured home', - 661: 'Model T', - 662: 'modem', - 663: 'monastery', - 664: 'monitor', - 665: 'moped', - 666: 'mortar', - 667: 'mortarboard', - 668: 'mosque', - 669: 'mosquito net', - 670: 'motor scooter, scooter', - 671: 'mountain bike, all-terrain bike, off-roader', - 672: 'mountain tent', - 673: 'mouse, computer mouse', - 674: 'mousetrap', - 675: 'moving van', - 676: 'muzzle', - 677: 'nail', - 678: 'neck brace', - 679: 'necklace', - 680: 'nipple', - 681: 'notebook, notebook computer', - 682: 'obelisk', - 683: 'oboe, hautboy, hautbois', - 684: 'ocarina, sweet potato', - 685: 'odometer, hodometer, mileometer, milometer', - 686: 'oil filter', - 687: 'organ, pipe organ', - 688: 'oscilloscope, scope, cathode-ray oscilloscope, CRO', - 689: 'overskirt', - 690: 'oxcart', - 691: 'oxygen mask', - 692: 'packet', - 693: 'paddle, boat paddle', - 694: 'paddlewheel, paddle wheel', - 695: 'padlock', - 696: 'paintbrush', - 697: 'pajama, pyjama, pj\'s, jammies', - 698: 'palace', - 699: 'panpipe, pandean pipe, syrinx', - 700: 'paper towel', - 701: 'parachute, chute', - 702: 'parallel bars, bars', - 703: 'park bench', - 704: 'parking meter', - 705: 'passenger car, coach, carriage', - 706: 'patio, terrace', - 707: 'pay-phone, pay-station', - 708: 'pedestal, plinth, footstall', - 709: 'pencil box, pencil case', - 710: 'pencil sharpener', - 711: 'perfume, essence', - 712: 'Petri dish', - 713: 'photocopier', - 714: 'pick, plectrum, plectron', - 715: 'pickelhaube', - 716: 'picket fence, paling', - 717: 'pickup, pickup truck', - 718: 'pier', - 719: 'piggy bank, penny bank', - 720: 'pill bottle', - 721: 'pillow', - 722: 'ping-pong ball', - 723: 'pinwheel', - 724: 'pirate, pirate ship', - 725: 'pitcher, ewer', - 726: 'plane, carpenter\'s plane, woodworking plane', - 727: 'planetarium', - 728: 'plastic bag', - 729: 'plate rack', - 730: 'plow, plough', - 731: 'plunger, plumber\'s helper', - 732: 'Polaroid camera, Polaroid Land camera', - 733: 'pole', - 734: 'police van, police wagon, paddy wagon, patrol wagon, wagon, black ' + - 'Maria', - 735: 'poncho', - 736: 'pool table, billiard table, snooker table', - 737: 'pop bottle, soda bottle', - 738: 'pot, flowerpot', - 739: 'potter\'s wheel', - 740: 'power drill', - 741: 'prayer rug, prayer mat', - 742: 'printer', - 743: 'prison, prison house', - 744: 'projectile, missile', - 745: 'projector', - 746: 'puck, hockey puck', - 747: 'punching bag, punch bag, punching ball, punchball', - 748: 'purse', - 749: 'quill, quill pen', - 750: 'quilt, comforter, comfort, puff', - 751: 'racer, race car, racing car', - 752: 'racket, racquet', - 753: 'radiator', - 754: 'radio, wireless', - 755: 'radio telescope, radio reflector', - 756: 'rain barrel', - 757: 'recreational vehicle, RV, R.V.', - 758: 'reel', - 759: 'reflex camera', - 760: 'refrigerator, icebox', - 761: 'remote control, remote', - 762: 'restaurant, eating house, eating place, eatery', - 763: 'revolver, six-gun, six-shooter', - 764: 'rifle', - 765: 'rocking chair, rocker', - 766: 'rotisserie', - 767: 'rubber eraser, rubber, pencil eraser', - 768: 'rugby ball', - 769: 'rule, ruler', - 770: 'running shoe', - 771: 'safe', - 772: 'safety pin', - 773: 'saltshaker, salt shaker', - 774: 'sandal', - 775: 'sarong', - 776: 'sax, saxophone', - 777: 'scabbard', - 778: 'scale, weighing machine', - 779: 'school bus', - 780: 'schooner', - 781: 'scoreboard', - 782: 'screen, CRT screen', - 783: 'screw', - 784: 'screwdriver', - 785: 'seat belt, seatbelt', - 786: 'sewing machine', - 787: 'shield, buckler', - 788: 'shoe shop, shoe-shop, shoe store', - 789: 'shoji', - 790: 'shopping basket', - 791: 'shopping cart', - 792: 'shovel', - 793: 'shower cap', - 794: 'shower curtain', - 795: 'ski', - 796: 'ski mask', - 797: 'sleeping bag', - 798: 'slide rule, slipstick', - 799: 'sliding door', - 800: 'slot, one-armed bandit', - 801: 'snorkel', - 802: 'snowmobile', - 803: 'snowplow, snowplough', - 804: 'soap dispenser', - 805: 'soccer ball', - 806: 'sock', - 807: 'solar dish, solar collector, solar furnace', - 808: 'sombrero', - 809: 'soup bowl', - 810: 'space bar', - 811: 'space heater', - 812: 'space shuttle', - 813: 'spatula', - 814: 'speedboat', - 815: 'spider web, spider\'s web', - 816: 'spindle', - 817: 'sports car, sport car', - 818: 'spotlight, spot', - 819: 'stage', - 820: 'steam locomotive', - 821: 'steel arch bridge', - 822: 'steel drum', - 823: 'stethoscope', - 824: 'stole', - 825: 'stone wall', - 826: 'stopwatch, stop watch', - 827: 'stove', - 828: 'strainer', - 829: 'streetcar, tram, tramcar, trolley, trolley car', - 830: 'stretcher', - 831: 'studio couch, day bed', - 832: 'stupa, tope', - 833: 'submarine, pigboat, sub, U-boat', - 834: 'suit, suit of clothes', - 835: 'sundial', - 836: 'sunglass', - 837: 'sunglasses, dark glasses, shades', - 838: 'sunscreen, sunblock, sun blocker', - 839: 'suspension bridge', - 840: 'swab, swob, mop', - 841: 'sweatshirt', - 842: 'swimming trunks, bathing trunks', - 843: 'swing', - 844: 'switch, electric switch, electrical switch', - 845: 'syringe', - 846: 'table lamp', - 847: 'tank, army tank, armored combat vehicle, armoured combat vehicle', - 848: 'tape player', - 849: 'teapot', - 850: 'teddy, teddy bear', - 851: 'television, television system', - 852: 'tennis ball', - 853: 'thatch, thatched roof', - 854: 'theater curtain, theatre curtain', - 855: 'thimble', - 856: 'thresher, thrasher, threshing machine', - 857: 'throne', - 858: 'tile roof', - 859: 'toaster', - 860: 'tobacco shop, tobacconist shop, tobacconist', - 861: 'toilet seat', - 862: 'torch', - 863: 'totem pole', - 864: 'tow truck, tow car, wrecker', - 865: 'toyshop', - 866: 'tractor', - 867: 'trailer truck, tractor trailer, trucking rig, rig, articulated ' + - 'lorry, semi', - 868: 'tray', - 869: 'trench coat', - 870: 'tricycle, trike, velocipede', - 871: 'trimaran', - 872: 'tripod', - 873: 'triumphal arch', - 874: 'trolleybus, trolley coach, trackless trolley', - 875: 'trombone', - 876: 'tub, vat', - 877: 'turnstile', - 878: 'typewriter keyboard', - 879: 'umbrella', - 880: 'unicycle, monocycle', - 881: 'upright, upright piano', - 882: 'vacuum, vacuum cleaner', - 883: 'vase', - 884: 'vault', - 885: 'velvet', - 886: 'vending machine', - 887: 'vestment', - 888: 'viaduct', - 889: 'violin, fiddle', - 890: 'volleyball', - 891: 'waffle iron', - 892: 'wall clock', - 893: 'wallet, billfold, notecase, pocketbook', - 894: 'wardrobe, closet, press', - 895: 'warplane, military plane', - 896: 'washbasin, handbasin, washbowl, lavabo, wash-hand basin', - 897: 'washer, automatic washer, washing machine', - 898: 'water bottle', - 899: 'water jug', - 900: 'water tower', - 901: 'whiskey jug', - 902: 'whistle', - 903: 'wig', - 904: 'window screen', - 905: 'window shade', - 906: 'Windsor tie', - 907: 'wine bottle', - 908: 'wing', - 909: 'wok', - 910: 'wooden spoon', - 911: 'wool, woolen, woollen', - 912: 'worm fence, snake fence, snake-rail fence, Virginia fence', - 913: 'wreck', - 914: 'yawl', - 915: 'yurt', - 916: 'web site, website, internet site, site', - 917: 'comic book', - 918: 'crossword puzzle, crossword', - 919: 'street sign', - 920: 'traffic light, traffic signal, stoplight', - 921: 'book jacket, dust cover, dust jacket, dust wrapper', - 922: 'menu', - 923: 'plate', - 924: 'guacamole', - 925: 'consomme', - 926: 'hot pot, hotpot', - 927: 'trifle', - 928: 'ice cream, icecream', - 929: 'ice lolly, lolly, lollipop, popsicle', - 930: 'French loaf', - 931: 'bagel, beigel', - 932: 'pretzel', - 933: 'cheeseburger', - 934: 'hotdog, hot dog, red hot', - 935: 'mashed potato', - 936: 'head cabbage', - 937: 'broccoli', - 938: 'cauliflower', - 939: 'zucchini, courgette', - 940: 'spaghetti squash', - 941: 'acorn squash', - 942: 'butternut squash', - 943: 'cucumber, cuke', - 944: 'artichoke, globe artichoke', - 945: 'bell pepper', - 946: 'cardoon', - 947: 'mushroom', - 948: 'Granny Smith', - 949: 'strawberry', - 950: 'orange', - 951: 'lemon', - 952: 'fig', - 953: 'pineapple, ananas', - 954: 'banana', - 955: 'jackfruit, jak, jack', - 956: 'custard apple', - 957: 'pomegranate', - 958: 'hay', - 959: 'carbonara', - 960: 'chocolate sauce, chocolate syrup', - 961: 'dough', - 962: 'meat loaf, meatloaf', - 963: 'pizza, pizza pie', - 964: 'potpie', - 965: 'burrito', - 966: 'red wine', - 967: 'espresso', - 968: 'cup', - 969: 'eggnog', - 970: 'alp', - 971: 'bubble', - 972: 'cliff, drop, drop-off', - 973: 'coral reef', - 974: 'geyser', - 975: 'lakeside, lakeshore', - 976: 'promontory, headland, head, foreland', - 977: 'sandbar, sand bar', - 978: 'seashore, coast, seacoast, sea-coast', - 979: 'valley, vale', - 980: 'volcano', - 981: 'ballplayer, baseball player', - 982: 'groom, bridegroom', - 983: 'scuba diver', - 984: 'rapeseed', - 985: 'daisy', - 986: 'yellow lady\'s slipper, yellow lady-slipper, Cypripedium calceolus, ' + - 'Cypripedium parviflorum', - 987: 'corn', - 988: 'acorn', - 989: 'hip, rose hip, rosehip', - 990: 'buckeye, horse chestnut, conker', - 991: 'coral fungus', - 992: 'agaric', - 993: 'gyromitra', - 994: 'stinkhorn, carrion fungus', - 995: 'earthstar', - 996: 'hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola ' + - 'frondosa', - 997: 'bolete', - 998: 'ear, spike, capitulum', - 999: 'toilet tissue, toilet paper, bathroom tissue' -}; - -},{}],7:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var squeezenet_1 = require("./squeezenet"); -exports.SqueezeNet = squeezenet_1.SqueezeNet; - -},{"./squeezenet":8}],8:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dl = require("deeplearn"); -var model_util = require("../util"); -var imagenet_classes_1 = require("./imagenet_classes"); -var GOOGLE_CLOUD_STORAGE_DIR = 'https://storage.googleapis.com/learnjs-data/checkpoint_zoo/'; -var SqueezeNet = (function () { - function SqueezeNet() { - this.preprocessOffset = dl.tensor1d([103.939, 116.779, 123.68]); - } - SqueezeNet.prototype.load = function () { - return __awaiter(this, void 0, void 0, function () { - var checkpointLoader, _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - checkpointLoader = new dl.CheckpointLoader(GOOGLE_CLOUD_STORAGE_DIR + 'squeezenet1_1/'); - _a = this; - return [4, checkpointLoader.getAllVariables()]; - case 1: - _a.variables = _b.sent(); - return [2]; - } - }); - }); - }; - SqueezeNet.prototype.predict = function (input) { - return this.predictWithActivation(input).logits; - }; - SqueezeNet.prototype.predictWithActivation = function (input, activationName) { - var _this = this; - return dl.tidy(function () { - var activation; - var preprocessedInput = dl.sub(input.asType('float32'), _this.preprocessOffset); - var conv1relu = preprocessedInput - .conv2d(_this.variables['conv1_W:0'], 2, 0) - .add(_this.variables['conv1_b:0']) - .relu(); - if (activationName === 'conv_1') { - activation = conv1relu; - } - var pool1 = conv1relu.maxPool(3, 2, 0); - if (activationName === 'maxpool_1') { - activation = pool1; - } - var fire2 = _this.fireModule(pool1, 2); - if (activationName === 'fire2') { - activation = fire2; - } - var fire3 = _this.fireModule(fire2, 3); - if (activationName === 'fire3') { - activation = fire3; - } - var pool2 = fire3.maxPool(3, 2, 'valid'); - if (activationName === 'maxpool_2') { - activation = pool2; - } - var fire4 = _this.fireModule(pool2, 4); - if (activationName === 'fire4') { - activation = fire4; - } - var fire5 = _this.fireModule(fire4, 5); - if (activationName === 'fire5') { - activation = fire5; - } - var pool3 = fire5.maxPool(3, 2, 0); - if (activationName === 'maxpool_3') { - activation = pool3; - } - var fire6 = _this.fireModule(pool3, 6); - if (activationName === 'fire6') { - activation = fire6; - } - var fire7 = _this.fireModule(fire6, 7); - if (activationName === 'fire7') { - activation = fire7; - } - var fire8 = _this.fireModule(fire7, 8); - if (activationName === 'fire8') { - activation = fire8; - } - var fire9 = _this.fireModule(fire8, 9); - if (activationName === 'fire9') { - activation = fire9; - } - var conv10 = fire9.conv2d(_this.variables['conv10_W:0'], 1, 0) - .add(_this.variables['conv10_b:0']); - if (activationName === 'conv10') { - activation = conv10; - } - return { - logits: dl.avgPool(conv10, conv10.shape[0], 1, 0).as1D(), - activation: activation - }; - }); - }; - SqueezeNet.prototype.fireModule = function (input, fireId) { - var y = dl.conv2d(input, this.variables["fire" + fireId + "/squeeze1x1_W:0"], 1, 0) - .add(this.variables["fire" + fireId + "/squeeze1x1_b:0"]) - .relu(); - var left = dl.conv2d(y, this.variables["fire" + fireId + "/expand1x1_W:0"], 1, 0) - .add(this.variables["fire" + fireId + "/expand1x1_b:0"]) - .relu(); - var right = dl.conv2d(y, this.variables["fire" + fireId + "/expand3x3_W:0"], 1, 1) - .add(this.variables["fire" + fireId + "/expand3x3_b:0"]) - .relu(); - return left.concat(right, 2); - }; - SqueezeNet.prototype.getTopKClasses = function (logits, topK) { - return __awaiter(this, void 0, void 0, function () { - var predictions, topk, _a, _b, topkIndices, topkValues, topClassesToProbability, i; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - predictions = dl.tidy(function () { - return dl.softmax(logits).asType('float32'); - }); - _b = (_a = model_util).topK; - return [4, predictions.data()]; - case 1: - topk = _b.apply(_a, [_c.sent(), topK]); - predictions.dispose(); - topkIndices = topk.indices; - topkValues = topk.values; - topClassesToProbability = {}; - for (i = 0; i < topkIndices.length; i++) { - topClassesToProbability[imagenet_classes_1.IMAGENET_CLASSES[topkIndices[i]]] = topkValues[i]; - } - return [2, topClassesToProbability]; - } - }); - }); - }; - SqueezeNet.prototype.dispose = function () { - this.preprocessOffset.dispose(); - for (var varName in this.variables) { - this.variables[varName].dispose(); - } - }; - return SqueezeNet; -}()); -exports.SqueezeNet = SqueezeNet; - -},{"../util":9,"./imagenet_classes":6,"deeplearn":67}],9:[function(require,module,exports){ -arguments[4][5][0].apply(exports,arguments) -},{"dup":5}],10:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var BrowserUtil = (function () { - function BrowserUtil() { - } - BrowserUtil.nextFrame = function () { - return new Promise(function (resolve) { return requestAnimationFrame(function () { return resolve(); }); }); - }; - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Timing' }) - ], BrowserUtil, "nextFrame", null); - return BrowserUtil; -}()); -exports.BrowserUtil = BrowserUtil; - -},{"./doc":32}],11:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var BatchDataset = (function () { - function BatchDataset(base, batchSize, smallLastBatch) { - if (smallLastBatch === void 0) { smallLastBatch = true; } - this.base = base; - this.batchSize = batchSize; - this.smallLastBatch = smallLastBatch; - } - BatchDataset.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - var batchesAsArrays; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.base.getStream()]; - case 1: - batchesAsArrays = (_a.sent()) - .batch(this.batchSize, this.smallLastBatch); - return [2, batchesAsArrays.map(makeDatasetBatch)]; - } - }); - }); - }; - return BatchDataset; -}()); -exports.BatchDataset = BatchDataset; -function makeDatasetBatch(elements) { - var rotated = {}; - var firstElement = elements[0]; - var keys = Object.keys(firstElement); - keys.forEach(function (key) { - rotated[key] = []; - }); - var _loop_1 = function (e) { - keys.forEach(function (key) { - var value = e[key]; - rotated[key].push(value); - }); - }; - for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) { - var e = elements_1[_i]; - _loop_1(e); - } - var result = {}; - for (var _a = 0, keys_1 = keys; _a < keys_1.length; _a++) { - var key = keys_1[_a]; - if (rotated[key].length !== elements.length) { - throw new Error("Batching failed to get a '" + key + "' value for each element."); - } - if (typeof rotated[key][0] === 'string') { - result[key] = rotated[key]; - } - else { - result[key] = batchConcat(rotated[key]); - } - } - return result; -} -function batchConcat(arrays) { - var elementShape = shapeAndValues(arrays[0])[0]; - var batchShape = [arrays.length].concat(elementShape); - var resultVals = new Float32Array(batchShape.reduce(function (x, y) { return x * y; })); - var offset = 0; - for (var _i = 0, arrays_1 = arrays; _i < arrays_1.length; _i++) { - var a = arrays_1[_i]; - var _a = shapeAndValues(a), aShape = _a[0], aVals = _a[1]; - if (!util.arraysEqual(aShape, elementShape)) { - throw new Error('Elements must have the same shape to be batched'); - } - resultVals.set(aVals, offset); - offset += aVals.length; - } - var result = tensor_1.Tensor.make(batchShape, { values: resultVals }); - return result; -} -function shapeAndValues(array) { - if (array instanceof tensor_1.Tensor) { - return [array.shape, array.dataSync()]; - } - else if (Array.isArray(array)) { - return [[array.length], array]; - } - else { - return [[], [array]]; - } -} - -},{"../../tensor":146,"../../util":151}],12:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var batch_dataset_1 = require("./batch_dataset"); -var statistics_1 = require("./statistics"); -var data_stream_1 = require("./streams/data_stream"); -var data_stream_2 = require("./streams/data_stream"); -var data_stream_3 = require("./streams/data_stream"); -var Dataset = (function () { - function Dataset() { - } - Dataset.prototype.computeStatistics = function (sampleSize, shuffleWindowSize) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, statistics_1.computeDatasetStatistics(this, sampleSize, shuffleWindowSize)]; - }); - }); - }; - Dataset.prototype.filter = function (filterer) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).filter(filterer)]; - } - }); - }); }); - }; - Dataset.prototype.map = function (transform) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).map(transform)]; - } - }); - }); }); - }; - Dataset.prototype.batch = function (batchSize, smallLastBatch) { - if (smallLastBatch === void 0) { smallLastBatch = true; } - return new batch_dataset_1.BatchDataset(this, batchSize, smallLastBatch); - }; - Dataset.prototype.concatenate = function (dataset) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: return [4, base.getStream()]; - case 1: - _b = (_a = (_c.sent())).concatenate; - return [4, dataset.getStream()]; - case 2: return [2, _b.apply(_a, [_c.sent()])]; - } - }); - }); }); - }; - Dataset.prototype.repeat = function (count) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var streamStream; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - streamStream = data_stream_2.streamFromFunction(function () { return base.getStream(); }); - return [4, data_stream_1.streamFromConcatenated(streamStream.take(count))]; - case 1: return [2, (_a.sent())]; - } - }); - }); }); - }; - Dataset.prototype.take = function (count) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).take(count)]; - } - }); - }); }); - }; - Dataset.prototype.skip = function (count) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).skip(count)]; - } - }); - }); }); - }; - Dataset.prototype.shuffle = function (bufferSize, seed, reshuffleEachIteration) { - var _this = this; - if (reshuffleEachIteration === void 0) { reshuffleEachIteration = true; } - var base = this; - var random = seedrandom(seed); - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var seed2; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - seed2 = random.int32(); - if (reshuffleEachIteration) { - seed2 += random.int32(); - } - return [4, base.getStream()]; - case 1: return [2, (_a.sent()).shuffle(bufferSize, seed2.toString())]; - } - }); - }); }); - }; - Dataset.prototype.prefetch = function (bufferSize) { - var _this = this; - var base = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, base.getStream()]; - case 1: return [2, (_a.sent()).prefetch(bufferSize)]; - } - }); - }); }); - }; - return Dataset; -}()); -exports.Dataset = Dataset; -function datasetFromStreamFn(getStreamFn) { - return new (function (_super) { - __extends(class_1, _super); - function class_1() { - return _super !== null && _super.apply(this, arguments) || this; - } - class_1.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, getStreamFn()]; - }); - }); - }; - return class_1; - }(Dataset))(); -} -exports.datasetFromStreamFn = datasetFromStreamFn; -function datasetFromElements(items) { - var _this = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, Promise.resolve(data_stream_3.streamFromItems(items))]; - }); - }); }); -} -exports.datasetFromElements = datasetFromElements; -function datasetFromConcatenated(datasets) { - var _this = this; - return datasetFromStreamFn(function () { return __awaiter(_this, void 0, void 0, function () { - var streamStream; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, Promise.all(datasets.map(function (d) { return d.getStream(); }))]; - case 1: - streamStream = _a.sent(); - return [2, data_stream_1.streamFromConcatenated(data_stream_3.streamFromItems(streamStream))]; - } - }); - }); }); -} -exports.datasetFromConcatenated = datasetFromConcatenated; - -},{"./batch_dataset":11,"./statistics":18,"./streams/data_stream":20,"seedrandom":153}],13:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dataset_1 = require("../dataset"); -var text_line_dataset_1 = require("./text_line_dataset"); -var CsvHeaderConfig; -(function (CsvHeaderConfig) { - CsvHeaderConfig[CsvHeaderConfig["READ_FIRST_LINE"] = 0] = "READ_FIRST_LINE"; - CsvHeaderConfig[CsvHeaderConfig["NUMBERED"] = 1] = "NUMBERED"; -})(CsvHeaderConfig = exports.CsvHeaderConfig || (exports.CsvHeaderConfig = {})); -var CSVDataset = (function (_super) { - __extends(CSVDataset, _super); - function CSVDataset(input) { - var _this = _super.call(this) || this; - _this.input = input; - _this.hasHeaderLine = false; - _this.base = new text_line_dataset_1.TextLineDataset(input, CSVDataset.textColumnName); - return _this; - } - Object.defineProperty(CSVDataset.prototype, "csvColumnNames", { - get: function () { - return this._csvColumnNames; - }, - enumerable: true, - configurable: true - }); - CSVDataset.prototype.setCsvColumnNames = function (csvColumnNames) { - return __awaiter(this, void 0, void 0, function () { - var stream, firstElement, firstLine, stream, firstElement, firstLine; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(csvColumnNames == null || csvColumnNames === CsvHeaderConfig.NUMBERED)) return [3, 3]; - return [4, this.base.getStream()]; - case 1: - stream = _a.sent(); - return [4, stream.next()]; - case 2: - firstElement = _a.sent(); - firstLine = firstElement[CSVDataset.textColumnName]; - this._csvColumnNames = - Array.from(firstLine.split(',').keys()).map(function (x) { return x.toString(); }); - return [3, 7]; - case 3: - if (!(csvColumnNames === CsvHeaderConfig.READ_FIRST_LINE)) return [3, 6]; - return [4, this.base.getStream()]; - case 4: - stream = _a.sent(); - return [4, stream.next()]; - case 5: - firstElement = _a.sent(); - firstLine = firstElement[CSVDataset.textColumnName]; - this._csvColumnNames = firstLine.split(','); - this.hasHeaderLine = true; - return [3, 7]; - case 6: - this._csvColumnNames = csvColumnNames; - _a.label = 7; - case 7: return [2]; - } - }); - }); - }; - CSVDataset.create = function (input, csvColumnNames) { - if (csvColumnNames === void 0) { csvColumnNames = CsvHeaderConfig.NUMBERED; } - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - result = new CSVDataset(input); - return [4, result.setCsvColumnNames(csvColumnNames)]; - case 1: - _a.sent(); - return [2, result]; - } - }); - }); - }; - CSVDataset.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - var lines; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.base.getStream()]; - case 1: - lines = _a.sent(); - if (this.hasHeaderLine) { - lines = lines.skip(1); - } - return [2, lines.map(function (x) { return _this.makeDatasetElement(x); })]; - } - }); - }); - }; - CSVDataset.prototype.makeDatasetElement = function (element) { - var line = element[CSVDataset.textColumnName]; - var values = line.split(','); - var result = {}; - for (var i = 0; i < this._csvColumnNames.length; i++) { - var value = values[i]; - if (value === '') { - result[this._csvColumnNames[i]] = undefined; - } - else { - var valueAsNum = Number(value); - if (isNaN(valueAsNum)) { - result[this._csvColumnNames[i]] = value; - } - else { - result[this._csvColumnNames[i]] = valueAsNum; - } - } - } - return result; - }; - CSVDataset.textColumnName = 'line'; - return CSVDataset; -}(dataset_1.Dataset)); -exports.CSVDataset = CSVDataset; - -},{"../dataset":12,"./text_line_dataset":14}],14:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var dataset_1 = require("../dataset"); -var TextLineDataset = (function (_super) { - __extends(TextLineDataset, _super); - function TextLineDataset(input, columnName) { - if (columnName === void 0) { columnName = 'line'; } - var _this = _super.call(this) || this; - _this.input = input; - _this.columnName = columnName; - return _this; - } - TextLineDataset.prototype.getStream = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - var readStream, utf8Stream, lineStream; - return __generator(this, function (_a) { - readStream = this.input.getStream(); - utf8Stream = readStream.decodeUTF8(); - lineStream = utf8Stream.split('\n'); - return [2, lineStream.map(function (x) { - return (_a = {}, _a[_this.columnName] = x, _a); - var _a; - })]; - }); - }); - }; - return TextLineDataset; -}(dataset_1.Dataset)); -exports.TextLineDataset = TextLineDataset; - -},{"../dataset":12}],15:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var DataSource = (function () { - function DataSource() { - } - return DataSource; -}()); -exports.DataSource = DataSource; - -},{}],16:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var datasource_1 = require("../datasource"); -var filereader_stream_1 = require("../streams/filereader_stream"); -var FileDataSource = (function (_super) { - __extends(FileDataSource, _super); - function FileDataSource(input, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.input = input; - _this.options = options; - return _this; - } - FileDataSource.prototype.getStream = function () { - return new filereader_stream_1.FileReaderStream(this.input, this.options); - }; - return FileDataSource; -}(datasource_1.DataSource)); -exports.FileDataSource = FileDataSource; - -},{"../datasource":15,"../streams/filereader_stream":21}],17:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var datasource_1 = require("../datasource"); -var url_stream_1 = require("../streams/url_stream"); -var URLDataSource = (function (_super) { - __extends(URLDataSource, _super); - function URLDataSource(url, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.url = url; - _this.options = options; - return _this; - } - URLDataSource.prototype.getStream = function () { - return new url_stream_1.URLStream(this.url, this.options); - }; - return URLDataSource; -}(datasource_1.DataSource)); -exports.URLDataSource = URLDataSource; - -},{"../datasource":15,"../streams/url_stream":23}],18:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../../tensor"); -function scaleTo01(min, max) { - var range = max - min; - var minTensor = tensor_1.Scalar.new(min); - var rangeTensor = tensor_1.Scalar.new(range); - return function (value) { - if (typeof (value) === 'string') { - throw new Error('Can\'t scale a string.'); - } - else { - if (value instanceof tensor_1.Tensor) { - var result = value.sub(minTensor).div(rangeTensor); - return result; - } - else if (value instanceof Array) { - return value.map(function (v) { return (v - min) / range; }); - } - else { - return (value - min) / range; - } - } - }; -} -exports.scaleTo01 = scaleTo01; -function computeDatasetStatistics(dataset, sampleSize, shuffleWindowSize) { - return __awaiter(this, void 0, void 0, function () { - var stream, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, dataset.getStream()]; - case 1: - stream = _a.sent(); - if (shuffleWindowSize != null) { - stream = stream.shuffle(shuffleWindowSize); - } - if (sampleSize != null) { - stream = stream.take(sampleSize); - } - result = {}; - return [4, stream.forEach(function (e) { - for (var key in e) { - var value = e[key]; - if (typeof (value) === 'string') { - } - else { - var recordMin = void 0; - var recordMax = void 0; - if (value instanceof tensor_1.Tensor) { - recordMin = value.min().dataSync()[0]; - recordMax = value.max().dataSync()[0]; - } - else if (value instanceof Array) { - recordMin = value.reduce(function (a, b) { return Math.min(a, b); }); - recordMax = value.reduce(function (a, b) { return Math.max(a, b); }); - } - else if (!isNaN(value) && isFinite(value)) { - recordMin = value; - recordMax = value; - } - else { - throw new Error("Cannot compute statistics: " + key + " = " + value); - } - var columnStats = result[key]; - if (columnStats == null) { - columnStats = { - min: Number.POSITIVE_INFINITY, - max: Number.NEGATIVE_INFINITY - }; - result[key] = columnStats; - } - columnStats.min = Math.min(columnStats.min, recordMin); - columnStats.max = Math.max(columnStats.max, recordMax); - } - } - return {}; - })]; - case 2: - _a.sent(); - return [2, result]; - } - }); - }); -} -exports.computeDatasetStatistics = computeDatasetStatistics; - -},{"../../tensor":146}],19:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var utf8 = require("utf8"); -var data_stream_1 = require("./data_stream"); -var string_stream_1 = require("./string_stream"); -var ByteStream = (function (_super) { - __extends(ByteStream, _super); - function ByteStream() { - return _super !== null && _super.apply(this, arguments) || this; - } - ByteStream.prototype.decodeUTF8 = function () { - return new Utf8Stream(this); - }; - return ByteStream; -}(data_stream_1.DataStream)); -exports.ByteStream = ByteStream; -var Utf8Stream = (function (_super) { - __extends(Utf8Stream, _super); - function Utf8Stream(upstream) { - var _this = _super.call(this) || this; - _this.impl = new Utf8StreamImpl(upstream); - return _this; - } - Utf8Stream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.impl.next()]; - }); - }); - }; - return Utf8Stream; -}(string_stream_1.StringStream)); -var Utf8StreamImpl = (function (_super) { - __extends(Utf8StreamImpl, _super); - function Utf8StreamImpl(upstream) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.partial = new Uint8Array([]); - _this.partialBytesValid = 0; - return _this; - } - Utf8StreamImpl.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var chunk, partialBytesRemaining, nextIndex, okUpToIndex, splitUtfWidth, bulk, reassembled; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - chunk = _a.sent(); - if (chunk == null) { - if (this.partial.length === 0) { - return [2, false]; - } - chunk = new Uint8Array([]); - } - partialBytesRemaining = this.partial.length - this.partialBytesValid; - nextIndex = partialBytesRemaining; - okUpToIndex = nextIndex; - splitUtfWidth = 0; - while (nextIndex < chunk.length) { - okUpToIndex = nextIndex; - splitUtfWidth = utfWidth(chunk[nextIndex]); - nextIndex = okUpToIndex + splitUtfWidth; - } - if (nextIndex === chunk.length) { - okUpToIndex = nextIndex; - } - bulk = utf8.decode(String.fromCharCode.apply(null, chunk.slice(partialBytesRemaining, okUpToIndex))); - if (partialBytesRemaining > 0) { - this.partial.set(chunk.slice(0, partialBytesRemaining), this.partialBytesValid); - reassembled = utf8.decode(String.fromCharCode.apply(null, this.partial)); - this.outputQueue.push(reassembled + bulk); - } - else { - this.outputQueue.push(bulk); - } - if (okUpToIndex === chunk.length) { - this.partial = new Uint8Array([]); - this.partialBytesValid = 0; - } - else { - this.partial = new Uint8Array(new ArrayBuffer(splitUtfWidth)); - this.partial.set(chunk.slice(okUpToIndex), 0); - this.partialBytesValid = chunk.length - okUpToIndex; - } - return [2, true]; - } - }); - }); - }; - return Utf8StreamImpl; -}(data_stream_1.QueueStream)); -function utfWidth(firstByte) { - if (firstByte >= 252) - return 6; - else if (firstByte >= 248) - return 5; - else if (firstByte >= 240) - return 4; - else if (firstByte >= 224) - return 3; - else if (firstByte >= 192) - return 2; - else - return 1; -} - -},{"./data_stream":20,"./string_stream":22,"utf8":161}],20:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var growing_ring_buffer_1 = require("../util/growing_ring_buffer"); -var ring_buffer_1 = require("../util/ring_buffer"); -function streamFromItems(items) { - return new ArrayStream(items); -} -exports.streamFromItems = streamFromItems; -function streamFromIncrementing(start) { - var i = start; - return streamFromFunction(function () { return i++; }); -} -exports.streamFromIncrementing = streamFromIncrementing; -function streamFromFunction(func) { - return new FunctionCallStream(func); -} -exports.streamFromFunction = streamFromFunction; -function streamFromConcatenated(baseStreams) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, ChainedStream.create(baseStreams)]; - }); - }); -} -exports.streamFromConcatenated = streamFromConcatenated; -function streamFromConcatenatedFunction(streamFunc, count) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, streamFromConcatenated(streamFromFunction(streamFunc).take(count))]; - }); - }); -} -exports.streamFromConcatenatedFunction = streamFromConcatenatedFunction; -var DataStream = (function () { - function DataStream() { - } - DataStream.prototype.collectRemaining = function () { - return __awaiter(this, void 0, void 0, function () { - var result, x; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - result = []; - return [4, this.next()]; - case 1: - x = _a.sent(); - _a.label = 2; - case 2: - if (!(x != null)) return [3, 4]; - result.push(x); - return [4, this.next()]; - case 3: - x = _a.sent(); - return [3, 2]; - case 4: return [2, result]; - } - }); - }); - }; - DataStream.prototype.resolveFully = function () { - return __awaiter(this, void 0, void 0, function () { - var x; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.next()]; - case 1: - x = _a.sent(); - _a.label = 2; - case 2: - if (!(x != null)) return [3, 4]; - return [4, this.next()]; - case 3: - x = _a.sent(); - return [3, 2]; - case 4: return [2]; - } - }); - }); - }; - DataStream.prototype.filter = function (predicate) { - return new FilterStream(this, predicate); - }; - DataStream.prototype.map = function (transform) { - return new MapStream(this, transform); - }; - DataStream.prototype.forEach = function (f) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.map(f).resolveFully()]; - }); - }); - }; - DataStream.prototype.batch = function (batchSize, smallLastBatch) { - if (smallLastBatch === void 0) { smallLastBatch = true; } - return new BatchStream(this, batchSize, smallLastBatch); - }; - DataStream.prototype.concatenate = function (stream) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, ChainedStream.create(new ArrayStream([this, stream]))]; - }); - }); - }; - DataStream.prototype.take = function (count) { - if (count < 0 || count == null) - return this; - return new TakeStream(this, count); - }; - DataStream.prototype.skip = function (count) { - if (count < 0 || count == null) - return this; - return new SkipStream(this, count); - }; - DataStream.prototype.prefetch = function (bufferSize) { - return new PrefetchStream(this, bufferSize); - }; - DataStream.prototype.shuffle = function (windowSize, seed) { - return new ShuffleStream(this, windowSize, seed); - }; - return DataStream; -}()); -exports.DataStream = DataStream; -var ArrayStream = (function (_super) { - __extends(ArrayStream, _super); - function ArrayStream(items) { - var _this = _super.call(this) || this; - _this.items = items; - _this.trav = 0; - return _this; - } - ArrayStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - if (this.trav >= this.items.length) { - return [2, undefined]; - } - result = this.items[this.trav]; - this.trav++; - return [2, result]; - }); - }); - }; - return ArrayStream; -}(DataStream)); -var FunctionCallStream = (function (_super) { - __extends(FunctionCallStream, _super); - function FunctionCallStream(nextFn) { - var _this = _super.call(this) || this; - _this.nextFn = nextFn; - return _this; - } - FunctionCallStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.nextFn()]; - }); - }); - }; - return FunctionCallStream; -}(DataStream)); -var SkipStream = (function (_super) { - __extends(SkipStream, _super); - function SkipStream(upstream, maxCount) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.maxCount = maxCount; - _this.count = 0; - return _this; - } - SkipStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var skipped; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.count++ < this.maxCount)) return [3, 2]; - return [4, this.upstream.next()]; - case 1: - skipped = _a.sent(); - if (skipped == null) { - return [2, undefined]; - } - return [3, 0]; - case 2: return [2, this.upstream.next()]; - } - }); - }); - }; - return SkipStream; -}(DataStream)); -var TakeStream = (function (_super) { - __extends(TakeStream, _super); - function TakeStream(upstream, maxCount) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.maxCount = maxCount; - _this.count = 0; - return _this; - } - TakeStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - if (this.count++ >= this.maxCount) { - return [2, undefined]; - } - return [2, this.upstream.next()]; - }); - }); - }; - return TakeStream; -}(DataStream)); -var QueueStream = (function (_super) { - __extends(QueueStream, _super); - function QueueStream() { - var _this = _super.call(this) || this; - _this.outputQueue = new growing_ring_buffer_1.GrowingRingBuffer(); - return _this; - } - QueueStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.outputQueue.length() === 0)) return [3, 2]; - return [4, this.pump()]; - case 1: - if (!(_a.sent())) { - return [2, undefined]; - } - return [3, 0]; - case 2: return [2, this.outputQueue.shift()]; - } - }); - }); - }; - return QueueStream; -}(DataStream)); -exports.QueueStream = QueueStream; -var BatchStream = (function (_super) { - __extends(BatchStream, _super); - function BatchStream(upstream, batchSize, enableSmallLastBatch) { - if (enableSmallLastBatch === void 0) { enableSmallLastBatch = true; } - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.batchSize = batchSize; - _this.enableSmallLastBatch = enableSmallLastBatch; - _this.currentBatch = []; - return _this; - } - BatchStream.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var item; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - item = _a.sent(); - if (item == null) { - if (this.enableSmallLastBatch && this.currentBatch.length > 0) { - this.outputQueue.push(this.currentBatch); - this.currentBatch = []; - return [2, true]; - } - return [2, false]; - } - this.currentBatch.push(item); - if (this.currentBatch.length === this.batchSize) { - this.outputQueue.push(this.currentBatch); - this.currentBatch = []; - } - return [2, true]; - } - }); - }); - }; - return BatchStream; -}(QueueStream)); -var FilterStream = (function (_super) { - __extends(FilterStream, _super); - function FilterStream(upstream, predicate) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.predicate = predicate; - return _this; - } - FilterStream.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var item, accept; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - item = _a.sent(); - if (item == null) { - return [2, false]; - } - accept = this.predicate(item); - if (!(accept instanceof Promise)) return [3, 3]; - return [4, accept]; - case 2: - accept = _a.sent(); - _a.label = 3; - case 3: - if (accept) { - this.outputQueue.push(item); - } - return [2, true]; - } - }); - }); - }; - return FilterStream; -}(QueueStream)); -var MapStream = (function (_super) { - __extends(MapStream, _super); - function MapStream(upstream, transform) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.transform = transform; - return _this; - } - MapStream.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var item, mapped; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.upstream.next()]; - case 1: - item = _a.sent(); - if (item == null) { - return [2, false]; - } - mapped = this.transform(item); - if (!(mapped instanceof Promise)) return [3, 3]; - return [4, mapped]; - case 2: - mapped = _a.sent(); - _a.label = 3; - case 3: - this.outputQueue.push(mapped); - return [2, true]; - } - }); - }); - }; - return MapStream; -}(QueueStream)); -var ChainState = (function () { - function ChainState(item, currentStream, moreStreams) { - this.item = item; - this.currentStream = currentStream; - this.moreStreams = moreStreams; - } - return ChainState; -}()); -function nextChainState(afterState) { - return __awaiter(this, void 0, void 0, function () { - var state, stream, item; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, afterState]; - case 1: - state = _a.sent(); - stream = state.currentStream; - if (stream == null) { - return [2, new ChainState(undefined, undefined, state.moreStreams)]; - } - return [4, stream.next()]; - case 2: - item = _a.sent(); - if (!(item == null)) return [3, 4]; - return [4, state.moreStreams.next()]; - case 3: - stream = _a.sent(); - return [2, nextChainState(Promise.resolve(new ChainState(undefined, stream, state.moreStreams)))]; - case 4: return [2, new ChainState(item, stream, state.moreStreams)]; - } - }); - }); -} -var ChainedStream = (function (_super) { - __extends(ChainedStream, _super); - function ChainedStream() { - return _super !== null && _super.apply(this, arguments) || this; - } - ChainedStream.create = function (baseStreams) { - return __awaiter(this, void 0, void 0, function () { - var c, currentStream; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - c = new ChainedStream(); - return [4, baseStreams.next()]; - case 1: - currentStream = _a.sent(); - c.currentPromise = - Promise.resolve(new ChainState(undefined, currentStream, baseStreams)); - return [2, c]; - } - }); - }); - }; - ChainedStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.currentPromise = nextChainState(this.currentPromise); - return [4, this.currentPromise]; - case 1: return [2, (_a.sent()).item]; - } - }); - }); - }; - return ChainedStream; -}(DataStream)); -exports.ChainedStream = ChainedStream; -var PrefetchStream = (function (_super) { - __extends(PrefetchStream, _super); - function PrefetchStream(upstream, bufferSize) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.bufferSize = bufferSize; - _this.total = 0; - _this.buffer = new ring_buffer_1.RingBuffer(bufferSize); - return _this; - } - PrefetchStream.prototype.refill = function () { - while (!this.buffer.isFull()) { - var v = this.upstream.next(); - if (v == null) { - return; - } - this.buffer.push(v); - } - }; - PrefetchStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.refill(); - if (this.buffer.isEmpty()) - return [2, undefined]; - return [4, this.buffer.shift()]; - case 1: - result = _a.sent(); - this.refill(); - return [2, result]; - } - }); - }); - }; - return PrefetchStream; -}(DataStream)); -exports.PrefetchStream = PrefetchStream; -var ShuffleStream = (function (_super) { - __extends(ShuffleStream, _super); - function ShuffleStream(upstream, windowSize, seed) { - var _this = _super.call(this, upstream, windowSize) || this; - _this.upstream = upstream; - _this.windowSize = windowSize; - _this.upstreamExhausted = false; - _this.random = seedrandom(seed); - return _this; - } - ShuffleStream.prototype.randomInt = function (max) { - return Math.floor(this.random() * max); - }; - ShuffleStream.prototype.chooseIndex = function () { - return this.randomInt(this.buffer.length()); - }; - ShuffleStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var chosenIndex, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!this.upstreamExhausted) { - this.refill(); - } - _a.label = 1; - case 1: - if (!!this.buffer.isEmpty()) return [3, 3]; - chosenIndex = this.chooseIndex(); - return [4, this.buffer.shuffleExcise(chosenIndex)]; - case 2: - result = _a.sent(); - if (result == null) { - this.upstreamExhausted = true; - } - else { - this.refill(); - return [2, result]; - } - return [3, 1]; - case 3: return [2, undefined]; - } - }); - }); - }; - return ShuffleStream; -}(PrefetchStream)); -exports.ShuffleStream = ShuffleStream; - -},{"../util/growing_ring_buffer":24,"../util/ring_buffer":25,"seedrandom":153}],21:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var byte_stream_1 = require("./byte_stream"); -var FileReaderStream = (function (_super) { - __extends(FileReaderStream, _super); - function FileReaderStream(file, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.file = file; - _this.options = options; - _this.offset = options.offset || 0; - _this.chunkSize = options.chunkSize || 1024 * 1024; - return _this; - } - FileReaderStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - var chunk; - return __generator(this, function (_a) { - if (this.offset >= this.file.size) { - return [2, undefined]; - } - chunk = new Promise(function (resolve, reject) { - var fileReader = new FileReader(); - fileReader.onload = function (event) { - var data = fileReader.result; - if (data instanceof ArrayBuffer) { - data = new Uint8Array(data); - } - if (!(data instanceof Uint8Array)) { - return reject(new TypeError('FileReader returned unknown type.')); - } - resolve(data); - }; - fileReader.onabort = function (event) { - return reject(new Error('Aborted')); - }; - fileReader.onerror = function (event) { - return reject(new Error(event.error)); - }; - var end = _this.offset + _this.chunkSize; - var slice = _this.file.slice(_this.offset, end); - fileReader.readAsArrayBuffer(slice); - _this.offset = end; - }); - return [2, chunk]; - }); - }); - }; - return FileReaderStream; -}(byte_stream_1.ByteStream)); -exports.FileReaderStream = FileReaderStream; - -},{"./byte_stream":19}],22:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var data_stream_1 = require("./data_stream"); -var StringStream = (function (_super) { - __extends(StringStream, _super); - function StringStream() { - return _super !== null && _super.apply(this, arguments) || this; - } - StringStream.prototype.split = function (separator) { - return new SplitStream(this, separator); - }; - return StringStream; -}(data_stream_1.DataStream)); -exports.StringStream = StringStream; -var SplitStream = (function (_super) { - __extends(SplitStream, _super); - function SplitStream(upstream, separator) { - var _this = _super.call(this) || this; - _this.impl = new SplitStreamImpl(upstream, separator); - return _this; - } - SplitStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.impl.next()]; - }); - }); - }; - return SplitStream; -}(StringStream)); -var SplitStreamImpl = (function (_super) { - __extends(SplitStreamImpl, _super); - function SplitStreamImpl(upstream, separator) { - var _this = _super.call(this) || this; - _this.upstream = upstream; - _this.separator = separator; - _this.carryover = ''; - return _this; - } - SplitStreamImpl.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var chunk, lines, _i, _a, line; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4, this.upstream.next()]; - case 1: - chunk = _b.sent(); - if (chunk == null) { - if (this.carryover === '') { - return [2, false]; - } - this.outputQueue.push(this.carryover); - this.carryover = ''; - return [2, true]; - } - lines = chunk.split(this.separator); - lines[0] = this.carryover + lines[0]; - for (_i = 0, _a = lines.slice(0, -1); _i < _a.length; _i++) { - line = _a[_i]; - this.outputQueue.push(line); - } - this.carryover = lines[lines.length - 1]; - return [2, true]; - } - }); - }); - }; - return SplitStreamImpl; -}(data_stream_1.QueueStream)); - -},{"./data_stream":20}],23:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var byte_stream_1 = require("./byte_stream"); -var data_stream_1 = require("./data_stream"); -var filereader_stream_1 = require("./filereader_stream"); -var URLStream = (function (_super) { - __extends(URLStream, _super); - function URLStream(url, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.impl = new URLStreamImpl(url, options); - return _this; - } - URLStream.prototype.next = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.impl.next()]; - }); - }); - }; - return URLStream; -}(byte_stream_1.ByteStream)); -exports.URLStream = URLStream; -var URLStreamImpl = (function (_super) { - __extends(URLStreamImpl, _super); - function URLStreamImpl(url, options) { - if (options === void 0) { options = {}; } - var _this = _super.call(this) || this; - _this.url = url; - _this.options = options; - _this.blobPromise = fetch(url, options).then(function (response) { - if (response.ok) { - return response.blob(); - } - else { - throw new Error(response.statusText); - } - }); - return _this; - } - URLStreamImpl.prototype.pump = function () { - return __awaiter(this, void 0, void 0, function () { - var blob, chunk; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.fileReaderStream == null)) return [3, 2]; - return [4, this.blobPromise]; - case 1: - blob = _a.sent(); - this.fileReaderStream = new filereader_stream_1.FileReaderStream(blob, this.options); - _a.label = 2; - case 2: return [4, this.fileReaderStream.next()]; - case 3: - chunk = _a.sent(); - if (chunk == null) - return [2, false]; - this.outputQueue.push(chunk); - return [2, true]; - } - }); - }); - }; - return URLStreamImpl; -}(data_stream_1.QueueStream)); - -},{"./byte_stream":19,"./data_stream":20,"./filereader_stream":21}],24:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var ring_buffer_1 = require("./ring_buffer"); -var GrowingRingBuffer = (function (_super) { - __extends(GrowingRingBuffer, _super); - function GrowingRingBuffer() { - return _super.call(this, GrowingRingBuffer.INITIAL_CAPACITY) || this; - } - GrowingRingBuffer.prototype.isFull = function () { - return false; - }; - GrowingRingBuffer.prototype.push = function (value) { - if (_super.prototype.isFull.call(this)) { - this.expand(); - } - _super.prototype.push.call(this, value); - }; - GrowingRingBuffer.prototype.unshift = function (value) { - if (_super.prototype.isFull.call(this)) { - this.expand(); - } - _super.prototype.unshift.call(this, value); - }; - GrowingRingBuffer.prototype.expand = function () { - var newCapacity = this.capacity * 2; - var newData = new Array(newCapacity); - var len = this.length(); - for (var i = 0; i < len; i++) { - newData[i] = this.get(this.wrap(this.begin + i)); - } - this.data = newData; - this.capacity = newCapacity; - this.doubledCapacity = 2 * this.capacity; - this.begin = 0; - this.end = len; - }; - GrowingRingBuffer.INITIAL_CAPACITY = 32; - return GrowingRingBuffer; -}(ring_buffer_1.RingBuffer)); -exports.GrowingRingBuffer = GrowingRingBuffer; - -},{"./ring_buffer":25}],25:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var RingBuffer = (function () { - function RingBuffer(capacity) { - this.capacity = capacity; - this.begin = 0; - this.end = 0; - if (capacity < 1) { - throw new RangeError('Can\'t create ring buffer of capacity < 1.'); - } - this.data = new Array(capacity); - this.doubledCapacity = 2 * capacity; - } - RingBuffer.prototype.wrap = function (index) { - while (index < 0) { - index += this.doubledCapacity; - } - return index % this.doubledCapacity; - }; - RingBuffer.prototype.get = function (index) { - if (index < 0) { - throw new RangeError('Can\'t get item at a negative index.'); - } - return this.data[index % this.capacity]; - }; - RingBuffer.prototype.set = function (index, value) { - if (index < 0) { - throw new RangeError('Can\'t set item at a negative index.'); - } - this.data[index % this.capacity] = value; - }; - RingBuffer.prototype.length = function () { - var length = this.end - this.begin; - if (length < 0) { - length = this.doubledCapacity + length; - } - return length; - }; - RingBuffer.prototype.isFull = function () { - return this.length() === this.capacity; - }; - RingBuffer.prototype.isEmpty = function () { - return this.length() === 0; - }; - RingBuffer.prototype.push = function (value) { - if (this.isFull()) { - throw new RangeError('Ring buffer is full.'); - } - this.set(this.end, value); - this.end = this.wrap(this.end + 1); - }; - RingBuffer.prototype.pop = function () { - if (this.isEmpty()) { - throw new RangeError('Ring buffer is empty.'); - } - this.end = this.wrap(this.end - 1); - var result = this.get(this.end); - this.set(this.end, undefined); - return result; - }; - RingBuffer.prototype.unshift = function (value) { - if (this.isFull()) { - throw new RangeError('Ring buffer is full.'); - } - this.begin = this.wrap(this.begin - 1); - this.set(this.begin, value); - }; - RingBuffer.prototype.shift = function () { - if (this.isEmpty()) { - throw new RangeError('Ring buffer is empty.'); - } - var result = this.get(this.begin); - this.set(this.begin, undefined); - this.begin = this.wrap(this.begin + 1); - return result; - }; - RingBuffer.prototype.shuffleExcise = function (relativeIndex) { - if (this.isEmpty()) { - throw new RangeError('Ring buffer is empty.'); - } - var index = this.wrap(this.begin + relativeIndex); - var result = this.get(index); - this.set(index, this.pop()); - return result; - }; - return RingBuffer; -}()); -exports.RingBuffer = RingBuffer; - -},{}],26:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var dataset_1 = require("./data/dataset"); -exports.Dataset = dataset_1.Dataset; -var csv_dataset_1 = require("./data/datasets/csv_dataset"); -exports.CSVDataset = csv_dataset_1.CSVDataset; -var text_line_dataset_1 = require("./data/datasets/text_line_dataset"); -exports.TextLineDataset = text_line_dataset_1.TextLineDataset; -var file_data_source_1 = require("./data/sources/file_data_source"); -exports.FileDataSource = file_data_source_1.FileDataSource; -var url_data_source_1 = require("./data/sources/url_data_source"); -exports.URLDataSource = url_data_source_1.URLDataSource; - -},{"./data/dataset":12,"./data/datasets/csv_dataset":13,"./data/datasets/text_line_dataset":14,"./data/sources/file_data_source":16,"./data/sources/url_data_source":17}],27:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var MANIFEST_FILE = 'manifest.json'; -var CheckpointLoader = (function () { - function CheckpointLoader(urlPath) { - this.urlPath = urlPath; - if (this.urlPath.charAt(this.urlPath.length - 1) !== '/') { - this.urlPath += '/'; - } - } - CheckpointLoader.prototype.loadManifest = function () { - var _this = this; - return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', _this.urlPath + MANIFEST_FILE); - xhr.onload = function () { - _this.checkpointManifest = JSON.parse(xhr.responseText); - resolve(); - }; - xhr.onerror = function (error) { - throw new Error(MANIFEST_FILE + " not found at " + _this.urlPath + ". " + error); - }; - xhr.send(); - }); - }; - CheckpointLoader.prototype.getCheckpointManifest = function () { - var _this = this; - if (this.checkpointManifest == null) { - return new Promise(function (resolve, reject) { - _this.loadManifest().then(function () { - resolve(_this.checkpointManifest); - }); - }); - } - return new Promise(function (resolve, reject) { - resolve(_this.checkpointManifest); - }); - }; - CheckpointLoader.prototype.getAllVariables = function () { - var _this = this; - if (this.variables != null) { - return new Promise(function (resolve, reject) { - resolve(_this.variables); - }); - } - return new Promise(function (resolve, reject) { - _this.getCheckpointManifest().then(function (checkpointDefinition) { - var variableNames = Object.keys(_this.checkpointManifest); - var variablePromises = []; - for (var i = 0; i < variableNames.length; i++) { - variablePromises.push(_this.getVariable(variableNames[i])); - } - Promise.all(variablePromises).then(function (variables) { - _this.variables = {}; - for (var i = 0; i < variables.length; i++) { - _this.variables[variableNames[i]] = variables[i]; - } - resolve(_this.variables); - }); - }); - }); - }; - CheckpointLoader.prototype.getVariable = function (varName) { - var _this = this; - if (!(varName in this.checkpointManifest)) { - throw new Error('Cannot load non-existant variable ' + varName); - } - var variableRequestPromiseMethod = function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.responseType = 'arraybuffer'; - var fname = _this.checkpointManifest[varName].filename; - xhr.open('GET', _this.urlPath + fname); - xhr.onload = function () { - if (xhr.status === 404) { - throw new Error("Not found variable " + varName); - } - var values = new Float32Array(xhr.response); - var tensor = tensor_1.Tensor.make(_this.checkpointManifest[varName].shape, { values: values }); - resolve(tensor); - }; - xhr.onerror = function (error) { - throw new Error("Could not fetch variable " + varName + ": " + error); - }; - xhr.send(); - }; - if (this.checkpointManifest == null) { - return new Promise(function (resolve, reject) { - _this.loadManifest().then(function () { - new Promise(variableRequestPromiseMethod).then(resolve); - }); - }); - } - return new Promise(variableRequestPromiseMethod); - }; - return CheckpointLoader; -}()); -exports.CheckpointLoader = CheckpointLoader; - -},{"../tensor":146}],28:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var STATS_SAMPLE_PERCENTAGE = 0.1; -var InMemoryDataset = (function () { - function InMemoryDataset(dataShapes) { - this.dataShapes = dataShapes; - this.normalizationInfo = {}; - } - InMemoryDataset.prototype.getDataShape = function (dataIndex) { - return this.dataShapes[dataIndex]; - }; - InMemoryDataset.prototype.getData = function () { - return this.dataset; - }; - InMemoryDataset.prototype.getStats = function () { - var _this = this; - if (this.dataset == null) { - throw new Error('Data is null.'); - } - return this.dataset.map(function (d) { return _this.getStatsForData(d); }); - }; - InMemoryDataset.prototype.getStatsForData = function (data) { - var inputMin = Number.POSITIVE_INFINITY; - var inputMax = Number.NEGATIVE_INFINITY; - var exampleIndices = data.map(function (example, i) { return i; }); - util.shuffle(exampleIndices); - exampleIndices = - exampleIndices.slice(exampleIndices.length * STATS_SAMPLE_PERCENTAGE); - for (var i = 0; i < exampleIndices.length; i++) { - var inputValues = data[exampleIndices[i]].dataSync(); - for (var j = 0; j < inputValues.length; j++) { - inputMin = Math.min(inputMin, inputValues[j]); - inputMax = Math.max(inputMax, inputValues[j]); - } - } - return { - inputMin: inputMin, - inputMax: inputMax, - exampleCount: data.length, - shape: data[0].shape, - }; - }; - InMemoryDataset.prototype.normalizeExamplesToRange = function (examples, curLowerBounds, curUpperBounds, newLowerBounds, newUpperBounds) { - var curBoundsIsPerDimension = (curUpperBounds instanceof Float32Array && - curLowerBounds instanceof Float32Array); - var newBoundsIsPerDimension = (newLowerBounds instanceof Float32Array && - newUpperBounds instanceof Float32Array); - var inputSize = util.sizeFromShape(examples[0].shape); - var newExamples = []; - examples.forEach(function (example) { - var inputValues = example.dataSync(); - var normalizedValues = new Float32Array(inputSize); - for (var j = 0; j < inputSize; j++) { - var curLowerBound = curBoundsIsPerDimension ? - curLowerBounds[j] : - curLowerBounds; - var curUpperBound = curBoundsIsPerDimension ? - curUpperBounds[j] : - curUpperBounds; - var curRange = curUpperBound - curLowerBound; - var newLowerBound = newBoundsIsPerDimension ? - newLowerBounds[j] : - newLowerBounds; - var newUpperBound = newBoundsIsPerDimension ? - newUpperBounds[j] : - newUpperBounds; - var newRange = newUpperBound - newLowerBound; - if (curRange === 0) { - normalizedValues[j] = newLowerBound; - } - else { - normalizedValues[j] = newLowerBound + - newRange * (inputValues[j] - curLowerBound) / curRange; - } - } - newExamples.push(tensor_1.Tensor.make(example.shape, { values: normalizedValues }, 'float32')); - }); - return newExamples; - }; - InMemoryDataset.prototype.computeBounds = function (dataIndex) { - var _this = this; - if (this.dataset == null) { - throw new Error('Data is null.'); - } - var size = util.sizeFromShape(this.dataset[dataIndex][0].shape); - this.normalizationInfo[dataIndex] = { - isNormalized: false, - minValues: new Float32Array(size), - maxValues: new Float32Array(size) - }; - for (var i = 0; i < size; i++) { - this.normalizationInfo[dataIndex].minValues[i] = Number.POSITIVE_INFINITY; - this.normalizationInfo[dataIndex].maxValues[i] = Number.NEGATIVE_INFINITY; - } - this.dataset[dataIndex].forEach(function (example) { - var inputValues = example.dataSync(); - for (var k = 0; k < size; k++) { - _this.normalizationInfo[dataIndex].minValues[k] = Math.min(_this.normalizationInfo[dataIndex].minValues[k], inputValues[k]); - _this.normalizationInfo[dataIndex].maxValues[k] = Math.max(_this.normalizationInfo[dataIndex].maxValues[k], inputValues[k]); - } - }); - }; - InMemoryDataset.prototype.normalizeWithinBounds = function (dataIndex, lowerBound, upperBound) { - if (this.dataset == null) { - throw new Error('Data is null.'); - } - if (dataIndex >= this.dataset.length) { - throw new Error('dataIndex out of bounds.'); - } - if (this.normalizationInfo[dataIndex] == null) { - this.computeBounds(dataIndex); - } - var curLowerBounds; - var curUpperBounds; - if (this.normalizationInfo[dataIndex].isNormalized) { - curLowerBounds = this.normalizationInfo[dataIndex].lowerBound; - curUpperBounds = this.normalizationInfo[dataIndex].upperBound; - } - else { - curLowerBounds = this.normalizationInfo[dataIndex].minValues; - curUpperBounds = this.normalizationInfo[dataIndex].maxValues; - } - this.dataset[dataIndex] = this.normalizeExamplesToRange(this.dataset[dataIndex], curLowerBounds, curUpperBounds, lowerBound, upperBound); - this.normalizationInfo[dataIndex].isNormalized = true; - this.normalizationInfo[dataIndex].lowerBound = lowerBound; - this.normalizationInfo[dataIndex].upperBound = upperBound; - }; - InMemoryDataset.prototype.isNormalized = function (dataIndex) { - return this.normalizationInfo != null && - this.normalizationInfo[dataIndex].isNormalized; - }; - InMemoryDataset.prototype.removeNormalization = function (dataIndex) { - if (this.dataset == null) { - throw new Error('Training or test data is null.'); - } - if (!this.isNormalized(dataIndex)) { - return; - } - this.dataset[dataIndex] = this.normalizeExamplesToRange(this.dataset[dataIndex], this.normalizationInfo[dataIndex].lowerBound, this.normalizationInfo[dataIndex].upperBound, this.normalizationInfo[dataIndex].minValues, this.normalizationInfo[dataIndex].maxValues); - this.normalizationInfo[dataIndex].isNormalized = false; - }; - InMemoryDataset.prototype.unnormalizeExamples = function (examples, dataIndex) { - if (!this.isNormalized(dataIndex)) { - return examples; - } - return this.normalizeExamplesToRange(examples, this.normalizationInfo[dataIndex].lowerBound, this.normalizationInfo[dataIndex].upperBound, this.normalizationInfo[dataIndex].minValues, this.normalizationInfo[dataIndex].maxValues); - }; - InMemoryDataset.prototype.dispose = function () { - if (this.dataset == null) { - return; - } - for (var i = 0; i < this.dataset.length; i++) { - for (var j = 0; j < this.dataset[i].length; j++) { - this.dataset[i][j].dispose(); - } - } - this.dataset = []; - }; - return InMemoryDataset; -}()); -exports.InMemoryDataset = InMemoryDataset; - -},{"../tensor":146,"../util":151}],29:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -var InMemoryShuffledInputProviderBuilder = (function () { - function InMemoryShuffledInputProviderBuilder(inputs) { - this.inputs = inputs; - this.idx = 0; - this.inputCounter = 0; - this.epoch = 0; - this.shuffledIndices = util.createShuffledIndices(inputs[0].length); - this.numInputs = inputs.length; - var numExamples = this.inputs[0].length; - for (var i = 0; i < this.numInputs; i++) { - util.assert(this.inputs[i].length === numExamples, 'Number of examples must match across different inputs.'); - } - for (var i = 0; i < this.numInputs; i++) { - var inputShape = this.inputs[i][0].shape; - for (var j = 0; j < this.inputs[i].length; j++) { - util.assertShapesMatch(inputShape, this.inputs[i][j].shape); - } - } - } - InMemoryShuffledInputProviderBuilder.prototype.getCurrentExampleIndex = function () { - var returnIdx = this.idx; - this.inputCounter++; - if (this.inputCounter >= this.numInputs) { - this.idx++; - this.inputCounter = 0; - if (this.idx >= this.inputs[0].length) { - this.idx = 0; - this.epoch++; - } - } - return returnIdx; - }; - InMemoryShuffledInputProviderBuilder.prototype.getNextInput = function (inputId) { - var currentExampleIndex = this.getCurrentExampleIndex(); - return this.inputs[inputId][this.shuffledIndices[currentExampleIndex]]; - }; - InMemoryShuffledInputProviderBuilder.prototype.getEpoch = function () { - return this.epoch; - }; - InMemoryShuffledInputProviderBuilder.prototype.getInputProviders = function () { - var inputProviders = []; - for (var i = 0; i < this.numInputs; i++) { - inputProviders.push(this.getInputProvider(i)); - } - return inputProviders; - }; - return InMemoryShuffledInputProviderBuilder; -}()); -exports.InMemoryShuffledInputProviderBuilder = InMemoryShuffledInputProviderBuilder; -var InCPUMemoryShuffledInputProviderBuilder = (function (_super) { - __extends(InCPUMemoryShuffledInputProviderBuilder, _super); - function InCPUMemoryShuffledInputProviderBuilder() { - return _super !== null && _super.apply(this, arguments) || this; - } - InCPUMemoryShuffledInputProviderBuilder.prototype.getInputProvider = function (inputId) { - var shuffledInputProvider = this; - return { - getNextCopy: function () { - return shuffledInputProvider.getNextInput(inputId).clone(); - }, - disposeCopy: function (copy) { - copy.dispose(); - } - }; - }; - return InCPUMemoryShuffledInputProviderBuilder; -}(InMemoryShuffledInputProviderBuilder)); -exports.InCPUMemoryShuffledInputProviderBuilder = InCPUMemoryShuffledInputProviderBuilder; -var InGPUMemoryShuffledInputProviderBuilder = (function (_super) { - __extends(InGPUMemoryShuffledInputProviderBuilder, _super); - function InGPUMemoryShuffledInputProviderBuilder() { - return _super !== null && _super.apply(this, arguments) || this; - } - InGPUMemoryShuffledInputProviderBuilder.prototype.getInputProvider = function (inputId) { - var shuffledInputProvider = this; - return { - getNextCopy: function () { - return shuffledInputProvider.getNextInput(inputId).clone(); - }, - disposeCopy: function (copy) { - copy.dispose(); - } - }; - }; - return InGPUMemoryShuffledInputProviderBuilder; -}(InMemoryShuffledInputProviderBuilder)); -exports.InGPUMemoryShuffledInputProviderBuilder = InGPUMemoryShuffledInputProviderBuilder; - -},{"../util":151}],30:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var dataset_1 = require("./dataset"); -var PARSING_IMAGE_CANVAS_HEIGHT_PX = 1000; -function getXhrDatasetConfig(jsonConfigPath) { - return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', jsonConfigPath); - xhr.onload = function () { - resolve(JSON.parse(xhr.responseText)); - }; - xhr.onerror = function (error) { - reject(error); - }; - xhr.send(); - }); -} -exports.getXhrDatasetConfig = getXhrDatasetConfig; -var XhrDataset = (function (_super) { - __extends(XhrDataset, _super); - function XhrDataset(xhrDatasetConfig) { - var _this = _super.call(this, xhrDatasetConfig.data.map(function (x) { return x.shape; })) || this; - _this.xhrDatasetConfig = xhrDatasetConfig; - return _this; - } - XhrDataset.prototype.getTensor = function (info) { - var dataPromise = info.dataType === 'png' ? - parseTypedArrayFromPng(info, info.shape) : - parseTypedArrayFromBinary(info); - var inputSize = util.sizeFromShape(info.shape); - return dataPromise.then(function (data) { - var tensors = []; - for (var i = 0; i < data.length / inputSize; i++) { - var values = data.subarray(i * inputSize, (i + 1) * inputSize); - var tensor = tensor_1.Tensor.make(info.shape, { values: new Float32Array(values) }, 'float32'); - tensors.push(tensor); - } - return tensors; - }); - }; - XhrDataset.prototype.fetchData = function () { - var _this = this; - return new Promise(function (resolve, reject) { - var promises = _this.xhrDatasetConfig.data.map(function (x) { return _this.getTensor(x); }); - Promise.all(promises).then(function (data) { - _this.dataset = data; - resolve(); - }); - }); - }; - return XhrDataset; -}(dataset_1.InMemoryDataset)); -exports.XhrDataset = XhrDataset; -function parseTypedArrayFromBinary(info) { - return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', info.path); - xhr.responseType = 'arraybuffer'; - xhr.onload = function (event) { - var data = (info.dataType === 'float32') ? - new Float32Array(xhr.response) : - new Uint8Array(xhr.response); - resolve(data); - }; - xhr.onerror = function (err) { return reject(err); }; - xhr.send(); - }); -} -function parseGrayscaleImageData(data, result, resultOffset) { - var idx = resultOffset; - for (var i = 0; i < data.length; i += 4) { - result[idx++] = data[i]; - } -} -function parseRGBImageData(data, result, resultOffset) { - var idx = resultOffset; - for (var i = 0; i < data.length; i += 4) { - result[idx] = data[i]; - result[idx + 1] = data[i + 1]; - result[idx + 2] = data[i + 2]; - idx += 3; - } -} -function parseImage(img, shape) { - var canvas = document.createElement('canvas'); - var ctx = canvas.getContext('2d'); - var N = img.height; - var inputSize = util.sizeFromShape(shape); - var result = new Uint8Array(N * inputSize); - if (img.width !== shape[0] * shape[1]) { - throw new Error("Image width (" + img.width + ") must be multiple of " + - ("rows*columns (" + shape[0] + "*" + shape[1] + ") of the tensor")); - } - canvas.width = img.width; - canvas.height = PARSING_IMAGE_CANVAS_HEIGHT_PX; - var sx = 0; - var sWidth = canvas.width; - var sHeight = canvas.height; - var dx = 0; - var dy = 0; - var dWidth = sWidth; - var dHeight = sHeight; - var depth = shape[2]; - var offset = 0; - var numPasses = Math.ceil(N / canvas.height); - for (var pass = 0; pass < numPasses; ++pass) { - var sy = pass * canvas.height; - if ((pass === numPasses - 1) && (N % canvas.height > 0)) { - canvas.height = N % canvas.height; - sHeight = canvas.height; - dHeight = sHeight; - } - ctx.drawImage(img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); - var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data; - (depth === 1) ? parseGrayscaleImageData(data, result, offset) : - parseRGBImageData(data, result, offset); - offset += canvas.height * inputSize; - } - return result; -} -function parseTypedArrayFromPng(info, shape) { - return new Promise(function (resolve, reject) { - var img = new Image(); - img.setAttribute('crossOrigin', ''); - img.onload = function () { - var result = parseImage(img, shape); - img.src = ''; - img = null; - resolve(result); - }; - img.src = info.path; - }); -} - -},{"../tensor":146,"../util":151,"./dataset":28}],31:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function isMobile() { - var a = navigator.userAgent || navigator.vendor || window.opera; - return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i - .test(a) || - /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i - .test(a.substr(0, 4)); -} -exports.isMobile = isMobile; - -},{}],32:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function doc(info) { - return function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - }; -} -exports.doc = doc; - -},{}],33:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("./environment"); -var globals_1 = require("./globals"); -var kernel_registry = require("./kernels/kernel_registry"); -var ops = require("./ops/ops"); -var profiler_1 = require("./profiler"); -var tape_util = require("./tape_util"); -var tensor_1 = require("./tensor"); -var util = require("./util"); -var Engine = (function () { - function Engine(backend, customBackend, safeMode) { - this.backend = backend; - this.customBackend = customBackend; - this.safeMode = safeMode; - this.registeredVariables = {}; - this.refCounter = new WeakMap(); - this.nextTapeNodeId = 0; - this.numBytes = 0; - this.numTensors = 0; - this.numDataBuffers = 0; - this.gradientScopeCount = 0; - this.customGradientDepth = 0; - this.activeScope = { keep: [], track: [] }; - this.scopeStack = [this.activeScope]; - this.profiler = new profiler_1.Profiler(backend); - } - Engine.prototype.executeKernel = function (kernelName, config, grad) { - var _this = this; - var result; - if (!environment_1.ENV.get('DEBUG')) { - result = kernel_registry.executeKernel(this.backend, kernelName, config); - } - else { - result = this.profiler.profileKernel(kernelName, function () { - return kernel_registry.executeKernel(_this.backend, kernelName, config); - }); - } - var recordKernel = this.activeTape != null && this.customGradientDepth === 0; - if (recordKernel) { - config = tape_util.stripUndefinedInputsFromInputConfig(config); - var evaluatedNode = { - id: this.nextTapeNodeId++, - type: 'kernel', - name: "kernel: " + kernelName, - kernel: kernelName, - inputAndArgs: config, - output: result, - gradient: grad - }; - this.activeTape.push(evaluatedNode); - } - return result; - }; - Engine.prototype.registerTensor = function (a) { - var refCount = this.refCounter.has(a.dataId) ? this.refCounter.get(a.dataId) : 0; - this.numTensors++; - if (refCount === 0) { - this.numDataBuffers++; - this.numBytes += - util.sizeFromShape(a.shape) * util.bytesPerElement(a.dtype); - this.backend.register(a.dataId, a.shape, a.dtype); - } - this.refCounter.set(a.dataId, refCount + 1); - if (!(a instanceof tensor_1.Variable)) { - this.track(a); - } - }; - Engine.prototype.registerVariable = function (v) { - if (this.registeredVariables[v.name] != null) { - throw new Error("Variable with name " + v.name + " was already registered"); - } - this.registeredVariables[v.name] = v; - }; - Engine.prototype.disposeTensor = function (a) { - if (!this.refCounter.has(a.dataId)) { - return; - } - this.numTensors--; - var refCount = this.refCounter.get(a.dataId); - if (refCount <= 1) { - this.refCounter.delete(a.dataId); - this.backend.disposeData(a.dataId); - this.numDataBuffers--; - this.numBytes -= - util.sizeFromShape(a.shape) * util.bytesPerElement(a.dtype); - } - else { - this.refCounter.set(a.dataId, refCount - 1); - } - }; - Engine.prototype.memory = function () { - var info = this.backend.memory(); - info.numTensors = this.numTensors; - info.numDataBuffers = this.numDataBuffers; - info.numBytes = this.numBytes; - return info; - }; - Engine.prototype.shouldRecord = function () { - return this.activeTape != null && this.customGradientDepth === 0; - }; - Engine.prototype.addTapeNode = function (inputs, result, gradientsFunc) { - var inputsMap = {}; - inputs.forEach(function (input, idx) { - inputsMap[idx] = input; - }); - var gradient = function (dy) { - var res = gradientsFunc(dy); - var resMap = {}; - res.forEach(function (r, idx) { - resMap[idx] = function () { return r; }; - }); - return resMap; - }; - var evaluatedNode = { - id: this.nextTapeNodeId++, - type: 'customGradient', - name: name, - inputAndArgs: { inputs: inputsMap }, - output: result, - gradient: gradient - }; - this.activeTape.push(evaluatedNode); - }; - Engine.prototype.keep = function (result) { - if (this.scopeStack.length === 1 && environment_1.ENV.engine.safeMode) { - throw new Error('Safe mode is ON. Enclose all tensor operations inside dl.tidy(): ' + - 'dl.tidy(() => {...}) to avoid memory leaks.'); - } - this.activeScope.keep.push(result); - return result; - }; - Engine.prototype.startScope = function (gradientsMode) { - if (gradientsMode === void 0) { gradientsMode = false; } - if (gradientsMode && this.gradientScopeCount === 0) { - this.activeTape = []; - } - if (gradientsMode) { - this.gradientScopeCount++; - } - var newScopeArrays = { keep: [], track: [] }; - this.scopeStack.push(newScopeArrays); - this.activeScope = newScopeArrays; - }; - Engine.prototype.endScope = function (result, gradientsMode) { - var _this = this; - if (gradientsMode === void 0) { gradientsMode = false; } - if (gradientsMode) { - this.gradientScopeCount--; - if (this.gradientScopeCount === 0) { - this.activeTape = null; - } - } - var tensorsToKeep = this.activeScope.keep; - var tensorsToTrackInParent = tape_util.extractTensorsFromScopeResult(result); - tensorsToKeep = tensorsToKeep.concat(tensorsToTrackInParent); - for (var i = 0; i < this.activeScope.track.length; i++) { - var tensor = this.activeScope.track[i]; - if (util.isTensorInList(tensor, tensorsToKeep)) { - continue; - } - if (this.activeTape != null) { - tensorsToTrackInParent.push(tensor); - } - else { - tensor.dispose(); - } - } - this.scopeStack.pop(); - this.activeScope = this.scopeStack.length === 0 ? - { keep: [], track: [] } : - this.scopeStack[this.scopeStack.length - 1]; - tensorsToTrackInParent.forEach(function (tensor) { - if (!util.isTensorInList(tensor, _this.activeScope.keep)) { - _this.track(tensor); - } - }); - }; - Engine.prototype.dispose = function () { - if (this.customBackend) { - this.backend.dispose(); - } - }; - Engine.prototype.gradients = function (f, xs, dy, allowNoGradients) { - var _this = this; - if (allowNoGradients === void 0) { allowNoGradients = false; } - return globals_1.tidy('gradients', function () { - var y = f(); - util.assert(y instanceof tensor_1.Tensor, 'The result y returned by f() must be a tensor.'); - var filteredTape = tape_util.getFilteredNodesXToY(_this.activeTape, xs, y); - if (!allowNoGradients && filteredTape.length === 0 && xs.length > 0) { - throw new Error('Cannot compute gradient of y=f(x) with respect to x. Make sure ' + - 'that the f you passed encloses all operations that lead from x ' + - 'to y.'); - } - var accumulatedGradientMap = {}; - accumulatedGradientMap[y.id] = (dy == null) ? ops.onesLike(y) : dy; - tape_util.backpropagateGradients(accumulatedGradientMap, filteredTape); - var grads = xs.map(function (x) { return accumulatedGradientMap[x.id]; }); - return { value: y, grads: grads }; - }, true); - }; - Engine.prototype.customGrad = function (f) { - var _this = this; - util.assert(util.isFunction(f), 'The f passed in customGrad(f) must be a function.'); - return function () { - var inputs = []; - for (var _i = 0; _i < arguments.length; _i++) { - inputs[_i] = arguments[_i]; - } - util.assert(inputs.every(function (t) { return t instanceof tensor_1.Tensor; }), 'The args passed in customGrad(f)(x1, x2,...) must all be tensors'); - _this.customGradientDepth++; - var gradientsFunc; - var gradientsMode = true; - var result = globals_1.tidy(f.name, function () { - var _a = f.apply(void 0, inputs), value = _a.value, gradFunc = _a.gradFunc; - util.assert(value instanceof tensor_1.Tensor, 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.value` is a tensor'); - util.assert(util.isFunction(gradFunc), 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.gradFunc` is a function.'); - gradientsFunc = gradFunc; - return value; - }, gradientsMode); - _this.customGradientDepth--; - if (_this.shouldRecord()) { - var gradFunc = function (dy) { - var res = gradientsFunc(dy); - var grads = Array.isArray(res) ? res : [res]; - util.assert(grads.length === inputs.length, 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.gradFunc` is a function that returns the same ' + - 'number of tensors as inputs passed to f(...).'); - util.assert(grads.every(function (t) { return t instanceof tensor_1.Tensor; }), 'The function f passed in customGrad(f) must return an object ' + - 'where `obj.gradFunc` is a function that returns a list of ' + - 'only tensors.'); - return grads; - }; - _this.addTapeNode(inputs, result, gradFunc); - } - return result; - }; - }; - Engine.prototype.write = function (dataId, values) { - this.backend.write(dataId, values); - }; - Engine.prototype.readSync = function (dataId) { - return this.backend.readSync(dataId); - }; - Engine.prototype.read = function (dataId) { - return this.backend.read(dataId); - }; - Engine.prototype.fromPixels = function (pixels, numChannels) { - return this.backend.fromPixels(pixels, numChannels); - }; - Engine.prototype.time = function (query) { - return __awaiter(this, void 0, void 0, function () { - var start, timingInfo; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - start = performance.now(); - return [4, this.backend.time(query)]; - case 1: - timingInfo = _a.sent(); - timingInfo.wallMs = performance.now() - start; - return [2, timingInfo]; - } - }); - }); - }; - Engine.prototype.track = function (result) { - if (this.scopeStack.length === 1 && this.safeMode) { - throw new Error('Safe mode is ON. Enclose all tensor operations inside dl.tidy(): ' + - 'dl.tidy(() => {op();...}); to avoid memory leaks.'); - } - this.activeScope.track.push(result); - return result; - }; - return Engine; -}()); -exports.Engine = Engine; - -},{"./environment":34,"./globals":35,"./kernels/kernel_registry":70,"./ops/ops":123,"./profiler":144,"./tape_util":145,"./tensor":146,"./util":151}],34:[function(require,module,exports){ -(function (global){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var device_util = require("./device_util"); -var doc_1 = require("./doc"); -var engine_1 = require("./engine"); -var math_1 = require("./math"); -var util = require("./util"); -var Type; -(function (Type) { - Type[Type["NUMBER"] = 0] = "NUMBER"; - Type[Type["BOOLEAN"] = 1] = "BOOLEAN"; - Type[Type["STRING"] = 2] = "STRING"; -})(Type = exports.Type || (exports.Type = {})); -exports.URL_PROPERTIES = [ - { name: 'DEBUG', type: Type.BOOLEAN }, - { name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION', type: Type.NUMBER }, - { name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE', type: Type.BOOLEAN }, - { name: 'WEBGL_VERSION', type: Type.NUMBER }, - { name: 'WEBGL_FLOAT_TEXTURE_ENABLED', type: Type.BOOLEAN }, { - name: 'WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED', - type: Type.BOOLEAN - }, - { name: 'BACKEND', type: Type.STRING } -]; -function hasExtension(gl, extensionName) { - var ext = gl.getExtension(extensionName); - return ext != null; -} -function getWebGLRenderingContext(webGLVersion) { - if (webGLVersion === 0) { - throw new Error('Cannot get WebGL rendering context, WebGL is disabled.'); - } - var tempCanvas = document.createElement('canvas'); - if (webGLVersion === 1) { - return (tempCanvas.getContext('webgl') || - tempCanvas.getContext('experimental-webgl')); - } - return tempCanvas.getContext('webgl2'); -} -function loseContext(gl) { - if (gl != null) { - var loseContextExtension = gl.getExtension('WEBGL_lose_context'); - if (loseContextExtension == null) { - throw new Error('Extension WEBGL_lose_context not supported on this browser.'); - } - loseContextExtension.loseContext(); - } -} -function isWebGLVersionEnabled(webGLVersion) { - var gl = getWebGLRenderingContext(webGLVersion); - if (gl != null) { - loseContext(gl); - return true; - } - return false; -} -function getWebGLDisjointQueryTimerVersion(webGLVersion) { - if (webGLVersion === 0) { - return 0; - } - var queryTimerVersion; - var gl = getWebGLRenderingContext(webGLVersion); - if (hasExtension(gl, 'EXT_disjoint_timer_query_webgl2') && - webGLVersion === 2) { - queryTimerVersion = 2; - } - else if (hasExtension(gl, 'EXT_disjoint_timer_query')) { - queryTimerVersion = 1; - } - else { - queryTimerVersion = 0; - } - if (gl != null) { - loseContext(gl); - } - return queryTimerVersion; -} -function isFloatTextureReadPixelsEnabled(webGLVersion) { - if (webGLVersion === 0) { - return false; - } - var gl = getWebGLRenderingContext(webGLVersion); - if (webGLVersion === 1) { - if (!hasExtension(gl, 'OES_texture_float')) { - return false; - } - } - else { - if (!hasExtension(gl, 'EXT_color_buffer_float')) { - return false; - } - } - var frameBuffer = gl.createFramebuffer(); - var texture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, texture); - var internalFormat = webGLVersion === 2 ? gl.RGBA32F : gl.RGBA; - gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, 1, 1, 0, gl.RGBA, gl.FLOAT, null); - gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); - var frameBufferComplete = (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE); - gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.FLOAT, new Float32Array(4)); - var readPixelsNoError = gl.getError() === gl.NO_ERROR; - loseContext(gl); - return frameBufferComplete && readPixelsNoError; -} -function isWebGLGetBufferSubDataAsyncExtensionEnabled(webGLVersion) { - if (webGLVersion !== 2) { - return false; - } - var gl = getWebGLRenderingContext(webGLVersion); - var isEnabled = hasExtension(gl, 'WEBGL_get_buffer_sub_data_async'); - loseContext(gl); - return isEnabled; -} -var SUPPORTED_BACKENDS = ['webgl', 'cpu']; -var Environment = (function () { - function Environment(features) { - this.features = {}; - this.BACKEND_REGISTRY = {}; - this.backends = this.BACKEND_REGISTRY; - if (features != null) { - this.features = features; - } - if (this.get('DEBUG')) { - console.warn('Debugging mode is ON. The output of every math call will ' + - 'be downloaded to CPU and checked for NaNs. ' + - 'This significantly impacts performance.'); - } - } - Environment.setBackend = function (backendType, safeMode) { - if (safeMode === void 0) { safeMode = false; } - if (!(backendType in exports.ENV.backends)) { - throw new Error("Backend type '" + backendType + "' not found in registry"); - } - exports.ENV.globalMath = new math_1.NDArrayMath(backendType, safeMode); - }; - Environment.getBackend = function () { - exports.ENV.initEngine(); - return exports.ENV.currentBackendType; - }; - Environment.memory = function () { - return exports.ENV.engine.memory(); - }; - Environment.prototype.get = function (feature) { - if (feature in this.features) { - return this.features[feature]; - } - this.features[feature] = this.evaluateFeature(feature); - return this.features[feature]; - }; - Environment.prototype.set = function (feature, value) { - this.features[feature] = value; - }; - Environment.prototype.getBestBackendType = function () { - for (var i = 0; i < SUPPORTED_BACKENDS.length; ++i) { - var backendId = SUPPORTED_BACKENDS[i]; - if (backendId in this.backends) { - return backendId; - } - } - throw new Error('No backend found in registry.'); - }; - Environment.prototype.evaluateFeature = function (feature) { - if (feature === 'DEBUG') { - return false; - } - else if (feature === 'BACKEND') { - return this.getBestBackendType(); - } - else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') { - var webGLVersion = this.get('WEBGL_VERSION'); - if (webGLVersion === 0) { - return 0; - } - return getWebGLDisjointQueryTimerVersion(webGLVersion); - } - else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE') { - return this.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0 && - !device_util.isMobile(); - } - else if (feature === 'WEBGL_VERSION') { - if (isWebGLVersionEnabled(2)) { - return 2; - } - else if (isWebGLVersionEnabled(1)) { - return 1; - } - return 0; - } - else if (feature === 'WEBGL_FLOAT_TEXTURE_ENABLED') { - return isFloatTextureReadPixelsEnabled(this.get('WEBGL_VERSION')); - } - else if (feature === 'WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED') { - return isWebGLGetBufferSubDataAsyncExtensionEnabled(this.get('WEBGL_VERSION')); - } - throw new Error("Unknown feature " + feature + "."); - }; - Environment.prototype.setFeatures = function (features) { - this.reset(); - this.features = features; - this.backends = {}; - }; - Environment.prototype.reset = function () { - this.features = getFeaturesFromURL(); - if (this.globalMath != null) { - this.globalMath.dispose(); - this.globalMath = null; - this.globalEngine = null; - } - if (this.backends !== this.BACKEND_REGISTRY) { - for (var name_1 in this.backends) { - this.backends[name_1].dispose(); - } - this.backends = this.BACKEND_REGISTRY; - } - }; - Environment.prototype.setMath = function (math, backend, safeMode) { - if (safeMode === void 0) { safeMode = false; } - if (this.globalMath === math) { - return; - } - var customBackend = false; - if (typeof backend === 'string') { - this.currentBackendType = backend; - backend = exports.ENV.findBackend(backend); - } - else { - customBackend = true; - this.currentBackendType = 'custom'; - } - this.globalEngine = new engine_1.Engine(backend, customBackend, safeMode); - this.globalMath = math; - }; - Environment.prototype.findBackend = function (name) { - return this.backends[name]; - }; - Environment.prototype.addCustomBackend = function (name, factory) { - if (name in this.backends) { - throw new Error(name + " backend was already registered"); - } - try { - var backend = factory(); - this.backends[name] = backend; - return true; - } - catch (err) { - return false; - } - }; - Environment.prototype.registerBackend = function (name, factory) { - if (name in this.BACKEND_REGISTRY) { - throw new Error(name + " backend was already registered as global"); - } - try { - var backend = factory(); - this.BACKEND_REGISTRY[name] = backend; - return true; - } - catch (err) { - return false; - } - }; - Object.defineProperty(Environment.prototype, "math", { - get: function () { - if (this.globalEngine == null) { - this.initEngine(); - } - return this.globalMath; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Environment.prototype, "engine", { - get: function () { - if (this.globalEngine == null) { - this.initEngine(); - } - return this.globalEngine; - }, - enumerable: true, - configurable: true - }); - Environment.prototype.initEngine = function () { - this.globalMath = new math_1.NDArrayMath(exports.ENV.get('BACKEND'), false); - }; - __decorate([ - doc_1.doc({ heading: 'Environment' }) - ], Environment, "setBackend", null); - __decorate([ - doc_1.doc({ heading: 'Environment' }) - ], Environment, "getBackend", null); - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Memory' }) - ], Environment, "memory", null); - return Environment; -}()); -exports.Environment = Environment; -var DEEPLEARNJS_FLAGS_PREFIX = 'dljsflags'; -function getFeaturesFromURL() { - var features = {}; - if (typeof window === 'undefined') { - return features; - } - var urlParams = util.getQueryParams(window.location.search); - if (DEEPLEARNJS_FLAGS_PREFIX in urlParams) { - var urlFlags_1 = {}; - var keyValues = urlParams[DEEPLEARNJS_FLAGS_PREFIX].split(','); - keyValues.forEach(function (keyValue) { - var _a = keyValue.split(':'), key = _a[0], value = _a[1]; - urlFlags_1[key] = value; - }); - exports.URL_PROPERTIES.forEach(function (urlProperty) { - if (urlProperty.name in urlFlags_1) { - console.log("Setting feature override from URL " + urlProperty.name + ": " + - ("" + urlFlags_1[urlProperty.name])); - if (urlProperty.type === Type.NUMBER) { - features[urlProperty.name] = +urlFlags_1[urlProperty.name]; - } - else if (urlProperty.type === Type.BOOLEAN) { - features[urlProperty.name] = urlFlags_1[urlProperty.name] === 'true'; - } - else if (urlProperty.type === Type.STRING) { - features[urlProperty.name] = urlFlags_1[urlProperty.name]; - } - else { - console.warn("Unknown URL param: " + urlProperty.name + "."); - } - } - }); - } - return features; -} -function getGlobalNamespace() { - var ns; - if (typeof (window) !== 'undefined') { - ns = window; - } - else if (typeof (global) !== 'undefined') { - ns = global; - } - else { - throw new Error('Could not find a global object'); - } - return ns; -} -function getOrMakeEnvironment() { - var ns = getGlobalNamespace(); - ns.ENV = ns.ENV || new Environment(getFeaturesFromURL()); - return ns.ENV; -} -exports.ENV = getOrMakeEnvironment(); - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./device_util":31,"./doc":32,"./engine":33,"./math":105,"./util":151}],35:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var gradients_1 = require("./gradients"); -var tracking_1 = require("./tracking"); -exports.tidy = tracking_1.Tracking.tidy; -exports.keep = tracking_1.Tracking.keep; -exports.time = tracking_1.Tracking.time; -exports.grad = gradients_1.Gradients.grad; -exports.valueAndGrad = gradients_1.Gradients.valueAndGrad; -exports.grads = gradients_1.Gradients.grads; -exports.valueAndGrads = gradients_1.Gradients.valueAndGrads; -exports.variableGrads = gradients_1.Gradients.variableGrads; -exports.customGrad = gradients_1.Gradients.customGrad; - -},{"./gradients":36,"./tracking":148}],36:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var environment_1 = require("./environment"); -var globals_1 = require("./globals"); -var tensor_1 = require("./tensor"); -var util = require("./util"); -var Gradients = (function () { - function Gradients() { - } - Gradients.gradScope = function (nameOrScopeFn, scopeFn) { - return globals_1.tidy(nameOrScopeFn, scopeFn, true); - }; - Gradients.grad = function (f) { - util.assert(util.isFunction(f), 'The f passed in grad(f) must be a function'); - return function (x, dy) { - util.assert(x instanceof tensor_1.Tensor, 'The x passed in grad(f)(x) must be a tensor'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in grad(f)(x, dy) must be a tensor'); - var _a = environment_1.ENV.engine.gradients(function () { return f(x); }, [x], dy), value = _a.value, grads = _a.grads; - if (dy != null) { - util.assertShapesMatch(value.shape, dy.shape, 'The shape of dy passed in grad(f)(x, dy) must match the shape ' + - 'returned by f(x)'); - } - value.dispose(); - checkGrads(grads); - return grads[0]; - }; - }; - Gradients.grads = function (f) { - util.assert(util.isFunction(f), 'The f passed in grads(f) must be a function'); - return function (args, dy) { - util.assert(Array.isArray(args) && args.every(function (arg) { return arg instanceof tensor_1.Tensor; }), 'The args passed in grads(f)(args) must be an array of tensors'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in grads(f)(args, dy) must be a tensor'); - var _a = environment_1.ENV.engine.gradients(function () { return f.apply(void 0, args); }, args, dy), value = _a.value, grads = _a.grads; - if (dy != null) { - util.assertShapesMatch(value.shape, dy.shape, 'The shape of dy passed in grads(f)([x1,...], dy) must match the ' + - 'shape returned by f([x1,...])'); - } - value.dispose(); - checkGrads(grads); - return grads; - }; - }; - Gradients.valueAndGrad = function (f) { - util.assert(util.isFunction(f), 'The f passed in valueAndGrad(f) must be a function'); - return function (x, dy) { - util.assert(x instanceof tensor_1.Tensor, 'The x passed in valueAndGrad(f)(x) must be a tensor'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in valueAndGrad(f)(x, dy) must be a tensor'); - var _a = environment_1.ENV.engine.gradients(function () { return f(x); }, [x], dy), grads = _a.grads, value = _a.value; - checkGrads(grads); - return { grad: grads[0], value: value }; - }; - }; - Gradients.valueAndGrads = function (f) { - util.assert(util.isFunction(f), 'The f passed in valueAndGrads(f) must be a function'); - return function (args, dy) { - util.assert(Array.isArray(args) && args.every(function (arg) { return arg instanceof tensor_1.Tensor; }), 'The args passed in valueAndGrads(f)(args) must be array of tensors'); - util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in valueAndGrads(f)(args, dy) must be a tensor'); - var res = environment_1.ENV.engine.gradients(function () { return f.apply(void 0, args); }, args, dy); - if (dy != null) { - util.assertShapesMatch(res.value.shape, dy.shape, 'The shape of dy passed in valueAndGrads(f)([x1,...], dy) must ' + - 'match the shape returned by f([x1,...])'); - } - checkGrads(res.grads); - return res; - }; - }; - Gradients.variableGrads = function (f, varList) { - util.assert(util.isFunction(f), 'The f passed in variableGrads(f) must be a function'); - util.assert(varList == null || - Array.isArray(varList) && varList.every(function (v) { return v instanceof tensor_1.Variable; }), 'The varList passed in variableGrads(f, varList) must be an array ' + - 'of variables'); - if (varList == null) { - varList = []; - for (var varName in environment_1.ENV.engine.registeredVariables) { - varList.push(environment_1.ENV.engine.registeredVariables[varName]); - } - } - varList = varList.filter(function (variable) { return variable.trainable; }); - var allowNoGradients = true; - var _a = environment_1.ENV.engine.gradients(f, varList, null, allowNoGradients), value = _a.value, grads = _a.grads; - util.assert(grads.some(function (g) { return g != null; }), 'Cannot find a connection between any variable and the result of the ' + - 'loss function y=f(x). Please make sure the operations that use ' + - 'variables are inside the function f passed to minimize().'); - util.assert(value.rank === 0, "The f passed in variableGrads(f) must return a scalar, but it " + - ("returned a rank-" + value.rank + " tensor")); - var namedGrads = {}; - varList.forEach(function (v, i) { - if (grads[i] != null) { - namedGrads[v.name] = grads[i]; - } - }); - return { value: value, grads: namedGrads }; - }; - Gradients.customGrad = function (f) { - return environment_1.ENV.engine.customGrad(f); - }; - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "grad", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "grads", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "valueAndGrad", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "valueAndGrads", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "variableGrads", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Gradients' }) - ], Gradients, "customGrad", null); - return Gradients; -}()); -exports.Gradients = Gradients; -function checkGrads(grads) { - var numNullGradients = grads.filter(function (g) { return g == null; }).length; - if (numNullGradients > 0) { - throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y."); - } -} - -},{"./doc":32,"./environment":34,"./globals":35,"./tensor":146,"./util":151}],37:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var TanHFunc = (function () { - function TanHFunc() { - this.one = tensor_1.Scalar.new(1); - } - TanHFunc.prototype.output = function (math, x) { - return math.tanh(x); - }; - TanHFunc.prototype.der = function (math, x, y) { - var _this = this; - return globals_1.tidy(function () { - var ySquared = math.multiplyStrict(y, y); - return math.subtract(_this.one, ySquared); - }); - }; - TanHFunc.prototype.dispose = function () { - this.one.dispose(); - }; - return TanHFunc; -}()); -exports.TanHFunc = TanHFunc; -var ReLUFunc = (function () { - function ReLUFunc() { - } - ReLUFunc.prototype.output = function (math, x) { - return math.relu(x); - }; - ReLUFunc.prototype.der = function (math, x, y) { - return math.step(x); - }; - ReLUFunc.prototype.dispose = function () { }; - return ReLUFunc; -}()); -exports.ReLUFunc = ReLUFunc; -var LeakyReluFunc = (function () { - function LeakyReluFunc(alpha) { - this.alpha = alpha; - } - LeakyReluFunc.prototype.output = function (math, x) { - return math.leakyRelu(x, this.alpha); - }; - LeakyReluFunc.prototype.der = function (math, x, y) { - return math.step(x, this.alpha); - }; - LeakyReluFunc.prototype.dispose = function () { }; - return LeakyReluFunc; -}()); -exports.LeakyReluFunc = LeakyReluFunc; -var SigmoidFunc = (function () { - function SigmoidFunc() { - } - SigmoidFunc.prototype.output = function (math, x) { - return math.sigmoid(x); - }; - SigmoidFunc.prototype.der = function (math, x, y) { - return globals_1.tidy(function () { - var ySquared = math.multiplyStrict(y, y); - return math.subStrict(y, ySquared); - }); - }; - SigmoidFunc.prototype.dispose = function () { }; - return SigmoidFunc; -}()); -exports.SigmoidFunc = SigmoidFunc; -var SquareFunc = (function () { - function SquareFunc() { - this.two = tensor_1.Scalar.new(2); - } - SquareFunc.prototype.output = function (math, x) { - return math.multiplyStrict(x, x); - }; - SquareFunc.prototype.der = function (math, x, y) { - return math.multiply(this.two, x); - }; - SquareFunc.prototype.dispose = function () { - this.two.dispose(); - }; - return SquareFunc; -}()); -exports.SquareFunc = SquareFunc; -var EluFunc = (function () { - function EluFunc() { - } - EluFunc.prototype.output = function (math, x) { - return math.elu(x); - }; - EluFunc.prototype.der = function (math, x, y) { - throw new Error('Not implemented'); - }; - EluFunc.prototype.dispose = function () { }; - return EluFunc; -}()); -exports.EluFunc = EluFunc; - -},{"../globals":35,"../tensor":146}],38:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var ops = require("../ops/ops"); -var SquareCostFunc = (function () { - function SquareCostFunc() { - this.halfOne = globals_1.keep(ops.scalar(0.5)); - } - SquareCostFunc.prototype.cost = function (x1, x2) { - var diff = x1.subStrict(x2); - var diffSquared = diff.square(); - var result = this.halfOne.mul(diffSquared); - diff.dispose(); - diffSquared.dispose(); - return result; - }; - SquareCostFunc.prototype.der = function (x1, x2) { - return x1.subStrict(x2); - }; - SquareCostFunc.prototype.dispose = function () { - this.halfOne.dispose(); - }; - return SquareCostFunc; -}()); -exports.SquareCostFunc = SquareCostFunc; - -},{"../globals":35,"../ops/ops":123}],39:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var concat_util = require("../ops/concat_util"); -var conv_util = require("../ops/conv_util"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var initializers_1 = require("./initializers"); -var GraphLayers = (function () { - function GraphLayers(g) { - this.g = g; - } - GraphLayers.prototype.dense = function (name, x, units, activation, useBias, kernelInitializer, biasInitializer) { - if (activation === void 0) { activation = null; } - if (useBias === void 0) { useBias = true; } - if (kernelInitializer === void 0) { kernelInitializer = new initializers_1.VarianceScalingInitializer(); } - if (biasInitializer === void 0) { biasInitializer = new initializers_1.ZerosInitializer(); } - var weights = this.g.variable(name + '-weights', kernelInitializer.initialize([x.shape[0], units], x.shape[0], units)); - var out = this.g.matmul(x, weights); - if (useBias) { - var bias = this.g.variable(name + '-bias', biasInitializer.initialize([units], x.shape[0], units)); - out = this.g.add(out, bias); - } - if (activation != null) { - out = activation(out); - } - return out; - }; - return GraphLayers; -}()); -exports.GraphLayers = GraphLayers; -var Graph = (function () { - function Graph() { - this.nodes = []; - this.layers = new GraphLayers(this); - } - Graph.prototype.variable = function (name, data) { - return this.addNodeAndReturnOutput(new VariableNode(this, name, data)); - }; - Graph.prototype.placeholder = function (name, shape) { - return this.addNodeAndReturnOutput(new PlaceholderNode(this, name, shape)); - }; - Graph.prototype.constant = function (value) { - var finalValue; - if (typeof value === 'number') { - finalValue = tensor_1.Scalar.new(value); - } - else if (value instanceof tensor_1.Tensor) { - finalValue = value; - } - else if (value instanceof Array) { - var flatValues = util.flatten(value); - var vals = new Float32Array(flatValues); - finalValue = tensor_1.Tensor.make(util.inferShape(value), { values: vals }); - } - else { - throw new Error('unimplemented constant type.'); - } - return this.addNodeAndReturnOutput(new ConstantNode(this, finalValue)); - }; - Graph.prototype.reshape = function (x, shape) { - return this.addNodeAndReturnOutput(new ReshapeNode(this, 'Reshape', x, shape)); - }; - Graph.prototype.fusedLinearCombination = function (x1, x2, c1, c2) { - return this.addNodeAndReturnOutput(new FusedLinearCombinationNode(this, x1, x2, c1, c2)); - }; - Graph.prototype.add = function (x1, x2) { - return this.addNodeAndReturnOutput(new AddNode(this, x1, x2)); - }; - Graph.prototype.subtract = function (x1, x2) { - return this.addNodeAndReturnOutput(new SubtractNode(this, x1, x2)); - }; - Graph.prototype.multiply = function (x1, x2) { - return this.addNodeAndReturnOutput(new MultiplyNode(this, x1, x2)); - }; - Graph.prototype.divide = function (x1, x2) { - return this.addNodeAndReturnOutput(new DivideNode(this, x1, x2)); - }; - Graph.prototype.reduceSum = function (x) { - return this.addNodeAndReturnOutput(new ReduceSumNode(this, x)); - }; - Graph.prototype.concat1d = function (x1, x2) { - return this.addNodeAndReturnOutput(new Concat1DNode(this, x1, x2)); - }; - Graph.prototype.concat2d = function (x1, x2, axis) { - return this.addNodeAndReturnOutput(new Concat2DNode(this, x1, x2, axis)); - }; - Graph.prototype.concat3d = function (x1, x2, axis) { - return this.addNodeAndReturnOutput(new Concat3DNode(this, x1, x2, axis)); - }; - Graph.prototype.concat4d = function (x1, x2, axis) { - return this.addNodeAndReturnOutput(new Concat4DNode(this, x1, x2, axis)); - }; - Graph.prototype.matmul = function (x1, x2) { - return this.addNodeAndReturnOutput(new MatMulNode(this, x1, x2)); - }; - Graph.prototype.conv2d = function (x, w, b, fieldSize, outputDepth, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - return this.addNodeAndReturnOutput(new Convolution2DNode(this, x, w, b, fieldSize, outputDepth, stride, zeroPad)); - }; - Graph.prototype.maxPool = function (x, fieldSize, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - return this.addNodeAndReturnOutput(new MaxPoolNode(this, x, fieldSize, stride, zeroPad)); - }; - Graph.prototype.exp = function (x) { - return this.addNodeAndReturnOutput(new ExpNode(this, x)); - }; - Graph.prototype.log = function (x) { - return this.addNodeAndReturnOutput(new LogNode(this, x)); - }; - Graph.prototype.relu = function (x) { - return this.addNodeAndReturnOutput(new ReLUNode(this, x)); - }; - Graph.prototype.leakyRelu = function (x, alpha) { - return this.addNodeAndReturnOutput(new LeakyReLUNode(this, x, alpha)); - }; - Graph.prototype.prelu = function (x, alpha) { - return this.addNodeAndReturnOutput(new PReLUNode(this, x, alpha)); - }; - Graph.prototype.elu = function (x) { - return this.addNodeAndReturnOutput(new EluNode(this, x)); - }; - Graph.prototype.tanh = function (x) { - return this.addNodeAndReturnOutput(new TanHNode(this, x)); - }; - Graph.prototype.sigmoid = function (x) { - return this.addNodeAndReturnOutput(new SigmoidNode(this, x)); - }; - Graph.prototype.square = function (x) { - return this.addNodeAndReturnOutput(new SquareNode(this, x)); - }; - Graph.prototype.softmax = function (x) { - return this.addNodeAndReturnOutput(new SoftmaxNode(this, x)); - }; - Graph.prototype.softmaxCrossEntropyCost = function (x, target) { - return this.addNodeAndReturnOutput(new SoftmaxCrossEntropyCostNode(this, x, target)); - }; - Graph.prototype.meanSquaredCost = function (label, prediction) { - return this.addNodeAndReturnOutput(new MeanSquaredCostNode(this, label, prediction)); - }; - Graph.prototype.argmax = function (x) { - return this.addNodeAndReturnOutput(new ArgMaxNode(this, x)); - }; - Graph.prototype.argmaxEquals = function (x1, x2) { - return this.addNodeAndReturnOutput(new ArgMaxEqualsNode(this, x1, x2)); - }; - Graph.prototype.addNodeAndReturnOutput = function (node) { - this.nodes.push(node); - node.validate(); - return node.output; - }; - Graph.prototype.getNodes = function () { - return this.nodes; - }; - return Graph; -}()); -exports.Graph = Graph; -var SymbolicTensor = (function (_super) { - __extends(SymbolicTensor, _super); - function SymbolicTensor(shape) { - var _this = _super.call(this, [], 'float32') || this; - _this.shape = shape; - _this.id = SymbolicTensor.nextID++; - return _this; - } - SymbolicTensor.nextID = 0; - return SymbolicTensor; -}(tensor_1.Tensor)); -exports.SymbolicTensor = SymbolicTensor; -var Node = (function () { - function Node(graph, name, inputs, output) { - this.graph = graph; - this.name = name; - this.inputs = inputs; - this.output = output; - this.id = Node.nextID++; - output.node = this; - } - Node.nextID = 0; - return Node; -}()); -exports.Node = Node; -var VariableNode = (function (_super) { - __extends(VariableNode, _super); - function VariableNode(graph, name, data) { - var _this = _super.call(this, graph, name, {}, new SymbolicTensor(data.shape)) || this; - _this.data = data; - return _this; - } - VariableNode.prototype.validate = function () { - util.assert(this.data != null, 'Error adding variable op: Data for variable \'' + this.name + - '\' is null or undefined'); - }; - return VariableNode; -}(Node)); -exports.VariableNode = VariableNode; -var PlaceholderNode = (function (_super) { - __extends(PlaceholderNode, _super); - function PlaceholderNode(graph, name, shape) { - return _super.call(this, graph, name, {}, new SymbolicTensor(shape)) || this; - } - PlaceholderNode.prototype.validate = function () { }; - return PlaceholderNode; -}(Node)); -exports.PlaceholderNode = PlaceholderNode; -var ConstantNode = (function (_super) { - __extends(ConstantNode, _super); - function ConstantNode(graph, data) { - var _this = _super.call(this, graph, 'Constant', {}, new SymbolicTensor(data.shape)) || this; - _this.data = data; - return _this; - } - ConstantNode.prototype.validate = function () { - util.assert(this.data != null, 'Error adding constant: data for placeholder \'' + this.name + - '\' is null or undefined'); - }; - return ConstantNode; -}(Node)); -exports.ConstantNode = ConstantNode; -var ReshapeNode = (function (_super) { - __extends(ReshapeNode, _super); - function ReshapeNode(graph, name, x, shape) { - var _this = _super.call(this, graph, name, { x: x }, new SymbolicTensor(shape)) || this; - _this.name = name; - _this.x = x; - _this.shape = shape; - return _this; - } - ReshapeNode.prototype.validate = function () { - var xSize = util.sizeFromShape(this.x.shape); - var shapeSize = util.sizeFromShape(this.shape); - util.assert(xSize === shapeSize, "Error making reshape operation: input to reshape '" + this.name + "'" + - (" of shape (" + this.x.shape + ") does not match size of ") + - ("requested shape " + this.shape + ".")); - }; - ReshapeNode.X = 'x'; - return ReshapeNode; -}(Node)); -exports.ReshapeNode = ReshapeNode; -var FusedLinearCombinationNode = (function (_super) { - __extends(FusedLinearCombinationNode, _super); - function FusedLinearCombinationNode(graph, t1, t2, c1, c2) { - var _this = _super.call(this, graph, 'Linear Combination', { t1: t1, t2: t2, c1: c1, c2: c2 }, new SymbolicTensor(t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - _this.c1 = c1; - _this.c2 = c2; - return _this; - } - FusedLinearCombinationNode.prototype.validate = function () { - util.assertShapesMatch(this.t1.shape, this.t2.shape); - if (!util.isScalarShape(this.c1.shape)) { - throw new Error('Error adding fusedLinearCombination: c1 is not a scalar, got ' + - ("shape: " + this.c1.shape)); - } - if (!util.isScalarShape(this.c2.shape)) { - throw new Error('Error adding fusedLinearCombination: c2 is not a scalar, got ' + - ("shape: " + this.c2.shape)); - } - }; - FusedLinearCombinationNode.T1 = 't1'; - FusedLinearCombinationNode.T2 = 't2'; - FusedLinearCombinationNode.C1 = 'c1'; - FusedLinearCombinationNode.C2 = 'c2'; - return FusedLinearCombinationNode; -}(Node)); -exports.FusedLinearCombinationNode = FusedLinearCombinationNode; -var AddNode = (function (_super) { - __extends(AddNode, _super); - function AddNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Add', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? - t2.shape : - (t1.shape.length < t2.shape.length ? t2.shape : t1.shape))) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - AddNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape) || - (this.t1.shape.length === 2 && this.t2.shape.length === 1 && - this.t1.shape[1] === this.t2.shape[0]) || - (this.t1.shape.length === 1 && this.t2.shape.length === 2 && - this.t1.shape[0] === this.t2.shape[1]), 'Error adding add operation op: one of inputs must be scalar, ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match,") + - 'or one of them can be broadcasted (2D and 1D).'); - }; - AddNode.T1 = 't1'; - AddNode.T2 = 't2'; - return AddNode; -}(Node)); -exports.AddNode = AddNode; -var SubtractNode = (function (_super) { - __extends(SubtractNode, _super); - function SubtractNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Subtract', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? t2.shape : t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - SubtractNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape), 'Error adding subtract op: one of inputs must be scalar or the ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match.")); - }; - SubtractNode.T1 = 't1'; - SubtractNode.T2 = 't2'; - return SubtractNode; -}(Node)); -exports.SubtractNode = SubtractNode; -var MultiplyNode = (function (_super) { - __extends(MultiplyNode, _super); - function MultiplyNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Multiply', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? t2.shape : t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - MultiplyNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape), 'Error adding multiply op: one of inputs must be scalar or the ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match.")); - }; - MultiplyNode.T1 = 't1'; - MultiplyNode.T2 = 't2'; - return MultiplyNode; -}(Node)); -exports.MultiplyNode = MultiplyNode; -var DivideNode = (function (_super) { - __extends(DivideNode, _super); - function DivideNode(graph, t1, t2) { - var _this = _super.call(this, graph, 'Divide', { t1: t1, t2: t2 }, new SymbolicTensor(util.sizeFromShape(t1.shape) === 1 ? t2.shape : t1.shape)) || this; - _this.t1 = t1; - _this.t2 = t2; - return _this; - } - DivideNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.t1.shape) === 1 || - util.sizeFromShape(this.t2.shape) === 1 || - util.arraysEqual(this.t1.shape, this.t2.shape), 'Error adding divide op: one of inputs must be scalar or the ' + - ("shapes " + this.t1.shape + " and " + this.t2.shape + " must match.")); - }; - DivideNode.T1 = 't1'; - DivideNode.T2 = 't2'; - return DivideNode; -}(Node)); -exports.DivideNode = DivideNode; -var ReduceSumNode = (function (_super) { - __extends(ReduceSumNode, _super); - function ReduceSumNode(graph, x) { - return _super.call(this, graph, 'ReduceSum', { x: x }, new SymbolicTensor([])) || this; - } - ReduceSumNode.prototype.validate = function () { }; - ReduceSumNode.X = 'x'; - return ReduceSumNode; -}(Node)); -exports.ReduceSumNode = ReduceSumNode; -var Concat1DNode = (function (_super) { - __extends(Concat1DNode, _super); - function Concat1DNode(graph, x1, x2) { - return _super.call(this, graph, 'Concat1D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape1D(x1.shape, x2.shape))) || this; - } - Concat1DNode.prototype.validate = function () { }; - Concat1DNode.X1 = 'x1'; - Concat1DNode.X2 = 'x2'; - return Concat1DNode; -}(Node)); -exports.Concat1DNode = Concat1DNode; -var Concat2DNode = (function (_super) { - __extends(Concat2DNode, _super); - function Concat2DNode(graph, x1, x2, axis) { - var _this = _super.call(this, graph, 'Concat2D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape(x1.shape, x2.shape, axis))) || this; - _this.x1 = x1; - _this.x2 = x2; - _this.axis = axis; - return _this; - } - Concat2DNode.prototype.validate = function () { - concat_util.assertParams(this.x1.shape, this.x2.shape, this.axis); - }; - Concat2DNode.X1 = 'x1'; - Concat2DNode.X2 = 'x2'; - Concat2DNode.AXIS = 'axis'; - return Concat2DNode; -}(Node)); -exports.Concat2DNode = Concat2DNode; -var Concat3DNode = (function (_super) { - __extends(Concat3DNode, _super); - function Concat3DNode(graph, x1, x2, axis) { - var _this = _super.call(this, graph, 'Concat3D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape(x1.shape, x2.shape, axis))) || this; - _this.x1 = x1; - _this.x2 = x2; - _this.axis = axis; - return _this; - } - Concat3DNode.prototype.validate = function () { - concat_util.assertParams(this.x1.shape, this.x2.shape, this.axis); - }; - Concat3DNode.X1 = 'x1'; - Concat3DNode.X2 = 'x2'; - Concat3DNode.AXIS = 'axis'; - return Concat3DNode; -}(Node)); -exports.Concat3DNode = Concat3DNode; -var Concat4DNode = (function (_super) { - __extends(Concat4DNode, _super); - function Concat4DNode(graph, x1, x2, axis) { - var _this = _super.call(this, graph, 'Concat4D', { x1: x1, x2: x2 }, new SymbolicTensor(concat_util.computeOutShape(x1.shape, x2.shape, axis))) || this; - _this.x1 = x1; - _this.x2 = x2; - _this.axis = axis; - return _this; - } - Concat4DNode.prototype.validate = function () { - concat_util.assertParams(this.x1.shape, this.x2.shape, this.axis); - }; - Concat4DNode.X1 = 'x1'; - Concat4DNode.X2 = 'x2'; - Concat4DNode.AXIS = 'axis'; - return Concat4DNode; -}(Node)); -exports.Concat4DNode = Concat4DNode; -function getMatMulOutputShape(x1Shape, x2Shape) { - if (x1Shape.length === 1 && x2Shape.length === 1) { - return [1]; - } - else if (x1Shape.length === 1 && x2Shape.length === 2) { - return [x2Shape[1]]; - } - else if (x1Shape.length === 2 && x2Shape.length === 1) { - return [x1Shape[0]]; - } - return [x1Shape[0], x2Shape[1]]; -} -var MatMulNode = (function (_super) { - __extends(MatMulNode, _super); - function MatMulNode(graph, x1, x2) { - var _this = _super.call(this, graph, 'MatMul', { x1: x1, x2: x2 }, new SymbolicTensor(getMatMulOutputShape(x1.shape, x2.shape))) || this; - _this.x1 = x1; - _this.x2 = x2; - return _this; - } - MatMulNode.prototype.validate = function () { - if (this.x1.shape.length === 2 && this.x2.shape.length === 2) { - util.assert(this.x1.shape[1] === this.x2.shape[0], 'Error adding matmul op: inner shapes of matrices with shapes ' + - (this.x1.shape + " and " + this.x2.shape + " must match.")); - } - else if (this.x1.shape.length === 2 && this.x2.shape.length === 1) { - util.assert(this.x1.shape[1] === this.x2.shape[0], 'Error adding matmul op: second dimension of matrix with shape ' + - this.x1.shape.toString() + - (" must match size of vector with shape " + this.x2.shape + ".")); - } - else if (this.x1.shape.length === 1 && this.x2.shape.length === 2) { - util.assert(this.x1.shape[0] === this.x2.shape[0], "Error adding matmul op: size of vector with shape " + this.x1.shape + - " must match first dimension of matrix with " + - ("shape " + this.x2.shape + ".")); - } - else { - throw new Error('Error adding matmul op: inputs must be vectors or matrices.'); - } - }; - MatMulNode.X1 = 'x1'; - MatMulNode.X2 = 'x2'; - return MatMulNode; -}(Node)); -exports.MatMulNode = MatMulNode; -var Convolution2DNode = (function (_super) { - __extends(Convolution2DNode, _super); - function Convolution2DNode(graph, x, w, b, fieldSize, outputDepth, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this, graph, 'Convolution 2D', { x: x, w: w, b: b }, new SymbolicTensor(conv_util.computeOutputShape3D(x.shape, fieldSize, outputDepth, stride, zeroPad))) || this; - _this.x = x; - _this.w = w; - _this.b = b; - _this.fieldSize = fieldSize; - _this.outputDepth = outputDepth; - _this.stride = stride; - _this.zeroPad = zeroPad; - return _this; - } - Convolution2DNode.prototype.validate = function () { - util.assert(this.x.shape.length === 3, 'Error adding conv2d op: input must be of rank 3, but got shape: ' + - (this.x.shape + ".")); - util.assert(this.w.shape.length === 4, 'Error adding conv2d op: weights must be of rank 4, but got shape: ' + - (this.w.shape + ".")); - util.assert(this.b.shape.length === 1, 'Error adding conv2d op: biases must be of rank 1, but got shape: ' + - (this.b.shape + ".")); - util.assert(this.x.shape[2] === this.w.shape[2], "Error adding conv2d op: depth of input (" + this.x.shape[2] + ") " + - ("must match input depth for weights (" + this.w.shape[2] + ").")); - }; - Convolution2DNode.X = 'x'; - Convolution2DNode.W = 'w'; - Convolution2DNode.B = 'b'; - return Convolution2DNode; -}(Node)); -exports.Convolution2DNode = Convolution2DNode; -var MaxPoolNode = (function (_super) { - __extends(MaxPoolNode, _super); - function MaxPoolNode(graph, x, fieldSize, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this, graph, 'Max pool', { x: x }, new SymbolicTensor(conv_util.computeOutputShape3D(x.shape, fieldSize, x.shape[2], stride, zeroPad))) || this; - _this.x = x; - _this.fieldSize = fieldSize; - _this.stride = stride; - _this.zeroPad = zeroPad; - return _this; - } - MaxPoolNode.prototype.validate = function () { - util.assert(this.x.shape.length === 3, 'Error adding maxPool op: input must be of rank 3, but got shape: ' + - (this.x.shape + ".")); - }; - MaxPoolNode.X = 'x'; - return MaxPoolNode; -}(Node)); -exports.MaxPoolNode = MaxPoolNode; -var ReLUNode = (function (_super) { - __extends(ReLUNode, _super); - function ReLUNode(graph, x) { - return _super.call(this, graph, 'ReLU', { x: x }, new SymbolicTensor(x.shape)) || this; - } - ReLUNode.prototype.validate = function () { }; - ReLUNode.X = 'x'; - return ReLUNode; -}(Node)); -exports.ReLUNode = ReLUNode; -var LeakyReLUNode = (function (_super) { - __extends(LeakyReLUNode, _super); - function LeakyReLUNode(graph, x, alpha) { - var _this = _super.call(this, graph, 'LeakyReLU', { x: x }, new SymbolicTensor(x.shape)) || this; - _this.alpha = alpha; - return _this; - } - LeakyReLUNode.prototype.validate = function () { }; - LeakyReLUNode.X = 'x'; - return LeakyReLUNode; -}(Node)); -exports.LeakyReLUNode = LeakyReLUNode; -var PReLUNode = (function (_super) { - __extends(PReLUNode, _super); - function PReLUNode(graph, x, alpha) { - var _this = _super.call(this, graph, 'PReLU', { x: x, alpha: alpha }, new SymbolicTensor(x.shape)) || this; - _this.x = x; - _this.alpha = alpha; - return _this; - } - PReLUNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.x.shape, this.alpha.shape), 'Error adding pRelu op: the ' + - ("shapes x: " + this.x.shape + " and alpha: " + this.alpha.shape + " must match.")); - }; - PReLUNode.X = 'x'; - PReLUNode.ALPHA = 'alpha'; - return PReLUNode; -}(Node)); -exports.PReLUNode = PReLUNode; -var EluNode = (function (_super) { - __extends(EluNode, _super); - function EluNode(graph, x) { - return _super.call(this, graph, 'Elu', { x: x }, new SymbolicTensor(x.shape)) || this; - } - EluNode.prototype.validate = function () { }; - EluNode.X = 'x'; - return EluNode; -}(Node)); -exports.EluNode = EluNode; -var ExpNode = (function (_super) { - __extends(ExpNode, _super); - function ExpNode(graph, x) { - return _super.call(this, graph, 'Exp', { x: x }, new SymbolicTensor(x.shape)) || this; - } - ExpNode.prototype.validate = function () { }; - ExpNode.X = 'x'; - return ExpNode; -}(Node)); -exports.ExpNode = ExpNode; -var LogNode = (function (_super) { - __extends(LogNode, _super); - function LogNode(graph, x) { - return _super.call(this, graph, 'Log', { x: x }, new SymbolicTensor(x.shape)) || this; - } - LogNode.prototype.validate = function () { }; - LogNode.X = 'x'; - return LogNode; -}(Node)); -exports.LogNode = LogNode; -var TanHNode = (function (_super) { - __extends(TanHNode, _super); - function TanHNode(graph, x) { - return _super.call(this, graph, 'TanH', { x: x }, new SymbolicTensor(x.shape)) || this; - } - TanHNode.prototype.validate = function () { }; - TanHNode.X = 'x'; - return TanHNode; -}(Node)); -exports.TanHNode = TanHNode; -var SigmoidNode = (function (_super) { - __extends(SigmoidNode, _super); - function SigmoidNode(graph, x) { - return _super.call(this, graph, 'Sigmoid', { x: x }, new SymbolicTensor(x.shape)) || this; - } - SigmoidNode.prototype.validate = function () { }; - SigmoidNode.X = 'x'; - return SigmoidNode; -}(Node)); -exports.SigmoidNode = SigmoidNode; -var SquareNode = (function (_super) { - __extends(SquareNode, _super); - function SquareNode(graph, x) { - return _super.call(this, graph, 'Square', { x: x }, new SymbolicTensor(x.shape)) || this; - } - SquareNode.prototype.validate = function () { }; - SquareNode.X = 'x'; - return SquareNode; -}(Node)); -exports.SquareNode = SquareNode; -var SoftmaxCrossEntropyCostNode = (function (_super) { - __extends(SoftmaxCrossEntropyCostNode, _super); - function SoftmaxCrossEntropyCostNode(graph, x, target) { - var _this = _super.call(this, graph, 'SoftmaxCrossEntropyCost', { x: x, target: target }, new SymbolicTensor([])) || this; - _this.x = x; - _this.target = target; - return _this; - } - SoftmaxCrossEntropyCostNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.x.shape, this.target.shape), "Error adding softmaxCrossEntropyCost op: x shape (" + this.x.shape + ") " + - ("must match target shape (" + this.target.shape + ").")); - }; - SoftmaxCrossEntropyCostNode.X = 'x'; - SoftmaxCrossEntropyCostNode.TARGET = 'target'; - return SoftmaxCrossEntropyCostNode; -}(Node)); -exports.SoftmaxCrossEntropyCostNode = SoftmaxCrossEntropyCostNode; -var SoftmaxNode = (function (_super) { - __extends(SoftmaxNode, _super); - function SoftmaxNode(graph, x) { - var _this = _super.call(this, graph, 'Softmax', { x: x }, new SymbolicTensor(x.shape)) || this; - _this.x = x; - return _this; - } - SoftmaxNode.prototype.validate = function () { - util.assert(this.x.shape.length === 1, 'The input to a softmax must be a 1-D tensor'); - util.assert(this.x.shape[0] >= 2, 'The input to a softmax must have at least 2 values'); - }; - SoftmaxNode.X = 'x'; - return SoftmaxNode; -}(Node)); -exports.SoftmaxNode = SoftmaxNode; -var MeanSquaredCostNode = (function (_super) { - __extends(MeanSquaredCostNode, _super); - function MeanSquaredCostNode(graph, label, prediction) { - var _this = _super.call(this, graph, 'Mean Squared Cost', { label: label, prediction: prediction }, new SymbolicTensor([])) || this; - _this.label = label; - _this.prediction = prediction; - return _this; - } - MeanSquaredCostNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.label.shape, this.prediction.shape), "Error adding meanSquaredCost op: label shape (" + this.label.shape + ") " + - ("must match prediction shape (" + this.prediction.shape + ").")); - }; - MeanSquaredCostNode.LABEL = 'label'; - MeanSquaredCostNode.PREDICTION = 'prediction'; - return MeanSquaredCostNode; -}(Node)); -exports.MeanSquaredCostNode = MeanSquaredCostNode; -var ArgMaxNode = (function (_super) { - __extends(ArgMaxNode, _super); - function ArgMaxNode(graph, x) { - var _this = _super.call(this, graph, 'ArgMax', { x: x }, new SymbolicTensor([1])) || this; - _this.x = x; - return _this; - } - ArgMaxNode.prototype.validate = function () { - util.assert(util.sizeFromShape(this.x.shape) > 0, 'Error adding argmax op: input tensor must have at least one entry.'); - }; - ArgMaxNode.X = 'x'; - return ArgMaxNode; -}(Node)); -exports.ArgMaxNode = ArgMaxNode; -var ArgMaxEqualsNode = (function (_super) { - __extends(ArgMaxEqualsNode, _super); - function ArgMaxEqualsNode(graph, x1, x2) { - var _this = _super.call(this, graph, 'ArgMaxEquals', { x1: x1, x2: x2 }, new SymbolicTensor([1])) || this; - _this.x1 = x1; - _this.x2 = x2; - return _this; - } - ArgMaxEqualsNode.prototype.validate = function () { - util.assert(util.arraysEqual(this.x1.shape, this.x2.shape), "Error adding ArgMaxEquals op: x1 shape (" + this.x1.shape + ") " + - ("must match x2 shape (" + this.x2.shape + ").")); - }; - ArgMaxEqualsNode.X1 = 'x1'; - ArgMaxEqualsNode.X2 = 'x2'; - return ArgMaxEqualsNode; -}(Node)); -exports.ArgMaxEqualsNode = ArgMaxEqualsNode; - -},{"../ops/concat_util":113,"../ops/conv_util":115,"../tensor":146,"../util":151,"./initializers":42}],40:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var session_1 = require("./session"); -var DEFAULT_EVAL_INTERVAL_MS = 1500; -var DEFAULT_COST_INTERVAL_MS = 500; -var DEFAULT_INFERENCE_EXAMPLE_INTERVAL_MS = 3000; -var MetricReduction; -(function (MetricReduction) { - MetricReduction[MetricReduction["SUM"] = 0] = "SUM"; - MetricReduction[MetricReduction["MEAN"] = 1] = "MEAN"; -})(MetricReduction = exports.MetricReduction || (exports.MetricReduction = {})); -var GraphRunner = (function () { - function GraphRunner(math, session, eventObserver) { - this.math = math; - this.session = session; - this.eventObserver = eventObserver; - this.lastCostTimestamp = 0; - this.lastEvalTimestamp = 0; - this.resetStatistics(); - this.zeroScalar = tensor_1.Scalar.new(0); - } - GraphRunner.prototype.resetStatistics = function () { - this.totalBatchesTrained = 0; - }; - GraphRunner.prototype.train = function (costTensor, trainFeedEntries, batchSize, optimizer, numBatches, metricTensor, metricFeedEntries, metricBatchSize, metricReduction, evalIntervalMs, costIntervalMs) { - if (metricReduction === void 0) { metricReduction = MetricReduction.MEAN; } - if (evalIntervalMs === void 0) { evalIntervalMs = DEFAULT_EVAL_INTERVAL_MS; } - if (costIntervalMs === void 0) { costIntervalMs = DEFAULT_COST_INTERVAL_MS; } - this.costTensor = costTensor; - this.trainFeedEntries = trainFeedEntries; - this.metricTensor = metricTensor; - this.metricFeedEntries = metricFeedEntries; - if (metricBatchSize != null && this.metricBatchSize !== metricBatchSize) { - if (this.metricBatchSizeScalar != null) { - this.metricBatchSizeScalar.dispose(); - } - this.metricBatchSizeScalar = tensor_1.Scalar.new(metricBatchSize); - } - this.metricBatchSize = metricBatchSize; - this.metricReduction = metricReduction; - this.batchSize = batchSize; - this.optimizer = optimizer; - this.metricIntervalMs = evalIntervalMs; - this.costIntervalMs = costIntervalMs; - this.currentTrainLoopNumBatches = numBatches; - this.batchesTrainedThisRun = 0; - this.isTraining = true; - this.trainStartTimestamp = performance.now(); - this.trainNetwork(); - }; - GraphRunner.prototype.stopTraining = function () { - this.isTraining = false; - }; - GraphRunner.prototype.resumeTraining = function () { - this.isTraining = true; - this.trainNetwork(); - }; - GraphRunner.prototype.trainNetwork = function () { - var _this = this; - if (this.batchesTrainedThisRun === this.currentTrainLoopNumBatches) { - this.stopTraining(); - } - if (!this.isTraining) { - if (this.eventObserver.doneTrainingCallback != null) { - this.eventObserver.doneTrainingCallback(); - } - return; - } - var start = performance.now(); - var shouldComputeCost = this.eventObserver.avgCostCallback != null && - (start - this.lastCostTimestamp > this.costIntervalMs); - if (shouldComputeCost) { - this.lastCostTimestamp = start; - } - var costReduction = shouldComputeCost ? session_1.CostReduction.MEAN : session_1.CostReduction.NONE; - globals_1.tidy(function () { - var avgCost = _this.session.train(_this.costTensor, _this.trainFeedEntries, _this.batchSize, _this.optimizer, costReduction); - if (shouldComputeCost) { - var trainTime = performance.now() - start; - _this.eventObserver.avgCostCallback(avgCost); - if (_this.eventObserver.trainExamplesPerSecCallback != null) { - var examplesPerSec = (_this.batchSize * 1000 / trainTime); - _this.eventObserver.trainExamplesPerSecCallback(examplesPerSec); - } - } - if (_this.eventObserver.metricCallback != null && - _this.metricFeedEntries != null && - start - _this.lastEvalTimestamp > _this.metricIntervalMs) { - _this.lastEvalTimestamp = start; - if (_this.lastComputedMetric != null) { - _this.lastComputedMetric.dispose(); - } - _this.lastComputedMetric = _this.computeMetric(); - _this.eventObserver.metricCallback(_this.lastComputedMetric); - } - if (_this.eventObserver.totalTimeCallback != null) { - _this.eventObserver.totalTimeCallback((start - _this.trainStartTimestamp) / 1000); - } - _this.batchesTrainedThisRun++; - _this.totalBatchesTrained++; - if (_this.eventObserver.batchesTrainedCallback != null) { - _this.eventObserver.batchesTrainedCallback(_this.totalBatchesTrained); - } - }); - requestAnimationFrame(function () { return _this.trainNetwork(); }); - }; - GraphRunner.prototype.infer = function (inferenceTensor, inferenceFeedEntries, inferenceExampleIntervalMs, inferenceExampleCount, numPasses) { - var _this = this; - if (inferenceExampleIntervalMs === void 0) { inferenceExampleIntervalMs = DEFAULT_INFERENCE_EXAMPLE_INTERVAL_MS; } - if (inferenceExampleCount === void 0) { inferenceExampleCount = 5; } - if (this.eventObserver.inferenceExamplesCallback == null && - this.eventObserver.inferenceExamplesPerSecCallback == null) { - throw new Error('Cannot start inference loop, no inference example or ' + - 'examples/sec observer provided.'); - } - for (var i = 0; i < inferenceFeedEntries.length; i++) { - var feedEntry = inferenceFeedEntries[i]; - if (feedEntry.data instanceof tensor_1.Tensor) { - throw new Error('Cannot start inference on the model runner with feed entries of ' + - 'type NDArray. Please use InputProviders.'); - } - } - this.inferenceExampleIntervalMs = inferenceExampleIntervalMs; - this.inferenceTensor = inferenceTensor; - this.inferenceFeedEntries = inferenceFeedEntries; - this.inferenceExampleCount = inferenceExampleCount; - this.currentInferenceLoopNumPasses = numPasses; - if (!this.isInferring) { - this.inferencePassesThisRun = 0; - requestAnimationFrame(function () { return _this.inferNetwork(); }); - } - this.isInferring = true; - }; - GraphRunner.prototype.inferNetwork = function () { - var _this = this; - if (!this.isInferring || - this.inferencePassesThisRun === this.currentInferenceLoopNumPasses) { - return; - } - globals_1.tidy(function () { - var feeds = []; - var inferenceValues = []; - var start = performance.now(); - for (var i = 0; i < _this.inferenceExampleCount; i++) { - var ndarrayFeedEntries = []; - for (var j = 0; j < _this.inferenceFeedEntries.length; j++) { - var feedEntry = _this.inferenceFeedEntries[j]; - var nextCopy = feedEntry.data.getNextCopy(); - ndarrayFeedEntries.push({ tensor: feedEntry.tensor, data: nextCopy }); - } - feeds.push(ndarrayFeedEntries); - inferenceValues.push(_this.session.eval(_this.inferenceTensor, ndarrayFeedEntries)); - } - if (_this.eventObserver.inferenceExamplesPerSecCallback != null) { - inferenceValues[inferenceValues.length - 1].dataSync(); - var inferenceExamplesPerSecTime = performance.now() - start; - var examplesPerSec = (_this.inferenceExampleCount * 1000 / inferenceExamplesPerSecTime); - _this.eventObserver.inferenceExamplesPerSecCallback(examplesPerSec); - } - if (_this.eventObserver.inferenceExamplesCallback != null) { - _this.eventObserver.inferenceExamplesCallback(feeds, inferenceValues); - } - _this.inferencePassesThisRun++; - }); - this.lastInferTimeoutID = window.setTimeout(function () { return _this.inferNetwork(); }, this.inferenceExampleIntervalMs); - }; - GraphRunner.prototype.stopInferring = function () { - this.isInferring = false; - window.clearTimeout(this.lastInferTimeoutID); - }; - GraphRunner.prototype.isInferenceRunning = function () { - return this.isInferring; - }; - GraphRunner.prototype.computeMetric = function () { - var _this = this; - if (this.metricFeedEntries == null) { - throw new Error('Cannot compute metric, no metric FeedEntries provided.'); - } - var metric = this.zeroScalar; - return globals_1.tidy(function () { - for (var i = 0; i < _this.metricBatchSize; i++) { - var metricValue = _this.session.eval(_this.metricTensor, _this.metricFeedEntries); - metric = _this.math.add(metric, metricValue.toFloat()); - } - if (_this.metricReduction === MetricReduction.MEAN) { - metric = _this.math.divide(metric, _this.metricBatchSizeScalar); - } - return metric; - }); - }; - GraphRunner.prototype.getTotalBatchesTrained = function () { - return this.totalBatchesTrained; - }; - GraphRunner.prototype.getLastComputedMetric = function () { - return this.lastComputedMetric; - }; - GraphRunner.prototype.setMath = function (math) { - this.math = math; - }; - GraphRunner.prototype.setSession = function (session) { - this.session = session; - }; - GraphRunner.prototype.setInferenceTensor = function (inferenceTensor) { - this.inferenceTensor = inferenceTensor; - }; - GraphRunner.prototype.setInferenceExampleCount = function (inferenceExampleCount) { - this.inferenceExampleCount = inferenceExampleCount; - }; - return GraphRunner; -}()); -exports.GraphRunner = GraphRunner; - -},{"../globals":35,"../tensor":146,"./session":64}],41:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var graph_1 = require("./graph"); -var priority_queue = require("./priority_queue"); -var priority_queue_1 = require("./priority_queue"); -function getUnorderedEvaluationSet(nodes, terminatingNodes) { - var terminatingNodeMap = {}; - var seen = {}; - var set = []; - var visit = nodes.slice(); - terminatingNodes.forEach(function (node) { return terminatingNodeMap[node.id] = node; }); - var _loop_1 = function () { - var cur = visit.pop(); - if (seen[cur.id] == null) { - if (terminatingNodeMap[cur.id] == null) { - Object.keys(cur.inputs) - .map(function (inputName) { return cur.inputs[inputName]; }) - .forEach(function (input) { return visit.push(input.node); }); - } - set.push(cur); - seen[cur.id] = cur; - } - }; - while (visit.length !== 0) { - _loop_1(); - } - return set; -} -exports.getUnorderedEvaluationSet = getUnorderedEvaluationSet; -function getOrderedEvaluationSet(unorderedEvaluationSet) { - var set = []; - var nodeIndices = {}; - var pendingDependencies = {}; - var nodeQueue = new priority_queue_1.PriorityQueue(function (a, b) { return priority_queue.defaultCompare(pendingDependencies[a.id], pendingDependencies[b.id]); }, function (node, newIndex) { return nodeIndices[node.id] = newIndex; }); - unorderedEvaluationSet.forEach(function (node) { return pendingDependencies[node.id] = 0; }); - unorderedEvaluationSet.forEach(function (node) { return Object.keys(node.inputs) - .map(function (key) { return node.inputs[key]; }) - .forEach(function (input) { - if (unorderedEvaluationSet.indexOf(input.node) !== -1) { - pendingDependencies[input.node.id]++; - } - }); }); - unorderedEvaluationSet.forEach(function (node) { return nodeQueue.enqueue(node); }); - while (!nodeQueue.empty()) { - set.unshift(nodeQueue.dequeue()); - Object.keys(set[0].inputs).map(function (key) { return set[0].inputs[key]; }).forEach(function (input) { - if (unorderedEvaluationSet.indexOf(input.node) === -1) { - return; - } - pendingDependencies[input.node.id]--; - nodeQueue.update(input.node, nodeIndices[input.node.id]); - }); - } - return set; -} -exports.getOrderedEvaluationSet = getOrderedEvaluationSet; -function isInputNode(node) { - return Object.keys(node.inputs).length === 0; -} -exports.isInputNode = isInputNode; -function shouldBackProp(t) { - return !(t.node instanceof graph_1.ConstantNode); -} -exports.shouldBackProp = shouldBackProp; -function isPassthroughNode(node, map) { - var keys = Object.keys(node.inputs); - for (var i = 0; i < keys.length; i++) { - var input = node.inputs[keys[i]]; - if (map.get(input, true) === map.get(node.output, true)) { - return true; - } - } - return false; -} -exports.isPassthroughNode = isPassthroughNode; - -},{"./graph":39,"./priority_queue":63}],42:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ops = require("../ops/ops"); -var VarianceScalingInitializer = (function () { - function VarianceScalingInitializer(scale, mode, distribution) { - if (scale === void 0) { scale = 1.0; } - if (mode === void 0) { mode = 'fan_in'; } - if (distribution === void 0) { distribution = 'normal'; } - this.scale = scale; - this.mode = mode; - this.distribution = distribution; - } - VarianceScalingInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - var n = 0; - if (this.mode === 'fan_in') { - n = inputUnits; - } - else if (this.mode === 'fan_out') { - n = outputUnits; - } - else if (this.mode === 'fan_avg') { - n = (inputUnits + outputUnits) / 2; - } - else { - throw new Error("Unexpected mode for variance scaling initializer: " + this.mode); - } - if (this.distribution === 'normal') { - return ops.truncatedNormal(weightsShape, 0.0, Math.sqrt(this.scale / n)); - } - else if (this.distribution === 'uniform') { - return ops.randomUniform(weightsShape, 0.0, Math.sqrt(3 * this.scale / n)); - } - else { - throw new Error("Unexpected distribution for variance scaling initializer: " + - ("" + this.distribution)); - } - }; - return VarianceScalingInitializer; -}()); -exports.VarianceScalingInitializer = VarianceScalingInitializer; -var ZerosInitializer = (function () { - function ZerosInitializer() { - } - ZerosInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.zeros(weightsShape); - }; - return ZerosInitializer; -}()); -exports.ZerosInitializer = ZerosInitializer; -var OnesInitializer = (function () { - function OnesInitializer() { - } - OnesInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.ones(weightsShape); - }; - return OnesInitializer; -}()); -exports.OnesInitializer = OnesInitializer; -var ConstantInitializer = (function () { - function ConstantInitializer(value) { - if (value === void 0) { value = 0; } - this.value = value; - } - ConstantInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.fill(weightsShape, this.value); - }; - return ConstantInitializer; -}()); -exports.ConstantInitializer = ConstantInitializer; -var TensorInitializer = (function () { - function TensorInitializer(tensor) { - this.tensor = tensor; - } - TensorInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return this.tensor; - }; - return TensorInitializer; -}()); -exports.TensorInitializer = TensorInitializer; -var RandomNormalInitializer = (function () { - function RandomNormalInitializer(mean, stdev) { - if (mean === void 0) { mean = 0; } - if (stdev === void 0) { stdev = .05; } - this.mean = mean; - this.stdev = stdev; - } - RandomNormalInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.randomNormal(weightsShape, this.mean, this.stdev); - }; - return RandomNormalInitializer; -}()); -exports.RandomNormalInitializer = RandomNormalInitializer; -var RandomTruncatedNormalInitializer = (function () { - function RandomTruncatedNormalInitializer(mean, stdev) { - if (mean === void 0) { mean = 0; } - if (stdev === void 0) { stdev = .05; } - this.mean = mean; - this.stdev = stdev; - } - RandomTruncatedNormalInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.truncatedNormal(weightsShape, this.mean, this.stdev); - }; - return RandomTruncatedNormalInitializer; -}()); -exports.RandomTruncatedNormalInitializer = RandomTruncatedNormalInitializer; -var RandomUniformInitializer = (function () { - function RandomUniformInitializer(minval, maxval) { - if (minval === void 0) { minval = -.05; } - if (maxval === void 0) { maxval = .05; } - this.minval = minval; - this.maxval = maxval; - } - RandomUniformInitializer.prototype.initialize = function (weightsShape, inputUnits, outputUnits) { - return ops.randomUniform(weightsShape, this.minval, this.maxval); - }; - return RandomUniformInitializer; -}()); -exports.RandomUniformInitializer = RandomUniformInitializer; - -},{"../ops/ops":123}],43:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var graph_1 = require("./graph"); -var graph_util = require("./graph_util"); -var add_1 = require("./ops/add"); -var argmax_1 = require("./ops/argmax"); -var argmaxequals_1 = require("./ops/argmaxequals"); -var concat_1 = require("./ops/concat"); -var convolution_1 = require("./ops/convolution"); -var divide_1 = require("./ops/divide"); -var element_wise_activation_1 = require("./ops/element_wise_activation"); -var element_wise_cost_1 = require("./ops/element_wise_cost"); -var exp_1 = require("./ops/exp"); -var linear_combination_1 = require("./ops/linear_combination"); -var log_1 = require("./ops/log"); -var matmul_1 = require("./ops/matmul"); -var max_pool_1 = require("./ops/max_pool"); -var multiply_1 = require("./ops/multiply"); -var reduce_sum_1 = require("./ops/reduce_sum"); -var reshape_1 = require("./ops/reshape"); -var softmax_1 = require("./ops/softmax"); -var subtract_1 = require("./ops/subtract"); -function emitFromGraphNodes(nodes) { - var ops = []; - nodes.forEach(function (node) { return Array.prototype.push.apply(ops, emitOpFromNode(node)); }); - return ops; -} -exports.emitFromGraphNodes = emitFromGraphNodes; -function emitOpFromNode(node) { - if (node instanceof graph_1.ReshapeNode) { - return [new reshape_1.Reshape(node.inputs[graph_1.ReshapeNode.X], node.output)]; - } - else if (node instanceof graph_1.MatMulNode) { - var x1 = node.inputs[graph_1.MatMulNode.X1]; - var x2 = node.inputs[graph_1.MatMulNode.X2]; - return [new matmul_1.MatMul(x1, x2, node.output)]; - } - else if (node instanceof graph_1.Convolution2DNode) { - var w = node.inputs[graph_1.Convolution2DNode.W]; - var x = node.inputs[graph_1.Convolution2DNode.X]; - var b = node.inputs[graph_1.Convolution2DNode.B]; - return [new convolution_1.Convolution2D(w, x, b, node.output, node.fieldSize, node.outputDepth, node.stride, node.zeroPad)]; - } - else if (node instanceof graph_1.MaxPoolNode) { - var x = node.inputs[graph_1.MaxPoolNode.X]; - return [new max_pool_1.MaxPool(x, node.output, node.fieldSize, node.stride, node.zeroPad)]; - } - else if (node instanceof graph_1.ExpNode) { - return [new exp_1.Exp(node.inputs[graph_1.ExpNode.X], node.output)]; - } - else if (node instanceof graph_1.LogNode) { - return [new log_1.Log(node.inputs[graph_1.LogNode.X], node.output)]; - } - else if (node instanceof graph_1.ReLUNode) { - return [new element_wise_activation_1.ReLU(node.inputs[graph_1.ReLUNode.X], node.output)]; - } - else if (node instanceof graph_1.LeakyReLUNode) { - return [new element_wise_activation_1.LeakyReLU(node.inputs[graph_1.LeakyReLUNode.X], node.output, node.alpha)]; - } - else if (node instanceof graph_1.PReLUNode) { - return [new element_wise_activation_1.PReLU(node.inputs[graph_1.PReLUNode.X], node.inputs[graph_1.PReLUNode.ALPHA], node.output)]; - } - else if (node instanceof graph_1.EluNode) { - return [new element_wise_activation_1.Elu(node.inputs[graph_1.EluNode.X], node.output)]; - } - else if (node instanceof graph_1.TanHNode) { - return [new element_wise_activation_1.TanH(node.inputs[graph_1.TanHNode.X], node.output)]; - } - else if (node instanceof graph_1.SigmoidNode) { - return [new element_wise_activation_1.Sigmoid(node.inputs[graph_1.SigmoidNode.X], node.output)]; - } - else if (node instanceof graph_1.SoftmaxCrossEntropyCostNode) { - var x = node.inputs[graph_1.SoftmaxCrossEntropyCostNode.X]; - var target = node.inputs[graph_1.SoftmaxCrossEntropyCostNode.TARGET]; - return [new softmax_1.SoftmaxCrossEntropyCost(x, target, node.output)]; - } - else if (node instanceof graph_1.SoftmaxNode) { - return [new softmax_1.Softmax(node.inputs[graph_1.SoftmaxNode.X], node.output)]; - } - else if (node instanceof graph_1.MeanSquaredCostNode) { - var label = node.inputs[graph_1.MeanSquaredCostNode.LABEL]; - var prediction = node.inputs[graph_1.MeanSquaredCostNode.PREDICTION]; - return [new element_wise_cost_1.MeanSquaredCost(label, prediction, node.output)]; - } - else if (node instanceof graph_1.ArgMaxEqualsNode) { - return [new argmaxequals_1.ArgMaxEquals(node.inputs[graph_1.ArgMaxEqualsNode.X1], node.inputs[graph_1.ArgMaxEqualsNode.X2], node.output)]; - } - else if (node instanceof graph_1.ArgMaxNode) { - return [new argmax_1.ArgMax(node.x, node.output)]; - } - else if (node instanceof graph_1.FusedLinearCombinationNode) { - return [new linear_combination_1.LinearCombination(node.inputs[graph_1.FusedLinearCombinationNode.T1], node.inputs[graph_1.FusedLinearCombinationNode.T2], node.inputs[graph_1.FusedLinearCombinationNode.C1], node.inputs[graph_1.FusedLinearCombinationNode.C2], node.output)]; - } - else if (node instanceof graph_1.Concat1DNode) { - return [new concat_1.Concat1D(node.inputs[graph_1.Concat1DNode.X1], node.inputs[graph_1.Concat1DNode.X2], node.output)]; - } - else if (node instanceof graph_1.Concat2DNode) { - return [new concat_1.Concat2D(node.inputs[graph_1.Concat2DNode.X1], node.inputs[graph_1.Concat2DNode.X2], node.axis, node.output)]; - } - else if (node instanceof graph_1.Concat3DNode) { - return [new concat_1.Concat3D(node.inputs[graph_1.Concat3DNode.X1], node.inputs[graph_1.Concat3DNode.X2], node.axis, node.output)]; - } - else if (node instanceof graph_1.Concat4DNode) { - return [new concat_1.Concat4D(node.inputs[graph_1.Concat4DNode.X1], node.inputs[graph_1.Concat4DNode.X2], node.axis, node.output)]; - } - else if (node instanceof graph_1.SquareNode) { - return [new element_wise_activation_1.Square(node.inputs[graph_1.SquareNode.X], node.output)]; - } - else if (node instanceof graph_1.AddNode) { - return [new add_1.Add(node.inputs[graph_1.AddNode.T1], node.inputs[graph_1.AddNode.T2], node.output)]; - } - else if (node instanceof graph_1.SubtractNode) { - return [new subtract_1.Subtract(node.inputs[graph_1.SubtractNode.T1], node.inputs[graph_1.SubtractNode.T2], node.output)]; - } - else if (node instanceof graph_1.MultiplyNode) { - return [new multiply_1.Multiply(node.inputs[graph_1.MultiplyNode.T1], node.inputs[graph_1.MultiplyNode.T2], node.output)]; - } - else if (node instanceof graph_1.DivideNode) { - return [new divide_1.Divide(node.inputs[graph_1.DivideNode.T1], node.inputs[graph_1.DivideNode.T2], node.output)]; - } - else if (node instanceof graph_1.ReduceSumNode) { - return [new reduce_sum_1.ReduceSum(node.inputs[graph_1.ReduceSumNode.X], node.output)]; - } - else if (graph_util.isInputNode(node)) { - return []; - } - else { - throw Error("Unsupported node type: " + node.constructor.name); - } -} - -},{"./graph":39,"./graph_util":41,"./ops/add":44,"./ops/argmax":45,"./ops/argmaxequals":46,"./ops/concat":47,"./ops/convolution":48,"./ops/divide":49,"./ops/element_wise_activation":50,"./ops/element_wise_cost":51,"./ops/exp":52,"./ops/linear_combination":53,"./ops/log":54,"./ops/matmul":55,"./ops/max_pool":56,"./ops/multiply":57,"./ops/reduce_sum":59,"./ops/reshape":60,"./ops/softmax":61,"./ops/subtract":62}],44:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Add = (function (_super) { - __extends(Add, _super); - function Add(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - util.assert(util.sizeFromShape(x1Tensor.shape) === 1 || - util.sizeFromShape(x2Tensor.shape) === 1 || - util.arraysEqual(x1Tensor.shape, x2Tensor.shape) || - (x1Tensor.shape.length === 2 && x2Tensor.shape.length === 1 && - x1Tensor.shape[1] === x2Tensor.shape[0]) || - (x1Tensor.shape.length === 1 && x2Tensor.shape.length === 2 && - x1Tensor.shape[0] === x2Tensor.shape[1]), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape, ' + - 'or one of them can be broadcasted (2D and 1D).'); - return _this; - } - Add.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(x1.shape)) { - result = math.scalarPlusArray(x1, x2); - } - else if (util.isScalarShape(x2.shape)) { - result = math.scalarPlusArray(x2, x1); - } - else { - result = math.add(x1, x2); - } - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - Add.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - if (_this.x1Tensor.shape.length === 1 && - _this.x2Tensor.shape.length === 2 && - _this.x1Tensor.shape[0] === _this.x2Tensor.shape[1]) { - var sum = math.sum(dy, 0); - gradientArrays.add(_this.x1Tensor, sum); - } - else if (util.isScalarShape(_this.x1Tensor.shape)) { - var sum = math.sum(dy); - gradientArrays.add(_this.x1Tensor, sum); - } - else { - gradientArrays.add(_this.x1Tensor, math.clone(dy)); - } - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - if (_this.x1Tensor.shape.length === 2 && - _this.x2Tensor.shape.length === 1 && - _this.x1Tensor.shape[1] === _this.x2Tensor.shape[0]) { - var sum = math.sum(dy, 0); - gradientArrays.add(_this.x2Tensor, sum); - } - else if (util.isScalarShape(_this.x2Tensor.shape)) { - var sum = math.sum(dy); - gradientArrays.add(_this.x2Tensor, sum); - } - else { - gradientArrays.add(_this.x2Tensor, math.clone(dy)); - } - } - }); - }; - Add.prototype.dispose = function () { - if (this.dySizeScalar != null) { - this.dySizeScalar.dispose(); - } - }; - return Add; -}(op_1.Operation)); -exports.Add = Add; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],45:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var op_1 = require("./op"); -var ArgMax = (function (_super) { - __extends(ArgMax, _super); - function ArgMax(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - return _this; - } - ArgMax.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.argMax(x))); - }); - }; - ArgMax.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - throw new Error('ArgMax backprop unimplemented'); - }; - return ArgMax; -}(op_1.Operation)); -exports.ArgMax = ArgMax; - -},{"../../globals":35,"./op":58}],46:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var op_1 = require("./op"); -var ArgMaxEquals = (function (_super) { - __extends(ArgMaxEquals, _super); - function ArgMaxEquals(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - return _this; - } - ArgMaxEquals.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.argMaxEquals(x1, x2))); - }); - }; - ArgMaxEquals.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - throw new Error('ArgMaxEquals backprop unimplemented'); - }; - return ArgMaxEquals; -}(op_1.Operation)); -exports.ArgMaxEquals = ArgMaxEquals; - -},{"../../globals":35,"./op":58}],47:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var concat_util = require("../../ops/concat_util"); -var util = require("../../util"); -var op_1 = require("./op"); -var Concat1D = (function (_super) { - __extends(Concat1D, _super); - function Concat1D(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - return _this; - } - Concat1D.prototype.feedForward = function (math, inferecenArrays) { - var _this = this; - var x1 = inferecenArrays.get(this.x1Tensor); - var x2 = inferecenArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat1D(x1, x2); - inferecenArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat1D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, 0, gradientArrays, inferenceArrays); - }); - }; - return Concat1D; -}(op_1.Operation)); -exports.Concat1D = Concat1D; -var Concat2D = (function (_super) { - __extends(Concat2D, _super); - function Concat2D(x1Tensor, x2Tensor, axis, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.axis = axis; - _this.yTensor = yTensor; - concat_util.assertParams(x1Tensor.shape, x2Tensor.shape, axis); - return _this; - } - Concat2D.prototype.feedForward = function (math, inferecenArrays) { - var _this = this; - var x1 = inferecenArrays.get(this.x1Tensor); - var x2 = inferecenArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat2D(x1, x2, _this.axis); - inferecenArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat2D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, _this.axis, gradientArrays, inferenceArrays); - }); - }; - return Concat2D; -}(op_1.Operation)); -exports.Concat2D = Concat2D; -var Concat3D = (function (_super) { - __extends(Concat3D, _super); - function Concat3D(x1Tensor, x2Tensor, axis, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.axis = axis; - _this.yTensor = yTensor; - concat_util.assertParams(x1Tensor.shape, x2Tensor.shape, axis); - return _this; - } - Concat3D.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat3D(x1, x2, _this.axis); - inferenceArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat3D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, _this.axis, gradientArrays, inferenceArrays); - }); - }; - return Concat3D; -}(op_1.Operation)); -exports.Concat3D = Concat3D; -var Concat4D = (function (_super) { - __extends(Concat4D, _super); - function Concat4D(x1Tensor, x2Tensor, axis, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.axis = axis; - _this.yTensor = yTensor; - concat_util.assertParams(x1Tensor.shape, x2Tensor.shape, axis); - return _this; - } - Concat4D.prototype.feedForward = function (math, inferecenArrays) { - var _this = this; - var x1 = inferecenArrays.get(this.x1Tensor); - var x2 = inferecenArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var concatResult = math.concat4D(x1, x2, _this.axis); - inferecenArrays.set(_this.yTensor, globals_1.keep(concatResult)); - }); - }; - Concat4D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - globals_1.tidy(function () { - concatBackProp(math, _this.x1Tensor, _this.x2Tensor, _this.yTensor, _this.axis, gradientArrays, inferenceArrays); - }); - }; - return Concat4D; -}(op_1.Operation)); -exports.Concat4D = Concat4D; -function concatBackProp(math, aTensor, bTensor, yTensor, axis, gradArrays, infArrays) { - var dy = gradArrays.get(yTensor); - var a = infArrays.get(aTensor); - var b = infArrays.get(bTensor); - var a2D = a.as2D(-1, util.sizeFromShape(a.shape.slice(axis))); - var b2D = b.as2D(-1, util.sizeFromShape(b.shape.slice(axis))); - var _a = concat_util.computeGradientSliceShapes(a2D.shape, b2D.shape), aBegin = _a.aBegin, aSize = _a.aSize, bBegin = _a.bBegin, bSize = _a.bSize; - var dy2D = dy.as2D(-1, a2D.shape[1] + b2D.shape[1]); - var slice1Result = math.slice2D(dy2D, aBegin, aSize).reshapeAs(a); - var slice2Result = math.slice2D(dy2D, bBegin, bSize).reshapeAs(b); - gradArrays.add(aTensor, slice1Result); - gradArrays.add(bTensor, slice2Result); -} - -},{"../../globals":35,"../../ops/concat_util":113,"../../util":151,"./op":58}],48:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var conv_util = require("../../ops/conv_util"); -var util = require("../../util"); -var op_1 = require("./op"); -var Convolution2D = (function (_super) { - __extends(Convolution2D, _super); - function Convolution2D(wTensor, xTensor, bTensor, yTensor, fieldSize, outputDepth, stride, zeroPad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this) || this; - _this.wTensor = wTensor; - _this.xTensor = xTensor; - _this.bTensor = bTensor; - _this.yTensor = yTensor; - _this.fieldSize = fieldSize; - _this.outputDepth = outputDepth; - _this.stride = stride; - _this.assertWeightsShape(wTensor.shape); - _this.zeroPad = zeroPad != null ? - zeroPad : - conv_util.computeDefaultPad(_this.xTensor.shape, _this.fieldSize, _this.stride); - util.assert(util.isInt(_this.zeroPad), "The zero padding (" + _this.zeroPad + ") must be an integer. Change the " + - "stride and/or zero pad parameters"); - return _this; - } - Convolution2D.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var weights = inferenceArrays.get(this.wTensor); - var biases = inferenceArrays.get(this.bTensor); - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.conv2d(x, weights, biases, _this.stride, _this.zeroPad))); - }); - }; - Convolution2D.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var filter = inferenceArrays.get(this.wTensor); - var x = inferenceArrays.get(this.xTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - var dw = math.conv2dDerFilter(x, dy, filter.shape, _this.stride, _this.zeroPad); - var db = math.sum(dy, [0, 1]); - var dx = math.conv2dDerInput(x.shape, dy, filter, _this.stride, _this.zeroPad); - gradientArrays.add(_this.wTensor, dw); - gradientArrays.add(_this.bTensor, db); - gradientArrays.add(_this.xTensor, dx); - }); - }; - Convolution2D.prototype.assertWeightsShape = function (weightsShape) { - util.assert(weightsShape[0] === this.fieldSize && - weightsShape[1] === this.fieldSize && - weightsShape[2] === this.xTensor.shape[2] && - weightsShape[3] === this.outputDepth, "weights must be of shape [" + this.fieldSize + "," + this.fieldSize + "," + - (this.xTensor.shape[2] + "," + this.outputDepth + "] but they are of") + - ("shape [" + weightsShape + "]")); - }; - return Convolution2D; -}(op_1.Operation)); -exports.Convolution2D = Convolution2D; - -},{"../../globals":35,"../../ops/conv_util":115,"../../util":151,"./op":58}],49:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Divide = (function (_super) { - __extends(Divide, _super); - function Divide(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - util.assert(util.sizeFromShape(x1Tensor.shape) === 1 || - util.sizeFromShape(x2Tensor.shape) === 1 || - util.arraysEqual(x1Tensor.shape, x2Tensor.shape), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape'); - return _this; - } - Divide.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var t1 = inferenceArrays.get(this.x1Tensor); - var t2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(t1.shape)) { - result = math.scalarDividedByArray(t1, t2); - } - else if (util.isScalarShape(t2.shape)) { - result = math.arrayDividedByScalar(t1, t2); - } - else { - result = math.divide(t1, t2); - } - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - Divide.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var dy = gradientArrays.get(this.yTensor); - var x1IsScalar = util.isScalarShape(x1.shape); - var x2IsScalar = util.isScalarShape(x2.shape); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - if (x1IsScalar) { - var div = math.divide(dy, x2); - gradientArrays.add(_this.x1Tensor, math.sum(div)); - div.dispose(); - } - else if (x2IsScalar) { - gradientArrays.add(_this.x1Tensor, math.arrayDividedByScalar(dy, x2)); - } - else { - gradientArrays.add(_this.x1Tensor, math.divide(dy, x2)); - } - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - var x2Squared = math.elementWiseMul(x2, x2); - var x1OverX2Squared = void 0; - if (x2IsScalar) { - x1OverX2Squared = math.arrayDividedByScalar(x1, x2Squared); - } - else if (x1IsScalar) { - x1OverX2Squared = math.scalarDividedByArray(x1, x2Squared); - } - else { - x1OverX2Squared = math.divide(x1, x2Squared); - } - var dx2 = math.neg(x1OverX2Squared); - var dyTimesDerivative = math.elementWiseMul(dy, dx2); - if (x2IsScalar) { - gradientArrays.add(_this.x2Tensor, math.sum(dyTimesDerivative)); - } - else { - gradientArrays.add(_this.x2Tensor, dyTimesDerivative); - } - } - }); - }; - return Divide; -}(op_1.Operation)); -exports.Divide = Divide; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],50:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var activation_functions_1 = require("../activation_functions"); -var op_1 = require("./op"); -var ElementWiseActivation = (function (_super) { - __extends(ElementWiseActivation, _super); - function ElementWiseActivation(xTensor, yTensor, func) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - _this.func = func; - return _this; - } - ElementWiseActivation.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(_this.func.output(math, x))); - }); - }; - ElementWiseActivation.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var y = inferenceArrays.get(this.yTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - var dydx = _this.func.der(math, x, y); - gradientArrays.add(_this.xTensor, math.elementWiseMul(dy, dydx)); - dydx.dispose(); - }); - }; - ElementWiseActivation.prototype.dispose = function () { - this.func.dispose(); - }; - return ElementWiseActivation; -}(op_1.Operation)); -exports.ElementWiseActivation = ElementWiseActivation; -var ReLU = (function (_super) { - __extends(ReLU, _super); - function ReLU(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.ReLUFunc()) || this; - } - return ReLU; -}(ElementWiseActivation)); -exports.ReLU = ReLU; -var LeakyReLU = (function (_super) { - __extends(LeakyReLU, _super); - function LeakyReLU(xTensor, yTensor, alpha) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.LeakyReluFunc(alpha)) || this; - } - return LeakyReLU; -}(ElementWiseActivation)); -exports.LeakyReLU = LeakyReLU; -var TanH = (function (_super) { - __extends(TanH, _super); - function TanH(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.TanHFunc()) || this; - } - return TanH; -}(ElementWiseActivation)); -exports.TanH = TanH; -var Sigmoid = (function (_super) { - __extends(Sigmoid, _super); - function Sigmoid(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.SigmoidFunc()) || this; - } - return Sigmoid; -}(ElementWiseActivation)); -exports.Sigmoid = Sigmoid; -var Square = (function (_super) { - __extends(Square, _super); - function Square(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.SquareFunc()) || this; - } - return Square; -}(ElementWiseActivation)); -exports.Square = Square; -var Elu = (function (_super) { - __extends(Elu, _super); - function Elu(xTensor, yTensor) { - return _super.call(this, xTensor, yTensor, new activation_functions_1.EluFunc()) || this; - } - return Elu; -}(ElementWiseActivation)); -exports.Elu = Elu; -var PReLU = (function (_super) { - __extends(PReLU, _super); - function PReLU(xTensor, alphaTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.alphaTensor = alphaTensor; - _this.yTensor = yTensor; - return _this; - } - PReLU.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var alpha = inferenceArrays.get(this.alphaTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.prelu(x, alpha))); - }); - }; - PReLU.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - throw new Error('Not implemented'); - }; - return PReLU; -}(op_1.Operation)); -exports.PReLU = PReLU; - -},{"../../globals":35,"../activation_functions":37,"./op":58}],51:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var globals_1 = require("../../globals"); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var cost_functions_1 = require("../cost_functions"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var ElementWiseCost = (function (_super) { - __extends(ElementWiseCost, _super); - function ElementWiseCost(x1Tensor, x2Tensor, yTensor, func) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - _this.func = func; - _this.oneOverNScalar = - environment_1.ENV.math.keep(tensor_1.Scalar.new(1 / util.sizeFromShape(x1Tensor.shape))); - return _this; - } - ElementWiseCost.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var elementWiseCost = _this.func.cost(x1, x2); - var sum = math.sum(elementWiseCost); - var result = math.scalarTimesArray(_this.oneOverNScalar, sum); - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - ElementWiseCost.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - gradientArrays.add(_this.x1Tensor, _this.func.der(x1, x2)); - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - gradientArrays.add(_this.x2Tensor, _this.func.der(x2, x1)); - } - }); - }; - ElementWiseCost.prototype.dispose = function () { - this.func.dispose(); - this.oneOverNScalar.dispose(); - }; - return ElementWiseCost; -}(op_1.Operation)); -exports.ElementWiseCost = ElementWiseCost; -var MeanSquaredCost = (function (_super) { - __extends(MeanSquaredCost, _super); - function MeanSquaredCost(x1Tensor, x2Tensor, yTensor) { - return _super.call(this, x1Tensor, x2Tensor, yTensor, new cost_functions_1.SquareCostFunc()) || this; - } - return MeanSquaredCost; -}(ElementWiseCost)); -exports.MeanSquaredCost = MeanSquaredCost; - -},{"../../environment":34,"../../globals":35,"../../tensor":146,"../../util":151,"../cost_functions":38,"../graph_util":41,"./op":58}],52:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Exp = (function (_super) { - __extends(Exp, _super); - function Exp(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - return _this; - } - Exp.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.exp(x))); - }); - }; - Exp.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var y = inferenceArrays.get(this.yTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.xTensor)) { - gradientArrays.add(_this.xTensor, math.elementWiseMul(y, dy)); - } - }); - }; - return Exp; -}(op_1.Operation)); -exports.Exp = Exp; - -},{"../../globals":35,"../graph_util":41,"./op":58}],53:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var LinearCombination = (function (_super) { - __extends(LinearCombination, _super); - function LinearCombination(x1Tensor, x2Tensor, c1Tensor, c2Tensor, outTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.c1Tensor = c1Tensor; - _this.c2Tensor = c2Tensor; - _this.outTensor = outTensor; - return _this; - } - LinearCombination.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var c1 = inferenceArrays.get(this.c1Tensor).asScalar(); - var c2 = inferenceArrays.get(this.c2Tensor).asScalar(); - globals_1.tidy(function () { - inferenceArrays.set(_this.outTensor, globals_1.keep(math.scaledArrayAdd(c1, x1, c2, x2))); - }); - }; - LinearCombination.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var c1 = inferenceArrays.get(this.c1Tensor); - var c2 = inferenceArrays.get(this.c2Tensor); - var dy = gradientArrays.get(this.outTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - gradientArrays.add(_this.x1Tensor, math.scalarTimesArray(c1, dy)); - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - gradientArrays.add(_this.x2Tensor, math.scalarTimesArray(c2, dy)); - } - if (graph_util.shouldBackProp(_this.c1Tensor)) { - var dotProduct1 = math.elementWiseMul(x1, dy); - gradientArrays.add(_this.c1Tensor, math.sum(dotProduct1)); - } - if (graph_util.shouldBackProp(_this.c2Tensor)) { - var dotProduct2 = math.elementWiseMul(x2, dy); - gradientArrays.add(_this.c2Tensor, math.sum(dotProduct2)); - } - }); - }; - return LinearCombination; -}(op_1.Operation)); -exports.LinearCombination = LinearCombination; - -},{"../../globals":35,"../graph_util":41,"./op":58}],54:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Log = (function (_super) { - __extends(Log, _super); - function Log(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - return _this; - } - Log.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.log(x))); - }); - }; - Log.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.xTensor)) { - gradientArrays.add(_this.xTensor, math.divide(dy, x)); - } - }); - }; - return Log; -}(op_1.Operation)); -exports.Log = Log; - -},{"../../globals":35,"../graph_util":41,"./op":58}],55:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var MatMul = (function (_super) { - __extends(MatMul, _super); - function MatMul(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - return _this; - } - MatMul.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - if (x1.shape.length === 2 && x2.shape.length === 2) { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.matMul(x1, x2))); - } - else if (x1.shape.length === 2 && x2.shape.length === 1) { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.matrixTimesVector(x1, x2))); - } - else if (x1.shape.length === 1 && x2.shape.length === 2) { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.vectorTimesMatrix(x1, x2))); - } - }); - }; - MatMul.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var dy = gradientArrays.get(this.yTensor); - if (x1.shape.length === 1) { - x1 = x1.reshape([1, x1.size]); - dy = dy.reshape([1, dy.size]); - } - if (x2.shape.length === 1) { - x2 = x2.reshape([x2.size, 1]); - dy = dy.reshape([dy.size, 1]); - } - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - var dx1 = math.matMul(dy, x2, false, true); - gradientArrays.add(_this.x1Tensor, _this.x1Tensor.shape.length === 1 ? dx1.as1D() : dx1); - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - var dx2 = math.matMul(x1, dy, true, false); - gradientArrays.add(_this.x2Tensor, _this.x2Tensor.shape.length === 1 ? dx2.as1D() : dx2); - } - }); - }; - return MatMul; -}(op_1.Operation)); -exports.MatMul = MatMul; - -},{"../../globals":35,"../graph_util":41,"./op":58}],56:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var conv_util = require("../../ops/conv_util"); -var util = require("../../util"); -var op_1 = require("./op"); -var MaxPool = (function (_super) { - __extends(MaxPool, _super); - function MaxPool(xTensor, yTensor, fieldSize, stride, pad) { - if (stride === void 0) { stride = 1; } - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - _this.fieldSize = fieldSize; - _this.stride = stride; - if (pad != null) { - _this.pad = pad; - } - else { - _this.pad = conv_util.computeDefaultPad(xTensor.shape, _this.fieldSize, _this.stride); - } - util.assert(util.isInt(_this.pad), "The zero padding (" + _this.pad + ") must be an integer. Change the " + - "stride and/or zero pad parameters"); - return _this; - } - MaxPool.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(math.maxPool(x, _this.fieldSize, _this.stride, _this.pad))); - }); - }; - MaxPool.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - gradientArrays.add(_this.xTensor, math.maxPoolBackprop(dy, x, _this.fieldSize, _this.stride, _this.pad)); - }); - }; - return MaxPool; -}(op_1.Operation)); -exports.MaxPool = MaxPool; - -},{"../../globals":35,"../../ops/conv_util":115,"../../util":151,"./op":58}],57:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Multiply = (function (_super) { - __extends(Multiply, _super); - function Multiply(x1Tensor, x2Tensor, yTensor) { - var _this = _super.call(this) || this; - _this.x1Tensor = x1Tensor; - _this.x2Tensor = x2Tensor; - _this.yTensor = yTensor; - util.assert(util.sizeFromShape(x1Tensor.shape) === 1 || - util.sizeFromShape(x2Tensor.shape) === 1 || - util.arraysEqual(x1Tensor.shape, x2Tensor.shape), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape'); - return _this; - } - Multiply.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var t1 = inferenceArrays.get(this.x1Tensor); - var t2 = inferenceArrays.get(this.x2Tensor); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(t1.shape)) { - result = math.scalarTimesArray(t1, t2); - } - else if (util.isScalarShape(t2.shape)) { - result = math.scalarTimesArray(t2, t1); - } - else { - result = math.elementWiseMul(t1, t2); - } - inferenceArrays.set(_this.yTensor, globals_1.keep(result)); - }); - }; - Multiply.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var x1 = inferenceArrays.get(this.x1Tensor); - var x2 = inferenceArrays.get(this.x2Tensor); - var dy = gradientArrays.get(this.yTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.x1Tensor)) { - if (util.isScalarShape(_this.x1Tensor.shape)) { - var mul = math.elementWiseMul(dy, x2); - gradientArrays.add(_this.x1Tensor, math.sum(mul)); - } - else if (util.isScalarShape(x2.shape)) { - gradientArrays.add(_this.x1Tensor, math.scalarTimesArray(x2, dy)); - } - else { - gradientArrays.add(_this.x1Tensor, math.elementWiseMul(x2, dy)); - } - } - if (graph_util.shouldBackProp(_this.x2Tensor)) { - if (util.isScalarShape(_this.x2Tensor.shape)) { - var mul = math.elementWiseMul(dy, x1); - gradientArrays.add(_this.x2Tensor, math.sum(mul)); - } - else if (util.isScalarShape(x1.shape)) { - gradientArrays.add(_this.x2Tensor, math.scalarTimesArray(x1, dy)); - } - else { - gradientArrays.add(_this.x2Tensor, math.elementWiseMul(x1, dy)); - } - } - }); - }; - return Multiply; -}(op_1.Operation)); -exports.Multiply = Multiply; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],58:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Operation = (function () { - function Operation() { - } - Operation.prototype.disposeTransientArrays = function (inferenceArrays, gradientArrays) { }; - Operation.prototype.dispose = function () { }; - return Operation; -}()); -exports.Operation = Operation; - -},{}],59:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var globals_1 = require("../../globals"); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var ReduceSum = (function (_super) { - __extends(ReduceSum, _super); - function ReduceSum(x, outTensor) { - var _this = _super.call(this) || this; - _this.x = x; - _this.outTensor = outTensor; - util.assertShapesMatch(outTensor.shape, []); - _this.ones = environment_1.ENV.math.keep(tensor_1.Tensor.ones(x.shape)); - return _this; - } - ReduceSum.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.x); - globals_1.tidy(function () { - inferenceArrays.set(_this.outTensor, globals_1.keep(math.sum(x))); - }); - }; - ReduceSum.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - if (!graph_util.shouldBackProp(this.x)) { - return; - } - globals_1.tidy(function () { - var dy = gradientArrays.get(_this.outTensor); - gradientArrays.add(_this.x, math.scalarTimesArray(dy, _this.ones)); - }); - }; - ReduceSum.prototype.dispose = function () { - this.ones.dispose(); - }; - return ReduceSum; -}(op_1.Operation)); -exports.ReduceSum = ReduceSum; - -},{"../../environment":34,"../../globals":35,"../../tensor":146,"../../util":151,"../graph_util":41,"./op":58}],60:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var op_1 = require("./op"); -var Reshape = (function (_super) { - __extends(Reshape, _super); - function Reshape(xTensor, yTensor) { - var _this = _super.call(this) || this; - _this.xTensor = xTensor; - _this.yTensor = yTensor; - var xSize = util.sizeFromShape(xTensor.shape); - var ySize = util.sizeFromShape(yTensor.shape); - util.assert(xSize === ySize, "The input size (" + xSize + ") and output size (" + ySize + ") must match"); - return _this; - } - Reshape.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var x = inferenceArrays.get(this.xTensor); - var clone = math.clone(x); - globals_1.tidy(function () { - inferenceArrays.set(_this.yTensor, globals_1.keep(clone.reshape(_this.yTensor.shape))); - }); - }; - Reshape.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var dy = gradientArrays.get(this.yTensor); - var clone = math.clone(dy); - globals_1.tidy(function () { - gradientArrays.add(_this.xTensor, clone.reshape(_this.xTensor.shape)); - }); - }; - return Reshape; -}(op_1.Operation)); -exports.Reshape = Reshape; - -},{"../../globals":35,"../../util":151,"./op":58}],61:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var globals_1 = require("../../globals"); -var tensor_1 = require("../../tensor"); -var util = require("../../util"); -var graph_1 = require("../graph"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Softmax = (function (_super) { - __extends(Softmax, _super); - function Softmax(logitsTensor, output) { - var _this = _super.call(this) || this; - _this.logitsTensor = logitsTensor; - _this.output = output; - return _this; - } - Softmax.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var logits = inferenceArrays.get(this.logitsTensor); - return globals_1.tidy(function () { - inferenceArrays.set(_this.output, globals_1.keep(math.softmax(logits))); - }); - }; - Softmax.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var y = inferenceArrays.get(this.output); - var dy = gradientArrays.get(this.output); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.logitsTensor)) { - var dlogits = math.elementWiseMul(math.subtract(dy, math.sum(math.elementWiseMul(dy, y))), y); - gradientArrays.add(_this.logitsTensor, dlogits); - } - }); - }; - return Softmax; -}(op_1.Operation)); -exports.Softmax = Softmax; -var SoftmaxCrossEntropyCost = (function (_super) { - __extends(SoftmaxCrossEntropyCost, _super); - function SoftmaxCrossEntropyCost(logitsTensor, labelTensor, yTensor) { - var _this = _super.call(this) || this; - _this.logitsTensor = logitsTensor; - _this.labelTensor = labelTensor; - _this.yTensor = yTensor; - _this.softmaxTensor = new graph_1.SymbolicTensor(logitsTensor.shape); - _this.epsilon = environment_1.ENV.math.keep(tensor_1.Scalar.new(1e-5)); - return _this; - } - SoftmaxCrossEntropyCost.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var logits = inferenceArrays.get(this.logitsTensor); - var label = inferenceArrays.get(this.labelTensor); - globals_1.tidy(function () { - var softmaxResult = math.softmax(logits); - inferenceArrays.set(_this.softmaxTensor, globals_1.keep(softmaxResult)); - inferenceArrays.set(_this.yTensor, globals_1.keep(crossEntropyCost(math, softmaxResult, label, _this.epsilon))); - }); - }; - SoftmaxCrossEntropyCost.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var softmax = inferenceArrays.get(this.softmaxTensor); - var label = inferenceArrays.get(this.labelTensor); - globals_1.tidy(function () { - gradientArrays.add(_this.logitsTensor, math.subtract(softmax, label)); - }); - }; - SoftmaxCrossEntropyCost.prototype.disposeTransientArrays = function (inferenceArrays, gradientArrays) { - inferenceArrays.disposeArray(this.softmaxTensor); - }; - SoftmaxCrossEntropyCost.prototype.dispose = function () { - this.epsilon.dispose(); - }; - return SoftmaxCrossEntropyCost; -}(op_1.Operation)); -exports.SoftmaxCrossEntropyCost = SoftmaxCrossEntropyCost; -function crossEntropyCost(math, y, target, epsilon) { - util.assert(y.size === target.size, 'The output and target must be the same size'); - return globals_1.tidy(function () { - var yPlusEps = math.scalarPlusArray(epsilon, y); - var logOutput = math.log(yPlusEps); - var tarLogOutput = math.elementWiseMul(target, logOutput); - var costVector = math.neg(tarLogOutput); - return math.sum(costVector); - }); -} -exports.crossEntropyCost = crossEntropyCost; - -},{"../../environment":34,"../../globals":35,"../../tensor":146,"../../util":151,"../graph":39,"../graph_util":41,"./op":58}],62:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../../globals"); -var util = require("../../util"); -var graph_util = require("../graph_util"); -var op_1 = require("./op"); -var Subtract = (function (_super) { - __extends(Subtract, _super); - function Subtract(t1, t2, outTensor) { - var _this = _super.call(this) || this; - _this.t1 = t1; - _this.t2 = t2; - _this.outTensor = outTensor; - util.assert(util.sizeFromShape(t1.shape) === 1 || - util.sizeFromShape(t2.shape) === 1 || - util.arraysEqual(t1.shape, t2.shape), 'One of t1 or t2 must be a scalar, or t1 and t2 must have ' + - 'the same shape'); - return _this; - } - Subtract.prototype.feedForward = function (math, inferenceArrays) { - var _this = this; - var t1 = inferenceArrays.get(this.t1); - var t2 = inferenceArrays.get(this.t2); - globals_1.tidy(function () { - var result; - if (util.isScalarShape(t1.shape)) { - result = math.scalarMinusArray(t1, t2); - } - else if (util.isScalarShape(t2.shape)) { - result = math.arrayMinusScalar(t1, t2); - } - else { - result = math.subtract(t1, t2); - } - inferenceArrays.set(_this.outTensor, globals_1.keep(result)); - }); - }; - Subtract.prototype.backProp = function (math, inferenceArrays, gradientArrays) { - var _this = this; - var dy = gradientArrays.get(this.outTensor); - globals_1.tidy(function () { - if (graph_util.shouldBackProp(_this.t1)) { - if (util.isScalarShape(_this.t1.shape)) { - var sum = math.sum(dy); - gradientArrays.add(_this.t1, sum); - } - else { - gradientArrays.add(_this.t1, math.clone(dy)); - } - } - if (graph_util.shouldBackProp(_this.t2)) { - if (util.isScalarShape(_this.t2.shape)) { - var sum = math.sum(dy); - var negSum = math.neg(sum); - gradientArrays.add(_this.t2, negSum); - } - else { - gradientArrays.add(_this.t2, math.neg(dy)); - } - } - }); - }; - Subtract.prototype.dispose = function () { - if (this.dySizeScalar != null) { - this.dySizeScalar.dispose(); - } - }; - return Subtract; -}(op_1.Operation)); -exports.Subtract = Subtract; - -},{"../../globals":35,"../../util":151,"../graph_util":41,"./op":58}],63:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function defaultCompare(a, b) { - if (a === b) { - return 0; - } - else if (a < b) { - return -1; - } - else { - return 1; - } -} -exports.defaultCompare = defaultCompare; -var PriorityQueue = (function () { - function PriorityQueue(comparator, indexObserver) { - this.comparator = comparator; - this.indexObserver = indexObserver; - this.heap = []; - } - PriorityQueue.prototype.enqueue = function (t) { - this.heap.push(t); - this.onIndexChanged(t, this.heap.length - 1); - this.siftUp(this.heap.length - 1); - }; - PriorityQueue.prototype.dequeue = function () { - if (this.empty()) { - throw new Error('dequeue called on empty priority queue.'); - } - var t = this.heap[0]; - this.swap(0, this.heap.length - 1); - this.heap.pop(); - this.siftDown(0); - return t; - }; - PriorityQueue.prototype.update = function (newT, index) { - var last = (index === this.heap.length - 1); - if (!last) { - this.swap(index, this.heap.length - 1); - } - this.heap.pop(); - if (!last) { - if (this.siftUpIndex(index) !== -1) { - this.siftUp(index); - } - else if (this.siftDownIndex(index) !== -1) { - this.siftDown(index); - } - } - this.enqueue(newT); - }; - PriorityQueue.prototype.empty = function () { - return this.heap.length === 0; - }; - PriorityQueue.prototype.onIndexChanged = function (t, newIndex) { - if (this.indexObserver) { - this.indexObserver(t, newIndex); - } - }; - PriorityQueue.prototype.getParentIndex = function (index) { - if (index === 0) { - return -1; - } - return Math.floor((index - 1) / 2); - }; - PriorityQueue.prototype.getLeftChildIndex = function (index) { - var candidate = index * 2 + 1; - return candidate < this.heap.length ? candidate : -1; - }; - PriorityQueue.prototype.getRightChildIndex = function (index) { - var candidate = index * 2 + 2; - return candidate < this.heap.length ? candidate : -1; - }; - PriorityQueue.prototype.siftUpIndex = function (index) { - var parentIndex = this.getParentIndex(index); - if (parentIndex === -1) { - return -1; - } - if (this.compare(parentIndex, index) > 0) { - return parentIndex; - } - return -1; - }; - PriorityQueue.prototype.siftUp = function (index) { - var siftIndex = this.siftUpIndex(index); - while (siftIndex !== -1) { - this.swap(index, siftIndex); - index = siftIndex; - siftIndex = this.siftUpIndex(index); - } - }; - PriorityQueue.prototype.siftDownIndex = function (index) { - if (index >= this.heap.length) { - return -1; - } - var largestChildIndex = index; - var leftChildIndex = this.getLeftChildIndex(index); - if ((leftChildIndex !== -1) && - (this.compare(leftChildIndex, largestChildIndex) < 0)) { - largestChildIndex = leftChildIndex; - } - var rightChildIndex = this.getRightChildIndex(index); - if ((rightChildIndex !== -1) && - (this.compare(rightChildIndex, largestChildIndex) < 0)) { - largestChildIndex = rightChildIndex; - } - return (largestChildIndex === index) ? -1 : largestChildIndex; - }; - PriorityQueue.prototype.siftDown = function (index) { - var siftIndex = this.siftDownIndex(index); - while (siftIndex !== -1) { - this.swap(index, siftIndex); - index = siftIndex; - siftIndex = this.siftDownIndex(index); - } - }; - PriorityQueue.prototype.compare = function (aIndex, bIndex) { - return this.comparator(this.heap[aIndex], this.heap[bIndex]); - }; - PriorityQueue.prototype.swap = function (a, b) { - var temp = this.heap[a]; - this.heap[a] = this.heap[b]; - this.heap[b] = temp; - this.onIndexChanged(this.heap[a], a); - this.onIndexChanged(this.heap[b], b); - }; - return PriorityQueue; -}()); -exports.PriorityQueue = PriorityQueue; - -},{}],64:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var operation_emitter = require("./operation_emitter"); -var session_util = require("./session_util"); -var tensor_array_map_1 = require("./tensor_array_map"); -var FeedDictionary = (function () { - function FeedDictionary(feedEntries) { - var _this = this; - this.dict = {}; - if (feedEntries) { - feedEntries.forEach(function (entry) { return _this.dict[entry.tensor.id] = entry; }); - } - } - return FeedDictionary; -}()); -exports.FeedDictionary = FeedDictionary; -var CostReduction; -(function (CostReduction) { - CostReduction[CostReduction["NONE"] = 0] = "NONE"; - CostReduction[CostReduction["SUM"] = 1] = "SUM"; - CostReduction[CostReduction["MEAN"] = 2] = "MEAN"; -})(CostReduction = exports.CostReduction || (exports.CostReduction = {})); -var Session = (function () { - function Session(graph, math) { - this.math = math; - this.activationArrayMap = new tensor_array_map_1.TensorArrayMap(); - this.runtimeCache = {}; - this.oneScalar = tensor_1.Scalar.new(1); - this.gradientArrayMap = new tensor_array_map_1.SummedTensorArrayMap(this.math); - } - Session.prototype.dispose = function () { - var _this = this; - this.activationArrayMap.dispose(); - Object.keys(this.runtimeCache).forEach(function (key) { - var runtime = _this.runtimeCache[key]; - if (runtime.operations) { - runtime.operations.forEach(function (op) { return op.dispose(); }); - } - }); - this.runtimeCache = {}; - if (this.batchSizeScalar != null) { - this.batchSizeScalar.dispose(); - } - this.oneScalar.dispose(); - }; - Session.prototype.evalAll = function (tensors, feedEntries) { - var _this = this; - return globals_1.tidy(function () { - var feed = new FeedDictionary(feedEntries); - var runtime = _this.getOrCreateRuntime(tensors, feed); - var activations = _this.activationArrayMap; - session_util.disposeAndInitializeOperationOutputs(runtime.nodes, activations); - session_util.disposeTransientOperationArrays(runtime.operations, _this.activationArrayMap, _this.gradientArrayMap); - session_util.addPersistentArraysToTensorArrayMap(runtime.nodes, activations); - session_util.loadInputsFromFeedDictionaryToTensorArrayMap(feed, activations, _this.math); - runtime.operations.forEach(function (op) { return op.feedForward(_this.math, activations); }); - var results = tensors.map(function (x) { return activations.get(x); }); - tensors.forEach(function (x) { return activations.delete(x); }); - session_util.releaseFeedDictionaryInputsFromTensorArrayMap(feed, activations, _this.math); - return results; - }); - }; - Session.prototype.eval = function (tensor, feedEntries) { - return this.evalAll([tensor], feedEntries)[0]; - }; - Session.prototype.train = function (costTensor, feedEntries, batchSize, optimizer, costReduction) { - var _this = this; - if (costReduction === void 0) { costReduction = CostReduction.NONE; } - util.assert(util.isScalarShape(costTensor.shape), 'Cost tensor for training must be a scalar value.'); - if (this.prevBatchSize !== batchSize) { - this.prevBatchSize = batchSize; - if (this.batchSizeScalar != null) { - this.batchSizeScalar.dispose(); - } - this.batchSizeScalar = this.math.keep(tensor_1.Scalar.new(batchSize)); - } - var feed = new FeedDictionary(feedEntries); - session_util.throwIfFeedDictionaryContainsNDArrays(feed); - var runtime = this.getOrCreateRuntime([costTensor], feed); - var inferenceOperations = runtime.operations; - var backPropOperations = runtime.operations.slice().reverse(); - var activations = this.activationArrayMap; - var gradients = this.gradientArrayMap; - gradients.nullify(costTensor); - gradients.add(costTensor, this.oneScalar); - session_util.addPersistentArraysToTensorArrayMap(runtime.nodes, activations); - optimizer.beforeBatch(this.math, batchSize, runtime, activations, gradients); - return globals_1.tidy(function () { - var cost = tensor_1.Scalar.new(0); - for (var i = 0; i < batchSize; ++i) { - session_util.disposeAndInitializeOperationOutputs(runtime.nodes, activations); - session_util.disposeAndInitializeOperationInputGradients(runtime.nodes, gradients); - session_util.disposeTransientOperationArrays(runtime.operations, activations, gradients); - session_util.loadInputsFromFeedDictionaryToTensorArrayMap(feed, activations, _this.math); - inferenceOperations.forEach(function (op) { return op.feedForward(_this.math, activations); }); - backPropOperations.forEach(function (op) { return op.backProp(_this.math, activations, gradients); }); - optimizer.afterExample(_this.math, runtime, activations, gradients); - session_util.releaseFeedDictionaryInputsFromTensorArrayMap(feed, activations, _this.math); - cost = _this.updateCostForExample(cost, activations.get(costTensor), costReduction); - } - optimizer.afterBatch(_this.math, batchSize, runtime, activations, gradients); - return _this.updateCostForBatch(cost, costReduction); - }); - }; - Session.prototype.updateCostForExample = function (totalCost, currCost, costReduction) { - if (costReduction === CostReduction.MEAN || - costReduction === CostReduction.SUM) { - return this.math.add(totalCost, currCost); - } - return totalCost; - }; - Session.prototype.updateCostForBatch = function (totalCost, costReduction) { - if (costReduction === CostReduction.MEAN) { - return this.math.divide(totalCost, this.batchSizeScalar); - } - return totalCost; - }; - Session.prototype.getOrCreateRuntime = function (tensors, feed) { - var key = this.makeRuntimeCacheKey(tensors, feed); - var runtime = this.runtimeCache[key]; - if (runtime === undefined) { - var nodes = session_util.getOrderedEvaluationSetFromEvalTensor(tensors, feed); - session_util.removeFeedDictionaryNodesFromEvaluationSet(feed, nodes); - session_util.throwErrorIfEvaluationSetContainsPlaceholderNodes(nodes); - var operations = operation_emitter.emitFromGraphNodes(nodes); - runtime = { nodes: nodes, operations: operations }; - this.runtimeCache[key] = runtime; - } - return runtime; - }; - Session.prototype.makeRuntimeCacheKey = function (tensors, feed) { - return tensors.map(function (x) { return x.id; }).sort().join('_') + '__' + - Object.keys(feed.dict).sort().join('_'); - }; - return Session; -}()); -exports.Session = Session; - -},{"../globals":35,"../tensor":146,"../util":151,"./operation_emitter":43,"./session_util":65,"./tensor_array_map":66}],65:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var graph_1 = require("./graph"); -var graph_util = require("./graph_util"); -function getTerminatingNodesFromFeedDictionary(feedDictionary) { - return Object.keys(feedDictionary.dict) - .map(function (tensorID) { return feedDictionary.dict[+tensorID].tensor.node; }); -} -exports.getTerminatingNodesFromFeedDictionary = getTerminatingNodesFromFeedDictionary; -function getOrderedEvaluationSetFromEvalTensor(evalTensors, feedDictionary) { - var terminatingNodes = getTerminatingNodesFromFeedDictionary(feedDictionary); - var evalNodes = evalTensors.map(function (x) { return x.node; }); - var unorderedEvaluationSet = graph_util.getUnorderedEvaluationSet(evalNodes, terminatingNodes); - var orderedEvaluationSet = graph_util.getOrderedEvaluationSet(unorderedEvaluationSet); - return orderedEvaluationSet; -} -exports.getOrderedEvaluationSetFromEvalTensor = getOrderedEvaluationSetFromEvalTensor; -function addPersistentArraysToTensorArrayMap(evaluationSet, tensorArrayMap) { - evaluationSet.forEach(function (node) { - if (node instanceof graph_1.VariableNode || node instanceof graph_1.ConstantNode) { - tensorArrayMap.set(node.output, node.data); - } - }); -} -exports.addPersistentArraysToTensorArrayMap = addPersistentArraysToTensorArrayMap; -function getVariableNodesFromEvaluationSet(evaluationSet) { - var nodes = []; - evaluationSet.forEach(function (node) { - if (node instanceof graph_1.VariableNode) { - nodes.push(node); - } - }); - return nodes; -} -exports.getVariableNodesFromEvaluationSet = getVariableNodesFromEvaluationSet; -function throwIfFeedDictionaryContainsNDArrays(feedDictionary) { - Object.keys(feedDictionary.dict).forEach(function (tensorID) { - if (feedDictionary.dict[+tensorID].data instanceof tensor_1.Tensor) { - throw new Error('training requires FeedDictionary entries to be InputProviders' + - 'and not NDArrays.'); - } - }); -} -exports.throwIfFeedDictionaryContainsNDArrays = throwIfFeedDictionaryContainsNDArrays; -function loadInputsFromFeedDictionaryToTensorArrayMap(batchFeed, activations, math) { - Object.keys(batchFeed.dict).forEach(function (tensorID) { - var feedEntry = batchFeed.dict[+tensorID]; - var data; - if (feedEntry.data instanceof tensor_1.Tensor) { - data = feedEntry.data; - } - else { - var provider = feedEntry.data; - data = provider.getNextCopy(); - } - util.assert(util.arraysEqual(feedEntry.tensor.shape, data.shape), "Error loading FeedEntry: feeding NDArray of shape " + data.shape + " " + - ("does not match Tensor (id: " + feedEntry.tensor.id + ") shape: ") + - (feedEntry.tensor.shape + ".")); - activations.set(feedEntry.tensor, data); - }); -} -exports.loadInputsFromFeedDictionaryToTensorArrayMap = loadInputsFromFeedDictionaryToTensorArrayMap; -function releaseFeedDictionaryInputsFromTensorArrayMap(batchFeed, activations, math) { - Object.keys(batchFeed.dict).forEach(function (tensorID) { - var feedEntry = batchFeed.dict[+tensorID]; - if (!(feedEntry.data instanceof tensor_1.Tensor)) { - var provider = feedEntry.data; - var feedEntryArray = activations.get(feedEntry.tensor); - provider.disposeCopy(feedEntryArray); - } - activations.delete(feedEntry.tensor); - }); -} -exports.releaseFeedDictionaryInputsFromTensorArrayMap = releaseFeedDictionaryInputsFromTensorArrayMap; -function removeFeedDictionaryNodesFromEvaluationSet(feedDictionary, evaluationSet) { - var i = 0; - while (i < evaluationSet.length) { - var node = evaluationSet[i]; - if (feedDictionary.dict[node.output.id] != null) { - evaluationSet.splice(i, 1); - } - else { - ++i; - } - } -} -exports.removeFeedDictionaryNodesFromEvaluationSet = removeFeedDictionaryNodesFromEvaluationSet; -function disposeAndInitializeOperationOutputs(evaluationSet, tensorArrayMap) { - evaluationSet.forEach(function (node) { - if (!graph_util.isInputNode(node)) { - if (!graph_util.isPassthroughNode(node, tensorArrayMap)) { - tensorArrayMap.disposeArray(node.output); - } - tensorArrayMap.set(node.output, null); - } - }); -} -exports.disposeAndInitializeOperationOutputs = disposeAndInitializeOperationOutputs; -function disposeAndInitializeOperationInputGradients(evaluationSet, gradients) { - evaluationSet.forEach(function (node) { - Object.keys(node.inputs).forEach(function (inputName) { - var input = node.inputs[inputName]; - if (gradients.get(input, true) !== gradients.get(node.output, true)) { - gradients.disposeArray(input); - } - gradients.nullify(input); - }); - }); -} -exports.disposeAndInitializeOperationInputGradients = disposeAndInitializeOperationInputGradients; -function disposeTransientOperationArrays(operations, activations, gradients) { - operations.forEach(function (op) { return op.disposeTransientArrays(activations, gradients); }); -} -exports.disposeTransientOperationArrays = disposeTransientOperationArrays; -function throwErrorIfEvaluationSetContainsPlaceholderNodes(evaluationSet) { - evaluationSet.forEach(function (node) { - if (node instanceof graph_1.PlaceholderNode) { - var shape = '[' + node.output.shape.join(', ') + ']'; - throw new Error('Placeholder node "' + node.name + '" ' + shape + - ' not present in feed dictionary.'); - } - }); -} -exports.throwErrorIfEvaluationSetContainsPlaceholderNodes = throwErrorIfEvaluationSetContainsPlaceholderNodes; - -},{"../tensor":146,"../util":151,"./graph":39,"./graph_util":41}],66:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var TensorArrayMapBase = (function () { - function TensorArrayMapBase() { - this.dict = {}; - } - TensorArrayMapBase.prototype.get = function (tensor, skipChecks) { - if (skipChecks === void 0) { skipChecks = false; } - if (!skipChecks && this.dict[tensor.id] === undefined) { - throw new Error("tensor " + tensor.id + " not in array map."); - } - var nda = this.dict[tensor.id]; - if (!skipChecks && nda === null) { - throw new Error("tensor " + tensor.id + " has null array."); - } - return nda; - }; - TensorArrayMapBase.prototype.delete = function (tensor) { - delete this.dict[tensor.id]; - }; - TensorArrayMapBase.prototype.nullify = function (tensor) { - this.dict[tensor.id] = null; - }; - TensorArrayMapBase.prototype.disposeArray = function (tensor) { - if (this.dict[tensor.id] === undefined) { - return; - } - var nda = this.dict[tensor.id]; - if (nda === null) { - return; - } - nda.dispose(); - this.dict[tensor.id] = null; - }; - TensorArrayMapBase.prototype.size = function () { - return Object.keys(this.dict).length; - }; - TensorArrayMapBase.prototype.dispose = function () { - var _this = this; - Object.keys(this.dict).forEach(function (tensorID) { - var nda = _this.dict[+tensorID]; - if (nda) { - nda.dispose(); - } - }); - this.dict = {}; - }; - TensorArrayMapBase.prototype.hasNullArray = function (tensor) { - if (this.dict[tensor.id] === undefined) { - throw new Error("tensor " + tensor.id + " not in array map."); - } - return this.dict[tensor.id] === null; - }; - return TensorArrayMapBase; -}()); -exports.TensorArrayMapBase = TensorArrayMapBase; -var TensorArrayMap = (function (_super) { - __extends(TensorArrayMap, _super); - function TensorArrayMap() { - return _super !== null && _super.apply(this, arguments) || this; - } - TensorArrayMap.prototype.set = function (tensor, array) { - this.dict[tensor.id] = array; - }; - return TensorArrayMap; -}(TensorArrayMapBase)); -exports.TensorArrayMap = TensorArrayMap; -var SummedTensorArrayMap = (function (_super) { - __extends(SummedTensorArrayMap, _super); - function SummedTensorArrayMap(math) { - var _this = _super.call(this) || this; - _this.math = math; - return _this; - } - SummedTensorArrayMap.prototype.add = function (tensor, array) { - if (this.dict[tensor.id] == null) { - this.dict[tensor.id] = this.math.keep(array); - } - else { - var oldValue = this.get(tensor); - var newValue = this.math.keep(this.math.addStrict(oldValue, array)); - this.dict[tensor.id] = newValue; - oldValue.dispose(); - } - }; - return SummedTensorArrayMap; -}(TensorArrayMapBase)); -exports.SummedTensorArrayMap = SummedTensorArrayMap; - -},{}],67:[function(require,module,exports){ -"use strict"; -function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; -} -Object.defineProperty(exports, "__esModule", { value: true }); -var browser_util_1 = require("./browser_util"); -var contrib = require("./contrib"); -exports.contrib = contrib; -var xhr_dataset = require("./data/xhr-dataset"); -exports.xhr_dataset = xhr_dataset; -var environment = require("./environment"); -exports.environment = environment; -var environment_1 = require("./environment"); -var gpgpu_util = require("./kernels/webgl/gpgpu_util"); -exports.gpgpu_util = gpgpu_util; -var webgl_util = require("./kernels/webgl/webgl_util"); -exports.webgl_util = webgl_util; -var conv_util = require("./ops/conv_util"); -exports.conv_util = conv_util; -var test_util = require("./test_util"); -exports.test_util = test_util; -var util = require("./util"); -exports.util = util; -var version_1 = require("./version"); -exports.version = version_1.version; -var checkpoint_loader_1 = require("./data/checkpoint_loader"); -exports.CheckpointLoader = checkpoint_loader_1.CheckpointLoader; -var dataset_1 = require("./data/dataset"); -exports.InMemoryDataset = dataset_1.InMemoryDataset; -var input_provider_1 = require("./data/input_provider"); -exports.InCPUMemoryShuffledInputProviderBuilder = input_provider_1.InCPUMemoryShuffledInputProviderBuilder; -exports.InGPUMemoryShuffledInputProviderBuilder = input_provider_1.InGPUMemoryShuffledInputProviderBuilder; -var xhr_dataset_1 = require("./data/xhr-dataset"); -exports.XhrDataset = xhr_dataset_1.XhrDataset; -var environment_2 = require("./environment"); -exports.ENV = environment_2.ENV; -exports.Environment = environment_2.Environment; -var graph_1 = require("./graph/graph"); -exports.Graph = graph_1.Graph; -exports.SymbolicTensor = graph_1.SymbolicTensor; -var graph_runner_1 = require("./graph/graph_runner"); -exports.GraphRunner = graph_runner_1.GraphRunner; -exports.MetricReduction = graph_runner_1.MetricReduction; -var initializers_1 = require("./graph/initializers"); -exports.ConstantInitializer = initializers_1.ConstantInitializer; -exports.OnesInitializer = initializers_1.OnesInitializer; -exports.RandomNormalInitializer = initializers_1.RandomNormalInitializer; -exports.RandomTruncatedNormalInitializer = initializers_1.RandomTruncatedNormalInitializer; -exports.RandomUniformInitializer = initializers_1.RandomUniformInitializer; -exports.TensorInitializer = initializers_1.TensorInitializer; -exports.VarianceScalingInitializer = initializers_1.VarianceScalingInitializer; -exports.ZerosInitializer = initializers_1.ZerosInitializer; -var session_1 = require("./graph/session"); -exports.CostReduction = session_1.CostReduction; -exports.Session = session_1.Session; -var backend_cpu_1 = require("./kernels/backend_cpu"); -exports.MathBackendCPU = backend_cpu_1.MathBackendCPU; -exports.NDArrayMathCPU = backend_cpu_1.NDArrayMathCPU; -var backend_webgl_1 = require("./kernels/backend_webgl"); -exports.MathBackendWebGL = backend_webgl_1.MathBackendWebGL; -exports.NDArrayMathGPU = backend_webgl_1.NDArrayMathGPU; -var matmul_1 = require("./kernels/types/matmul"); -exports.MatrixOrientation = matmul_1.MatrixOrientation; -var gpgpu_context_1 = require("./kernels/webgl/gpgpu_context"); -exports.GPGPUContext = gpgpu_context_1.GPGPUContext; -var math_1 = require("./math"); -exports.NDArrayMath = math_1.NDArrayMath; -var adadelta_optimizer_1 = require("./optimizers/adadelta_optimizer"); -exports.AdadeltaOptimizer = adadelta_optimizer_1.AdadeltaOptimizer; -var adagrad_optimizer_1 = require("./optimizers/adagrad_optimizer"); -exports.AdagradOptimizer = adagrad_optimizer_1.AdagradOptimizer; -var adam_optimizer_1 = require("./optimizers/adam_optimizer"); -exports.AdamOptimizer = adam_optimizer_1.AdamOptimizer; -var adamax_optimizer_1 = require("./optimizers/adamax_optimizer"); -exports.AdamaxOptimizer = adamax_optimizer_1.AdamaxOptimizer; -var momentum_optimizer_1 = require("./optimizers/momentum_optimizer"); -exports.MomentumOptimizer = momentum_optimizer_1.MomentumOptimizer; -var optimizer_1 = require("./optimizers/optimizer"); -exports.Optimizer = optimizer_1.Optimizer; -var rmsprop_optimizer_1 = require("./optimizers/rmsprop_optimizer"); -exports.RMSPropOptimizer = rmsprop_optimizer_1.RMSPropOptimizer; -var sgd_optimizer_1 = require("./optimizers/sgd_optimizer"); -exports.SGDOptimizer = sgd_optimizer_1.SGDOptimizer; -var tensor_1 = require("./tensor"); -exports.Array1D = tensor_1.Array1D; -exports.Array2D = tensor_1.Array2D; -exports.Array3D = tensor_1.Array3D; -exports.Array4D = tensor_1.Array4D; -exports.NDArray = tensor_1.NDArray; -exports.Scalar = tensor_1.Scalar; -exports.Tensor = tensor_1.Tensor; -exports.Tensor1D = tensor_1.Tensor1D; -exports.Tensor2D = tensor_1.Tensor2D; -exports.Tensor3D = tensor_1.Tensor3D; -exports.Tensor4D = tensor_1.Tensor4D; -exports.variable = tensor_1.variable; -exports.Variable = tensor_1.Variable; -var types_1 = require("./types"); -exports.Rank = types_1.Rank; -__export(require("./ops/ops")); -__export(require("./train")); -__export(require("./globals")); -exports.setBackend = environment_1.Environment.setBackend; -exports.getBackend = environment_1.Environment.getBackend; -exports.memory = environment_1.Environment.memory; -exports.nextFrame = browser_util_1.BrowserUtil.nextFrame; - -},{"./browser_util":10,"./contrib":26,"./data/checkpoint_loader":27,"./data/dataset":28,"./data/input_provider":29,"./data/xhr-dataset":30,"./environment":34,"./globals":35,"./graph/graph":39,"./graph/graph_runner":40,"./graph/initializers":42,"./graph/session":64,"./kernels/backend_cpu":68,"./kernels/backend_webgl":69,"./kernels/types/matmul":71,"./kernels/webgl/gpgpu_context":83,"./kernels/webgl/gpgpu_util":85,"./kernels/webgl/webgl_util":104,"./math":105,"./ops/conv_util":115,"./ops/ops":123,"./optimizers/adadelta_optimizer":135,"./optimizers/adagrad_optimizer":136,"./optimizers/adam_optimizer":137,"./optimizers/adamax_optimizer":138,"./optimizers/momentum_optimizer":139,"./optimizers/optimizer":140,"./optimizers/rmsprop_optimizer":142,"./optimizers/sgd_optimizer":143,"./tensor":146,"./test_util":147,"./train":149,"./types":150,"./util":151,"./version":152}],68:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var environment_1 = require("../environment"); -var math_1 = require("../math"); -var axis_util = require("../ops/axis_util"); -var broadcast_util = require("../ops/broadcast_util"); -var concat_util = require("../ops/concat_util"); -var ops = require("../ops/ops"); -var ops_1 = require("../ops/ops"); -var selu_util = require("../ops/selu_util"); -var tensor_1 = require("../tensor"); -var types = require("../types"); -var util = require("../util"); -var MathBackendCPU = (function () { - function MathBackendCPU() { - this.data = new WeakMap(); - if (typeof document !== 'undefined') { - this.canvas = document.createElement('canvas'); - } - } - MathBackendCPU.prototype.register = function (dataId, shape, dtype) { - if (this.data.has(dataId)) { - throw new Error("Data buffer is already registered"); - } - this.data.set(dataId, null); - }; - MathBackendCPU.prototype.write = function (dataId, values) { - if (values == null) { - throw new Error('MathBackendCPU.write(): values can not be null'); - } - this.throwIfNoData(dataId); - this.data.set(dataId, values); - }; - MathBackendCPU.prototype.fromPixels = function (pixels, numChannels) { - if (pixels == null) { - throw new Error('MathBackendCPU.writePixels(): pixels can not be null'); - } - var vals; - if (pixels instanceof ImageData) { - vals = pixels.data; - } - else if (pixels instanceof HTMLCanvasElement) { - vals = pixels.getContext('2d') - .getImageData(0, 0, pixels.width, pixels.height) - .data; - } - else if (pixels instanceof HTMLImageElement || - pixels instanceof HTMLVideoElement) { - if (this.canvas == null) { - throw new Error('Can\'t read pixels from HTMLImageElement outside ' + - 'the browser.'); - } - this.canvas.width = pixels.width; - this.canvas.height = pixels.height; - this.canvas.getContext('2d').drawImage(pixels, 0, 0, pixels.width, pixels.height); - vals = this.canvas.getContext('2d') - .getImageData(0, 0, pixels.width, pixels.height) - .data; - } - else { - throw new Error("pixels is of unknown type: " + pixels.constructor.name); - } - var values; - if (numChannels === 4) { - values = new Int32Array(vals); - } - else { - var numPixels = pixels.width * pixels.height; - values = new Int32Array(numPixels * numChannels); - for (var i = 0; i < numPixels; i++) { - for (var channel = 0; channel < numChannels; ++channel) { - values[i * numChannels + channel] = vals[i * 4 + channel]; - } - } - } - var outShape = [pixels.height, pixels.width, numChannels]; - return ops_1.tensor3d(values, outShape, 'int32'); - }; - MathBackendCPU.prototype.read = function (dataId) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2, this.readSync(dataId)]; - }); - }); - }; - MathBackendCPU.prototype.readSync = function (dataId) { - this.throwIfNoData(dataId); - return this.data.get(dataId); - }; - MathBackendCPU.prototype.disposeData = function (dataId) { - if (this.data.has(dataId)) { - this.data.delete(dataId); - } - }; - MathBackendCPU.prototype.time = function (f) { - return __awaiter(this, void 0, void 0, function () { - var start, kernelMs; - return __generator(this, function (_a) { - start = performance.now(); - f(); - kernelMs = performance.now() - start; - return [2, { kernelMs: kernelMs }]; - }); - }); - }; - MathBackendCPU.prototype.memory = function () { - return { - unreliable: true - }; - }; - MathBackendCPU.prototype.throwIfNoData = function (dataId) { - if (!this.data.has(dataId)) { - throw new Error("CPU backend: No data found for this tensor. " + - "Did you change your backend in the middle of the program? " + - "New backends can't use Tensors created with previous backends"); - } - }; - MathBackendCPU.prototype.slice1D = function (x, begin, size) { - var newVals = x.dataSync().slice(begin, begin + size); - return ops.tensor1d(newVals, x.dtype); - }; - MathBackendCPU.prototype.slice2D = function (x, begin, size) { - var buffer = ops.buffer(size, x.dtype); - var startI = begin[0], startJ = begin[1]; - for (var i = 0; i < size[0]; ++i) { - for (var j = 0; j < size[1]; ++j) { - var val = x.get(i + startI, j + startJ); - buffer.set(val, i, j); - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.slice3D = function (x, begin, size) { - var buffer = ops.buffer(size, x.dtype); - var startI = begin[0], startJ = begin[1], startK = begin[2]; - for (var i = 0; i < size[0]; ++i) { - for (var j = 0; j < size[1]; ++j) { - for (var k = 0; k < size[2]; ++k) { - var val = x.get(i + startI, j + startJ, k + startK); - buffer.set(val, i, j, k); - } - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.slice4D = function (x, begin, size) { - var buffer = ops.buffer(size, x.dtype); - var startI = begin[0], startJ = begin[1], startK = begin[2], startL = begin[3]; - for (var i = 0; i < size[0]; ++i) { - for (var j = 0; j < size[1]; ++j) { - for (var k = 0; k < size[2]; ++k) { - for (var l = 0; l < size[3]; ++l) { - var val = x.get(i + startI, j + startJ, k + startK, l + startL); - buffer.set(val, i, j, k, l); - } - } - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.reverse4D = function (x, axis) { - var buffer = ops.buffer(x.shape, x.dtype); - var revAxis = function (i) { return axis.indexOf(i) !== -1 && x.shape[i] !== 1; }; - for (var b = 0; b < x.shape[0]; ++b) { - for (var r = 0; r < x.shape[1]; ++r) { - for (var c = 0; c < x.shape[2]; ++c) { - for (var d = 0; d < x.shape[3]; ++d) { - var b0 = revAxis(0) ? x.shape[0] - b - 1 : b; - var r0 = revAxis(1) ? x.shape[1] - r - 1 : r; - var c0 = revAxis(2) ? x.shape[2] - c - 1 : c; - var d0 = revAxis(3) ? x.shape[3] - d - 1 : d; - var val = x.get(b0, r0, c0, d0); - buffer.set(val, b, r, c, d); - } - } - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.concat = function (a, b) { - var outShape = concat_util.computeOutShape(a.shape, b.shape, 1); - var buffer = ops.buffer(outShape, a.dtype); - if (a.shape[0] === 1 && b.shape[0] === 1) { - var aVals = a.dataSync(); - var bVals = b.dataSync(); - var vals = buffer.values; - vals.set(aVals, 0); - vals.set(bVals, a.size); - return buffer.toTensor(); - } - for (var i = 0; i < outShape[0]; ++i) { - for (var j = 0; j < a.shape[1]; ++j) { - buffer.set(a.get(i, j), i, j); - } - for (var j = 0; j < b.shape[1]; ++j) { - buffer.set(b.get(i, j), i, j + a.shape[1]); - } - } - return buffer.toTensor(); - }; - MathBackendCPU.prototype.neg = function (x) { - return this.multiply(ops.scalar(-1), x); - }; - MathBackendCPU.prototype.add = function (a, b) { - return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue + bValue; }); - }; - MathBackendCPU.prototype.subtract = function (a, b) { - return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue - bValue; }); - }; - MathBackendCPU.prototype.pow = function (a, b) { - return this.broadcastedBinaryOp(a, b, a.dtype, function (aValue, bValue) { return Math.pow(aValue, bValue); }); - }; - MathBackendCPU.prototype.matMul = function (a, b, transposeA, transposeB) { - var sharedDim = transposeA ? a.shape[0] : a.shape[1]; - var leftDim = transposeA ? a.shape[1] : a.shape[0]; - var rightDim = transposeB ? b.shape[0] : b.shape[1]; - var normalGetter = function (matrix, i, j) { - return matrix.get(i, j); - }; - var transposedGetter = function (matrix, i, j) { - return matrix.get(j, i); - }; - var aGetter = transposeA ? transposedGetter : normalGetter; - var bGetter = transposeB ? transposedGetter : normalGetter; - var values = new Float32Array(leftDim * rightDim); - var index = 0; - for (var i = 0; i < leftDim; ++i) { - for (var j = 0; j < rightDim; ++j) { - var sum = 0; - for (var k = 0; k < sharedDim; ++k) { - sum += aGetter(a, i, k) * bGetter(b, k, j); - } - values[index++] = sum; - } - } - return ops.tensor2d(values, [leftDim, rightDim]); - }; - MathBackendCPU.prototype.multiply = function (a, b) { - return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue * bValue; }); - }; - MathBackendCPU.prototype.divide = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'float32', function (aValue, bValue) { return aValue / bValue; }); - }; - MathBackendCPU.prototype.sum = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('sum', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var resultDtype = types.upcastType(x.dtype, 'int32'); - var result = ops.zeros(outShape, resultDtype); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var sum = 0; - for (var j = 0; j < reduceSize; ++j) { - sum += aVals[offset + j]; - } - vals[i] = sum; - } - return result; - }; - MathBackendCPU.prototype.argMin = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMin', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, 'int32'); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var min = aVals[offset]; - var minIndex = 0; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - minIndex = util.NAN_INT32; - break; - } - if (value < min) { - min = value; - minIndex = j; - } - } - vals[i] = minIndex; - } - return result; - }; - MathBackendCPU.prototype.argMax = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMax', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, 'int32'); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var max = aVals[offset]; - var maxIndex = 0; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - maxIndex = util.NAN_INT32; - break; - } - if (value > max) { - max = value; - maxIndex = j; - } - } - vals[i] = maxIndex; - } - return result; - }; - MathBackendCPU.prototype.equal = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal === bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.notEqual = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal !== bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.less = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal < bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.lessEqual = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal <= bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.greater = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal > bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.greaterEqual = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return (aVal >= bVal) ? 1 : 0; - } - }); - }; - MathBackendCPU.prototype.logicalNot = function (x) { - var values = x.dataSync(); - var newValues = new Int32Array(values.length); - for (var i = 0; i < values.length; ++i) { - if (util.isValNaN(values[i], x.dtype)) { - newValues[i] = util.getNaN('bool'); - } - else { - newValues[i] = values[i] ? 0 : 1; - } - } - return tensor_1.Tensor.make(x.shape, { values: newValues }, 'bool'); - }; - MathBackendCPU.prototype.logicalAnd = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return aVal && bVal; - } - }); - }; - MathBackendCPU.prototype.logicalOr = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return aVal || bVal; - } - }); - }; - MathBackendCPU.prototype.logicalXor = function (a, b) { - return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) { - if (util.isValNaN(aVal, a.dtype) || util.isValNaN(bVal, b.dtype)) { - return util.getNaN('bool'); - } - else { - return aVal ^ bVal; - } - }); - }; - MathBackendCPU.prototype.where = function (condition, a, b, dtype) { - var values = condition.dataSync(); - var aValues = a.dataSync(); - var bValues = b.dataSync(); - var result = ops.zeros(a.shape, dtype); - var newValues = result.dataSync(); - var index = 0; - var offset = condition.rank === 0 || condition.rank > 1 || a.rank === 1 ? - 1 : - a.shape[1]; - for (var i = 0; i < values.length; i++) { - for (var j = 0; j < offset; j++) { - if (values[i] === 1) { - newValues[index++] = aValues[i]; - } - else { - newValues[index++] = bValues[i]; - } - } - } - return result; - }; - MathBackendCPU.prototype.topKValues = function (x, k) { - return this.topK(x, k).values; - }; - MathBackendCPU.prototype.topKIndices = function (x, k) { - return this.topK(x, k).indices; - }; - MathBackendCPU.prototype.topK = function (x, k) { - var values = x.dataSync(); - var valuesAndIndices = []; - for (var i = 0; i < values.length; i++) { - valuesAndIndices.push({ value: values[i], index: i }); - } - valuesAndIndices.sort(function (a, b) { - return b.value - a.value; - }); - var topkValues = util.getTypedArrayFromDType(x.dtype, k); - var topkIndices = new Int32Array(k); - for (var i = 0; i < k; i++) { - topkValues[i] = valuesAndIndices[i].value; - topkIndices[i] = valuesAndIndices[i].index; - } - return { - values: ops.tensor1d(topkValues, x.dtype), - indices: tensor_1.Tensor1D.new(topkIndices) - }; - }; - MathBackendCPU.prototype.min = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('min', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, x.dtype); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var min = aVals[0]; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - min = Number.NaN; - break; - } - if (value < min) { - min = value; - } - } - vals[i] = min; - } - return result; - }; - MathBackendCPU.prototype.minimum = function (a, b) { - return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) { return Math.min(aVal, bVal); }); - }; - MathBackendCPU.prototype.max = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('max', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var result = ops.zeros(outShape, x.dtype); - var reduceSize = util.sizeFromShape(reduceShape); - var vals = result.dataSync(); - var aVals = x.dataSync(); - for (var i = 0; i < vals.length; ++i) { - var offset = i * reduceSize; - var max = aVals[offset]; - for (var j = 0; j < reduceSize; ++j) { - var value = aVals[offset + j]; - if (isNaN(value)) { - max = Number.NaN; - break; - } - if (value > max) { - max = value; - } - } - vals[i] = max; - } - return result; - }; - MathBackendCPU.prototype.maximum = function (a, b) { - return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) { return Math.max(aVal, bVal); }); - }; - MathBackendCPU.prototype.ceil = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - newValues[i] = Math.ceil(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.floor = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - newValues[i] = Math.floor(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.exp = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - newValues[i] = Math.exp(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.log = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - newValues[i] = Math.log(value); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.sqrt = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - newValues[i] = Math.sqrt(value); - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.square = function (x) { - var values = x.dataSync(); - var newValues = new Float32Array(values.length); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - newValues[i] = value * value; - } - return tensor_1.Tensor.make(x.shape, { values: newValues }); - }; - MathBackendCPU.prototype.relu = function (x) { - var res = ops.zeros(x.shape, x.dtype); - var resVals = res.dataSync(); - var inVals = x.dataSync(); - for (var i = 0; i < inVals.length; ++i) { - var val = inVals[i]; - if (util.isValNaN(val, x.dtype)) { - resVals[i] = util.getNaN(res.dtype); - } - else { - resVals[i] = Math.max(0, inVals[i]); - } - } - return res; - }; - MathBackendCPU.prototype.elu = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = v; - } - else { - resultValues[i] = (Math.exp(v) - 1); - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.eluDer = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = 1; - } - else { - resultValues[i] = Math.exp(v); - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.selu = function (x) { - var scaleAlpha = selu_util.SELU_SCALEALPHA; - var scale = selu_util.SELU_SCALE; - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = scale * v; - } - else { - resultValues[i] = scaleAlpha * (Math.exp(v) - 1); - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.leakyRelu = function (x, alpha) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; i++) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = v; - } - else { - resultValues[i] = alpha * v; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.prelu = function (x, alpha) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - var alphas = alpha.dataSync(); - for (var i = 0; i < values.length; i++) { - var v = values[i]; - if (v >= 0) { - resultValues[i] = v; - } - else { - resultValues[i] = alphas[i] * v; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.preluDer = function (x, alpha) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - var alphas = alpha.dataSync(); - for (var i = 0; i < values.length; i++) { - var v = values[i]; - if (v > 0) { - resultValues[i] = 1; - } - else if (v < 0) { - resultValues[i] = alphas[i]; - } - else { - resultValues[i] = v; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.clip = function (x, min, max) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.min(max, Math.max(min, values[i])); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.abs = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.abs(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.int = function (x) { - var resultValues = new Int32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = values[i]; - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }, 'int32'); - }; - MathBackendCPU.prototype.sigmoid = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = 1 / (1 + Math.exp(-values[i])); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.sin = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.sin(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.cos = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.cos(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.tan = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.tan(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.asin = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.asin(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.acos = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.acos(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.atan = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.atan(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.sinh = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.sinh(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.cosh = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = Math.cosh(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.tanh = function (x) { - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - resultValues[i] = util.tanh(values[i]); - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.step = function (x, alpha) { - if (alpha === void 0) { alpha = 0; } - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - for (var i = 0; i < values.length; ++i) { - var value = values[i]; - if (util.isValNaN(value, x.dtype)) { - resultValues[i] = util.getNaN(x.dtype); - } - else { - resultValues[i] = value > 0 ? 1 : alpha; - } - } - return tensor_1.Tensor.make(x.shape, { values: resultValues }); - }; - MathBackendCPU.prototype.conv2d = function (x, filter, convInfo) { - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = convInfo.padInfo.left; - var padTop = convInfo.padInfo.top; - var y = ops.buffer(convInfo.outShape, x.dtype); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d2 = 0; d2 < convInfo.outChannels; ++d2) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * convInfo.strideHeight - padLeft; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * convInfo.strideWidth - padTop; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - var dotProd = 0; - for (var xR = xRMin; xR < xRMax; ++xR) { - var wR = xR - xRCorner; - for (var xC = xCMin; xC < xCMax; ++xC) { - var wC = xC - xCCorner; - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - var pixel = x.get(b, xR, xC, d1); - var weight = filter.get(wR, wC, d1, d2); - dotProd += pixel * weight; - } - } - } - y.set(dotProd, b, yR, yC, d2); - } - } - } - } - return y.toTensor(); - }; - MathBackendCPU.prototype.conv2dDerInput = function (dy, filter, convInfo) { - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var topPad = filterHeight - 1 - convInfo.padInfo.top; - var leftPad = filterWidth - 1 - convInfo.padInfo.left; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var dx = ops.buffer(convInfo.inShape, 'float32'); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - for (var xR = 0; xR < convInfo.inHeight; ++xR) { - var xRCorner = xR - leftPad; - var xRMin = Math.max(0, Math.ceil(xRCorner / strideHeight)); - var yRMax = Math.min(convInfo.outHeight, (filterHeight + xRCorner) / strideHeight); - for (var xC = 0; xC < convInfo.inWidth; ++xC) { - var xCCorner = xC - topPad; - var xCMin = Math.max(0, Math.ceil(xCCorner / strideWidth)); - var yCMax = Math.min(convInfo.outWidth, (filterWidth + xCCorner) / strideWidth); - var dotProd = 0; - for (var yR = xRMin; yR < yRMax; ++yR) { - var wR = yR * strideHeight - xRCorner; - for (var yC = xCMin; yC < yCMax; ++yC) { - var wC = yC * strideWidth - xCCorner; - for (var d2 = 0; d2 < convInfo.outChannels; ++d2) { - var pixel = dy.get(b, yR, yC, d2); - var weight = filter.get(filterHeight - 1 - wR, filterWidth - 1 - wC, d1, d2); - dotProd += pixel * weight; - } - } - } - dx.set(dotProd, b, xR, xC, d1); - } - } - } - } - return dx.toTensor(); - }; - MathBackendCPU.prototype.conv2dDerFilter = function (x, dy, convInfo) { - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var dW = ops.buffer(convInfo.filterShape, 'float32'); - var leftPad = convInfo.padInfo.left; - var topPad = convInfo.padInfo.top; - for (var wR = 0; wR < filterHeight; ++wR) { - var yRMin = Math.max(0, Math.ceil((topPad - wR) / strideHeight)); - var yRMax = Math.min(convInfo.outHeight, (convInfo.inHeight + topPad - wR) / strideHeight); - for (var wC = 0; wC < filterWidth; ++wC) { - var yCMin = Math.max(0, Math.ceil((leftPad - wC) / strideWidth)); - var yCMax = Math.min(convInfo.outWidth, (convInfo.inWidth + leftPad - wC) / strideWidth); - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - for (var d2 = 0; d2 < convInfo.outChannels; ++d2) { - var dotProd = 0; - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var yR = yRMin; yR < yRMax; ++yR) { - var xR = wR + yR * strideHeight - topPad; - for (var yC = yCMin; yC < yCMax; ++yC) { - var xC = wC + yC * strideWidth - leftPad; - dotProd += x.get(b, xR, xC, d1) * dy.get(b, yR, yC, d2); - } - } - } - dW.set(dotProd, wR, wC, d1, d2); - } - } - } - } - return dW.toTensor(); - }; - MathBackendCPU.prototype.depthwiseConv2D = function (x, filter, convInfo) { - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = convInfo.padInfo.left; - var padTop = convInfo.padInfo.top; - var chMul = convInfo.outChannels / convInfo.inChannels; - var y = ops.buffer(convInfo.outShape, x.dtype); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d1 = 0; d1 < convInfo.inChannels; ++d1) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * convInfo.strideHeight - padLeft; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * convInfo.strideWidth - padTop; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - for (var q = 0; q < chMul; ++q) { - var dotProd = 0; - for (var xR = xRMin; xR < xRMax; ++xR) { - var wR = xR - xRCorner; - for (var xC = xCMin; xC < xCMax; ++xC) { - var wC = xC - xCCorner; - var pixel = x.get(b, xR, xC, d1); - var weight = filter.get(wR, wC, d1, q); - dotProd += pixel * weight; - } - } - y.set(dotProd, b, yR, yC, d1 * chMul + q); - } - } - } - } - } - return y.toTensor(); - }; - MathBackendCPU.prototype.tile = function (x, reps) { - var newShape = new Array(x.rank); - for (var i = 0; i < newShape.length; i++) { - newShape[i] = x.shape[i] * reps[i]; - } - var result = ops.buffer(newShape, x.dtype); - var values = x.dataSync(); - for (var i = 0; i < result.values.length; ++i) { - var newLoc = result.indexToLoc(i); - var originalLoc = new Array(x.rank); - for (var i_1 = 0; i_1 < originalLoc.length; i_1++) { - originalLoc[i_1] = newLoc[i_1] % x.shape[i_1]; - } - var originalIndex = x.locToIndex(originalLoc); - result.values[i] = values[originalIndex]; - } - return result.toTensor(); - }; - MathBackendCPU.prototype.pad1D = function (x, paddings, constantValue) { - var leftPadding = paddings[0]; - var rightPadding = paddings[1]; - var values = x.dataSync(); - var result = ops.zeros([leftPadding + values.length + rightPadding], x.dtype); - var newValues = result.dataSync(); - var z = 0; - for (var i = 0; i < newValues.length; i++) { - if (i >= leftPadding && i < leftPadding + values.length) { - newValues[i] = values[z++]; - } - else { - newValues[i] = constantValue; - } - } - return result; - }; - MathBackendCPU.prototype.pad2D = function (x, paddings, constantValue) { - var topPadding = paddings[0][0]; - var bottomPadding = paddings[0][1]; - var leftPadding = paddings[1][0]; - var rightPadding = paddings[1][1]; - var newShape = [ - topPadding + x.shape[0] + bottomPadding, - leftPadding + x.shape[1] + rightPadding - ]; - var result = ops.zeros(newShape, x.dtype); - var newValues = result.dataSync(); - var values = x.dataSync(); - var z = 0; - for (var i = 0; i < newShape[0]; i++) { - var rangeStart = -1; - var rangeEnd = -1; - if (i >= topPadding && i < newShape[0] - bottomPadding) { - rangeStart = i * newShape[1] + leftPadding; - rangeEnd = rangeStart + x.shape[1] - 1; - } - for (var j = 0; j < newShape[1]; j++) { - var v = i * newShape[1] + j; - if (v >= rangeStart && v <= rangeEnd) { - newValues[v] = values[z++]; - } - else { - newValues[v] = constantValue; - } - } - } - return result; - }; - MathBackendCPU.prototype.transpose = function (x, perm) { - var newShape = new Array(x.rank); - for (var i = 0; i < newShape.length; i++) { - newShape[i] = x.shape[perm[i]]; - } - var resultValues = new Float32Array(x.size); - var values = x.dataSync(); - var result = tensor_1.Tensor.make(newShape, { values: resultValues }); - for (var i = 0; i < x.size; ++i) { - var loc = x.indexToLoc(i); - var newLoc = new Array(loc.length); - for (var i_2 = 0; i_2 < newLoc.length; i_2++) { - newLoc[i_2] = loc[perm[i_2]]; - } - var newIndex = result.locToIndex(newLoc); - resultValues[newIndex] = values[i]; - } - return result; - }; - MathBackendCPU.prototype.gather = function (x, indices, axis) { - var newShape = x.shape.slice(); - var indicesValues = indices.dataSync(); - newShape[axis] = indicesValues.length; - var result = ops.zeros(newShape, x.dtype); - var values = x.dataSync(); - var resultValues = result.dataSync(); - for (var i = 0; i < result.size; ++i) { - var newLoc = result.indexToLoc(i); - var originalLoc = newLoc.slice(); - originalLoc[axis] = indicesValues[newLoc[axis]]; - var originalIndex = x.locToIndex(originalLoc); - resultValues[i] = values[originalIndex]; - } - return result; - }; - MathBackendCPU.prototype.pool = function (x, convInfo, poolType) { - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var y = ops.buffer(convInfo.outShape, 'float32'); - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * strideHeight - padTop; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * strideWidth - padLeft; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - var minMaxValue = (poolType === 'max' ? Number.NEGATIVE_INFINITY : - Number.POSITIVE_INFINITY); - var avgValue = 0; - for (var xR = xRMin; xR < xRMax; ++xR) { - for (var xC = xCMin; xC < xCMax; ++xC) { - var pixel = x.get(b, xR, xC, d); - if (isNaN(pixel)) { - minMaxValue = NaN; - avgValue = NaN; - break; - } - if ((poolType === 'max' && pixel > minMaxValue) || - (poolType === 'min' && pixel < minMaxValue)) { - minMaxValue = pixel; - } - else if (poolType === 'avg') { - avgValue += pixel / (filterHeight * filterWidth); - } - } - if (isNaN(minMaxValue)) { - break; - } - } - y.set(poolType === 'avg' ? avgValue : minMaxValue, b, yR, yC, d); - } - } - } - } - return y.toTensor(); - }; - MathBackendCPU.prototype.maxPool = function (x, convInfo) { - return this.pool(x, convInfo, 'max'); - }; - MathBackendCPU.prototype.maxPoolPositions = function (x, convInfo) { - var maxPositions = ops.buffer(convInfo.outShape, 'int32'); - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var yR = 0; yR < convInfo.outHeight; ++yR) { - var xRCorner = yR * strideHeight - padTop; - var xRMin = Math.max(0, xRCorner); - var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner); - for (var yC = 0; yC < convInfo.outWidth; ++yC) { - var xCCorner = yC * strideWidth - padLeft; - var xCMin = Math.max(0, xCCorner); - var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner); - var maxValue = Number.NEGATIVE_INFINITY; - var maxPosition = -1; - for (var xR = xRMin; xR < xRMax; ++xR) { - var wR = xR - xRCorner; - for (var xC = xCMin; xC < xCMax; ++xC) { - var wC = xC - xCCorner; - var pixel = x.get(b, xR, xC, d); - if (pixel > maxValue) { - maxValue = pixel; - maxPosition = wR * filterWidth + wC; - } - } - } - maxPositions.set(maxPosition, b, yR, yC, d); - } - } - } - } - return maxPositions.toTensor(); - }; - MathBackendCPU.prototype.maxPoolBackprop = function (dy, x, convInfo) { - var maxPositions = this.maxPoolPositions(x, convInfo); - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var dx = ops.buffer(x.shape, 'float32'); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var dxR = 0; dxR < convInfo.inHeight; ++dxR) { - for (var dxC = 0; dxC < convInfo.inWidth; ++dxC) { - var dyRCorner = dxR - padTop; - var dyCCorner = dxC - padLeft; - var dotProd = 0; - for (var wR = 0; wR < filterHeight; ++wR) { - var dyR = (dyRCorner + wR) / strideHeight; - if (dyR < 0 || dyR >= convInfo.outHeight || - Math.floor(dyR) !== dyR) { - continue; - } - for (var wC = 0; wC < filterWidth; ++wC) { - var dyC = (dyCCorner + wC) / strideWidth; - if (dyC < 0 || dyC >= convInfo.outWidth || - Math.floor(dyC) !== dyC) { - continue; - } - var maxPos = filterHeight * filterWidth - 1 - - maxPositions.get(b, dyR, dyC, d); - var curPos = wR * filterWidth + wC; - var mask = maxPos === curPos ? 1 : 0; - if (mask === 0) { - continue; - } - var pixel = dy.get(b, dyR, dyC, d); - dotProd += pixel * mask; - } - } - dx.set(dotProd, b, dxR, dxC, d); - } - } - } - } - return dx.toTensor(); - }; - MathBackendCPU.prototype.avgPoolBackprop = function (dy, x, convInfo) { - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var dx = ops.buffer(x.shape, 'float32'); - var avgMultiplier = 1 / (filterHeight * filterWidth); - for (var b = 0; b < convInfo.batchSize; ++b) { - for (var d = 0; d < convInfo.inChannels; ++d) { - for (var dxR = 0; dxR < convInfo.inHeight; ++dxR) { - for (var dxC = 0; dxC < convInfo.inWidth; ++dxC) { - var dyRCorner = dxR - padTop; - var dyCCorner = dxC - padLeft; - var dotProd = 0; - for (var wR = 0; wR < filterHeight; ++wR) { - var dyR = (dyRCorner + wR) / strideHeight; - if (dyR < 0 || dyR >= convInfo.outHeight || - Math.floor(dyR) !== dyR) { - continue; - } - for (var wC = 0; wC < filterWidth; ++wC) { - var dyC = (dyCCorner + wC) / strideWidth; - if (dyC < 0 || dyC >= convInfo.outWidth || - Math.floor(dyC) !== dyC) { - continue; - } - var pixel = dy.get(b, dyR, dyC, d); - dotProd += pixel; - } - } - dx.set(dotProd * avgMultiplier, b, dxR, dxC, d); - } - } - } - } - return dx.toTensor(); - }; - MathBackendCPU.prototype.minPool = function (x, convInfo) { - return this.pool(x, convInfo, 'min'); - }; - MathBackendCPU.prototype.avgPool = function (x, convInfo) { - return this.pool(x, convInfo, 'avg').toFloat(); - }; - MathBackendCPU.prototype.resizeBilinear = function (x, newHeight, newWidth, alignCorners) { - var _a = x.shape, batch = _a[0], oldHeight = _a[1], oldWidth = _a[2], numChannels = _a[3]; - var output = ops.buffer([batch, newHeight, newWidth, numChannels], x.dtype); - var effectiveInputSize = alignCorners ? [oldHeight - 1, oldWidth - 1] : [oldHeight, oldWidth]; - var effectiveOutputSize = alignCorners ? [newHeight - 1, newWidth - 1] : [newHeight, newWidth]; - for (var b = 0; b < batch; b++) { - for (var r = 0; r < newHeight; r++) { - for (var c = 0; c < newWidth; c++) { - for (var d = 0; d < numChannels; d++) { - var sourceFracRow = (effectiveInputSize[0]) * r / (effectiveOutputSize[0]); - var sourceFracCol = (effectiveInputSize[1]) * c / (effectiveOutputSize[1]); - var sourceRowFloor = Math.floor(sourceFracRow); - var sourceRowCeil = Math.min(oldHeight - 1, Math.ceil(sourceFracRow)); - var sourceColFloor = Math.floor(sourceFracCol); - var sourceColCeil = Math.min(oldWidth - 1, Math.ceil(sourceFracCol)); - var topLeft = x.get(b, sourceRowFloor, sourceColFloor, d); - var bottomLeft = x.get(b, sourceRowCeil, sourceColFloor, d); - var topRight = x.get(b, sourceRowFloor, sourceColCeil, d); - var bottomRight = x.get(b, sourceRowCeil, sourceColCeil, d); - var rowFrac = sourceFracRow - sourceRowFloor; - var colFrac = sourceFracCol - sourceColFloor; - var top_1 = topLeft + (topRight - topLeft) * colFrac; - var bottom = bottomLeft + (bottomRight - bottomLeft) * colFrac; - var newValue = top_1 + (bottom - top_1) * rowFrac; - output.set(newValue, b, r, c, d); - } - } - } - } - return output.toTensor(); - }; - MathBackendCPU.prototype.batchNormalization4D = function (x, mean, variance, varianceEpsilon, scale, offset) { - var xValues = x.dataSync(); - var meanValues = mean.dataSync(); - var varianceValues = variance.dataSync(); - var scaleValues = scale ? scale.dataSync() : new Float32Array([1]); - var offsetValues = offset ? offset.dataSync() : new Float32Array([0]); - var outValues = new Float32Array(xValues.length); - for (var i = 0; i < xValues.length; i++) { - outValues[i] = offsetValues[i % offsetValues.length] + - (xValues[i] - meanValues[i % meanValues.length]) * - scaleValues[i % scaleValues.length] / - Math.sqrt(varianceValues[i % varianceValues.length] + varianceEpsilon); - } - return ops_1.tensor4d(outValues, x.shape); - }; - MathBackendCPU.prototype.localResponseNormalization4D = function (x, radius, bias, alpha, beta, normRegion) { - var output = ops.buffer(x.shape, 'float32'); - var rad = radius; - var maxW = output.shape[1] - 1; - var maxH = output.shape[2] - 1; - var maxD = output.shape[3] - 1; - var sumAcrossChannels = function (b, r, c, d) { - var sum = 0.0; - for (var j = Math.max(0, d - rad); j <= Math.min(d + rad, maxD); j++) { - var z = x.get(b, r, c, j); - sum += z * z; - } - return sum; - }; - var sumWithinChannel = function (b, r, c, d) { - var sum = 0.0; - for (var u = Math.max(0, r - rad); u <= Math.min(r + rad, maxW); u++) { - for (var v = Math.max(0, c - rad); v <= Math.min(c + rad, maxH); v++) { - sum += Math.pow(x.get(b, u, v, d), 2); - } - } - return sum; - }; - for (var b = 0; b < output.shape[0]; b++) { - for (var r = 0; r <= output.shape[1]; r++) { - for (var c = 0; c < output.shape[2]; c++) { - for (var d = 0; d < output.shape[3]; d++) { - var sum = normRegion === 'withinChannel' ? - sumWithinChannel(b, r, c, d) : - sumAcrossChannels(b, r, c, d); - var val = x.get(b, r, c, d) * Math.pow(bias + alpha * sum, -beta); - output.set(val, b, r, c, d); - } - } - } - } - return output.toTensor(); - }; - MathBackendCPU.prototype.multinomial = function (probabilities, numSamples, seed) { - var batchSize = probabilities.shape[0]; - var numEvents = probabilities.shape[1]; - var res = ops.zeros([batchSize, numSamples], 'int32'); - var resVals = res.dataSync(); - var probVals = probabilities.dataSync(); - for (var b = 0; b < batchSize; ++b) { - var offset = b * numEvents; - var cdf = new Float32Array(numEvents - 1); - cdf[0] = probVals[offset]; - for (var event_1 = 1; event_1 < cdf.length; ++event_1) { - cdf[event_1] = cdf[event_1 - 1] + probVals[offset + event_1]; - } - var random = seedrandom.alea(seed.toString()); - var outOffset = b * numSamples; - for (var sampleId = 0; sampleId < numSamples; ++sampleId) { - var r = random(); - resVals[outOffset + sampleId] = cdf.length; - for (var event_2 = 0; event_2 < cdf.length; event_2++) { - if (r < cdf[event_2]) { - resVals[outOffset + sampleId] = event_2; - break; - } - } - } - } - return res; - }; - MathBackendCPU.prototype.oneHot = function (indices, depth, onValue, offValue) { - var res = new Float32Array(indices.size * depth); - res.fill(offValue); - for (var event_3 = 0; event_3 < indices.size; ++event_3) { - res[event_3 * depth + indices.get(event_3)] = onValue; - } - return ops.tensor2d(res, [indices.size, depth]); - }; - MathBackendCPU.prototype.broadcastedBinaryOp = function (a, b, dtype, op) { - var newShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var result = ops.buffer(newShape, dtype); - var aValues = a.dataSync(); - var bValues = b.dataSync(); - var aBroadcastDims = broadcast_util.getBroadcastDims(a.shape, newShape); - var bBroadcastDims = broadcast_util.getBroadcastDims(b.shape, newShape); - var _loop_1 = function (i) { - var loc = result.indexToLoc(i); - var aLoc = loc.slice(-a.rank); - aBroadcastDims.forEach(function (d) { return aLoc[d] = 0; }); - var aIndex = a.locToIndex(aLoc); - var bLoc = loc.slice(-b.rank); - bBroadcastDims.forEach(function (d) { return bLoc[d] = 0; }); - var bIndex = b.locToIndex(bLoc); - result.values[i] = op(aValues[aIndex], bValues[bIndex]); - }; - for (var i = 0; i < result.values.length; ++i) { - _loop_1(i); - } - return result.toTensor(); - }; - MathBackendCPU.prototype.dispose = function () { }; - return MathBackendCPU; -}()); -exports.MathBackendCPU = MathBackendCPU; -environment_1.ENV.registerBackend('cpu', function () { return new MathBackendCPU(); }); -var NDArrayMathCPU = (function (_super) { - __extends(NDArrayMathCPU, _super); - function NDArrayMathCPU(safeMode) { - if (safeMode === void 0) { safeMode = false; } - var _this = this; - console.warn('new NDArrayMathCPU() is deprecated. Please use ' + - 'dl.setBackend(\'cpu\').'); - _this = _super.call(this, 'cpu', safeMode) || this; - return _this; - } - return NDArrayMathCPU; -}(math_1.NDArrayMath)); -exports.NDArrayMathCPU = NDArrayMathCPU; - -},{"../environment":34,"../math":105,"../ops/axis_util":107,"../ops/broadcast_util":110,"../ops/concat_util":113,"../ops/ops":123,"../ops/selu_util":129,"../tensor":146,"../types":150,"../util":151,"seedrandom":153}],69:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var math_1 = require("../math"); -var axis_util = require("../ops/axis_util"); -var reduce_util = require("../ops/reduce_util"); -var tensor_1 = require("../tensor"); -var types = require("../types"); -var util = require("../util"); -var argminmax_gpu_1 = require("./webgl/argminmax_gpu"); -var avg_pool_backprop_gpu_1 = require("./webgl/avg_pool_backprop_gpu"); -var batchnorm_gpu_1 = require("./webgl/batchnorm_gpu"); -var binaryop_gpu = require("./webgl/binaryop_gpu"); -var binaryop_gpu_1 = require("./webgl/binaryop_gpu"); -var clip_gpu_1 = require("./webgl/clip_gpu"); -var concat_gpu_1 = require("./webgl/concat_gpu"); -var conv_backprop_gpu_1 = require("./webgl/conv_backprop_gpu"); -var conv_gpu_1 = require("./webgl/conv_gpu"); -var conv_gpu_depthwise_1 = require("./webgl/conv_gpu_depthwise"); -var from_pixels_gpu_1 = require("./webgl/from_pixels_gpu"); -var gather_gpu_1 = require("./webgl/gather_gpu"); -var gpgpu_context_1 = require("./webgl/gpgpu_context"); -var gpgpu_math = require("./webgl/gpgpu_math"); -var logical_gpu_1 = require("./webgl/logical_gpu"); -var lrn_gpu_1 = require("./webgl/lrn_gpu"); -var max_pool_backprop_gpu_1 = require("./webgl/max_pool_backprop_gpu"); -var mulmat_gpu_1 = require("./webgl/mulmat_gpu"); -var multinomial_gpu_1 = require("./webgl/multinomial_gpu"); -var onehot_gpu_1 = require("./webgl/onehot_gpu"); -var pad_gpu_1 = require("./webgl/pad_gpu"); -var pool_gpu_1 = require("./webgl/pool_gpu"); -var reduce_gpu_1 = require("./webgl/reduce_gpu"); -var resize_bilinear_gpu_1 = require("./webgl/resize_bilinear_gpu"); -var reverse_gpu_1 = require("./webgl/reverse_gpu"); -var slice_gpu_1 = require("./webgl/slice_gpu"); -var tex_util_1 = require("./webgl/tex_util"); -var texture_manager_1 = require("./webgl/texture_manager"); -var tile_gpu_1 = require("./webgl/tile_gpu"); -var transpose_gpu_1 = require("./webgl/transpose_gpu"); -var unary_op = require("./webgl/unaryop_gpu"); -var unaryop_gpu_1 = require("./webgl/unaryop_gpu"); -var webgl_util = require("./webgl/webgl_util"); -var MathBackendWebGL = (function () { - function MathBackendWebGL(gpgpu, delayedStorage) { - if (delayedStorage === void 0) { delayedStorage = true; } - this.gpgpu = gpgpu; - this.delayedStorage = delayedStorage; - this.texData = new WeakMap(); - this.uploadWaitMs = 0; - this.downloadWaitMs = 0; - this.binaryCache = {}; - this.disposed = false; - if (environment_1.ENV.get('WEBGL_VERSION') < 1) { - throw new Error('WebGL is not supported on this device'); - } - if (gpgpu == null) { - this.gpgpu = new gpgpu_context_1.GPGPUContext(); - this.gpgpuCreatedLocally = true; - } - else { - this.gpgpuCreatedLocally = false; - } - if (typeof document !== 'undefined') { - this.canvas = document.createElement('canvas'); - } - this.textureManager = new texture_manager_1.TextureManager(this.gpgpu); - } - MathBackendWebGL.prototype.register = function (dataId, shape, dtype) { - if (this.texData.has(dataId)) { - throw new Error('Data buffer is already registered'); - } - this.texData.set(dataId, { - shape: shape, - dtype: dtype, - values: null, - texture: null, - texShape: null, - texType: tex_util_1.TextureType.FLOAT - }); - }; - MathBackendWebGL.prototype.fromPixels = function (pixels, numChannels) { - if (pixels == null) { - throw new Error('MathBackendWebGL.writePixels(): pixels can not be null'); - } - var texShape = [pixels.height, pixels.width]; - var outShape = [pixels.height, pixels.width, numChannels]; - if (pixels instanceof HTMLVideoElement) { - if (this.canvas == null) { - throw new Error('Can\'t read pixels from HTMLImageElement outside ' + - 'the browser.'); - } - this.canvas.width = pixels.width; - this.canvas.height = pixels.height; - this.canvas.getContext('2d').drawImage(pixels, 0, 0, pixels.width, pixels.height); - pixels = this.canvas; - } - var tempPixelArray = tensor_1.Tensor.make(texShape, {}, 'int32'); - this.texData.get(tempPixelArray.dataId).texType = tex_util_1.TextureType.UNSIGNED_BYTE; - this.gpgpu.uploadPixelDataToTexture(this.getTexture(tempPixelArray.dataId), pixels); - var program = new from_pixels_gpu_1.FromPixelsProgram(outShape); - var res = this.compileAndRun(program, [tempPixelArray]); - tempPixelArray.dispose(); - return res; - }; - MathBackendWebGL.prototype.write = function (dataId, values) { - if (values == null) { - throw new Error('MathBackendWebGL.write(): values can not be null'); - } - this.throwIfNoData(dataId); - var texData = this.texData.get(dataId); - var texture = texData.texture, texShape = texData.texShape, texType = texData.texType; - if (texture != null) { - this.textureManager.releaseTexture(texture, texShape, texType); - texData.texture = null; - texData.texShape = null; - } - texData.values = values; - if (!this.delayedStorage) { - this.uploadToGPU(dataId); - } - }; - MathBackendWebGL.prototype.readSync = function (dataId) { - this.throwIfNoData(dataId); - var texData = this.texData.get(dataId); - var texture = texData.texture, values = texData.values, texShape = texData.texShape; - if (values != null) { - this.cacheOnCPU(dataId); - return values; - } - var shouldTimeProgram = this.activeTimers != null; - var start; - if (shouldTimeProgram) { - start = performance.now(); - } - var float32Values = this.gpgpu.downloadMatrixFromTexture(texture, texShape[0], texShape[1]); - if (shouldTimeProgram) { - this.downloadWaitMs += performance.now() - start; - } - this.cacheOnCPU(dataId, float32Values); - return texData.values; - }; - MathBackendWebGL.prototype.read = function (dataId) { - return __awaiter(this, void 0, void 0, function () { - var texData, texture, values, texShape, float32Values; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.throwIfNoData(dataId); - texData = this.texData.get(dataId); - texture = texData.texture, values = texData.values, texShape = texData.texShape; - if (values != null) { - this.cacheOnCPU(dataId); - return [2, values]; - } - if (!environment_1.ENV.get('WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED')) return [3, 2]; - return [4, this.gpgpu.downloadMatrixFromTextureAsync(texture, texShape[0], texShape[1])]; - case 1: - float32Values = _a.sent(); - this.cacheOnCPU(dataId, float32Values); - return [2, texData.values]; - case 2: - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 0) { - return [2, this.readSync(dataId)]; - } - return [4, this.gpgpu.runQuery(function () { })]; - case 3: - _a.sent(); - return [2, this.readSync(dataId)]; - } - }); - }); - }; - MathBackendWebGL.prototype.time = function (f) { - return __awaiter(this, void 0, void 0, function () { - var oldActiveTimers, newActiveTimers, outerMostTime, flattenedActiveTimers, kernelMs, res; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - oldActiveTimers = this.activeTimers; - newActiveTimers = []; - outerMostTime = false; - if (this.programTimersStack == null) { - this.programTimersStack = newActiveTimers; - outerMostTime = true; - } - else { - this.activeTimers.push(newActiveTimers); - } - this.activeTimers = newActiveTimers; - f(); - flattenedActiveTimers = util.flatten(this.activeTimers); - this.activeTimers = oldActiveTimers; - if (outerMostTime) { - this.programTimersStack = null; - } - return [4, Promise.all(flattenedActiveTimers).then(function (results) { - var sum = 0; - results.forEach(function (result) { return sum += result; }); - return sum; - })]; - case 1: - kernelMs = _a.sent(); - res = { - uploadWaitMs: this.uploadWaitMs, - downloadWaitMs: this.downloadWaitMs, - kernelMs: kernelMs, - wallMs: null - }; - this.uploadWaitMs = 0; - this.downloadWaitMs = 0; - return [2, res]; - } - }); - }); - }; - MathBackendWebGL.prototype.memory = function () { - return { unreliable: false }; - }; - MathBackendWebGL.prototype.startTimer = function () { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) { - return this.gpgpu.beginQuery(); - } - return { startMs: performance.now(), endMs: null }; - }; - MathBackendWebGL.prototype.endTimer = function (query) { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) { - this.gpgpu.endQuery(); - return query; - } - query.endMs = performance.now(); - return query; - }; - MathBackendWebGL.prototype.getQueryTime = function (query) { - return __awaiter(this, void 0, void 0, function () { - var timerQuery; - return __generator(this, function (_a) { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) { - return [2, this.gpgpu.pollQueryTime(query)]; - } - timerQuery = query; - return [2, timerQuery.endMs - timerQuery.startMs]; - }); - }); - }; - MathBackendWebGL.prototype.disposeData = function (dataId) { - if (this.texData.has(dataId)) { - var _a = this.texData.get(dataId), texture = _a.texture, texShape = _a.texShape, texType = _a.texType; - if (texture != null) { - this.textureManager.releaseTexture(texture, texShape, texType); - } - this.texData.delete(dataId); - } - }; - MathBackendWebGL.prototype.getTexture = function (dataId) { - this.uploadToGPU(dataId); - return this.texData.get(dataId).texture; - }; - MathBackendWebGL.prototype.getTextureData = function (dataId) { - this.uploadToGPU(dataId); - return this.texData.get(dataId); - }; - MathBackendWebGL.prototype.getGPGPUContext = function () { - return this.gpgpu; - }; - MathBackendWebGL.prototype.slice1D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram([size]); - var customSetup = program.getCustomSetupFunc([begin]); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.slice2D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram(size); - var customSetup = program.getCustomSetupFunc(begin); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.slice3D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram(size); - var customSetup = program.getCustomSetupFunc(begin); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.slice4D = function (x, begin, size) { - var program = new slice_gpu_1.SliceProgram(size); - var customSetup = program.getCustomSetupFunc(begin); - return this.compileAndRun(program, [x], null, customSetup); - }; - MathBackendWebGL.prototype.reverse4D = function (x, axis) { - var program = new reverse_gpu_1.ReverseProgram(x.shape, axis); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.concat = function (a, b) { - var program = new concat_gpu_1.ConcatProgram(a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.neg = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.NEG); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.matMul = function (a, b, transposeA, transposeB) { - var program = new mulmat_gpu_1.MatMulProgram(a.shape, b.shape, transposeA, transposeB); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.multiply = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MUL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.batchNormalization4D = function (x, mean, variance, varianceEpsilon, scale, offset) { - var inputs = [x, mean, variance]; - var offsetShape = null; - if (offset != null) { - offsetShape = offset.shape; - inputs.push(offset); - } - var scaleShape = null; - if (scale != null) { - scaleShape = scale.shape; - inputs.push(scale); - } - var program = new batchnorm_gpu_1.BatchNormProgram(x.shape, mean.shape, variance.shape, offsetShape, scaleShape, varianceEpsilon); - return this.compileAndRun(program, inputs); - }; - MathBackendWebGL.prototype.localResponseNormalization4D = function (x, radius, bias, alpha, beta, normRegion) { - var program = new lrn_gpu_1.LRNProgram(x.shape, radius, bias, alpha, beta, normRegion); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.tile = function (x, reps) { - var program = new tile_gpu_1.TileProgram(x.shape, reps); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.pad1D = function (x, paddings, constantValue) { - var program = new pad_gpu_1.Pad1DProgram(x.shape, paddings, constantValue); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.pad2D = function (x, paddings, constantValue) { - var program = new pad_gpu_1.Pad2DProgram(x.shape, paddings, constantValue); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.transpose = function (x, perm) { - var program = new transpose_gpu_1.TransposeProgram(x.shape, perm); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.gather = function (x, indices, axis) { - var program = new gather_gpu_1.GatherProgram(x.shape, indices.size, axis); - return this.compileAndRun(program, [x, indices]); - }; - MathBackendWebGL.prototype.reduce = function (x, reduceType, dtype) { - var batchSize = x.shape[0]; - var inSize = x.shape[1]; - var windowSize = reduce_util.computeOptimalWindowSize(inSize); - var reduceInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize }; - var program = new reduce_gpu_1.ReduceProgram(reduceInfo, reduceType); - var _a = program.outputShape, rows = _a[0], cols = _a[1]; - var output = this.makeOutputArray([rows, cols], dtype); - this.compileAndRun(program, [x], output); - if (output.shape[1] === 1) { - return output; - } - return this.reduce(output, reduceType, dtype); - }; - MathBackendWebGL.prototype.argReduce = function (x, reduceType, bestIndicesA) { - if (bestIndicesA === void 0) { bestIndicesA = null; } - var batchSize = x.shape[0]; - var inSize = x.shape[1]; - if (bestIndicesA != null) { - batchSize = bestIndicesA.shape[0]; - inSize = bestIndicesA.shape[1]; - } - var windowSize = reduce_util.computeOptimalWindowSize(inSize); - var reduceInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize }; - var program = new argminmax_gpu_1.ArgMinMaxProgram(reduceInfo, reduceType, bestIndicesA == null); - var _a = program.outputShape, rows = _a[0], cols = _a[1]; - var output = this.makeOutputArray([rows, cols], 'int32'); - var inputs = [x]; - if (bestIndicesA != null) { - inputs.push(bestIndicesA); - } - this.compileAndRun(program, inputs, output); - if (output.shape[1] === 1) { - return output; - } - return this.argReduce(x, reduceType, output); - }; - MathBackendWebGL.prototype.sum = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('sum', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - var outputDType = types.sumOutType(x.dtype); - return this.reduce(a2D, 'sum', outputDType).reshape(outShape); - }; - MathBackendWebGL.prototype.argMin = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMin', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.argReduce(a2D, 'min').reshape(outShape); - }; - MathBackendWebGL.prototype.argMax = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('argMax', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.argReduce(a2D, 'max').reshape(outShape); - }; - MathBackendWebGL.prototype.equal = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.notEqual = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.NOT_EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.less = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LESS, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.lessEqual = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LESS_EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.greater = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.GREATER, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.greaterEqual = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.GREATER_EQUAL, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.logicalNot = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOGICAL_NOT); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.logicalAnd = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_AND, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.logicalOr = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_OR, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.logicalXor = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_XOR, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'bool'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.where = function (condition, a, b, dtype) { - var program = new logical_gpu_1.WhereProgram(condition.rank, a.shape, a.rank); - var output = this.makeOutputArray(program.outputShape, dtype); - return this.compileAndRun(program, [condition, a, b], output); - }; - MathBackendWebGL.prototype.topKValues = function (x, k) { - throw new Error('topKValues GPU not yet implemented!'); - }; - MathBackendWebGL.prototype.topKIndices = function (x, k) { - throw new Error('topKIndices GPU not yet implemented!'); - }; - MathBackendWebGL.prototype.min = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('min', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.reduce(a2D, 'min', a2D.dtype).reshape(outShape); - }; - MathBackendWebGL.prototype.minimum = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MIN, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.max = function (x, axes) { - axis_util.assertAxesAreInnerMostDims('max', axes, x.rank); - var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1]; - var inSize = util.sizeFromShape(reduceShape); - var a2D = x.as2D(-1, inSize); - return this.reduce(a2D, 'max', a2D.dtype).reshape(outShape); - }; - MathBackendWebGL.prototype.maximum = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MAX, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.divide = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.DIV, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, 'float32'); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.add = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.ADD, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.subtract = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.SUB, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.pow = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.POW, a.shape, b.shape); - var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype)); - return this.compileAndRun(program, [a, b], output); - }; - MathBackendWebGL.prototype.ceil = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.CEIL); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.floor = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.FLOOR); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.exp = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.EXP); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.log = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOG); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sqrt = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SQRT); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.square = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SQUARE); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.relu = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.RELU); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.elu = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ELU); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.eluDer = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ELU_DER); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.selu = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SELU); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.leakyRelu = function (x, alpha) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LEAKY_RELU(alpha)); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.prelu = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.PRELU, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.preluDer = function (a, b) { - var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.PRELU_DER, a.shape, b.shape); - return this.compileAndRun(program, [a, b]); - }; - MathBackendWebGL.prototype.int = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TO_INT); - var output = this.makeOutputArray(program.outputShape, 'int32'); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.clip = function (x, min, max) { - var program = new clip_gpu_1.ClipProgram(x.shape, min, max); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.abs = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ABS); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sigmoid = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIGMOID); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sin = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.cos = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.COS); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.tan = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TAN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.asin = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ASIN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.acos = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ACOS); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.atan = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ATAN); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.sinh = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SINH); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.cosh = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.COSH); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.tanh = function (x) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TANH); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.step = function (x, alpha) { - var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.STEP(alpha)); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.conv2d = function (x, filter, convInfo) { - var program = new conv_gpu_1.Conv2DProgram(convInfo); - return this.compileAndRun(program, [x, filter]); - }; - MathBackendWebGL.prototype.conv2dDerInput = function (dy, filter, convInfo) { - var program = new conv_backprop_gpu_1.Conv2DDerInputProgram(convInfo); - return this.compileAndRun(program, [dy, filter]); - }; - MathBackendWebGL.prototype.conv2dDerFilter = function (x, dy, convInfo) { - var program = new conv_backprop_gpu_1.Conv2DDerFilterProgram(convInfo); - return this.compileAndRun(program, [x, dy]); - }; - MathBackendWebGL.prototype.depthwiseConv2D = function (x, filter, convInfo) { - var program = new conv_gpu_depthwise_1.DepthwiseConv2DProgram(convInfo); - return this.compileAndRun(program, [x, filter]); - }; - MathBackendWebGL.prototype.maxPool = function (x, convInfo) { - var program = new pool_gpu_1.Pool2DProgram(convInfo, 'max', false); - var output = this.makeOutputArray(program.outputShape, x.dtype); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.minPool = function (x, convInfo) { - var program = new pool_gpu_1.Pool2DProgram(convInfo, 'min', false); - var output = this.makeOutputArray(program.outputShape, x.dtype); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.avgPool = function (x, convInfo) { - var program = new pool_gpu_1.Pool2DProgram(convInfo, 'avg', false); - var output = this.makeOutputArray(program.outputShape, 'float32'); - return this.compileAndRun(program, [x], output); - }; - MathBackendWebGL.prototype.maxPoolBackprop = function (dy, x, convInfo) { - var getPositions = true; - var maxPoolPositionsProgram = new pool_gpu_1.Pool2DProgram(convInfo, 'max', getPositions); - var maxPoolPositions = this.compileAndRun(maxPoolPositionsProgram, [x]); - var maxPoolBackPropProgram = new max_pool_backprop_gpu_1.MaxPool2DBackpropProgram(convInfo); - var output = this.makeOutputArray(maxPoolBackPropProgram.outputShape, x.dtype); - var result = this.compileAndRun(maxPoolBackPropProgram, [dy, maxPoolPositions], output); - maxPoolPositions.dispose(); - return result; - }; - MathBackendWebGL.prototype.avgPoolBackprop = function (dy, x, convInfo) { - var avgPoolBackpropProgram = new avg_pool_backprop_gpu_1.AvgPool2DBackpropProgram(convInfo); - var output = this.makeOutputArray(avgPoolBackpropProgram.outputShape, x.dtype); - return this.compileAndRun(avgPoolBackpropProgram, [dy], output); - }; - MathBackendWebGL.prototype.resizeBilinear = function (x, newHeight, newWidth, alignCorners) { - var program = new resize_bilinear_gpu_1.ResizeBilinearProgram(x.shape, newHeight, newWidth, alignCorners); - return this.compileAndRun(program, [x]); - }; - MathBackendWebGL.prototype.multinomial = function (probs, numSamples, seed) { - var batchSize = probs.shape[0]; - var numOutcomes = probs.shape[1]; - var program = new multinomial_gpu_1.MultinomialProgram(batchSize, numOutcomes, numSamples); - var output = this.makeOutputArray(program.outputShape, 'int32'); - var customSetup = program.getCustomSetupFunc(seed); - return this.compileAndRun(program, [probs], output, customSetup); - }; - MathBackendWebGL.prototype.oneHot = function (indices, depth, onValue, offValue) { - var program = new onehot_gpu_1.OneHotProgram(indices.size, depth, onValue, offValue); - return this.compileAndRun(program, [indices]); - }; - MathBackendWebGL.prototype.makeOutputArray = function (shape, dtype) { - return tensor_1.Tensor.make(shape, {}, dtype); - }; - MathBackendWebGL.prototype.compileAndRun = function (program, inputs, output, customSetup) { - var _this = this; - if (output == null) { - output = this.makeOutputArray(program.outputShape, inputs[0].dtype); - } - var inputsData = inputs.map(function (input) { - _this.uploadToGPU(input.dataId); - return { tensor: input, texData: _this.texData.get(input.dataId) }; - }); - this.uploadToGPU(output.dataId); - var outputData = { - tensor: output, - texData: this.texData.get(output.dataId) - }; - var key = gpgpu_math.makeShaderKey(program, inputsData, outputData); - var binary = this.getAndSaveBinary(key, function () { - return gpgpu_math.compileProgram(_this.gpgpu, program, inputsData, outputData); - }); - var shouldTimeProgram = this.activeTimers != null; - var query; - if (shouldTimeProgram) { - query = this.startTimer(); - } - gpgpu_math.runProgram(binary, inputsData, outputData, customSetup); - if (shouldTimeProgram) { - query = this.endTimer(query); - this.activeTimers.push(this.getQueryTime(query)); - } - return output; - }; - MathBackendWebGL.prototype.getAndSaveBinary = function (key, getBinary) { - if (!(key in this.binaryCache)) { - this.binaryCache[key] = getBinary(); - } - return this.binaryCache[key]; - }; - MathBackendWebGL.prototype.getTextureManager = function () { - return this.textureManager; - }; - MathBackendWebGL.prototype.dispose = function () { - if (this.disposed) { - return; - } - for (var key in this.binaryCache) { - this.gpgpu.deleteProgram(this.binaryCache[key].webGLProgram); - } - this.textureManager.dispose(); - this.canvas.remove(); - if (this.gpgpuCreatedLocally) { - this.gpgpu.dispose(); - } - this.disposed = true; - }; - MathBackendWebGL.prototype.throwIfNoData = function (dataId) { - if (!this.texData.has(dataId)) { - throw new Error("WebGL backend: No data found for this tensor. " + - "Did you change your backend in the middle of the program? " + - "New backends can't use Tensors created with previous backends"); - } - }; - MathBackendWebGL.prototype.uploadToGPU = function (dataId) { - this.throwIfNoData(dataId); - var texData = this.texData.get(dataId); - var shape = texData.shape, values = texData.values, texture = texData.texture, dtype = texData.dtype, texType = texData.texType; - if (texture != null) { - return; - } - var shouldTimeProgram = this.activeTimers != null; - var start; - if (shouldTimeProgram) { - start = performance.now(); - } - var texShape = webgl_util.getTextureShapeFromLogicalShape(this.gpgpu.gl, shape); - texData.texShape = texShape; - var newTexture = this.textureManager.acquireTexture(texShape, texType); - texData.texture = newTexture; - if (values != null) { - this.gpgpu.uploadMatrixToTexture(newTexture, texShape[0], texShape[1], typedArrayToFloat32(values, dtype)); - texData.values = null; - if (shouldTimeProgram) { - this.uploadWaitMs += performance.now() - start; - } - } - }; - MathBackendWebGL.prototype.cacheOnCPU = function (dataId, float32Values) { - var dontKeepCopyOnGPU = this.delayedStorage; - var texData = this.texData.get(dataId); - var texture = texData.texture, texShape = texData.texShape, dtype = texData.dtype, texType = texData.texType; - if (dontKeepCopyOnGPU && texture != null) { - this.textureManager.releaseTexture(texture, texShape, texType); - texData.texture = null; - texData.texShape = null; - } - if (float32Values != null) { - texData.values = float32ToTypedArray(float32Values, dtype); - } - }; - return MathBackendWebGL; -}()); -exports.MathBackendWebGL = MathBackendWebGL; -environment_1.ENV.registerBackend('webgl', function () { return new MathBackendWebGL(); }); -var NDArrayMathGPU = (function (_super) { - __extends(NDArrayMathGPU, _super); - function NDArrayMathGPU(gpgpu, safeMode) { - if (safeMode === void 0) { safeMode = false; } - var _this = this; - console.warn('new NDArrayMathGPU() is deprecated. Please use ' + - 'dl.setBackend(\'webgl\').'); - _this = _super.call(this, new MathBackendWebGL(gpgpu), safeMode) || this; - return _this; - } - NDArrayMathGPU.prototype.getGPGPUContext = function () { - return this.engine.backend.getGPGPUContext(); - }; - NDArrayMathGPU.prototype.getTextureManager = function () { - return this.engine.backend.getTextureManager(); - }; - return NDArrayMathGPU; -}(math_1.NDArrayMath)); -exports.NDArrayMathGPU = NDArrayMathGPU; -function float32ToTypedArray(a, dtype) { - if (dtype === 'float32') { - return a; - } - else if (dtype === 'int32' || dtype === 'bool') { - var result = (dtype === 'int32') ? new Int32Array(a.length) : - new Uint8Array(a.length); - for (var i = 0; i < result.length; ++i) { - var val = a[i]; - val = isNaN(val) ? util.getNaN(dtype) : Math.round(val); - result[i] = val; - } - return result; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -function typedArrayToFloat32(a, dtype) { - if (a instanceof Float32Array) { - return a; - } - else { - var res = new Float32Array(a.length); - for (var i = 0; i < res.length; i++) { - var val = a[i]; - res[i] = util.isValNaN(val, dtype) ? NaN : val; - } - return res; - } -} - -},{"../environment":34,"../math":105,"../ops/axis_util":107,"../ops/reduce_util":126,"../tensor":146,"../types":150,"../util":151,"./webgl/argminmax_gpu":72,"./webgl/avg_pool_backprop_gpu":73,"./webgl/batchnorm_gpu":74,"./webgl/binaryop_gpu":75,"./webgl/clip_gpu":76,"./webgl/concat_gpu":77,"./webgl/conv_backprop_gpu":78,"./webgl/conv_gpu":79,"./webgl/conv_gpu_depthwise":80,"./webgl/from_pixels_gpu":81,"./webgl/gather_gpu":82,"./webgl/gpgpu_context":83,"./webgl/gpgpu_math":84,"./webgl/logical_gpu":86,"./webgl/lrn_gpu":87,"./webgl/max_pool_backprop_gpu":88,"./webgl/mulmat_gpu":89,"./webgl/multinomial_gpu":90,"./webgl/onehot_gpu":91,"./webgl/pad_gpu":92,"./webgl/pool_gpu":93,"./webgl/reduce_gpu":94,"./webgl/resize_bilinear_gpu":95,"./webgl/reverse_gpu":96,"./webgl/slice_gpu":98,"./webgl/tex_util":99,"./webgl/texture_manager":100,"./webgl/tile_gpu":101,"./webgl/transpose_gpu":102,"./webgl/unaryop_gpu":103,"./webgl/webgl_util":104}],70:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ops = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -function executeKernel(backend, kernelName, inputAndArgs) { - if (kernelName === 'MatMul') { - var config = inputAndArgs; - return backend.matMul(config.inputs.a, config.inputs.b, config.args.transposeA, config.args.transposeB); - } - else if (kernelName === 'Slice1D') { - var config = inputAndArgs; - return backend.slice1D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Slice2D') { - var config = inputAndArgs; - return backend.slice2D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Slice3D') { - var config = inputAndArgs; - return backend.slice3D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Slice4D') { - var config = inputAndArgs; - return backend.slice4D(config.inputs.x, config.args.begin, config.args.size); - } - else if (kernelName === 'Reverse4D') { - var config = inputAndArgs; - return backend.reverse4D(config.inputs.x, config.args.axis); - } - else if (kernelName === 'Concat') { - var config = inputAndArgs; - return backend.concat(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Neg') { - var config = inputAndArgs; - return backend.neg(config.inputs.x); - } - else if (kernelName === 'Add') { - var config = inputAndArgs; - return backend.add(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Sub') { - var config = inputAndArgs; - return backend.subtract(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Mul') { - var config = inputAndArgs; - return backend.multiply(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Div') { - var config = inputAndArgs; - return backend.divide(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Sum') { - var config = inputAndArgs; - return backend.sum(config.inputs.x, config.args.axes); - } - else if (kernelName === 'ArgMax') { - var config = inputAndArgs; - return backend.argMax(config.inputs.x, config.args.axes); - } - else if (kernelName === 'ArgMin') { - var config = inputAndArgs; - return backend.argMin(config.inputs.x, config.args.axes); - } - else if (kernelName === 'Equal') { - var config = inputAndArgs; - return backend.equal(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'NotEqual') { - var config = inputAndArgs; - return backend.notEqual(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Less') { - var config = inputAndArgs; - return backend.less(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LessEqual') { - var config = inputAndArgs; - return backend.lessEqual(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Greater') { - var config = inputAndArgs; - return backend.greater(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'GreaterEqual') { - var config = inputAndArgs; - return backend.greaterEqual(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LogicalNot') { - var config = inputAndArgs; - return backend.logicalNot(config.inputs.x); - } - else if (kernelName === 'LogicalAnd') { - var config = inputAndArgs; - return backend.logicalAnd(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LogicalOr') { - var config = inputAndArgs; - return backend.logicalOr(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'LogicalXor') { - var config = inputAndArgs; - return backend.logicalXor(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Where') { - var config = inputAndArgs; - return backend.where(config.inputs.condition, config.inputs.a, config.inputs.b, config.args.dtype); - } - else if (kernelName === 'TopKValues') { - var config = inputAndArgs; - return backend.topKValues(config.inputs.x, config.args.k); - } - else if (kernelName === 'TopKIndices') { - var config = inputAndArgs; - return backend.topKIndices(config.inputs.x, config.args.k); - } - else if (kernelName === 'Min') { - var config = inputAndArgs; - return backend.min(config.inputs.x, config.args.axes); - } - else if (kernelName === 'Minimum') { - var config = inputAndArgs; - return backend.minimum(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Max') { - var config = inputAndArgs; - return backend.max(config.inputs.x, config.args.axes); - } - else if (kernelName === 'Maximum') { - var config = inputAndArgs; - return backend.maximum(config.inputs.a, config.inputs.b); - } - else if (kernelName === 'Ceil') { - var config = inputAndArgs; - return backend.ceil(config.inputs.x); - } - else if (kernelName === 'Floor') { - var config = inputAndArgs; - return backend.floor(config.inputs.x); - } - else if (kernelName === 'Pow') { - var config = inputAndArgs; - return backend.pow(config.inputs.base, config.inputs.exp); - } - else if (kernelName === 'Exp') { - var config = inputAndArgs; - return backend.exp(config.inputs.x); - } - else if (kernelName === 'Log') { - var config = inputAndArgs; - return backend.log(config.inputs.x); - } - else if (kernelName === 'Sqrt') { - var config = inputAndArgs; - return backend.sqrt(config.inputs.x); - } - else if (kernelName === 'Square') { - var config = inputAndArgs; - return backend.square(config.inputs.x); - } - else if (kernelName === 'Relu') { - var config = inputAndArgs; - return backend.relu(config.inputs.x); - } - else if (kernelName === 'Reshape') { - var config = inputAndArgs; - var x = config.inputs.x; - var newShape = config.args.newShape; - return tensor_1.Tensor.make(newShape, { dataId: x.dataId }, x.dtype); - } - else if (kernelName === 'Cast') { - var config = inputAndArgs; - var x = config.inputs.x; - var newDType = config.args.newDType; - if (!util.hasEncodingLoss(x.dtype, newDType)) { - return tensor_1.Tensor.make(x.shape, { dataId: x.dataId }, newDType); - } - if (newDType === 'int32') { - return backend.int(x); - } - else if (newDType === 'bool') { - return backend.notEqual(x, ops.scalar(0, x.dtype)); - } - else { - throw new Error("Error in Cast: unknown dtype argument (" + newDType + ")"); - } - } - else if (kernelName === 'LeakyRelu') { - var config = inputAndArgs; - return backend.leakyRelu(config.inputs.x, config.args.alpha); - } - else if (kernelName === 'PReLU') { - var config = inputAndArgs; - return backend.prelu(config.inputs.x, config.inputs.alpha); - } - else if (kernelName === 'PReLUDer') { - var config = inputAndArgs; - return backend.preluDer(config.inputs.x, config.inputs.alpha); - } - else if (kernelName === 'Elu') { - var config = inputAndArgs; - return backend.elu(config.inputs.x); - } - else if (kernelName === 'EluDer') { - var config = inputAndArgs; - return backend.eluDer(config.inputs.x); - } - else if (kernelName === 'Selu') { - var config = inputAndArgs; - return backend.selu(config.inputs.x); - } - else if (kernelName === 'Abs') { - var config = inputAndArgs; - return backend.abs(config.inputs.x); - } - else if (kernelName === 'Sigmoid') { - var config = inputAndArgs; - return backend.sigmoid(config.inputs.x); - } - else if (kernelName === 'Step') { - var config = inputAndArgs; - return backend.step(config.inputs.x, config.args.alpha); - } - else if (kernelName === 'Sin') { - var config = inputAndArgs; - return backend.sin(config.inputs.x); - } - else if (kernelName === 'Cos') { - var config = inputAndArgs; - return backend.cos(config.inputs.x); - } - else if (kernelName === 'Tan') { - var config = inputAndArgs; - return backend.tan(config.inputs.x); - } - else if (kernelName === 'Asin') { - var config = inputAndArgs; - return backend.asin(config.inputs.x); - } - else if (kernelName === 'Acos') { - var config = inputAndArgs; - return backend.acos(config.inputs.x); - } - else if (kernelName === 'Atan') { - var config = inputAndArgs; - return backend.atan(config.inputs.x); - } - else if (kernelName === 'Sinh') { - var config = inputAndArgs; - return backend.sinh(config.inputs.x); - } - else if (kernelName === 'Cosh') { - var config = inputAndArgs; - return backend.cosh(config.inputs.x); - } - else if (kernelName === 'Tanh') { - var config = inputAndArgs; - return backend.tanh(config.inputs.x); - } - else if (kernelName === 'Clip') { - var config = inputAndArgs; - return backend.clip(config.inputs.x, config.args.min, config.args.max); - } - else if (kernelName === 'Tile') { - var config = inputAndArgs; - return backend.tile(config.inputs.x, config.args.reps); - } - else if (kernelName === 'Gather') { - var config = inputAndArgs; - return backend.gather(config.inputs.x, config.inputs.indices, config.args.axis); - } - else if (kernelName === 'Pad1D') { - var config = inputAndArgs; - return backend.pad1D(config.inputs.x, config.args.paddings, config.args.constantValue); - } - else if (kernelName === 'Pad2D') { - var config = inputAndArgs; - return backend.pad2D(config.inputs.x, config.args.paddings, config.args.constantValue); - } - else if (kernelName === 'Transpose') { - var config = inputAndArgs; - return backend.transpose(config.inputs.x, config.args.perm); - } - else if (kernelName === 'Conv2D') { - var config = inputAndArgs; - return backend.conv2d(config.inputs.x, config.inputs.filter, config.args.convInfo); - } - else if (kernelName === 'Conv2DDerInput') { - var config = inputAndArgs; - return backend.conv2dDerInput(config.inputs.dy, config.inputs.filter, config.args.convInfo); - } - else if (kernelName === 'Conv2DDerFilter') { - var config = inputAndArgs; - return backend.conv2dDerFilter(config.inputs.x, config.inputs.dy, config.args.convInfo); - } - else if (kernelName === 'DepthwiseConv2D') { - var config = inputAndArgs; - return backend.depthwiseConv2D(config.inputs.x, config.inputs.filter, config.args.convInfo); - } - else if (kernelName === 'MaxPool') { - var config = inputAndArgs; - return backend.maxPool(config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'MaxPoolBackprop') { - var config = inputAndArgs; - return backend.maxPoolBackprop(config.inputs.dy, config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'AvgPool') { - var config = inputAndArgs; - return backend.avgPool(config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'AvgPoolBackprop') { - var config = inputAndArgs; - return backend.avgPoolBackprop(config.inputs.dy, config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'MinPool') { - var config = inputAndArgs; - return backend.minPool(config.inputs.x, config.args.convInfo); - } - else if (kernelName === 'ResizeBilinear') { - var config = inputAndArgs; - return backend.resizeBilinear(config.inputs.x, config.args.newHeight, config.args.newWidth, config.args.alignCorners); - } - else if (kernelName === 'BatchNorm4D') { - var config = inputAndArgs; - return backend.batchNormalization4D(config.inputs.x, config.inputs.mean, config.inputs.variance, config.args.varianceEpsilon, config.inputs.scale, config.inputs.offset); - } - else if (kernelName === 'LRN4D') { - var config = inputAndArgs; - return backend.localResponseNormalization4D(config.inputs.x, config.args.radius, config.args.bias, config.args.alpha, config.args.beta, config.args.normRegion); - } - else if (kernelName === 'Multinomial') { - var config = inputAndArgs; - return backend.multinomial(config.inputs.probs, config.args.numSamples, config.args.seed); - } - else if (kernelName === 'OneHot') { - var config = inputAndArgs; - return backend.oneHot(config.inputs.indices, config.args.depth, config.args.onValue, config.args.offValue); - } - throw new Error("No backend method found for kernel " + kernelName); -} -exports.executeKernel = executeKernel; - -},{"../ops/ops":123,"../tensor":146,"../util":151}],71:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MatrixOrientation; -(function (MatrixOrientation) { - MatrixOrientation[MatrixOrientation["REGULAR"] = 0] = "REGULAR"; - MatrixOrientation[MatrixOrientation["TRANSPOSED"] = 1] = "TRANSPOSED"; -})(MatrixOrientation = exports.MatrixOrientation || (exports.MatrixOrientation = {})); - -},{}],72:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ArgMinMaxProgram = (function () { - function ArgMinMaxProgram(reduceInfo, op, firstPass) { - this.variableNames = ['A']; - var windowSize = reduceInfo.windowSize; - var batchSize = reduceInfo.batchSize; - var inSize = reduceInfo.inSize; - var outSize = Math.ceil(inSize / windowSize); - if (!firstPass) { - this.variableNames.push('bestIndicesA'); - } - this.outputShape = [batchSize, outSize]; - var compOp = (op === 'max') ? '>' : '<'; - var indexSnippet = firstPass ? - 'inOffset + i;' : - 'round(getBestIndicesA(batch, inOffset + i));'; - this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * " + windowSize + ";\n\n int bestIndex = 0;\n float bestValue = getA(batch, inOffset);\n\n for (int i = 0; i < " + windowSize + "; i++) {\n int inIdx = " + indexSnippet + ";\n float candidate = getA(batch, inIdx);\n if (isNaN(candidate)) {\n setOutput(candidate);\n return;\n }\n if (candidate " + compOp + " bestValue) {\n bestValue = candidate;\n bestIndex = inIdx;\n }\n }\n setOutput(float(bestIndex));\n }\n "; - } - return ArgMinMaxProgram; -}()); -exports.ArgMinMaxProgram = ArgMinMaxProgram; - -},{}],73:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var AvgPool2DBackpropProgram = (function () { - function AvgPool2DBackpropProgram(convInfo) { - this.variableNames = ['dy']; - this.outputShape = convInfo.inShape; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var avgMultiplier = 1 / (filterHeight * filterWidth); - this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n const float avgMultiplier = float(" + avgMultiplier + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n setOutput(dotProd);\n }\n "; - } - return AvgPool2DBackpropProgram; -}()); -exports.AvgPool2DBackpropProgram = AvgPool2DBackpropProgram; - -},{}],74:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var broadcast_util = require("../../ops/broadcast_util"); -var BatchNormProgram = (function () { - function BatchNormProgram(xShape, meanShape, varianceShape, offsetShape, scaleShape, varianceEpsilon) { - this.outputShape = []; - this.supportsBroadcasting = true; - this.variableNames = ['x', 'mean', 'variance']; - broadcast_util.assertAndGetBroadcastShape(xShape, meanShape); - broadcast_util.assertAndGetBroadcastShape(xShape, varianceShape); - var offsetSnippet = '0.0'; - if (offsetShape != null) { - broadcast_util.assertAndGetBroadcastShape(xShape, offsetShape); - this.variableNames.push('offset'); - offsetSnippet = 'getOffsetAtOutCoords()'; - } - var scaleSnippet = '1.0'; - if (scaleShape != null) { - broadcast_util.assertAndGetBroadcastShape(xShape, scaleShape); - this.variableNames.push('scale'); - scaleSnippet = 'getScaleAtOutCoords()'; - } - this.outputShape = xShape; - this.userCode = "\n void main() {\n float x = getXAtOutCoords();\n float mean = getMeanAtOutCoords();\n float variance = getVarianceAtOutCoords();\n float offset = " + offsetSnippet + ";\n float scale = " + scaleSnippet + ";\n float inv = scale / sqrt(variance + float(" + varianceEpsilon + "));\n setOutput((x - mean) * inv + offset);\n }\n "; - } - return BatchNormProgram; -}()); -exports.BatchNormProgram = BatchNormProgram; - -},{"../../ops/broadcast_util":110}],75:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var broadcast_util = require("../../ops/broadcast_util"); -var CHECK_NAN_SNIPPET = "\n if (isNaN(a)) return a;\n if (isNaN(b)) return b;\n"; -exports.ADD = 'return a + b;'; -exports.SUB = 'return a - b;'; -exports.MUL = 'return a * b;'; -exports.DIV = 'return a / b;'; -exports.POW = "\n return (round(mod(b, 2.0)) == 0 || round(mod(b, 2.0)) == 2) ?\n pow(abs(a), b) : sign(a) * pow(abs(a), b);\n"; -exports.EQUAL = CHECK_NAN_SNIPPET + "\n return float(a == b);\n"; -exports.NOT_EQUAL = CHECK_NAN_SNIPPET + "\n return float(a != b);\n"; -exports.LESS = CHECK_NAN_SNIPPET + "\n return float(a < b);\n"; -exports.LESS_EQUAL = CHECK_NAN_SNIPPET + "\n return float(a <= b);\n"; -exports.GREATER = CHECK_NAN_SNIPPET + "\n return float(a > b);\n"; -exports.GREATER_EQUAL = CHECK_NAN_SNIPPET + "\n return float(a >= b);\n"; -exports.LOGICAL_AND = CHECK_NAN_SNIPPET + "\n return float(a >= 1.0 && b >= 1.0);\n"; -exports.LOGICAL_OR = CHECK_NAN_SNIPPET + "\n return float(a >= 1.0 || b >= 1.0);\n"; -exports.LOGICAL_XOR = CHECK_NAN_SNIPPET + "\n return float(a >= 1.0 ^^ b >= 1.0);\n"; -exports.PRELU = "\n return (a >= 0.0) ? a : b * a;\n"; -exports.PRELU_DER = "\n return (a > 0.0) ? 1.0 : ((a < 0.0) ? b : a);\n"; -exports.MAX = CHECK_NAN_SNIPPET + "\n return max(a, b);\n"; -exports.MIN = CHECK_NAN_SNIPPET + "\n return min(a, b);\n"; -var BinaryOpProgram = (function () { - function BinaryOpProgram(op, aShape, bShape) { - this.variableNames = ['A', 'B']; - this.supportsBroadcasting = true; - this.outputShape = - broadcast_util.assertAndGetBroadcastShape(aShape, bShape); - this.userCode = "\n float binaryOperation(float a, float b) {\n " + op + "\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n "; - } - return BinaryOpProgram; -}()); -exports.BinaryOpProgram = BinaryOpProgram; - -},{"../../ops/broadcast_util":110}],76:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ClipProgram = (function () { - function ClipProgram(aShape, min, max) { - this.variableNames = ['A']; - this.outputShape = aShape; - var minFixed = min.toFixed(20); - var maxFixed = max.toFixed(20); - this.userCode = "\n void main() {\n float value = getAAtOutCoords();\n if (isNaN(value)) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, " + minFixed + ", " + maxFixed + "));\n }\n "; - } - return ClipProgram; -}()); -exports.ClipProgram = ClipProgram; - -},{}],77:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var concat_util = require("../../ops/concat_util"); -var ConcatProgram = (function () { - function ConcatProgram(aShape, bShape) { - this.variableNames = ['A', 'B']; - this.outputShape = []; - this.outputShape = - concat_util.computeOutShape(aShape, bShape, 1); - this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int yR = coords.x;\n int yC = coords.y;\n\n float value = 0.0;\n if (yC < " + aShape[1] + ") {\n value = getA(yR, yC);\n } else {\n yC -= " + aShape[1] + ";\n value = getB(yR, yC);\n }\n\n setOutput(value);\n }\n "; - } - return ConcatProgram; -}()); -exports.ConcatProgram = ConcatProgram; - -},{"../../ops/concat_util":113}],78:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Conv2DDerFilterProgram = (function () { - function Conv2DDerFilterProgram(convInfo) { - this.variableNames = ['x', 'dy']; - this.outputShape = convInfo.filterShape; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int d2 = coords.w;\n\n // Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int b = 0; b < " + convInfo.batchSize + "; b++) {\n for (int yR = 0; yR < " + convInfo.outHeight + "; yR++) {\n int xR = wR + yR * " + strideHeight + " - " + padTop + ";\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int yC = 0; yC < " + convInfo.outWidth + "; yC++) {\n int xC = wC + yC * " + strideWidth + " - " + padLeft + ";\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n "; - } - return Conv2DDerFilterProgram; -}()); -exports.Conv2DDerFilterProgram = Conv2DDerFilterProgram; -var Conv2DDerInputProgram = (function () { - function Conv2DDerInputProgram(convInfo) { - this.variableNames = ['dy', 'W']; - this.outputShape = convInfo.inShape; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n\n ivec2 dyCorner = coords.yz - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = " + filterHeight + " - 1 - wR;\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = " + filterWidth + " - 1 - wC;\n\n for (int d2 = 0; d2 < " + convInfo.outChannels + "; d2++) {\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n "; - } - return Conv2DDerInputProgram; -}()); -exports.Conv2DDerInputProgram = Conv2DDerInputProgram; - -},{}],79:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Conv2DProgram = (function () { - function Conv2DProgram(convInfo) { - this.variableNames = ['x', 'W']; - this.outputShape = convInfo.outShape; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var inputDepthNearestVec4 = Math.floor(convInfo.inChannels / 4) * 4; - var inputDepthVec4Remainder = convInfo.inChannels % 4; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d2 = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n for (int d1 = 0; d1 < " + inputDepthNearestVec4 + "; d1 += 4) {\n vec4 xValues = vec4(\n getX(batch, xR, xC, d1),\n getX(batch, xR, xC, d1 + 1),\n getX(batch, xR, xC, d1 + 2),\n getX(batch, xR, xC, d1 + 3)\n );\n vec4 wValues = vec4(\n getW(wR, wC, d1, d2),\n getW(wR, wC, d1 + 1, d2),\n getW(wR, wC, d1 + 2, d2),\n getW(wR, wC, d1 + 3, d2)\n );\n\n dotProd += dot(xValues, wValues);\n }\n\n if (" + (inputDepthVec4Remainder === 1) + ") {\n dotProd +=\n getX(batch, xR, xC, " + inputDepthNearestVec4 + ") *\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2);\n } else if (" + (inputDepthVec4Remainder === 2) + ") {\n vec2 xValues = vec2(\n getX(batch, xR, xC, " + inputDepthNearestVec4 + "),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 1)\n );\n vec2 wValues = vec2(\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if (" + (inputDepthVec4Remainder === 3) + ") {\n vec3 xValues = vec3(\n getX(batch, xR, xC, " + inputDepthNearestVec4 + "),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 1),\n getX(batch, xR, xC, " + inputDepthNearestVec4 + " + 2)\n );\n vec3 wValues = vec3(\n getW(wR, wC, " + inputDepthNearestVec4 + ", d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 1, d2),\n getW(wR, wC, " + inputDepthNearestVec4 + " + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n setOutput(dotProd);\n }\n "; - } - return Conv2DProgram; -}()); -exports.Conv2DProgram = Conv2DProgram; - -},{}],80:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var DepthwiseConv2DProgram = (function () { - function DepthwiseConv2DProgram(convInfo) { - this.variableNames = ['x', 'W']; - this.outputShape = convInfo.outShape; - var xNumRows = convInfo.inHeight; - var xNumCols = convInfo.inWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var channelMul = convInfo.outChannels / convInfo.inChannels; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2 / " + channelMul + ";\n int q = d2 - d1 * " + channelMul + ";\n\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n // TODO(dsmilkov): Flatten the two for loops and vec4 the operations.\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + xNumRows + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + xNumCols + ") {\n continue;\n }\n\n float xVal = getX(batch, xR, xC, d1);\n float wVal = getW(wR, wC, d1, q);\n dotProd += xVal * wVal;\n }\n }\n setOutput(dotProd);\n }\n "; - } - return DepthwiseConv2DProgram; -}()); -exports.DepthwiseConv2DProgram = DepthwiseConv2DProgram; - -},{}],81:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var FromPixelsProgram = (function () { - function FromPixelsProgram(outputShape) { - this.variableNames = ['A']; - var height = outputShape[0], width = outputShape[1]; - this.outputShape = outputShape; - this.userCode = "\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + width + ".0, " + height + ".0);\n\n vec4 values = texture2D(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n setOutput(floor(value * 255.0 + 0.5));\n }\n "; - } - return FromPixelsProgram; -}()); -exports.FromPixelsProgram = FromPixelsProgram; - -},{}],82:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var GatherProgram = (function () { - function GatherProgram(aShape, indicesLength, axis) { - this.variableNames = ['A', 'indices']; - var outputShape = aShape.slice(); - outputShape[axis] = indicesLength; - this.outputShape = outputShape; - this.rank = outputShape.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var sourceCoords = getSourceCoords(aShape, axis); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + sourceCoords + "));\n }\n "; - } - return GatherProgram; -}()); -exports.GatherProgram = GatherProgram; -function getSourceCoords(aShape, axis) { - var rank = aShape.length; - if (rank > 4) { - throw Error("Gather for rank " + rank + " is not yet supported"); - } - if (rank === 1) { - return "int(getIndices(resRC))"; - } - var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var sourceCoords = []; - for (var i = 0; i < aShape.length; i++) { - if (i === axis) { - sourceCoords.push("int(getIndices(" + currentCoords[i] + "))"); - } - else { - sourceCoords.push("" + currentCoords[i]); - } - } - return sourceCoords.join(); -} - -},{"./shader_compiler":97}],83:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var util = require("../../util"); -var gpgpu_util = require("./gpgpu_util"); -var tex_util = require("./tex_util"); -var webgl_util = require("./webgl_util"); -var GPGPUContext = (function () { - function GPGPUContext(gl) { - this.outputTexture = null; - this.program = null; - this.disposed = false; - this.autoDebugValidate = false; - if (gl != null) { - this.gl = gl; - } - else { - this.gl = gpgpu_util.createWebGLContext(); - } - if (environment_1.ENV.get('WEBGL_VERSION') === 1) { - this.textureFloatExtension = - webgl_util.getExtensionOrThrow(this.gl, 'OES_texture_float'); - this.colorBufferFloatExtension = - this.gl.getExtension('WEBGL_color_buffer_float'); - } - else { - this.colorBufferFloatExtension = - webgl_util.getExtensionOrThrow(this.gl, 'EXT_color_buffer_float'); - } - this.loseContextExtension = - webgl_util.getExtensionOrThrow(this.gl, 'WEBGL_lose_context'); - if (environment_1.ENV.get('WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED')) { - this.getBufferSubDataAsyncExtension = - this.gl.getExtension('WEBGL_get_buffer_sub_data_async'); - } - this.vertexBuffer = gpgpu_util.createVertexBuffer(this.gl); - this.indexBuffer = gpgpu_util.createIndexBuffer(this.gl); - this.framebuffer = webgl_util.createFramebuffer(this.gl); - } - GPGPUContext.prototype.dispose = function () { - var _this = this; - if (this.disposed) { - return; - } - if (this.program != null) { - console.warn('Disposing a GPGPUContext that still has a bound WebGLProgram.' + - ' This is probably a resource leak, delete the program with ' + - 'GPGPUContext.deleteProgram before disposing.'); - } - if (this.outputTexture != null) { - console.warn('Disposing a GPGPUContext that still has a bound output matrix ' + - 'texture. This is probably a resource leak, delete the output ' + - 'matrix texture with GPGPUContext.deleteMatrixTexture before ' + - 'disposing.'); - } - var gl = this.gl; - webgl_util.callAndCheck(gl, function () { return gl.finish(); }); - webgl_util.callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, null); }); - webgl_util.callAndCheck(gl, function () { return gl.deleteFramebuffer(_this.framebuffer); }); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, null); }); - webgl_util.callAndCheck(gl, function () { return gl.deleteBuffer(_this.vertexBuffer); }); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); }); - webgl_util.callAndCheck(gl, function () { return gl.deleteBuffer(_this.indexBuffer); }); - this.loseContextExtension.loseContext(); - this.disposed = true; - }; - GPGPUContext.prototype.enableAutomaticDebugValidation = function (enabled) { - this.autoDebugValidate = enabled; - webgl_util.enableDebugWebGLErrorChecking(enabled); - }; - GPGPUContext.prototype.createMatrixTexture = function (rows, columns) { - this.throwIfDisposed(); - return gpgpu_util.createMatrixTexture(this.gl, rows, columns); - }; - GPGPUContext.prototype.uploadPixelDataToTexture = function (texture, pixels) { - this.throwIfDisposed(); - gpgpu_util.uploadPixelDataToTexture(this.gl, texture, pixels); - }; - GPGPUContext.prototype.createPackedMatrixTexture = function (rows, columns) { - this.throwIfDisposed(); - return gpgpu_util.createPackedMatrixTexture(this.gl, rows, columns); - }; - GPGPUContext.prototype.deleteMatrixTexture = function (texture) { - var _this = this; - this.throwIfDisposed(); - if (this.outputTexture === texture) { - webgl_util.unbindColorTextureFromFramebuffer(this.gl, this.framebuffer); - this.outputTexture = null; - } - webgl_util.callAndCheck(this.gl, function () { return _this.gl.deleteTexture(texture); }); - }; - GPGPUContext.prototype.uploadMatrixToTexture = function (texture, rows, columns, matrix) { - this.throwIfDisposed(); - var numChannels = 1; - return gpgpu_util.uploadMatrixToTexture(this.gl, texture, rows, columns, matrix, numChannels); - }; - GPGPUContext.prototype.uploadMatrixToPackedTexture = function (texture, rows, columns, matrix) { - this.throwIfDisposed(); - return gpgpu_util.uploadMatrixToPackedTexture(this.gl, texture, rows, columns, matrix); - }; - GPGPUContext.prototype.downloadMatrixFromTexture = function (texture, rows, columns) { - var _this = this; - return this.downloadMatrixDriver(texture, function () { - return gpgpu_util.downloadMatrixFromOutputTexture(_this.gl, rows, columns); - }); - }; - GPGPUContext.prototype.downloadMatrixFromTextureAsync = function (texture, rows, columns) { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - if (this.getBufferSubDataAsyncExtension == null) { - throw new Error("Cannot download matrix from output texture asynchronously, " + - "WEBGL_get_buffer_sub_data_async is not enabled."); - } - return [2, this.downloadMatrixDriverAsync(texture, function () { return gpgpu_util.downloadMatrixFromOutputTextureAsync(_this.gl, _this.getBufferSubDataAsyncExtension, rows, columns); })]; - }); - }); - }; - GPGPUContext.prototype.downloadMatrixFromRGBAColorTexture = function (texture, rows, columns, channels) { - var _this = this; - return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadMatrixFromRGBAColorTexture(_this.gl, rows, columns, channels); }); - }; - GPGPUContext.prototype.downloadMatrixFromPackedTexture = function (texture, rows, columns) { - var _this = this; - return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadMatrixFromPackedOutputTexture(_this.gl, rows, columns); }); - }; - GPGPUContext.prototype.createProgram = function (fragmentShaderSource) { - this.throwIfDisposed(); - var gl = this.gl; - var fragmentShader = webgl_util.createFragmentShader(gl, fragmentShaderSource); - var vertexShader = gpgpu_util.createVertexShader(gl); - var program = webgl_util.createProgram(gl); - webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, vertexShader); }); - webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, fragmentShader); }); - webgl_util.linkProgram(gl, program); - if (this.autoDebugValidate) { - webgl_util.validateProgram(gl, program); - } - return program; - }; - GPGPUContext.prototype.deleteProgram = function (program) { - var _this = this; - this.throwIfDisposed(); - if (program === this.program) { - this.program = null; - } - if (program != null) { - webgl_util.callAndCheck(this.gl, function () { return _this.gl.deleteProgram(program); }); - } - }; - GPGPUContext.prototype.setProgram = function (program) { - var _this = this; - this.throwIfDisposed(); - this.program = program; - if ((this.program != null) && this.autoDebugValidate) { - webgl_util.validateProgram(this.gl, this.program); - } - webgl_util.callAndCheck(this.gl, function () { return _this.gl.useProgram(program); }); - }; - GPGPUContext.prototype.getUniformLocation = function (program, uniformName, shouldThrow) { - if (shouldThrow === void 0) { shouldThrow = true; } - this.throwIfDisposed(); - if (shouldThrow) { - return webgl_util.getProgramUniformLocationOrThrow(this.gl, program, uniformName); - } - else { - return webgl_util.getProgramUniformLocation(this.gl, program, uniformName); - } - }; - GPGPUContext.prototype.getAttributeLocation = function (program, attribute) { - var _this = this; - this.throwIfDisposed(); - return webgl_util.callAndCheck(this.gl, function () { return _this.gl.getAttribLocation(program, attribute); }); - }; - GPGPUContext.prototype.getUniformLocationNoThrow = function (program, uniformName) { - this.throwIfDisposed(); - return this.gl.getUniformLocation(program, uniformName); - }; - GPGPUContext.prototype.setInputMatrixTexture = function (inputMatrixTexture, uniformLocation, textureUnit) { - this.throwIfDisposed(); - this.throwIfNoProgram(); - webgl_util.bindTextureToProgramUniformSampler(this.gl, this.program, inputMatrixTexture, uniformLocation, textureUnit); - }; - GPGPUContext.prototype.setOutputMatrixTexture = function (outputMatrixTexture, rows, columns) { - this.setOutputMatrixTextureDriver(outputMatrixTexture, columns, rows); - }; - GPGPUContext.prototype.setOutputPackedMatrixTexture = function (outputPackedMatrixTexture, rows, columns) { - this.throwIfDisposed(); - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - this.setOutputMatrixTextureDriver(outputPackedMatrixTexture, width, height); - }; - GPGPUContext.prototype.setOutputMatrixWriteRegion = function (startRow, numRows, startColumn, numColumns) { - this.setOutputMatrixWriteRegionDriver(startColumn, startRow, numColumns, numRows); - }; - GPGPUContext.prototype.setOutputPackedMatrixWriteRegion = function (startRow, numRows, startColumn, numColumns) { - throw new Error('setOutputPackedMatrixWriteRegion not implemented.'); - }; - GPGPUContext.prototype.debugValidate = function () { - if (this.program != null) { - webgl_util.validateProgram(this.gl, this.program); - } - webgl_util.validateFramebuffer(this.gl); - }; - GPGPUContext.prototype.executeProgram = function (attribLocations) { - this.throwIfDisposed(); - this.throwIfNoProgram(); - var gl = this.gl; - gpgpu_util.bindVertexProgramAttributeStreams(gl, this.program, this.vertexBuffer, attribLocations); - if (this.autoDebugValidate) { - this.debugValidate(); - } - webgl_util.callAndCheck(gl, function () { return gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0); }); - }; - GPGPUContext.prototype.blockUntilAllProgramsCompleted = function () { - var _this = this; - this.throwIfDisposed(); - webgl_util.callAndCheck(this.gl, function () { return _this.gl.finish(); }); - }; - GPGPUContext.prototype.getQueryTimerExtension = function () { - if (this.disjointQueryTimerExtension == null) { - this.disjointQueryTimerExtension = - webgl_util.getExtensionOrThrow(this.gl, environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2 ? - 'EXT_disjoint_timer_query_webgl2' : - 'EXT_disjoint_timer_query'); - } - return this.disjointQueryTimerExtension; - }; - GPGPUContext.prototype.getQueryTimerExtensionWebGL2 = function () { - return this.getQueryTimerExtension(); - }; - GPGPUContext.prototype.getQueryTimerExtensionWebGL1 = function () { - return this.getQueryTimerExtension(); - }; - GPGPUContext.prototype.runQuery = function (queryFn) { - var query = this.beginQuery(); - queryFn(); - this.endQuery(); - return this.pollQueryTime(query); - }; - GPGPUContext.prototype.beginQuery = function () { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2) { - var gl2 = this.gl; - var ext = this.getQueryTimerExtensionWebGL2(); - var query = gl2.createQuery(); - gl2.beginQuery(ext.TIME_ELAPSED_EXT, query); - return query; - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - var query = ext.createQueryEXT(); - ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, query); - return query; - } - }; - GPGPUContext.prototype.endQuery = function () { - if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2) { - var gl2 = this.gl; - var ext = this.getQueryTimerExtensionWebGL2(); - gl2.endQuery(ext.TIME_ELAPSED_EXT); - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - ext.endQueryEXT(ext.TIME_ELAPSED_EXT); - } - }; - GPGPUContext.prototype.isQueryAvailable = function (query, queryTimerVersion) { - if (queryTimerVersion === 0) { - return true; - } - if (queryTimerVersion === 2) { - var gl2 = this.gl; - var ext = this.getQueryTimerExtensionWebGL2(); - var available = gl2.getQueryParameter(query, gl2.QUERY_RESULT_AVAILABLE); - var disjoint = this.gl.getParameter(ext.GPU_DISJOINT_EXT); - return available && !disjoint; - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - var available = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_AVAILABLE_EXT); - var disjoint = this.gl.getParameter(ext.GPU_DISJOINT_EXT); - return available && !disjoint; - } - }; - GPGPUContext.prototype.pollQueryTime = function (query) { - var _this = this; - return new Promise(function (resolve, reject) { - var resolveWithWarning = function () { - console.warn('Disjoint query timer never available.'); - resolve(-1); - }; - var queryTimerVersion = environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION'); - util.repeatedTry(function () { return _this.isQueryAvailable(query, queryTimerVersion); }) - .then(function () { return resolve(_this.getQueryTime(query, queryTimerVersion)); }) - .catch(resolveWithWarning); - }); - }; - GPGPUContext.prototype.getQueryTime = function (query, queryTimerVersion) { - if (queryTimerVersion === 0) { - return null; - } - if (queryTimerVersion === 2) { - var gl2 = this.gl; - var timeElapsedNanos = gl2.getQueryParameter(query, gl2.QUERY_RESULT); - return timeElapsedNanos / 1000000; - } - else { - var ext = this.getQueryTimerExtensionWebGL1(); - var timeElapsedNanos = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_EXT); - return timeElapsedNanos / 1000000; - } - }; - GPGPUContext.prototype.downloadMatrixDriverSetup = function (texture) { - this.throwIfDisposed(); - webgl_util.bindColorTextureToFramebuffer(this.gl, texture, this.framebuffer); - if (this.autoDebugValidate) { - webgl_util.validateFramebuffer(this.gl); - } - }; - GPGPUContext.prototype.downloadMatrixDriverTeardown = function () { - if (this.outputTexture != null) { - webgl_util.bindColorTextureToFramebuffer(this.gl, this.outputTexture, this.framebuffer); - if (this.autoDebugValidate) { - webgl_util.validateFramebuffer(this.gl); - } - } - else { - webgl_util.unbindColorTextureFromFramebuffer(this.gl, this.framebuffer); - } - }; - GPGPUContext.prototype.downloadMatrixDriver = function (texture, downloadAndDecode) { - this.downloadMatrixDriverSetup(texture); - var result = downloadAndDecode(); - this.downloadMatrixDriverTeardown(); - return result; - }; - GPGPUContext.prototype.downloadMatrixDriverAsync = function (texture, downloadAndDecode) { - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.downloadMatrixDriverSetup(texture); - return [4, downloadAndDecode()]; - case 1: - result = _a.sent(); - this.downloadMatrixDriverTeardown(); - return [2, result]; - } - }); - }); - }; - GPGPUContext.prototype.setOutputMatrixTextureDriver = function (outputMatrixTextureMaybePacked, width, height) { - this.throwIfDisposed(); - var gl = this.gl; - webgl_util.bindColorTextureToFramebuffer(gl, outputMatrixTextureMaybePacked, this.framebuffer); - if (this.autoDebugValidate) { - webgl_util.validateFramebuffer(gl); - } - this.outputTexture = outputMatrixTextureMaybePacked; - webgl_util.callAndCheck(gl, function () { return gl.viewport(0, 0, width, height); }); - webgl_util.callAndCheck(gl, function () { return gl.scissor(0, 0, width, height); }); - }; - GPGPUContext.prototype.setOutputMatrixWriteRegionDriver = function (x, y, width, height) { - var _this = this; - this.throwIfDisposed(); - webgl_util.callAndCheck(this.gl, function () { return _this.gl.scissor(x, y, width, height); }); - }; - GPGPUContext.prototype.throwIfDisposed = function () { - if (this.disposed) { - throw new Error('Attempted to use disposed GPGPUContext.'); - } - }; - GPGPUContext.prototype.throwIfNoProgram = function () { - if (this.program == null) { - throw new Error('No GPU program is currently set.'); - } - }; - return GPGPUContext; -}()); -exports.GPGPUContext = GPGPUContext; - -},{"../../environment":34,"../../util":151,"./gpgpu_util":85,"./tex_util":99,"./webgl_util":104}],84:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var util = require("../../util"); -var shader_compiler = require("./shader_compiler"); -var ATTRIBUTE_NAMES = ['uv', 'clipSpacePos']; -var NAN_UNIFORM_NAME = 'NaN'; -function shouldUploadNaNUniform() { - return !environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED'); -} -function compileProgram(gpgpu, program, inputs, output) { - var userCode = program.userCode; - var inputInfos = inputs.map(function (input, i) { - var shapeInfo = { - logicalShape: input.tensor.shape, - texShape: input.texData.texShape - }; - return { name: program.variableNames[i], shapeInfo: shapeInfo }; - }); - var inShapeInfos = inputInfos.map(function (x) { return x.shapeInfo; }); - var outShapeInfo = { - logicalShape: output.tensor.shape, - texShape: output.texData.texShape - }; - var source = shader_compiler.makeShader(inputInfos, outShapeInfo, userCode, program.supportsBroadcasting === true); - var webGLProgram = gpgpu.createProgram(source); - var uniformLocations = {}; - for (var i = 0; i < program.variableNames.length; i++) { - var uniformName = program.variableNames[i]; - uniformLocations[uniformName] = - gpgpu.getUniformLocation(webGLProgram, uniformName); - } - var attributeLocations = {}; - ATTRIBUTE_NAMES.forEach(function (attribute) { - attributeLocations[attribute] = - gpgpu.getAttributeLocation(webGLProgram, attribute); - }); - if (shouldUploadNaNUniform()) { - var throwIfNaNUniformIsNotUsed = false; - uniformLocations[NAN_UNIFORM_NAME] = gpgpu.getUniformLocation(webGLProgram, NAN_UNIFORM_NAME, throwIfNaNUniformIsNotUsed); - } - return { - program: program, - source: source, - webGLProgram: webGLProgram, - uniformLocations: uniformLocations, - attributeLocations: attributeLocations, - gpgpu: gpgpu, - inShapeInfos: inShapeInfos, - outShapeInfo: outShapeInfo - }; -} -exports.compileProgram = compileProgram; -function validateBinaryAndProgram(shapeInfos, inputs) { - if (shapeInfos.length !== inputs.length) { - throw Error("Binary was compiled with " + shapeInfos.length + " inputs, but " + - ("was executed with " + inputs.length + " inputs")); - } - shapeInfos.forEach(function (s, i) { - var shapeA = s.logicalShape; - var texShapeA = s.texShape; - var shapeB = inputs[i].tensor.shape; - var texShapeB = inputs[i].texData.texShape; - if (!util.arraysEqual(shapeA, shapeB)) { - throw Error("Binary was compiled with different shapes than " + - ("the current args. Shapes " + shapeA + " and " + shapeB + " must match")); - } - if (!util.arraysEqual(texShapeA, texShapeB)) { - throw Error("Binary was compiled with different texture shapes than the" + - (" current args. Shape " + texShapeA + " and " + texShapeB + " must match")); - } - }); -} -function runProgram(binary, inputs, output, customSetup) { - validateBinaryAndProgram(binary.inShapeInfos, inputs); - validateBinaryAndProgram([binary.outShapeInfo], [output]); - var outTex = output.texData.texture; - var outTexShape = output.texData.texShape; - var gpgpu = binary.gpgpu; - gpgpu.setOutputMatrixTexture(outTex, outTexShape[0], outTexShape[1]); - gpgpu.setProgram(binary.webGLProgram); - inputs.forEach(function (input, i) { - var tex = input.texData.texture; - var variableName = binary.program.variableNames[i]; - var variableUniformLocation = binary.uniformLocations[variableName]; - gpgpu.setInputMatrixTexture(tex, variableUniformLocation, i); - }); - if (shouldUploadNaNUniform()) { - gpgpu.gl.uniform1f(binary.uniformLocations[NAN_UNIFORM_NAME], NaN); - } - if (customSetup != null) { - customSetup(gpgpu, binary.webGLProgram); - } - gpgpu.executeProgram(binary.attributeLocations); -} -exports.runProgram = runProgram; -function makeShaderKey(program, inputs, output) { - var keyInputs = ''; - inputs.concat(output).forEach(function (x) { - keyInputs += x.tensor.shape + "_" + x.texData.texShape; - }); - var keyUserCode = program.userCode; - var keyBroadcast = (program.supportsBroadcasting === true).toString(); - var key = program.constructor.name; - key += '_' + keyBroadcast + '_' + keyInputs + '_' + keyUserCode; - return key; -} -exports.makeShaderKey = makeShaderKey; - -},{"../../environment":34,"../../util":151,"./shader_compiler":97}],85:[function(require,module,exports){ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var tex_util = require("./tex_util"); -var webgl_util = require("./webgl_util"); -function getWebGLContextAttributes() { - return { - alpha: false, - antialias: false, - premultipliedAlpha: false, - preserveDrawingBuffer: false, - depth: false, - stencil: false, - failIfMajorPerformanceCaveat: true - }; -} -exports.getWebGLContextAttributes = getWebGLContextAttributes; -function createWebGLContext(canvas) { - var attributes = getWebGLContextAttributes(); - var gl; - if (canvas != null) { - gl = webgl_util.createWebGLRenderingContextFromCanvas(canvas, attributes); - } - else { - gl = webgl_util.createWebGLRenderingContext(attributes); - } - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.DEPTH_TEST); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.STENCIL_TEST); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.BLEND); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.DITHER); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.POLYGON_OFFSET_FILL); }); - webgl_util.callAndCheck(gl, function () { return gl.disable(gl.SAMPLE_COVERAGE); }); - webgl_util.callAndCheck(gl, function () { return gl.enable(gl.SCISSOR_TEST); }); - webgl_util.callAndCheck(gl, function () { return gl.enable(gl.CULL_FACE); }); - webgl_util.callAndCheck(gl, function () { return gl.cullFace(gl.BACK); }); - return gl; -} -exports.createWebGLContext = createWebGLContext; -function createVertexShader(gl) { - var vertexShaderSource = "\n precision highp float;\n attribute vec3 clipSpacePos;\n attribute vec2 uv;\n varying vec2 resultUV;\n\n void main() {\n gl_Position = vec4(clipSpacePos, 1);\n resultUV = uv;\n }"; - return webgl_util.createVertexShader(gl, vertexShaderSource); -} -exports.createVertexShader = createVertexShader; -function createVertexBuffer(gl) { - var vertexArray = new Float32Array([-1, 1, 0, 0, 1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 1, -1, 0, 1, 0]); - return webgl_util.createStaticVertexBuffer(gl, vertexArray); -} -exports.createVertexBuffer = createVertexBuffer; -function createIndexBuffer(gl) { - var triangleVertexIndices = new Uint16Array([0, 1, 2, 2, 1, 3]); - return webgl_util.createStaticIndexBuffer(gl, triangleVertexIndices); -} -exports.createIndexBuffer = createIndexBuffer; -function getTextureInternalFormat(gl, numChannels) { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return gl.RGBA; - } - if (environment_1.ENV.get('WEBGL_VERSION') === 2) { - if (numChannels === 4) { - return gl.RGBA32F; - } - return gl.R32F; - } - return gl.RGBA; -} -function getTextureFormat(gl, numChannels) { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return gl.RGBA; - } - if (environment_1.ENV.get('WEBGL_VERSION') === 2) { - if (numChannels === 4) { - return gl.RGBA; - } - return gl.RED; - } - return gl.RGBA; -} -function getTextureType(gl) { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return gl.UNSIGNED_BYTE; - } - return gl.FLOAT; -} -function createAndConfigureTexture(gl, width, height, numChannels) { - webgl_util.validateTextureSize(gl, width, height); - var texture = webgl_util.createTexture(gl); - var tex2d = gl.TEXTURE_2D; - var internalFormat = getTextureInternalFormat(gl, numChannels); - var format = getTextureFormat(gl, numChannels); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(tex2d, texture); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MIN_FILTER, gl.NEAREST); }); - webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MAG_FILTER, gl.NEAREST); }); - webgl_util.callAndCheck(gl, function () { return gl.texImage2D(tex2d, 0, internalFormat, width, height, 0, format, getTextureType(gl), null); }); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); - return texture; -} -function createMatrixTexture(gl, rows, columns) { - var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - var numChannels = 1; - return createAndConfigureTexture(gl, width, height, numChannels); -} -exports.createMatrixTexture = createMatrixTexture; -function createColorMatrixTexture(gl, rows, columns) { - var _a = tex_util.getColorMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - var numChannels = 4; - return createAndConfigureTexture(gl, width, height, numChannels); -} -exports.createColorMatrixTexture = createColorMatrixTexture; -function createPackedMatrixTexture(gl, rows, columns) { - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1]; - var numChannels = 4; - return createAndConfigureTexture(gl, width, height, numChannels); -} -exports.createPackedMatrixTexture = createPackedMatrixTexture; -function bindVertexProgramAttributeStreams(gl, program, vertexBuffer, attribLocations) { - var posOffset = 0; - var uvOffset = 3 * 4; - var stride = (3 * 4) + (2 * 4); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); }); - webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'clipSpacePos', vertexBuffer, 3, stride, posOffset, attribLocations); - webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'uv', vertexBuffer, 2, stride, uvOffset, attribLocations); -} -exports.bindVertexProgramAttributeStreams = bindVertexProgramAttributeStreams; -function uploadPixelDataToTexture(gl, texture, pixels) { - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); }); - webgl_util.callAndCheck(gl, function () { return gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels); }); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); -} -exports.uploadPixelDataToTexture = uploadPixelDataToTexture; -function uploadDataToTexture(gl, texture, width, height, data, numChannels) { - var textureFormat = getTextureFormat(gl, numChannels); - webgl_util.validateTextureSize(gl, width, height); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); }); - webgl_util.callAndCheck(gl, function () { return gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, textureFormat, getTextureType(gl), data); }); - webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); -} -function uploadMatrixToTexture(gl, texture, rows, columns, matrix, numChannels) { - var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var unpackedArray; - if (environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - var channelsPerTexture = numChannels === 1 ? webgl_util.getChannelsPerTexture() : numChannels; - if (channelsPerTexture === 1) { - unpackedArray = matrix; - } - else { - unpackedArray = - new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(matrix.length, channelsPerTexture)); - tex_util.encodeMatrixToUnpackedArray(matrix, unpackedArray, channelsPerTexture); - } - } - else { - unpackedArray = tex_util.encodeFloatArray(matrix); - } - uploadDataToTexture(gl, texture, w, h, unpackedArray, numChannels); -} -exports.uploadMatrixToTexture = uploadMatrixToTexture; -function uploadMatrixToPackedTexture(gl, texture, rows, columns, matrix) { - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var packedRGBA = new Float32Array(tex_util.getPackedRGBAArraySizeFromMatrixShape(rows, columns)); - tex_util.encodeMatrixToPackedRGBA(matrix, rows, columns, packedRGBA); - var numChannels = 4; - uploadDataToTexture(gl, texture, w, h, packedRGBA, numChannels); -} -exports.uploadMatrixToPackedTexture = uploadMatrixToPackedTexture; -function getDownloadTargetArrayBuffer(rows, columns, channelsPerTexture) { - var isFloatTexture = environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED'); - var downloadTarget; - if (isFloatTexture) { - downloadTarget = - new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(rows * columns, channelsPerTexture)); - } - else { - downloadTarget = new Uint8Array(rows * columns * channelsPerTexture); - } - return downloadTarget; -} -function decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel) { - var isFloatTexture = environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED'); - if (isFloatTexture) { - var matrix = new Float32Array(rows * columns); - tex_util.decodeMatrixFromUnpackedArray(downloadTarget, matrix, channelsPerPixel); - return matrix; - } - else { - return tex_util.decodeToFloatArray(downloadTarget); - } -} -function downloadMatrixFromOutputTextureAsync(gl, getBufferSubDataAsyncExtension, rows, columns) { - return __awaiter(this, void 0, void 0, function () { - var gl2, channelsPerPixel, downloadTarget, bufferSizeBytes, buffer; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - gl2 = gl; - channelsPerPixel = 4; - downloadTarget = getDownloadTargetArrayBuffer(rows, columns, channelsPerPixel); - bufferSizeBytes = downloadTarget instanceof Float32Array ? - downloadTarget.length * 4 : - downloadTarget; - buffer = gl.createBuffer(); - webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl2.PIXEL_PACK_BUFFER, buffer); }); - webgl_util.callAndCheck(gl, function () { return gl.bufferData(gl2.PIXEL_PACK_BUFFER, bufferSizeBytes, gl.STATIC_DRAW); }); - webgl_util.callAndCheck(gl, function () { - return gl2.readPixels(0, 0, columns, rows, gl.RGBA, getTextureType(gl), 0); - }); - return [4, getBufferSubDataAsyncExtension.getBufferSubDataAsync(gl2.PIXEL_PACK_BUFFER, 0, downloadTarget)]; - case 1: - _a.sent(); - return [2, decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel)]; - } - }); - }); -} -exports.downloadMatrixFromOutputTextureAsync = downloadMatrixFromOutputTextureAsync; -function downloadMatrixFromOutputTexture(gl, rows, columns) { - var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var channelsPerPixel = 4; - var downloadTarget = getDownloadTargetArrayBuffer(rows, columns, channelsPerPixel); - webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, gl.RGBA, getTextureType(gl), downloadTarget); }); - return decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel); -} -exports.downloadMatrixFromOutputTexture = downloadMatrixFromOutputTexture; -function downloadMatrixFromRGBAColorTexture(gl, rows, columns, channels) { - var size = rows * columns * 4; - var downloadTarget = new Uint8Array(size); - webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, columns, rows, gl.RGBA, gl.UNSIGNED_BYTE, downloadTarget); }); - var packedRGBA = new Float32Array(size); - for (var i = 0; i < downloadTarget.length; i++) { - packedRGBA[i] = downloadTarget[i]; - } - var matrix = new Float32Array(rows * columns * channels); - tex_util.decodeMatrixFromUnpackedColorRGBAArray(packedRGBA, matrix, channels); - return matrix; -} -exports.downloadMatrixFromRGBAColorTexture = downloadMatrixFromRGBAColorTexture; -function downloadMatrixFromPackedOutputTexture(gl, rows, columns) { - var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - var packedRGBA = new Float32Array(tex_util.getPackedRGBAArraySizeFromMatrixShape(rows, columns)); - webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, gl.RGBA, getTextureType(gl), packedRGBA); }); - var matrix = new Float32Array(rows * columns); - return tex_util.decodeMatrixFromPackedRGBA(packedRGBA, rows, columns, matrix); -} -exports.downloadMatrixFromPackedOutputTexture = downloadMatrixFromPackedOutputTexture; - -},{"../../environment":34,"./tex_util":99,"./webgl_util":104}],86:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var WhereProgram = (function () { - function WhereProgram(cRank, shape, rank) { - this.variableNames = ['c', 'a', 'b']; - this.outputShape = shape; - var cCoords; - var abCoords; - if (rank > 4) { - throw Error("Where for rank " + rank + " is not yet supported"); - } - if (rank === 1) { - abCoords = "resRC"; - cCoords = "resRC"; - } - else { - var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var cCoordVars = []; - var abCoordVars = []; - for (var i = 0; i < shape.length; i++) { - abCoordVars.push("" + currentCoords[i]); - if (i < cRank) { - cCoordVars.push("" + currentCoords[i]); - } - } - cCoords = cCoordVars.join(); - abCoords = abCoordVars.join(); - } - var dtype = shader_compiler_1.getCoordsDataType(rank); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n float cVal = getC(" + cCoords + ");\n if (cVal >= 1.0) {\n setOutput(getA(" + abCoords + "));\n } else {\n setOutput(getB(" + abCoords + "));\n }\n }\n "; - } - return WhereProgram; -}()); -exports.WhereProgram = WhereProgram; - -},{"./shader_compiler":97}],87:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var LRNProgram = (function () { - function LRNProgram(xShape, radius, bias, alpha, beta, normRegion) { - this.variableNames = ['x']; - this.outputShape = []; - var rad = radius; - var maxW = xShape[1] - 1; - var maxH = xShape[2] - 1; - var maxD = xShape[3] - 1; - this.outputShape = xShape; - var powOperator; - var basis = "float(" + bias + ") + float(" + alpha + ") * sum"; - if (beta === 0.5) { - powOperator = "inversesqrt(" + basis + ")"; - } - else if (beta === 1.0) { - powOperator = "1.0/(" + basis + ")"; - } - else { - powOperator = "exp(log(" + basis + ") * float(-" + beta + "));"; - } - if (normRegion === 'withinChannel') { - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int u = -" + rad + "; u <= " + rad + "; u++) {\n for (int v = -" + rad + "; v <= " + rad + "; v++) {\n int idx = r + u;\n int idy = c + v;\n if (idx >= 0 && idx <= " + maxW + " && idy >= 0 && idy <= " + maxH + ") {\n float z = getX(b, idx, idy, d);\n sum += z * z;\n }\n }\n }\n float val = x * " + powOperator + ";\n setOutput(val);\n }\n "; - } - else { - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int j = -" + rad + "; j <= " + rad + "; j++) {\n int idx = d + j;\n if (idx >= 0 && idx <= " + maxD + ") {\n float z = getX(b, r, c, idx);\n sum += z * z;\n }\n }\n float val = x * " + powOperator + ";\n setOutput(val);\n }\n "; - } - } - return LRNProgram; -}()); -exports.LRNProgram = LRNProgram; - -},{}],88:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MaxPool2DBackpropProgram = (function () { - function MaxPool2DBackpropProgram(convInfo) { - this.variableNames = ['dy', 'maxPos']; - this.outputShape = convInfo.inShape; - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = filterHeight - 1 - convInfo.padInfo.top; - var padLeft = filterWidth - 1 - convInfo.padInfo.left; - var lastIndex = filterHeight * filterWidth - 1; - this.userCode = "\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n float dyR = float(dyRCorner + wR) / " + strideHeight + ".0;\n\n if (dyR < 0.0 || dyR >= " + convInfo.outHeight + ".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n float dyC = float(dyCCorner + wC) / " + strideWidth + ".0;\n\n if (dyC < 0.0 || dyC >= " + convInfo.outWidth + ".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n int maxPosValue = " + lastIndex + " - int(getMaxPos(b, idyR, idyC, d));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue = wR * " + filterWidth + " + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n setOutput(dotProd);\n }\n "; - } - return MaxPool2DBackpropProgram; -}()); -exports.MaxPool2DBackpropProgram = MaxPool2DBackpropProgram; - -},{}],89:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MatMulProgram = (function () { - function MatMulProgram(aShape, bShape, transposeA, transposeB) { - if (transposeA === void 0) { transposeA = false; } - if (transposeB === void 0) { transposeB = false; } - this.variableNames = ['matrixA', 'matrixB']; - var outerShapeA = transposeA ? aShape[1] : aShape[0]; - var outerShapeB = transposeB ? bShape[0] : bShape[1]; - var sharedDim = transposeA ? aShape[0] : aShape[1]; - this.outputShape = [outerShapeA, outerShapeB]; - var aSnippetFromOffset = function (vec4Offset, indexVar) { - return transposeA ? indexVar + " + " + vec4Offset + ", aRow" : - "aRow, " + indexVar + " + " + vec4Offset; - }; - var bSnippetFromOffset = function (vec4Offset, indexVar) { - return transposeB ? "bCol, " + indexVar + " + " + vec4Offset : - indexVar + " + " + vec4Offset + ", bCol"; - }; - var sharedDimNearestVec4 = Math.floor(sharedDim / 4) * 4; - var sharedDimVec4Remainder = sharedDim % 4; - this.userCode = " float dotARowBCol(int aRow, int bCol) {\n float result = 0.0;\n for (int i = 0; i < " + sharedDimNearestVec4 + "; i += 4) {\n vec4 a = vec4(\n getMatrixA(" + aSnippetFromOffset(0, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(1, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(2, 'i') + "),\n getMatrixA(" + aSnippetFromOffset(3, 'i') + ")\n );\n vec4 b = vec4(\n getMatrixB(" + bSnippetFromOffset(0, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(1, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(2, 'i') + "),\n getMatrixB(" + bSnippetFromOffset(3, 'i') + ")\n );\n\n result += dot(a, b);\n }\n\n if (" + (sharedDimVec4Remainder === 1) + ") {\n result += getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + ") *\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + ");\n } else if (" + (sharedDimVec4Remainder === 2) + ") {\n vec2 a = vec2(\n getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(1, sharedDimNearestVec4) + ")\n );\n vec2 b = vec2(\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(1, sharedDimNearestVec4) + ")\n );\n result += dot(a, b);\n } else if (" + (sharedDimVec4Remainder === 3) + ") {\n vec3 a = vec3(\n getMatrixA(" + aSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(1, sharedDimNearestVec4) + "),\n getMatrixA(" + aSnippetFromOffset(2, sharedDimNearestVec4) + ")\n );\n vec3 b = vec3(\n getMatrixB(" + bSnippetFromOffset(0, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(1, sharedDimNearestVec4) + "),\n getMatrixB(" + bSnippetFromOffset(2, sharedDimNearestVec4) + ")\n );\n result += dot(a, b);\n }\n\n return result;\n }\n\n void main() {\n ivec2 resRC = getOutputCoords();\n setOutput(dotARowBCol(resRC.x, resRC.y));\n }\n "; - } - return MatMulProgram; -}()); -exports.MatMulProgram = MatMulProgram; - -},{}],90:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MultinomialProgram = (function () { - function MultinomialProgram(batchSize, numOutcomes, numSamples) { - this.variableNames = ['probs']; - this.outputShape = [batchSize, numSamples]; - this.userCode = "\n uniform float seed;\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n\n float r = random(seed);\n float cdf = 0.0;\n\n for (int i = 0; i < " + (numOutcomes - 1) + "; i++) {\n cdf += getProbs(batch, i);\n\n if (r < cdf) {\n setOutput(float(i));\n return;\n }\n }\n\n // If no other event happened, last event happened.\n setOutput(float(" + (numOutcomes - 1) + "));\n }\n "; - } - MultinomialProgram.prototype.getCustomSetupFunc = function (seed) { - var _this = this; - return function (gpgpu, webGLProgram) { - if (_this.seedLoc == null) { - _this.seedLoc = gpgpu.getUniformLocation(webGLProgram, 'seed'); - } - gpgpu.gl.uniform1f(_this.seedLoc, seed); - }; - }; - return MultinomialProgram; -}()); -exports.MultinomialProgram = MultinomialProgram; - -},{}],91:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var OneHotProgram = (function () { - function OneHotProgram(numIndices, depth, onValue, offValue) { - this.variableNames = ['indices']; - this.outputShape = [numIndices, depth]; - this.userCode = "\n void main() {\n ivec2 coords = getOutputCoords();\n int index = round(getIndices(coords.x));\n setOutput(mix(float(" + offValue + "), float(" + onValue + "),\n float(index == coords.y)));\n }\n "; - } - return OneHotProgram; -}()); -exports.OneHotProgram = OneHotProgram; - -},{}],92:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Pad1DProgram = (function () { - function Pad1DProgram(xShape, paddings, constantValue) { - this.variableNames = ['x']; - var leftPadding = paddings[0]; - var rightPadding = paddings[1]; - this.outputShape = [leftPadding + xShape[0] + rightPadding]; - this.rank = 1; - this.userCode = "\n void main() {\n int resRC = getOutputCoords();\n if (resRC < " + leftPadding + " || resRC >= " + leftPadding + " + " + xShape[0] + ") {\n setOutput(float(" + constantValue + "));\n } else {\n setOutput(getX(resRC - " + leftPadding + "));\n }\n }\n "; - } - return Pad1DProgram; -}()); -exports.Pad1DProgram = Pad1DProgram; -var Pad2DProgram = (function () { - function Pad2DProgram(xShape, paddings, constantValue) { - this.variableNames = ['x']; - var topPadding = paddings[0][0]; - var bottomPadding = paddings[0][1]; - var leftPadding = paddings[1][0]; - var rightPadding = paddings[1][1]; - this.outputShape = [ - topPadding + xShape[0] + bottomPadding, - leftPadding + xShape[1] + rightPadding - ]; - this.rank = 2; - var sourceCoords = "resRC.x - " + topPadding + ", resRC.y - " + leftPadding; - this.userCode = "\n void main() {\n ivec2 resRC = getOutputCoords();\n int topShape = " + topPadding + " + " + xShape[0] + ";\n int leftShape = " + leftPadding + " + " + xShape[1] + ";\n if (resRC.x < " + topPadding + " || resRC.x >= topShape ||\n resRC.y < " + leftPadding + " || resRC.y >= leftShape) {\n setOutput(float(" + constantValue + "));\n } else {\n setOutput(getX(" + sourceCoords + "));\n }\n }\n "; - } - return Pad2DProgram; -}()); -exports.Pad2DProgram = Pad2DProgram; - -},{}],93:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Pool2DProgram = (function () { - function Pool2DProgram(convInfo, poolType, computePositions) { - this.variableNames = ['x']; - if (poolType === 'avg' && computePositions) { - throw new Error('Cannot compute positions for average pool.'); - } - var filterHeight = convInfo.filterHeight; - var filterWidth = convInfo.filterWidth; - var strideHeight = convInfo.strideHeight; - var strideWidth = convInfo.strideWidth; - var padTop = convInfo.padInfo.top; - var padLeft = convInfo.padInfo.left; - this.outputShape = convInfo.outShape; - var isAvgPool = poolType === 'avg'; - var initializationValue = '0.0'; - if (!isAvgPool) { - if (poolType === 'min') { - initializationValue = '1.0 / 0.0'; - } - else { - initializationValue = '-1.0 / 0.0'; - } - } - if (computePositions) { - var compareOp_1 = poolType === 'min' ? '<=' : '>='; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n float avgValue = 0.0;\n\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidth + "; wC++) {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n continue;\n }\n\n float value = getX(batch, xR, xC, d);\n\n if (isNaN(value)) {\n setOutput(value);\n return;\n }\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value " + compareOp_1 + " currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = wR * " + filterWidth + " + wC;\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n "; - return; - } - var compareOp = poolType === 'min' ? 'min' : 'max'; - var returnValue = poolType + "(" + poolType + "(" + poolType + "(" + - 'minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])'; - if (poolType === 'avg') { - returnValue = "avgValue / " + filterHeight * filterWidth + ".0"; - } - var filterWidthNearestVec4 = Math.floor(filterWidth / 4) * 4; - var filterWidthVec4Remainder = filterWidth % 4; - var updateSnippet = "\n if (hasNaN(values)) {\n setOutput(getNaN(values));\n return;\n }\n if (" + isAvgPool + ") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = " + compareOp + "(values, minMaxValue);\n }\n "; - this.userCode = "\n const ivec2 strides = ivec2(" + strideHeight + ", " + strideWidth + ");\n const ivec2 pads = ivec2(" + padTop + ", " + padLeft + ");\n const float initializationValue = " + initializationValue + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int xR, int xC, int d) {\n if (xC < 0 || xC >= " + convInfo.inWidth + ") {\n return initializationValue;\n }\n return getX(batch, xR, xC, d);\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n vec4 minMaxValue = vec4(" + initializationValue + ");\n float avgValue = 0.0;\n\n for (int wR = 0; wR < " + filterHeight + "; wR++) {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= " + convInfo.inHeight + ") {\n continue;\n }\n\n for (int wC = 0; wC < " + filterWidthNearestVec4 + "; wC += 4) {\n int xC = xCCorner + wC;\n\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n getValue(batch, xR, xC + 2, d),\n getValue(batch, xR, xC + 3, d)\n );\n\n " + updateSnippet + "\n }\n\n int xC = xCCorner + " + filterWidthNearestVec4 + ";\n if (" + (filterWidthVec4Remainder === 1) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n initializationValue,\n initializationValue,\n initializationValue\n );\n " + updateSnippet + "\n } else if (" + (filterWidthVec4Remainder === 2) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n initializationValue,\n initializationValue\n );\n\n " + updateSnippet + "\n } else if (" + (filterWidthVec4Remainder === 3) + ") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + 1, d),\n getValue(batch, xR, xC + 2, d),\n initializationValue\n );\n\n " + updateSnippet + "\n }\n }\n setOutput(" + returnValue + ");\n }\n "; - } - return Pool2DProgram; -}()); -exports.Pool2DProgram = Pool2DProgram; - -},{}],94:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ReduceProgram = (function () { - function ReduceProgram(reduceInfo, reduceType) { - this.variableNames = ['x']; - var windowSize = reduceInfo.windowSize; - var batchSize = reduceInfo.batchSize; - var inSize = reduceInfo.inSize; - var outSize = Math.ceil(inSize / windowSize); - this.outputShape = [batchSize, outSize]; - var isReduceSum = reduceType === 'sum'; - var initializationValue = '0.0'; - if (!isReduceSum) { - if (reduceType === 'min') { - initializationValue = '1.0 / 0.0'; - } - else { - initializationValue = '-1.0 / 0.0'; - } - } - var compareOp = reduceType === 'min' ? 'min' : 'max'; - var returnValue = reduceType + "(" + reduceType + "(" + reduceType + "(" + - 'minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])'; - if (reduceType === 'sum') { - returnValue = "sumValue"; - } - var windowSizeNearestVec4 = Math.floor(windowSize / 4) * 4; - var windowSizeVec4Remainder = windowSize % 4; - var updateSnippet = "\n if (" + isReduceSum + ") {\n sumValue += dot(values, ones);\n } else {\n if (hasNaN(values)) {\n setOutput(getNaN(values));\n return;\n }\n minMaxValue = " + compareOp + "(values, minMaxValue);\n }\n "; - var checkOutOfBounds = ''; - if (inSize % windowSize > 0) { - checkOutOfBounds = "\n if (inIdx < 0 || inIdx >= " + inSize + ") {\n return initializationValue;\n }\n "; - } - this.userCode = "\n const float initializationValue = " + initializationValue + ";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int inIdx) {\n " + checkOutOfBounds + "\n return getX(batch, inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * " + windowSize + ";\n\n vec4 minMaxValue = vec4(" + initializationValue + ");\n float sumValue = 0.0;\n\n for (int i = 0; i < " + windowSizeNearestVec4 + "; i += 4) {\n int inIdx = inOffset + i;\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n " + updateSnippet + "\n }\n\n int inIdx = inOffset + " + windowSizeNearestVec4 + ";\n if (" + (windowSizeVec4Remainder === 1) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n " + updateSnippet + "\n } else if (" + (windowSizeVec4Remainder === 2) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n " + updateSnippet + "\n } else if (" + (windowSizeVec4Remainder === 3) + ") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n " + updateSnippet + "\n }\n setOutput(" + returnValue + ");\n }\n "; - } - return ReduceProgram; -}()); -exports.ReduceProgram = ReduceProgram; - -},{}],95:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ResizeBilinearProgram = (function () { - function ResizeBilinearProgram(inputShape, newHeight, newWidth, alignCorners) { - this.variableNames = ['A']; - this.outputShape = []; - var batch = inputShape[0], oldHeight = inputShape[1], oldWidth = inputShape[2], depth = inputShape[3]; - this.outputShape = [batch, newHeight, newWidth, depth]; - var effectiveInSize = alignCorners ? [oldHeight - 1, oldWidth - 1] : [oldHeight, oldWidth]; - var effectiveOutSize = alignCorners ? [newHeight - 1, newWidth - 1] : [newHeight, newWidth]; - this.userCode = "\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n " + effectiveInSize[0] / effectiveOutSize[0] + ",\n " + effectiveInSize[1] / effectiveOutSize[1] + ");\n const vec2 inputShapeRC = vec2(" + oldHeight + ".0, " + oldWidth + ".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);\n ivec2 sourceCeilRC = ivec2(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);\n float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);\n float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);\n float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);\n\n vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);\n\n float top = topLeft + (topRight - topLeft) * fracRC.y;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;\n float newValue = top + (bottom - top) * fracRC.x;\n\n setOutput(newValue);\n }\n "; - } - return ResizeBilinearProgram; -}()); -exports.ResizeBilinearProgram = ResizeBilinearProgram; - -},{}],96:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var ReverseProgram = (function () { - function ReverseProgram(xShape, axis) { - this.variableNames = ['x']; - this.outputShape = xShape; - var getRevVar = function (i) { - if (axis.indexOf(i) !== -1 && xShape[i] !== 1) { - return xShape[i] + " - coords[" + i + "] - 1"; - } - return "coords[" + i + "]"; - }; - var b = getRevVar(0); - var r = getRevVar(1); - var c = getRevVar(2); - var d = getRevVar(3); - this.userCode = "\n void main() {\n ivec4 coords = getOutputCoords();\n float val = getX(" + b + ", " + r + ", " + c + ", " + d + ");\n setOutput(val);\n }\n "; - } - return ReverseProgram; -}()); -exports.ReverseProgram = ReverseProgram; - -},{}],97:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../../environment"); -var util = require("../../util"); -var broadcast_util = require("../../ops/broadcast_util"); -var tex_util = require("./tex_util"); -function makeShader(inputsInfo, outputShape, userCode, broadcast) { - var sampleSnippet = getSampleSnippet(); - var setOutputSnippet = getSetOutputSnippet(); - var inputPrefixSnippet = inputsInfo.map(function (x) { return "uniform sampler2D " + x.name + ";"; }).join('\n'); - var inputSamplingSnippet = inputsInfo.map(function (x) { return getInputSamplingSnippet(x, outputShape, broadcast); }) - .join('\n'); - var outTexShape = outputShape.texShape; - var outputSamplingSnippet = getOutputSamplingSnippet(outputShape.logicalShape, outTexShape); - var source = [ - SHADER_PREFIX, sampleSnippet, setOutputSnippet, inputPrefixSnippet, - outputSamplingSnippet, inputSamplingSnippet, userCode - ].join('\n'); - return source; -} -exports.makeShader = makeShader; -function getSampleSnippet() { - return environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED') ? - FLOAT_TEXTURE_SAMPLE_SNIPPET : - UNSIGNED_BYTE_TEXTURE_SAMPLE_SNIPPET; -} -function getSetOutputSnippet() { - return environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED') ? - FLOAT_TEXTURE_SETOUTPUT_SNIPPET : - UNSIGNED_BYTE_TEXTURE_SETOUTPUT_SNIPPET; -} -function getSamplerFromInInfo(inInfo) { - var shape = inInfo.shapeInfo.logicalShape; - switch (shape.length) { - case 0: - return getSamplerScalar(inInfo); - case 1: - return getSampler1D(inInfo); - case 2: - return getSampler2D(inInfo); - case 3: - return getSampler3D(inInfo); - case 4: - return getSampler4D(inInfo); - default: - throw new Error(shape.length + "-D input sampling" + - " is not yet supported"); - } -} -function getInputSamplingSnippet(inInfo, outShapeInfo, broadcast) { - var res = getSamplerFlat(inInfo); - res += getSamplerFromInInfo(inInfo); - if (broadcast || - util.arraysEqual(inInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape)) { - res += getSamplerAtOutputCoords(inInfo, outShapeInfo, broadcast); - } - return res; -} -function getOutputSamplingSnippet(outShape, outTexShape) { - switch (outShape.length) { - case 0: - return getOutputScalarCoords(); - case 1: - return getOutput1DCoords(outShape, outTexShape); - case 2: - return getOutput2DCoords(outShape, outTexShape); - case 3: - return getOutput3DCoords(outShape, outTexShape); - case 4: - return getOutput4DCoords(outShape, outTexShape); - default: - throw new Error(outShape.length + "-D output sampling is not yet supported"); - } -} -var SAMPLE_1D_SNIPPET = "\nvec2 UVfrom1D(int texNumR, int texNumC, int index) {\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var SAMPLE_2D_SNIPPET = "\nvec2 UVfrom2D(int texNumR, int texNumC, int numC, int row, int col) {\n int index = row * numC + col;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var SAMPLE_3D_SNIPPET = "\nvec2 UVfrom3D(int texNumR, int texNumC, int stride0,\n int stride1, int row, int col, int depth) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var SAMPLE_4D_SNIPPET = "\nvec2 UVfrom4D(int texNumR, int texNumC, int stride0,\n int stride1, int stride2, int row, int col, int depth,\n int depth2) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * stride0 + col * stride1 + depth * stride2 + depth2;\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n"; -var UNSIGNED_BYTE_TEXTURE_SAMPLE_SNIPPET = "\n uniform float NaN;\n\n const vec4 floatDeltas = vec4(\n 1.0,\n 1.0 / 255.0,\n 1.0 / (255.0 * 255.0),\n 1.0 / (255.0 * 255.0 * 255.0)\n );\n const float minValue = " + tex_util.FLOAT_MIN + ".0;\n const float maxValue = " + tex_util.FLOAT_MAX + ".0;\n const float range = (maxValue - minValue) / 255.0;\n const vec2 dotRange = vec2(1.0, range);\n\n float sample(sampler2D texture, vec2 uv) {\n vec4 sampleValue = texture2D(texture, uv);\n if (all(equal(sampleValue, vec4(" + tex_util.BYTE_NAN_VALUE + ")))) {\n return NaN;\n }\n\n vec4 encValue = floor(sampleValue * 255.0 + 0.5);\n float decodedValue = dot(encValue, floatDeltas);\n return dot(vec2(minValue, decodedValue), dotRange);\n }\n"; -var UNSIGNED_BYTE_TEXTURE_SETOUTPUT_SNIPPET = "\n const vec4 floatPowers = vec4(\n 1.0,\n 255.0,\n 255.0 * 255.0,\n 255.0 * 255.0 * 255.0\n );\n const vec2 recipRange = vec2(1.0/range);\n const vec2 recipRange255 = vec2(1.0/(maxValue - minValue));\n\n void setOutput(float decodedValue) {\n if (isNaN(decodedValue)) {\n gl_FragColor = vec4(" + tex_util.BYTE_NAN_VALUE + ");\n return;\n }\n\n float a = dot(vec2(decodedValue, -minValue), recipRange);\n float b = fract(a) * 255.0;\n float c = fract(b) * 255.0;\n float d = fract(c) * 255.0;\n gl_FragColor = floor(vec4(a, b, c, d)) / 255.0;\n\n // TODO(dsmilkov): Version above gets better accuracy but probably slower\n // than the version below. Benchmark to determine if the accuracy is worth\n // the cost.\n\n // float normValue = dot(vec2(decodedValue, -minValue), recipRange255);\n // vec4 f = normValue * floatPowers;\n // gl_FragColor = floor(fract(f) * 255.0) / 255.0;\n }\n"; -var FLOAT_TEXTURE_SAMPLE_SNIPPET = "\n float sample(sampler2D texture, vec2 uv) {\n return texture2D(texture, uv).r;\n }\n"; -var FLOAT_TEXTURE_SETOUTPUT_SNIPPET = "\n void setOutput(float val) {\n gl_FragColor = vec4(val, 0, 0, 0);\n }\n"; -var SHADER_PREFIX = "\n precision highp float;\n precision highp int;\n varying vec2 resultUV;\n const vec2 halfCR = vec2(0.5, 0.5);\n\n bool isNaN(float val) {\n float v1 = val * val;\n float v2 = val * val;\n return v1 == v2 ? false : true;\n }\n\n bool hasNaN(vec4 values) {\n vec4 v1 = values * values;\n vec4 v2 = values * values;\n return any(notEqual(v1, v2));\n }\n\n float getNaN(vec4 values) {\n return dot(vec4(1), values);\n }\n\n int round(float value) {\n return int(floor(value + 0.5));\n }\n\n int imod(int x, int y) {\n return x - y * (x / y);\n }\n\n const vec2 randomConst = vec2(\n 23.14069263277926, // e^pi (Gelfond's constant)\n 2.665144142690225 // 2^sqrt(2) (Gelfond\u2013Schneider constant)\n );\n\n float random(float seed) {\n return fract(cos(dot(resultUV * seed, randomConst)) * 12345.6789);\n }\n\n " + SAMPLE_1D_SNIPPET + "\n " + SAMPLE_2D_SNIPPET + "\n " + SAMPLE_3D_SNIPPET + "\n " + SAMPLE_4D_SNIPPET + "\n"; -function getOutputScalarCoords() { - return "\n int getOutputCoords() {\n return 0;\n }\n "; -} -function getOutput1DCoords(shape, texShape) { - if (texShape[0] === 1) { - return "\n int getOutputCoords() {\n return int(resultUV.x * " + texShape[1] + ".0);\n }\n "; - } - if (texShape[1] === 1) { - return "\n int getOutputCoords() {\n return int(resultUV.y * " + texShape[0] + ".0);\n }\n "; - } - return "\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n return resTexRC.x * " + texShape[1] + " + resTexRC.y;\n }\n "; -} -function getOutput3DCoords(shape, texShape) { - var stride0 = shape[1] * shape[2]; - var stride1 = shape[2]; - return "\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n int r = index / " + stride0 + ";\n index -= r * " + stride0 + ";\n int c = index / " + stride1 + ";\n int d = index - c * " + stride1 + ";\n return ivec3(r, c, d);\n }\n "; -} -function getOutput4DCoords(shape, texShape) { - var stride2 = shape[3]; - var stride1 = shape[2] * stride2; - var stride0 = shape[1] * stride1; - return "\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n\n int r = index / " + stride0 + ";\n index -= r * " + stride0 + ";\n\n int c = index / " + stride1 + ";\n index -= c * " + stride1 + ";\n\n int d = index / " + stride2 + ";\n int d2 = index - d * " + stride2 + ";\n\n return ivec4(r, c, d, d2);\n }\n "; -} -function getOutput2DCoords(shape, texShape) { - if (util.arraysEqual(shape, texShape)) { - return "\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2(" + texShape[0] + ", " + texShape[1] + "));\n }\n "; - } - if (shape[1] === 1) { - return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n return ivec2(index, 0);\n }\n "; - } - if (shape[0] === 1) { - return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n return ivec2(0, index);\n }\n "; - } - return "\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + texShape[0] + ", " + texShape[1] + "));\n int index = resTexRC.x * " + texShape[1] + " + resTexRC.y;\n int r = index / " + shape[1] + ";\n int c = index - r * " + shape[1] + ";\n return ivec2(r, c);\n }\n "; -} -function getSamplerScalar(inputInfo) { - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - return "\n float " + funcName + "() {\n return sample(" + texName + ", halfCR);\n }\n "; -} -function getSampler1D(inputInfo) { - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - return "\n float " + funcName + "(int index) {\n return " + funcName + "Flat(index);\n }\n "; -} -function getSampler2D(inputInfo) { - var shape = inputInfo.shapeInfo.logicalShape; - var texShape = inputInfo.shapeInfo.texShape; - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - var texNumR = texShape[0]; - var texNumC = texShape[1]; - if (util.arraysEqual(shape, texShape)) { - return "\n float " + funcName + "(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims; - var squeezedShape = newShape; - if (squeezedShape.length < shape.length) { - var newInputInfo = squeezeInputInfo(inputInfo, squeezedShape); - var params = ['row', 'col']; - return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n "; - } - if (texNumC === 1) { - return "\n float " + funcName + "(int row, int col) {\n int index = row * " + shape[1] + " + col;\n vec2 uv = vec2(0.5, (float(index) + 0.5) / " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (texNumR === 1) { - return "\n float " + funcName + "(int row, int col) {\n int index = row * " + shape[1] + " + col;\n vec2 uv = vec2((float(index) + 0.5) / " + texNumC + ".0, 0.5);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int row, int col) {\n vec2 uv = UVfrom2D(" + texNumR + ", " + texNumC + ", " + shape[1] + ", row, col);\n return sample(" + texName + ", uv);\n }\n"; -} -function getSampler3D(inputInfo) { - var texShape = inputInfo.shapeInfo.texShape; - var shape = inputInfo.shapeInfo.logicalShape; - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - var texNumR = texShape[0]; - var texNumC = texShape[1]; - var stride0 = shape[1] * shape[2]; - var stride1 = shape[2]; - var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims; - var squeezedShape = newShape; - if (squeezedShape.length < shape.length) { - var newInputInfo = squeezeInputInfo(inputInfo, squeezedShape); - var params = ['row', 'col', 'depth']; - return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col, int depth) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n "; - } - if (texNumC === stride0) { - return "\n float " + funcName + "(int row, int col, int depth) {\n int texR = row;\n int texC = col * " + stride1 + " + depth;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (texNumC === stride1) { - return "\n float " + funcName + "(int row, int col, int depth) {\n int texR = row * " + shape[1] + " + col;\n int texC = depth;\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int row, int col, int depth) {\n vec2 uv = UVfrom3D(\n " + texNumR + ", " + texNumC + ", " + stride0 + ", " + stride1 + ", row, col, depth);\n return sample(" + texName + ", uv);\n }\n "; -} -function getSampler4D(inputInfo) { - var shape = inputInfo.shapeInfo.logicalShape; - var texShape = inputInfo.shapeInfo.texShape; - var texName = inputInfo.name; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1); - var texNumR = texShape[0]; - var texNumC = texShape[1]; - var stride2 = shape[3]; - var stride1 = shape[2] * stride2; - var stride0 = shape[1] * stride1; - var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims; - if (newShape.length < shape.length) { - var newInputInfo = squeezeInputInfo(inputInfo, newShape); - var params = ['row', 'col', 'depth', 'depth2']; - return "\n " + getSamplerFromInInfo(newInputInfo) + "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n return " + funcName + "(" + getSqueezedParams(params, keptDims) + ");\n }\n "; - } - if (texNumC === stride0) { - return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n int texR = row;\n int texC = col * " + stride1 + " + depth * " + stride2 + " + depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (texNumC === stride2) { - return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n int texR = row * " + shape[1] * shape[2] + " + col * " + shape[2] + " + depth;\n int texC = depth2;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + texNumC + ".0, " + texNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int row, int col, int depth, int depth2) {\n vec2 uv = UVfrom4D(" + texNumR + ", " + texNumC + ", " + stride0 + ", " + stride1 + ",\n " + stride2 + ", row, col, depth, depth2);\n return sample(" + texName + ", uv);\n }\n "; -} -function getSamplerFlat(inputInfo) { - var texName = inputInfo.name; - var texShape = inputInfo.shapeInfo.texShape; - var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1) + 'Flat'; - var tNumR = texShape[0]; - var tNumC = texShape[1]; - if (tNumC === 1 && tNumR === 1) { - return "\n float " + funcName + "(int index) {\n return sample(" + texName + ", halfCR);\n }\n "; - } - if (tNumC === 1) { - return "\n float " + funcName + "(int index) {\n vec2 uv = vec2(0.5, (float(index) + 0.5) / " + tNumR + ".0);\n return sample(" + texName + ", uv);\n }\n "; - } - if (tNumR === 1) { - return "\n float " + funcName + "(int index) {\n vec2 uv = vec2((float(index) + 0.5) / " + tNumC + ".0, 0.5);\n return sample(" + texName + ", uv);\n }\n "; - } - return "\n float " + funcName + "(int index) {\n vec2 uv = UVfrom1D(" + tNumR + ", " + tNumC + ", index);\n return sample(" + texName + ", uv);\n }\n "; -} -function getBroadcastOutputCoordsSampler(inputInfo, outShapeInfo, texFuncSnippet, funcName) { - var inRank = inputInfo.shapeInfo.logicalShape.length; - var outRank = outShapeInfo.logicalShape.length; - var type = 'int'; - if (outRank === 2) { - type = 'ivec2'; - } - else if (outRank === 3) { - type = 'ivec3'; - } - else if (outRank === 4) { - type = 'ivec4'; - } - var broadcastDims = broadcast_util.getBroadcastDims(inputInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape); - var rankDiff = outRank - inRank; - var coordsSnippet; - if (inRank === 0) { - coordsSnippet = ''; - } - else if (outRank < 2 && broadcastDims.length >= 1) { - coordsSnippet = 'coords = 0;'; - } - else { - coordsSnippet = - broadcastDims.map(function (d) { return "coords[" + (d + rankDiff) + "] = 0;"; }).join('\n'); - } - var unpackedCoordsSnippet = ''; - if (outRank < 2 && inRank > 0) { - unpackedCoordsSnippet = 'coords'; - } - else { - unpackedCoordsSnippet = inputInfo.shapeInfo.logicalShape - .map(function (s, i) { return "coords[" + (i + rankDiff) + "]"; }) - .join(', '); - } - return "\n float " + funcName + "() {\n " + type + " coords = getOutputCoords();\n " + coordsSnippet + "\n return get" + texFuncSnippet + "(" + unpackedCoordsSnippet + ");\n }\n "; -} -function getSamplerAtOutputCoords(inputInfo, outShapeInfo, supportsBroadcasting) { - var inTexShape = inputInfo.shapeInfo.texShape; - var texName = inputInfo.name; - var texFuncSnippet = texName.charAt(0).toUpperCase() + texName.slice(1); - var funcName = 'get' + texFuncSnippet + 'AtOutCoords'; - var broadcastDims = broadcast_util.getBroadcastDims(inputInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape); - var inRank = inputInfo.shapeInfo.logicalShape.length; - var outRank = outShapeInfo.logicalShape.length; - var doBroadcast = supportsBroadcasting && ((outRank > inRank) || broadcastDims.length > 0); - var broadcastOverOuter = broadcast_util.broadcastDimsAreOuter(broadcastDims); - if (doBroadcast && !broadcastOverOuter) { - return getBroadcastOutputCoordsSampler(inputInfo, outShapeInfo, texFuncSnippet, funcName); - } - var outTexShape = outShapeInfo.texShape; - if (util.arraysEqual(inTexShape, outTexShape)) { - return "\n float " + funcName + "() {\n return sample(" + texName + ", resultUV);\n }\n "; - } - var inSize = util.sizeFromShape(inTexShape); - var broadcastSnippet = ''; - if (doBroadcast && broadcastOverOuter) { - broadcastSnippet = "\n int mainPart = index / " + inSize + ";\n index -= mainPart * " + inSize + ";\n "; - } - return "\n float " + funcName + "() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2(" + outTexShape[0] + ", " + outTexShape[1] + "));\n int index = resTexRC.x * " + outTexShape[1] + " + resTexRC.y;\n " + broadcastSnippet + "\n int texR = index / " + inTexShape[1] + ";\n int texC = index - texR * " + inTexShape[1] + ";\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2(" + inTexShape[1] + ".0, " + inTexShape[0] + ".0);\n\n return sample(" + texName + ", uv);\n }\n "; -} -function getCoordsDataType(rank) { - if (rank <= 1) { - return 'int'; - } - else if (rank === 2) { - return 'ivec2'; - } - else if (rank === 3) { - return 'ivec3'; - } - else if (rank === 4) { - return 'ivec4'; - } - else { - throw Error("GPU for rank " + rank + " is not yet supported"); - } -} -exports.getCoordsDataType = getCoordsDataType; -function squeezeInputInfo(inInfo, squeezedShape) { - var newInputInfo = JSON.parse(JSON.stringify(inInfo)); - newInputInfo.shapeInfo.logicalShape = squeezedShape; - return newInputInfo; -} -function getSqueezedParams(params, keptDims) { - return keptDims.map(function (d) { return params[d]; }).join(', '); -} - -},{"../../environment":34,"../../ops/broadcast_util":110,"../../util":151,"./tex_util":99}],98:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var SliceProgram = (function () { - function SliceProgram(destSize) { - this.variableNames = ['source']; - this.outputShape = destSize; - this.rank = destSize.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var sourceCoords = getCoords(this.rank); - this.userCode = "\n uniform " + dtype + " start;\n\n void main() {\n " + dtype + " sourceLoc = start + getOutputCoords();\n setOutput(getSource(" + sourceCoords + "));\n }\n "; - } - SliceProgram.prototype.getCustomSetupFunc = function (start) { - var _this = this; - if (start.length !== this.rank) { - throw Error("The rank (" + this.rank + ") of the program must match the " + - ("length of start (" + start.length + ")")); - } - return function (gpgpu, webGLProgram) { - if (_this.startLoc == null) { - _this.startLoc = gpgpu.getUniformLocationNoThrow(webGLProgram, 'start'); - if (_this.startLoc == null) { - return; - } - } - if (_this.rank === 1) { - gpgpu.gl.uniform1i(_this.startLoc, start[0]); - } - else if (_this.rank === 2) { - gpgpu.gl.uniform2i(_this.startLoc, start[0], start[1]); - } - else if (_this.rank === 3) { - gpgpu.gl.uniform3i(_this.startLoc, start[0], start[1], start[2]); - } - else if (_this.rank === 4) { - gpgpu.gl.uniform4i(_this.startLoc, start[0], start[1], start[2], start[3]); - } - else { - throw Error("Slicing for rank " + _this.rank + " is not yet supported"); - } - }; - }; - return SliceProgram; -}()); -exports.SliceProgram = SliceProgram; -function getCoords(rank) { - if (rank === 1) { - return 'sourceLoc'; - } - else if (rank === 2) { - return 'sourceLoc.x, sourceLoc.y'; - } - else if (rank === 3) { - return 'sourceLoc.x, sourceLoc.y, sourceLoc.z'; - } - else if (rank === 4) { - return 'sourceLoc.x, sourceLoc.y, sourceLoc.z, sourceLoc.w'; - } - else { - throw Error("Slicing for rank " + rank + " is not yet supported"); - } -} - -},{"./shader_compiler":97}],99:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var TextureType; -(function (TextureType) { - TextureType[TextureType["FLOAT"] = 0] = "FLOAT"; - TextureType[TextureType["UNSIGNED_BYTE"] = 1] = "UNSIGNED_BYTE"; -})(TextureType = exports.TextureType || (exports.TextureType = {})); -function getUnpackedMatrixTextureShapeWidthHeight(rows, columns) { - return [columns, rows]; -} -exports.getUnpackedMatrixTextureShapeWidthHeight = getUnpackedMatrixTextureShapeWidthHeight; -function getUnpackedArraySizeFromMatrixSize(matrixSize, channelsPerTexture) { - return matrixSize * channelsPerTexture; -} -exports.getUnpackedArraySizeFromMatrixSize = getUnpackedArraySizeFromMatrixSize; -function getColorMatrixTextureShapeWidthHeight(rows, columns) { - return [columns * 4, rows]; -} -exports.getColorMatrixTextureShapeWidthHeight = getColorMatrixTextureShapeWidthHeight; -function getMatrixSizeFromUnpackedArraySize(unpackedSize, channelsPerTexture) { - if (unpackedSize % channelsPerTexture !== 0) { - throw new Error("unpackedSize (" + unpackedSize + ") must be a multiple of " + - ("" + channelsPerTexture)); - } - return unpackedSize / channelsPerTexture; -} -exports.getMatrixSizeFromUnpackedArraySize = getMatrixSizeFromUnpackedArraySize; -function encodeMatrixToUnpackedArray(matrix, unpackedArray, channelsPerTexture) { - var requiredSize = getUnpackedArraySizeFromMatrixSize(matrix.length, channelsPerTexture); - if (unpackedArray.length < requiredSize) { - throw new Error("unpackedArray length (" + unpackedArray.length + ") must be >= " + - ("" + requiredSize)); - } - var dst = 0; - for (var src = 0; src < matrix.length; ++src) { - unpackedArray[dst] = matrix[src]; - dst += channelsPerTexture; - } -} -exports.encodeMatrixToUnpackedArray = encodeMatrixToUnpackedArray; -exports.FLOAT_MAX = 20000; -exports.FLOAT_MIN = -exports.FLOAT_MAX; -var FLOAT_RANGE = (exports.FLOAT_MAX - exports.FLOAT_MIN) / 255; -var FLOAT_DELTAS = [1, 1 / 255, 1 / (255 * 255), 1 / (255 * 255 * 255)]; -var FLOAT_POWERS = [1, 255, 255 * 255]; -exports.BYTE_NAN_VALUE = 0; -function encodeFloatArray(floatArray) { - var uintArray = new Uint8Array(floatArray.length * 4); - var _loop_1 = function (i) { - var value = floatArray[i / 4]; - if (isNaN(value)) { - uintArray[i] = exports.BYTE_NAN_VALUE; - uintArray[i + 1] = exports.BYTE_NAN_VALUE; - uintArray[i + 2] = exports.BYTE_NAN_VALUE; - uintArray[i + 3] = exports.BYTE_NAN_VALUE; - return "continue"; - } - var normalizedValue = (value - exports.FLOAT_MIN) / FLOAT_RANGE; - var enc = FLOAT_POWERS.map(function (pow) { return pow * normalizedValue; }); - var buckets = enc.map(function (value) { return Math.floor((value % 1) * 255); }); - uintArray[i] = Math.floor(normalizedValue); - uintArray[i + 1] = buckets[0]; - uintArray[i + 2] = buckets[1]; - uintArray[i + 3] = buckets[2]; - }; - for (var i = 0; i < uintArray.length; i += 4) { - _loop_1(i); - } - return uintArray; -} -exports.encodeFloatArray = encodeFloatArray; -function decodeToFloatArray(uintArray) { - var floatArray = new Float32Array(uintArray.length / 4); - var _loop_2 = function (i) { - if (uintArray[i] === exports.BYTE_NAN_VALUE && - uintArray[i + 1] === exports.BYTE_NAN_VALUE && - uintArray[i + 2] === exports.BYTE_NAN_VALUE && - uintArray[i + 3] === exports.BYTE_NAN_VALUE) { - floatArray[i / 4] = NaN; - return "continue"; - } - var dot = 0; - FLOAT_DELTAS.forEach(function (delta, j) { - dot += delta * uintArray[i + j]; - }); - var value = dot * FLOAT_RANGE + exports.FLOAT_MIN; - floatArray[i / 4] = value; - }; - for (var i = 0; i < uintArray.length; i += 4) { - _loop_2(i); - } - return floatArray; -} -exports.decodeToFloatArray = decodeToFloatArray; -function decodeMatrixFromUnpackedArray(unpackedArray, matrix, channelsPerTexture) { - var requiredSize = getMatrixSizeFromUnpackedArraySize(unpackedArray.length, channelsPerTexture); - if (matrix.length < requiredSize) { - throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize); - } - var dst = 0; - for (var src = 0; src < unpackedArray.length; src += channelsPerTexture) { - matrix[dst++] = unpackedArray[src]; - } -} -exports.decodeMatrixFromUnpackedArray = decodeMatrixFromUnpackedArray; -function decodeMatrixFromUnpackedColorRGBAArray(unpackedArray, matrix, channels) { - var requiredSize = unpackedArray.length * channels / 4; - if (matrix.length < requiredSize) { - throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize); - } - var dst = 0; - for (var src = 0; src < unpackedArray.length; src += 4) { - for (var c = 0; c < channels; c++) { - matrix[dst++] = unpackedArray[src + c]; - } - } -} -exports.decodeMatrixFromUnpackedColorRGBAArray = decodeMatrixFromUnpackedColorRGBAArray; -function getPackedMatrixTextureShapeWidthHeight(rows, columns) { - return [Math.ceil(columns / 2), Math.ceil(rows / 2)]; -} -exports.getPackedMatrixTextureShapeWidthHeight = getPackedMatrixTextureShapeWidthHeight; -function getPackedRGBAArraySizeFromMatrixShape(rows, columns) { - var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1]; - return w * h * 4; -} -exports.getPackedRGBAArraySizeFromMatrixShape = getPackedRGBAArraySizeFromMatrixShape; -function encodeMatrixToPackedRGBA(matrix, rows, columns, packedRGBA) { - var requiredSize = getPackedRGBAArraySizeFromMatrixShape(rows, columns); - if (packedRGBA.length < requiredSize) { - throw new Error("packedRGBA length (" + packedRGBA.length + ") must be >= " + requiredSize); - } - var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), textureWidth = _a[0], textureHeight = _a[1]; - var oddWidth = (columns % 2) === 1; - var oddHeight = (rows % 2) === 1; - var widthInFullBlocks = Math.floor(columns / 2); - var heightInFullBlocks = Math.floor(rows / 2); - { - var dstStride = (oddWidth ? 4 : 0); - var oneRow = columns; - var dst = 0; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - var matrixSrcRow = (blockY * 2 * columns); - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - var matrixSrcCol = blockX * 2; - var src = matrixSrcRow + matrixSrcCol; - packedRGBA[dst] = matrix[src]; - packedRGBA[dst + 1] = matrix[src + 1]; - packedRGBA[dst + 2] = matrix[src + oneRow]; - packedRGBA[dst + 3] = matrix[src + oneRow + 1]; - dst += 4; - } - dst += dstStride; - } - } - if (oddWidth) { - var src = columns - 1; - var dst = (textureWidth - 1) * 4; - var srcStride = 2 * columns; - var dstStride = textureWidth * 4; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - packedRGBA[dst] = matrix[src]; - packedRGBA[dst + 2] = matrix[src + columns]; - src += srcStride; - dst += dstStride; - } - } - if (oddHeight) { - var src = (rows - 1) * columns; - var dst = (textureHeight - 1) * textureWidth * 4; - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - packedRGBA[dst++] = matrix[src++]; - packedRGBA[dst++] = matrix[src++]; - dst += 2; - } - } - if (oddWidth && oddHeight) { - packedRGBA[packedRGBA.length - 4] = matrix[matrix.length - 1]; - } - return packedRGBA; -} -exports.encodeMatrixToPackedRGBA = encodeMatrixToPackedRGBA; -function decodeMatrixFromPackedRGBA(packedRGBA, rows, columns, matrix) { - var requiredSize = rows * columns; - if (requiredSize < matrix.length) { - throw new Error("matrix length (" + matrix.length + ") must be >= " + requiredSize); - } - var oddWidth = (columns % 2) === 1; - var oddHeight = (rows % 2) === 1; - var widthInFullBlocks = Math.floor(columns / 2); - var heightInFullBlocks = Math.floor(rows / 2); - var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), textureWidth = _a[0], textureHeight = _a[1]; - { - var srcStride = oddWidth ? 4 : 0; - var dstStride = columns + (oddWidth ? 1 : 0); - var src = 0; - var dstRow1 = 0; - var dstRow2 = columns; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - matrix[dstRow1++] = packedRGBA[src++]; - matrix[dstRow1++] = packedRGBA[src++]; - matrix[dstRow2++] = packedRGBA[src++]; - matrix[dstRow2++] = packedRGBA[src++]; - } - src += srcStride; - dstRow1 += dstStride; - dstRow2 += dstStride; - } - } - if (oddWidth) { - var src = (textureWidth - 1) * 4; - var dst = columns - 1; - var srcStride = textureWidth * 4; - var dstStride = 2 * columns; - for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) { - matrix[dst] = packedRGBA[src]; - matrix[dst + columns] = packedRGBA[src + 2]; - src += srcStride; - dst += dstStride; - } - } - if (oddHeight) { - var src = (textureHeight - 1) * textureWidth * 4; - var dst = (rows - 1) * columns; - for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) { - matrix[dst++] = packedRGBA[src++]; - matrix[dst++] = packedRGBA[src++]; - src += 2; - } - } - if (oddWidth && oddHeight) { - matrix[matrix.length - 1] = packedRGBA[packedRGBA.length - 4]; - } - return matrix; -} -exports.decodeMatrixFromPackedRGBA = decodeMatrixFromPackedRGBA; - -},{}],100:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tex_util_1 = require("./tex_util"); -var TextureManager = (function () { - function TextureManager(gpgpu) { - this.gpgpu = gpgpu; - this.numUsedTextures = 0; - this.numFreeTextures = 0; - this.freeTextures = {}; - this.logEnabled = false; - this.allocatedTextures = []; - this.usedTextureCount = {}; - } - TextureManager.prototype.acquireTexture = function (shapeRC, texType) { - if (texType === void 0) { texType = tex_util_1.TextureType.FLOAT; } - var shapeKey = getKeyFromTextureShape(shapeRC, texType); - if (!(shapeKey in this.freeTextures)) { - this.freeTextures[shapeKey] = []; - } - if (!(shapeKey in this.usedTextureCount)) { - this.usedTextureCount[shapeKey] = 0; - } - this.usedTextureCount[shapeKey]++; - if (this.freeTextures[shapeKey].length > 0) { - this.numFreeTextures--; - this.numUsedTextures++; - this.log(); - return this.freeTextures[shapeKey].shift(); - } - this.numUsedTextures++; - this.log(); - var newTexture = this.gpgpu.createMatrixTexture(shapeRC[0], shapeRC[1]); - this.allocatedTextures.push(newTexture); - return newTexture; - }; - TextureManager.prototype.releaseTexture = function (texture, shape, texType) { - if (texType === void 0) { texType = tex_util_1.TextureType.FLOAT; } - var shapeKey = getKeyFromTextureShape(shape, texType); - if (!(shapeKey in this.freeTextures)) { - this.freeTextures[shapeKey] = []; - } - this.freeTextures[shapeKey].push(texture); - this.numFreeTextures++; - this.numUsedTextures--; - this.usedTextureCount[shapeKey]--; - this.log(); - }; - TextureManager.prototype.log = function () { - if (!this.logEnabled) { - return; - } - var total = this.numFreeTextures + this.numUsedTextures; - console.log('Free/Used', this.numFreeTextures + " / " + this.numUsedTextures, "(" + total + ")"); - }; - TextureManager.prototype.getNumUsedTextures = function () { - return this.numUsedTextures; - }; - TextureManager.prototype.getNumFreeTextures = function () { - return this.numFreeTextures; - }; - TextureManager.prototype.dispose = function () { - var _this = this; - if (this.allocatedTextures == null) { - return; - } - this.allocatedTextures.forEach(function (texture) { - _this.gpgpu.deleteMatrixTexture(texture); - }); - this.freeTextures = null; - this.allocatedTextures = null; - this.usedTextureCount = null; - this.numUsedTextures = 0; - this.numFreeTextures = 0; - }; - return TextureManager; -}()); -exports.TextureManager = TextureManager; -function getKeyFromTextureShape(shapeRowsCol, texType) { - return shapeRowsCol[0] + "_" + shapeRowsCol[1] + "_" + texType; -} - -},{"./tex_util":99}],101:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var TileProgram = (function () { - function TileProgram(aShape, reps) { - this.variableNames = ['A']; - var outputShape = new Array(aShape.length); - for (var i = 0; i < outputShape.length; i++) { - outputShape[i] = aShape[i] * reps[i]; - } - this.outputShape = outputShape; - this.rank = outputShape.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var sourceCoords = getSourceCoords(aShape); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + sourceCoords + "));\n }\n "; - } - return TileProgram; -}()); -exports.TileProgram = TileProgram; -function getSourceCoords(aShape) { - var rank = aShape.length; - if (rank > 4) { - throw Error("Tile for rank " + rank + " is not yet supported"); - } - if (rank === 1) { - return "imod(resRC, " + aShape[0] + ")"; - } - var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var sourceCoords = []; - for (var i = 0; i < aShape.length; i++) { - sourceCoords.push("imod(" + currentCoords[i] + ", " + aShape[i] + ")"); - } - return sourceCoords.join(); -} - -},{"./shader_compiler":97}],102:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var shader_compiler_1 = require("./shader_compiler"); -var TransposeProgram = (function () { - function TransposeProgram(aShape, newDim) { - this.variableNames = ['A']; - var outputShape = new Array(aShape.length); - for (var i = 0; i < outputShape.length; i++) { - outputShape[i] = aShape[newDim[i]]; - } - this.outputShape = outputShape; - this.rank = outputShape.length; - var dtype = shader_compiler_1.getCoordsDataType(this.rank); - var switched = getSwitchedCoords(newDim); - this.userCode = "\n void main() {\n " + dtype + " resRC = getOutputCoords();\n setOutput(getA(" + switched + "));\n }\n "; - } - return TransposeProgram; -}()); -exports.TransposeProgram = TransposeProgram; -function getSwitchedCoords(newDim) { - var rank = newDim.length; - if (rank > 4) { - throw Error("Transpose for rank " + rank + " is not yet supported"); - } - var originalOrder = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w']; - var switchedCoords = new Array(rank); - for (var i = 0; i < newDim.length; i++) { - switchedCoords[newDim[i]] = originalOrder[i]; - } - return switchedCoords.join(); -} - -},{"./shader_compiler":97}],103:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var selu_util = require("../../ops/selu_util"); -var UnaryOpProgram = (function () { - function UnaryOpProgram(aShape, opSnippet) { - this.variableNames = ['A']; - this.outputShape = aShape; - this.userCode = "\n float unaryOperation(float x) {\n " + opSnippet + "\n }\n\n void main() {\n float x = getAAtOutCoords();\n float y = unaryOperation(x);\n\n setOutput(y);\n }\n "; - } - return UnaryOpProgram; -}()); -exports.UnaryOpProgram = UnaryOpProgram; -var CHECK_NAN_SNIPPET = "\n if (isNaN(x)) return x;\n"; -exports.ABS = "\n return abs(x);\n"; -exports.RELU = CHECK_NAN_SNIPPET + "\n return (x < 0.0) ? 0.0 : x;\n"; -exports.ELU = "\n return (x >= 0.0) ? x : (exp(x) - 1.0);\n"; -exports.ELU_DER = "\n return (x >= 0.0) ? 1.0 : exp(x);\n"; -exports.SELU = "\n // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.\n // see: https://arxiv.org/abs/1706.02515\n float scaleAlpha = " + selu_util.SELU_SCALEALPHA + ";\n float scale = " + selu_util.SELU_SCALE + ";\n return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\n"; -function LEAKY_RELU(alpha) { - return "\n return (x >= 0.0) ? x : " + alpha + " * x;\n "; -} -exports.LEAKY_RELU = LEAKY_RELU; -function STEP(alpha) { - if (alpha === void 0) { alpha = 0.0; } - return CHECK_NAN_SNIPPET + ("\n return x > 0.0 ? 1.0 : float(" + alpha + ");\n "); -} -exports.STEP = STEP; -exports.NEG = "\n return -x;\n"; -exports.CEIL = "\n return ceil(x);\n"; -exports.FLOOR = "\n return floor(x);\n"; -exports.EXP = "\n return exp(x);\n"; -exports.LOG = "\n return log(x);\n"; -exports.SQRT = CHECK_NAN_SNIPPET + "\n return sqrt(x);\n"; -exports.SIGMOID = "\n return 1.0 / (1.0 + exp(-1.0 * x));\n"; -exports.SIN = CHECK_NAN_SNIPPET + "\n return sin(x);\n"; -exports.COS = CHECK_NAN_SNIPPET + "\n return cos(x);\n"; -exports.TAN = "\n return tan(x);\n"; -exports.ASIN = CHECK_NAN_SNIPPET + "\n return asin(x);\n"; -exports.ACOS = CHECK_NAN_SNIPPET + "\n return acos(x);\n"; -exports.ATAN = CHECK_NAN_SNIPPET + "\n return atan(x);\n"; -exports.SINH = "\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n"; -exports.COSH = "\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n"; -exports.TANH = "\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n"; -exports.SQUARE = "\n return x * x;\n"; -exports.LOGICAL_NOT = CHECK_NAN_SNIPPET + "\n return float(!(x >= 1.0));\n"; -exports.TO_INT = "\n return float(int(x));\n"; - -},{"../../ops/selu_util":129}],104:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var MAX_TEXTURE_SIZE = null; -var util = require("../../util"); -var environment_1 = require("../../environment"); -function createWebGLRenderingContext(attributes) { - var canvas = document.createElement('canvas'); - canvas.width = 1; - canvas.height = 1; - return createWebGLRenderingContextFromCanvas(canvas, attributes); -} -exports.createWebGLRenderingContext = createWebGLRenderingContext; -function createWebGLRenderingContextFromCanvas(canvas, attributes) { - var gl; - var webglVersion = environment_1.ENV.get('WEBGL_VERSION'); - if (webglVersion === 2) { - gl = canvas.getContext('webgl2', attributes); - } - else if (webglVersion === 1) { - gl = (canvas.getContext('webgl', attributes) || - canvas.getContext('experimental-webgl', attributes)); - } - if (webglVersion === 0 || gl == null) { - throw new Error('This browser does not support WebGL.'); - } - return gl; -} -exports.createWebGLRenderingContextFromCanvas = createWebGLRenderingContextFromCanvas; -function callAndCheck(gl, func) { - var returnValue = func(); - checkWebGLError(gl); - return returnValue; -} -exports.callAndCheck = callAndCheck; -var webGLDebugErrorCheckingEnabled = false; -function enableDebugWebGLErrorChecking(enabled) { - webGLDebugErrorCheckingEnabled = enabled; -} -exports.enableDebugWebGLErrorChecking = enableDebugWebGLErrorChecking; -function checkWebGLError(gl) { - if (webGLDebugErrorCheckingEnabled) { - var error = gl.getError(); - if (error !== gl.NO_ERROR) { - throw new Error('WebGL Error: ' + getWebGLErrorMessage(gl, error)); - } - } -} -exports.checkWebGLError = checkWebGLError; -function getWebGLErrorMessage(gl, status) { - switch (status) { - case gl.NO_ERROR: - return 'NO_ERROR'; - case gl.INVALID_ENUM: - return 'INVALID_ENUM'; - case gl.INVALID_VALUE: - return 'INVALID_VALUE'; - case gl.INVALID_OPERATION: - return 'INVALID_OPERATION'; - case gl.INVALID_FRAMEBUFFER_OPERATION: - return 'INVALID_FRAMEBUFFER_OPERATION'; - case gl.OUT_OF_MEMORY: - return 'OUT_OF_MEMORY'; - case gl.CONTEXT_LOST_WEBGL: - return 'CONTEXT_LOST_WEBGL'; - default: - return "Unknown error code " + status; - } -} -exports.getWebGLErrorMessage = getWebGLErrorMessage; -function getExtensionOrThrow(gl, extensionName) { - return throwIfNull(gl, function () { return gl.getExtension(extensionName); }, 'Extension "' + extensionName + '" not supported on this browser.'); -} -exports.getExtensionOrThrow = getExtensionOrThrow; -function createVertexShader(gl, vertexShaderSource) { - var vertexShader = throwIfNull(gl, function () { return gl.createShader(gl.VERTEX_SHADER); }, 'Unable to create vertex WebGLShader.'); - callAndCheck(gl, function () { return gl.shaderSource(vertexShader, vertexShaderSource); }); - callAndCheck(gl, function () { return gl.compileShader(vertexShader); }); - if (gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS) === false) { - console.log(gl.getShaderInfoLog(vertexShader)); - throw new Error('Failed to compile vertex shader.'); - } - return vertexShader; -} -exports.createVertexShader = createVertexShader; -function createFragmentShader(gl, fragmentShaderSource) { - var fragmentShader = throwIfNull(gl, function () { return gl.createShader(gl.FRAGMENT_SHADER); }, 'Unable to create fragment WebGLShader.'); - callAndCheck(gl, function () { return gl.shaderSource(fragmentShader, fragmentShaderSource); }); - callAndCheck(gl, function () { return gl.compileShader(fragmentShader); }); - if (gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS) === false) { - logShaderSourceAndInfoLog(fragmentShaderSource, gl.getShaderInfoLog(fragmentShader)); - throw new Error('Failed to compile fragment shader.'); - } - return fragmentShader; -} -exports.createFragmentShader = createFragmentShader; -var lineNumberRegex = /ERROR: [0-9]+:([0-9]+):/g; -function logShaderSourceAndInfoLog(shaderSource, shaderInfoLog) { - var lineNumberRegexResult = lineNumberRegex.exec(shaderInfoLog); - if (lineNumberRegexResult == null) { - console.log("Couldn't parse line number in error: " + shaderInfoLog); - console.log(shaderSource); - return; - } - var lineNumber = +lineNumberRegexResult[1]; - var shaderLines = shaderSource.split('\n'); - var pad = shaderLines.length.toString().length + 2; - var linesWithLineNumbers = shaderLines.map(function (line, lineNumber) { - return util.rightPad((lineNumber + 1).toString(), pad) + line; - }); - var maxLineLength = 0; - for (var i = 0; i < linesWithLineNumbers.length; i++) { - maxLineLength = Math.max(linesWithLineNumbers[i].length, maxLineLength); - } - var beforeErrorLines = linesWithLineNumbers.slice(0, lineNumber - 1); - var errorLine = linesWithLineNumbers.slice(lineNumber - 1, lineNumber); - var afterErrorLines = linesWithLineNumbers.slice(lineNumber); - console.log(beforeErrorLines.join('\n')); - console.log(shaderInfoLog.split('\n')[0]); - console.log("%c " + util.rightPad(errorLine[0], maxLineLength), 'border:1px solid red; background-color:#e3d2d2; color:#a61717'); - console.log(afterErrorLines.join('\n')); -} -function createProgram(gl) { - return throwIfNull(gl, function () { return gl.createProgram(); }, 'Unable to create WebGLProgram.'); -} -exports.createProgram = createProgram; -function linkProgram(gl, program) { - callAndCheck(gl, function () { return gl.linkProgram(program); }); - if (gl.getProgramParameter(program, gl.LINK_STATUS) === false) { - console.log(gl.getProgramInfoLog(program)); - throw new Error('Failed to link vertex and fragment shaders.'); - } -} -exports.linkProgram = linkProgram; -function validateProgram(gl, program) { - callAndCheck(gl, function () { return gl.validateProgram(program); }); - if (gl.getProgramParameter(program, gl.VALIDATE_STATUS) === false) { - console.log(gl.getProgramInfoLog(program)); - throw new Error('Shader program validation failed.'); - } -} -exports.validateProgram = validateProgram; -function createStaticVertexBuffer(gl, data) { - var buffer = throwIfNull(gl, function () { return gl.createBuffer(); }, 'Unable to create WebGLBuffer'); - callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, buffer); }); - callAndCheck(gl, function () { return gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW); }); - return buffer; -} -exports.createStaticVertexBuffer = createStaticVertexBuffer; -function createStaticIndexBuffer(gl, data) { - var buffer = throwIfNull(gl, function () { return gl.createBuffer(); }, 'Unable to create WebGLBuffer'); - callAndCheck(gl, function () { return gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer); }); - callAndCheck(gl, function () { return gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data, gl.STATIC_DRAW); }); - return buffer; -} -exports.createStaticIndexBuffer = createStaticIndexBuffer; -function queryMaxTextureSize(gl) { - if (MAX_TEXTURE_SIZE != null) { - return MAX_TEXTURE_SIZE; - } - MAX_TEXTURE_SIZE = - callAndCheck(gl, function () { return gl.getParameter(gl.MAX_TEXTURE_SIZE); }); - return MAX_TEXTURE_SIZE; -} -exports.queryMaxTextureSize = queryMaxTextureSize; -function getChannelsPerTexture() { - if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) { - return 4; - } - if (environment_1.ENV.get('WEBGL_VERSION') === 2) { - return 1; - } - return 4; -} -exports.getChannelsPerTexture = getChannelsPerTexture; -function createTexture(gl) { - return throwIfNull(gl, function () { return gl.createTexture(); }, 'Unable to create WebGLTexture.'); -} -exports.createTexture = createTexture; -function validateTextureSize(gl, width, height) { - var maxTextureSize = queryMaxTextureSize(gl); - if ((width <= 0) || (height <= 0)) { - var requested = "[" + width + "x" + height + "]"; - throw new Error('Requested texture size ' + requested + ' is invalid.'); - } - if ((width > maxTextureSize) || (height > maxTextureSize)) { - var requested = "[" + width + "x" + height + "]"; - var max = "[" + maxTextureSize + "x" + maxTextureSize + "]"; - throw new Error('Requested texture size ' + requested + - ' greater than WebGL maximum on this browser / GPU ' + max + '.'); - } -} -exports.validateTextureSize = validateTextureSize; -function createFramebuffer(gl) { - return throwIfNull(gl, function () { return gl.createFramebuffer(); }, 'Unable to create WebGLFramebuffer.'); -} -exports.createFramebuffer = createFramebuffer; -function bindVertexBufferToProgramAttribute(gl, program, attribute, buffer, arrayEntriesPerItem, itemStrideInBytes, itemOffsetInBytes, attribLocations) { - var loc = -1; - if ((attribLocations != null) && (attribute in attribLocations)) { - loc = attribLocations[attribute]; - } - else { - loc = gl.getAttribLocation(program, attribute); - } - if (loc === -1) { - return; - } - callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, buffer); }); - callAndCheck(gl, function () { return gl.vertexAttribPointer(loc, arrayEntriesPerItem, gl.FLOAT, false, itemStrideInBytes, itemOffsetInBytes); }); - callAndCheck(gl, function () { return gl.enableVertexAttribArray(loc); }); -} -exports.bindVertexBufferToProgramAttribute = bindVertexBufferToProgramAttribute; -function bindTextureUnit(gl, texture, textureUnit) { - validateTextureUnit(gl, textureUnit); - callAndCheck(gl, function () { return gl.activeTexture(gl.TEXTURE0 + textureUnit); }); - callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); }); -} -exports.bindTextureUnit = bindTextureUnit; -function unbindTextureUnit(gl, textureUnit) { - validateTextureUnit(gl, textureUnit); - callAndCheck(gl, function () { return gl.activeTexture(gl.TEXTURE0 + textureUnit); }); - callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); }); -} -exports.unbindTextureUnit = unbindTextureUnit; -function getProgramUniformLocationOrThrow(gl, program, uniformName) { - return throwIfNull(gl, function () { return gl.getUniformLocation(program, uniformName); }, 'uniform "' + uniformName + '" not present in program.'); -} -exports.getProgramUniformLocationOrThrow = getProgramUniformLocationOrThrow; -function getProgramUniformLocation(gl, program, uniformName) { - return gl.getUniformLocation(program, uniformName); -} -exports.getProgramUniformLocation = getProgramUniformLocation; -function bindTextureToProgramUniformSampler(gl, program, texture, uniformSamplerLocation, textureUnit) { - callAndCheck(gl, function () { return bindTextureUnit(gl, texture, textureUnit); }); - callAndCheck(gl, function () { return gl.uniform1i(uniformSamplerLocation, textureUnit); }); -} -exports.bindTextureToProgramUniformSampler = bindTextureToProgramUniformSampler; -function bindCanvasToFramebuffer(gl) { - callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, null); }); - callAndCheck(gl, function () { return gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); }); - callAndCheck(gl, function () { return gl.scissor(0, 0, gl.canvas.width, gl.canvas.height); }); -} -exports.bindCanvasToFramebuffer = bindCanvasToFramebuffer; -function bindColorTextureToFramebuffer(gl, texture, framebuffer) { - callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); }); - callAndCheck(gl, function () { return gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); }); -} -exports.bindColorTextureToFramebuffer = bindColorTextureToFramebuffer; -function unbindColorTextureFromFramebuffer(gl, framebuffer) { - callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); }); - callAndCheck(gl, function () { return gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0); }); -} -exports.unbindColorTextureFromFramebuffer = unbindColorTextureFromFramebuffer; -function validateFramebuffer(gl) { - var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER); - if (status !== gl.FRAMEBUFFER_COMPLETE) { - throw new Error('Error binding framebuffer: ' + getFramebufferErrorMessage(gl, status)); - } -} -exports.validateFramebuffer = validateFramebuffer; -function getFramebufferErrorMessage(gl, status) { - switch (status) { - case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT: - return 'FRAMEBUFFER_INCOMPLETE_ATTACHMENT'; - case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: - return 'FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT'; - case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS: - return 'FRAMEBUFFER_INCOMPLETE_DIMENSIONS'; - case gl.FRAMEBUFFER_UNSUPPORTED: - return 'FRAMEBUFFER_UNSUPPORTED'; - default: - return "unknown error " + status; - } -} -exports.getFramebufferErrorMessage = getFramebufferErrorMessage; -function throwIfNull(gl, returnTOrNull, failureMessage) { - var tOrNull = callAndCheck(gl, function () { return returnTOrNull(); }); - if (tOrNull == null) { - throw new Error(failureMessage); - } - return tOrNull; -} -function validateTextureUnit(gl, textureUnit) { - var maxTextureUnit = gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1; - var glTextureUnit = textureUnit + gl.TEXTURE0; - if (glTextureUnit < gl.TEXTURE0 || glTextureUnit > maxTextureUnit) { - var textureUnitRange = "[gl.TEXTURE0, gl.TEXTURE" + maxTextureUnit + "]"; - throw new Error("textureUnit must be in " + textureUnitRange + "."); - } -} -function getTextureShapeFromLogicalShape(gl, logShape) { - if (logShape.length !== 2) { - var squeezeResult = util.squeezeShape(logShape); - logShape = squeezeResult.newShape; - } - var maxTexSize = queryMaxTextureSize(gl); - var size = util.sizeFromShape(logShape); - if (logShape.length <= 1 && size <= maxTexSize) { - return [size, 1]; - } - else if (logShape.length === 2 && logShape[0] <= maxTexSize && - logShape[1] <= maxTexSize) { - return logShape; - } - else if (logShape.length === 3 && logShape[0] <= maxTexSize && - logShape[1] * logShape[2] <= maxTexSize) { - return [logShape[0], logShape[1] * logShape[2]]; - } - else if (logShape.length === 4 && logShape[0] <= maxTexSize && - logShape[1] * logShape[2] * logShape[3] <= maxTexSize) { - return [logShape[0], logShape[1] * logShape[2] * logShape[3]]; - } - else { - return util.sizeToSquarishShape(size); - } -} -exports.getTextureShapeFromLogicalShape = getTextureShapeFromLogicalShape; - -},{"../../environment":34,"../../util":151}],105:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("./environment"); -var array_ops = require("./ops/array_ops"); -var batchnorm = require("./ops/batchnorm"); -var binary_ops = require("./ops/binary_ops"); -var compare = require("./ops/compare"); -var conv = require("./ops/conv"); -var image_ops = require("./ops/image_ops"); -var logical = require("./ops/logical_ops"); -var lrn_ops = require("./ops/lrn"); -var lstm_ops = require("./ops/lstm"); -var matmul = require("./ops/matmul"); -var norm = require("./ops/norm"); -var ops = require("./ops/ops"); -var pool = require("./ops/pool"); -var reduction_ops = require("./ops/reduction_ops"); -var reverse = require("./ops/reverse"); -var slice = require("./ops/slice"); -var softmax_ops = require("./ops/softmax"); -var transpose = require("./ops/transpose"); -var unary_ops = require("./ops/unary_ops"); -var tracking_1 = require("./tracking"); -var util = require("./util"); -var tidy = tracking_1.Tracking.tidy; -var keep = tracking_1.Tracking.keep; -var NDArrayMath = (function () { - function NDArrayMath(backend, safeMode) { - this.matMul = matmul.Ops.matMul; - this.vectorTimesMatrix = matmul.Ops.vectorTimesMatrix; - this.outerProduct = matmul.Ops.outerProduct; - this.matrixTimesVector = matmul.Ops.matrixTimesVector; - this.dotProduct = matmul.Ops.dotProduct; - this.slice = slice.Ops.slice; - this.slice1D = slice.Ops.slice1d; - this.slice2D = slice.Ops.slice2d; - this.slice3D = slice.Ops.slice3d; - this.slice4D = slice.Ops.slice4d; - this.reverse = reverse.Ops.reverse; - this.reverse1D = reverse.Ops.reverse1d; - this.reverse2D = reverse.Ops.reverse2d; - this.reverse3D = reverse.Ops.reverse3d; - this.reverse4D = reverse.Ops.reverse4d; - this.batchNormalization = batchnorm.Ops.batchNormalization; - this.batchNormalization2D = batchnorm.Ops.batchNormalization2d; - this.batchNormalization3D = batchnorm.Ops.batchNormalization3d; - this.batchNormalization4D = batchnorm.Ops.batchNormalization4d; - this.avgPool = pool.Ops.avgPool; - this.maxPool = pool.Ops.maxPool; - this.minPool = pool.Ops.minPool; - this.maxPoolBackprop = pool.Ops.maxPoolBackprop; - this.conv2dTranspose = conv.Ops.conv2dTranspose; - this.depthwiseConv2D = conv.Ops.depthwiseConv2d; - this.conv2dDerFilter = conv.Ops.conv2dDerFilter; - this.conv2dDerInput = conv.Ops.conv2dDerInput; - this.argMax = reduction_ops.Ops.argMax; - this.argMin = reduction_ops.Ops.argMin; - this.logSumExp = reduction_ops.Ops.logSumExp; - this.max = reduction_ops.Ops.max; - this.mean = reduction_ops.Ops.mean; - this.min = reduction_ops.Ops.min; - this.moments = reduction_ops.Ops.moments; - this.sum = reduction_ops.Ops.sum; - this.add = binary_ops.Ops.add; - this.addStrict = binary_ops.Ops.addStrict; - this.div = binary_ops.Ops.div; - this.divide = this.div; - this.divStrict = binary_ops.Ops.divStrict; - this.divideStrict = this.divStrict; - this.maximum = binary_ops.Ops.maximum; - this.maximumStrict = binary_ops.Ops.maximumStrict; - this.minimum = binary_ops.Ops.minimum; - this.minimumStrict = binary_ops.Ops.minimumStrict; - this.mul = binary_ops.Ops.mul; - this.multiply = this.mul; - this.mulStrict = binary_ops.Ops.mulStrict; - this.multiplyStrict = this.mulStrict; - this.pow = binary_ops.Ops.pow; - this.powStrict = binary_ops.Ops.powStrict; - this.sub = binary_ops.Ops.sub; - this.subtract = this.sub; - this.subStrict = binary_ops.Ops.subStrict; - this.logicalNot = logical.Ops.logicalNot; - this.logicalAnd = logical.Ops.logicalAnd; - this.logicalOr = logical.Ops.logicalOr; - this.logicalXor = logical.Ops.logicalXor; - this.where = logical.Ops.where; - this.transpose = transpose.Ops.transpose; - this.equal = compare.Ops.equal; - this.equalStrict = compare.Ops.equalStrict; - this.greater = compare.Ops.greater; - this.greaterStrict = compare.Ops.greaterStrict; - this.greaterEqual = compare.Ops.greaterEqual; - this.greaterEqualStrict = compare.Ops.greaterEqualStrict; - this.less = compare.Ops.less; - this.lessStrict = compare.Ops.lessStrict; - this.lessEqual = compare.Ops.lessEqual; - this.lessEqualStrict = compare.Ops.lessEqualStrict; - this.notEqual = compare.Ops.notEqual; - this.notEqualStrict = compare.Ops.notEqualStrict; - this.abs = unary_ops.Ops.abs; - this.acos = unary_ops.Ops.acos; - this.asin = unary_ops.Ops.asin; - this.atan = unary_ops.Ops.atan; - this.ceil = unary_ops.Ops.ceil; - this.clip = unary_ops.Ops.clipByValue; - this.cos = unary_ops.Ops.cos; - this.cosh = unary_ops.Ops.cosh; - this.elu = unary_ops.Ops.elu; - this.exp = unary_ops.Ops.exp; - this.floor = unary_ops.Ops.floor; - this.leakyRelu = unary_ops.Ops.leakyRelu; - this.log = unary_ops.Ops.log; - this.neg = unary_ops.Ops.neg; - this.prelu = unary_ops.Ops.prelu; - this.relu = unary_ops.Ops.relu; - this.selu = unary_ops.Ops.selu; - this.sigmoid = unary_ops.Ops.sigmoid; - this.sin = unary_ops.Ops.sin; - this.sinh = unary_ops.Ops.sinh; - this.sqrt = unary_ops.Ops.sqrt; - this.square = unary_ops.Ops.square; - this.step = unary_ops.Ops.step; - this.tan = unary_ops.Ops.tan; - this.tanh = unary_ops.Ops.tanh; - this.norm = norm.Ops.norm; - this.basicLSTMCell = lstm_ops.Ops.basicLSTMCell; - this.multiRNNCell = lstm_ops.Ops.multiRNNCell; - this.softmax = softmax_ops.Ops.softmax; - this.softmaxCrossEntropy = softmax_ops.Ops.softmaxCrossEntropy; - this.cast = array_ops.Ops.cast; - this.clone = array_ops.Ops.clone; - this.gather = array_ops.Ops.gather; - this.reshape = array_ops.Ops.reshape; - this.tile = array_ops.Ops.tile; - this.oneHot = array_ops.Ops.oneHot; - this.multinomial = array_ops.Ops.multinomial; - this.pad1D = array_ops.Ops.pad1d; - this.pad2D = array_ops.Ops.pad2d; - this.resizeBilinear3D = image_ops.Ops.resizeBilinear; - this.localResponseNormalization3D = lrn_ops.LRN.localResponseNormalization; - this.localResponseNormalization4D = lrn_ops.LRN.localResponseNormalization; - this.keep = tracking_1.Tracking.keep; - environment_1.ENV.setMath(this, backend, safeMode); - this.engine = environment_1.ENV.engine; - this.dispose = environment_1.ENV.engine.dispose.bind(environment_1.ENV.engine); - this.registeredVariables = environment_1.ENV.engine.registeredVariables; - this.startScope = environment_1.ENV.engine.startScope.bind(environment_1.ENV.engine); - this.endScope = environment_1.ENV.engine.endScope.bind(environment_1.ENV.engine); - } - NDArrayMath.prototype.scope = function (scopeFn) { - var keepFn = function (tensor) { return keep(tensor); }; - var trackFn = function (tensor) { return tensor; }; - return tidy(function () { return scopeFn(keepFn, trackFn); }); - }; - NDArrayMath.prototype.track = function (result) { - return result; - }; - NDArrayMath.prototype.topK = function (x, k) { - util.assert(k <= x.size, "Error in topK: k value (" + k + ") must be less than size of input " + - ("tensor, got shape " + x.shape + ".")); - var values; - var indices; - tidy('topK', function () { - values = environment_1.ENV.engine.executeKernel('TopKValues', { inputs: { x: x }, args: { k: k } }); - indices = - environment_1.ENV.engine.executeKernel('TopKIndices', { inputs: { x: x }, args: { k: k } }); - return values; - }); - var result = { values: values, indices: indices }; - return result; - }; - NDArrayMath.prototype.elementWiseMul = function (a, b) { - return a.mulStrict(b); - }; - NDArrayMath.prototype.scalarDividedByArray = function (c, a) { - util.assert(c.size === 1, "Error in scalarDividedByArray: first argument must be rank 0, but " + - ("got Tensor of rank " + c.rank + ".")); - return c.div(a); - }; - NDArrayMath.prototype.arrayDividedByScalar = function (a, c) { - util.assert(c.size === 1, "Error in arrayDividedByScalar: second argument must be rank 0, " + - ("but got Tensor of rank " + c.rank + ".")); - return a.div(c); - }; - NDArrayMath.prototype.switchDim = function (x, perm) { - return ops.transpose(x, perm); - }; - NDArrayMath.prototype.scalarPlusArray = function (c, a) { - util.assert(c.size === 1, "Error in scalarPlusArray: first argument must be rank 0, but got " + - ("rank " + c.rank + ".")); - return this.add(c, a); - }; - NDArrayMath.prototype.scalarMinusArray = function (c, a) { - util.assert(c.size === 1, "Error in scalarMinusArray: first argument must be rank 0, but got " + - ("rank " + c.rank + ".")); - return this.subtract(c, a); - }; - NDArrayMath.prototype.arrayMinusScalar = function (a, c) { - util.assert(c.size === 1, "Error in arrayMinusScalar: second argument must be rank 0, but " + - ("got rank " + c.rank + ".")); - return this.subtract(a, c); - }; - NDArrayMath.prototype.scaledArrayAdd = function (c1, a, c2, b) { - var _this = this; - util.assert(c1.size === 1, "Error in scaledArrayAdd: first argument must rank 0, but got " + - (" rank " + c1.rank + ".")); - util.assert(c2.size === 1, "Error in scaledArrayAdd: third argument must be rank 0, but got " + - ("Tensor of rank " + c2.rank + ".")); - util.assertShapesMatch(a.shape, b.shape, 'Error in scaledArrayAdd: '); - return tidy('scaledArrayAdd', function () { - return _this.add(_this.multiply(c1, a), _this.multiply(c2, b)); - }); - }; - NDArrayMath.prototype.scalarTimesArray = function (c, a) { - util.assert(c.size === 1, "Error in arrayDividedByScalar: first argument must be rank 0, but " + - ("got rank " + c.rank + ".")); - return this.multiply(c, a); - }; - NDArrayMath.prototype.concat = function (a, b, axis) { - return ops.concat([a, b], axis); - }; - NDArrayMath.prototype.concat1D = function (a, b) { - return ops.concat1d([a, b]); - }; - NDArrayMath.prototype.concat2D = function (a, b, axis) { - return ops.concat2d([a, b], axis); - }; - NDArrayMath.prototype.concat3D = function (a, b, axis) { - return ops.concat3d([a, b], axis); - }; - NDArrayMath.prototype.concat4D = function (a, b, axis) { - return ops.concat4d([a, b], axis); - }; - NDArrayMath.prototype.conv1d = function (input, filter, bias, stride, pad, dimRoundingMode) { - if (bias != null) { - util.assert(bias.rank === 1, "Error in conv1d: bias must be rank 1, but got rank " + - (bias.rank + ".")); - } - var res = ops.conv1d(input, filter, stride, pad, dimRoundingMode); - return res.add(bias); - }; - NDArrayMath.prototype.conv2d = function (x, filter, bias, strides, pad, dimRoundingMode) { - if (bias != null) { - util.assert(bias.rank === 1, "Error in conv2d: bias must be rank 1, but got rank " + - (bias.rank + ".")); - } - var res = ops.conv2d(x, filter, strides, pad, dimRoundingMode); - return res.add(bias); - }; - NDArrayMath.prototype.argMaxEquals = function (x1, x2) { - util.assertShapesMatch(x1.shape, x2.shape, 'Error in argMaxEquals: '); - return x1.argMax().equal(x2.argMax()); - }; - return NDArrayMath; -}()); -exports.NDArrayMath = NDArrayMath; - -},{"./environment":34,"./ops/array_ops":106,"./ops/batchnorm":108,"./ops/binary_ops":109,"./ops/compare":111,"./ops/conv":114,"./ops/image_ops":116,"./ops/logical_ops":117,"./ops/lrn":118,"./ops/lstm":119,"./ops/matmul":120,"./ops/norm":121,"./ops/ops":123,"./ops/pool":124,"./ops/reduction_ops":127,"./ops/reverse":128,"./ops/slice":130,"./ops/softmax":132,"./ops/transpose":133,"./ops/unary_ops":134,"./tracking":148,"./util":151}],106:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var concat_1 = require("./concat"); -var operation_1 = require("./operation"); -var rand_1 = require("./rand"); -var Ops = (function () { - function Ops() { - } - Ops.tensor = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (shape != null && inferredShape.length !== 1) { - util.assertShapesMatch(shape, inferredShape, "Error creating a new Tensor. " + - ("Inferred shape (" + inferredShape + ") does not match the ") + - ("provided shape (" + shape + "). ")); - } - if (!util.isTypedArray(values) && !Array.isArray(values)) { - values = [values]; - } - shape = shape || inferredShape; - return tensor_1.Tensor.make(shape, { values: toTypedArray(values, dtype) }, dtype); - }; - Ops.scalar = function (value, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - if (util.isTypedArray(value) || Array.isArray(value)) { - throw new Error('Error creating a new Scalar: value must be a primitive ' + - '(number|boolean)'); - } - return Ops.tensor(value, [], dtype); - }; - Ops.tensor1d = function (values, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor1D: values must be a flat/TypedArray'); - } - return Ops.tensor(values, inferredShape, dtype); - }; - Ops.tensor2d = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 2 && inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor2D: values must be number[][] ' + - 'or flat/TypedArray'); - } - shape = shape || inferredShape; - return Ops.tensor(values, shape, dtype); - }; - Ops.tensor3d = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 3 && inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor3D: values must be number[][][]' + - 'or flat/TypedArray'); - } - shape = shape || inferredShape; - return Ops.tensor(values, shape, dtype); - }; - Ops.tensor4d = function (values, shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var inferredShape = util.inferShape(values); - if (inferredShape.length !== 4 && inferredShape.length !== 1) { - throw new Error('Error creating a new Tensor4D: values must be number[][][][]' + - 'or flat/TypedArray'); - } - shape = shape || inferredShape; - return Ops.tensor(values, shape, dtype); - }; - Ops.ones = function (shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var values = makeOnesTypedArray(util.sizeFromShape(shape), dtype); - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.zeros = function (shape, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var values = makeZerosTypedArray(util.sizeFromShape(shape), dtype); - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.fill = function (shape, value, dtype) { - if (dtype === void 0) { dtype = 'float32'; } - var values = util.getTypedArrayFromDType(dtype, util.sizeFromShape(shape)); - values.fill(value); - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.onesLike = function (x) { - return Ops.ones(x.shape, x.dtype); - }; - Ops.zerosLike = function (x) { - return Ops.zeros(x.shape, x.dtype); - }; - Ops.clone = function (x) { - return tensor_1.Tensor.make(x.shape, { dataId: x.dataId }, x.dtype); - }; - Ops.randomNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - if (dtype != null && dtype === 'bool') { - throw new Error("Unsupported data type " + dtype); - } - var randGauss = new rand_1.MPRandGauss(mean, stdDev, dtype, false, seed); - return tensor_1.Tensor.rand(shape, function () { return randGauss.nextValue(); }, dtype); - }; - Ops.truncatedNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - if (dtype != null && dtype === 'bool') { - throw new Error("Unsupported data type " + dtype); - } - var randGauss = new rand_1.MPRandGauss(mean, stdDev, dtype, true, seed); - return tensor_1.Tensor.rand(shape, function () { return randGauss.nextValue(); }, dtype); - }; - Ops.randomUniform = function (shape, minval, maxval, dtype) { - if (minval === void 0) { minval = 0; } - if (maxval === void 0) { maxval = 1; } - if (dtype === void 0) { dtype = 'float32'; } - return tensor_1.Tensor.rand(shape, function () { return util.randUniform(minval, maxval); }, dtype); - }; - Ops.rand = function (shape, randFunction, dtype) { - var size = util.sizeFromShape(shape); - var values = null; - if (dtype == null || dtype === 'float32') { - values = new Float32Array(size); - } - else if (dtype === 'int32') { - values = new Int32Array(size); - } - else if (dtype === 'bool') { - values = new Uint8Array(size); - } - else { - throw new Error("Unknown data type " + dtype); - } - for (var i = 0; i < size; i++) { - values[i] = randFunction(); - } - return tensor_1.Tensor.make(shape, { values: values }, dtype); - }; - Ops.multinomial = function (probabilities, numSamples, seed) { - var numOutcomes = probabilities.size; - if (numOutcomes < 2) { - throw new Error("Error in multinomial: you need at least 2 outcomes, but got " + - (numOutcomes + ".")); - } - if (probabilities.rank > 2) { - throw new Error("Rank of probabilities must be 1 or 2, but is " + probabilities.rank); - } - seed = seed || Math.random(); - var origRank = probabilities.rank; - if (probabilities.rank === 1) { - probabilities = probabilities.as2D(1, -1); - } - var res = environment_1.ENV.engine.executeKernel('Multinomial', { - inputs: { probs: probabilities }, - args: { numSamples: numSamples, seed: seed } - }); - if (origRank === 1) { - return res.as1D(); - } - return res; - }; - Ops.oneHot = function (indices, depth, onValue, offValue) { - if (onValue === void 0) { onValue = 1; } - if (offValue === void 0) { offValue = 0; } - if (depth < 2) { - throw new Error("Error in oneHot: depth must be >=2, but it is " + depth); - } - return environment_1.ENV.engine.executeKernel('OneHot', { inputs: { indices: indices }, args: { depth: depth, onValue: onValue, offValue: offValue } }); - }; - Ops.fromPixels = function (pixels, numChannels) { - if (numChannels === void 0) { numChannels = 3; } - if (numChannels > 4) { - throw new Error('Cannot construct Tensor with more than 4 channels from pixels.'); - } - return environment_1.ENV.engine.fromPixels(pixels, numChannels); - }; - Ops.reshape = function (x, shape) { - shape = util.inferFromImplicitShape(shape, x.size); - util.assert(x.size === util.sizeFromShape(shape), 'new shape and old shape must have the same number of elements.'); - var grad = function (dy, y) { - return { x: function () { return dy.reshape(x.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Reshape', { inputs: { x: x }, args: { newShape: shape } }, grad); - }; - Ops.squeeze = function (x, axis) { - return Ops.reshape(x, util.squeezeShape(x.shape, axis).newShape); - }; - Ops.cast = function (x, dtype) { - var grad = function (dy, y) { - return { x: function () { return dy.reshape(dy.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Cast', { inputs: { x: x }, args: { newDType: dtype } }, grad); - }; - Ops.tile = function (x, reps) { - util.assert(x.rank === reps.length, "Error in transpose: rank of input " + x.rank + " " + - ("must match length of reps " + reps + ".")); - return environment_1.ENV.engine.executeKernel('Tile', { inputs: { x: x }, args: { reps: reps } }); - }; - Ops.gather = function (x, indices, axis) { - if (axis === void 0) { axis = 0; } - return environment_1.ENV.engine.executeKernel('Gather', { inputs: { x: x, indices: indices }, args: { axis: axis } }); - }; - Ops.pad1d = function (x, paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - util.assert(paddings.length === 2, 'Invalid number of paddings. Must be length of 2.'); - return environment_1.ENV.engine.executeKernel('Pad1D', { inputs: { x: x }, args: { paddings: paddings, constantValue: constantValue } }); - }; - Ops.pad2d = function (x, paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - util.assert(paddings.length === 2 && paddings[0].length === 2 && - paddings[1].length === 2, 'Invalid number of paddings. Must be length of 2 each.'); - return environment_1.ENV.engine.executeKernel('Pad2D', { inputs: { x: x }, args: { paddings: paddings, constantValue: constantValue } }); - }; - Ops.pad = function (x, paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - if (x.rank === 0) { - throw new Error('pad(scalar) is not defined. Pass non-scalar to pad'); - } - else if (x.rank === 1) { - return Ops.pad1d(x, paddings[0], constantValue); - } - else if (x.rank === 2) { - return Ops.pad2d(x, paddings, constantValue); - } - else { - throw new Error("pad of rank-" + x.rank + " tensor is not yet supported"); - } - }; - Ops.stack = function (tensors, axis) { - if (axis === void 0) { axis = 0; } - util.assert(tensors.length >= 2, 'Pass at least two tensors to dl.stack'); - var rank = tensors[0].rank; - var shape = tensors[0].shape; - var dtype = tensors[0].dtype; - util.assert(axis <= rank, 'Axis must be <= rank of the tensor'); - tensors.forEach(function (t) { - util.assertShapesMatch(shape, t.shape, 'All tensors passed to stack must have matching shapes'); - }); - tensors.forEach(function (t) { - util.assert(dtype === t.dtype, 'All tensors passed to stack must have matching dtypes'); - }); - var expandedTensors = tensors.map(function (t) { return t.expandDims(axis); }); - return concat_1.Concat.concat(expandedTensors, axis); - }; - Ops.expandDims = function (x, axis) { - if (axis === void 0) { axis = 0; } - util.assert(axis <= x.rank, 'Axis must be <= rank of the tensor'); - var newShape = x.shape.slice(); - newShape.splice(axis, 0, 1); - return Ops.reshape(x, newShape); - }; - Ops.linspace = function (start, stop, num) { - if (num === 0) { - throw new Error('Cannot request zero samples'); - } - var step = (stop - start) / (num - 1); - var values = makeZerosTypedArray(num, 'float32'); - values[0] = start; - for (var i = 1; i < values.length; i++) { - values[i] = values[i - 1] + step; - } - return tensor_1.Tensor1D.new(values, 'float32'); - }; - Ops.range = function (start, stop, step, dtype) { - if (step === void 0) { step = 1; } - if (dtype === void 0) { dtype = 'float32'; } - if (step === 0) { - throw new Error('Cannot have a step of zero'); - } - var sameStartStop = start === stop; - var increasingRangeNegativeStep = start < stop && step < 0; - var decreasingRangePositiveStep = stop < start && step > 1; - if (sameStartStop || increasingRangeNegativeStep || - decreasingRangePositiveStep) { - return Ops.zeros([0], dtype); - } - var numElements = Math.abs(Math.ceil((stop - start) / step)); - var values = makeZerosTypedArray(numElements, dtype); - if (stop < start && step === 1) { - step = -1; - } - values[0] = start; - for (var i = 1; i < values.length; i++) { - values[i] = values[i - 1] + step; - } - return Ops.tensor1d(values, dtype); - }; - Ops.buffer = function (shape, dtype, values) { - if (dtype === void 0) { dtype = 'float32'; } - return new tensor_1.TensorBuffer(shape, dtype, values); - }; - Ops.print = function (x, verbose) { - if (verbose === void 0) { verbose = false; } - var C = (function () { - function Tensor() { - } - return Tensor; - }()); - var displayTensor = new C(); - displayTensor.shape = x.shape; - displayTensor.values = Array.from(x.dataSync()); - displayTensor.toString = function () { - var fields = [ - "values: [" + this.values.join(', ') + "]", "shape: [" + x.shape.join(', ') + "]", - "rank: " + x.rank - ]; - if (verbose) { - fields.push("dtype: '" + this.dtype + "'"); - fields.push("size: " + this.size); - } - for (var i = 0; i < fields.length; i++) { - fields[i] = ' ' + fields[i]; - } - return 'TensorInfo {\n' + fields.join(',\n') + '\n}'; - }; - if (verbose) { - displayTensor.dtype = x.dtype; - displayTensor.size = x.size; - } - console.log(displayTensor); - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "scalar", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor1d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor2d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor3d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "tensor4d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "ones", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "zeros", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "fill", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "onesLike", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "zerosLike", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "clone", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "randomNormal", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "truncatedNormal", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "randomUniform", null); - __decorate([ - operation_1.operation - ], Ops, "rand", null); - __decorate([ - operation_1.operation - ], Ops, "multinomial", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "oneHot", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }), - operation_1.operation - ], Ops, "fromPixels", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "reshape", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }) - ], Ops, "squeeze", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "cast", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "tile", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "gather", null); - __decorate([ - operation_1.operation - ], Ops, "pad1d", null); - __decorate([ - operation_1.operation - ], Ops, "pad2d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "pad", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "stack", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }), - operation_1.operation - ], Ops, "expandDims", null); - __decorate([ - operation_1.operation, - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "linspace", null); - __decorate([ - operation_1.operation, - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "range", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "buffer", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Ops, "print", null); - return Ops; -}()); -exports.Ops = Ops; -function makeZerosTypedArray(size, dtype) { - if (dtype == null || dtype === 'float32') { - return new Float32Array(size); - } - else if (dtype === 'int32') { - return new Int32Array(size); - } - else if (dtype === 'bool') { - return new Uint8Array(size); - } - else { - throw new Error("Unknown data type $ {dtype}"); - } -} -function makeOnesTypedArray(size, dtype) { - var array = makeZerosTypedArray(size, dtype); - for (var i = 0; i < array.length; i++) { - array[i] = 1; - } - return array; -} -function toTypedArray(a, dtype) { - if (noConversionNeeded(a, dtype)) { - return a; - } - if (Array.isArray(a)) { - a = util.flatten(a); - } - return util.copyTypedArray(a, dtype); -} -function noConversionNeeded(a, dtype) { - return (a instanceof Float32Array && dtype === 'float32') || - (a instanceof Int32Array && dtype === 'int32') || - (a instanceof Uint8Array && dtype === 'bool'); -} - -},{"../doc":32,"../environment":34,"../tensor":146,"../util":151,"./concat":112,"./operation":122,"./rand":125}],107:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function axesAreInnerMostDims(axes, rank) { - for (var i = 0; i < axes.length; ++i) { - if (axes[axes.length - i - 1] !== rank - 1 - i) { - return false; - } - } - return true; -} -exports.axesAreInnerMostDims = axesAreInnerMostDims; -function combineLocations(outputLoc, reduceLoc, axes) { - var rank = outputLoc.length + reduceLoc.length; - var loc = []; - var outIdx = 0; - var reduceIdx = 0; - for (var dim = 0; dim < rank; dim++) { - if (axes.indexOf(dim) === -1) { - loc.push(outputLoc[outIdx++]); - } - else { - loc.push(reduceLoc[reduceIdx++]); - } - } - return loc; -} -exports.combineLocations = combineLocations; -function computeOutAndReduceShapes(aShape, axes) { - var outShape = []; - var rank = aShape.length; - for (var dim = 0; dim < rank; dim++) { - if (axes.indexOf(dim) === -1) { - outShape.push(aShape[dim]); - } - } - var reduceShape = axes.map(function (dim) { return aShape[dim]; }); - return [outShape, reduceShape]; -} -exports.computeOutAndReduceShapes = computeOutAndReduceShapes; -function expandShapeToKeepDim(shape, axes) { - var reduceSubShape = axes.map(function (x) { return 1; }); - return combineLocations(shape, reduceSubShape, axes); -} -exports.expandShapeToKeepDim = expandShapeToKeepDim; -function parseAxisParam(axis, shape) { - var rank = shape.length; - axis = axis == null ? shape.map(function (s, i) { return i; }) : [].concat(axis); - util.assert(axis.every(function (ax) { return ax >= -rank && ax < rank; }), "All values in axis param must be in range [-" + rank + ", " + rank + ") but " + - ("got axis " + axis)); - util.assert(axis.every(function (ax) { return util.isInt(ax); }), "All values in axis param must be integers but " + - ("got axis " + axis)); - return axis.map(function (a) { return a < 0 ? rank + a : a; }); -} -exports.parseAxisParam = parseAxisParam; -function assertAxesAreInnerMostDims(msg, axes, rank) { - util.assert(axesAreInnerMostDims(axes, rank), msg + " supports only inner-most axes for now. " + - ("Got axes " + axes + " and rank-" + rank + " input.")); -} -exports.assertAxesAreInnerMostDims = assertAxesAreInnerMostDims; -function getAxesPermutation(axes, rank) { - if (axesAreInnerMostDims(axes, rank)) { - return null; - } - var result = []; - for (var i = 0; i < rank; ++i) { - if (axes.indexOf(i) === -1) { - result.push(i); - } - } - axes.forEach(function (axis) { return result.push(axis); }); - return result; -} -exports.getAxesPermutation = getAxesPermutation; -function getUndoAxesPermutation(axes) { - return axes.map(function (axis, i) { return [i, axis]; }) - .sort(function (a, b) { return a[1] - b[1]; }) - .map(function (x) { return x[0]; }); -} -exports.getUndoAxesPermutation = getUndoAxesPermutation; -function getInnerMostAxes(numAxes, rank) { - var res = []; - for (var i = rank - numAxes; i < rank; ++i) { - res.push(i); - } - return res; -} -exports.getInnerMostAxes = getInnerMostAxes; - -},{"../util":151}],108:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.batchNormalization2d = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - util.assert(x.rank === 2, "Error in batchNormalization3D: x must be rank 3 but got rank " + - (x.rank + ".")); - util.assert(mean.rank === 2 || mean.rank === 1, "Error in batchNormalization2D: mean must be rank 2 or rank 1 but " + - ("got rank " + mean.rank + ".")); - util.assert(variance.rank === 2 || variance.rank === 1, "Error in batchNormalization2D: variance must be rank 2 or rank 1 " + - ("but got rank " + variance.rank + ".")); - if (scale != null) { - util.assert(scale.rank === 2 || scale.rank === 1, "Error in batchNormalization2D: scale must be rank 2 or rank 1 " + - ("but got rank " + scale.rank + ".")); - } - if (offset != null) { - util.assert(offset.rank === 2 || offset.rank === 1, "Error in batchNormalization2D: offset must be rank 2 or rank 1 " + - ("but got rank " + offset.rank + ".")); - } - return Ops.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset); - }; - Ops.batchNormalization3d = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - util.assert(x.rank === 3, "Error in batchNormalization3D: x must be rank 3 but got rank " + - (x.rank + ".")); - util.assert(mean.rank === 3 || mean.rank === 1, "Error in batchNormalization3D: mean must be rank 3 or rank 1 but " + - ("got rank " + mean.rank + ".")); - util.assert(variance.rank === 3 || variance.rank === 1, "Error in batchNormalization3D: variance must be rank 3 or rank 1 " + - ("but got rank " + variance.rank + ".")); - if (scale != null) { - util.assert(scale.rank === 3 || scale.rank === 1, "Error in batchNormalization3D: scale must be rank 3 or rank 1 " + - ("but got rank " + scale.rank + ".")); - } - if (offset != null) { - util.assert(offset.rank === 3 || offset.rank === 1, "Error in batchNormalization3D: offset must be rank 3 or rank 1 " + - ("but got rank " + offset.rank + ".")); - } - return Ops.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset); - }; - Ops.batchNormalization4d = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - util.assert(x.rank === 4, "Error in batchNormalization4D: x must be rank 4 but got rank " + - (x.rank + ".")); - util.assert(mean.rank === 4 || mean.rank === 1, "Error in batchNormalization4D: mean must be rank 4 or rank 1 but " + - ("got rank " + mean.rank + ".")); - util.assert(variance.rank === 4 || variance.rank === 1, "Error in batchNormalization4D: variance must be rank 4 or rank 1 " + - ("but got rank " + variance.rank + ".")); - if (scale != null) { - util.assert(scale.rank === 4 || scale.rank === 1, "Error in batchNormalization4D: scale must be rank 4 or rank 1 " + - ("but got rank " + scale.rank + ".")); - } - if (offset != null) { - util.assert(offset.rank === 4 || offset.rank === 1, "Error in batchNormalization4D: offset must be rank 4 or rank 1 " + - ("but got rank " + offset.rank + ".")); - } - return Ops.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset); - }; - Ops.batchNormalization = function (x, mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - var x4D; - if (x.rank === 0 || x.rank === 1) { - x4D = x.as4D(1, 1, 1, x.size); - } - else if (x.rank === 2) { - x4D = x.as4D(1, 1, x.shape[0], x.shape[1]); - } - else if (x.rank === 3) { - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - else { - x4D = x; - } - return environment_1.ENV.engine - .executeKernel('BatchNorm4D', { - inputs: { - x: x4D, - mean: batchnormReshape4D(mean), - variance: batchnormReshape4D(variance), - scale: batchnormReshape4D(scale), - offset: batchnormReshape4D(offset) - }, - args: { varianceEpsilon: varianceEpsilon } - }) - .reshape(x.shape); - }; - __decorate([ - operation_1.operation - ], Ops, "batchNormalization2d", null); - __decorate([ - operation_1.operation - ], Ops, "batchNormalization3d", null); - __decorate([ - operation_1.operation - ], Ops, "batchNormalization4d", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }) - ], Ops, "batchNormalization", null); - return Ops; -}()); -exports.Ops = Ops; -function batchnormReshape4D(x) { - if (x == null) { - return null; - } - if (x.rank === 0) { - return x.as1D(); - } - else if (x.rank === 1) { - return x; - } - else if (x.rank === 2) { - return x.as4D(1, 1, x.shape[0], x.shape[1]); - } - else if (x.rank === 3) { - return x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - return x; -} - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122}],109:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var broadcast_util = require("./broadcast_util"); -var operation_1 = require("./operation"); -var ops_1 = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.add = function (a, b) { - util.assertTypesMatch(a, b); - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.reshape(a.shape); - }; - var derB = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.reshape(b.shape); - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Add', { inputs: { a: a, b: b } }, der); - }; - Ops.addStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in addStrict: '); - return a.add(b); - }; - Ops.sub = function (a, b) { - util.assertTypesMatch(a, b); - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.reshape(a.shape); - }; - var derB = function () { - var res = dy; - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes); - } - return res.neg().reshape(b.shape); - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Sub', { inputs: { a: a, b: b } }, der); - }; - Ops.subStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in subStrict: '); - return a.sub(b); - }; - Ops.pow = function (base, exp) { - util.assert(exp.dtype === 'int32', 'only supports int32 data type for the exponent parameter.'); - broadcast_util.assertAndGetBroadcastShape(base.shape, exp.shape); - var gradient = function (dy, y) { - if (!util.arraysEqual(base.shape, exp.shape) && - !util.isScalarShape(exp.shape)) { - throw new Error("Gradient of pow not yet supported for broadcasted shapes."); - } - var derBase = function () { - var dx = exp.toFloat().mul(base.pow(exp.sub(ops_1.scalar(1, 'int32'))).toFloat()); - return dy.mul(dx); - }; - var derExp = function () { - throw new Error("Backprop through exponent not implemented yet."); - }; - return { base: derBase, exp: derExp }; - }; - return environment_1.ENV.engine.executeKernel('Pow', { inputs: { base: base, exp: exp } }, gradient); - }; - Ops.powStrict = function (base, exp) { - util.assertShapesMatch(base.shape, exp.shape, 'Error in powStrict: '); - return base.pow(exp); - }; - Ops.mul = function (a, b) { - util.assertTypesMatch(a, b); - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy.mul(b.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - return res.sum(reduceAxes).reshape(a.shape); - } - return res; - }; - var derB = function () { - var res = dy.mul(a.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - return res.sum(reduceAxes).reshape(b.shape); - } - return res; - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Mul', { inputs: { a: a, b: b } }, der); - }; - Ops.mulStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in multiplyStrict: '); - return a.mul(b); - }; - Ops.div = function (a, b) { - var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { - var res = dy.div(b.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape); - if (reduceAxes.length > 0) { - return res.sum(reduceAxes).reshape(a.shape); - } - return res; - }; - var derB = function () { - var res = dy.mul(a.toFloat()); - var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape); - if (reduceAxes.length > 0) { - res = res.sum(reduceAxes).reshape(b.shape); - } - var tmp = b.square(); - return res.div(tmp.toFloat()).neg(); - }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Div', { inputs: { a: a, b: b } }, der); - }; - Ops.divStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in divideStrict: '); - return a.div(b); - }; - Ops.minimum = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { return dy.mul(a.lessEqual(b).toFloat()); }; - var derB = function () { return dy.mul(a.greater(b).toFloat()); }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Minimum', { inputs: { a: a, b: b } }, der); - }; - Ops.minimumStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in minimumStrict: '); - return a.minimum(b); - }; - Ops.maximum = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - var der = function (dy, y) { - var derA = function () { return dy.mul(a.greaterEqual(b).toFloat()); }; - var derB = function () { return dy.mul(a.less(b).toFloat()); }; - return { a: derA, b: derB }; - }; - return environment_1.ENV.engine.executeKernel('Maximum', { inputs: { a: a, b: b } }, der); - }; - Ops.maximumStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in minimumStrict: '); - return a.maximum(b); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "add", null); - __decorate([ - operation_1.operation - ], Ops, "addStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "sub", null); - __decorate([ - operation_1.operation - ], Ops, "subStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "pow", null); - __decorate([ - operation_1.operation - ], Ops, "powStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "mul", null); - __decorate([ - operation_1.operation - ], Ops, "mulStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "div", null); - __decorate([ - operation_1.operation - ], Ops, "divStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "minimum", null); - __decorate([ - operation_1.operation - ], Ops, "minimumStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }), - operation_1.operation - ], Ops, "maximum", null); - __decorate([ - operation_1.operation - ], Ops, "maximumStrict", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./broadcast_util":110,"./operation":122,"./ops":123}],110:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function getBroadcastDims(inShape, outShape) { - var inRank = inShape.length; - var dims = []; - for (var i = 0; i < inRank; i++) { - var dim = inRank - 1 - i; - var a = inShape[dim] || 1; - var b = outShape[outShape.length - 1 - i] || 1; - if (b > 1 && a === 1) { - dims.unshift(dim); - } - } - return dims; -} -exports.getBroadcastDims = getBroadcastDims; -function getReductionAxes(inShape, outShape) { - var result = []; - for (var i = 0; i < outShape.length; i++) { - var inDim = inShape[inShape.length - i - 1]; - var outAxis = outShape.length - i - 1; - var outDim = outShape[outAxis]; - if (inDim == null || (inDim === 1 && outDim > 1)) { - result.unshift(outAxis); - } - } - return result; -} -exports.getReductionAxes = getReductionAxes; -function broadcastDimsAreOuter(dims) { - for (var i = 0; i < dims.length; i++) { - if (dims[i] !== i) { - return false; - } - } - return true; -} -exports.broadcastDimsAreOuter = broadcastDimsAreOuter; -function assertAndGetBroadcastShape(shapeA, shapeB) { - var result = []; - var errMsg = "Operands could not be broadcast together with shapes " + - (shapeA + " and " + shapeB + "."); - var l = Math.max(shapeA.length, shapeB.length); - for (var i = 0; i < l; i++) { - var a = shapeA[shapeA.length - i - 1] || 1; - var b = shapeB[shapeB.length - i - 1] || 1; - if (a > 1 && b > 1 && a !== b) { - throw Error(errMsg); - } - result.unshift(Math.max(a, b)); - } - return result; -} -exports.assertAndGetBroadcastShape = assertAndGetBroadcastShape; - -},{}],111:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var broadcast_util = require("./broadcast_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.notEqual = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('NotEqual', { inputs: { a: a, b: b } }); - }; - Ops.notEqualStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in notEqualStrict: '); - return a.notEqual(b); - }; - Ops.less = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('Less', { inputs: { a: a, b: b } }); - }; - Ops.lessStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in lessStrict: '); - return a.less(b); - }; - Ops.equal = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('Equal', { inputs: { a: a, b: b } }); - }; - Ops.equalStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in equalStrict: '); - return a.equal(b); - }; - Ops.lessEqual = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LessEqual', { inputs: { a: a, b: b } }); - }; - Ops.lessEqualStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in lessEqualStrict: '); - return a.lessEqual(b); - }; - Ops.greater = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('Greater', { inputs: { a: a, b: b } }); - }; - Ops.greaterStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in greaterStrict: '); - return a.greater(b); - }; - Ops.greaterEqual = function (a, b) { - util.assertTypesMatch(a, b); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('GreaterEqual', { inputs: { a: a, b: b } }); - }; - Ops.greaterEqualStrict = function (a, b) { - util.assertShapesMatch(a.shape, b.shape, 'Error in greaterEqualStrict: '); - return a.greaterEqual(b); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "notEqual", null); - __decorate([ - operation_1.operation - ], Ops, "notEqualStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "less", null); - __decorate([ - operation_1.operation - ], Ops, "lessStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "equal", null); - __decorate([ - operation_1.operation - ], Ops, "equalStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "lessEqual", null); - __decorate([ - operation_1.operation - ], Ops, "lessEqualStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "greater", null); - __decorate([ - operation_1.operation - ], Ops, "greaterStrict", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "greaterEqual", null); - __decorate([ - operation_1.operation - ], Ops, "greaterEqualStrict", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./broadcast_util":110,"./operation":122}],112:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var concat_util = require("./concat_util"); -var operation_1 = require("./operation"); -var Concat = (function () { - function Concat() { - } - Concat.concat1d = function (tensors) { - return Concat.concat(tensors, 0); - }; - Concat.concat2d = function (tensors, axis) { - return Concat.concat(tensors, axis); - }; - Concat.concat3d = function (tensors, axis) { - return Concat.concat(tensors, axis); - }; - Concat.concat4d = function (tensors, axis) { - return Concat.concat(tensors, axis); - }; - Concat.concat = function (tensors, axis) { - if (axis === void 0) { axis = 0; } - util.assert(tensors.length >= 2, 'Pass at least two tensors to concat'); - var result = tensors[0]; - for (var i = 1; i < tensors.length; ++i) { - result = concat2Tensors(result, tensors[i], axis); - } - return result; - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Concat, "concat", null); - return Concat; -}()); -exports.Concat = Concat; -function concat2Tensors(a, b, axis) { - concat_util.assertParams(a.shape, b.shape, axis); - var outShape = concat_util.computeOutShape(a.shape, b.shape, axis); - var a2D = a.as2D(-1, util.sizeFromShape(a.shape.slice(axis))); - var b2D = b.as2D(-1, util.sizeFromShape(b.shape.slice(axis))); - var _a = concat_util.computeGradientSliceShapes(a2D.shape, b2D.shape), aBegin = _a.aBegin, aSize = _a.aSize, bBegin = _a.bBegin, bSize = _a.bSize; - var der = function (dy) { - return { a: function () { return dy.slice(aBegin, aSize); }, b: function () { return dy.slice(bBegin, bSize); } }; - }; - var res = environment_1.ENV.engine.executeKernel('Concat', { inputs: { a: a2D, b: b2D } }, der); - return res.reshape(outShape); -} - -},{"../doc":32,"../environment":34,"../util":151,"./concat_util":113,"./operation":122}],113:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function assertParams(aShape, bShape, axis) { - var aRank = aShape.length; - var bRank = bShape.length; - util.assert(aShape.length === bShape.length, "Error in concat" + aRank + "D: rank of x1 (" + aRank + ") and x2 (" + bRank + ") " + - "must be the same."); - util.assert(axis >= 0 && axis < aRank, "Error in concat" + aRank + "D: axis must be " + - ("between 0 and " + (aRank - 1) + ".")); - for (var i = 0; i < aRank; i++) { - util.assert((i === axis) || (aShape[i] === bShape[i]), "Error in concat" + aRank + "D: Shape (" + aShape + ") does not match " + - ("(" + bShape + ") along the non-concatenated axis " + i + ".")); - } -} -exports.assertParams = assertParams; -function computeOutShape1D(x1Shape, x2Shape) { - util.assert(x1Shape.length === 1 && x2Shape.length === 1, 'x1 and x2 should be 1d array.'); - var outputShape = x1Shape.slice(); - outputShape[0] += x2Shape[0]; - return outputShape; -} -exports.computeOutShape1D = computeOutShape1D; -function computeOutShape(x1Shape, x2Shape, axis) { - util.assert(x1Shape.length === x2Shape.length, 'x1 and x2 should have the same rank.'); - var outputShape = x1Shape.slice(); - outputShape[axis] += x2Shape[axis]; - return outputShape; -} -exports.computeOutShape = computeOutShape; -function computeGradientSliceShapes(aShape, bShape) { - return { - aBegin: [0, 0], - aSize: aShape, - bBegin: [0, aShape[1]], - bSize: bShape - }; -} -exports.computeGradientSliceShapes = computeGradientSliceShapes; - -},{"../util":151}],114:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var conv_util = require("./conv_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.conv1d = function (input, filter, stride, pad, dimRoundingMode) { - var input3D = input; - var reshapedTo3D = false; - if (input.rank === 2) { - reshapedTo3D = true; - input3D = input.as3D(1, input.shape[0], input.shape[1]); - } - util.assert(input3D.rank === 3, "Error in conv1d: input must be rank 3, but got rank " + input3D.rank + "."); - util.assert(filter.rank === 3, "Error in conv1d: filter must be rank 3, but got rank " + - (filter.rank + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv1d: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - util.assert(input3D.shape[2] === filter.shape[1], "Error in conv1d: depth of input (" + input3D.shape[2] + ") must match " + - ("input depth for filter " + filter.shape[1] + ".")); - var filter4D = filter.as4D(1, filter.shape[0], filter.shape[1], filter.shape[2]); - var input4D = input3D.as4D(input3D.shape[0], 1, input3D.shape[1], input3D.shape[2]); - var strides = [1, stride]; - var res = Ops.conv2d(input4D, filter4D, strides, pad, dimRoundingMode); - if (reshapedTo3D) { - return res.as2D(res.shape[2], res.shape[3]); - } - return res.as3D(res.shape[0], res.shape[2], res.shape[3]); - }; - Ops.conv2d = function (x, filter, strides, pad, dimRoundingMode) { - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - util.assert(x4D.rank === 4, "Error in conv2d: input must be rank 4, but got rank " + x4D.rank + "."); - util.assert(filter.rank === 4, "Error in conv2d: filter must be rank 4, but got rank " + - (filter.rank + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv2d: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - util.assert(x4D.shape[3] === filter.shape[2], "Error in conv2d: depth of input (" + x4D.shape[3] + ") must match " + - ("input depth for filter " + filter.shape[2] + ".")); - var convInfo = conv_util.computeConv2DInfo(x4D.shape, filter.shape, strides, pad, dimRoundingMode); - var gradients = function (dy, y) { - return { - x: function () { return Ops.conv2dDerInput(x4D.shape, dy, filter, strides, pad); }, - filter: function () { return Ops.conv2dDerFilter(x4D, dy, filter.shape, strides, pad); } - }; - }; - var res = environment_1.ENV.engine.executeKernel('Conv2D', { inputs: { x: x4D, filter: filter }, args: { convInfo: convInfo } }, gradients); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.conv2dDerInput = function (xShape, dy, filter, strides, pad, dimRoundingMode) { - util.assert(xShape.length === dy.rank, "Length of inShape " + - ("(" + xShape.length + ") and rank of dy (" + dy.rank + ") must match")); - var xShape4D = xShape; - var dy4D = dy; - var reshapedTo4D = false; - if (dy.rank === 3) { - reshapedTo4D = true; - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - xShape4D = [1, xShape[0], xShape[1], xShape[2]]; - } - var inDepth = xShape4D[3]; - var outDepth = dy4D.shape[3]; - util.assert(xShape4D.length === 4, "Error in conv2dDerInput: inShape must be length 4, but got length " + - (xShape4D.length + ".")); - util.assert(dy4D.rank === 4, "Error in conv2dDerInput: dy must be rank 4, but got " + - ("rank " + dy4D.rank)); - util.assert(filter.rank === 4, "Error in conv2dDerInput: filter must be rank 4, but got " + - ("rank " + filter.rank)); - util.assert(inDepth === filter.shape[2], "Error in conv2dDerInput: depth of input (" + inDepth + ") must " + - ("match input depth for filter " + filter.shape[2] + ".")); - util.assert(outDepth === filter.shape[3], "Error in conv2dDerInput: depth of output (" + outDepth + ") must" + - ("match output depth for filter " + filter.shape[3] + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv2dDerInput: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computeConv2DInfo(xShape4D, filter.shape, strides, pad, dimRoundingMode); - var res = environment_1.ENV.engine.executeKernel('Conv2DDerInput', { inputs: { dy: dy4D, filter: filter }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.conv2dDerFilter = function (x, dy, filterShape, strides, pad, dimRoundingMode) { - var x4D = x; - if (x.rank === 3) { - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - var dy4D = dy; - if (dy4D.rank === 3) { - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - } - util.assert(x4D.rank === 4, "Error in conv2dDerFilter: input must be rank 4, but got shape " + - (x4D.shape + ".")); - util.assert(dy4D.rank === 4, "Error in conv2dDerFilter: dy must be rank 4, but got shape " + - (dy4D.shape + ".")); - util.assert(filterShape.length === 4, "Error in conv2dDerFilter: filterShape must be length 4, but got " + - (filterShape + ".")); - util.assert(x4D.shape[3] === filterShape[2], "Error in conv2dDerFilter: depth of input " + x4D.shape[3] + ") must " + - ("match input depth in filter (" + filterShape[2] + ".")); - util.assert(dy4D.shape[3] === filterShape[3], "Error in conv2dDerFilter: depth of dy (" + dy4D.shape[3] + ") must " + - ("match output depth for filter (" + filterShape[3] + ").")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in conv2dDerFilter: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computeConv2DInfo(x4D.shape, filterShape, strides, pad, dimRoundingMode); - return environment_1.ENV.engine.executeKernel('Conv2DDerFilter', { inputs: { x: x4D, dy: dy4D }, args: { convInfo: convInfo } }); - }; - Ops.conv2dTranspose = function (x, filter, outputShape, strides, pad, dimRoundingMode) { - return Ops.conv2dDerInput(outputShape, x, filter, strides, pad, dimRoundingMode); - }; - Ops.depthwiseConv2d = function (input, filter, strides, pad, rates, dimRoundingMode) { - if (rates === void 0) { rates = [1, 1]; } - var input4D = input; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - } - util.assert(input4D.rank === 4, "Error in depthwiseConv2D: input must be rank 4, but got " + - ("rank " + input4D.rank + ".")); - util.assert(filter.rank === 4, "Error in depthwiseConv2D: filter must be rank 4, but got rank " + - (filter.rank + ".")); - util.assert(input4D.shape[3] === filter.shape[2], "Error in depthwiseConv2D: number of input channels " + - ("(" + input4D.shape[3] + ") must match the inChannels dimension in ") + - ("filter " + filter.shape[2] + ".")); - rates = rates || [1, 1]; - var _a = parseTupleParam(rates), rateHeight = _a[0], rateWidth = _a[1]; - util.assert(rateHeight === 1 && rateWidth === 1, 'Error in depthwiseConv2D: rates greater than 1 are not yet ' + - ("supported. Got rates '" + rates + "'")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in depthwiseConv2D: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computeConv2DInfo(input4D.shape, filter.shape, strides, pad, dimRoundingMode, true); - var res = environment_1.ENV.engine.executeKernel('DepthwiseConv2D', { inputs: { x: input4D, filter: filter }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "conv1d", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "conv2d", null); - __decorate([ - operation_1.operation - ], Ops, "conv2dDerInput", null); - __decorate([ - operation_1.operation - ], Ops, "conv2dDerFilter", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "conv2dTranspose", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "depthwiseConv2d", null); - return Ops; -}()); -exports.Ops = Ops; -function parseTupleParam(param) { - return typeof param === 'number' ? [param, param] : param; -} - -},{"../doc":32,"../environment":34,"../util":151,"./conv_util":115,"./operation":122}],115:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function computePool2DInfo(inShape, filterSize, strides, pad, roundingMode, dataFormat) { - if (dataFormat === void 0) { dataFormat = 'channelsLast'; } - var _a = parseTupleParam(filterSize), filterHeight = _a[0], filterWidth = _a[1]; - var filterShape; - if (dataFormat === 'channelsLast') { - filterShape = [filterHeight, filterWidth, inShape[3], inShape[3]]; - } - else if (dataFormat === 'channelsFirst') { - filterShape = [filterHeight, filterWidth, inShape[1], inShape[1]]; - } - else { - throw new Error("Unknown dataFormat " + dataFormat); - } - return computeConv2DInfo(inShape, filterShape, strides, pad, roundingMode, false, dataFormat); -} -exports.computePool2DInfo = computePool2DInfo; -function computeConv2DInfo(inShape, filterShape, strides, pad, roundingMode, depthwise, dataFormat) { - if (depthwise === void 0) { depthwise = false; } - if (dataFormat === void 0) { dataFormat = 'channelsLast'; } - var _a = [-1, -1, -1, -1], batchSize = _a[0], inHeight = _a[1], inWidth = _a[2], inChannels = _a[3]; - if (dataFormat === 'channelsLast') { - batchSize = inShape[0], inHeight = inShape[1], inWidth = inShape[2], inChannels = inShape[3]; - } - else if (dataFormat === 'channelsFirst') { - batchSize = inShape[0], inChannels = inShape[1], inHeight = inShape[2], inWidth = inShape[3]; - } - else { - throw new Error("Unknown dataFormat " + dataFormat); - } - var filterHeight = filterShape[0], filterWidth = filterShape[1], filterChannels = filterShape[3]; - var _b = parseTupleParam(strides), strideHeight = _b[0], strideWidth = _b[1]; - var _c = getPadAndOutInfo(pad, inHeight, inWidth, strideHeight, strideWidth, filterHeight, filterWidth, roundingMode), padInfo = _c.padInfo, outHeight = _c.outHeight, outWidth = _c.outWidth; - var outChannels = depthwise ? filterChannels * inChannels : filterChannels; - var outShape; - if (dataFormat === 'channelsFirst') { - outShape = [batchSize, outChannels, outHeight, outWidth]; - } - else if (dataFormat === 'channelsLast') { - outShape = [batchSize, outHeight, outWidth, outChannels]; - } - return { - batchSize: batchSize, - dataFormat: dataFormat, - inHeight: inHeight, - inWidth: inWidth, - inChannels: inChannels, - outHeight: outHeight, - outWidth: outWidth, - outChannels: outChannels, - padInfo: padInfo, - strideHeight: strideHeight, - strideWidth: strideWidth, - filterHeight: filterHeight, - filterWidth: filterWidth, - inShape: inShape, - outShape: outShape, - filterShape: filterShape - }; -} -exports.computeConv2DInfo = computeConv2DInfo; -function computeOutputShape3D(inShape, fieldSize, outDepth, stride, zeroPad, roundingMode) { - if (zeroPad == null) { - zeroPad = computeDefaultPad(inShape, fieldSize, stride); - } - var inputRows = inShape[0]; - var inputCols = inShape[1]; - var outputRows = conditionalRound((inputRows - fieldSize + 2 * zeroPad) / stride + 1, roundingMode); - util.assert(util.isInt(outputRows), "The output # of rows (" + outputRows + ") must be an integer. Change the " + - "stride and/or zero pad parameters"); - var outputCols = conditionalRound((inputCols - fieldSize + 2 * zeroPad) / stride + 1, roundingMode); - util.assert(util.isInt(outputCols), "The output # of columns (" + outputCols + ") must be an integer. Change " + - "the stride and/or zero pad parameters"); - return [outputRows, outputCols, outDepth]; -} -exports.computeOutputShape3D = computeOutputShape3D; -function computeDefaultPad(inputShape, fieldSize, stride) { - return Math.floor((inputShape[0] * (stride - 1) - stride + fieldSize) / 2); -} -exports.computeDefaultPad = computeDefaultPad; -function computeWeightsShape4D(inputDepth, outputDepth, filterHeight, filterWidth) { - return [filterHeight, filterWidth, inputDepth, outputDepth]; -} -exports.computeWeightsShape4D = computeWeightsShape4D; -function computeDilatedRC(rc, origStride) { - var rowsDilated = (rc[0] - 1) * origStride + 1; - var colsDilated = (rc[1] - 1) * origStride + 1; - return [rowsDilated, colsDilated]; -} -exports.computeDilatedRC = computeDilatedRC; -function parseTupleParam(param) { - return typeof param === 'number' ? [param, param] : param; -} -function getPadAndOutInfo(pad, inHeight, inWidth, strideHeight, strideWidth, filterHeight, filterWidth, roundingMode) { - var padInfo; - var outHeight; - var outWidth; - if (typeof pad === 'number') { - padInfo = { top: pad, bottom: pad, left: pad, right: pad }; - var outShape = computeOutputShape3D([inHeight, inWidth, 1], filterHeight, 1, strideHeight, pad, roundingMode); - outHeight = outShape[0]; - outWidth = outShape[1]; - } - else if (pad === 'same') { - outHeight = Math.ceil(inHeight / strideHeight); - outWidth = Math.ceil(inWidth / strideWidth); - var padAlongHeight = (outHeight - 1) * strideHeight + filterHeight - inHeight; - var padAlongWidth = (outWidth - 1) * strideWidth + filterWidth - inWidth; - var top_1 = Math.floor(padAlongHeight / 2); - var bottom = padAlongHeight - top_1; - var left = Math.floor(padAlongWidth / 2); - var right = padAlongWidth - left; - padInfo = { top: top_1, bottom: bottom, left: left, right: right }; - } - else if (pad === 'valid') { - padInfo = { top: 0, bottom: 0, left: 0, right: 0 }; - outHeight = Math.ceil((inHeight - filterHeight + 1) / strideHeight); - outWidth = Math.ceil((inWidth - filterWidth + 1) / strideWidth); - } - else { - throw Error("Unknown padding parameter: " + pad); - } - return { padInfo: padInfo, outHeight: outHeight, outWidth: outWidth }; -} -function conditionalRound(value, roundingMode) { - if (!roundingMode) { - return value; - } - switch (roundingMode) { - case 'round': - return Math.round(value); - case 'ceil': - return Math.ceil(value); - case 'floor': - return Math.floor(value); - default: - throw new Error("Unknown roundingMode " + roundingMode); - } -} - -},{"../util":151}],116:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.resizeBilinear = function (images, size, alignCorners) { - if (alignCorners === void 0) { alignCorners = false; } - util.assert(images.rank === 3 || images.rank === 4, "Error in resizeBilinear: x must be rank 3 or 4, but got " + - ("rank " + images.rank + ".")); - util.assert(size.length === 2, "Error in resizeBilinear: new shape must 2D, but got shape " + - (size + ".")); - var batchImages = images; - var reshapedTo4D = false; - if (images.rank === 3) { - reshapedTo4D = true; - batchImages = - images.as4D(1, images.shape[0], images.shape[1], images.shape[2]); - } - var newHeight = size[0], newWidth = size[1]; - var res = environment_1.ENV.engine.executeKernel('ResizeBilinear', { inputs: { x: batchImages }, args: { newHeight: newHeight, newWidth: newWidth, alignCorners: alignCorners } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Images', namespace: 'image' }), - operation_1.operation - ], Ops, "resizeBilinear", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122}],117:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var types = require("../types"); -var util = require("../util"); -var broadcast_util = require("./broadcast_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.logicalNot = function (x) { - util.assert(x.dtype === 'bool', 'Error Array must be of type bool.'); - return environment_1.ENV.engine.executeKernel('LogicalNot', { inputs: { x: x } }); - }; - Ops.logicalAnd = function (a, b) { - util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.'); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LogicalAnd', { inputs: { a: a, b: b } }); - }; - Ops.logicalOr = function (a, b) { - util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.'); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LogicalOr', { inputs: { a: a, b: b } }); - }; - Ops.logicalXor = function (a, b) { - util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.'); - broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape); - return environment_1.ENV.engine.executeKernel('LogicalXor', { inputs: { a: a, b: b } }); - }; - Ops.where = function (condition, a, b) { - util.assert(condition.dtype === 'bool' || a.dtype === 'bool' || b.dtype === 'bool', 'Error Array must be of type bool.'); - util.assertShapesMatch(a.shape, b.shape, 'Error in where: '); - if (condition.rank === 1) { - util.assert(condition.shape[0] === a.shape[0], 'The first dimension of `a` must match the size of `condition`.'); - } - else { - util.assertShapesMatch(condition.shape, b.shape, 'Error in where: '); - } - var dtype = types.upcastType(a.dtype, b.dtype); - return environment_1.ENV.engine.executeKernel('Where', { inputs: { condition: condition, a: a, b: b }, args: { dtype: dtype } }); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalNot", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalAnd", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalOr", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "logicalXor", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Logical' }), - operation_1.operation - ], Ops, "where", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../types":150,"../util":151,"./broadcast_util":110,"./operation":122}],118:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var LRN = (function () { - function LRN() { - } - LRN.localResponseNormalization = function (x, radius, bias, alpha, beta, normRegion) { - if (radius === void 0) { radius = 5; } - if (bias === void 0) { bias = 1; } - if (alpha === void 0) { alpha = 1; } - if (beta === void 0) { beta = 0.5; } - if (normRegion === void 0) { normRegion = 'acrossChannels'; } - util.assert(x.rank === 4 || x.rank === 3, "Error in localResponseNormalization: x must be rank 3 or 4 but got\n rank " + x.rank + "."); - util.assert(util.isInt(radius), "Error in localResponseNormalization3D: radius must be an integer\n but got radius " + radius + "."); - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - var res = environment_1.ENV.engine.executeKernel('LRN4D', { inputs: { x: x4D }, args: { radius: radius, bias: bias, alpha: alpha, beta: beta, normRegion: normRegion } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - else { - return res; - } - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }), - operation_1.operation - ], LRN, "localResponseNormalization", null); - return LRN; -}()); -exports.LRN = LRN; - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122}],119:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.multiRNNCell = function (lstmCells, data, c, h) { - var input = data; - var newStates = []; - for (var i = 0; i < lstmCells.length; i++) { - var output = lstmCells[i](input, c[i], h[i]); - newStates.push(output[0]); - newStates.push(output[1]); - input = output[1]; - } - var newC = []; - var newH = []; - for (var i = 0; i < newStates.length; i += 2) { - newC.push(newStates[i]); - newH.push(newStates[i + 1]); - } - return [newC, newH]; - }; - Ops.basicLSTMCell = function (forgetBias, lstmKernel, lstmBias, data, c, h) { - var combined = data.concat(h, 1); - var weighted = combined.matMul(lstmKernel); - var res = weighted.add(lstmBias); - var batchSize = res.shape[0]; - var sliceCols = res.shape[1] / 4; - var sliceSize = [batchSize, sliceCols]; - var i = res.slice([0, 0], sliceSize); - var j = res.slice([0, sliceCols], sliceSize); - var f = res.slice([0, sliceCols * 2], sliceSize); - var o = res.slice([0, sliceCols * 3], sliceSize); - var newC = i.sigmoid().mulStrict(j.tanh()).addStrict(c.mulStrict(forgetBias.add(f).sigmoid())); - var newH = newC.tanh().mulStrict(o.sigmoid()); - return [newC, newH]; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'RNN' }), - operation_1.operation - ], Ops, "multiRNNCell", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'RNN' }), - operation_1.operation - ], Ops, "basicLSTMCell", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"./operation":122}],120:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var matmul_1 = require("../kernels/types/matmul"); -var util = require("../util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.matMul = function (a, b, transposeA, transposeB) { - if (transposeA === void 0) { transposeA = false; } - if (transposeB === void 0) { transposeB = false; } - _a = [enumToBool(transposeA), enumToBool(transposeB)], transposeA = _a[0], transposeB = _a[1]; - var innerShapeA = transposeA ? a.shape[0] : a.shape[1]; - var innerShapeB = transposeB ? b.shape[1] : b.shape[0]; - util.assert(a.rank === 2 && b.rank === 2, "Error in matMul: inputs must be rank 2, got ranks " + a.rank + - (" and " + b.rank + ".")); - util.assert(innerShapeA === innerShapeB, "Error in matMul: inner shapes (" + innerShapeA + ") and (" + - (innerShapeB + ") of Tensors with shapes " + a.shape + " and ") + - (b.shape + " and transposeA=" + transposeA) + - (" and transposeB=" + transposeB + " must match.")); - return environment_1.ENV.engine.executeKernel('MatMul', { inputs: { a: a, b: b }, args: { transposeA: transposeA, transposeB: transposeB } }, function (dy, y) { - if (transposeA || transposeB) { - throw new Error("Backprop for transposed MatMul not yet implemented."); - } - return { - a: function () { return dy.matMul(b.toFloat(), false, true); }, - b: function () { return a.toFloat().matMul(dy, true, false); } - }; - }); - var _a; - }; - Ops.vectorTimesMatrix = function (v, matrix) { - util.assert(v.rank === 1, "Error in vectorTimesMatrix: first input must be rank 1, but got " + - ("rank " + v.rank + ".")); - util.assert(matrix.rank === 2, "Error in vectorTimesMatrix: second input must be rank 2, but got " + - ("rank " + matrix.rank + ".")); - util.assert(v.size === matrix.shape[0], "Error in vectorTimesMatrix: size of vector (" + v.size + ") " + - ("must match first dimension of matrix (" + matrix.shape[0] + ")")); - return v.as2D(1, -1).matMul(matrix).as1D(); - }; - Ops.matrixTimesVector = function (matrix, v) { - util.assert(v.rank === 1, "Error in matrixTimesVector: second input must rank 1, but got " + - ("rank " + v.rank + ".")); - util.assert(matrix.rank === 2, "Error in matrixTimesVector: first input must be a rank 2, but got " + - ("rank " + matrix.rank + ".")); - util.assert(v.size === matrix.shape[1], "Error in matrixTimesVector: size of first rank 1 input " + v.size + " " + - "must match inner dimension of second rank 2 input, but got " + - ("shape " + matrix.shape + ".")); - return matrix.matMul(v.as2D(-1, 1)).as1D(); - }; - Ops.dotProduct = function (v1, v2) { - util.assert(v1.rank === 1 && v2.rank === 1, "Error in dotProduct: inputs must be rank 1, but got ranks " + - (v1.rank + " and " + v2.rank + ".")); - util.assert(v1.size === v2.size, "Error in dotProduct: size of inputs (" + v1.size + ") and (" + - (v2.size + ") must match.")); - return v1.as2D(1, -1).matMul(v2.as2D(-1, 1)).asScalar(); - }; - Ops.outerProduct = function (v1, v2) { - util.assert(v1.rank === 1 && v2.rank === 1, "Error in outerProduct: inputs must be rank 1, but got ranks " + - (v1.rank + " and " + v2.rank + ".")); - return v1.as2D(-1, 1).matMul(v2.as2D(1, -1)); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "matMul", null); - __decorate([ - operation_1.operation - ], Ops, "vectorTimesMatrix", null); - __decorate([ - operation_1.operation - ], Ops, "matrixTimesVector", null); - __decorate([ - operation_1.operation - ], Ops, "dotProduct", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "outerProduct", null); - return Ops; -}()); -exports.Ops = Ops; -function enumToBool(transpose) { - if (transpose === matmul_1.MatrixOrientation.REGULAR) { - return false; - } - if (transpose === matmul_1.MatrixOrientation.TRANSPOSED) { - return true; - } - return transpose; -} - -},{"../doc":32,"../environment":34,"../kernels/types/matmul":71,"../util":151,"./operation":122}],121:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.norm = function (x, ord, axis, keepDims) { - if (ord === void 0) { ord = 'euclidean'; } - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var norm = normImpl(x, ord, axis); - var keepDimsShape = norm.shape; - if (keepDims) { - var axes = axis_util.parseAxisParam(axis, x.shape); - keepDimsShape = axis_util.expandShapeToKeepDim(norm.shape, axes); - } - return norm.reshape(keepDimsShape); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "norm", null); - return Ops; -}()); -exports.Ops = Ops; -function normImpl(x, p, axis) { - if (axis === void 0) { axis = null; } - if (x.rank === 0) { - return x.abs(); - } - if (x.rank !== 1 && axis === null) { - return normImpl(x.reshape([-1]), p, axis); - } - if (x.rank === 1 || typeof axis === 'number' || - axis instanceof Array && axis.length === 1) { - if (p === 1) { - return x.abs().sum(axis); - } - if (p === Infinity) { - return x.abs().max(axis); - } - if (p === -Infinity) { - return x.abs().min(axis); - } - if (p === 'euclidean' || p === 2) { - return x.abs().pow(ops.scalar(2, 'int32')).sum(axis).sqrt(); - } - throw new Error("Error in norm: invalid ord value: " + p); - } - if (axis instanceof Array && axis.length === 2) { - if (p === 1) { - return x.abs().sum(axis[0]).max(axis[1] - 1); - } - if (p === Infinity) { - return x.abs().sum(axis[1]).max(axis[0]); - } - if (p === -Infinity) { - return x.abs().sum(axis[1]).min(axis[0]); - } - if (p === 'fro' || p === 'euclidean') { - return x.square().sum(axis).sqrt(); - } - throw new Error("Error in norm: invalid ord value: " + p); - } - throw new Error("Error in norm: invalid axis: " + axis); -} - -},{"../doc":32,"./axis_util":107,"./operation":122,"./ops":123}],122:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var globals_1 = require("../globals"); -function operation(target, name, descriptor) { - var fn = descriptor.value; - descriptor.value = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return globals_1.tidy(name, function () { return fn.apply(void 0, args); }); - }; - return descriptor; -} -exports.operation = operation; - -},{"../globals":35}],123:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var array_ops = require("./array_ops"); -var batchnorm_ops = require("./batchnorm"); -var binary_ops = require("./binary_ops"); -var compare_ops = require("./compare"); -var concat_ops = require("./concat"); -var conv_ops = require("./conv"); -var image_ops = require("./image_ops"); -var logical_ops = require("./logical_ops"); -var lrn_ops = require("./lrn"); -var lstm_ops = require("./lstm"); -var matmul_ops = require("./matmul"); -var norm_ops = require("./norm"); -var pool_ops = require("./pool"); -var reduction_ops = require("./reduction_ops"); -var reverse_ops = require("./reverse"); -var slice_ops = require("./slice"); -var softmax_ops = require("./softmax"); -var transpose_ops = require("./transpose"); -var unary_ops = require("./unary_ops"); -exports.batchNormalization = batchnorm_ops.Ops.batchNormalization; -exports.batchNormalization2d = batchnorm_ops.Ops.batchNormalization2d; -exports.batchNormalization3d = batchnorm_ops.Ops.batchNormalization3d; -exports.batchNormalization4d = batchnorm_ops.Ops.batchNormalization4d; -exports.concat = concat_ops.Concat.concat; -exports.concat1d = concat_ops.Concat.concat1d; -exports.concat2d = concat_ops.Concat.concat2d; -exports.concat3d = concat_ops.Concat.concat3d; -exports.concat4d = concat_ops.Concat.concat4d; -exports.conv1d = conv_ops.Ops.conv1d; -exports.conv2d = conv_ops.Ops.conv2d; -exports.conv2dTranspose = conv_ops.Ops.conv2dTranspose; -exports.depthwiseConv2d = conv_ops.Ops.depthwiseConv2d; -exports.matMul = matmul_ops.Ops.matMul; -exports.matrixTimesVector = matmul_ops.Ops.matrixTimesVector; -exports.outerProduct = matmul_ops.Ops.outerProduct; -exports.vectorTimesMatrix = matmul_ops.Ops.vectorTimesMatrix; -exports.avgPool = pool_ops.Ops.avgPool; -exports.maxPool = pool_ops.Ops.maxPool; -exports.minPool = pool_ops.Ops.minPool; -exports.transpose = transpose_ops.Ops.transpose; -exports.reverse = reverse_ops.Ops.reverse; -exports.reverse1d = reverse_ops.Ops.reverse1d; -exports.reverse2d = reverse_ops.Ops.reverse2d; -exports.reverse3d = reverse_ops.Ops.reverse3d; -exports.reverse4d = reverse_ops.Ops.reverse4d; -exports.slice = slice_ops.Ops.slice; -exports.slice1d = slice_ops.Ops.slice1d; -exports.slice2d = slice_ops.Ops.slice2d; -exports.slice3d = slice_ops.Ops.slice3d; -exports.slice4d = slice_ops.Ops.slice4d; -exports.argMax = reduction_ops.Ops.argMax; -exports.argMin = reduction_ops.Ops.argMin; -exports.logSumExp = reduction_ops.Ops.logSumExp; -exports.max = reduction_ops.Ops.max; -exports.mean = reduction_ops.Ops.mean; -exports.min = reduction_ops.Ops.min; -exports.moments = reduction_ops.Ops.moments; -exports.sum = reduction_ops.Ops.sum; -exports.equal = compare_ops.Ops.equal; -exports.equalStrict = compare_ops.Ops.equalStrict; -exports.greater = compare_ops.Ops.greater; -exports.greaterStrict = compare_ops.Ops.greaterStrict; -exports.greaterEqual = compare_ops.Ops.greaterEqual; -exports.greaterEqualStrict = compare_ops.Ops.greaterEqualStrict; -exports.less = compare_ops.Ops.less; -exports.lessStrict = compare_ops.Ops.lessStrict; -exports.lessEqual = compare_ops.Ops.lessEqual; -exports.lessEqualStrict = compare_ops.Ops.lessEqualStrict; -exports.notEqual = compare_ops.Ops.notEqual; -exports.notEqualStrict = compare_ops.Ops.notEqualStrict; -exports.logicalNot = logical_ops.Ops.logicalNot; -exports.logicalAnd = logical_ops.Ops.logicalAnd; -exports.logicalOr = logical_ops.Ops.logicalOr; -exports.logicalXor = logical_ops.Ops.logicalXor; -exports.where = logical_ops.Ops.where; -exports.abs = unary_ops.Ops.abs; -exports.acos = unary_ops.Ops.acos; -exports.asin = unary_ops.Ops.asin; -exports.atan = unary_ops.Ops.atan; -exports.ceil = unary_ops.Ops.ceil; -exports.clipByValue = unary_ops.Ops.clipByValue; -exports.cos = unary_ops.Ops.cos; -exports.cosh = unary_ops.Ops.cosh; -exports.elu = unary_ops.Ops.elu; -exports.exp = unary_ops.Ops.exp; -exports.floor = unary_ops.Ops.floor; -exports.leakyRelu = unary_ops.Ops.leakyRelu; -exports.log = unary_ops.Ops.log; -exports.neg = unary_ops.Ops.neg; -exports.prelu = unary_ops.Ops.prelu; -exports.relu = unary_ops.Ops.relu; -exports.selu = unary_ops.Ops.selu; -exports.sigmoid = unary_ops.Ops.sigmoid; -exports.sin = unary_ops.Ops.sin; -exports.sinh = unary_ops.Ops.sinh; -exports.sqrt = unary_ops.Ops.sqrt; -exports.square = unary_ops.Ops.square; -exports.step = unary_ops.Ops.step; -exports.tan = unary_ops.Ops.tan; -exports.tanh = unary_ops.Ops.tanh; -exports.add = binary_ops.Ops.add; -exports.addStrict = binary_ops.Ops.addStrict; -exports.div = binary_ops.Ops.div; -exports.divStrict = binary_ops.Ops.divStrict; -exports.maximum = binary_ops.Ops.maximum; -exports.maximumStrict = binary_ops.Ops.maximumStrict; -exports.minimum = binary_ops.Ops.minimum; -exports.minimumStrict = binary_ops.Ops.minimumStrict; -exports.mul = binary_ops.Ops.mul; -exports.mulStrict = binary_ops.Ops.mulStrict; -exports.pow = binary_ops.Ops.pow; -exports.powStrict = binary_ops.Ops.powStrict; -exports.sub = binary_ops.Ops.sub; -exports.subStrict = binary_ops.Ops.subStrict; -exports.norm = norm_ops.Ops.norm; -exports.cast = array_ops.Ops.cast; -exports.clone = array_ops.Ops.clone; -exports.fromPixels = array_ops.Ops.fromPixels; -exports.ones = array_ops.Ops.ones; -exports.onesLike = array_ops.Ops.onesLike; -exports.zeros = array_ops.Ops.zeros; -exports.zerosLike = array_ops.Ops.zerosLike; -exports.rand = array_ops.Ops.rand; -exports.randomNormal = array_ops.Ops.randomNormal; -exports.truncatedNormal = array_ops.Ops.truncatedNormal; -exports.randomUniform = array_ops.Ops.randomUniform; -exports.reshape = array_ops.Ops.reshape; -exports.squeeze = array_ops.Ops.squeeze; -exports.tile = array_ops.Ops.tile; -exports.gather = array_ops.Ops.gather; -exports.oneHot = array_ops.Ops.oneHot; -exports.linspace = array_ops.Ops.linspace; -exports.range = array_ops.Ops.range; -exports.buffer = array_ops.Ops.buffer; -exports.fill = array_ops.Ops.fill; -exports.tensor = array_ops.Ops.tensor; -exports.scalar = array_ops.Ops.scalar; -exports.tensor1d = array_ops.Ops.tensor1d; -exports.tensor2d = array_ops.Ops.tensor2d; -exports.tensor3d = array_ops.Ops.tensor3d; -exports.tensor4d = array_ops.Ops.tensor4d; -exports.print = array_ops.Ops.print; -exports.expandDims = array_ops.Ops.expandDims; -exports.stack = array_ops.Ops.stack; -exports.pad = array_ops.Ops.pad; -exports.pad1d = array_ops.Ops.pad1d; -exports.pad2d = array_ops.Ops.pad2d; -exports.basicLSTMCell = lstm_ops.Ops.basicLSTMCell; -exports.multiRNNCell = lstm_ops.Ops.multiRNNCell; -exports.softmax = softmax_ops.Ops.softmax; -exports.localResponseNormalization = lrn_ops.LRN.localResponseNormalization; -var tensor_1 = require("../tensor"); -var types_1 = require("../types"); -[tensor_1.Tensor, types_1.Rank, tensor_1.Tensor3D, tensor_1.Tensor4D]; -exports.losses = { - softmaxCrossEntropy: softmax_ops.Ops.softmaxCrossEntropy -}; -exports.image = { - resizeBilinear: image_ops.Ops.resizeBilinear -}; - -},{"../tensor":146,"../types":150,"./array_ops":106,"./batchnorm":108,"./binary_ops":109,"./compare":111,"./concat":112,"./conv":114,"./image_ops":116,"./logical_ops":117,"./lrn":118,"./lstm":119,"./matmul":120,"./norm":121,"./pool":124,"./reduction_ops":127,"./reverse":128,"./slice":130,"./softmax":132,"./transpose":133,"./unary_ops":134}],124:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var conv_util = require("./conv_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.maxPool = function (x, filterSize, strides, pad, dimRoundingMode) { - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - util.assert(x4D.rank === 4, "Error in maxPool: input must be rank 4 but got rank " + x4D.rank + "."); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in maxPool: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(x4D.shape, filterSize, strides, pad, dimRoundingMode); - var gradients = function (dy, y) { - return { x: function () { return Ops.maxPoolBackprop(dy, x4D, filterSize, strides, pad); } }; - }; - var res = environment_1.ENV.engine.executeKernel('MaxPool', { inputs: { x: x4D }, args: { convInfo: convInfo } }, gradients); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.maxPoolBackprop = function (dy, input, filterSize, strides, pad, dimRoundingMode) { - util.assert(input.rank === dy.rank, "Rank of input (" + input.rank + ") does not match rank of dy (" + dy.rank + ")"); - var input4D = input; - var dy4D = dy; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - } - util.assert(dy4D.rank === 4, "Error in maxPoolBackprop: dy must be rank 4 but got rank " + - (dy4D.rank + ".")); - util.assert(input4D.rank === 4, "Error in maxPoolBackprop: input must be rank 4 but got rank " + - (input4D.rank + ".")); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in maxPoolBackprop: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad, dimRoundingMode); - var res = environment_1.ENV.engine.executeKernel('MaxPoolBackprop', { inputs: { dy: dy4D, x: input4D }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.minPool = function (input, filterSize, strides, pad, dimRoundingMode) { - var input4D = input; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - } - util.assert(input4D.rank === 4, "Error in minPool: x must be rank 4 but got rank " + input4D.rank + "."); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in minPool: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad, dimRoundingMode); - var res = environment_1.ENV.engine.executeKernel('MinPool', { inputs: { x: input4D }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.avgPool = function (x, filterSize, strides, pad, dimRoundingMode) { - var x4D = x; - var reshapedTo4D = false; - if (x.rank === 3) { - reshapedTo4D = true; - x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - util.assert(x4D.rank === 4, "Error in avgPool: x must be rank 4 but got rank " + x4D.rank + "."); - if (dimRoundingMode != null) { - util.assert(util.isInt(pad), "Error in avgPool: pad must be an integer when using, " + - ("dimRoundingMode " + dimRoundingMode + " but got pad " + pad + ".")); - } - var convInfo = conv_util.computePool2DInfo(x4D.shape, filterSize, strides, pad); - var gradients = function (dy, y) { - return { x: function () { return Ops.avgPoolBackprop(dy, x4D, filterSize, strides, pad); } }; - }; - var res = environment_1.ENV.engine.executeKernel('AvgPool', { inputs: { x: x4D }, args: { convInfo: convInfo } }, gradients); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - Ops.avgPoolBackprop = function (dy, input, filterSize, strides, pad) { - util.assert(input.rank === dy.rank, "Rank of input (" + input.rank + ") does not match rank of dy (" + dy.rank + ")"); - var input4D = input; - var dy4D = dy; - var reshapedTo4D = false; - if (input.rank === 3) { - reshapedTo4D = true; - input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]); - dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]); - } - util.assert(dy4D.rank === 4, "Error in avgPoolBackprop: dy must be rank 4 but got rank " + - (dy4D.rank + ".")); - util.assert(input4D.rank === 4, "Error in avgPoolBackprop: input must be rank 4 but got rank " + - (input4D.rank + ".")); - var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad); - var res = environment_1.ENV.engine.executeKernel('AvgPoolBackprop', { inputs: { dy: dy4D, x: input4D }, args: { convInfo: convInfo } }); - if (reshapedTo4D) { - return res.as3D(res.shape[1], res.shape[2], res.shape[3]); - } - return res; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "maxPool", null); - __decorate([ - operation_1.operation - ], Ops, "maxPoolBackprop", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "minPool", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }), - operation_1.operation - ], Ops, "avgPool", null); - __decorate([ - operation_1.operation - ], Ops, "avgPoolBackprop", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./conv_util":115,"./operation":122}],125:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var seedrandom = require("seedrandom"); -var MPRandGauss = (function () { - function MPRandGauss(mean, stdDeviation, dtype, truncated, seed) { - this.mean = mean; - this.stdDev = stdDeviation; - this.dtype = dtype; - this.nextVal = NaN; - this.truncated = truncated; - if (this.truncated) { - this.upper = this.mean + this.stdDev * 2; - this.lower = this.mean - this.stdDev * 2; - } - var seedValue = seed ? seed : Math.random(); - this.random = seedrandom.alea(seedValue.toString()); - } - MPRandGauss.prototype.nextValue = function () { - if (!isNaN(this.nextVal)) { - var value = this.nextVal; - this.nextVal = NaN; - return value; - } - var resultX, resultY; - var isValid = false; - while (!isValid) { - var v1 = void 0, v2 = void 0, s = void 0; - do { - v1 = 2 * this.random() - 1; - v2 = 2 * this.random() - 1; - s = v1 * v1 + v2 * v2; - } while (s >= 1 || s === 0); - var mul = Math.sqrt(-2.0 * Math.log(s) / s); - resultX = this.mean + this.stdDev * v1 * mul; - resultY = this.mean + this.stdDev * v2 * mul; - if (!this.truncated || this.isValidTruncated(resultX)) { - isValid = true; - } - } - if (!this.truncated || this.isValidTruncated(resultY)) { - this.nextVal = this.convertValue(resultY); - } - return this.convertValue(resultX); - }; - MPRandGauss.prototype.convertValue = function (value) { - if (this.dtype == null || this.dtype === 'float32') { - return value; - } - return Math.round(value); - }; - MPRandGauss.prototype.isValidTruncated = function (value) { - return value <= this.upper && value >= this.lower; - }; - return MPRandGauss; -}()); -exports.MPRandGauss = MPRandGauss; - -},{"seedrandom":153}],126:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.PARALLELIZE_THRESHOLD = 30; -function computeOptimalWindowSize(inSize) { - if (inSize <= exports.PARALLELIZE_THRESHOLD) { - return inSize; - } - return nearestDivisor(inSize, Math.floor(Math.sqrt(inSize))); -} -exports.computeOptimalWindowSize = computeOptimalWindowSize; -function nearestDivisor(size, start) { - for (var i = start; i < size; ++i) { - if (size % i === 0) { - return i; - } - } - return size; -} - -},{}],127:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_1 = require("../tensor"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.logSumExp = function (input, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, input.shape); - var xMax = input.max(axes, true); - var a = input.sub(xMax); - var b = a.exp(); - var c = b.sum(axes); - var d = c.log(); - var res = xMax.reshape(d.shape).add(d); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(res.shape, axes); - return res.reshape(newShape); - } - return res; - }; - Ops.sum = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var customOp = globals_1.customGrad(function (x) { - var permutation = axis_util.getAxesPermutation(axes, x.rank); - var reductionAxes = axes; - var permutedX = x; - if (permutation != null) { - permutedX = x.transpose(permutation); - reductionAxes = - axis_util.getInnerMostAxes(reductionAxes.length, x.rank); - } - var value = environment_1.ENV.engine.executeKernel('Sum', { inputs: { x: permutedX }, args: { axes: reductionAxes } }); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(value.shape, axes); - value = value.reshape(newShape); - } - var gradFunc = function (dy) { - var expandedDyShape = x.shape.slice(); - axes.forEach(function (axis) { - expandedDyShape[axis] = 1; - }); - var expandedDy = dy.reshape(expandedDyShape); - var derX = expandedDy.mul(tensor_1.Tensor.ones(x.shape, 'float32')); - return derX; - }; - return { value: value, gradFunc: gradFunc }; - }); - return customOp(x); - }; - Ops.mean = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var shapes = axis_util.computeOutAndReduceShapes(x.shape, axes); - var reduceShape = shapes[1]; - var reduceSize = util.sizeFromShape(reduceShape); - var customOp = globals_1.customGrad(function (x) { - var reduceSizeScalar = ops.scalar(reduceSize); - var res = x.div(reduceSizeScalar); - var value = res.sum(axis, keepDims); - var gradFunc = function (dy) { - var expandedDyShape = x.shape.slice(); - axes.forEach(function (axis) { - expandedDyShape[axis] = 1; - }); - var expandedDy = dy.reshape(expandedDyShape); - var derX = expandedDy.mul(tensor_1.Tensor.ones(x.shape, 'float32')) - .div(reduceSizeScalar); - return derX; - }; - return { value: value, gradFunc: gradFunc }; - }); - return customOp(x); - }; - Ops.min = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var origAxes = axis_util.parseAxisParam(axis, x.shape); - var axes = origAxes; - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - var res = environment_1.ENV.engine.executeKernel('Min', { inputs: { x: x }, args: { axes: axes } }); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes); - return res.reshape(newShape); - } - return res; - }; - Ops.max = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var origAxes = axis_util.parseAxisParam(axis, x.shape); - var axes = origAxes; - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - var res = environment_1.ENV.engine.executeKernel('Max', { inputs: { x: x }, args: { axes: axes } }); - if (keepDims) { - var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes); - return res.reshape(newShape); - } - return res; - }; - Ops.argMin = function (x, axis) { - if (axis === void 0) { axis = null; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - return environment_1.ENV.engine.executeKernel('ArgMin', { inputs: { x: x }, args: { axes: axes } }); - }; - Ops.argMax = function (x, axis) { - if (axis === void 0) { axis = null; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var permutedAxes = axis_util.getAxesPermutation(axes, x.rank); - if (permutedAxes != null) { - x = x.transpose(permutedAxes); - axes = axis_util.getInnerMostAxes(axes.length, x.rank); - } - return environment_1.ENV.engine.executeKernel('ArgMax', { inputs: { x: x }, args: { axes: axes } }); - }; - Ops.moments = function (x, axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - var axes = axis_util.parseAxisParam(axis, x.shape); - var mean = x.mean(axes, keepDims); - var keepDimsShape = mean.shape; - if (!keepDims) { - keepDimsShape = axis_util.expandShapeToKeepDim(mean.shape, axes); - } - var devSquared = x.toFloat().sub(mean.reshape(keepDimsShape)).square(); - var variance = devSquared.mean(axes, keepDims); - return { mean: mean, variance: variance }; - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "logSumExp", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "sum", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "mean", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "min", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "max", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "argMin", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }), - operation_1.operation - ], Ops, "argMax", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }), - operation_1.operation - ], Ops, "moments", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../globals":35,"../tensor":146,"../util":151,"./axis_util":107,"./operation":122,"./ops":123}],128:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.reverse1d = function (x) { - util.assert(x.rank === 1, "Error in reverse1D: x must be rank 1 but got\n rank " + x.rank + "."); - return Ops.reverse(x, 0); - }; - Ops.reverse2d = function (x, axis) { - util.assert(x.rank === 2, "Error in reverse2D: x must be rank 2 but got\n rank " + x.rank + "."); - return Ops.reverse(x, axis); - }; - Ops.reverse3d = function (x, axis) { - util.assert(x.rank === 3, "Error in reverse3D: x must be rank 3 but got\n rank " + x.rank + "."); - return Ops.reverse(x, axis); - }; - Ops.reverse4d = function (x, axis) { - util.assert(x.rank === 4, "Error in reverse4D: x must be rank 4 but got\n rank " + x.rank + "."); - return Ops.reverse(x, axis); - }; - Ops.reverse = function (x, axis) { - var x4d; - var axisCleaned = axis_util.parseAxisParam(axis, x.shape).map(function (a) { return a + 4 - x.rank; }); - if (x.rank === 0) { - return x.clone(); - } - else if (x.rank === 1) { - x4d = x.as4D(1, 1, 1, x.shape[0]); - } - else if (x.rank === 2) { - x4d = x.as4D(1, 1, x.shape[0], x.shape[1]); - } - else if (x.rank === 3) { - x4d = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]); - } - else if (x.rank === 4) { - x4d = x; - } - else { - throw new Error("Reverse for rank " + x.rank + " is not yet implemented"); - } - var res = environment_1.ENV.engine.executeKernel('Reverse4D', { inputs: { x: x4d }, args: { axis: axisCleaned } }); - return res.reshapeAs(x); - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "reverse", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./axis_util":107,"./operation":122}],129:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SELU_SCALEALPHA = 1.7580993408473768599402175208123; -exports.SELU_SCALE = 1.0507009873554804934193349852946; - -},{}],130:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var operation_1 = require("./operation"); -var slice_util = require("./slice_util"); -var Ops = (function () { - function Ops() { - } - Ops.slice1d = function (x, begin, size) { - slice_util.assertParamsValid(x, [begin], [size]); - return environment_1.ENV.engine.executeKernel('Slice1D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice2d = function (x, begin, size) { - slice_util.assertParamsValid(x, begin, size); - return environment_1.ENV.engine.executeKernel('Slice2D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice3d = function (x, begin, size) { - slice_util.assertParamsValid(x, begin, size); - return environment_1.ENV.engine.executeKernel('Slice3D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice4d = function (x, begin, size) { - slice_util.assertParamsValid(x, begin, size); - return environment_1.ENV.engine.executeKernel('Slice4D', { inputs: { x: x }, args: { begin: begin, size: size } }); - }; - Ops.slice = function (x, begin, size) { - if (x.rank === 0) { - throw new Error('Slicing scalar is not possible'); - } - else if (x.rank === 1) { - return Ops.slice1d(x, begin[0], size[0]); - } - else if (x.rank === 2) { - return Ops.slice2d(x, begin, size); - } - else if (x.rank === 3) { - return Ops.slice3d(x, begin, size); - } - else if (x.rank === 4) { - return Ops.slice4d(x, begin, size); - } - else { - throw new Error("Slicing for rank " + x.rank + " not implemented yet"); - } - }; - __decorate([ - operation_1.operation - ], Ops, "slice1d", null); - __decorate([ - operation_1.operation - ], Ops, "slice2d", null); - __decorate([ - operation_1.operation - ], Ops, "slice3d", null); - __decorate([ - operation_1.operation - ], Ops, "slice4d", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }), - operation_1.operation - ], Ops, "slice", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"./operation":122,"./slice_util":131}],131:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("../util"); -function assertParamsValid(input, begin, size) { - util.assert(input.rank === begin.length, "Error in slice" + input.rank + "D: Length of begin " + begin + " must " + - ("match the rank of the array (" + input.rank + ").")); - util.assert(input.rank === size.length, "Error in slice" + input.rank + "D: Length of size " + size + " must " + - ("match the rank of the array (" + input.rank + ").")); - for (var i = 0; i < input.rank; ++i) { - util.assert(begin[i] + size[i] <= input.shape[i], "Error in slice" + input.rank + "D: begin[" + i + "] + size[" + i + "] " + - ("(" + (begin[i] + size[i]) + ") would overflow input.shape[" + i + "] (" + input.shape[i] + ")")); - } -} -exports.assertParamsValid = assertParamsValid; - -},{"../util":151}],132:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var globals_1 = require("../globals"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var Ops = (function () { - function Ops() { - } - Ops.softmax = function (logits, dim) { - if (dim === void 0) { dim = -1; } - if (dim === -1) { - dim = logits.rank - 1; - } - if (dim !== logits.rank - 1) { - throw Error('Softmax along a non-last dimension is not yet supported. ' + - ("Logits was rank " + logits.rank + " and dim was " + dim)); - } - var customOp = globals_1.customGrad(function (logits) { - var keepDims = true; - var lse = logits.logSumExp([dim], keepDims); - var logResult = logits.toFloat().sub(lse); - var y = logResult.exp(); - var gradFunc = function (dy) { - var dyTimesY = dy.mul(y); - var keepDims = true; - return dyTimesY.sub(dyTimesY.sum([dim], keepDims).mul(y)); - }; - return { value: y, gradFunc: gradFunc }; - }); - return customOp(logits); - }; - Ops.softmaxCrossEntropy = function (labels, logits, dim) { - if (dim === void 0) { dim = -1; } - util.assertShapesMatch(labels.shape, logits.shape, 'Error in softmaxCrossEntropy: '); - if (dim === -1) { - dim = logits.rank - 1; - } - if (dim !== logits.rank - 1) { - throw Error("Softmax cross entropy along a non-last dimension is not yet " + - ("supported. Labels / logits was rank " + logits.rank + " ") + - ("and dim was " + dim)); - } - var customOp = globals_1.customGrad(function (labels, logits) { - var predictedProbs = logits.softmax(dim); - var costVector = ops.scalar(1e-5).add(predictedProbs).log().mul(labels).neg(); - var value = costVector.sum([dim]); - var gradFunc = function (dy) { - var dyShape = axis_util.expandShapeToKeepDim(dy.shape, [dim]); - return [ - dy.reshape(dyShape).mul(labels.toFloat().sub(predictedProbs)), - dy.reshape(dyShape).mul(predictedProbs.sub(labels.toFloat())), - ]; - }; - return { value: value, gradFunc: gradFunc }; - }); - return customOp(labels, logits); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }), - operation_1.operation - ], Ops, "softmax", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }), - operation_1.operation - ], Ops, "softmaxCrossEntropy", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../globals":35,"../util":151,"./axis_util":107,"./operation":122,"./ops":123}],133:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var axis_util = require("./axis_util"); -var operation_1 = require("./operation"); -var Ops = (function () { - function Ops() { - } - Ops.transpose = function (x, perm) { - if (perm == null) { - perm = x.shape.map(function (s, i) { return i; }).reverse(); - } - var der = function (dy) { - var undoPerm = axis_util.getUndoAxesPermutation(perm); - var derX = function () { return dy.transpose(undoPerm); }; - return { x: derX }; - }; - util.assert(x.rank === perm.length, "Error in transpose: rank of input " + x.rank + " " + - ("must match length of perm " + perm + ".")); - return environment_1.ENV.engine.executeKernel('Transpose', { inputs: { x: x }, args: { perm: perm } }, der); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }), - operation_1.operation - ], Ops, "transpose", null); - return Ops; -}()); -exports.Ops = Ops; - -},{"../doc":32,"../environment":34,"../util":151,"./axis_util":107,"./operation":122}],134:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var environment_1 = require("../environment"); -var util = require("../util"); -var operation_1 = require("./operation"); -var ops = require("./ops"); -var ops_1 = require("./ops"); -var selu_util = require("./selu_util"); -var Ops = (function () { - function Ops() { - } - Ops.neg = function (x) { - return environment_1.ENV.engine.executeKernel('Neg', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.neg(); } }; - }); - }; - Ops.ceil = function (x) { - var gradient = function (dy, y) { - return { x: function () { return ops.zeros(y.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Ceil', { inputs: { x: x } }, gradient); - }; - Ops.floor = function (x) { - var gradient = function (dy, y) { - return { x: function () { return ops.zeros(y.shape); } }; - }; - return environment_1.ENV.engine.executeKernel('Floor', { inputs: { x: x } }, gradient); - }; - Ops.exp = function (x) { - return environment_1.ENV.engine.executeKernel('Exp', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(y); } }; - }); - }; - Ops.log = function (x) { - return environment_1.ENV.engine.executeKernel('Log', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(x.toFloat()); } }; - }); - }; - Ops.sqrt = function (x) { - return environment_1.ENV.engine.executeKernel('Sqrt', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(x.toFloat().sqrt().mul(ops.scalar(2))); } }; - }); - }; - Ops.square = function (x) { - return environment_1.ENV.engine.executeKernel('Square', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(x.toFloat().mul(ops.scalar(2))); } }; - }); - }; - Ops.abs = function (x) { - return environment_1.ENV.engine.executeKernel('Abs', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(x.toFloat().step(-1)); } }; - }); - }; - Ops.clipByValue = function (x, clipValueMin, clipValueMax) { - util.assert((clipValueMin <= clipValueMax), "Error in clip: min (" + clipValueMin + ") must be" + - ("less than or equal to max (" + clipValueMax + ").")); - return environment_1.ENV.engine.executeKernel('Clip', { inputs: { x: x }, args: { min: clipValueMin, max: clipValueMax } }, function (dy, y) { - return { - x: function () { return dy.where(x.greater(ops.scalar(clipValueMin)) - .logicalAnd(x.less(ops.scalar(clipValueMax))), ops_1.zerosLike(dy)); }, - }; - }); - }; - Ops.relu = function (x) { - return environment_1.ENV.engine.executeKernel('Relu', { inputs: { x: x } }, function (dy, y) { - var stepRes = x.step(); - return { x: function () { return dy.mul(stepRes.toFloat()); } }; - }); - }; - Ops.elu = function (x) { - var der = function (dy) { - return { - x: function () { return dy.mul(eluDer(x)); }, - alpha: function () { - throw new Error('Derivative of prelu with respect to alpha is ' + - 'not implemented yet'); - } - }; - }; - return environment_1.ENV.engine.executeKernel('Elu', { inputs: { x: x } }, der); - }; - Ops.selu = function (x) { - var gradient = function (dy, y) { - return { - x: function () { - var mask = x.greater(ops.scalar(0)); - var scaleAlpha = ops.scalar(selu_util.SELU_SCALEALPHA); - var scale = ops.scalar(selu_util.SELU_SCALE); - var greaterThanZeroDer = dy.mul(scale); - var lessEqualZeroDer = dy.mul(scaleAlpha).mul(x.toFloat().exp()); - var res = ops.where(mask, greaterThanZeroDer, lessEqualZeroDer); - return res; - } - }; - }; - return environment_1.ENV.engine.executeKernel('Selu', { inputs: { x: x } }, gradient); - }; - Ops.leakyRelu = function (x, alpha) { - if (alpha === void 0) { alpha = 0.2; } - var gradient = function (dy, y) { - return { x: function () { return dy.mul(x.step(alpha)); } }; - }; - return environment_1.ENV.engine.executeKernel('LeakyRelu', { inputs: { x: x }, args: { alpha: alpha } }, gradient); - }; - Ops.prelu = function (x, alpha) { - var der = function (dy) { - return { - x: function () { return dy.mul(preluDer(x, alpha)); }, - alpha: function () { - throw new Error('Derivative of prelu with respect to alpha is ' + - 'not implemented yet'); - } - }; - }; - return environment_1.ENV.engine.executeKernel('PReLU', { inputs: { x: x, alpha: alpha } }, der); - }; - Ops.sigmoid = function (x) { - return environment_1.ENV.engine.executeKernel('Sigmoid', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.mul(y.mul(ops.scalar(1).sub(y))); } }; - }); - }; - Ops.sin = function (x) { - return environment_1.ENV.engine.executeKernel('Sin', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().cos().mul(dy); } }; - }); - }; - Ops.cos = function (x) { - return environment_1.ENV.engine.executeKernel('Cos', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().sin().neg().mul(dy); } }; - }); - }; - Ops.tan = function (x) { - return environment_1.ENV.engine.executeKernel('Tan', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(x.cos().square()); } }; - }); - }; - Ops.asin = function (x) { - return environment_1.ENV.engine.executeKernel('Asin', { inputs: { x: x } }, function (dy, y) { - return { - x: function () { return dy.div(Ops.sqrt(ops.scalar(1).sub(x.toFloat().square()))); } - }; - }); - }; - Ops.acos = function (x) { - return environment_1.ENV.engine.executeKernel('Acos', { inputs: { x: x } }, function (dy, y) { - return { - x: function () { return dy.div(Ops.sqrt(ops.scalar(1).sub(x.toFloat().square()))).neg(); } - }; - }); - }; - Ops.atan = function (x) { - return environment_1.ENV.engine.executeKernel('Atan', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return dy.div(ops.scalar(1).add(x.toFloat().square())); } }; - }); - }; - Ops.sinh = function (x) { - return environment_1.ENV.engine.executeKernel('Sinh', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().cosh().mul(dy); } }; - }); - }; - Ops.cosh = function (x) { - return environment_1.ENV.engine.executeKernel('Cosh', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return x.toFloat().sinh().mul(dy); } }; - }); - }; - Ops.tanh = function (x) { - return environment_1.ENV.engine.executeKernel('Tanh', { inputs: { x: x } }, function (dy, y) { - return { x: function () { return ops.scalar(1).sub(y.square()).mul(dy); } }; - }); - }; - Ops.step = function (x, alpha) { - if (alpha === void 0) { alpha = 0.0; } - return environment_1.ENV.engine.executeKernel('Step', { inputs: { x: x }, args: { alpha: alpha } }, function (dy, y) { - return { x: function () { return ops.zeros(y.shape); } }; - }); - }; - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "neg", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "ceil", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "floor", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "exp", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "log", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sqrt", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "square", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "abs", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "clipByValue", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "relu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "elu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "selu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "leakyRelu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "prelu", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sigmoid", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sin", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "cos", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "tan", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "asin", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "acos", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "atan", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "sinh", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "cosh", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "tanh", null); - __decorate([ - doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }), - operation_1.operation - ], Ops, "step", null); - return Ops; -}()); -exports.Ops = Ops; -function preluDer(x, alpha) { - return environment_1.ENV.engine.executeKernel('PReLUDer', { inputs: { x: x, alpha: alpha } }); -} -function eluDer(x) { - return environment_1.ENV.engine.executeKernel('EluDer', { inputs: { x: x } }); -} - -},{"../doc":32,"../environment":34,"../util":151,"./operation":122,"./ops":123,"./selu_util":129}],135:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdadeltaOptimizer = (function (_super) { - __extends(AdadeltaOptimizer, _super); - function AdadeltaOptimizer(learningRate, rho, specifiedVariableList, epsilon) { - if (epsilon === void 0) { epsilon = 1e-8; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.accumulatedGrads = {}; - _this.accumulatedUpdates = {}; - _this.accumulatedSquaredGradientsGraph = new tensor_array_map_1.TensorArrayMap(); - _this.accumulatedUpdatesGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.epsilon = globals_1.keep(ops_1.scalar(epsilon)); - _this.rho = globals_1.keep(ops_1.scalar(rho)); - _this.oneMinusRho = globals_1.keep(ops_1.scalar(1 - rho)); - return _this; - } - AdadeltaOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulatedGrads[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulatedGrads[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_1); - }); - } - if (this_1.accumulatedUpdates[variableName] == null) { - var trainable_2 = false; - globals_1.tidy(function () { - _this.accumulatedUpdates[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_2); - }); - } - var gradient = variableGradients[variableName]; - var accumulatedGrad = this_1.accumulatedGrads[variableName]; - var accumulatedUpdate = this_1.accumulatedUpdates[variableName]; - globals_1.tidy(function () { - var newAccumulatedGrad = _this.rho.mul(accumulatedGrad) - .add(_this.oneMinusRho.mul(gradient.square())); - var updates = accumulatedUpdate.add(_this.epsilon) - .sqrt() - .div(accumulatedGrad.add(_this.epsilon).sqrt()) - .mul(gradient); - var newAccumulatedUpdate = _this.rho.mul(accumulatedUpdate) - .add(_this.oneMinusRho.mul(updates.square())); - _this.accumulatedGrads[variableName].assign(newAccumulatedGrad); - _this.accumulatedUpdates[variableName].assign(newAccumulatedUpdate); - var newValue = _this.c.mul(updates).add(value); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - AdadeltaOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.accumulatedSquaredGradientsGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.accumulatedSquaredGradientsGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - _this.accumulatedUpdatesGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdadeltaOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldCache = _this.accumulatedSquaredGradientsGraph.get(node.output); - var oldUpdates = _this.accumulatedUpdatesGraph.get(node.output); - var gradientSquare = math.multiply(gradient, gradient); - var cache = math.scaledArrayAdd(_this.rho, oldCache, math.subtract(_this.one, _this.rho), gradientSquare); - var updates = math.multiply(math.divide(math.sqrt(math.add(oldUpdates, _this.epsilon)), math.sqrt(math.add(oldCache, _this.epsilon))), gradient); - var variable = math.scaledArrayAdd(_this.cGraph, updates, _this.one, oldVariable); - var updateSquare = math.multiply(updates, updates); - var newUpdates = math.scaledArrayAdd(_this.rho, oldUpdates, math.subtract(_this.one, _this.rho), updateSquare); - _this.accumulatedSquaredGradientsGraph.set(node.output, globals_1.keep(cache)); - _this.accumulatedUpdatesGraph.set(node.output, globals_1.keep(newUpdates)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldCache.dispose(); - oldUpdates.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdadeltaOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.epsilon.dispose(); - this.rho.dispose(); - this.oneMinusRho.dispose(); - if (this.one != null) { - this.one.dispose(); - } - if (this.accumulatedSquaredGradientsGraph != null) { - this.accumulatedSquaredGradientsGraph.dispose(); - } - if (this.accumulatedUpdatesGraph != null) { - this.accumulatedUpdatesGraph.dispose(); - } - if (this.accumulatedUpdates != null) { - Object.keys(this.accumulatedUpdates) - .forEach(function (name) { return _this.accumulatedUpdates[name].dispose(); }); - Object.keys(this.accumulatedGrads) - .forEach(function (name) { return _this.accumulatedGrads[name].dispose(); }); - } - }; - return AdadeltaOptimizer; -}(optimizer_1.Optimizer)); -exports.AdadeltaOptimizer = AdadeltaOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],136:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdagradOptimizer = (function (_super) { - __extends(AdagradOptimizer, _super); - function AdagradOptimizer(learningRate, specifiedVariableList, initialAccumulatorValue) { - if (initialAccumulatorValue === void 0) { initialAccumulatorValue = 0.1; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.initialAccumulatorValue = initialAccumulatorValue; - _this.accumulatedGrads = {}; - _this.accumulatedSquaredGradients = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.epsilon = globals_1.keep(ops_1.scalar(1e-8)); - return _this; - } - AdagradOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulatedGrads[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulatedGrads[variableName] = tensor_2.variable(ops_1.fill(value.shape, _this.initialAccumulatorValue), trainable_1); - }); - } - var gradient = variableGradients[variableName]; - var accumulatedGrad = this_1.accumulatedGrads[variableName]; - globals_1.tidy(function () { - var newAccumulatedGrad = accumulatedGrad.add(gradient.square()); - _this.accumulatedGrads[variableName].assign(newAccumulatedGrad); - var newValue = _this.c - .mul(gradient.div(newAccumulatedGrad.add(_this.epsilon).sqrt())) - .add(value); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - AdagradOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.accumulatedSquaredGradients.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.accumulatedSquaredGradients.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdagradOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldCache = _this.accumulatedSquaredGradients.get(node.output); - var gradientSquare = math.multiply(gradient, gradient); - var cache = math.add(oldCache, gradientSquare); - var variable = math.scaledArrayAdd(_this.cGraph, math.divide(gradient, math.add(math.sqrt(cache), _this.epsilon)), _this.one, oldVariable); - _this.accumulatedSquaredGradients.set(node.output, globals_1.keep(cache)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldCache.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdagradOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.epsilon.dispose(); - this.c.dispose(); - if (this.one != null) { - this.one.dispose(); - } - if (this.accumulatedSquaredGradients != null) { - this.accumulatedSquaredGradients.dispose(); - } - if (this.accumulatedGrads != null) { - Object.keys(this.accumulatedGrads) - .forEach(function (name) { return _this.accumulatedGrads[name].dispose(); }); - } - }; - return AdagradOptimizer; -}(optimizer_1.Optimizer)); -exports.AdagradOptimizer = AdagradOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],137:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdamOptimizer = (function (_super) { - __extends(AdamOptimizer, _super); - function AdamOptimizer(learningRate, beta1, beta2, epsilon, specifiedVariableList) { - if (epsilon === void 0) { epsilon = 1e-8; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.accumulatedFirstMoment = {}; - _this.accumulatedSecondMoment = {}; - _this.firstMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.secondMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.eps = globals_1.keep(ops_1.scalar(epsilon)); - _this.beta1 = globals_1.keep(ops_1.scalar(beta1)); - _this.beta2 = globals_1.keep(ops_1.scalar(beta2)); - globals_1.tidy(function () { - _this.accBeta1 = tensor_2.variable(ops_1.scalar(beta1)); - _this.accBeta2 = tensor_2.variable(ops_1.scalar(beta2)); - }); - _this.oneMinusBeta1 = globals_1.keep(ops_1.scalar(1 - beta1)); - _this.oneMinusBeta2 = globals_1.keep(ops_1.scalar(1 - beta2)); - _this.one = globals_1.keep(ops_1.scalar(1)); - return _this; - } - AdamOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - globals_1.tidy(function () { - var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1); - var oneMinusAccBeta2 = _this.one.sub(_this.accBeta2); - for (var variableName in variableGradients) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (_this.accumulatedFirstMoment[variableName] == null) { - var trainable = false; - _this.accumulatedFirstMoment[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - if (_this.accumulatedSecondMoment[variableName] == null) { - var trainable = false; - _this.accumulatedSecondMoment[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - var gradient = variableGradients[variableName]; - var firstMoment = _this.accumulatedFirstMoment[variableName]; - var secondMoment = _this.accumulatedSecondMoment[variableName]; - var newFirstMoment = _this.beta1.mul(firstMoment).add(_this.oneMinusBeta1.mul(gradient)); - var newSecondMoment = _this.beta2.mul(secondMoment) - .add(_this.oneMinusBeta2.mul(gradient.square())); - var biasCorrectedFirstMoment = newFirstMoment.div(oneMinusAccBeta1); - var biasCorrectedSecondMoment = newSecondMoment.div(oneMinusAccBeta2); - _this.accumulatedFirstMoment[variableName].assign(newFirstMoment); - _this.accumulatedSecondMoment[variableName].assign(newSecondMoment); - var newValue = _this.c - .mul(biasCorrectedFirstMoment.div(_this.eps.add(biasCorrectedSecondMoment.sqrt()))) - .add(value); - value.assign(newValue); - } - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - _this.accBeta2.assign(_this.accBeta2.mul(_this.beta2)); - }); - }; - AdamOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.firstMomentGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.firstMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - if (this.secondMomentGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.secondMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdamOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1); - var oneMinusAccBeta2 = _this.one.sub(_this.accBeta2); - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldFirstMoment = _this.firstMomentGraph.get(node.output); - var oldSecondMoment = _this.secondMomentGraph.get(node.output); - var newFirstMoment = math.scaledArrayAdd(_this.beta1, oldFirstMoment, _this.oneMinusBeta1, gradient); - var newSecondMoment = math.scaledArrayAdd(_this.beta2, oldSecondMoment, _this.oneMinusBeta2, gradient.square()); - var biasCorrectedFirstMoment = newFirstMoment.div(oneMinusAccBeta1); - var biasCorrectedSecondMoment = newSecondMoment.div(oneMinusAccBeta2); - var variable = math.scaledArrayAdd(_this.cGraph, biasCorrectedFirstMoment.div(_this.eps.add(biasCorrectedSecondMoment.sqrt())), _this.one, oldVariable); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - _this.firstMomentGraph.set(node.output, globals_1.keep(newFirstMoment)); - _this.secondMomentGraph.set(node.output, globals_1.keep(newSecondMoment)); - oldVariable.dispose(); - gradient.dispose(); - oldFirstMoment.dispose(); - oldSecondMoment.dispose(); - }); - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - _this.accBeta2.assign(_this.accBeta2.mul(_this.beta2)); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdamOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.eps.dispose(); - this.beta1.dispose(); - this.beta2.dispose(); - this.accBeta1.dispose(); - this.accBeta2.dispose(); - this.oneMinusBeta1.dispose(); - this.oneMinusBeta2.dispose(); - this.one.dispose(); - if (this.firstMomentGraph != null) { - this.firstMomentGraph.dispose(); - } - if (this.secondMomentGraph != null) { - this.secondMomentGraph.dispose(); - } - if (this.accumulatedFirstMoment != null) { - Object.keys(this.accumulatedFirstMoment) - .forEach(function (name) { return _this.accumulatedFirstMoment[name].dispose(); }); - } - if (this.accumulatedSecondMoment != null) { - Object.keys(this.accumulatedSecondMoment) - .forEach(function (name) { return _this.accumulatedSecondMoment[name].dispose(); }); - } - }; - return AdamOptimizer; -}(optimizer_1.Optimizer)); -exports.AdamOptimizer = AdamOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],138:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var AdamaxOptimizer = (function (_super) { - __extends(AdamaxOptimizer, _super); - function AdamaxOptimizer(learningRate, beta1, beta2, epsilon, decay, specifiedVariableList) { - if (epsilon === void 0) { epsilon = 1e-8; } - if (decay === void 0) { decay = 0.0; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.accumulatedFirstMoment = {}; - _this.accumulatedWeightedInfNorm = {}; - _this.firstMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.weightedInfNormGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(-learningRate)); - _this.eps = globals_1.keep(ops_1.scalar(epsilon)); - _this.beta1 = globals_1.keep(ops_1.scalar(beta1)); - _this.beta2 = globals_1.keep(ops_1.scalar(beta2)); - _this.decay = globals_1.keep(ops_1.scalar(decay)); - globals_1.tidy(function () { - _this.iteration = tensor_2.variable(ops_1.scalar(0)); - _this.accBeta1 = tensor_2.variable(ops_1.scalar(beta1)); - }); - _this.oneMinusBeta1 = globals_1.keep(ops_1.scalar(1 - beta1)); - _this.one = globals_1.keep(ops_1.scalar(1)); - return _this; - } - AdamaxOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - globals_1.tidy(function () { - var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1); - var lr = _this.c.div(_this.one.add(_this.decay.mul(_this.iteration))); - for (var variableName in variableGradients) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (_this.accumulatedFirstMoment[variableName] == null) { - var trainable = false; - _this.accumulatedFirstMoment[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - if (_this.accumulatedWeightedInfNorm[variableName] == null) { - var trainable = false; - _this.accumulatedWeightedInfNorm[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable); - } - var gradient = variableGradients[variableName]; - var firstMoment = _this.accumulatedFirstMoment[variableName]; - var weightedInfNorm = _this.accumulatedWeightedInfNorm[variableName]; - var newFirstMoment = _this.beta1.mul(firstMoment).add(_this.oneMinusBeta1.mul(gradient)); - var ut0 = _this.beta2.mul(weightedInfNorm); - var ut1 = gradient.abs(); - var newWeightedInfNorm = ut0.maximum(ut1); - _this.accumulatedFirstMoment[variableName].assign(newFirstMoment); - _this.accumulatedWeightedInfNorm[variableName].assign(newWeightedInfNorm); - var newValue = lr.div(oneMinusAccBeta1) - .mul(newFirstMoment.div(_this.eps.add(newWeightedInfNorm))) - .add(value); - value.assign(newValue); - } - _this.iteration.assign(_this.iteration.add(_this.one)); - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - }); - }; - AdamaxOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.firstMomentGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.firstMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - if (this.weightedInfNormGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.weightedInfNormGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - AdamaxOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - var lr = _this.cGraph.div(_this.one.add(_this.decay.mul(_this.iteration))); - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldFirstMoment = _this.firstMomentGraph.get(node.output); - var oldWeightedInfNorm = _this.weightedInfNormGraph.get(node.output); - var newFirstMoment = math.scaledArrayAdd(_this.beta1, oldFirstMoment, _this.oneMinusBeta1, gradient); - var ut0 = _this.beta2.mul(oldWeightedInfNorm); - var ut1 = gradient.abs(); - var newWeightedInfNorm = ut0.maximum(ut1); - var variable = math.scaledArrayAdd(_this.one, oldVariable, lr.div(_this.one.sub(_this.accBeta1)), newFirstMoment.div(_this.eps.add(newWeightedInfNorm))); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - _this.firstMomentGraph.set(node.output, globals_1.keep(newFirstMoment)); - _this.weightedInfNormGraph.set(node.output, globals_1.keep(newWeightedInfNorm)); - oldVariable.dispose(); - gradient.dispose(); - oldFirstMoment.dispose(); - oldWeightedInfNorm.dispose(); - }); - _this.iteration.assign(_this.iteration.add(_this.one)); - _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1)); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - AdamaxOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.eps.dispose(); - this.accBeta1.dispose(); - this.beta1.dispose(); - this.beta2.dispose(); - this.oneMinusBeta1.dispose(); - this.decay.dispose(); - this.iteration.dispose(); - this.one.dispose(); - if (this.firstMomentGraph != null) { - this.firstMomentGraph.dispose(); - } - if (this.weightedInfNormGraph != null) { - this.weightedInfNormGraph.dispose(); - } - if (this.accumulatedFirstMoment != null) { - Object.keys(this.accumulatedFirstMoment) - .forEach(function (name) { return _this.accumulatedFirstMoment[name].dispose(); }); - } - if (this.accumulatedWeightedInfNorm != null) { - Object.keys(this.accumulatedWeightedInfNorm) - .forEach(function (name) { return _this.accumulatedWeightedInfNorm[name].dispose(); }); - } - }; - return AdamaxOptimizer; -}(optimizer_1.Optimizer)); -exports.AdamaxOptimizer = AdamaxOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],139:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var sgd_optimizer_1 = require("./sgd_optimizer"); -var MomentumOptimizer = (function (_super) { - __extends(MomentumOptimizer, _super); - function MomentumOptimizer(learningRate, momentum, specifiedVariableList) { - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.momentum = momentum; - _this.m = ops_1.scalar(_this.momentum); - _this.accumulations = {}; - return _this; - } - MomentumOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulations[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulations[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_1); - }); - } - var accumulation = this_1.accumulations[variableName]; - var gradient = variableGradients[variableName]; - globals_1.tidy(function () { - var newAccumulation = _this.m.mul(accumulation).add(gradient); - _this.accumulations[variableName].assign(newAccumulation); - var newValue = _this.c.mul(newAccumulation).add(value); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - MomentumOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.variableVelocitiesGraph == null) { - this.variableVelocitiesGraph = new tensor_array_map_1.TensorArrayMap(); - } - _super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap); - if (this.variableVelocitiesGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.variableVelocitiesGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - MomentumOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldVelocity = _this.variableVelocitiesGraph.get(node.output); - var velocity = math.scaledArrayAdd(_this.m, oldVelocity, _this.one, gradient); - var variable = math.scaledArrayAdd(_this.cGraph, velocity, _this.one, oldVariable); - _this.variableVelocitiesGraph.set(node.output, globals_1.keep(velocity)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldVelocity.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - MomentumOptimizer.prototype.dispose = function () { - _super.prototype.dispose.call(this); - this.m.dispose(); - if (this.one != null) { - this.one.dispose(); - } - if (this.variableVelocitiesGraph != null) { - this.variableVelocitiesGraph.dispose(); - } - if (this.accumulations != null) { - for (var variableName in this.accumulations) { - this.accumulations[variableName].dispose(); - } - } - }; - MomentumOptimizer.prototype.setMomentum = function (momentum) { - this.momentum = momentum; - }; - return MomentumOptimizer; -}(sgd_optimizer_1.SGDOptimizer)); -exports.MomentumOptimizer = MomentumOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./sgd_optimizer":143}],140:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var globals_1 = require("../globals"); -var session_util = require("../graph/session_util"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var Optimizer = (function () { - function Optimizer(learningRate, specifiedVariableList) { - this.learningRate = learningRate; - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - if (specifiedVariableList != null) { - this.specifiedVariableNodes = specifiedVariableList; - } - } - Optimizer.prototype.minimize = function (f, returnCost, varList) { - if (returnCost === void 0) { returnCost = false; } - var _a = this.computeGradients(f, varList), value = _a.value, grads = _a.grads; - this.applyGradients(grads); - var varNames = Object.keys(grads); - varNames.forEach(function (varName) { return grads[varName].dispose(); }); - if (returnCost) { - return value; - } - else { - value.dispose(); - return null; - } - }; - Optimizer.prototype.computeGradients = function (f, varList) { - return globals_1.variableGrads(f, varList); - }; - Optimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - this.variableNodes = this.specifiedVariableNodes == null ? - session_util.getVariableNodesFromEvaluationSet(runtime.nodes) : - this.specifiedVariableNodes; - if (batchSize !== this.prevBatchSize) { - if (this.cGraph != null) { - this.cGraph.dispose(); - } - this.prevBatchSize = batchSize; - this.cGraph = math.keep(ops.scalar(-this.learningRate / batchSize)); - } - this.variableNodes.forEach(function (node) { return _this.variableGradients.set(node.output, math.keep(tensor_1.Tensor.zeros(node.output.shape))); }); - }; - Optimizer.prototype.afterExample = function (math, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var gradient = gradientArrayMap.get(node.output); - var accumulatedGradient = _this.variableGradients.get(node.output); - _this.variableGradients.set(node.output, globals_1.keep(math.add(gradient, accumulatedGradient))); - accumulatedGradient.dispose(); - }); - }); - }; - Optimizer.prototype.dispose = function () { - if (this.cGraph != null) { - this.cGraph.dispose(); - } - if (this.variableNodes != null) { - this.variableNodes.forEach(function (node) { - node.data.dispose(); - }); - } - if (this.specifiedVariableNodes != null) { - this.specifiedVariableNodes.forEach(function (node) { - node.data.dispose(); - }); - } - }; - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers' }) - ], Optimizer.prototype, "minimize", null); - Optimizer = __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Classes', namespace: 'train' }) - ], Optimizer); - return Optimizer; -}()); -exports.Optimizer = Optimizer; - -},{"../doc":32,"../globals":35,"../graph/session_util":65,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146}],141:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("../doc"); -var adadelta_optimizer_1 = require("./adadelta_optimizer"); -var adagrad_optimizer_1 = require("./adagrad_optimizer"); -var adam_optimizer_1 = require("./adam_optimizer"); -var adamax_optimizer_1 = require("./adamax_optimizer"); -var momentum_optimizer_1 = require("./momentum_optimizer"); -var rmsprop_optimizer_1 = require("./rmsprop_optimizer"); -var sgd_optimizer_1 = require("./sgd_optimizer"); -var OptimizerConstructors = (function () { - function OptimizerConstructors() { - } - OptimizerConstructors.sgd = function (learningRate) { - return new sgd_optimizer_1.SGDOptimizer(learningRate); - }; - OptimizerConstructors.momentum = function (learningRate, momentum) { - return new momentum_optimizer_1.MomentumOptimizer(learningRate, momentum); - }; - OptimizerConstructors.rmsprop = function (learningRate, decay, momentum, epsilon) { - if (decay === void 0) { decay = .9; } - if (momentum === void 0) { momentum = 0.0; } - if (epsilon === void 0) { epsilon = 1e-8; } - return new rmsprop_optimizer_1.RMSPropOptimizer(learningRate, decay, momentum, undefined, epsilon); - }; - OptimizerConstructors.adam = function (learningRate, beta1, beta2, epsilon) { - if (learningRate === void 0) { learningRate = 0.001; } - if (beta1 === void 0) { beta1 = 0.9; } - if (beta2 === void 0) { beta2 = 0.999; } - if (epsilon === void 0) { epsilon = 1e-8; } - return new adam_optimizer_1.AdamOptimizer(learningRate, beta1, beta2, epsilon, undefined); - }; - OptimizerConstructors.adadelta = function (learningRate, rho, epsilon) { - if (learningRate === void 0) { learningRate = .001; } - if (rho === void 0) { rho = .95; } - if (epsilon === void 0) { epsilon = 1e-8; } - return new adadelta_optimizer_1.AdadeltaOptimizer(learningRate, rho, undefined, epsilon); - }; - OptimizerConstructors.adamax = function (learningRate, beta1, beta2, epsilon, decay) { - if (learningRate === void 0) { learningRate = 0.002; } - if (beta1 === void 0) { beta1 = 0.9; } - if (beta2 === void 0) { beta2 = 0.999; } - if (epsilon === void 0) { epsilon = 1e-8; } - if (decay === void 0) { decay = 0.0; } - return new adamax_optimizer_1.AdamaxOptimizer(learningRate, beta1, beta2, epsilon, decay, undefined); - }; - OptimizerConstructors.adagrad = function (learningRate, initialAccumulatorValue) { - if (initialAccumulatorValue === void 0) { initialAccumulatorValue = 0.1; } - return new adagrad_optimizer_1.AdagradOptimizer(learningRate, undefined, initialAccumulatorValue); - }; - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "sgd", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "momentum", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "rmsprop", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adam", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adadelta", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adamax", null); - __decorate([ - doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' }) - ], OptimizerConstructors, "adagrad", null); - return OptimizerConstructors; -}()); -exports.OptimizerConstructors = OptimizerConstructors; - -},{"../doc":32,"./adadelta_optimizer":135,"./adagrad_optimizer":136,"./adam_optimizer":137,"./adamax_optimizer":138,"./momentum_optimizer":139,"./rmsprop_optimizer":142,"./sgd_optimizer":143}],142:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var session_util = require("../graph/session_util"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var tensor_1 = require("../tensor"); -var tensor_2 = require("../tensor"); -var optimizer_1 = require("./optimizer"); -var RMSPropOptimizer = (function (_super) { - __extends(RMSPropOptimizer, _super); - function RMSPropOptimizer(learningRate, decay, momentum, specifiedVariableList, epsilon) { - if (decay === void 0) { decay = 0.9; } - if (momentum === void 0) { momentum = 0.0; } - if (epsilon === void 0) { epsilon = 1e-8; } - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.accumulatedMeanSquares = {}; - _this.accumulatedMoments = {}; - _this.accumulatedMeanSquaredGraph = new tensor_array_map_1.TensorArrayMap(); - _this.accumulatedMomentGraph = new tensor_array_map_1.TensorArrayMap(); - _this.c = globals_1.keep(ops_1.scalar(learningRate)); - _this.epsilon = globals_1.keep(ops_1.scalar(epsilon)); - _this.decay = globals_1.keep(ops_1.scalar(decay)); - _this.momentum = globals_1.keep(ops_1.scalar(momentum)); - _this.oneMinusDecay = globals_1.keep(ops_1.scalar(1 - decay)); - return _this; - } - RMSPropOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var _loop_1 = function (variableName) { - var value = environment_1.ENV.engine.registeredVariables[variableName]; - if (this_1.accumulatedMeanSquares[variableName] == null) { - var trainable_1 = false; - globals_1.tidy(function () { - _this.accumulatedMeanSquares[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_1); - }); - } - if (this_1.accumulatedMoments[variableName] == null) { - var trainable_2 = false; - globals_1.tidy(function () { - _this.accumulatedMoments[variableName] = - tensor_2.variable(ops_1.zerosLike(value), trainable_2); - }); - } - var accumulatedMeanSquare = this_1.accumulatedMeanSquares[variableName]; - var accumulatedMoments = this_1.accumulatedMoments[variableName]; - var gradient = variableGradients[variableName]; - globals_1.tidy(function () { - var newAccumulatedMeanSquare = _this.decay.mul(accumulatedMeanSquare) - .add(_this.oneMinusDecay.mul(gradient.square())); - var newAccumulatedMoments = _this.momentum.mul(accumulatedMoments) - .add(_this.c.mul(gradient).div(newAccumulatedMeanSquare.add(_this.epsilon).sqrt())); - _this.accumulatedMeanSquares[variableName].assign(newAccumulatedMeanSquare); - _this.accumulatedMoments[variableName].assign(newAccumulatedMoments); - var newValue = value.sub(newAccumulatedMoments); - value.assign(newValue); - }); - }; - var this_1 = this; - for (var variableName in variableGradients) { - _loop_1(variableName); - } - }; - RMSPropOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - this.variableNodes = this.specifiedVariableNodes == null ? - session_util.getVariableNodesFromEvaluationSet(runtime.nodes) : - this.specifiedVariableNodes; - if (batchSize !== this.prevBatchSize) { - if (this.cGraph != null) { - this.cGraph.dispose(); - } - this.prevBatchSize = batchSize; - this.cGraph = math.keep(ops_1.scalar(this.learningRate / batchSize)); - } - this.variableNodes.forEach(function (node) { return _this.variableGradients.set(node.output, math.keep(tensor_1.Tensor.zeros(node.output.shape))); }); - if (this.accumulatedMeanSquaredGraph.size() === 0) { - this.variableNodes.forEach(function (node) { - _this.accumulatedMeanSquaredGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - _this.accumulatedMomentGraph.set(node.output, tensor_1.Tensor.zeros(node.output.shape)); - }); - } - }; - RMSPropOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var oldMeanSquare = _this.accumulatedMeanSquaredGraph.get(node.output); - var oldMoment = _this.accumulatedMomentGraph.get(node.output); - var meanSquare = math.scaledArrayAdd(_this.decay, oldMeanSquare, _this.oneMinusDecay, gradient.square()); - var moment = math.scaledArrayAdd(_this.momentum, oldMoment, _this.cGraph, gradient.div(meanSquare.add(_this.epsilon).sqrt())); - var variable = oldVariable.sub(moment); - _this.accumulatedMeanSquaredGraph.set(node.output, globals_1.keep(meanSquare)); - _this.accumulatedMomentGraph.set(node.output, globals_1.keep(moment)); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - oldMeanSquare.dispose(); - oldMoment.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - RMSPropOptimizer.prototype.dispose = function () { - var _this = this; - _super.prototype.dispose.call(this); - this.c.dispose(); - this.epsilon.dispose(); - this.decay.dispose(); - this.momentum.dispose(); - this.oneMinusDecay.dispose(); - if (this.accumulatedMeanSquaredGraph != null) { - this.accumulatedMeanSquaredGraph.dispose(); - } - if (this.accumulatedMomentGraph != null) { - this.accumulatedMomentGraph.dispose(); - } - if (this.accumulatedMeanSquares != null) { - Object.keys(this.accumulatedMeanSquares) - .forEach(function (name) { return _this.accumulatedMeanSquares[name].dispose(); }); - } - if (this.accumulatedMoments != null) { - Object.keys(this.accumulatedMoments) - .forEach(function (name) { return _this.accumulatedMoments[name].dispose(); }); - } - }; - return RMSPropOptimizer; -}(optimizer_1.Optimizer)); -exports.RMSPropOptimizer = RMSPropOptimizer; - -},{"../environment":34,"../globals":35,"../graph/session_util":65,"../graph/tensor_array_map":66,"../ops/ops":123,"../tensor":146,"./optimizer":140}],143:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("../environment"); -var globals_1 = require("../globals"); -var tensor_array_map_1 = require("../graph/tensor_array_map"); -var ops_1 = require("../ops/ops"); -var optimizer_1 = require("./optimizer"); -var SGDOptimizer = (function (_super) { - __extends(SGDOptimizer, _super); - function SGDOptimizer(learningRate, specifiedVariableList) { - var _this = _super.call(this, learningRate, specifiedVariableList) || this; - _this.learningRate = learningRate; - _this.setLearningRate(learningRate); - return _this; - } - SGDOptimizer.prototype.applyGradients = function (variableGradients) { - var _this = this; - var varNames = Object.keys(variableGradients); - varNames.forEach(function (varName) { - var gradient = variableGradients[varName]; - var value = environment_1.ENV.engine.registeredVariables[varName]; - globals_1.tidy(function () { - var newValue = _this.c.mul(gradient).add(value); - value.assign(newValue); - }); - }); - }; - SGDOptimizer.prototype.setLearningRate = function (learningRate) { - this.learningRate = learningRate; - if (this.c != null) { - this.c.dispose(); - } - this.c = environment_1.ENV.math.keep(ops_1.scalar(-learningRate)); - }; - SGDOptimizer.prototype.dispose = function () { - this.c.dispose(); - if (this.one != null) { - this.one.dispose(); - } - _super.prototype.dispose.call(this); - }; - SGDOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) { - var _this = this; - if (this.one == null) { - this.one = globals_1.keep(ops_1.scalar(1)); - } - globals_1.tidy(function () { - _this.variableNodes.forEach(function (node) { - var oldVariable = activationArrayMap.get(node.output); - var gradient = _this.variableGradients.get(node.output); - var variable = math.scaledArrayAdd(_this.cGraph, gradient, _this.one, oldVariable); - activationArrayMap.set(node.output, globals_1.keep(variable)); - node.data = variable; - oldVariable.dispose(); - }); - }); - this.variableGradients.dispose(); - this.variableGradients = new tensor_array_map_1.TensorArrayMap(); - }; - return SGDOptimizer; -}(optimizer_1.Optimizer)); -exports.SGDOptimizer = SGDOptimizer; - -},{"../environment":34,"../globals":35,"../graph/tensor_array_map":66,"../ops/ops":123,"./optimizer":140}],144:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("./util"); -var Profiler = (function () { - function Profiler(backendTimer, logger) { - this.backendTimer = backendTimer; - this.logger = logger; - if (logger == null) { - this.logger = new Logger(); - } - } - Profiler.prototype.profileKernel = function (kernelName, f) { - var _this = this; - var result; - var holdResultWrapperFn = function () { - result = f(); - }; - var timer = this.backendTimer.time(holdResultWrapperFn); - var vals = result.dataSync(); - util.checkForNaN(vals, result.dtype, kernelName); - timer.then(function (timing) { - _this.logger.logKernelProfile(kernelName, result, vals, timing.kernelMs); - }); - return result; - }; - return Profiler; -}()); -exports.Profiler = Profiler; -var Logger = (function () { - function Logger() { - } - Logger.prototype.logKernelProfile = function (kernelName, result, vals, timeMs) { - var time = util.rightPad(timeMs + "ms", 9); - var paddedName = util.rightPad(kernelName, 25); - var rank = result.rank; - var size = result.size; - var shape = util.rightPad(result.shape.toString(), 14); - console.log("%c" + paddedName + "\t%c" + time + "\t%c" + rank + "D " + shape + "\t%c" + size, 'font-weight:bold', 'color:red', 'color:blue', 'color: orange'); - }; - return Logger; -}()); -exports.Logger = Logger; - -},{"./util":151}],145:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var util = require("./util"); -var tensor_1 = require("./tensor"); -function getFilteredNodesXToY(tape, xs, y) { - var tensorsFromX = {}; - var nodesFromX = {}; - for (var i = 0; i < xs.length; i++) { - tensorsFromX[xs[i].id] = true; - } - for (var i = 0; i < tape.length; i++) { - var node = tape[i]; - var nodeInputs = node.inputAndArgs.inputs; - for (var inputName in nodeInputs) { - var input = nodeInputs[inputName]; - var anyInputFromX = false; - for (var j = 0; j < xs.length; j++) { - if (tensorsFromX[input.id]) { - if (node.output instanceof tensor_1.Tensor) { - tensorsFromX[node.output.id] = true; - } - else { - var keys = Object.keys(node.output); - for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { - var key = keys_1[_i]; - tensorsFromX[node.output[key].id] = true; - } - } - anyInputFromX = true; - nodesFromX[node.id] = true; - break; - } - } - if (anyInputFromX) { - break; - } - } - } - var tensorsLeadToY = {}; - tensorsLeadToY[y.id] = true; - var nodesToY = {}; - for (var i = tape.length - 1; i >= 0; i--) { - var node = tape[i]; - var nodeInputs = node.inputAndArgs.inputs; - var outputs = []; - if (node.output instanceof tensor_1.Tensor) { - outputs.push(node.output); - } - else { - var keys = Object.keys(node.output); - for (var _a = 0, keys_2 = keys; _a < keys_2.length; _a++) { - var key = keys_2[_a]; - outputs.push(node.output[key]); - } - } - for (var j = 0; j < outputs.length; j++) { - if (tensorsLeadToY[outputs[j].id]) { - for (var inputName in nodeInputs) { - tensorsLeadToY[nodeInputs[inputName].id] = true; - nodesToY[node.id] = true; - } - break; - } - } - } - var filteredTape = []; - for (var i = 0; i < tape.length; i++) { - var node = tape[i]; - if (nodesFromX[node.id] && nodesToY[node.id]) { - var prunedInputs = {}; - for (var inputName in node.inputAndArgs.inputs) { - var nodeInput = node.inputAndArgs.inputs[inputName]; - if (tensorsFromX[nodeInput.id]) { - prunedInputs[inputName] = nodeInput; - } - } - var prunedOutputs = void 0; - if (node.output instanceof tensor_1.Tensor) { - prunedOutputs = node.output; - } - else { - prunedOutputs = {}; - for (var outputName in node.output) { - var output = node.output[outputName]; - if (tensorsLeadToY[output.id]) { - prunedOutputs[outputName] = node.output[outputName]; - } - } - } - var prunedNode = Object.assign({}, node); - prunedNode.inputAndArgs = { inputs: prunedInputs }; - prunedNode.output = prunedOutputs; - filteredTape.push(prunedNode); - } - } - return filteredTape; -} -exports.getFilteredNodesXToY = getFilteredNodesXToY; -function backpropagateGradients(tensorAccumulatedGradientMap, filteredTape) { - for (var i = filteredTape.length - 1; i >= 0; i--) { - var node = filteredTape[i]; - var dy = void 0; - if (node.output instanceof tensor_1.Tensor) { - dy = tensorAccumulatedGradientMap[node.output.id]; - } - else { - dy = {}; - var keys = Object.keys(node.output); - for (var _i = 0, keys_3 = keys; _i < keys_3.length; _i++) { - var key = keys_3[_i]; - dy[key] = tensorAccumulatedGradientMap[node.output[key].id]; - } - } - if (node.gradient == null) { - throw new Error("Cannot compute gradient: gradient function not found " + - ("for " + node.name + ".")); - } - var inputGradients = node.gradient(dy, node.output); - for (var inputName in node.inputAndArgs.inputs) { - if (!(inputName in inputGradients)) { - throw new Error("Cannot backprop through input " + inputName + ". " + - ("Available gradients found: " + Object.keys(inputGradients) + ".")); - } - var dx = inputGradients[inputName](); - var x = node.inputAndArgs.inputs[inputName]; - if (!util.arraysEqual(dx.shape, x.shape)) { - throw new Error("Error in gradient for op " + node.name + ". The gradient of input " + - ("'" + inputName + "' has shape '" + dx.shape + "', which does not match ") + - ("the shape of the input '" + x.shape + "'")); - } - if (tensorAccumulatedGradientMap[x.id] == null) { - tensorAccumulatedGradientMap[x.id] = dx; - } - else { - var curGradient = tensorAccumulatedGradientMap[x.id]; - tensorAccumulatedGradientMap[x.id] = curGradient.add(dx); - curGradient.dispose(); - } - } - } -} -exports.backpropagateGradients = backpropagateGradients; -function extractTensorsFromScopeResult(result) { - if (result == null) { - return []; - } - if (result instanceof tensor_1.Tensor) { - return [result]; - } - var list = []; - var resultObj = result; - for (var k in resultObj) { - var sublist = util.flatten(resultObj[k]).filter(function (x) { return x instanceof tensor_1.Tensor; }); - list.push.apply(list, sublist); - } - return list; -} -exports.extractTensorsFromScopeResult = extractTensorsFromScopeResult; -function stripUndefinedInputsFromInputConfig(config) { - var keys = Object.keys(config.inputs); - keys.forEach(function (key) { - if (config.inputs[key] == null) { - delete config.inputs[key]; - } - }); - return config; -} -exports.stripUndefinedInputsFromInputConfig = stripUndefinedInputsFromInputConfig; - -},{"./tensor":146,"./util":151}],146:[function(require,module,exports){ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [0, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var environment_1 = require("./environment"); -var ops = require("./ops/ops"); -var util = require("./util"); -var TensorBuffer = (function () { - function TensorBuffer(shape, dtype, values) { - this.shape = shape; - this.dtype = dtype; - this.values = values; - if (values != null) { - var n = values.length; - var size = util.sizeFromShape(shape); - util.assert(n === size, "Length of values '" + n + "' does not match the size " + - ("inferred by the shape '" + size + "'")); - } - this.values = - values || util.getTypedArrayFromDType(dtype, util.sizeFromShape(shape)); - this.strides = computeStrides(shape); - } - TensorBuffer.prototype.set = function (value) { - var locs = []; - for (var _i = 1; _i < arguments.length; _i++) { - locs[_i - 1] = arguments[_i]; - } - if (locs.length === 0) { - locs = [0]; - } - util.assert(locs.length === this.rank, "The number of provided coordinates (" + locs.length + ") must " + - ("match the rank (" + this.rank + ")")); - var index = this.locToIndex(locs); - this.values[index] = value; - }; - TensorBuffer.prototype.get = function () { - var locs = []; - for (var _i = 0; _i < arguments.length; _i++) { - locs[_i] = arguments[_i]; - } - if (locs.length === 0) { - locs = [0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return this.values[index]; - }; - TensorBuffer.prototype.locToIndex = function (locs) { - if (this.rank === 0) { - return 0; - } - else if (this.rank === 1) { - return locs[0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return index; - }; - TensorBuffer.prototype.indexToLoc = function (index) { - if (this.rank === 0) { - return []; - } - else if (this.rank === 1) { - return [index]; - } - var locs = new Array(this.shape.length); - for (var i = 0; i < locs.length - 1; ++i) { - locs[i] = Math.floor(index / this.strides[i]); - index -= locs[i] * this.strides[i]; - } - locs[locs.length - 1] = index; - return locs; - }; - Object.defineProperty(TensorBuffer.prototype, "rank", { - get: function () { - return this.shape.length; - }, - enumerable: true, - configurable: true - }); - TensorBuffer.prototype.toTensor = function () { - return Tensor.make(this.shape, { values: this.values }, this.dtype); - }; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], TensorBuffer.prototype, "set", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], TensorBuffer.prototype, "get", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], TensorBuffer.prototype, "toTensor", null); - TensorBuffer = __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], TensorBuffer); - return TensorBuffer; -}()); -exports.TensorBuffer = TensorBuffer; -var Tensor = (function () { - function Tensor(shape, dtype, values, dataId) { - this.isDisposed = false; - this.size = util.sizeFromShape(shape); - if (values != null) { - util.assert(this.size === values.length, "Constructing tensor of shape (" + this.size + ") should match the " + - ("length of values (" + values.length + ")")); - } - this.shape = shape; - this.dtype = dtype || 'float32'; - this.strides = computeStrides(shape); - this.dataId = dataId != null ? dataId : {}; - this.id = Tensor_1.nextId++; - this.rankType = (this.rank < 5 ? this.rank.toString() : 'higher'); - environment_1.ENV.engine.registerTensor(this); - if (values != null) { - environment_1.ENV.engine.write(this.dataId, values); - } - } - Tensor_1 = Tensor; - Tensor.ones = function (shape, dtype) { - return ops.ones(shape, dtype); - }; - Tensor.zeros = function (shape, dtype) { - return ops.zeros(shape, dtype); - }; - Tensor.onesLike = function (x) { - return ops.onesLike(x); - }; - Tensor.zerosLike = function (x) { - return ops.zerosLike(x); - }; - Tensor.like = function (x) { - return ops.clone(x); - }; - Tensor.make = function (shape, data, dtype) { - return new Tensor_1(shape, dtype, data.values, data.dataId); - }; - Tensor.fromPixels = function (pixels, numChannels) { - if (numChannels === void 0) { numChannels = 3; } - return ops.fromPixels(pixels, numChannels); - }; - Tensor.rand = function (shape, randFunction, dtype) { - return ops.rand(shape, randFunction, dtype); - }; - Tensor.randNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - return ops.randomNormal(shape, mean, stdDev, dtype, seed); - }; - Tensor.randTruncatedNormal = function (shape, mean, stdDev, dtype, seed) { - if (mean === void 0) { mean = 0; } - if (stdDev === void 0) { stdDev = 1; } - return ops.truncatedNormal(shape, mean, stdDev, dtype, seed); - }; - Tensor.randUniform = function (shape, a, b, dtype) { - return ops.randomUniform(shape, a, b, dtype); - }; - Tensor.prototype.flatten = function () { - this.throwIfDisposed(); - return this.as1D(); - }; - Tensor.prototype.asScalar = function () { - this.throwIfDisposed(); - util.assert(this.size === 1, 'The array must have only 1 element.'); - return this.reshape([]); - }; - Tensor.prototype.as1D = function () { - this.throwIfDisposed(); - return this.reshape([this.size]); - }; - Tensor.prototype.as2D = function (rows, columns) { - this.throwIfDisposed(); - return this.reshape([rows, columns]); - }; - Tensor.prototype.as3D = function (rows, columns, depth) { - this.throwIfDisposed(); - return this.reshape([rows, columns, depth]); - }; - Tensor.prototype.as4D = function (rows, columns, depth, depth2) { - this.throwIfDisposed(); - return this.reshape([rows, columns, depth, depth2]); - }; - Tensor.prototype.asType = function (dtype) { - this.throwIfDisposed(); - return ops.cast(this, dtype); - }; - Object.defineProperty(Tensor.prototype, "rank", { - get: function () { - return this.shape.length; - }, - enumerable: true, - configurable: true - }); - Tensor.prototype.get = function () { - var locs = []; - for (var _i = 0; _i < arguments.length; _i++) { - locs[_i] = arguments[_i]; - } - this.throwIfDisposed(); - if (locs.length === 0) { - locs = [0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return this.dataSync()[index]; - }; - Tensor.prototype.val = function () { - var locs = []; - for (var _i = 0; _i < arguments.length; _i++) { - locs[_i] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (locs.length === 0) { - locs = [0]; - } - this.throwIfDisposed(); - return [4, this.data()]; - case 1: - _a.sent(); - return [2, this.get.apply(this, locs)]; - } - }); - }); - }; - Tensor.prototype.locToIndex = function (locs) { - this.throwIfDisposed(); - if (this.rank === 0) { - return 0; - } - else if (this.rank === 1) { - return locs[0]; - } - var index = locs[locs.length - 1]; - for (var i = 0; i < locs.length - 1; ++i) { - index += this.strides[i] * locs[i]; - } - return index; - }; - Tensor.prototype.indexToLoc = function (index) { - this.throwIfDisposed(); - if (this.rank === 0) { - return []; - } - else if (this.rank === 1) { - return [index]; - } - var locs = new Array(this.shape.length); - for (var i = 0; i < locs.length - 1; ++i) { - locs[i] = Math.floor(index / this.strides[i]); - index -= locs[i] * this.strides[i]; - } - locs[locs.length - 1] = index; - return locs; - }; - Tensor.prototype.getValues = function () { - return this.dataSync(); - }; - Tensor.prototype.getValuesAsync = function () { - return this.data(); - }; - Tensor.prototype.buffer = function () { - return ops.buffer(this.shape, this.dtype, this.dataSync()); - }; - Tensor.prototype.data = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - this.throwIfDisposed(); - return [2, environment_1.ENV.engine.read(this.dataId)]; - }); - }); - }; - Tensor.prototype.dataSync = function () { - this.throwIfDisposed(); - return environment_1.ENV.engine.readSync(this.dataId); - }; - Tensor.prototype.dispose = function () { - if (this.isDisposed) { - return; - } - this.isDisposed = true; - environment_1.ENV.engine.disposeTensor(this); - }; - Tensor.prototype.throwIfDisposed = function () { - if (this.isDisposed) { - throw new Error("Tensor is disposed."); - } - }; - Tensor.prototype.toFloat = function () { - return this.asType('float32'); - }; - Tensor.prototype.toInt = function () { - return this.asType('int32'); - }; - Tensor.prototype.toBool = function () { - return this.asType('bool'); - }; - Tensor.prototype.print = function (verbose) { - if (verbose === void 0) { verbose = false; } - return ops.print(this, verbose); - }; - Tensor.prototype.reshape = function (newShape) { - this.throwIfDisposed(); - return ops.reshape(this, newShape); - }; - Tensor.prototype.reshapeAs = function (x) { - this.throwIfDisposed(); - return this.reshape(x.shape); - }; - Tensor.prototype.expandDims = function (axis) { - if (axis === void 0) { axis = 0; } - return ops.expandDims(this, axis); - }; - Tensor.prototype.squeeze = function (axis) { - this.throwIfDisposed(); - return ops.squeeze(this, axis); - }; - Tensor.prototype.clone = function () { - this.throwIfDisposed(); - return ops.clone(this); - }; - Tensor.prototype.tile = function (reps) { - this.throwIfDisposed(); - return ops.tile(this, reps); - }; - Tensor.prototype.gather = function (indices, axis) { - if (axis === void 0) { axis = 0; } - this.throwIfDisposed(); - return ops.gather(this, indices); - }; - Tensor.prototype.matMul = function (b, transposeA, transposeB) { - if (transposeA === void 0) { transposeA = false; } - if (transposeB === void 0) { transposeB = false; } - this.throwIfDisposed(); - return ops.matMul(this, b, transposeA, transposeB); - }; - Tensor.prototype.norm = function (ord, axis, keepDims) { - if (ord === void 0) { ord = 'euclidean'; } - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.norm(this, ord, axis, keepDims); - }; - Tensor.prototype.slice = function (begin, size) { - this.throwIfDisposed(); - return ops.slice(this, begin, size); - }; - Tensor.prototype.reverse = function (axis) { - this.throwIfDisposed(); - return ops.reverse(this, axis); - }; - Tensor.prototype.concat = function (x, axis) { - if (axis === void 0) { axis = 0; } - this.throwIfDisposed(); - return ops.concat([this, x], axis); - }; - Tensor.prototype.stack = function (x, axis) { - if (axis === void 0) { axis = 0; } - return ops.stack([this, x], axis); - }; - Tensor.prototype.pad = function (paddings, constantValue) { - if (constantValue === void 0) { constantValue = 0; } - return ops.pad(this, paddings, constantValue); - }; - Tensor.prototype.batchNormalization = function (mean, variance, varianceEpsilon, scale, offset) { - if (varianceEpsilon === void 0) { varianceEpsilon = .001; } - this.throwIfDisposed(); - return ops.batchNormalization(this, mean, variance, varianceEpsilon, scale, offset); - }; - Tensor.prototype.logSumExp = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.logSumExp(this, axis, keepDims); - }; - Tensor.prototype.sum = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.sum(this, axis, keepDims); - }; - Tensor.prototype.mean = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.mean(this, axis, keepDims); - }; - Tensor.prototype.min = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.min(this, axis, keepDims); - }; - Tensor.prototype.max = function (axis, keepDims) { - if (axis === void 0) { axis = null; } - if (keepDims === void 0) { keepDims = false; } - this.throwIfDisposed(); - return ops.max(this, axis, keepDims); - }; - Tensor.prototype.argMin = function (axis) { - if (axis === void 0) { axis = null; } - this.throwIfDisposed(); - return ops.argMin(this, axis); - }; - Tensor.prototype.argMax = function (axis) { - if (axis === void 0) { axis = null; } - this.throwIfDisposed(); - return ops.argMax(this, axis); - }; - Tensor.prototype.add = function (x) { - this.throwIfDisposed(); - return ops.add(this, x); - }; - Tensor.prototype.addStrict = function (x) { - this.throwIfDisposed(); - return ops.addStrict(this, x); - }; - Tensor.prototype.sub = function (x) { - this.throwIfDisposed(); - return ops.sub(this, x); - }; - Tensor.prototype.subStrict = function (x) { - this.throwIfDisposed(); - return ops.subStrict(this, x); - }; - Tensor.prototype.pow = function (exp) { - this.throwIfDisposed(); - return ops.pow(this, exp); - }; - Tensor.prototype.powStrict = function (exp) { - this.throwIfDisposed(); - return ops.powStrict(this, exp); - }; - Tensor.prototype.mul = function (x) { - this.throwIfDisposed(); - return ops.mul(this, x); - }; - Tensor.prototype.mulStrict = function (x) { - this.throwIfDisposed(); - return ops.mulStrict(this, x); - }; - Tensor.prototype.div = function (x) { - this.throwIfDisposed(); - return ops.div(this, x); - }; - Tensor.prototype.divStrict = function (x) { - this.throwIfDisposed(); - return ops.divStrict(this, x); - }; - Tensor.prototype.minimum = function (x) { - this.throwIfDisposed(); - return ops.minimum(this, x); - }; - Tensor.prototype.minimumStrict = function (x) { - this.throwIfDisposed(); - return ops.minimumStrict(this, x); - }; - Tensor.prototype.maximum = function (x) { - this.throwIfDisposed(); - return ops.maximum(this, x); - }; - Tensor.prototype.maximumStrict = function (x) { - this.throwIfDisposed(); - return ops.maximumStrict(this, x); - }; - Tensor.prototype.transpose = function (perm) { - this.throwIfDisposed(); - return ops.transpose(this, perm); - }; - Tensor.prototype.notEqual = function (x) { - this.throwIfDisposed(); - return ops.notEqual(this, x); - }; - Tensor.prototype.notEqualStrict = function (x) { - this.throwIfDisposed(); - return ops.notEqualStrict(this, x); - }; - Tensor.prototype.less = function (x) { - this.throwIfDisposed(); - return ops.less(this, x); - }; - Tensor.prototype.lessStrict = function (x) { - this.throwIfDisposed(); - return ops.lessStrict(this, x); - }; - Tensor.prototype.equal = function (x) { - this.throwIfDisposed(); - return ops.equal(this, x); - }; - Tensor.prototype.equalStrict = function (x) { - this.throwIfDisposed(); - return ops.equalStrict(this, x); - }; - Tensor.prototype.lessEqual = function (x) { - this.throwIfDisposed(); - return ops.lessEqual(this, x); - }; - Tensor.prototype.lessEqualStrict = function (x) { - this.throwIfDisposed(); - return ops.lessEqualStrict(this, x); - }; - Tensor.prototype.greater = function (x) { - this.throwIfDisposed(); - return ops.greater(this, x); - }; - Tensor.prototype.greaterStrict = function (x) { - this.throwIfDisposed(); - return ops.greaterStrict(this, x); - }; - Tensor.prototype.greaterEqual = function (x) { - this.throwIfDisposed(); - return ops.greaterEqual(this, x); - }; - Tensor.prototype.greaterEqualStrict = function (x) { - this.throwIfDisposed(); - return ops.greaterEqualStrict(this, x); - }; - Tensor.prototype.logicalAnd = function (x) { - this.throwIfDisposed(); - return ops.logicalAnd(this, x); - }; - Tensor.prototype.logicalOr = function (x) { - this.throwIfDisposed(); - return ops.logicalOr(this, x); - }; - Tensor.prototype.logicalXor = function (x) { - this.throwIfDisposed(); - return ops.logicalXor(this, x); - }; - Tensor.prototype.where = function (condition, x) { - this.throwIfDisposed(); - return ops.where(condition, this, x); - }; - Tensor.prototype.neg = function () { - this.throwIfDisposed(); - return ops.neg(this); - }; - Tensor.prototype.ceil = function () { - this.throwIfDisposed(); - return ops.ceil(this); - }; - Tensor.prototype.floor = function () { - this.throwIfDisposed(); - return ops.floor(this); - }; - Tensor.prototype.exp = function () { - this.throwIfDisposed(); - return ops.exp(this); - }; - Tensor.prototype.log = function () { - this.throwIfDisposed(); - return ops.log(this); - }; - Tensor.prototype.sqrt = function () { - this.throwIfDisposed(); - return ops.sqrt(this); - }; - Tensor.prototype.square = function () { - this.throwIfDisposed(); - return ops.square(this); - }; - Tensor.prototype.abs = function () { - this.throwIfDisposed(); - return ops.abs(this); - }; - Tensor.prototype.clipByValue = function (min, max) { - this.throwIfDisposed(); - return ops.clipByValue(this, min, max); - }; - Tensor.prototype.relu = function () { - this.throwIfDisposed(); - return ops.relu(this); - }; - Tensor.prototype.elu = function () { - this.throwIfDisposed(); - return ops.elu(this); - }; - Tensor.prototype.selu = function () { - this.throwIfDisposed(); - return ops.selu(this); - }; - Tensor.prototype.leakyRelu = function (alpha) { - if (alpha === void 0) { alpha = 0.2; } - this.throwIfDisposed(); - return ops.leakyRelu(this, alpha); - }; - Tensor.prototype.prelu = function (alpha) { - this.throwIfDisposed(); - return ops.prelu(this, alpha); - }; - Tensor.prototype.sigmoid = function () { - this.throwIfDisposed(); - return ops.sigmoid(this); - }; - Tensor.prototype.sin = function () { - this.throwIfDisposed(); - return ops.sin(this); - }; - Tensor.prototype.cos = function () { - this.throwIfDisposed(); - return ops.cos(this); - }; - Tensor.prototype.tan = function () { - this.throwIfDisposed(); - return ops.tan(this); - }; - Tensor.prototype.asin = function () { - this.throwIfDisposed(); - return ops.asin(this); - }; - Tensor.prototype.acos = function () { - this.throwIfDisposed(); - return ops.acos(this); - }; - Tensor.prototype.atan = function () { - this.throwIfDisposed(); - return ops.atan(this); - }; - Tensor.prototype.sinh = function () { - this.throwIfDisposed(); - return ops.sinh(this); - }; - Tensor.prototype.cosh = function () { - this.throwIfDisposed(); - return ops.cosh(this); - }; - Tensor.prototype.tanh = function () { - this.throwIfDisposed(); - return ops.tanh(this); - }; - Tensor.prototype.step = function (alpha) { - if (alpha === void 0) { alpha = 0.0; } - this.throwIfDisposed(); - return ops.step(this, alpha); - }; - Tensor.prototype.softmax = function (dim) { - if (dim === void 0) { dim = -1; } - this.throwIfDisposed(); - return ops.softmax(this, dim); - }; - Tensor.prototype.resizeBilinear = function (newShape2D, alignCorners) { - if (alignCorners === void 0) { alignCorners = false; } - this.throwIfDisposed(); - return ops.image.resizeBilinear(this, newShape2D, alignCorners); - }; - Tensor.prototype.conv1d = function (filter, stride, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.conv1d(this, filter, stride, pad, dimRoundingMode); - }; - Tensor.prototype.conv2d = function (filter, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.conv2d(this, filter, strides, pad, dimRoundingMode); - }; - Tensor.prototype.conv2dTranspose = function (filter, outputShape, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.conv2dTranspose(this, filter, outputShape, strides, pad, dimRoundingMode); - }; - Tensor.prototype.depthwiseConv2D = function (filter, strides, pad, rates, dimRoundingMode) { - if (rates === void 0) { rates = [1, 1]; } - this.throwIfDisposed(); - return ops.depthwiseConv2d(this, filter, strides, pad, rates, dimRoundingMode); - }; - Tensor.prototype.avgPool = function (filterSize, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.avgPool(this, filterSize, strides, pad, dimRoundingMode); - }; - Tensor.prototype.maxPool = function (filterSize, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.maxPool(this, filterSize, strides, pad, dimRoundingMode); - }; - Tensor.prototype.minPool = function (filterSize, strides, pad, dimRoundingMode) { - this.throwIfDisposed(); - return ops.minPool(this, filterSize, strides, pad, dimRoundingMode); - }; - Tensor.prototype.localResponseNormalization = function (radius, bias, alpha, beta, normRegion) { - if (radius === void 0) { radius = 5; } - if (bias === void 0) { bias = 1; } - if (alpha === void 0) { alpha = 1; } - if (beta === void 0) { beta = 0.5; } - if (normRegion === void 0) { normRegion = 'acrossChannels'; } - return ops.localResponseNormalization(this, radius, bias, alpha, beta, normRegion); - }; - Tensor.prototype.variable = function (trainable, name, dtype) { - if (trainable === void 0) { trainable = true; } - this.throwIfDisposed(); - return Variable.variable(this, trainable, name, dtype); - }; - Tensor.nextId = 0; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "flatten", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "asScalar", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as1D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as2D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as3D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "as4D", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "asType", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "buffer", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "data", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "dataSync", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "dispose", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "toFloat", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "toInt", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "toBool", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "print", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "reshape", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "reshapeAs", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "expandDims", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "squeeze", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor.prototype, "clone", null); - Tensor = Tensor_1 = __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Tensor); - return Tensor; - var Tensor_1; -}()); -exports.Tensor = Tensor; -exports.NDArray = Tensor; -var Scalar = (function (_super) { - __extends(Scalar, _super); - function Scalar() { - return _super !== null && _super.apply(this, arguments) || this; - } - Scalar.new = function (value, dtype) { - return ops.scalar(value, dtype); - }; - return Scalar; -}(Tensor)); -exports.Scalar = Scalar; -var Tensor1D = (function (_super) { - __extends(Tensor1D, _super); - function Tensor1D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor1D.new = function (values, dtype) { - return ops.tensor1d(values, dtype); - }; - return Tensor1D; -}(Tensor)); -exports.Tensor1D = Tensor1D; -exports.Array1D = Tensor1D; -var Tensor2D = (function (_super) { - __extends(Tensor2D, _super); - function Tensor2D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor2D.new = function (shape, values, dtype) { - return ops.tensor2d(values, shape, dtype); - }; - return Tensor2D; -}(Tensor)); -exports.Tensor2D = Tensor2D; -exports.Array2D = Tensor2D; -var Tensor3D = (function (_super) { - __extends(Tensor3D, _super); - function Tensor3D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor3D.new = function (shape, values, dtype) { - return ops.tensor3d(values, shape, dtype); - }; - return Tensor3D; -}(Tensor)); -exports.Tensor3D = Tensor3D; -exports.Array3D = Tensor3D; -var Tensor4D = (function (_super) { - __extends(Tensor4D, _super); - function Tensor4D() { - return _super !== null && _super.apply(this, arguments) || this; - } - Tensor4D.new = function (shape, values, dtype) { - return ops.tensor4d(values, shape, dtype); - }; - return Tensor4D; -}(Tensor)); -exports.Tensor4D = Tensor4D; -exports.Array4D = Tensor4D; -var Variable = (function (_super) { - __extends(Variable, _super); - function Variable(initialValue, trainable, name) { - if (trainable === void 0) { trainable = true; } - var _this = _super.call(this, initialValue.shape, initialValue.dtype, null, initialValue.dataId) || this; - _this.trainable = trainable; - _this.name = name; - if (_this.name == null) { - _this.name = Variable_1.nextVarId.toString(); - Variable_1.nextVarId++; - } - environment_1.ENV.engine.registerVariable(_this); - return _this; - } - Variable_1 = Variable; - Variable.variable = function (initialValue, trainable, name, dtype) { - if (trainable === void 0) { trainable = true; } - if (dtype != null && dtype !== initialValue.dtype) { - initialValue = initialValue.asType(dtype); - } - return new Variable_1(initialValue, trainable, name); - }; - Variable.prototype.assign = function (newValue) { - if (newValue.dtype !== this.dtype) { - throw new Error("dtype of the new value (" + newValue.dtype + ") and " + - ("previous value (" + this.dtype + ") must match")); - } - if (!util.arraysEqual(newValue.shape, this.shape)) { - throw new Error("shape of the new value (" + newValue.shape + ") and " + - ("previous value (" + this.shape + ") must match")); - } - environment_1.ENV.engine.disposeTensor(this); - this.dataId = newValue.dataId; - environment_1.ENV.engine.registerTensor(this); - }; - Variable.nextVarId = 0; - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Variable.prototype, "assign", null); - __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }) - ], Variable, "variable", null); - Variable = Variable_1 = __decorate([ - doc_1.doc({ heading: 'Tensors', subheading: 'Classes' }) - ], Variable); - return Variable; - var Variable_1; -}(Tensor)); -exports.Variable = Variable; -var variable = Variable.variable; -exports.variable = variable; -function computeStrides(shape) { - var rank = shape.length; - if (rank < 2) { - return []; - } - var strides = new Array(rank - 1); - strides[rank - 2] = shape[rank - 1]; - for (var i = rank - 3; i >= 0; --i) { - strides[i] = strides[i + 1] * shape[i + 1]; - } - return strides; -} - -},{"./doc":32,"./environment":34,"./ops/ops":123,"./util":151}],147:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var environment_1 = require("./environment"); -var backend_cpu_1 = require("./kernels/backend_cpu"); -var backend_webgl_1 = require("./kernels/backend_webgl"); -var tensor_1 = require("./tensor"); -var util = require("./util"); -var WEBGL_FLOAT_ENVS = [ - { 'BACKEND': 'webgl', 'WEBGL_FLOAT_TEXTURE_ENABLED': true, 'WEBGL_VERSION': 1 }, - { - 'BACKEND': 'webgl', - 'WEBGL_FLOAT_TEXTURE_ENABLED': true, - 'WEBGL_VERSION': 2 - } -]; -exports.WEBGL_ENVS = WEBGL_FLOAT_ENVS.concat([{ - 'BACKEND': 'webgl', - 'WEBGL_FLOAT_TEXTURE_ENABLED': false, - 'WEBGL_VERSION': 1 - }]); -exports.CPU_ENVS = [{ 'BACKEND': 'cpu' }]; -exports.ALL_FLOAT_ENVS = WEBGL_FLOAT_ENVS.concat(exports.CPU_ENVS); -exports.ALL_ENVS = exports.WEBGL_ENVS.concat(exports.CPU_ENVS); -exports.TEST_EPSILON = 1e-2; -function expectArraysClose(actual, expected, epsilon) { - if (epsilon === void 0) { epsilon = exports.TEST_EPSILON; } - if (!(actual instanceof tensor_1.Tensor) && !(expected instanceof tensor_1.Tensor)) { - var aType = actual.constructor.name; - var bType = expected.constructor.name; - if (aType !== bType) { - throw new Error("Arrays are of different type actual: " + aType + " " + - ("vs expected: " + bType)); - } - } - else if (actual instanceof tensor_1.Tensor && expected instanceof tensor_1.Tensor) { - if (actual.dtype !== expected.dtype) { - throw new Error("Arrays are of different type actual: " + actual.dtype + " " + - ("vs expected: " + expected.dtype + ".")); - } - if (!util.arraysEqual(actual.shape, expected.shape)) { - throw new Error("Arrays are of different shape actual: " + actual.shape + " " + - ("vs expected: " + expected.shape + ".")); - } - } - var actualValues; - var expectedValues; - if (actual instanceof tensor_1.Tensor) { - actualValues = actual.dataSync(); - } - else { - actualValues = actual; - } - if (expected instanceof tensor_1.Tensor) { - expectedValues = expected.dataSync(); - } - else { - expectedValues = expected; - } - if (actualValues.length !== expectedValues.length) { - throw new Error("Arrays have different lengths actual: " + actualValues.length + " vs " + - ("expected: " + expectedValues.length + ".\n") + - ("Actual: " + actualValues + ".\n") + - ("Expected: " + expectedValues + ".")); - } - for (var i = 0; i < expectedValues.length; ++i) { - var a = actualValues[i]; - var e = expectedValues[i]; - if (!areClose(a, Number(e), epsilon)) { - throw new Error("Arrays differ: actual[" + i + "] = " + a + ", expected[" + i + "] = " + e + ".\n" + - ("Actual: " + actualValues + ".\n") + - ("Expected: " + expectedValues + ".")); - } - } -} -exports.expectArraysClose = expectArraysClose; -function expectArraysEqual(actual, expected) { - return expectArraysClose(actual, expected, 0); -} -exports.expectArraysEqual = expectArraysEqual; -function expectNumbersClose(a, e, epsilon) { - if (epsilon === void 0) { epsilon = exports.TEST_EPSILON; } - if (!areClose(a, e, epsilon)) { - throw new Error("Numbers differ: actual === " + a + ", expected === " + e); - } -} -exports.expectNumbersClose = expectNumbersClose; -function areClose(a, e, epsilon) { - if (isNaN(a) && isNaN(e)) { - return true; - } - if (isNaN(a) || isNaN(e) || Math.abs(a - e) > epsilon) { - return false; - } - return true; -} -function expectValuesInRange(actual, low, high) { - var actualVals; - if (actual instanceof tensor_1.Tensor) { - actualVals = actual.dataSync(); - } - else { - actualVals = actual; - } - for (var i = 0; i < actualVals.length; i++) { - if (actualVals[i] < low || actualVals[i] > high) { - throw new Error("Value out of range:" + actualVals[i] + " low: " + low + ", high: " + high); - } - } -} -exports.expectValuesInRange = expectValuesInRange; -function describeWithFlags(name, featuresList, tests) { - featuresList.forEach(function (features) { - var testName = name + ' ' + JSON.stringify(features); - executeTests(testName, tests, features); - }); -} -exports.describeWithFlags = describeWithFlags; -function executeTests(testName, tests, features) { - describe(testName, function () { - beforeEach(function () { - environment_1.ENV.setFeatures(features || {}); - environment_1.ENV.addCustomBackend('webgl', function () { return new backend_webgl_1.MathBackendWebGL(); }); - environment_1.ENV.addCustomBackend('cpu', function () { return new backend_cpu_1.MathBackendCPU(); }); - if (features && features.BACKEND != null) { - environment_1.Environment.setBackend(features.BACKEND); - } - environment_1.ENV.engine.startScope(); - }); - afterEach(function () { - environment_1.ENV.engine.endScope(null); - environment_1.ENV.reset(); - }); - tests(); - }); -} -function assertIsNan(val, dtype) { - if (!util.isValNaN(val, dtype)) { - throw new Error("Value " + val + " does not represent NaN for dtype " + dtype); - } -} -exports.assertIsNan = assertIsNan; - -},{"./environment":34,"./kernels/backend_cpu":68,"./kernels/backend_webgl":69,"./tensor":146,"./util":151}],148:[function(require,module,exports){ -"use strict"; -var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { - var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; - if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); - else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var doc_1 = require("./doc"); -var environment_1 = require("./environment"); -var Tracking = (function () { - function Tracking() { - } - Tracking.tidy = function (nameOrFn, fn, gradMode) { - if (gradMode === void 0) { gradMode = false; } - if (fn == null) { - if (typeof nameOrFn !== 'function') { - throw new Error('Please provide a function to dl.tidy()'); - } - fn = nameOrFn; - nameOrFn = ''; - } - else { - if (typeof nameOrFn !== 'string' && !(nameOrFn instanceof String)) { - throw new Error('When calling with two arguments, the first argument ' + - 'to dl.tidy() must be a string'); - } - if (typeof fn !== 'function') { - throw new Error('When calling with two arguments, the 2nd argument ' + - 'to dl.tidy() must be a function'); - } - } - environment_1.ENV.engine.startScope(gradMode); - var result = fn(); - if (result instanceof Promise) { - result.then(function (r) { return environment_1.ENV.engine.endScope(r, gradMode); }); - return result; - } - else { - environment_1.ENV.engine.endScope(result, gradMode); - return result; - } - }; - Tracking.keep = function (result) { - return environment_1.ENV.engine.keep(result); - }; - Tracking.time = function (f) { - return environment_1.ENV.engine.time(f); - }; - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Memory' }) - ], Tracking, "tidy", null); - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Memory' }) - ], Tracking, "keep", null); - __decorate([ - doc_1.doc({ heading: 'Performance', subheading: 'Timing' }) - ], Tracking, "time", null); - return Tracking; -}()); -exports.Tracking = Tracking; - -},{"./doc":32,"./environment":34}],149:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var adadelta_optimizer_1 = require("./optimizers/adadelta_optimizer"); -var adagrad_optimizer_1 = require("./optimizers/adagrad_optimizer"); -var adam_optimizer_1 = require("./optimizers/adam_optimizer"); -var adamax_optimizer_1 = require("./optimizers/adamax_optimizer"); -var momentum_optimizer_1 = require("./optimizers/momentum_optimizer"); -var optimizer_constructors_1 = require("./optimizers/optimizer_constructors"); -var rmsprop_optimizer_1 = require("./optimizers/rmsprop_optimizer"); -var sgd_optimizer_1 = require("./optimizers/sgd_optimizer"); -[momentum_optimizer_1.MomentumOptimizer, sgd_optimizer_1.SGDOptimizer, adadelta_optimizer_1.AdadeltaOptimizer, adagrad_optimizer_1.AdagradOptimizer, - rmsprop_optimizer_1.RMSPropOptimizer, adamax_optimizer_1.AdamaxOptimizer, adam_optimizer_1.AdamOptimizer]; -exports.train = { - sgd: optimizer_constructors_1.OptimizerConstructors.sgd, - momentum: optimizer_constructors_1.OptimizerConstructors.momentum, - adadelta: optimizer_constructors_1.OptimizerConstructors.adadelta, - adagrad: optimizer_constructors_1.OptimizerConstructors.adagrad, - rmsprop: optimizer_constructors_1.OptimizerConstructors.rmsprop, - adamax: optimizer_constructors_1.OptimizerConstructors.adamax, - adam: optimizer_constructors_1.OptimizerConstructors.adam -}; - -},{"./optimizers/adadelta_optimizer":135,"./optimizers/adagrad_optimizer":136,"./optimizers/adam_optimizer":137,"./optimizers/adamax_optimizer":138,"./optimizers/momentum_optimizer":139,"./optimizers/optimizer_constructors":141,"./optimizers/rmsprop_optimizer":142,"./optimizers/sgd_optimizer":143}],150:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var DType; -(function (DType) { - DType["float32"] = "float32"; - DType["int32"] = "int32"; - DType["bool"] = "bool"; -})(DType = exports.DType || (exports.DType = {})); -var Rank; -(function (Rank) { - Rank["R0"] = "R0"; - Rank["R1"] = "R1"; - Rank["R2"] = "R2"; - Rank["R3"] = "R3"; - Rank["R4"] = "R4"; -})(Rank = exports.Rank || (exports.Rank = {})); -var UpcastInt32AndMap; -(function (UpcastInt32AndMap) { - UpcastInt32AndMap["float32"] = "float32"; - UpcastInt32AndMap["int32"] = "int32"; - UpcastInt32AndMap["bool"] = "int32"; -})(UpcastInt32AndMap || (UpcastInt32AndMap = {})); -var UpcastBoolAndMap; -(function (UpcastBoolAndMap) { - UpcastBoolAndMap["float32"] = "float32"; - UpcastBoolAndMap["int32"] = "int32"; - UpcastBoolAndMap["bool"] = "bool"; -})(UpcastBoolAndMap || (UpcastBoolAndMap = {})); -var UpcastFloat32AndMap; -(function (UpcastFloat32AndMap) { - UpcastFloat32AndMap["float32"] = "float32"; - UpcastFloat32AndMap["int32"] = "float32"; - UpcastFloat32AndMap["bool"] = "float32"; -})(UpcastFloat32AndMap || (UpcastFloat32AndMap = {})); -var upcastTypeMap = { - float32: UpcastFloat32AndMap, - int32: UpcastInt32AndMap, - bool: UpcastBoolAndMap -}; -function upcastType(typeA, typeB) { - return upcastTypeMap[typeA][typeB]; -} -exports.upcastType = upcastType; -function sumOutType(type) { - return upcastType(type, 'int32'); -} -exports.sumOutType = sumOutType; - -},{}],151:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var tensor_1 = require("./tensor"); -function shuffle(array) { - var counter = array.length; - var temp = 0; - var index = 0; - while (counter > 0) { - index = (Math.random() * counter) | 0; - counter--; - temp = array[counter]; - array[counter] = array[index]; - array[index] = temp; - } -} -exports.shuffle = shuffle; -function clamp(min, x, max) { - return Math.max(min, Math.min(x, max)); -} -exports.clamp = clamp; -function randUniform(a, b) { - return Math.random() * (b - a) + a; -} -exports.randUniform = randUniform; -function distSquared(a, b) { - var result = 0; - for (var i = 0; i < a.length; i++) { - var diff = Number(a[i]) - Number(b[i]); - result += diff * diff; - } - return result; -} -exports.distSquared = distSquared; -function assert(expr, msg) { - if (!expr) { - throw new Error(msg); - } -} -exports.assert = assert; -function assertShapesMatch(shapeA, shapeB, errorMessagePrefix) { - if (errorMessagePrefix === void 0) { errorMessagePrefix = ''; } - assert(arraysEqual(shapeA, shapeB), errorMessagePrefix + ("Shapes " + shapeA + " and " + shapeB + " must match")); -} -exports.assertShapesMatch = assertShapesMatch; -function assertTypesMatch(a, b) { - assert(a.dtype === b.dtype, "The dtypes of the first (" + a.dtype + ") and " + - ("second (" + b.dtype + ") input must match")); -} -exports.assertTypesMatch = assertTypesMatch; -function flatten(arr, ret) { - if (ret === void 0) { ret = []; } - if (Array.isArray(arr)) { - for (var i = 0; i < arr.length; ++i) { - flatten(arr[i], ret); - } - } - else { - ret.push(arr); - } - return ret; -} -exports.flatten = flatten; -function inferShape(val) { - if (isTypedArray(val)) { - return [val.length]; - } - if (!Array.isArray(val)) { - return []; - } - var shape = []; - while (val instanceof Array) { - shape.push(val.length); - val = val[0]; - } - return shape; -} -exports.inferShape = inferShape; -function sizeFromShape(shape) { - if (shape.length === 0) { - return 1; - } - var size = shape[0]; - for (var i = 1; i < shape.length; i++) { - size *= shape[i]; - } - return size; -} -exports.sizeFromShape = sizeFromShape; -function isScalarShape(shape) { - return shape.length === 0; -} -exports.isScalarShape = isScalarShape; -function arraysEqual(n1, n2) { - if (n1.length !== n2.length) { - return false; - } - for (var i = 0; i < n1.length; i++) { - if (n1[i] !== n2[i]) { - return false; - } - } - return true; -} -exports.arraysEqual = arraysEqual; -function isInt(a) { - return a % 1 === 0; -} -exports.isInt = isInt; -function tanh(x) { - if (Math.tanh != null) { - return Math.tanh(x); - } - if (x === Infinity) { - return 1; - } - else if (x === -Infinity) { - return -1; - } - else { - var e2x = Math.exp(2 * x); - return (e2x - 1) / (e2x + 1); - } -} -exports.tanh = tanh; -function sizeToSquarishShape(size) { - for (var a = Math.floor(Math.sqrt(size)); a > 1; --a) { - if (size % a === 0) { - return [a, size / a]; - } - } - return [1, size]; -} -exports.sizeToSquarishShape = sizeToSquarishShape; -function createShuffledIndices(n) { - var shuffledIndices = new Uint32Array(n); - for (var i = 0; i < n; ++i) { - shuffledIndices[i] = i; - } - shuffle(shuffledIndices); - return shuffledIndices; -} -exports.createShuffledIndices = createShuffledIndices; -function rightPad(a, size) { - if (size <= a.length) { - return a; - } - return a + ' '.repeat(size - a.length); -} -exports.rightPad = rightPad; -function repeatedTry(checkFn, delayFn, maxCounter) { - if (delayFn === void 0) { delayFn = function (counter) { return 0; }; } - return new Promise(function (resolve, reject) { - var tryCount = 0; - var tryFn = function () { - if (checkFn()) { - resolve(); - return; - } - tryCount++; - var nextBackoff = delayFn(tryCount); - if (maxCounter != null && tryCount >= maxCounter) { - reject(); - return; - } - setTimeout(tryFn, nextBackoff); - }; - setTimeout(tryFn, 0); - }); -} -exports.repeatedTry = repeatedTry; -function getQueryParams(queryString) { - var params = {}; - queryString.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function (s) { - var t = []; - for (var _i = 1; _i < arguments.length; _i++) { - t[_i - 1] = arguments[_i]; - } - decodeParam(params, t[0], t[1]); - return t.join('='); - }); - return params; -} -exports.getQueryParams = getQueryParams; -function decodeParam(params, name, value) { - params[decodeURIComponent(name)] = decodeURIComponent(value || ''); -} -function inferFromImplicitShape(shape, size) { - var shapeProd = 1; - var implicitIdx = -1; - for (var i = 0; i < shape.length; ++i) { - if (shape[i] > 0) { - shapeProd *= shape[i]; - } - else if (shape[i] === -1) { - if (implicitIdx !== -1) { - throw Error("Shapes can only have 1 implicit size. " + - ("Found -1 at dim " + implicitIdx + " and dim " + i)); - } - implicitIdx = i; - } - else if (shape[i] <= 0) { - throw Error("Shapes can not be <= 0. Found " + shape[i] + " at dim " + i); - } - } - if (implicitIdx === -1) { - if (size > 0 && size !== shapeProd) { - throw Error("Size (" + size + ") must match the product of shape " + shape); - } - return shape; - } - if (size % shapeProd !== 0) { - throw Error("The implicit shape can't be a fractional number. " + - ("Got " + size + " / " + shapeProd)); - } - var newShape = shape.slice(); - newShape[implicitIdx] = size / shapeProd; - return newShape; -} -exports.inferFromImplicitShape = inferFromImplicitShape; -exports.NAN_INT32 = 1 << 31; -exports.NAN_BOOL = 255; -exports.NAN_FLOAT32 = NaN; -function getNaN(dtype) { - if (dtype === 'float32') { - return exports.NAN_FLOAT32; - } - else if (dtype === 'int32') { - return exports.NAN_INT32; - } - else if (dtype === 'bool') { - return exports.NAN_BOOL; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -exports.getNaN = getNaN; -function isValNaN(val, dtype) { - if (isNaN(val)) { - return true; - } - if (dtype === 'float32') { - return false; - } - else if (dtype === 'int32') { - return val === exports.NAN_INT32; - } - else if (dtype === 'bool') { - return val === exports.NAN_BOOL; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -exports.isValNaN = isValNaN; -function squeezeShape(shape, axis) { - var newShape = []; - var keptDims = []; - var j = 0; - for (var i = 0; i < shape.length; ++i) { - if (axis !== undefined) { - if (axis[j] === i && shape[i] > 1) { - throw new Error("axis " + i + " is not 1"); - } - if ((axis[j] === undefined || axis[j] > i) && shape[i] === 1) { - newShape.push(shape[i]); - keptDims.push(i); - } - if (axis[j] <= i) - j++; - } - if (shape[i] > 1) { - newShape.push(shape[i]); - keptDims.push(i); - } - } - return { newShape: newShape, keptDims: keptDims }; -} -exports.squeezeShape = squeezeShape; -function getTypedArrayFromDType(dtype, size) { - var values = null; - if (dtype == null || dtype === 'float32') { - values = new Float32Array(size); - } - else if (dtype === 'int32') { - values = new Int32Array(size); - } - else if (dtype === 'bool') { - values = new Uint8Array(size); - } - else { - throw new Error("Unknown data type " + dtype); - } - return values; -} -exports.getTypedArrayFromDType = getTypedArrayFromDType; -function isTensorInList(tensor, tensorList) { - for (var i = 0; i < tensorList.length; i++) { - if (tensorList[i].id === tensor.id) { - return true; - } - } - return false; -} -exports.isTensorInList = isTensorInList; -function checkForNaN(vals, dtype, name) { - for (var i = 0; i < vals.length; i++) { - if (isValNaN(vals[i], dtype)) { - throw Error("The result of the '" + name + "' has NaNs."); - } - } -} -exports.checkForNaN = checkForNaN; -function flattenNameArrayMap(nameArrayMap, keys) { - var xs = []; - if (nameArrayMap instanceof tensor_1.Tensor) { - xs.push(nameArrayMap); - } - else { - var xMap = nameArrayMap; - for (var i = 0; i < keys.length; i++) { - xs.push(xMap[keys[i]]); - } - } - return xs; -} -exports.flattenNameArrayMap = flattenNameArrayMap; -function unflattenToNameArrayMap(keys, flatArrays) { - if (keys.length !== flatArrays.length) { - throw new Error("Cannot unflatten Tensor[], keys and arrays are not of same length."); - } - var result = {}; - for (var i = 0; i < keys.length; i++) { - result[keys[i]] = flatArrays[i]; - } - return result; -} -exports.unflattenToNameArrayMap = unflattenToNameArrayMap; -function hasEncodingLoss(oldType, newType) { - if (newType === 'float32') { - return false; - } - if (newType === 'int32' && oldType !== 'float32') { - return false; - } - if (newType === 'bool' && oldType === 'bool') { - return false; - } - return true; -} -exports.hasEncodingLoss = hasEncodingLoss; -function copyTypedArray(array, dtype) { - if (dtype == null || dtype === 'float32') { - return new Float32Array(array); - } - else if (dtype === 'int32') { - var vals = new Int32Array(array.length); - for (var i = 0; i < vals.length; ++i) { - var val = array[i]; - if (isValNaN(val, 'int32')) { - vals[i] = getNaN('int32'); - } - else { - vals[i] = val; - } - } - return vals; - } - else if (dtype === 'bool') { - var bool = new Uint8Array(array.length); - for (var i = 0; i < bool.length; ++i) { - var val = array[i]; - if (isValNaN(val, 'bool')) { - bool[i] = getNaN('bool'); - } - else if (Math.round(val) !== 0) { - bool[i] = 1; - } - } - return bool; - } - else { - throw new Error("Unknown data type " + dtype); - } -} -exports.copyTypedArray = copyTypedArray; -function isTypedArray(a) { - return a instanceof Float32Array || a instanceof Int32Array || - a instanceof Uint8Array; -} -exports.isTypedArray = isTypedArray; -function bytesPerElement(dtype) { - if (dtype === 'float32' || dtype === 'int32') { - return 4; - } - else if (dtype === 'bool') { - return 1; - } - else { - throw new Error("Unknown dtype " + dtype); - } -} -exports.bytesPerElement = bytesPerElement; -function isFunction(f) { - return !!(f && f.constructor && f.call && f.apply); -} -exports.isFunction = isFunction; - -},{"./tensor":146}],152:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var version = '0.5.0'; -exports.version = version; - -},{}],153:[function(require,module,exports){ -// A library of seedable RNGs implemented in Javascript. -// -// Usage: -// -// var seedrandom = require('seedrandom'); -// var random = seedrandom(1); // or any seed. -// var x = random(); // 0 <= x < 1. Every bit is random. -// var x = random.quick(); // 0 <= x < 1. 32 bits of randomness. - -// alea, a 53-bit multiply-with-carry generator by Johannes Baagøe. -// Period: ~2^116 -// Reported to pass all BigCrush tests. -var alea = require('./lib/alea'); - -// xor128, a pure xor-shift generator by George Marsaglia. -// Period: 2^128-1. -// Reported to fail: MatrixRank and LinearComp. -var xor128 = require('./lib/xor128'); - -// xorwow, George Marsaglia's 160-bit xor-shift combined plus weyl. -// Period: 2^192-2^32 -// Reported to fail: CollisionOver, SimpPoker, and LinearComp. -var xorwow = require('./lib/xorwow'); - -// xorshift7, by François Panneton and Pierre L'ecuyer, takes -// a different approach: it adds robustness by allowing more shifts -// than Marsaglia's original three. It is a 7-shift generator -// with 256 bits, that passes BigCrush with no systmatic failures. -// Period 2^256-1. -// No systematic BigCrush failures reported. -var xorshift7 = require('./lib/xorshift7'); - -// xor4096, by Richard Brent, is a 4096-bit xor-shift with a -// very long period that also adds a Weyl generator. It also passes -// BigCrush with no systematic failures. Its long period may -// be useful if you have many generators and need to avoid -// collisions. -// Period: 2^4128-2^32. -// No systematic BigCrush failures reported. -var xor4096 = require('./lib/xor4096'); - -// Tyche-i, by Samuel Neves and Filipe Araujo, is a bit-shifting random -// number generator derived from ChaCha, a modern stream cipher. -// https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf -// Period: ~2^127 -// No systematic BigCrush failures reported. -var tychei = require('./lib/tychei'); - -// The original ARC4-based prng included in this library. -// Period: ~2^1600 -var sr = require('./seedrandom'); - -sr.alea = alea; -sr.xor128 = xor128; -sr.xorwow = xorwow; -sr.xorshift7 = xorshift7; -sr.xor4096 = xor4096; -sr.tychei = tychei; - -module.exports = sr; - -},{"./lib/alea":154,"./lib/tychei":155,"./lib/xor128":156,"./lib/xor4096":157,"./lib/xorshift7":158,"./lib/xorwow":159,"./seedrandom":160}],154:[function(require,module,exports){ -// A port of an algorithm by Johannes Baagøe , 2010 -// http://baagoe.com/en/RandomMusings/javascript/ -// https://github.com/nquinlan/better-random-numbers-for-javascript-mirror -// Original work is under MIT license - - -// Copyright (C) 2010 by Johannes Baagøe -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall 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. - - - -(function(global, module, define) { - -function Alea(seed) { - var me = this, mash = Mash(); - - me.next = function() { - var t = 2091639 * me.s0 + me.c * 2.3283064365386963e-10; // 2^-32 - me.s0 = me.s1; - me.s1 = me.s2; - return me.s2 = t - (me.c = t | 0); - }; - - // Apply the seeding algorithm from Baagoe. - me.c = 1; - me.s0 = mash(' '); - me.s1 = mash(' '); - me.s2 = mash(' '); - me.s0 -= mash(seed); - if (me.s0 < 0) { me.s0 += 1; } - me.s1 -= mash(seed); - if (me.s1 < 0) { me.s1 += 1; } - me.s2 -= mash(seed); - if (me.s2 < 0) { me.s2 += 1; } - mash = null; -} - -function copy(f, t) { - t.c = f.c; - t.s0 = f.s0; - t.s1 = f.s1; - t.s2 = f.s2; - return t; -} - -function impl(seed, opts) { - var xg = new Alea(seed), - state = opts && opts.state, - prng = xg.next; - prng.int32 = function() { return (xg.next() * 0x100000000) | 0; } - prng.double = function() { - return prng() + (prng() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53 - }; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -function Mash() { - var n = 0xefc8249d; - - var mash = function(data) { - data = data.toString(); - for (var i = 0; i < data.length; i++) { - n += data.charCodeAt(i); - var h = 0.02519603282416938 * n; - n = h >>> 0; - h -= n; - h *= n; - n = h >>> 0; - h -= n; - n += h * 0x100000000; // 2^32 - } - return (n >>> 0) * 2.3283064365386963e-10; // 2^-32 - }; - - return mash; -} - - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.alea = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],155:[function(require,module,exports){ -// A Javascript implementaion of the "Tyche-i" prng algorithm by -// Samuel Neves and Filipe Araujo. -// See https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf - -(function(global, module, define) { - -function XorGen(seed) { - var me = this, strseed = ''; - - // Set up generator function. - me.next = function() { - var b = me.b, c = me.c, d = me.d, a = me.a; - b = (b << 25) ^ (b >>> 7) ^ c; - c = (c - d) | 0; - d = (d << 24) ^ (d >>> 8) ^ a; - a = (a - b) | 0; - me.b = b = (b << 20) ^ (b >>> 12) ^ c; - me.c = c = (c - d) | 0; - me.d = (d << 16) ^ (c >>> 16) ^ a; - return me.a = (a - b) | 0; - }; - - /* The following is non-inverted tyche, which has better internal - * bit diffusion, but which is about 25% slower than tyche-i in JS. - me.next = function() { - var a = me.a, b = me.b, c = me.c, d = me.d; - a = (me.a + me.b | 0) >>> 0; - d = me.d ^ a; d = d << 16 ^ d >>> 16; - c = me.c + d | 0; - b = me.b ^ c; b = b << 12 ^ d >>> 20; - me.a = a = a + b | 0; - d = d ^ a; me.d = d = d << 8 ^ d >>> 24; - me.c = c = c + d | 0; - b = b ^ c; - return me.b = (b << 7 ^ b >>> 25); - } - */ - - me.a = 0; - me.b = 0; - me.c = 2654435769 | 0; - me.d = 1367130551; - - if (seed === Math.floor(seed)) { - // Integer seed. - me.a = (seed / 0x100000000) | 0; - me.b = seed | 0; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 20; k++) { - me.b ^= strseed.charCodeAt(k) | 0; - me.next(); - } -} - -function copy(f, t) { - t.a = f.a; - t.b = f.b; - t.c = f.c; - t.d = f.d; - return t; -}; - -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.tychei = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],156:[function(require,module,exports){ -// A Javascript implementaion of the "xor128" prng algorithm by -// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper - -(function(global, module, define) { - -function XorGen(seed) { - var me = this, strseed = ''; - - me.x = 0; - me.y = 0; - me.z = 0; - me.w = 0; - - // Set up generator function. - me.next = function() { - var t = me.x ^ (me.x << 11); - me.x = me.y; - me.y = me.z; - me.z = me.w; - return me.w ^= (me.w >>> 19) ^ t ^ (t >>> 8); - }; - - if (seed === (seed | 0)) { - // Integer seed. - me.x = seed; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 64; k++) { - me.x ^= strseed.charCodeAt(k) | 0; - me.next(); - } -} - -function copy(f, t) { - t.x = f.x; - t.y = f.y; - t.z = f.z; - t.w = f.w; - return t; -} - -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xor128 = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],157:[function(require,module,exports){ -// A Javascript implementaion of Richard Brent's Xorgens xor4096 algorithm. -// -// This fast non-cryptographic random number generator is designed for -// use in Monte-Carlo algorithms. It combines a long-period xorshift -// generator with a Weyl generator, and it passes all common batteries -// of stasticial tests for randomness while consuming only a few nanoseconds -// for each prng generated. For background on the generator, see Brent's -// paper: "Some long-period random number generators using shifts and xors." -// http://arxiv.org/pdf/1004.3115v1.pdf -// -// Usage: -// -// var xor4096 = require('xor4096'); -// random = xor4096(1); // Seed with int32 or string. -// assert.equal(random(), 0.1520436450538547); // (0, 1) range, 53 bits. -// assert.equal(random.int32(), 1806534897); // signed int32, 32 bits. -// -// For nonzero numeric keys, this impelementation provides a sequence -// identical to that by Brent's xorgens 3 implementaion in C. This -// implementation also provides for initalizing the generator with -// string seeds, or for saving and restoring the state of the generator. -// -// On Chrome, this prng benchmarks about 2.1 times slower than -// Javascript's built-in Math.random(). - -(function(global, module, define) { - -function XorGen(seed) { - var me = this; - - // Set up generator function. - me.next = function() { - var w = me.w, - X = me.X, i = me.i, t, v; - // Update Weyl generator. - me.w = w = (w + 0x61c88647) | 0; - // Update xor generator. - v = X[(i + 34) & 127]; - t = X[i = ((i + 1) & 127)]; - v ^= v << 13; - t ^= t << 17; - v ^= v >>> 15; - t ^= t >>> 12; - // Update Xor generator array state. - v = X[i] = v ^ t; - me.i = i; - // Result is the combination. - return (v + (w ^ (w >>> 16))) | 0; - }; - - function init(me, seed) { - var t, v, i, j, w, X = [], limit = 128; - if (seed === (seed | 0)) { - // Numeric seeds initialize v, which is used to generates X. - v = seed; - seed = null; - } else { - // String seeds are mixed into v and X one character at a time. - seed = seed + '\0'; - v = 0; - limit = Math.max(limit, seed.length); - } - // Initialize circular array and weyl value. - for (i = 0, j = -32; j < limit; ++j) { - // Put the unicode characters into the array, and shuffle them. - if (seed) v ^= seed.charCodeAt((j + 32) % seed.length); - // After 32 shuffles, take v as the starting w value. - if (j === 0) w = v; - v ^= v << 10; - v ^= v >>> 15; - v ^= v << 4; - v ^= v >>> 13; - if (j >= 0) { - w = (w + 0x61c88647) | 0; // Weyl. - t = (X[j & 127] ^= (v + w)); // Combine xor and weyl to init array. - i = (0 == t) ? i + 1 : 0; // Count zeroes. - } - } - // We have detected all zeroes; make the key nonzero. - if (i >= 128) { - X[(seed && seed.length || 0) & 127] = -1; - } - // Run the generator 512 times to further mix the state before using it. - // Factoring this as a function slows the main generator, so it is just - // unrolled here. The weyl generator is not advanced while warming up. - i = 127; - for (j = 4 * 128; j > 0; --j) { - v = X[(i + 34) & 127]; - t = X[i = ((i + 1) & 127)]; - v ^= v << 13; - t ^= t << 17; - v ^= v >>> 15; - t ^= t >>> 12; - X[i] = v ^ t; - } - // Storing state as object members is faster than using closure variables. - me.w = w; - me.X = X; - me.i = i; - } - - init(me, seed); -} - -function copy(f, t) { - t.i = f.i; - t.w = f.w; - t.X = f.X.slice(); - return t; -}; - -function impl(seed, opts) { - if (seed == null) seed = +(new Date); - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (state.X) copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xor4096 = impl; -} - -})( - this, // window object or global - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - -},{}],158:[function(require,module,exports){ -// A Javascript implementaion of the "xorshift7" algorithm by -// François Panneton and Pierre L'ecuyer: -// "On the Xorgshift Random Number Generators" -// http://saluc.engr.uconn.edu/refs/crypto/rng/panneton05onthexorshift.pdf - -(function(global, module, define) { - -function XorGen(seed) { - var me = this; - - // Set up generator function. - me.next = function() { - // Update xor generator. - var X = me.x, i = me.i, t, v, w; - t = X[i]; t ^= (t >>> 7); v = t ^ (t << 24); - t = X[(i + 1) & 7]; v ^= t ^ (t >>> 10); - t = X[(i + 3) & 7]; v ^= t ^ (t >>> 3); - t = X[(i + 4) & 7]; v ^= t ^ (t << 7); - t = X[(i + 7) & 7]; t = t ^ (t << 13); v ^= t ^ (t << 9); - X[i] = v; - me.i = (i + 1) & 7; - return v; - }; - - function init(me, seed) { - var j, w, X = []; - - if (seed === (seed | 0)) { - // Seed state array using a 32-bit integer. - w = X[0] = seed; - } else { - // Seed state using a string. - seed = '' + seed; - for (j = 0; j < seed.length; ++j) { - X[j & 7] = (X[j & 7] << 15) ^ - (seed.charCodeAt(j) + X[(j + 1) & 7] << 13); - } - } - // Enforce an array length of 8, not all zeroes. - while (X.length < 8) X.push(0); - for (j = 0; j < 8 && X[j] === 0; ++j); - if (j == 8) w = X[7] = -1; else w = X[j]; - - me.x = X; - me.i = 0; - - // Discard an initial 256 values. - for (j = 256; j > 0; --j) { - me.next(); - } - } - - init(me, seed); -} - -function copy(f, t) { - t.x = f.x.slice(); - t.i = f.i; - return t; -} - -function impl(seed, opts) { - if (seed == null) seed = +(new Date); - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (state.x) copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xorshift7 = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - -},{}],159:[function(require,module,exports){ -// A Javascript implementaion of the "xorwow" prng algorithm by -// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper - -(function(global, module, define) { - -function XorGen(seed) { - var me = this, strseed = ''; - - // Set up generator function. - me.next = function() { - var t = (me.x ^ (me.x >>> 2)); - me.x = me.y; me.y = me.z; me.z = me.w; me.w = me.v; - return (me.d = (me.d + 362437 | 0)) + - (me.v = (me.v ^ (me.v << 4)) ^ (t ^ (t << 1))) | 0; - }; - - me.x = 0; - me.y = 0; - me.z = 0; - me.w = 0; - me.v = 0; - - if (seed === (seed | 0)) { - // Integer seed. - me.x = seed; - } else { - // String seed. - strseed += seed; - } - - // Mix in string seed, then discard an initial batch of 64 values. - for (var k = 0; k < strseed.length + 64; k++) { - me.x ^= strseed.charCodeAt(k) | 0; - if (k == strseed.length) { - me.d = me.x << 10 ^ me.x >>> 4; - } - me.next(); - } -} - -function copy(f, t) { - t.x = f.x; - t.y = f.y; - t.z = f.z; - t.w = f.w; - t.v = f.v; - t.d = f.d; - return t; -} - -function impl(seed, opts) { - var xg = new XorGen(seed), - state = opts && opts.state, - prng = function() { return (xg.next() >>> 0) / 0x100000000; }; - prng.double = function() { - do { - var top = xg.next() >>> 11, - bot = (xg.next() >>> 0) / 0x100000000, - result = (top + bot) / (1 << 21); - } while (result === 0); - return result; - }; - prng.int32 = xg.next; - prng.quick = prng; - if (state) { - if (typeof(state) == 'object') copy(state, xg); - prng.state = function() { return copy(xg, {}); } - } - return prng; -} - -if (module && module.exports) { - module.exports = impl; -} else if (define && define.amd) { - define(function() { return impl; }); -} else { - this.xorwow = impl; -} - -})( - this, - (typeof module) == 'object' && module, // present in node.js - (typeof define) == 'function' && define // present with an AMD loader -); - - - -},{}],160:[function(require,module,exports){ -/* -Copyright 2014 David Bau. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall 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. - -*/ - -(function (pool, math) { -// -// The following constants are related to IEEE 754 limits. -// -var global = this, - width = 256, // each RC4 output is 0 <= x < 256 - chunks = 6, // at least six RC4 outputs for each double - digits = 52, // there are 52 significant digits in a double - rngname = 'random', // rngname: name for Math.random and Math.seedrandom - startdenom = math.pow(width, chunks), - significance = math.pow(2, digits), - overflow = significance * 2, - mask = width - 1, - nodecrypto; // node.js crypto module, initialized at the bottom. - -// -// seedrandom() -// This is the seedrandom function described above. -// -function seedrandom(seed, options, callback) { - var key = []; - options = (options == true) ? { entropy: true } : (options || {}); - - // Flatten the seed string or build one from local entropy if needed. - var shortseed = mixkey(flatten( - options.entropy ? [seed, tostring(pool)] : - (seed == null) ? autoseed() : seed, 3), key); - - // Use the seed to initialize an ARC4 generator. - var arc4 = new ARC4(key); - - // This function returns a random double in [0, 1) that contains - // randomness in every bit of the mantissa of the IEEE 754 value. - var prng = function() { - var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48 - d = startdenom, // and denominator d = 2 ^ 48. - x = 0; // and no 'extra last byte'. - while (n < significance) { // Fill up all significant digits by - n = (n + x) * width; // shifting numerator and - d *= width; // denominator and generating a - x = arc4.g(1); // new least-significant-byte. - } - while (n >= overflow) { // To avoid rounding up, before adding - n /= 2; // last byte, shift everything - d /= 2; // right using integer math until - x >>>= 1; // we have exactly the desired bits. - } - return (n + x) / d; // Form the number within [0, 1). - }; - - prng.int32 = function() { return arc4.g(4) | 0; } - prng.quick = function() { return arc4.g(4) / 0x100000000; } - prng.double = prng; - - // Mix the randomness into accumulated entropy. - mixkey(tostring(arc4.S), pool); - - // Calling convention: what to return as a function of prng, seed, is_math. - return (options.pass || callback || - function(prng, seed, is_math_call, state) { - if (state) { - // Load the arc4 state from the given state if it has an S array. - if (state.S) { copy(state, arc4); } - // Only provide the .state method if requested via options.state. - prng.state = function() { return copy(arc4, {}); } - } - - // If called as a method of Math (Math.seedrandom()), mutate - // Math.random because that is how seedrandom.js has worked since v1.0. - if (is_math_call) { math[rngname] = prng; return seed; } - - // Otherwise, it is a newer calling convention, so return the - // prng directly. - else return prng; - })( - prng, - shortseed, - 'global' in options ? options.global : (this == math), - options.state); -} -math['seed' + rngname] = seedrandom; - -// -// ARC4 -// -// An ARC4 implementation. The constructor takes a key in the form of -// an array of at most (width) integers that should be 0 <= x < (width). -// -// The g(count) method returns a pseudorandom integer that concatenates -// the next (count) outputs from ARC4. Its return value is a number x -// that is in the range 0 <= x < (width ^ count). -// -function ARC4(key) { - var t, keylen = key.length, - me = this, i = 0, j = me.i = me.j = 0, s = me.S = []; - - // The empty key [] is treated as [0]. - if (!keylen) { key = [keylen++]; } - - // Set up S using the standard key scheduling algorithm. - while (i < width) { - s[i] = i++; - } - for (i = 0; i < width; i++) { - s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))]; - s[j] = t; - } - - // The "g" method returns the next (count) outputs as one number. - (me.g = function(count) { - // Using instance members instead of closure state nearly doubles speed. - var t, r = 0, - i = me.i, j = me.j, s = me.S; - while (count--) { - t = s[i = mask & (i + 1)]; - r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))]; - } - me.i = i; me.j = j; - return r; - // For robust unpredictability, the function call below automatically - // discards an initial batch of values. This is called RC4-drop[256]. - // See http://google.com/search?q=rsa+fluhrer+response&btnI - })(width); -} - -// -// copy() -// Copies internal state of ARC4 to or from a plain object. -// -function copy(f, t) { - t.i = f.i; - t.j = f.j; - t.S = f.S.slice(); - return t; -}; - -// -// flatten() -// Converts an object tree to nested arrays of strings. -// -function flatten(obj, depth) { - var result = [], typ = (typeof obj), prop; - if (depth && typ == 'object') { - for (prop in obj) { - try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {} - } - } - return (result.length ? result : typ == 'string' ? obj : obj + '\0'); -} - -// -// mixkey() -// Mixes a string seed into a key that is an array of integers, and -// returns a shortened string seed that is equivalent to the result key. -// -function mixkey(seed, key) { - var stringseed = seed + '', smear, j = 0; - while (j < stringseed.length) { - key[mask & j] = - mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++)); - } - return tostring(key); -} - -// -// autoseed() -// Returns an object for autoseeding, using window.crypto and Node crypto -// module if available. -// -function autoseed() { - try { - var out; - if (nodecrypto && (out = nodecrypto.randomBytes)) { - // The use of 'out' to remember randomBytes makes tight minified code. - out = out(width); - } else { - out = new Uint8Array(width); - (global.crypto || global.msCrypto).getRandomValues(out); - } - return tostring(out); - } catch (e) { - var browser = global.navigator, - plugins = browser && browser.plugins; - return [+new Date, global, plugins, global.screen, tostring(pool)]; - } -} - -// -// tostring() -// Converts an array of charcodes to a string -// -function tostring(a) { - return String.fromCharCode.apply(0, a); -} - -// -// When seedrandom.js is loaded, we immediately mix a few bits -// from the built-in RNG into the entropy pool. Because we do -// not want to interfere with deterministic PRNG state later, -// seedrandom will not call math.random on its own again after -// initialization. -// -mixkey(math.random(), pool); - -// -// Nodejs and AMD support: export the implementation as a module using -// either convention. -// -if ((typeof module) == 'object' && module.exports) { - module.exports = seedrandom; - // When in node.js, try using crypto package for autoseeding. - try { - nodecrypto = require('crypto'); - } catch (ex) {} -} else if ((typeof define) == 'function' && define.amd) { - define(function() { return seedrandom; }); -} - -// End anonymous scope, and pass initial values. -})( - [], // pool: entropy pool starts empty - Math // math: package containing random, pow, and seedrandom -); - -},{"crypto":2}],161:[function(require,module,exports){ -(function (global){ -/*! https://mths.be/utf8js v2.1.2 by @mathias */ -;(function(root) { - - // Detect free variables `exports` - var freeExports = typeof exports == 'object' && exports; - - // Detect free variable `module` - var freeModule = typeof module == 'object' && module && - module.exports == freeExports && module; - - // Detect free variable `global`, from Node.js or Browserified code, - // and use it as `root` - var freeGlobal = typeof global == 'object' && global; - if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { - root = freeGlobal; - } - - /*--------------------------------------------------------------------------*/ - - var stringFromCharCode = String.fromCharCode; - - // Taken from https://mths.be/punycode - function ucs2decode(string) { - var output = []; - var counter = 0; - var length = string.length; - var value; - var extra; - while (counter < length) { - value = string.charCodeAt(counter++); - if (value >= 0xD800 && value <= 0xDBFF && counter < length) { - // high surrogate, and there is a next character - extra = string.charCodeAt(counter++); - if ((extra & 0xFC00) == 0xDC00) { // low surrogate - output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); - } else { - // unmatched surrogate; only append this code unit, in case the next - // code unit is the high surrogate of a surrogate pair - output.push(value); - counter--; - } - } else { - output.push(value); - } - } - return output; - } - - // Taken from https://mths.be/punycode - function ucs2encode(array) { - var length = array.length; - var index = -1; - var value; - var output = ''; - while (++index < length) { - value = array[index]; - if (value > 0xFFFF) { - value -= 0x10000; - output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); - value = 0xDC00 | value & 0x3FF; - } - output += stringFromCharCode(value); - } - return output; - } - - function checkScalarValue(codePoint) { - if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { - throw Error( - 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + - ' is not a scalar value' - ); - } - } - /*--------------------------------------------------------------------------*/ - - function createByte(codePoint, shift) { - return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); - } - - function encodeCodePoint(codePoint) { - if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence - return stringFromCharCode(codePoint); - } - var symbol = ''; - if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence - symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); - } - else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence - checkScalarValue(codePoint); - symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); - symbol += createByte(codePoint, 6); - } - else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence - symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); - symbol += createByte(codePoint, 12); - symbol += createByte(codePoint, 6); - } - symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); - return symbol; - } - - function utf8encode(string) { - var codePoints = ucs2decode(string); - var length = codePoints.length; - var index = -1; - var codePoint; - var byteString = ''; - while (++index < length) { - codePoint = codePoints[index]; - byteString += encodeCodePoint(codePoint); - } - return byteString; - } - - /*--------------------------------------------------------------------------*/ - - function readContinuationByte() { - if (byteIndex >= byteCount) { - throw Error('Invalid byte index'); - } - - var continuationByte = byteArray[byteIndex] & 0xFF; - byteIndex++; - - if ((continuationByte & 0xC0) == 0x80) { - return continuationByte & 0x3F; - } - - // If we end up here, it?™s not a continuation byte - throw Error('Invalid continuation byte'); - } - - function decodeSymbol() { - var byte1; - var byte2; - var byte3; - var byte4; - var codePoint; - - if (byteIndex > byteCount) { - throw Error('Invalid byte index'); - } - - if (byteIndex == byteCount) { - return false; - } - - // Read first byte - byte1 = byteArray[byteIndex] & 0xFF; - byteIndex++; - - // 1-byte sequence (no continuation bytes) - if ((byte1 & 0x80) == 0) { - return byte1; - } - - // 2-byte sequence - if ((byte1 & 0xE0) == 0xC0) { - byte2 = readContinuationByte(); - codePoint = ((byte1 & 0x1F) << 6) | byte2; - if (codePoint >= 0x80) { - return codePoint; - } else { - throw Error('Invalid continuation byte'); - } - } - - // 3-byte sequence (may include unpaired surrogates) - if ((byte1 & 0xF0) == 0xE0) { - byte2 = readContinuationByte(); - byte3 = readContinuationByte(); - codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; - if (codePoint >= 0x0800) { - checkScalarValue(codePoint); - return codePoint; - } else { - throw Error('Invalid continuation byte'); - } - } - - // 4-byte sequence - if ((byte1 & 0xF8) == 0xF0) { - byte2 = readContinuationByte(); - byte3 = readContinuationByte(); - byte4 = readContinuationByte(); - codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | - (byte3 << 0x06) | byte4; - if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { - return codePoint; - } - } - - throw Error('Invalid UTF-8 detected'); - } - - var byteArray; - var byteCount; - var byteIndex; - function utf8decode(byteString) { - byteArray = ucs2decode(byteString); - byteCount = byteArray.length; - byteIndex = 0; - var codePoints = []; - var tmp; - while ((tmp = decodeSymbol()) !== false) { - codePoints.push(tmp); - } - return ucs2encode(codePoints); - } - - /*--------------------------------------------------------------------------*/ - - var utf8 = { - 'version': '2.1.2', - 'encode': utf8encode, - 'decode': utf8decode - }; - - // Some AMD build optimizers, like r.js, check for specific condition patterns - // like the following: - if ( - typeof define == 'function' && - typeof define.amd == 'object' && - define.amd - ) { - define(function() { - return utf8; - }); - } else if (freeExports && !freeExports.nodeType) { - if (freeModule) { // in Node.js or RingoJS v0.8.0+ - freeModule.exports = utf8; - } else { // in Narwhal or RingoJS v0.7.0- - var object = {}; - var hasOwnProperty = object.hasOwnProperty; - for (var key in utf8) { - hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); - } - } - } else { // in Rhino or a web browser - root.utf8 = utf8; - } - -}(this)); - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}]},{},[1]); diff --git a/test_teachable_machine_boilerplate/teachable_machine.js b/test_teachable_machine_boilerplate/teachable_machine.js deleted file mode 100644 index fdc3b6ba99..0000000000 --- a/test_teachable_machine_boilerplate/teachable_machine.js +++ /dev/null @@ -1,47 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function teachable_machine_open(input_num) { - if (document.getElementById("train")) - { - document.getElementById("train").innerHTML = ""; - document.getElementById("probability").innerHTML = ""; - document.getElementById("num").innerHTML = input_num; - } - else - { - var div = document.createElement('div'); - div.id = "train"; - div.style.position = 'absolute'; - div.style.display = 'none'; - document.body.appendChild(div); - - var div1 = document.createElement('div'); - div1.id = "probability"; - div1.style.position = 'absolute'; - div1.style.display = 'none'; - document.body.appendChild(div1); - - var div2 = document.createElement('div'); - div2.id = "num"; - div2.style.position = 'absolute'; - div2.style.display = 'none'; - div2.innerHTML = 4; - document.body.appendChild(div2); - } - } - - function teachable_machine_proportion(input_property){ - if (input_property=="train") - return Number(document.getElementById("train").innerHTML); - else if (input_property=="probability") - return Number(document.getElementById("probability").innerHTML); - } - - window.teachable_machine_open = teachable_machine_open; - window.teachable_machine_proportion = teachable_machine_proportion; - -}(window, window.document)); diff --git a/test_xmlHTTP_20180206/blockly.json b/test_xmlHTTP_20180206/blockly.json deleted file mode 100644 index 28c1913fca..0000000000 --- a/test_xmlHTTP_20180206/blockly.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "types": ["xmlHTTP_ResponseData"], - "category": "catPlus", - "scripts": [ - "blockly/blocks.js", - "blockly/javascript.js" - ], - "dependencies": [ - "xmlHttp.js" - ], - "msg": "blockly/msg", - "blocksMsg": "blockly/msg/blocks", - "toolbox": "blockly/toolbox.xml" -} diff --git a/test_xmlHTTP_20180206/blockly/blocks.js b/test_xmlHTTP_20180206/blockly/blocks.js deleted file mode 100644 index ad376b4d42..0000000000 --- a/test_xmlHTTP_20180206/blockly/blocks.js +++ /dev/null @@ -1,21 +0,0 @@ -Blockly.Blocks['xmlHTTP_ResponseData'] = { - init: function() { - this.appendDummyInput() - .appendField(Blockly.Msg.XMLHTTP_RESPONSEDATA) - .appendField(new Blockly.FieldDropdown([ - ["JSON","JSON"], - ["HTML","HTML"], - ["XML","XML"] - ]), "value_format_"); - this.appendValueInput("value_url_") - .setCheck("String"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setColour(300); - this.setTooltip(""); - this.setHelpUrl(""); - } -}; - - - diff --git a/test_xmlHTTP_20180206/blockly/javascript.js b/test_xmlHTTP_20180206/blockly/javascript.js deleted file mode 100644 index da391a8360..0000000000 --- a/test_xmlHTTP_20180206/blockly/javascript.js +++ /dev/null @@ -1,6 +0,0 @@ -Blockly.JavaScript['xmlHTTP_ResponseData'] = function(block) { - var value_format_ = block.getFieldValue('value_format_'); - var value_url_ = Blockly.JavaScript.valueToCode(block, 'value_url_', Blockly.JavaScript.ORDER_ATOMIC); - var code = 'getResponse('+value_url_+',"'+value_format_+'")'; - return [code, Blockly.JavaScript.ORDER_NONE]; -}; diff --git a/test_xmlHTTP_20180206/blockly/msg/blocks/en.js b/test_xmlHTTP_20180206/blockly/msg/blocks/en.js deleted file mode 100644 index 719e485be6..0000000000 --- a/test_xmlHTTP_20180206/blockly/msg/blocks/en.js +++ /dev/null @@ -1 +0,0 @@ -Blockly.Msg.XMLHTTP_RESPONSEDATA = "XMLHTTP GET RESPONSE DATA"; diff --git a/test_xmlHTTP_20180206/blockly/msg/blocks/zh-hans.js b/test_xmlHTTP_20180206/blockly/msg/blocks/zh-hans.js deleted file mode 100644 index d074444d43..0000000000 --- a/test_xmlHTTP_20180206/blockly/msg/blocks/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -Blockly.Msg.XMLHTTP_RESPONSEDATA = "XMLHTTP 取得回应资料"; diff --git a/test_xmlHTTP_20180206/blockly/msg/blocks/zh-hant.js b/test_xmlHTTP_20180206/blockly/msg/blocks/zh-hant.js deleted file mode 100644 index 09d37086f8..0000000000 --- a/test_xmlHTTP_20180206/blockly/msg/blocks/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -Blockly.Msg.XMLHTTP_RESPONSEDATA = "XMLHTTP 取得回應資料"; diff --git a/test_xmlHTTP_20180206/blockly/msg/en.js b/test_xmlHTTP_20180206/blockly/msg/en.js deleted file mode 100644 index 85aaeb383b..0000000000 --- a/test_xmlHTTP_20180206/blockly/msg/en.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catxmlHTTPResponseData = "xmlHTTP"; diff --git a/test_xmlHTTP_20180206/blockly/msg/zh-hans.js b/test_xmlHTTP_20180206/blockly/msg/zh-hans.js deleted file mode 100644 index 85aaeb383b..0000000000 --- a/test_xmlHTTP_20180206/blockly/msg/zh-hans.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catxmlHTTPResponseData = "xmlHTTP"; diff --git a/test_xmlHTTP_20180206/blockly/msg/zh-hant.js b/test_xmlHTTP_20180206/blockly/msg/zh-hant.js deleted file mode 100644 index 85aaeb383b..0000000000 --- a/test_xmlHTTP_20180206/blockly/msg/zh-hant.js +++ /dev/null @@ -1 +0,0 @@ -MSG.catxmlHTTPResponseData = "xmlHTTP"; diff --git a/test_xmlHTTP_20180206/blockly/toolbox.xml b/test_xmlHTTP_20180206/blockly/toolbox.xml deleted file mode 100644 index 792bea5d8e..0000000000 --- a/test_xmlHTTP_20180206/blockly/toolbox.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - JSON - - - - - - - diff --git a/test_xmlHTTP_20180206/xmlHttp.js b/test_xmlHTTP_20180206/xmlHttp.js deleted file mode 100644 index 14b40a487a..0000000000 --- a/test_xmlHTTP_20180206/xmlHttp.js +++ /dev/null @@ -1,71 +0,0 @@ -// Author: Chung-Yi Fu (Kaohsiung, Taiwan) https://www.facebook.com/francefu - -+(function (window, document) { - - 'use strict'; - - function getResponse(input_url_,input_format_) - { - getData(input_url_,input_format_,function(err, response) - { - if (err) - document.getElementById('demo-area-01-show').innerHTML = "failed"; - else - console.log(String(response)); - document.getElementById('demo-area-01-show').innerHTML = String(response); - } - ); - } - - function getData(DataUrl,DataFormat,callback) - { - if (DataFormat=="JSON") - { - var data = $.ajax({ - type: "get", - dataType: "jsonp", - url: DataUrl, - success: function(json) - { - console.log(json); - callback(null, String(json)); - }, - error: function(exception) - { - console.log(DataFormat+" fail"); - callback(null, DataFormat+" fail"); - } - }); - } - else - { - if (window.XMLHttpRequest) - var xmlHttp = new XMLHttpRequest(); - else - var xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); - - xmlHttp.onreadystatechange = function() - { - if (this.readyState == 4 && this.status == 200) - { - if (DataFormat=="HTML") - { - console.log(this.responseText); - callback(null, String(this.responseText)); - } - else if (DataFormat=="XML") - { - console.log(this.responseXML); - callback(null, String(this.responseXML)); - } - } - }; - xmlHttp.open("PUT", DataUrl, true); - xmlHttp.send(); - } - } - - window.getResponse = getResponse; - window.getData = getData; - -}(window, window.document)); diff --git a/webduino_bit_reply.gs b/webduino_bit_reply.gs new file mode 100644 index 0000000000..539ff4ebdf --- /dev/null +++ b/webduino_bit_reply.gs @@ -0,0 +1,26 @@ +function doPost(e) { + var CHANNEL_ACCESS_TOKEN = 'xxxxx'; + var msg = JSON.parse(e.postData.contents); + var userMessage = "Command: " + msg.events[0].message.text; + + var replyToken = msg.events[0].replyToken; + if (typeof replyToken === 'undefined') { + return; + } + + var url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': [{ + 'type': 'text', + 'text': userMessage, + }], + }), + }); +} diff --git a/xAI_googleCalendar.gs b/xAI_googleCalendar.gs new file mode 100644 index 0000000000..246e384797 --- /dev/null +++ b/xAI_googleCalendar.gs @@ -0,0 +1,130 @@ +/* +Author : ChungYi Fu (Kaohsiung, Taiwan) 2025/4/30 08:00 +https://www.facebook.com/francefu +*/ + +let channel_access_TOKEN = "xxxxx"; +let xAI_api_KEY = "xxxxx"; + +let openAI_assistant_behavior = ` +請依照以下規範:\n +1. 如果對話內容並未能包含完整日期、時間、持續時間、工作事項,請回傳'error'。\n +2. 如果對話內容包含日期、時間、持續時間、工作事項,請回傳json格式資料,格式如下:\n +{"date":"填入日期轉換為 'YYYY-MM-DD' 格式", "time":"填入時間轉換為 'HH:MM:00' 格式", "duration":"持續幾小時,預設為1","workMatter":"工作事項內容"}\n +3. 資料格式示範: {"date":"2025-05-01", "time":"12:00:00", "duration":1, "workMatter":"相約吃海鮮大餐!"}\n +4. 若沒有提及年份,則表示今年。\n +5. 若沒有提及月份,則表示本月。\n +6. 若沒有提及持續幾小時,則duration值為1。\n +7. 若提到持續一天或全天,時間由當日00:00:00算起。\n +8. 請不要多做解釋。\n +9. 請不要使用Markdown語法。\n +`; + +const error_message = "請傳送文字訊息包含行事曆所需資料:日期、時間、持續時間(可無)、事項描述並聲明要新增行事曆,或者發生提供的openAI Key無法使用!"; + +function doPost(e) { + if (e.postData) { + + let msg = JSON.parse(e.postData.contents); + let userType = msg.events[0].message.type; + let replyToken = msg.events[0].replyToken; + + if (userType=="text") { + let userMessage = msg.events[0].message.text.trim(); + + let openAI_messages = [{"role": "system", "content": openAI_assistant_behavior + "9. 現在時間為" + Utilities.formatDate(new Date(), "GMT+8", "yyyy/MM/dd HH:mm:ss")}]; + let chat_message = {}; + chat_message.role = "user"; + chat_message.content = userMessage; + openAI_messages.push(chat_message); + + let jsonData = sendMessageToOpenaiChat(xAI_api_KEY, openAI_messages).replace(/```json|```/g, ""); + if (jsonData!="error") { + try { + let data = JSON.parse(jsonData); + let date = data.date; // 預期格式:'YYYY-MM-DD' + let time = data.time; // 預期格式:'HH:MM:00' + let duration = data.duration; // 預期格式:1 + let workMatter = data.workMatter; // 預期格式:文字敘述 + let response = `行程:${workMatter}\n時間:${date} ${time}\n時數:${duration}\n\n`; + + let eventDateTime = new Date(date + 'T' + time); + let calendar = CalendarApp.getDefaultCalendar(); + try { + calendar.createEvent(workMatter, eventDateTime, new Date(eventDateTime.getTime() + Number(duration) * 60 * 60 * 1000)); + let replyMessage = [{ + "type":"text", + "text": response + "行事曆建立成功!" + }]; + sendMessageToLineBot(replyToken, replyMessage); + } catch (calendarError) { + let replyMessage = [{ + "type":"text", + "text": jsonData + "\n\n行事曆建立失敗,請檢查日期時間格式或權限設定!\n錯誤訊息:" + calendarError + }]; + sendMessageToLineBot(replyToken, replyMessage); + } + } catch (error) { + let replyMessage = [{ + "type":"text", + "text": error_message + }] + sendMessageToLineBot(replyToken, replyMessage); + } + } else { + let replyMessage = [{ + "type":"text", + "text": error_message + }] + sendMessageToLineBot(replyToken, replyMessage); + } + } + } + + return ContentService.createTextOutput("OK"); +} + +function sendMessageToOpenaiChat(key, messages) { + try { + let url = "https://api.x.ai/v1/chat/completions"; + let data = { + "model": "grok-3-fast-beta", + "messages": messages + }; + + const authHeader = "Bearer " + key; + const options = { + headers: { + Authorization: authHeader + }, + method: 'POST', + contentType: 'application/json', + payload: JSON.stringify(data) + } + + let response = UrlFetchApp.fetch(url, options); + let json = JSON.parse(response.getContentText()); + response = json["choices"][0]["message"]["content"]; + if (response == "null") + response = json["error"]["message"]; + + return response; + } catch (error) { + return error; + } +} + +function sendMessageToLineBot(replyToken, reply_message) { + let url = 'https://api.line.me/v2/bot/message/reply'; + UrlFetchApp.fetch(url, { + 'headers': { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': 'Bearer ' + channel_access_TOKEN, + }, + 'method': 'post', + 'payload': JSON.stringify({ + 'replyToken': replyToken, + 'messages': reply_message + }), + }); +}