FloorMod
场景说明
给出输入张量input,取模张量mod以及长度length,计算两个输入张量的逐元素模运算,将计算结果存储于输出张量output。例如:
1 2 3 4 | input: [5,7,15,7] mod: [8,6,20,3] output: [5,1,15,1] length: 4 |
代码示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #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; //调用FloorMod算子,结果存储于output数组,第一个参数及第二个参数均为数组 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; //输入空指针,打印日志"ERROR Parameter verification failed for the FloorMod Op." ret = FloorMod(static_cast<float *>(nullptr), mod, output, length); //输入空指针,打印日志"ERROR Parameter verification failed for the FloorMod Op." ret = FloorMod(input, mod, static_cast<float *>(nullptr), length); // right //调用FloorMod算子,结果存储于output数组,第一个参数为数组,第二个参数为一个元素 ret = FloorMod(input, mod[0], output, length); //输入空指针,打印日志"ERROR Parameter verification failed for the FloorMod Op." ret = FloorMod(static_cast<float *>(nullptr), mod[0], output, length); // left //调用FloorMod算子,结果存储于output数组,第一个参数为一个元素,第二个参数为数组 ret = FloorMod(input[0], mod, output, length); //输入空指针,打印日志"ERROR Parameter verification failed for the FloorMod Op." ret = FloorMod(input[0], static_cast<float *>(nullptr), output, length); delete[] output; } |
父主题: 使用示例