Skip to content

Commit

Permalink
fix: empty dim len can be 1 (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-camuto authored Mar 1, 2025
1 parent bc26691 commit fcbb276
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/onnx/hierarchical_risk/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"input_data": [[0.38538306951522827, 0.6133589744567871, 0.576287031173706, -0.3345218300819397, 0.13568370044231415, -0.28134018182754517, -0.09186103194952011, -0.4819085896015167, -0.15042705833911896, 0.39111578464508057, -0.043726757168769836, -0.37419062852859497, -0.14557626843452454, -0.23101887106895447, -0.3833008408546448, 0.08098119497299194, 0.3284634053707123, 0.11909070611000061, -0.12443117797374725, 0.15384003520011902, -0.15162622928619385, 0.2291812002658844, 0.3672296404838562, 0.5550448894500732, 0.25582489371299744, 0.4945962131023407, 0.41473111510276794, 0.5560457706451416, -0.04632486402988434, -0.01135106198489666, -0.10522330552339554, 0.20866376161575317, -0.27693474292755127, -0.3848901689052582, -0.23265987634658813, 0.3436954915523529, 0.06377606838941574, -0.08818407356739044, 0.09670328348875046, -0.19627152383327484, -0.3115144968032837, 0.12585119903087616, -0.3302604556083679, -0.2670367956161499, -0.2548302412033081, 0.4729992151260376, -0.3537588119506836, -0.19166556000709534, -0.18276460468769073, -0.27753162384033203, -0.07367578893899918, 0.07239707559347153, -0.09759834408760071, 0.2881709039211273, -0.23403164744377136, -0.2351384311914444, -0.2806495726108551, -0.13014139235019684, -0.09153909981250763, 0.11444039642810822, -0.01956137828528881, 0.5119493007659912, -0.300140917301178, 0.37762439250946045, 0.28902676701545715, 0.386743426322937, 1.006115198135376, 0.4514278173446655, 0.06932933628559113, -0.021149098873138428, -0.40812429785728455, 0.2731946110725403, -0.03443802520632744, 0.13093075156211853, 0.05959396809339523, 0.14264248311519623, 0.11500101536512375, -0.1240064948797226, -0.8816145062446594, -0.4014143943786621, 0.002173628890886903, -0.09472399204969406, -0.5480992794036865, -0.2940787672996521, 0.10723762959241867, 0.20200449228286743, 0.5147047638893127, 0.16579338908195496, 0.1487904042005539, -0.06181745231151581, -0.4114017188549042, 0.09076526761054993, -0.34445902705192566, -0.40635788440704346, 0.35710960626602173, 0.11778929829597473, -0.5019088983535767, -0.11292687058448792, 0.2212088704109192, -0.02508154883980751, 0.1281510591506958, 0.22904279828071594, 0.4963783025741577, 0.028141885995864868, -0.03705349564552307, 0.1943856179714203, 0.21387037634849548, 0.11466631293296814, 0.0529819019138813, 0.3865973651409149, 0.12527155876159668, -0.003862619400024414, -0.2914058268070221, -0.17464767396450043, -0.31370580196380615, 0.0037097185850143433, 0.14523544907569885, 0.09839935600757599, -0.10616163164377213, 0.15510712563991547, -0.0025370956864207983, 0.06685025244951248, 0.07193008065223694, 0.23612673580646515, 0.21900193393230438, 0.2056366503238678, 0.3633444607257843, 0.2483634650707245, 0.3862321078777313, 0.4793143570423126, -0.3697430491447449, -0.2861303389072418, -0.02720690704882145, 0.44896024465560913, 0.3910651206970215, 0.2958049476146698, 0.22830159962177277, 0.11940164864063263, -0.639940083026886, 0.1625312864780426, -0.0750688761472702, 0.254666805267334, -0.19311591982841492, 0.15506117045879364, -0.1945347785949707, 0.17382541298866272, 0.6625428199768066, 0.5433394908905029, 0.053896307945251465, -0.03255516290664673, -0.288638174533844, -0.030797407031059265, 0.0697503387928009, 0.3085521161556244, -0.07721073925495148, 0.4759986400604248, -0.4960240423679352, -0.36611121892929077, -0.6234266757965088, -0.021398499608039856, -0.38011065125465393, -0.12540410459041595, -0.06520618498325348, -0.1771024614572525, 0.05736656114459038, -0.17803017795085907, 0.017380714416503906, -0.314117431640625, -0.32043206691741943, 0.22244103252887726, 0.5381128787994385, 0.1155034750699997, -0.30937010049819946, 0.059343770146369934, 0.28958582878112793, 0.5927042365074158, 0.00716352229937911, 0.03768940642476082, -0.29925745725631714, -0.117927186191082, -0.18638956546783447, -0.5431879758834839, -0.6267232298851013, -0.3727932274341583, -0.10375466197729111, -0.4765024185180664, -0.9040462374687195, -0.23336412012577057, 0.20458267629146576, -0.054911285638809204, 0.27449923753738403, 0.2790139317512512, 0.35487768054008484, -0.08321517705917358, 0.37963181734085083, 0.027654170989990234, -0.2350667268037796, -0.016259513795375824, 0.15811413526535034, 0.3776678740978241, 0.10521241277456284, 0.6499807834625244, 0.01150447130203247, -0.16530533134937286, 0.037032268941402435, 0.32078784704208374, 0.6092091798782349, 0.3047492504119873, -0.1629253774881363, -0.37031278014183044, -0.32248029112815857, -0.30173546075820923, 0.030863190069794655, 0.14009936153888702, -0.010699033737182617, -0.6268912553787231, -0.07959906756877899, 0.2658081352710724, -0.6134042739868164, 0.30617469549179077, 0.061885710805654526, -0.1105659231543541, 0.3716871440410614, 0.5470790266990662, -0.0009010103531181812, 0.4709896147251129, 0.20665067434310913, -0.1939283013343811, -0.1145315170288086, -0.03362914174795151, 0.13347481191158295, 0.5634680986404419, -0.014397501945495605, -0.2634809911251068, -0.876323401927948, -0.5263463258743286, 0.003524616127833724, 0.023887958377599716, 0.08252733945846558, 0.13545586168766022, -0.18582606315612793, -0.014794446527957916, -0.2305324375629425, 0.05126190185546875, -0.17437782883644104, -0.09485913813114166, -0.182660311460495, 0.3325154483318329, 0.25108686089515686, -0.0766766369342804, 0.32995477318763733, 0.24008214473724365, 0.10794620960950851, 0.21392208337783813, 0.27265873551368713, 0.16179952025413513, -0.1370963305234909, 0.09085039794445038, -0.5675800442695618, -0.5805855393409729, -0.2958093285560608, -0.025639012455940247, -0.08411598205566406, 0.15609431266784668, -0.3197535276412964, -0.1907433569431305, 0.18712268769741058, -0.014174345880746841, 0.26117202639579773, 0.20033296942710876, -0.6780304312705994, -0.0843668282032013, -0.27586042881011963, 0.039073556661605835, -1.0137548446655273, -0.2616872191429138, -0.02443857491016388, -0.22350150346755981, 0.5891871452331543, 0.11536568403244019, 0.238596111536026, 0.6672472953796387, 0.5128185153007507, 0.4972516894340515, 0.08291845768690109, 0.3685847222805023, 0.22705209255218506, 0.09468726813793182, 0.1946587860584259, -0.18977826833724976, -0.25072145462036133, -0.17389994859695435, -0.0627235621213913, -0.06792039424180984, -0.3037205934524536, -0.0964118167757988, 0.40414872765541077, 0.27389347553253174, 0.48578372597694397, 0.3921940326690674, -0.006353108678013086, 0.025571826845407486, 0.5271127223968506, 0.31628668308258057, 0.08076059073209763, -0.16156327724456787, 0.27964815497398376, -0.21380449831485748, 0.09072685241699219, 0.3978114724159241, -0.7595541477203369, -0.4650924801826477, 0.03597730025649071, -0.5835506916046143, -0.23086275160312653, -0.40489381551742554, -0.15294457972049713, -0.09210854768753052, 0.4230278432369232, -0.21248456835746765, 0.0866876021027565, -0.1595083326101303, 0.36659735441207886, -0.33145207166671753, 0.09303014725446701, 0.1515604555606842, 0.0542825311422348, 0.06470347940921783, 0.07563569396734238, 0.23725424706935883, -0.5856565833091736, -0.32469063997268677, 0.08702871203422546, 0.11871860921382904, -0.18188679218292236, 0.009085036814212799, 0.17707616090774536, 0.14014102518558502, 0.36464160680770874, 0.10451368987560272, 0.11333306133747101, -0.14408458769321442, -0.2230147123336792, -0.03670718893408775, 0.12168169021606445, 0.5221200585365295, 0.14179125428199768, 0.4116024076938629, 0.1895531266927719, -0.0966031402349472, -0.23411501944065094, -0.12904629111289978, -0.15878860652446747, 0.026737332344055176, 0.027480773627758026, -0.3579445779323578, -0.06405069679021835, -0.2708514928817749, -0.3039588928222656, 0.44613248109817505, 0.38006237149238586, 0.669472336769104, 0.25570863485336304, 0.13847386837005615, -0.35469919443130493, -0.3766522705554962, -0.30364564061164856, 0.3657338619232178, -0.04368864372372627, 0.025192372500896454, 0.833344042301178, 0.6542593240737915, 0.06918025016784668, 0.2163095474243164, -0.004826441407203674, 0.22486187517642975, -0.027937594801187515, -0.34793540835380554, -0.6077075600624084, -0.05355929583311081, -0.11814750730991364, 0.18249180912971497, -0.14365234971046448, -0.12587125599384308, 0.13327476382255554, 0.04563218355178833, -0.0543404296040535, 0.05790398642420769, 0.29406076669692993, -0.11858345568180084, -0.24213624000549316, -0.055022940039634705, -0.19703036546707153, -0.8023577928543091, -0.39739394187927246, 0.025507599115371704, 0.19748948514461517, 0.004848100244998932, -0.29243382811546326, 0.1927582323551178]]}
Binary file added examples/onnx/hierarchical_risk/network.onnx
Binary file not shown.
4 changes: 3 additions & 1 deletion src/tensor/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,9 +1342,11 @@ impl<F: PrimeField + TensorType + PartialOrd + std::hash::Hash> ValTensor<F> {
/// Gets the total number of elements in the tensor
pub fn len(&self) -> usize {
match self {
ValTensor::Value { dims, .. } => {
ValTensor::Value { dims, inner, .. } => {
if !dims.is_empty() && (dims != &[0]) {
dims.iter().product::<usize>()
} else if dims.is_empty() {
inner.inner.len()
} else {
0
}
Expand Down

0 comments on commit fcbb276

Please sign in to comment.