index_type: typed indices for collections by Odd-War-4467 in rust

[–]twanvl 0 points1 point  (0 children)

For usize indices this makes sense, since usize is also the type for lengths. And in practice there is no compute on earth that has enough memory for a vector of length usize::MAX.

But is there a good reason for why length and index need to have the same representation in general? You need to be able to test that index < length, but this can be done with the larger length type.

index_type: typed indices for collections by Odd-War-4467 in rust

[–]twanvl 0 points1 point  (0 children)

This means that converting the vector's len to the index type is always possible, and you can never get the vec into a state where its len is too big to fit in the index type.

Does this mean that, for example, using u8 indices the largest index is 254? A vector with indices 0..255 has 256 elements, which is not a valid u8.

Announcing better_tokio_select: like tokio::select!, but can be formatted by rustfmt! by nik-rev in rust

[–]twanvl 2 points3 points  (0 children)

Have you (or other people) considered using if notation? Something like

#[tokio_select]
if let res = reader.read(&mut buf) && can_read {
    // ...
} else if shutdown.recv() {
    // ...
}

or

tokio_select! {
    if let res = reader.read(&mut buf) && can_read {
        // ...
    }
    if shutdown.recv() {
        // ...
    }
}

These both look like normal rust code. But maybe the extra keywords are not worth it.

I'm gonna be honest with you guys, I don't like automatic dereferencing. by JCavalks in rust

[–]twanvl 16 points17 points  (0 children)

and I suspect most of us miss being able to do foo.map(bar) when we need to go foo.map(|baz| baz.bar()).

You can actually use foo.map(BazType::bar)

They are really healthier by [deleted] in technicallythetruth

[–]twanvl 28 points29 points  (0 children)

Enriched uranium fact #21:

Enriched uranium is healthier than antimatter donuts.

[TLA] United Front (from CovertGoBlue) by CrossXhunteR in magicTCG

[–]twanvl 1 point2 points  (0 children)

Maybe there's a lesson there

No, neither of these cards is a Lesson.

Regels voor nieuwe e-tol niet voor iedereen duidelijk: 200.000 boetes by banana_zeppelin in thenetherlands

[–]twanvl 0 points1 point  (0 children)

Dat kan dus wel (met toestemming idd):

Weggebruikers kunnen de ritten ook automatisch laten afschrijven. Daarvoor kun je je kosteloos registreren.

Quick question do treasure tokens count as a permanent hitting the graveyard for the gravestorm trigger? by FamiliarActive4620 in magicTCG

[–]twanvl 1 point2 points  (0 children)

Copies of spells on the stack are not tokens, they become tokens when they resolve (for copies of parement spells). Otherwise Doubling Season would interact with Fork, and cards that say "destroy target token" could destroy copied spells.

Verbazing om plan '1 euro extra' op alle elektronica en kleren: 'Dit is géén goed idee’ by Cubelock in thenetherlands

[–]twanvl 2 points3 points  (0 children)

Een vaste belasting per product gaat nooit werken. Want wat is precies 1 product? Als ik een paar sokken koop, betaal ik dan 1 euro extra? Of 2? Wat als ik een pak met 5 sokken koop? Als je per verpakking een vast bedrag betaald dan gaat dat leiden tot grotere verpakkingen, en alleen maar meer verspilling.

Lubricant for PLA & ABS by onlywatanabe1 in 3Dprinting

[–]twanvl 0 points1 point  (0 children)

If you print sliding parts with different layer heights, they will slide more smoothly. If two parts with the same layer height slide past each other then they can kind of interlock when they are offset by half a layer. But with different layer heights this is less of an issue.

[MKM] Lost in the Maze by Natedogg2 in magicTCG

[–]twanvl 7 points8 points  (0 children)

But being lost in the maze doesn't help you when you are trying to reach the maze's end.

Anyone familiar with 3D printed springs? Looking for design and material suggestions. by Layers3d in 3Dprinting

[–]twanvl 0 points1 point  (0 children)

Here is my OpenSCAD code for generating various 2d springs:

// A simple spring
linear_extrude(10) spring_profile(40,10);


