Block2x2#
-
class numpy::Block2x2#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use Block2x2
Block2x2 obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_LINALG.H:3333 |
|
|
NP_LINALG.H:3337 |
Linear Algebra#
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
NP_LINALG.H:3361 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_LINALG.H:3345 |
|
|
void |
NP_LINALG.H:3388 |
Code Examples#
The following examples are extracted from the test suite.
norm (np_test_1_all.cpp:7964)
7954void testComplex256FunctionsComplex256() {
7955 std::cout << "========= testComplex256FunctionsComplex256 =======================";
7956
7957 complex256 z(3.0L, 4.0L); // 3 + 4i
7958
7959 // std::cout << "z = " << z << std::endl;
7960 // std::cout << "real(z) = " << z.real() << std::endl;
7961 // std::cout << "imag(z) = " << z.imag() << std::endl;
7962 // std::cout << "abs(z) = " << std::abs(z) << std::endl;
7963 // std::cout << "arg(z) = " << std::arg(z) << " radians" << std::endl;
7964 // std::cout << "norm(z) = " << std::norm(z) << std::endl;
7965 // std::cout << "conj(z) = " << std::conj(z) << std::endl;
7966
7967 // Polar form
7968 auto magnitude = std::abs(z);
7969 auto phase = std::arg(z);
7970 auto polar_z = std::polar(magnitude, phase);
7971 // std::cout << "polar form: " << polar_z << std::endl;
7972
7973 std::cout << " -> tests passed" << std::endl;
7974}
trace (np_test_2_all.cpp:4981)
4971 // Test transpose
4972 numpy::Matrix<double> m("1 2 3; 4 5 6");
4973 auto mt = m.transpose();
4974 assert_test(mt.rows() == 3, "Transpose rows");
4975 assert_test(mt.cols() == 2, "Transpose cols");
4976 assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element");
4977 assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element");
4978
4979 // Test trace for square matrix
4980 numpy::Matrix<double> square("1 2; 3 4");
4981 double tr = square.trace();
4982 assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace");
4983
4984 // Test determinant for 2x2 matrix
4985 double det = square.det();
4986 assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2");
4987
4988 // Test matrix inverse for 2x2
4989 auto inv = square.inv();
4990 assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0");
4991 assert_test(std::abs(inv(0, 1) - 1.0) < 1e-10, "Matrix inverse 0,1");