Use `object` instead of `np.object` and `str` instead of `np.str`. (#337)

This commit is contained in:
Edward Chen 2022-12-19 15:45:07 -08:00 коммит произвёл GitHub
Родитель 1d8d4b1fa4
Коммит 280ec289cb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 22 добавлений и 21 удалений

Просмотреть файл

@ -102,7 +102,7 @@ node = onnx.helper.make_node(
)
text = "Hello world louder"
inputs = np.array([text], dtype=np.object),
inputs = np.array([text], dtype=object),
bert_tokenize_result = bert_cased_tokenizer.tokenize(text)
@ -207,7 +207,7 @@ node = onnx.helper.make_node(
)
text = "Hello world louder"
token_ids = np.array([bert_cased_tokenizer.tokenize(text)], dtype=np.object),
token_ids = np.array([bert_cased_tokenizer.tokenize(text)], dtype=object),
sentences = np.array(text)
@ -383,7 +383,7 @@ graph = helper.make_graph(
model = helper.make_model(
graph, opset_imports=[helper.make_operatorsetid(domain, 1)])
text = np.array(["unwanted running", "unwantedX running"], dtype=np.object)
text = np.array(["unwanted running", "unwantedX running"], dtype=object)
tokens = np.array(['un', '##want', '##ed', 'runn', '##ing', 'un', '##want', '##ed',
'[UNK]', 'runn', '##ing'], dtype=object),
indices = np.array([14, 11, 12, 15, 16, 14, 11, 12, -1, 15, 16], dtype=int32)
@ -452,7 +452,7 @@ node = onnx.helper.make_node(
model=model
)
inputs = np.array(["Hello world", "Hello world louder"], dtype=np.object),
inputs = np.array(["Hello world", "Hello world louder"], dtype=object),
nbest_size = np.array([0], dtype=np.float32),
alpha = np.array([0], dtype=np.float32),
add_bos = np.array([0], dtype=np.bool_),
@ -521,7 +521,7 @@ node = onnx.helper.make_node(
outputs=['tokens'],
)
inputs = np.array([ "Hello world louder"], dtype=np.object),
inputs = np.array([ "Hello world louder"], dtype=object),
tokens = np.array(tokenizer(inputs), dtype=int32)
expect(node, inputs=[inputs],

Просмотреть файл

@ -147,7 +147,7 @@ class TestPythonOp(unittest.TestCase):
res = []
for x in xs:
res.append(sep.join(x))
return np.array(res, dtype=np.object)
return np.array(res, dtype=object)
def test_python_operator(self):
so = _ort.SessionOptions()
@ -222,9 +222,9 @@ class TestPythonOp(unittest.TestCase):
onnx_model = _create_test_join()
self.assertIn('op_type: "PyOpJoin"', str(onnx_model))
sess = _ort.InferenceSession(onnx_model.SerializeToString(), so)
arr = np.array([["a", "b"]], dtype=np.object)
arr = np.array([["a", "b"]], dtype=object)
txout = sess.run(None, {'input_1': arr})
exp = np.array(["a;b"], dtype=np.object)
exp = np.array(["a;b"], dtype=object)
assert txout[0][0] == exp[0]

Просмотреть файл

@ -298,7 +298,7 @@ class TestPythonOpSentencePiece(unittest.TestCase):
inputs = dict(
model=model,
inputs=np.array(
["Hello world", "Hello world louder"], dtype=np.object),
["Hello world", "Hello world louder"], dtype=object),
nbest_size=np.array([0], dtype=np.int64),
alpha=np.array([0], dtype=np.float32),
add_bos=np.array([0], dtype=np.bool_),
@ -321,7 +321,7 @@ class TestPythonOpSentencePiece(unittest.TestCase):
inputs = dict(
model=model,
inputs=np.array(
["Hello world", "Hello world louder"], dtype=np.object),
["Hello world", "Hello world louder"], dtype=object),
nbest_size=np.array([0], dtype=np.int64),
alpha=np.array([0], dtype=np.float32),
add_bos=np.array([0], dtype=np.bool_),
@ -346,7 +346,7 @@ class TestPythonOpSentencePiece(unittest.TestCase):
inputs = dict(
model=model,
inputs=np.array(
["Hello world", "Hello world louder"], dtype=np.object),
["Hello world", "Hello world louder"], dtype=object),
nbest_size=np.array([0], dtype=np.int64),
alpha=np.array([0], dtype=np.float32),
add_bos=np.array([0], dtype=np.bool_),
@ -380,7 +380,7 @@ class TestPythonOpSentencePiece(unittest.TestCase):
model=model,
inputs=np.array(
["Hello world", "Hello world louder"],
dtype=np.object),
dtype=object),
nbest_size=np.array(
[nbest_size], dtype=np.int64),
alpha=np.array([alpha], dtype=np.float32),
@ -415,7 +415,7 @@ class TestPythonOpSentencePiece(unittest.TestCase):
model=model,
inputs=np.array(
["Hello world", "Hello world louder"],
dtype=np.object),
dtype=object),
nbest_size=np.array(
[nbest_size], dtype=np.int64),
alpha=np.array([alpha], dtype=np.float32),

Просмотреть файл

@ -830,19 +830,19 @@ class TestPythonOpString(unittest.TestCase):
def enumerate_matrix_couples(self):
for i in range(1, 5):
shape = (3,) * i
a = (np.random.rand(*shape) * 10).astype(np.int32).astype(np.str)
a = (np.random.rand(*shape) * 10).astype(np.int32).astype(str)
yield a, a
for j in range(i):
shape2 = list(shape)
shape2[j] = 1
b = (np.random.rand(*shape2) * 10).astype(
np.int32).astype(np.str)
np.int32).astype(str)
yield a, b
for k in range(j+1, i):
shape3 = list(shape2)
shape3[k] = 1
b = (np.random.rand(*shape3) * 10).astype(
np.int32).astype(np.str)
np.int32).astype(str)
yield a, b
def test_string_equal_python(self):
@ -1117,7 +1117,7 @@ class TestPythonOpString(unittest.TestCase):
cc_sess = _ort.InferenceSession(cc_onnx_model.SerializeToString(), so)
inputs = dict(text=np.array(["unwanted running",
"unwantedX running"], dtype=np.object))
"unwantedX running"], dtype=object))
cc_txout = cc_sess.run(None, inputs)
exp = [np.array(['un', '##want', '##ed', 'runn', '##ing',
'un', '##want', '##ed', '[UNK]', 'runn', '##ing']),

Просмотреть файл

@ -365,7 +365,7 @@
" for a in list(node.attr.keys()):\n",
" del node.attr[a]\n",
" # Add the separator as an additional string input\n",
" separator_const = ctx.make_const(utils.make_name('separator_const'), np.array([separator], dtype=np.object))\n",
" separator_const = ctx.make_const(utils.make_name('separator_const'), np.array([separator], dtype=object))\n",
" ctx.replace_inputs(node, node.input + [separator_const.output[0]])"
],
"cell_type": "code",
@ -459,7 +459,7 @@
" outputs=[PyCustomOpDef.dt_string])\n",
"def unsorted_segment_join(x, segment_ids, num_segments):\n",
" # The custom op implementation.\n",
" result = np.full([num_segments], '', dtype=np.object)\n",
" result = np.full([num_segments], '', dtype=object)\n",
" for s, seg_id in zip(x, segment_ids):\n",
" result[seg_id] += s\n",
" return result\n",
@ -473,7 +473,7 @@
" for s, seg_id in zip(x, segment_ids):\n",
" result[seg_id].append(s)\n",
" result_joined = [separator.join(l) for l in result]\n",
" return np.array(result_joined, dtype=np.object)"
" return np.array(result_joined, dtype=object)"
]
},
{
@ -485,7 +485,8 @@
"output_type": "stream",
"name": "stdout",
"text": [
"[array(['javascript', 'carpet'], dtype=object)]\n[array(['java-script', 'car-pet'], dtype=object)]\n"
"[array(['javascript', 'carpet'], dtype=object)]\n",
"[array(['java-script', 'car-pet'], dtype=object)]\n"
]
}
],