mirror of
https://github.com/ml-explore/mlx.git
synced 2025-07-14 20:41:13 +08:00
fix array from list for > 32 bit types (#501)
This commit is contained in:
parent
ddf50113c5
commit
6bf779e72b
@ -229,9 +229,28 @@ array array_from_list(
|
|||||||
return array(vals.begin(), shape, specified_type.value_or(bool_));
|
return array(vals.begin(), shape, specified_type.value_or(bool_));
|
||||||
}
|
}
|
||||||
case pyint: {
|
case pyint: {
|
||||||
std::vector<int> vals;
|
auto dtype = specified_type.value_or(int32);
|
||||||
fill_vector(pl, vals);
|
if (dtype == int64) {
|
||||||
return array(vals.begin(), shape, specified_type.value_or(int32));
|
std::vector<int64_t> vals;
|
||||||
|
fill_vector(pl, vals);
|
||||||
|
return array(vals.begin(), shape, dtype);
|
||||||
|
} else if (dtype == uint64) {
|
||||||
|
std::vector<uint64_t> vals;
|
||||||
|
fill_vector(pl, vals);
|
||||||
|
return array(vals.begin(), shape, dtype);
|
||||||
|
} else if (dtype == uint32) {
|
||||||
|
std::vector<uint32_t> vals;
|
||||||
|
fill_vector(pl, vals);
|
||||||
|
return array(vals.begin(), shape, dtype);
|
||||||
|
} else if (is_floating_point(dtype)) {
|
||||||
|
std::vector<float> vals;
|
||||||
|
fill_vector(pl, vals);
|
||||||
|
return array(vals.begin(), shape, dtype);
|
||||||
|
} else {
|
||||||
|
std::vector<int> vals;
|
||||||
|
fill_vector(pl, vals);
|
||||||
|
return array(vals.begin(), shape, dtype);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case pyfloat: {
|
case pyfloat: {
|
||||||
std::vector<float> vals;
|
std::vector<float> vals;
|
||||||
|
@ -226,6 +226,14 @@ class TestArray(mlx_tests.MLXTestCase):
|
|||||||
x = mx.array([1 + 0j, 2j, True, 0], mx.complex64)
|
x = mx.array([1 + 0j, 2j, True, 0], mx.complex64)
|
||||||
self.assertEqual(x.tolist(), [1 + 0j, 2j, 1 + 0j, 0j])
|
self.assertEqual(x.tolist(), [1 + 0j, 2j, 1 + 0j, 0j])
|
||||||
|
|
||||||
|
xnp = np.array([0, 4294967295], dtype=np.uint32)
|
||||||
|
x = mx.array([0, 4294967295], dtype=mx.uint32)
|
||||||
|
self.assertTrue(np.array_equal(x, xnp))
|
||||||
|
|
||||||
|
xnp = np.array([0, 4294967295], dtype=np.float32)
|
||||||
|
x = mx.array([0, 4294967295], dtype=mx.float32)
|
||||||
|
self.assertTrue(np.array_equal(x, xnp))
|
||||||
|
|
||||||
def test_construction_from_lists_of_mlx_arrays(self):
|
def test_construction_from_lists_of_mlx_arrays(self):
|
||||||
dtypes = [
|
dtypes = [
|
||||||
mx.bool_,
|
mx.bool_,
|
||||||
|
Loading…
Reference in New Issue
Block a user