Skip to content

Commit b296bc3

Browse files
committed
Fix a silly oversight
1 parent f55340b commit b296bc3

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

librapid/include/librapid/array/storage.hpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,13 @@ namespace librapid {
366366
LIBRAPID_ASSERT(err == 0, "posix_memalign failed with error code {}", err);
367367
auto ptr = static_cast<Pointer>(_ptr);
368368
#elif defined(LIBRAPID_MSVC) || defined(LIBRAPID_MINGW)
369-
auto ptr = static_cast<Pointer>(_aligned_malloc(size * sizeof(T), LIBRAPID_MEM_ALIGN));
369+
Pointer ptr;
370+
try {
371+
ptr =
372+
static_cast<Pointer>(_aligned_malloc(size * sizeof(T), LIBRAPID_MEM_ALIGN));
373+
} catch (const std::exception &) {
374+
LIBRAPID_ASSERT(false, "Failed to allocate {} bytes of memory", size * sizeof(T));
375+
}
370376
#else
371377
auto ptr =
372378
static_cast<Pointer>(std::aligned_alloc(LIBRAPID_MEM_ALIGN, size * sizeof(T)));
@@ -377,7 +383,6 @@ namespace librapid {
377383

378384
// If the type cannot be trivially constructed, we need to
379385
// initialize each value
380-
381386
auto ptr_ = LIBRAPID_ASSUME_ALIGNED(ptr);
382387
LIBRAPID_ASSUME(ptr_ != nullptr);
383388
LIBRAPID_ASSUME(size > 0);
@@ -471,7 +476,7 @@ namespace librapid {
471476
if (this != &other) {
472477
size_t oldSize = m_size;
473478
m_size = other.m_size;
474-
if (other.m_size != m_size) LIBRAPID_UNLIKELY {
479+
if (oldSize != m_size) LIBRAPID_UNLIKELY {
475480
if (m_ownsData) LIBRAPID_LIKELY {
476481
// Reallocate
477482
detail::safeDeallocate(m_begin, oldSize);

librapid/include/librapid/cuda/cudaStorage.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,17 @@ namespace librapid {
359359
template<typename V>
360360
auto CudaStorage<T>::fromData(const std::initializer_list<V> &list) -> CudaStorage {
361361
CudaStorage ret;
362-
ret.initData(list.begin(), list.end());
362+
// ret.initData(list.begin(), list.end());
363+
ret.initData(static_cast<const V *>(list.begin()), static_cast<const V *>(list.end()));
363364
return ret;
364365
}
365366

366367
template<typename T>
367368
template<typename V>
368369
auto CudaStorage<T>::fromData(const std::vector<V> &vec) -> CudaStorage {
369370
CudaStorage ret;
370-
ret.initData(vec.begin(), vec.end());
371+
// ret.initData(vec.begin(), vec.end());
372+
ret.initData(&vec[0], &vec[0] + vec.size());
371373
return ret;
372374
}
373375

librapid/include/librapid/ml/activations.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ namespace librapid::ml {
173173
"sigmoidActivationForward",
174174
dst.shape().size(),
175175
temp.shape().size(),
176-
dst.storage().begin().get(),
177-
temp.storage().begin().get());
176+
dst.storage().begin(),
177+
temp.storage().begin());
178178
}
179179

180180
template<
@@ -189,8 +189,8 @@ namespace librapid::ml {
189189
"sigmoidActivationBackward",
190190
dst.shape().size(),
191191
temp.shape().size(),
192-
dst.storage().begin().get(),
193-
temp.storage().begin().get());
192+
dst.storage().begin(),
193+
temp.storage().begin());
194194
}
195195
#endif // LIBRAPID_HAS_CUDA
196196
};

0 commit comments

Comments
 (0)