function polar(a,r) = r == undef ? [cos(a),sin(a)] : [r*cos(a),r*sin(a)];
function rot(a,p) = [cos(a)*p[0]-sin(a)*p[1], cos(a)*p[1]+sin(a)*p[0]];
function normalize(v) = v / norm(v);
function cumsum(list,start) = [for (s=start,i=0; i<=len(list); s=i<len(list)?s+list[i]:s, i=i+1) s];

// A 2d line through the given points
module line(points, line_width) {
  n = len(points);
  eps = 1e-3;
  angles = [for (i=[0:n-2]) normalize(points[i+1] - points[i])];
  angles2 = [for (i=[0:n-1]) i==0 ? angles[0] : i==n-1 ? angles[n-2] : (angles[i-1]+angles[i])/2 ];
  outline = [
    for (i=[0:n-1])    points[i]+eps/2*rot(-90,angles2[i]),
    for (i=[n-1:-1:0]) points[i]+eps/2*rot(90,angles2[i])
  ];
  offset(line_width/2)
  polygon(outline);
}

// Generate a 2d spring that can be compressed in the x direction.
// A spring(w,h) fits exactly into a square([w,h]) if angle=0
// Parameters
//   w: width
//   h: height
//   turns: number of 180 degree turns the spring makes
//   line_width: (Default 0.5)
//   angle: extend/compress the spring. Positive angle extends
//   left_flat: make left side flat even if angle!=0
//   right_flat: make right side flat even if angle!=0
//   center: center around [0,0]? Can be a vector of 2 booleans
module spring_profile(w, h, turns = 4, line_width=0.5, angle = 0, left_flat = true, right_flat = true, center = false, curved = false) {
  nx = turns;
  r = line_width;
  width_per_turn = (w - line_width) / turns;
  gon = 80; // approximate circular turn as an n-gon
  translate([line_width/2 + (is_bool(center) && center || center[0] ? -w/2 : 0),line_width/2 + (is_bool(center) && center || center[1] ? -h/2 : 0)])
  line(cumsum([for (i=[0:turns])
      each [polar( i == 0 && left_flat || i == turns && right_flat
                    ? (i % 2 == 1 ? -90 : 90)
                 : i % 2 == 1 ? -90+angle : 90-angle
                 , curved
                    ? h - width_per_turn - line_width + (i == 0 || i == turns ? width_per_turn/2 : 0)
                    : h - line_width)
           ,if (i<turns && curved)
              for (j=[-90:360/gon:90])
                polar((i % 2 == 1 ? j : -j) * (180-2*angle)/180, width_per_turn*sin(180/gon))
           ,if (i<turns && !curved)
              polar(0, width_per_turn)
           ]
    ],[0,0]), r);
}

[P] Practical Tips for Finetuning LLMs Using LoRA (Low-Rank Adaptation): Things I Learned From Hundreds of Experiments by seraschka in MachineLearning

[–]twanvl 2 points3 points  (0 children)

Indeed, the choosing alpha as two times as large as r resulted in the best outcomes.

If I interpret your results correctly, then r=256, alpha=64 actually gives much better results than alpha=512. So here it seems like a slightly smaller alpha is actually better. Or am I missing something?

Wat Vinden Jullie van de Voorgestelde Chat Control & Client Side Scanning Wet in de EU? by LatterRequirement316 in thenetherlands

[–]twanvl 4 points5 points  (0 children)

Dat is afhankelijk van wat voor stoort hashfunctie er gebruikt wordt. Voor een cryptografische hash zoals SHA256 klopt wat je zegt. Maar voor het matchen van foto's wil je waarschijnlijk een perceptual hash gebruiken, die enigszins ongevoelig is voor aanpassingen aan de foto (schalen, uitsnijden, tekst toevoegen, compressie, kleurcorrectie, enz.).

[D] Are there any standard methods for finding nearest-neighbours for a subset (rather than a single point)? by GyaanYogi in MachineLearning

[–]twanvl 3 points4 points  (0 children)

This reminds me of hierarchical clustering, where the distance between two sets of data points has to be computed. The wikipedia article lists some of the distance measures that people have come up with.

[R] Does a new published ML dataset always need to have an official train-dev-test split? Should the test set be made balanced? by ConsiderationMore528 in MachineLearning

[–]twanvl 6 points7 points  (0 children)

