| 1 | package CXC::Number::Grid::Types; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Type::Tiny types for CXC::Number::Grid | ||||||||||
| 4 | |||||||||||
| 5 | 13 | ▶ | use v5.28; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 13 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 13 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 13 | our $VERSION = '0.12'; | |||||||||
| 10 | |||||||||||
| 11 | 13 | ▶ | use Math::BigInt upgrade => 'Math::BigFloat'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 13 | ▶ | use Math::BigFloat; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 13 | ▶ | use List::Util 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 13 | ▶ | use Type::Utils '-all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 13 | ▶ | use Types::Standard qw[ CycleTuple Num Int Enum Tuple Any InstanceOf Dict ArrayRef Value ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 13 | ▶ | use Types::Common::Numeric qw[ PositiveNum PositiveOrZeroNum PositiveInt ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 13 | use Type::Library -base, -declare => qw( | |||||||||
| 19 | BinEdges | ||||||||||
| 20 | BinBounds | ||||||||||
| 21 | Spacing | ||||||||||
| 22 | MonotonicallyIncreasingArrayOfBigNums | ||||||||||
| 23 | 13 | ▶ | ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | 13 | ▶ | BEGIN { extends 'CXC::Number::Types' } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | declare BinEdges, as ArrayRef [ BigNum, 2 ], where { | ||||||||||
| 34 | 144 | ▶ | my $arr = $_; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 35 | 144 | ▶ | $arr->[$_] < $arr->[ $_ + 1 ] || return for 0 .. ( $arr->@* - 2 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 140 | 1; | |||||||||
| 37 | }, message { | ||||||||||
| 38 | 6 | ▶ | ArrayRef( [ BigNum, 2 ] )->validate( $_ ) | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 39 | or 'Must be an array of monotonically increasing numbers with at lest two elements' | ||||||||||
| 40 | 13 | }, coercion => 1; | |||||||||
| 41 | |||||||||||
| 42 | 1 | ▶ | coerce BinEdges, from InstanceOf ['CXC::Number::Sequence'], via { $_->bignum->elements } | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 13 | ; | |||||||||
| 44 | |||||||||||
| 45 | declare BinBounds, as CycleTuple [ BigNum, BigNum ], where { | ||||||||||
| 46 | 8 | ▶ | return unless $_->@*; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 47 | 5 | my $lval = $_->[0]; | |||||||||
| 48 | 5 | my $ub = 0; # this gets toggled between true and false | |||||||||
| 49 | return all { | ||||||||||
| 50 | 34 | ▶ | ( my $_lval, $lval ) = ( $lval, $_ ); | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 51 | 34 | ( my $_ub, $ub ) = ( $ub, 1 - $ub ); # save ub flag and toggle it for next round. | |||||||||
| 52 | 34 | ▶ | $_ub ? $_ > $_lval : $_ >= $_lval; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 5 | } $_->@*; | |||||||||
| 54 | }, message { | ||||||||||
| 55 | # it's either | ||||||||||
| 56 | # 1. not pairs, | ||||||||||
| 57 | # 2. not pairs of numbers, | ||||||||||
| 58 | # 3. not sorted | ||||||||||
| 59 | 3 | ▶ | !eval { CycleTuple( [ BigNum, BigNum ] )->assert_coerce( $_ ); $_->@* } | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||
| 60 | ? 'Must be non-empty array of numbers with an even number of elements' | ||||||||||
| 61 | : 'The elements in the array must be in ascending order'; | ||||||||||
| 62 | 13 | }, coercion => 1; | |||||||||
| 63 | |||||||||||
| 64 | 13 | 1; | |||||||||
| 65 | |||||||||||
| 66 | # | ||||||||||
| 67 | # This file is part of CXC-Number | ||||||||||
| 68 | # | ||||||||||
| 69 | # This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory. | ||||||||||
| 70 | # | ||||||||||
| 71 | # This is free software, licensed under: | ||||||||||
| 72 | # | ||||||||||
| 73 | # The GNU General Public License, Version 3, June 2007 | ||||||||||
| 74 | # | ||||||||||
| 75 | |||||||||||
| 76 | __END__ | ||||||||||
| 77 | |||||||||||
| 78 | =pod | ||||||||||
| 79 | |||||||||||
| 80 | =for :stopwords Diab Jerius Smithsonian Astrophysical Observatory BinEdges | ||||||||||
| 81 | |||||||||||
| 82 | =head1 NAME | ||||||||||
| 83 | |||||||||||
| 84 | CXC::Number::Grid::Types - Type::Tiny types for CXC::Number::Grid | ||||||||||
| 85 | |||||||||||
| 86 | =head1 VERSION | ||||||||||
| 87 | |||||||||||
| 88 | version 0.12 | ||||||||||
| 89 | |||||||||||
| 90 | =head1 TYPES | ||||||||||
| 91 | |||||||||||
| 92 | =head2 BinEdges | ||||||||||
| 93 | |||||||||||
| 94 | A array of numbers with at lest two members which is sorted by increasing value | ||||||||||
| 95 | |||||||||||
| 96 | =head1 INTERNALS | ||||||||||
| 97 | |||||||||||
| 98 | =head1 SUPPORT | ||||||||||
| 99 | |||||||||||
| 100 | =head2 Bugs | ||||||||||
| 101 | |||||||||||
| 102 | Please report any bugs or feature requests to bug-cxc-number@rt.cpan.org or through the web interface at: L<https://rt.cpan.org/Public/Dist/Display.html?Name=CXC-Number> | ||||||||||
| 103 | |||||||||||
| 104 | =head2 Source | ||||||||||
| 105 | |||||||||||
| 106 | Source is available at | ||||||||||
| 107 | |||||||||||
| 108 | https://gitlab.com/djerius/cxc-number | ||||||||||
| 109 | |||||||||||
| 110 | and may be cloned from | ||||||||||
| 111 | |||||||||||
| 112 | https://gitlab.com/djerius/cxc-number.git | ||||||||||
| 113 | |||||||||||
| 114 | =head1 SEE ALSO | ||||||||||
| 115 | |||||||||||
| 116 | Please see those modules/websites for more information related to this module. | ||||||||||
| 117 | |||||||||||
| 118 | =over 4 | ||||||||||
| 119 | |||||||||||
| 120 | =item * | ||||||||||
| 121 | |||||||||||
| 122 | L<CXC::Number|CXC::Number> | ||||||||||
| 123 | |||||||||||
| 124 | =back | ||||||||||
| 125 | |||||||||||
| 126 | =head1 AUTHOR | ||||||||||
| 127 | |||||||||||
| 128 | Diab Jerius <djerius@cpan.org> | ||||||||||
| 129 | |||||||||||
| 130 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 131 | |||||||||||
| 132 | This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory. | ||||||||||
| 133 | |||||||||||
| 134 | This is free software, licensed under: | ||||||||||
| 135 | |||||||||||
| 136 | The GNU General Public License, Version 3, June 2007 | ||||||||||
| 137 | |||||||||||
| 138 | =cut | ||||||||||