@@ -601,3 +601,98 @@ TEST_F(OpDivScalarOutTest, OptimizedSanityCheck) {
601601 // Check that it matches the expected output.
602602 EXPECT_TENSOR_CLOSE (out, tf.make (sizes, {0.65 , 1.05 , 2.3 , 4.1 }));
603603}
604+
605+ //
606+ // Complex Type Tests
607+ //
608+
609+ TEST_F (OpDivOutTest, ComplexFloatBasic) {
610+ TensorFactory<ScalarType::ComplexFloat> tf;
611+
612+ const std::vector<int32_t > sizes = {2 , 2 };
613+
614+ // (1+2i) / (1+0i) = (1+2i)
615+ // (4+4i) / (2+0i) = (2+2i)
616+ // (3+4i) / (1-1i) = (3+4i)(1+1i) / 2 = (-1+7i) / 2 = (-0.5+3.5i)
617+ // (8+0i) / (2+2i) = (8)(2-2i) / 8 = (2-2i)
618+ Tensor a = tf.make (
619+ sizes,
620+ {executorch::aten::complex <float >(1 .0f , 2 .0f ),
621+ executorch::aten::complex <float >(4 .0f , 4 .0f ),
622+ executorch::aten::complex <float >(3 .0f , 4 .0f ),
623+ executorch::aten::complex <float >(8 .0f , 0 .0f )});
624+
625+ Tensor b = tf.make (
626+ sizes,
627+ {executorch::aten::complex <float >(1 .0f , 0 .0f ),
628+ executorch::aten::complex <float >(2 .0f , 0 .0f ),
629+ executorch::aten::complex <float >(1 .0f , -1 .0f ),
630+ executorch::aten::complex <float >(2 .0f , 2 .0f )});
631+
632+ Tensor out = tf.zeros (sizes);
633+
634+ op_div_out (a, b, out);
635+
636+ Tensor expected = tf.make (
637+ sizes,
638+ {executorch::aten::complex <float >(1 .0f , 2 .0f ),
639+ executorch::aten::complex <float >(2 .0f , 2 .0f ),
640+ executorch::aten::complex <float >(-0 .5f , 3 .5f ),
641+ executorch::aten::complex <float >(2 .0f , -2 .0f )});
642+
643+ EXPECT_TENSOR_CLOSE (out, expected);
644+ }
645+
646+ TEST_F (OpDivOutTest, ComplexDoubleBasic) {
647+ TensorFactory<ScalarType::ComplexDouble> tf;
648+
649+ const std::vector<int32_t > sizes = {2 };
650+
651+ Tensor a = tf.make (
652+ sizes,
653+ {executorch::aten::complex <double >(6.0 , 8.0 ),
654+ executorch::aten::complex <double >(4.0 , 0.0 )});
655+
656+ Tensor b = tf.make (
657+ sizes,
658+ {executorch::aten::complex <double >(2.0 , 0.0 ),
659+ executorch::aten::complex <double >(0.0 , 2.0 )});
660+
661+ Tensor out = tf.zeros (sizes);
662+
663+ op_div_out (a, b, out);
664+
665+ // (6+8i) / 2 = (3+4i)
666+ // 4 / 2i = 4 * (-i) / 2 = -2i = (0-2i)
667+ Tensor expected = tf.make (
668+ sizes,
669+ {executorch::aten::complex <double >(3.0 , 4.0 ),
670+ executorch::aten::complex <double >(0.0 , -2.0 )});
671+
672+ EXPECT_TENSOR_CLOSE (out, expected);
673+ }
674+
675+ TEST_F (OpDivOutTest, ComplexFloatIdentity) {
676+ TensorFactory<ScalarType::ComplexFloat> tf;
677+
678+ const std::vector<int32_t > sizes = {3 };
679+
680+ // Dividing by 1 should return the same value
681+ Tensor a = tf.make (
682+ sizes,
683+ {executorch::aten::complex <float >(1 .0f , 2 .0f ),
684+ executorch::aten::complex <float >(3 .0f , 4 .0f ),
685+ executorch::aten::complex <float >(-5 .0f , 6 .0f )});
686+
687+ Tensor one = tf.make (
688+ sizes,
689+ {executorch::aten::complex <float >(1 .0f , 0 .0f ),
690+ executorch::aten::complex <float >(1 .0f , 0 .0f ),
691+ executorch::aten::complex <float >(1 .0f , 0 .0f )});
692+
693+ Tensor out = tf.zeros (sizes);
694+
695+ op_div_out (a, one, out);
696+
697+ EXPECT_TENSOR_CLOSE (out, a);
698+ }
0 commit comments