object#
-
class numpy::object_#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use object_
object_ obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_OBJECT_HOLDER.H:117 |
|
|
NP_OBJECT_HOLDER.H:127 |
|
|
NP_OBJECT_HOLDER.H:136 |
|
|
NP_OBJECT_HOLDER.H:185 |
Operators#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
object_ & |
NP_OBJECT_HOLDER.H:159 |
|
|
object_ & noexcept |
NP_OBJECT_HOLDER.H:214 |
|
|
bool |
NP_OBJECT_HOLDER.H:545 |
|
|
bool |
NP_OBJECT_HOLDER.H:559 |
|
|
bool |
NP_OBJECT_HOLDER.H:563 |
|
|
bool |
NP_OBJECT_HOLDER.H:567 |
|
|
bool |
NP_OBJECT_HOLDER.H:572 |
|
|
bool |
NP_OBJECT_HOLDER.H:579 |
|
|
object_ |
NP_OBJECT_HOLDER.H:590 |
|
|
object_ |
NP_OBJECT_HOLDER.H:620 |
|
|
object_ |
NP_OBJECT_HOLDER.H:643 |
|
|
object_ |
NP_OBJECT_HOLDER.H:666 |
|
|
object_ |
NP_OBJECT_HOLDER.H:686 |
|
|
object_ & |
NP_OBJECT_HOLDER.H:697 |
|
|
object_ & |
NP_OBJECT_HOLDER.H:702 |
|
|
object_ & |
NP_OBJECT_HOLDER.H:707 |
|
|
object_ & |
NP_OBJECT_HOLDER.H:712 |
Indexing / Selection#
Math Operations#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
object_ |
NP_OBJECT_HOLDER.H:691 |
I/O#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::string |
NP_OBJECT_HOLDER.H:539 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
NP_OBJECT_HOLDER.H:506 |
|
|
bool |
NP_OBJECT_HOLDER.H:586 |
|
|
bool |
NP_OBJECT_HOLDER.H:523 |
|
|
bool |
NP_OBJECT_HOLDER.H:585 |
|
|
bool |
NP_OBJECT_HOLDER.H:513 |
|
|
bool |
NP_OBJECT_HOLDER.H:584 |
|
|
bool |
NP_OBJECT_HOLDER.H:534 |
|
|
bool |
NP_OBJECT_HOLDER.H:587 |
|
|
bool |
NP_OBJECT_HOLDER.H:487 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
size_t |
NP_OBJECT_HOLDER.H:528 |
|
|
bool |
NP_OBJECT_HOLDER.H:475 |
|
|
void |
NP_OBJECT_HOLDER.H:411 |
|
|
void |
NP_OBJECT_HOLDER.H:246 |
|
|
std::string |
NP_OBJECT_HOLDER.H:518 |
Code Examples#
The following examples are extracted from the test suite.
object (np_test_1_all.cpp:1469)
1459 std::cout << std::string("[FAIL] ") + description << std::endl;
1460 throw std::runtime_error(description);
1461 }
1462 if (!(*assigned.get_as<int>() == 42)) {
1463 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*assigned.get_as<int>() == 42)";
1464 std::cout << std::string("[FAIL] ") + description << std::endl;
1465 throw std::runtime_error(description);
1466 }
1467
1468 // Test move constructor
1469 object_ moved(std::move(object_(100)));
1470 if (!(!moved.is_null())) {
1471 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!moved.is_null())";
1472 std::cout << std::string("[FAIL] ") + description << std::endl;
1473 throw std::runtime_error(description);
1474 }
1475 if (!(moved.is_type<int>())) {
1476 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moved.is_type<int>())";
1477 std::cout << std::string("[FAIL] ") + description << std::endl;
1478 throw std::runtime_error(description);
1479 }
object (np_test_1_all.cpp:1469)
1459 std::cout << std::string("[FAIL] ") + description << std::endl;
1460 throw std::runtime_error(description);
1461 }
1462 if (!(*assigned.get_as<int>() == 42)) {
1463 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*assigned.get_as<int>() == 42)";
1464 std::cout << std::string("[FAIL] ") + description << std::endl;
1465 throw std::runtime_error(description);
1466 }
1467
1468 // Test move constructor
1469 object_ moved(std::move(object_(100)));
1470 if (!(!moved.is_null())) {
1471 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!moved.is_null())";
1472 std::cout << std::string("[FAIL] ") + description << std::endl;
1473 throw std::runtime_error(description);
1474 }
1475 if (!(moved.is_type<int>())) {
1476 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moved.is_type<int>())";
1477 std::cout << std::string("[FAIL] ") + description << std::endl;
1478 throw std::runtime_error(description);
1479 }
object (np_test_1_all.cpp:1469)
1459 std::cout << std::string("[FAIL] ") + description << std::endl;
1460 throw std::runtime_error(description);
1461 }
1462 if (!(*assigned.get_as<int>() == 42)) {
1463 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*assigned.get_as<int>() == 42)";
1464 std::cout << std::string("[FAIL] ") + description << std::endl;
1465 throw std::runtime_error(description);
1466 }
1467
1468 // Test move constructor
1469 object_ moved(std::move(object_(100)));
1470 if (!(!moved.is_null())) {
1471 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!moved.is_null())";
1472 std::cout << std::string("[FAIL] ") + description << std::endl;
1473 throw std::runtime_error(description);
1474 }
1475 if (!(moved.is_type<int>())) {
1476 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moved.is_type<int>())";
1477 std::cout << std::string("[FAIL] ") + description << std::endl;
1478 throw std::runtime_error(description);
1479 }
object (np_test_1_all.cpp:1469)
1459 std::cout << std::string("[FAIL] ") + description << std::endl;
1460 throw std::runtime_error(description);
1461 }
1462 if (!(*assigned.get_as<int>() == 42)) {
1463 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*assigned.get_as<int>() == 42)";
1464 std::cout << std::string("[FAIL] ") + description << std::endl;
1465 throw std::runtime_error(description);
1466 }
1467
1468 // Test move constructor
1469 object_ moved(std::move(object_(100)));
1470 if (!(!moved.is_null())) {
1471 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!moved.is_null())";
1472 std::cout << std::string("[FAIL] ") + description << std::endl;
1473 throw std::runtime_error(description);
1474 }
1475 if (!(moved.is_type<int>())) {
1476 std::string description = std::string("testObjectCopyAndAssignment():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moved.is_type<int>())";
1477 std::cout << std::string("[FAIL] ") + description << std::endl;
1478 throw std::runtime_error(description);
1479 }
get_as (np_test_1_all.cpp:1363)
1353 if (!(!int_obj.is_null())) {
1354 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!int_obj.is_null())";
1355 std::cout << std::string("[FAIL] ") + description << std::endl;
1356 throw std::runtime_error(description);
1357 }
1358 if (!(int_obj.is_type<int>())) {
1359 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(int_obj.is_type<int>())";
1360 std::cout << std::string("[FAIL] ") + description << std::endl;
1361 throw std::runtime_error(description);
1362 }
1363 if (!(*int_obj.get_as<int>() == 42)) {
1364 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*int_obj.get_as<int>() == 42)";
1365 std::cout << std::string("[FAIL] ") + description << std::endl;
1366 throw std::runtime_error(description);
1367 }
1368
1369 // Test string construction
1370 object_ str_obj(std::string("hello"));
1371 if (!(!str_obj.is_null())) {
1372 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!str_obj.is_null())";
1373 std::cout << std::string("[FAIL] ") + description << std::endl;
get_as (np_test_1_all.cpp:1363)
1353 if (!(!int_obj.is_null())) {
1354 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!int_obj.is_null())";
1355 std::cout << std::string("[FAIL] ") + description << std::endl;
1356 throw std::runtime_error(description);
1357 }
1358 if (!(int_obj.is_type<int>())) {
1359 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(int_obj.is_type<int>())";
1360 std::cout << std::string("[FAIL] ") + description << std::endl;
1361 throw std::runtime_error(description);
1362 }
1363 if (!(*int_obj.get_as<int>() == 42)) {
1364 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*int_obj.get_as<int>() == 42)";
1365 std::cout << std::string("[FAIL] ") + description << std::endl;
1366 throw std::runtime_error(description);
1367 }
1368
1369 // Test string construction
1370 object_ str_obj(std::string("hello"));
1371 if (!(!str_obj.is_null())) {
1372 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!str_obj.is_null())";
1373 std::cout << std::string("[FAIL] ") + description << std::endl;
abs (np_test_1_all.cpp:101)
91 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) {
92 for (size_t i = 0; i < arr.getShape()[0]; ++i) {
93 // std::cout << static_cast<int64_t>(arr.getElementAt({i})) << " ";
94 }
95 }
96 // std::cout << std::endl;
97 }
98
99 // Helper function for core array extensions tests
100 bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) {
101 return std::abs(a - b) < tolerance;
102 }
103}
104
105void f_nothing() {
106 // This function does nothing and tests nothing
107 // It's a placeholder test function
108}
109
110// ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 --------------------------------
to_string (np_test_1_all.cpp:454)
444 // Modify through different views
445 view1.setElementAt({0, 0}, 100);
446 view2.setElementAt({2, 1}, 200); // This is (1, 2) in original
447 view3.setElementAt({0, 0}, 300); // This is (1, 1) in original
448
449 // std::cout << "After modifications through multiple views:" << std::endl;
450 //original.printArray();
451
452 // Verify all changes are reflected
453 if (!(original.getElementAt({0, 0}) == 100)) {
454 std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)";
455 std::cout << std::string("[FAIL] ") + description << std::endl;
456 throw std::runtime_error(description);
457 }
458 if (!(original.getElementAt({1, 2}) == 200)) {
459 std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)";
460 std::cout << std::string("[FAIL] ") + description << std::endl;
461 throw std::runtime_error(description);
462 }
463 if (!(original.getElementAt({1, 1}) == 300)) {
464 std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)";
is_array (np_test_1_all.cpp:1395)
1385 }
1386
1387 // Test NDArray construction
1388 NDArray<double> arr({2, 2}, 3.14);
1389 object_ arr_obj(arr);
1390 if (!(!arr_obj.is_null())) {
1391 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!arr_obj.is_null())";
1392 std::cout << std::string("[FAIL] ") + description << std::endl;
1393 throw std::runtime_error(description);
1394 }
1395 if (!(arr_obj.is_array())) {
1396 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr_obj.is_array())";
1397 std::cout << std::string("[FAIL] ") + description << std::endl;
1398 throw std::runtime_error(description);
1399 }
1400 if (!(arr_obj.is_type<NDArray<double>>())) {
1401 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr_obj.is_type<NDArray<double>>())";
1402 std::cout << std::string("[FAIL] ") + description << std::endl;
1403 throw std::runtime_error(description);
1404 }
is_floating (np_test_3_all.cpp:21656)
21646 CHECK(int_obj.is_numeric(), "np_test_object_arith_type_queries", "int should be numeric");
21647 CHECK(dbl_obj.is_numeric(), "np_test_object_arith_type_queries", "dbl should be numeric");
21648 CHECK(!str_obj.is_numeric(), "np_test_object_arith_type_queries", "str should not be numeric");
21649 CHECK(!null_obj.is_numeric(), "np_test_object_arith_type_queries", "null should not be numeric");
21650
21651 CHECK(int_obj.is_integral(), "np_test_object_arith_type_queries", "int should be integral");
21652 CHECK(!dbl_obj.is_integral(), "np_test_object_arith_type_queries", "dbl should not be integral");
21653 CHECK(!str_obj.is_integral(), "np_test_object_arith_type_queries", "str should not be integral");
21654
21655 CHECK(!int_obj.is_floating(), "np_test_object_arith_type_queries", "int should not be floating");
21656 CHECK(dbl_obj.is_floating(), "np_test_object_arith_type_queries", "dbl should be floating");
21657 CHECK(!str_obj.is_floating(), "np_test_object_arith_type_queries", "str should not be floating");
21658
21659 CHECK(!int_obj.is_string(), "np_test_object_arith_type_queries", "int should not be string");
21660 CHECK(!dbl_obj.is_string(), "np_test_object_arith_type_queries", "dbl should not be string");
21661 CHECK(str_obj.is_string(), "np_test_object_arith_type_queries", "str should be string");
21662
21663 std::cout << " -> tests passed" << std::endl;
21664}
is_hashable (np_test_3_all.cpp:21836)
21826}
21827
21828void np_test_object_mixed_hash_compare() {
21829 std::cout << "========= object_ hash and comparison ====" ;
21830
21831 numpy::object_ a(10);
21832 numpy::object_ b(20);
21833 numpy::object_ c(10);
21834
21835 // Hashable check
21836 CHECK(a.is_hashable(), "np_test_object_mixed_hash_compare", "a is_hashable failed");
21837 CHECK(b.is_hashable(), "np_test_object_mixed_hash_compare", "b is_hashable failed");
21838
21839 // Hash values
21840 CHECK(a.hash() == c.hash(), "np_test_object_mixed_hash_compare", "hash equality failed");
21841 CHECK(a.hash() != b.hash(), "np_test_object_mixed_hash_compare", "hash inequality failed");
21842
21843 // Sortable check
21844 CHECK(a.is_sortable(), "np_test_object_mixed_hash_compare", "a is_sortable failed");
21845 CHECK(b.is_sortable(), "np_test_object_mixed_hash_compare", "b is_sortable failed");
is_integral (np_test_3_all.cpp:21652)
21642 numpy::object_ int_obj(5);
21643 numpy::object_ dbl_obj(3.14);
21644 numpy::object_ str_obj(std::string("hello"));
21645 numpy::object_ null_obj;
21646
21647 CHECK(int_obj.is_numeric(), "np_test_object_arith_type_queries", "int should be numeric");
21648 CHECK(dbl_obj.is_numeric(), "np_test_object_arith_type_queries", "dbl should be numeric");
21649 CHECK(!str_obj.is_numeric(), "np_test_object_arith_type_queries", "str should not be numeric");
21650 CHECK(!null_obj.is_numeric(), "np_test_object_arith_type_queries", "null should not be numeric");
21651
21652 CHECK(int_obj.is_integral(), "np_test_object_arith_type_queries", "int should be integral");
21653 CHECK(!dbl_obj.is_integral(), "np_test_object_arith_type_queries", "dbl should not be integral");
21654 CHECK(!str_obj.is_integral(), "np_test_object_arith_type_queries", "str should not be integral");
21655
21656 CHECK(!int_obj.is_floating(), "np_test_object_arith_type_queries", "int should not be floating");
21657 CHECK(dbl_obj.is_floating(), "np_test_object_arith_type_queries", "dbl should be floating");
21658 CHECK(!str_obj.is_floating(), "np_test_object_arith_type_queries", "str should not be floating");
21659
21660 CHECK(!int_obj.is_string(), "np_test_object_arith_type_queries", "int should not be string");
21661 CHECK(!dbl_obj.is_string(), "np_test_object_arith_type_queries", "dbl should not be string");
21662 CHECK(str_obj.is_string(), "np_test_object_arith_type_queries", "str should be string");
is_null (np_test_1_all.cpp:1345)
1335 std::cout << " -> tests passed" << std::endl;
1336}
1337
1338// Object array test functions
1339void testObjectConstruction() {
1340 std::cout << "========= testObjectConstruction =======================";
1341
1342 // Test default constructor
1343 object_ empty_obj;
1344 if (!(empty_obj.is_null())) {
1345 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(empty_obj.is_null())";
1346 std::cout << std::string("[FAIL] ") + description << std::endl;
1347 throw std::runtime_error(description);
1348 }
1349
1350 // Test primitive type construction
1351 object_ int_obj(42);
1352 if (!(!int_obj.is_null())) {
1353 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!int_obj.is_null())";
1354 std::cout << std::string("[FAIL] ") + description << std::endl;
is_numeric (np_test_1_all.cpp:7511)
7501 std::cout << " -> tests passed" << std::endl;
7502}
7503
7504void testNumericConversionStringTypes() {
7505 std::cout << "========= testNumericStringOperationsStringTypes =======================";
7506
7507 str32 num_str1("123.45");
7508 str32 num_str2("67.89");
7509 str32 not_num("hello");
7510
7511 // std::cout << "String '" << num_str1 << "' is numeric: " << is_numeric(num_str1) << std::endl;
7512 // std::cout << "String '" << not_num << "' is numeric: " << is_numeric(not_num) << std::endl;
7513
7514 if (is_numeric(num_str1)) {
7515 double val1 = to_numeric(num_str1);
7516 // std::cout << "Numeric value of '" << num_str1 << "': " << val1 << std::endl;
7517 }
7518
7519 if (is_numeric(num_str2)) {
7520 double val2 = to_numeric(num_str2);
7521 // std::cout << "Numeric value of '" << num_str2 << "': " << val2 << std::endl;
is_sortable (np_test_3_all.cpp:21844)
21834 // Hashable check
21835 CHECK(a.is_hashable(), "np_test_object_mixed_hash_compare", "a is_hashable failed");
21836 CHECK(b.is_hashable(), "np_test_object_mixed_hash_compare", "b is_hashable failed");
21837
21838 // Hash values
21839 CHECK(a.hash() == c.hash(), "np_test_object_mixed_hash_compare", "hash equality failed");
21840 CHECK(a.hash() != b.hash(), "np_test_object_mixed_hash_compare", "hash inequality failed");
21841
21842 // Sortable check
21843 CHECK(a.is_sortable(), "np_test_object_mixed_hash_compare", "a is_sortable failed");
21844 CHECK(b.is_sortable(), "np_test_object_mixed_hash_compare", "b is_sortable failed");
21845
21846 // Comparison
21847 CHECK(a < b, "np_test_object_mixed_hash_compare", "a < b failed");
21848 CHECK(b > a, "np_test_object_mixed_hash_compare", "b > a failed");
21849 CHECK(a == c, "np_test_object_mixed_hash_compare", "a == c failed");
21850 CHECK(a != b, "np_test_object_mixed_hash_compare", "a != b failed");
21851
21852 std::cout << " -> tests passed" << std::endl;
21853}
is_string (np_test_3_all.cpp:21660)
21650 CHECK(!null_obj.is_numeric(), "np_test_object_arith_type_queries", "null should not be numeric");
21651
21652 CHECK(int_obj.is_integral(), "np_test_object_arith_type_queries", "int should be integral");
21653 CHECK(!dbl_obj.is_integral(), "np_test_object_arith_type_queries", "dbl should not be integral");
21654 CHECK(!str_obj.is_integral(), "np_test_object_arith_type_queries", "str should not be integral");
21655
21656 CHECK(!int_obj.is_floating(), "np_test_object_arith_type_queries", "int should not be floating");
21657 CHECK(dbl_obj.is_floating(), "np_test_object_arith_type_queries", "dbl should be floating");
21658 CHECK(!str_obj.is_floating(), "np_test_object_arith_type_queries", "str should not be floating");
21659
21660 CHECK(!int_obj.is_string(), "np_test_object_arith_type_queries", "int should not be string");
21661 CHECK(!dbl_obj.is_string(), "np_test_object_arith_type_queries", "dbl should not be string");
21662 CHECK(str_obj.is_string(), "np_test_object_arith_type_queries", "str should be string");
21663
21664 std::cout << " -> tests passed" << std::endl;
21665}
21666
21667void np_test_object_arith_promote_helper() {
21668 std::cout << "========= promoteType helper ====" ;
21669
21670 numpy::object_ int_obj(5);
is_type (np_test_1_all.cpp:1358)
1348 throw std::runtime_error(description);
1349 }
1350
1351 // Test primitive type construction
1352 object_ int_obj(42);
1353 if (!(!int_obj.is_null())) {
1354 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!int_obj.is_null())";
1355 std::cout << std::string("[FAIL] ") + description << std::endl;
1356 throw std::runtime_error(description);
1357 }
1358 if (!(int_obj.is_type<int>())) {
1359 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(int_obj.is_type<int>())";
1360 std::cout << std::string("[FAIL] ") + description << std::endl;
1361 throw std::runtime_error(description);
1362 }
1363 if (!(*int_obj.get_as<int>() == 42)) {
1364 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*int_obj.get_as<int>() == 42)";
1365 std::cout << std::string("[FAIL] ") + description << std::endl;
1366 throw std::runtime_error(description);
1367 }
hash (np_test_3_all.cpp:21840)
21830 numpy::object_ a(10);
21831 numpy::object_ b(20);
21832 numpy::object_ c(10);
21833
21834 // Hashable check
21835 CHECK(a.is_hashable(), "np_test_object_mixed_hash_compare", "a is_hashable failed");
21836 CHECK(b.is_hashable(), "np_test_object_mixed_hash_compare", "b is_hashable failed");
21837
21838 // Hash values
21839 CHECK(a.hash() == c.hash(), "np_test_object_mixed_hash_compare", "hash equality failed");
21840 CHECK(a.hash() != b.hash(), "np_test_object_mixed_hash_compare", "hash inequality failed");
21841
21842 // Sortable check
21843 CHECK(a.is_sortable(), "np_test_object_mixed_hash_compare", "a is_sortable failed");
21844 CHECK(b.is_sortable(), "np_test_object_mixed_hash_compare", "b is_sortable failed");
21845
21846 // Comparison
21847 CHECK(a < b, "np_test_object_mixed_hash_compare", "a < b failed");
21848 CHECK(b > a, "np_test_object_mixed_hash_compare", "b > a failed");
21849 CHECK(a == c, "np_test_object_mixed_hash_compare", "a == c failed");
incrementIndices (np_test_1_all.cpp:52)
42// Helper functions for array comparison tests
43namespace {
44 const double TOLERANCE = 1e-10;
45
46 bool allTrue(const NDArray<bool>& arr) {
47 std::vector<size_t> indices(arr.getShape().size(), 0);
48 do {
49 if (!arr.getElementAt(indices)) {
50 return false;
51 }
52 } while (incrementIndices(indices, arr.getShape()));
53 return true;
54 }
55
56 bool allFalse(const NDArray<bool>& arr) {
57 std::vector<size_t> indices(arr.getShape().size(), 0);
58 do {
59 if (arr.getElementAt(indices)) {
60 return false;
61 }
62 } while (incrementIndices(indices, arr.getShape()));