Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
* Impl FFI
Browse files Browse the repository at this point in the history
  • Loading branch information
hanke580 committed Mar 10, 2020
1 parent 1084ab5 commit 4061f24
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
14 changes: 9 additions & 5 deletions python/mxnet/ndarray/numpy/_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,8 +1189,9 @@ def fmod(x1, x2, out=None, **kwargs):
out : ndarray or scalar
This is a scalar if both x1 and x2 are scalars.
"""
return _ufunc_helper(x1, x2, _npi.fmod, _np.fmod, _npi.fmod_scalar, _npi.rfmod_scalar, out)

if isinstance(x1, numeric_types) and isinstance(x2, numeric_types):
_np.fmod(x1, x2, out=out)
return _api_internal.fmod(x1, x2, out)

@set_module('mxnet.ndarray.numpy')
def delete(arr, obj, axis=None):
Expand Down Expand Up @@ -4307,8 +4308,9 @@ def fmax(x1, x2, out=None, **kwargs):
-------
out : mxnet.numpy.ndarray or scalar
The maximum of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars."""
return _ufunc_helper(x1, x2, _npi.fmax, _np.fmax, _npi.fmax_scalar, None, out)

if isinstance(x1, numeric_types) and isinstance(x2, numeric_types):
_np.fmax(x1, x2, out=out)
return _api_internal.fmax(x1, x2, out)

@set_module('mxnet.ndarray.numpy')
@wrap_np_binary_func
Expand Down Expand Up @@ -4345,7 +4347,9 @@ def fmin(x1, x2, out=None, **kwargs):
-------
out : mxnet.numpy.ndarray or scalar
The minimum of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars."""
return _ufunc_helper(x1, x2, _npi.fmin, _np.fmin, _npi.fmin_scalar, None, out)
if isinstance(x1, numeric_types) and isinstance(x2, numeric_types):
_np.fmin(x1, x2, out=out)
return _api_internal.fmin(x1, x2, out)


@set_module('mxnet.ndarray.numpy')
Expand Down
56 changes: 56 additions & 0 deletions src/api/operator/numpy/np_elemwise_broadcast_op_extended.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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_op_extended.cc
* \brief Implementation of the API of functions in src/operator/numpy/np_elemwise_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.fmax")
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
using namespace runtime;
const nnvm::Op* op = Op::Get("_npi_fmax");
const nnvm::Op* op_scalar = Op::Get("_npi_fmax_scalar");
UFuncHelper(args, ret, op, op_scalar, nullptr);
});

MXNET_REGISTER_API("_npi.fmin")
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
using namespace runtime;
const nnvm::Op* op = Op::Get("_npi_fmin");
const nnvm::Op* op_scalar = Op::Get("_npi_fmin_scalar");
UFuncHelper(args, ret, op, op_scalar, nullptr);
});

MXNET_REGISTER_API("_npi.fmod")
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
using namespace runtime;
const nnvm::Op* op = Op::Get("_npi_fmod");
const nnvm::Op* op_scalar = Op::Get("_npi_fmod_scalar");
const nnvm::Op* op_rscalar = Op::Get("_npi_rfmod_scalar");
UFuncHelper(args, ret, op, op_scalar, op_rscalar);
});

} // namespace mxnet

0 comments on commit 4061f24

Please sign in to comment.