Block2x2 ======== .. cpp:class:: numpy::Block2x2 numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use Block2x2 Block2x2 obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``Block2x2(size_tr, size_tc, Ta11_val, Ta12_val, Ta21_val, Ta22_val)`` - NP_LINALG.H:3333 - * - ``Block2x2(const NDArray&matrix, size_tr, size_tc)`` - NP_LINALG.H:3337 - Linear Algebra -------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``T determinant()`` - T - NP_LINALG.H:3399 - * - ``std::pair,std::complex> eigenvalues()`` - std::pair,std::complex> - NP_LINALG.H:3366 - * - ``T norm()`` - T - NP_LINALG.H:3402 - :ref:`View ` * - ``T trace()`` - T - NP_LINALG.H:3396 - :ref:`View ` Type Checking ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool is_complex_pair()`` - bool - NP_LINALG.H:3361 - Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void standardize()`` - void - NP_LINALG.H:3345 - * - ``void write_to_matrix(NDArray&matrix)`` - void - NP_LINALG.H:3388 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-block2x2-norm-0: .. dropdown:: norm (np_test_1_all.cpp:7964) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7954 :emphasize-lines: 11 void testComplex256FunctionsComplex256() { std::cout << "========= testComplex256FunctionsComplex256 ======================="; complex256 z(3.0L, 4.0L); // 3 + 4i // std::cout << "z = " << z << std::endl; // std::cout << "real(z) = " << z.real() << std::endl; // std::cout << "imag(z) = " << z.imag() << std::endl; // std::cout << "abs(z) = " << std::abs(z) << std::endl; // std::cout << "arg(z) = " << std::arg(z) << " radians" << std::endl; // std::cout << "norm(z) = " << std::norm(z) << std::endl; // std::cout << "conj(z) = " << std::conj(z) << std::endl; // Polar form auto magnitude = std::abs(z); auto phase = std::arg(z); auto polar_z = std::polar(magnitude, phase); // std::cout << "polar form: " << polar_z << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-block2x2-trace-1: .. dropdown:: trace (np_test_2_all.cpp:4981) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4971 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); assert_test(std::abs(inv(0, 1) - 1.0) < 1e-10, "Matrix inverse 0,1");