Chapter 52 Programming? I taught myself that.
Chapter 52 Programming? I taught myself that.
The three people instinctively gave up their seats.
It wasn't deliberate politeness, but rather an instinctive reaction.
It's like when interns arguing on the operating table, they automatically back away when the surgeon pushes the door open.
Although they knew very well that Lu Feng was a mechanical engineering major.
But I just inexplicably trust him. Is it because of Lu Feng's absolute understanding of mathematics? It doesn't seem so. It's just that I trust him as a person.
Lu Feng bent down and glanced at the screen.
The screen was filled with red error messages, densely packed with English text, like a death sentence, directly declaring the fate of Wang Zhe and his team.
But in his eyes, these things were not as distinctive as the complicated menu at the cafeteria entrance.
"IndexError: matrix dimension mismatch at line 247."
Lu Feng's gaze followed the error message upwards, quickly scrolling through the code editor.
Line 218, definition of the constraint matrix.
Line 233, assigning a value to the index of the variable.
Line 247, matrix multiplication.
It turned out to be the case.
He didn't speak or explain; he simply pulled out a chair and sat down.
Hands rested on the keyboard.
"Tap tap tap tap—"
A series of dense, almost uninterrupted tapping sounds suddenly erupted, unusually crisp in the quiet server room.
The pace was so fast it didn't feel like writing code; it felt more like playing a piano piece.
Wild bees fluttered about, and the hand moved with lightning speed.
Wang Zhe had just opened his mouth, wanting to say, "Let me explain the code structure to you," but before he could finish speaking, the scene in front of him completely shut him down.
He saw Lu Feng's fingers fly across the keyboard, the cursor precisely jumping to line 218, selecting an entire block of matrix definition code, and deleting it.
Type it in again.
Three lines of code replaced the original twelve lines.
Then the cursor jumps to line 233.
This time, Lu Feng didn't even modify it line by line; instead, he directly cut off the entire for loop and replaced it with a single line of NumPy vectorized operations.
Wang Zhe's pupils suddenly contracted.
He's a computer science student who won second prize in a provincial programming competition, and he has an extremely keen ability to judge the quality of code. Lu Feng's move just now wasn't simply fixing a bug; it was refactoring.
He replaced an inefficient matrix operation with a single-line vectorized statement.
This requires an extremely deep understanding of NumPy's underlying broadcasting mechanism, as well as a precise grasp of the transformation rules of matrix dimensions in linear algebra.
The key issue is that it's too fast.
It's been less than a minute since I sat down.
Wang Zhe subconsciously glanced at his hands, those hands that had undergone three years of programming training and that he considered to have a fairly fast hand speed.
Such fast hand speed requires an incredible understanding of the keyboard.
At this moment, they are hanging obediently at their sides, without moving.
Compared to others, his hand speed isn't even good enough to be on the table.
They're now fit to be a backdrop.
The knocking continued.
Lu Feng's cursor jumped to the matrix multiplication section on line 247, and he changed the original double loop manual multiplication into a call to the np.dot() function.
Then I scrolled down a few more lines and stopped at the definition of the objective function of the planning model.
He frowned.
"The symbols here are reversed. You're using 'maximize' for minimization problems, so the solver is in the wrong direction."
He changed `maximize` to `minimize` and casually added a non-negative constraint to the constraints below.
Then I pressed the run button.
The green progress bar flashed once.
Screen refresh.
A neat set of optimal solution data appears in the output window.
The optimal scheduling schemes for the three production lines, including the operating temperature range, humidity threshold, and equipment rotation cycle for each line, are all presented in tabular form.
A line chart is automatically generated at the bottom, showing a comparison curve of the defect rate before and after optimization.
From the first line of red error messages to the final output.
Two and a half minutes.
Li Hao stared at the clean and neat output data on the screen, his mind blank.
He is the leader of the programming group and has been using MATLAB and Python for three years.
He, Wang Zhe, and Liu Yu discussed the matrix dimension mismatch problem for nearly twenty minutes, trying everything from index checking to type conversion, but they still couldn't figure it out.
When they arrived, they made changes and adjustments in two and a half minutes and produced the result directly.
Moreover, the amount of code that was fixed was only one-third of their original amount.
Liu Yu pushed up his glasses and his throat bobbed. He leaned closer to the screen and looked at the lines of code that Lu Feng had modified three times.
"Vectorized broadcasting... dynamic index slicing..." His voice was a little hoarse. "Even the gold medalists in the ACM competition couldn't write this much."
Lu Feng stood up from his chair and stretched his wrists.
The problem lies in two places.
He walked to the whiteboard next to him, picked up a pen, and drew a diagram of two matrices.
"First, when you were constructing the constraint matrix, you were manually assigning values row by row using a loop. However, the parameter vector of the regression equation is a column vector, and directly performing matrix multiplication will cause misalignment in the second dimension. After switching to vectorized operations, NumPy will automatically handle dimension broadcasting, and there is no need for manual alignment at all."
He marked the dimensions on the whiteboard.
"Second, there's the issue of the solution direction. The scipy.optimize.linprog you're calling defaults to minimizing, but you haven't added a negative sign before the objective function, which is equivalent to maximizing the defect rate."
He paused, turned his head, and glanced at the three of them.
"It's like you wrote a program to help a factory produce the most duplicate products."
Liu Yu's glasses almost slipped off.
Li Hao covered his face, feeling somewhat embarrassed.
Even if you're not a good friend, you can still make mistakes like this, and the problem is still there and you haven't even noticed it.
Wang Zhe slammed his fist heavily on the table, his voice a mixture of frustration and admiration.
"Damn it, 'maximize' and 'minimize' are only three letters apart, and we've been looking for twenty minutes..."
Chen Jing, who had been watching from the sidelines, walked over with a water glass in her hand, her face bearing a numb expression that seemed to say, "I should have expected this."
"Junior, is your programming skill level this good too?" she asked.
Lu Feng put the whiteboard marker back into the pen slot.
"I studied on my own for a while before."
"Pfft~"
Chen Jing sprayed water directly out of her mouth.
A large cloud of water mist precisely covered the monitor in front of him that had just been calibrated, and the beautiful output data on the screen was instantly covered with a layer of saliva.
"Cough cough cough!"
Chen Jing coughed violently, one hand gripping the table while the other frantically pulled out tissues to wipe the screen.
Zhou Xiaoxiao quickly handed her a pack of tissues.
"No, self-taught?" Chen Jing swallowed hard, pointing to the few lines of textbook-level code on the screen, her voice already trembling with tears.
"How many of your skills are actually self-taught?"
Lu Feng thought about it.
"Quite a lot."
Chen Jing became completely withdrawn.
Who am I? Where am I? What am I doing? What kind of monster am I?
Li Hao silently closed the code file he had written and stared at the filename for two seconds.
Then right-click and delete.
"From now on, junior, you'll keep an eye on programming as well," he said, looking up with a sincere tone.
Lu Feng nodded without refusing.
Because they are really too bad.
PDLP