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.

node.h 3.1 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_NODE_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_NODE_H_
  18. #include <memory>
  19. #include <unordered_map>
  20. #include <vector>
  21. #include "minddata/dataset/engine/gnn/feature.h"
  22. #include "minddata/dataset/util/status.h"
  23. namespace mindspore {
  24. namespace dataset {
  25. namespace gnn {
  26. using NodeType = int8_t;
  27. using NodeIdType = int32_t;
  28. constexpr NodeIdType kDefaultNodeId = -1;
  29. class Node {
  30. public:
  31. // Constructor
  32. // @param NodeIdType id - node id
  33. // @param NodeType type - node type
  34. Node(NodeIdType id, NodeType type) : id_(id), type_(type) {}
  35. virtual ~Node() = default;
  36. // @return NodeIdType - Returned node id
  37. NodeIdType id() const { return id_; }
  38. // @return NodeIdType - Returned node type
  39. NodeType type() const { return type_; }
  40. // Get the feature of a node
  41. // @param FeatureType feature_type - type of feature
  42. // @param std::shared_ptr<Feature> *out_feature - Returned feature
  43. // @return Status - The error code return
  44. virtual Status GetFeatures(FeatureType feature_type, std::shared_ptr<Feature> *out_feature) = 0;
  45. // Get the all neighbors of a node
  46. // @param NodeType neighbor_type - type of neighbor
  47. // @param std::vector<NodeIdType> *out_neighbors - Returned neighbors id
  48. // @return Status - The error code return
  49. virtual Status GetAllNeighbors(NodeType neighbor_type, std::vector<NodeIdType> *out_neighbors,
  50. bool exclude_itself = false) = 0;
  51. // Get the sampled neighbors of a node
  52. // @param NodeType neighbor_type - type of neighbor
  53. // @param int32_t samples_num - Number of neighbors to be acquired
  54. // @param std::vector<NodeIdType> *out_neighbors - Returned neighbors id
  55. // @return Status - The error code return
  56. virtual Status GetSampledNeighbors(NodeType neighbor_type, int32_t samples_num,
  57. std::vector<NodeIdType> *out_neighbors) = 0;
  58. // Add neighbor of node
  59. // @param std::shared_ptr<Node> node -
  60. // @return Status - The error code return
  61. virtual Status AddNeighbor(const std::shared_ptr<Node> &node) = 0;
  62. // Update feature of node
  63. // @param std::shared_ptr<Feature> feature -
  64. // @return Status - The error code return
  65. virtual Status UpdateFeature(const std::shared_ptr<Feature> &feature) = 0;
  66. protected:
  67. NodeIdType id_;
  68. NodeType type_;
  69. };
  70. } // namespace gnn
  71. } // namespace dataset
  72. } // namespace mindspore
  73. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_NODE_H_