Donate to Remove ads

Got a credit card? use our Credit Card & Finance Calculators

Thanks to Wasron,jfgw,Rhyd6,eyeball08,Wondergirly, for Donating to support the site

OpenAI \ ChatGPT

Scientific discovery and discussion
Watis
Lemon Quarter
Posts: 1423
Joined: November 5th, 2016, 10:53 am
Has thanked: 356 times
Been thanked: 500 times

Re: OpenAI \ ChatGPT

#588332

Postby Watis » May 10th, 2023, 11:15 pm

Could this be the next iteration?

Auto-GPT is able to write its own prompts once it has been set a task, potentially enabling it to produce the desired results without further intervention.

I wonder whether it would help Sorcery and others here with their quest to get useful work from one of the GPT tools?

Details here: https://www.zdnet.com/article/what-is-a ... l-ai-tool/

Watis

JohnB
Lemon Quarter
Posts: 2509
Joined: January 15th, 2017, 9:20 am
Has thanked: 696 times
Been thanked: 1008 times

Re: OpenAI \ ChatGPT

#588336

Postby JohnB » May 10th, 2023, 11:30 pm

Google fight back by rushing out improvements to Bard, and threaten their search results will be couched in GPT waffle https://www.theguardian.com/technology/ ... f-the-pack
https://www.bbc.co.uk/news/technology-65545864

servodude
Lemon Half
Posts: 8413
Joined: November 8th, 2016, 5:56 am
Has thanked: 4490 times
Been thanked: 3621 times

Re: OpenAI \ ChatGPT

#588338

Postby servodude » May 10th, 2023, 11:52 pm

mc2fool wrote:So, in summary, two good suggestions (use strict/warnings and "my"), two suggestions that were what was in the program already, and one suggestion that totally wrecked the utility of the program. Along with repeated confusion about the form of the print function used and an inability to sequentially number a list. All round, pretty useless....


It's been trained on the internet..
Consider if someone had asked about a coding question on a forum
- so for every great answer (if there is one) there's normally a bunch of wrong or irrelevant or misunderstanding responses

I really expect that for all the examples these have been trained on the majority of the information will be at best mediocre.

You would have wanted it to pick up quickly on the obvious anti-patterns sorcery had shown it but it behaves at best as if it's just digested a syntax manual - the kind of guy on your team that is just a time sink

I really should see if I've got hardware and cycles to set up my own and train it on the output of Pike, Kernigan, Hoare etc

-sd

jfgw
Lemon Quarter
Posts: 2565
Joined: November 4th, 2016, 3:36 pm
Has thanked: 1108 times
Been thanked: 1167 times

Re: OpenAI \ ChatGPT

#588465

Postby jfgw » May 11th, 2023, 3:29 pm

odysseus2000 wrote:Wolfram talking to Fridman about computer consciousness (9 mins 23):

https://youtu.be/pXha5xzyypw

Wolfram has interesting views comparing start to crash as being like a life for any computer, not just a llm.

Regards,


Complete and utter @@ in my opinion.

If everything with processing power is conscious, how come I am not aware of the functions of my autonomic nervous system? I am not consciously aware of, and do not (and cannot) control my heart rate, digestive system, temperature, nor many other functions that I do not even know exist.* Almost everything that happens in my brain does not involve consciousness. If I walk or cycle, I can admire the view and just let my legs, arms and body get on with what they are doing, consciously intervening only when I want or need to. I perform the complex task of keeping my balance without even knowing how I do it.

My brain is massively parallel but I can only concentrate my mind on one thing at a time, and I am limited in what I can concentrate on. For example, I cannot concentrate on what my endocrine system is doing as I do not have conscious access to it. If someone is engrossed in a book, they may not even hear their name being called — they may not be conscious of their own hearing!

*If I am aware of my heart beat, it is because I can feel it, not because I am directly aware of what my heart is doing. If I have a fever, I may actually feel cold because my unconscious immune system is calling for my temperature to be higher in order to help fight the infection.


Julian F. G. W.

XFool
The full Lemon
Posts: 12636
Joined: November 8th, 2016, 7:21 pm
Been thanked: 2609 times

Re: OpenAI \ ChatGPT

#588467

Postby XFool » May 11th, 2023, 3:42 pm

