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.

edge.h 3.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_EDGE_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_EDGE_H_
  18. #include <memory>
  19. #include <unordered_map>
  20. #include <utility>
  21. #include "minddata/dataset/util/status.h"
  22. #include "minddata/dataset/engine/gnn/feature.h"
  23. #include "minddata/dataset/engine/gnn/node.h"
  24. namespace mindspore {
  25. namespace dataset {
  26. namespace gnn {
  27. using EdgeType = int8_t;
  28. using EdgeIdType = int32_t;
  29. class Edge {
  30. public:
  31. // Constructor
  32. // @param EdgeIdType id - edge id
  33. // @param EdgeType type - edge type
  34. // @param WeightType weight - edge weight
  35. // @param std::shared_ptr<Node> src_node - source node
  36. // @param std::shared_ptr<Node> dst_node - destination node
  37. Edge(EdgeIdType id, EdgeType type, WeightType weight, std::shared_ptr<Node> src_node, std::shared_ptr<Node> dst_node)
  38. : id_(id), type_(type), weight_(weight), src_node_(src_node), dst_node_(dst_node) {}
  39. virtual ~Edge() = default;
  40. // @return NodeIdType - Returned edge id
  41. EdgeIdType id() const { return id_; }
  42. // @return NodeIdType - Returned edge type
  43. EdgeType type() const { return type_; }
  44. // @return WeightType - Returned edge weight
  45. WeightType weight() const { return weight_; }
  46. // Get the feature of a edge
  47. // @param FeatureType feature_type - type of feature
  48. // @param std::shared_ptr<Feature> *out_feature - Returned feature
  49. // @return Status The status code returned
  50. virtual Status GetFeatures(FeatureType feature_type, std::shared_ptr<Feature> *out_feature) = 0;
  51. // Get nodes on the edge
  52. // @param std::pair<std::shared_ptr<Node>, std::shared_ptr<Node>> *out_node - Source and destination nodes returned
  53. Status GetNode(std::pair<std::shared_ptr<Node>, std::shared_ptr<Node>> *out_node) {
  54. RETURN_UNEXPECTED_IF_NULL(out_node);
  55. *out_node = std::make_pair(src_node_, dst_node_);
  56. return Status::OK();
  57. }
  58. // Set node to edge
  59. // @param const std::pair<std::shared_ptr<Node>, std::shared_ptr<Node>> &in_node -
  60. Status SetNode(const std::pair<std::shared_ptr<Node>, std::shared_ptr<Node>> &in_node) {
  61. src_node_ = in_node.first;
  62. dst_node_ = in_node.second;
  63. return Status::OK();
  64. }
  65. // Update feature of edge
  66. // @param std::shared_ptr<Feature> feature -
  67. // @return Status The status code returned
  68. virtual Status UpdateFeature(const std::shared_ptr<Feature> &feature) = 0;
  69. protected:
  70. EdgeIdType id_;
  71. EdgeType type_;
  72. WeightType weight_;
  73. std::shared_ptr<Node> src_node_;
  74. std::shared_ptr<Node> dst_node_;
  75. };
  76. } // namespace gnn
  77. } // namespace dataset
  78. } // namespace mindspore
  79. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_EDGE_H_