Skip to content

Commit 1925493

Browse files
authored
Merge branch 'master' into feat/akita
2 parents f15eba0 + 3288cdc commit 1925493

File tree

18 files changed

+7806
-4748
lines changed

18 files changed

+7806
-4748
lines changed

packages/hedgehog-core/package-lock.json

Lines changed: 1026 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hedgehog-core/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
"dependencies": {
2323
"@babel/core": "^7.10.5",
2424
"@babel/preset-env": "^7.10.4",
25+
"@babel/preset-react": "^7.12.10",
2526
"@babel/preset-typescript": "^7.10.4",
2627
"@babel/standalone": "^7.10.5",
28+
"@tensorflow/tfjs": "^2.7.0",
2729
"babel-template": "^6.26.0",
2830
"clean-webpack-plugin": "^3.0.0",
2931
"esbuild-loader": "^2.9.1",
@@ -32,6 +34,7 @@
3234
"nerdamer": "^1.1.5",
3335
"webpack": "^5.21.2",
3436
"webpack-cli": "^4.5.0"
37+
"sync-fetch": "^0.3.0"
3538
},
3639
"devDependencies": {
3740
"@babel/types": "^7.10.5",

packages/hedgehog-core/src/runtime/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ export function executeOutput(code: string) {
1818
'prelude',
1919
preludeImport + code + '\n return _OUTPUT_ITEMS_LIST_;'
2020
);
21+
2122
const results = fn.call({}, prelude);
2223

2324
console.log('Execution results:');
2425
console.log(results);
26+
console.log('-- End of execution results:');
2527

2628
const returnList = [...results];
2729
prelude._OUTPUT_ITEMS_LIST_.length = 0;

packages/hedgehog-core/src/runtime/prelude.ts

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,35 @@ import { Chol, QR, LU } from '../lib/algebra';
99
import { OutputItem } from '../output/output-item';
1010
import { rawInputsToTex } from '../utilites/process-raw-inputs';
1111

12-
export { Sym, Mat, Scalar, _Mat };
12+
import * as React from 'react';
13+
import * as d3 from 'd3';
14+
15+
/*
16+
Third party libraries
17+
*/
18+
19+
// synchrounous fetch
20+
const fetch = require('sync-fetch');
21+
22+
// gpu.js
23+
import { GPU } from 'gpu.js';
24+
25+
// math.js
26+
import * as mathjs from 'mathjs';
27+
28+
// ml.js
29+
30+
// tensorflow.js
31+
import * as tf from '@tensorflow/tfjs';
32+
33+
// opencv.js
34+
35+
// d3.js
36+
37+
//tvm.js
38+
39+
40+
export { Sym, Mat, Scalar, _Mat, nerdamer, GPU, mathjs, tf, Chol, React, d3 };
1341

1442
/**
1543
* wrapper of constructing a Mat object
@@ -248,6 +276,18 @@ export function draw(data: any, layout?: any) {
248276

249277
// plot2D is a wrapper for draw() function for scatter plot on 2D only
250278
export function plot2D(x_: any, y_: any) {
279+
if (x_ instanceof Mat && y_ instanceof Mat) {
280+
draw([
281+
{
282+
x: x_.toArray(),
283+
y: y_.toArray(),
284+
type: 'scatter',
285+
mode: 'markers',
286+
marker: { color: 'blue', size: '2' },
287+
},
288+
]);
289+
return;
290+
}
251291
draw([
252292
{
253293
x: x_,
@@ -260,6 +300,18 @@ export function plot2D(x_: any, y_: any) {
260300
}
261301

262302
export function plot2DLine(x_: any, y_: any) {
303+
if (x_ instanceof Mat && y_ instanceof Mat) {
304+
draw([
305+
{
306+
x: x_.toArray(),
307+
y: y_.toArray(),
308+
type: 'scatter',
309+
mode: 'lines+markers',
310+
marker: { color: 'blue', size: '4' },
311+
},
312+
]);
313+
return;
314+
}
263315
draw([
264316
{
265317
x: x_,
@@ -273,6 +325,23 @@ export function plot2DLine(x_: any, y_: any) {
273325

274326
// plot3D is a wrapper for draw() function for scatter plot on 3D only
275327
export function plot3D(x_: any, y_: any, z_: any) {
328+
if (x_ instanceof Mat && y_ instanceof Mat && z_ instanceof Mat){
329+
draw(
330+
[
331+
{
332+
x: x_.toArray(),
333+
y: y_.toArray(),
334+
z: z_.toArray(),
335+
mode: 'markers',
336+
marker: { color: 'blue', size: 2 },
337+
opacity: 0.5,
338+
type: 'scatter3d',
339+
},
340+
],
341+
{}
342+
);
343+
return;
344+
}
276345
draw(
277346
[
278347
{
@@ -290,6 +359,23 @@ export function plot3D(x_: any, y_: any, z_: any) {
290359
}
291360

292361
export function plot3DMesh(x_: any, y_: any, z_: any) {
362+
if (x_ instanceof Mat && y_ instanceof Mat && z_ instanceof Mat){
363+
draw(
364+
[
365+
{
366+
x: x_.toArray(),
367+
y: y_.toArray(),
368+
z: z_.toArray(),
369+
mode: 'markers',
370+
marker: { color: 'blue', size: 2 },
371+
opacity: 0.5,
372+
type: 'mesh3d',
373+
},
374+
],
375+
{}
376+
);
377+
return;
378+
}
293379
draw(
294380
[
295381
{
@@ -317,6 +403,16 @@ export function formulaTex(...inputs: any[]) {
317403
_OUTPUT_ITEMS_LIST_.push({ itemType: 'FORMULA', text: inputTex });
318404
}
319405

320-
export function markdown(inputMarkdown: string) {
406+
export function markdown(...inputs: any[]) {
407+
const inputMarkdown: string = rawInputsToTex(...inputs);
321408
_OUTPUT_ITEMS_LIST_.push({ itemType: 'MARKDOWN', text: inputMarkdown });
322409
}
410+
411+
/*
412+
Synchrnous get function.
413+
Input: string, URL
414+
Output: string, text of URL
415+
*/
416+
export function get(input:string):string{
417+
return fetch(input).text();
418+
}

packages/hedgehog-core/src/transpiler/operator-overload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function invokedTemplate(op: any) {
1919
return (sym(LEFT_ARG)[Symbol.for("${op}")](RIGHT_ARG));
2020
else if (Array.isArray(LEFT_ARG) && (RIGHT_ARG instanceof Mat))
2121
return (mat(LEFT_ARG)[Symbol.for("${op}")](RIGHT_ARG));
22-
else if ( typeof LEFT_ARG === 'number' && (RIGHT_ARG instanceof Mat))
22+
else if ( (!isNaN(LEFT_ARG)) && (RIGHT_ARG instanceof Mat))
2323
return (scalar(LEFT_ARG)[Symbol.for("${op}")](RIGHT_ARG));
2424
else
2525
return LEFT_ARG ${op} RIGHT_ARG;

packages/hedgehog-core/src/transpiler/preprocess.ts

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)