servodude wrote:I really should see if I've got hardware and cycles to set up my own and train it on the output of Pike, Kernigan, Hoare etc

"Pike"?

Possibly I'm just too old...

Sorcery
Lemon Quarter
Posts: 1242
Joined: November 4th, 2016, 6:38 pm
Has thanked: 148 times
Been thanked: 377 times

Re: OpenAI \ ChatGPT

#588504

Postby Sorcery » May 11th, 2023, 7:18 pm

Another conversation with ChatGPT. This time rather than offering my code, and asking for it to be reviewed, I asked it to generate code to a spec. This was much more productive. However the idea that it has no memory, I find a little mind boggling. Final code has not been checked in the realworld yet.

Interactive conversation follows :

2 / 2

I apologize for the confusion and any frustration I may have caused. It was not my intention to waste your time or provide incorrect information. As an AI language model, I don't have the ability to keep track of past interactions, so I may have misunderstood your request. If you could please provide me with the code for the nextblack function and any additional information or requirements, I would be happy to assist you to the best of my abilities.





User
It is going to be difficult to proceed with nextblack if you cannot remember from one interaction to the next the contents of say a simplish function. Would it help if you wrote the function to my instructions?
ChatGPT
I apologize for any confusion earlier. I'm here to help, and I'm happy to write the nextblack function based on your instructions. Please provide me with the instructions, including the expected input and output of the function, as well as any additional requirements or constraints. I'll do my best to write the function accordingly.





User
Ok.
ChatGPT
Sure, I can give it a try. What are the instructions for the nextblack function? Please provide any specific requirements or rules for the function.





User
In C the function should take the following arguments : long nextblack(BYTE *mp, long maxbits, long sbit)
BYTE is a synonym for an array of "unsigned char" . "*mp" is a pointer to it. *mp typically points to a row of a bitmap where each bit is either 0 (white) or 1 (black). The bits are ordered from least significant to most significant.
ChatGPT
Thank you for providing the arguments for the nextblack function in C. Based on your description, it sounds like the nextblack function will search for the next occurrence of a black pixel in a bitmap image represented as an array of unsigned char. Here is a possible implementation of the nextblack function:

c
Copy code
long nextblack(BYTE *mp, long maxbits, long sbit) {
long byte_idx = sbit / 8; // calculate the byte index of the starting bit
long bit_idx = sbit % 8; // calculate the bit index within the starting byte
BYTE byte_val = mp[byte_idx]; // get the value of the starting byte
byte_val >>= bit_idx; // shift right to align the starting bit with the LSB
long bit_pos = sbit; // initialize the current bit position to the starting bit

while (byte_idx < maxbits) {
if (byte_val & 0x01) { // check if the LSB is 1
return bit_pos; // found a black pixel, return its bit position
}
byte_val >>= 1; // shift right to check the next bit
bit_pos++; // increment the current bit position
bit_idx++; // increment the bit index within the current byte

if (bit_idx == 8) { // if we have checked all bits in the current byte
bit_idx = 0; // reset the bit index
byte_idx++; // move to the next byte
if (byte_idx < maxbits) {
byte_val = mp[byte_idx]; // get the value of the next byte
}
}
}

return -1; // no black pixel found within the given range
}
This implementation starts searching for a black pixel from the sbit position and returns the bit position of the next black pixel found in the bitmap. If no black pixel is found within the given range, it returns -1.

Note that this is just one possible implementation and there may be other ways to implement the nextblack function depending on the specific requirements and constraints of your application.





User
That's a good guess, However maxbits is what should returned in the case of no black bits found.
ChatGPT
I apologize for the confusion earlier. Thank you for clarifying that maxbits should be returned in the case where no black bits are found.

Here's a possible implementation for the nextblack function in C based on your specifications:

java
Copy code
long nextblack(BYTE *mp, long maxbits, long sbit) {
long byte_idx = sbit / 8; // Index of the byte containing the sbit-th bit
long bit_idx = sbit % 8; // Index of the sbit-th bit within the byte

BYTE mask = 1 << bit_idx; // Create a mask with only the sbit-th bit set to 1

// Iterate over the bytes in the bitmap starting from byte_idx
for (long i = byte_idx; i < maxbits / 8; i++) {
BYTE b = mp[i];

// If the sbit-th bit is set in this byte or there are any bits set to 1 after it, return the index of the next black bit
if ((b & mask) || (b >> (bit_idx + 1))) {
return i * 8 + __builtin_ctz(b & ~((1 << bit_idx) - 1));
}

// Set the mask to 1 for the next bit in the next byte
mask = 1;
bit_idx = 0;
}

// No black bits found, return maxbits
return maxbits;
}
Here's how the function works:

