Rate This Document
Findability
Accuracy
Completeness
Readability

FloorMod

Scenario Description

Based on the input tensor input, modulo tensor mod, and the length value, perform the element-wise modulo operations on the two tensors, and store the calculation results in the output tensor. For example:

input: [5,7,15,7]
mod: [8,6,20,3]
output: [5,1,15,1]
length: 4

Code Example

#include <cmath>
#include <random>
#include <cstdint>
#include <iostream>

#include "ktfop.h"
int main()
{
    using namespace ktfop;
    size_t length = 4;
    float inputArray[] = {5, 7, 15, 7};                               
    float modArray[] = {8, 6, 20, 3};                                 
    float *input = inputArray;                                   
    float *mod = modArray;                                        
    auto *output = new float[4];                                   
    int ret = -1;
    // Call the FloorMod operator and store the results in the output array. The first and second parameters are arrays.
    ret = FloorMod(input, mod, output, length);
    std::cout << "output: [";
    for (int i = 0; i < 4; ++i) {
        std::cout << output[i];
        if (i < 3) {
            std::cout << ", ";
        }
    }
    std::cout << "]" << std::endl;         
    // Enter a null pointer and print the log "ERROR Parameter verification failed for the FloorMod Op."
    ret = FloorMod(static_cast<float *>(nullptr), mod, output, length); 
    // Enter a null pointer and print the log "ERROR Parameter verification failed for the FloorMod Op."
    ret = FloorMod(input, mod, static_cast<float *>(nullptr), length);  
    // right
    // Call the FloorMod operator and store the results in the output array. The first parameter is an array, and the second parameter is an element.
    ret = FloorMod(input, mod[0], output, length);              
    // Enter a null pointer and print the log "ERROR Parameter verification failed for the FloorMod Op."
    ret = FloorMod(static_cast<float *>(nullptr), mod[0], output, length); 
    // left
    // Call the FloorMod operator and store the results in the output array. The first parameter is an element, and the second parameter is an array.
    ret = FloorMod(input[0], mod, output, length);              
    // Enter a null pointer and print the log "ERROR Parameter verification failed for the FloorMod Op."
    ret = FloorMod(input[0], static_cast<float *>(nullptr), output, length); 
    delete[] output;
}