This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[NumPy] add op random.laplace #17316
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
585b238
NumPy Laplace Distribution partly Frontend and Backend
AntiZpvoh 2de8ac4
NumPy Laplace Distribution Backend style rectified
AntiZpvoh b789cd7
NumPy Laplace Distribution Frontend modified
AntiZpvoh 97a5d35
Laplece op nightly test and normal op test correction
AntiZpvoh 94087e6
NumPy Laplace Distribution unit test and code style
AntiZpvoh eec4ec2
Register uniform_n in CUDA
AntiZpvoh 14dd8b2
Delete the registering of Laplace_n
AntiZpvoh 96c9130
fix some alignment and indentation problems
AntiZpvoh f0f6535
merge with upstream master
AntiZpvoh 48cc7d3
fix some sanity problems such as too long lines
AntiZpvoh 2d9a72c
fix some sanity problems again
AntiZpvoh 6a79e2f
merge with upstream master
AntiZpvoh 2302afa
merge with upstream master
AntiZpvoh c89f1f5
merge with upstream
AntiZpvoh de61812
laplace parmeters form change
AntiZpvoh 5e14d39
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
AntiZpvoh 115cc41
implement basic laplace function
AntiZpvoh 29b0034
add frontend implement and ndarray loc case
AntiZpvoh d1e968b
complete the frontend
AntiZpvoh a849e94
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
AntiZpvoh 4a62caa
fix some sanity problems
AntiZpvoh 20c05c1
fix some sanity problems
AntiZpvoh b52931f
fix some typos
AntiZpvoh 336cd9f
fix some problems
AntiZpvoh 1e871ce
fix a typo
AntiZpvoh 99e60cb
Merge branch 'NumPyLaplaceOp' of https://github.com/AntiZpvoh/incubat…
AntiZpvoh c115c73
add size==() condition handling
AntiZpvoh fe998f6
Merge branch 'master' of https://github.com/apache/incubator-mxnet in…
AntiZpvoh 670e0ad
Merge branch 'NumPyLaplaceOp' of https://github.com/AntiZpvoh/incubat…
AntiZpvoh befba1e
fix some typos
5dc7075
remove unused code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* \file np_laplace_op.cc | ||
* \brief Implementation of the API of functions in src/operator/numpy/np_laplace_op.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../../utils.h" | ||
#include "../../../../operator/numpy/random/np_laplace_op.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.laplace") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_laplace"); | ||
nnvm::NodeAttrs attrs; | ||
op::NumpyLaplaceParam param; | ||
|
||
NDArray** inputs = new NDArray*[2](); | ||
int num_inputs = 0; | ||
|
||
if (args[0].type_code() == kNull) { | ||
param.loc = dmlc::nullopt; | ||
} else if (args[0].type_code() == kNDArrayHandle) { | ||
param.loc = dmlc::nullopt; | ||
inputs[num_inputs] = args[0].operator mxnet::NDArray *(); | ||
num_inputs++; | ||
} else { | ||
param.loc = args[0].operator double(); // convert arg to T | ||
} | ||
|
||
if (args[1].type_code() == kNull) { | ||
param.scale = dmlc::nullopt; | ||
} else if (args[1].type_code() == kNDArrayHandle) { | ||
param.scale = dmlc::nullopt; | ||
inputs[num_inputs] = args[1].operator mxnet::NDArray *(); | ||
num_inputs++; | ||
} else { | ||
param.scale = args[1].operator double(); // convert arg to T | ||
} | ||
|
||
if (args[2].type_code() == kNull) { | ||
param.size = dmlc::nullopt; | ||
} else { | ||
if (args[2].type_code() == kDLInt) { | ||
param.size = mxnet::Tuple<int>(1, args[2].operator int64_t()); | ||
} else { | ||
param.size = mxnet::Tuple<int>(args[2].operator ObjectRef()); | ||
} | ||
} | ||
|
||
if (args[3].type_code() == kNull) { | ||
param.dtype = mshadow::kFloat32; | ||
} else { | ||
param.dtype = String2MXNetTypeWithBool(args[3].operator std::string()); | ||
} | ||
attrs.parsed = std::move(param); | ||
attrs.op = op; | ||
SetAttrDict<op::NumpyLaplaceParam>(&attrs); | ||
if (args[4].type_code() != kNull) { | ||
attrs.dict["ctx"] = args[4].operator std::string(); | ||
} | ||
|
||
inputs = inputs == nullptr ? nullptr : inputs; | ||
|
||
NDArray* out = args[5].operator mxnet::NDArray*(); | ||
NDArray** outputs = out == nullptr ? nullptr : &out; | ||
int num_outputs = out != nullptr; | ||
auto ndoutputs = Invoke(op, &attrs, num_inputs, inputs, &num_outputs, outputs); | ||
if (out) { | ||
*ret = PythonArg(5); | ||
} else { | ||
*ret = ndoutputs[0]; | ||
} | ||
}); | ||
|
||
} // namespace mxnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* Copyright (c) 2019 by Contributors | ||
* \file np_laplace_op.cc | ||
* \brief Operator for numpy sampling from Laplace distributions | ||
*/ | ||
#include "./np_laplace_op.h" | ||
|
||
namespace mxnet { | ||
namespace op { | ||
|
||
DMLC_REGISTER_PARAMETER(NumpyLaplaceParam); | ||
|
||
NNVM_REGISTER_OP(_npi_laplace) | ||
.describe("numpy behavior Laplace") | ||
.set_num_inputs( | ||
[](const nnvm::NodeAttrs& attrs) { | ||
const NumpyLaplaceParam& param = nnvm::get<NumpyLaplaceParam>(attrs.parsed); | ||
int num_inputs = 2; | ||
if (param.loc.has_value()) num_inputs -= 1; | ||
if (param.scale.has_value()) num_inputs -= 1; | ||
return num_inputs; | ||
} | ||
) | ||
.set_num_outputs(1) | ||
.set_attr<nnvm::FListInputNames>("FListInputNames", | ||
[](const NodeAttrs& attrs) { | ||
const NumpyLaplaceParam& param = nnvm::get<NumpyLaplaceParam>(attrs.parsed); | ||
int num_inputs = 2; | ||
if (param.loc.has_value()) num_inputs -= 1; | ||
if (param.scale.has_value()) num_inputs -= 1; | ||
if (num_inputs == 0) return std::vector<std::string>(); | ||
if (num_inputs == 1) return std::vector<std::string>{"input1"}; | ||
return std::vector<std::string>{"input1", "input2"}; | ||
}) | ||
.set_attr_parser(ParamParser<NumpyLaplaceParam>) | ||
.set_attr<mxnet::FInferShape>("FInferShape", TwoparamsDistOpShape<NumpyLaplaceParam>) | ||
.set_attr<nnvm::FInferType>("FInferType", NumpyLaplaceOpType) | ||
.set_attr<FResourceRequest>("FResourceRequest", | ||
[](const nnvm::NodeAttrs& attrs) { | ||
return std::vector<ResourceRequest>{ | ||
ResourceRequest::kRandom, ResourceRequest::kTempSpace}; | ||
}) | ||
.set_attr<FCompute>("FCompute<cpu>", NumpyLaplaceForward<cpu>) | ||
.set_attr<nnvm::FGradient>("FGradient", MakeZeroGradNodes) | ||
.add_argument("input1", "NDArray-or-Symbol", "Source input") | ||
.add_argument("input2", "NDArray-or-Symbol", "Source input") | ||
.add_arguments(NumpyLaplaceParam::__FIELDS__()); | ||
|
||
} // namespace op | ||
} // namespace mxnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/*! | ||
* Copyright (c) 2019 by Contributors | ||
* \file np_laplace_op.cu | ||
* \brief Operator for numpy sampling from Laplace distributions | ||
*/ | ||
|
||
#include "./np_laplace_op.h" | ||
|
||
namespace mxnet { | ||
namespace op { | ||
|
||
NNVM_REGISTER_OP(_npi_laplace) | ||
.set_attr<FCompute>("FCompute<gpu>", NumpyLaplaceForward<gpu>); | ||
|
||
} // namespace op | ||
} // namespace mxnet |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.