DataFrame#
-
class numpy::DataFrame#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use DataFrame
DataFrame obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
df_dataframe.h:381 |
|
|
df_dataframe.h:433 |
|
|
df_dataframe.h:492 |
|
|
df_dataframe.h:543 |
|
|
df_dataframe.h:558 |
Construction#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_dataframe.h:18160 |
|
|
DataFrame |
df_dataframe.h:18339 |
|
|
DataFrame |
df_dataframe.h:18288 |
|
|
DataFrame |
df_dataframe.h:18388 |
|
|
DataFrame |
df_dataframe.h:18573 |
|
|
DataFrame |
df_dataframe.h:18716 |
|
|
oss << |
df_dataframe.h:17976 |
|
|
oss << |
df_dataframe.h:17991 |
|
|
oss << |
df_dataframe.h:18012 |
Array Creation#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
df_dataframe.h:616 |
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
T |
df_dataframe.h:1659 |
|
|
DataFrame |
df_dataframe.h:12177 |
|
|
const Attrs& |
df_dataframe.h:750 |
|
|
Attrs& |
df_dataframe.h:757 |
|
|
std::optional<ReturnType> |
df_dataframe.h:6165 |
|
|
size_t |
df_dataframe.h:1494 |
|
|
std::vector<double> |
df_dataframe.h:10357 |
|
|
size_t |
df_dataframe.h:8009 |
|
|
std::optional<const NDFrameBase*> |
df_dataframe.h:2398 |
|
|
size_t |
df_dataframe.h:22250 |
|
|
bool |
df_dataframe.h:3287 |
|
|
std::string |
df_dataframe.h:22137 |
|
|
ItemsRange |
df_dataframe.h:1045 |
|
|
DataFrame |
df_dataframe.h:2623 |
|
|
DataFrame |
df_dataframe.h:1720 |
|
|
DataFrame |
df_dataframe.h:3564 |
Shape Manipulation#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_dataframe.h:685 |
|
|
DataFrame |
df_dataframe.h:8673 |
|
|
DataFrame |
df_dataframe.h:6201 |
|
|
DataFrame |
df_dataframe.h:7426 |
Statistics#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_dataframe.h:6763 |
|
|
Series<numpy::float64> |
df_dataframe.h:5481 |
|
|
Series<numpy::float64> |
df_dataframe.h:4383 |
|
|
Series<numpy::float64> |
df_dataframe.h:5314 |
|
|
Series<numpy::float64> |
df_dataframe.h:4322 |
|
|
Series<numpy::float64> |
df_dataframe.h:4849 |
|
|
Series<numpy::float64> |
df_dataframe.h:4801 |
|
|
Series<numpy::float64> |
df_dataframe.h:5438 |
|
|
Series<numpy::float64> |
df_dataframe.h:4353 |
|
|
Series<numpy::float64> |
df_dataframe.h:5685 |
|
|
Series<numpy::float64> |
df_dataframe.h:6681 |
|
|
Series<numpy::float64> |
df_dataframe.h:5357 |
|
|
Series<numpy::float64> |
df_dataframe.h:4599 |
|
|
Series<numpy::float64> |
df_dataframe.h:5274 |
|
|
Series<numpy::float64> |
df_dataframe.h:4293 |
|
|
Series<numpy::float64> |
df_dataframe.h:5405 |
|
|
Series<numpy::float64> |
df_dataframe.h:4637 |
Sorting#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_dataframe.h:7326 |
|
|
DataFrame |
df_dataframe.h:7290 |
|
|
DataFrame |
df_dataframe.h:7297 |
Math Operations#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_dataframe.h:9252 |
|
|
DataFrame |
df_dataframe.h:8958 |
|
|
DataFrame |
df_dataframe.h:8962 |
|
|
void |
df_dataframe.h:2466 |
|
|
DataFrame |
df_dataframe.h:2317 |
|
|
df_dataframe.h:15159 |
||
|
df_dataframe.h:15163 |
||
|
df_dataframe.h:15172 |
||
|
df_dataframe.h:15179 |
||
|
df_dataframe.h:15182 |
||
|
DataFrame |
df_dataframe.h:2362 |
|
|
df_dataframe.h:15216 |
||
|
df_dataframe.h:15224 |
||
|
df_dataframe.h:15234 |
||
|
df_dataframe.h:15245 |
||
|
df_dataframe.h:15257 |
||
|
df_dataframe.h:15268 |
||
|
df_dataframe.h:15388 |
||
|
DataFrame |
df_dataframe.h:9245 |
|
|
DataFrame |
df_dataframe.h:9007 |
|
|
DataFrameExpanding |
df_dataframe.h:5971 |
|
|
DataFrame |
df_dataframe.h:8613 |
|
|
DataFrame |
df_dataframe.h:9238 |
|
|
DataFrame |
df_dataframe.h:9022 |
|
|
DataFrame |
df_dataframe.h:9026 |
|
|
DataFrame |
df_dataframe.h:9033 |
|
|
DataFrame |
df_dataframe.h:9037 |
|
|
* Returns a DataFrame where each column contains the |
df_dataframe.h:4903 |
|
|
DataFrame |
df_dataframe.h:4912 |
|
|
DataFrame |
df_dataframe.h:4931 |
|
|
DataFrame |
df_dataframe.h:5067 |
|
|
DataFrame |
df_dataframe.h:8992 |
|
|
DataFrame |
df_dataframe.h:9228 |
|
|
DataFrame |
df_dataframe.h:8977 |
|
|
DataFrame |
df_dataframe.h:12215 |
Linear Algebra#
Random#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_dataframe.h:1694 |
|
|
DataFrame |
df_dataframe.h:1712 |
Comparison#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
df_dataframe.h:4193 |
Logical#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
df_dataframe.h:11025 |
|
|
Series<numpy::bool_> |
df_dataframe.h:11053 |
|
|
bool |
df_dataframe.h:11035 |
|
|
Series<numpy::bool_> |
df_dataframe.h:11175 |
Set Operations#
I/O#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
df_dataframe.h:17591 |
|
|
std::string |
df_dataframe.h:12336 |
|
|
std::map<std::string, std::vector<std::string>> |
df_dataframe.h:12669 |
|
|
std::map<std::string, std::map<std::string, std::string>> |
df_dataframe.h:12714 |
|
|
std::map<std::string, std::map<std::string, std::string>> |
df_dataframe.h:12800 |
|
|
std::vector<std::map<std::string, std::string>> |
df_dataframe.h:12753 |
|
|
std::map<std::string, std::unique_ptr<NDFrameBase>> |
df_dataframe.h:12954 |
|
|
DictSplitResult |
df_dataframe.h:12840 |
|
|
DictTightResult |
df_dataframe.h:12899 |
|
|
void |
df_dataframe.h:15022 |
|
|
* This is the inverse operation of |
df_dataframe.h:19062 |
|
|
* This is the inverse operation of |
df_dataframe.h:20763 |
|
|
std::vector<uint8_t> |
df_dataframe.h:20934 |
|
|
void |
df_dataframe.h:6255 |
|
|
std::vector<uint8_t> |
df_dataframe.h:14419 |
|
|
* Reads a file written by |
df_dataframe.h:19928 |
|
|
* This is the inverse operation of |
df_dataframe.h:19929 |
|
|
std::string |
df_dataframe.h:15603 |
|
|
std::string |
df_dataframe.h:12367 |
|
|
std::string |
df_dataframe.h:15983 |
|
|
std::string |
df_dataframe.h:17799 |
|
|
numpy::NDArray<numpy::float64> |
df_dataframe.h:6218 |
|
|
std::vector<uint8_t> |
df_dataframe.h:13005 |
|
|
std::vector<uint8_t> |
df_dataframe.h:13568 |
|
|
* This is the inverse operation of |
df_dataframe.h:19474 |
|
|
* (use |
df_dataframe.h:20912 |
|
|
DataFrame |
df_dataframe.h:12013 |
|
|
std::vector<uint8_t> |
df_dataframe.h:14213 |
|
|
numpy::RecordArray |
df_dataframe.h:16347 |
|
|
std::vector<std::map<std::string, std::string>> |
df_dataframe.h:20867 |
|
|
std::optional<int64_t> |
df_dataframe.h:14659 |
|
|
* Reads a SQLite database file created by |
df_dataframe.h:20155 |
|
|
* This parses the SQL file format generated by |
df_dataframe.h:20156 |
|
|
* generated by |
df_dataframe.h:20176 |
|
|
std::vector<uint8_t> |
df_dataframe.h:16620 |
|
|
* This is the inverse operation of |
df_dataframe.h:20373 |
|
|
* If false, write a string representation (similar to |
df_dataframe.h:17544 |
|
|
std::string |
df_dataframe.h:22164 |
|
|
std::vector<std::string> |
df_dataframe.h:22150 |
|
|
DataFrame |
df_dataframe.h:12054 |
|
|
Dataset |
df_dataframe.h:21983 |
|
|
std::string |
df_dataframe.h:6278 |
Joining / Splitting#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
df_dataframe.h:2434 |
|
|
df_dataframe.h:2467 |
||
|
DataFrame |
df_dataframe.h:8694 |
Type Handling#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_dataframe.h:9622 |
|
|
DataFrame |
df_dataframe.h:9644 |
|
|
DataFrame |
df_dataframe.h:12317 |
|
|
df_dataframe.h:17639 |
||
|
static void |
df_dataframe.h:17648 |
|
|
void |
df_dataframe.h:3336 |
Special Functions#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_dataframe.h:11622 |
|
|
DataFrame |
df_dataframe.h:11738 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static bool |
df_dataframe.h:9861 |
|
|
static bool |
df_dataframe.h:9906 |
|
|
static bool |
df_dataframe.h:9887 |
|
|
bool |
df_dataframe.h:785 |
|
|
static bool |
df_dataframe.h:9869 |
|
|
bool |
df_dataframe.h:3252 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
* DataFrame |
df_dataframe.h:8801 |
|
|
* DataFrame |
df_dataframe.h:8859 |
|
|
* DataFrame |
df_dataframe.h:8802 |
|
|
* Reads an |
df_dataframe.h:19061 |
|
|
* Reads a |
df_dataframe.h:20762 |
|
|
* Hierarchical Data |
df_dataframe.h:14344 |
|
|
df_dataframe.h:17672 |
||
|
df_dataframe.h:17682 |
||
|
df_dataframe.h:17678 |
||
|
* The Series has a |
df_dataframe.h:6464 |
|
|
* Writes the DataFrame to an Excel file in the Office Open |
df_dataframe.h:14963 |
|
|
DataFrame |
df_dataframe.h:10908 |
|
|
DataFrame |
df_dataframe.h:10968 |
|
|
DataFrame |
df_dataframe.h:10998 |
|
|
DataFrame |
df_dataframe.h:11005 |
|
|
std::pair<DataFrame, DataFrame> |
df_dataframe.h:11556 |
|
|
* If empty, uses default |
df_dataframe.h:17748 |
|
|
DataFrame |
df_dataframe.h:9473 |
|
|
std::vector<double> |
df_dataframe.h:10375 |
|
|
DataFrame |
df_dataframe.h:9515 |
|
|
std::istringstream |
df_dataframe.h:18980 |
|
|
DataFrame |
df_dataframe.h:11966 |
|
|
Series<numpy::float64> |
df_dataframe.h:12260 |
|
|
DataFrame |
df_dataframe.h:12266 |
|
|
DataFrame |
df_dataframe.h:4253 |
|
|
std::vector<const IndexBase*> |
df_dataframe.h:706 |
|
|
numpy::NDArray<numpy::float64> |
df_dataframe.h:8882 |
|
|
DataFrame |
df_dataframe.h:6012 |
|
|
iterator |
df_dataframe.h:888 |
|
|
const_iterator |
df_dataframe.h:892 |
|
|
DataFrame |
df_dataframe.h:12190 |
|
|
DataFrame |
df_dataframe.h:12205 |
|
|
DataFrame |
df_dataframe.h:2897 |
|
|
DataFrame |
df_dataframe.h:22262 |
|
|
DataFrame |
df_dataframe.h:22407 |
|
|
bool |
df_dataframe.h:6079 |
|
|
const_iterator |
df_dataframe.h:896 |
|
|
const_iterator |
df_dataframe.h:912 |
|
|
std::ifstream |
df_dataframe.h:14575 |
|
|
std::ifstream |
df_dataframe.h:14691 |
|
|
void |
df_dataframe.h:22233 |
|
|
DataFrame |
df_dataframe.h:9259 |
|
|
std::unique_ptr<NDFrameBase> |
df_dataframe.h:12325 |
|
|
numpy::NDArray<numpy::int64> |
df_dataframe.h:6657 |
|
|
Series<T>& |
df_dataframe.h:1467 |
|
|
const Series<T>& |
df_dataframe.h:1481 |
|
|
std::istringstream |
df_dataframe.h:20211 |
|
|
* Counts the number of unique (distinct) values per |
df_dataframe.h:6396 |
|
|
* Apply a named transform function to each |
df_dataframe.h:10681 |
|
|
const Index<std::string>& |
df_dataframe.h:692 |
|
|
* Data |
df_dataframe.h:12432 |
|
|
std::vector<std::vector<std::string>> |
df_dataframe.h:18836 |
|
|
std::vector<std::vector<std::string>> |
df_dataframe.h:19406 |
|
|
std::vector<std::vector<std::string>> |
df_dataframe.h:20303 |
|
|
DataFrame |
df_dataframe.h:11832 |
|
|
DataFrame |
df_dataframe.h:22376 |
|
|
static DataFrame |
df_dataframe.h:11278 |
|
|
DataFrame |
df_dataframe.h:22493 |
|
|
DataFrame |
df_dataframe.h:10058 |
|
|
* Unlike |
df_dataframe.h:10183 |
|
|
static numpy::bool_ |
df_dataframe.h:9829 |
|
|
static numpy::float64 |
df_dataframe.h:9795 |
|
|
static numpy::int64 |
df_dataframe.h:9767 |
|
|
DataFrame |
df_dataframe.h:6722 |
|
|
Series<numpy::float64> |
df_dataframe.h:6809 |
|
|
Series<numpy::float64> |
df_dataframe.h:7105 |
|
|
size_t |
df_dataframe.h:2756 |
|
|
Series<numpy::int64> |
df_dataframe.h:4653 |
|
|
DataFrame |
df_dataframe.h:9367 |
|
|
DataFrame |
df_dataframe.h:9336 |
|
|
DataFrame |
df_dataframe.h:9305 |
|
|
DataFrame |
df_dataframe.h:9274 |
|
|
DataArray<numpy::float64> |
df_dataframe.h:22054 |
|
|
DataArray<numpy::int64> |
df_dataframe.h:22065 |
|
|
DataArray<numpy::int32> |
df_dataframe.h:22076 |
|
|
DataArray<numpy::float32> |
df_dataframe.h:22087 |
|
|
DataArray<bool> |
df_dataframe.h:22098 |
|
|
DataArray<std::string> |
df_dataframe.h:22110 |
|
|
DataArray<std::string> |
df_dataframe.h:22120 |
|
|
numpy::NDArray<numpy::float64> |
df_dataframe.h:22050 |
|
|
numpy::NDArray<numpy::int64> |
df_dataframe.h:22061 |
|
|
numpy::NDArray<numpy::int32> |
df_dataframe.h:22072 |
|
|
numpy::NDArray<numpy::float32> |
df_dataframe.h:22083 |
|
|
numpy::NDArray<bool> |
df_dataframe.h:22094 |
|
|
numpy::NDArray<std::string> |
df_dataframe.h:22106 |
|
|
numpy::NDArray<std::string> |
df_dataframe.h:22116 |
|
|
DataFrame |
df_dataframe.h:4670 |
|
|
* DataFrame |
df_dataframe.h:880 |
|
|
* DataFrame |
df_dataframe.h:924 |
|
|
* DataFrame |
df_dataframe.h:1030 |
|
|
* DataFrame |
df_dataframe.h:1169 |
|
|
* DataFrame |
df_dataframe.h:1379 |
|
|
* DataFrame |
df_dataframe.h:1761 |
|
|
* DataFrame |
df_dataframe.h:3401 |
|
|
* DataFrame |
df_dataframe.h:3451 |
|
|
* DataFrame |
df_dataframe.h:3558 |
|
|
* DataFrame |
df_dataframe.h:3611 |
|
|
* DataFrame |
df_dataframe.h:3665 |
|
|
* DataFrame |
df_dataframe.h:3804 |
|
|
* DataFrame |
df_dataframe.h:6468 |
|
|
* DataFrame |
df_dataframe.h:10049 |
|
|
* DataFrame |
df_dataframe.h:10196 |
|
|
* DataFrame |
df_dataframe.h:12655 |
|
|
* DataFrame |
df_dataframe.h:12705 |
|
|
* DataFrame |
df_dataframe.h:12745 |
|
|
* DataFrame |
df_dataframe.h:12791 |
|
|
* DataFrame |
df_dataframe.h:12831 |
|
|
* DataFrame |
df_dataframe.h:12886 |
|
|
* DataFrame |
df_dataframe.h:12946 |
|
|
* DataFrame |
df_dataframe.h:16322 |
|
|
* pandas::DataFrame |
df_dataframe.h:17560 |
|
|
* DataFrame |
df_dataframe.h:17760 |
|
|
* DataFrame |
df_dataframe.h:21973 |
|
|
* DataFrame |
df_dataframe.h:22462 |
|
|
* Converts a sequence of |
df_dataframe.h:18539 |
|
|
DataFrame |
df_dataframe.h:9398 |
|
|
DataFrame |
df_dataframe.h:8999 |
|
|
DataFrame |
df_dataframe.h:9003 |
|
|
DataFrame |
df_dataframe.h:2542 |
|
|
DataFrame |
df_dataframe.h:4117 |
|
|
void |
df_dataframe.h:2551 |
|
|
static std::string |
df_dataframe.h:7673 |
|
|
DataFrame |
df_dataframe.h:7483 |
|
|
DataFrame |
df_dataframe.h:7500 |
|
|
DataFrame |
df_dataframe.h:7522 |
|
|
DataFrame |
df_dataframe.h:7544 |
|
|
DataFrame |
df_dataframe.h:7617 |
|
|
DataFrame |
df_dataframe.h:7567 |
|
|
DataFrame |
df_dataframe.h:2767 |
|
|
* DatetimeIndex |
df_dataframe.h:11998 |
|
|
* DatetimeIndex |
df_dataframe.h:12146 |
|
|
std::string |
df_dataframe.h:649 |
|
|
Series<std::string> |
df_dataframe.h:713 |
|
|
Series<numpy::bool_> |
df_dataframe.h:4050 |
|
|
iterator |
df_dataframe.h:904 |
|
|
const_iterator |
df_dataframe.h:908 |
|
|
* Provides begin() and |
df_dataframe.h:1002 |
|
|
* Provides begin() and |
df_dataframe.h:1132 |
|
|
* Provides begin() and |
df_dataframe.h:1336 |
|
|
DataFrame |
df_dataframe.h:8912 |
|
|
df_dataframe.h:15725 |
||
|
oss << |
df_dataframe.h:16190 |
|
|
oss << |
df_dataframe.h:16202 |
|
|
oss << |
df_dataframe.h:16220 |
|
|
oss << |
df_dataframe.h:16230 |
|
|
oss << |
df_dataframe.h:16254 |
|
|
static std::string |
df_dataframe.h:6334 |
|
|
std::variant<Series<numpy::float64>, DataFrame, std::monostate> |
df_dataframe.h:3822 |
|
|
std::vector<double> |
df_dataframe.h:3928 |
|
|
double |
df_dataframe.h:3950 |
|
|
bool |
df_dataframe.h:3736 |
|
|
bool |
df_dataframe.h:3704 |
|
|
df_dataframe.h:3715 |
||
|
df_dataframe.h:3720 |
||
|
DataFrameEWM |
df_dataframe.h:5982 |
|
|
DataFrame |
df_dataframe.h:2811 |
|
|
std::ofstream |
df_dataframe.h:6318 |
|
|
std::ofstream |
df_dataframe.h:13506 |
|
|
std::ofstream |
df_dataframe.h:14149 |
|
|
std::ofstream |
df_dataframe.h:14328 |
|
|
std::ofstream |
df_dataframe.h:14582 |
|
|
std::ofstream |
df_dataframe.h:15502 |
|
|
* std::ofstream |
df_dataframe.h:15562 |
|
|
* std::ofstream |
df_dataframe.h:15958 |
|
|
std::ofstream |
df_dataframe.h:17521 |
|
|
* std::ofstream |
df_dataframe.h:17793 |
|
|
std::ifstream |
df_dataframe.h:19101 |
|
|
std::ifstream |
df_dataframe.h:19500 |
|
|
std::ifstream |
df_dataframe.h:19955 |
|
|
std::ifstream |
df_dataframe.h:20187 |
|
|
std::ifstream |
df_dataframe.h:20399 |
|
|
std::ifstream |
df_dataframe.h:20789 |
|
|
std::ofstream |
df_dataframe.h:21935 |
|
|
DataFrame |
df_dataframe.h:3512 |
|
|
DataFrame |
df_dataframe.h:3523 |
|
|
void |
df_dataframe.h:3265 |
|
|
DataFrame |
df_dataframe.h:6103 |
|
|
DataFrame |
df_dataframe.h:1727 |
|
|
DataFrame |
df_dataframe.h:1734 |
|
|
DataFrame |
df_dataframe.h:12223 |
|
|
std::optional<std::string> |
df_dataframe.h:6030 |
|
|
const Flags& |
df_dataframe.h:771 |
|
|
insert_sql << |
df_dataframe.h:14878 |
|
|
insert_sql << |
df_dataframe.h:14885 |
|
|
insert_sql << |
df_dataframe.h:14908 |
|
|
insert_sql << |
df_dataframe.h:14915 |
|
|
oss << |
df_dataframe.h:16265 |
|
|
std::string |
df_dataframe.h:20418 |
|
|
std::string |
df_dataframe.h:20428 |
|
|
DataFrame |
df_dataframe.h:8947 |
|
|
std::mt19937 |
df_dataframe.h:1700 |
|
|
DataFrameGroupBy |
df_dataframe.h:11908 |
|
|
DataFrameGroupBy |
df_dataframe.h:11921 |
|
|
DataFrame |
df_dataframe.h:8940 |
|
|
bool |
df_dataframe.h:22237 |
|
|
bool |
df_dataframe.h:1505 |
|
|
bool |
df_dataframe.h:2746 |
|
|
DataFrame |
df_dataframe.h:1678 |
|
|
* Can also be a list of strings to use as column |
df_dataframe.h:14974 |
|
|
T |
df_dataframe.h:1667 |
|
|
numpy::NDArray<numpy::int64> |
df_dataframe.h:22014 |
|
|
numpy::NDArray<numpy::float64> |
df_dataframe.h:22022 |
|
|
Series<std::string> |
df_dataframe.h:4425 |
|
|
Series<std::string> |
df_dataframe.h:4518 |
|
|
T |
df_dataframe.h:1562 |
|
|
DataFrame |
df_dataframe.h:1645 |
|
|
DataFrame |
df_dataframe.h:1631 |
|
|
DataFrame |
df_dataframe.h:1580 |
|
|
DataFrame |
df_dataframe.h:1590 |
|
|
DataFrame |
df_dataframe.h:1601 |
|
|
const IndexBase& |
df_dataframe.h:699 |
|
|
* For hierarchical |
df_dataframe.h:1811 |
|
|
static std::string |
df_dataframe.h:9921 |
|
|
DataFrame |
df_dataframe.h:10206 |
|
|
void |
df_dataframe.h:12442 |
|
|
DataFrame |
df_dataframe.h:2989 |
|
|
df_dataframe.h:3015 |
||
|
void |
df_dataframe.h:3032 |
|
|
df_dataframe.h:3020 |
||
|
void |
df_dataframe.h:3145 |
|
|
void |
df_dataframe.h:6182 |
|
|
numpy::NDArray<numpy::bool_> |
df_dataframe.h:3360 |
|
|
numpy::NDArray<numpy::bool_> |
df_dataframe.h:5994 |
|
|
std::istringstream |
df_dataframe.h:3840 |
|
|
std::istringstream |
df_dataframe.h:7675 |
|
|
std::istringstream |
df_dataframe.h:7710 |
|
|
RowsRange |
df_dataframe.h:1186 |
|
|
* and dtype preservation, consider using |
df_dataframe.h:1068 |
|
|
* preservation, use |
df_dataframe.h:1162 |
|
|
TuplesRange |
df_dataframe.h:1411 |
|
|
DataFrame |
df_dataframe.h:11475 |
|
|
const Index<std::string>& |
df_dataframe.h:933 |
|
|
* Returns a dictionary with five |
df_dataframe.h:12874 |
|
|
Series<numpy::float64> |
df_dataframe.h:5619 |
|
|
Series<numpy::float64> |
df_dataframe.h:4753 |
|
|
Series<numpy::float64> |
df_dataframe.h:5673 |
|
|
* Returns the row |
df_dataframe.h:4413 |
|
|
* Returns the row |
df_dataframe.h:4506 |
|
|
* over the column |
df_dataframe.h:822 |
|
|
DataFrame |
df_dataframe.h:12230 |
|
|
std::optional<std::string> |
df_dataframe.h:6050 |
|
|
DataFrame |
df_dataframe.h:8933 |
|
|
std::vector<std::vector<std::string>> |
df_dataframe.h:6614 |
|
|
* innermost |
df_dataframe.h:7875 |
|
|
T |
df_dataframe.h:1517 |
|
|
DataFrame |
df_dataframe.h:1548 |
|
|
DataFrame |
df_dataframe.h:1526 |
|
|
DataFrame |
df_dataframe.h:1534 |
|
|
DataFrame |
df_dataframe.h:8926 |
|
|
* |
df_dataframe.h:9550 |
|
|
DataFrame |
df_dataframe.h:9562 |
|
|
* This is the inverse of where(): |
df_dataframe.h:3607 |
|
|
DataFrame |
df_dataframe.h:3617 |
|
|
DataFrame |
df_dataframe.h:8538 |
|
|
Series<numpy::int64> |
df_dataframe.h:12552 |
|
|
size_t |
df_dataframe.h:12597 |
|
|
DataFrame |
df_dataframe.h:11311 |
|
|
DataFrame |
df_dataframe.h:11459 |
|
|
DataFrame |
df_dataframe.h:8984 |
|
|
DataFrame |
df_dataframe.h:8988 |
|
|
MultiIndex |
df_dataframe.h:6664 |
|
|
std::string |
df_dataframe.h:19156 |
|
|
* with hierarchical column |
df_dataframe.h:10764 |
|
|
size_t |
df_dataframe.h:637 |
|
|
size_t |
df_dataframe.h:678 |
|
|
size_t |
df_dataframe.h:630 |
|
|
DataFrame |
df_dataframe.h:8919 |
|
|
DataFrame |
df_dataframe.h:7348 |
|
|
numpy::NDArray<numpy::bool_> |
df_dataframe.h:3375 |
|
|
numpy::NDArray<numpy::bool_> |
df_dataframe.h:6002 |
|
|
size_t |
df_dataframe.h:671 |
|
|
DataFrame |
df_dataframe.h:7356 |
|
|
Series<numpy::int64> |
df_dataframe.h:6403 |
|
|
Series<numpy::int64> |
df_dataframe.h:6358 |
|
|
std::istringstream |
df_dataframe.h:19020 |
|
|
* Series |
df_dataframe.h:12940 |
|
|
* a generator |
df_dataframe.h:1027 |
|
|
DataFrame |
df_dataframe.h:6022 |
|
|
oss << |
df_dataframe.h:18020 |
|
|
oss << |
df_dataframe.h:18024 |
|
|
oss << |
df_dataframe.h:18043 |
|
|
oss << |
df_dataframe.h:18053 |
|
|
oss << |
df_dataframe.h:18064 |
|
|
oss << |
df_dataframe.h:18068 |
|
|
oss << |
df_dataframe.h:18076 |
|
|
oss << |
df_dataframe.h:18086 |
|
|
df_dataframe.h:21147 |
||
|
df_dataframe.h:21258 |
||
|
df_dataframe.h:21271 |
||
|
df_dataframe.h:21868 |
||
|
std::vector<std::pair<std::string, numpy::int64>> |
df_dataframe.h:6570 |
|
|
query::QueryExpression |
df_dataframe.h:3675 |
|
|
DataFrame |
df_dataframe.h:7260 |
|
|
* PeriodIndex |
df_dataframe.h:12036 |
|
|
auto |
df_dataframe.h:11013 |
|
|
DataFrame |
df_dataframe.h:8094 |
|
|
DataFrame |
df_dataframe.h:8165 |
|
|
DataFrame |
df_dataframe.h:8186 |
|
|
DataFrame |
df_dataframe.h:8363 |
|
|
DataFrame |
df_dataframe.h:8390 |
|
|
DataFrame |
df_dataframe.h:9044 |
|
|
DataFrame |
df_dataframe.h:9048 |
|
|
* to specify which axis to |
df_dataframe.h:2307 |
|
|
Series<numpy::float64> |
df_dataframe.h:5214 |
|
|
Series<numpy::float64> |
df_dataframe.h:5168 |
|
|
Series<numpy::float64> |
df_dataframe.h:5791 |
|
|
* empty vector if path is |
df_dataframe.h:12980 |
|
|
DataFrame |
df_dataframe.h:3673 |
|
|
DataFrame |
df_dataframe.h:9066 |
|
|
DataFrame |
df_dataframe.h:9071 |
|
|
DataFrame |
df_dataframe.h:7370 |
|
|
DataFrame |
df_dataframe.h:9135 |
|
|
DataFrame |
df_dataframe.h:9139 |
|
|
std::regex |
df_dataframe.h:6115 |
|
|
std::regex |
df_dataframe.h:6142 |
|
|
static DataFrame |
df_dataframe.h:18779 |
|
|
static DataFrame |
df_dataframe.h:19093 |
|
|
static DataFrame |
df_dataframe.h:20784 |
|
|
static DataFrame |
df_dataframe.h:19950 |
|
|
static DataFrame |
df_dataframe.h:18930 |
|
|
static DataFrame |
df_dataframe.h:19495 |
|
|
static DataFrame |
df_dataframe.h:20181 |
|
|
static DataFrame |
df_dataframe.h:20394 |
|
|
DataFrame |
df_dataframe.h:2175 |
|
|
DataFrame |
df_dataframe.h:12273 |
|
|
DataFrame |
df_dataframe.h:2410 |
|
|
DataFrame |
df_dataframe.h:2146 |
|
|
DataFrame |
df_dataframe.h:2284 |
|
|
DataFrame |
df_dataframe.h:2124 |
|
|
DataFrame |
df_dataframe.h:7775 |
|
|
DataFrame |
df_dataframe.h:7826 |
|
|
DataFrame |
df_dataframe.h:7849 |
|
|
DataFrame |
df_dataframe.h:8051 |
|
|
static std::string |
df_dataframe.h:7708 |
|
|
DataFrame |
df_dataframe.h:8024 |
|
|
DataFrame |
df_dataframe.h:3540 |
|
|
void |
df_dataframe.h:3275 |
|
|
std::string |
df_dataframe.h:22218 |
|
|
* |
df_dataframe.h:15531 |
|
|
* |
df_dataframe.h:15925 |
|
|
DataFrameResampler |
df_dataframe.h:11952 |
|
|
void |
df_dataframe.h:2096 |
|
|
numpy::RecordArray |
df_dataframe.h:16454 |
|
|
DataFrame |
df_dataframe.h:9165 |
|
|
DataFrame |
df_dataframe.h:9169 |
|
|
DataFrame |
df_dataframe.h:9187 |
|
|
DataFrame |
df_dataframe.h:9191 |
|
|
DataFrame |
df_dataframe.h:9112 |
|
|
DataFrame |
df_dataframe.h:9117 |
|
|
* Provides |
df_dataframe.h:5802 |
|
|
DataFrameRolling |
df_dataframe.h:5962 |
|
|
DataFrame |
df_dataframe.h:9209 |
|
|
DataFrame |
df_dataframe.h:9213 |
|
|
DataFrame |
df_dataframe.h:9090 |
|
|
DataFrame |
df_dataframe.h:9094 |
|
|
DataFrame |
df_dataframe.h:9147 |
|
|
DataFrame |
df_dataframe.h:9151 |
|
|
DataFrame |
df_dataframe.h:22319 |
|
|
DataFrame |
df_dataframe.h:22345 |
|
|
Series<numpy::float64> |
df_dataframe.h:5525 |
|
|
Series<numpy::float64> |
df_dataframe.h:4699 |
|
|
* |
df_dataframe.h:15544 |
|
|
void |
df_dataframe.h:764 |
|
|
DataFrame |
df_dataframe.h:2245 |
|
|
df_dataframe.h:16530 |
||
|
df_dataframe.h:16537 |
||
|
void |
df_dataframe.h:778 |
|
|
void |
df_dataframe.h:2060 |
|
|
DataFrame |
df_dataframe.h:2073 |
|
|
void |
df_dataframe.h:3317 |
|
|
void |
df_dataframe.h:3301 |
|
|
std::vector<size_t> |
df_dataframe.h:623 |
|
|
DataFrame |
df_dataframe.h:9432 |
|
|
size_t |
df_dataframe.h:609 |
|
|
Series<numpy::float64> |
df_dataframe.h:5566 |
|
|
Series<numpy::float64> |
df_dataframe.h:4715 |
|
|
* represent time |
df_dataframe.h:11973 |
|
|
* Format |
df_dataframe.h:14406 |
|
|
std::ofstream |
df_dataframe.h:14936 |
|
|
std::stringstream |
df_dataframe.h:8625 |
|
|
std::string |
df_dataframe.h:20017 |
|
|
numpy::str64 |
df_dataframe.h:16511 |
|
|
numpy::str64 |
df_dataframe.h:16518 |
|
|
std::istringstream |
df_dataframe.h:18786 |
|
|
* If empty |
df_dataframe.h:9546 |
|
|
inline Styler |
df_dataframe.h:22483 |
|
|
DataFrame |
df_dataframe.h:8969 |
|
|
DataFrame |
df_dataframe.h:8973 |
|
|
* to specify which axis to |
df_dataframe.h:2352 |
|
|
DataFrame |
df_dataframe.h:7912 |
|
|
DataFrame |
df_dataframe.h:7960 |
|
|
DataFrame |
df_dataframe.h:7983 |
|
|
DataFrame |
df_dataframe.h:1686 |
|
|
DataFrame |
df_dataframe.h:10615 |
|
|
DataFrame |
df_dataframe.h:10713 |
|
|
DataFrame |
df_dataframe.h:10777 |
|
|
DataFrame |
df_dataframe.h:10817 |
|
|
DataFrame |
df_dataframe.h:10866 |
|
|
DataFrame |
df_dataframe.h:9011 |
|
|
DataFrame |
df_dataframe.h:9015 |
|
|
DataFrame |
df_dataframe.h:12106 |
|
|
* use |
df_dataframe.h:12160 |
|
|
* use |
df_dataframe.h:12102 |
|
|
DataFrame |
df_dataframe.h:12164 |
|
|
DataFrame |
df_dataframe.h:22293 |
|
|
DataFrame |
df_dataframe.h:8708 |
|
|
* Currently |
df_dataframe.h:15935 |
|
|
void |
df_dataframe.h:11791 |
|
|
* Series<double> |
df_dataframe.h:8860 |
|
|
* Can be a single |
df_dataframe.h:15524 |
|
|
std::variant<Series<numpy::int64>, Series<numpy::float64>> |
df_dataframe.h:6490 |
|
|
numpy::NDArray<numpy::float64> |
df_dataframe.h:730 |
|
|
* missing |
df_dataframe.h:10028 |
|
|
* Provides exponential |
df_dataframe.h:5909 |
|
|
* object implementing a binary |
df_dataframe.h:14169 |
|
|
df_dataframe.h:16978 |
||
|
df_dataframe.h:16981 |
||
|
df_dataframe.h:16997 |
||
|
df_dataframe.h:16999 |
||
|
df_dataframe.h:17139 |
||
|
df_dataframe.h:17142 |
||
|
df_dataframe.h:17236 |
||
|
df_dataframe.h:17237 |
||
|
df_dataframe.h:17238 |
||
|
df_dataframe.h:17261 |
||
|
df_dataframe.h:17302 |
||
|
df_dataframe.h:17305 |
||
|
df_dataframe.h:17308 |
||
|
df_dataframe.h:17335 |
||
|
df_dataframe.h:17337 |
||
|
df_dataframe.h:17376 |
||
|
df_dataframe.h:17424 |
||
|
df_dataframe.h:17427 |
||
|
df_dataframe.h:17495 |
||
|
df_dataframe.h:17509 |
||
|
df_dataframe.h:17511 |
||
|
df_dataframe.h:13806 |
||
|
df_dataframe.h:13810 |
||
|
df_dataframe.h:13814 |
||
|
df_dataframe.h:13818 |
||
|
df_dataframe.h:13822 |
||
|
df_dataframe.h:13825 |
||
|
df_dataframe.h:13828 |
||
|
df_dataframe.h:13831 |
||
|
df_dataframe.h:13949 |
||
|
df_dataframe.h:13953 |
||
|
df_dataframe.h:13957 |
||
|
df_dataframe.h:13961 |
||
|
df_dataframe.h:13964 |
||
|
df_dataframe.h:13966 |
||
|
df_dataframe.h:13968 |
||
|
df_dataframe.h:13970 |
||
|
df_dataframe.h:13996 |
||
|
df_dataframe.h:14000 |
||
|
df_dataframe.h:14008 |
||
|
df_dataframe.h:14011 |
||
|
df_dataframe.h:14020 |
||
|
df_dataframe.h:14023 |
||
|
df_dataframe.h:14027 |
||
|
df_dataframe.h:14033 |
||
|
df_dataframe.h:14037 |
||
|
df_dataframe.h:14045 |
||
|
df_dataframe.h:14052 |
||
|
df_dataframe.h:14056 |
||
|
df_dataframe.h:14061 |
||
|
df_dataframe.h:14065 |
||
|
df_dataframe.h:14070 |
||
|
df_dataframe.h:14075 |
||
|
df_dataframe.h:14079 |
||
|
df_dataframe.h:14083 |
||
|
df_dataframe.h:14087 |
||
|
df_dataframe.h:14091 |
||
|
df_dataframe.h:14101 |
||
|
df_dataframe.h:14105 |
||
|
df_dataframe.h:14112 |
||
|
df_dataframe.h:14116 |
||
|
df_dataframe.h:14118 |
||
|
df_dataframe.h:14124 |
||
|
df_dataframe.h:21359 |
||
|
df_dataframe.h:17165 |
||
|
df_dataframe.h:17168 |
||
|
df_dataframe.h:17447 |
||
|
df_dataframe.h:17450 |
||
|
df_dataframe.h:17125 |
||
|
df_dataframe.h:17175 |
||
|
df_dataframe.h:17181 |
||
|
df_dataframe.h:17184 |
||
|
df_dataframe.h:17413 |
||
|
df_dataframe.h:17456 |
||
|
df_dataframe.h:17461 |
||
|
df_dataframe.h:17464 |
||
|
df_dataframe.h:17147 |
||
|
df_dataframe.h:17150 |
||
|
df_dataframe.h:17311 |
||
|
df_dataframe.h:17352 |
||
|
df_dataframe.h:17431 |
||
|
df_dataframe.h:17434 |
||
|
df_dataframe.h:17118 |
||
|
df_dataframe.h:17120 |
||
|
df_dataframe.h:17155 |
||
|
df_dataframe.h:17158 |
||
|
df_dataframe.h:17230 |
||
|
df_dataframe.h:17241 |
||
|
df_dataframe.h:17244 |
||
|
df_dataframe.h:17249 |
||
|
df_dataframe.h:17255 |
||
|
df_dataframe.h:17314 |
||
|
df_dataframe.h:17410 |
||
|
df_dataframe.h:17438 |
||
|
df_dataframe.h:17441 |
||
|
df_dataframe.h:17493 |
||
|
df_dataframe.h:17496 |
||
|
df_dataframe.h:17497 |
||
|
df_dataframe.h:17501 |
||
|
df_dataframe.h:17505 |
||
|
df_dataframe.h:14279 |
||
|
df_dataframe.h:14280 |
||
|
df_dataframe.h:14281 |
||
|
df_dataframe.h:14525 |
||
|
df_dataframe.h:14526 |
||
|
df_dataframe.h:14527 |
||
|
df_dataframe.h:16966 |
||
|
df_dataframe.h:21173 |
||
|
df_dataframe.h:21195 |
||
|
df_dataframe.h:21252 |
||
|
df_dataframe.h:21255 |
||
|
df_dataframe.h:21370 |
||
|
df_dataframe.h:21766 |
||
|
df_dataframe.h:21862 |
||
|
df_dataframe.h:21927 |
||
|
df_dataframe.h:21175 |
||
|
df_dataframe.h:21209 |
||
|
df_dataframe.h:21237 |
||
|
df_dataframe.h:14046 |
||
|
df_dataframe.h:14066 |
||
|
df_dataframe.h:14071 |
||
|
df_dataframe.h:14113 |
||
|
df_dataframe.h:14009 |
||
|
df_dataframe.h:14024 |
||
|
df_dataframe.h:14072 |
||
|
df_dataframe.h:14117 |
||
|
df_dataframe.h:14119 |
||
|
df_dataframe.h:14125 |
||
|
df_dataframe.h:14283 |
||
|
df_dataframe.h:14292 |
||
|
df_dataframe.h:14296 |
||
|
df_dataframe.h:14307 |
||
|
df_dataframe.h:14311 |
||
|
df_dataframe.h:14322 |
||
|
df_dataframe.h:14510 |
||
|
df_dataframe.h:14529 |
||
|
df_dataframe.h:14538 |
||
|
df_dataframe.h:14542 |
||
|
df_dataframe.h:14554 |
||
|
df_dataframe.h:14558 |
||
|
df_dataframe.h:14567 |
||
|
df_dataframe.h:17029 |
||
|
df_dataframe.h:17045 |
||
|
df_dataframe.h:17055 |
||
|
df_dataframe.h:17057 |
||
|
df_dataframe.h:17066 |
||
|
df_dataframe.h:17128 |
||
|
df_dataframe.h:17189 |
||
|
df_dataframe.h:17233 |
||
|
df_dataframe.h:17317 |
||
|
df_dataframe.h:17329 |
||
|
df_dataframe.h:17347 |
||
|
df_dataframe.h:17357 |
||
|
df_dataframe.h:17363 |
||
|
df_dataframe.h:17365 |
||
|
df_dataframe.h:17371 |
||
|
df_dataframe.h:17415 |
||
|
df_dataframe.h:17468 |
||
|
df_dataframe.h:17494 |
||
|
df_dataframe.h:16941 |
||
|
df_dataframe.h:16942 |
||
|
df_dataframe.h:16945 |
||
|
df_dataframe.h:16946 |
||
|
df_dataframe.h:16947 |
||
|
df_dataframe.h:16950 |
||
|
df_dataframe.h:16951 |
||
|
df_dataframe.h:16952 |
||
|
df_dataframe.h:16955 |
||
|
df_dataframe.h:16961 |
||
|
df_dataframe.h:16964 |
||
|
df_dataframe.h:16970 |
||
|
df_dataframe.h:16973 |
||
|
df_dataframe.h:16983 |
||
|
df_dataframe.h:16986 |
||
|
df_dataframe.h:17001 |
||
|
df_dataframe.h:17003 |
||
|
df_dataframe.h:17007 |
||
|
df_dataframe.h:17011 |
||
|
df_dataframe.h:17015 |
||
|
df_dataframe.h:17019 |
||
|
df_dataframe.h:17023 |
||
|
df_dataframe.h:17031 |
||
|
df_dataframe.h:17035 |
||
|
df_dataframe.h:17039 |
||
|
df_dataframe.h:17043 |
||
|
df_dataframe.h:17047 |
||
|
df_dataframe.h:17051 |
||
|
df_dataframe.h:17060 |
||
|
df_dataframe.h:17064 |
||
|
df_dataframe.h:17068 |
||
|
df_dataframe.h:17072 |
||
|
df_dataframe.h:17073 |
||
|
df_dataframe.h:17077 |
||
|
df_dataframe.h:17194 |
||
|
df_dataframe.h:17198 |
||
|
df_dataframe.h:17199 |
||
|
df_dataframe.h:17203 |
||
|
df_dataframe.h:17214 |
||
|
df_dataframe.h:17266 |
||
|
df_dataframe.h:17271 |
||
|
df_dataframe.h:17275 |
||
|
df_dataframe.h:16959 |
||
|
df_dataframe.h:16976 |
||
|
df_dataframe.h:17017 |
||
|
df_dataframe.h:17037 |
||
|
df_dataframe.h:14267 |
||
|
df_dataframe.h:14298 |
||
|
df_dataframe.h:14303 |
||
|
df_dataframe.h:14503 |
||
|
df_dataframe.h:14544 |
||
|
df_dataframe.h:14550 |
||
|
df_dataframe.h:16957 |
||
|
df_dataframe.h:16968 |
||
|
df_dataframe.h:14290 |
||
|
df_dataframe.h:14315 |
||
|
df_dataframe.h:14536 |
||
|
df_dataframe.h:14562 |
||
|
df_dataframe.h:13066 |
||
|
df_dataframe.h:13081 |
||
|
df_dataframe.h:13087 |
||
|
df_dataframe.h:13807 |
||
|
df_dataframe.h:13811 |
||
|
df_dataframe.h:13815 |
||
|
df_dataframe.h:13823 |
||
|
df_dataframe.h:13826 |
||
|
df_dataframe.h:13829 |
||
|
df_dataframe.h:13832 |
||
|
df_dataframe.h:13950 |
||
|
df_dataframe.h:13954 |
||
|
df_dataframe.h:13958 |
||
|
df_dataframe.h:13965 |
||
|
df_dataframe.h:13967 |
||
|
df_dataframe.h:13969 |
||
|
df_dataframe.h:13971 |
||
|
df_dataframe.h:14012 |
||
|
df_dataframe.h:14021 |
||
|
df_dataframe.h:14034 |
||
|
df_dataframe.h:14053 |
||
|
df_dataframe.h:14062 |
||
|
df_dataframe.h:14067 |
||
|
df_dataframe.h:14076 |
||
|
df_dataframe.h:14080 |
||
|
df_dataframe.h:14084 |
||
|
df_dataframe.h:14088 |
||
|
df_dataframe.h:14092 |
||
|
df_dataframe.h:14102 |
||
|
df_dataframe.h:14106 |
||
|
std::string |
df_dataframe.h:19175 |
|
|
std::string |
df_dataframe.h:19225 |
|
|
std::string |
df_dataframe.h:19265 |
|
|
DataFrame |
df_dataframe.h:1775 |
|
|
DataFrame |
df_dataframe.h:1796 |
|
|
DataFrame |
df_dataframe.h:1826 |
|
|
DataFrame |
df_dataframe.h:1893 |
|
|
DataFrame |
df_dataframe.h:1999 |
|
|
DataFrame |
df_dataframe.h:1841 |
|
|
DataFrame |
df_dataframe.h:1941 |
Code Examples#
The following examples are extracted from the test suite.
empty (np_test_1_all.cpp:6316)
6306}
6307
6308void test_data_generator_emptyBenchmarkSorting() {
6309 std::cout << "========= test_data_generator_empty =======================";
6310
6311 DataGenerator<int> gen(42);
6312
6313 // Test empty data generation
6314 std::vector<int> data = gen.generate(0, DataPattern::RANDOM);
6315
6316 if (!(data.empty())) {
6317 std::string description = std::string("test_data_generator_emptyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.empty())";
6318 std::cout << std::string("[FAIL] ") + description << std::endl;
6319 throw std::runtime_error(description);
6320 }
6321
6322 // std::cout << "Empty data generation test passed" << std::endl;
6323
6324 std::cout << " -> tests passed" << std::endl;
6325}
at (np_test_1_all.cpp:144)
134 array.setElementAt({0, 0}, 1);
135 array.setElementAt({0, 1}, 2);
136 array.setElementAt({0, 2}, 3);
137 array.setElementAt({1, 1}, 5);
138 array.setElementAt({2, 2}, 9);
139
140 // std::cout << "Array after setting elements:" << std::endl;
141 //array.printArray();
142
143 // std::cout << "Element at (1,1): " << array.getElementAt({1, 1}) << std::endl;
144 // std::cout << "Element at (2,2): " << array.getElementAt({2, 2});
145
146 std::cout << " -> tests passed" << std::endl;
147}
148
149void testArithmetic() {
150 std::cout << "========= testArithmeticOperations =======================";
151
152 auto array1 = createFloat32Array({2, 2}, 5.0f);
153 auto array2 = createFloat32Array({2, 2}, 3.0f);
get (np_test_1_all.cpp:28526)
28516 std::cout << " -> tests passed" << std::endl;
28517 }
28518
28519 void np_test_indexing_mask_indices() {
28520 std::cout << "========= mask_indices: triangular mask indices =======================";
28521
28522 // Get upper triangular indices for 3x3 matrix
28523 auto triu_idx = numpy::mask_indices(3, "triu", 0);
28524
28525 // Should return tuple of 2 arrays
28526 bool passed = (std::get<0>(triu_idx).getSize() > 0);
28527 passed = passed && (std::get<1>(triu_idx).getSize() > 0);
28528 passed = passed && (std::get<0>(triu_idx).getSize() == std::get<1>(triu_idx).getSize());
28529
28530 // Get lower triangular indices
28531 auto tril_idx = numpy::mask_indices(3, "tril", 0);
28532 passed = passed && (std::get<0>(tril_idx).getSize() > 0);
28533 passed = passed && (std::get<1>(tril_idx).getSize() > 0);
28534
28535 if (!passed) {
28536 std::cout << " [FAIL] : in np_test_indexing_mask_indices() : Mask indices incorrect";
take (np_test_5_all.cpp:4313)
4303 for (size_t i = 0; i < 6; ++i) {
4304 arr.setElementAt({ i }, static_cast<int32_t>(i * 10)); // [0, 10, 20, 30, 40, 50]
4305 }
4306
4307 // Take specific indices
4308 numpy::NDArray<size_t> indices({ 3 });
4309 indices.setElementAt({ 0 }, 5); // 50
4310 indices.setElementAt({ 1 }, 2); // 20
4311 indices.setElementAt({ 2 }, 0); // 0
4312
4313 auto result = numpy::take(arr, indices);
4314
4315 if (result.getSize() != 3) {
4316 std::cout << " [FAIL] : in np_test_take_basic() : Wrong result size";
4317 throw std::runtime_error("Test failed");
4318 }
4319
4320 if (result.getElementAt({ 0 }) != 50 || result.getElementAt({ 1 }) != 20 || result.getElementAt({ 2 }) != 0) {
4321 std::cout << " [FAIL] : in np_test_take_basic() : Wrong values extracted";
4322 throw std::runtime_error("Test failed");
4323 }
where (np_test_3_all.cpp:15253)
15243 auto y_data = createInt32Array({ 4 }, 0);
15244 y_data.setElementAt({ 0 }, 100);
15245 y_data.setElementAt({ 1 }, 200);
15246 y_data.setElementAt({ 2 }, 300);
15247 y_data.setElementAt({ 3 }, 400);
15248
15249 auto y_mask = createBoolArray({ 4 }, false);
15250 MaskedArray<int32> y(y_data, y_mask, -999);
15251
15252 // Test where() selection
15253 auto result = where(condition, x, y);
15254
15255 if (!(result.getElementAt({ 0 }) == 10)) {
15256 std::string description = std::string("test_where_selection():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 10)";
15257 std::cout << std::string("[FAIL] ") + description << std::endl;
15258 throw std::runtime_error(description);
15259 }
15260 if (!(result.getElementAt({ 1 }) == 200)) {
15261 std::string description = std::string("test_where_selection():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 200)";
15262 std::cout << std::string("[FAIL] ") + description << std::endl;
T (np_test_1_all.cpp:20062)
20052 std::mt19937 gen;
20053
20054 public:
20055 MatrixGenerator(unsigned seed = 12345) : gen(seed) {}
20056
20057 // Generate real matrix with known real eigenvalues
20058 NDArray<T> real_matrix_real_eigenvalues(size_t n) {
20059 // Create diagonal matrix with known eigenvalues
20060 NDArray<T> D = NDArray<T>::createZeros({ n, n });
20061 for (size_t i = 0; i < n; ++i) {
20062 D.setElementAt({ i, i }, T(i + 1)); // Eigenvalues 1, 2, 3, ...
20063 }
20064
20065 // Create random orthogonal transformation
20066 auto Q = random_orthogonal_matrix(n);
20067 auto QT = Q.transposeArray();
20068
20069 // A = Q * D * Q^T
20070 return matmul(matmul(Q, D), QT);
20071 }
squeeze (np_test_1_all.cpp:18076)
18066 using namespace numpy;
18067
18068
18069 void testSqueeze() {
18070 std::cout << "========= testSqueeze =======================";
18071
18072 // Create array with singleton dimensions
18073 auto array = createInt32Array({ 1, 4, 1, 3, 1 }, 5);
18074
18075 // Test squeeze all singleton dimensions
18076 auto squeezed_all = squeeze(array);
18077 if (!(squeezed_all.getShape().size() == 2)) {
18078 std::string description = std::string("testSqueeze():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(squeezed_all.getShape().size() == 2)";
18079 std::cout << std::string("[FAIL] ") + description << std::endl;
18080 throw std::runtime_error(description);
18081 }
18082 if (!(squeezed_all.getShape()[0] == 4)) {
18083 std::string description = std::string("testSqueeze():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(squeezed_all.getShape()[0] == 4)";
18084 std::cout << std::string("[FAIL] ") + description << std::endl;
18085 throw std::runtime_error(description);
18086 }
swapaxes (np_test_2_all.cpp:3707)
3697 std::cout << std::string("[FAIL] ") + description << std::endl;
3698 throw std::runtime_error(description);
3699 }
3700 if (!(isApproxEqualMCO(rolled.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 3 })))) {
3701 std::string description = std::string("testRotationFlipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(rolled.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 3 })))";
3702 std::cout << std::string("[FAIL] ") + description << std::endl;
3703 throw std::runtime_error(description);
3704 }
3705
3706 // Test swapaxes
3707 auto swapped = swapaxes(arr, 0, 1);
3708 if (!(swapped.getShape() == std::vector<size_t>({ 4, 3 }))) {
3709 std::string description = std::string("testRotationFlipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(swapped.getShape() == std::vector<size_t>({ 4, 3 }))";
3710 std::cout << std::string("[FAIL] ") + description << std::endl;
3711 throw std::runtime_error(description);
3712 }
3713 if (!(isApproxEqualMCO(swapped.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 0 })))) {
3714 std::string description = std::string("testRotationFlipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(swapped.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 0 })))";
3715 std::cout << std::string("[FAIL] ") + description << std::endl;
3716 throw std::runtime_error(description);
3717 }
transpose (np_test_2_all.cpp:4973)
4963 }
4964
4965 /**
4966 * Test matrix properties and methods
4967 */
4968 void testMatrixProperties() {
4969 std::cout << "========= testMatrixProperties =======================";
4970
4971 // Test transpose
4972 numpy::Matrix<double> m("1 2 3; 4 5 6");
4973 auto mt = m.transpose();
4974 assert_test(mt.rows() == 3, "Transpose rows");
4975 assert_test(mt.cols() == 2, "Transpose cols");
4976 assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element");
4977 assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element");
4978
4979 // Test trace for square matrix
4980 numpy::Matrix<double> square("1 2; 3 4");
4981 double tr = square.trace();
4982 assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace");
cov (np_test_1_all.cpp:12038)
12028 data.setElementAt({ 0, 0 }, 1.0);
12029 data.setElementAt({ 0, 1 }, 2.0);
12030 data.setElementAt({ 0, 2 }, 3.0);
12031
12032 // Variable 2: [2, 4, 6] (perfectly correlated)
12033 data.setElementAt({ 1, 0 }, 2.0);
12034 data.setElementAt({ 1, 1 }, 4.0);
12035 data.setElementAt({ 1, 2 }, 6.0);
12036
12037 // Test covariance matrix
12038 auto cov_matrix = cov(data);
12039 if (!(cov_matrix.getShape()[0] == 2)) {
12040 std::string description = std::string("testCovarianceAndCorrelation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(cov_matrix.getShape()[0] == 2)";
12041 std::cout << std::string("[FAIL] ") + description << std::endl;
12042 throw std::runtime_error(description);
12043 }
12044 if (!(cov_matrix.getShape()[1] == 2)) {
12045 std::string description = std::string("testCovarianceAndCorrelation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(cov_matrix.getShape()[1] == 2)";
12046 std::cout << std::string("[FAIL] ") + description << std::endl;
12047 throw std::runtime_error(description);
12048 }
max (np_test_1_all.cpp:7274)
7264 if (sizeof(uintp) == sizeof(void*)) {
7265 // std::cout << " -> uintp size matches pointer size";
7266 } else {
7267 // std::cout << " ✗ uintp size doesn't match pointer size" << std::endl;
7268 }
7269
7270 // Test range limits
7271 // std::cout << "Range Information:" << std::endl;
7272 // std::cout << " intp min: " << std::numeric_limits<intp>::min() << std::endl;
7273 // std::cout << " intp max: " << std::numeric_limits<intp>::max() << std::endl;
7274 // std::cout << " uintp max: " << std::numeric_limits<uintp>::max() << std::endl;
7275 // std::cout << " longdouble digits: " << std::numeric_limits<longdouble>::digits << std::endl;
7276
7277 std::cout << " -> tests passed" << std::endl;
7278}
7279
7280void testComplexArithmeticExtendedTypes() {
7281 std::cout << "========= testComplexArithmeticExtendedTypes =======================";
7282
7283 clongdouble c1(3.0L, 4.0L); // 3 + 4i
mean (np_test_1_all.cpp:11714)
11704 // Create test array
11705 auto array = createInt32Array({ 2, 3 }, 0);
11706 array.setElementAt({ 0, 0 }, 1);
11707 array.setElementAt({ 0, 1 }, 2);
11708 array.setElementAt({ 0, 2 }, 3);
11709 array.setElementAt({ 1, 0 }, 4);
11710 array.setElementAt({ 1, 1 }, 5);
11711 array.setElementAt({ 1, 2 }, 6);
11712
11713 // Test mean without axis
11714 auto mean_all = mean(array);
11715 if (!(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))) {
11716 std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))";
11717 std::cout << std::string("[FAIL] ") + description << std::endl;
11718 throw std::runtime_error(description);
11719 }
11720 // std::cout << "[OK] mean (all elements) works correctly\n";
11721
11722 // Test mean along axis 0
11723 auto mean_axis0 = mean(array, 0);
11724 if (!(mean_axis0.getShape()[0] == 3)) {
median (np_test_1_all.cpp:11882)
11872 std::cout << "========= testMedianAndPercentiles =======================";
11873
11874 // Test median with odd number of elements
11875 auto odd_array = createInt32Array({ 5 }, 0);
11876 odd_array.setElementAt({ 0 }, 1);
11877 odd_array.setElementAt({ 1 }, 3);
11878 odd_array.setElementAt({ 2 }, 5);
11879 odd_array.setElementAt({ 3 }, 7);
11880 odd_array.setElementAt({ 4 }, 9);
11881
11882 auto median_odd = median(odd_array);
11883 if (!(approx_equal(median_odd.getElementAt({ 0 }), 5.0, 1e-10))) {
11884 std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(median_odd.getElementAt({ 0 }), 5.0, 1e-10))";
11885 std::cout << std::string("[FAIL] ") + description << std::endl;
11886 throw std::runtime_error(description);
11887 }
11888 // std::cout << "[OK] Median with odd count works correctly\n";
11889
11890 // Test median with even number of elements
11891 auto even_array = createInt32Array({ 4 }, 0);
11892 even_array.setElementAt({ 0 }, 1);
min (np_test_1_all.cpp:2350)
2340 if (i % 3 == 0) {
2341 large_array.setElementAt({i}, object_(static_cast<int>(i)));
2342 } else if (i % 3 == 1) {
2343 large_array.setElementAt({i}, object_(static_cast<double>(i) * 0.5));
2344 } else {
2345 large_array.setElementAt({i}, object_(std::string("str") + std::to_string(i)));
2346 }
2347 }
2348
2349 // Verify pattern
2350 for (size_t i = 0; i < std::min(large_size, size_t(100)); ++i) { // Check first 100
2351 object_ obj = large_array.getElementAt({i});
2352 if (i % 3 == 0) {
2353 if (!(obj.is_type<int>())) {
2354 std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<int>())";
2355 std::cout << std::string("[FAIL] ") + description << std::endl;
2356 throw std::runtime_error(description);
2357 }
2358 } else if (i % 3 == 1) {
2359 if (!(obj.is_type<double>())) {
2360 std::string description = std::string("unknown_function():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<double>())";
quantile (np_test_1_all.cpp:11929)
11919 // Test 25th percentile
11920 auto perc25 = percentile(perc_array, 25.0);
11921 if (!(approx_equal(perc25.getElementAt({ 0 }), 3.25, 1e-10))) {
11922 std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(perc25.getElementAt({ 0 }), 3.25, 1e-10))";
11923 std::cout << std::string("[FAIL] ") + description << std::endl;
11924 throw std::runtime_error(description);
11925 }
11926 // std::cout << "[OK] 25th percentile works correctly\n";
11927
11928 // Test quantile (equivalent to percentile/100)
11929 auto quant75 = quantile(perc_array, 0.75);
11930 auto perc75 = percentile(perc_array, 75.0);
11931 if (!(approx_equal(quant75.getElementAt({ 0 }), perc75.getElementAt({ 0 }), 1e-10))) {
11932 std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(quant75.getElementAt({ 0 }), perc75.getElementAt({ 0 }), 1e-10))";
11933 std::cout << std::string("[FAIL] ") + description << std::endl;
11934 throw std::runtime_error(description);
11935 }
11936 // std::cout << "[OK] Quantile function works correctly\n";
11937 std::cout << " -> tests passed" << std::endl;
11938 }
std (np_test_1_all.cpp:11836)
11826 auto var_sample = var(array, std::nullopt, 1); // ddof=1 for sample variance
11827 double expected_sample_var = 1.25 * 4.0 / 3.0; // Bessel's correction
11828 if (!(approx_equal(var_sample.getElementAt({ 0 }), expected_sample_var, 1e-10))) {
11829 std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_sample.getElementAt({ 0 }), expected_sample_var, 1e-10))";
11830 std::cout << std::string("[FAIL] ") + description << std::endl;
11831 throw std::runtime_error(description);
11832 }
11833 // std::cout << "[OK] Sample variance works correctly\n";
11834
11835 // Test standard deviation
11836 auto std_result = numpy::std(array, std::nullopt, 0);
11837 if (!(approx_equal(std_result.getElementAt({ 0 }), std::sqrt(expected_var), 1e-10))) {
11838 std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(std_result.getElementAt({ 0 }), std::sqrt(expected_var), 1e-10))";
11839 std::cout << std::string("[FAIL] ") + description << std::endl;
11840 throw std::runtime_error(description);
11841 }
11842 // std::cout << "[OK] Standard deviation works correctly\n";
11843
11844 // Test along axis
11845 auto array2d = createFloat64Array({ 2, 2 }, 0);
11846 array2d.setElementAt({ 0, 0 }, 1.0);
sum (np_test_1_all.cpp:11766)
11756 throw std::runtime_error(description);
11757 }
11758 if (!(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))) {
11759 std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))";
11760 std::cout << std::string("[FAIL] ") + description << std::endl;
11761 throw std::runtime_error(description);
11762 }
11763 // std::cout << "[OK] mean along axis 1 works correctly\n";
11764
11765 // Test sum
11766 auto sum_all = sum(array);
11767 if (!(sum_all.getElementAt({ 0 }) == 21)) {
11768 std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sum_all.getElementAt({ 0 }) == 21)";
11769 std::cout << std::string("[FAIL] ") + description << std::endl;
11770 throw std::runtime_error(description);
11771 }
11772 // std::cout << "[OK] sum works correctly\n";
11773
11774 // Test min and max
11775 auto min_all = min(array);
11776 auto max_all = max(array);
var (np_test_1_all.cpp:11816)
11806 std::cout << "========= testVarianceAndStandardDeviation =======================";
11807
11808 // Create test array with known variance
11809 auto array = createFloat64Array({ 4 }, 0);
11810 array.setElementAt({ 0 }, 1.0);
11811 array.setElementAt({ 1 }, 2.0);
11812 array.setElementAt({ 2 }, 3.0);
11813 array.setElementAt({ 3 }, 4.0);
11814
11815 // Test variance (population)
11816 auto var_result = var(array, std::nullopt, 0); // ddof=0 for population variance
11817 double expected_var = 1.25; // Known variance for [1,2,3,4]
11818 if (!(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))) {
11819 std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))";
11820 std::cout << std::string("[FAIL] ") + description << std::endl;
11821 throw std::runtime_error(description);
11822 }
11823 // std::cout << "[OK] Population variance works correctly\n";
11824
11825 // Test variance (sample)
11826 auto var_sample = var(array, std::nullopt, 1); // ddof=1 for sample variance
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 --------------------------------
add (np_test_1_all.cpp:6410)
6400void testCharArrayStringOperationsCharArray() {
6401 std::cout << "========= testStringOperations =======================";
6402
6403 // Test string concatenation
6404 std::vector<std::string> words1 = {"Hello", "Good", "Nice"};
6405 std::vector<std::string> words2 = {" World", " Day", " Work"};
6406
6407 auto arr1 = array<32>(words1);
6408 auto arr2 = array<32>(words2);
6409
6410 auto result = add(arr1, arr2);
6411 // std::cout << "String concatenation (add):" << std::endl;
6412 for (size_t i = 0; i < result.size(); ++i) {
6413 // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'";
6414 }
6415
6416 // Test scalar addition
6417 auto scalar_result = add(arr1, "!");
6418 // std::cout << "Scalar concatenation:" << std::endl;
6419 for (size_t i = 0; i < scalar_result.size(); ++i) {
6420 // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'";
add (np_test_1_all.cpp:6410)
6400void testCharArrayStringOperationsCharArray() {
6401 std::cout << "========= testStringOperations =======================";
6402
6403 // Test string concatenation
6404 std::vector<std::string> words1 = {"Hello", "Good", "Nice"};
6405 std::vector<std::string> words2 = {" World", " Day", " Work"};
6406
6407 auto arr1 = array<32>(words1);
6408 auto arr2 = array<32>(words2);
6409
6410 auto result = add(arr1, arr2);
6411 // std::cout << "String concatenation (add):" << std::endl;
6412 for (size_t i = 0; i < result.size(); ++i) {
6413 // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'";
6414 }
6415
6416 // Test scalar addition
6417 auto scalar_result = add(arr1, "!");
6418 // std::cout << "Scalar concatenation:" << std::endl;
6419 for (size_t i = 0; i < scalar_result.size(); ++i) {
6420 // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'";
ceil (np_test_2_all.cpp:5735)
5725 throw std::runtime_error(description);
5726 }
5727 if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) {
5728 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))";
5729 std::cout << std::string("[FAIL] ") + description << std::endl;
5730 throw std::runtime_error(description);
5731 }
5732 // std::cout << "[OK] floor function works correctly\n";
5733
5734 // Test ceil
5735 auto ceil_result = ceil(values);
5736 if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) {
5737 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))";
5738 std::cout << std::string("[FAIL] ") + description << std::endl;
5739 throw std::runtime_error(description);
5740 }
5741 if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) {
5742 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))";
5743 std::cout << std::string("[FAIL] ") + description << std::endl;
5744 throw std::runtime_error(description);
5745 }
divide (np_test_3_all.cpp:16880)
16870 std::cout << " -> tests passed" << std::endl;
16871 }
16872
16873 void np_test_missing_math_functions_divide_array() {
16874 std::cout << "========= divide: array-array division =======================";
16875
16876 // explicit namespace to avoid name clashes
16877 numpy::NDArray<double> a = numpy::arange<double>(10.0, 16.0, 1.0);
16878 numpy::NDArray<double> b = numpy::arange<double>(2.0, 8.0, 1.0);
16879
16880 numpy::NDArray<double> result = numpy::divide(a, b);
16881
16882 // Verify values: [10,11,12,13,14,15] / [2,3,4,5,6,7] = [5,3.666...,3,2.6,2.333...,2.142...]
16883 auto pass = true;
16884 double expected[] = { 5.0, 11.0 / 3.0, 3.0, 2.6, 14.0 / 6.0, 15.0 / 7.0 };
16885 for (size_t i = 0; i < 6 && pass; ++i) {
16886 double val = result.getElementAt({ i });
16887 double exp = expected[i];
16888 if (std::abs(val - exp) > 1e-10) {
16889 pass = false;
16890 }
floor (np_test_2_all.cpp:5721)
5711 throw std::runtime_error(description);
5712 }
5713 if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) {
5714 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))";
5715 std::cout << std::string("[FAIL] ") + description << std::endl;
5716 throw std::runtime_error(description);
5717 }
5718 // std::cout << "[OK] round function works correctly\n";
5719
5720 // Test floor
5721 auto floor_result = floor(values);
5722 if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) {
5723 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))";
5724 std::cout << std::string("[FAIL] ") + description << std::endl;
5725 throw std::runtime_error(description);
5726 }
5727 if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) {
5728 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))";
5729 std::cout << std::string("[FAIL] ") + description << std::endl;
5730 throw std::runtime_error(description);
5731 }
mod (np_test_1_all.cpp:21258)
21248 a.setElementAt({ 1 }, -7);
21249 a.setElementAt({ 2 }, 7);
21250 a.setElementAt({ 3 }, -7);
21251
21252 auto b = NDArray<int32>({ 4 });
21253 b.setElementAt({ 0 }, 3);
21254 b.setElementAt({ 1 }, 3);
21255 b.setElementAt({ 2 }, -3);
21256 b.setElementAt({ 3 }, -3);
21257
21258 auto result = mod(a, b);
21259
21260 if (!(result.getElementAt({ 0 }) == 1)) {
21261 std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)";
21262 std::cout << std::string("[FAIL] ") + description << std::endl;
21263 throw std::runtime_error(description);
21264 }
21265 if (!(result.getElementAt({ 1 }) == 2)) {
21266 std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)";
21267 std::cout << std::string("[FAIL] ") + description << std::endl;
21268 throw std::runtime_error(description);
mod (np_test_1_all.cpp:21258)
21248 a.setElementAt({ 1 }, -7);
21249 a.setElementAt({ 2 }, 7);
21250 a.setElementAt({ 3 }, -7);
21251
21252 auto b = NDArray<int32>({ 4 });
21253 b.setElementAt({ 0 }, 3);
21254 b.setElementAt({ 1 }, 3);
21255 b.setElementAt({ 2 }, -3);
21256 b.setElementAt({ 3 }, -3);
21257
21258 auto result = mod(a, b);
21259
21260 if (!(result.getElementAt({ 0 }) == 1)) {
21261 std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)";
21262 std::cout << std::string("[FAIL] ") + description << std::endl;
21263 throw std::runtime_error(description);
21264 }
21265 if (!(result.getElementAt({ 1 }) == 2)) {
21266 std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)";
21267 std::cout << std::string("[FAIL] ") + description << std::endl;
21268 throw std::runtime_error(description);
mode (np_test_4_all.cpp:20711)
20701#include <stdexcept>
20702
20703using namespace numpy;
20704
20705namespace numpy_tests {
20706namespace numpy_tests_phase6b {
20707
20708void np_test_phase6b_can_cast() {
20709 std::cout << "=== Test can_cast() ===";
20710
20711 // Test SAFE casting mode (default)
20712 {
20713 // Same type is always safe
20714 if (!(can_cast(DType::INT32, DType::INT32, CastingMode::SAFE) == true)) {
20715 std::string description = std::string("np_test_phase6b_can_cast():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_cast(DType::INT32, DType::INT32, CastingMode::SAFE) == true)";
20716 std::cout << std::string("[FAIL] ") + description << std::endl;
20717 throw std::runtime_error(description);
20718 }
20719 if (!(can_cast(DType::FLOAT64, DType::FLOAT64, CastingMode::SAFE) == true)) {
20720 std::string description = std::string("np_test_phase6b_can_cast():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_cast(DType::FLOAT64, DType::FLOAT64, CastingMode::SAFE) == true)";
20721 std::cout << std::string("[FAIL] ") + description << std::endl;
mode (np_test_4_all.cpp:20711)
20701#include <stdexcept>
20702
20703using namespace numpy;
20704
20705namespace numpy_tests {
20706namespace numpy_tests_phase6b {
20707
20708void np_test_phase6b_can_cast() {
20709 std::cout << "=== Test can_cast() ===";
20710
20711 // Test SAFE casting mode (default)
20712 {
20713 // Same type is always safe
20714 if (!(can_cast(DType::INT32, DType::INT32, CastingMode::SAFE) == true)) {
20715 std::string description = std::string("np_test_phase6b_can_cast():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_cast(DType::INT32, DType::INT32, CastingMode::SAFE) == true)";
20716 std::cout << std::string("[FAIL] ") + description << std::endl;
20717 throw std::runtime_error(description);
20718 }
20719 if (!(can_cast(DType::FLOAT64, DType::FLOAT64, CastingMode::SAFE) == true)) {
20720 std::string description = std::string("np_test_phase6b_can_cast():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_cast(DType::FLOAT64, DType::FLOAT64, CastingMode::SAFE) == true)";
20721 std::cout << std::string("[FAIL] ") + description << std::endl;
multiply (np_test_1_all.cpp:6426)
6416 // Test scalar addition
6417 auto scalar_result = add(arr1, "!");
6418 // std::cout << "Scalar concatenation:" << std::endl;
6419 for (size_t i = 0; i < scalar_result.size(); ++i) {
6420 // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'";
6421 }
6422
6423 // Test string multiplication
6424 std::vector<std::string> patterns = {"Ha", "Ho", "Hi"};
6425 auto pattern_arr = array<32>(patterns);
6426 auto repeated = multiply(pattern_arr, 3);
6427 // std::cout << "String multiplication:" << std::endl;
6428 for (size_t i = 0; i < repeated.size(); ++i) {
6429 // std::cout << "'" << pattern_arr[i] << "' * 3 = '" << repeated[i] << "'";
6430 }
6431
6432 std::cout << " -> tests passed" << std::endl;
6433}
6434
6435void testCaseConversionsCharArray() {
6436 std::cout << "========= testCaseConversions =======================";
round (np_test_1_all.cpp:23769)
23759 throw std::runtime_error(description);
23760 }
23761 if (!(power_scalar_result.getShape() == array.getShape())) {
23762 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())";
23763 std::cout << std::string("[FAIL] ") + description << std::endl;
23764 throw std::runtime_error(description);
23765 }
23766 // std::cout << "[OK] Power functions have correct signatures\n";
23767
23768 // Test rounding functions with new decimals parameter
23769 auto round_result = round(array); // Default decimals=0
23770 auto round_decimals_result = round(array, 2); // With decimals
23771 if (!(round_result.getShape() == array.getShape())) {
23772 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())";
23773 std::cout << std::string("[FAIL] ") + description << std::endl;
23774 throw std::runtime_error(description);
23775 }
23776 if (!(round_decimals_result.getShape() == array.getShape())) {
23777 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())";
23778 std::cout << std::string("[FAIL] ") + description << std::endl;
23779 throw std::runtime_error(description);
subtract (np_test_3_all.cpp:16825)
16815 std::cout << " -> tests passed" << std::endl;
16816 }
16817
16818 void np_test_missing_math_functions_subtract_array() {
16819 std::cout << "========= subtract: array-array subtraction =======================";
16820
16821 // explicit namespace to avoid name clashes
16822 numpy::NDArray<double> a = numpy::arange<double>(10.0, 16.0, 1.0);
16823 numpy::NDArray<double> b = numpy::arange<double>(0.0, 6.0, 1.0);
16824
16825 numpy::NDArray<double> result = numpy::subtract(a, b);
16826
16827 // Verify values: [10,11,12,13,14,15] - [0,1,2,3,4,5] = [10,10,10,10,10,10]
16828 auto pass = true;
16829 for (size_t i = 0; i < 6 && pass; ++i) {
16830 double val = result.getElementAt({ i });
16831 double exp = 10.0;
16832 if (std::abs(val - exp) > 1e-10) {
16833 pass = false;
16834 }
16835 }
truncate (np_test_5_all.cpp:7536)
7526 if (!passed) {
7527 std::cout << " [FAIL] : cutdeg failed";
7528 throw std::runtime_error("np_test_cutdeg failed");
7529 }
7530
7531 std::cout << " -> tests passed" << std::endl;
7532 }
7533
7534 void np_test_truncate() {
7535 std::cout << "========= truncate: truncate to size =======================";
7536
7537 numpy::Polynomial<double> p({ 1.0, 2.0, 3.0, 4.0, 5.0 });
7538 auto truncated = p.truncate(3); // Keep only first 3 coefficients
7539
7540 auto coefs = truncated.coefficients();
7541 bool passed = (coefs.size() == 3 &&
7542 std::abs(coefs[0] - 1.0) < 1e-10 &&
7543 std::abs(coefs[1] - 2.0) < 1e-10 &&
7544 std::abs(coefs[2] - 3.0) < 1e-10);
dot (np_test_2_all.cpp:11523)
11513 numpy::NDArray<double> v2({ 3 });
11514
11515 v1.setElementAt({ 0 }, 1.0);
11516 v1.setElementAt({ 1 }, 2.0);
11517 v1.setElementAt({ 2 }, 3.0);
11518
11519 v2.setElementAt({ 0 }, 4.0);
11520 v2.setElementAt({ 1 }, 5.0);
11521 v2.setElementAt({ 2 }, 6.0);
11522
11523 auto result = numpy::linalg::dot(v1, v2);
11524 double expected = 1.0 * 4.0 + 2.0 * 5.0 + 3.0 * 6.0; // = 32
11525
11526 // Extract scalar from 0-D array
11527 double result_value = result.getElementAt({});
11528
11529 if (std::abs(result_value - expected) > 1e-10) {
11530 std::cout << " [FAIL] : dot product incorrect, expected " << expected << ", got " << result_value;
11531 throw std::runtime_error("dot test failed");
11532 }
dot (np_test_2_all.cpp:11523)
11513 numpy::NDArray<double> v2({ 3 });
11514
11515 v1.setElementAt({ 0 }, 1.0);
11516 v1.setElementAt({ 1 }, 2.0);
11517 v1.setElementAt({ 2 }, 3.0);
11518
11519 v2.setElementAt({ 0 }, 4.0);
11520 v2.setElementAt({ 1 }, 5.0);
11521 v2.setElementAt({ 2 }, 6.0);
11522
11523 auto result = numpy::linalg::dot(v1, v2);
11524 double expected = 1.0 * 4.0 + 2.0 * 5.0 + 3.0 * 6.0; // = 32
11525
11526 // Extract scalar from 0-D array
11527 double result_value = result.getElementAt({});
11528
11529 if (std::abs(result_value - expected) > 1e-10) {
11530 std::cout << " [FAIL] : dot product incorrect, expected " << expected << ", got " << result_value;
11531 throw std::runtime_error("dot test failed");
11532 }
sample (np_test_1_all.cpp:22321)
22311 throw std::runtime_error(description);
22312 }
22313 for (size_t i = 0; i < 3; ++i) {
22314 double val = random_samp.getElementAt({ i });
22315 if (!(val >= 0.0 && val < 1.0)) {
22316 std::string description = std::string("testRandomUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0 && val < 1.0)";
22317 std::cout << std::string("[FAIL] ") + description << std::endl;
22318 throw std::runtime_error(description);
22319 }
22320 }
22321 // std::cout << "[OK] Random sample (alias)\n";
22322
22323 auto ranf_arr = ranf<double>({ {3} });
22324 if (!(ranf_arr.getShape()[0] == 3)) {
22325 std::string description = std::string("testRandomUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ranf_arr.getShape()[0] == 3)";
22326 std::cout << std::string("[FAIL] ") + description << std::endl;
22327 throw std::runtime_error(description);
22328 }
22329 // std::cout << "[OK] ranf (alias)\n";
22330
22331 auto sample_arr = sample<double>({ {3} });
all (np_test_4_all.cpp:23928)
23918 }
23919 }
23920 }
23921
23922 auto result = numpy::einsum<numpy::float64>("ijk->ik", {A});
23923
23924 if (result.getShape()[0] != 2 || result.getShape()[1] != 2) {
23925 throw std::runtime_error("einsum partial sum shape wrong");
23926 }
23927
23928 // Sum over j: 1+2+3 = 6 for all (i,k) positions
23929 if (std::abs(result.getElementAt({0, 0}) - 6.0) > 1e-10 ||
23930 std::abs(result.getElementAt({1, 1}) - 6.0) > 1e-10) {
23931 throw std::runtime_error("einsum partial sum values wrong");
23932 }
23933
23934 // std::cout << " OK: Partial sum: 'ijk->ik'\n";
23935 }
23936
23937 // Test 5: Size-1 dimension handling
23938 {
any (np_test_2_all.cpp:16758)
16748 // ANY() TESTS - SCALAR RESULT
16749 // ============================================================================
16750
16751 void np_test_logic_any_scalar_all_false() {
16752 std::cout << "========= any: all false elements =======================";
16753
16754 // Create array with all false/zero elements
16755 std::vector<double> data = { 0.0, 0.0, 0.0 };
16756 numpy::NDArray<double> arr = numpy::createArrayFromVector<double>({ 3 }, data);
16757
16758 bool result = numpy::any(arr);
16759
16760 if (result != false) {
16761 std::cout << " [FAIL] : in np_test_logic_any_scalar_all_false() : expected false for all-zero array";
16762 throw std::runtime_error("np_test_logic_any_scalar_all_false failed: expected false");
16763 }
16764
16765 std::cout << " -> tests passed" << std::endl;
16766 }
16767
16768 void np_test_logic_any_scalar_all_true() {
isin (np_test_1_all.cpp:19434)
19424 std::cout << std::string("[FAIL] ") + description << std::endl;
19425 throw std::runtime_error(description);
19426 }
19427 if (!(membership.getElementAt({ 5 }) == false)) {
19428 std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(membership.getElementAt({ 5 }) == false)";
19429 std::cout << std::string("[FAIL] ") + description << std::endl;
19430 throw std::runtime_error(description);
19431 }
19432 // std::cout << "[OK] Membership testing (in1d) works correctly\n";
19433
19434 // Test isin (alias for in1d)
19435 auto isin_result = isin(test_array, test_values);
19436
19437 // Should be identical to in1d result
19438 for (size_t i = 0; i < membership.getSize(); ++i) {
19439 if (!(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))) {
19440 std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))";
19441 std::cout << std::string("[FAIL] ") + description << std::endl;
19442 throw std::runtime_error(description);
19443 }
19444 }
isin (np_test_1_all.cpp:19434)
19424 std::cout << std::string("[FAIL] ") + description << std::endl;
19425 throw std::runtime_error(description);
19426 }
19427 if (!(membership.getElementAt({ 5 }) == false)) {
19428 std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(membership.getElementAt({ 5 }) == false)";
19429 std::cout << std::string("[FAIL] ") + description << std::endl;
19430 throw std::runtime_error(description);
19431 }
19432 // std::cout << "[OK] Membership testing (in1d) works correctly\n";
19433
19434 // Test isin (alias for in1d)
19435 auto isin_result = isin(test_array, test_values);
19436
19437 // Should be identical to in1d result
19438 for (size_t i = 0; i < membership.getSize(); ++i) {
19439 if (!(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))) {
19440 std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))";
19441 std::cout << std::string("[FAIL] ") + description << std::endl;
19442 throw std::runtime_error(description);
19443 }
19444 }
to_numpy (np_test_5_all.cpp:21373)
21363 if (errors == 0) {
21364 std::cout << "np_test_timedelta_components -> tests passed" << std::endl;
21365 }
21366 return errors;
21367}
21368
21369// =============================================================================
21370// Test 4: Total Conversion Properties
21371// =============================================================================
21372int np_test_timedelta_total_conversions() {
21373 int errors = 0;
21374
21375 numpy::Timedelta td(1, 12, 0); // 1 day 12 hours = 1.5 days = 36 hours
21376
21377 // total_seconds
21378 {
21379 double secs = td.total_seconds();
21380 double expected = (24 + 12) * 3600.0;
21381 if (std::abs(secs - expected) > 0.0001) {
21382 std::cout << "[FAIL] np_test_timedelta_total_conversions: total_seconds expected "
21383 << expected << ", got " << secs << std::endl;
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)";
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)";
insert (np_test_1_all.cpp:6990)
6980}
6981
6982void testBusinessDateRangeDateTime() {
6983 std::cout << "========= testBusinessDateRangeDateTime =======================";
6984
6985 datetime64 start("2024-03-11"); // Monday
6986 datetime64 end("2024-03-22"); // Friday (2 weeks later)
6987
6988 // Create holidays set
6989 std::set<datetime64> holidays;
6990 holidays.insert(datetime64("2024-03-15")); // Friday holiday
6991
6992 auto business_dates = createBusinessDateRange(start, end, holidays);
6993 // std::cout << "Business dates from " << start.toString()
6994 // << " to " << end.toString() << " (excluding 2024-03-15):" << std::endl;
6995 //business_dates.printArray();
6996
6997 std::cout << " -> tests passed" << std::endl;
6998}
6999
7000void testMonthRangeDateTime() {
insert (np_test_1_all.cpp:6990)
6980}
6981
6982void testBusinessDateRangeDateTime() {
6983 std::cout << "========= testBusinessDateRangeDateTime =======================";
6984
6985 datetime64 start("2024-03-11"); // Monday
6986 datetime64 end("2024-03-22"); // Friday (2 weeks later)
6987
6988 // Create holidays set
6989 std::set<datetime64> holidays;
6990 holidays.insert(datetime64("2024-03-15")); // Friday holiday
6991
6992 auto business_dates = createBusinessDateRange(start, end, holidays);
6993 // std::cout << "Business dates from " << start.toString()
6994 // << " to " << end.toString() << " (excluding 2024-03-15):" << std::endl;
6995 //business_dates.printArray();
6996
6997 std::cout << " -> tests passed" << std::endl;
6998}
6999
7000void testMonthRangeDateTime() {
stack (np_test_1_all.cpp:5509)
5499void testStackArrayUtils() {
5500 std::cout << "========= testStackArrayUtils =======================";
5501
5502 // Test 1D stacking
5503 auto arr1 = NDArray<int32>::createRange(0, 3, 1); // [0, 1, 2]
5504 auto arr2 = NDArray<int32>::createRange(3, 6, 1); // [3, 4, 5]
5505 auto arr3 = NDArray<int32>::createRange(6, 9, 1); // [6, 7, 8]
5506
5507 // Stack along axis 0 (new first dimension)
5508 auto result0 = stack<int32>({arr1, arr2, arr3}, 0);
5509 // std::cout << "1D stack (axis=0):";
5510 //result0.printArray();
5511
5512 if (!(result0.getShape()[0] == 3)) {
5513 std::string description = std::string("testStackArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result0.getShape()[0] == 3)";
5514 std::cout << std::string("[FAIL] ") + description << std::endl;
5515 throw std::runtime_error(description);
5516 }
5517 if (!(result0.getShape()[1] == 3)) {
5518 std::string description = std::string("testStackArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result0.getShape()[1] == 3)";
astype (np_test_3_all.cpp:796)
786 auto ufunc_square = numpy::frompyfunc(square, 1, 1);
787
788 numpy::NDArray<double> arr({ 3 });
789 arr.setElementAt({ 0 }, 2.0);
790 arr.setElementAt({ 1 }, 3.0);
791 arr.setElementAt({ 2 }, 4.0);
792
793 auto result = ufunc_square(arr);
794
795 // Convert back to double to check values
796 auto typed_result = numpy::astype<double>(result);
797 if (std::abs(typed_result.getElementAt({ 0 }) - 4.0) > 1e-10 ||
798 std::abs(typed_result.getElementAt({ 1 }) - 9.0) > 1e-10 ||
799 std::abs(typed_result.getElementAt({ 2 }) - 16.0) > 1e-10) {
800 std::cout << "[FAIL] Basic frompyfunc creation failed";
801 return 1;
802 }
803
804 // std::cout << "[OK] Basic frompyfunc creation works correctly" << std::endl;
805 std::cout << " -> tests passed" << std::endl;
806 return 0;
astype (np_test_3_all.cpp:796)
786 auto ufunc_square = numpy::frompyfunc(square, 1, 1);
787
788 numpy::NDArray<double> arr({ 3 });
789 arr.setElementAt({ 0 }, 2.0);
790 arr.setElementAt({ 1 }, 3.0);
791 arr.setElementAt({ 2 }, 4.0);
792
793 auto result = ufunc_square(arr);
794
795 // Convert back to double to check values
796 auto typed_result = numpy::astype<double>(result);
797 if (std::abs(typed_result.getElementAt({ 0 }) - 4.0) > 1e-10 ||
798 std::abs(typed_result.getElementAt({ 1 }) - 9.0) > 1e-10 ||
799 std::abs(typed_result.getElementAt({ 2 }) - 16.0) > 1e-10) {
800 std::cout << "[FAIL] Basic frompyfunc creation failed";
801 return 1;
802 }
803
804 // std::cout << "[OK] Basic frompyfunc creation works correctly" << std::endl;
805 std::cout << " -> tests passed" << std::endl;
806 return 0;
copy (np_test_1_all.cpp:9812)
9802 //original.printArray();
9803
9804 // The modification should be at position (1,1) in original
9805 if (!(original.getElementAt({1, 1}) == 9999)) {
9806 std::string description = std::string("testSliceCopyVsViewMemoryOwnership():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 9999)";
9807 std::cout << std::string("[FAIL] ") + description << std::endl;
9808 throw std::runtime_error(description);
9809 }
9810 // std::cout << "[OK] Slice view shares memory with original";
9811
9812 // Test slice copy (should be independent)
9813 auto slice_copy = original.sliceArray({{2, 4}, {2, 4}});
9814 // std::cout << "Slice copy [2:4, 2:4]:";
9815 //slice_copy.printArray();
9816
9817 slice_copy.setElementAt({0, 0}, 7777);
9818
9819 // std::cout << "After modifying slice copy at (0,0):" << std::endl;
9820 // std::cout << "Original array:" << std::endl;
9821 //original.printArray();
9822 // std::cout << "Slice copy:" << std::endl;
combine (np_test_5_all.cpp:22273)
22263 auto pass = true;
22264 std::string fail_msg;
22265
22266 // Default constructor (NaT)
22267 numpy::Timestamp nat;
22268 if (!nat.isNaT()) {
22269 pass = false;
22270 fail_msg = "Default constructor should create NaT";
22271 }
22272
22273 // Component constructor
22274 numpy::Timestamp ts1(2024, 6, 15, 14, 30, 45);
22275 if (ts1.year() != 2024 || ts1.month() != 6 || ts1.day() != 15 ||
22276 ts1.hour() != 14 || ts1.minute() != 30 || ts1.second() != 45) {
22277 pass = false;
22278 fail_msg = "Component constructor values incorrect";
22279 }
22280
22281 // With microseconds and nanoseconds
22282 numpy::Timestamp ts2(2024, 1, 1, 12, 0, 0, 123456, 789);
A (np_test_1_all.cpp:15562)
15552 auto pseudoinv = pinv(matrix);
15553
15554 // std::cout << "Pseudoinverse:" << std::endl;
15555 //pseudoinv.printArray();
15556
15557 // Test Moore-Penrose conditions
15558 // 1. A * A^+ * A = A
15559 auto AApA = matmul(matmul(matrix, pseudoinv), matrix);
15560
15561 // std::cout << "A * A^+ * A (should equal A):" << std::endl;
15562 //AApA.printArray();
15563
15564 // Check reconstruction
15565 double max_error = 0.0;
15566 for (size_t i = 0; i < 3; ++i) {
15567 for (size_t j = 0; j < 2; ++j) {
15568 double error = std::abs(matrix.getElementAt({ i, j }) - AApA.getElementAt({ i, j }));
15569 if (error > max_error) max_error = error;
15570 }
15571 }
A (np_test_1_all.cpp:15562)
15552 auto pseudoinv = pinv(matrix);
15553
15554 // std::cout << "Pseudoinverse:" << std::endl;
15555 //pseudoinv.printArray();
15556
15557 // Test Moore-Penrose conditions
15558 // 1. A * A^+ * A = A
15559 auto AApA = matmul(matmul(matrix, pseudoinv), matrix);
15560
15561 // std::cout << "A * A^+ * A (should equal A):" << std::endl;
15562 //AApA.printArray();
15563
15564 // Check reconstruction
15565 double max_error = 0.0;
15566 for (size_t i = 0; i < 3; ++i) {
15567 for (size_t j = 0; j < 2; ++j) {
15568 double error = std::abs(matrix.getElementAt({ i, j }) - AApA.getElementAt({ i, j }));
15569 if (error > max_error) max_error = error;
15570 }
15571 }
B (np_test_2_all.cpp:3245)
3235 mkl_set_num_threads(4);
3236 int num_threads = mkl_get_max_threads();
3237 // std::cout << "MKL Max Threads: " << num_threads << std::endl;
3238
3239 std::cout << " -> tests passed" << std::endl;
3240 }
3241
3242 void testMKLMatrixMultiplication() {
3243 std::cout << "========= testMKLMatrixMultiplication =======================";
3244
3245 // Create test matrices: A (3x4) * B (4x2) = C (3x2)
3246 const int m = 3, n = 2, k = 4;
3247
3248 // Matrix A (3x4) - row major order
3249 std::vector<double> A = {
3250 1.0, 2.0, 3.0, 4.0, // row 0
3251 5.0, 6.0, 7.0, 8.0, // row 1
3252 9.0, 10.0, 11.0, 12.0 // row 2
3253 };
3254
3255 // Matrix B (4x2) - row major order
axes (np_test_5_all.cpp:16631)
16621 return 0;
16622 } else {
16623 std::cout << " [FAIL] reshape() failed" << std::endl;
16624 return 1;
16625 }
16626}
16627
16628// Test 15: transpose() - Transpose array (SKIPPED - needs implementation)
16629int test_transpose() {
16630 std::cout << "\n[TEST] ma.transpose() - SKIPPED (needs correct transpose API)" << std::endl;
16631 return 0; // Skip for now
16632}
16633
16634// Test 16: swapaxes() - Swap two axes (SKIPPED - needs implementation)
16635int test_swapaxes() {
16636 std::cout << "\n[TEST] ma.swapaxes() - SKIPPED (needs correct swapaxes API)" << std::endl;
16637 return 0; // Skip for now
16638}
16639
16640// Test 17: repeat() - Repeat elements
16641int test_repeat() {
b (np_test_1_all.cpp:7707)
7697 // std::cout << "Float16 ones array (2x3):";
7698 //ones_array.printArray();
7699
7700 std::cout << " -> tests passed" << std::endl;
7701}
7702
7703void testFloat16ArithmeticFloat16() {
7704 std::cout << "========= testFloat16ArithmeticFloat16 =======================";
7705
7706 float16 a(2.5f);
7707 float16 b(1.5f);
7708
7709 // std::cout << "a = " << a << ", b = " << b << std::endl;
7710 // std::cout << "a + b = " << (a + b) << std::endl;
7711 // std::cout << "a - b = " << (a - b) << std::endl;
7712 // std::cout << "a * b = " << (a * b) << std::endl;
7713 // std::cout << "a / b = " << (a / b) << std::endl;
7714
7715 // Test array arithmetic
7716 auto arr1 = createFloat16Array({2}, float16(2.5f));
7717 auto arr2 = createFloat16Array({2}, float16(1.5f));
begin (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
begin (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
bool_ (np_test_3_all.cpp:15233)
15223 std::cout << "========= test_where_selection ====";
15224
15225 // Create condition, x, and y arrays
15226 auto cond_data = createBoolArray({ 4 }, false);
15227 cond_data.setElementAt({ 0 }, true);
15228 cond_data.setElementAt({ 1 }, false);
15229 cond_data.setElementAt({ 2 }, true);
15230 cond_data.setElementAt({ 3 }, false);
15231
15232 auto cond_mask = createBoolArray({ 4 }, false);
15233 MaskedArray<bool_> condition(cond_data, cond_mask, bool_(false));
15234
15235 auto x_data = createInt32Array({ 4 }, 0);
15236 x_data.setElementAt({ 0 }, 10);
15237 x_data.setElementAt({ 1 }, 20);
15238 x_data.setElementAt({ 2 }, 30);
15239 x_data.setElementAt({ 3 }, 40);
15240
15241 auto x_mask = createBoolArray({ 4 }, false);
15242 MaskedArray<int32> x(x_data, x_mask, -999);
check_file (np_test_5_all.cpp:709)
699 arr.setElementAt({ static_cast<size_t>(i / 3), static_cast<size_t>(i % 3) }, i);
700 }
701
702 writer.add_array("data", arr);
703 writer.finalize(); // Test finalize
704
705 // std::cout << " NPZ file finalized successfully" << std::endl;
706 }
707
708 // Verify file was written
709 std::ifstream check_file(filename, std::ios::binary);
710 assert_condition(check_file.good(), "NPZ file was not created after finalize()");
711 check_file.close();
712
713 // std::cout << " Verified NPZ file exists on disk" << std::endl;
714
715 std::cout << " -> tests passed" << std::endl;
716 }
717
718 void np_test_io_npz_add_arrays_to_writer() {
719 std::cout << "========= add_arrays_to_writer() helper ========================";
check_file (np_test_5_all.cpp:709)
699 arr.setElementAt({ static_cast<size_t>(i / 3), static_cast<size_t>(i % 3) }, i);
700 }
701
702 writer.add_array("data", arr);
703 writer.finalize(); // Test finalize
704
705 // std::cout << " NPZ file finalized successfully" << std::endl;
706 }
707
708 // Verify file was written
709 std::ifstream check_file(filename, std::ios::binary);
710 assert_condition(check_file.good(), "NPZ file was not created after finalize()");
711 check_file.close();
712
713 // std::cout << " Verified NPZ file exists on disk" << std::endl;
714
715 std::cout << " -> tests passed" << std::endl;
716 }
717
718 void np_test_io_npz_add_arrays_to_writer() {
719 std::cout << "========= add_arrays_to_writer() helper ========================";
clip (np_test_1_all.cpp:15142)
15132 numpy::NDArray<double> values({ 5 });
15133 values.setElementAt({ 0 }, -2.0);
15134 values.setElementAt({ 1 }, -1.0);
15135 values.setElementAt({ 2 }, 0.5);
15136 values.setElementAt({ 3 }, 2.0);
15137 values.setElementAt({ 4 }, 5.0);
15138 double min_val = -1.0;
15139 double max_val = 3.0;
15140
15141 auto clip_result = numpy::clip(values, min_val, max_val);
15142
15143 bool test8_pass = true;
15144 if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 ||
15145 std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 ||
15146 std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) {
15147 test8_pass = false;
15148 }
15149
15150 if (test8_pass) {
15151 // std::cout << "[OK] Clip function works correctly";
clone (np_test_1_all.cpp:24942)
24932 }
24933
24934 // Test reproducibility
24935 numpy::random::PCG64DXSM rng2(11111);
24936 if (rng2.next_uint64() != val) {
24937 std::cout << " [FAIL] : in np_test_bitgen_pcg64dxsm() : not reproducible";
24938 throw std::runtime_error("np_test_bitgen_pcg64dxsm failed");
24939 }
24940
24941 // Test clone
24942 auto cloned = rng.clone();
24943 if (cloned->name() != "PCG64DXSM") {
24944 std::cout << " [FAIL] : in np_test_bitgen_pcg64dxsm() : clone name incorrect";
24945 throw std::runtime_error("np_test_bitgen_pcg64dxsm failed");
24946 }
24947
24948 std::cout << " -> tests passed" << std::endl;
24949 }
24950
24951 // ============================================================================
24952 // PHILOX TESTS
column (np_test_4_all.cpp:21695)
21685 data.setElementAt({0, 1}, 2.0);
21686 data.setElementAt({0, 2}, 3.0);
21687 data.setElementAt({1, 0}, 4.0);
21688 data.setElementAt({1, 1}, 5.0);
21689 data.setElementAt({1, 2}, 6.0);
21690 data.setElementAt({2, 0}, 7.0);
21691 data.setElementAt({2, 1}, 8.0);
21692 data.setElementAt({2, 2}, 9.0);
21693
21694 NDArray<bool_> mask({3, 3}, bool_(false));
21695 // Mask entire middle column (col 1)
21696 mask.setElementAt({0, 1}, bool_(true));
21697 mask.setElementAt({1, 1}, bool_(true));
21698 mask.setElementAt({2, 1}, bool_(true));
21699
21700 auto ma = ma::masked_array(data, mask);
21701 auto result = ma::compress_cols(ma);
21702
21703 // Should keep columns 0 and 2 only
21704 if (!(result.getShape()[0] == 3)) {
21705 std::string description = std::string("np_test_phase6c_compress_cols():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getShape()[0] == 3)";
column (np_test_4_all.cpp:21695)
21685 data.setElementAt({0, 1}, 2.0);
21686 data.setElementAt({0, 2}, 3.0);
21687 data.setElementAt({1, 0}, 4.0);
21688 data.setElementAt({1, 1}, 5.0);
21689 data.setElementAt({1, 2}, 6.0);
21690 data.setElementAt({2, 0}, 7.0);
21691 data.setElementAt({2, 1}, 8.0);
21692 data.setElementAt({2, 2}, 9.0);
21693
21694 NDArray<bool_> mask({3, 3}, bool_(false));
21695 // Mask entire middle column (col 1)
21696 mask.setElementAt({0, 1}, bool_(true));
21697 mask.setElementAt({1, 1}, bool_(true));
21698 mask.setElementAt({2, 1}, bool_(true));
21699
21700 auto ma = ma::masked_array(data, mask);
21701 auto result = ma::compress_cols(ma);
21702
21703 // Should keep columns 0 and 2 only
21704 if (!(result.getShape()[0] == 3)) {
21705 std::string description = std::string("np_test_phase6c_compress_cols():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getShape()[0] == 3)";
columns (np_test_4_all.cpp:22531)
22521 mask.setElementAt({1, 3}, false);
22522
22523 mask.setElementAt({2, 0}, false);
22524 mask.setElementAt({2, 1}, true);
22525 mask.setElementAt({2, 2}, true);
22526 mask.setElementAt({2, 3}, false);
22527
22528 MaskedArray<int> marr(data, mask);
22529 auto result = numpy::ma::compress_nd(marr, 1);
22530
22531 // Should have 2 columns (columns 0 and 3)
22532 if (!(result.data().getShape().size() == 2)) {
22533 std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape().size() == 2)";
22534 std::cout << std::string("[FAIL] ") + description << std::endl;
22535 throw std::runtime_error(description);
22536 }
22537 if (!(result.data().getShape()[0] == 3)) {
22538 std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape()[0] == 3)";
22539 std::cout << std::string("[FAIL] ") + description << std::endl;
22540 throw std::runtime_error(description);
22541 }
columns (np_test_4_all.cpp:22531)
22521 mask.setElementAt({1, 3}, false);
22522
22523 mask.setElementAt({2, 0}, false);
22524 mask.setElementAt({2, 1}, true);
22525 mask.setElementAt({2, 2}, true);
22526 mask.setElementAt({2, 3}, false);
22527
22528 MaskedArray<int> marr(data, mask);
22529 auto result = numpy::ma::compress_nd(marr, 1);
22530
22531 // Should have 2 columns (columns 0 and 3)
22532 if (!(result.data().getShape().size() == 2)) {
22533 std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape().size() == 2)";
22534 std::cout << std::string("[FAIL] ") + description << std::endl;
22535 throw std::runtime_error(description);
22536 }
22537 if (!(result.data().getShape()[0] == 3)) {
22538 std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape()[0] == 3)";
22539 std::cout << std::string("[FAIL] ") + description << std::endl;
22540 throw std::runtime_error(description);
22541 }
columns (np_test_4_all.cpp:22531)
22521 mask.setElementAt({1, 3}, false);
22522
22523 mask.setElementAt({2, 0}, false);
22524 mask.setElementAt({2, 1}, true);
22525 mask.setElementAt({2, 2}, true);
22526 mask.setElementAt({2, 3}, false);
22527
22528 MaskedArray<int> marr(data, mask);
22529 auto result = numpy::ma::compress_nd(marr, 1);
22530
22531 // Should have 2 columns (columns 0 and 3)
22532 if (!(result.data().getShape().size() == 2)) {
22533 std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape().size() == 2)";
22534 std::cout << std::string("[FAIL] ") + description << std::endl;
22535 throw std::runtime_error(description);
22536 }
22537 if (!(result.data().getShape()[0] == 3)) {
22538 std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape()[0] == 3)";
22539 std::cout << std::string("[FAIL] ") + description << std::endl;
22540 throw std::runtime_error(description);
22541 }
columns (np_test_4_all.cpp:22531)
22521 mask.setElementAt({1, 3}, false);
22522
22523 mask.setElementAt({2, 0}, false);
22524 mask.setElementAt({2, 1}, true);
22525 mask.setElementAt({2, 2}, true);
22526 mask.setElementAt({2, 3}, false);
22527
22528 MaskedArray<int> marr(data, mask);
22529 auto result = numpy::ma::compress_nd(marr, 1);
22530
22531 // Should have 2 columns (columns 0 and 3)
22532 if (!(result.data().getShape().size() == 2)) {
22533 std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape().size() == 2)";
22534 std::cout << std::string("[FAIL] ") + description << std::endl;
22535 throw std::runtime_error(description);
22536 }
22537 if (!(result.data().getShape()[0] == 3)) {
22538 std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape()[0] == 3)";
22539 std::cout << std::string("[FAIL] ") + description << std::endl;
22540 throw std::runtime_error(description);
22541 }
count (np_test_1_all.cpp:3616)
3606 // Create larger arrays for performance testing
3607 auto large_arr = NDArray<double>::createOnes({100, 100});
3608 auto broadcast_arr = NDArray<double>::createOnes({1, 100});
3609
3610 // Time the operation (basic timing)
3611 auto start = std::chrono::high_resolution_clock::now();
3612 auto result = large_arr.addArrays(broadcast_arr);
3613 auto end = std::chrono::high_resolution_clock::now();
3614
3615 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
3616 // std::cout << "Large array broadcasting took " << duration.count() << " microseconds" << std::endl;
3617
3618 // Verify result shape
3619 if (!((result.getShape() == std::vector<size_t>{100, 100}))) {
3620 std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((result.getShape() == std::vector<size_t>{100, 100}))";
3621 std::cout << std::string("[FAIL] ") + description << std::endl;
3622 throw std::runtime_error(description);
3623 }
3624 if (!(result.getElementAt({50, 50}) == 2.0)) {
3625 std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({50, 50}) == 2.0)";
3626 std::cout << std::string("[FAIL] ") + description << std::endl;
cumprod (np_test_5_all.cpp:5107)
5097 }
5098
5099 void np_test_cumprod_1d() {
5100 std::cout << "========= cumprod 1D =======================";
5101
5102 // Test cumprod with 1D array
5103 numpy::NDArray<int32_t> arr({ 5 });
5104 arr.setElementAt({ 0 }, 1);
5105 arr.setElementAt({ 1 }, 2);
5106 arr.setElementAt({ 2 }, 3);
5107 arr.setElementAt({ 3 }, 4);
5108 arr.setElementAt({ 4 }, 5);
5109
5110 auto result = numpy::cumprod(arr);
5111
5112 // Expected: [1, 2, 6, 24, 120]
5113 if (result.getElementAt({ 0 }) != 1 || result.getElementAt({ 1 }) != 2 ||
5114 result.getElementAt({ 2 }) != 6 || result.getElementAt({ 3 }) != 24 ||
5115 result.getElementAt({ 4 }) != 120) {
5116 std::cout << " [FAIL] : in np_test_cumprod_1d() : Incorrect cumprod result";
5117 throw std::runtime_error("Test failed");
cumsum (np_test_5_all.cpp:5028)
5018 namespace numpy_tests_cumulative_operations {
5019
5020 void np_test_cumsum_1d() {
5021 std::cout << "========= cumsum 1D =======================";
5022
5023 // Test cumsum with 1D array
5024 numpy::NDArray<int32_t> arr({ 5 });
5025 arr.setElementAt({ 0 }, 1);
5026 arr.setElementAt({ 1 }, 2);
5027 arr.setElementAt({ 2 }, 3);
5028 arr.setElementAt({ 3 }, 4);
5029 arr.setElementAt({ 4 }, 5);
5030
5031 auto result = numpy::cumsum(arr);
5032
5033 // Expected: [1, 3, 6, 10, 15]
5034 if (result.getElementAt({ 0 }) != 1 || result.getElementAt({ 1 }) != 3 ||
5035 result.getElementAt({ 2 }) != 6 || result.getElementAt({ 3 }) != 10 ||
5036 result.getElementAt({ 4 }) != 15) {
5037 std::cout << " [FAIL] : in np_test_cumsum_1d() : Incorrect cumsum result";
5038 throw std::runtime_error("Test failed");
data (np_test_1_all.cpp:2084)
2074 }
2075 if (!(derived_ptr->extra == 2)) {
2076 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077 std::cout << std::string("[FAIL] ") + description << std::endl;
2078 throw std::runtime_error(description);
2079 }
2080
2081 // Test 6: Large object handling
2082 struct LargeObject {
2083 std::vector<double> data;
2084 LargeObject() : data(10000, 3.14159) {} // Large object
2085 };
2086
2087 LargeObject large;
2088 object_ large_obj(large); // Should handle large objects
2089 if (!(!large_obj.is_null())) {
2090 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091 std::cout << std::string("[FAIL] ") + description << std::endl;
2092 throw std::runtime_error(description);
2093 }
2094 if (!(large_obj.is_type<LargeObject>())) {
data (np_test_1_all.cpp:2084)
2074 }
2075 if (!(derived_ptr->extra == 2)) {
2076 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077 std::cout << std::string("[FAIL] ") + description << std::endl;
2078 throw std::runtime_error(description);
2079 }
2080
2081 // Test 6: Large object handling
2082 struct LargeObject {
2083 std::vector<double> data;
2084 LargeObject() : data(10000, 3.14159) {} // Large object
2085 };
2086
2087 LargeObject large;
2088 object_ large_obj(large); // Should handle large objects
2089 if (!(!large_obj.is_null())) {
2090 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091 std::cout << std::string("[FAIL] ") + description << std::endl;
2092 throw std::runtime_error(description);
2093 }
2094 if (!(large_obj.is_type<LargeObject>())) {
data (np_test_1_all.cpp:2084)
2074 }
2075 if (!(derived_ptr->extra == 2)) {
2076 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077 std::cout << std::string("[FAIL] ") + description << std::endl;
2078 throw std::runtime_error(description);
2079 }
2080
2081 // Test 6: Large object handling
2082 struct LargeObject {
2083 std::vector<double> data;
2084 LargeObject() : data(10000, 3.14159) {} // Large object
2085 };
2086
2087 LargeObject large;
2088 object_ large_obj(large); // Should handle large objects
2089 if (!(!large_obj.is_null())) {
2090 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091 std::cout << std::string("[FAIL] ") + description << std::endl;
2092 throw std::runtime_error(description);
2093 }
2094 if (!(large_obj.is_type<LargeObject>())) {
data (np_test_1_all.cpp:2084)
2074 }
2075 if (!(derived_ptr->extra == 2)) {
2076 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077 std::cout << std::string("[FAIL] ") + description << std::endl;
2078 throw std::runtime_error(description);
2079 }
2080
2081 // Test 6: Large object handling
2082 struct LargeObject {
2083 std::vector<double> data;
2084 LargeObject() : data(10000, 3.14159) {} // Large object
2085 };
2086
2087 LargeObject large;
2088 object_ large_obj(large); // Should handle large objects
2089 if (!(!large_obj.is_null())) {
2090 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091 std::cout << std::string("[FAIL] ") + description << std::endl;
2092 throw std::runtime_error(description);
2093 }
2094 if (!(large_obj.is_type<LargeObject>())) {
data (np_test_1_all.cpp:2084)
2074 }
2075 if (!(derived_ptr->extra == 2)) {
2076 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077 std::cout << std::string("[FAIL] ") + description << std::endl;
2078 throw std::runtime_error(description);
2079 }
2080
2081 // Test 6: Large object handling
2082 struct LargeObject {
2083 std::vector<double> data;
2084 LargeObject() : data(10000, 3.14159) {} // Large object
2085 };
2086
2087 LargeObject large;
2088 object_ large_obj(large); // Should handle large objects
2089 if (!(!large_obj.is_null())) {
2090 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091 std::cout << std::string("[FAIL] ") + description << std::endl;
2092 throw std::runtime_error(description);
2093 }
2094 if (!(large_obj.is_type<LargeObject>())) {
data (np_test_1_all.cpp:2084)
2074 }
2075 if (!(derived_ptr->extra == 2)) {
2076 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077 std::cout << std::string("[FAIL] ") + description << std::endl;
2078 throw std::runtime_error(description);
2079 }
2080
2081 // Test 6: Large object handling
2082 struct LargeObject {
2083 std::vector<double> data;
2084 LargeObject() : data(10000, 3.14159) {} // Large object
2085 };
2086
2087 LargeObject large;
2088 object_ large_obj(large); // Should handle large objects
2089 if (!(!large_obj.is_null())) {
2090 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091 std::cout << std::string("[FAIL] ") + description << std::endl;
2092 throw std::runtime_error(description);
2093 }
2094 if (!(large_obj.is_type<LargeObject>())) {
data (np_test_1_all.cpp:2084)
2074 }
2075 if (!(derived_ptr->extra == 2)) {
2076 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077 std::cout << std::string("[FAIL] ") + description << std::endl;
2078 throw std::runtime_error(description);
2079 }
2080
2081 // Test 6: Large object handling
2082 struct LargeObject {
2083 std::vector<double> data;
2084 LargeObject() : data(10000, 3.14159) {} // Large object
2085 };
2086
2087 LargeObject large;
2088 object_ large_obj(large); // Should handle large objects
2089 if (!(!large_obj.is_null())) {
2090 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091 std::cout << std::string("[FAIL] ") + description << std::endl;
2092 throw std::runtime_error(description);
2093 }
2094 if (!(large_obj.is_type<LargeObject>())) {
describe (np_test_1_all.cpp:11448)
11438 auto moment2_result = moment(normal_data, 2);
11439 // std::cout << "2nd moment: " << moment2_result.getElementAt({ 0 }) << std::endl;
11440 if (!(moment2_result.getElementAt({ 0 }) > 0)) {
11441 std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moment2_result.getElementAt({ 0 }) > 0)";
11442 std::cout << std::string("[FAIL] ") + description << std::endl;
11443 throw std::runtime_error(description);
11444 }
11445 // std::cout << "[OK] Moment calculation\n";
11446
11447 // Test describe
11448 auto desc_result = describe(normal_data);
11449 // std::cout << "Describe result:" << std::endl;
11450 // std::cout << " nobs: " << desc_result.nobs << std::endl;
11451 // std::cout << " min: " << desc_result.minmax.first << ", max: " << desc_result.minmax.second << std::endl;
11452 // std::cout << " mean: " << desc_result.mean << std::endl;
11453 // std::cout << " variance: " << desc_result.variance << std::endl;
11454 if (!(desc_result.nobs == 5)) {
11455 std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(desc_result.nobs == 5)";
11456 std::cout << std::string("[FAIL] ") + description << std::endl;
11457 throw std::runtime_error(description);
11458 }
diff (np_test_2_all.cpp:4947)
4937 // Test matrix addition and subtraction
4938 numpy::Matrix<double> a("1 2; 3 4");
4939 numpy::Matrix<double> b("5 6; 7 8");
4940
4941 auto sum = a + b;
4942 assert_test(std::abs(sum(0, 0) - 6.0) < 1e-10, "Matrix addition");
4943 assert_test(std::abs(sum(1, 1) - 12.0) < 1e-10, "Matrix addition");
4944
4945 auto diff = b - a;
4946 assert_test(std::abs(diff(0, 0) - 4.0) < 1e-10, "Matrix subtraction");
4947 assert_test(std::abs(diff(1, 1) - 4.0) < 1e-10, "Matrix subtraction");
4948
4949 // Test matrix multiplication (not element-wise!)
4950 auto product = a * b;
4951 assert_test(std::abs(product(0, 0) - 19.0) < 1e-10, "Matrix multiplication 0,0");
4952 assert_test(std::abs(product(0, 1) - 22.0) < 1e-10, "Matrix multiplication 0,1");
4953 assert_test(std::abs(product(1, 0) - 43.0) < 1e-10, "Matrix multiplication 1,0");
4954 assert_test(std::abs(product(1, 1) - 50.0) < 1e-10, "Matrix multiplication 1,1");
4955
4956 // Test scalar multiplication
dtype_name (np_test_2_all.cpp:3567)
3557 std::cout << std::string("[FAIL] ") + description << std::endl;
3558 throw std::runtime_error(description);
3559 }
3560 if (!(flags_info.writeable == true)) {
3561 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.writeable == true)";
3562 std::cout << std::string("[FAIL] ") + description << std::endl;
3563 throw std::runtime_error(description);
3564 }
3565
3566 // Test dtype functions
3567 if (!(dtype_name(arr) == "float64")) {
3568 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_name(arr) == \"float64\")";
3569 std::cout << std::string("[FAIL] ") + description << std::endl;
3570 throw std::runtime_error(description);
3571 }
3572 if (!(dtype_itemsize(arr) == sizeof(double))) {
3573 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_itemsize(arr) == sizeof(double))";
3574 std::cout << std::string("[FAIL] ") + description << std::endl;
3575 throw std::runtime_error(description);
3576 }
dtypes (np_test_4_all.cpp:10403)
10393 }
10394 catch (const std::exception& e) {
10395 std::cout << "====================================== np_test_power_scalar FAILED ==================================== ";
10396 std::cout << "Exception: " << e.what() << std::endl;
10397 return 1;
10398 }
10399 }
10400
10401} // namespace numpy_tests
10402// Test file for abs() scalar support
10403// Tests all 13 dtypes (8 int, 1 bool, 2 float, 2 complex) + edge cases
10404// Expected: 17 tests, all passing
10405
10406#include <iostream>
10407#include <cmath>
10408#include <stdexcept>
10409#include "../numpy/np_ndarray.h"
10410#include "../numpy/np_math_utils_sqrt.h"
10411
10412namespace numpy_tests {
10413namespace numpy_tests_abs_scalar {
end (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
end (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
end (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
end (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
end (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream
27026 std::ifstream file(test_filename, std::ios::binary);
27027 file.seekg(30); // Move to position 30
27028 size_t size2 = io::get_remaining_size(file);
27029 if (size2 != 70) {
27030 std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031 throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032 }
27033
27034 // Verify position preserved
27035 auto pos = file.tellg();
27036 if (pos != 30) {
filter (np_test_2_all.cpp:9555)
9545 for (int i = 0; i < size; i++) {
9546 signal[i] = std::sin(2.0f * 3.14159f * i / 8.0f) + 0.1f * (i % 3 - 1);
9547 }
9548
9549 // std::cout << "Original Signal: ";
9550 for (int i = 0; i < size; i++) {
9551 // std::cout << std::setw(8) << std::fixed << std::setprecision(3) << signal[i] << " ";
9552 }
9553 // std::cout << std::endl;
9554
9555 // Apply a simple smoothing filter (moving average)
9556 const int kernel_size = 3;
9557 std::vector<Ipp32f> kernel = { 1.0f / 3.0f, 1.0f / 3.0f, 1.0f / 3.0f };
9558
9559 // For simplicity, we'll do a basic convolution manually for demonstration
9560 for (int i = 1; i < size - 1; i++) {
9561 filtered[i] = (signal[i - 1] + signal[i] + signal[i + 1]) / 3.0f;
9562 }
9563 filtered[0] = signal[0];
9564 filtered[size - 1] = signal[size - 1];
first (np_test_4_all.cpp:12410)
12400 // std::cout << "[OK] NaN-ignoring behavior tests\n";
12401}
12402
12403// Test both NaN returns first NaN
12404void test_fmax_both_nan() {
12405 std::cout << "========= test_fmax_both_nan ====";
12406
12407 double nan1 = std::numeric_limits<double>::quiet_NaN();
12408 double nan2 = std::numeric_limits<double>::quiet_NaN();
12409
12410 // If both are NaN, return first (which is still NaN)
12411 double result = numpy::fmax(nan1, nan2);
12412 if (!std::isnan(result)) {
12413 std::cout << " [FAIL] : test_fmax_both_nan failed - fmax(NaN, NaN) should be NaN";
12414 throw std::runtime_error("fmax(NaN, NaN) should return NaN");
12415 }
12416
12417 // std::cout << "[OK] Both NaN returns NaN test\n";
12418}
12419
12420// Test type preservation
flags (np_test_2_all.cpp:3554)
3544 }
3545
3546 // Test nbytes
3547 if (!(nbytes(arr) == 24 * sizeof(double))) {
3548 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(nbytes(arr) == 24 * sizeof(double))";
3549 std::cout << std::string("[FAIL] ") + description << std::endl;
3550 throw std::runtime_error(description);
3551 }
3552
3553 // Test flags
3554 auto flags_info = flags(arr);
3555 if (!(flags_info.owndata == true)) {
3556 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.owndata == true)";
3557 std::cout << std::string("[FAIL] ") + description << std::endl;
3558 throw std::runtime_error(description);
3559 }
3560 if (!(flags_info.writeable == true)) {
3561 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.writeable == true)";
3562 std::cout << std::string("[FAIL] ") + description << std::endl;
3563 throw std::runtime_error(description);
3564 }
found (np_test_1_all.cpp:27676)
27666 void test_clump_masked_unmasked() {
27667 std::cout << "========= ma::clump_masked() and ma::clump_unmasked(): find sequences ===";
27668
27669 auto data = numpy::array({ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 });
27670 auto mask = numpy::array({ false, true, true, false, false, true });
27671 auto ma = numpy::ma::masked_array(data, mask);
27672
27673 auto masked_clumps = numpy::ma::clump_masked(ma);
27674 auto unmasked_clumps = numpy::ma::clump_unmasked(ma);
27675
27676 // std::cout << " ma::clump_masked([F,T,T,F,F,T]): " << masked_clumps.size() << " sequences found (expected: 2)" << std::endl;
27677 // std::cout << " ma::clump_unmasked([F,T,T,F,F,T]): " << unmasked_clumps.size() << " sequences found (expected: 2)" << std::endl;
27678 std::cout << " -> tests passed" << std::endl;
27679 }
27680
27681 void test_mask_rows_cols() {
27682 std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ===";
27683
27684 auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} });
27685 auto mask = numpy::array({ {false, true, false}, {false, false, false} });
27686 auto ma = numpy::ma::masked_array(data, mask);
found (np_test_1_all.cpp:27676)
27666 void test_clump_masked_unmasked() {
27667 std::cout << "========= ma::clump_masked() and ma::clump_unmasked(): find sequences ===";
27668
27669 auto data = numpy::array({ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 });
27670 auto mask = numpy::array({ false, true, true, false, false, true });
27671 auto ma = numpy::ma::masked_array(data, mask);
27672
27673 auto masked_clumps = numpy::ma::clump_masked(ma);
27674 auto unmasked_clumps = numpy::ma::clump_unmasked(ma);
27675
27676 // std::cout << " ma::clump_masked([F,T,T,F,F,T]): " << masked_clumps.size() << " sequences found (expected: 2)" << std::endl;
27677 // std::cout << " ma::clump_unmasked([F,T,T,F,F,T]): " << unmasked_clumps.size() << " sequences found (expected: 2)" << std::endl;
27678 std::cout << " -> tests passed" << std::endl;
27679 }
27680
27681 void test_mask_rows_cols() {
27682 std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ===";
27683
27684 auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} });
27685 auto mask = numpy::array({ {false, true, false}, {false, false, false} });
27686 auto ma = numpy::ma::masked_array(data, mask);
gen (np_test_1_all.cpp:6126)
6116 }
6117
6118 // std::cout << "BenchmarkResult storage test passed" << std::endl;
6119
6120 std::cout << " -> tests passed" << std::endl;
6121}
6122
6123void test_data_generator_randomBenchmarkSorting() {
6124 std::cout << "========= test_data_generator_random =======================";
6125
6126 DataGenerator<int> gen(42); // Fixed seed for reproducibility
6127
6128 // Test random data generation
6129 std::vector<int> data = gen.generate(100, DataPattern::RANDOM);
6130
6131 if (!(data.size() == 100)) {
6132 std::string description = std::string("test_data_generator_randomBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 100)";
6133 std::cout << std::string("[FAIL] ") + description << std::endl;
6134 throw std::runtime_error(description);
6135 }
index (np_test_5_all.cpp:1283)
1273 // ============================================================================
1274 // SEARCH OPERATION TESTS
1275 // ============================================================================
1276
1277 void np_test_string_index() {
1278 std::cout << "========= index search operation =======================";
1279
1280 std::vector<std::string> strings = { "hello world", "tomorrow" };
1281 auto arr = numpy::char_::array<32>(strings);
1282 auto indices = numpy::char_::index(arr, "o");
1283
1284 bool passed = (indices.getSize() == arr.size());
1285
1286 if (!passed) {
1287 std::cout << " [FAIL] : in np_test_string_index() : indices size mismatch";
1288 throw std::runtime_error("np_test_string_index failed");
1289 }
1290
1291 std::cout << " -> tests passed" << std::endl;
1292 }
index (np_test_5_all.cpp:1283)
1273 // ============================================================================
1274 // SEARCH OPERATION TESTS
1275 // ============================================================================
1276
1277 void np_test_string_index() {
1278 std::cout << "========= index search operation =======================";
1279
1280 std::vector<std::string> strings = { "hello world", "tomorrow" };
1281 auto arr = numpy::char_::array<32>(strings);
1282 auto indices = numpy::char_::index(arr, "o");
1283
1284 bool passed = (indices.getSize() == arr.size());
1285
1286 if (!passed) {
1287 std::cout << " [FAIL] : in np_test_string_index() : indices size mismatch";
1288 throw std::runtime_error("np_test_string_index failed");
1289 }
1290
1291 std::cout << " -> tests passed" << std::endl;
1292 }
info (np_test_2_all.cpp:19772)
19762 // ============================================================================
19763 // INFO TESTS (using primitive types to avoid NDArray complexities)
19764 // ============================================================================
19765
19766 void np_test_introspection_info() {
19767 std::cout << "========= info: display object information =======================";
19768
19769 // Test info on primitive type
19770 int x = 42;
19771 // std::cout << "Primitive type info:" << std::endl;
19772 numpy::introspection::info(x);
19773
19774 double y = 3.14;
19775 // std::cout << "Double type info:" << std::endl;
19776 numpy::introspection::info(y, true);
19777
19778 bool passed = true; // Just verify no exceptions
19779
19780 if (!passed) {
19781 std::cout << " [FAIL] : in np_test_introspection_info() : info test failed";
19782 throw std::runtime_error("np_test_introspection_info failed");
join (np_test_5_all.cpp:1341)
1331 // ============================================================================
1332
1333 void np_test_string_join() {
1334 std::cout << "========= join operation =======================";
1335
1336 // Join takes a separator string and vector of CharArrays
1337 std::vector<numpy::CharArray<32>> arrays;
1338 arrays.push_back(numpy::char_::array<32>({ "a", "b", "c" }));
1339 arrays.push_back(numpy::char_::array<32>({ "x", "y", "z" }));
1340
1341 auto result = numpy::char_::join("-", arrays);
1342
1343 bool passed = true;
1344
1345 if (!passed) {
1346 std::cout << " [FAIL] : in np_test_string_join() : join operation failed";
1347 throw std::runtime_error("np_test_string_join failed");
1348 }
1349
1350 std::cout << " -> tests passed" << std::endl;
1351 }
keys (np_test_2_all.cpp:8614)
8604 if (!indices.empty()) {
8605 std::cout << " IPP empty array test: -> [FAIL]";
8606 throw std::runtime_error("IPP empty array test: FAILED - should return empty");
8607 }
8608 // std::cout << "[OK] IPP empty array test: PASSED" << std::endl;
8609 }
8610
8611 // Test 6: Large array performance
8612 {
8613 const size_t n = 10000;
8614 std::vector<std::vector<int>> keys(2);
8615 keys[0].resize(n);
8616 keys[1].resize(n);
8617
8618 std::mt19937 gen(42);
8619 std::uniform_int_distribution<int> dist(0, 1000);
8620
8621 for (size_t i = 0; i < n; ++i) {
8622 keys[0][i] = dist(gen);
8623 keys[1][i] = dist(gen);
8624 }
keys (np_test_2_all.cpp:8614)
8604 if (!indices.empty()) {
8605 std::cout << " IPP empty array test: -> [FAIL]";
8606 throw std::runtime_error("IPP empty array test: FAILED - should return empty");
8607 }
8608 // std::cout << "[OK] IPP empty array test: PASSED" << std::endl;
8609 }
8610
8611 // Test 6: Large array performance
8612 {
8613 const size_t n = 10000;
8614 std::vector<std::vector<int>> keys(2);
8615 keys[0].resize(n);
8616 keys[1].resize(n);
8617
8618 std::mt19937 gen(42);
8619 std::uniform_int_distribution<int> dist(0, 1000);
8620
8621 for (size_t i = 0; i < n; ++i) {
8622 keys[0][i] = dist(gen);
8623 keys[1][i] = dist(gen);
8624 }
kurtosis (np_test_1_all.cpp:11433)
11423 // std::cout << "Skewness of [1,2,3,4,5]: " << skew_result.getElementAt({ 0 }) << std::endl;
11424 // Should be close to 0 for symmetric data
11425 if (!(std::abs(skew_result.getElementAt({ 0 })) < 0.1)) {
11426 std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(skew_result.getElementAt({ 0 })) < 0.1)";
11427 std::cout << std::string("[FAIL] ") + description << std::endl;
11428 throw std::runtime_error(description);
11429 }
11430 // std::cout << "[OK] Skewness calculation\n";
11431
11432 // Test kurtosis
11433 auto kurt_result = kurtosis(normal_data);
11434 // std::cout << "Kurtosis of [1,2,3,4,5]: " << kurt_result.getElementAt({ 0 }) << std::endl;
11435 // std::cout << "[OK] Kurtosis calculation\n";
11436
11437 // Test moment
11438 auto moment2_result = moment(normal_data, 2);
11439 // std::cout << "2nd moment: " << moment2_result.getElementAt({ 0 }) << std::endl;
11440 if (!(moment2_result.getElementAt({ 0 }) > 0)) {
11441 std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moment2_result.getElementAt({ 0 }) > 0)";
11442 std::cout << std::string("[FAIL] ") + description << std::endl;
11443 throw std::runtime_error(description);
levels (np_test_5_all.cpp:105)
95 }
96
97 std::cout << " -> tests passed" << std::endl;
98 }
99
100 // ===========================================================================
101 // Test 2: Compression Levels
102 // ===========================================================================
103
104 void np_test_zlib_compression_levels() {
105 std::cout << "========= compression levels (0-9) =============================";
106
107 std::vector<unsigned char> data = create_test_data(1000, 'A');
108
109 for (int level = 0; level <= 9; ++level) {
110 uLongf compressed_len = compressBound(static_cast<uLong>(data.size()));
111 std::vector<Bytef> compressed(compressed_len);
112
113 int result = compress2(compressed.data(), &compressed_len,
114 data.data(), static_cast<uLong>(data.size()), level);
mask (np_test_1_all.cpp:27691)
27681 void test_mask_rows_cols() {
27682 std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ===";
27683
27684 auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} });
27685 auto mask = numpy::array({ {false, true, false}, {false, false, false} });
27686 auto ma = numpy::ma::masked_array(data, mask);
27687
27688 auto result_rows = numpy::ma::mask_rows(ma);
27689 auto result_cols = numpy::ma::mask_cols(ma);
27690
27691 // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl;
27692 // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false");
27693 std::cout << " -> tests passed";
27694 }
27695
27696 void test_compress_rowcols() {
27697 std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ===";
27698
27699 auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} });
27700 auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} });
27701 auto ma = numpy::ma::masked_array(data, mask);
mask (np_test_1_all.cpp:27691)
27681 void test_mask_rows_cols() {
27682 std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ===";
27683
27684 auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} });
27685 auto mask = numpy::array({ {false, true, false}, {false, false, false} });
27686 auto ma = numpy::ma::masked_array(data, mask);
27687
27688 auto result_rows = numpy::ma::mask_rows(ma);
27689 auto result_cols = numpy::ma::mask_cols(ma);
27690
27691 // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl;
27692 // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false");
27693 std::cout << " -> tests passed";
27694 }
27695
27696 void test_compress_rowcols() {
27697 std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ===";
27698
27699 auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} });
27700 auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} });
27701 auto ma = numpy::ma::masked_array(data, mask);
name (np_test_1_all.cpp:24865)
24855 uint64_t before_restore = rng.next_uint64();
24856 rng.set_state(state);
24857 uint64_t after_restore = rng.next_uint64();
24858
24859 if (before_restore != after_restore) {
24860 std::cout << " [FAIL] : in np_test_bitgen_mt19937() : state restore failed";
24861 throw std::runtime_error("np_test_bitgen_mt19937 failed: state");
24862 }
24863
24864 // Test name
24865 if (rng.name() != "MT19937") {
24866 std::cout << " [FAIL] : in np_test_bitgen_mt19937() : incorrect name";
24867 throw std::runtime_error("np_test_bitgen_mt19937 failed: name");
24868 }
24869
24870 std::cout << " -> tests passed" << std::endl;
24871 }
24872
24873 // ============================================================================
24874 // PCG64 TESTS
24875 // ============================================================================
names (np_test_2_all.cpp:18817)
18807 create_txt_file("test_auto_names.txt");
18808
18809 // Don't provide names - should generate f0, f1, f2, f3
18810 auto data = numpy::io::recfromtxt(csv_test_dir + "test_auto_names.txt");
18811
18812 auto dtype = data.getDType();
18813
18814 // Verify auto-generated names
18815 if (!dtype.hasField("f0") || !dtype.hasField("f1") ||
18816 !dtype.hasField("f2") || !dtype.hasField("f3")) {
18817 std::cout << " [FAIL] : Missing auto-generated field names (f0, f1, f2, f3)";
18818 throw std::runtime_error("np_test_io_extensions_recfromtxt_auto_names failed: missing auto names");
18819 }
18820
18821 std::cout << " -> tests passed" << std::endl;
18822 }
18823
18824 // ============================================================================
18825 // ERROR HANDLING TESTS
18826 // ============================================================================
nbytes (np_test_2_all.cpp:3547)
3537 }
3538
3539 // Test itemsize
3540 if (!(itemsize(arr) == sizeof(double))) {
3541 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(itemsize(arr) == sizeof(double))";
3542 std::cout << std::string("[FAIL] ") + description << std::endl;
3543 throw std::runtime_error(description);
3544 }
3545
3546 // Test nbytes
3547 if (!(nbytes(arr) == 24 * sizeof(double))) {
3548 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(nbytes(arr) == 24 * sizeof(double))";
3549 std::cout << std::string("[FAIL] ") + description << std::endl;
3550 throw std::runtime_error(description);
3551 }
3552
3553 // Test flags
3554 auto flags_info = flags(arr);
3555 if (!(flags_info.owndata == true)) {
3556 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.owndata == true)";
3557 std::cout << std::string("[FAIL] ") + description << std::endl;
ndim (np_test_2_all.cpp:3526)
3516 void testArrayInfo() {
3517 std::cout << "Testing array information functions...\n";
3518
3519 // Test basic info functions
3520 auto arr = createFloat64Array({ 2, 3, 4 });
3521 for (size_t i = 0; i < arr.getSize(); ++i) {
3522 arr.setElementAt({ i / 12, (i / 4) % 3, i % 4 }, static_cast<double>(i));
3523 }
3524
3525 // Test ndim
3526 if (!(ndim(arr) == 3)) {
3527 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ndim(arr) == 3)";
3528 std::cout << std::string("[FAIL] ") + description << std::endl;
3529 throw std::runtime_error(description);
3530 }
3531
3532 // Test size
3533 if (!(size(arr) == 24)) {
3534 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(size(arr) == 24)";
3535 std::cout << std::string("[FAIL] ") + description << std::endl;
3536 throw std::runtime_error(description);
objects (np_test_1_all.cpp:2136)
2126 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(copy_ptr != large_ptr)";
2127 std::cout << std::string("[FAIL] ") + description << std::endl;
2128 throw std::runtime_error(description);
2129 }
2130 if (!(copy_ptr->data.size() == 10000)) {
2131 std::string description = std::string("unknown_function():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(copy_ptr->data.size() == 10000)";
2132 std::cout << std::string("[FAIL] ") + description << std::endl;
2133 throw std::runtime_error(description);
2134 }
2135
2136 // Test 7: Object containing other objects (if supported)
2137 object_ inner_obj(std::string("inner"));
2138
2139 struct ObjectContainer {
2140 object_ contained;
2141 ObjectContainer(object_ obj) : contained(obj) {}
2142 };
2143
2144 ObjectContainer container(inner_obj);
2145 object_ container_obj(container);
2146 if (!(container_obj.is_type<ObjectContainer>())) {
of (np_test_1_all.cpp:20581)
20571 SchurValidator<std::complex<double>> validator;
20572 SchurBenchmark benchmark("Hermitian matrices");
20573
20574 bool all_passed = true;
20575
20576 // Create Hermitian matrix
20577 NDArray<std::complex<double>> matrix({ 3, 3 });
20578 matrix.setElementAt({ 0, 0 }, std::complex<double>(2, 0));
20579 matrix.setElementAt({ 0, 1 }, std::complex<double>(1, 1));
20580 matrix.setElementAt({ 0, 2 }, std::complex<double>(0, -1));
20581 matrix.setElementAt({ 1, 0 }, std::complex<double>(1, -1)); // Conjugate of (0,1)
20582 matrix.setElementAt({ 1, 1 }, std::complex<double>(3, 0));
20583 matrix.setElementAt({ 1, 2 }, std::complex<double>(1, 0));
20584 matrix.setElementAt({ 2, 0 }, std::complex<double>(0, 1)); // Conjugate of (0,2)
20585 matrix.setElementAt({ 2, 1 }, std::complex<double>(1, 0));
20586 matrix.setElementAt({ 2, 2 }, std::complex<double>(4, 0));
20587
20588 // std::cout << " Testing 3x3 Hermitian matrix..." << std::endl;
20589
20590 benchmark.time_operation([&]() {
20591 auto schur_result = schur_decomposition(matrix);
pad (np_test_1_all.cpp:18733)
18723 std::cout << "========= testPadding =======================";
18724
18725 // Create test array
18726 auto array = createInt32Array({ 2, 2 }, 0);
18727 array.setElementAt({ 0, 0 }, 1);
18728 array.setElementAt({ 0, 1 }, 2);
18729 array.setElementAt({ 1, 0 }, 3);
18730 array.setElementAt({ 1, 1 }, 4);
18731
18732 // Test constant padding
18733 auto padded_const = pad(array, 1, "constant", 0);
18734 if (!(padded_const.getShape()[0] == 4)) {
18735 std::string description = std::string("testPadding():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(padded_const.getShape()[0] == 4)";
18736 std::cout << std::string("[FAIL] ") + description << std::endl;
18737 throw std::runtime_error(description);
18738 }
18739 if (!(padded_const.getShape()[1] == 4)) {
18740 std::string description = std::string("testPadding():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(padded_const.getShape()[1] == 4)";
18741 std::cout << std::string("[FAIL] ") + description << std::endl;
18742 throw std::runtime_error(description);
18743 }
pairs (np_test_2_all.cpp:8793)
8783 if (result != expected) {
8784 std::cout << " IPP integer msort: -> [FAIL]";
8785 throw std::runtime_error("IPP integer msort: FAILED - incorrect sorted order");
8786 }
8787 // std::cout << "[OK] IPP integer msort: PASSED" << std::endl;
8788 }
8789
8790 // Test 2: Float msort with stability test
8791 {
8792 // Test stability using pairs (value, original_index)
8793 struct TestPair {
8794 double value;
8795 int original_index;
8796 bool operator==(const TestPair& other) const {
8797 return value == other.value && original_index == other.original_index;
8798 }
8799 bool operator<(const TestPair& other) const {
8800 return value < other.value;
8801 }
8802 };
pow (np_test_1_all.cpp:15230)
15220 std::cout << "[FAIL] Broadcasting validation failed" << std::endl;
15221 errors++;
15222 }
15223
15224 // Test 11: Performance with caching
15225 std::cout << "========= test_caching_performance =======================" ;
15226
15227 int call_count = 0;
15228 auto expensive_func = [&call_count](double x) {
15229 call_count++;
15230 return std::pow(x, 3) + std::sin(x); // Simulate expensive computation
15231 };
15232
15233 auto cached_vectorized = numpy::vectorize(expensive_func, true, 100);
15234
15235 numpy::NDArray<double> test_array({ 3 });
15236 test_array.setElementAt({ 0 }, 1.0);
15237 test_array.setElementAt({ 1 }, 2.0);
15238 test_array.setElementAt({ 2 }, 3.0);
15239
15240 // First call
pow (np_test_1_all.cpp:15230)
15220 std::cout << "[FAIL] Broadcasting validation failed" << std::endl;
15221 errors++;
15222 }
15223
15224 // Test 11: Performance with caching
15225 std::cout << "========= test_caching_performance =======================" ;
15226
15227 int call_count = 0;
15228 auto expensive_func = [&call_count](double x) {
15229 call_count++;
15230 return std::pow(x, 3) + std::sin(x); // Simulate expensive computation
15231 };
15232
15233 auto cached_vectorized = numpy::vectorize(expensive_func, true, 100);
15234
15235 numpy::NDArray<double> test_array({ 3 });
15236 test_array.setElementAt({ 0 }, 1.0);
15237 test_array.setElementAt({ 1 }, 2.0);
15238 test_array.setElementAt({ 2 }, 3.0);
15239
15240 // First call
prefix (np_test_1_all.cpp:9465)
9455 vstring_ short_str("A");
9456 vstring_ long_str("AAAAA");
9457 if (!(short_str < long_str)) {
9458 std::string description = std::string("testStringOperationEdgeCasesVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(short_str < long_str)";
9459 std::cout << std::string("[FAIL] ") + description << std::endl;
9460 throw std::runtime_error(description);
9461 }
9462
9463 // Test with strings that are prefixes
9464 vstring_ prefix("Test");
9465 vstring_ prefix_extended("Testing");
9466 if (!(prefix < prefix_extended)) {
9467 std::string description = std::string("testStringOperationEdgeCasesVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(prefix < prefix_extended)";
9468 std::cout << std::string("[FAIL] ") + description << std::endl;
9469 throw std::runtime_error(description);
9470 }
9471 if (!(!(prefix > prefix_extended))) {
9472 std::string description = std::string("testStringOperationEdgeCasesVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!(prefix > prefix_extended))";
9473 std::cout << std::string("[FAIL] ") + description << std::endl;
9474 throw std::runtime_error(description);
prod (np_test_1_all.cpp:11795)
11785 throw std::runtime_error(description);
11786 }
11787 // std::cout << "[OK] min and max work correctly\n";
11788
11789 // Test product
11790 auto small_array = createInt32Array({ 3 }, 0);
11791 small_array.setElementAt({ 0 }, 2);
11792 small_array.setElementAt({ 1 }, 3);
11793 small_array.setElementAt({ 2 }, 4);
11794
11795 auto prod_result = prod(small_array);
11796 if (!(prod_result.getElementAt({ 0 }) == 24)) {
11797 std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(prod_result.getElementAt({ 0 }) == 24)";
11798 std::cout << std::string("[FAIL] ") + description << std::endl;
11799 throw std::runtime_error(description);
11800 }
11801 // std::cout << "[OK] prod works correctly\n";
11802 std::cout << " -> tests passed" << std::endl;
11803 }
11804
11805 void testVarianceAndStandardDeviation() {
product (np_test_1_all.cpp:5362)
5352 try {
5353 auto result = array1.multiplyArrays(array2);
5354 std::cout << "[FAIL] Incompatible shape multiplication should have thrown" << std::endl;
5355 } catch (const std::invalid_argument& e) {
5356 // std::cout << "[OK] Incompatible multiplication properly throws: " << e.what();
5357 }
5358
5359 // Test incompatible dot product
5360 try {
5361 auto result = array1.dotProduct(array2); // 2x3 * 3x2 should actually work
5362 // std::cout << "[OK] Compatible dot product (2x3 * 3x2) works" << std::endl;
5363 } catch (const std::exception& e) {
5364 std::cout << " [FAIL] : in testIncompatibleShapesErrorExtended(): Unexpected dot product error: " << e.what();
5365 throw std::runtime_error("testIncompatibleShapesErrorExtended(): Unexpected dot product error: " + std::string(e.what()));
5366 }
5367
5368 // Test truly incompatible dot product
5369 auto array3 = createInt32Array({2, 2}, 1);
5370 try {
5371 auto result = array1.dotProduct(array3); // 2x3 * 2x2 should fail
5372 std::cout << "[FAIL] Incompatible dot product should have thrown" << std::endl;
replace (np_test_1_all.cpp:6717)
6707 std::vector<std::string> text = {"Hello world", "The world is big", "world peace"};
6708 auto arr = array<64>(text);
6709
6710 // std::cout << "Original text:" << std::endl;
6711 for (size_t i = 0; i < arr.size(); ++i) {
6712 // std::cout << "'" << arr[i] << "'";
6713 }
6714
6715 // Test replace
6716 auto replaced = replace(arr, "world", "universe");
6717 // std::cout << "After replacing 'world' with 'universe':" << std::endl;
6718 for (size_t i = 0; i < replaced.size(); ++i) {
6719 // std::cout << "'" << replaced[i] << "'";
6720 }
6721
6722 // Test replace with count limit
6723 std::vector<std::string> repeated_text = {"test test test", "more test cases", "test everything"};
6724 auto repeated_arr = array<64>(repeated_text);
6725 auto limited_replace = replace(repeated_arr, "test", "example", 1);
representation (np_test_2_all.cpp:13663)
13653 // no using namespace in tests - to avoid name clashes
13654
13655 // use a separate namespace for each test group
13656 namespace numpy_tests_bitwise_repr {
13657
13658 // ============================================================================
13659 // BASE_REPR TESTS
13660 // ============================================================================
13661
13662 void np_test_base_repr_binary() {
13663 std::cout << "========= base_repr: binary representation (base=2) =======================";
13664
13665 // Test basic binary conversion
13666 std::string result1 = numpy::base_repr(5, 2);
13667 if (result1 != "101") {
13668 std::cout << " [FAIL] : base_repr(5, 2) returned \"" << result1 << "\", expected \"101\"";
13669 throw std::runtime_error("np_test_base_repr_binary failed");
13670 }
13671
13672 std::string result2 = numpy::base_repr(255, 2);
13673 if (result2 != "11111111") {
representation (np_test_2_all.cpp:13663)
13653 // no using namespace in tests - to avoid name clashes
13654
13655 // use a separate namespace for each test group
13656 namespace numpy_tests_bitwise_repr {
13657
13658 // ============================================================================
13659 // BASE_REPR TESTS
13660 // ============================================================================
13661
13662 void np_test_base_repr_binary() {
13663 std::cout << "========= base_repr: binary representation (base=2) =======================";
13664
13665 // Test basic binary conversion
13666 std::string result1 = numpy::base_repr(5, 2);
13667 if (result1 != "101") {
13668 std::cout << " [FAIL] : base_repr(5, 2) returned \"" << result1 << "\", expected \"101\"";
13669 throw std::runtime_error("np_test_base_repr_binary failed");
13670 }
13671
13672 std::string result2 = numpy::base_repr(255, 2);
13673 if (result2 != "11111111") {
result (np_test_1_all.cpp:6090)
6080 throw std::runtime_error(description);
6081 }
6082 // std::cout << "Timer restart test passed. Second: " << second_elapsed << " ms" << std::endl;
6083
6084 std::cout << " -> tests passed" << std::endl;
6085}
6086
6087void test_benchmark_result_storageBenchmarkSorting() {
6088 std::cout << "========= test_benchmark_result_storage =======================";
6089
6090 BenchmarkResult result("TestAlgorithm", 1000, 15.5, true, 4096);
6091
6092 if (!(result.algorithm_name == "TestAlgorithm")) {
6093 std::string description = std::string("test_benchmark_result_storageBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.algorithm_name == \"TestAlgorithm\")";
6094 std::cout << std::string("[FAIL] ") + description << std::endl;
6095 throw std::runtime_error(description);
6096 }
6097 if (!(result.array_size == 1000)) {
6098 std::string description = std::string("test_benchmark_result_storageBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.array_size == 1000)";
6099 std::cout << std::string("[FAIL] ") + description << std::endl;
6100 throw std::runtime_error(description);
sequences (np_test_1_all.cpp:9081)
9071 NDArray<vstring_> str_array = createVariableStringArrayFromInitializerList({
9072 "First", "Second", "Third"
9073 });
9074 // std::cout << "Variable string array created successfully" << std::endl;
9075 std::cout << " -> tests passed" << std::endl;
9076}
9077
9078void testUTF8EdgeCasesVariableStrings() {
9079 std::cout << "========= testUTF8EdgeCasesVariableStrings =======================";
9080
9081 // Test 1: Invalid UTF-8 sequences (should be handled gracefully)
9082 std::string invalid_utf8_orphaned = "\x80\x81\x82"; // Orphaned continuation bytes
9083 vunicode_ orphaned_test(invalid_utf8_orphaned);
9084 // Should not crash and produce some result
9085 if (!(!orphaned_test.to_utf8().empty() || orphaned_test.empty())) {
9086 std::string description = std::string("testUTF8EdgeCasesVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!orphaned_test.to_utf8().empty() || orphaned_test.empty())";
9087 std::cout << std::string("[FAIL] ") + description << std::endl;
9088 throw std::runtime_error(description);
9089 }
9090
9091 std::string invalid_utf8_start = "\xF8\xF9\xFF"; // Invalid start bytes
shape (np_test_1_all.cpp:3751)
3741 }
3742
3743 for (size_t j = 0; j < 3; ++j) {
3744 arr3.setElementAt({0, j}, static_cast<double>((j + 1) * 100)); // [100, 200, 300]
3745 }
3746
3747 // Broadcast all arrays together
3748 std::vector<NDArray<double>> arrays = {arr1, arr2, arr3};
3749 auto broadcasted = broadcast_arrays(arrays);
3750
3751 // All should have shape (2, 3)
3752 for (const auto& arr : broadcasted) {
3753 if (!((arr.getShape() == std::vector<size_t>{2, 3}))) {
3754 std::string description = std::string("test_broadcast_arrays():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((arr.getShape() == std::vector<size_t>{2, 3}))";
3755 std::cout << std::string("[FAIL] ") + description << std::endl;
3756 throw std::runtime_error(description);
3757 }
3758 }
3759
3760 // Check values
3761 if (!(broadcasted[0].getElementAt({0, 1}) == 2.0)) {
shift (np_test_1_all.cpp:2761)
2751 throw std::runtime_error(description);
2752 }
2753 if (!(left_array.getElementAt({3}) == 16384)) {
2754 std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(left_array.getElementAt({3}) == 16384)";
2755 std::cout << std::string("[FAIL] ") + description << std::endl;
2756 throw std::runtime_error(description);
2757 }
2758
2759 // std::cout << "[OK] Left shift by array\n";
2760
2761 // Test excessive shift (should result in 0)
2762 auto excessive_left = left_shift(arr, 20); // More than 16 bits
2763 if (!(excessive_left.getElementAt({0}) == 0)) {
2764 std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(excessive_left.getElementAt({0}) == 0)";
2765 std::cout << std::string("[FAIL] ") + description << std::endl;
2766 throw std::runtime_error(description);
2767 }
2768 if (!(excessive_left.getElementAt({1}) == 0)) {
2769 std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(excessive_left.getElementAt({1}) == 0)";
2770 std::cout << std::string("[FAIL] ") + description << std::endl;
2771 throw std::runtime_error(description);
size (np_test_1_all.cpp:47)
37using namespace numpy;
38using namespace numpy::benchmark;
39using namespace numpy::char_;
40
41// Helper functions for array comparison tests
42namespace {
43 const double TOLERANCE = 1e-10;
44
45 bool allTrue(const NDArray<bool>& arr) {
46 std::vector<size_t> indices(arr.getShape().size(), 0);
47 do {
48 if (!arr.getElementAt(indices)) {
49 return false;
50 }
51 } while (incrementIndices(indices, arr.getShape()));
52 return true;
53 }
54
55 bool allFalse(const NDArray<bool>& arr) {
56 std::vector<size_t> indices(arr.getShape().size(), 0);
skew (np_test_1_all.cpp:11422)
11412 std::cout << "========= testDistributionShapeMeasures =======================";
11413
11414 // Test skewness with known data
11415 auto normal_data = createFloat32Array({ 5 }, 0.0f);
11416 normal_data.setElementAt({ 0 }, 1.0f);
11417 normal_data.setElementAt({ 1 }, 2.0f);
11418 normal_data.setElementAt({ 2 }, 3.0f);
11419 normal_data.setElementAt({ 3 }, 4.0f);
11420 normal_data.setElementAt({ 4 }, 5.0f);
11421
11422 auto skew_result = skew(normal_data);
11423 // std::cout << "Skewness of [1,2,3,4,5]: " << skew_result.getElementAt({ 0 }) << std::endl;
11424 // Should be close to 0 for symmetric data
11425 if (!(std::abs(skew_result.getElementAt({ 0 })) < 0.1)) {
11426 std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(skew_result.getElementAt({ 0 })) < 0.1)";
11427 std::cout << std::string("[FAIL] ") + description << std::endl;
11428 throw std::runtime_error(description);
11429 }
11430 // std::cout << "[OK] Skewness calculation\n";
11431
11432 // Test kurtosis
ss (np_test_1_all.cpp:25034)
25024 }
25025
25026 // ============================================================================
25027 // SEEDSEQUENCE TESTS
25028 // ============================================================================
25029
25030 void np_test_bitgen_seedsequence() {
25031 std::cout << "========= SeedSequence =======================";
25032
25033 // Test construction
25034 numpy::random::SeedSequence ss(42);
25035
25036 // Test state generation
25037 auto state = ss.generate_state(10);
25038 if (state.size() != 10) {
25039 std::cout << " [FAIL] : in np_test_bitgen_seedsequence() : generate_state size";
25040 throw std::runtime_error("np_test_bitgen_seedsequence failed");
25041 }
25042
25043 // Test spawning
25044 auto children = ss.spawn(5);
str (np_test_1_all.cpp:13279)
13269 throw std::runtime_error(description);
13270 }
13271 // std::cout << "[OK] Vectorized str_len works correctly\n";
13272 std::cout << " -> tests passed" << std::endl;
13273 }
13274
13275 void test_numpy_compatibility_examples() {
13276 std::cout << "========= test_numpy_compatibility_examples =======================";
13277
13278 // Example: numpy string slicing behavior
13279 vstring_ str("hello world"); // length = 11
13280
13281 // These should behave like NumPy string slicing
13282 if (!(str.slice(5, 20).to_string() == " world")) {
13283 std::string description = std::string("test_numpy_compatibility_examples():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.slice(5, 20).to_string() == \" world\")";
13284 std::cout << std::string("[FAIL] ") + description << std::endl;
13285 throw std::runtime_error(description);
13286 }
13287 if (!(str.slice(-20, 5).to_string() == "hello")) {
13288 std::string description = std::string("test_numpy_compatibility_examples():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.slice(-20, 5).to_string() == \"hello\")";
13289 std::cout << std::string("[FAIL] ") + description << std::endl;
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)";
tz_convert (np_test_5_all.cpp:22899)
22889 if (floored_h.hour() != 14 || floored_h.minute() != 0 || floored_h.second() != 0) {
22890 pass = false;
22891 fail_msg = "floor to hour failed";
22892 }
22893
22894 // ceil to hour
22895 numpy::Timestamp ceiled_h = ts.ceil("h");
22896 if (ceiled_h.hour() != 15 || ceiled_h.minute() != 0) {
22897 pass = false;
22898 fail_msg = "ceil to hour failed";
22899 }
22900
22901 // round to hour (37 minutes -> round up)
22902 numpy::Timestamp rounded_h = ts.round("h");
22903 if (rounded_h.hour() != 15) {
22904 pass = false;
22905 fail_msg = "round to hour should be 15 (37 > 30)";
22906 }
22907
22908 // normalize (floor to day)
22909 numpy::Timestamp normalized = ts.normalize();
tz_convert (np_test_5_all.cpp:22899)
22889 if (floored_h.hour() != 14 || floored_h.minute() != 0 || floored_h.second() != 0) {
22890 pass = false;
22891 fail_msg = "floor to hour failed";
22892 }
22893
22894 // ceil to hour
22895 numpy::Timestamp ceiled_h = ts.ceil("h");
22896 if (ceiled_h.hour() != 15 || ceiled_h.minute() != 0) {
22897 pass = false;
22898 fail_msg = "ceil to hour failed";
22899 }
22900
22901 // round to hour (37 minutes -> round up)
22902 numpy::Timestamp rounded_h = ts.round("h");
22903 if (rounded_h.hour() != 15) {
22904 pass = false;
22905 fail_msg = "round to hour should be 15 (37 > 30)";
22906 }
22907
22908 // normalize (floor to day)
22909 numpy::Timestamp normalized = ts.normalize();
tz_localize (np_test_5_all.cpp:22892)
22882 auto pass = true;
22883 std::string fail_msg;
22884
22885 numpy::Timestamp ts(2024, 6, 15, 14, 37, 45, 123456);
22886
22887 // floor to hour
22888 numpy::Timestamp floored_h = ts.floor("h");
22889 if (floored_h.hour() != 14 || floored_h.minute() != 0 || floored_h.second() != 0) {
22890 pass = false;
22891 fail_msg = "floor to hour failed";
22892 }
22893
22894 // ceil to hour
22895 numpy::Timestamp ceiled_h = ts.ceil("h");
22896 if (ceiled_h.hour() != 15 || ceiled_h.minute() != 0) {
22897 pass = false;
22898 fail_msg = "ceil to hour failed";
22899 }
22900
22901 // round to hour (37 minutes -> round up)
22902 numpy::Timestamp rounded_h = ts.round("h");
tz_localize (np_test_5_all.cpp:22892)
22882 auto pass = true;
22883 std::string fail_msg;
22884
22885 numpy::Timestamp ts(2024, 6, 15, 14, 37, 45, 123456);
22886
22887 // floor to hour
22888 numpy::Timestamp floored_h = ts.floor("h");
22889 if (floored_h.hour() != 14 || floored_h.minute() != 0 || floored_h.second() != 0) {
22890 pass = false;
22891 fail_msg = "floor to hour failed";
22892 }
22893
22894 // ceil to hour
22895 numpy::Timestamp ceiled_h = ts.ceil("h");
22896 if (ceiled_h.hour() != 15 || ceiled_h.minute() != 0) {
22897 pass = false;
22898 fail_msg = "ceil to hour failed";
22899 }
22900
22901 // round to hour (37 minutes -> round up)
22902 numpy::Timestamp rounded_h = ts.round("h");
unused (np_test_3_all.cpp:18289)
18279 int n = 3;
18280 int kl = 1;
18281 int ku = 1;
18282 int ldab = 2 * kl + ku + 1; // = 4 for gbtrf
18283 numpy::NDArray<double> AB({ static_cast<size_t>(ldab), static_cast<size_t>(n) });
18284
18285 // Fill band matrix in LAPACK band storage format
18286 // Row ku = 1 contains the superdiagonal
18287 // Row kl+ku = 2 contains the diagonal
18288 // Row kl+ku+1 = 3 contains the subdiagonal
18289 AB.setElementAt({ 0, 0 }, 0.0); // unused (extra space for pivoting)
18290 AB.setElementAt({ 0, 1 }, 0.0);
18291 AB.setElementAt({ 0, 2 }, 1.0); // A[0,2] doesn't exist, just filling
18292
18293 AB.setElementAt({ 1, 0 }, 0.0); // unused
18294 AB.setElementAt({ 1, 1 }, 1.0); // superdiagonal A[0,1]
18295 AB.setElementAt({ 1, 2 }, 1.0); // superdiagonal A[1,2]
18296
18297 AB.setElementAt({ 2, 0 }, 4.0); // diagonal A[0,0]
18298 AB.setElementAt({ 2, 1 }, 4.0); // diagonal A[1,1]
18299 AB.setElementAt({ 2, 2 }, 4.0); // diagonal A[2,2]
v (np_test_3_all.cpp:5664)
5654 // std::cout << "Computed eigenvalues:" << std::endl;
5655 //eig_result.eigenvalues.printArray();
5656
5657 // std::cout << "Eigenvectors:" << std::endl;
5658 //eig_result.eigenvectors.printArray();
5659
5660 // Verify A*v = lambda*v for each eigenvector
5661 double max_residual = 0.0;
5662 for (size_t k = 0; k < 3; ++k) {
5663 // Extract k-th eigenvector
5664 NDArray<complex128> v({ 3, 1 });
5665 for (size_t i = 0; i < 3; ++i) {
5666 v.setElementAt({ i, 0 }, eig_result.eigenvectors.getElementAt({ i, k }));
5667 }
5668
5669 complex128 lambda = eig_result.eigenvalues.getElementAt({ k });
5670
5671 // Compute A*v
5672 auto Av = matmul(matrix, v);
5673
5674 // Compute lambda*v
value (np_test_1_all.cpp:7786)
7776}
7777
7778void testFloat16PrecisionFloat16() {
7779 std::cout << "========= testFloat16PrecisionFloat16 =======================";
7780
7781 // Test precision limits
7782 float16 small_val(0.0001f);
7783 float16 large_val(30000.0f);
7784 float16 very_small(1e-8f); // This might underflow to zero
7785
7786 // std::cout << "Small value (0.0001): " << small_val << std::endl;
7787 // std::cout << "Large value (30000): " << large_val << std::endl;
7788 // std::cout << "Very small value (1e-8): " << very_small << std::endl;
7789
7790 // Test conversion accuracy
7791 float original = 1.234f;
7792 float16 converted(original);
7793 float back_converted = static_cast<float>(converted);
7794
7795 // std::cout << "Original float: " << std::setprecision(10) << original << std::endl;
7796 // std::cout << "Float16 version: " << converted << std::endl;
values (np_test_1_all.cpp:15133)
15123 std::cout << " -> tests passed" << std::endl;
15124 }
15125 else {
15126 std::cout << "[FAIL] Where function failed" << std::endl;
15127 errors++;
15128 }
15129
15130 // Test 8: Clip function
15131 std::cout << "========= test_clip_function =======================" ;
15132
15133 numpy::NDArray<double> values({ 5 });
15134 values.setElementAt({ 0 }, -2.0);
15135 values.setElementAt({ 1 }, -1.0);
15136 values.setElementAt({ 2 }, 0.5);
15137 values.setElementAt({ 3 }, 2.0);
15138 values.setElementAt({ 4 }, 5.0);
15139 double min_val = -1.0;
15140 double max_val = 3.0;
15141
15142 auto clip_result = numpy::clip(values, min_val, max_val);
values (np_test_1_all.cpp:15133)
15123 std::cout << " -> tests passed" << std::endl;
15124 }
15125 else {
15126 std::cout << "[FAIL] Where function failed" << std::endl;
15127 errors++;
15128 }
15129
15130 // Test 8: Clip function
15131 std::cout << "========= test_clip_function =======================" ;
15132
15133 numpy::NDArray<double> values({ 5 });
15134 values.setElementAt({ 0 }, -2.0);
15135 values.setElementAt({ 1 }, -1.0);
15136 values.setElementAt({ 2 }, 0.5);
15137 values.setElementAt({ 3 }, 2.0);
15138 values.setElementAt({ 4 }, 5.0);
15139 double min_val = -1.0;
15140 double max_val = 3.0;
15141
15142 auto clip_result = numpy::clip(values, min_val, max_val);
write (np_test_1_all.cpp:27015)
27005 }
27006
27007 void test_get_remaining_size() {
27008 std::cout << "========= get_remaining_size: calculate remaining file bytes =======================";
27009
27010 // Create temporary test file
27011 const char* test_filename = "temp_test_file_phase5.bin";
27012 {
27013 std::ofstream out(test_filename, std::ios::binary);
27014 const char data[100] = {};
27015 out.write(data, 100);
27016 }
27017
27018 // Test with filename
27019 size_t size1 = io::get_remaining_size(test_filename);
27020 if (size1 != 100) {
27021 std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022 throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023 }
27024
27025 // Test with file stream