|
|
@ -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"
|
|
|
@ -44,6 +46,12 @@ class FillConstantKernel : public framework::OpKernel<T> {
|
|
|
|
T value;
|
|
|
|
T value;
|
|
|
|
if (str_value.empty()) {
|
|
|
|
if (str_value.empty()) {
|
|
|
|
value = static_cast<T>(float_value);
|
|
|
|
value = static_cast<T>(float_value);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// handle NaN/Inf first, which cannot be read from stream.
|
|
|
|
|
|
|
|
if (str_value == "inf") {
|
|
|
|
|
|
|
|
value = static_cast<T>(std::numeric_limits<double>::infinity());
|
|
|
|
|
|
|
|
} else if (str_value == "nan") {
|
|
|
|
|
|
|
|
value = static_cast<T>(std::numeric_limits<double>::quiet_NaN());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
std::stringstream convert_stream(str_value);
|
|
|
|
std::stringstream convert_stream(str_value);
|
|
|
|
if (std::is_same<int64_t, T>::value) {
|
|
|
|
if (std::is_same<int64_t, T>::value) {
|
|
|
@ -56,6 +64,7 @@ class FillConstantKernel : public framework::OpKernel<T> {
|
|
|
|
value = static_cast<T>(tmp_value);
|
|
|
|
value = static_cast<T>(tmp_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (ctx.HasInput("ValueTensor")) {
|
|
|
|
if (ctx.HasInput("ValueTensor")) {
|
|
|
|
auto *value_tensor = ctx.Input<framework::Tensor>("ValueTensor");
|
|
|
|
auto *value_tensor = ctx.Input<framework::Tensor>("ValueTensor");
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|