• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daisytuner / docc / 22023884668

14 Feb 2026 08:36PM UTC coverage: 64.903% (-1.4%) from 66.315%
22023884668

Pull #525

github

web-flow
Merge 1d47f8bf2 into 9d01cacd5
Pull Request #525: Step 3 (Native Tensor Support): Refactor Python Frontend

2522 of 3435 new or added lines in 32 files covered. (73.42%)

320 existing lines in 15 files now uncovered.

23204 of 35752 relevant lines covered (64.9%)

370.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/sdfg/src/data_flow/library_nodes/math/tensor/elementwise_ops/cast_node.cpp
1
#include "sdfg/data_flow/library_nodes/math/tensor/elementwise_ops/cast_node.h"
2

3
#include "sdfg/analysis/analysis.h"
4
#include "sdfg/builder/structured_sdfg_builder.h"
5

6
#include "sdfg/analysis/scope_analysis.h"
7

8
namespace sdfg {
9
namespace math {
10
namespace tensor {
11

12
CastNode::CastNode(
13
    size_t element_id,
14
    const DebugInfo& debug_info,
15
    const graph::Vertex vertex,
16
    data_flow::DataFlowGraph& parent,
17
    const std::vector<symbolic::Expression>& shape,
18
    types::PrimitiveType target_type
19
)
20
    : ElementWiseUnaryNode(element_id, debug_info, vertex, parent, LibraryNodeType_Cast, shape),
28✔
21
      target_type_(target_type) {}
28✔
22

23
bool CastNode::expand_operation(
24
    builder::StructuredSDFGBuilder& builder,
25
    analysis::AnalysisManager& analysis_manager,
26
    structured_control_flow::Sequence& body,
27
    const std::string& input_name,
28
    const std::string& output_name,
29
    const types::Tensor& input_type,
30
    const types::Tensor& output_type,
31
    const data_flow::Subset& subset
32
) {
28✔
33
    // Add code block
34
    auto& code_block = builder.add_block(body);
28✔
35

36
    auto& input_node_new = builder.add_access(code_block, input_name);
28✔
37
    auto& output_node_new = builder.add_access(code_block, output_name);
28✔
38

39
    // Use assign tasklet which handles type casting when input and output types differ
40
    auto& tasklet = builder.add_tasklet(code_block, data_flow::TaskletCode::assign, "_out", {"_in"});
28✔
41
    builder.add_computational_memlet(code_block, input_node_new, tasklet, "_in", subset, input_type);
28✔
42
    builder.add_computational_memlet(code_block, tasklet, "_out", output_node_new, subset, output_type);
28✔
43

44
    return true;
28✔
45
}
28✔
46

47
void CastNode::validate(const Function& function) const {
28✔
48
    auto& graph = this->get_parent();
28✔
49

50
    // Check that all input memlets are tensor of scalar
51
    for (auto& iedge : graph.in_edges(*this)) {
28✔
52
        if (iedge.base_type().type_id() != types::TypeID::Tensor) {
28✔
UNCOV
53
            throw InvalidSDFGException(
×
NEW
54
                "CastNode: Input memlet must be of tensor type. Found type: " + iedge.base_type().print()
×
55
            );
×
56
        }
×
57
    }
28✔
58

59
    // Check that all output memlets are tensor of scalar
60
    for (auto& oedge : graph.out_edges(*this)) {
28✔
61
        if (oedge.base_type().type_id() != types::TypeID::Tensor) {
28✔
UNCOV
62
            throw InvalidSDFGException(
×
NEW
63
                "CastNode: Output memlet must be of tensor type. Found type: " + oedge.base_type().print()
×
64
            );
×
65
        }
×
66
    }
28✔
67

68
    // For CastNode, we DON'T check that all memlets have the same primitive type
69
    // because the whole point of casting is to convert between types
70
}
28✔
71

72
std::unique_ptr<data_flow::DataFlowNode> CastNode::
73
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
74
    return std::unique_ptr<data_flow::DataFlowNode>(
×
75
        new CastNode(element_id, this->debug_info(), vertex, parent, this->shape_, this->target_type_)
×
76
    );
×
77
}
×
78

79
nlohmann::json CastNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
80
    const CastNode& cast_node = static_cast<const CastNode&>(library_node);
×
81
    nlohmann::json j;
×
82

83
    j["code"] = cast_node.code().value();
×
84

85
    serializer::JSONSerializer serializer;
×
86
    j["shape"] = nlohmann::json::array();
×
87
    for (auto& dim : cast_node.shape()) {
×
88
        j["shape"].push_back(serializer.expression(dim));
×
89
    }
×
90

91
    j["target_type"] = static_cast<int>(cast_node.target_type());
×
92

93
    return j;
×
94
}
×
95

96
data_flow::LibraryNode& CastNodeSerializer::deserialize(
97
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
98
) {
×
99
    // Assertions for required fields
100
    assert(j.contains("element_id"));
×
101
    assert(j.contains("code"));
×
102
    assert(j.contains("debug_info"));
×
103
    assert(j.contains("shape"));
×
104
    assert(j.contains("target_type"));
×
105

106
    std::vector<symbolic::Expression> shape;
×
107
    for (const auto& dim : j["shape"]) {
×
108
        shape.push_back(symbolic::parse(dim.get<std::string>()));
×
109
    }
×
110

111
    types::PrimitiveType target_type = static_cast<types::PrimitiveType>(j["target_type"].get<int>());
×
112

113
    // Extract debug info using JSONSerializer
114
    sdfg::serializer::JSONSerializer serializer;
×
115
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
116

117
    return static_cast<CastNode&>(builder.add_library_node<CastNode>(parent, debug_info, shape, target_type));
×
118
}
×
119

120
} // namespace tensor
121
} // namespace math
122
} // namespace sdfg
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc