



import json
import os
import pickle
import subprocess
from hashlib import mda
from pathlib import Path
from tempfile import gettempdir
from textwrap import dedent
from types import CodeType, FunctionType
from unittest import TestCase
from unittest.mock import patch

import pytest
from multiprocess import Pool
from packaging import version

import datasets
from datasets.fingerprint import Hasher, fingerprint_transform
from datasets.table import InMemoryTable

from .utils import (
    require_regex,
    require_spacy,
    require_spacy_model,
    require_tiktoken,
    require_torch,
    require_transformers,
)
class lowerCAmelCase_       :







	'''simple docstring'''




	def __init__(	self   ,       lowerCamelCase       ):



				'''simple docstring'''


				a__					=  foo







	def __call__(	self       ):



				'''simple docstring'''


				return self.foo


class lowerCAmelCase_       (   datasets.Dataset			):







	'''simple docstring'''




	@fingerprint_transform(inplace=lowerCamelCase       )
	def 				_A			(	self   ,       lowerCamelCase   ,       *lowerCamelCase   ,       **lowerCamelCase       ):



				'''simple docstring'''


				return DatasetChild(self.data   ,       fingerprint=lowerCamelCase       )







	@fingerprint_transform(inplace=lowerCamelCase       )
	def 				_A			(	self   ,       lowerCamelCase   ,       *lowerCamelCase   ,       **lowerCamelCase       ):



				'''simple docstring'''


				return DatasetChild(self.data   ,       fingerprint=lowerCamelCase       )


class lowerCAmelCase_       :







	'''simple docstring'''




	def __init__(	self   ,       lowerCamelCase       ):



				'''simple docstring'''


				a__					=  callable

	def __call__(	self   ,       *lowerCamelCase   ,       **lowerCamelCase       ):



				'''simple docstring'''


				if self.callable is not None:
							return self.callable(*lowerCamelCase   ,       **lowerCamelCase       )







	def __getstate__(	self       ):



				'''simple docstring'''


				raise pickle.PicklingError()


