Class: CATimedelta
- Inherits:
-
Object
- Object
- CATimedelta
- Defined in:
- lib/carray/time.rb,
lib/carray/time.rb
Overview
============================================================================
Ruby surface operators (CATimedelta)
Defined Under Namespace
Classes: Element
Reductions collapse
-
#mean(axis: nil, **opts) ⇒ Element, CATimedelta
Returns the mean duration rounded to the nearest unit count.
-
#median(axis: nil, **opts) ⇒ Element, CATimedelta
Returns the median duration on
self's unit. -
#minmax(*axes, **opts) ⇒ Array(Element, Element), Array(CATimedelta, CATimedelta)
Returns the shortest and longest duration as a
[min, max]pair. -
#percentile(*p, axis: nil, **opts) ⇒ Element, ...
Returns the percentile durations on
self's unit, in the shapes the plain CArray#percentile uses (onepreduces to a single value, two or more give an Array). -
#quantile(axis: nil, **opts) ⇒ Array<Element>, Array<CATimedelta>
Returns the five quartile durations
[p0, p25, p50, p75, p100]onself's unit. -
#stddev(axis: nil, **opts) ⇒ Element, CATimedelta
Returns the spread of the durations on
self's unit. -
#stddevp(axis: nil, **opts) ⇒ Element, CATimedelta
Returns the population spread on
self's unit, in the same shapes as #stddev. -
#sum(*args, **opts) ⇒ Element, CATimedelta
Returns the sum of durations as a Element for full reduction or as a CATimedelta view for per-axis reduction.
-
#variance(*) ⇒ Object
min / max ride the core reduce Face gate (ORDERABLE storage descent + output re-lift, see ext/mkkernel.rb face_gate: :relift); the inherited CArray#min / #max return the Element / CATimedelta shapes directly.
-
#variancep(*) ⇒ Object
Not supported, for the same reason as #variance.
Class Method Summary collapse
-
.new(*shape, unit: :ns) ⇒ CATimedelta
Allocates a new int64 storage CArray of the given
shapeand wraps it as a CATimedelta Face with the givenunit. -
.wrap(raw, unit: :ns) ⇒ CATimedelta
Zero-copy Face wrap of an existing int64 CArray as a duration.
Instance Method Summary collapse
-
#*(other) ⇒ CATimedelta
Returns
selfscaled by an Integer. -
#+(other) ⇒ CATimedelta, CATime
Returns
self + other. -
#-(other) ⇒ CATimedelta
Returns the difference of two CATimedelta at the finer of the two units (a cross-group pair raises).
-
#-@ ⇒ CATimedelta
Returns each duration with its sign reversed, on the same unit.
-
#/(other) ⇒ CATimedelta, CArray
Returns element-wise division: by Integer yields a CATimedelta, by another CATimedelta with matching
unityields a dimensionless CArray. -
#abs ⇒ CATimedelta
Returns the magnitude of each duration as a CATimedelta on the same unit.
-
#linear_fetch(addr, axis: nil) ⇒ Element, CATimedelta
Returns the duration at the fractional position
addron this array's grid, interpolating between the two bracketing durations. -
#scalar_to_storage(surface) ⇒ Integer, Object
Write-direction counterpart of storage_to_scalar: brings a surface value object into this Face's int64 storage (count in self's unit) so a scalar store round-trips with a fetch.
-
#ticks ⇒ CArray
Returns the underlying int64 CArray of tick counts — the duration measured in this array's resolution (see CATime#ticks).
-
#to_comparable(operand) ⇒ CATimedelta
Brings
operandintoself's unit space for a direct storage comparison (see CATime#to_comparable for the reference-side contract). -
#to_unit(unit) ⇒ CATimedelta
Returns the same durations re-expressed on a finer grid: a new CATimedelta whose storage is
self's ticks widened intounit.
Class Method Details
.new(*shape, unit: :ns) ⇒ CATimedelta
499 500 501 502 |
# File 'lib/carray/time.rb', line 499 def self.new(*shape, unit: :ns) raw = CArray.int64(*shape) wrap(raw, unit: unit) end |
.wrap(raw, unit: :ns) ⇒ CATimedelta
509 510 511 |
# File 'lib/carray/time.rb', line 509 def self.wrap(raw, unit: :ns) __wrap__(raw, unit) end |
Instance Method Details
#*(other) ⇒ CATimedelta
1247 1248 1249 1250 1251 1252 |
# File 'lib/carray/time.rb', line 1247 def *(other) case other when Integer then (parent * other).timedelta(unit: unit) else raise TypeError, "CATimedelta * #{other.class} is not allowed (Integer only)" end end |
#+(other) ⇒ CATimedelta, CATime
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 |
# File 'lib/carray/time.rb', line 1195 def +(other) case other when CATimedelta u = _finer_duration(other.unit) a = CATimeUnitAlgebra.convert_scale!(parent, unit, u) b = CATimeUnitAlgebra.convert_scale!(other.parent, other.unit, u) (a + b).timedelta(unit: u) when CATime other + self # commutative -> time's unit else raise TypeError, "CATimedelta + #{other.class} is not allowed" end end |
#-(other) ⇒ CATimedelta
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 |
# File 'lib/carray/time.rb', line 1215 def -(other) case other when CATimedelta u = _finer_duration(other.unit) a = CATimeUnitAlgebra.convert_scale!(parent, unit, u) b = CATimeUnitAlgebra.convert_scale!(other.parent, other.unit, u) (a - b).timedelta(unit: u) else raise TypeError, "CATimedelta - #{other.class} is not allowed" end end |
#-@ ⇒ CATimedelta
1238 1239 1240 |
# File 'lib/carray/time.rb', line 1238 def -@ (-parent).timedelta(unit: unit) end |
#/(other) ⇒ CATimedelta, CArray
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 |
# File 'lib/carray/time.rb', line 1261 def /(other) case other when Integer then (parent / other).timedelta(unit: unit) when CATimedelta u = _finer_duration(other.unit) CATimeUnitAlgebra.convert_scale!(parent, unit, u) / CATimeUnitAlgebra.convert_scale!(other.parent, other.unit, u) else raise TypeError, "CATimedelta / #{other.class} is not allowed" end end |
#abs ⇒ CATimedelta
1231 1232 1233 |
# File 'lib/carray/time.rb', line 1231 def abs parent.abs.timedelta(unit: unit) end |
#linear_fetch(addr, axis: nil) ⇒ Element, CATimedelta
1466 1467 1468 1469 1470 1471 1472 1473 |
# File 'lib/carray/time.rb', line 1466 def linear_fetch (addr, **opts) r = parent.float64.linear_fetch(addr, **opts) case r when CArray then r.mask_invalid.round.int64.timedelta(unit: unit) when Numeric then r.to_f.nan? ? nil : Element.new(r.round, unit) else r end end |
#mean(axis: nil, **opts) ⇒ Element, CATimedelta
1290 1291 1292 |
# File 'lib/carray/time.rb', line 1290 def mean(*args, **opts) _lift_reduced(parent.mean(*args, **opts)) end |
#median(axis: nil, **opts) ⇒ Element, CATimedelta
1302 1303 1304 |
# File 'lib/carray/time.rb', line 1302 def median(*args, **opts) _lift_reduced(parent.median(*args, **opts)) end |
#minmax(*axes, **opts) ⇒ Array(Element, Element), Array(CATimedelta, CATimedelta)
1381 1382 1383 1384 |
# File 'lib/carray/time.rb', line 1381 def minmax(*args, **opts) lo, hi = parent.minmax(*args, **opts) [_lift_extremum(lo), _lift_extremum(hi)] end |
#percentile(*p, axis: nil, **opts) ⇒ Element, ...
1311 1312 1313 |
# File 'lib/carray/time.rb', line 1311 def percentile(*args, **opts) _lift_reduced(parent.percentile(*args, **opts)) end |
#quantile(axis: nil, **opts) ⇒ Array<Element>, Array<CATimedelta>
1319 1320 1321 |
# File 'lib/carray/time.rb', line 1319 def quantile(*args, **opts) _lift_reduced(parent.quantile(*args, **opts)) end |
#scalar_to_storage(surface) ⇒ Integer, Object
1442 1443 1444 1445 1446 1447 1448 1449 |
# File 'lib/carray/time.rb', line 1442 def scalar_to_storage (surface) case surface when Integer, String surface else to_comparable(surface).parent[0] end end |
#stddev(axis: nil, **opts) ⇒ Element, CATimedelta
1328 1329 1330 |
# File 'lib/carray/time.rb', line 1328 def stddev(*args, **opts) _lift_reduced(parent.stddev(*args, **opts)) end |
#stddevp(axis: nil, **opts) ⇒ Element, CATimedelta
1336 1337 1338 |
# File 'lib/carray/time.rb', line 1336 def stddevp(*args, **opts) _lift_reduced(parent.stddevp(*args, **opts)) end |
#sum(*args, **opts) ⇒ Element, CATimedelta
1283 1284 1285 |
# File 'lib/carray/time.rb', line 1283 def sum(*args, **opts) _lift_reduced(parent.sum(*args, **opts)) end |
#to_comparable(operand) ⇒ CATimedelta
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 |
# File 'lib/carray/time.rb', line 1414 def to_comparable (operand) case operand when CATimedelta return operand if operand.unit == unit CATimeUnitAlgebra.convert_scale!(operand.parent, operand.unit, unit) .timedelta(unit: unit) when CATimedelta::Element lifted = CATimedelta.wrap(CA_INT64([operand.value]), unit: operand.unit) to_comparable(lifted) else raise TypeError, "CATimedelta cannot reconcile #{operand.class} " \ "(use ca.parent to compare the raw int64 storage directly)" end end |
#to_unit(unit) ⇒ CATimedelta
1182 1183 1184 1185 1186 |
# File 'lib/carray/time.rb', line 1182 def to_unit(unit) to = CATime::Resolution.parse(unit) CATimeUnitAlgebra.widen(parent, CATimeUnitAlgebra.multiple_factor(self.unit, to)).timedelta(unit: to) end |
#variance(*) ⇒ Object
min / max ride the core reduce Face gate (ORDERABLE storage descent + output re-lift, see ext/mkkernel.rb face_gate: :relift); the inherited CArray#min / #max return the Element / CATimedelta shapes directly.
1365 1366 1367 |
# File 'lib/carray/time.rb', line 1365 def variance(*) raise TypeError, "CATimedelta#variance is ill-defined (squared-time units); use stddev" end |
#variancep(*) ⇒ Object
1372 1373 1374 |
# File 'lib/carray/time.rb', line 1372 def variancep(*) raise TypeError, "CATimedelta#variancep is ill-defined (squared-time units); use stddevp" end |