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.4 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. using WeightType = float;
  29. constexpr NodeIdType kDefaultNodeId = -1;
  30. class Node {
  31. public:
  32. // Constructor
  33. // @param NodeIdType id - node id
  34. // @param NodeType type - node type
  35. // @param WeightType type - node weight
  36. Node(NodeIdType id, NodeType type, WeightType weight) : id_(id), type_(type), weight_(weight) {}
  37. virtual ~Node() = default;
  38. // @return NodeIdType - Returned node id
  39. NodeIdType id() const { return id_; }
  40. // @return NodeIdType - Returned node type
  41. NodeType type() const { return type_; }
  42. // @return WeightType - Returned node weight
  43. WeightType weight() const { return weight_; }
  44. // Get the feature of a node
  45. // @param FeatureType feature_type - type of feature
  46. // @param std::shared_ptr<Feature> *out_feature - Returned feature
  47. // @return Status The status code returned
  48. virtual Status GetFeatures(FeatureType feature_type, std::shared_ptr<Feature> *out_feature) = 0;
  49. // Get the all neighbors of a node
  50. // @param NodeType neighbor_type - type of neighbor
  51. // @param std::vector<NodeIdType> *out_neighbors - Returned neighbors id
  52. // @return Status The status code returned
  53. virtual Status GetAllNeighbors(NodeType neighbor_type, std::vector<NodeIdType> *out_neighbors,
  54. bool exclude_itself = false) = 0;
  55. // Get the sampled neighbors of a node
  56. // @param NodeType neighbor_type - type of neighbor
  57. // @param int32_t samples_num - Number of neighbors to be acquired
  58. // @param SamplingStrategy strategy - Sampling strategy
  59. // @param std::vector<NodeIdType> *out_neighbors - Returned neighbors id
  60. // @return Status The status code returned
  61. virtual Status GetSampledNeighbors(NodeType neighbor_type, int32_t samples_num, SamplingStrategy strategy,
  62. std::vector<NodeIdType> *out_neighbors) = 0;
  63. // Add neighbor of node
  64. // @param std::shared_ptr<Node> node -
  65. // @return Status The status code returned
  66. virtual Status AddNeighbor(const std::shared_ptr<Node> &node, const WeightType &weight) = 0;
  67. // Update feature of node
  68. // @param std::shared_ptr<Feature> feature -
  69. // @return Status The status code returned
  70. virtual Status UpdateFeature(const std::shared_ptr<Feature> &feature) = 0;
  71. protected:
  72. NodeIdType id_;
  73. NodeType type_;
  74. WeightType weight_;
  75. };
  76. } // namespace gnn
  77. } // namespace dataset
  78. } // namespace mindspore
  79. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_NODE_H_