Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui committed Feb 12, 2025
1 parent f0b2c3d commit b11db18
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tools/pnnx/src/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2255,11 +2255,17 @@ int Graph::python(const std::string& pypath, const std::string& pnnxbinpath)
{
if (op->type == "Tensor.index_put" && it.first == "values")
{
fprintf(pyfp, "torch.tensor(%g)", param.f);
if (param.f == (int)param.f)
fprintf(pyfp, "torch.tensor(%.1f)", param.f);
else
fprintf(pyfp, "torch.tensor(%g)", param.f);
}
else
{
fprintf(pyfp, "%g", param.f);
if (param.f == (int)param.f)
fprintf(pyfp, "%.1f", param.f);
else
fprintf(pyfp, "%g", param.f);
}
}
if (param.type == 4)
Expand Down Expand Up @@ -2318,7 +2324,10 @@ int Graph::python(const std::string& pypath, const std::string& pnnxbinpath)
fprintf(pyfp, "(");
for (size_t i = 0; i < param.af.size(); i++)
{
fprintf(pyfp, "%g", param.af[i]);
if (param.af[i] == (int)param.af[i])
fprintf(pyfp, "%.1f", param.af[i]);
else
fprintf(pyfp, "%g", param.af[i]);
if (i + 1 != param.af.size() || param.af.size() == 1)
fprintf(pyfp, ",");
}
Expand Down

0 comments on commit b11db18

Please sign in to comment.