Skip to content

Commit

Permalink
EidosValue design overhaul, step 1
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Dec 20, 2023
1 parent b7dcd6a commit 20acfc7
Show file tree
Hide file tree
Showing 29 changed files with 643 additions and 761 deletions.
9 changes: 4 additions & 5 deletions core/chromosome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2041,8 +2041,7 @@ EidosValue_SP Chromosome::ExecuteMethod_setAncestralNucleotides(EidosGlobalStrin
else
{
// non-singleton, direct access
const EidosValue_Int_vector *int_vec = sequence_value->IntVector();
const int64_t *int_data = int_vec->data();
const int64_t *int_data = sequence_value->IntData();

ancestral_seq_buffer_ = new NucleotideArray(sequence_value_count, int_data);
}
Expand All @@ -2052,13 +2051,13 @@ EidosValue_SP Chromosome::ExecuteMethod_setAncestralNucleotides(EidosGlobalStrin
if (sequence_value_count != 1)
{
// A vector of characters has been provided, which must all be "A" / "C" / "G" / "T"
const std::vector<std::string> *string_vec = sequence_value->StringVector();
const std::string *string_data = sequence_value->StringData();

ancestral_seq_buffer_ = new NucleotideArray(sequence_value_count, *string_vec);
ancestral_seq_buffer_ = new NucleotideArray(sequence_value_count, string_data);
}
else // sequence_value_count == 1
{
const std::string &sequence_string = sequence_value->IsSingleton() ? ((EidosValue_String_singleton *)sequence_value)->StringValue() : (*sequence_value->StringVector())[0];
const std::string &sequence_string = sequence_value->StringData()[0];
bool contains_only_nuc = true;

// OK, we do a weird thing here. We want to try to construct a NucleotideArray
Expand Down
2 changes: 1 addition & 1 deletion core/community_eidos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ EidosValue_SP Community::GetProperty(EidosGlobalStringID p_property_id)
// variables
case gID_tick:
{
if (cached_value_tick_ && (((EidosValue_Int_singleton *)cached_value_tick_.get())->IntValue() != tick_))
if (cached_value_tick_ && (cached_value_tick_->IntData()[0] != tick_))
cached_value_tick_.reset();
if (!cached_value_tick_)
cached_value_tick_ = EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Int_singleton(tick_));
Expand Down
8 changes: 4 additions & 4 deletions core/genome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void Genome::SetProperty_Accelerated_tag(EidosObject **p_values, size_t p_values
}
else
{
const int64_t *source_data = p_source.IntVector()->data();
const int64_t *source_data = p_source.IntData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((Genome *)(p_values[value_index]))->tag_value_ = source_data[value_index];
Expand Down Expand Up @@ -767,7 +767,7 @@ EidosValue_SP Genome::ExecuteMethod_Accelerated_containsMutations(EidosObject **
EidosValue_SP result(logical_result);
int64_t result_index = 0;

EidosObject * const *mutations_data = mutations_value->ObjectElementVector()->data();
EidosObject * const *mutations_data = mutations_value->ObjectData();

for (size_t element_index = 0; element_index < p_elements_size; ++element_index)
{
Expand Down Expand Up @@ -1181,7 +1181,7 @@ EidosValue_SP Genome::ExecuteMethod_nucleotides(EidosGlobalStringID p_method_id,
else
{
// vector case: replace the appropriate element in char_value
std::vector<std::string> *char_vec = ((EidosValue_String_vector *)(char_value.get()))->StringVector_Mutable();
std::string &char_vec = char_value->StringData_Mutable()[0];
GenomeWalker walker(this);

walker.MoveToPosition(start);
Expand All @@ -1198,7 +1198,7 @@ EidosValue_SP Genome::ExecuteMethod_nucleotides(EidosGlobalStringID p_method_id,
int8_t nuc = mut->nucleotide_;

if (nuc != -1)
(*char_vec)[pos - start] = gSLiM_Nucleotides[nuc];
char_vec[pos - start] = gSLiM_Nucleotides[nuc];

walker.NextMutation();
}
Expand Down
59 changes: 28 additions & 31 deletions core/individual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ void Individual::SetProperty_Accelerated_tag(EidosObject **p_values, size_t p_va
}
else
{
const int64_t *source_data = p_source.IntVector()->data();
const int64_t *source_data = p_source.IntData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((Individual *)(p_values[value_index]))->tag_value_ = source_data[value_index];
Expand All @@ -1266,7 +1266,7 @@ void Individual::SetProperty_Accelerated_tagF(EidosObject **p_values, size_t p_v
}
else
{
const double *source_data = p_source.FloatVector()->data();
const double *source_data = p_source.FloatData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((Individual *)(p_values[value_index]))->tagF_value_ = source_data[value_index];
Expand All @@ -1277,9 +1277,11 @@ void Individual::SetProperty_Accelerated_tagL0(EidosObject **p_values, size_t p_
{
s_any_individual_tagL_set_ = true;

const eidos_logical_t *source_data = p_source.LogicalData();

if (p_source_size == 1)
{
eidos_logical_t source_value = p_source.LogicalAtIndex(0, nullptr);
eidos_logical_t source_value = source_data[0];

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Expand All @@ -1291,7 +1293,6 @@ void Individual::SetProperty_Accelerated_tagL0(EidosObject **p_values, size_t p_
}
else
{
const eidos_logical_t *source_data = p_source.LogicalVector()->data();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Expand All @@ -1307,9 +1308,11 @@ void Individual::SetProperty_Accelerated_tagL1(EidosObject **p_values, size_t p_
{
s_any_individual_tagL_set_ = true;

const eidos_logical_t *source_data = p_source.LogicalData();

if (p_source_size == 1)
{
eidos_logical_t source_value = p_source.LogicalAtIndex(0, nullptr);
eidos_logical_t source_value = source_data[0];

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Expand All @@ -1321,8 +1324,6 @@ void Individual::SetProperty_Accelerated_tagL1(EidosObject **p_values, size_t p_
}
else
{
const eidos_logical_t *source_data = p_source.LogicalVector()->data();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Individual *individual = ((Individual *)(p_values[value_index]));
Expand All @@ -1337,9 +1338,11 @@ void Individual::SetProperty_Accelerated_tagL2(EidosObject **p_values, size_t p_
{
s_any_individual_tagL_set_ = true;

const eidos_logical_t *source_data = p_source.LogicalData();

if (p_source_size == 1)
{
eidos_logical_t source_value = p_source.LogicalAtIndex(0, nullptr);
eidos_logical_t source_value = source_data[0];

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Expand All @@ -1351,8 +1354,6 @@ void Individual::SetProperty_Accelerated_tagL2(EidosObject **p_values, size_t p_
}
else
{
const eidos_logical_t *source_data = p_source.LogicalVector()->data();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Individual *individual = ((Individual *)(p_values[value_index]));
Expand All @@ -1367,9 +1368,11 @@ void Individual::SetProperty_Accelerated_tagL3(EidosObject **p_values, size_t p_
{
s_any_individual_tagL_set_ = true;

const eidos_logical_t *source_data = p_source.LogicalData();

if (p_source_size == 1)
{
eidos_logical_t source_value = p_source.LogicalAtIndex(0, nullptr);
eidos_logical_t source_value = source_data[0];

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Expand All @@ -1381,8 +1384,6 @@ void Individual::SetProperty_Accelerated_tagL3(EidosObject **p_values, size_t p_
}
else
{
const eidos_logical_t *source_data = p_source.LogicalVector()->data();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Individual *individual = ((Individual *)(p_values[value_index]));
Expand All @@ -1397,9 +1398,11 @@ void Individual::SetProperty_Accelerated_tagL4(EidosObject **p_values, size_t p_
{
s_any_individual_tagL_set_ = true;

const eidos_logical_t *source_data = p_source.LogicalData();

if (p_source_size == 1)
{
eidos_logical_t source_value = p_source.LogicalAtIndex(0, nullptr);
eidos_logical_t source_value = source_data[0];

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Expand All @@ -1411,8 +1414,6 @@ void Individual::SetProperty_Accelerated_tagL4(EidosObject **p_values, size_t p_
}
else
{
const eidos_logical_t *source_data = p_source.LogicalVector()->data();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Individual *individual = ((Individual *)(p_values[value_index]));
Expand Down Expand Up @@ -1478,7 +1479,7 @@ void Individual::SetProperty_Accelerated_fitnessScaling(EidosObject **p_values,
}
else
{
const double *source_data = p_source.FloatVector()->data();
const double *source_data = p_source.FloatData();

needs_raise = _SetFitnessScaling_N(source_data, p_values, p_values_size);
}
Expand All @@ -1498,7 +1499,7 @@ void Individual::SetProperty_Accelerated_x(EidosObject **p_values, size_t p_valu
}
else
{
const double *source_data = p_source.FloatVector()->data();
const double *source_data = p_source.FloatData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((Individual *)(p_values[value_index]))->spatial_x_ = source_data[value_index];
Expand All @@ -1516,7 +1517,7 @@ void Individual::SetProperty_Accelerated_y(EidosObject **p_values, size_t p_valu
}
else
{
const double *source_data = p_source.FloatVector()->data();
const double *source_data = p_source.FloatData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((Individual *)(p_values[value_index]))->spatial_y_ = source_data[value_index];
Expand All @@ -1534,7 +1535,7 @@ void Individual::SetProperty_Accelerated_z(EidosObject **p_values, size_t p_valu
}
else
{
const double *source_data = p_source.FloatVector()->data();
const double *source_data = p_source.FloatData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((Individual *)(p_values[value_index]))->spatial_z_ = source_data[value_index];
Expand Down Expand Up @@ -1573,12 +1574,12 @@ void Individual::SetProperty_Accelerated_color(EidosObject **p_values, size_t p_
}
else
{
const std::vector<std::string> *source_data = p_source.StringVector();
const std::string *source_data = p_source.StringData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
{
Individual *individual = ((Individual *)(p_values[value_index]));
const std::string &source_value = (*source_data)[value_index];
const std::string &source_value = source_data[value_index];

if (source_value.empty())
{
Expand Down Expand Up @@ -1606,7 +1607,7 @@ void Individual::SetProperty_Accelerated_age(EidosObject **p_values, size_t p_va
}
else
{
const int64_t *source_data = p_source.IntVector()->data();
const int64_t *source_data = p_source.IntData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((Individual *)(p_values[value_index]))->age_ = SLiMCastToAgeTypeOrRaise(source_data[value_index]);
Expand Down Expand Up @@ -2282,8 +2283,7 @@ EidosValue_SP Individual_Class::ExecuteMethod_setSpatialPosition(EidosGlobalStri
}
else if (target_size > 1)
{
const EidosValue_Object_vector *target_vec = p_target->ObjectElementVector();
Individual * const *targets = (Individual * const *)(target_vec->data());
Individual * const *targets = (Individual * const *)(p_target->ObjectData());

dimensionality = targets[0]->subpopulation_->species_.SpatialDimensionality();

Expand Down Expand Up @@ -2333,8 +2333,7 @@ EidosValue_SP Individual_Class::ExecuteMethod_setSpatialPosition(EidosGlobalStri
else if (target_size > 1)
{
// Vector target case, one point
const EidosValue_Object_vector *target_vec = p_target->ObjectElementVector();
Individual * const *targets = (Individual * const *)(target_vec->data());
Individual * const *targets = (Individual * const *)(p_target->ObjectData());

switch (dimensionality)
{
Expand Down Expand Up @@ -2391,10 +2390,8 @@ EidosValue_SP Individual_Class::ExecuteMethod_setSpatialPosition(EidosGlobalStri
else if (value_count == dimensionality * target_size)
{
// Vector target case, one point per target (so the point vector has to be non-singleton too)
const EidosValue_Object_vector *target_vec = p_target->ObjectElementVector();
Individual * const *targets = (Individual * const *)(target_vec->data());
const EidosValue_Float_vector *position_vec = position_value->FloatVector();
const double *positions = position_vec->data();
Individual * const *targets = (Individual * const *)(p_target->ObjectData());
const double *positions = position_value->FloatData();

#ifdef _OPENMP
if (((dimensionality == 1) && (target_size >= EIDOS_OMPMIN_SET_SPATIAL_POS_2_1D)) ||
Expand Down
4 changes: 2 additions & 2 deletions core/interaction_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3698,7 +3698,7 @@ EidosValue_SP InteractionType::ExecuteMethod_clippedIntegral(EidosGlobalStringID
}
else
{
receivers_data = (Individual * const *)receivers_value->ObjectElementVector()->data();
receivers_data = (Individual * const *)receivers_value->ObjectData();
}

InteractionsData &receiver_subpop_data = InteractionsDataForSubpop(data_, receivers_data[0]->subpopulation_);
Expand Down Expand Up @@ -6159,7 +6159,7 @@ EidosValue_SP InteractionType::ExecuteMethod_testConstraints(EidosGlobalStringID
else
{
// non-singleton case
Individual * const *inds = (Individual * const *)individuals_value->ObjectElementVector()->data();
Individual * const *inds = (Individual * const *)individuals_value->ObjectData();

if (returnIndividuals)
{
Expand Down
4 changes: 2 additions & 2 deletions core/mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ void Mutation::SetProperty_Accelerated_subpopID(EidosObject **p_values, size_t p
}
else
{
const int64_t *source_data = p_source.IntVector()->data();
const int64_t *source_data = p_source.IntData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((Mutation *)(p_values[value_index]))->subpop_index_ = SLiMCastToObjectidTypeOrRaise(source_data[value_index]);
Expand All @@ -688,7 +688,7 @@ void Mutation::SetProperty_Accelerated_tag(EidosObject **p_values, size_t p_valu
}
else
{
const int64_t *source_data = p_source.IntVector()->data();
const int64_t *source_data = p_source.IntData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((Mutation *)(p_values[value_index]))->tag_value_ = source_data[value_index];
Expand Down
4 changes: 2 additions & 2 deletions core/mutation_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ void MutationType::SetProperty_Accelerated_convertToSubstitution(EidosObject **p
}
else
{
const eidos_logical_t *source_data = p_source.LogicalVector()->data();
const eidos_logical_t *source_data = p_source.LogicalData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((MutationType *)(p_values[value_index]))->convert_to_substitution_ = source_data[value_index];
Expand All @@ -707,7 +707,7 @@ void MutationType::SetProperty_Accelerated_tag(EidosObject **p_values, size_t p_
}
else
{
const int64_t *source_data = p_source.IntVector()->data();
const int64_t *source_data = p_source.IntData();

for (size_t value_index = 0; value_index < p_values_size; ++value_index)
((MutationType *)(p_values[value_index]))->tag_value_ = source_data[value_index];
Expand Down
12 changes: 3 additions & 9 deletions core/population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,13 +826,8 @@ slim_popsize_t Population::ApplyMateChoiceCallbacks(slim_popsize_t p_parent1_ind
weights_modified = true;
}

// We really want to use EidosValue_Float_vector's FloatVector() method to get the values;
// if we have an EidosValue_Float_singleton we have to get its value with FloatAtIndex.
// BCH 1/18/2018: IsSingleton() should be much faster than the dynamic_cast<> used here before
if (!result->IsSingleton())
memcpy(current_weights, ((EidosValue_Float_vector *)result)->FloatVector()->data(), sizeof(double) * weights_length);
else
current_weights[0] = result->FloatAtIndex(0, nullptr);
// use FloatData() to get the values, copy them with memcpy()
memcpy(current_weights, result->FloatData(), sizeof(double) * weights_length);

// remember this callback for error attribution below
last_interventionist_mate_choice_callback = mate_choice_callback;
Expand Down Expand Up @@ -2512,8 +2507,7 @@ bool Population::ApplyRecombinationCallbacks(slim_popsize_t p_parent_index, Geno
p_crossovers[0] = (slim_position_t)local_crossovers_ptr->IntAtIndex(0, nullptr);
else
{
const EidosValue_Int_vector *new_crossover_vector = local_crossovers_ptr->IntVector();
const int64_t *new_crossover_data = new_crossover_vector->data();
const int64_t *new_crossover_data = local_crossovers_ptr->IntData();
slim_position_t *p_crossovers_data = p_crossovers.data();

for (int value_index = 0; value_index < count; ++value_index)
Expand Down
2 changes: 1 addition & 1 deletion core/slim_eidos_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ void SLiMTypeInterpreter::_SetTypeForISArgumentOfClass(const EidosASTNode *p_arg
// The argument can be numeric, in which case it must have a cached int value that is singleton and within bounds
EidosValue *cached_value = p_arg_node->cached_literal_value_.get();

if (cached_value && (cached_value->Type() == EidosValueType::kValueInt) && (cached_value->IsSingleton()))
if (cached_value && (cached_value->Type() == EidosValueType::kValueInt) && (cached_value->Count() == 1))
{
int64_t cached_int = cached_value->IntAtIndex(0, nullptr);

Expand Down
Loading

0 comments on commit 20acfc7

Please sign in to comment.