Skip to content

Commit

Permalink
"simple" contraction of two SU(2) tensors
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendl committed Sep 26, 2024
1 parent 4fc41ef commit deec869
Show file tree
Hide file tree
Showing 10 changed files with 1,146 additions and 57 deletions.
65 changes: 65 additions & 0 deletions src/tensor/dense_tensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,70 @@ bool dense_tensor_allclose(const struct dense_tensor* restrict s, const struct d
}


//________________________________________________________________________________________________________________________
///
/// \brief Test whether a dense tensors is entrywise zero within tolerance 'tol'.
///
/// To test whether the tensor is exactly zero, set 'tol = 0.0'.
///
bool dense_tensor_is_zero(const struct dense_tensor* t, const double tol)
{
const long nelem = dense_tensor_num_elements(t);

switch (t->dtype)
{
case CT_SINGLE_REAL:
{
const float* data = t->data;
for (long i = 0; i < nelem; i++) {
if (fabsf(data[i]) > tol) {
return false;
}
}
break;
}
case CT_DOUBLE_REAL:
{
const double* data = t->data;
for (long i = 0; i < nelem; i++) {
if (fabs(data[i]) > tol) {
return false;
}
}
break;
}
case CT_SINGLE_COMPLEX:
{
const scomplex* data = t->data;
for (long i = 0; i < nelem; i++) {
if (cabsf(data[i]) > tol) {
return false;
}
}
break;
}
case CT_DOUBLE_COMPLEX:
{
const dcomplex* data = t->data;
for (long i = 0; i < nelem; i++) {
if (cabs(data[i]) > tol) {
return false;
}
}
break;
}
default:
{
// unknown data type
assert(false);
return false;
}
}

return true;
}


//________________________________________________________________________________________________________________________
///
/// \brief Test whether a dense tensors is close to the identity matrix within tolerance 'tol'.
Expand Down Expand Up @@ -2746,6 +2810,7 @@ bool dense_tensor_is_identity(const struct dense_tensor* t, const double tol)
return true;
}


//________________________________________________________________________________________________________________________
///
/// \brief Test whether a dense tensors is an isometry within tolerance 'tol'.
Expand Down
2 changes: 2 additions & 0 deletions src/tensor/dense_tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ void dense_tensor_block(const struct dense_tensor* restrict t, const long* restr

bool dense_tensor_allclose(const struct dense_tensor* restrict s, const struct dense_tensor* restrict t, const double tol);

bool dense_tensor_is_zero(const struct dense_tensor* t, const double tol);

bool dense_tensor_is_identity(const struct dense_tensor* t, const double tol);

bool dense_tensor_is_isometry(const struct dense_tensor* t, const double tol, const bool transpose);
Loading

0 comments on commit deec869

Please sign in to comment.