Spaces:
Running
Running
Update cubic_cpp.cpp
Browse files- cubic_cpp.cpp +37 -35
cubic_cpp.cpp
CHANGED
@@ -363,41 +363,7 @@ std::tuple<double, double> compute_eigenvalues_for_beta(double z_a, double y, do
|
|
363 |
// Return min and max
|
364 |
return std::make_tuple(eigenvalues.front(), eigenvalues.back());
|
365 |
}
|
366 |
-
|
367 |
-
std::tuple<std::vector<double>, std::vector<double>>
|
368 |
-
compute_derivatives(const std::vector<double>& curve, const std::vector<double>& betas) {
|
369 |
-
size_t n = curve.size();
|
370 |
-
std::vector<double> d1(n, 0.0);
|
371 |
-
std::vector<double> d2(n, 0.0);
|
372 |
-
|
373 |
-
if (n < 2 || n != betas.size()) {
|
374 |
-
return std::make_tuple(d1, d2); // Return zeros if invalid input
|
375 |
-
}
|
376 |
-
|
377 |
-
// First derivative using central differences
|
378 |
-
for (size_t i = 1; i < n-1; i++) {
|
379 |
-
d1[i] = (curve[i+1] - curve[i-1]) / (betas[i+1] - betas[i-1]);
|
380 |
-
}
|
381 |
-
|
382 |
-
// Edge cases using forward/backward differences
|
383 |
-
if (n > 1) {
|
384 |
-
d1[0] = (curve[1] - curve[0]) / (betas[1] - betas[0]);
|
385 |
-
d1[n-1] = (curve[n-1] - curve[n-2]) / (betas[n-1] - betas[n-2]);
|
386 |
-
}
|
387 |
-
|
388 |
-
// Second derivative using the same method applied to first derivative
|
389 |
-
for (size_t i = 1; i < n-1; i++) {
|
390 |
-
d2[i] = (d1[i+1] - d1[i-1]) / (betas[i+1] - betas[i-1]);
|
391 |
-
}
|
392 |
-
|
393 |
-
// Edge cases for second derivative
|
394 |
-
if (n > 1) {
|
395 |
-
d2[0] = (d1[1] - d1[0]) / (betas[1] - betas[0]);
|
396 |
-
d2[n-1] = (d1[n-1] - d1[n-2]) / (betas[n-1] - betas[n-2]);
|
397 |
-
}
|
398 |
-
|
399 |
-
return std::make_tuple(d1, d2);
|
400 |
-
}
|
401 |
// Fast computation of eigenvalue support boundaries
|
402 |
std::tuple<std::vector<double>, std::vector<double>, std::vector<double>, std::vector<double>>
|
403 |
compute_eigenvalue_support_boundaries(double z_a, double y, const std::vector<double>& beta_values,
|
@@ -680,6 +646,42 @@ std::vector<double> generate_eigenvalue_distribution(double beta, double y, doub
|
|
680 |
return eigenvalues;
|
681 |
}
|
682 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
683 |
// Python module definition
|
684 |
PYBIND11_MODULE(cubic_cpp, m) {
|
685 |
m.doc() = "C++ accelerated functions for cubic root analysis";
|
|
|
363 |
// Return min and max
|
364 |
return std::make_tuple(eigenvalues.front(), eigenvalues.back());
|
365 |
}
|
366 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
// Fast computation of eigenvalue support boundaries
|
368 |
std::tuple<std::vector<double>, std::vector<double>, std::vector<double>, std::vector<double>>
|
369 |
compute_eigenvalue_support_boundaries(double z_a, double y, const std::vector<double>& beta_values,
|
|
|
646 |
return eigenvalues;
|
647 |
}
|
648 |
|
649 |
+
// ADD THE MISSING COMPUTE_DERIVATIVES FUNCTION
|
650 |
+
std::tuple<std::vector<double>, std::vector<double>>
|
651 |
+
compute_derivatives(const std::vector<double>& curve, const std::vector<double>& betas) {
|
652 |
+
size_t n = curve.size();
|
653 |
+
std::vector<double> d1(n, 0.0);
|
654 |
+
std::vector<double> d2(n, 0.0);
|
655 |
+
|
656 |
+
if (n < 2 || n != betas.size()) {
|
657 |
+
return std::make_tuple(d1, d2); // Return zeros if invalid input
|
658 |
+
}
|
659 |
+
|
660 |
+
// First derivative using central differences
|
661 |
+
for (size_t i = 1; i < n-1; i++) {
|
662 |
+
d1[i] = (curve[i+1] - curve[i-1]) / (betas[i+1] - betas[i-1]);
|
663 |
+
}
|
664 |
+
|
665 |
+
// Edge cases using forward/backward differences
|
666 |
+
if (n > 1) {
|
667 |
+
d1[0] = (curve[1] - curve[0]) / (betas[1] - betas[0]);
|
668 |
+
d1[n-1] = (curve[n-1] - curve[n-2]) / (betas[n-1] - betas[n-2]);
|
669 |
+
}
|
670 |
+
|
671 |
+
// Second derivative using the same method applied to first derivative
|
672 |
+
for (size_t i = 1; i < n-1; i++) {
|
673 |
+
d2[i] = (d1[i+1] - d1[i-1]) / (betas[i+1] - betas[i-1]);
|
674 |
+
}
|
675 |
+
|
676 |
+
// Edge cases for second derivative
|
677 |
+
if (n > 1) {
|
678 |
+
d2[0] = (d1[1] - d1[0]) / (betas[1] - betas[0]);
|
679 |
+
d2[n-1] = (d1[n-1] - d1[n-2]) / (betas[n-1] - betas[n-2]);
|
680 |
+
}
|
681 |
+
|
682 |
+
return std::make_tuple(d1, d2);
|
683 |
+
}
|
684 |
+
|
685 |
// Python module definition
|
686 |
PYBIND11_MODULE(cubic_cpp, m) {
|
687 |
m.doc() = "C++ accelerated functions for cubic root analysis";
|