File indexing completed on 2026-04-09 07:49:45
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <vector>
0018 struct NP ;
0019
0020 struct SPropMockup
0021 {
0022 static constexpr const char* DEMO_BASE = "$HOME/.opticks/GEOM/$GEOM" ;
0023 static constexpr const char* DEMO_RELP = "CSGFoundry/SSim/stree/material/LS/RINDEX.npy" ;
0024
0025 static const NP* CombinationDemo();
0026 static const NP* Combination(const char* base, const char* relp );
0027 static const NP* Combination(const NP* a_ );
0028
0029
0030 static const NP* NarrowCombine(const std::vector<const NP*>& aa );
0031 static const NP* Combine(const std::vector<const NP*>& aa );
0032 };
0033
0034
0035 #include <vector>
0036 #include "NP.hh"
0037 #include "spath.h"
0038
0039
0040 inline const NP* SPropMockup::CombinationDemo()
0041 {
0042 const NP* propcom = Combination( DEMO_BASE, DEMO_RELP);
0043 return propcom ;
0044 }
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060 inline const NP* SPropMockup::Combination(const char* base, const char* relp )
0061 {
0062 const char* path = spath::Resolve(base, relp);
0063 std::cout
0064 << "SPropMockup::Combination"
0065 << " base " << base
0066 << " relp " << relp
0067 << " spath::Resolve to path " << path
0068 << std::endl
0069 ;
0070
0071 if( path == nullptr ) return nullptr ;
0072
0073 bool exists = NP::Exists(path) ;
0074 std::cout
0075 << "SPropMockup::Combination"
0076 << " path " << ( path ? path : "-" )
0077 << " exists " << ( exists ? "YES" : "NO " )
0078 << std::endl
0079 ;
0080
0081
0082 NP* a = exists ? NP::Load(path) : nullptr ;
0083 if( a == nullptr ) return nullptr ;
0084
0085 bool is_double = strcmp( a->dtype, "<f8") == 0;
0086 if(!is_double) std::cerr
0087 << "SPropMockup::Combination"
0088 << " EXPECTING double precision input array "
0089 << std::endl
0090 ;
0091 assert(is_double);
0092
0093 return Combination(a) ;
0094 }
0095
0096
0097 inline const NP* SPropMockup::Combination(const NP* a_ )
0098 {
0099 NP* a = a_->copy();
0100 NP* b = a_->copy();
0101 NP* c = a_->copy();
0102
0103 a->pscale<double>(1e6, 0u);
0104 b->pscale<double>(1e6, 0u);
0105 c->pscale<double>(1e6, 0u);
0106
0107 b->pscale<double>(1.05, 1u);
0108 c->pscale<double>(0.95, 1u);
0109
0110 std::vector<const NP*> aa = {a, b, c } ;
0111 const NP* com = NarrowCombine(aa);
0112
0113 std::cout
0114 << "SPropMockup::Combination"
0115 << " com " << ( com ? com->desc() : "-" )
0116 << std::endl
0117 ;
0118
0119 return com ;
0120 }
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 inline const NP* SPropMockup::NarrowCombine(const std::vector<const NP*>& aa )
0140 {
0141 std::cout << "SPropMockup::NarrowCombine : narrowing double to float " << std::endl ;
0142 std::vector<const NP*> nn ;
0143 for(unsigned i=0 ; i < aa.size() ; i++)
0144 {
0145 const NP* a = aa[i] ;
0146 const NP* n = NP::MakeNarrow( a );
0147 nn.push_back(n);
0148 }
0149 NP* com = NP::Combine(nn) ;
0150 return com ;
0151 }
0152
0153 inline const NP* SPropMockup::Combine(const std::vector<const NP*>& aa )
0154 {
0155 std::cout << "SPropMockup::Combine : not-narrowing retaining double " << std::endl ;
0156 NP* com = NP::Combine(aa) ;
0157 return com ;
0158 }
0159
0160