changeset 1225:6567e38b05ca refactor/LazyTensors/tuple_manipulation

Replace flatten_tuple with concatenate_tuple
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 18 Feb 2023 12:24:44 +0100
parents e2f6dafb5d83
children ea5b4fca85e0
files TODO.md src/LazyTensors/lazy_tensor_operations.jl src/LazyTensors/tuple_manipulation.jl test/LazyTensors/tuple_manipulation_test.jl
diffstat 4 files changed, 2 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/TODO.md	Sat Feb 18 12:18:34 2023 +0100
+++ b/TODO.md	Sat Feb 18 12:24:44 2023 +0100
@@ -5,7 +5,6 @@
  - [ ] Ändra namn på variabler och funktioner så att det följer style-guide
  - [ ] Add new Laplace operator to DiffOps, probably named WaveEqOp(?!!?)
  - [ ] Create a struct that bundles the necessary Tensor operators for solving the wave equation.
- - [ ] Replace getindex hack for flattening tuples with flatten_tuple. (eg. `getindex.(range_size.(L.D2),1)`)
  - [ ] Use `@inferred` in a lot of tests.
  - [ ] Replace `@inferred` tests with a benchmark suite that automatically tests for regressions.
  - [ ] Make sure we are setting tolerances in tests in a consistent way
--- a/src/LazyTensors/lazy_tensor_operations.jl	Sat Feb 18 12:18:34 2023 +0100
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Sat Feb 18 12:24:44 2023 +0100
@@ -176,7 +176,7 @@
 # TODO: Implement some pretty printing in terms of ⊗. E.g InflatedTensor(I(3),B,I(2)) -> I(3)⊗B⊗I(2)
 
 function range_size(itm::InflatedTensor)
-    return flatten_tuple(
+    return concatenate_tuples(
         range_size(itm.before),
         range_size(itm.tm),
         range_size(itm.after),
@@ -184,7 +184,7 @@
 end
 
 function domain_size(itm::InflatedTensor)
-    return flatten_tuple(
+    return concatenate_tuples(
         domain_size(itm.before),
         domain_size(itm.tm),
         domain_size(itm.after),
--- a/src/LazyTensors/tuple_manipulation.jl	Sat Feb 18 12:18:34 2023 +0100
+++ b/src/LazyTensors/tuple_manipulation.jl	Sat Feb 18 12:24:44 2023 +0100
@@ -88,19 +88,9 @@
     return ntuple(i->cum_szs[i]+1:cum_szs[i+1], length(szs))
 end
 
-
 concatenate_tuples(t::Tuple,ts::Vararg{Tuple}) = (t..., concatenate_tuples(ts...)...)
 concatenate_tuples(t::Tuple) = t
 
-"""
-    flatten_tuple(t)
-
-Takes a nested tuple and flattens the whole structure
-"""
-flatten_tuple(t::NTuple{N, Number} where N) = t
-flatten_tuple(t::Tuple) = ((flatten_tuple.(t)...)...,) # simplify?
-flatten_tuple(ts::Vararg) = flatten_tuple(ts)
-# TBD: Can concatenate_tuples be used instead?
 
 """
     left_pad_tuple(t, val, N)
--- a/test/LazyTensors/tuple_manipulation_test.jl	Sat Feb 18 12:18:34 2023 +0100
+++ b/test/LazyTensors/tuple_manipulation_test.jl	Sat Feb 18 12:24:44 2023 +0100
@@ -95,14 +95,6 @@
     @test LazyTensors.concatenate_tuples((1,2,3),(4,5),(6,7)) == (1,2,3,4,5,6,7)
 end
 
-@testset "flatten_tuple" begin
-    @test LazyTensors.flatten_tuple((1,)) == (1,)
-    @test LazyTensors.flatten_tuple((1,2,3,4,5,6)) == (1,2,3,4,5,6)
-    @test LazyTensors.flatten_tuple((1,2,(3,4),5,6)) == (1,2,3,4,5,6)
-    @test LazyTensors.flatten_tuple((1,2,(3,(4,5)),6)) == (1,2,3,4,5,6)
-    @test LazyTensors.flatten_tuple(((1,2),(3,4),(5,),6)) == (1,2,3,4,5,6)
-end
-
 @testset "left_pad_tuple" begin
     @test LazyTensors.left_pad_tuple((1,2), 0, 2) == (1,2)
     @test LazyTensors.left_pad_tuple((1,2), 0, 3) == (0,1,2)