Skip to content

Commit 014ff64

Browse files
authored
Merge pull request #23 from comet-toolkit/v0.21.0
allow to not copy data (and hence save memory)
2 parents b376b4d + ee82fac commit 014ff64

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

comet_maths/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.21.2"
1+
__version__ = "0.22.3"

comet_maths/generate_sample/generate_sample.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def generate_sample(
5959
corr_x = np.array([corr_x])
6060
i = 0
6161

62-
if np.any(u_x[i] < 0):
62+
if (not comp_list) and (not u_x[i] is None) and np.any(u_x[i] < 0):
6363
raise ValueError(
6464
"comet_maths.generate_sample: u_x cannot have any negative values"
6565
)
@@ -650,7 +650,13 @@ def generate_sample_cov(
650650

651651

652652
def correlate_sample_corr(
653-
sample, corr, mean=None, std=None, dtype=None, iterate_sample=False
653+
sample,
654+
corr,
655+
mean=None,
656+
std=None,
657+
dtype=None,
658+
iterate_sample=False,
659+
maintain_sample_unmodified=False,
654660
):
655661
"""
656662
Method to correlate independent sample of input quantities using correlation matrix and Cholesky decomposition.
@@ -666,7 +672,9 @@ def correlate_sample_corr(
666672
:param dtype: dtype of the produced sample
667673
:type dtype: numpy.dtype, optional
668674
:param iterate_sample: boolean to indicate if comet_maths should iterate over the different samples when introducing correlation. (This is more time-consuming but might be necessary if the different samples have different error correlations), defaults to False.
669-
:type iterate_sample: bool
675+
:type iterate_sample: bool, optional
676+
:param maintain_sample_unmodified: boolean to indicate if the provided sample must remain unchanged (as opposed to introducing correlation). This requires a full copy of the sample, and thus doubles the memory required. Defaults to False.
677+
:type maintain_sample_unmodified: bool, optional
670678
:return: correlated sample of input quantities
671679
:rtype: array[array]
672680
"""
@@ -693,7 +701,10 @@ def correlate_sample_corr(
693701
except:
694702
L = cm.nearestPD_cholesky(corr, corr=True)
695703

696-
sample_out = copy.deepcopy(sample)
704+
if maintain_sample_unmodified:
705+
sample_out = copy.deepcopy(sample)
706+
else:
707+
sample_out = sample
697708

698709
if iterate_sample:
699710
sample_out_iter = np.empty(len(sample), dtype=object)

docs/content/random_generator.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ generate_sample_random(), generate_sample_systematic() and generate_sample_corre
5454
There is generate_sample_same() function that trivially generates a sample where u_x is zero and thus consists of repeats of the provided x array.
5555
Then, there is the generate_sample_cov() function where a covariance matrix is provided instead of the u_x and corr_x (which contain the same information).
5656

57-
A somewhat more useful function is correlate_sample_corr(). This function can be used to add correlation to a previously generated sample.
58-
This can particularly be useful when multiple MC samples where generated (e.g. for different variables, optionally each with their own internal
57+
Another useful function is correlate_sample_corr(). This function can be used to add correlation to a previously generated sample.
58+
This can particularly be useful when multiple MC samples were generated (e.g. for different variables, optionally each with their own internal
5959
correlation) and these different samples need to be correlated (e.g. because the different variables themselves are correlated).
60+
Note that by default the provided samples will be modified, though there is a keyword that allows to maintain the samples unchanged (at the cost of higher memory usage).
61+
6062
Finally, there is the generate_error_sample() function, which gives the differences between the sample generated by generate_sample() and x itself.
6163

6264
.. _pdf:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# required modules
2-
numpy
2+
numpy>=0.44.2
33
matplotlib
44
numdifftools
55
scikit-learn

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def read(filename):
3030
"scikit-learn",
3131
"numdifftools",
3232
"scipy",
33-
"punpy",
33+
"punpy>=0.44.2",
3434
"matplotlib",
3535
],
3636
extras_require={

0 commit comments

Comments
 (0)