You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_iterator.py 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright 2019 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. import numpy as np
  16. import mindspore.dataset as ds
  17. DATA_DIR = ["../data/dataset/testTFTestAllTypes/test.data"]
  18. SCHEMA_DIR = "../data/dataset/testTFTestAllTypes/datasetSchema.json"
  19. COLUMNS = ["col_1d", "col_2d", "col_3d", "col_binary", "col_float",
  20. "col_sint16", "col_sint32", "col_sint64"]
  21. def check(project_columns):
  22. data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=COLUMNS)
  23. data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=project_columns)
  24. for data_actual, data_expected in zip(data1.create_tuple_iterator(project_columns), data2.create_tuple_iterator()):
  25. assert len(data_actual) == len(data_expected)
  26. assert all([np.array_equal(d1, d2) for d1, d2 in zip(data_actual, data_expected)])
  27. def test_case_iterator():
  28. """
  29. Test creating tuple iterator
  30. """
  31. check(COLUMNS)
  32. check(COLUMNS[0:1])
  33. check(COLUMNS[0:2])
  34. check(COLUMNS[0:7])
  35. check(COLUMNS[7:8])
  36. check(COLUMNS[0:2:8])

MindSpore is a new open source deep learning training/inference framework that could be used for mobile, edge and cloud scenarios.