byte_idx and bit_idx are calculated to determine the starting position of the search.
A mask is created with only the sbit-th bit set to 1.
The function iterates over the bytes in the bitmap, starting from byte_idx. For each byte:
If the sbit-th bit is set or there are any bits set to 1 after it, the index of the next black bit is returned.
Otherwise, the mask is set to 1 for the next bit in the next byte.
If no black bits are found, the function returns maxbits.
Note that this implementation assumes that maxbits is a multiple of 8, which is typical for bitmaps. If this is not the case, the function can be modified to handle the remaining bits separately.





User
can you explain what this part of the code does in quotes // If the sbit-th bit is set in this byte or there are any bits set to 1 after it, return the index of the next black bit
if ((b & mask) || (b >> (bit_idx + 1))) {
return i * 8 + __builtin_ctz(b & ~((1 << bit_idx) - 1));
}
ChatGPT
Certainly! Here's what that code does:

(b & mask) checks if the sbit-th bit (the bit at position sbit - 1) is set (equal to 1) in the current byte b. mask is a bit mask where the sbit-th bit is set to 1 and all other bits are set to 0. If the sbit-th bit is set, then the condition (b & mask) is true.

(b >> (bit_idx + 1)) checks if there are any bits set to 1 after the sbit-th bit in the current byte b. It does this by shifting the bits of b to the right by bit_idx + 1 positions and then checking if any of the shifted bits are set to 1. If there are any bits set to 1 after the sbit-th bit, then the condition (b >> (bit_idx + 1)) is true.

If either of the conditions in steps 1 or 2 is true, then the code inside the if statement is executed. This code finds the index of the next black bit after the current byte b. It does this by first masking off all the bits before the sbit-th bit in b using ~((1 << bit_idx) - 1), which sets all bits before the sbit-th bit to 1 and all bits after it to 0. The result of this operation is then ANDed with b to keep only the bits after the sbit-th bit. Finally, the index of the next black bit is computed using the __builtin_ctz function, which returns the number of trailing zeros (i.e., the index of the least significant bit that is set to 1) in the resulting value. The overall index of the next black bit is then computed by adding this value to i * 8, which gives the index of the current byte in the array mp.





User
I would need to test that works to be sure. It does not compile unfortunately, there is no such function "__builtin_ctz". However I would prefer for speed reasons, that we do net check a bit at time but a byte at a time. Is that possible with the inclusion of say lookup tables?
ChatGPT
Yes, using lookup tables can speed up the process of searching for the next black bit by checking a byte at a time instead of a bit at a time. One way to do this is to create lookup tables for each possible byte value (0 to 255) that contain the index of the next black bit in that byte.

Here's an example implementation of the nextblack function using lookup tables:

arduino
Copy code
#define BYTE unsigned char

