UNPKG

lysergic

Version:

Synaptic's neural network compiler

208 lines 5.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const nodes_1 = require("./nodes"); function heap(position) { return new nodes_1.HeapReferenceNode(position | 0); } exports.heap = heap; function number(floatingNumber) { return new nodes_1.FloatNumberNode(floatingNumber); } exports.number = number; function intNumber(floatingNumber) { return new nodes_1.IntNumberNode(floatingNumber); } exports.intNumber = intNumber; function assign(target, rhs) { return binaryOp(target, '=', rhs); } exports.assign = assign; function krnonecker(i, j) { return binaryOp(i, 'kronecker', j); } exports.krnonecker = krnonecker; function assignMul(target, rhs) { return binaryOp(target, '*=', rhs); } exports.assignMul = assignMul; function assignSum(target, rhs) { return binaryOp(target, '+=', rhs); } exports.assignSum = assignSum; function assignSub(target, rhs) { return binaryOp(target, '-=', rhs); } exports.assignSub = assignSub; function assignDiv(target, rhs) { return binaryOp(target, '/=', rhs); } exports.assignDiv = assignDiv; function sum(lhs, rhs) { let bo = binaryOp(lhs, '+', rhs); bo.hasParenthesis = true; return bo; } exports.sum = sum; function max(lhs, rhs) { let bo = binaryOp(lhs, 'max', rhs); bo.hasParenthesis = true; return bo; } exports.max = max; function gt(lhs, rhs) { let bo = binaryOp(lhs, '>', rhs); bo.hasParenthesis = true; return bo; } exports.gt = gt; function gte(lhs, rhs) { let bo = binaryOp(lhs, '>=', rhs); bo.hasParenthesis = true; return bo; } exports.gte = gte; function lt(lhs, rhs) { let bo = binaryOp(lhs, '<', rhs); bo.hasParenthesis = true; return bo; } exports.lt = lt; function lte(lhs, rhs) { let bo = binaryOp(lhs, '<=', rhs); bo.hasParenthesis = true; return bo; } exports.lte = lte; function equal(lhs, rhs) { let bo = binaryOp(lhs, '==', rhs); bo.hasParenthesis = true; return bo; } exports.equal = equal; function pow(lhs, rhs) { let bo = binaryOp(lhs, '^', rhs); bo.hasParenthesis = true; return bo; } exports.pow = pow; function sub(lhs, rhs) { let bo = binaryOp(lhs, '-', rhs); bo.hasParenthesis = true; return bo; } exports.sub = sub; function mul(lhs, rhs) { return binaryOp(lhs, '*', rhs); } exports.mul = mul; function div(lhs, rhs) { return binaryOp(lhs, '/', rhs); } exports.div = div; function exp(rhs) { return unaryOp('exp', rhs); } exports.exp = exp; function sign(rhs) { return unaryOp('sign', rhs); } exports.sign = sign; function ln(rhs) { return unaryOp('ln', rhs); } exports.ln = ln; function sqrt(rhs) { return unaryOp('sqrt', rhs); } exports.sqrt = sqrt; function neg(rhs) { return unaryOp('-', rhs); } exports.neg = neg; function abs(rhs) { return unaryOp('abs', rhs); } exports.abs = abs; function rand(rhs) { return unaryOp('rand', rhs); } exports.rand = rand; function conditional(condition, truePart, falsePart) { const node = new nodes_1.TernaryExpressionNode(); node.condition = condition; node.truePart = truePart; node.falsePart = falsePart; return node; } exports.conditional = conditional; function binaryOp(lhs, op, rhs) { let node = new nodes_1.BinaryExpressionNode(); node.operator = op; node.lhs = lhs; node.rhs = rhs; return node; } exports.binaryOp = binaryOp; function unaryOp(op, rhs) { let node = new nodes_1.UnaryExpressionNode(); node.operator = op; node.rhs = rhs; return node; } exports.unaryOp = unaryOp; function func(name, ...parameters) { let node = new nodes_1.FunctionNode(); node.name = name; node.body = new nodes_1.BlockNode(); return node; } exports.func = func; function params(...parameters) { let node = new nodes_1.ParametersNode(); node.children = parameters.map(paramName => new nodes_1.ParameterNode(paramName)); return node; } exports.params = params; function document(...args) { let node = new nodes_1.DocumentNode(); for (let i of args) { if (i) { node.children.push(i); } } return node; } exports.document = document; function pointer(ptr) { let a = new nodes_1.HeapPointer(); a.position = ptr; return a; } exports.pointer = pointer; function floatVariable(name, value) { let a = new nodes_1.VariableDeclaration(name, 'float', value); return a; } exports.floatVariable = floatVariable; function integerVariable(name, value) { let a = new nodes_1.VariableDeclaration(name, 'int', value); return a; } exports.integerVariable = integerVariable; function block(...ops) { let r = new nodes_1.BlockNode(); r.addNode(ops); return r; } exports.block = block; function forLoop(variableName, from, to, fun) { let variable = integerVariable(variableName, 0); let loop = new nodes_1.ForLoopNode(); loop.from = from; loop.to = to; loop.var = new nodes_1.VariableReference(variable); loop.expression = fun(loop.var); return block(variable, loop); } exports.forLoop = forLoop; //# sourceMappingURL=operations.js.map