Re: Assign to Array Column

2023-01-31 Thread Paul via Digitalmars-d-learn

On Wednesday, 1 February 2023 at 03:45:11 UTC, Salih Dincer wrote:

On Tuesday, 31 January 2023 at 01:04:41 UTC, Paul wrote:
Can I perform a similar assignment to the column?  This, 
myArr[][0] = 5, doesn't work.


Of course, this question has a short answer and a long answer. 
So the issue is more about column-major. I am someone who likes 
to talk with codes. In fact, everything is side by side in 
memory. This example (something like array) covers the issue:


Thanks Salih.  Much appreciated.


Re: Address of a class object

2023-01-31 Thread Paul via Digitalmars-d-learn

On Thursday, 5 January 2023 at 05:59:26 UTC, Ali Çehreli wrote:

On 1/4/23 20:04, Paul wrote:
>> (Again, there is no problem here; we are just learning.)
>> Ali
>
> Do I have this much right?

> ..with this output?

Looks good to me.

While we're here, you can force the class objects to be on the 
stack as well:


scope MyClassVar1 = new MyClass();

I replaced 'auto' with 'scope'.

Ali


I was tinkering with this use of 'scope' and the math for pointer 
location, object size, and alignment started working out.


Re: Assign to Array Column

2023-01-31 Thread Salih Dincer via Digitalmars-d-learn

Sorry, I forget this:

```d
enum : size_t {
  ROW = 3,
  COL = 3,
  SUM = ROW * COL
}
```
SDB@79




Re: Assign to Array Column

2023-01-31 Thread Salih Dincer via Digitalmars-d-learn

On Tuesday, 31 January 2023 at 01:04:41 UTC, Paul wrote:
Can I perform a similar assignment to the column?  This, 
myArr[][0] = 5, doesn't work.


Of course, this question has a short answer and a long answer. So 
the issue is more about column-major. I am someone who likes to 
talk with codes. In fact, everything is side by side in memory. 
This example (something like array) covers the issue:


```d
import std.stdio;

void main()
{
  int[COL][ROW] sample = [ [ 5, 5, 5 ],
   [ 0, 0, 0 ],
   [ 0, 0, 0 ],
 ];

  auto arrayish = Arrayish!int(ROW, COL);
  assert(arrayish.length == SUM);

  // copy array...
  foreach(r; 0..ROW)
  {
foreach(c; 0..COL)
{
  arrayish[r, c] = sample[r][c];
}
  }

  arrayish.print();

  foreach(n; 0..COL)
  {
//arrayish.columnMajor(n).writeln;/*
arrayish[n].writeln;//*/
  }

  // clear and set...
  arrayish.elements[] = 0;
  foreach(r; 0..ROW) arrayish[r] = 5;
  arrayish.print();
}

struct Arrayish(T) {
  private {
T[] elements;
const size_t row, col;
  }

  this(size_t row, size_t col) {
this.elements = new T[row * col];
this.row = row;
this.col = col;
  }

  ref T opIndex(size_t row = 0, size_t col = 0) {
return elements[row * this.col + col];
  }

  ref T columnMajor(size_t row = 0, size_t col = 0) {
return elements[col * this.row + row];
  }

  auto length() {
return row * col;
  }

  void print() {
foreach(r; 0..row) {
  foreach(c; 0..col)
this[r, c].write;
  writeln;
}
  }
} /* Prints:

555
000
000
5
0
0
500
500
500

*/

```
SDB@79


Re: More Elegant Settable Methods?

2023-01-31 Thread jwatson-CO-edu via Digitalmars-d-learn

On Monday, 30 January 2023 at 07:48:09 UTC, Salih Dincer wrote:
On Saturday, 21 January 2023 at 23:07:45 UTC, jwatson-CO-edu 
wrote:
I am trying to create a struct with a settable method that has 
access to the struct scope.

Is this the only way?
Is there a way to give access without explicitly passing 
`this`?


Why not use the delegate? What exactly do you want to do?  Set 
after constructor or assign delegate?


```d
struct S {
float /*--*/ a;
float /*--*/ b;

    void delegate(float x, float y) set;
    auto sum() { return a + b; }
}

void main() {
    S s;
    s.set = (x, y) {
        s.a = x;
        s.b = y;
    };
    s.set(10, 20);
    assert(s.sum == 30);
}
```

SDB@79


So `delegate` looks closer to what I want.  I am looking to 
implement a [Strategy 
Pattern](https://en.wikipedia.org/wiki/Strategy_pattern) in which 
I have an object with an  update method which is settable at 
runtime, either during instantiation or after. The function you 
have assigned to `set` has access to the `S` object, just like I 
had wished; Thank you!


The application is a [Braitenberg 
Vehicle](https://en.wikipedia.org/wiki/Braitenberg_vehicle) 
environment.  There are a more than a few component types that 
are connected to each other in the same way and pass messages of 
a consistent type.  I'd like not to write a struct/class for each 
component type; but rather write their common structure once and 
set their type-specific behavior as they are created.


It looks like I can write a function for each component type and 
assign a `delegate` update strategy after the common struct has 
been created.  This is what I had asked for.  Thank you for this 
lesson.





Re: hasUDA alternatives?

2023-01-31 Thread Anonymouse via Digitalmars-d-learn

On Saturday, 28 January 2023 at 17:16:07 UTC, Hipreme wrote:

[...]


Thank you. I incorporated some of these ideas and looked up how 
to profile the compilation with tracy, and now dmd memory 
requirements are down to ~2100 Mb. It's still a far cry from your 
250 Mb, however.


I changed it to only call `getSymbolsByUDA` once (per plugin 
module) and then filtered it by use of arrays of indices, like 
you suggested. This reduced memory needed by some 150 Mb; less 
than I had hoped but still a step in the right direction.


I then went through the compilation with tracy and removed, 
replaced or versioned out parts that the compiler seemed to spend 
a long time on in semantic analysis. I lost some functionality 
but the returns were considerable.


The remaining big offender seems to be `std.concurrency.send`. I 
consolidated some unique instantiations, but it's pretty core to 
how the thing works and I'm not sure what I can neatly do about 
that.