Skip to content

Commit

Permalink
feat: add Flatten2DFloat64Array utility to @observerly/iris
Browse files Browse the repository at this point in the history
feat: add Flatten2DFloat64Array utility to @observerly/iris
  • Loading branch information
michealroberts committed Oct 28, 2024
1 parent 47df02e commit fd0a25e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
17 changes: 17 additions & 0 deletions pkg/utils/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ func Flatten2DUInt32Array(a [][]uint32) []float32 {

/*****************************************************************************************************************/

/*
Flatten2DFloat64Array
Flattens a 2D array of float64 into a 1D array of float64.
*/
func Flatten2DFloat64Array(a [][]float64) []float64 {
f := make([]float64, 0)

for _, j := range a {
f = append(f, j...)
}

return f
}

/*****************************************************************************************************************/

/*
BoundsFloat32Array
Expand Down
59 changes: 57 additions & 2 deletions pkg/utils/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func TestMeanABC(t *testing.T) {
t.Errorf("result should be 6 but got %v", m[5])
}

//... Assume here that the mean calculation is correct for all other elements
// Assume here that the mean calculation is correct for all other elements
}

/*****************************************************************************************************************/
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestMeanABCD(t *testing.T) {
t.Errorf("result should be 6 but got %v", m[5])
}

//... Assume here that the mean calculation is correct for all other elements
// Assume here that the mean calculation is correct for all other elements
}

/*****************************************************************************************************************/
Expand Down Expand Up @@ -412,6 +412,61 @@ func TestFlatten2DUInt32Array1Rows5Columns(t *testing.T) {

/*****************************************************************************************************************/

func TestFlatten2DUFloat64Array2Rows5Columns(t *testing.T) {
a := [][]float64{
{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
}

f := Flatten2DFloat64Array(a)

if len(f) != 5 {
t.Errorf("result should be of length 10, but got %v", len(f))
}

if f[0] != 1 {
t.Errorf("result should be 1, but got %v", f[0])
}

if f[1] != 2 {
t.Errorf("result should be 2, but got %v", f[1])
}

if f[2] != 3 {
t.Errorf("result should be 3, but got %v", f[2])
}

if f[3] != 4 {
t.Errorf("result should be 4, but got %v", f[3])
}

if f[4] != 5 {
t.Errorf("result should be 5, but got %v", f[4])
}

if f[5] != 6 {
t.Errorf("result should be 6, but got %v", f[5])
}

if f[6] != 7 {
t.Errorf("result should be 7, but got %v", f[6])
}

if f[7] != 8 {
t.Errorf("result should be 8, but got %v", f[7])
}

if f[8] != 9 {
t.Errorf("result should be 9, but got %v", f[8])
}

if f[9] != 10 {
t.Errorf("result should be 10, but got %v", f[9])
}
}

/*****************************************************************************************************************/

func TestBoundsFloat32Array(t *testing.T) {
a := []float32{5, 1, 3, 1, 2, 7, 8, 10, 2, 4, 6, 9}

Expand Down

0 comments on commit fd0a25e

Please sign in to comment.