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

IntelPython / dpnp / 25934098681

15 May 2026 06:18PM UTC coverage: 78.21% (-0.1%) from 78.324%
25934098681

Pull #2916

github

web-flow
Merge 8d4adfcce into f1f5467a2
Pull Request #2916: Add `--includes` and` --include-dir` to dpnp CLI

1539 of 2874 branches covered (53.55%)

Branch coverage included in aggregate %.

0 of 11 new or added lines in 1 file covered. (0.0%)

38 existing lines in 2 files now uncovered.

26292 of 32711 relevant lines covered (80.38%)

7942.07 hits per line

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

37.88
/dpnp/tensor/libtensor/include/utils/memory_overlap.hpp
1
//*****************************************************************************
2
// Copyright (c) 2026, Intel Corporation
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are met:
7
// - Redistributions of source code must retain the above copyright notice,
8
//   this list of conditions and the following disclaimer.
9
// - Redistributions in binary form must reproduce the above copyright notice,
10
//   this list of conditions and the following disclaimer in the documentation
11
//   and/or other materials provided with the distribution.
12
// - Neither the name of the copyright holder nor the names of its contributors
13
//   may be used to endorse or promote products derived from this software
14
//   without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26
// THE POSSIBILITY OF SUCH DAMAGE.
27
//*****************************************************************************
28
///
29
/// \file
30
/// This file defines utility to determine whether two arrays have memory
31
/// overlap.
32
//===----------------------------------------------------------------------===//
33

34
#pragma once
35

36
#include <algorithm>
37
#include <iterator>
38

39
#include <pybind11/pybind11.h>
40

41
#include "dpnp4pybind11.hpp"
42

43
/* @brief check for overlap of memory regions behind arrays.
44

45
Presently assume that array occupies all bytes between smallest and largest
46
displaced elements.
47

48
TODO: Write proper Frobenius solver to account for holes, e.g.
49
   overlap( x_contig[::2], x_contig[1::2]) should give False,
50
   while this implementation gives True.
51
*/
52
namespace dpnp::tensor::overlap
53
{
54
namespace py = pybind11;
55

56
struct MemoryOverlap
57
{
58
    bool operator()(dpnp::tensor::usm_ndarray ar1,
59
                    dpnp::tensor::usm_ndarray ar2) const
60
    {
230,211✔
61
        const char *ar1_data = ar1.get_data();
230,211✔
62

63
        const auto &ar1_offsets = ar1.get_minmax_offsets();
230,211✔
64
        py::ssize_t ar1_elem_size =
230,211✔
65
            static_cast<py::ssize_t>(ar1.get_elemsize());
230,211✔
66

67
        const char *ar2_data = ar2.get_data();
230,211✔
68
        const auto &ar2_offsets = ar2.get_minmax_offsets();
230,211✔
69
        py::ssize_t ar2_elem_size =
230,211✔
70
            static_cast<py::ssize_t>(ar2.get_elemsize());
230,211✔
71

72
        /* Memory of array1 extends from  */
73
        /*    [ar1_data + ar1_offsets.first * ar1_elem_size, ar1_data +
74
         * ar1_offsets.second * ar1_elem_size + ar1_elem_size] */
75
        /* Memory of array2 extends from */
76
        /*    [ar2_data + ar2_offsets.first * ar2_elem_size, ar2_data +
77
         * ar2_offsets.second * ar2_elem_size + ar2_elem_size] */
78

79
        /* Intervals [x0, x1] and [y0, y1] do not overlap if (x0 <= x1) && (y0
80
         * <= y1)
81
         * && (x1 <=y0 || y1 <= x0 ) */
82
        /* Given that x0 <= x1 and y0 <= y1 are true by construction, the
83
         * condition for overlap us (x1 > y0) && (y1 > x0) */
84

85
        /*  Applying:
86
            (ar1_data + ar1_offsets.second * ar1_elem_size + ar1_elem_size >
87
        ar2_data
88
        + ar2_offsets.first * ar2_elem_size) && (ar2_data + ar2_offsets.second *
89
        ar2_elem_size + ar2_elem_size > ar1_data + ar1_offsets.first *
90
        ar1_elem_size)
91
        */
92

93
        auto byte_distance = static_cast<py::ssize_t>(ar2_data - ar1_data);
230,211✔
94

95
        py::ssize_t x1_minus_y0 =
230,211✔
96
            (-byte_distance +
230,211✔
97
             (ar1_elem_size + (ar1_offsets.second * ar1_elem_size) -
230,211✔
98
              (ar2_offsets.first * ar2_elem_size)));
230,211✔
99

100
        py::ssize_t y1_minus_x0 =
230,211✔
101
            (byte_distance +
230,211✔
102
             (ar2_elem_size + (ar2_offsets.second * ar2_elem_size) -
230,211✔
103
              (ar1_offsets.first * ar1_elem_size)));
230,211✔
104

105
        bool memory_overlap = (x1_minus_y0 > 0) && (y1_minus_x0 > 0);
230,211✔
106

107
        return memory_overlap;
230,211✔
108
    }
230,211✔
109
};
110

111
struct SameLogicalTensors
112
{
113
    bool operator()(dpnp::tensor::usm_ndarray ar1,
114
                    dpnp::tensor::usm_ndarray ar2) const
UNCOV
115
    {
×
UNCOV
116
        // Same ndim
×
UNCOV
117
        int nd1 = ar1.get_ndim();
×
UNCOV
118
        if (nd1 != ar2.get_ndim())
×
119
            return false;
×
UNCOV
120

×
UNCOV
121
        // Same dtype
×
UNCOV
122
        int tn1 = ar1.get_typenum();
×
UNCOV
123
        if (tn1 != ar2.get_typenum())
×
124
            return false;
×
UNCOV
125

×
UNCOV
126
        // Same pointer
×
UNCOV
127
        const char *ar1_data = ar1.get_data();
×
UNCOV
128
        const char *ar2_data = ar2.get_data();
×
UNCOV
129

×
UNCOV
130
        if (ar1_data != ar2_data)
×
131
            return false;
×
UNCOV
132

×
UNCOV
133
        // Same shape and strides
×
UNCOV
134
        const py::ssize_t *ar1_shape = ar1.get_shape_raw();
×
UNCOV
135
        const py::ssize_t *ar2_shape = ar2.get_shape_raw();
×
UNCOV
136

×
UNCOV
137
        if (!std::equal(ar1_shape, ar1_shape + nd1, ar2_shape))
×
138
            return false;
×
UNCOV
139

×
UNCOV
140
        // Same shape and strides
×
UNCOV
141
        auto const &ar1_strides = ar1.get_strides_vector();
×
UNCOV
142
        auto const &ar2_strides = ar2.get_strides_vector();
×
UNCOV
143

×
UNCOV
144
        auto ar1_beg_it = std::begin(ar1_strides);
×
UNCOV
145
        auto ar1_end_it = std::end(ar1_strides);
×
UNCOV
146

×
UNCOV
147
        auto ar2_beg_it = std::begin(ar2_strides);
×
UNCOV
148

×
UNCOV
149
        if (!std::equal(ar1_beg_it, ar1_end_it, ar2_beg_it))
×
150
            return false;
×
UNCOV
151

×
UNCOV
152
        // all checks passed: arrays are logical views
×
UNCOV
153
        // into the same memory
×
UNCOV
154
        return true;
×
UNCOV
155
    }
×
156
};
157
} // namespace dpnp::tensor::overlap
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