(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
    typeof define === 'function' && define.amd ? define(factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MaximDeraining = factory());
})(this, (function () { 'use strict';

    const NAME = "@upscalerjs/maxim-deraining";
    const VERSION = "0.1.0";

    const getSize = (size_tensor) => {
        const size = Array.from((size_tensor).dataSync());
        if (size_tensor.shape[0] < 2) {
            console.error(size_tensor.dataSync(), size_tensor.shape);
            throw new Error('Invalid size tensor');
        }
        const [height, width,] = Array.from(size_tensor.dataSync());
        if (!height || !width) {
            console.error(size);
            throw new Error('Missing size elements');
        }
        return [
            height,
            width,
        ];
    };
    function registerOps(tf) {
        const ScaleAndTranslate = ({ inputs, }) => {
            if (inputs.length <= 2) {
                throw new Error('Expected four tensors to scale and translate op');
            }
            const [input, size_tensor,] = inputs;
            return tf.tidy(() => {
                const size = getSize(size_tensor);
                return tf.image.resizeNearestNeighbor(input, size);
            });
        };
        tf.registerOp('ScaleAndTranslate', ScaleAndTranslate);
    }

    const getMaximDefinition = ({ name, version, meta, path: modelPath, divisibilityFactor, }) => ({
        inputRange: [0, 1,],
        outputRange: [0, 1,],
        preprocess: t => t.cast('float32'),
        setup: registerOps,
        modelType: 'graph',
        _internals: {
            path: modelPath,
            name,
            version,
        },
        meta,
        divisibilityFactor,
    });

    var index = getMaximDefinition({
        path: 'models/model.json',
        name: NAME,
        version: VERSION,
        meta: {
            dataset: 'Rain13k',
            quantization: null,
        },
        divisibilityFactor: 64,
    });

    return index;

}));