// Lookup table for the next black bit in a byte
static const int next_black_bit[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0-15
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 16-31
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 32-47
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 48-63
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 64-79
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 80-95
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 96-111
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 112-127
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // 128-143
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // 144-159
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // 160-175
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,




User
The implementation is too short. It seems to have stopped before the "next_black_bit" table was complete.
ChatGPT

2 / 2

I apologize for the confusion. It seems that the implementation I provided was incomplete. Here's the updated implementation that includes the complete next_black_bit table:

c
Copy code
#include <stdio.h>
#include <stdint.h>

#define BYTE uint8_t

// Table of the position of the next black bit in a byte
const BYTE next_black_bit[256] = {
8, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4,
7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3,
7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3,
6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2,
7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3,
6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2,
6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2,
5, 4, 4, 3, 4, 3, 3, 2, 3, 2, 2, 1, 2, 1, 1, 0,
7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3,
6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2,
6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2,
5, 4, 4, 3, 4, 3, 3, 2, 3, 2, 2, 1, 2, 1, 1, 0,
6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2,
5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1,
5, 4




User
The table generation did not complete.
ChatGPT
My apologies for the error in the previous implementation. Here is a corrected implementation that generates the next_black_bit table and uses it to implement the nextblack function efficiently:

c
Copy code
#include <stdlib.h>
#include <stdint.h>

#define BYTE uint8_t

static int next_black_bit[256];

void generate_next_black_bit_table() {
for (int i = 0; i < 256; i++) {
int next_bit = 8;
for (int j = 0; j < 8; j++) {
if (i & (1 << j)) {
next_bit = j;
break;
}
}
next_black_bit[i] = next_bit;
}
}

long nextblack(BYTE *mp, long maxbits, long sbit) {
long bit_idx = sbit % 8;
BYTE mask = (1 << bit_idx) - 1;
BYTE *p = mp + (sbit / 8);
long n = (maxbits - sbit) / 8;

// check bits in the current byte
BYTE b = *p & ~mask;
if (b) {
return (p - mp) * 8 + next_black_bit[b];
}

// check bytes after the current byte
for (long i = 1; i < n; i++) {
p++;
b = *p;
if (b) {
return (p - mp) * 8 + next_black_bit[b];
}
}

return maxbits;
}
This implementation generates the next_black_bit table in the generate_next_black_bit_table function using a simple loop that scans each byte and records the position of the next black bit in the byte (starting from the least significant bit). The next_black_bit table is then used in the nextblack function to efficiently find the next black bit in the bitmap.

Note that the nextblack function takes a pointer to the bitmap mp, the maximum number of bits maxbits, and the starting bit index sbit. The function computes the byte index and bit index of the starting bit, and then checks for a black bit in the current byte and subsequent bytes. If a black bit is found, the function returns the index of the bit relative to the start of the bitmap. If no black bit is found, the function returns maxbits.





User
That looks a lot simpler and more efficient.
ChatGPT

2 / 2

Yes, using lookup tables can be much more efficient than checking each bit individually. It reduces the number of operations required to find the next black bit, and can make the function run faster. It's a common optimization technique used in many applications.





User
If I said that 90% of the bits are white, and 10% black, would that help you optimise further?
ChatGPT
Yes, that information can be helpful in optimizing the function further. With 90% of the bits being white, the function can be optimized to quickly skip over long stretches of white bits, rather than checking every single bit. One approach could be to add a check to quickly skip over groups of 8 white bits at a time. For example, if the current byte being examined is all zeros, the function can quickly skip ahead to the next byte that is not all zeros.

Another approach could be to use a lookup table for bytes that are all white. For example, if a byte is all zeros, the function can simply look up the next black bit in a table rather than performing any additional checks. This can further speed up the function when dealing with long stretches of white bits.

servodude
Lemon Half
Posts: 8413
Joined: November 8th, 2016, 5:56 am
Has thanked: 4490 times
Been thanked: 3621 times

Re: OpenAI \ ChatGPT

#588535

Postby servodude » May 11th, 2023, 11:48 pm

XFool wrote:
servodude wrote:I really should see if I've got hardware and cycles to set up my own and train it on the output of Pike, Kernigan, Hoare etc

"Pike"?

Possibly I'm just too old...


Rob Pike - wrote The Practice of Programming with Kernighan in the 90s and "notes in programming in C" that did the rounds on the early internet. I think he's still at Google and it's probably most famous now for the Go language.

9873210
Lemon Quarter
Posts: 1020
Joined: December 9th, 2016, 6:44 am
Has thanked: 234 times
Been thanked: 308 times

Re: OpenAI \ ChatGPT

#588584

Postby 9873210 » May 12th, 2023, 8:59 am

Sorcery wrote:Another conversation with ChatGPT. This time rather than offering my code, and asking for it to be reviewed, I asked it to generate code to a spec. This was much more productive.

...



Unless you try to use the code.

It did not ask what maxbits and sbit mean. Its assumptions are interesting though hair raising. It looks more like a copy and paste that solves some other problem but contained a few matching keywords.

Note that the C and java versions are different. In C it assumes maxbits is the size of the array in BYTEs while in java it assumes it is the size of the array in BITs. My guess is that the C version is not what you want as it may search well beyond the intended end of the array. This is a pretty insidious error that because it may actually work almost all of the time, sometimes returning too high a value and probably a rare crash when reading beyond the end of the array triggers a page fault.

In some of the places I've worked this would result in some programmer adding silly validation to the arguments before calling nextblack(), byzantine checking of the return value, or insisting that we must use the java version because for some reason C does not work. In other places we were allowed to defenestrate the afore mentioned programmer and every piece of code he got his hands on.

(If "(byte_idx < maxbits)" does not induce vomiting, you should not be working in programming. ChatGPT should find a new line of work.)

Sorcery
Lemon Quarter
Posts: 1242
Joined: November 4th, 2016, 6:38 pm
Has thanked: 148 times
Been thanked: 377 times

Re: OpenAI \ ChatGPT

#588663

Postby Sorcery » May 12th, 2023, 12:37 pm

9873210 wrote:
Sorcery wrote:Another conversation with ChatGPT. This time rather than offering my code, and asking for it to be reviewed, I asked it to generate code to a spec. This was much more productive.

...



Unless you try to use the code.

It did not ask what maxbits and sbit mean. Its assumptions are interesting though hair raising. It looks more like a copy and paste that solves some other problem but contained a few matching keywords.

Note that the C and java versions are different. In C it assumes maxbits is the size of the array in BYTEs while in java it assumes it is the size of the array in BITs. My guess is that the C version is not what you want as it may search well beyond the intended end of the array. This is a pretty insidious error that because it may actually work almost all of the time, sometimes returning too high a value and probably a rare crash when reading beyond the end of the array triggers a page fault.

In some of the places I've worked this would result in some programmer adding silly validation to the arguments before calling nextblack(), byzantine checking of the return value, or insisting that we must use the java version because for some reason C does not work. In other places we were allowed to defenestrate the afore mentioned programmer and every piece of code he got his hands on.

(If "(byte_idx < maxbits)" does not induce vomiting, you should not be working in programming. ChatGPT should find a new line of work.)


Maybe you are looking at one of the intermediate versions, I can't see a line "(byte_idx < maxbits)" in the final version ChatGPT presented. You are right about it not working though, I was trying to find out where and ensure it wasn't my changes causing it. If you don't believe me(!) here is the version I have been using for years and it works :

long nextblack(BYTE *mp, long maxbits, long sbit)
{
ULONG *mpx, *mpend;
ULONG mpval, bitindex;

if (sbit >= maxbits)
return maxbits;

// Check partial unsigned long on LHS
mpx = (ULONG *)mp + (sbit >> 5);
mpval = *mpx++ & $pd_rhbits[sbit & 31];
if (mpval) {
_BitScanForward(&bitindex, mpval);
bitindex += (sbit >> 5) << 5;
if (bitindex <= (ULONG)maxbits)
return bitindex;
return maxbits;
}

// Check middle words
mpend = (ULONG *)mp + (maxbits >> 5);
while (mpx < mpend) {
if (*mpx) {
_BitScanForward(&bitindex, *mpx);
bitindex += (ULONG)((mpx - (ULONG *)mp) << 5);
if (bitindex <= (ULONG)maxbits)
return bitindex;
return maxbits;
}
mpx++;
}
if (maxbits & 31) {
mpval = *mpx & $pd_lhbits[maxbits & 31];
if (mpval) {
_BitScanForward(&bitindex, mpval);
bitindex += (ULONG)((mpx - (ULONG *)mp) << 5);
if (bitindex <= (ULONG)maxbits)
return bitindex;
return maxbits;
}
}
return maxbits;
}

The ChatGPT code I have been testing is this which is slightly different to the ChatGPT version, the pre-enumerated array next_black_bit[256] is
BYTE next_black_bit[256] = {
8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
};
All the odd numbers are set to zero, tick, if it's an odd number then bit 0 is the first bit set black, 8 for an all white byte is valid (tick).

The code from ChatGPT is as follows :
// ChatGPT attempt, doesn't work at the moment
long nextblack(BYTE *mp, long maxbits, long sbit) {
long bit_idx = sbit % 8;
BYTE mask = (1 << bit_idx) - 1;
BYTE *p = mp + (sbit / 8);
long n = (maxbits - sbit) / 8;

// check bits in the current byte
BYTE b = *p & ~mask;
if (b) {
return ((p - mp) * 8) + next_black_bit[b];
}

// check bytes after the current byte
for (long i = 1; i < n; i++) {
p++;
b = *p;
if (b) {
return ((p - mp) * 8) + next_black_bit[b];
}
}

return maxbits;
}
I have not yet found the fault and I'm wondering whether it's worth it ;-) I think ChatGPT is being overhyped, if you have to debug it's code then it's not going to make programmers redundant or even save them time. Sorry about the lack of indenting, TLF seems to remove leading tabs and spaces.

mc2fool
Lemon Half
Posts: 7895
Joined: November 4th, 2016, 11:24 am
Has thanked: 7 times
Been thanked: 3051 times

Re: OpenAI \ ChatGPT

#588670

Postby mc2fool » May 12th, 2023, 1:06 pm

Sorcery wrote:Sorry about the lack of indenting, TLF seems to remove leading tabs and spaces.

If you put the code inside [code][/code] tags (either typing them in manually or using the Code button in the post editing toolbar), then it'll (a) preserve indentation and (b) limit the immediately visible size to 13 lines, adding a scrollbar if the contents are longer and so making it that you don't end up with a visibly really long post. :D

For examples see my post up-thread, viewtopic.php?p=588248#p588248. The 4th code block shows the scrollbar.

9873210
Lemon Quarter
Posts: 1020
Joined: December 9th, 2016, 6:44 am
Has thanked: 234 times
Been thanked: 308 times

Re: OpenAI \ ChatGPT

#588704

Postby 9873210 » May 12th, 2023, 5:03 pm

Sorcery wrote:
9873210 wrote:
(If "(byte_idx < maxbits)" does not induce vomiting, you should not be working in programming. ChatGPT should find a new line of work.)

Maybe you are looking at one of the intermediate versions, I can't see a line "(byte_idx < maxbits)" in the final version ChatGPT presented.

It's in the first "naive" version.

Sorcery wrote:I have not yet found the fault and I'm wondering whether it's worth it ;-) I think ChatGPT is being overhyped, if you have to debug it's code then it's not going to make programmers redundant or even save them time. Sorry about the lack of indenting, TLF seems to remove leading tabs and spaces.

