@@ -350,9 +350,9 @@ void RTNAME(Pack)(Descriptor &result, const Descriptor &source,
350
350
}
351
351
}
352
352
353
- } // extern "C" - TODO put Reshape under extern "C"
353
+ // RESHAPE
354
354
// F2018 16.9.163
355
- OwningPtr<Descriptor> RTNAME (Reshape)(const Descriptor &source,
355
+ void RTNAME (Reshape)(Descriptor &result, const Descriptor &source,
356
356
const Descriptor &shape, const Descriptor *pad, const Descriptor *order,
357
357
const char *sourceFile, int line) {
358
358
// Compute and check the rank of the result.
@@ -394,9 +394,10 @@ OwningPtr<Descriptor> RTNAME(Reshape)(const Descriptor &source,
394
394
RUNTIME_CHECK (terminator, order->GetDimension (0 ).Extent () == resultRank);
395
395
std::uint64_t values{0 };
396
396
SubscriptValue orderSubscript{order->GetDimension (0 ).LowerBound ()};
397
+ std::size_t orderElementBytes{order->ElementBytes ()};
397
398
for (SubscriptValue j{0 }; j < resultRank; ++j, ++orderSubscript) {
398
- auto k{GetInt64 (order->OffsetElement <char >(orderSubscript),
399
- shapeElementBytes, terminator)};
399
+ auto k{GetInt64 (order->Element <char >(& orderSubscript), orderElementBytes ,
400
+ terminator)};
400
401
RUNTIME_CHECK (
401
402
terminator, k >= 1 && k <= resultRank && !((values >> k) & 1 ));
402
403
values |= std::uint64_t {1 } << k;
@@ -408,64 +409,33 @@ OwningPtr<Descriptor> RTNAME(Reshape)(const Descriptor &source,
408
409
}
409
410
}
410
411
411
- // Create and populate the result's descriptor.
412
- const DescriptorAddendum *sourceAddendum{source.Addendum ()};
413
- const typeInfo::DerivedType *sourceDerivedType{
414
- sourceAddendum ? sourceAddendum->derivedType () : nullptr };
415
- OwningPtr<Descriptor> result;
416
- if (sourceDerivedType) {
417
- result = Descriptor::Create (*sourceDerivedType, nullptr , resultRank,
418
- resultExtent, CFI_attribute_allocatable);
419
- } else {
420
- result = Descriptor::Create (source.type (), elementBytes, nullptr ,
421
- resultRank, resultExtent,
422
- CFI_attribute_allocatable); // TODO rearrange these arguments
423
- }
424
- DescriptorAddendum *resultAddendum{result->Addendum ()};
425
- RUNTIME_CHECK (terminator, resultAddendum);
426
- resultAddendum->flags () |= DescriptorAddendum::DoNotFinalize;
427
- if (sourceDerivedType) {
428
- std::size_t lenParameters{sourceAddendum->LenParameters ()};
429
- for (std::size_t j{0 }; j < lenParameters; ++j) {
430
- resultAddendum->SetLenParameterValue (
431
- j, sourceAddendum->LenParameterValue (j));
432
- }
433
- }
434
- // Allocate storage for the result's data.
435
- for (int j{0 }; j < resultRank; ++j) {
436
- result->GetDimension (j).SetBounds (1 , resultExtent[j]);
437
- }
438
- int status{result->Allocate ()};
439
- if (status != CFI_SUCCESS) {
440
- terminator.Crash (" RESHAPE: Allocate failed (error %d)" , status);
441
- }
412
+ // Allocate result descriptor
413
+ AllocateResult (
414
+ result, source, resultRank, resultExtent, terminator, " RESHAPE" );
442
415
443
416
// Populate the result's elements.
444
417
SubscriptValue resultSubscript[maxRank];
445
- result-> GetLowerBounds (resultSubscript);
418
+ result. GetLowerBounds (resultSubscript);
446
419
SubscriptValue sourceSubscript[maxRank];
447
420
source.GetLowerBounds (sourceSubscript);
448
421
std::size_t resultElement{0 };
449
422
std::size_t elementsFromSource{std::min (resultElements, sourceElements)};
450
423
for (; resultElement < elementsFromSource; ++resultElement) {
451
- CopyElement (* result, resultSubscript, source, sourceSubscript, terminator);
424
+ CopyElement (result, resultSubscript, source, sourceSubscript, terminator);
452
425
source.IncrementSubscripts (sourceSubscript);
453
- result-> IncrementSubscripts (resultSubscript, dimOrder);
426
+ result. IncrementSubscripts (resultSubscript, dimOrder);
454
427
}
455
428
if (resultElement < resultElements) {
456
429
// Remaining elements come from the optional PAD= argument.
457
430
SubscriptValue padSubscript[maxRank];
458
431
pad->GetLowerBounds (padSubscript);
459
432
for (; resultElement < resultElements; ++resultElement) {
460
- CopyElement (* result, resultSubscript, *pad, padSubscript, terminator);
433
+ CopyElement (result, resultSubscript, *pad, padSubscript, terminator);
461
434
pad->IncrementSubscripts (padSubscript);
462
- result-> IncrementSubscripts (resultSubscript, dimOrder);
435
+ result. IncrementSubscripts (resultSubscript, dimOrder);
463
436
}
464
437
}
465
-
466
- return result;
467
438
}
468
- extern " C" { // TODO - remove when Reshape is under extern "C"
469
439
470
440
// SPREAD
471
441
void RTNAME (Spread)(Descriptor &result, const Descriptor &source, int dim,
0 commit comments