MCPcopy Create free account
hub / github.com/alibaba/MNN / compareOutput

Function compareOutput

tools/converter/source/common/cli.cpp:679–756  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

677}
678
679static bool compareOutput(MNN::Express::VARP output, const std::string& directName, const std::string& name, MNN::Express::Dimensionformat dataFormat, int order, float maxError) {
680 if (output == nullptr) {
681 MNN_ERROR("TESTERROR name:%s, output is null.\n", name.c_str());
682 return false;
683 }
684 auto info = output->getInfo();
685 if (info && info->size <= 0) {
686 MNN_PRINT("skip checking value for zero content tensor %s\n", name.c_str());
687 return true;
688 }
689 std::ifstream outputOrigin;
690 // First find key
691 {
692 std::ostringstream outputFileOs;
693 outputFileOs << directName << "/" << name <<".txt";
694 outputOrigin.open(outputFileOs.str().c_str());
695 }
696 // Second find order
697 if (outputOrigin.fail()) {
698 std::ostringstream outputFileOs;
699 outputFileOs << directName << "/" << order <<".txt";
700 outputOrigin.open(outputFileOs.str().c_str());
701 }
702 if (outputOrigin.fail()) {
703 MNN_PRINT("Skip check %s\n", name.c_str());
704 return true;
705 }
706 if (nullptr == info) {
707 MNN_ERROR("TESTERROR name:%s, info is null.\n", name.c_str());
708 return false;
709 }
710 if (info->order == MNN::Express::NC4HW4 && info->dim.size() > 1) {
711 output = _Convert(output, dataFormat);
712 info = output->getInfo();
713 }
714 if (info->type.code != halide_type_float) {
715 output = MNN::Express::_Cast<float>(output);
716 info = output->getInfo();
717 }
718 auto ptr = output->readMap<float>();
719 if (nullptr == info || nullptr == ptr) {
720 MNN_ERROR("TESTERROR name:%s, info:%p, ptr:%p.\n", name.c_str(), info, ptr);
721 return false;
722 }
723 MNN_PRINT("%s: (", name.c_str());
724 for (int i=0; i<info->dim.size(); ++i) {
725 MNN_PRINT("%d, ", info->dim[i]);
726 }
727 MNN_PRINT(")\n");
728 auto targetValue = _Input({info->dim}, info->order, info->type);
729 auto targetPtr = targetValue->writeMap<float>();
730 for (int i=0; i<info->size; ++i) {
731 double tempValue;
732 outputOrigin >> tempValue;
733 targetPtr[i] = tempValue;
734 }
735
736 auto absMax = MNN::Express::_ReduceMax(MNN::Express::_Abs(targetValue), {});

Callers 1

testconvertMethod · 0.70

Calls 11

_ConvertFunction · 0.85
_InputFunction · 0.85
_ReduceMaxFunction · 0.85
_AbsFunction · 0.85
_MaximumFunction · 0.85
isnanFunction · 0.85
c_strMethod · 0.45
getInfoMethod · 0.45
openMethod · 0.45
strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected