(vec vector.Any)
| 28 | } |
| 29 | |
| 30 | func (a *Abs) abs(vec vector.Any) vector.Any { |
| 31 | switch vec := vec.(type) { |
| 32 | case *vector.Const: |
| 33 | typ := vec.Type() |
| 34 | if super.IsFloat(typ.ID()) { |
| 35 | v := math.Abs(vector.FloatValue(vec, 0)) |
| 36 | return vector.NewConstFloat(typ, v, vec.Len()) |
| 37 | } |
| 38 | v := vector.IntValue(vec, 0) |
| 39 | if v < 0 { |
| 40 | v = -v |
| 41 | } |
| 42 | return vector.NewConstInt(typ, v, vec.Len()) |
| 43 | case *vector.View: |
| 44 | return vector.Pick(a.abs(vec.Any), vec.Index) |
| 45 | case *vector.Dict: |
| 46 | return vector.NewDict(a.abs(vec.Any), vec.Index, vec.Counts) |
| 47 | case *vector.Int: |
| 48 | var ints []int64 |
| 49 | for _, v := range vec.Values { |
| 50 | if v < 0 { |
| 51 | v = -v |
| 52 | } |
| 53 | ints = append(ints, v) |
| 54 | } |
| 55 | return vector.NewInt(vec.Type(), ints) |
| 56 | case *vector.Float: |
| 57 | var floats []float64 |
| 58 | for _, v := range vec.Values { |
| 59 | floats = append(floats, math.Abs(v)) |
| 60 | } |
| 61 | return vector.NewFloat(vec.Type(), floats) |
| 62 | default: |
| 63 | panic(vec) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | type Ceil struct { |
| 68 | sctx *super.Context |
no test coverage detected