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.

local_node.h 3.1 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_LOCAL_NODE_H_
  17. #define DATASET_ENGINE_GNN_LOCAL_NODE_H_
  18. #include <memory>
  19. #include <unordered_map>
  20. #include <vector>
  21. #include "dataset/util/status.h"
  22. #include "dataset/engine/gnn/node.h"
  23. #include "dataset/engine/gnn/feature.h"
  24. namespace mindspore {
  25. namespace dataset {
  26. namespace gnn {
  27. class LocalNode : public Node {
  28. public:
  29. // Constructor
  30. // @param NodeIdType id - node id
  31. // @param NodeType type - node type
  32. LocalNode(NodeIdType id, NodeType type);
  33. ~LocalNode() = default;
  34. // Get the feature of a node
  35. // @param FeatureType feature_type - type of feature
  36. // @param std::shared_ptr<Feature> *out_feature - Returned feature
  37. // @return Status - The error code return
  38. Status GetFeatures(FeatureType feature_type, std::shared_ptr<Feature> *out_feature) override;
  39. // Get the all neighbors of a node
  40. // @param NodeType neighbor_type - type of neighbor
  41. // @param std::vector<NodeIdType> *out_neighbors - Returned neighbors id
  42. // @return Status - The error code return
  43. Status GetAllNeighbors(NodeType neighbor_type, std::vector<NodeIdType> *out_neighbors,
  44. bool exclude_itself = false) override;
  45. // Get the sampled neighbors of a node
  46. // @param NodeType neighbor_type - type of neighbor
  47. // @param int32_t samples_num - Number of neighbors to be acquired
  48. // @param std::vector<NodeIdType> *out_neighbors - Returned neighbors id
  49. // @return Status - The error code return
  50. Status GetSampledNeighbors(NodeType neighbor_type, int32_t samples_num,
  51. std::vector<NodeIdType> *out_neighbors) override;
  52. // Add neighbor of node
  53. // @param std::shared_ptr<Node> node -
  54. // @return Status - The error code return
  55. Status AddNeighbor(const std::shared_ptr<Node> &node) override;
  56. // Update feature of node
  57. // @param std::shared_ptr<Feature> feature -
  58. // @return Status - The error code return
  59. Status UpdateFeature(const std::shared_ptr<Feature> &feature) override;
  60. private:
  61. Status GetSampledNeighbors(const std::vector<std::shared_ptr<Node>> &neighbors, int32_t samples_num,
  62. std::vector<NodeIdType> *out);
  63. std::mt19937 rnd_;
  64. std::unordered_map<FeatureType, std::shared_ptr<Feature>> features_;
  65. std::unordered_map<NodeType, std::vector<std::shared_ptr<Node>>> neighbor_nodes_;
  66. };
  67. } // namespace gnn
  68. } // namespace dataset
  69. } // namespace mindspore
  70. #endif // DATASET_ENGINE_GNN_LOCAL_NODE_H_