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

daisytuner / docc / 29726336683

20 Jul 2026 07:59AM UTC coverage: 63.437% (+0.3%) from 63.18%
29726336683

Pull #857

github

web-flow
Merge 129cc05f2 into b57f184e7
Pull Request #857: Added PyTorch frontend

419 of 544 new or added lines in 14 files covered. (77.02%)

1 existing line in 1 file now uncovered.

41006 of 64641 relevant lines covered (63.44%)

977.69 hits per line

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

64.29
/sdfg/src/types/tensor.cpp
1
#include "sdfg/types/tensor.h"
2

3
#include "sdfg/symbolic/symbolic.h"
4
#include "sdfg/types/scalar.h"
5

6
namespace sdfg {
7
namespace types {
8

9
symbolic::MultiExpression Tensor::strides_from_shape(const symbolic::MultiExpression& shape) {
8✔
10
    if (shape.empty()) {
8✔
11
        return {};
×
12
    }
×
13
    symbolic::MultiExpression strides(shape.size());
8✔
14
    strides.back() = SymEngine::integer(1);
8✔
15
    for (size_t i = shape.size() - 1; i > 0; --i) {
18✔
16
        strides[i - 1] = SymEngine::mul(strides[i], shape[i]);
10✔
17
    }
10✔
18
    return strides;
8✔
19
}
8✔
20

21
Tensor::Tensor(const Scalar& element_type, const math::tensor::TensorLayout& layout)
22
    : element_type_(std::unique_ptr<Scalar>(static_cast<Scalar*>(element_type.clone().release()))), layout_(layout) {}
1,916✔
23

24
Tensor::Tensor(const Scalar& element_type, const symbolic::MultiExpression& shape)
25
    : Tensor(element_type, math::tensor::TensorLayout(shape)) {};
1,041✔
26

27
Tensor::Tensor(
28
    const Scalar& element_type,
29
    const symbolic::MultiExpression& shape,
30
    const symbolic::MultiExpression& strides,
31
    const symbolic::Expression& offset
32
)
33
    : Tensor(element_type, math::tensor::TensorLayout(shape, strides, offset)) {};
5✔
34

35
Tensor::Tensor(
36
    StorageType storage_type,
37
    size_t alignment,
38
    const std::string& initializer,
39
    const Scalar& element_type,
40
    const math::tensor::TensorLayout& layout
41
)
42
    : IType(storage_type, alignment, initializer),
5,583✔
43
      element_type_(std::unique_ptr<Scalar>(static_cast<Scalar*>(element_type.clone().release()))), layout_(layout) {};
5,583✔
44

45
Tensor::Tensor(
46
    StorageType storage_type,
47
    size_t alignment,
48
    const std::string& initializer,
49
    const Scalar& element_type,
50
    const symbolic::MultiExpression& shape,
51
    const symbolic::MultiExpression& strides,
52
    const symbolic::Expression& offset
53
)
54
    : Tensor(
1,545✔
55
          std::move(storage_type),
1,545✔
56
          alignment,
1,545✔
57
          initializer,
1,545✔
58
          element_type,
1,545✔
59
          math::tensor::TensorLayout(shape, strides, offset)
1,545✔
60
      ) {};
1,545✔
61

62
PrimitiveType Tensor::primitive_type() const { return this->element_type_->primitive_type(); };
4,486✔
63

64
bool Tensor::is_symbol() const { return false; };
1✔
65

66
const Scalar& Tensor::element_type() const { return *this->element_type_; };
2,591✔
67

68
const math::tensor::TensorLayout& Tensor::layout() const { return this->layout_; }
2,270✔
69

70
const symbolic::MultiExpression& Tensor::shape() const { return this->layout_.shape(); };
19,372✔
71

72
const symbolic::MultiExpression& Tensor::strides() const { return this->layout_.strides(); };
9,943✔
73

74
const symbolic::Expression& Tensor::offset() const { return this->layout_.offset(); };
1,553✔
75

76
symbolic::Expression Tensor::total_elements() const { return layout_.total_elements(); };
×
77

NEW
78
symbolic::Expression Tensor::total_size() const {
×
NEW
79
    return symbolic::mul(layout_.total_elements(), symbolic::size_of_type(*element_type_));
×
NEW
80
}
×
81

82
bool Tensor::is_scalar() const { return layout_.is_scalar(); }
7,851✔
83

NEW
84
bool Tensor::is_contiguous() const { return layout_.has_linear_accesses_no_padding(); }
×
85

86
TypeID Tensor::type_id() const { return TypeID::Tensor; };
20,056✔
87

88
bool Tensor::operator==(const IType& other) const {
8✔
89
    if (!dynamic_cast<const Tensor*>(&other)) {
8✔
90
        return false;
×
91
    }
×
92
    const auto& tensor_type = static_cast<const Tensor&>(other);
8✔
93

94
    if (!this->element_type_->operator==(*tensor_type.element_type_)) {
8✔
95
        return false;
1✔
96
    }
1✔
97
    if (layout_ != tensor_type.layout_) {
7✔
98
        return false;
1✔
99
    }
1✔
100

101
    return true;
6✔
102
};
7✔
103

104

105
std::unique_ptr<IType> Tensor::clone() const {
4,036✔
106
    return std::make_unique<
4,036✔
107
        Tensor>(this->storage_type(), this->alignment(), this->initializer(), *this->element_type_, this->layout_);
4,036✔
108
};
4,036✔
109

110
std::string Tensor::print() const {
×
111
    std::string result = "Tensor(" + this->element_type_->print() + ", ";
×
112
    result += layout_.toStr();
×
113
    result += ")";
×
114
    return result;
×
115
};
×
116

117
std::unique_ptr<Tensor> Tensor::newaxis(size_t axis) const {
×
118
    return std::make_unique<Tensor>(
×
119
        this->storage_type(), this->alignment(), this->initializer(), *this->element_type_, *layout_.newaxis(axis)
×
120
    );
×
121
}
×
122

123
std::unique_ptr<Tensor> Tensor::flip(size_t axis) const {
1✔
124
    return std::make_unique<
1✔
125
        Tensor>(this->storage_type(), this->alignment(), this->initializer(), *this->element_type_, *layout_.flip(axis));
1✔
126
}
1✔
127

128
std::unique_ptr<Tensor> Tensor::unsqueeze(size_t axis) const { return this->newaxis(axis); }
×
129

130
std::unique_ptr<Tensor> Tensor::squeeze(size_t axis) const {
×
131
    return std::make_unique<Tensor>(
×
132
        this->storage_type(), this->alignment(), this->initializer(), *this->element_type_, *layout_.squeeze(axis)
×
133
    );
×
134
}
×
135

136
std::unique_ptr<Tensor> Tensor::squeeze() const {
×
137
    return std::make_unique<
×
138
        Tensor>(this->storage_type(), this->alignment(), this->initializer(), *this->element_type_, *layout_.squeeze());
×
139
}
×
140

141
std::unique_ptr<Tensor> Tensor::reshape(const symbolic::MultiExpression& new_shape) const {
1✔
142
    return std::make_unique<Tensor>(
1✔
143
        this->storage_type(), this->alignment(), this->initializer(), *this->element_type_, *layout_.reshape(new_shape)
1✔
144
    );
1✔
145
}
1✔
146

147
} // namespace types
148
} // namespace sdfg
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc