mirror of
https://github.com/ml-explore/mlx.git
synced 2025-12-15 17:39:05 +08:00
[Metal] No copy array init (#2875)
Some checks failed
Build and Test / Check Lint (push) Has been cancelled
Build and Test / Linux (cpu, aarch64) (push) Has been cancelled
Build and Test / Linux (cpu, x86_64) (push) Has been cancelled
Build and Test / Linux (cuda-12.6, aarch64) (push) Has been cancelled
Build and Test / Linux (cuda-12.9, aarch64) (push) Has been cancelled
Build and Test / Linux (cuda-12.6, x86_64) (push) Has been cancelled
Build and Test / Linux (cuda-12.9, x86_64) (push) Has been cancelled
Build and Test / macOS (14.0) (push) Has been cancelled
Build and Test / macOS (15.0) (push) Has been cancelled
Build and Test / Build Documentation (push) Has been cancelled
Build and Test / Linux Fedora (aarch64) (push) Has been cancelled
Build and Test / Linux Fedora (x86_64) (push) Has been cancelled
Some checks failed
Build and Test / Check Lint (push) Has been cancelled
Build and Test / Linux (cpu, aarch64) (push) Has been cancelled
Build and Test / Linux (cpu, x86_64) (push) Has been cancelled
Build and Test / Linux (cuda-12.6, aarch64) (push) Has been cancelled
Build and Test / Linux (cuda-12.9, aarch64) (push) Has been cancelled
Build and Test / Linux (cuda-12.6, x86_64) (push) Has been cancelled
Build and Test / Linux (cuda-12.9, x86_64) (push) Has been cancelled
Build and Test / macOS (14.0) (push) Has been cancelled
Build and Test / macOS (15.0) (push) Has been cancelled
Build and Test / Build Documentation (push) Has been cancelled
Build and Test / Linux Fedora (aarch64) (push) Has been cancelled
Build and Test / Linux Fedora (x86_64) (push) Has been cancelled
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// Copyright © 2023 Apple Inc.
|
||||
|
||||
#include <climits>
|
||||
|
||||
#include "doctest/doctest.h"
|
||||
@@ -608,3 +607,24 @@ TEST_CASE("test make empty array") {
|
||||
CHECK_EQ(a.size(), 0);
|
||||
CHECK_EQ(a.dtype(), bool_);
|
||||
}
|
||||
|
||||
TEST_CASE("test make array from user buffer") {
|
||||
int size = 4096;
|
||||
std::vector<int> buffer(size, 0);
|
||||
|
||||
int count = 0;
|
||||
auto deleter = [&count](void*) { count++; };
|
||||
|
||||
{
|
||||
auto a = array(buffer.data(), Shape{size}, int32, deleter);
|
||||
if (metal::is_available()) {
|
||||
CHECK_EQ(buffer.data(), a.data<int>());
|
||||
}
|
||||
auto b = a + array(1);
|
||||
eval(b);
|
||||
auto expected = ones({4096});
|
||||
CHECK(array_equal(b, expected).item<bool>());
|
||||
}
|
||||
// deleter should always get called
|
||||
CHECK_EQ(count, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user