From ec6c508bf4fd8a473a9c1913a3e25a160cbae4fe Mon Sep 17 00:00:00 2001 From: blind1 Date: Fri, 13 Sep 2019 15:59:18 +0200 Subject: [PATCH 01/40] BROKEN. First implementation of modf --- heat/core/rounding.py | 63 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/heat/core/rounding.py b/heat/core/rounding.py index 1349448086..a0419a4918 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -1,4 +1,5 @@ import torch +import heat as ht from . import operations from . import dndarray @@ -11,7 +12,8 @@ 'clip', 'fabs', 'floor', - 'trunc' + 'trunc', + 'round' ] @@ -212,3 +214,62 @@ def trunc(x, out=None): tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]) """ return operations.__local_op(torch.trunc, x, out) + + + +def modf(a): + """ + Return the fractional and integral parts of an array, element-wise. + The fractional and integral parts are negative if the given number is negative. + + Parameters + ---------- + x : ht.DNDarray + Input array + out : ht.DNDarray, optional + A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. + If not provided or None, a freshly-allocated array is returned. + + Returns + ------- + tuple(array: fractionalParts, array: integralParts) + + fractionalParts : ndarray + Fractional part of x. This is a scalar if x is a scalar. + + integralParts : ndarray + Integral part of x. This is a scalar if x is a scalar. + + Examples + -------- + >>> ht.modf(ht.arrange(-2.0, 2.0, 0.4)) + (tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]), tensor([-0.0, -0.6, -0.2, -0.8, -0.4, 0.0, 0.4, 0.8, 0.2, 0.6])) #TODO + + """ + + integralParts = ht.trunc(a) + fractionalParts = a-integralParts + + return (integralParts, fractionalParts) + + +modf(ht.arange(-2.0, 2.0, 0.4)) + + + + + + + + + + + + + + + + + + + From b3d1c71463934905888576d525148126ef131036 Mon Sep 17 00:00:00 2001 From: blind1 Date: Mon, 30 Sep 2019 07:02:47 +0200 Subject: [PATCH 02/40] BROKEN. Implementation of modf (and round) --- heat/core/rounding.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/heat/core/rounding.py b/heat/core/rounding.py index a0419a4918..5cded50c7f 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -13,7 +13,9 @@ 'fabs', 'floor', 'trunc', + 'modf', 'round' + ] @@ -242,7 +244,7 @@ def modf(a): Examples -------- - >>> ht.modf(ht.arrange(-2.0, 2.0, 0.4)) + >>> ht.modf(ht.arange(-2.0, 2.0, 0.4)) (tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]), tensor([-0.0, -0.6, -0.2, -0.8, -0.4, 0.0, 0.4, 0.8, 0.2, 0.6])) #TODO """ @@ -253,12 +255,42 @@ def modf(a): return (integralParts, fractionalParts) -modf(ht.arange(-2.0, 2.0, 0.4)) +def round(x, out=None, dtype=None): + """ + Calculate the rounded value element-wise. + + Parameters + ---------- + x : ht.DNDarray + The values for which the compute the rounded value. + out : ht.DNDarray, optional + A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. + If not provided or None, a freshly-allocated array is returned. + dtype : ht.type, optional + Determines the data type of the output array. The values are cast to this type with potential loss of + precision. + + Returns + ------- + rounded_values : ht.DNDarray + A tensor containing the rounded value of each element in x. + """ + if dtype is not None and not issubclass(dtype, types.generic): + raise TypeError('dtype must be a heat data type') + + rounded_values = operations.__local_op(torch.round, x, out) + if dtype is not None: + rounded_values._DNDarray__array = rounded_values._DNDarray__array.type( + dtype.torch_type()) + rounded_values._DNDarray__dtype = dtype + + return rounded_values + From 71b8832f88b49e6b3ffc5ece4a850fb40ce4f6e1 Mon Sep 17 00:00:00 2001 From: blind1 Date: Mon, 30 Sep 2019 14:17:08 +0200 Subject: [PATCH 03/40] Modf and round modified. --- heat/core/rounding.py | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/heat/core/rounding.py b/heat/core/rounding.py index 5cded50c7f..d557b1af37 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -234,33 +234,31 @@ def modf(a): Returns ------- - tuple(array: fractionalParts, array: integralParts) + tuple(ht.DNDarray: fractionalParts, ht.DNDarray: integralParts) - fractionalParts : ndarray + fractionalParts : ht.DNDdarray Fractional part of x. This is a scalar if x is a scalar. - integralParts : ndarray + integralParts : ht.DNDdarray Integral part of x. This is a scalar if x is a scalar. Examples -------- >>> ht.modf(ht.arange(-2.0, 2.0, 0.4)) - (tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]), tensor([-0.0, -0.6, -0.2, -0.8, -0.4, 0.0, 0.4, 0.8, 0.2, 0.6])) #TODO - + (tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]), + tensor([ 0.0000, -0.6000, -0.2000, -0.8000, -0.4000, 0.0000, 0.4000, 0.8000, 0.2000, 0.6000])) """ integralParts = ht.trunc(a) fractionalParts = a-integralParts - return (integralParts, fractionalParts) - + return (fractionalParts, integralParts) - -def round(x, out=None, dtype=None): +def round(x, decimals=0, out=None, dtype=None): """ Calculate the rounded value element-wise. @@ -275,33 +273,35 @@ def round(x, out=None, dtype=None): Determines the data type of the output array. The values are cast to this type with potential loss of precision. + decimals: int, optional + Number of decimal places to round to (default: 0). + If decimals is negative, it specifies the number of positions to the left of the decimal point. + Returns ------- rounded_values : ht.DNDarray A tensor containing the rounded value of each element in x. + + Examples + -------- + >>> ht.round(ht.arange(-2.0, 2.0, 0.4)) + tensor([-2., -2., -1., -1., -0., 0., 0., 1., 1., 2.]) + """ if dtype is not None and not issubclass(dtype, types.generic): raise TypeError('dtype must be a heat data type') + if decimals != 0: + x*=10**decimals + rounded_values = operations.__local_op(torch.round, x, out) + + if decimals !=0: + rounded_values/=10**decimals + if dtype is not None: rounded_values._DNDarray__array = rounded_values._DNDarray__array.type( dtype.torch_type()) rounded_values._DNDarray__dtype = dtype - return rounded_values - - - - - - - - - - - - - - - + return rounded_values \ No newline at end of file From 828cb50fa600ae1968d576a12652a99c7e3b163d Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Mon, 7 Oct 2019 21:52:33 +0200 Subject: [PATCH 04/40] Implemented test_round(). --- heat/core/tests/test_rounding.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 35182903d6..3f49f8d3fe 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -162,6 +162,32 @@ def test_floor(self): with self.assertRaises(TypeError): ht.floor(object()) + def test_round(self): + start, end, step = -5.0, 5.0, 1.4 + comparison = torch.arange(start, end, step, dtype=torch.float64).round() + + # exponential of float32 + float32_tensor = ht.arange(start, end, step, dtype=ht.float32) + float32_round = float32_tensor.round() + self.assertIsInstance(float32_round, ht.DNDarray) + self.assertEqual(float32_round.dtype, ht.float32) + self.assertEqual(float32_round.dtype, ht.float32) + self.assertTrue((float32_round._DNDarray__array == comparison.float()).all()) + + # exponential of float64 + float64_tensor = ht.arange(start, end, step, dtype=ht.float64) + float64_round = float64_tensor.round() + self.assertIsInstance(float64_round, ht.DNDarray) + self.assertEqual(float64_round.dtype, ht.float64) + self.assertEqual(float64_round.dtype, ht.float64) + self.assertTrue((float64_round._DNDarray__array == comparison).all()) + + # check exceptions + with self.assertRaises(TypeError): + ht.round([0, 1, 2, 3]) + with self.assertRaises(TypeError): + ht.round(object()) + def test_trunc(self): base_array = np.random.randn(20) From 9a8d6f3e773804948816a54cfc1ce6ede12c81de Mon Sep 17 00:00:00 2001 From: blind1 Date: Thu, 10 Oct 2019 10:34:47 +0200 Subject: [PATCH 05/40] Implementation of round in dndArray --- heat/core/dndarray.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/heat/core/dndarray.py b/heat/core/dndarray.py index a762d75b6f..1b5639a25a 100644 --- a/heat/core/dndarray.py +++ b/heat/core/dndarray.py @@ -54,6 +54,7 @@ def __init__(self, array, gshape, dtype, split, device, comm): self.__device = device self.__comm = comm + @property def comm(self): return self.__comm @@ -2207,6 +2208,35 @@ def __rmod__(self, other): """ return arithmetics.mod(other, self) + + def round(x, decimals=0, out=None, dtype=None): + """ + Calculate the rounded value element-wise. + + Parameters + ---------- + x : ht.DNDarray + The values for which the compute the rounded value. + out : ht.DNDarray, optional + A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. + If not provided or None, a freshly-allocated array is returned. + dtype : ht.type, optional + Determines the data type of the output array. The values are cast to this type with potential loss of + precision. + + decimals: int, optional + Number of decimal places to round to (default: 0). + If decimals is negative, it specifies the number of positions to the left of the decimal point. + + Returns + ------- + rounded_values : ht.DNDarray + A tensor containing the rounded value of each element in x. + """ + + return rounding.round(x, decimals, out, dtype) + + def __rpow__(self, other): """ Element-wise exponential function of second operand (not-heat-typed) with values from first operand (tensor). From 4ae4be5d1291f53f538fe5cf6089863e2f759ee9 Mon Sep 17 00:00:00 2001 From: blind1 Date: Thu, 10 Oct 2019 11:12:44 +0200 Subject: [PATCH 06/40] Functions in alphabetical order --- heat/core/rounding.py | 67 +++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/heat/core/rounding.py b/heat/core/rounding.py index d557b1af37..4293c5cded 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -189,36 +189,6 @@ def floor(x, out=None): return operations.__local_op(torch.floor, x, out) -def trunc(x, out=None): - """ - Return the trunc of the input, element-wise. - - The truncated value of the scalar x is the nearest integer i which is closer to zero than x is. In short, the - fractional part of the signed number x is discarded. - - Parameters - ---------- - x : ht.DNDarray - The value for which to compute the trunced values. - out : ht.DNDarray or None, optional - A location in which to store the results. If provided, it must have a broadcastable shape. If not provided - or set to None, a fresh tensor is allocated. - - Returns - ------- - trunced : ht.DNDarray - A tensor of the same shape as x, containing the trunced valued of each element in this tensor. If out was - provided, trunced is a reference to it. - - Examples - -------- - >>> ht.trunc(ht.arange(-2.0, 2.0, 0.4)) - tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]) - """ - return operations.__local_op(torch.trunc, x, out) - - - def modf(a): """ Return the fractional and integral parts of an array, element-wise. @@ -304,4 +274,39 @@ def round(x, decimals=0, out=None, dtype=None): dtype.torch_type()) rounded_values._DNDarray__dtype = dtype - return rounded_values \ No newline at end of file + return rounded_values + + + + + +def trunc(x, out=None): + """ + Return the trunc of the input, element-wise. + + The truncated value of the scalar x is the nearest integer i which is closer to zero than x is. In short, the + fractional part of the signed number x is discarded. + + Parameters + ---------- + x : ht.DNDarray + The value for which to compute the trunced values. + out : ht.DNDarray or None, optional + A location in which to store the results. If provided, it must have a broadcastable shape. If not provided + or set to None, a fresh tensor is allocated. + + Returns + ------- + trunced : ht.DNDarray + A tensor of the same shape as x, containing the trunced valued of each element in this tensor. If out was + provided, trunced is a reference to it. + + Examples + -------- + >>> ht.trunc(ht.arange(-2.0, 2.0, 0.4)) + tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]) + """ + return operations.__local_op(torch.trunc, x, out) + + + From 2e57691f5417aed6288b936c2c990779d2fce474 Mon Sep 17 00:00:00 2001 From: blind1 Date: Thu, 10 Oct 2019 12:56:21 +0200 Subject: [PATCH 07/40] Test function modf --- heat/core/tests/test_rounding.py | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 3f49f8d3fe..28c1b73962 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -162,6 +162,42 @@ def test_floor(self): with self.assertRaises(TypeError): ht.floor(object()) + + def test_modf(self): + start, end, step = -5.0, 5.0, 1.4 + comparison = np.modf(np.arange(start, end, step, np.float32)) + + # exponential of float32 + float32_tensor = ht.arange(start, end, step, dtype=ht.float32) + float32_modf = float32_tensor.modf() + self.assertIsInstance(float32_modf[0], ht.DNDarray) + self.assertIsInstance(float32_modf[1], ht.DNDarray) + self.assertEqual(float32_modf[0].dtype, ht.float32) + self.assertEqual(float32_modf[1].dtype, ht.float32) + self.assertTrue((x for x in float32_modf[0]._DNDarray__array) == y for y in comparison[0]) + self.assertTrue((x for x in float32_modf[1]._DNDarray__array) == y for y in comparison[1]) + + + # exponential of float64 + comparison = np.modf(np.arange(start, end, step, np.float64)) + + float64_tensor = ht.arange(start, end, step, dtype=ht.float64) + float64_modf = float64_tensor.modf() + self.assertIsInstance(float64_modf[0], ht.DNDarray) + self.assertIsInstance(float64_modf[1], ht.DNDarray) + self.assertEqual(float64_modf[0].dtype, ht.float64) + self.assertEqual(float64_modf[1].dtype, ht.float64) + self.assertTrue((x for x in float32_modf[0]._DNDarray__array) == y for y in comparison[0]) + self.assertTrue((x for x in float32_modf[1]._DNDarray__array) == y for y in comparison[1]) + + + # check exceptions + with self.assertRaises(TypeError): + ht.modf([0, 1, 2, 3]) + with self.assertRaises(TypeError): + ht.modf(object()) + + def test_round(self): start, end, step = -5.0, 5.0, 1.4 comparison = torch.arange(start, end, step, dtype=torch.float64).round() @@ -188,6 +224,7 @@ def test_round(self): with self.assertRaises(TypeError): ht.round(object()) + def test_trunc(self): base_array = np.random.randn(20) @@ -212,3 +249,6 @@ def test_trunc(self): ht.trunc([0, 1, 2, 3]) with self.assertRaises(TypeError): ht.trunc(object()) + + + From b045297619b95398c54252bf230be99ac15119a5 Mon Sep 17 00:00:00 2001 From: blind1 Date: Thu, 10 Oct 2019 12:59:33 +0200 Subject: [PATCH 08/40] Added modf to dndArray --- heat/core/dndarray.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/heat/core/dndarray.py b/heat/core/dndarray.py index 1b5639a25a..c63a391c05 100644 --- a/heat/core/dndarray.py +++ b/heat/core/dndarray.py @@ -1859,6 +1859,34 @@ def __mod__(self, other): """ return arithmetics.mod(self, other) + def modf(a): + """ + Return the fractional and integral parts of an array, element-wise. + The fractional and integral parts are negative if the given number is negative. + + Parameters + ---------- + x : ht.DNDarray + Input array + out : ht.DNDarray, optional + A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. + If not provided or None, a freshly-allocated array is returned. + + Returns + ------- + tuple(ht.DNDarray: fractionalParts, ht.DNDarray: integralParts) + + fractionalParts : ht.DNDdarray + Fractional part of x. This is a scalar if x is a scalar. + + integralParts : ht.DNDdarray + Integral part of x. This is a scalar if x is a scalar. + """ + + return rounding.modf(a) + + + def __mul__(self, other): """ Element-wise multiplication (not matrix multiplication) with values from second operand (scalar or tensor) From 3d23b9db199731daebe8a8c5d314fbbe3333eb99 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Wed, 16 Oct 2019 11:48:03 +0200 Subject: [PATCH 09/40] Added option of user-defined output buffer for ht.modf(). --- heat/core/rounding.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/heat/core/rounding.py b/heat/core/rounding.py index 4293c5cded..2529d766fc 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -138,7 +138,7 @@ def clip(a, a_min, a_max, out=None): return a._DNDarray__array.clamp(a_min, a_max, out=out._DNDarray__array) and out - + def fabs(x, out=None): """ Calculate the absolute value element-wise and return floating-point tensor. @@ -159,7 +159,7 @@ def fabs(x, out=None): """ return abs(x, out, dtype=None) - + def floor(x, out=None): """ @@ -189,18 +189,18 @@ def floor(x, out=None): return operations.__local_op(torch.floor, x, out) -def modf(a): +def modf(x, out=None): """ - Return the fractional and integral parts of an array, element-wise. + Return the fractional and integral parts of a tensor, element-wise. The fractional and integral parts are negative if the given number is negative. Parameters ---------- x : ht.DNDarray - Input array + Input tensor out : ht.DNDarray, optional A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. - If not provided or None, a freshly-allocated array is returned. + If not provided or None, a freshly-allocated tensor is returned. Returns ------- @@ -219,13 +219,21 @@ def modf(a): tensor([ 0.0000, -0.6000, -0.2000, -0.8000, -0.4000, 0.0000, 0.4000, 0.8000, 0.2000, 0.6000])) """ - integralParts = ht.trunc(a) - fractionalParts = a-integralParts - - return (fractionalParts, integralParts) - + integralParts = ht.trunc(x) + fractionalParts = x - integralParts + if out is not None: + if not isinstance(out, tuple): + raise TypeError('expected out to be None or a tuple of ht.DNDarray, but was {}'.format(type(out))) + if len(out) != 2: + raise ValueError('expected out to be a tuple of length 2, but was of length {}'.format(len(out))) + if (not isinstance(out[0], ht.DNDarray)) or (not isinstance(out[1], ht.DNDarray)): + raise TypeError('expected out to be None or a tuple of ht.DNDarray, but was ({}, {})'.format(type(out[0]), type(out[1]))) + out[0]._DNDarray__array = fractionalParts._DNDarray__array + out[1]._DNDarray__array = integralParts._DNDarray__array + return out + return (fractionalParts, integralParts) def round(x, decimals=0, out=None, dtype=None): @@ -262,12 +270,12 @@ def round(x, decimals=0, out=None, dtype=None): raise TypeError('dtype must be a heat data type') if decimals != 0: - x*=10**decimals + x *= 10**decimals rounded_values = operations.__local_op(torch.round, x, out) - if decimals !=0: - rounded_values/=10**decimals + if decimals != 0: + rounded_values /= 10**decimals if dtype is not None: rounded_values._DNDarray__array = rounded_values._DNDarray__array.type( @@ -277,9 +285,6 @@ def round(x, decimals=0, out=None, dtype=None): return rounded_values - - - def trunc(x, out=None): """ Return the trunc of the input, element-wise. @@ -307,6 +312,3 @@ def trunc(x, out=None): tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]) """ return operations.__local_op(torch.trunc, x, out) - - - From 11aa1f12fd97c48e792d89e3bc27fd9e80a16960 Mon Sep 17 00:00:00 2001 From: blind1 Date: Wed, 16 Oct 2019 14:00:21 +0200 Subject: [PATCH 10/40] modf with out --- heat/core/rounding.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/heat/core/rounding.py b/heat/core/rounding.py index c5e1d5a807..dc9c641b89 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -188,7 +188,7 @@ def modf(x, out=None): ---------- x : ht.DNDarray Input tensor - out : ht.DNDarray, optional + out : tuple(ht.DNDarray, ht.DNDarray), optional A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated tensor is returned. @@ -226,6 +226,7 @@ def modf(x, out=None): return (fractionalParts, integralParts) + def round(x, decimals=0, out=None, dtype=None): """ Calculate the rounded value element-wise. @@ -234,6 +235,9 @@ def round(x, decimals=0, out=None, dtype=None): ---------- x : ht.DNDarray The values for which the compute the rounded value. + decimals: int, optional + Number of decimal places to round to (default: 0). + If decimals is negative, it specifies the number of positions to the left of the decimal point. out : ht.DNDarray, optional A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. @@ -241,9 +245,6 @@ def round(x, decimals=0, out=None, dtype=None): Determines the data type of the output array. The values are cast to this type with potential loss of precision. - decimals: int, optional - Number of decimal places to round to (default: 0). - If decimals is negative, it specifies the number of positions to the left of the decimal point. Returns ------- @@ -275,6 +276,9 @@ def round(x, decimals=0, out=None, dtype=None): return rounded_values + + + def trunc(x, out=None): """ Return the trunc of the input, element-wise. @@ -302,3 +306,6 @@ def trunc(x, out=None): tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]) """ return operations.__local_op(torch.trunc, x, out) + + + From bbe33a6e909f647a8176fd5120b2c2463c0a6dc8 Mon Sep 17 00:00:00 2001 From: blind1 Date: Wed, 16 Oct 2019 14:14:01 +0200 Subject: [PATCH 11/40] Expanded test_modf for out --- heat/core/tests/test_rounding.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 51a0ea3f62..62fa391680 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -196,6 +196,12 @@ def test_modf(self): ht.modf([0, 1, 2, 3]) with self.assertRaises(TypeError): ht.modf(object()) + with self.assertRaises(TypeError): + ht.modf(float32_tensor, 1) + with self.assertRaises(ValueError): + ht.modf(float32_tensor, (float32_tensor, float32_tensor, float64_tensor)) + with self.assertRaises(TypeError): + ht.modf(float32_tensor, (float32_tensor, 2)) def test_round(self): From e123b3c2af3ef8a2769e11c883a0f84fa6453c1c Mon Sep 17 00:00:00 2001 From: blind1 Date: Thu, 24 Oct 2019 10:31:11 +0200 Subject: [PATCH 12/40] Adaptation to pre-commit --- heat/core/dndarray.py | 9 ++------- heat/core/rounding.py | 30 +++++++++++++++--------------- heat/core/tests/test_rounding.py | 8 -------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/heat/core/dndarray.py b/heat/core/dndarray.py index 1ee63bc839..014b2b298b 100644 --- a/heat/core/dndarray.py +++ b/heat/core/dndarray.py @@ -51,7 +51,6 @@ def __init__(self, array, gshape, dtype, split, device, comm): self.__device = device self.__comm = comm - @property def comm(self): return self.__comm @@ -1927,7 +1926,7 @@ def __mod__(self, other): """ return arithmetics.mod(self, other) - def modf(a): + def modf(a, out=None): """ Return the fractional and integral parts of an array, element-wise. The fractional and integral parts are negative if the given number is negative. @@ -1951,9 +1950,7 @@ def modf(a): Integral part of x. This is a scalar if x is a scalar. """ - return rounding.modf(a) - - + return rounding.modf(a, out) def __mul__(self, other): """ @@ -2342,7 +2339,6 @@ def __rmod__(self, other): """ return arithmetics.mod(other, self) - def round(x, decimals=0, out=None, dtype=None): """ Calculate the rounded value element-wise. @@ -2370,7 +2366,6 @@ def round(x, decimals=0, out=None, dtype=None): return rounding.round(x, decimals, out, dtype) - def __rpow__(self, other): """ Element-wise exponential function of second operand (not-heat-typed) with values from first operand (tensor). diff --git a/heat/core/rounding.py b/heat/core/rounding.py index dc9c641b89..926c9519f4 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -214,11 +214,19 @@ def modf(x, out=None): if out is not None: if not isinstance(out, tuple): - raise TypeError('expected out to be None or a tuple of ht.DNDarray, but was {}'.format(type(out))) + raise TypeError( + "expected out to be None or a tuple of ht.DNDarray, but was {}".format(type(out)) + ) if len(out) != 2: - raise ValueError('expected out to be a tuple of length 2, but was of length {}'.format(len(out))) + raise ValueError( + "expected out to be a tuple of length 2, but was of length {}".format(len(out)) + ) if (not isinstance(out[0], ht.DNDarray)) or (not isinstance(out[1], ht.DNDarray)): - raise TypeError('expected out to be None or a tuple of ht.DNDarray, but was ({}, {})'.format(type(out[0]), type(out[1]))) + raise TypeError( + "expected out to be None or a tuple of ht.DNDarray, but was ({}, {})".format( + type(out[0]), type(out[1]) + ) + ) out[0]._DNDarray__array = fractionalParts._DNDarray__array out[1]._DNDarray__array = integralParts._DNDarray__array return out @@ -226,7 +234,6 @@ def modf(x, out=None): return (fractionalParts, integralParts) - def round(x, decimals=0, out=None, dtype=None): """ Calculate the rounded value element-wise. @@ -258,27 +265,23 @@ def round(x, decimals=0, out=None, dtype=None): """ if dtype is not None and not issubclass(dtype, types.generic): - raise TypeError('dtype must be a heat data type') + raise TypeError("dtype must be a heat data type") if decimals != 0: - x *= 10**decimals + x *= 10 ** decimals rounded_values = operations.__local_op(torch.round, x, out) if decimals != 0: - rounded_values /= 10**decimals + rounded_values /= 10 ** decimals if dtype is not None: - rounded_values._DNDarray__array = rounded_values._DNDarray__array.type( - dtype.torch_type()) + rounded_values._DNDarray__array = rounded_values._DNDarray__array.type(dtype.torch_type()) rounded_values._DNDarray__dtype = dtype return rounded_values - - - def trunc(x, out=None): """ Return the trunc of the input, element-wise. @@ -306,6 +309,3 @@ def trunc(x, out=None): tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]) """ return operations.__local_op(torch.trunc, x, out) - - - diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 62fa391680..557c802d1e 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -162,7 +162,6 @@ def test_floor(self): with self.assertRaises(TypeError): ht.floor(object()) - def test_modf(self): start, end, step = -5.0, 5.0, 1.4 comparison = np.modf(np.arange(start, end, step, np.float32)) @@ -177,7 +176,6 @@ def test_modf(self): self.assertTrue((x for x in float32_modf[0]._DNDarray__array) == y for y in comparison[0]) self.assertTrue((x for x in float32_modf[1]._DNDarray__array) == y for y in comparison[1]) - # exponential of float64 comparison = np.modf(np.arange(start, end, step, np.float64)) @@ -190,7 +188,6 @@ def test_modf(self): self.assertTrue((x for x in float32_modf[0]._DNDarray__array) == y for y in comparison[0]) self.assertTrue((x for x in float32_modf[1]._DNDarray__array) == y for y in comparison[1]) - # check exceptions with self.assertRaises(TypeError): ht.modf([0, 1, 2, 3]) @@ -203,7 +200,6 @@ def test_modf(self): with self.assertRaises(TypeError): ht.modf(float32_tensor, (float32_tensor, 2)) - def test_round(self): start, end, step = -5.0, 5.0, 1.4 comparison = torch.arange(start, end, step, dtype=torch.float64).round() @@ -230,7 +226,6 @@ def test_round(self): with self.assertRaises(TypeError): ht.round(object()) - def test_trunc(self): base_array = np.random.randn(20) @@ -255,6 +250,3 @@ def test_trunc(self): ht.trunc([0, 1, 2, 3]) with self.assertRaises(TypeError): ht.trunc(object()) - - - From 5d088b97e2ed46c6938d254dfe1a6a2a38f34e15 Mon Sep 17 00:00:00 2001 From: blind1 Date: Mon, 11 Nov 2019 15:32:15 +0100 Subject: [PATCH 13/40] Implementation of requested changes --- heat/core/rounding.py | 8 +++++--- heat/core/tests/test_rounding.py | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/heat/core/rounding.py b/heat/core/rounding.py index 926c9519f4..f5618c6a42 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -1,5 +1,4 @@ import torch -import heat as ht from . import operations from . import dndarray @@ -209,7 +208,10 @@ def modf(x, out=None): tensor([ 0.0000, -0.6000, -0.2000, -0.8000, -0.4000, 0.0000, 0.4000, 0.8000, 0.2000, 0.6000])) """ - integralParts = ht.trunc(x) + if not isinstance(x, dndarray.DNDarray): + raise TypeError("expected x to be a ht.DNDarray, but was {}".format(type(out))) + + integralParts = trunc(x) fractionalParts = x - integralParts if out is not None: @@ -221,7 +223,7 @@ def modf(x, out=None): raise ValueError( "expected out to be a tuple of length 2, but was of length {}".format(len(out)) ) - if (not isinstance(out[0], ht.DNDarray)) or (not isinstance(out[1], ht.DNDarray)): + if (not isinstance(out[0], dndarray.DNDarray)) or (not isinstance(out[1], dndarray.DNDarray)): raise TypeError( "expected out to be None or a tuple of ht.DNDarray, but was ({}, {})".format( type(out[0]), type(out[1]) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 557c802d1e..7e9c725eec 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -173,8 +173,17 @@ def test_modf(self): self.assertIsInstance(float32_modf[1], ht.DNDarray) self.assertEqual(float32_modf[0].dtype, ht.float32) self.assertEqual(float32_modf[1].dtype, ht.float32) - self.assertTrue((x for x in float32_modf[0]._DNDarray__array) == y for y in comparison[0]) - self.assertTrue((x for x in float32_modf[1]._DNDarray__array) == y for y in comparison[1]) + + + + self.assertAlmostEqual(float32_modf[0].numpy().all(), comparison[0].all()) + self.assertAlmostEqual(float32_modf[1].numpy().all(), comparison[1].all()) + + + self.assertAlmostEqual(ht.all(float32_modf[0]), ht.all(ht.array(comparison[0]))) + self.assertAlmostEqual(ht.all(float32_modf[1]), ht.all(ht.array(comparison[1]))) + + # exponential of float64 comparison = np.modf(np.arange(start, end, step, np.float64)) @@ -185,8 +194,14 @@ def test_modf(self): self.assertIsInstance(float64_modf[1], ht.DNDarray) self.assertEqual(float64_modf[0].dtype, ht.float64) self.assertEqual(float64_modf[1].dtype, ht.float64) - self.assertTrue((x for x in float32_modf[0]._DNDarray__array) == y for y in comparison[0]) - self.assertTrue((x for x in float32_modf[1]._DNDarray__array) == y for y in comparison[1]) + + self.assertAlmostEqual(float64_modf[0].numpy().all(), comparison[0].all()) + self.assertAlmostEqual(float64_modf[1].numpy().all(), comparison[1].all()) + + self.assertAlmostEqual(ht.all(float64_modf[0]), ht.all(ht.array(comparison[0]))) + self.assertAlmostEqual(ht.all(float64_modf[1]), ht.all(ht.array(comparison[1]))) + + # check exceptions with self.assertRaises(TypeError): From db796cc0661fffffdc631ca26cdf79de710fa1fe Mon Sep 17 00:00:00 2001 From: blind1 Date: Thu, 14 Nov 2019 07:46:01 +0100 Subject: [PATCH 14/40] Code reformatted via black --- heat/core/rounding.py | 4 +++- heat/core/tests/test_rounding.py | 7 ------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/heat/core/rounding.py b/heat/core/rounding.py index f5618c6a42..b9577b9812 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -223,7 +223,9 @@ def modf(x, out=None): raise ValueError( "expected out to be a tuple of length 2, but was of length {}".format(len(out)) ) - if (not isinstance(out[0], dndarray.DNDarray)) or (not isinstance(out[1], dndarray.DNDarray)): + if (not isinstance(out[0], dndarray.DNDarray)) or ( + not isinstance(out[1], dndarray.DNDarray) + ): raise TypeError( "expected out to be None or a tuple of ht.DNDarray, but was ({}, {})".format( type(out[0]), type(out[1]) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 7e9c725eec..8d3af762fa 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -174,17 +174,12 @@ def test_modf(self): self.assertEqual(float32_modf[0].dtype, ht.float32) self.assertEqual(float32_modf[1].dtype, ht.float32) - - self.assertAlmostEqual(float32_modf[0].numpy().all(), comparison[0].all()) self.assertAlmostEqual(float32_modf[1].numpy().all(), comparison[1].all()) - self.assertAlmostEqual(ht.all(float32_modf[0]), ht.all(ht.array(comparison[0]))) self.assertAlmostEqual(ht.all(float32_modf[1]), ht.all(ht.array(comparison[1]))) - - # exponential of float64 comparison = np.modf(np.arange(start, end, step, np.float64)) @@ -201,8 +196,6 @@ def test_modf(self): self.assertAlmostEqual(ht.all(float64_modf[0]), ht.all(ht.array(comparison[0]))) self.assertAlmostEqual(ht.all(float64_modf[1]), ht.all(ht.array(comparison[1]))) - - # check exceptions with self.assertRaises(TypeError): ht.modf([0, 1, 2, 3]) From efcefbd2315337072b26c55fbf56a8f27137f3e0 Mon Sep 17 00:00:00 2001 From: blind1 Date: Wed, 20 Nov 2019 07:56:09 +0100 Subject: [PATCH 15/40] Tests with split tensors --- heat/core/tests/test_rounding.py | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 8d3af762fa..dd7dd26ae9 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -208,6 +208,39 @@ def test_modf(self): with self.assertRaises(TypeError): ht.modf(float32_tensor, (float32_tensor, 2)) + # with split tensors + + # exponential of float32 + float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) + float32_modf_distrbd = float32_tensor_distrbd.modf() + + self.assertIsInstance(float32_modf_distrbd[0], ht.DNDarray) + self.assertIsInstance(float32_modf_distrbd[1], ht.DNDarray) + self.assertEqual(float32_modf_distrbd[0].dtype, ht.float32) + self.assertEqual(float32_modf_distrbd[1].dtype, ht.float32) + + self.assertAlmostEqual(float32_modf_distrbd[0].numpy().all(), comparison[0].all()) + self.assertAlmostEqual(float32_modf_distrbd[1].numpy().all(), comparison[1].all()) + + self.assertAlmostEqual(ht.all(float32_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) + self.assertAlmostEqual(ht.all(float32_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) + + # exponential of float64 + comparison = np.modf(np.arange(start, end, step, np.float64)) + + float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) + float64_modf_distrbd = float64_tensor_distrbd.modf() + self.assertIsInstance(float64_modf_distrbd[0], ht.DNDarray) + self.assertIsInstance(float64_modf_distrbd[1], ht.DNDarray) + self.assertEqual(float64_modf_distrbd[0].dtype, ht.float64) + self.assertEqual(float64_modf_distrbd[1].dtype, ht.float64) + + self.assertAlmostEqual(float64_modf_distrbd[0].numpy().all(), comparison[0].all()) + self.assertAlmostEqual(float64_modf_distrbd[1].numpy().all(), comparison[1].all()) + + self.assertAlmostEqual(ht.all(float64_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) + self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) + def test_round(self): start, end, step = -5.0, 5.0, 1.4 comparison = torch.arange(start, end, step, dtype=torch.float64).round() @@ -233,6 +266,26 @@ def test_round(self): ht.round([0, 1, 2, 3]) with self.assertRaises(TypeError): ht.round(object()) + with self.assertRaises(TypeError): + ht.round(float32_tensor, 1, 1) + + # with split tensors + + # exponential of float32 + float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) + float32_round_distrbd = float32_tensor_distrbd.round() + self.assertIsInstance(float32_round_distrbd, ht.DNDarray) + self.assertEqual(float32_round_distrbd.dtype, ht.float32) + self.assertEqual(float32_round_distrbd.dtype, ht.float32) + self.assertTrue((float32_round_distrbd._DNDarray__array == comparison.float()).all()) + + # exponential of float64 + float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) + float64_round_distrbd = float64_tensor_distrbd.round() + self.assertIsInstance(float64_round_distrbd, ht.DNDarray) + self.assertEqual(float64_round_distrbd.dtype, ht.float64) + self.assertEqual(float64_round_distrbd.dtype, ht.float64) + self.assertTrue((float64_round_distrbd._DNDarray__array == comparison).all()) def test_trunc(self): base_array = np.random.randn(20) From 46b001c4dfc8a513af20a4f04fcf5a717cc9a4f2 Mon Sep 17 00:00:00 2001 From: blind1 Date: Wed, 20 Nov 2019 08:24:37 +0100 Subject: [PATCH 16/40] Tests correction --- heat/core/tests/test_rounding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index dd7dd26ae9..3521872354 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -228,7 +228,7 @@ def test_modf(self): # exponential of float64 comparison = np.modf(np.arange(start, end, step, np.float64)) - float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) + float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) float64_modf_distrbd = float64_tensor_distrbd.modf() self.assertIsInstance(float64_modf_distrbd[0], ht.DNDarray) self.assertIsInstance(float64_modf_distrbd[1], ht.DNDarray) From f456d7b687ef9eb8d68e1765753b8ebbdd13f137 Mon Sep 17 00:00:00 2001 From: blind1 Date: Wed, 20 Nov 2019 09:49:56 +0100 Subject: [PATCH 17/40] Integration of ht.equal for tests --- heat/core/tests/test_rounding.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 3521872354..783e3f760f 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -243,7 +243,7 @@ def test_modf(self): def test_round(self): start, end, step = -5.0, 5.0, 1.4 - comparison = torch.arange(start, end, step, dtype=torch.float64).round() + comparison = torch.arange(start, end, step, dtype=torch.float32).round() # exponential of float32 float32_tensor = ht.arange(start, end, step, dtype=ht.float32) @@ -251,15 +251,16 @@ def test_round(self): self.assertIsInstance(float32_round, ht.DNDarray) self.assertEqual(float32_round.dtype, ht.float32) self.assertEqual(float32_round.dtype, ht.float32) - self.assertTrue((float32_round._DNDarray__array == comparison.float()).all()) + self.assertTrue(ht.equal(float32_round, ht.array(comparison))) # exponential of float64 + comparison = torch.arange(start, end, step, dtype=torch.float64).round() float64_tensor = ht.arange(start, end, step, dtype=ht.float64) float64_round = float64_tensor.round() self.assertIsInstance(float64_round, ht.DNDarray) self.assertEqual(float64_round.dtype, ht.float64) self.assertEqual(float64_round.dtype, ht.float64) - self.assertTrue((float64_round._DNDarray__array == comparison).all()) + self.assertTrue(ht.equal(float64_round, ht.array(comparison))) # check exceptions with self.assertRaises(TypeError): @@ -272,20 +273,22 @@ def test_round(self): # with split tensors # exponential of float32 + comparison = torch.arange(start, end, step, dtype=torch.float32).round() float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) float32_round_distrbd = float32_tensor_distrbd.round() self.assertIsInstance(float32_round_distrbd, ht.DNDarray) self.assertEqual(float32_round_distrbd.dtype, ht.float32) self.assertEqual(float32_round_distrbd.dtype, ht.float32) - self.assertTrue((float32_round_distrbd._DNDarray__array == comparison.float()).all()) + self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) # exponential of float64 + comparison = torch.arange(start, end, step, dtype=torch.float64).round() float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) float64_round_distrbd = float64_tensor_distrbd.round() self.assertIsInstance(float64_round_distrbd, ht.DNDarray) self.assertEqual(float64_round_distrbd.dtype, ht.float64) self.assertEqual(float64_round_distrbd.dtype, ht.float64) - self.assertTrue((float64_round_distrbd._DNDarray__array == comparison).all()) + self.assertTrue(ht.equal(float64_round_distrbd, ht.array(comparison))) def test_trunc(self): base_array = np.random.randn(20) From 1ecdeba4b149a1c661342919bb4ca9f13560d7d7 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Mon, 25 Nov 2019 12:57:54 +0100 Subject: [PATCH 18/40] Debugging attempts. --- heat/core/tests/test_rounding.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 783e3f760f..375d65906f 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -242,11 +242,13 @@ def test_modf(self): self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) def test_round(self): + print("DEBUG: test_round, size = ") start, end, step = -5.0, 5.0, 1.4 comparison = torch.arange(start, end, step, dtype=torch.float32).round() # exponential of float32 float32_tensor = ht.arange(start, end, step, dtype=ht.float32) + print("DEBUG: test_round. split, size = ", float32_tensor.split, float32_tensor.comm.size) float32_round = float32_tensor.round() self.assertIsInstance(float32_round, ht.DNDarray) self.assertEqual(float32_round.dtype, ht.float32) @@ -276,6 +278,12 @@ def test_round(self): comparison = torch.arange(start, end, step, dtype=torch.float32).round() float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) float32_round_distrbd = float32_tensor_distrbd.round() + print( + "DEBUG: test_round. split, dtype, size = ", + float32_tensor.split, + float32_tensor.dtype, + float32_tensor.comm.size, + ) self.assertIsInstance(float32_round_distrbd, ht.DNDarray) self.assertEqual(float32_round_distrbd.dtype, ht.float32) self.assertEqual(float32_round_distrbd.dtype, ht.float32) @@ -284,6 +292,12 @@ def test_round(self): # exponential of float64 comparison = torch.arange(start, end, step, dtype=torch.float64).round() float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) + print( + "DEBUG: test_round. split, dtype, size = ", + float64_tensor.split, + float64_tensor.dtype, + float64_tensor.comm.size, + ) float64_round_distrbd = float64_tensor_distrbd.round() self.assertIsInstance(float64_round_distrbd, ht.DNDarray) self.assertEqual(float64_round_distrbd.dtype, ht.float64) From 6a82e9c8bd7eb4c926b04a82e758d8746dba7b58 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Mon, 25 Nov 2019 13:03:18 +0100 Subject: [PATCH 19/40] Fixing debugging attempts. --- heat/core/tests/test_rounding.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 375d65906f..007cdc92fb 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -280,9 +280,9 @@ def test_round(self): float32_round_distrbd = float32_tensor_distrbd.round() print( "DEBUG: test_round. split, dtype, size = ", - float32_tensor.split, - float32_tensor.dtype, - float32_tensor.comm.size, + float32_tensor_distrbd.split, + float32_tensor_distrbd.dtype, + float32_tensor_distrbd.comm.size, ) self.assertIsInstance(float32_round_distrbd, ht.DNDarray) self.assertEqual(float32_round_distrbd.dtype, ht.float32) @@ -294,9 +294,9 @@ def test_round(self): float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) print( "DEBUG: test_round. split, dtype, size = ", - float64_tensor.split, - float64_tensor.dtype, - float64_tensor.comm.size, + float64_tensor_distrbd.split, + float64_tensor_distrbd.dtype, + float64_tensor_distrbd.comm.size, ) float64_round_distrbd = float64_tensor_distrbd.round() self.assertIsInstance(float64_round_distrbd, ht.DNDarray) From 342e661d7b49d4cfd10953ba707fae97dfdee252 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Mon, 25 Nov 2019 13:14:28 +0100 Subject: [PATCH 20/40] test_modf(), test_round(): defining test tensors so that they are always distributed evenly (shape is a multiple of number of ranks). --- heat/core/tests/test_rounding.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 007cdc92fb..f80d0edfdb 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -163,7 +163,9 @@ def test_floor(self): ht.floor(object()) def test_modf(self): - start, end, step = -5.0, 5.0, 1.4 + size = ht.communication.MPI_WORLD.size + start, end = -5.0, 5.0 + step = (end - start) / (2 * size) comparison = np.modf(np.arange(start, end, step, np.float32)) # exponential of float32 @@ -242,13 +244,13 @@ def test_modf(self): self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) def test_round(self): - print("DEBUG: test_round, size = ") - start, end, step = -5.0, 5.0, 1.4 + size = ht.communication.MPI_WORLD.size + start, end = -5.0, 5.0 + step = (end - start) / (2 * size) comparison = torch.arange(start, end, step, dtype=torch.float32).round() # exponential of float32 float32_tensor = ht.arange(start, end, step, dtype=ht.float32) - print("DEBUG: test_round. split, size = ", float32_tensor.split, float32_tensor.comm.size) float32_round = float32_tensor.round() self.assertIsInstance(float32_round, ht.DNDarray) self.assertEqual(float32_round.dtype, ht.float32) @@ -278,12 +280,6 @@ def test_round(self): comparison = torch.arange(start, end, step, dtype=torch.float32).round() float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) float32_round_distrbd = float32_tensor_distrbd.round() - print( - "DEBUG: test_round. split, dtype, size = ", - float32_tensor_distrbd.split, - float32_tensor_distrbd.dtype, - float32_tensor_distrbd.comm.size, - ) self.assertIsInstance(float32_round_distrbd, ht.DNDarray) self.assertEqual(float32_round_distrbd.dtype, ht.float32) self.assertEqual(float32_round_distrbd.dtype, ht.float32) @@ -292,12 +288,6 @@ def test_round(self): # exponential of float64 comparison = torch.arange(start, end, step, dtype=torch.float64).round() float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) - print( - "DEBUG: test_round. split, dtype, size = ", - float64_tensor_distrbd.split, - float64_tensor_distrbd.dtype, - float64_tensor_distrbd.comm.size, - ) float64_round_distrbd = float64_tensor_distrbd.round() self.assertIsInstance(float64_round_distrbd, ht.DNDarray) self.assertEqual(float64_round_distrbd.dtype, ht.float64) From 0f3d6e4c4fa5a2759102f2ed0b4ba7201c039b38 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Mon, 25 Nov 2019 13:24:13 +0100 Subject: [PATCH 21/40] More debugging attempts. --- heat/core/tests/test_rounding.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index f80d0edfdb..9a6443ccd6 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -163,6 +163,7 @@ def test_floor(self): ht.floor(object()) def test_modf(self): + print("IN TEST_MODF") size = ht.communication.MPI_WORLD.size start, end = -5.0, 5.0 step = (end - start) / (2 * size) @@ -244,6 +245,7 @@ def test_modf(self): self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) def test_round(self): + print("IN TEST_ROUND") size = ht.communication.MPI_WORLD.size start, end = -5.0, 5.0 step = (end - start) / (2 * size) From 7ad1fb3091dc80b9566f8f77446c6dafbce0e6cc Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Mon, 25 Nov 2019 14:19:19 +0100 Subject: [PATCH 22/40] Removed print/debugging statements --- heat/core/tests/test_rounding.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 9a6443ccd6..f80d0edfdb 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -163,7 +163,6 @@ def test_floor(self): ht.floor(object()) def test_modf(self): - print("IN TEST_MODF") size = ht.communication.MPI_WORLD.size start, end = -5.0, 5.0 step = (end - start) / (2 * size) @@ -245,7 +244,6 @@ def test_modf(self): self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) def test_round(self): - print("IN TEST_ROUND") size = ht.communication.MPI_WORLD.size start, end = -5.0, 5.0 step = (end - start) / (2 * size) From 387d1f45dfad0d3054e8fb5589c88cffd9ef3940 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Tue, 3 Dec 2019 13:54:05 +0100 Subject: [PATCH 23/40] Debugging attempts. --- heat/core/tests/test_rounding.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index f80d0edfdb..b847cbe891 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -169,6 +169,7 @@ def test_modf(self): comparison = np.modf(np.arange(start, end, step, np.float32)) # exponential of float32 + print("LOCAL, FLOAT32") float32_tensor = ht.arange(start, end, step, dtype=ht.float32) float32_modf = float32_tensor.modf() self.assertIsInstance(float32_modf[0], ht.DNDarray) @@ -183,6 +184,8 @@ def test_modf(self): self.assertAlmostEqual(ht.all(float32_modf[1]), ht.all(ht.array(comparison[1]))) # exponential of float64 + print("LOCAL, FLOAT64") + comparison = np.modf(np.arange(start, end, step, np.float64)) float64_tensor = ht.arange(start, end, step, dtype=ht.float64) @@ -199,6 +202,8 @@ def test_modf(self): self.assertAlmostEqual(ht.all(float64_modf[1]), ht.all(ht.array(comparison[1]))) # check exceptions + print("LOCAL, EXCEPTIONS") + with self.assertRaises(TypeError): ht.modf([0, 1, 2, 3]) with self.assertRaises(TypeError): @@ -213,6 +218,8 @@ def test_modf(self): # with split tensors # exponential of float32 + print("SPLIT, FLOAT32") + float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) float32_modf_distrbd = float32_tensor_distrbd.modf() @@ -228,6 +235,7 @@ def test_modf(self): self.assertAlmostEqual(ht.all(float32_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) # exponential of float64 + print("SPLIT, FLOAT64") comparison = np.modf(np.arange(start, end, step, np.float64)) float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) From 0af380366d61361445e9b2e9ccf7128b10eb5a2c Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Tue, 3 Dec 2019 14:15:21 +0100 Subject: [PATCH 24/40] Debugging --- heat/core/tests/test_rounding.py | 168 +++++++++++++++---------------- 1 file changed, 80 insertions(+), 88 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index b847cbe891..894ee2bb4d 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -162,94 +162,86 @@ def test_floor(self): with self.assertRaises(TypeError): ht.floor(object()) - def test_modf(self): - size = ht.communication.MPI_WORLD.size - start, end = -5.0, 5.0 - step = (end - start) / (2 * size) - comparison = np.modf(np.arange(start, end, step, np.float32)) - - # exponential of float32 - print("LOCAL, FLOAT32") - float32_tensor = ht.arange(start, end, step, dtype=ht.float32) - float32_modf = float32_tensor.modf() - self.assertIsInstance(float32_modf[0], ht.DNDarray) - self.assertIsInstance(float32_modf[1], ht.DNDarray) - self.assertEqual(float32_modf[0].dtype, ht.float32) - self.assertEqual(float32_modf[1].dtype, ht.float32) - - self.assertAlmostEqual(float32_modf[0].numpy().all(), comparison[0].all()) - self.assertAlmostEqual(float32_modf[1].numpy().all(), comparison[1].all()) - - self.assertAlmostEqual(ht.all(float32_modf[0]), ht.all(ht.array(comparison[0]))) - self.assertAlmostEqual(ht.all(float32_modf[1]), ht.all(ht.array(comparison[1]))) - - # exponential of float64 - print("LOCAL, FLOAT64") - - comparison = np.modf(np.arange(start, end, step, np.float64)) - - float64_tensor = ht.arange(start, end, step, dtype=ht.float64) - float64_modf = float64_tensor.modf() - self.assertIsInstance(float64_modf[0], ht.DNDarray) - self.assertIsInstance(float64_modf[1], ht.DNDarray) - self.assertEqual(float64_modf[0].dtype, ht.float64) - self.assertEqual(float64_modf[1].dtype, ht.float64) - - self.assertAlmostEqual(float64_modf[0].numpy().all(), comparison[0].all()) - self.assertAlmostEqual(float64_modf[1].numpy().all(), comparison[1].all()) - - self.assertAlmostEqual(ht.all(float64_modf[0]), ht.all(ht.array(comparison[0]))) - self.assertAlmostEqual(ht.all(float64_modf[1]), ht.all(ht.array(comparison[1]))) - - # check exceptions - print("LOCAL, EXCEPTIONS") - - with self.assertRaises(TypeError): - ht.modf([0, 1, 2, 3]) - with self.assertRaises(TypeError): - ht.modf(object()) - with self.assertRaises(TypeError): - ht.modf(float32_tensor, 1) - with self.assertRaises(ValueError): - ht.modf(float32_tensor, (float32_tensor, float32_tensor, float64_tensor)) - with self.assertRaises(TypeError): - ht.modf(float32_tensor, (float32_tensor, 2)) - - # with split tensors - - # exponential of float32 - print("SPLIT, FLOAT32") - - float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) - float32_modf_distrbd = float32_tensor_distrbd.modf() - - self.assertIsInstance(float32_modf_distrbd[0], ht.DNDarray) - self.assertIsInstance(float32_modf_distrbd[1], ht.DNDarray) - self.assertEqual(float32_modf_distrbd[0].dtype, ht.float32) - self.assertEqual(float32_modf_distrbd[1].dtype, ht.float32) - - self.assertAlmostEqual(float32_modf_distrbd[0].numpy().all(), comparison[0].all()) - self.assertAlmostEqual(float32_modf_distrbd[1].numpy().all(), comparison[1].all()) - - self.assertAlmostEqual(ht.all(float32_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) - self.assertAlmostEqual(ht.all(float32_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) - - # exponential of float64 - print("SPLIT, FLOAT64") - comparison = np.modf(np.arange(start, end, step, np.float64)) - - float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) - float64_modf_distrbd = float64_tensor_distrbd.modf() - self.assertIsInstance(float64_modf_distrbd[0], ht.DNDarray) - self.assertIsInstance(float64_modf_distrbd[1], ht.DNDarray) - self.assertEqual(float64_modf_distrbd[0].dtype, ht.float64) - self.assertEqual(float64_modf_distrbd[1].dtype, ht.float64) - - self.assertAlmostEqual(float64_modf_distrbd[0].numpy().all(), comparison[0].all()) - self.assertAlmostEqual(float64_modf_distrbd[1].numpy().all(), comparison[1].all()) - - self.assertAlmostEqual(ht.all(float64_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) - self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) + # def test_modf(self): + # size = ht.communication.MPI_WORLD.size + # start, end = -5.0, 5.0 + # step = (end - start) / (2 * size) + # comparison = np.modf(np.arange(start, end, step, np.float32)) + + # # exponential of float32 + # float32_tensor = ht.arange(start, end, step, dtype=ht.float32) + # float32_modf = float32_tensor.modf() + # self.assertIsInstance(float32_modf[0], ht.DNDarray) + # self.assertIsInstance(float32_modf[1], ht.DNDarray) + # self.assertEqual(float32_modf[0].dtype, ht.float32) + # self.assertEqual(float32_modf[1].dtype, ht.float32) + + # self.assertAlmostEqual(float32_modf[0].numpy().all(), comparison[0].all()) + # self.assertAlmostEqual(float32_modf[1].numpy().all(), comparison[1].all()) + + # self.assertAlmostEqual(ht.all(float32_modf[0]), ht.all(ht.array(comparison[0]))) + # self.assertAlmostEqual(ht.all(float32_modf[1]), ht.all(ht.array(comparison[1]))) + + # # exponential of float64 + # comparison = np.modf(np.arange(start, end, step, np.float64)) + + # float64_tensor = ht.arange(start, end, step, dtype=ht.float64) + # float64_modf = float64_tensor.modf() + # self.assertIsInstance(float64_modf[0], ht.DNDarray) + # self.assertIsInstance(float64_modf[1], ht.DNDarray) + # self.assertEqual(float64_modf[0].dtype, ht.float64) + # self.assertEqual(float64_modf[1].dtype, ht.float64) + + # self.assertAlmostEqual(float64_modf[0].numpy().all(), comparison[0].all()) + # self.assertAlmostEqual(float64_modf[1].numpy().all(), comparison[1].all()) + + # self.assertAlmostEqual(ht.all(float64_modf[0]), ht.all(ht.array(comparison[0]))) + # self.assertAlmostEqual(ht.all(float64_modf[1]), ht.all(ht.array(comparison[1]))) + + # # check exceptions + # with self.assertRaises(TypeError): + # ht.modf([0, 1, 2, 3]) + # with self.assertRaises(TypeError): + # ht.modf(object()) + # with self.assertRaises(TypeError): + # ht.modf(float32_tensor, 1) + # with self.assertRaises(ValueError): + # ht.modf(float32_tensor, (float32_tensor, float32_tensor, float64_tensor)) + # with self.assertRaises(TypeError): + # ht.modf(float32_tensor, (float32_tensor, 2)) + + # # with split tensors + + # # exponential of float32 + # float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) + # float32_modf_distrbd = float32_tensor_distrbd.modf() + + # self.assertIsInstance(float32_modf_distrbd[0], ht.DNDarray) + # self.assertIsInstance(float32_modf_distrbd[1], ht.DNDarray) + # self.assertEqual(float32_modf_distrbd[0].dtype, ht.float32) + # self.assertEqual(float32_modf_distrbd[1].dtype, ht.float32) + + # self.assertAlmostEqual(float32_modf_distrbd[0].numpy().all(), comparison[0].all()) + # self.assertAlmostEqual(float32_modf_distrbd[1].numpy().all(), comparison[1].all()) + + # self.assertAlmostEqual(ht.all(float32_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) + # self.assertAlmostEqual(ht.all(float32_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) + + # # exponential of float64 + # comparison = np.modf(np.arange(start, end, step, np.float64)) + + # float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) + # float64_modf_distrbd = float64_tensor_distrbd.modf() + # self.assertIsInstance(float64_modf_distrbd[0], ht.DNDarray) + # self.assertIsInstance(float64_modf_distrbd[1], ht.DNDarray) + # self.assertEqual(float64_modf_distrbd[0].dtype, ht.float64) + # self.assertEqual(float64_modf_distrbd[1].dtype, ht.float64) + + # self.assertAlmostEqual(float64_modf_distrbd[0].numpy().all(), comparison[0].all()) + # self.assertAlmostEqual(float64_modf_distrbd[1].numpy().all(), comparison[1].all()) + + # self.assertAlmostEqual(ht.all(float64_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) + # self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) def test_round(self): size = ht.communication.MPI_WORLD.size From 9ef2614a834ea088218ecab415782f810243d81d Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Tue, 3 Dec 2019 14:24:20 +0100 Subject: [PATCH 25/40] Debugging. Removed test_modf() and test_round() --- heat/core/tests/test_rounding.py | 88 ++++++++++++++++---------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 894ee2bb4d..fda400b63a 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -243,56 +243,56 @@ def test_floor(self): # self.assertAlmostEqual(ht.all(float64_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) # self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) - def test_round(self): - size = ht.communication.MPI_WORLD.size - start, end = -5.0, 5.0 - step = (end - start) / (2 * size) - comparison = torch.arange(start, end, step, dtype=torch.float32).round() + # def test_round(self): + # size = ht.communication.MPI_WORLD.size + # start, end = -5.0, 5.0 + # step = (end - start) / (2 * size) + # comparison = torch.arange(start, end, step, dtype=torch.float32).round() - # exponential of float32 - float32_tensor = ht.arange(start, end, step, dtype=ht.float32) - float32_round = float32_tensor.round() - self.assertIsInstance(float32_round, ht.DNDarray) - self.assertEqual(float32_round.dtype, ht.float32) - self.assertEqual(float32_round.dtype, ht.float32) - self.assertTrue(ht.equal(float32_round, ht.array(comparison))) + # # exponential of float32 + # float32_tensor = ht.arange(start, end, step, dtype=ht.float32) + # float32_round = float32_tensor.round() + # self.assertIsInstance(float32_round, ht.DNDarray) + # self.assertEqual(float32_round.dtype, ht.float32) + # self.assertEqual(float32_round.dtype, ht.float32) + # self.assertTrue(ht.equal(float32_round, ht.array(comparison))) - # exponential of float64 - comparison = torch.arange(start, end, step, dtype=torch.float64).round() - float64_tensor = ht.arange(start, end, step, dtype=ht.float64) - float64_round = float64_tensor.round() - self.assertIsInstance(float64_round, ht.DNDarray) - self.assertEqual(float64_round.dtype, ht.float64) - self.assertEqual(float64_round.dtype, ht.float64) - self.assertTrue(ht.equal(float64_round, ht.array(comparison))) + # # exponential of float64 + # comparison = torch.arange(start, end, step, dtype=torch.float64).round() + # float64_tensor = ht.arange(start, end, step, dtype=ht.float64) + # float64_round = float64_tensor.round() + # self.assertIsInstance(float64_round, ht.DNDarray) + # self.assertEqual(float64_round.dtype, ht.float64) + # self.assertEqual(float64_round.dtype, ht.float64) + # self.assertTrue(ht.equal(float64_round, ht.array(comparison))) - # check exceptions - with self.assertRaises(TypeError): - ht.round([0, 1, 2, 3]) - with self.assertRaises(TypeError): - ht.round(object()) - with self.assertRaises(TypeError): - ht.round(float32_tensor, 1, 1) + # # check exceptions + # with self.assertRaises(TypeError): + # ht.round([0, 1, 2, 3]) + # with self.assertRaises(TypeError): + # ht.round(object()) + # with self.assertRaises(TypeError): + # ht.round(float32_tensor, 1, 1) - # with split tensors + # # with split tensors - # exponential of float32 - comparison = torch.arange(start, end, step, dtype=torch.float32).round() - float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) - float32_round_distrbd = float32_tensor_distrbd.round() - self.assertIsInstance(float32_round_distrbd, ht.DNDarray) - self.assertEqual(float32_round_distrbd.dtype, ht.float32) - self.assertEqual(float32_round_distrbd.dtype, ht.float32) - self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) + # # exponential of float32 + # comparison = torch.arange(start, end, step, dtype=torch.float32).round() + # float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) + # float32_round_distrbd = float32_tensor_distrbd.round() + # self.assertIsInstance(float32_round_distrbd, ht.DNDarray) + # self.assertEqual(float32_round_distrbd.dtype, ht.float32) + # self.assertEqual(float32_round_distrbd.dtype, ht.float32) + # self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) - # exponential of float64 - comparison = torch.arange(start, end, step, dtype=torch.float64).round() - float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) - float64_round_distrbd = float64_tensor_distrbd.round() - self.assertIsInstance(float64_round_distrbd, ht.DNDarray) - self.assertEqual(float64_round_distrbd.dtype, ht.float64) - self.assertEqual(float64_round_distrbd.dtype, ht.float64) - self.assertTrue(ht.equal(float64_round_distrbd, ht.array(comparison))) + # # exponential of float64 + # comparison = torch.arange(start, end, step, dtype=torch.float64).round() + # float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) + # float64_round_distrbd = float64_tensor_distrbd.round() + # self.assertIsInstance(float64_round_distrbd, ht.DNDarray) + # self.assertEqual(float64_round_distrbd.dtype, ht.float64) + # self.assertEqual(float64_round_distrbd.dtype, ht.float64) + # self.assertTrue(ht.equal(float64_round_distrbd, ht.array(comparison))) def test_trunc(self): base_array = np.random.randn(20) From 865b8686e56a2ce2e200a6a934dd5de69fa50595 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Tue, 3 Dec 2019 14:54:58 +0100 Subject: [PATCH 26/40] In assert_array_equal(), Allreduce running on self._comm, not on self.comm --- heat/core/tests/test_suites/basic_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heat/core/tests/test_suites/basic_test.py b/heat/core/tests/test_suites/basic_test.py index 5a6f19a241..eb1c402443 100644 --- a/heat/core/tests/test_suites/basic_test.py +++ b/heat/core/tests/test_suites/basic_test.py @@ -101,7 +101,7 @@ def assert_array_equal(self, heat_array, expected_array): # Array is distributed correctly equal_res = np.array(compare_func(local_numpy, expected_array[slices])) - self.comm.Allreduce(MPI.IN_PLACE, equal_res, MPI.LAND) + self._comm.Allreduce(MPI.IN_PLACE, equal_res, MPI.LAND) self.assertTrue(equal_res, "Local tensors do not match the corresponding numpy slices.") self.assertEqual( local_numpy.dtype, From d0613dc60ba5dd66c68106822ddd223e25953bb5 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Tue, 3 Dec 2019 14:56:39 +0100 Subject: [PATCH 27/40] Debugging. Replacing failing array comparison with BasicTest.assert_array_equal(). --- heat/core/tests/test_rounding.py | 91 +++++++++++++++++--------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index fda400b63a..13d96c8d1e 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -3,6 +3,8 @@ import numpy as np import heat as ht +from heat.core.tests.test_suites.basic_test import BasicTest + class TestRounding(unittest.TestCase): def test_abs(self): @@ -243,56 +245,57 @@ def test_floor(self): # self.assertAlmostEqual(ht.all(float64_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) # self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) - # def test_round(self): - # size = ht.communication.MPI_WORLD.size - # start, end = -5.0, 5.0 - # step = (end - start) / (2 * size) - # comparison = torch.arange(start, end, step, dtype=torch.float32).round() + def test_round(self): + size = ht.communication.MPI_WORLD.size + start, end = -5.0, 5.0 + step = (end - start) / (2 * size) + comparison = torch.arange(start, end, step, dtype=torch.float32).round() - # # exponential of float32 - # float32_tensor = ht.arange(start, end, step, dtype=ht.float32) - # float32_round = float32_tensor.round() - # self.assertIsInstance(float32_round, ht.DNDarray) - # self.assertEqual(float32_round.dtype, ht.float32) - # self.assertEqual(float32_round.dtype, ht.float32) - # self.assertTrue(ht.equal(float32_round, ht.array(comparison))) + # exponential of float32 + float32_tensor = ht.arange(start, end, step, dtype=ht.float32) + float32_round = float32_tensor.round() + self.assertIsInstance(float32_round, ht.DNDarray) + self.assertEqual(float32_round.dtype, ht.float32) + self.assertEqual(float32_round.dtype, ht.float32) + self.assertTrue(ht.equal(float32_round, ht.array(comparison))) - # # exponential of float64 - # comparison = torch.arange(start, end, step, dtype=torch.float64).round() - # float64_tensor = ht.arange(start, end, step, dtype=ht.float64) - # float64_round = float64_tensor.round() - # self.assertIsInstance(float64_round, ht.DNDarray) - # self.assertEqual(float64_round.dtype, ht.float64) - # self.assertEqual(float64_round.dtype, ht.float64) - # self.assertTrue(ht.equal(float64_round, ht.array(comparison))) + # exponential of float64 + comparison = torch.arange(start, end, step, dtype=torch.float64).round() + float64_tensor = ht.arange(start, end, step, dtype=ht.float64) + float64_round = float64_tensor.round() + self.assertIsInstance(float64_round, ht.DNDarray) + self.assertEqual(float64_round.dtype, ht.float64) + self.assertEqual(float64_round.dtype, ht.float64) + BasicTest.assert_array_equal(self, float64_round, comparison) + # self.assertTrue(ht.equal(float64_round, ht.array(comparison))) - # # check exceptions - # with self.assertRaises(TypeError): - # ht.round([0, 1, 2, 3]) - # with self.assertRaises(TypeError): - # ht.round(object()) - # with self.assertRaises(TypeError): - # ht.round(float32_tensor, 1, 1) + # check exceptions + with self.assertRaises(TypeError): + ht.round([0, 1, 2, 3]) + with self.assertRaises(TypeError): + ht.round(object()) + with self.assertRaises(TypeError): + ht.round(float32_tensor, 1, 1) - # # with split tensors + # with split tensors - # # exponential of float32 - # comparison = torch.arange(start, end, step, dtype=torch.float32).round() - # float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) - # float32_round_distrbd = float32_tensor_distrbd.round() - # self.assertIsInstance(float32_round_distrbd, ht.DNDarray) - # self.assertEqual(float32_round_distrbd.dtype, ht.float32) - # self.assertEqual(float32_round_distrbd.dtype, ht.float32) - # self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) + # exponential of float32 + comparison = torch.arange(start, end, step, dtype=torch.float32).round() + float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) + float32_round_distrbd = float32_tensor_distrbd.round() + self.assertIsInstance(float32_round_distrbd, ht.DNDarray) + self.assertEqual(float32_round_distrbd.dtype, ht.float32) + self.assertEqual(float32_round_distrbd.dtype, ht.float32) + self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) - # # exponential of float64 - # comparison = torch.arange(start, end, step, dtype=torch.float64).round() - # float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) - # float64_round_distrbd = float64_tensor_distrbd.round() - # self.assertIsInstance(float64_round_distrbd, ht.DNDarray) - # self.assertEqual(float64_round_distrbd.dtype, ht.float64) - # self.assertEqual(float64_round_distrbd.dtype, ht.float64) - # self.assertTrue(ht.equal(float64_round_distrbd, ht.array(comparison))) + # exponential of float64 + comparison = torch.arange(start, end, step, dtype=torch.float64).round() + float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) + float64_round_distrbd = float64_tensor_distrbd.round() + self.assertIsInstance(float64_round_distrbd, ht.DNDarray) + self.assertEqual(float64_round_distrbd.dtype, ht.float64) + self.assertEqual(float64_round_distrbd.dtype, ht.float64) + self.assertTrue(ht.equal(float64_round_distrbd, ht.array(comparison))) def test_trunc(self): base_array = np.random.randn(20) From bdc5be2cec4eb9318a37b09c1c842742ce218697 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Tue, 3 Dec 2019 15:10:53 +0100 Subject: [PATCH 28/40] rest_round(), replacing all assertTrue(ht.equal(...)) with BasicTest.assert_array_equal() --- heat/core/tests/test_rounding.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 13d96c8d1e..313afc5d6f 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -257,7 +257,8 @@ def test_round(self): self.assertIsInstance(float32_round, ht.DNDarray) self.assertEqual(float32_round.dtype, ht.float32) self.assertEqual(float32_round.dtype, ht.float32) - self.assertTrue(ht.equal(float32_round, ht.array(comparison))) + BasicTest.assert_array_equal(self, float32_round, comparison) + # self.assertTrue(ht.equal(float32_round, ht.array(comparison))) # exponential of float64 comparison = torch.arange(start, end, step, dtype=torch.float64).round() @@ -286,7 +287,8 @@ def test_round(self): self.assertIsInstance(float32_round_distrbd, ht.DNDarray) self.assertEqual(float32_round_distrbd.dtype, ht.float32) self.assertEqual(float32_round_distrbd.dtype, ht.float32) - self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) + BasicTest.assert_array_equal(self, float32_round_distrbd, comparison) + # self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) # exponential of float64 comparison = torch.arange(start, end, step, dtype=torch.float64).round() @@ -295,7 +297,8 @@ def test_round(self): self.assertIsInstance(float64_round_distrbd, ht.DNDarray) self.assertEqual(float64_round_distrbd.dtype, ht.float64) self.assertEqual(float64_round_distrbd.dtype, ht.float64) - self.assertTrue(ht.equal(float64_round_distrbd, ht.array(comparison))) + BasicTest.assert_array_equal(self, float64_round_distrbd, comparison) + # self.assertTrue(ht.equal(float64_round_distrbd, ht.array(comparison))) def test_trunc(self): base_array = np.random.randn(20) From 30464c325e548ff99a32bcc64f9eda3dd7eb24e3 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Tue, 3 Dec 2019 15:31:00 +0100 Subject: [PATCH 29/40] Debugging. test_round(), remiving distributed tests --- heat/core/tests/test_rounding.py | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 313afc5d6f..b697447e68 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -280,25 +280,25 @@ def test_round(self): # with split tensors - # exponential of float32 - comparison = torch.arange(start, end, step, dtype=torch.float32).round() - float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) - float32_round_distrbd = float32_tensor_distrbd.round() - self.assertIsInstance(float32_round_distrbd, ht.DNDarray) - self.assertEqual(float32_round_distrbd.dtype, ht.float32) - self.assertEqual(float32_round_distrbd.dtype, ht.float32) - BasicTest.assert_array_equal(self, float32_round_distrbd, comparison) - # self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) - - # exponential of float64 - comparison = torch.arange(start, end, step, dtype=torch.float64).round() - float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) - float64_round_distrbd = float64_tensor_distrbd.round() - self.assertIsInstance(float64_round_distrbd, ht.DNDarray) - self.assertEqual(float64_round_distrbd.dtype, ht.float64) - self.assertEqual(float64_round_distrbd.dtype, ht.float64) - BasicTest.assert_array_equal(self, float64_round_distrbd, comparison) - # self.assertTrue(ht.equal(float64_round_distrbd, ht.array(comparison))) + # # exponential of float32 + # comparison = torch.arange(start, end, step, dtype=torch.float32).round() + # float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) + # float32_round_distrbd = float32_tensor_distrbd.round() + # self.assertIsInstance(float32_round_distrbd, ht.DNDarray) + # self.assertEqual(float32_round_distrbd.dtype, ht.float32) + # self.assertEqual(float32_round_distrbd.dtype, ht.float32) + # BasicTest.assert_array_equal(self, float32_round_distrbd, comparison) + # # self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) + + # # exponential of float64 + # comparison = torch.arange(start, end, step, dtype=torch.float64).round() + # float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) + # float64_round_distrbd = float64_tensor_distrbd.round() + # self.assertIsInstance(float64_round_distrbd, ht.DNDarray) + # self.assertEqual(float64_round_distrbd.dtype, ht.float64) + # self.assertEqual(float64_round_distrbd.dtype, ht.float64) + # BasicTest.assert_array_equal(self, float64_round_distrbd, comparison) + # # self.assertTrue(ht.equal(float64_round_distrbd, ht.array(comparison))) def test_trunc(self): base_array = np.random.randn(20) From c5810a600f15ed9c6d69984dfc84e7d0147189ad Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Tue, 3 Dec 2019 15:42:20 +0100 Subject: [PATCH 30/40] Debugging. Adding back distributed test_round one bit at a time. --- heat/core/tests/test_rounding.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index b697447e68..dbac846b2d 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -280,14 +280,13 @@ def test_round(self): # with split tensors - # # exponential of float32 - # comparison = torch.arange(start, end, step, dtype=torch.float32).round() - # float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) + # exponential of float32 + comparison = torch.arange(start, end, step, dtype=torch.float32) # .round() + float32_tensor_distrbd = ht.array(comparison, split=0) # float32_round_distrbd = float32_tensor_distrbd.round() - # self.assertIsInstance(float32_round_distrbd, ht.DNDarray) - # self.assertEqual(float32_round_distrbd.dtype, ht.float32) - # self.assertEqual(float32_round_distrbd.dtype, ht.float32) - # BasicTest.assert_array_equal(self, float32_round_distrbd, comparison) + self.assertIsInstance(float32_distrbd.round(), ht.DNDarray) + self.assertEqual(float32_distrbd.round().dtype, ht.float32) + BasicTest.assert_array_equal(self, float32_round_distrbd.round(), comparison.round()) # # self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) # # exponential of float64 From 3ecd8505d55a25108375082c61b05994e981e373 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Tue, 3 Dec 2019 15:49:30 +0100 Subject: [PATCH 31/40] Small changes after pre-commit failed. --- heat/core/tests/test_rounding.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index dbac846b2d..b3ba34c645 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -283,10 +283,11 @@ def test_round(self): # exponential of float32 comparison = torch.arange(start, end, step, dtype=torch.float32) # .round() float32_tensor_distrbd = ht.array(comparison, split=0) - # float32_round_distrbd = float32_tensor_distrbd.round() - self.assertIsInstance(float32_distrbd.round(), ht.DNDarray) - self.assertEqual(float32_distrbd.round().dtype, ht.float32) - BasicTest.assert_array_equal(self, float32_round_distrbd.round(), comparison.round()) + comparison = comparison.round() + float32_round_distrbd = float32_tensor_distrbd.round() + self.assertIsInstance(float32_round_distrbd, ht.DNDarray) + self.assertEqual(float32_round_distrbd.dtype, ht.float32) + BasicTest.assert_array_equal(self, float32_round_distrbd, comparison) # # self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) # # exponential of float64 From c383c78acb4c35f0a5432e79dc84d2db3b15b16a Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Tue, 3 Dec 2019 15:59:59 +0100 Subject: [PATCH 32/40] Debugging. Adding back distributed tests for test_round(). Replaced ht.arange(start, end, step, etc....) with ht.array(comparison, split=0). --- heat/core/tests/test_rounding.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index b3ba34c645..74bdb7dafb 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -258,7 +258,6 @@ def test_round(self): self.assertEqual(float32_round.dtype, ht.float32) self.assertEqual(float32_round.dtype, ht.float32) BasicTest.assert_array_equal(self, float32_round, comparison) - # self.assertTrue(ht.equal(float32_round, ht.array(comparison))) # exponential of float64 comparison = torch.arange(start, end, step, dtype=torch.float64).round() @@ -268,7 +267,6 @@ def test_round(self): self.assertEqual(float64_round.dtype, ht.float64) self.assertEqual(float64_round.dtype, ht.float64) BasicTest.assert_array_equal(self, float64_round, comparison) - # self.assertTrue(ht.equal(float64_round, ht.array(comparison))) # check exceptions with self.assertRaises(TypeError): @@ -288,17 +286,16 @@ def test_round(self): self.assertIsInstance(float32_round_distrbd, ht.DNDarray) self.assertEqual(float32_round_distrbd.dtype, ht.float32) BasicTest.assert_array_equal(self, float32_round_distrbd, comparison) - # # self.assertTrue(ht.equal(float32_round_distrbd, ht.array(comparison))) - - # # exponential of float64 - # comparison = torch.arange(start, end, step, dtype=torch.float64).round() - # float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) - # float64_round_distrbd = float64_tensor_distrbd.round() - # self.assertIsInstance(float64_round_distrbd, ht.DNDarray) - # self.assertEqual(float64_round_distrbd.dtype, ht.float64) - # self.assertEqual(float64_round_distrbd.dtype, ht.float64) - # BasicTest.assert_array_equal(self, float64_round_distrbd, comparison) - # # self.assertTrue(ht.equal(float64_round_distrbd, ht.array(comparison))) + + # exponential of float64 + comparison = torch.arange(start, end, step, dtype=torch.float64) # .round() + float64_tensor_distrbd = ht.array(comparison, split=0) + comparison = comparison.round() + float64_round_distrbd = float64_tensor_distrbd.round() + self.assertIsInstance(float64_round_distrbd, ht.DNDarray) + self.assertEqual(float64_round_distrbd.dtype, ht.float64) + self.assertEqual(float64_round_distrbd.dtype, ht.float64) + BasicTest.assert_array_equal(self, float64_round_distrbd, comparison) def test_trunc(self): base_array = np.random.randn(20) From 7f5e34bf227dd1b7e95c39c345ef61b1ad33fbd9 Mon Sep 17 00:00:00 2001 From: blind1 Date: Wed, 4 Dec 2019 08:27:25 +0100 Subject: [PATCH 33/40] Replaced ht.arange with ht.array for non-distribution case --- heat/core/tests/test_rounding.py | 162 +++++++++++++++---------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 74bdb7dafb..52a55f256c 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -165,85 +165,85 @@ def test_floor(self): ht.floor(object()) # def test_modf(self): - # size = ht.communication.MPI_WORLD.size - # start, end = -5.0, 5.0 - # step = (end - start) / (2 * size) - # comparison = np.modf(np.arange(start, end, step, np.float32)) - - # # exponential of float32 - # float32_tensor = ht.arange(start, end, step, dtype=ht.float32) - # float32_modf = float32_tensor.modf() - # self.assertIsInstance(float32_modf[0], ht.DNDarray) - # self.assertIsInstance(float32_modf[1], ht.DNDarray) - # self.assertEqual(float32_modf[0].dtype, ht.float32) - # self.assertEqual(float32_modf[1].dtype, ht.float32) - - # self.assertAlmostEqual(float32_modf[0].numpy().all(), comparison[0].all()) - # self.assertAlmostEqual(float32_modf[1].numpy().all(), comparison[1].all()) - - # self.assertAlmostEqual(ht.all(float32_modf[0]), ht.all(ht.array(comparison[0]))) - # self.assertAlmostEqual(ht.all(float32_modf[1]), ht.all(ht.array(comparison[1]))) - - # # exponential of float64 - # comparison = np.modf(np.arange(start, end, step, np.float64)) - - # float64_tensor = ht.arange(start, end, step, dtype=ht.float64) - # float64_modf = float64_tensor.modf() - # self.assertIsInstance(float64_modf[0], ht.DNDarray) - # self.assertIsInstance(float64_modf[1], ht.DNDarray) - # self.assertEqual(float64_modf[0].dtype, ht.float64) - # self.assertEqual(float64_modf[1].dtype, ht.float64) - - # self.assertAlmostEqual(float64_modf[0].numpy().all(), comparison[0].all()) - # self.assertAlmostEqual(float64_modf[1].numpy().all(), comparison[1].all()) - - # self.assertAlmostEqual(ht.all(float64_modf[0]), ht.all(ht.array(comparison[0]))) - # self.assertAlmostEqual(ht.all(float64_modf[1]), ht.all(ht.array(comparison[1]))) - - # # check exceptions - # with self.assertRaises(TypeError): - # ht.modf([0, 1, 2, 3]) - # with self.assertRaises(TypeError): - # ht.modf(object()) - # with self.assertRaises(TypeError): - # ht.modf(float32_tensor, 1) - # with self.assertRaises(ValueError): - # ht.modf(float32_tensor, (float32_tensor, float32_tensor, float64_tensor)) - # with self.assertRaises(TypeError): - # ht.modf(float32_tensor, (float32_tensor, 2)) - - # # with split tensors - - # # exponential of float32 - # float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) - # float32_modf_distrbd = float32_tensor_distrbd.modf() - - # self.assertIsInstance(float32_modf_distrbd[0], ht.DNDarray) - # self.assertIsInstance(float32_modf_distrbd[1], ht.DNDarray) - # self.assertEqual(float32_modf_distrbd[0].dtype, ht.float32) - # self.assertEqual(float32_modf_distrbd[1].dtype, ht.float32) - - # self.assertAlmostEqual(float32_modf_distrbd[0].numpy().all(), comparison[0].all()) - # self.assertAlmostEqual(float32_modf_distrbd[1].numpy().all(), comparison[1].all()) - - # self.assertAlmostEqual(ht.all(float32_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) - # self.assertAlmostEqual(ht.all(float32_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) - - # # exponential of float64 - # comparison = np.modf(np.arange(start, end, step, np.float64)) - - # float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) - # float64_modf_distrbd = float64_tensor_distrbd.modf() - # self.assertIsInstance(float64_modf_distrbd[0], ht.DNDarray) - # self.assertIsInstance(float64_modf_distrbd[1], ht.DNDarray) - # self.assertEqual(float64_modf_distrbd[0].dtype, ht.float64) - # self.assertEqual(float64_modf_distrbd[1].dtype, ht.float64) - - # self.assertAlmostEqual(float64_modf_distrbd[0].numpy().all(), comparison[0].all()) - # self.assertAlmostEqual(float64_modf_distrbd[1].numpy().all(), comparison[1].all()) - - # self.assertAlmostEqual(ht.all(float64_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) - # self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) + # size = ht.communication.MPI_WORLD.size + # start, end = -5.0, 5.0 + # step = (end - start) / (2 * size) + # comparison = np.modf(np.arange(start, end, step, np.float32)) + # + # # exponential of float32 + # float32_tensor = ht.arange(start, end, step, dtype=ht.float32) + # float32_modf = float32_tensor.modf() + # self.assertIsInstance(float32_modf[0], ht.DNDarray) + # self.assertIsInstance(float32_modf[1], ht.DNDarray) + # self.assertEqual(float32_modf[0].dtype, ht.float32) + # self.assertEqual(float32_modf[1].dtype, ht.float32) + # + # self.assertAlmostEqual(float32_modf[0].numpy().all(), comparison[0].all()) + # self.assertAlmostEqual(float32_modf[1].numpy().all(), comparison[1].all()) + # + # self.assertAlmostEqual(ht.all(float32_modf[0]), ht.all(ht.array(comparison[0]))) + # self.assertAlmostEqual(ht.all(float32_modf[1]), ht.all(ht.array(comparison[1]))) + # + # # exponential of float64 + # comparison = np.modf(np.arange(start, end, step, np.float64)) + # + # float64_tensor = ht.arange(start, end, step, dtype=ht.float64) + # float64_modf = float64_tensor.modf() + # self.assertIsInstance(float64_modf[0], ht.DNDarray) + # self.assertIsInstance(float64_modf[1], ht.DNDarray) + # self.assertEqual(float64_modf[0].dtype, ht.float64) + # self.assertEqual(float64_modf[1].dtype, ht.float64) + # + # self.assertAlmostEqual(float64_modf[0].numpy().all(), comparison[0].all()) + # self.assertAlmostEqual(float64_modf[1].numpy().all(), comparison[1].all()) + # + # self.assertAlmostEqual(ht.all(float64_modf[0]), ht.all(ht.array(comparison[0]))) + # self.assertAlmostEqual(ht.all(float64_modf[1]), ht.all(ht.array(comparison[1]))) + # + # # check exceptions + # with self.assertRaises(TypeError): + # ht.modf([0, 1, 2, 3]) + # with self.assertRaises(TypeError): + # ht.modf(object()) + # with self.assertRaises(TypeError): + # ht.modf(float32_tensor, 1) + # with self.assertRaises(ValueError): + # ht.modf(float32_tensor, (float32_tensor, float32_tensor, float64_tensor)) + # with self.assertRaises(TypeError): + # ht.modf(float32_tensor, (float32_tensor, 2)) + # + # # # with split tensors + # + # # exponential of float32 + # float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) + # float32_modf_distrbd = float32_tensor_distrbd.modf() + # + # self.assertIsInstance(float32_modf_distrbd[0], ht.DNDarray) + # self.assertIsInstance(float32_modf_distrbd[1], ht.DNDarray) + # self.assertEqual(float32_modf_distrbd[0].dtype, ht.float32) + # self.assertEqual(float32_modf_distrbd[1].dtype, ht.float32) + # + # self.assertAlmostEqual(float32_modf_distrbd[0].numpy().all(), comparison[0].all()) + # self.assertAlmostEqual(float32_modf_distrbd[1].numpy().all(), comparison[1].all()) + # + # self.assertAlmostEqual(ht.all(float32_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) + # self.assertAlmostEqual(ht.all(float32_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) + # + # # exponential of float64 + # comparison = np.modf(np.arange(start, end, step, np.float64)) + # + # float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) + # float64_modf_distrbd = float64_tensor_distrbd.modf() + # self.assertIsInstance(float64_modf_distrbd[0], ht.DNDarray) + # self.assertIsInstance(float64_modf_distrbd[1], ht.DNDarray) + # self.assertEqual(float64_modf_distrbd[0].dtype, ht.float64) + # self.assertEqual(float64_modf_distrbd[1].dtype, ht.float64) + # + # self.assertAlmostEqual(float64_modf_distrbd[0].numpy().all(), comparison[0].all()) + # self.assertAlmostEqual(float64_modf_distrbd[1].numpy().all(), comparison[1].all()) + # + # self.assertAlmostEqual(ht.all(float64_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) + # self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) def test_round(self): size = ht.communication.MPI_WORLD.size @@ -252,7 +252,7 @@ def test_round(self): comparison = torch.arange(start, end, step, dtype=torch.float32).round() # exponential of float32 - float32_tensor = ht.arange(start, end, step, dtype=ht.float32) + float32_tensor = ht.array(comparison, dtype=ht.float32) float32_round = float32_tensor.round() self.assertIsInstance(float32_round, ht.DNDarray) self.assertEqual(float32_round.dtype, ht.float32) @@ -261,7 +261,7 @@ def test_round(self): # exponential of float64 comparison = torch.arange(start, end, step, dtype=torch.float64).round() - float64_tensor = ht.arange(start, end, step, dtype=ht.float64) + float64_tensor = ht.array(comparison, dtype=ht.float64) float64_round = float64_tensor.round() self.assertIsInstance(float64_round, ht.DNDarray) self.assertEqual(float64_round.dtype, ht.float64) From 567c2e4da1522ec30c605fdf37818e4536376daa Mon Sep 17 00:00:00 2001 From: blind1 Date: Wed, 4 Dec 2019 11:01:10 +0100 Subject: [PATCH 34/40] Changed inheritance hierarchy of test_rounding to BasicTest --- heat/core/tests/test_rounding.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 52a55f256c..5b934b6c7d 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -6,7 +6,7 @@ from heat.core.tests.test_suites.basic_test import BasicTest -class TestRounding(unittest.TestCase): +class TestRounding(BasicTest): def test_abs(self): # for abs==absolute float32_tensor = ht.arange(-10, 10, dtype=ht.float32, split=0) @@ -168,18 +168,24 @@ def test_floor(self): # size = ht.communication.MPI_WORLD.size # start, end = -5.0, 5.0 # step = (end - start) / (2 * size) - # comparison = np.modf(np.arange(start, end, step, np.float32)) + # comparison=np.arange(start, end, step, dtype=np.float32) # # # exponential of float32 - # float32_tensor = ht.arange(start, end, step, dtype=ht.float32) + # float32_tensor = ht.array(comparison, dtype=ht.float32) # float32_modf = float32_tensor.modf() # self.assertIsInstance(float32_modf[0], ht.DNDarray) # self.assertIsInstance(float32_modf[1], ht.DNDarray) # self.assertEqual(float32_modf[0].dtype, ht.float32) # self.assertEqual(float32_modf[1].dtype, ht.float32) # - # self.assertAlmostEqual(float32_modf[0].numpy().all(), comparison[0].all()) - # self.assertAlmostEqual(float32_modf[1].numpy().all(), comparison[1].all()) + # self.assert_func_equal( + # comparison, + # heat_func=ht.modf, + # numpy_func=np.modf + # ) + # + # #self.assertAlmostEqual(float32_modf[0].numpy().all(), comparison[0].all()) + # #self.assertAlmostEqual(float32_modf[1].numpy().all(), comparison[1].all()) # # self.assertAlmostEqual(ht.all(float32_modf[0]), ht.all(ht.array(comparison[0]))) # self.assertAlmostEqual(ht.all(float32_modf[1]), ht.all(ht.array(comparison[1]))) @@ -187,7 +193,7 @@ def test_floor(self): # # exponential of float64 # comparison = np.modf(np.arange(start, end, step, np.float64)) # - # float64_tensor = ht.arange(start, end, step, dtype=ht.float64) + # float64_tensor = ht.array(comparison, dtype=ht.float64) # float64_modf = float64_tensor.modf() # self.assertIsInstance(float64_modf[0], ht.DNDarray) # self.assertIsInstance(float64_modf[1], ht.DNDarray) @@ -212,7 +218,7 @@ def test_floor(self): # with self.assertRaises(TypeError): # ht.modf(float32_tensor, (float32_tensor, 2)) # - # # # with split tensors + # # with split tensors # # # exponential of float32 # float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) @@ -257,7 +263,7 @@ def test_round(self): self.assertIsInstance(float32_round, ht.DNDarray) self.assertEqual(float32_round.dtype, ht.float32) self.assertEqual(float32_round.dtype, ht.float32) - BasicTest.assert_array_equal(self, float32_round, comparison) + self.assert_array_equal(float32_round, comparison) # exponential of float64 comparison = torch.arange(start, end, step, dtype=torch.float64).round() @@ -266,7 +272,7 @@ def test_round(self): self.assertIsInstance(float64_round, ht.DNDarray) self.assertEqual(float64_round.dtype, ht.float64) self.assertEqual(float64_round.dtype, ht.float64) - BasicTest.assert_array_equal(self, float64_round, comparison) + self.assert_array_equal(float64_round, comparison) # check exceptions with self.assertRaises(TypeError): @@ -285,7 +291,7 @@ def test_round(self): float32_round_distrbd = float32_tensor_distrbd.round() self.assertIsInstance(float32_round_distrbd, ht.DNDarray) self.assertEqual(float32_round_distrbd.dtype, ht.float32) - BasicTest.assert_array_equal(self, float32_round_distrbd, comparison) + self.assert_array_equal(float32_round_distrbd, comparison) # exponential of float64 comparison = torch.arange(start, end, step, dtype=torch.float64) # .round() @@ -295,7 +301,7 @@ def test_round(self): self.assertIsInstance(float64_round_distrbd, ht.DNDarray) self.assertEqual(float64_round_distrbd.dtype, ht.float64) self.assertEqual(float64_round_distrbd.dtype, ht.float64) - BasicTest.assert_array_equal(self, float64_round_distrbd, comparison) + self.assert_array_equal(float64_round_distrbd, comparison) def test_trunc(self): base_array = np.random.randn(20) From 05b319cbd9c7f3da68ac41a0bbd16aa47b56d1dc Mon Sep 17 00:00:00 2001 From: blind1 Date: Wed, 4 Dec 2019 11:35:40 +0100 Subject: [PATCH 35/40] Integration of assert_array_equal within test_round --- heat/core/tests/test_rounding.py | 159 ++++++++++++++----------------- 1 file changed, 73 insertions(+), 86 deletions(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 5b934b6c7d..90eb8cc8b7 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -164,92 +164,79 @@ def test_floor(self): with self.assertRaises(TypeError): ht.floor(object()) - # def test_modf(self): - # size = ht.communication.MPI_WORLD.size - # start, end = -5.0, 5.0 - # step = (end - start) / (2 * size) - # comparison=np.arange(start, end, step, dtype=np.float32) - # - # # exponential of float32 - # float32_tensor = ht.array(comparison, dtype=ht.float32) - # float32_modf = float32_tensor.modf() - # self.assertIsInstance(float32_modf[0], ht.DNDarray) - # self.assertIsInstance(float32_modf[1], ht.DNDarray) - # self.assertEqual(float32_modf[0].dtype, ht.float32) - # self.assertEqual(float32_modf[1].dtype, ht.float32) - # - # self.assert_func_equal( - # comparison, - # heat_func=ht.modf, - # numpy_func=np.modf - # ) - # - # #self.assertAlmostEqual(float32_modf[0].numpy().all(), comparison[0].all()) - # #self.assertAlmostEqual(float32_modf[1].numpy().all(), comparison[1].all()) - # - # self.assertAlmostEqual(ht.all(float32_modf[0]), ht.all(ht.array(comparison[0]))) - # self.assertAlmostEqual(ht.all(float32_modf[1]), ht.all(ht.array(comparison[1]))) - # - # # exponential of float64 - # comparison = np.modf(np.arange(start, end, step, np.float64)) - # - # float64_tensor = ht.array(comparison, dtype=ht.float64) - # float64_modf = float64_tensor.modf() - # self.assertIsInstance(float64_modf[0], ht.DNDarray) - # self.assertIsInstance(float64_modf[1], ht.DNDarray) - # self.assertEqual(float64_modf[0].dtype, ht.float64) - # self.assertEqual(float64_modf[1].dtype, ht.float64) - # - # self.assertAlmostEqual(float64_modf[0].numpy().all(), comparison[0].all()) - # self.assertAlmostEqual(float64_modf[1].numpy().all(), comparison[1].all()) - # - # self.assertAlmostEqual(ht.all(float64_modf[0]), ht.all(ht.array(comparison[0]))) - # self.assertAlmostEqual(ht.all(float64_modf[1]), ht.all(ht.array(comparison[1]))) - # - # # check exceptions - # with self.assertRaises(TypeError): - # ht.modf([0, 1, 2, 3]) - # with self.assertRaises(TypeError): - # ht.modf(object()) - # with self.assertRaises(TypeError): - # ht.modf(float32_tensor, 1) - # with self.assertRaises(ValueError): - # ht.modf(float32_tensor, (float32_tensor, float32_tensor, float64_tensor)) - # with self.assertRaises(TypeError): - # ht.modf(float32_tensor, (float32_tensor, 2)) - # - # # with split tensors - # - # # exponential of float32 - # float32_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float32, split=0) - # float32_modf_distrbd = float32_tensor_distrbd.modf() - # - # self.assertIsInstance(float32_modf_distrbd[0], ht.DNDarray) - # self.assertIsInstance(float32_modf_distrbd[1], ht.DNDarray) - # self.assertEqual(float32_modf_distrbd[0].dtype, ht.float32) - # self.assertEqual(float32_modf_distrbd[1].dtype, ht.float32) - # - # self.assertAlmostEqual(float32_modf_distrbd[0].numpy().all(), comparison[0].all()) - # self.assertAlmostEqual(float32_modf_distrbd[1].numpy().all(), comparison[1].all()) - # - # self.assertAlmostEqual(ht.all(float32_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) - # self.assertAlmostEqual(ht.all(float32_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) - # - # # exponential of float64 - # comparison = np.modf(np.arange(start, end, step, np.float64)) - # - # float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) - # float64_modf_distrbd = float64_tensor_distrbd.modf() - # self.assertIsInstance(float64_modf_distrbd[0], ht.DNDarray) - # self.assertIsInstance(float64_modf_distrbd[1], ht.DNDarray) - # self.assertEqual(float64_modf_distrbd[0].dtype, ht.float64) - # self.assertEqual(float64_modf_distrbd[1].dtype, ht.float64) - # - # self.assertAlmostEqual(float64_modf_distrbd[0].numpy().all(), comparison[0].all()) - # self.assertAlmostEqual(float64_modf_distrbd[1].numpy().all(), comparison[1].all()) - # - # self.assertAlmostEqual(ht.all(float64_modf_distrbd[0]), ht.all(ht.array(comparison[0]))) - # self.assertAlmostEqual(ht.all(float64_modf_distrbd[1]), ht.all(ht.array(comparison[1]))) + def test_modf(self): + size = ht.communication.MPI_WORLD.size + start, end = -5.0, 5.0 + step = (end - start) / (2 * size) + npArray = np.arange(start, end, step, dtype=np.float32) + comparison = np.modf(npArray) + + # exponential of float32 + float32_tensor = ht.array(npArray, dtype=ht.float32) + float32_modf = float32_tensor.modf() + self.assertIsInstance(float32_modf[0], ht.DNDarray) + self.assertIsInstance(float32_modf[1], ht.DNDarray) + self.assertEqual(float32_modf[0].dtype, ht.float32) + self.assertEqual(float32_modf[1].dtype, ht.float32) + + self.assert_array_equal(float32_modf[0], comparison[0]) + self.assert_array_equal(float32_modf[1], comparison[1]) + + # exponential of float64 + npArray = np.arange(start, end, step, np.float64) + comparison = np.modf(npArray) + + float64_tensor = ht.array(npArray, dtype=ht.float64) + float64_modf = float64_tensor.modf() + self.assertIsInstance(float64_modf[0], ht.DNDarray) + self.assertIsInstance(float64_modf[1], ht.DNDarray) + self.assertEqual(float64_modf[0].dtype, ht.float64) + self.assertEqual(float64_modf[1].dtype, ht.float64) + + self.assert_array_equal(float64_modf[0], comparison[0]) + self.assert_array_equal(float64_modf[1], comparison[1]) + + # check exceptions + with self.assertRaises(TypeError): + ht.modf([0, 1, 2, 3]) + with self.assertRaises(TypeError): + ht.modf(object()) + with self.assertRaises(TypeError): + ht.modf(float32_tensor, 1) + with self.assertRaises(ValueError): + ht.modf(float32_tensor, (float32_tensor, float32_tensor, float64_tensor)) + with self.assertRaises(TypeError): + ht.modf(float32_tensor, (float32_tensor, 2)) + + # with split tensors + + # exponential of float32 + npArray = np.arange(start, end, step, dtype=np.float32) + comparison = np.modf(npArray) + float32_tensor_distrbd = ht.array(npArray, split=0) + float32_modf_distrbd = float32_tensor_distrbd.modf() + + self.assertIsInstance(float32_modf_distrbd[0], ht.DNDarray) + self.assertIsInstance(float32_modf_distrbd[1], ht.DNDarray) + self.assertEqual(float32_modf_distrbd[0].dtype, ht.float32) + self.assertEqual(float32_modf_distrbd[1].dtype, ht.float32) + + self.assert_array_equal(float32_modf_distrbd[0], comparison[0]) + self.assert_array_equal(float32_modf_distrbd[1], comparison[1]) + + # exponential of float64 + npArray = npArray = np.arange(start, end, step, np.float64) + comparison = np.modf(npArray) + + float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) + float64_modf_distrbd = float64_tensor_distrbd.modf() + self.assertIsInstance(float64_modf_distrbd[0], ht.DNDarray) + self.assertIsInstance(float64_modf_distrbd[1], ht.DNDarray) + self.assertEqual(float64_modf_distrbd[0].dtype, ht.float64) + self.assertEqual(float64_modf_distrbd[1].dtype, ht.float64) + + self.assert_array_equal(float64_modf_distrbd[0], comparison[0]) + self.assert_array_equal(float64_modf_distrbd[1], comparison[1]) def test_round(self): size = ht.communication.MPI_WORLD.size From 58ac9db166f59708c37365a175146e2868951bf2 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Fri, 6 Dec 2019 09:41:42 +0100 Subject: [PATCH 36/40] Replacing ht.arange with ht.array(npArray) --- heat/core/tests/test_rounding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 90eb8cc8b7..7ccdb889ca 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -228,7 +228,7 @@ def test_modf(self): npArray = npArray = np.arange(start, end, step, np.float64) comparison = np.modf(npArray) - float64_tensor_distrbd = ht.arange(start, end, step, dtype=ht.float64, split=0) + float64_tensor_distrbd = ht.array(npArray, split=0) float64_modf_distrbd = float64_tensor_distrbd.modf() self.assertIsInstance(float64_modf_distrbd[0], ht.DNDarray) self.assertIsInstance(float64_modf_distrbd[1], ht.DNDarray) From 9356e818872341e90583c7c0f45a584ee285b431 Mon Sep 17 00:00:00 2001 From: coquelin77 Date: Fri, 6 Dec 2019 16:38:31 +0100 Subject: [PATCH 37/40] extending coverage --- heat/core/rounding.py | 2 +- heat/core/tests/test_rounding.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/heat/core/rounding.py b/heat/core/rounding.py index b9577b9812..ba32b28723 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -209,7 +209,7 @@ def modf(x, out=None): """ if not isinstance(x, dndarray.DNDarray): - raise TypeError("expected x to be a ht.DNDarray, but was {}".format(type(out))) + raise TypeError("expected x to be a ht.DNDarray, but was {}".format(type(x))) integralParts = trunc(x) fractionalParts = x - integralParts diff --git a/heat/core/tests/test_rounding.py b/heat/core/tests/test_rounding.py index 7ccdb889ca..77dafbd69e 100644 --- a/heat/core/tests/test_rounding.py +++ b/heat/core/tests/test_rounding.py @@ -229,7 +229,12 @@ def test_modf(self): comparison = np.modf(npArray) float64_tensor_distrbd = ht.array(npArray, split=0) - float64_modf_distrbd = float64_tensor_distrbd.modf() + float64_modf_distrbd = ( + ht.zeros_like(float64_tensor_distrbd, dtype=float64_tensor_distrbd.dtype), + ht.zeros_like(float64_tensor_distrbd, dtype=float64_tensor_distrbd.dtype), + ) + # float64_modf_distrbd = float64_tensor_distrbd.modf() + float64_tensor_distrbd.modf(out=float64_modf_distrbd) self.assertIsInstance(float64_modf_distrbd[0], ht.DNDarray) self.assertIsInstance(float64_modf_distrbd[1], ht.DNDarray) self.assertEqual(float64_modf_distrbd[0].dtype, ht.float64) @@ -240,7 +245,7 @@ def test_modf(self): def test_round(self): size = ht.communication.MPI_WORLD.size - start, end = -5.0, 5.0 + start, end = -5.7, 5.1 step = (end - start) / (2 * size) comparison = torch.arange(start, end, step, dtype=torch.float32).round() @@ -268,14 +273,16 @@ def test_round(self): ht.round(object()) with self.assertRaises(TypeError): ht.round(float32_tensor, 1, 1) + with self.assertRaises(TypeError): + ht.round(float32_tensor, dtype=np.int) # with split tensors # exponential of float32 comparison = torch.arange(start, end, step, dtype=torch.float32) # .round() - float32_tensor_distrbd = ht.array(comparison, split=0) + float32_tensor_distrbd = ht.array(comparison, split=0, dtype=ht.double) comparison = comparison.round() - float32_round_distrbd = float32_tensor_distrbd.round() + float32_round_distrbd = float32_tensor_distrbd.round(dtype=ht.float) self.assertIsInstance(float32_round_distrbd, ht.DNDarray) self.assertEqual(float32_round_distrbd.dtype, ht.float32) self.assert_array_equal(float32_round_distrbd, comparison) From 8bd1ae778ec9ae5ad5a27e55a7aef43399ae4edf Mon Sep 17 00:00:00 2001 From: coquelin77 Date: Fri, 6 Dec 2019 16:54:06 +0100 Subject: [PATCH 38/40] corrected indent in docs for modf --- heat/core/dndarray.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/heat/core/dndarray.py b/heat/core/dndarray.py index 8bd93ba3d3..38844cd198 100644 --- a/heat/core/dndarray.py +++ b/heat/core/dndarray.py @@ -1896,26 +1896,26 @@ def __mod__(self, other): def modf(a, out=None): """ - Return the fractional and integral parts of an array, element-wise. - The fractional and integral parts are negative if the given number is negative. + Return the fractional and integral parts of an array, element-wise. + The fractional and integral parts are negative if the given number is negative. - Parameters - ---------- - x : ht.DNDarray - Input array - out : ht.DNDarray, optional - A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. - If not provided or None, a freshly-allocated array is returned. + Parameters + ---------- + x : ht.DNDarray + Input array + out : ht.DNDarray, optional + A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. + If not provided or None, a freshly-allocated array is returned. - Returns - ------- - tuple(ht.DNDarray: fractionalParts, ht.DNDarray: integralParts) + Returns + ------- + tuple(ht.DNDarray: fractionalParts, ht.DNDarray: integralParts) - fractionalParts : ht.DNDdarray - Fractional part of x. This is a scalar if x is a scalar. + fractionalParts : ht.DNDdarray + Fractional part of x. This is a scalar if x is a scalar. - integralParts : ht.DNDdarray - Integral part of x. This is a scalar if x is a scalar. + integralParts : ht.DNDdarray + Integral part of x. This is a scalar if x is a scalar. """ return rounding.modf(a, out) From cfa1f74501887f3824831392bd9724985b48aa22 Mon Sep 17 00:00:00 2001 From: coquelin77 Date: Fri, 6 Dec 2019 16:55:16 +0100 Subject: [PATCH 39/40] corrected indent in docs for modf, minor formatting --- heat/core/dndarray.py | 2 -- heat/core/rounding.py | 53 +++++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/heat/core/dndarray.py b/heat/core/dndarray.py index 38844cd198..8bf6a49b85 100644 --- a/heat/core/dndarray.py +++ b/heat/core/dndarray.py @@ -2303,7 +2303,6 @@ def __rmod__(self, other): >>> T = ht.int32([1, 3]) >>> 2 % T tensor([0, 2], dtype=torch.int32) - """ return arithmetics.mod(other, self) @@ -2331,7 +2330,6 @@ def round(x, decimals=0, out=None, dtype=None): rounded_values : ht.DNDarray A tensor containing the rounded value of each element in x. """ - return rounding.round(x, decimals, out, dtype) def __rpow__(self, other): diff --git a/heat/core/rounding.py b/heat/core/rounding.py index ba32b28723..395c040b4d 100644 --- a/heat/core/rounding.py +++ b/heat/core/rounding.py @@ -180,34 +180,33 @@ def floor(x, out=None): def modf(x, out=None): """ - Return the fractional and integral parts of a tensor, element-wise. - The fractional and integral parts are negative if the given number is negative. - - Parameters - ---------- - x : ht.DNDarray - Input tensor - out : tuple(ht.DNDarray, ht.DNDarray), optional - A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. - If not provided or None, a freshly-allocated tensor is returned. - - Returns - ------- - tuple(ht.DNDarray: fractionalParts, ht.DNDarray: integralParts) - - fractionalParts : ht.DNDdarray - Fractional part of x. This is a scalar if x is a scalar. - - integralParts : ht.DNDdarray - Integral part of x. This is a scalar if x is a scalar. - - Examples - -------- - >>> ht.modf(ht.arange(-2.0, 2.0, 0.4)) - (tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]), - tensor([ 0.0000, -0.6000, -0.2000, -0.8000, -0.4000, 0.0000, 0.4000, 0.8000, 0.2000, 0.6000])) - """ + Return the fractional and integral parts of a tensor, element-wise. + The fractional and integral parts are negative if the given number is negative. + Parameters + ---------- + x : ht.DNDarray + Input tensor + out : tuple(ht.DNDarray, ht.DNDarray), optional + A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. + If not provided or None, a freshly-allocated tensor is returned. + + Returns + ------- + tuple(ht.DNDarray: fractionalParts, ht.DNDarray: integralParts) + + fractionalParts : ht.DNDdarray + Fractional part of x. This is a scalar if x is a scalar. + + integralParts : ht.DNDdarray + Integral part of x. This is a scalar if x is a scalar. + + Examples + -------- + >>> ht.modf(ht.arange(-2.0, 2.0, 0.4)) + (tensor([-2., -1., -1., -0., -0., 0., 0., 0., 1., 1.]), + tensor([ 0.0000, -0.6000, -0.2000, -0.8000, -0.4000, 0.0000, 0.4000, 0.8000, 0.2000, 0.6000])) + """ if not isinstance(x, dndarray.DNDarray): raise TypeError("expected x to be a ht.DNDarray, but was {}".format(type(x))) From 2b52855f5796170c4f52dfdc4f5a3a699194711d Mon Sep 17 00:00:00 2001 From: coquelin77 Date: Fri, 6 Dec 2019 16:57:12 +0100 Subject: [PATCH 40/40] self replacing x/a in modf and round --- heat/core/dndarray.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/heat/core/dndarray.py b/heat/core/dndarray.py index 8bf6a49b85..84d187abde 100644 --- a/heat/core/dndarray.py +++ b/heat/core/dndarray.py @@ -1894,7 +1894,7 @@ def __mod__(self, other): """ return arithmetics.mod(self, other) - def modf(a, out=None): + def modf(self, out=None): """ Return the fractional and integral parts of an array, element-wise. The fractional and integral parts are negative if the given number is negative. @@ -1918,7 +1918,7 @@ def modf(a, out=None): Integral part of x. This is a scalar if x is a scalar. """ - return rounding.modf(a, out) + return rounding.modf(self, out) def __mul__(self, other): """ @@ -2306,7 +2306,7 @@ def __rmod__(self, other): """ return arithmetics.mod(other, self) - def round(x, decimals=0, out=None, dtype=None): + def round(self, decimals=0, out=None, dtype=None): """ Calculate the rounded value element-wise. @@ -2330,7 +2330,7 @@ def round(x, decimals=0, out=None, dtype=None): rounded_values : ht.DNDarray A tensor containing the rounded value of each element in x. """ - return rounding.round(x, decimals, out, dtype) + return rounding.round(self, decimals, out, dtype) def __rpow__(self, other): """