That was my conclusion also.

Amongst other things
long n = (maxbits - sbit) / 8;
is wrong for maxbits = 9, sbit = 7 or thereabouts.

But the real problem is that the root of all evil is premature optimization, and assumptions about optimizations that are pessimization on most architectures. If 10% of the bits are set you need to optimize the search on the first byte or two, not the long tail. Even if the 10% is really 0.01% testing each byte for zero probably gets you most of any possible gains without thrashing the cache or branch prediction.

If I'd measured it and it really was a bottleneck that needed optimizing, something like Duff's device might be best (Depending on whether the hardware is better at branching or caching memory) ChatGPTs answer to the following question is misguided at best. Unfortunately, there are quite a few programmers that have been taught to give the same answer.
Sorcery wrote:User
If I said that 90% of the bits are white, and 10% black, would that help you optimise further?
ChatGPT
Yes, that information can be helpful in optimizing the function further. With 90% of the bits being white, the function can be optimized to quickly skip over long stretches of white bits, rather than checking every single bit. One approach could be to add a check to quickly skip over groups of 8 white bits at a time. For example, if the current byte being examined is all zeros, the function can quickly skip ahead to the next byte that is not all zeros.

Sorcery
Lemon Quarter
Posts: 1242
Joined: November 4th, 2016, 6:38 pm
Has thanked: 148 times
Been thanked: 377 times

