From 8e369131384ea4c8f1799dc2f498072d54e5c475 Mon Sep 17 00:00:00 2001 From: HowToSD Date: Wed, 26 Feb 2025 19:39:04 -0800 Subject: [PATCH] Added a large number of low-level PyTorch wrapper nodes. --- __init__.py | 126 ++++++++++++++++++ docs/reference/node_reference.md | 78 ++++++++++- docs/reference/pt_abs.md | 17 +++ docs/reference/pt_acos.md | 17 +++ docs/reference/pt_add.md | 18 +++ docs/reference/pt_asin.md | 17 +++ docs/reference/pt_atan.md | 17 +++ docs/reference/pt_bitwise_and.md | 18 +++ docs/reference/pt_bitwise_left_shift.md | 18 +++ docs/reference/pt_bitwise_not.md | 17 +++ docs/reference/pt_bitwise_or.md | 18 +++ docs/reference/pt_bitwise_right_shift.md | 18 +++ docs/reference/pt_bitwise_xor.md | 18 +++ docs/reference/pt_bmm.md | 18 +++ docs/reference/pt_bool_create.md | 22 +++ docs/reference/pt_cos.md | 17 +++ docs/reference/pt_cosh.md | 17 +++ docs/reference/pt_div.md | 18 +++ docs/reference/pt_einsum.md | 26 ++++ docs/reference/pt_eq.md | 18 +++ docs/reference/pt_exp.md | 17 +++ docs/reference/pt_float_create.md | 2 +- docs/reference/pt_floor_divide.md | 18 +++ docs/reference/pt_from_image.md | 2 +- docs/reference/pt_from_latent.md | 2 +- docs/reference/pt_from_numpy.md | 2 +- docs/reference/pt_ge.md | 18 +++ docs/reference/pt_gt.md | 18 +++ docs/reference/pt_int_create.md | 2 +- docs/reference/pt_le.md | 18 +++ docs/reference/pt_log.md | 17 +++ docs/reference/pt_logical_and.md | 18 +++ docs/reference/pt_logical_not.md | 17 +++ docs/reference/pt_logical_or.md | 18 +++ docs/reference/pt_logical_xor.md | 18 +++ docs/reference/pt_lt.md | 18 +++ docs/reference/pt_matmul.md | 18 +++ docs/reference/pt_mm.md | 18 +++ docs/reference/pt_mul.md | 18 +++ docs/reference/pt_ne.md | 18 +++ docs/reference/pt_neg.md | 17 +++ docs/reference/pt_pow.md | 18 +++ docs/reference/pt_remainder.md | 18 +++ docs/reference/pt_show_text.md | 18 +++ docs/reference/pt_sin.md | 17 +++ docs/reference/pt_sinh.md | 17 +++ docs/reference/pt_size.md | 2 +- docs/reference/pt_size_create.md | 2 +- docs/reference/pt_size_to_numpy.md | 2 +- docs/reference/pt_size_to_string.md | 2 +- docs/reference/pt_sub.md | 18 +++ docs/reference/pt_tan.md | 17 +++ docs/reference/pt_tanh.md | 17 +++ docs/reference/pt_to_image.md | 2 +- docs/reference/pt_to_latent.md | 2 +- docs/reference/pt_to_numpy.md | 2 +- docs/reference/pt_to_rgb_tensors.md | 4 +- modules/numpy_wrapper/numpy_float_create.py | 2 +- modules/numpy_wrapper/numpy_int_create.py | 2 +- modules/pytorch_wrapper/pt_abs.py | 39 ++++++ modules/pytorch_wrapper/pt_acos.py | 39 ++++++ modules/pytorch_wrapper/pt_add.py | 41 ++++++ modules/pytorch_wrapper/pt_asin.py | 39 ++++++ modules/pytorch_wrapper/pt_atan.py | 39 ++++++ modules/pytorch_wrapper/pt_bitwise_and.py | 41 ++++++ .../pytorch_wrapper/pt_bitwise_left_shift.py | 42 ++++++ modules/pytorch_wrapper/pt_bitwise_not.py | 39 ++++++ modules/pytorch_wrapper/pt_bitwise_or.py | 41 ++++++ .../pytorch_wrapper/pt_bitwise_right_shift.py | 42 ++++++ modules/pytorch_wrapper/pt_bitwise_xor.py | 41 ++++++ modules/pytorch_wrapper/pt_bmm.py | 44 ++++++ modules/pytorch_wrapper/pt_bool_create.py | 51 +++++++ modules/pytorch_wrapper/pt_cos.py | 39 ++++++ modules/pytorch_wrapper/pt_cosh.py | 39 ++++++ modules/pytorch_wrapper/pt_div.py | 41 ++++++ modules/pytorch_wrapper/pt_einsum.py | 67 ++++++++++ modules/pytorch_wrapper/pt_eq.py | 41 ++++++ modules/pytorch_wrapper/pt_exp.py | 39 ++++++ modules/pytorch_wrapper/pt_flatten.py | 2 +- modules/pytorch_wrapper/pt_float_create.py | 4 +- modules/pytorch_wrapper/pt_floor_divide.py | 41 ++++++ modules/pytorch_wrapper/pt_from_image.py | 4 +- modules/pytorch_wrapper/pt_from_latent.py | 4 +- modules/pytorch_wrapper/pt_from_numpy.py | 4 +- modules/pytorch_wrapper/pt_ge.py | 41 ++++++ modules/pytorch_wrapper/pt_gt.py | 41 ++++++ modules/pytorch_wrapper/pt_int_create.py | 4 +- modules/pytorch_wrapper/pt_le.py | 41 ++++++ modules/pytorch_wrapper/pt_log.py | 39 ++++++ modules/pytorch_wrapper/pt_logical_and.py | 41 ++++++ modules/pytorch_wrapper/pt_logical_not.py | 39 ++++++ modules/pytorch_wrapper/pt_logical_or.py | 41 ++++++ modules/pytorch_wrapper/pt_logical_xor.py | 41 ++++++ modules/pytorch_wrapper/pt_lt.py | 41 ++++++ modules/pytorch_wrapper/pt_matmul.py | 41 ++++++ modules/pytorch_wrapper/pt_mm.py | 44 ++++++ modules/pytorch_wrapper/pt_mul.py | 41 ++++++ modules/pytorch_wrapper/pt_ne.py | 41 ++++++ modules/pytorch_wrapper/pt_neg.py | 39 ++++++ modules/pytorch_wrapper/pt_pow.py | 41 ++++++ modules/pytorch_wrapper/pt_remainder.py | 41 ++++++ modules/pytorch_wrapper/pt_show_text.py | 62 +++++++++ modules/pytorch_wrapper/pt_sin.py | 39 ++++++ modules/pytorch_wrapper/pt_sinh.py | 39 ++++++ modules/pytorch_wrapper/pt_size.py | 4 +- modules/pytorch_wrapper/pt_size_create.py | 4 +- modules/pytorch_wrapper/pt_size_to_numpy.py | 4 +- modules/pytorch_wrapper/pt_size_to_string.py | 4 +- modules/pytorch_wrapper/pt_sub.py | 41 ++++++ modules/pytorch_wrapper/pt_tan.py | 39 ++++++ modules/pytorch_wrapper/pt_tanh.py | 39 ++++++ modules/pytorch_wrapper/pt_to_image.py | 4 +- modules/pytorch_wrapper/pt_to_latent.py | 4 +- modules/pytorch_wrapper/pt_to_numpy.py | 4 +- modules/pytorch_wrapper/pt_to_rgb_tensors.py | 4 +- pyproject.toml | 2 +- tests/pytorch_wrapper/pt_abs_test.py | 40 ++++++ tests/pytorch_wrapper/pt_acos_test.py | 39 ++++++ tests/pytorch_wrapper/pt_add_test.py | 39 ++++++ tests/pytorch_wrapper/pt_asin_test.py | 39 ++++++ tests/pytorch_wrapper/pt_atan_test.py | 39 ++++++ tests/pytorch_wrapper/pt_bitwise_and_test.py | 40 ++++++ .../pt_bitwise_left_shift_test.py | 40 ++++++ tests/pytorch_wrapper/pt_bitwise_not_test.py | 40 ++++++ tests/pytorch_wrapper/pt_bitwise_or_test.py | 54 ++++++++ .../pt_bitwise_right_shift_test.py | 40 ++++++ tests/pytorch_wrapper/pt_bitwise_xor_test.py | 54 ++++++++ tests/pytorch_wrapper/pt_bmm_test.py | 60 +++++++++ tests/pytorch_wrapper/pt_bool_create_test.py | 58 ++++++++ tests/pytorch_wrapper/pt_cos_test.py | 39 ++++++ tests/pytorch_wrapper/pt_cosh_test.py | 39 ++++++ tests/pytorch_wrapper/pt_div_test.py | 39 ++++++ tests/pytorch_wrapper/pt_einsum_test.py | 99 ++++++++++++++ tests/pytorch_wrapper/pt_eq_test.py | 40 ++++++ tests/pytorch_wrapper/pt_exp_test.py | 39 ++++++ tests/pytorch_wrapper/pt_floor_divide_test.py | 39 ++++++ tests/pytorch_wrapper/pt_ge_test.py | 40 ++++++ tests/pytorch_wrapper/pt_gt_test.py | 40 ++++++ tests/pytorch_wrapper/pt_le_test.py | 40 ++++++ tests/pytorch_wrapper/pt_log_test.py | 39 ++++++ tests/pytorch_wrapper/pt_logical_and_test.py | 40 ++++++ tests/pytorch_wrapper/pt_logical_not_test.py | 40 ++++++ tests/pytorch_wrapper/pt_logical_or_test.py | 40 ++++++ tests/pytorch_wrapper/pt_logical_xor_test.py | 40 ++++++ tests/pytorch_wrapper/pt_lt_test.py | 40 ++++++ tests/pytorch_wrapper/pt_matmul_test.py | 63 +++++++++ tests/pytorch_wrapper/pt_mm_test.py | 58 ++++++++ tests/pytorch_wrapper/pt_mul_test.py | 39 ++++++ tests/pytorch_wrapper/pt_ne_test.py | 40 ++++++ tests/pytorch_wrapper/pt_neg_test.py | 40 ++++++ tests/pytorch_wrapper/pt_pow_test.py | 39 ++++++ tests/pytorch_wrapper/pt_remainder_test.py | 39 ++++++ tests/pytorch_wrapper/pt_sin_test.py | 39 ++++++ tests/pytorch_wrapper/pt_sinh_test.py | 39 ++++++ tests/pytorch_wrapper/pt_sub_test.py | 39 ++++++ tests/pytorch_wrapper/pt_tan_test.py | 39 ++++++ tests/pytorch_wrapper/pt_tanh_test.py | 39 ++++++ web/js/ShowSeries.js | 2 +- 158 files changed, 4540 insertions(+), 52 deletions(-) create mode 100644 docs/reference/pt_abs.md create mode 100644 docs/reference/pt_acos.md create mode 100644 docs/reference/pt_add.md create mode 100644 docs/reference/pt_asin.md create mode 100644 docs/reference/pt_atan.md create mode 100644 docs/reference/pt_bitwise_and.md create mode 100644 docs/reference/pt_bitwise_left_shift.md create mode 100644 docs/reference/pt_bitwise_not.md create mode 100644 docs/reference/pt_bitwise_or.md create mode 100644 docs/reference/pt_bitwise_right_shift.md create mode 100644 docs/reference/pt_bitwise_xor.md create mode 100644 docs/reference/pt_bmm.md create mode 100644 docs/reference/pt_bool_create.md create mode 100644 docs/reference/pt_cos.md create mode 100644 docs/reference/pt_cosh.md create mode 100644 docs/reference/pt_div.md create mode 100644 docs/reference/pt_einsum.md create mode 100644 docs/reference/pt_eq.md create mode 100644 docs/reference/pt_exp.md create mode 100644 docs/reference/pt_floor_divide.md create mode 100644 docs/reference/pt_ge.md create mode 100644 docs/reference/pt_gt.md create mode 100644 docs/reference/pt_le.md create mode 100644 docs/reference/pt_log.md create mode 100644 docs/reference/pt_logical_and.md create mode 100644 docs/reference/pt_logical_not.md create mode 100644 docs/reference/pt_logical_or.md create mode 100644 docs/reference/pt_logical_xor.md create mode 100644 docs/reference/pt_lt.md create mode 100644 docs/reference/pt_matmul.md create mode 100644 docs/reference/pt_mm.md create mode 100644 docs/reference/pt_mul.md create mode 100644 docs/reference/pt_ne.md create mode 100644 docs/reference/pt_neg.md create mode 100644 docs/reference/pt_pow.md create mode 100644 docs/reference/pt_remainder.md create mode 100644 docs/reference/pt_show_text.md create mode 100644 docs/reference/pt_sin.md create mode 100644 docs/reference/pt_sinh.md create mode 100644 docs/reference/pt_sub.md create mode 100644 docs/reference/pt_tan.md create mode 100644 docs/reference/pt_tanh.md create mode 100644 modules/pytorch_wrapper/pt_abs.py create mode 100644 modules/pytorch_wrapper/pt_acos.py create mode 100644 modules/pytorch_wrapper/pt_add.py create mode 100644 modules/pytorch_wrapper/pt_asin.py create mode 100644 modules/pytorch_wrapper/pt_atan.py create mode 100644 modules/pytorch_wrapper/pt_bitwise_and.py create mode 100644 modules/pytorch_wrapper/pt_bitwise_left_shift.py create mode 100644 modules/pytorch_wrapper/pt_bitwise_not.py create mode 100644 modules/pytorch_wrapper/pt_bitwise_or.py create mode 100644 modules/pytorch_wrapper/pt_bitwise_right_shift.py create mode 100644 modules/pytorch_wrapper/pt_bitwise_xor.py create mode 100644 modules/pytorch_wrapper/pt_bmm.py create mode 100644 modules/pytorch_wrapper/pt_bool_create.py create mode 100644 modules/pytorch_wrapper/pt_cos.py create mode 100644 modules/pytorch_wrapper/pt_cosh.py create mode 100644 modules/pytorch_wrapper/pt_div.py create mode 100644 modules/pytorch_wrapper/pt_einsum.py create mode 100644 modules/pytorch_wrapper/pt_eq.py create mode 100644 modules/pytorch_wrapper/pt_exp.py create mode 100644 modules/pytorch_wrapper/pt_floor_divide.py create mode 100644 modules/pytorch_wrapper/pt_ge.py create mode 100644 modules/pytorch_wrapper/pt_gt.py create mode 100644 modules/pytorch_wrapper/pt_le.py create mode 100644 modules/pytorch_wrapper/pt_log.py create mode 100644 modules/pytorch_wrapper/pt_logical_and.py create mode 100644 modules/pytorch_wrapper/pt_logical_not.py create mode 100644 modules/pytorch_wrapper/pt_logical_or.py create mode 100644 modules/pytorch_wrapper/pt_logical_xor.py create mode 100644 modules/pytorch_wrapper/pt_lt.py create mode 100644 modules/pytorch_wrapper/pt_matmul.py create mode 100644 modules/pytorch_wrapper/pt_mm.py create mode 100644 modules/pytorch_wrapper/pt_mul.py create mode 100644 modules/pytorch_wrapper/pt_ne.py create mode 100644 modules/pytorch_wrapper/pt_neg.py create mode 100644 modules/pytorch_wrapper/pt_pow.py create mode 100644 modules/pytorch_wrapper/pt_remainder.py create mode 100644 modules/pytorch_wrapper/pt_show_text.py create mode 100644 modules/pytorch_wrapper/pt_sin.py create mode 100644 modules/pytorch_wrapper/pt_sinh.py create mode 100644 modules/pytorch_wrapper/pt_sub.py create mode 100644 modules/pytorch_wrapper/pt_tan.py create mode 100644 modules/pytorch_wrapper/pt_tanh.py create mode 100644 tests/pytorch_wrapper/pt_abs_test.py create mode 100644 tests/pytorch_wrapper/pt_acos_test.py create mode 100644 tests/pytorch_wrapper/pt_add_test.py create mode 100644 tests/pytorch_wrapper/pt_asin_test.py create mode 100644 tests/pytorch_wrapper/pt_atan_test.py create mode 100644 tests/pytorch_wrapper/pt_bitwise_and_test.py create mode 100644 tests/pytorch_wrapper/pt_bitwise_left_shift_test.py create mode 100644 tests/pytorch_wrapper/pt_bitwise_not_test.py create mode 100644 tests/pytorch_wrapper/pt_bitwise_or_test.py create mode 100644 tests/pytorch_wrapper/pt_bitwise_right_shift_test.py create mode 100644 tests/pytorch_wrapper/pt_bitwise_xor_test.py create mode 100644 tests/pytorch_wrapper/pt_bmm_test.py create mode 100644 tests/pytorch_wrapper/pt_bool_create_test.py create mode 100644 tests/pytorch_wrapper/pt_cos_test.py create mode 100644 tests/pytorch_wrapper/pt_cosh_test.py create mode 100644 tests/pytorch_wrapper/pt_div_test.py create mode 100644 tests/pytorch_wrapper/pt_einsum_test.py create mode 100644 tests/pytorch_wrapper/pt_eq_test.py create mode 100644 tests/pytorch_wrapper/pt_exp_test.py create mode 100644 tests/pytorch_wrapper/pt_floor_divide_test.py create mode 100644 tests/pytorch_wrapper/pt_ge_test.py create mode 100644 tests/pytorch_wrapper/pt_gt_test.py create mode 100644 tests/pytorch_wrapper/pt_le_test.py create mode 100644 tests/pytorch_wrapper/pt_log_test.py create mode 100644 tests/pytorch_wrapper/pt_logical_and_test.py create mode 100644 tests/pytorch_wrapper/pt_logical_not_test.py create mode 100644 tests/pytorch_wrapper/pt_logical_or_test.py create mode 100644 tests/pytorch_wrapper/pt_logical_xor_test.py create mode 100644 tests/pytorch_wrapper/pt_lt_test.py create mode 100644 tests/pytorch_wrapper/pt_matmul_test.py create mode 100644 tests/pytorch_wrapper/pt_mm_test.py create mode 100644 tests/pytorch_wrapper/pt_mul_test.py create mode 100644 tests/pytorch_wrapper/pt_ne_test.py create mode 100644 tests/pytorch_wrapper/pt_neg_test.py create mode 100644 tests/pytorch_wrapper/pt_pow_test.py create mode 100644 tests/pytorch_wrapper/pt_remainder_test.py create mode 100644 tests/pytorch_wrapper/pt_sin_test.py create mode 100644 tests/pytorch_wrapper/pt_sinh_test.py create mode 100644 tests/pytorch_wrapper/pt_sub_test.py create mode 100644 tests/pytorch_wrapper/pt_tan_test.py create mode 100644 tests/pytorch_wrapper/pt_tanh_test.py diff --git a/__init__.py b/__init__.py index 9ca7431..d7f7ca3 100644 --- a/__init__.py +++ b/__init__.py @@ -118,16 +118,58 @@ from .modules.pandas_wrapper.pandas_var import PandasVar from .modules.pandas_wrapper.pandas_vertical_concat import PandasVerticalConcat from .modules.pandas_wrapper.pandas_vertical_split import PandasVerticalSplit from .modules.pandas_wrapper.pandas_xs import PandasXs +from .modules.pytorch_wrapper.pt_abs import PtAbs +from .modules.pytorch_wrapper.pt_acos import PtAcos +from .modules.pytorch_wrapper.pt_add import PtAdd +from .modules.pytorch_wrapper.pt_asin import PtAsin +from .modules.pytorch_wrapper.pt_atan import PtAtan +from .modules.pytorch_wrapper.pt_bitwise_and import PtBitwiseAnd +from .modules.pytorch_wrapper.pt_bitwise_left_shift import PtBitwiseLeftShift +from .modules.pytorch_wrapper.pt_bitwise_not import PtBitwiseNot +from .modules.pytorch_wrapper.pt_bitwise_or import PtBitwiseOr +from .modules.pytorch_wrapper.pt_bitwise_right_shift import PtBitwiseRightShift +from .modules.pytorch_wrapper.pt_bitwise_xor import PtBitwiseXor +from .modules.pytorch_wrapper.pt_bmm import PtBmm +from .modules.pytorch_wrapper.pt_bool_create import PtBoolCreate +from .modules.pytorch_wrapper.pt_cos import PtCos +from .modules.pytorch_wrapper.pt_cosh import PtCosh +from .modules.pytorch_wrapper.pt_div import PtDiv +from .modules.pytorch_wrapper.pt_einsum import PtEinsum +from .modules.pytorch_wrapper.pt_eq import PtEq +from .modules.pytorch_wrapper.pt_exp import PtExp from .modules.pytorch_wrapper.pt_flatten import PtFlatten from .modules.pytorch_wrapper.pt_float_create import PtFloatCreate +from .modules.pytorch_wrapper.pt_floor_divide import PtFloorDiv from .modules.pytorch_wrapper.pt_from_image import PtFromImage from .modules.pytorch_wrapper.pt_from_latent import PtFromLatent from .modules.pytorch_wrapper.pt_from_numpy import PtFromNumpy +from .modules.pytorch_wrapper.pt_ge import PtGe +from .modules.pytorch_wrapper.pt_gt import PtGt from .modules.pytorch_wrapper.pt_int_create import PtIntCreate +from .modules.pytorch_wrapper.pt_le import PtLe +from .modules.pytorch_wrapper.pt_log import PtLog +from .modules.pytorch_wrapper.pt_logical_and import PtLogicalAnd +from .modules.pytorch_wrapper.pt_logical_not import PtLogicalNot +from .modules.pytorch_wrapper.pt_logical_or import PtLogicalOr +from .modules.pytorch_wrapper.pt_logical_xor import PtLogicalXor +from .modules.pytorch_wrapper.pt_lt import PtLt +from .modules.pytorch_wrapper.pt_matmul import PtMatMul +from .modules.pytorch_wrapper.pt_mm import PtMm +from .modules.pytorch_wrapper.pt_mul import PtMul +from .modules.pytorch_wrapper.pt_ne import PtNe +from .modules.pytorch_wrapper.pt_neg import PtNeg +from .modules.pytorch_wrapper.pt_pow import PtPow +from .modules.pytorch_wrapper.pt_remainder import PtRemainder +from .modules.pytorch_wrapper.pt_show_text import PtShowText +from .modules.pytorch_wrapper.pt_sin import PtSin +from .modules.pytorch_wrapper.pt_sinh import PtSinh from .modules.pytorch_wrapper.pt_size import PtSize from .modules.pytorch_wrapper.pt_size_create import PtSizeCreate from .modules.pytorch_wrapper.pt_size_to_numpy import PtSizeToNumpy from .modules.pytorch_wrapper.pt_size_to_string import PtSizeToString +from .modules.pytorch_wrapper.pt_sub import PtSub +from .modules.pytorch_wrapper.pt_tan import PtTan +from .modules.pytorch_wrapper.pt_tanh import PtTanh from .modules.pytorch_wrapper.pt_to_image import PtToImage from .modules.pytorch_wrapper.pt_to_latent import PtToLatent from .modules.pytorch_wrapper.pt_to_numpy import PtToNumpy @@ -261,16 +303,58 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = { "PandasVerticalConcat": PandasVerticalConcat, "PandasVerticalSplit": PandasVerticalSplit, "PandasXs": PandasXs, + "PtAbs": PtAbs, + "PtAcos": PtAcos, + "PtAdd": PtAdd, + "PtAsin": PtAsin, + "PtAtan": PtAtan, + "PtBitwiseAnd": PtBitwiseAnd, + "PtBitwiseLeftShift": PtBitwiseLeftShift, + "PtBitwiseNot": PtBitwiseNot, + "PtBitwiseOr": PtBitwiseOr, + "PtBitwiseRightShift": PtBitwiseRightShift, + "PtBitwiseXor": PtBitwiseXor, + "PtBmm": PtBmm, + "PtBoolCreate": PtBoolCreate, + "PtCos": PtCos, + "PtCosh": PtCosh, + "PtDiv": PtDiv, + "PtEinsum": PtEinsum, + "PtEq": PtEq, + "PtExp": PtExp, "PtFlatten": PtFlatten, "PtFloatCreate": PtFloatCreate, + "PtFloorDiv": PtFloorDiv, "PtFromImage": PtFromImage, "PtFromLatent": PtFromLatent, "PtFromNumpy": PtFromNumpy, + "PtGe": PtGe, + "PtGt": PtGt, "PtIntCreate": PtIntCreate, + "PtLe": PtLe, + "PtLog": PtLog, + "PtLogicalAnd": PtLogicalAnd, + "PtLogicalNot": PtLogicalNot, + "PtLogicalOr": PtLogicalOr, + "PtLogicalXor": PtLogicalXor, + "PtLt": PtLt, + "PtMatMul": PtMatMul, + "PtMm": PtMm, + "PtMul": PtMul, + "PtNe": PtNe, + "PtNeg": PtNeg, + "PtPow": PtPow, + "PtRemainder": PtRemainder, + "PtShowText": PtShowText, + "PtSin": PtSin, + "PtSinh": PtSinh, "PtSize": PtSize, "PtSizeCreate": PtSizeCreate, "PtSizeToNumpy": PtSizeToNumpy, "PtSizeToString": PtSizeToString, + "PtSub": PtSub, + "PtTan": PtTan, + "PtTanh": PtTanh, "PtToImage": PtToImage, "PtToLatent": PtToLatent, "PtToNumpy": PtToNumpy, @@ -407,16 +491,58 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = { "PandasVerticalConcat": "Pandas Vertical Concat", "PandasVerticalSplit": "Pandas Vertical Split", "PandasXs": "Pandas Xs", + "PtAbs": "Pt Abs", + "PtAcos": "Pt Acos", + "PtAdd": "Pt Add", + "PtAsin": "Pt Asin", + "PtAtan": "Pt Atan", + "PtBitwiseAnd": "Pt Bitwise And", + "PtBitwiseLeftShift": "Pt Bitwise Left Shift", + "PtBitwiseNot": "Pt Bitwise Not", + "PtBitwiseOr": "Pt Bitwise Or", + "PtBitwiseRightShift": "Pt Bitwise Right Shift", + "PtBitwiseXor": "Pt Bitwise Xor", + "PtBmm": "Pt Bmm", + "PtBoolCreate": "Pt Bool Create", + "PtCos": "Pt Cos", + "PtCosh": "Pt Cosh", + "PtDiv": "Pt Div", + "PtEinsum": "Pt Einsum", + "PtEq": "Pt Eq", + "PtExp": "Pt Exp", "PtFlatten": "Pt Flatten", "PtFloatCreate": "Pt Float Create", + "PtFloorDiv": "Pt Floor Div", "PtFromImage": "Pt From Image", "PtFromLatent": "Pt From Latent", "PtFromNumpy": "Pt From Numpy", + "PtGe": "Pt Ge", + "PtGt": "Pt Gt", "PtIntCreate": "Pt Int Create", + "PtLe": "Pt Le", + "PtLog": "Pt Log", + "PtLogicalAnd": "Pt Logical And", + "PtLogicalNot": "Pt Logical Not", + "PtLogicalOr": "Pt Logical Or", + "PtLogicalXor": "Pt Logical Xor", + "PtLt": "Pt Lt", + "PtMatMul": "Pt Mat Mul", + "PtMm": "Pt Mm", + "PtMul": "Pt Mul", + "PtNe": "Pt Ne", + "PtNeg": "Pt Neg", + "PtPow": "Pt Pow", + "PtRemainder": "Pt Remainder", + "PtShowText": "Pt Show Text", + "PtSin": "Pt Sin", + "PtSinh": "Pt Sinh", "PtSize": "Pt Size", "PtSizeCreate": "Pt Size Create", "PtSizeToNumpy": "Pt Size To Numpy", "PtSizeToString": "Pt Size To String", + "PtSub": "Pt Sub", + "PtTan": "Pt Tan", + "PtTanh": "Pt Tanh", "PtToImage": "Pt To Image", "PtToLatent": "Pt To Latent", "PtToNumpy": "Pt To Numpy", diff --git a/docs/reference/node_reference.md b/docs/reference/node_reference.md index b3b956e..3286616 100644 --- a/docs/reference/node_reference.md +++ b/docs/reference/node_reference.md @@ -89,6 +89,7 @@ | [Pandas Show Series](pandas_show_series.md) | Displays a Pandas Series as text. | | [Pandas Show Text](pandas_show_text.md) | Displays a string. | | [Pandas To String](pandas_to_string.md) | Converts a pandas DataFrame to a string representation. | +| [Pt Show Text](pt_show_text.md) | Displays PyTorch tensor as a string. Note that the tensor is partially printed out when | ## IO | Node | Description | | --- | --- | @@ -122,7 +123,6 @@ | Node | Description | | --- | --- | | [Pt Flatten](pt_flatten.md) | Flattens a PyTorch tensor into a 1D tensor. | -| [Pt To Rgb Tensors](pt_to_rgb_tensors.md) | Splits a PyTorch tensor into R, G, and B tensors. | ## Numpy | Node | Description | | --- | --- | @@ -140,21 +140,87 @@ | [SNS Histogram](sns_histogram.md) | Generates a histogram from a Pandas DataFrame using Seaborn. | | [SNS Line Plot](sns_line.md) | Generates a line plot from a pandas DataFrame using Seaborn. | | [SNS Scatter Plot](sns_scatter.md) | Generates a scatter plot from a pandas DataFrame using Seaborn. | -## PyTorch wrapper +## PyTorch wrapper - Arithmetic operations | Node | Description | | --- | --- | +| [Pt Add](pt_add.md) | Adds two PyTorch tensors. | +| [Pt Div](pt_div.md) | Divides one PyTorch tensor by another element-wise. | +| [Pt Floor Div](pt_floor_divide.md) | Performs element-wise floor division on two PyTorch tensors. | +| [Pt Mul](pt_mul.md) | Multiplies two PyTorch tensors element-wise. | +| [Pt Pow](pt_pow.md) | Raises one PyTorch tensor to the power of another element-wise. | +| [Pt Remainder](pt_remainder.md) | Computes the element-wise remainder of division between two PyTorch tensors. | +| [Pt Sub](pt_sub.md) | Subtracts one PyTorch tensor from another. | +## PyTorch wrapper - Bitwise operations +| Node | Description | +| --- | --- | +| [Pt Bitwise And](pt_bitwise_and.md) | Performs a bitwise AND operation on two PyTorch tensors element-wise. | +| [Pt Bitwise Left Shift](pt_bitwise_left_shift.md) | Performs a bitwise left shift operation on two PyTorch tensors element-wise. | +| [Pt Bitwise Not](pt_bitwise_not.md) | Performs a bitwise NOT operation on a PyTorch tensor element-wise. | +| [Pt Bitwise Or](pt_bitwise_or.md) | Performs a bitwise OR operation on two PyTorch tensors element-wise. | +| [Pt Bitwise Right Shift](pt_bitwise_right_shift.md) | Performs a bitwise right shift operation on two PyTorch tensors element-wise. | +| [Pt Bitwise Xor](pt_bitwise_xor.md) | Performs a bitwise XOR operation on two PyTorch tensors element-wise. | +## PyTorch wrapper - Comparison operations +| Node | Description | +| --- | --- | +| [Pt Eq](pt_eq.md) | Tests whether two PyTorch tensors are equal element-wise. | +| [Pt Ge](pt_ge.md) | Tests whether elements in the first PyTorch tensor are greater than or equal to the corresponding elements in the second tensor. | +| [Pt Gt](pt_gt.md) | Tests whether elements in the first PyTorch tensor are greater than the corresponding elements in the second tensor. | +| [Pt Le](pt_le.md) | Tests whether elements in the first PyTorch tensor are less than or equal to the corresponding elements in the second tensor. | +| [Pt Lt](pt_lt.md) | Tests whether elements in the first PyTorch tensor are less than the corresponding elements in the second tensor. | +| [Pt Ne](pt_ne.md) | Tests whether two PyTorch tensors are not equal element-wise. | +## PyTorch wrapper - Logical operations +| Node | Description | +| --- | --- | +| [Pt Logical And](pt_logical_and.md) | Performs a logical AND operation on two PyTorch tensors element-wise. | +| [Pt Logical Not](pt_logical_not.md) | Performs a logical NOT operation on a PyTorch tensor element-wise. | +| [Pt Logical Or](pt_logical_or.md) | Performs a logical OR operation on two PyTorch tensors element-wise. | +| [Pt Logical Xor](pt_logical_xor.md) | Performs a logical XOR operation on two PyTorch tensors element-wise. | +## PyTorch wrapper - Math operations +| Node | Description | +| --- | --- | +| [Pt Abs](pt_abs.md) | Computes the absolute value of each element in a PyTorch tensor. | +| [Pt Acos](pt_acos.md) | Computes the arccosine (inverse cosine) of a PyTorch tensor element-wise. | +| [Pt Asin](pt_asin.md) | Computes the arcsine (inverse sine) of a PyTorch tensor element-wise. | +| [Pt Atan](pt_atan.md) | Computes the arc tangent (inverse tangent) of a PyTorch tensor element-wise. | +| [Pt Cos](pt_cos.md) | Computes the cosine of a PyTorch tensor element-wise. | +| [Pt Cosh](pt_cosh.md) | Computes the hyperbolic cosine of a PyTorch tensor element-wise. | +| [Pt Exp](pt_exp.md) | Performs an exponential operation on a PyTorch tensor element-wise. | +| [Pt Log](pt_log.md) | Computes the natural logarithm (log base e) of a PyTorch tensor element-wise. | +| [Pt Neg](pt_neg.md) | Computes the negation of each element in a PyTorch tensor. | +| [Pt Sin](pt_sin.md) | Computes the sine of a PyTorch tensor element-wise. | +| [Pt Sinh](pt_sinh.md) | Computes the hyperbolic sine of a PyTorch tensor element-wise. | +| [Pt Tan](pt_tan.md) | Computes the tangent of a PyTorch tensor element-wise. | +| [Pt Tanh](pt_tanh.md) | Computes the hyperbolic tangent of a PyTorch tensor element-wise. | +## PyTorch wrapper - Matrix operations +| Node | Description | +| --- | --- | +| [Pt Bmm](pt_bmm.md) | Performs batched matrix multiplication on two 3D PyTorch tensors. | +| [Pt Einsum](pt_einsum.md) | Performs Tensor operations specified in the Einstein summation equation. | +| [Pt Mat Mul](pt_matmul.md) | Performs matrix multiplication on two PyTorch tensors. | +| [Pt Mm](pt_mm.md) | Performs 2D matrix multiplication on two PyTorch tensors. | +## PyTorch wrapper - Size object support +| Node | Description | +| --- | --- | +| [Pt Size](pt_size.md) | Extracts the PyTorch Size object of a PyTorch tensor using the size() method. | +| [Pt Size Create](pt_size_create.md) | Creates a PyTorch Size using values entered in the text field. | +| [Pt Size To Numpy](pt_size_to_numpy.md) | Converts PyTorch Size object to NumPy ndarray. | +| [Pt Size To String](pt_size_to_string.md) | Converts PyTorch Size object to a Python string. | +## PyTorch wrapper - Tensor creation +| Node | Description | +| --- | --- | +| [Pt Bool Create](pt_bool_create.md) | Creates a PyTorch tensor of dtype bool from True or False values entered as a list in the text field. | | [Pt Float Create](pt_float_create.md) | Creates a PyTorch tensor with 32-bit floating point precision | | [Pt From Image](pt_from_image.md) | Casts an Image tensor as a PyTorch tensor. | | [Pt From Latent](pt_from_latent.md) | Casts a latent tensor as a PyTorch tensor. | | [Pt From Numpy](pt_from_numpy.md) | Converts a NumPy ndarray to a PyTorch tensor while preserving its data type. | | [Pt Int Create](pt_int_create.md) | Creates a PyTorch tensor with 32-bit integer | -| [Pt Size](pt_size.md) | Extracts the PyTorch Size object of a PyTorch tensor using the size() method. | -| [Pt Size Create](pt_size_create.md) | Creates a PyTorch Size using values entered in the text field. | -| [Pt Size To Numpy](pt_size_to_numpy.md) | Converts PyTorch Size object to NumPy ndarray. | -| [Pt Size To String](pt_size_to_string.md) | Converts PyTorch Size object to a Python string. | +## PyTorch wrapper - Tensor data conversion +| Node | Description | +| --- | --- | | [Pt To Image](pt_to_image.md) | Casts a PyTorch tensor as an Image tensor. | | [Pt To Latent](pt_to_latent.md) | Casts a PyTorch tensor as a latent tensor. | | [Pt To Numpy](pt_to_numpy.md) | Converts PyTorch tensor to NumPy ndarray. | +| [Pt To Rgb Tensors](pt_to_rgb_tensors.md) | Splits a PyTorch tensor into R, G, and B tensors. | ## Python wrapper | Node | Description | | --- | --- | diff --git a/docs/reference/pt_abs.md b/docs/reference/pt_abs.md new file mode 100644 index 0000000..2565442 --- /dev/null +++ b/docs/reference/pt_abs.md @@ -0,0 +1,17 @@ +# Pt Abs +Computes the absolute value of each element in a PyTorch tensor. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_acos.md b/docs/reference/pt_acos.md new file mode 100644 index 0000000..6df37ca --- /dev/null +++ b/docs/reference/pt_acos.md @@ -0,0 +1,17 @@ +# Pt Acos +Computes the arccosine (inverse cosine) of a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_add.md b/docs/reference/pt_add.md new file mode 100644 index 0000000..070bfd0 --- /dev/null +++ b/docs/reference/pt_add.md @@ -0,0 +1,18 @@ +# Pt Add +Adds two PyTorch tensors. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Arithmetic operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_asin.md b/docs/reference/pt_asin.md new file mode 100644 index 0000000..8700137 --- /dev/null +++ b/docs/reference/pt_asin.md @@ -0,0 +1,17 @@ +# Pt Asin +Computes the arcsine (inverse sine) of a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_atan.md b/docs/reference/pt_atan.md new file mode 100644 index 0000000..d745a09 --- /dev/null +++ b/docs/reference/pt_atan.md @@ -0,0 +1,17 @@ +# Pt Atan +Computes the arc tangent (inverse tangent) of a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_bitwise_and.md b/docs/reference/pt_bitwise_and.md new file mode 100644 index 0000000..3678455 --- /dev/null +++ b/docs/reference/pt_bitwise_and.md @@ -0,0 +1,18 @@ +# Pt Bitwise And +Performs a bitwise AND operation on two PyTorch tensors element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Bitwise operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_bitwise_left_shift.md b/docs/reference/pt_bitwise_left_shift.md new file mode 100644 index 0000000..17ef621 --- /dev/null +++ b/docs/reference/pt_bitwise_left_shift.md @@ -0,0 +1,18 @@ +# Pt Bitwise Left Shift +Performs a bitwise left shift operation on two PyTorch tensors element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Bitwise operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_bitwise_not.md b/docs/reference/pt_bitwise_not.md new file mode 100644 index 0000000..fd0080f --- /dev/null +++ b/docs/reference/pt_bitwise_not.md @@ -0,0 +1,17 @@ +# Pt Bitwise Not +Performs a bitwise NOT operation on a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Bitwise operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_bitwise_or.md b/docs/reference/pt_bitwise_or.md new file mode 100644 index 0000000..2bea79d --- /dev/null +++ b/docs/reference/pt_bitwise_or.md @@ -0,0 +1,18 @@ +# Pt Bitwise Or +Performs a bitwise OR operation on two PyTorch tensors element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Bitwise operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_bitwise_right_shift.md b/docs/reference/pt_bitwise_right_shift.md new file mode 100644 index 0000000..b206a8f --- /dev/null +++ b/docs/reference/pt_bitwise_right_shift.md @@ -0,0 +1,18 @@ +# Pt Bitwise Right Shift +Performs a bitwise right shift operation on two PyTorch tensors element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Bitwise operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_bitwise_xor.md b/docs/reference/pt_bitwise_xor.md new file mode 100644 index 0000000..4074bb6 --- /dev/null +++ b/docs/reference/pt_bitwise_xor.md @@ -0,0 +1,18 @@ +# Pt Bitwise Xor +Performs a bitwise XOR operation on two PyTorch tensors element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Bitwise operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_bmm.md b/docs/reference/pt_bmm.md new file mode 100644 index 0000000..151f974 --- /dev/null +++ b/docs/reference/pt_bmm.md @@ -0,0 +1,18 @@ +# Pt Bmm +Performs batched matrix multiplication on two 3D PyTorch tensors. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Matrix operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_bool_create.md b/docs/reference/pt_bool_create.md new file mode 100644 index 0000000..e342555 --- /dev/null +++ b/docs/reference/pt_bool_create.md @@ -0,0 +1,22 @@ +# Pt Bool Create +Creates a PyTorch tensor of dtype bool from True or False values entered as a list in the text field. +For example, entering: +``` +[True, False, False] +``` +will create a 1D boolean tensor. + +## Input +| Name | Data type | +|---|---| +| data | String | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Tensor creation + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_cos.md b/docs/reference/pt_cos.md new file mode 100644 index 0000000..d180b87 --- /dev/null +++ b/docs/reference/pt_cos.md @@ -0,0 +1,17 @@ +# Pt Cos +Computes the cosine of a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_cosh.md b/docs/reference/pt_cosh.md new file mode 100644 index 0000000..9e3b309 --- /dev/null +++ b/docs/reference/pt_cosh.md @@ -0,0 +1,17 @@ +# Pt Cosh +Computes the hyperbolic cosine of a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_div.md b/docs/reference/pt_div.md new file mode 100644 index 0000000..585cdb7 --- /dev/null +++ b/docs/reference/pt_div.md @@ -0,0 +1,18 @@ +# Pt Div +Divides one PyTorch tensor by another element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Arithmetic operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_einsum.md b/docs/reference/pt_einsum.md new file mode 100644 index 0000000..fa1fcda --- /dev/null +++ b/docs/reference/pt_einsum.md @@ -0,0 +1,26 @@ +# Pt Einsum +Performs Tensor operations specified in the Einstein summation equation. + +Specify Einstein summation notation in the first socket. +Specify two tensors in tens_a, tens_b. If you specify the third tensor, specify in tens_c. +Otherwise, leave the socket unconnected. + +Sublist format is not supported. + +## Input +| Name | Data type | +|---|---| +| equation | String | +| tens_a | Tensor | +| tens_b | Tensor | +| tens_c | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Matrix operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_eq.md b/docs/reference/pt_eq.md new file mode 100644 index 0000000..9228fa7 --- /dev/null +++ b/docs/reference/pt_eq.md @@ -0,0 +1,18 @@ +# Pt Eq +Tests whether two PyTorch tensors are equal element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Comparison operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_exp.md b/docs/reference/pt_exp.md new file mode 100644 index 0000000..8c4ffe0 --- /dev/null +++ b/docs/reference/pt_exp.md @@ -0,0 +1,17 @@ +# Pt Exp +Performs an exponential operation on a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_float_create.md b/docs/reference/pt_float_create.md index a9f9b85..d84a389 100644 --- a/docs/reference/pt_float_create.md +++ b/docs/reference/pt_float_create.md @@ -13,6 +13,6 @@ using values entered in the text field. | Tensor |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Tensor creation ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_floor_divide.md b/docs/reference/pt_floor_divide.md new file mode 100644 index 0000000..8f52b4f --- /dev/null +++ b/docs/reference/pt_floor_divide.md @@ -0,0 +1,18 @@ +# Pt Floor Div +Performs element-wise floor division on two PyTorch tensors. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Arithmetic operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_from_image.md b/docs/reference/pt_from_image.md index 82ecbf1..b63ad10 100644 --- a/docs/reference/pt_from_image.md +++ b/docs/reference/pt_from_image.md @@ -12,6 +12,6 @@ Casts an Image tensor as a PyTorch tensor. | Tensor |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Tensor creation ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_from_latent.md b/docs/reference/pt_from_latent.md index 8b8e27e..5ecb5b3 100644 --- a/docs/reference/pt_from_latent.md +++ b/docs/reference/pt_from_latent.md @@ -12,6 +12,6 @@ Casts a latent tensor as a PyTorch tensor. | Tensor |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Tensor creation ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_from_numpy.md b/docs/reference/pt_from_numpy.md index 77db3d5..105284d 100644 --- a/docs/reference/pt_from_numpy.md +++ b/docs/reference/pt_from_numpy.md @@ -12,6 +12,6 @@ Converts a NumPy ndarray to a PyTorch tensor while preserving its data type. | Tensor |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Tensor creation ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_ge.md b/docs/reference/pt_ge.md new file mode 100644 index 0000000..bd7b39c --- /dev/null +++ b/docs/reference/pt_ge.md @@ -0,0 +1,18 @@ +# Pt Ge +Tests whether elements in the first PyTorch tensor are greater than or equal to the corresponding elements in the second tensor. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Comparison operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_gt.md b/docs/reference/pt_gt.md new file mode 100644 index 0000000..5401090 --- /dev/null +++ b/docs/reference/pt_gt.md @@ -0,0 +1,18 @@ +# Pt Gt +Tests whether elements in the first PyTorch tensor are greater than the corresponding elements in the second tensor. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Comparison operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_int_create.md b/docs/reference/pt_int_create.md index ffb9681..9f3d826 100644 --- a/docs/reference/pt_int_create.md +++ b/docs/reference/pt_int_create.md @@ -13,6 +13,6 @@ using values entered in the text field. | Tensor |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Tensor creation ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_le.md b/docs/reference/pt_le.md new file mode 100644 index 0000000..aee74d2 --- /dev/null +++ b/docs/reference/pt_le.md @@ -0,0 +1,18 @@ +# Pt Le +Tests whether elements in the first PyTorch tensor are less than or equal to the corresponding elements in the second tensor. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Comparison operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_log.md b/docs/reference/pt_log.md new file mode 100644 index 0000000..f15a101 --- /dev/null +++ b/docs/reference/pt_log.md @@ -0,0 +1,17 @@ +# Pt Log +Computes the natural logarithm (log base e) of a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_logical_and.md b/docs/reference/pt_logical_and.md new file mode 100644 index 0000000..10255b1 --- /dev/null +++ b/docs/reference/pt_logical_and.md @@ -0,0 +1,18 @@ +# Pt Logical And +Performs a logical AND operation on two PyTorch tensors element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Logical operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_logical_not.md b/docs/reference/pt_logical_not.md new file mode 100644 index 0000000..66616e3 --- /dev/null +++ b/docs/reference/pt_logical_not.md @@ -0,0 +1,17 @@ +# Pt Logical Not +Performs a logical NOT operation on a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Logical operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_logical_or.md b/docs/reference/pt_logical_or.md new file mode 100644 index 0000000..3519a38 --- /dev/null +++ b/docs/reference/pt_logical_or.md @@ -0,0 +1,18 @@ +# Pt Logical Or +Performs a logical OR operation on two PyTorch tensors element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Logical operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_logical_xor.md b/docs/reference/pt_logical_xor.md new file mode 100644 index 0000000..c67fe55 --- /dev/null +++ b/docs/reference/pt_logical_xor.md @@ -0,0 +1,18 @@ +# Pt Logical Xor +Performs a logical XOR operation on two PyTorch tensors element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Logical operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_lt.md b/docs/reference/pt_lt.md new file mode 100644 index 0000000..b44c48b --- /dev/null +++ b/docs/reference/pt_lt.md @@ -0,0 +1,18 @@ +# Pt Lt +Tests whether elements in the first PyTorch tensor are less than the corresponding elements in the second tensor. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Comparison operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_matmul.md b/docs/reference/pt_matmul.md new file mode 100644 index 0000000..8536132 --- /dev/null +++ b/docs/reference/pt_matmul.md @@ -0,0 +1,18 @@ +# Pt Mat Mul +Performs matrix multiplication on two PyTorch tensors. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Matrix operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_mm.md b/docs/reference/pt_mm.md new file mode 100644 index 0000000..c6524b9 --- /dev/null +++ b/docs/reference/pt_mm.md @@ -0,0 +1,18 @@ +# Pt Mm +Performs 2D matrix multiplication on two PyTorch tensors. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Matrix operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_mul.md b/docs/reference/pt_mul.md new file mode 100644 index 0000000..cda34b4 --- /dev/null +++ b/docs/reference/pt_mul.md @@ -0,0 +1,18 @@ +# Pt Mul +Multiplies two PyTorch tensors element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Arithmetic operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_ne.md b/docs/reference/pt_ne.md new file mode 100644 index 0000000..37e88c7 --- /dev/null +++ b/docs/reference/pt_ne.md @@ -0,0 +1,18 @@ +# Pt Ne +Tests whether two PyTorch tensors are not equal element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Comparison operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_neg.md b/docs/reference/pt_neg.md new file mode 100644 index 0000000..23d9114 --- /dev/null +++ b/docs/reference/pt_neg.md @@ -0,0 +1,17 @@ +# Pt Neg +Computes the negation of each element in a PyTorch tensor. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_pow.md b/docs/reference/pt_pow.md new file mode 100644 index 0000000..1d717bf --- /dev/null +++ b/docs/reference/pt_pow.md @@ -0,0 +1,18 @@ +# Pt Pow +Raises one PyTorch tensor to the power of another element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Arithmetic operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_remainder.md b/docs/reference/pt_remainder.md new file mode 100644 index 0000000..e4f68e6 --- /dev/null +++ b/docs/reference/pt_remainder.md @@ -0,0 +1,18 @@ +# Pt Remainder +Computes the element-wise remainder of division between two PyTorch tensors. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Arithmetic operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_show_text.md b/docs/reference/pt_show_text.md new file mode 100644 index 0000000..40e397d --- /dev/null +++ b/docs/reference/pt_show_text.md @@ -0,0 +1,18 @@ +# Pt Show Text +Displays PyTorch tensor as a string. Note that the tensor is partially printed out when +the tensor contains more elements than the threshold set internally. + +## Input +| Name | Data type | +|---|---| +| tens | Tensor | + +## Output +| Data type | +|---| +| String | + +
+Category: Display data + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_sin.md b/docs/reference/pt_sin.md new file mode 100644 index 0000000..158065b --- /dev/null +++ b/docs/reference/pt_sin.md @@ -0,0 +1,17 @@ +# Pt Sin +Computes the sine of a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_sinh.md b/docs/reference/pt_sinh.md new file mode 100644 index 0000000..755828f --- /dev/null +++ b/docs/reference/pt_sinh.md @@ -0,0 +1,17 @@ +# Pt Sinh +Computes the hyperbolic sine of a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_size.md b/docs/reference/pt_size.md index 7a4bab0..a879754 100644 --- a/docs/reference/pt_size.md +++ b/docs/reference/pt_size.md @@ -12,6 +12,6 @@ Extracts the PyTorch Size object of a PyTorch tensor using the size() method. | Ptsize |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Size object support ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_size_create.md b/docs/reference/pt_size_create.md index 256505f..8aee4ab 100644 --- a/docs/reference/pt_size_create.md +++ b/docs/reference/pt_size_create.md @@ -12,6 +12,6 @@ Creates a PyTorch Size using values entered in the text field. | Ptsize |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Size object support ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_size_to_numpy.md b/docs/reference/pt_size_to_numpy.md index 853ebff..784063d 100644 --- a/docs/reference/pt_size_to_numpy.md +++ b/docs/reference/pt_size_to_numpy.md @@ -12,6 +12,6 @@ Converts PyTorch Size object to NumPy ndarray. | Ndarray |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Size object support ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_size_to_string.md b/docs/reference/pt_size_to_string.md index 52f3ec0..2e94aaa 100644 --- a/docs/reference/pt_size_to_string.md +++ b/docs/reference/pt_size_to_string.md @@ -12,6 +12,6 @@ Converts PyTorch Size object to a Python string. | String |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Size object support ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_sub.md b/docs/reference/pt_sub.md new file mode 100644 index 0000000..827a938 --- /dev/null +++ b/docs/reference/pt_sub.md @@ -0,0 +1,18 @@ +# Pt Sub +Subtracts one PyTorch tensor from another. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | +| tens_b | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Arithmetic operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_tan.md b/docs/reference/pt_tan.md new file mode 100644 index 0000000..a05b3a5 --- /dev/null +++ b/docs/reference/pt_tan.md @@ -0,0 +1,17 @@ +# Pt Tan +Computes the tangent of a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_tanh.md b/docs/reference/pt_tanh.md new file mode 100644 index 0000000..eff2b90 --- /dev/null +++ b/docs/reference/pt_tanh.md @@ -0,0 +1,17 @@ +# Pt Tanh +Computes the hyperbolic tangent of a PyTorch tensor element-wise. + +## Input +| Name | Data type | +|---|---| +| tens_a | Tensor | + +## Output +| Data type | +|---| +| Tensor | + +
+Category: PyTorch wrapper - Math operations + +ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_image.md b/docs/reference/pt_to_image.md index f399842..0255ba6 100644 --- a/docs/reference/pt_to_image.md +++ b/docs/reference/pt_to_image.md @@ -12,6 +12,6 @@ Casts a PyTorch tensor as an Image tensor. | Image |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Tensor data conversion ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_latent.md b/docs/reference/pt_to_latent.md index 144104f..9a1278c 100644 --- a/docs/reference/pt_to_latent.md +++ b/docs/reference/pt_to_latent.md @@ -12,6 +12,6 @@ Casts a PyTorch tensor as a latent tensor. | Latent |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Tensor data conversion ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_numpy.md b/docs/reference/pt_to_numpy.md index be9698a..47821d3 100644 --- a/docs/reference/pt_to_numpy.md +++ b/docs/reference/pt_to_numpy.md @@ -12,6 +12,6 @@ Converts PyTorch tensor to NumPy ndarray. | Ndarray |
-Category: PyTorch wrapper +Category: PyTorch wrapper - Tensor data conversion ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/docs/reference/pt_to_rgb_tensors.md b/docs/reference/pt_to_rgb_tensors.md index efd507a..aff0b37 100644 --- a/docs/reference/pt_to_rgb_tensors.md +++ b/docs/reference/pt_to_rgb_tensors.md @@ -1,8 +1,6 @@ # Pt To Rgb Tensors Splits a PyTorch tensor into R, G, and B tensors. -Category: PyTorch wrapper - ## Input | Name | Data type | |---|---| @@ -16,6 +14,6 @@ Category: PyTorch wrapper | Tensor |
-Category: Miscellaneous +Category: PyTorch wrapper - Tensor data conversion ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved. diff --git a/modules/numpy_wrapper/numpy_float_create.py b/modules/numpy_wrapper/numpy_float_create.py index 657003a..7a849ee 100644 --- a/modules/numpy_wrapper/numpy_float_create.py +++ b/modules/numpy_wrapper/numpy_float_create.py @@ -27,7 +27,7 @@ class NumpyFloatCreate: RETURN_TYPES: tuple = ("NDARRAY",) FUNCTION: str = "f" - CATEGORY: str = "Numpy wrapper" + CATEGORY: str = "Data Analysis" def f(self, data: str) -> tuple: """ diff --git a/modules/numpy_wrapper/numpy_int_create.py b/modules/numpy_wrapper/numpy_int_create.py index 6f11fd3..571f41c 100644 --- a/modules/numpy_wrapper/numpy_int_create.py +++ b/modules/numpy_wrapper/numpy_int_create.py @@ -27,7 +27,7 @@ class NumpyIntCreate: RETURN_TYPES: tuple = ("NDARRAY",) FUNCTION: str = "f" - CATEGORY: str = "Numpy wrapper" + CATEGORY: str = "Data Analysis" def f(self, data: str) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_abs.py b/modules/pytorch_wrapper/pt_abs.py new file mode 100644 index 0000000..3453cee --- /dev/null +++ b/modules/pytorch_wrapper/pt_abs.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtAbs: + """ + Computes the absolute value of each element in a PyTorch tensor. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the absolute value of a PyTorch tensor element-wise. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after applying the absolute function. + """ + return (torch.abs(tens_a),) diff --git a/modules/pytorch_wrapper/pt_acos.py b/modules/pytorch_wrapper/pt_acos.py new file mode 100644 index 0000000..1d68c2a --- /dev/null +++ b/modules/pytorch_wrapper/pt_acos.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtAcos: + """ + Computes the arccosine (inverse cosine) of a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise arccosine (inverse cosine) of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. Values must be in the range [-1, 1]. + + Returns: + tuple: A tuple containing the resultant tensor after applying the arccosine function. + """ + return (torch.acos(tens_a),) diff --git a/modules/pytorch_wrapper/pt_add.py b/modules/pytorch_wrapper/pt_add.py new file mode 100644 index 0000000..4220656 --- /dev/null +++ b/modules/pytorch_wrapper/pt_add.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtAdd: + """ + Adds two PyTorch tensors. + + category: PyTorch wrapper - Arithmetic operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Adds two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of shape that supports addition with `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor. + """ + return (torch.add(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_asin.py b/modules/pytorch_wrapper/pt_asin.py new file mode 100644 index 0000000..ef9b6dd --- /dev/null +++ b/modules/pytorch_wrapper/pt_asin.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtAsin: + """ + Computes the arcsine (inverse sine) of a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise arcsine (inverse sine) of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. Values must be in the range [-1, 1]. + + Returns: + tuple: A tuple containing the resultant tensor after applying the arcsine function. + """ + return (torch.asin(tens_a),) diff --git a/modules/pytorch_wrapper/pt_atan.py b/modules/pytorch_wrapper/pt_atan.py new file mode 100644 index 0000000..93e8c68 --- /dev/null +++ b/modules/pytorch_wrapper/pt_atan.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtAtan: + """ + Computes the arc tangent (inverse tangent) of a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise arc tangent (inverse tangent) of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after applying the arc tangent function. + """ + return (torch.atan(tens_a),) diff --git a/modules/pytorch_wrapper/pt_bitwise_and.py b/modules/pytorch_wrapper/pt_bitwise_and.py new file mode 100644 index 0000000..ca130ef --- /dev/null +++ b/modules/pytorch_wrapper/pt_bitwise_and.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtBitwiseAnd: + """ + Performs a bitwise AND operation on two PyTorch tensors element-wise. + + category: PyTorch wrapper - Bitwise operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs a bitwise AND operation on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of integer type. + tens_b (torch.Tensor): A PyTorch tensor of the same shape and integer type as `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor after applying bitwise AND. + """ + return (torch.bitwise_and(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_bitwise_left_shift.py b/modules/pytorch_wrapper/pt_bitwise_left_shift.py new file mode 100644 index 0000000..19cea42 --- /dev/null +++ b/modules/pytorch_wrapper/pt_bitwise_left_shift.py @@ -0,0 +1,42 @@ +from typing import Any, Dict +import torch + +class PtBitwiseLeftShift: + """ + Performs a bitwise left shift operation on two PyTorch tensors element-wise. + + category: PyTorch wrapper - Bitwise operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs a bitwise left shift operation on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of integer type. + tens_b (torch.Tensor): A PyTorch tensor of the same shape and integer type as `tens_a`, + representing the number of positions to shift. + + Returns: + tuple: A tuple containing the resultant tensor after applying bitwise left shift. + """ + return (torch.bitwise_left_shift(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_bitwise_not.py b/modules/pytorch_wrapper/pt_bitwise_not.py new file mode 100644 index 0000000..7fb05c0 --- /dev/null +++ b/modules/pytorch_wrapper/pt_bitwise_not.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtBitwiseNot: + """ + Performs a bitwise NOT operation on a PyTorch tensor element-wise. + + category: PyTorch wrapper - Bitwise operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Performs a bitwise NOT operation on a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of integer type. + + Returns: + tuple: A tuple containing the resultant tensor after applying bitwise NOT. + """ + return (torch.bitwise_not(tens_a),) diff --git a/modules/pytorch_wrapper/pt_bitwise_or.py b/modules/pytorch_wrapper/pt_bitwise_or.py new file mode 100644 index 0000000..b5d86f8 --- /dev/null +++ b/modules/pytorch_wrapper/pt_bitwise_or.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtBitwiseOr: + """ + Performs a bitwise OR operation on two PyTorch tensors element-wise. + + category: PyTorch wrapper - Bitwise operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs a bitwise OR operation on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of integer type. + tens_b (torch.Tensor): A PyTorch tensor of the same shape and integer type as `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor after applying bitwise OR. + """ + return (torch.bitwise_or(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_bitwise_right_shift.py b/modules/pytorch_wrapper/pt_bitwise_right_shift.py new file mode 100644 index 0000000..fafde91 --- /dev/null +++ b/modules/pytorch_wrapper/pt_bitwise_right_shift.py @@ -0,0 +1,42 @@ +from typing import Any, Dict +import torch + +class PtBitwiseRightShift: + """ + Performs a bitwise right shift operation on two PyTorch tensors element-wise. + + category: PyTorch wrapper - Bitwise operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs a bitwise right shift operation on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of integer type. + tens_b (torch.Tensor): A PyTorch tensor of the same shape and integer type as `tens_a`, + representing the number of positions to shift. + + Returns: + tuple: A tuple containing the resultant tensor after applying bitwise right shift. + """ + return (torch.bitwise_right_shift(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_bitwise_xor.py b/modules/pytorch_wrapper/pt_bitwise_xor.py new file mode 100644 index 0000000..bf910e0 --- /dev/null +++ b/modules/pytorch_wrapper/pt_bitwise_xor.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtBitwiseXor: + """ + Performs a bitwise XOR operation on two PyTorch tensors element-wise. + + category: PyTorch wrapper - Bitwise operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs a bitwise XOR operation on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of integer type. + tens_b (torch.Tensor): A PyTorch tensor of the same shape and integer type as `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor after applying bitwise XOR. + """ + return (torch.bitwise_xor(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_bmm.py b/modules/pytorch_wrapper/pt_bmm.py new file mode 100644 index 0000000..9bebbc6 --- /dev/null +++ b/modules/pytorch_wrapper/pt_bmm.py @@ -0,0 +1,44 @@ +from typing import Any, Dict +import torch + +class PtBmm: + """ + Performs batched matrix multiplication on two 3D PyTorch tensors. + + category: PyTorch wrapper - Matrix operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs batched matrix multiplication on two 3D PyTorch tensors. + + Args: + tens_a (torch.Tensor): A 3D PyTorch tensor (batch, m, n). + tens_b (torch.Tensor): A 3D PyTorch tensor (batch, n, p) that supports matrix multiplication with `tens_a`. + + Returns: + tuple: A tuple containing the resultant 3D tensor. + """ + if tens_a.dim() != 3 or tens_b.dim() != 3: + raise ValueError("torch.bmm() only supports batch matrix multiplication for 3D tensors.") + + return (torch.bmm(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_bool_create.py b/modules/pytorch_wrapper/pt_bool_create.py new file mode 100644 index 0000000..016e34a --- /dev/null +++ b/modules/pytorch_wrapper/pt_bool_create.py @@ -0,0 +1,51 @@ +from typing import Any, Dict +import torch +import ast + + +class PtBoolCreate: + """ + Creates a PyTorch tensor of dtype bool from True or False values entered as a list in the text field. + For example, entering: + ``` + [True, False, False] + ``` + will create a 1D boolean tensor. + + category: PyTorch wrapper - Tensor creation + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the input types for the function. + + Returns: + Dict[str, Any]: A dictionary specifying required input types. + """ + return { + "required": { + "data": ("STRING", {"multiline": True}), + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, data: str) -> tuple: + """ + Creates a PyTorch tensor with bool data type using True or False string values entered in the text field. + + Args: + data (str): String value in the text field. + + Returns: + tuple: A tuple containing the tensor. + """ + # Convert string to Python list + list_data = ast.literal_eval(data) + + # Convert list to PyTorch tensor + tensor = torch.tensor(list_data, dtype=torch.bool) + return (tensor,) diff --git a/modules/pytorch_wrapper/pt_cos.py b/modules/pytorch_wrapper/pt_cos.py new file mode 100644 index 0000000..7a66956 --- /dev/null +++ b/modules/pytorch_wrapper/pt_cos.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtCos: + """ + Computes the cosine of a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise cosine of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type, representing angles in radians. + + Returns: + tuple: A tuple containing the resultant tensor after applying the cosine function. + """ + return (torch.cos(tens_a),) diff --git a/modules/pytorch_wrapper/pt_cosh.py b/modules/pytorch_wrapper/pt_cosh.py new file mode 100644 index 0000000..b168937 --- /dev/null +++ b/modules/pytorch_wrapper/pt_cosh.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtCosh: + """ + Computes the hyperbolic cosine of a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise hyperbolic cosine of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after applying the hyperbolic cosine function. + """ + return (torch.cosh(tens_a),) diff --git a/modules/pytorch_wrapper/pt_div.py b/modules/pytorch_wrapper/pt_div.py new file mode 100644 index 0000000..db87bc0 --- /dev/null +++ b/modules/pytorch_wrapper/pt_div.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtDiv: + """ + Divides one PyTorch tensor by another element-wise. + + category: PyTorch wrapper - Arithmetic operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Divides one PyTorch tensor by another element-wise. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of shape that supports element-wise division with `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor. + """ + return (torch.div(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_einsum.py b/modules/pytorch_wrapper/pt_einsum.py new file mode 100644 index 0000000..ddd4dc8 --- /dev/null +++ b/modules/pytorch_wrapper/pt_einsum.py @@ -0,0 +1,67 @@ +from typing import Any, Dict +import torch + + +class PtEinsum: + """ + Performs Tensor operations specified in the Einstein summation equation. + + Specify Einstein summation notation in the first socket. + Specify two tensors in tens_a, tens_b. If you specify the third tensor, specify in tens_c. + Otherwise, leave the socket unconnected. + + Sublist format is not supported. + + category: PyTorch wrapper - Matrix operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "equation": ("STRING", {"default": ""}), + "tens_a": ("TENSOR", {}) + }, + "optional":{ + "tens_b": ("TENSOR", {}), + "tens_c": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, + equation: str, + tens_a: torch.Tensor, + tens_b: torch.Tensor = None, + tens_c: torch.Tensor = None) -> tuple: + """ + Performs Tensor operations specified in the Einstein summation equation. + + Args: + equation (str): Einstein summation equation. + tens_a (torch.Tensor): A PyTorch tensor. + tens_b (torch.Tensor): A PyTorch tensor. + tens_c (torch.Tensor): A PyTorch tensor. + + Returns: + tuple: A tuple containing the resultant tensor. + """ + if tens_a is None: + raise ValueError("tens_a is None") + + if tens_b is None and tens_c is None: + tens_ret_val = torch.einsum(equation, tens_a) + elif tens_c is None: + tens_ret_val = torch.einsum(equation, tens_a, tens_b) + else: + tens_ret_val = torch.einsum(equation, tens_a, tens_b, tens_c) + return (tens_ret_val,) diff --git a/modules/pytorch_wrapper/pt_eq.py b/modules/pytorch_wrapper/pt_eq.py new file mode 100644 index 0000000..ffadbce --- /dev/null +++ b/modules/pytorch_wrapper/pt_eq.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtEq: + """ + Tests whether two PyTorch tensors are equal element-wise. + + category: PyTorch wrapper - Comparison operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Compares two PyTorch tensors for element-wise equality. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of the same shape as `tens_a`. + + Returns: + tuple: A tuple containing a boolean tensor indicating element-wise equality. + """ + return (torch.eq(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_exp.py b/modules/pytorch_wrapper/pt_exp.py new file mode 100644 index 0000000..3773009 --- /dev/null +++ b/modules/pytorch_wrapper/pt_exp.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtExp: + """ + Performs an exponential operation on a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise exponential of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after applying the exponential function. + """ + return (torch.exp(tens_a),) diff --git a/modules/pytorch_wrapper/pt_flatten.py b/modules/pytorch_wrapper/pt_flatten.py index 791062d..4b565a2 100644 --- a/modules/pytorch_wrapper/pt_flatten.py +++ b/modules/pytorch_wrapper/pt_flatten.py @@ -25,7 +25,7 @@ class PtFlatten: RETURN_TYPES: tuple = ("TENSOR",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, tens: torch.Tensor) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_float_create.py b/modules/pytorch_wrapper/pt_float_create.py index 48672fe..264b986 100644 --- a/modules/pytorch_wrapper/pt_float_create.py +++ b/modules/pytorch_wrapper/pt_float_create.py @@ -8,7 +8,7 @@ class PtFloatCreate: Creates a PyTorch tensor with 32-bit floating point precision using values entered in the text field. - category: PyTorch wrapper + category: PyTorch wrapper - Tensor creation """ @classmethod @@ -27,7 +27,7 @@ class PtFloatCreate: RETURN_TYPES: tuple = ("TENSOR",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, data: str) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_floor_divide.py b/modules/pytorch_wrapper/pt_floor_divide.py new file mode 100644 index 0000000..f579d98 --- /dev/null +++ b/modules/pytorch_wrapper/pt_floor_divide.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtFloorDiv: + """ + Performs element-wise floor division on two PyTorch tensors. + + category: PyTorch wrapper - Arithmetic operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs element-wise floor division on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of shape that supports element-wise floor division with `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor. + """ + return (torch.floor_divide(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_from_image.py b/modules/pytorch_wrapper/pt_from_image.py index fca4f89..94d4b13 100644 --- a/modules/pytorch_wrapper/pt_from_image.py +++ b/modules/pytorch_wrapper/pt_from_image.py @@ -6,7 +6,7 @@ class PtFromImage: """ Casts an Image tensor as a PyTorch tensor. - category: PyTorch wrapper + category: PyTorch wrapper - Tensor creation """ @classmethod @@ -25,7 +25,7 @@ class PtFromImage: RETURN_TYPES: tuple = ("TENSOR",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, image: torch.Tensor) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_from_latent.py b/modules/pytorch_wrapper/pt_from_latent.py index 6bc9ddc..bfb581b 100644 --- a/modules/pytorch_wrapper/pt_from_latent.py +++ b/modules/pytorch_wrapper/pt_from_latent.py @@ -6,7 +6,7 @@ class PtFromLatent: """ Casts a latent tensor as a PyTorch tensor. - category: PyTorch wrapper + category: PyTorch wrapper - Tensor creation """ @classmethod @@ -25,7 +25,7 @@ class PtFromLatent: RETURN_TYPES: tuple = ("TENSOR",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, latent: torch.Tensor) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_from_numpy.py b/modules/pytorch_wrapper/pt_from_numpy.py index 3ea0b91..0c068d8 100644 --- a/modules/pytorch_wrapper/pt_from_numpy.py +++ b/modules/pytorch_wrapper/pt_from_numpy.py @@ -7,7 +7,7 @@ class PtFromNumpy: """ Converts a NumPy ndarray to a PyTorch tensor while preserving its data type. - category: PyTorch wrapper + category: PyTorch wrapper - Tensor creation """ @classmethod @@ -26,7 +26,7 @@ class PtFromNumpy: RETURN_TYPES: tuple = ("TENSOR",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, array: np.ndarray) -> Tuple[torch.Tensor]: """ diff --git a/modules/pytorch_wrapper/pt_ge.py b/modules/pytorch_wrapper/pt_ge.py new file mode 100644 index 0000000..9fc7798 --- /dev/null +++ b/modules/pytorch_wrapper/pt_ge.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtGe: + """ + Tests whether elements in the first PyTorch tensor are greater than or equal to the corresponding elements in the second tensor. + + category: PyTorch wrapper - Comparison operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Compares two PyTorch tensors for element-wise greater-than-or-equal-to condition. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of the same shape as `tens_a`. + + Returns: + tuple: A tuple containing a boolean tensor indicating where `tens_a >= tens_b`. + """ + return (torch.ge(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_gt.py b/modules/pytorch_wrapper/pt_gt.py new file mode 100644 index 0000000..f30d6f5 --- /dev/null +++ b/modules/pytorch_wrapper/pt_gt.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtGt: + """ + Tests whether elements in the first PyTorch tensor are greater than the corresponding elements in the second tensor. + + category: PyTorch wrapper - Comparison operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Compares two PyTorch tensors for element-wise greater-than condition. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of the same shape as `tens_a`. + + Returns: + tuple: A tuple containing a boolean tensor indicating where `tens_a > tens_b`. + """ + return (torch.gt(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_int_create.py b/modules/pytorch_wrapper/pt_int_create.py index 6739ad0..a1bdb9e 100644 --- a/modules/pytorch_wrapper/pt_int_create.py +++ b/modules/pytorch_wrapper/pt_int_create.py @@ -8,7 +8,7 @@ class PtIntCreate: Creates a PyTorch tensor with 32-bit integer using values entered in the text field. - category: PyTorch wrapper + category: PyTorch wrapper - Tensor creation """ @classmethod @@ -27,7 +27,7 @@ class PtIntCreate: RETURN_TYPES: tuple = ("TENSOR",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, data: str) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_le.py b/modules/pytorch_wrapper/pt_le.py new file mode 100644 index 0000000..641cf79 --- /dev/null +++ b/modules/pytorch_wrapper/pt_le.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtLe: + """ + Tests whether elements in the first PyTorch tensor are less than or equal to the corresponding elements in the second tensor. + + category: PyTorch wrapper - Comparison operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Compares two PyTorch tensors for element-wise less-than-or-equal-to condition. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of the same shape as `tens_a`. + + Returns: + tuple: A tuple containing a boolean tensor indicating where `tens_a <= tens_b`. + """ + return (torch.le(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_log.py b/modules/pytorch_wrapper/pt_log.py new file mode 100644 index 0000000..bebd1d7 --- /dev/null +++ b/modules/pytorch_wrapper/pt_log.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtLog: + """ + Computes the natural logarithm (log base e) of a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise natural logarithm (log base e) of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. Must contain only positive values. + + Returns: + tuple: A tuple containing the resultant tensor after applying the natural logarithm. + """ + return (torch.log(tens_a),) diff --git a/modules/pytorch_wrapper/pt_logical_and.py b/modules/pytorch_wrapper/pt_logical_and.py new file mode 100644 index 0000000..0b19d48 --- /dev/null +++ b/modules/pytorch_wrapper/pt_logical_and.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtLogicalAnd: + """ + Performs a logical AND operation on two PyTorch tensors element-wise. + + category: PyTorch wrapper - Logical operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs a logical AND operation on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of boolean or numerical type. + tens_b (torch.Tensor): A PyTorch tensor of the same shape and type as `tens_a`. + + Returns: + tuple: A tuple containing a boolean tensor where `tens_a AND tens_b` is applied element-wise. + """ + return (torch.logical_and(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_logical_not.py b/modules/pytorch_wrapper/pt_logical_not.py new file mode 100644 index 0000000..60c83dd --- /dev/null +++ b/modules/pytorch_wrapper/pt_logical_not.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtLogicalNot: + """ + Performs a logical NOT operation on a PyTorch tensor element-wise. + + category: PyTorch wrapper - Logical operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Performs a logical NOT operation on a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of boolean or numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after applying logical NOT. + """ + return (torch.logical_not(tens_a),) diff --git a/modules/pytorch_wrapper/pt_logical_or.py b/modules/pytorch_wrapper/pt_logical_or.py new file mode 100644 index 0000000..8a6d1f7 --- /dev/null +++ b/modules/pytorch_wrapper/pt_logical_or.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtLogicalOr: + """ + Performs a logical OR operation on two PyTorch tensors element-wise. + + category: PyTorch wrapper - Logical operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs a logical OR operation on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of boolean or numerical type. + tens_b (torch.Tensor): A PyTorch tensor of the same shape and type as `tens_a`. + + Returns: + tuple: A tuple containing a boolean tensor where `tens_a OR tens_b` is applied element-wise. + """ + return (torch.logical_or(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_logical_xor.py b/modules/pytorch_wrapper/pt_logical_xor.py new file mode 100644 index 0000000..4b162cb --- /dev/null +++ b/modules/pytorch_wrapper/pt_logical_xor.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtLogicalXor: + """ + Performs a logical XOR operation on two PyTorch tensors element-wise. + + category: PyTorch wrapper - Logical operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs a logical XOR operation on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of boolean or numerical type. + tens_b (torch.Tensor): A PyTorch tensor of the same shape and type as `tens_a`. + + Returns: + tuple: A tuple containing a boolean tensor where `tens_a XOR tens_b` is applied element-wise. + """ + return (torch.logical_xor(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_lt.py b/modules/pytorch_wrapper/pt_lt.py new file mode 100644 index 0000000..2fafb48 --- /dev/null +++ b/modules/pytorch_wrapper/pt_lt.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtLt: + """ + Tests whether elements in the first PyTorch tensor are less than the corresponding elements in the second tensor. + + category: PyTorch wrapper - Comparison operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Compares two PyTorch tensors for element-wise less-than condition. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of the same shape as `tens_a`. + + Returns: + tuple: A tuple containing a boolean tensor indicating where `tens_a < tens_b`. + """ + return (torch.lt(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_matmul.py b/modules/pytorch_wrapper/pt_matmul.py new file mode 100644 index 0000000..6401bfe --- /dev/null +++ b/modules/pytorch_wrapper/pt_matmul.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtMatMul: + """ + Performs matrix multiplication on two PyTorch tensors. + + category: PyTorch wrapper - Matrix operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs matrix multiplication on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of shape compatible for matrix multiplication. + tens_b (torch.Tensor): A PyTorch tensor of shape that supports matrix multiplication with `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor. + """ + return (torch.matmul(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_mm.py b/modules/pytorch_wrapper/pt_mm.py new file mode 100644 index 0000000..16f33b1 --- /dev/null +++ b/modules/pytorch_wrapper/pt_mm.py @@ -0,0 +1,44 @@ +from typing import Any, Dict +import torch + +class PtMm: + """ + Performs 2D matrix multiplication on two PyTorch tensors. + + category: PyTorch wrapper - Matrix operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Performs 2D matrix multiplication on two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A 2D PyTorch tensor. + tens_b (torch.Tensor): A 2D PyTorch tensor that supports matrix multiplication with `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor. + """ + if tens_a.dim() != 2 or tens_b.dim() != 2: + raise ValueError("torch.mm() only supports 2D tensors.") + + return (torch.mm(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_mul.py b/modules/pytorch_wrapper/pt_mul.py new file mode 100644 index 0000000..1a4a1c1 --- /dev/null +++ b/modules/pytorch_wrapper/pt_mul.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtMul: + """ + Multiplies two PyTorch tensors element-wise. + + category: PyTorch wrapper - Arithmetic operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Multiplies two PyTorch tensors element-wise. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of shape that supports element-wise multiplication with `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor. + """ + return (torch.mul(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_ne.py b/modules/pytorch_wrapper/pt_ne.py new file mode 100644 index 0000000..cd8aab9 --- /dev/null +++ b/modules/pytorch_wrapper/pt_ne.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtNe: + """ + Tests whether two PyTorch tensors are not equal element-wise. + + category: PyTorch wrapper - Comparison operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Compares two PyTorch tensors for element-wise inequality. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of the same shape as `tens_a`. + + Returns: + tuple: A tuple containing a boolean tensor indicating element-wise inequality. + """ + return (torch.ne(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_neg.py b/modules/pytorch_wrapper/pt_neg.py new file mode 100644 index 0000000..c0dd79c --- /dev/null +++ b/modules/pytorch_wrapper/pt_neg.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtNeg: + """ + Computes the negation of each element in a PyTorch tensor. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the negation of a PyTorch tensor element-wise. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after applying negation. + """ + return (torch.neg(tens_a),) diff --git a/modules/pytorch_wrapper/pt_pow.py b/modules/pytorch_wrapper/pt_pow.py new file mode 100644 index 0000000..52f3cb6 --- /dev/null +++ b/modules/pytorch_wrapper/pt_pow.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtPow: + """ + Raises one PyTorch tensor to the power of another element-wise. + + category: PyTorch wrapper - Arithmetic operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Raises one PyTorch tensor to the power of another element-wise. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of shape that supports element-wise exponentiation with `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor. + """ + return (torch.pow(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_remainder.py b/modules/pytorch_wrapper/pt_remainder.py new file mode 100644 index 0000000..25c9591 --- /dev/null +++ b/modules/pytorch_wrapper/pt_remainder.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtRemainder: + """ + Computes the element-wise remainder of division between two PyTorch tensors. + + category: PyTorch wrapper - Arithmetic operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Computes the element-wise remainder of division between two PyTorch tensors. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of shape that supports element-wise remainder computation with `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor. + """ + return (torch.remainder(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_show_text.py b/modules/pytorch_wrapper/pt_show_text.py new file mode 100644 index 0000000..152db36 --- /dev/null +++ b/modules/pytorch_wrapper/pt_show_text.py @@ -0,0 +1,62 @@ +""" +Almost all of this code was taken from +https://github.com/pythongosssss/ComfyUI-Custom-Scripts/blob/main/py/show_text.py + +See credit/credit.md for the full license. +""" +from typing import List +import torch + + +class PtShowText: + """ + Displays PyTorch tensor as a string. Note that the tensor is partially printed out when + the tensor contains more elements than the threshold set internally. + + category: Display data + """ + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "tens": ("TENSOR", {}), + }, + "hidden": { + "unique_id": "UNIQUE_ID", + "extra_pnginfo": "EXTRA_PNGINFO", + }, + } + + INPUT_IS_LIST = True + RETURN_TYPES = ("STRING",) + FUNCTION = "notify" + OUTPUT_NODE = True + OUTPUT_IS_LIST = (True,) + + CATEGORY = "Data Analysis" + + MAX_NUM_ELEMENTS_TO_DISPLAY = 100 + + def notify(self, tens: torch.Tensor, unique_id=None, extra_pnginfo=None): + torch.set_printoptions(threshold=PtShowText.MAX_NUM_ELEMENTS_TO_DISPLAY) + text = str(tens[0]) + + if unique_id is not None and extra_pnginfo is not None: + if not isinstance(extra_pnginfo, list): + print("Error: extra_pnginfo is not a list") + elif ( + not isinstance(extra_pnginfo[0], dict) + or "workflow" not in extra_pnginfo[0] + ): + print("Error: extra_pnginfo[0] is not a dict or missing 'workflow' key") + else: + workflow = extra_pnginfo[0]["workflow"] + node = next( + (x for x in workflow["nodes"] if str(x["id"]) == str(unique_id[0])), + None, + ) + if node: + node["widgets_values"] = [text] + else: + print("unique_id or extra_pnginfo is None.") + return {"ui": {"text": [text]}, "result": ([text],)} diff --git a/modules/pytorch_wrapper/pt_sin.py b/modules/pytorch_wrapper/pt_sin.py new file mode 100644 index 0000000..fb25085 --- /dev/null +++ b/modules/pytorch_wrapper/pt_sin.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtSin: + """ + Computes the sine of a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise sine of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type, representing angles in radians. + + Returns: + tuple: A tuple containing the resultant tensor after applying the sine function. + """ + return (torch.sin(tens_a),) diff --git a/modules/pytorch_wrapper/pt_sinh.py b/modules/pytorch_wrapper/pt_sinh.py new file mode 100644 index 0000000..5707082 --- /dev/null +++ b/modules/pytorch_wrapper/pt_sinh.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtSinh: + """ + Computes the hyperbolic sine of a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise hyperbolic sine of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after applying the hyperbolic sine function. + """ + return (torch.sinh(tens_a),) diff --git a/modules/pytorch_wrapper/pt_size.py b/modules/pytorch_wrapper/pt_size.py index 6965cd4..dd3be36 100644 --- a/modules/pytorch_wrapper/pt_size.py +++ b/modules/pytorch_wrapper/pt_size.py @@ -7,7 +7,7 @@ class PtSize: """ Extracts the PyTorch Size object of a PyTorch tensor using the size() method. - category: PyTorch wrapper + category: PyTorch wrapper - Size object support """ @classmethod @@ -26,7 +26,7 @@ class PtSize: RETURN_TYPES: tuple = ("PTSIZE",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, tens: torch.Tensor) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_size_create.py b/modules/pytorch_wrapper/pt_size_create.py index 9403056..c19b877 100644 --- a/modules/pytorch_wrapper/pt_size_create.py +++ b/modules/pytorch_wrapper/pt_size_create.py @@ -7,7 +7,7 @@ class PtSizeCreate: """ Creates a PyTorch Size using values entered in the text field. - category: PyTorch wrapper + category: PyTorch wrapper - Size object support """ @classmethod @@ -26,7 +26,7 @@ class PtSizeCreate: RETURN_TYPES: tuple = ("PTSIZE",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, data: str) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_size_to_numpy.py b/modules/pytorch_wrapper/pt_size_to_numpy.py index e0f3900..eb8ce05 100644 --- a/modules/pytorch_wrapper/pt_size_to_numpy.py +++ b/modules/pytorch_wrapper/pt_size_to_numpy.py @@ -6,7 +6,7 @@ class PtSizeToNumpy: """ Converts PyTorch Size object to NumPy ndarray. - category: PyTorch wrapper + category: PyTorch wrapper - Size object support """ @classmethod @@ -25,7 +25,7 @@ class PtSizeToNumpy: RETURN_TYPES: tuple = ("NDARRAY",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, sz: torch.Size) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_size_to_string.py b/modules/pytorch_wrapper/pt_size_to_string.py index 25f7bed..8dc7992 100644 --- a/modules/pytorch_wrapper/pt_size_to_string.py +++ b/modules/pytorch_wrapper/pt_size_to_string.py @@ -6,7 +6,7 @@ class PtSizeToString: """ Converts PyTorch Size object to a Python string. - category: PyTorch wrapper + category: PyTorch wrapper - Size object support """ @classmethod @@ -25,7 +25,7 @@ class PtSizeToString: RETURN_TYPES: tuple = ("STRING",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, sz: torch.Size) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_sub.py b/modules/pytorch_wrapper/pt_sub.py new file mode 100644 index 0000000..026b0b1 --- /dev/null +++ b/modules/pytorch_wrapper/pt_sub.py @@ -0,0 +1,41 @@ +from typing import Any, Dict +import torch + +class PtSub: + """ + Subtracts one PyTorch tensor from another. + + category: PyTorch wrapper - Arithmetic operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}), + "tens_b": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor, tens_b: torch.Tensor) -> tuple: + """ + Subtracts one PyTorch tensor from another. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of any shape. + tens_b (torch.Tensor): A PyTorch tensor of shape that supports subtraction from `tens_a`. + + Returns: + tuple: A tuple containing the resultant tensor. + """ + return (torch.sub(tens_a, tens_b),) diff --git a/modules/pytorch_wrapper/pt_tan.py b/modules/pytorch_wrapper/pt_tan.py new file mode 100644 index 0000000..0f38135 --- /dev/null +++ b/modules/pytorch_wrapper/pt_tan.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtTan: + """ + Computes the tangent of a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise tangent of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type, representing angles in radians. + + Returns: + tuple: A tuple containing the resultant tensor after applying the tangent function. + """ + return (torch.tan(tens_a),) diff --git a/modules/pytorch_wrapper/pt_tanh.py b/modules/pytorch_wrapper/pt_tanh.py new file mode 100644 index 0000000..9e08aca --- /dev/null +++ b/modules/pytorch_wrapper/pt_tanh.py @@ -0,0 +1,39 @@ +from typing import Any, Dict +import torch + +class PtTanh: + """ + Computes the hyperbolic tangent of a PyTorch tensor element-wise. + + category: PyTorch wrapper - Math operations + """ + + @classmethod + def INPUT_TYPES(cls) -> Dict[str, Any]: + """ + Defines the required input types. + + Returns: + Dict[str, Any]: A dictionary of required input types. + """ + return { + "required": { + "tens_a": ("TENSOR", {}) + } + } + + RETURN_TYPES: tuple = ("TENSOR",) + FUNCTION: str = "f" + CATEGORY: str = "Data Analysis" + + def f(self, tens_a: torch.Tensor) -> tuple: + """ + Computes the element-wise hyperbolic tangent of a PyTorch tensor. + + Args: + tens_a (torch.Tensor): A PyTorch tensor of numerical type. + + Returns: + tuple: A tuple containing the resultant tensor after applying the hyperbolic tangent function. + """ + return (torch.tanh(tens_a),) diff --git a/modules/pytorch_wrapper/pt_to_image.py b/modules/pytorch_wrapper/pt_to_image.py index d126251..fba4d01 100644 --- a/modules/pytorch_wrapper/pt_to_image.py +++ b/modules/pytorch_wrapper/pt_to_image.py @@ -6,7 +6,7 @@ class PtToImage: """ Casts a PyTorch tensor as an Image tensor. - category: PyTorch wrapper + category: PyTorch wrapper - Tensor data conversion """ @classmethod @@ -25,7 +25,7 @@ class PtToImage: RETURN_TYPES: tuple = ("IMAGE",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, tens: torch.Tensor) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_to_latent.py b/modules/pytorch_wrapper/pt_to_latent.py index 240d3cc..b9a7fb2 100644 --- a/modules/pytorch_wrapper/pt_to_latent.py +++ b/modules/pytorch_wrapper/pt_to_latent.py @@ -6,7 +6,7 @@ class PtToLatent: """ Casts a PyTorch tensor as a latent tensor. - category: PyTorch wrapper + category: PyTorch wrapper - Tensor data conversion """ @classmethod @@ -25,7 +25,7 @@ class PtToLatent: RETURN_TYPES: tuple = ("LATENT",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, tens: torch.Tensor) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_to_numpy.py b/modules/pytorch_wrapper/pt_to_numpy.py index f5ff4fc..4b2b9b7 100644 --- a/modules/pytorch_wrapper/pt_to_numpy.py +++ b/modules/pytorch_wrapper/pt_to_numpy.py @@ -6,7 +6,7 @@ class PtToNumpy: """ Converts PyTorch tensor to NumPy ndarray. - category: PyTorch wrapper + category: PyTorch wrapper - Tensor data conversion """ @classmethod @@ -25,7 +25,7 @@ class PtToNumpy: RETURN_TYPES: tuple = ("NDARRAY",) FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, tens: torch.Tensor) -> tuple: """ diff --git a/modules/pytorch_wrapper/pt_to_rgb_tensors.py b/modules/pytorch_wrapper/pt_to_rgb_tensors.py index 66f6a7c..a162129 100644 --- a/modules/pytorch_wrapper/pt_to_rgb_tensors.py +++ b/modules/pytorch_wrapper/pt_to_rgb_tensors.py @@ -6,7 +6,7 @@ class PtToRgbTensors: """ Splits a PyTorch tensor into R, G, and B tensors. - Category: PyTorch wrapper + category: PyTorch wrapper - Tensor data conversion """ @classmethod @@ -26,7 +26,7 @@ class PtToRgbTensors: RETURN_NAMES: tuple = ("R", "G", "B") RETURN_TYPES: tuple = ("TENSOR", "TENSOR", "TENSOR") FUNCTION: str = "f" - CATEGORY: str = "PyTorch wrapper" + CATEGORY: str = "Data Analysis" def f(self, tens: torch.Tensor) -> tuple: """ diff --git a/pyproject.toml b/pyproject.toml index 3169751..961e54e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "data-analysis" description = "Data analysis custom modules for ComfyUI - Use Pandas & Matplotlib within ComfyUI" -version = "1.3.6" +version = "1.4.0" license = {file = "LICENSE"} [project.urls] diff --git a/tests/pytorch_wrapper/pt_abs_test.py b/tests/pytorch_wrapper/pt_abs_test.py new file mode 100644 index 0000000..046e88a --- /dev/null +++ b/tests/pytorch_wrapper/pt_abs_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_abs import PtAbs # Updated import to PtAbs + + +class TestPtAbs(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtAbs() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([-1, 2, -3, 4], dtype=torch.float32), torch.tensor([1, 2, 3, 4], dtype=torch.float32)), # Mixed positive/negative + (torch.tensor([0, -5, 10, -15], dtype=torch.int32), torch.tensor([0, 5, 10, 15], dtype=torch.int32)), # Integer case + (torch.tensor([[-1.5, 2.3], [-3.7, 4.9]], dtype=torch.float32), torch.tensor([[1.5, 2.3], [3.7, 4.9]], dtype=torch.float32)), # 2D case + (torch.tensor([[-100, 0, 50], [-25, -75, 100]], dtype=torch.int64), torch.tensor([[100, 0, 50], [25, 75, 100]], dtype=torch.int64)), # Large numbers + (torch.full((2, 2), -7.7, dtype=torch.float32), torch.full((2, 2), 7.7, dtype=torch.float32)), # Constant matrix + ] + + def test_absolute_value(self): + """Test tensor element-wise absolute value using torch.abs().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected absolute value operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_acos_test.py b/tests/pytorch_wrapper/pt_acos_test.py new file mode 100644 index 0000000..528acf8 --- /dev/null +++ b/tests/pytorch_wrapper/pt_acos_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_acos import PtAcos # Updated import to PtAcos + + +class TestPtAcos(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtAcos() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([1.0, 0.0, -1.0], dtype=torch.float32), torch.acos(torch.tensor([1.0, 0.0, -1.0], dtype=torch.float32))), # Edge cases + (torch.tensor([0.5, -0.5], dtype=torch.float32), torch.acos(torch.tensor([0.5, -0.5], dtype=torch.float32))), # Common values + (torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32), torch.acos(torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 0.6, dtype=torch.float32), torch.acos(torch.full((2, 2), 0.6, dtype=torch.float32))), # Constant matrix + ] + + def test_acos(self): + """Test tensor element-wise arc cosine using torch.acos().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected acos values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_add_test.py b/tests/pytorch_wrapper/pt_add_test.py new file mode 100644 index 0000000..a46d181 --- /dev/null +++ b/tests/pytorch_wrapper/pt_add_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_add import PtAdd + + +class TestPtAdd(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtAdd() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0]), torch.tensor([4.0, 5.0, 6.0]), torch.tensor([5.0, 7.0, 9.0])), + (torch.ones(3, 3), torch.ones(3, 3), torch.full((3, 3), 2.0)), + (torch.zeros(2, 2), torch.ones(2, 2), torch.ones(2, 2)), + (torch.tensor([[1.0], [2.0]]), torch.tensor([[3.0], [4.0]]), torch.tensor([[4.0], [6.0]])), + ] + + def test_addition(self): + """Test tensor addition.""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected sum + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_asin_test.py b/tests/pytorch_wrapper/pt_asin_test.py new file mode 100644 index 0000000..92f8905 --- /dev/null +++ b/tests/pytorch_wrapper/pt_asin_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_asin import PtAsin # Updated import to PtAsin + + +class TestPtAsin(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtAsin() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([1.0, 0.0, -1.0], dtype=torch.float32), torch.asin(torch.tensor([1.0, 0.0, -1.0], dtype=torch.float32))), # Edge cases + (torch.tensor([0.5, -0.5], dtype=torch.float32), torch.asin(torch.tensor([0.5, -0.5], dtype=torch.float32))), # Common values + (torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32), torch.asin(torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 0.6, dtype=torch.float32), torch.asin(torch.full((2, 2), 0.6, dtype=torch.float32))), # Constant matrix + ] + + def test_asin(self): + """Test tensor element-wise arc sine using torch.asin().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected asin values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_atan_test.py b/tests/pytorch_wrapper/pt_atan_test.py new file mode 100644 index 0000000..551d7a5 --- /dev/null +++ b/tests/pytorch_wrapper/pt_atan_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_atan import PtAtan # Updated import to PtAtan + + +class TestPtAtan(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtAtan() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([1.0, 0.0, -1.0], dtype=torch.float32), torch.atan(torch.tensor([1.0, 0.0, -1.0], dtype=torch.float32))), # Edge cases + (torch.tensor([0.5, -0.5], dtype=torch.float32), torch.atan(torch.tensor([0.5, -0.5], dtype=torch.float32))), # Common values + (torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32), torch.atan(torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 0.6, dtype=torch.float32), torch.atan(torch.full((2, 2), 0.6, dtype=torch.float32))), # Constant matrix + ] + + def test_atan(self): + """Test tensor element-wise arc tangent using torch.atan().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected atan values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_bitwise_and_test.py b/tests/pytorch_wrapper/pt_bitwise_and_test.py new file mode 100644 index 0000000..630d459 --- /dev/null +++ b/tests/pytorch_wrapper/pt_bitwise_and_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_bitwise_and import PtBitwiseAnd # Updated import to PtBitwiseAnd + + +class TestPtBitwiseAnd(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtBitwiseAnd() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([0b0001, 0b0011, 0b0101]), torch.tensor([0b0001, 0b0010, 0b0110]), torch.tensor([0b0001, 0b0010, 0b0100])), + (torch.tensor([0b1111, 0b1010, 0b1100]), torch.tensor([0b0101, 0b1100, 0b1010]), torch.tensor([0b0101, 0b1000, 0b1000])), + (torch.tensor([1, 2, 3]), torch.tensor([3, 2, 1]), torch.tensor([1, 2, 1])), + (torch.ones(2, 2, dtype=torch.int32), torch.zeros(2, 2, dtype=torch.int32), torch.zeros(2, 2, dtype=torch.int32)), + (torch.full((2, 2), 0b1010, dtype=torch.int32), torch.full((2, 2), 0b1100, dtype=torch.int32), torch.full((2, 2), 0b1000, dtype=torch.int32)), + ] + + def test_bitwise_and(self): + """Test tensor element-wise bitwise AND using torch.bitwise_and().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected bitwise AND operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_bitwise_left_shift_test.py b/tests/pytorch_wrapper/pt_bitwise_left_shift_test.py new file mode 100644 index 0000000..124b8bf --- /dev/null +++ b/tests/pytorch_wrapper/pt_bitwise_left_shift_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_bitwise_left_shift import PtBitwiseLeftShift # Updated import to PtBitwiseLeftShift + + +class TestPtBitwiseLeftShift(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtBitwiseLeftShift() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([1, 2, 4], dtype=torch.int64), torch.tensor([1, 2, 3], dtype=torch.int64), torch.tensor([2, 8, 32], dtype=torch.int64)), # 1<<1, 2<<2, 4<<3 + (torch.tensor([4, 8, 16], dtype=torch.int64), torch.tensor([2, 1, 3], dtype=torch.int64), torch.tensor([16, 16, 128], dtype=torch.int64)), # 4<<2, 8<<1, 16<<3 + (torch.tensor([0b0001, 0b0010, 0b0100], dtype=torch.int64), torch.tensor([1, 2, 3], dtype=torch.int64), torch.tensor([0b0010, 0b1000, 0b100000], dtype=torch.int64)), # Bitwise shift + (torch.ones(3, 3, dtype=torch.int64), torch.full((3, 3), 2, dtype=torch.int64), torch.full((3, 3), 4, dtype=torch.int64)), # 1<<2 = 4 + (torch.full((2, 2), 5, dtype=torch.int64), torch.full((2, 2), 3, dtype=torch.int64), torch.full((2, 2), 40, dtype=torch.int64)), # 5<<3 = 40 + ] + + def test_bitwise_left_shift(self): + """Test tensor element-wise bitwise left shift using torch.bitwise_left_shift().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected bitwise left shift operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_bitwise_not_test.py b/tests/pytorch_wrapper/pt_bitwise_not_test.py new file mode 100644 index 0000000..a7d87d8 --- /dev/null +++ b/tests/pytorch_wrapper/pt_bitwise_not_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_bitwise_not import PtBitwiseNot # Updated import to PtBitwiseNot + + +class TestPtBitwiseNot(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtBitwiseNot() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([0, 1, 2, 3], dtype=torch.int32), torch.tensor([-1, -2, -3, -4], dtype=torch.int32)), # Bitwise NOT + (torch.tensor([0b0000, 0b0001, 0b0010], dtype=torch.int32), torch.tensor([-1, -2, -3], dtype=torch.int32)), # Binary representation + (torch.tensor([[5, 10], [15, 20]], dtype=torch.int32), torch.tensor([[-6, -11], [-16, -21]], dtype=torch.int32)), # Matrix case + (torch.full((2, 2), 0, dtype=torch.int32), torch.full((2, 2), -1, dtype=torch.int32)), # NOT 0 -> -1 + (torch.full((3, 3), -1, dtype=torch.int32), torch.full((3, 3), 0, dtype=torch.int32)), # NOT -1 -> 0 + ] + + def test_bitwise_not(self): + """Test tensor element-wise bitwise NOT using torch.bitwise_not().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected bitwise NOT operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_bitwise_or_test.py b/tests/pytorch_wrapper/pt_bitwise_or_test.py new file mode 100644 index 0000000..9b606fd --- /dev/null +++ b/tests/pytorch_wrapper/pt_bitwise_or_test.py @@ -0,0 +1,54 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_bitwise_or import PtBitwiseOr # Updated import to PtBitwiseOr + + +class TestPtBitwiseOr(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtBitwiseOr() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([0b0001, 0b0011, 0b0101], dtype=torch.int32), + torch.tensor([0b0010, 0b0100, 0b0110], dtype=torch.int32), + torch.tensor([0b0011, 0b0111, 0b0111], dtype=torch.int32)), # Binary OR + + (torch.tensor([1, 2, 4], dtype=torch.int32), + torch.tensor([8, 16, 32], dtype=torch.int32), + torch.tensor([9, 18, 36], dtype=torch.int32)), # Decimal OR + + (torch.tensor([5, 10, 15], dtype=torch.int32), + torch.tensor([3, 6, 12], dtype=torch.int32), + torch.tensor([7, 14, 15], dtype=torch.int32)), # Mixed values + + (torch.zeros(3, 3, dtype=torch.int32), + torch.ones(3, 3, dtype=torch.int32), + torch.ones(3, 3, dtype=torch.int32)), # OR with all ones + + (torch.full((2, 2), 0b1010, dtype=torch.int32), + torch.full((2, 2), 0b1100, dtype=torch.int32), + torch.full((2, 2), 0b1110, dtype=torch.int32)), # OR with constant matrices + ] + + def test_bitwise_or(self): + """Test tensor element-wise bitwise OR using torch.bitwise_or().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected bitwise OR operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_bitwise_right_shift_test.py b/tests/pytorch_wrapper/pt_bitwise_right_shift_test.py new file mode 100644 index 0000000..69a9b9b --- /dev/null +++ b/tests/pytorch_wrapper/pt_bitwise_right_shift_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_bitwise_right_shift import PtBitwiseRightShift # Updated import to PtBitwiseRightShift + + +class TestPtBitwiseRightShift(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtBitwiseRightShift() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([4, 8, 16], dtype=torch.int64), torch.tensor([1, 2, 3], dtype=torch.int64), torch.tensor([2, 2, 2], dtype=torch.int64)), # 4>>1, 8>>2, 16>>3 + (torch.tensor([32, 64, 128], dtype=torch.int64), torch.tensor([2, 3, 4], dtype=torch.int64), torch.tensor([8, 8, 8], dtype=torch.int64)), # 32>>2, 64>>3, 128>>4 + (torch.tensor([0b1000, 0b10000, 0b100000], dtype=torch.int64), torch.tensor([1, 2, 3], dtype=torch.int64), torch.tensor([0b0100, 0b00100, 0b000100], dtype=torch.int64)), # Bitwise shift + (torch.full((3, 3), 16, dtype=torch.int64), torch.full((3, 3), 2, dtype=torch.int64), torch.full((3, 3), 4, dtype=torch.int64)), # 16>>2 = 4 + (torch.full((2, 2), 40, dtype=torch.int64), torch.full((2, 2), 3, dtype=torch.int64), torch.full((2, 2), 5, dtype=torch.int64)), # 40>>3 = 5 + ] + + def test_bitwise_right_shift(self): + """Test tensor element-wise bitwise right shift using torch.bitwise_right_shift().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected bitwise right shift operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_bitwise_xor_test.py b/tests/pytorch_wrapper/pt_bitwise_xor_test.py new file mode 100644 index 0000000..24ce242 --- /dev/null +++ b/tests/pytorch_wrapper/pt_bitwise_xor_test.py @@ -0,0 +1,54 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_bitwise_xor import PtBitwiseXor # Updated import to PtBitwiseXor + + +class TestPtBitwiseXor(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtBitwiseXor() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([0b0001, 0b0011, 0b0101], dtype=torch.int32), + torch.tensor([0b0010, 0b0100, 0b0110], dtype=torch.int32), + torch.tensor([0b0011, 0b0111, 0b0011], dtype=torch.int32)), # Binary XOR + + (torch.tensor([1, 2, 4], dtype=torch.int32), + torch.tensor([8, 16, 32], dtype=torch.int32), + torch.tensor([9, 18, 36], dtype=torch.int32)), # Decimal XOR + + (torch.tensor([5, 10, 15], dtype=torch.int32), + torch.tensor([3, 6, 12], dtype=torch.int32), + torch.tensor([6, 12, 3], dtype=torch.int32)), # Mixed values + + (torch.zeros(3, 3, dtype=torch.int32), + torch.ones(3, 3, dtype=torch.int32), + torch.ones(3, 3, dtype=torch.int32)), # XOR with all ones + + (torch.full((2, 2), 0b1010, dtype=torch.int32), + torch.full((2, 2), 0b1100, dtype=torch.int32), + torch.full((2, 2), 0b0110, dtype=torch.int32)), # XOR with constant matrices + ] + + def test_bitwise_xor(self): + """Test tensor element-wise bitwise XOR using torch.bitwise_xor().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected bitwise XOR operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_bmm_test.py b/tests/pytorch_wrapper/pt_bmm_test.py new file mode 100644 index 0000000..e1e1a87 --- /dev/null +++ b/tests/pytorch_wrapper/pt_bmm_test.py @@ -0,0 +1,60 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_bmm import PtBmm # Updated import to PtBmm + + +class TestPtBmm(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtBmm() + + # Valid test cases: (Tensor A, Tensor B, Expected result) + self.valid_test_cases = [ + # Case 1: Batch of 2 matrices (3x4) * (4x5) → (2, 3, 5) + (torch.ones(2, 3, 4), torch.ones(2, 4, 5), torch.full((2, 3, 5), 4.0)), + + # Case 2: Batch of 3 matrices (2x3) * (3x2) → (3, 2, 2) + (torch.tensor([[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]]), + torch.tensor([[[7.0, 8.0], [9.0, 10.0], [11.0, 12.0]]]), + torch.tensor([[[58.0, 64.0], [139.0, 154.0]]])), + + # Case 3: Identity matrix batch multiplication (should remain the same) + (torch.eye(3).expand(4, -1, -1), torch.eye(3).expand(4, -1, -1), torch.eye(3).expand(4, -1, -1)), + ] + + # Invalid test cases (should raise errors) + self.invalid_test_cases = [ + (torch.ones(3, 4), torch.ones(4, 5)), # 2D tensors (not allowed) + (torch.ones(2, 3, 4), torch.ones(3, 4, 5)), # Mismatched batch size + (torch.ones(2, 3, 4, 5), torch.ones(2, 5, 6)), # 4D tensors (not allowed) + (torch.ones(2, 3, 4), torch.ones(2, 5, 6)), # Matmul shape mismatch within batch + ] + + def test_batched_matrix_multiplication(self): + """Test valid batched matrix multiplication cases.""" + for tens_a, tens_b, expected in self.valid_test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected batch matrix multiplication + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + + def test_invalid_multiplication(self): + """Test invalid cases where dimensions do not match.""" + for tens_a, tens_b in self.invalid_test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + with self.assertRaises(Exception, msg=f"torch.bmm() should fail for shapes {tens_a.shape} and {tens_b.shape}"): + self.node.f(tens_a, tens_b) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_bool_create_test.py b/tests/pytorch_wrapper/pt_bool_create_test.py new file mode 100644 index 0000000..8e3ce6e --- /dev/null +++ b/tests/pytorch_wrapper/pt_bool_create_test.py @@ -0,0 +1,58 @@ +import os +import sys +import unittest +import torch +import ast + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_bool_create import PtBoolCreate + +class TestPtBoolCreate(unittest.TestCase): + def setUp(self): + """Set up test data.""" + self.node = PtBoolCreate() + + # Test cases covering various ranks + self.test_cases = [ + # Rank 0 (scalar) + ("True", torch.tensor(True, dtype=torch.bool)), + ("False", torch.tensor(False, dtype=torch.bool)), + + # Rank 1 (1D array) + ("[True, False, True]", torch.tensor([True, False, True], dtype=torch.bool)), + + # Rank 2 (2D matrix) + ("[[True, False], [False, True]]", torch.tensor([[True, False], [False, True]], dtype=torch.bool)), + + # Rank 3 (3D tensor) + ( + "[[[True, False], [False, True]], [[False, True], [True, False]]]", + torch.tensor([[[True, False], [False, True]], [[False, True], [True, False]]], dtype=torch.bool), + ), + ] + + def test_create_tensor(self): + """Test PyTorch boolean tensor creation from various structured inputs.""" + for data_str, expected_tensor in self.test_cases: + with self.subTest(data=data_str): + retval = self.node.f(data_str)[0] + + # Ensure the returned value is a PyTorch tensor + self.assertTrue(isinstance(retval, torch.Tensor), f"Expected tensor, got {type(retval)}") + + # Ensure the dtype is bool + self.assertEqual(retval.dtype, torch.bool, f"Dtype mismatch for input: {data_str}") + + # Ensure the shape matches + self.assertEqual(retval.shape, expected_tensor.shape, + f"Shape mismatch for input: {data_str} (Expected {expected_tensor.shape}, got {retval.shape})") + + # Ensure values match + torch.testing.assert_close(retval, expected_tensor, + msg=f"Value mismatch for input: {data_str}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_cos_test.py b/tests/pytorch_wrapper/pt_cos_test.py new file mode 100644 index 0000000..9d03217 --- /dev/null +++ b/tests/pytorch_wrapper/pt_cos_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_cos import PtCos # Updated import to PtCos + + +class TestPtCos(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtCos() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([0.0, torch.pi / 2, torch.pi], dtype=torch.float32), torch.cos(torch.tensor([0.0, torch.pi / 2, torch.pi], dtype=torch.float32))), # Edge cases + (torch.tensor([0.5, -0.5], dtype=torch.float32), torch.cos(torch.tensor([0.5, -0.5], dtype=torch.float32))), # Common values + (torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32), torch.cos(torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 0.6, dtype=torch.float32), torch.cos(torch.full((2, 2), 0.6, dtype=torch.float32))), # Constant matrix + ] + + def test_cos(self): + """Test tensor element-wise cosine using torch.cos().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected cos values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_cosh_test.py b/tests/pytorch_wrapper/pt_cosh_test.py new file mode 100644 index 0000000..299fec0 --- /dev/null +++ b/tests/pytorch_wrapper/pt_cosh_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_cosh import PtCosh # Updated import to PtCosh + + +class TestPtCosh(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtCosh() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([0.0, 1.0, -1.0], dtype=torch.float32), torch.cosh(torch.tensor([0.0, 1.0, -1.0], dtype=torch.float32))), # Edge cases + (torch.tensor([0.5, -0.5], dtype=torch.float32), torch.cosh(torch.tensor([0.5, -0.5], dtype=torch.float32))), # Common values + (torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32), torch.cosh(torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 0.6, dtype=torch.float32), torch.cosh(torch.full((2, 2), 0.6, dtype=torch.float32))), # Constant matrix + ] + + def test_cosh(self): + """Test tensor element-wise hyperbolic cosine using torch.cosh().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected cosh values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_div_test.py b/tests/pytorch_wrapper/pt_div_test.py new file mode 100644 index 0000000..7e6e022 --- /dev/null +++ b/tests/pytorch_wrapper/pt_div_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_div import PtDiv # Updated import to PtDiv + + +class TestPtDiv(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtDiv() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([4.0, 10.0, 18.0]), torch.tensor([2.0, 5.0, 6.0]), torch.tensor([2.0, 2.0, 3.0])), + (torch.ones(3, 3), torch.ones(3, 3), torch.ones(3, 3)), # 1 / 1 = 1 + (torch.full((2, 2), 4.0), torch.full((2, 2), 2.0), torch.full((2, 2), 2.0)), # 4 / 2 = 2 + (torch.tensor([[6.0], [12.0]]), torch.tensor([[3.0], [4.0]]), torch.tensor([[2.0], [3.0]])), # Element-wise division + ] + + def test_division(self): + """Test tensor division.""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected quotient + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_einsum_test.py b/tests/pytorch_wrapper/pt_einsum_test.py new file mode 100644 index 0000000..ef93fcb --- /dev/null +++ b/tests/pytorch_wrapper/pt_einsum_test.py @@ -0,0 +1,99 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_einsum import PtEinsum # Updated import to PtEinsum + + +class TestPtEinsum(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtEinsum() + + def test_trace_extraction(self): + """Extract the diagonal (1,2,3,4,5) and sum it up (trace).""" + matrix = torch.tensor([[1, 0, 0, 0, 0], + [0, 2, 0, 0, 0], + [0, 0, 3, 0, 0], + [0, 0, 0, 4, 0], + [0, 0, 0, 0, 5]], dtype=torch.float32) + expected = torch.tensor(15.0) # Sum of diagonal + result, = self.node.f("ii", matrix) # Only requires `tens_a` + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + + def test_diagonal_extraction(self): + """Extract diagonal elements (1,2,3,4,5).""" + matrix = torch.tensor([[1, 0, 0, 0, 0], + [0, 2, 0, 0, 0], + [0, 0, 3, 0, 0], + [0, 0, 0, 4, 0], + [0, 0, 0, 0, 5]], dtype=torch.float32) + expected = torch.tensor([1, 2, 3, 4, 5], dtype=torch.float32) + result, = self.node.f("ii->i", matrix) # Only requires `tens_a` + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + + def test_hadamard_product(self): + """Compute Hadamard product (element-wise multiplication).""" + a = torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=torch.float32) + b = torch.tensor([[9, 10, 11, 12], [13, 14, 15, 16]], dtype=torch.float32) + expected = a * b + result, = self.node.f("ij,ij->ij", a, b) + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + + def test_matrix_multiplication(self): + """Test standard matrix multiplication.""" + a = torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=torch.float32) + b = torch.tensor([[9, 10], [11, 12], [13, 14], [15, 16]], dtype=torch.float32) + expected = torch.mm(a, b) + result, = self.node.f("ij,jk->ik", a, b) + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + + def test_3d_tensor_multiplication(self): + """Test matrix multiplication for rank-3 tensors.""" + a = torch.ones(2, 3, 4, dtype=torch.float32) + b = torch.ones(2, 4, 5, dtype=torch.float32) + expected = torch.matmul(a, b) + result, = self.node.f("bij,bjk->bik", a, b) + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + + def test_4d_tensor_multiplication(self): + """Test matrix multiplication for rank-4 tensors.""" + a = torch.ones(2, 3, 4, 6, dtype=torch.float32) # (batch, groups, rows, cols) + b = torch.ones(2, 3, 6, 5, dtype=torch.float32) # (batch, groups, cols, out_features) + + expected = torch.matmul(a, b) # Standard 4D matrix multiplication + result, = self.node.f("bijk,bikl->bijl", a, b) # Correct einsum notation + + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + + def test_bilinear_transformation(self): + """Test bilinear transformation: a vector, W matrix, and b vector.""" + a = torch.tensor([1, 2, 3, 4, 5], dtype=torch.float32) + W = torch.tensor([[6, 7, 8, 9, 10], + [11, 12, 13, 14, 15], + [16, 17, 18, 19, 20], + [21, 22, 23, 24, 25], + [26, 27, 28, 29, 30]], dtype=torch.float32) + b = torch.tensor([31, 32, 33, 34, 35], dtype=torch.float32) + + expected = torch.dot(a, torch.matmul(W, b)) + result, = self.node.f("i,ij,j->", a, W, b) + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + + def test_tensor_format_conversion(self): + """Test conversion from (B, C, H, W) format to (B, H, W, C) format.""" + a = torch.randn(2, 3, 64, 64, dtype=torch.float32) # (Batch, Channels, Height, Width) + + expected = a.permute(0, 2, 3, 1) # Convert to (Batch, Height, Width, Channels) + result, = self.node.f("bchw->bhwc", a) # Correct einsum notation for format swap + + self.assertTrue(torch.equal(result, expected), f"Expected {expected.shape}, got {result.shape}") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_eq_test.py b/tests/pytorch_wrapper/pt_eq_test.py new file mode 100644 index 0000000..0943a8f --- /dev/null +++ b/tests/pytorch_wrapper/pt_eq_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_eq import PtEq # Updated import to PtEq + + +class TestPtEq(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtEq() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([1, 2, 3]), torch.tensor([1, 2, 3]), torch.tensor([True, True, True])), + (torch.tensor([1, 2, 3]), torch.tensor([3, 2, 1]), torch.tensor([False, True, False])), + (torch.ones(3, 3), torch.ones(3, 3), torch.full((3, 3), True, dtype=torch.bool)), + (torch.zeros(2, 2), torch.ones(2, 2), torch.full((2, 2), False, dtype=torch.bool)), + (torch.tensor([[1], [2]]), torch.tensor([[1], [3]]), torch.tensor([[True], [False]])), + ] + + def test_equality(self): + """Test tensor element-wise equality using torch.eq().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected element-wise equality + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_exp_test.py b/tests/pytorch_wrapper/pt_exp_test.py new file mode 100644 index 0000000..b88551c --- /dev/null +++ b/tests/pytorch_wrapper/pt_exp_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_exp import PtExp # Updated import to PtExp + + +class TestPtExp(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtExp() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([0.0, 1.0, 2.0], dtype=torch.float32), torch.exp(torch.tensor([0.0, 1.0, 2.0], dtype=torch.float32))), # Edge cases + (torch.tensor([-1.0, -2.0, 0.5], dtype=torch.float32), torch.exp(torch.tensor([-1.0, -2.0, 0.5], dtype=torch.float32))), # Common values + (torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32), torch.exp(torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 0.6, dtype=torch.float32), torch.exp(torch.full((2, 2), 0.6, dtype=torch.float32))), # Constant matrix + ] + + def test_exp(self): + """Test tensor element-wise exponential function using torch.exp().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected exp values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_floor_divide_test.py b/tests/pytorch_wrapper/pt_floor_divide_test.py new file mode 100644 index 0000000..9347727 --- /dev/null +++ b/tests/pytorch_wrapper/pt_floor_divide_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_floor_divide import PtFloorDiv + + +class TestPtFloorDiv(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtFloorDiv() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([4.0, 10.0, 18.0]), torch.tensor([3.0, 4.0, 5.0]), torch.tensor([1.0, 2.0, 3.0])), + (torch.ones(3, 3) * 7, torch.ones(3, 3) * 3, torch.ones(3, 3) * 2), # 7 // 3 = 2 + (torch.full((2, 2), 9.0), torch.full((2, 2), 2.0), torch.full((2, 2), 4.0)), # 9 // 2 = 4 + (torch.tensor([[7.0], [15.0]]), torch.tensor([[2.0], [4.0]]), torch.tensor([[3.0], [3.0]])), # Element-wise floor division + ] + + def test_floor_division(self): + """Test tensor floor division.""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected floor quotient + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_ge_test.py b/tests/pytorch_wrapper/pt_ge_test.py new file mode 100644 index 0000000..92ab581 --- /dev/null +++ b/tests/pytorch_wrapper/pt_ge_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_ge import PtGe # Updated import to PtGe + + +class TestPtGe(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtGe() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([1, 2, 3]), torch.tensor([0, 2, 4]), torch.tensor([True, True, False])), + (torch.tensor([3, 5, 7]), torch.tensor([1, 5, 10]), torch.tensor([True, True, False])), + (torch.ones(3, 3), torch.ones(3, 3), torch.full((3, 3), True, dtype=torch.bool)), + (torch.zeros(2, 2), torch.ones(2, 2), torch.full((2, 2), False, dtype=torch.bool)), + (torch.tensor([[5], [10]]), torch.tensor([[5], [10]]), torch.tensor([[True], [True]])), + ] + + def test_greater_or_equal(self): + """Test tensor element-wise greater-than-or-equal condition using torch.ge().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected greater-than-or-equal comparison + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_gt_test.py b/tests/pytorch_wrapper/pt_gt_test.py new file mode 100644 index 0000000..29603bf --- /dev/null +++ b/tests/pytorch_wrapper/pt_gt_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_gt import PtGt # Updated import to PtGt + + +class TestPtGt(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtGt() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([1, 2, 3]), torch.tensor([0, 2, 4]), torch.tensor([True, False, False])), + (torch.tensor([3, 5, 7]), torch.tensor([1, 5, 10]), torch.tensor([True, False, False])), + (torch.ones(3, 3), torch.zeros(3, 3), torch.full((3, 3), True, dtype=torch.bool)), + (torch.zeros(2, 2), torch.ones(2, 2), torch.full((2, 2), False, dtype=torch.bool)), + (torch.tensor([[5], [10]]), torch.tensor([[3], [10]]), torch.tensor([[True], [False]])), + ] + + def test_greater_than(self): + """Test tensor element-wise greater-than condition using torch.gt().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected greater-than comparison + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_le_test.py b/tests/pytorch_wrapper/pt_le_test.py new file mode 100644 index 0000000..4cb062d --- /dev/null +++ b/tests/pytorch_wrapper/pt_le_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_le import PtLe # Updated import to PtLe + + +class TestPtLe(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtLe() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([1, 2, 3]), torch.tensor([0, 2, 4]), torch.tensor([False, True, True])), + (torch.tensor([3, 5, 7]), torch.tensor([1, 5, 10]), torch.tensor([False, True, True])), + (torch.ones(3, 3), torch.ones(3, 3), torch.full((3, 3), True, dtype=torch.bool)), + (torch.zeros(2, 2), torch.ones(2, 2), torch.full((2, 2), True, dtype=torch.bool)), + (torch.tensor([[5], [10]]), torch.tensor([[5], [10]]), torch.tensor([[True], [True]])), + ] + + def test_less_or_equal(self): + """Test tensor element-wise less-than-or-equal condition using torch.le().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected less-than-or-equal comparison + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_log_test.py b/tests/pytorch_wrapper/pt_log_test.py new file mode 100644 index 0000000..a2b644a --- /dev/null +++ b/tests/pytorch_wrapper/pt_log_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_log import PtLog # Updated import to PtLog + + +class TestPtLog(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtLog() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([1.0, torch.e, 10.0], dtype=torch.float32), torch.log(torch.tensor([1.0, torch.e, 10.0], dtype=torch.float32))), # Edge cases + (torch.tensor([0.5, 2.0, 3.0], dtype=torch.float32), torch.log(torch.tensor([0.5, 2.0, 3.0], dtype=torch.float32))), # Common values + (torch.tensor([[1.5, 3.2], [4.7, 5.9]], dtype=torch.float32), torch.log(torch.tensor([[1.5, 3.2], [4.7, 5.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 2.5, dtype=torch.float32), torch.log(torch.full((2, 2), 2.5, dtype=torch.float32))), # Constant matrix + ] + + def test_log(self): + """Test tensor element-wise natural logarithm using torch.log().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected log values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_logical_and_test.py b/tests/pytorch_wrapper/pt_logical_and_test.py new file mode 100644 index 0000000..c5227fb --- /dev/null +++ b/tests/pytorch_wrapper/pt_logical_and_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_logical_and import PtLogicalAnd # Updated import to PtLogicalAnd + + +class TestPtLogicalAnd(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtLogicalAnd() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([True, False, True]), torch.tensor([False, False, True]), torch.tensor([False, False, True])), + (torch.tensor([[True, True], [False, False]]), torch.tensor([[True, False], [True, False]]), torch.tensor([[True, False], [False, False]])), + (torch.ones(3, 3, dtype=torch.bool), torch.zeros(3, 3, dtype=torch.bool), torch.zeros(3, 3, dtype=torch.bool)), # All true AND all false -> all false + (torch.ones(2, 2, dtype=torch.bool), torch.ones(2, 2, dtype=torch.bool), torch.ones(2, 2, dtype=torch.bool)), # All true AND all true -> all true + (torch.tensor([1, 0, 1, 0], dtype=torch.bool), torch.tensor([1, 1, 0, 0], dtype=torch.bool), torch.tensor([True, False, False, False])), # Mixed cases + ] + + def test_logical_and(self): + """Test tensor element-wise logical AND using torch.logical_and().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected logical AND operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_logical_not_test.py b/tests/pytorch_wrapper/pt_logical_not_test.py new file mode 100644 index 0000000..de18c94 --- /dev/null +++ b/tests/pytorch_wrapper/pt_logical_not_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_logical_not import PtLogicalNot # Updated import to PtLogicalNot + + +class TestPtLogicalNot(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtLogicalNot() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([True, False, True]), torch.tensor([False, True, False])), + (torch.tensor([[True, True], [False, False]]), torch.tensor([[False, False], [True, True]])), + (torch.ones(3, 3, dtype=torch.bool), torch.zeros(3, 3, dtype=torch.bool)), # NOT all true -> all false + (torch.zeros(2, 2, dtype=torch.bool), torch.ones(2, 2, dtype=torch.bool)), # NOT all false -> all true + (torch.tensor([1, 0, 1, 0], dtype=torch.bool), torch.tensor([False, True, False, True])), # Mixed cases + ] + + def test_logical_not(self): + """Test tensor element-wise logical NOT using torch.logical_not().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected logical NOT operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_logical_or_test.py b/tests/pytorch_wrapper/pt_logical_or_test.py new file mode 100644 index 0000000..97ae602 --- /dev/null +++ b/tests/pytorch_wrapper/pt_logical_or_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_logical_or import PtLogicalOr # Updated import to PtLogicalOr + + +class TestPtLogicalOr(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtLogicalOr() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([True, False, True]), torch.tensor([False, False, True]), torch.tensor([True, False, True])), + (torch.tensor([[True, True], [False, False]]), torch.tensor([[False, True], [True, False]]), torch.tensor([[True, True], [True, False]])), + (torch.ones(3, 3, dtype=torch.bool), torch.zeros(3, 3, dtype=torch.bool), torch.ones(3, 3, dtype=torch.bool)), # All true OR all false -> all true + (torch.zeros(2, 2, dtype=torch.bool), torch.zeros(2, 2, dtype=torch.bool), torch.zeros(2, 2, dtype=torch.bool)), # All false OR all false -> all false + (torch.tensor([1, 0, 1, 0], dtype=torch.bool), torch.tensor([1, 1, 0, 0], dtype=torch.bool), torch.tensor([True, True, True, False])), # Mixed cases + ] + + def test_logical_or(self): + """Test tensor element-wise logical OR using torch.logical_or().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected logical OR operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_logical_xor_test.py b/tests/pytorch_wrapper/pt_logical_xor_test.py new file mode 100644 index 0000000..7756330 --- /dev/null +++ b/tests/pytorch_wrapper/pt_logical_xor_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_logical_xor import PtLogicalXor # Updated import to PtLogicalXor + + +class TestPtLogicalXor(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtLogicalXor() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([True, False, True]), torch.tensor([False, False, True]), torch.tensor([True, False, False])), + (torch.tensor([[True, True], [False, False]]), torch.tensor([[False, True], [True, False]]), torch.tensor([[True, False], [True, False]])), + (torch.ones(3, 3, dtype=torch.bool), torch.zeros(3, 3, dtype=torch.bool), torch.ones(3, 3, dtype=torch.bool)), # True XOR False -> True + (torch.zeros(2, 2, dtype=torch.bool), torch.zeros(2, 2, dtype=torch.bool), torch.zeros(2, 2, dtype=torch.bool)), # False XOR False -> False + (torch.tensor([1, 0, 1, 0], dtype=torch.bool), torch.tensor([1, 1, 0, 0], dtype=torch.bool), torch.tensor([False, True, True, False])), # Mixed cases + ] + + def test_logical_xor(self): + """Test tensor element-wise logical XOR using torch.logical_xor().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected logical XOR operation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_lt_test.py b/tests/pytorch_wrapper/pt_lt_test.py new file mode 100644 index 0000000..027c478 --- /dev/null +++ b/tests/pytorch_wrapper/pt_lt_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_lt import PtLt # Updated import to PtLt + + +class TestPtLt(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtLt() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([1, 2, 3]), torch.tensor([0, 2, 4]), torch.tensor([False, False, True])), + (torch.tensor([3, 5, 7]), torch.tensor([1, 5, 10]), torch.tensor([False, False, True])), + (torch.ones(3, 3), torch.ones(3, 3), torch.full((3, 3), False, dtype=torch.bool)), + (torch.zeros(2, 2), torch.ones(2, 2), torch.full((2, 2), True, dtype=torch.bool)), + (torch.tensor([[5], [10]]), torch.tensor([[5], [10]]), torch.tensor([[False], [False]])), + ] + + def test_less_than(self): + """Test tensor element-wise less-than condition using torch.lt().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected less-than comparison + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_matmul_test.py b/tests/pytorch_wrapper/pt_matmul_test.py new file mode 100644 index 0000000..d3f5245 --- /dev/null +++ b/tests/pytorch_wrapper/pt_matmul_test.py @@ -0,0 +1,63 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_matmul import PtMatMul # Updated import to PtMatMul + + +class TestPtMatMul(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtMatMul() + + # Valid test cases: (Tensor A, Tensor B, Expected result) + self.valid_test_cases = [ + # Case 1: 1D x 1D (dot product) + (torch.tensor([1.0, 2.0, 3.0]), torch.tensor([4.0, 5.0, 6.0]), torch.tensor(32.0)), + + # Case 2: 1D x 2D (vector-matrix multiplication) + (torch.tensor([1.0, 2.0]), torch.tensor([[3.0, 4.0], [5.0, 6.0]]), torch.tensor([13.0, 16.0])), + + # Case 3: 2D x 2D (matrix-matrix multiplication) + (torch.tensor([[1.0, 2.0], [3.0, 4.0]]), torch.tensor([[5.0, 6.0], [7.0, 8.0]]), torch.tensor([[19.0, 22.0], [43.0, 50.0]])), + + # Case 4: 3D x 2D (batched matrix-matrix multiplication) + (torch.ones(2, 3, 4), torch.ones(4, 5), torch.full((2, 3, 5), 4.0)), # (2,3,4) * (4,5) → (2,3,5) + + # Case 5: 3D x 3D (batched matrix multiplication with broadcasting) + (torch.ones(2, 3, 4), torch.ones(2, 4, 5), torch.full((2, 3, 5), 4.0)), # (2,3,4) * (2,4,5) → (2,3,5) + ] + + # Invalid test cases (should raise errors) + self.invalid_test_cases = [ + (torch.ones(2, 3), torch.ones(4, 2)), # (2,3) * (4,2) is invalid + (torch.tensor([1.0, 2.0, 3.0]), torch.tensor([4.0, 5.0])), # Vector size mismatch + (torch.ones(2, 3, 4), torch.ones(3, 5)), # (2,3,4) * (3,5) should fail due to misalignment + ] + + def test_matrix_multiplication(self): + """Test valid matrix multiplication cases.""" + for tens_a, tens_b, expected in self.valid_test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected matrix multiplication + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + + def test_invalid_multiplication(self): + """Test invalid cases where dimensions do not match.""" + for tens_a, tens_b in self.invalid_test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + with self.assertRaises(RuntimeError, msg=f"MatMul should fail for shapes {tens_a.shape} and {tens_b.shape}"): + self.node.f(tens_a, tens_b) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_mm_test.py b/tests/pytorch_wrapper/pt_mm_test.py new file mode 100644 index 0000000..33fb78f --- /dev/null +++ b/tests/pytorch_wrapper/pt_mm_test.py @@ -0,0 +1,58 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_mm import PtMm # Updated import to PtMm + + +class TestPtMm(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtMm() + + # Valid test cases: (Tensor A, Tensor B, Expected result) + self.valid_test_cases = [ + # Case 1: 2D x 2D (matrix-matrix multiplication) + (torch.tensor([[1.0, 2.0], [3.0, 4.0]]), torch.tensor([[5.0, 6.0], [7.0, 8.0]]), torch.tensor([[19.0, 22.0], [43.0, 50.0]])), + + # Case 2: 2D identity matrix multiplication (should remain the same) + (torch.eye(3), torch.eye(3), torch.eye(3)), + + # Case 3: Rectangular 2D matrix multiplication + (torch.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]), torch.tensor([[7.0, 8.0], [9.0, 10.0], [11.0, 12.0]]), torch.tensor([[58.0, 64.0], [139.0, 154.0]])), + ] + + # Invalid test cases (should raise errors) + self.invalid_test_cases = [ + (torch.tensor([1.0, 2.0, 3.0]), torch.tensor([4.0, 5.0, 6.0])), # 1D x 1D (dot product not supported by mm) + (torch.tensor([[1.0, 2.0]]), torch.tensor([3.0, 4.0])), # 2D x 1D mismatch + (torch.ones(2, 3, 4), torch.ones(4, 5)), # 3D x 2D is invalid for mm + (torch.ones(2, 3, 4), torch.ones(2, 4, 5)), # 3D x 3D is invalid for mm + ] + + def test_matrix_multiplication(self): + """Test valid matrix multiplication cases.""" + for tens_a, tens_b, expected in self.valid_test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected matrix multiplication + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + + def test_invalid_multiplication(self): + """Test invalid cases where dimensions do not match.""" + for tens_a, tens_b in self.invalid_test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + with self.assertRaises(ValueError, msg=f"torch.mm() should fail for shapes {tens_a.shape} and {tens_b.shape}"): + self.node.f(tens_a, tens_b) + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_mul_test.py b/tests/pytorch_wrapper/pt_mul_test.py new file mode 100644 index 0000000..8bff3f9 --- /dev/null +++ b/tests/pytorch_wrapper/pt_mul_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_mul import PtMul # Updated import to PtMul + + +class TestPtMul(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtMul() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([1.0, 2.0, 3.0]), torch.tensor([4.0, 5.0, 6.0]), torch.tensor([4.0, 10.0, 18.0])), + (torch.ones(3, 3), torch.ones(3, 3), torch.ones(3, 3)), # 1 * 1 = 1 + (torch.zeros(2, 2), torch.ones(2, 2), torch.zeros(2, 2)), # 0 * 1 = 0 + (torch.tensor([[2.0], [3.0]]), torch.tensor([[3.0], [4.0]]), torch.tensor([[6.0], [12.0]])), # Element-wise multiplication + ] + + def test_multiplication(self): + """Test tensor multiplication.""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected product + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_ne_test.py b/tests/pytorch_wrapper/pt_ne_test.py new file mode 100644 index 0000000..4816b21 --- /dev/null +++ b/tests/pytorch_wrapper/pt_ne_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_ne import PtNe # Updated import to PtNe + + +class TestPtNe(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtNe() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([1, 2, 3]), torch.tensor([1, 2, 3]), torch.tensor([False, False, False])), + (torch.tensor([1, 2, 3]), torch.tensor([3, 2, 1]), torch.tensor([True, False, True])), + (torch.ones(3, 3), torch.ones(3, 3), torch.full((3, 3), False, dtype=torch.bool)), + (torch.zeros(2, 2), torch.ones(2, 2), torch.full((2, 2), True, dtype=torch.bool)), + (torch.tensor([[1], [2]]), torch.tensor([[1], [3]]), torch.tensor([[False], [True]])), + ] + + def test_inequality(self): + """Test tensor element-wise inequality using torch.ne().""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected element-wise inequality + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_neg_test.py b/tests/pytorch_wrapper/pt_neg_test.py new file mode 100644 index 0000000..57c66e1 --- /dev/null +++ b/tests/pytorch_wrapper/pt_neg_test.py @@ -0,0 +1,40 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_neg import PtNeg # Updated import to PtNeg + + +class TestPtNeg(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtNeg() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([1, -2, 3]), torch.tensor([-1, 2, -3])), + (torch.tensor([0, 5, -7]), torch.tensor([0, -5, 7])), + (torch.ones(3, 3), torch.full((3, 3), -1.0)), # Negation of ones + (torch.zeros(2, 2), torch.zeros(2, 2)), # Negation of zeros + (torch.tensor([[5], [-10]]), torch.tensor([[-5], [10]])), # Column vector case + ] + + def test_neg(self): + """Test tensor element-wise negation using torch.neg().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected negation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_pow_test.py b/tests/pytorch_wrapper/pt_pow_test.py new file mode 100644 index 0000000..b6bde5f --- /dev/null +++ b/tests/pytorch_wrapper/pt_pow_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_pow import PtPow + + +class TestPtPow(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtPow() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([2.0, 3.0, 4.0]), torch.tensor([3.0, 2.0, 1.0]), torch.tensor([8.0, 9.0, 4.0])), # 2^3, 3^2, 4^1 + (torch.ones(3, 3) * 4, torch.ones(3, 3) * 2, torch.ones(3, 3) * 16), # 4^2 = 16 + (torch.full((2, 2), 5.0), torch.full((2, 2), 3.0), torch.full((2, 2), 125.0)), # 5^3 = 125 + (torch.tensor([[2.0], [3.0]]), torch.tensor([[4.0], [5.0]]), torch.tensor([[16.0], [243.0]])), # 2^4 = 16, 3^5 = 243 + ] + + def test_power(self): + """Test tensor exponentiation.""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected power computation + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_remainder_test.py b/tests/pytorch_wrapper/pt_remainder_test.py new file mode 100644 index 0000000..fbd17d0 --- /dev/null +++ b/tests/pytorch_wrapper/pt_remainder_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_remainder import PtRemainder + + +class TestPtRemainder(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtRemainder() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([4.0, 10.0, 18.0]), torch.tensor([3.0, 4.0, 5.0]), torch.tensor([1.0, 2.0, 3.0])), + (torch.ones(3, 3) * 7, torch.ones(3, 3) * 3, torch.ones(3, 3) * 1), # 7 % 3 = 1 + (torch.full((2, 2), 9.0), torch.full((2, 2), 2.0), torch.full((2, 2), 1.0)), # 9 % 2 = 1 + (torch.tensor([[7.0], [15.0]]), torch.tensor([[2.0], [4.0]]), torch.tensor([[1.0], [3.0]])), # Element-wise remainder + ] + + def test_remainder(self): + """Test tensor remainder computation.""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected remainder + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_sin_test.py b/tests/pytorch_wrapper/pt_sin_test.py new file mode 100644 index 0000000..25d0b3f --- /dev/null +++ b/tests/pytorch_wrapper/pt_sin_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_sin import PtSin # Updated import to PtSin + + +class TestPtSin(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtSin() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([0.0, torch.pi / 2, torch.pi], dtype=torch.float32), torch.sin(torch.tensor([0.0, torch.pi / 2, torch.pi], dtype=torch.float32))), # Edge cases + (torch.tensor([0.5, -0.5], dtype=torch.float32), torch.sin(torch.tensor([0.5, -0.5], dtype=torch.float32))), # Common values + (torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32), torch.sin(torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 0.6, dtype=torch.float32), torch.sin(torch.full((2, 2), 0.6, dtype=torch.float32))), # Constant matrix + ] + + def test_sin(self): + """Test tensor element-wise sine using torch.sin().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected sin values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_sinh_test.py b/tests/pytorch_wrapper/pt_sinh_test.py new file mode 100644 index 0000000..9e9a360 --- /dev/null +++ b/tests/pytorch_wrapper/pt_sinh_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_sinh import PtSinh # Updated import to PtSinh + + +class TestPtSinh(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtSinh() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([0.0, 1.0, -1.0], dtype=torch.float32), torch.sinh(torch.tensor([0.0, 1.0, -1.0], dtype=torch.float32))), # Edge cases + (torch.tensor([0.5, -0.5], dtype=torch.float32), torch.sinh(torch.tensor([0.5, -0.5], dtype=torch.float32))), # Common values + (torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32), torch.sinh(torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 0.6, dtype=torch.float32), torch.sinh(torch.full((2, 2), 0.6, dtype=torch.float32))), # Constant matrix + ] + + def test_sinh(self): + """Test tensor element-wise hyperbolic sine using torch.sinh().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected sinh values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_sub_test.py b/tests/pytorch_wrapper/pt_sub_test.py new file mode 100644 index 0000000..4894c0b --- /dev/null +++ b/tests/pytorch_wrapper/pt_sub_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_sub import PtSub + + +class TestPtSub(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtSub() + + # Test cases: (Tensor A, Tensor B, Expected result) + self.test_cases = [ + (torch.tensor([5.0, 7.0, 9.0]), torch.tensor([4.0, 5.0, 6.0]), torch.tensor([1.0, 2.0, 3.0])), + (torch.full((3, 3), 2.0), torch.ones(3, 3), torch.ones(3, 3)), + (torch.ones(2, 2), torch.ones(2, 2), torch.zeros(2, 2)), + (torch.tensor([[4.0], [6.0]]), torch.tensor([[3.0], [4.0]]), torch.tensor([[1.0], [2.0]])), + ] + + def test_subtraction(self): + """Test tensor subtraction.""" + for tens_a, tens_b, expected in self.test_cases: + with self.subTest(tens_a=tens_a, tens_b=tens_b): + result, = self.node.f(tens_a, tens_b) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected difference + self.assertTrue(torch.equal(result, expected), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_tan_test.py b/tests/pytorch_wrapper/pt_tan_test.py new file mode 100644 index 0000000..1346872 --- /dev/null +++ b/tests/pytorch_wrapper/pt_tan_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_tan import PtTan # Updated import to PtTan + + +class TestPtTan(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtTan() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([0.0, torch.pi / 4, -torch.pi / 4], dtype=torch.float32), torch.tan(torch.tensor([0.0, torch.pi / 4, -torch.pi / 4], dtype=torch.float32))), # Common angles + (torch.tensor([0.5, -0.5], dtype=torch.float32), torch.tan(torch.tensor([0.5, -0.5], dtype=torch.float32))), # General values + (torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32), torch.tan(torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 0.6, dtype=torch.float32), torch.tan(torch.full((2, 2), 0.6, dtype=torch.float32))), # Constant matrix + ] + + def test_tan(self): + """Test tensor element-wise tangent using torch.tan().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected tan values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/tests/pytorch_wrapper/pt_tanh_test.py b/tests/pytorch_wrapper/pt_tanh_test.py new file mode 100644 index 0000000..e2f0fc8 --- /dev/null +++ b/tests/pytorch_wrapper/pt_tanh_test.py @@ -0,0 +1,39 @@ +import os +import sys +import unittest +import torch + +PROJECT_ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..")) +MODULE_ROOT = os.path.join(PROJECT_ROOT, "modules") +sys.path.append(MODULE_ROOT) + +from pytorch_wrapper.pt_tanh import PtTanh # Updated import to PtTanh + + +class TestPtTanh(unittest.TestCase): + def setUp(self): + """Set up test instance.""" + self.node = PtTanh() + + # Test cases: (Tensor A, Expected result) + self.test_cases = [ + (torch.tensor([0.0, 1.0, -1.0], dtype=torch.float32), torch.tanh(torch.tensor([0.0, 1.0, -1.0], dtype=torch.float32))), # Common values + (torch.tensor([0.5, -0.5], dtype=torch.float32), torch.tanh(torch.tensor([0.5, -0.5], dtype=torch.float32))), # General cases + (torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32), torch.tanh(torch.tensor([[0.1, -0.3], [0.7, -0.9]], dtype=torch.float32))), # 2D case + (torch.full((2, 2), 0.6, dtype=torch.float32), torch.tanh(torch.full((2, 2), 0.6, dtype=torch.float32))), # Constant matrix + ] + + def test_tanh(self): + """Test tensor element-wise hyperbolic tangent using torch.tanh().""" + for tens_a, expected in self.test_cases: + with self.subTest(tens_a=tens_a): + result, = self.node.f(tens_a) + + # Ensure return value is a tensor + self.assertTrue(isinstance(result, torch.Tensor), "Output is not a tensor") + + # Ensure result matches expected tanh values + self.assertTrue(torch.allclose(result, expected, atol=1e-6), f"Expected {expected}, got {result}") + +if __name__ == "__main__": + unittest.main() diff --git a/web/js/ShowSeries.js b/web/js/ShowSeries.js index f8acd49..62e3162 100644 --- a/web/js/ShowSeries.js +++ b/web/js/ShowSeries.js @@ -12,7 +12,7 @@ import { ComfyWidgets } from "../../../scripts/widgets.js"; app.registerExtension({ name: "HowToSD.ShowSeries", async beforeRegisterNodeDef(nodeType, nodeData, app) { - if (nodeData.name === "PandasShowSeries") { // This needs to match NODE_CLASS_MAPPINGS in Python + if (["PtShowText", "PandasShowSeries"].includes(nodeData.name)) { // This needs to match NODE_CLASS_MAPPINGS in Python function populate(text) { if (this.widgets) { // Clear all widgets on the node