Skip to content

Commit 582bfc2

Browse files
Added opaque_size_ functions
1 parent 5a59680 commit 582bfc2

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

ext/drjit-core

include/drjit/array_router.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,13 @@ DRJIT_ROUTE_BINARY_FALLBACK(dot, dot, (E) a1 * (E) a2)
526526

527527
template <typename Array>
528528
DRJIT_INLINE auto mean(const Array &a) {
529-
if constexpr (is_array_v<Array>)
530-
return sum(a) * (1.f / a.derived().size());
531-
else
529+
if constexpr (is_array_v<Array>){
530+
if (jit_flag(JitFlag::FreezingScope)) {
531+
return sum(a) * (1.f / a.derived().opaque_size_());
532+
} else {
533+
return sum(a) * (1.f / a.derived().size());
534+
}
535+
} else
532536
return a;
533537
}
534538

include/drjit/array_static.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ struct StaticArrayBase : ArrayBaseT<Value_, IsMask_, Derived_> {
7979

8080
DRJIT_INLINE constexpr size_t size() const { return Derived::Size; }
8181

82+
DRJIT_INLINE constexpr size_t opaque_size_() const { return Derived::Size; }
83+
8284
DRJIT_INLINE void init_(size_t) { }
8385

8486
static Derived empty_(size_t size) {

include/drjit/autodiff.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,11 @@ struct DRJIT_TRIVIAL_ABI DiffArray
709709

710710
size_t size() const { return jit_var_size((uint32_t) m_index); }
711711

712+
auto opaque_size_() const {
713+
using UInt32 = JitArray<Backend, uint32_t>;
714+
return UInt32::steal(jit_var_opaque_width(m_index));
715+
}
716+
712717
bool grad_enabled_() const {
713718
if constexpr (IsFloat)
714719
return (m_index >> 32) != 0;

include/drjit/dynamic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct DynamicArray
123123
}
124124

125125
DRJIT_INLINE size_t size() const { return m_size; }
126+
DRJIT_INLINE size_t opaque_size_() const { return m_size; }
126127
DRJIT_INLINE DynamicArray copy() { return DynamicArray(*this); }
127128

128129
DRJIT_INLINE Value &entry(size_t i) {

include/drjit/jit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ struct DRJIT_TRIVIAL_ABI JitArray
596596

597597
bool valid() const { return m_index != 0; }
598598
size_t size() const { return jit_var_size(m_index); }
599+
auto opaque_size_() const {
600+
using UInt32 = JitArray<Backend, uint32_t>;
601+
return UInt32::steal(jit_var_opaque_width(m_index));
602+
}
599603
uint32_t index() const { return m_index; }
600604
uint32_t index_ad() const { return 0; }
601605
uint64_t index_combined() const { return m_index; }

0 commit comments

Comments
 (0)