euler314 commited on
Commit
3fa9b3b
·
verified ·
1 Parent(s): 2cad740

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -66,7 +66,44 @@ except ImportError as e:
66
  except Exception as compile_error:
67
  print(f"Failed to compile C++ module: {compile_error}")
68
  cpp_available = False
69
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  def add_sqrt_support(expr_str):
71
  """Replace 'sqrt(' with 'sp.sqrt(' for sympy compatibility"""
72
  return expr_str.replace('sqrt(', 'sp.sqrt(')
 
66
  except Exception as compile_error:
67
  print(f"Failed to compile C++ module: {compile_error}")
68
  cpp_available = False
69
+ # Use C++ implementations if available, otherwise use Python implementations
70
+ if cpp_available:
71
+ try:
72
+ # Try to get each function, fall back to Python implementation if missing
73
+ discriminant_func = getattr(cubic_cpp, "discriminant_func", discriminant_func_py)
74
+ find_z_at_discriminant_zero = getattr(cubic_cpp, "find_z_at_discriminant_zero", find_z_at_discriminant_zero_py)
75
+ sweep_beta_and_find_z_bounds = getattr(cubic_cpp, "sweep_beta_and_find_z_bounds", sweep_beta_and_find_z_bounds_py)
76
+ compute_eigenvalue_support_boundaries = getattr(cubic_cpp, "compute_eigenvalue_support_boundaries", compute_eigenvalue_support_boundaries_py)
77
+ compute_cubic_roots = getattr(cubic_cpp, "compute_cubic_roots", compute_cubic_roots_py)
78
+ compute_high_y_curve = getattr(cubic_cpp, "compute_high_y_curve", compute_high_y_curve_py)
79
+ compute_alternate_low_expr = getattr(cubic_cpp, "compute_alternate_low_expr", compute_alternate_low_expr_py)
80
+ compute_max_k_expression = getattr(cubic_cpp, "compute_max_k_expression", compute_max_k_expression_py)
81
+ compute_min_t_expression = getattr(cubic_cpp, "compute_min_t_expression", compute_min_t_expression_py)
82
+ compute_derivatives = getattr(cubic_cpp, "compute_derivatives", compute_derivatives_py)
83
+
84
+ # Special case for lambda function
85
+ if hasattr(cubic_cpp, "generate_eigenvalue_distribution"):
86
+ generate_eigenvalue_distribution = lambda beta, y, z_a, n=1000, seed=42: cubic_cpp.generate_eigenvalue_distribution(beta, y, z_a, n, seed)
87
+ else:
88
+ generate_eigenvalue_distribution = generate_eigenvalue_distribution_py
89
+
90
+ print("Using C++ acceleration for available functions")
91
+ except Exception as e:
92
+ print(f"Error setting up C++ functions: {e}")
93
+ # Fall back to all Python implementations
94
+ cpp_available = False
95
+ else:
96
+ discriminant_func = discriminant_func_py
97
+ find_z_at_discriminant_zero = find_z_at_discriminant_zero_py
98
+ sweep_beta_and_find_z_bounds = sweep_beta_and_find_z_bounds_py
99
+ compute_eigenvalue_support_boundaries = compute_eigenvalue_support_boundaries_py
100
+ compute_cubic_roots = compute_cubic_roots_py
101
+ compute_high_y_curve = compute_high_y_curve_py
102
+ compute_alternate_low_expr = compute_alternate_low_expr_py
103
+ compute_max_k_expression = compute_max_k_expression_py
104
+ compute_min_t_expression = compute_min_t_expression_py
105
+ compute_derivatives = compute_derivatives_py
106
+ generate_eigenvalue_distribution = generate_eigenvalue_distribution_py
107
  def add_sqrt_support(expr_str):
108
  """Replace 'sqrt(' with 'sp.sqrt(' for sympy compatibility"""
109
  return expr_str.replace('sqrt(', 'sp.sqrt(')