Skip to content

Conversation

@jokasimr
Copy link
Contributor

@jokasimr jokasimr commented Sep 14, 2023

Fixes #3125.

Should I add a test for size_of for a Variable containing many strings?
What is the c++ api equivalent of sc.scalar('abc').broadcast(dims=('x',), shape=(1000000,))?

@jokasimr jokasimr requested a review from jl-wynen September 14, 2023 11:51
Copy link
Member

@SimonHeybrock SimonHeybrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add a test for size_of for a Variable containing many strings?
What is the c++ api equivalent of sc.scalar('abc').broadcast(dims=('x',), shape=(1000000,))?

You need something like

Dimensions dims(Dim::X, 1000000);
broadcast(makeVariable<std::string>(Values{'abc'}), dims);

iirc

out += sizeof(std::string) + str.size();
}
}
void operator()(scipp::index &out, const scipp::index &s) { out += s; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you could have put this in the overloaded above, by adding another lambda there. Then the diff would be much smaller.

@jokasimr
Copy link
Contributor Author

D:\a\scipp\scipp\lib\dataset\test\size_of_test.cpp(155): error: Expected equality of these values:
  size_of(var, SizeofTag::ViewOnly)
    Which is: 35000256
  view_size
    Which is: 32000256
D:\a\scipp\scipp\lib\dataset\test\size_of_test.cpp(156): error: Expected equality of these values:
  size_of(var, SizeofTag::Underlying)
    Which is: 291
  str_size + object_size
    Which is: 288
[  FAILED  ] SizeOf.variable_of_many_strings (1 ms)

Interesting @jl-wynen, here we get the opposite (this is Windows).

@jl-wynen
Copy link
Member

The small string optimisation depends on the standard library implementation. It is possible that the Windows library doesn't do it. To circumvent, you could use a long string to ensure a heap allocation. Something like 10-20 elements should do.

@jokasimr jokasimr force-pushed the fix-sizeof-large-str branch from e3fd9da to a2d5553 Compare September 14, 2023 14:25
@jokasimr jokasimr force-pushed the fix-sizeof-large-str branch from 4f6050f to b1741ce Compare September 25, 2023 07:41
@jokasimr jokasimr merged commit 0054cb7 into main Sep 25, 2023
@jokasimr jokasimr deleted the fix-sizeof-large-str branch September 25, 2023 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception from HTML repr for variable with many strings

4 participants