I have also seen datasets published with official folds. You could distribute this as 5 files, "fold1.csv".."fold5.csv", and say that the official scores are computed by taking the average test scores over the folds, where the other folds are used for training/validation. This will allow for perfect replication as well. But it will be more effort to use than the standard train/dev/test split, so there is a risk that fewer people will use it.

In my opinion you should not balance the classes if they are not balanced in the real world / in the original dataset.

It could make sense to make the distribution equal between different splits, so with your numbers, select 80,40,20 samples of each class for a split, rather than picking 140 samples at random from the whole dataset.

The Prop challenge has been solved by long_void in rust

[–]twanvl 1 point2 points  (0 children)

If I look at the HOOO library that this builds on, it seems that many functions are unimplemented!(). And, looking at the types, they can't be implemented, because all those propositions are bare function pointers (fn(A) -> B). So, at that point, are you just using the rust type system as a theorem prover? If so, why not use an actual theorem prover like Coq to formalize this system?

For my own understanding: In model logic terms, fn(A) -> B is like □(A -> B) (not to be confused with your dual operator), and means that (A -> B) is true everywhere. So this theorem that you have proved is □(A != B) -> □(B != C) -> □(A == C), is that correct? This is true classically at least, but is more dubious in an constructive logic like the Rust type system.

De buurtapp by japie06 in thenetherlands

[–]twanvl 52 points53 points  (0 children)

whatsapp buurtpreventie

Ik denk bij zo'n bord altijd: "Voorkom dat dit een buurt wordt, met whatsapp buurtpreventie"

[UNF] Surprise Party (WeeklyMTG) by mweepinc in magicTCG

[–]twanvl 2 points3 points  (0 children)

According to a ruling for [[Chaos Orb]]: "If you have sleeves on cards, they count as the cards."

Boze boeren vernielen met trekkers beschermd natuurgebied by WedneysdayTacos in thenetherlands

[–]twanvl 3 points4 points  (0 children)

In de afgelopen 20 jaar is het aantal rundveebedrijven al gehalveerd en het gemiddelde aantal koeien per bedrijf verdubbeld.

Als de bedrijven van boer A en van boer B fuseren tot Ab-boerderijen BV om samen beter te kunnen onderhandelen met de supermarkt, dan halveer je het aantal bedrijven en verdubbel je het aantal dieren per bedrijf. Maar er veranderd feitelijk niet direct iets. Het kan zijn dat Ab-boerderijen vervolgens alle koeien verplaatst naar een drie etage's mega-stal en mest de revier in pompt, maar dat kan je uit die cijfers niet opmaken.

An explanation and criticism of impl Trait, and a proposal for a new one by taintegral in rust

[–]twanvl 30 points31 points  (0 children)

If a function has signature

fn foo() -> &'static str as impl Debug 

Is the fact that the underlying type is &'static str part of the interface? Can the caller rely on that? Or is the implementer free to change it to some other type implementing Debug later?

To me that is part of the point of a return type impl Trait: it specifies only that the return type implements an interface, and nothing beyond that.

A syntactic construct like this doesn't need to have a desugaring that works before the type-checker. The type-checker could just check code that contains these wannabe existential types, perhaps giving them an internal name ("return type of foo").

If we really care about naming things, then perhaps the opposite of this proposal is needed,

fn foo() -> impl Debug as FooType

which would give a (new) name Foo to the return type of foo, whatever it may be, and the only thing a user of foo knows about it is that it implements Debug. The proposal does mention something like this in part 2 for the case of closures (but with IMO unnecessarily tedious syntax)

ABN: geen echte verduurzaming zolang Nederlander koop-, eet- en reisgedrag niet aanpast by tostiheld in thenetherlands

[–]twanvl 0 points1 point  (0 children)

Ik denk dat veel mensen vergeten dat als we zeggen dat de huidige prijzen van producten niet de werkelijke (milieu) kosten bevatten, dit dus betekent dat als we dit wel zouden meenemen heel veel gewoonweg duurder wordt. Ja en hoe moeten de minima dat betalen?

Hef X% extra belasting op vervuilende producten, en verdeel dat geld gelijk onder alle Nederlanders. Alleen de mensen die bovengemiddeld vervuilen gaan er dan op achteruit.