Source

AI/Operations/Arithmetic/generators.js

import { Order } from 'blockly/javascript';
/**
 * @category AI
 * @subcategory Operations
 * @module Arithmetic
 */
/**
 * Adds two tf.Tensors element-wise, A + B. Supports broadcasting.
 *
 * @param {Tensor} tensorA The first tf.Tensor to add.
 * @param {Tensor} tensorB The second tf.Tensor to add. Must have the same type as TensorA.
 * @returns {Tensor} tf.add(tensorA, tensorB)
 */
function addition(block, generator) {
    const tensorA = generator.valueToCode(block, 'TENSOR_A', Order.NONE) || '';
    const tensorB = generator.valueToCode(block, 'TENSOR_B', Order.NONE) || '';
    return [`tf.add(${tensorA},${tensorB})`, Order.VOID];
}
/**
 * Subtracts two tf.Tensors element-wise, A - B. Supports broadcasting.
 *
 * @param {Tensor} tensorA The first tf.Tensor to subtract from.
 * @param {Tensor} tensorB The second tf.Tensor to be subtracted. Must have the same dtype as TensorA.
 * @returns {Tensor} tf.sub(tensorA, tensorB)
 */
function subtraction(block, generator) {
    const tensorA = generator.valueToCode(block, 'TENSOR_A', Order.NONE) || '';
    const tensorB = generator.valueToCode(block, 'TENSOR_B', Order.NONE) || '';
    return [`tf.sub(${tensorA},${tensorB})`, Order.VOID];
}
/**
 * Multiplies two tf.Tensors element-wise, A * B. Supports broadcasting.
 *
 * @param {Tensor} tensorA The first tensor to multiply.
 * @param {Tensor} tensorB The second tf.Tensor to multiply. Must have the same dtype as TensorA.
 * @returns {Tensor} tf.mul(tensorA, tensorB)
 */
function multiplication(block, generator) {
    const tensorA = generator.valueToCode(block, 'TENSOR_A', Order.NONE) || '';
    const tensorB = generator.valueToCode(block, 'TENSOR_B', Order.NONE) || '';
    return [`tf.mul(${tensorA},${tensorB})`, Order.VOID];
}
/**
 * Divides two tf.Tensors element-wise, A / B. Supports broadcasting.
 *
 * @param {Tensor} tensorA The first tensor as the numerator.
 * @param {Tensor} tensorB The second tensor as the denominator. Must have the same dtype as TensorA.
 * @returns {Tensor} tf.div(tensorA, tensorB)
 */
function division(block, generator) {
    const tensorA = generator.valueToCode(block, 'TENSOR_A', Order.NONE) || '';
    const tensorB = generator.valueToCode(block, 'TENSOR_B', Order.NONE) || '';
    return [`tf.div(${tensorA},${tensorB})`, Order.VOID];
}
export const arithmeticBlockGenerator = {
    ['addition']: addition,
    ['subtraction']: subtraction,
    ['multiplication']: multiplication,
    ['division']: division,
};
//# sourceMappingURL=generators.js.map