Turi Create
4.0
|
#include <toolkits/ml_data_2/iterators/composite_row_type.hpp>
A collection of subrows to put into a composite row container. Requires a composite_row_specification to first be defined; this specification determines how the container is going to be filled by the iterator.
The following code segment illustrates how this is to be used:
// Create a simple sframe sframe X = make_integer_testing_sframe( {"C0", "C1", "C2"}, { {1,2,3}, {4,5,6} } );
v2::ml_data data;
// Set column "C0" to be untranslated. data.set_data(X, "", {}, { {"C0", v2::ml_column_mode::UNTRANSLATED} });
data.fill();
auto row_spec = std::make_shared<v2::composite_row_specification>(data.metadata());
// Add one dense subrow formed from columns 1 and 2 size_t dense_row_index_1 = row_spec->add_dense_subrow( {1, 2} );
// Add a sparse subrow formed from column 2 size_t sparse_row_index = row_spec->add_sparse_subrow( {2} );
// Add an untranslated row formed from column 0 size_t flex_row_index = row_spec->add_flex_type_subrow( {0} );
// Add another dense subrow formed from column 1 size_t dense_row_index_2 = row_spec->add_dense_subrow( {1} );
v2::composite_row_container crc(row_spec);
////////////////////////////////////////
auto it = data.get_iterator();
{ it.fill_observation(crc);
// The 1st dense component; two numerical columns. const auto& vd = crc.dense_subrows[dense_row_index_1];
ASSERT_EQ(vd.size(), 2); ASSERT_EQ(size_t(vd[0]), 2); // First row, 2nd column ASSERT_EQ(size_t(vd[1]), 3); // First row, 3nd column
// The 2nd dense component; one numerical columns. const auto& vd2 = crc.dense_subrows[dense_row_index_2];
ASSERT_EQ(vd2.size(), 1); ASSERT_EQ(size_t(vd2[0]), 2); // First row, 2nd column
// The sparse component: one numerical column const auto& vs = crc.sparse_subrows[sparse_row_index];
ASSERT_EQ(vs.size(), 1); ASSERT_EQ(size_t(vs.coeff(0)), 3); // First row, 3nd column
// The untranslated column. const auto& vf = crc.flex_subrows[flex_row_index];
ASSERT_EQ(vf.size(), 1); ASSERT_TRUE(vf[0] == 1); // First row, 1st column }
Definition at line 90 of file composite_row_type.hpp.