{"instance_id": "sympy__sympy-14976", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/printing/pycode.py b/sympy/printing/pycode.py\nindex d06901425d..6d0a8b5b06 100644\n--- a/sympy/printing/pycode.py\n+++ b/sympy/printing/pycode.py\n@@ -331,6 +331,11 @@ def _print_Float(self, e):\n         args = str(tuple(map(int, e._mpf_)))\n         return '{func}({args})'.format(func=self._module_format('mpmath.mpf'), args=args)\n \n+    def _print_Rational(self, e):\n+        return '{0}({1})/{0}({2})'.format(\n+            self._module_format('mpmath.mpf'),\n+            e.p,\n+            e.q)\n \n     def _print_uppergamma(self, e):\n         return \"{0}({1}, {2}, {3})\".format(\n", "model": "claude-sonnet-5-5", "steps": 4, "finished": true, "patch_lines": 16, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 16, "steps": 4}], "ms": 10727}
{"instance_id": "sympy__sympy-15017", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/tensor/array/dense_ndim_array.py b/sympy/tensor/array/dense_ndim_array.py\nindex 9be94a8631..9790712755 100644\n--- a/sympy/tensor/array/dense_ndim_array.py\n+++ b/sympy/tensor/array/dense_ndim_array.py\n@@ -149,7 +149,7 @@ def _new(cls, iterable, shape, **kwargs):\n         self._shape = shape\n         self._array = list(flat_list)\n         self._rank = len(shape)\n-        self._loop_size = functools.reduce(lambda x,y: x*y, shape) if shape else 0\n+        self._loop_size = functools.reduce(lambda x,y: x*y, shape) if shape else 1\n         return self\n \n     def __setitem__(self, index, value):\n@@ -174,7 +174,7 @@ def _new(cls, iterable, shape, **kwargs):\n         self._shape = shape\n         self._array = list(flat_list)\n         self._rank = len(shape)\n-        self._loop_size = functools.reduce(lambda x,y: x*y, shape) if shape else 0\n+        self._loop_size = functools.reduce(lambda x,y: x*y, shape) if shape else 1\n         return self\n \n     def __setitem__(self, index, value):\ndiff --git a/sympy/tensor/array/sparse_ndim_array.py b/sympy/tensor/array/sparse_ndim_array.py\nindex 72b5d51299..0cf329a012 100644\n--- a/sympy/tensor/array/sparse_ndim_array.py\n+++ b/sympy/tensor/array/sparse_ndim_array.py\n@@ -130,7 +130,7 @@ def __new__(cls, iterable=None, shape=None, **kwargs):\n \n         shape, flat_list = cls._handle_ndarray_creation_inputs(iterable, shape, **kwargs)\n         shape = Tuple(*map(_sympify, shape))\n-        loop_size = functools.reduce(lambda x,y: x*y, shape) if shape else 0\n+        loop_size = functools.reduce(lambda x,y: x*y, shape) if shape else 1\n \n         # Sparse array:\n         if isinstance(flat_list, (dict, Dict)):\n@@ -167,7 +167,7 @@ def __new__(cls, iterable=None, shape=None, **kwargs):\n         self = object.__new__(cls)\n         self._shape = shape\n         self._rank = len(shape)\n-        self._loop_size = functools.reduce(lambda x,y: x*y, shape) if shape else 0\n+        self._loop_size = functools.reduce(lambda x,y: x*y, shape) if shape else 1\n \n         # Sparse array:\n         if isinstance(flat_list, (dict, Dict)):\n", "model": "claude-sonnet-5-5", "steps": 12, "finished": true, "patch_lines": 44, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 2, "diff_lines": 44, "steps": 12}], "ms": 26394}
{"instance_id": "sympy__sympy-15345", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sympy/printing/mathematica.py b/sympy/printing/mathematica.py\nindex ea7e3a2d94..5f248c3aad 100644\n--- a/sympy/printing/mathematica.py\n+++ b/sympy/printing/mathematica.py\n@@ -101,6 +101,12 @@ def _print_Function(self, expr):\n                     return \"%s[%s]\" % (mfunc, self.stringify(expr.args, \", \"))\n         return expr.func.__name__ + \"[%s]\" % self.stringify(expr.args, \", \")\n \n+    def _print_Max(self, expr):\n+        return \"Max[%s]\" % self.stringify(expr.args, \", \")\n+\n+    def _print_Min(self, expr):\n+        return \"Min[%s]\" % self.stringify(expr.args, \", \")\n+\n     def _print_Integral(self, expr):\n         if len(expr.variables) == 1 and not expr.limits[0][1:]:\n             args = [expr.args[0], expr.variables[0]]\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 17, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 17, "steps": 6}], "ms": 15416}
{"instance_id": "scikit-learn__scikit-learn-12585", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/base.py b/sklearn/base.py\nindex 56ffb18bf8..fb42081295 100644\n--- a/sklearn/base.py\n+++ b/sklearn/base.py\n@@ -48,7 +48,7 @@ def clone(estimator, safe=True):\n     # XXX: not handling dictionaries\n     if estimator_type in (list, tuple, set, frozenset):\n         return estimator_type([clone(e, safe=safe) for e in estimator])\n-    elif not hasattr(estimator, 'get_params'):\n+    elif not hasattr(estimator, 'get_params') or isinstance(estimator, type):\n         if not safe:\n             return copy.deepcopy(estimator)\n         else:\n@@ -180,7 +180,8 @@ class BaseEstimator(object):\n         out = dict()\n         for key in self._get_param_names():\n             value = getattr(self, key, None)\n-            if deep and hasattr(value, 'get_params'):\n+            if deep and hasattr(value, 'get_params') and not isinstance(\n+                    value, type):\n                 deep_items = value.get_params().items()\n                 out.update((key + '__' + k, val) for k, val in deep_items)\n             out[key] = value\n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 23, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 23, "steps": 9}], "ms": 24809}
{"instance_id": "scikit-learn__scikit-learn-12682", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/decomposition/dict_learning.py b/sklearn/decomposition/dict_learning.py\nindex a318c957fe..aa67531329 100644\n--- a/sklearn/decomposition/dict_learning.py\n+++ b/sklearn/decomposition/dict_learning.py\n@@ -865,8 +865,10 @@ class SparseCodingMixin(TransformerMixin):\n                                   transform_algorithm='omp',\n                                   transform_n_nonzero_coefs=None,\n                                   transform_alpha=None, split_sign=False,\n-                                  n_jobs=None, positive_code=False):\n+                                  n_jobs=None, positive_code=False,\n+                                  transform_max_iter=1000):\n         self.n_components = n_components\n+        self.transform_max_iter = transform_max_iter\n         self.transform_algorithm = transform_algorithm\n         self.transform_n_nonzero_coefs = transform_n_nonzero_coefs\n         self.transform_alpha = transform_alpha\n@@ -899,8 +901,8 @@ class SparseCodingMixin(TransformerMixin):\n         code = sparse_encode(\n             X, self.components_, algorithm=self.transform_algorithm,\n             n_nonzero_coefs=self.transform_n_nonzero_coefs,\n-            alpha=self.transform_alpha, n_jobs=self.n_jobs,\n-            positive=self.positive_code)\n+            alpha=self.transform_alpha, max_iter=self.transform_max_iter,\n+            n_jobs=self.n_jobs, positive=self.positive_code)\n \n         if self.split_sign:\n             # feature vector is split into a positive and negative side\n@@ -974,6 +976,11 @@ class SparseCoder(BaseEstimator, SparseCodingMixin):\n \n         .. versionadded:: 0.20\n \n+    transform_max_iter : int, optional (default=1000)\n+        Maximum number of iterations to perform if `algorithm='lasso_cd'`.\n+\n+        .. versionadded:: 0.22\n+\n     Attributes\n     ----------\n     components_ : array, [n_components, n_features]\n@@ -991,12 +998,13 @@ class SparseCoder(BaseEstimator, SparseCodingMixin):\n \n     def __init__(self, dictionary, transform_algorithm='omp',\n                  transform_n_nonzero_coefs=None, transform_alpha=None,\n-                 split_sign=False, n_jobs=None, positive_code=False):\n+                 split_sign=False, n_jobs=None, positive_code=False,\n+                 transform_max_iter=1000):\n         self._set_sparse_coding_params(dictionary.shape[0],\n                                        transform_algorithm,\n                                        transform_n_nonzero_coefs,\n                                        transform_alpha, split_sign, n_jobs,\n-                                       positive_code)\n+                                       positive_code, transform_max_iter)\n         self.components_ = dictionary\n \n     def fit(self, X, y=None):\n@@ -1122,6 +1130,11 @@ class DictionaryLearning(BaseEstimator, SparseCodingMixin):\n \n         .. versionadded:: 0.20\n \n+    transform_max_iter : int, optional (default=1000)\n+        Maximum number of iterations to perform if `algorithm='lasso_cd'`.\n+\n+        .. versionadded:: 0.22\n+\n     Attributes\n     ----------\n     components_ : array, [n_components, n_features]\n@@ -1152,12 +1165,13 @@ class DictionaryLearning(BaseEstimator, SparseCodingMixin):\n                  transform_n_nonzero_coefs=None, transform_alpha=None,\n                  n_jobs=None, code_init=None, dict_init=None, verbose=False,\n                  split_sign=False, random_state=None,\n-                 positive_code=False, positive_dict=False):\n+                 positive_code=False, positive_dict=False,\n+                 transform_max_iter=1000):\n \n         self._set_sparse_coding_params(n_components, transform_algorithm,\n                                        transform_n_nonzero_coefs,\n                                        transform_alpha, split_sign, n_jobs,\n-                                       positive_code)\n+                                       positive_code, transform_max_iter)\n         self.alpha = alpha\n         self.max_iter = max_iter\n         self.tol = tol\n@@ -1305,6 +1319,11 @@ class MiniBatchDictionaryLearning(BaseEstimator, SparseCodingMixin):\n \n         .. versionadded:: 0.20\n \n+    transform_max_iter : int, optional (default=1000)\n+        Maximum number of iterations to perform if `algorithm='lasso_cd'`.\n+\n+        .. versionadded:: 0.22\n+\n     Attributes\n     ----------\n     components_ : array, [n_components, n_features]\n@@ -1341,12 +1360,13 @@ class MiniBatchDictionaryLearning(BaseEstimator, SparseCodingMixin):\n                  shuffle=True, dict_init=None, transform_algorithm='omp',\n                  transform_n_nonzero_coefs=None, transform_alpha=None,\n                  verbose=False, split_sign=False, random_state=None,\n-                 positive_code=False, positive_dict=False):\n+                 positive_code=False, positive_dict=False,\n+                 transform_max_iter=1000):\n \n         self._set_sparse_coding_params(n_components, transform_algorithm,\n                                        transform_n_nonzero_coefs,\n                                        transform_alpha, split_sign, n_jobs,\n-                                       positive_code)\n+                                       positive_code, transform_max_iter)\n         self.alpha = alpha\n         self.n_iter = n_iter\n         self.fit_algorithm = fit_algorithm\n", "model": "claude-sonnet-5-5", "steps": 16, "finished": true, "patch_lines": 111, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 111, "steps": 16}], "ms": 47391}
{"instance_id": "scikit-learn__scikit-learn-13124", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/model_selection/_split.py b/sklearn/model_selection/_split.py\nindex 24394f8691..077065a501 100644\n--- a/sklearn/model_selection/_split.py\n+++ b/sklearn/model_selection/_split.py\n@@ -576,8 +576,7 @@ class StratifiedKFold(_BaseKFold):\n             ``n_splits`` default value will change from 3 to 5 in v0.22.\n \n     shuffle : boolean, optional\n-        Whether to shuffle each stratification of the data before splitting\n-        into batches.\n+        Whether to shuffle each class's samples before splitting into batches.\n \n     random_state : int, RandomState instance or None, optional, default=None\n         If int, random_state is the seed used by the random number generator;\n@@ -620,7 +619,7 @@ class StratifiedKFold(_BaseKFold):\n         super().__init__(n_splits, shuffle, random_state)\n \n     def _make_test_folds(self, X, y=None):\n-        rng = self.random_state\n+        rng = check_random_state(self.random_state)\n         y = np.asarray(y)\n         type_of_target_y = type_of_target(y)\n         allowed_target_types = ('binary', 'multiclass')\n@@ -645,29 +644,23 @@ class StratifiedKFold(_BaseKFold):\n                            \" be less than n_splits=%d.\"\n                            % (min_groups, self.n_splits)), Warning)\n \n-        # pre-assign each sample to a test fold index using individual KFold\n-        # splitting strategies for each class so as to respect the balance of\n-        # classes\n-        # NOTE: Passing the data corresponding to ith class say X[y==class_i]\n-        # will break when the data is not 100% stratifiable for all classes.\n-        # So we pass np.zeroes(max(c, n_splits)) as data to the KFold\n-        per_cls_cvs = [\n-            KFold(self.n_splits, shuffle=self.shuffle,\n-                  random_state=rng).split(np.zeros(max(count, self.n_splits)))\n-            for count in y_counts]\n-\n-        test_folds = np.zeros(n_samples, dtype=np.int)\n-        for test_fold_indices, per_cls_splits in enumerate(zip(*per_cls_cvs)):\n-            for cls, (_, test_split) in zip(unique_y, per_cls_splits):\n-                cls_test_folds = test_folds[y == cls]\n-                # the test split can be too big because we used\n-                # KFold(...).split(X[:max(c, n_splits)]) when data is not 100%\n-                # stratifiable for all the classes\n-                # (we use a warning instead of raising an exception)\n-                # If this is the case, let's trim it:\n-                test_split = test_split[test_split < len(cls_test_folds)]\n-                cls_test_folds[test_split] = test_fold_indices\n-                test_folds[y == cls] = cls_test_folds\n+        # pre-assign each sample to a test fold index, respecting the balance\n+        # of classes: distributing the sorted labels round-robin over the\n+        # folds gives the number of samples of each class in each fold\n+        n_classes = len(unique_y)\n+        y_order = np.sort(y_inversed)\n+        allocation = np.asarray(\n+            [np.bincount(y_order[i::self.n_splits], minlength=n_classes)\n+             for i in range(self.n_splits)])\n+\n+        # assign samples of each class to folds in blocks, shuffling the\n+        # assignment independently for each class when shuffle=True\n+        test_folds = np.empty(n_samples, dtype='i')\n+        for k in range(n_classes):\n+            folds_for_class = np.arange(self.n_splits).repeat(allocation[:, k])\n+            if self.shuffle:\n+                rng.shuffle(folds_for_class)\n+            test_folds[y_inversed == k] = folds_for_class\n \n         return test_folds\n \n", "model": "claude-sonnet-5-5", "steps": 14, "finished": true, "patch_lines": 70, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 70, "steps": 14}], "ms": 47261}
{"instance_id": "scikit-learn__scikit-learn-13135", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/preprocessing/_discretization.py b/sklearn/preprocessing/_discretization.py\nindex dd969c12b2..35d654399d 100644\n--- a/sklearn/preprocessing/_discretization.py\n+++ b/sklearn/preprocessing/_discretization.py\n@@ -172,6 +172,8 @@ class KBinsDiscretizer(BaseEstimator, TransformerMixin):\n                 # 1D k-means procedure\n                 km = KMeans(n_clusters=n_bins[jj], init=init, n_init=1)\n                 centers = km.fit(column[:, None]).cluster_centers_[:, 0]\n+                # Must sort, centers may be unsorted even with sorted init\n+                centers.sort()\n                 bin_edges[jj] = (centers[1:] + centers[:-1]) * 0.5\n                 bin_edges[jj] = np.r_[col_min, bin_edges[jj], col_max]\n \n", "model": "claude-sonnet-5-5", "steps": 3, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 13, "steps": 3}], "ms": 8727}
{"instance_id": "scikit-learn__scikit-learn-13142", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/mixture/base.py b/sklearn/mixture/base.py\nindex bd34333c06..8920bef181 100644\n--- a/sklearn/mixture/base.py\n+++ b/sklearn/mixture/base.py\n@@ -257,11 +257,6 @@ class BaseMixture(DensityMixin, BaseEstimator, metaclass=ABCMeta):\n                 best_params = self._get_parameters()\n                 best_n_iter = n_iter\n \n-        # Always do a final e-step to guarantee that the labels returned by\n-        # fit_predict(X) are always consistent with fit(X).predict(X)\n-        # for any value of max_iter and tol (and any random_state).\n-        _, log_resp = self._e_step(X)\n-\n         if not self.converged_:\n             warnings.warn('Initialization %d did not converge. '\n                           'Try different init parameters, '\n@@ -273,6 +268,11 @@ class BaseMixture(DensityMixin, BaseEstimator, metaclass=ABCMeta):\n         self.n_iter_ = best_n_iter\n         self.lower_bound_ = max_lower_bound\n \n+        # Always do a final e-step to guarantee that the labels returned by\n+        # fit_predict(X) are always consistent with fit(X).predict(X)\n+        # for any value of max_iter and tol (and any random_state).\n+        _, log_resp = self._e_step(X)\n+\n         return log_resp.argmax(axis=1)\n \n     def _e_step(self, X):\n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 28, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 28, "steps": 9}], "ms": 19508}
{"instance_id": "scikit-learn__scikit-learn-13328", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/linear_model/huber.py b/sklearn/linear_model/huber.py\nindex 65c6864007..2859136848 100644\n--- a/sklearn/linear_model/huber.py\n+++ b/sklearn/linear_model/huber.py\n@@ -251,7 +251,8 @@ class HuberRegressor(LinearModel, RegressorMixin, BaseEstimator):\n         self : object\n         \"\"\"\n         X, y = check_X_y(\n-            X, y, copy=False, accept_sparse=['csr'], y_numeric=True)\n+            X, y, copy=False, accept_sparse=['csr'], y_numeric=True,\n+            dtype=[np.float64, np.float32])\n         if sample_weight is not None:\n             sample_weight = np.array(sample_weight)\n             check_consistent_length(y, sample_weight)\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 14, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 14, "steps": 6}], "ms": 10818}
{"instance_id": "matplotlib__matplotlib-20859", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py\nindex 44ab024698..1b8cee8250 100644\n--- a/lib/matplotlib/legend.py\n+++ b/lib/matplotlib/legend.py\n@@ -360,7 +360,7 @@ class Legend(Artist):\n         \"\"\"\n         # local import only to avoid circularity\n         from matplotlib.axes import Axes\n-        from matplotlib.figure import Figure\n+        from matplotlib.figure import FigureBase\n \n         super().__init__()\n \n@@ -434,7 +434,7 @@ class Legend(Artist):\n             self.isaxes = True\n             self.axes = parent\n             self.set_figure(parent.figure)\n-        elif isinstance(parent, Figure):\n+        elif isinstance(parent, FigureBase):\n             self.isaxes = False\n             self.set_figure(parent)\n         else:\n", "model": "claude-sonnet-5-5", "steps": 10, "finished": true, "patch_lines": 22, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 22, "steps": 10}], "ms": 26705}
