From db206977f7921a863aa4f3a281bf034a4f04f716 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Thu, 4 Jun 2020 12:00:05 +0200 Subject: [PATCH 1/5] Implemented fliplr() --- heat/core/manipulations.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/heat/core/manipulations.py b/heat/core/manipulations.py index a708a5d276..739b1b27f7 100644 --- a/heat/core/manipulations.py +++ b/heat/core/manipulations.py @@ -18,6 +18,7 @@ "expand_dims", "flatten", "flip", + "fliplr", "flipud", "hstack", "reshape", @@ -702,6 +703,35 @@ def flip(a, axis=None): return res +def fliplr(a): + """ + Flip array in the left/right direction. If a.ndim > 2, flip along dimension 1. + + Parameters + ---------- + a: ht.DNDarray + Input array to be flipped, must be at least 2-D + + Returns + ------- + res: ht.DNDarray + The flipped array. + + Examples + -------- + >>> a = ht.array([[0,1],[2,3]]) + >>> ht.fliplr(a) + tensor([[1, 0], + [3, 2]]) + + >>> b = ht.array([[0,1,2],[3,4,5]], split=0) + >>> ht.fliplr(b) + (1/2) tensor([[2, 1, 0]]) + (2/2) tensor([[5, 4, 3]]) + """ + return flip(a, 1) + + def flipud(a): """ Flip array in the up/down direction. From 1bd08957743e45b326a98460e855964ca414817a Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Thu, 4 Jun 2020 12:18:07 +0200 Subject: [PATCH 2/5] Added tests for fliplr. --- heat/core/tests/test_manipulations.py | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/heat/core/tests/test_manipulations.py b/heat/core/tests/test_manipulations.py index 9019b28f2e..5778d4a567 100644 --- a/heat/core/tests/test_manipulations.py +++ b/heat/core/tests/test_manipulations.py @@ -827,6 +827,45 @@ def test_flip(self): ) self.assertTrue(ht.equal(ht.flip(a, [1, 2]), r_a)) + def test_fliplr(self): + b = ht.array([[1, 2], [3, 4]], device=ht_device) + r_b = ht.array([[2, 1], [4, 3]], device=ht_device) + self.assertTrue(ht.equal(ht.fliplr(b), r_b)) + + # splitted + c = ht.array( + [[[0, 1], [2, 3]], [[4, 5], [6, 7]], [[8, 9], [10, 11]], [[12, 13], [14, 15]]], + split=0, + device=ht_device, + ) + r_c = ht.array( + [[[2, 3], [0, 1]], [[6, 7], [4, 5]], [[10, 11], [8, 9]], [[14, 15], [12, 13]]], + split=0, + device=ht_device, + ) + self.assertTrue(ht.equal(ht.fliplr(c), r_c)) + + c = ht.array( + [[[0, 1], [2, 3]], [[4, 5], [6, 7]], [[8, 9], [10, 11]], [[12, 13], [14, 15]]], + split=1, + device=ht_device, + dtype=ht.float32, + ) + self.assertTrue(ht.equal(ht.resplit(ht.fliplr(c), 0), r_c)) + + c = ht.array( + [[[0, 1], [2, 3]], [[4, 5], [6, 7]], [[8, 9], [10, 11]], [[12, 13], [14, 15]]], + split=2, + device=ht_device, + dtype=ht.int8, + ) + self.assertTrue(ht.equal(ht.resplit(ht.fliplr(c), 0), r_c)) + + # test exception + a = ht.arange(10, device=ht_device) + with self.assertRaises(IndexError): + ht.fliplr(a) + def test_flipud(self): a = ht.array([1, 2], device=ht_device) r_a = ht.array([2, 1], device=ht_device) From 7760f16ec33019dfd3f704a69ec9563efedbf47e Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Thu, 4 Jun 2020 12:29:24 +0200 Subject: [PATCH 3/5] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9843d5a8dc..75cfeb0a5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Pending Additions - [#573](https://github.com/helmholtz-analytics/heat/pull/573) Bugfix: matmul fixes: early out for 2 vectors, remainders not added if inner block is 1 for split 10 case +- [#580](https://github.com/helmholtz-analytics/heat/pull/580) New feature: fliplr() # v0.4.0 From f4dba28e92ba651f140377183d7f3647a1baa4f2 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Thu, 4 Jun 2020 13:41:26 +0200 Subject: [PATCH 4/5] travis tricks --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 618bcc1371..f4594989fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: python python: - - "3.6" + - "3.7" services: - docker From 415095e8d9eddb8318427b14b44068d64e59f4f7 Mon Sep 17 00:00:00 2001 From: Claudia Comito Date: Thu, 4 Jun 2020 13:50:44 +0200 Subject: [PATCH 5/5] undo travis tricks --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f4594989fa..618bcc1371 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: python python: - - "3.7" + - "3.6" services: - docker