github.com/qiaogw/arrgo@v0.0.8/condition_opt.go (about) 1 package arrgo 2 3 func Where(cond *Arrb, tv, fv interface{}) *Arrf { 4 t := Zeros(cond.Shape...) 5 for i, v := range cond.Data { 6 if v { 7 switch tv.(type) { 8 case float64: 9 t.Data[i] = tv.(float64) 10 case float32: 11 t.Data[i] = float64(tv.(float32)) 12 case int: 13 t.Data[i] = float64(tv.(int)) 14 case *Arrf: 15 t.Data[i] = tv.(*Arrf).Data[i] 16 default: 17 panic(TYPE_ERROR) 18 } 19 } else { 20 switch fv.(type) { 21 case float64: 22 t.Data[i] = fv.(float64) 23 case float32: 24 t.Data[i] = float64(fv.(float32)) 25 case int: 26 t.Data[i] = float64(fv.(int)) 27 case *Arrf: 28 t.Data[i] = fv.(*Arrf).Data[i] 29 default: 30 panic(TYPE_ERROR) 31 } 32 } 33 } 34 return t 35 }