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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Numpy] FFI: random.shuffle, equal, not_equal, less_equal, greater_eq…
…ual, less, maximum and minimum (#17896) * add random.shuffle, equal, not_equal, less_equal, greater_equal, less, maximum and minimum ffi and benchmark * fix the implementation of binary ops * fix some code logic issues (non-commutative) Co-authored-by: Hao Jin <[email protected]>
- Loading branch information
Showing
6 changed files
with
210 additions
and
10 deletions.
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,74 @@ | ||
/* | ||
* 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_elemwise_broadcast_logic_op.cc | ||
* \brief Implementation of the API of functions in src/operator/numpy/np_elemwise_broadcast_logic_op.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../utils.h" | ||
#include "../ufunc_helper.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.equal") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_equal"); | ||
const nnvm::Op* op_scalar = Op::Get("_npi_equal_scalar"); | ||
UFuncHelper(args, ret, op, op_scalar, nullptr); | ||
}); | ||
|
||
MXNET_REGISTER_API("_npi.not_equal") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_not_equal"); | ||
const nnvm::Op* op_scalar = Op::Get("_npi_not_equal_scalar"); | ||
UFuncHelper(args, ret, op, op_scalar, nullptr); | ||
}); | ||
|
||
MXNET_REGISTER_API("_npi.less") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_less"); | ||
const nnvm::Op* op_scalar = Op::Get("_npi_less_scalar"); | ||
const nnvm::Op* op_rscalar = Op::Get("_npi_less_scalar"); | ||
UFuncHelper(args, ret, op, op_scalar, op_rscalar); | ||
}); | ||
|
||
MXNET_REGISTER_API("_npi.greater_equal") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_greater_equal"); | ||
const nnvm::Op* op_scalar = Op::Get("_npi_greater_equal_scalar"); | ||
const nnvm::Op* op_rscalar = Op::Get("_npi_greater_equal_scalar"); | ||
UFuncHelper(args, ret, op, op_scalar, op_rscalar); | ||
}); | ||
|
||
MXNET_REGISTER_API("_npi.less_equal") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_less_equal"); | ||
const nnvm::Op* op_scalar = Op::Get("_npi_less_equal_scalar"); | ||
const nnvm::Op* op_rscalar = Op::Get("_npi_less_equal_scalar"); | ||
UFuncHelper(args, ret, op, op_scalar, op_rscalar); | ||
}); | ||
|
||
} // 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,57 @@ | ||
/* | ||
* 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 shuffle_op.cc | ||
* \brief Implementation of the API of functions in src/operator/random/shuffle_op.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../utils.h" | ||
#include "../../../operator/elemwise_op_common.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.shuffle") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_shuffle"); | ||
nnvm::NodeAttrs attrs; | ||
|
||
NDArray* inputs[1]; | ||
int num_inputs = 1; | ||
|
||
if (args[0].type_code() != kNull) { | ||
inputs[0] = args[0].operator mxnet::NDArray *(); | ||
} | ||
|
||
attrs.op = op; | ||
|
||
NDArray* out = args[1].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(1); | ||
} else { | ||
*ret = ndoutputs[0]; | ||
} | ||
}); | ||
|
||
} // namespace mxnet |
47 changes: 47 additions & 0 deletions
47
src/api/operator/tensor/elemwise_binary_broadcast_op_extended.cc
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,47 @@ | ||
/* | ||
* 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 elemwise_binary_broadcast_op_extended.cc | ||
* \brief Implementation of the API of functions in src/operator/tensor/elemwise_binary_broadcast_op_extended.cc | ||
*/ | ||
#include <mxnet/api_registry.h> | ||
#include <mxnet/runtime/packed_func.h> | ||
#include "../utils.h" | ||
#include "../ufunc_helper.h" | ||
|
||
namespace mxnet { | ||
|
||
MXNET_REGISTER_API("_npi.maximum") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_maximum"); | ||
const nnvm::Op* op_scalar = Op::Get("_npi_maximum_scalar"); | ||
UFuncHelper(args, ret, op, op_scalar, nullptr); | ||
}); | ||
|
||
MXNET_REGISTER_API("_npi.minimum") | ||
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) { | ||
using namespace runtime; | ||
const nnvm::Op* op = Op::Get("_npi_minimum"); | ||
const nnvm::Op* op_scalar = Op::Get("_npi_minimum_scalar"); | ||
UFuncHelper(args, ret, op, op_scalar, nullptr); | ||
}); | ||
|
||
} // namespace mxnet |