Skip to content

"add unsigned to attribute map" #3623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions paddle/framework/attribute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ AttrType AttrTypeID<int>() {
return INT;
}
template <>
AttrType AttrTypeID<unsigned>() {
return INT;
}
template <>
AttrType AttrTypeID<float>() {
return FLOAT;
}
Expand Down
5 changes: 3 additions & 2 deletions paddle/framework/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ limitations under the License. */
namespace paddle {
namespace framework {

typedef boost::variant<boost::blank, int, float, std::string, std::vector<int>,
std::vector<float>, std::vector<std::string>>
typedef boost::variant<boost::blank, int, unsigned, float, std::string,
std::vector<int>, std::vector<float>,
std::vector<std::string>>
Attribute;

typedef std::unordered_map<std::string, Attribute> AttributeMap;
Expand Down
9 changes: 4 additions & 5 deletions paddle/operators/gaussian_random_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class CPUGaussianRandomKernel : public framework::OpKernel {
auto* tensor = context.Output<framework::Tensor>("Out");
T* data = tensor->mutable_data<T>(context.GetPlace());

unsigned int seed =
static_cast<unsigned int>(context.op_.GetAttr<int>("seed"));
unsigned int seed = context.op_.GetAttr<int>("seed");
std::minstd_rand engine;
if (seed == 0) {
seed = std::random_device()();
Expand Down Expand Up @@ -67,9 +66,9 @@ Use to initialize tensor with gaussian random generator.
AddAttr<std::vector<int>>("dims", "The dimension of random tensor.");
AddAttr<float>("mean", "mean of random tensor.").SetDefault(.0f);
AddAttr<float>("std", "std of random tensor.").SetDefault(1.0f);
AddAttr<int>("seed",
"Random seed of generator."
"0 means use system wide seed")
AddAttr<unsigned>("seed",
"Random seed of generator."
"0 means use system wide seed")
.SetDefault(0);
}
};
Expand Down
9 changes: 4 additions & 5 deletions paddle/operators/uniform_random_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class CPUUniformRandomKernel : public framework::OpKernel {
void Compute(const framework::ExecutionContext& context) const override {
auto* tensor = context.Output<framework::Tensor>("Out");
T* data = tensor->mutable_data<T>(context.GetPlace());
unsigned int seed =
static_cast<unsigned int>(context.op_.GetAttr<int>("seed"));
unsigned int seed = context.op_.GetAttr<int>("seed");
std::minstd_rand engine;
if (seed == 0) {
seed = std::random_device()();
Expand Down Expand Up @@ -69,9 +68,9 @@ Used to initialize tensor with uniform random generator.
AddAttr<std::vector<int>>("dims", "the dimension of random tensor");
AddAttr<float>("min", "Minimum value of uniform random").SetDefault(-1.0f);
AddAttr<float>("max", "Maximun value of uniform random").SetDefault(1.0f);
AddAttr<int>("seed",
"Random seed of uniform random. "
"0 means generate a seed by system")
AddAttr<unsigned>("seed",
"Random seed of uniform random. "
"0 means generate a seed by system")
.SetDefault(0);
}
};
Expand Down