Re: OpenAI \ ChatGPT

#588747

Postby Sorcery » May 12th, 2023, 8:41 pm

9873210 wrote:Amongst other things
long n = (maxbits - sbit) / 8;
is wrong for maxbits = 9, sbit = 7 or thereabouts.


You may be right about that, though I was thinking that it's wrong because the sbit:maxbit range could span more bytes to be examined than the evaluation of n. eg if sbit was 4 and maxbits was 25. The code should read
long n = (maxbits - sbit + 7) >>3;
It's not logically fatal but what twit divides an integer by 8 as opposed to a shift right?


Then there are the first two lines
long bit_idx = sbit % 8;
BYTE mask = (1 << bit_idx) - 1;

So if bit_idx is non-zero it definitely doesn't work, the 1 gets left shifted to make zero and the following subtraction of -1 makes the mask =255 for all non zero cases. Think its probable that the bit_idx = zero, case is'nt right either.

9873210 wrote:But the real problem is that the root of all evil is premature optimization, and assumptions about optimizations that are pessimization on most architectures. If 10% of the bits are set you need to optimize the search on the first byte or two, not the long tail. Even if the 10% is really 0.01% testing each byte for zero probably gets you most of any possible gains without thrashing the cache or branch prediction.

If I'd measured it and it really was a bottleneck that needed optimizing, something like Duff's device might be best (Depending on whether the hardware is better at branching or caching memory) ChatGPTs answer to the following question is misguided at best. Unfortunately, there are quite a few programmers that have been taught to give the same answer.


