|
|
@ -14,9 +14,11 @@ limitations under the License. */
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
#include <sstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
#include "paddle/fluid/framework/data_type.h"
|
|
|
|
#include "paddle/fluid/framework/data_type.h"
|
|
|
|
#include "paddle/fluid/framework/op_registry.h"
|
|
|
|
#include "paddle/fluid/framework/op_registry.h"
|
|
|
|
#include "paddle/fluid/operators/math/math_function.h"
|
|
|
|
#include "paddle/fluid/operators/math/math_function.h"
|
|
|
@ -45,15 +47,22 @@ class FillConstantKernel : public framework::OpKernel<T> {
|
|
|
|
if (str_value.empty()) {
|
|
|
|
if (str_value.empty()) {
|
|
|
|
value = static_cast<T>(float_value);
|
|
|
|
value = static_cast<T>(float_value);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
std::stringstream convert_stream(str_value);
|
|
|
|
// handle NaN/Inf first, which cannot be read from stream.
|
|
|
|
if (std::is_same<int64_t, T>::value) {
|
|
|
|
if (str_value == "inf") {
|
|
|
|
int64_t tmp_value;
|
|
|
|
value = static_cast<T>(std::numeric_limits<double>::infinity());
|
|
|
|
convert_stream >> tmp_value;
|
|
|
|
} else if (str_value == "nan") {
|
|
|
|
value = static_cast<T>(tmp_value);
|
|
|
|
value = static_cast<T>(std::numeric_limits<double>::quiet_NaN());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
double tmp_value;
|
|
|
|
std::stringstream convert_stream(str_value);
|
|
|
|
convert_stream >> tmp_value;
|
|
|
|
if (std::is_same<int64_t, T>::value) {
|
|
|
|
value = static_cast<T>(tmp_value);
|
|
|
|
int64_t tmp_value;
|
|
|
|
|
|
|
|
convert_stream >> tmp_value;
|
|
|
|
|
|
|
|
value = static_cast<T>(tmp_value);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
double tmp_value;
|
|
|
|
|
|
|
|
convert_stream >> tmp_value;
|
|
|
|
|
|
|
|
value = static_cast<T>(tmp_value);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ctx.HasInput("ValueTensor")) {
|
|
|
|
if (ctx.HasInput("ValueTensor")) {
|
|
|
|