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 2.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 DATASET_ENGINE_GNN_NODE_H_
  17. #define DATASET_ENGINE_GNN_NODE_H_
  18. #include <memory>
  19. #include <unordered_map>
  20. #include <vector>
  21. #include "dataset/util/status.h"
  22. #include "dataset/engine/gnn/feature.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 neighbors of a node
  46. // @param NodeType neighbor_type - type of neighbor
  47. // @param int32_t samples_num - Number of neighbors to be acquired, if -1 means all neighbors are acquired
  48. // @param std::vector<NodeIdType> *out_neighbors - Returned neighbors id
  49. // @return Status - The error code return
  50. virtual Status GetNeighbors(NodeType neighbor_type, int32_t samples_num, std::vector<NodeIdType> *out_neighbors) = 0;
  51. // Add neighbor of node
  52. // @param std::shared_ptr<Node> node -
  53. // @return Status - The error code return
  54. virtual Status AddNeighbor(const std::shared_ptr<Node> &node) = 0;
  55. // Update feature of node
  56. // @param std::shared_ptr<Feature> feature -
  57. // @return Status - The error code return
  58. virtual Status UpdateFeature(const std::shared_ptr<Feature> &feature) = 0;
  59. protected:
  60. NodeIdType id_;
  61. NodeType type_;
  62. };
  63. } // namespace gnn
  64. } // namespace dataset
  65. } // namespace mindspore
  66. #endif // DATASET_ENGINE_GNN_NODE_H_