If I can paraphrase you, the root of a lot of problems is premature complication. I happen to know that bitmaps in the program that most use them are dominated by a short black run followed by a long white run. That's why in the subroutine that I use for nextblack, BYTE processing is replaced by 32 bit unsigned longs. The execution time reduces by a factor of 4 for the same number of statements.

Interesting discussion. I picked nextblack for ChatGPT because it seems like a lot of code to do something fairly simple and have always thought that the potential for improvement was there.

Regards, Steve

JohnB
Lemon Quarter
Posts: 2509
Joined: January 15th, 2017, 9:20 am
Has thanked: 696 times
Been thanked: 1008 times

Re: OpenAI \ ChatGPT

#588758

Postby JohnB » May 12th, 2023, 11:18 pm

Ted Chiang in the New Yorker, concerned that AI will supercharge capitalism to toe benefit of the 0.01%'s capital, rather than the worker's labour. https://www.newyorker.com/science/annal ... w-mckinsey. I suspect he is right to worry.

servodude
Lemon Half
Posts: 8413
Joined: November 8th, 2016, 5:56 am
Has thanked: 4490 times
Been thanked: 3621 times

Re: OpenAI \ ChatGPT

#588760

Postby servodude » May 13th, 2023, 2:03 am

Sorcery wrote:It's not logically fatal but what twit divides an integer by 8 as opposed to a shift right?


The same kind of twit that uses decimals when referring to bitfields?

Just wait until you see some Java or C# guy take a value of 255 that's mean to be the inverse of a mask in C and make the check > 255.0 (.. the other one I see regularly is leaving holes in integer ranges when they promote to doubles :roll: )

and this is the problem with ChatGPT, or learning how to code via the average of what's available on the internet,
if you don't know the problems and pitfalls beforehand you might not pick up on the bad stuff until it's too late

Strangely though if you ask ChatGPT specifically about red flags in code it will normally give sensible advice
- but that puts it in the category of the "well... you never asked" guy and we really don't need more of those :D

Sorcery
Lemon Quarter
Posts: 1242
Joined: November 4th, 2016, 6:38 pm
Has thanked: 148 times
Been thanked: 377 times

Re: OpenAI \ ChatGPT

#588987

Postby Sorcery » May 14th, 2023, 6:56 pm

servodude wrote:
Sorcery wrote:It's not logically fatal but what twit divides an integer by 8 as opposed to a shift right?


The same kind of twit that uses decimals when referring to bitfields?

Just wait until you see some Java or C# guy take a value of 255 that's mean to be the inverse of a mask in C and make the check > 255.0 (.. the other one I see regularly is leaving holes in integer ranges when they promote to doubles :roll: )

and this is the problem with ChatGPT, or learning how to code via the average of what's available on the internet,
if you don't know the problems and pitfalls beforehand you might not pick up on the bad stuff until it's too late

Strangely though if you ask ChatGPT specifically about red flags in code it will normally give sensible advice
- but that puts it in the category of the "well... you never asked" guy and we really don't need more of those :D


