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

Commit

Permalink
Refactor according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
meta-project-ci committed Feb 23, 2020
1 parent be7db15 commit d29bb7d
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 206 deletions.
4 changes: 2 additions & 2 deletions include/mxnet/runtime/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ class ADTObj : public Object, public InplaceArrayBase<ADTObj, ObjectRef> {
uint32_t size{0};
// The fields of the structure follows directly in memory.

static constexpr const uint32_t _type_index = TypeIndex::kVMADT;
static constexpr const char* _type_key = "vm.ADT";
static constexpr const uint32_t _type_index = TypeIndex::kMXNetADT;
static constexpr const char* _type_key = "MXNet.ADT";
MXNET_DECLARE_FINAL_OBJECT_INFO(ADTObj, Object);

private:
Expand Down
6 changes: 3 additions & 3 deletions include/mxnet/runtime/ffi_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace runtime {
class EllipsisObj : public Object {
public:
static constexpr const uint32_t _type_index = TypeIndex::kEllipsis;
static constexpr const char* _type_key = "vm.Ellipsis";
static constexpr const char* _type_key = "MXNet.Ellipsis";
MXNET_DECLARE_FINAL_OBJECT_INFO(EllipsisObj, Object);
};

Expand All @@ -53,7 +53,7 @@ class SliceObj : public Object {
int64_t step;

static constexpr const uint32_t _type_index = TypeIndex::kSlice;
static constexpr const char* _type_key = "vm.Slice";
static constexpr const char* _type_key = "MXNet.Slice";
MXNET_DECLARE_FINAL_OBJECT_INFO(SliceObj, Object);
};

Expand Down Expand Up @@ -85,7 +85,7 @@ class IntegerObj: public Object {
public:
int64_t value;
static constexpr const uint32_t _type_index = TypeIndex::kInteger;
static constexpr const char* _type_key = "vm.Integer";
static constexpr const char* _type_key = "MXNet.Integer";
MXNET_DECLARE_FINAL_OBJECT_INFO(IntegerObj, Object);
};

Expand Down
6 changes: 3 additions & 3 deletions include/mxnet/runtime/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ namespace runtime {
enum TypeIndex {
/*! \brief Root object type. */
kRoot = 0,
kVMTensor = 1,
kVMClosure = 2,
kVMADT = 3,
kMXNetTensor = 1,
kMXNetClosure = 2,
kMXNetADT = 3,
kRuntimeModule = 4,
kEllipsis = 5,
kSlice = 6,
Expand Down
4 changes: 2 additions & 2 deletions python/mxnet/_ffi/_ctypes/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class TypeCode(object):
FLOAT = 2
HANDLE = 3
NULL = 4
TVM_TYPE = 5
TVM_CONTEXT = 6
MXNET_TYPE = 5
MXNET_CONTEXT = 6
ARRAY_HANDLE = 7
OBJECT_HANDLE = 8
MODULE_HANDLE = 9
Expand Down
13 changes: 3 additions & 10 deletions python/mxnet/ndarray/numpy/_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'equal', 'not_equal', 'greater', 'less', 'greater_equal', 'less_equal', 'rot90', 'einsum',
'true_divide', 'nonzero', 'quantile', 'percentile', 'shares_memory', 'may_share_memory',
'diff', 'resize', 'polyval', 'nan_to_num', 'isnan', 'isinf', 'isposinf', 'isneginf', 'isfinite',
'where', 'bincount', 'pad', 'nop']
'where', 'bincount', 'pad']


@set_module('mxnet.ndarray.numpy')
Expand Down Expand Up @@ -111,6 +111,8 @@ def zeros(shape, dtype=None, order='C', ctx=None): # pylint: disable=redefined-
"""
if order != 'C':
raise NotImplementedError
# If the following code (4 lines) regarding ctx is removed
# np.zeros((3, 4)) can be as fast as 4.96 us
if ctx is None:
ctx = str(current_context())
else:
Expand Down Expand Up @@ -7480,12 +7482,3 @@ def pad(x, pad_width, mode='constant', **kwargs): # pylint: disable=too-many-arg
raise ValueError("unsupported stat_length '{}'".format(values))
return _npi.pad(x, pad_width, mode='minimum')
return _npi.pad(x, pad_width, mode='constant', constant_value=0)


@set_module('mxnet.ndarray.numpy')
def nop(*args):
r"""
nop(*args)
A dummy function for FFI test.
"""
return _api_internal.nop(*args)
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

/*!
* Implementation of API functions related to Higher DSL build.
* \file api_lang.cc
* \file _api_internal.cc
* \brief Internal functions exposed to python for FFI use only
*/
// Acknowledgement: This file originates from incubator-tvm
#include <mxnet/api_registry.h>
Expand All @@ -30,7 +30,6 @@
#include <mxnet/runtime/container.h>
#include <mxnet/runtime/ffi_helper.h>
#include <nnvm/c_api.h>
#include <iostream>

namespace mxnet {

Expand Down Expand Up @@ -58,4 +57,8 @@ MXNET_REGISTER_GLOBAL("_ADT")
*ret = ADT(0, data.begin(), data.end());
});

MXNET_REGISTER_API("_nop")
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
});

} // namespace mxnet
181 changes: 0 additions & 181 deletions src/api/api_npi.cc

This file was deleted.

55 changes: 55 additions & 0 deletions src/api/operator/numpy/np_init_op.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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_init_op.cc
* \brief Implementation of the API of functions in src/operator/numpy/np_init_op.cc
*/
#include "../utils.h"
#include "../../../operator/tensor/init_op.h"

namespace mxnet {

MXNET_REGISTER_API("_npi.zeros")
.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
using namespace runtime;
const nnvm::Op* op = Op::Get("_npi_zeros");
nnvm::NodeAttrs attrs;
op::InitOpParam param;
if (args[0].type_code() == kDLInt) {
param.shape = TShape(1, args[0].operator int64_t());
} else {
param.shape = TShape(args[0].operator ObjectRef());
}
if (args[1].type_code() == kNull) {
param.dtype = mshadow::kFloat32;
} else {
param.dtype = String2MXNetTypeWithBool(args[1].operator std::string());
}
attrs.parsed = std::move(param);
attrs.op = op;
if (args[2].type_code() != kNull) {
attrs.dict["ctx"] = args[2].operator std::string();
}
int num_outputs = 0;
auto ndoutputs = Invoke<op::InitOpParam>(op, &attrs, 0, nullptr, &num_outputs, nullptr);
*ret = ndoutputs[0];
});

} // namespace mxnet
Loading

0 comments on commit d29bb7d

Please sign in to comment.