class lowerCAmelCase_       (   A_			):







	'''simple docstring'''




	@require_transformers
	@pytest.mark.integration
	def 				_A			(	self       ):



				'''simple docstring'''


				from transformers import AutoTokenizer

				def encode(lowerCamelCase       ):
							return tokenizer(lowerCamelCase       )

				# TODO: add hash consistency tests across sessions
				a__					=  AutoTokenizer.from_pretrained("""bert-base-uncased"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  mda(datasets.utils.py_utils.dumps(lambda lowerCamelCase       : tokenizer(lowerCamelCase       )       )       ).hexdigest()
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  AutoTokenizer.from_pretrained("""bert-base-cased"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  mda(datasets.utils.py_utils.dumps(lambda lowerCamelCase       : tokenizer(lowerCamelCase       )       )       ).hexdigest()
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  AutoTokenizer.from_pretrained("""bert-base-uncased"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  mda(datasets.utils.py_utils.dumps(lambda lowerCamelCase       : tokenizer(lowerCamelCase       )       )       ).hexdigest()
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )

	@require_transformers
	@pytest.mark.integration
	def 				_A			(	self       ):



				'''simple docstring'''


				from transformers import AutoTokenizer

				a__					=  AutoTokenizer.from_pretrained("""gpt2"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				tokenizer("""Hello world !"""       )  # call once to change the tokenizer's cache
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )







	@require_regex
	def 				_A			(	self       ):



				'''simple docstring'''


				import regex

				a__					=  regex.Regex("""foo"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  regex.Regex("""bar"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  regex.Regex("""foo"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )


class lowerCAmelCase_       (   A_			):







	'''simple docstring'''




	def 				_A			(	self       ):



				'''simple docstring'''


				def func():
							return foo

				a__					=  [0]
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  [1]
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  [0]
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )

	def 				_A			(	self       ):



				'''simple docstring'''


				def func():
							pass

				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()

				def func():
							pass

				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  mda(datasets.utils.py_utils.dumps(Foo([0]       )       )       ).hexdigest()
				a__					=  mda(datasets.utils.py_utils.dumps(Foo([1]       )       )       ).hexdigest()
				a__					=  mda(datasets.utils.py_utils.dumps(Foo([0]       )       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  mda(datasets.utils.py_utils.dumps(Foo([0]       ).__call__       )       ).hexdigest()
				a__					=  mda(datasets.utils.py_utils.dumps(Foo([1]       ).__call__       )       ).hexdigest()
				a__					=  mda(datasets.utils.py_utils.dumps(Foo([0]       ).__call__       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  (
				    """co_argcount""",
				    """co_kwonlyargcount""",
				    """co_nlocals""",
				    """co_stacksize""",
				    """co_flags""",
				    """co_code""",
				    """co_consts""",
				    """co_names""",
				    """co_varnames""",
				    """co_filename""",
				    """co_name""",
				    """co_firstlineno""",
				    """co_lnotab""",
				    """co_freevars""",
				    """co_cellvars""",
				)

				def _create_code_pyaa(*lowerCamelCase       ):
							if hasattr(args[-3]   ,       """encode"""       ):
										a__					=  list(lowerCamelCase       )
										a__					=  args[-3].encode()  # co_lnotab
										a__					=  args[-10].encode()  # co_code
							if hasattr(lowerCamelCase   ,       """co_posonlyargcount"""       ):
										if len(lowerCamelCase       ) == 16:
													return CodeType(*lowerCamelCase       )
										elif len(lowerCamelCase       ) == 15:
													return CodeType(args[0]   ,       0   ,       *args[1:]       )
										return CodeType(args[0]   ,       0   ,       0   ,       *args[1:]       )
							elif hasattr(lowerCamelCase   ,       """co_kwonlyargcount"""       ):
										if len(lowerCamelCase       ) == 16:
													return CodeType(args[0]   ,       *args[2:]       )
										elif len(lowerCamelCase       ) == 15:
													return CodeType(*lowerCamelCase       )
										return CodeType(args[0]   ,       0   ,       *args[1:]       )
							if len(lowerCamelCase       ) == 16:
										return CodeType(args[0]   ,       *args[3:]       )
							elif len(lowerCamelCase       ) == 15:
										return CodeType(args[0]   ,       *args[2:]       )
							return CodeType(*lowerCamelCase       )

				def create_ipython_func(lowerCamelCase   ,       lowerCamelCase       ):
							def func():
										return returned_obj

							a__					=  func.__code__
							# Use _create_code from dill in order to make it work for different python versions
							if datasets.config.PY_VERSION < version.parse("""3.8"""       ):
										a__					=  _create_code_pyaa(
										    *[getattr(lowerCamelCase   ,       lowerCamelCase       ) if k != """co_filename""" else co_filename for k in code_args_pyaa]       )
							else:
										a__					=  code.replace(co_filename=lowerCamelCase       )
							return FunctionType(lowerCamelCase   ,       func.__globals__   ,       func.__name__   ,       func.__defaults__   ,       func.__closure__       )

				a__				,       a__					=  """<ipython-input-2-e0383a102aae>""", [0]
				a__					=  mda(datasets.utils.py_utils.dumps(create_ipython_func(lowerCamelCase   ,       lowerCamelCase       )       )       ).hexdigest()
				a__				,       a__					=  """<ipython-input-2-e0383a102aae>""", [1]
				a__					=  mda(datasets.utils.py_utils.dumps(create_ipython_func(lowerCamelCase   ,       lowerCamelCase       )       )       ).hexdigest()
				a__				,       a__					=  """<ipython-input-5-713f6613acf3>""", [0]
				a__					=  mda(datasets.utils.py_utils.dumps(create_ipython_func(lowerCamelCase   ,       lowerCamelCase       )       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )

				a__				,       a__					=  os.path.join(gettempdir()   ,       """ipykernel_12345"""   ,       """321456789.py"""       ), [0]
				a__					=  mda(datasets.utils.py_utils.dumps(create_ipython_func(lowerCamelCase   ,       lowerCamelCase       )       )       ).hexdigest()
				a__				,       a__					=  os.path.join(gettempdir()   ,       """ipykernel_12345"""   ,       """321456789.py"""       ), [1]
				a__					=  mda(datasets.utils.py_utils.dumps(create_ipython_func(lowerCamelCase   ,       lowerCamelCase       )       )       ).hexdigest()
				a__				,       a__					=  os.path.join(gettempdir()   ,       """ipykernel_12345"""   ,       """654123987.py"""       ), [0]
				a__					=  mda(datasets.utils.py_utils.dumps(create_ipython_func(lowerCamelCase   ,       lowerCamelCase       )       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )







	def 				_A			(	self       ):



				'''simple docstring'''


				a__				,       a__					=  [0], [1]

				def func():
							return foo, bar

				a__					=  """__main__"""

				def globalvars_mocka_side_effect(lowerCamelCase   ,       *lowerCamelCase   ,       **lowerCamelCase       ):
							return {"foo": foo, "bar": bar}

				def globalvars_mocka_side_effect(lowerCamelCase   ,       *lowerCamelCase   ,       **lowerCamelCase       ):
							return {"bar": bar, "foo": foo}

				with patch("""dill.detect.globalvars"""   ,       side_effect=lowerCamelCase       ) as globalvars_mocka:
							a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
							self.assertGreater(globalvars_mocka.call_count   ,       0       )
				with patch("""dill.detect.globalvars"""   ,       side_effect=lowerCamelCase       ) as globalvars_mocka:
							a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
							self.assertGreater(globalvars_mocka.call_count   ,       0       )
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )


class lowerCAmelCase_       (   A_			):







	'''simple docstring'''




	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  Hasher.hash("""hello"""       )
				a__					=  Hasher.hash("""hello"""       )
				a__					=  Hasher.hash("""there"""       )
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  Hasher.hash(Foo("""hello"""       )       )
				a__					=  Hasher.hash(Foo("""hello"""       )       )
				a__					=  Hasher.hash(Foo("""there"""       )       )
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  Hasher()
				for x in ["hello", Foo("""hello"""       )]:
							hasher.update(lowerCamelCase       )
				a__					=  hasher.hexdigest()
				a__					=  Hasher()
				for x in ["hello", Foo("""hello"""       )]:
							hasher.update(lowerCamelCase       )
				a__					=  hasher.hexdigest()
				a__					=  Hasher()
				for x in ["there", Foo("""there"""       )]:
							hasher.update(lowerCamelCase       )
				a__					=  hasher.hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )

	def 				_A			(	self       ):



				'''simple docstring'''


				with self.assertRaises(pickle.PicklingError       ):
							Hasher.hash(UnpicklableCallable(Foo("""hello"""       )       )       )

	def 				_A			(	self       ):



				'''simple docstring'''


				a__					=  """abc"""
				a__					=  [string, string]  # two strings have the same ids
				a__					=  [string, string]
				a__					=  json.loads(f'["{string}", "{string}"]'       )  # two strings have different ids
				self.assertIs(obja[0]   ,       lowerCamelCase       )
				self.assertIs(obja[0]   ,       obja[1]       )
				self.assertIs(obja[0]   ,       lowerCamelCase       )
				self.assertIs(obja[0]   ,       obja[1]       )
				self.assertIsNot(obja[0]   ,       lowerCamelCase       )
				self.assertIsNot(obja[0]   ,       obja[1]       )
				a__					=  Hasher.hash(lowerCamelCase       )
				a__					=  Hasher.hash(lowerCamelCase       )
				a__					=  Hasher.hash(lowerCamelCase       )
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )

	@require_tiktoken
	def 				_A			(	self       ):



				'''simple docstring'''


				import tiktoken

				a__					=  tiktoken.get_encoding("""gpt2"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  tiktoken.get_encoding("""r50k_base"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  tiktoken.get_encoding("""gpt2"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )

	@require_torch
	def 				_A			(	self       ):



				'''simple docstring'''


				import torch

				a__					=  torch.tensor([1.0]       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  torch.tensor([2.0]       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  torch.tensor([1.0]       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )







	@require_spacy
	@require_spacy_model("""en_core_web_sm"""       )
	@require_spacy_model("""fr_core_news_sm"""       )
	@pytest.mark.integration
	def 				_A			(	self       ):



				'''simple docstring'''


				import spacy

				a__					=  spacy.load("""en_core_web_sm"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  spacy.load("""fr_core_news_sm"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				a__					=  spacy.load("""en_core_web_sm"""       )
				a__					=  mda(datasets.utils.py_utils.dumps(lowerCamelCase       )       ).hexdigest()
				self.assertEqual(lowerCamelCase   ,       lowerCamelCase       )
				self.assertNotEqual(lowerCamelCase   ,       lowerCamelCase       )




@pytest.mark.integration
def    UpperCAmelCase					(  lowercase__						:					Path	):



			'''simple docstring'''





			a__					=  tmp_path / """dir1"""
			a__					=  tmp_path / """dir2"""
			dira.mkdir()
			dira.mkdir()
			a__					=  """script.py"""
			a__					=  dedent(
			    """
    from datasets.fingerprint import Hasher
    def foo():
        pass
    print(Hasher.hash(foo))
    """	)
			a__					=  dira / script_filename
			a__					=  dira / script_filename
			with script_patha.open("""w"""	) as f:
						f.write(lowercase__	)
			with script_patha.open("""w"""	) as f:
						f.write(lowercase__	)
			a__					=  subprocess.check_output(["""python""", str(lowercase__	)]	)
			a__					=  subprocess.check_output(["""python""", str(lowercase__	)]	)
			assert fingerprinta == fingerprinta




def    UpperCAmelCase					(  ):



			'''simple docstring'''





			a__					=  {"""a""": [0, 1, 2]}
			a__					=  DatasetChild(InMemoryTable.from_pydict(lowercase__	)	)
			a__					=  dataset.funca()._fingerprint
			assert expected_fingerprint == dataset.funca()._fingerprint
			assert expected_fingerprint != dataset.funca()._fingerprint

			with Pool(2	) as p:
						assert expected_fingerprint == p.apply_async(dataset.funca	).get()._fingerprint
						assert expected_fingerprint != p.apply_async(dataset.funca	).get()._fingerprint




def    UpperCAmelCase					(  ):



			'''simple docstring'''





			a__					=  {"""a""": [0, 1, 2]}
			class lowerCAmelCase_       (   datasets.Dataset			):







				'''simple docstring'''




				@fingerprint_transform(inplace=lowerCamelCase       )
				def 				_A			(	self   ,       lowerCamelCase       ):



							'''simple docstring'''


							return DummyDatasetChild(self.data   ,       fingerprint=lowerCamelCase       )


			a__					=  DummyDatasetChild(InMemoryTable.from_pydict(lowercase__	)	).func()
			class lowerCAmelCase_       (   datasets.Dataset			):







				'''simple docstring'''




				@fingerprint_transform(inplace=lowerCamelCase   ,       version="""1.0.0"""       )
				def 				_A			(	self   ,       lowerCamelCase       ):



							'''simple docstring'''


							return DummyDatasetChild(self.data   ,       fingerprint=lowerCamelCase       )


			a__					=  DummyDatasetChild(InMemoryTable.from_pydict(lowercase__	)	).func()
			class lowerCAmelCase_       (   datasets.Dataset			):







				'''simple docstring'''




				@fingerprint_transform(inplace=lowerCamelCase   ,       version="""2.0.0"""       )
				def 				_A			(	self   ,       lowerCamelCase       ):



							'''simple docstring'''


							return DummyDatasetChild(self.data   ,       fingerprint=lowerCamelCase       )


			a__					=  DummyDatasetChild(InMemoryTable.from_pydict(lowercase__	)	).func()

			assert len({fingeprint_no_version, fingeprint_a, fingeprint_a}	) == 3





def    UpperCAmelCase					(  ):



			'''simple docstring'''





			a__					=  Hasher()
			hasher.update(lambda lowercase__	: x	)






from typing import Any

import numpy as np




def    UpperCAmelCase					(  lowercase__						:					np.ndarray	):



			'''simple docstring'''





			assert np.shape(lowercase__	)[0] == np.shape(lowercase__	)[1]

			# If matrix not symmetric, exit right away.
			if np.allclose(lowercase__				,					matrix.T	) is False:
						return False

			# Get eigenvalues and eignevectors for a symmetric matrix.
			a__				,       a__					=  np.linalg.eigh(lowercase__	)

			# Check sign of all eigenvalues.
			# np.all returns a value of type np.bool_
			return bool(np.all(eigen_values > 0	)	)




def    UpperCAmelCase					(  lowercase__						:					int	):



			'''simple docstring'''





			a__					=  np.random.randn(lowercase__				,					lowercase__	)
			a__					=  np.dot(lowercase__				,					random_matrix.T	)
			assert _is_matrix_spd(lowercase__	)
			return spd_matrix




def    UpperCAmelCase					(  lowercase__						:					np.ndarray				,					lowercase__						:					np.ndarray				,					lowercase__						:					int = 1000				,					lowercase__						:					float = 1e-8				,					):



			'''simple docstring'''





			assert np.shape(lowercase__	)[0] == np.shape(lowercase__	)[1]
			assert np.shape(lowercase__	)[0] == np.shape(lowercase__	)[0]
			assert _is_matrix_spd(lowercase__	)

			# Initialize solution guess, residual, search direction.
			a__					=  np.zeros((np.shape(lowercase__	)[0], 1)	)
			a__					=  np.copy(lowercase__	)
			a__					=  np.copy(lowercase__	)

			# Set initial errors in solution guess and residual.
			a__					=  1e9
			a__					=  1e9
			a__					=  1e9

			# Set iteration counter to threshold number of iterations.
			a__					=  0

			while error > tol:
						# Save this value so we only calculate the matrix-vector product once.
						a__					=  np.dot(lowercase__				,					lowercase__	)

						# The main algorithm.

						# Update search direction magnitude.
						a__					=  np.dot(ra.T				,					lowercase__	) / np.dot(pa.T				,					lowercase__	)
						# Update solution guess.
						a__					=  xa + alpha * pa
						# Calculate new residual.
						a__					=  ra - alpha * w
						# Calculate new Krylov subspace scale.
						a__					=  np.dot(r.T				,					lowercase__	) / np.dot(ra.T				,					lowercase__	)
						# Calculate new A conjuage search direction.
						a__					=  r + beta * pa

						# Calculate errors.
						a__					=  np.linalg.norm(r - ra	)
						a__					=  np.linalg.norm(x - xa	)
						a__					=  np.maximum(lowercase__				,					lowercase__	)

						# Update variables.
						a__					=  np.copy(lowercase__	)
						a__					=  np.copy(lowercase__	)
						a__					=  np.copy(lowercase__	)

						# Update number of iterations.
						iterations += 1
						if iterations > max_iterations:
									break

			return x




def    UpperCAmelCase					(  ):



			'''simple docstring'''





			a__					=  3
			a__					=  _create_spd_matrix(lowercase__	)
			a__					=  np.random.randn(lowercase__				,					1	)
			a__					=  np.dot(lowercase__				,					lowercase__	)

			# Numpy solution.
			a__					=  np.linalg.solve(lowercase__				,					lowercase__	)

			# Our implementation.
			a__					=  conjugate_gradient(lowercase__				,					lowercase__	)

			# Ensure both solutions are close to x_true (and therefore one another).
			assert np.linalg.norm(x_numpy - x_true	) <= 1e-6
			assert np.linalg.norm(x_conjugate_gradient - x_true	) <= 1e-6


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	test_conjugate_gradient()