I did a mea culpa on here in a post that would have been placed here (directly after servodude's). I can't imagine why it would have been pulled, unless ChatGPT (or it's backers) intervened ;-) Not sure what to do now, can't remember exactly what was said.

servodude
Lemon Half
Posts: 8413
Joined: November 8th, 2016, 5:56 am
Has thanked: 4490 times
Been thanked: 3621 times

Re: OpenAI \ ChatGPT

#589017

Postby servodude » May 15th, 2023, 1:30 am

Sorcery wrote:
servodude wrote:
The same kind of twit that uses decimals when referring to bitfields?

Just wait until you see some Java or C# guy take a value of 255 that's mean to be the inverse of a mask in C and make the check > 255.0 (.. the other one I see regularly is leaving holes in integer ranges when they promote to doubles :roll: )

and this is the problem with ChatGPT, or learning how to code via the average of what's available on the internet,
if you don't know the problems and pitfalls beforehand you might not pick up on the bad stuff until it's too late

Strangely though if you ask ChatGPT specifically about red flags in code it will normally give sensible advice
- but that puts it in the category of the "well... you never asked" guy and we really don't need more of those :D


I did a mea culpa on here in a post that would have been placed here (directly after servodude's). I can't imagine why it would have been pulled, unless ChatGPT (or it's backers) intervened ;-) Not sure what to do now, can't remember exactly what was said.


...I guess that's SkyNet going active then :(

We've had a good run :)

GrahamPlatt
Lemon Quarter
Posts: 2092
Joined: November 4th, 2016, 9:40 am
Has thanked: 1041 times
Been thanked: 847 times

Re: OpenAI \ ChatGPT

#589070

Postby GrahamPlatt » May 15th, 2023, 9:25 am

Sorcery wrote:I did a mea culpa on here in a post that would have been placed here (directly after servodude's). I can't imagine why it would have been pulled, unless ChatGPT (or it's backers) intervened ;-) Not sure what to do now, can't remember exactly what was said.


Happens when you (I) hit “preview” instead of “submit” & then move on without noticing.

Mike4
Lemon Half
Posts: 7206
Joined: November 24th, 2016, 3:29 am
Has thanked: 1670 times
Been thanked: 3840 times

Re: OpenAI \ ChatGPT

#589075

Postby Mike4 » May 15th, 2023, 9:46 am

GrahamPlatt wrote:
Sorcery wrote:I did a mea culpa on here in a post that would have been placed here (directly after servodude's). I can't imagine why it would have been pulled, unless ChatGPT (or it's backers) intervened ;-) Not sure what to do now, can't remember exactly what was said.


Happens when you (I) hit “preview” instead of “submit” & then move on without noticing.



Also happens when another post gets added to the thread while you are composing yours.

You hit "Submit" but a screen appears asking you to review your post in the light of the recent thread update that occurred while you were busy typing. Easily missed and bloody annoying!

Watis
Lemon Quarter
Posts: 1423
Joined: November 5th, 2016, 10:53 am
Has thanked: 356 times
Been thanked: 500 times

Re: OpenAI \ ChatGPT

#589093

Postby Watis » May 15th, 2023, 10:48 am

Mike4 wrote:
GrahamPlatt wrote:
Happens when you (I) hit “preview” instead of “submit” & then move on without noticing.



Also happens when another post gets added to the thread while you are composing yours.

You hit "Submit" but a screen appears asking you to review your post in the light of the recent thread update that occurred while you were busy typing. Easily missed and bloody annoying!


A good test is to ensure the 'edit' icon is displayed in the top right corner of your post, to confirm that it has actually been added to the thread.

Watis

Sorcery
Lemon Quarter
Posts: 1242
Joined: November 4th, 2016, 6:38 pm
Has thanked: 148 times
Been thanked: 377 times

Re: OpenAI \ ChatGPT

#589241

Postby Sorcery » May 15th, 2023, 8:11 pm

Thanks for all the advice re the missing post.

My mea culpa involves :
Then there are the first two lines
long bit_idx = sbit % 8;
BYTE mask = (1 << bit_idx) - 1;

So if bit_idx is non-zero it definitely doesn't work, the 1 gets left shifted to make zero and the following subtraction of -1 makes the mask =255 for all non zero cases. Think its probable that the bit_idx = zero, case is'nt right either.

The last explanation is wrong, I am mixing up left shift with right shift. A left shift is a multiply, a right is division. It might be wrong but not for the reason given.

Have not pursued where the fault(s) are, too time consuming. I wouldn't use ChatGPT as a programmer assistant if I have to debug it's incorrect output. If it could do some self testing and refine it's code accordingly then it could be worth it.


Return to “Science”

Who is online

Users browsing this forum: No registered users and 38 guests